<?xml version="1.0"?>
<project name="Tomcat 6.0" default="deploy" basedir=".">

  <!--
  Properties required to be set:
  maven.home - full path to Maven2 installation, mvn or mvn.bat is assumed to be in ${maven.home}/bin/
  maven.bin  - the script to execute for maven, would be mvn or mvn.bat
  maven.repo.url - the URL of the repository, for example scp://people.apache.org/www/people.apache.org/repo/m2-snapshot-repository
  maven.repo.repositoryId - the id of the repository, for example apache.snapshots
  maven.deploy.version - the version that the components will be deployed as, for example @MAVEN.DEPLOY.VERSION@
  tomcat.lib.path - the path to tomcat JAR files
  tomcat.bin.path - the path to tomcat's bin directory (for other JAR files)
  tomcat.pom.path - the path to the POM files
  All these can be defined by mvn.properties (and defaults are in mvn.properties.default)
  
  To do password less upload, you can modify either
  $MAVE_HOME/conf/settings.xml or ~/.m2/settings.xml and add this snippet
    <server>
      <id>apache.snapshots</id>
      <username>yourusername</username>
      <privateKey>/home/yourusername/.ssh/id_rsa</privateKey>
      <passphrase></passphrase>
    </server>
  -->
  <property file="${basedir}/mvn.properties"/>
  <property file="${basedir}/mvn.properties.default"/>
  
  <target name="maven-deploy">
    <!--replace the version in the pom-->
    <copy file="${pom}" tofile="${pom}.tmp">
      <filterset>
        <filter token="MAVEN.DEPLOY.VERSION" value="${maven.deploy.version}"/>
      </filterset>
    </copy>
    <exec executable="${maven.home}/bin/${maven.bin}" failonerror="true">
      <env key="MAVEN_HOME" value="${maven.home}"/>
      <arg value="deploy:deploy-file"/>
      <arg value="-Dfile=${file}"/>
      <arg value="-DgroupId=${groupId}"/>
      <arg value="-DartifactId=${artifactId}"/>
      <arg value="-Dversion=${maven.deploy.version}"/>
      <arg value="-Dpackaging=jar"/>
      <arg value="-DgeneratePom=false"/>
      <arg value="-DrepositoryId=${maven.repo.repositoryId}"/>
      <arg value="-Durl=${maven.repo.url}"/>
      <arg value="-DpomFile=${pom}.tmp"/>
    </exec>
    <delete file="${pom}.tmp"/>
  </target>
  
  <target name="generic-deploy">
    <antcall target="maven-deploy"><!--Deploy annotations-->
      <param name="file" value="${tomcat.lib.path}/annotations-api.jar"/>
      <param name="groupId" value="org.apache.tomcat"/>
      <param name="artifactId" value="annotations-api"/>
      <param name="pom" value="${tomcat.pom.path}/annotations-api.pom"/>
    </antcall>
    <antcall target="maven-deploy"><!--Deploy Servlet api-->
      <param name="file" value="${tomcat.lib.path}/servlet-api.jar"/>
      <param name="groupId" value="org.apache.tomcat"/>
      <param name="artifactId" value="servlet-api"/>
      <param name="pom" value="${tomcat.pom.path}/servlet-api.pom"/>
    </antcall>
    <antcall target="maven-deploy"><!--Deploy expression lanaguage api-->
      <param name="file" value="${tomcat.lib.path}/el-api.jar"/>
      <param name="groupId" value="org.apache.tomcat"/>
      <param name="artifactId" value="el-api"/>
      <param name="pom" value="${tomcat.pom.path}/el-api.pom"/>
    </antcall>
    <antcall target="maven-deploy"><!--Deploy JSP api-->
      <param name="file" value="${tomcat.lib.path}/jsp-api.jar"/>
      <param name="groupId" value="org.apache.tomcat"/>
      <param name="artifactId" value="jsp-api"/>
      <param name="pom" value="${tomcat.pom.path}/jsp-api.pom"/>
    </antcall>
    <antcall target="maven-deploy"><!--Deploy JULI-->
      <param name="file" value="${tomcat.bin.path}/tomcat-juli.jar"/>
      <param name="groupId" value="org.apache.tomcat"/>
      <param name="artifactId" value="juli"/>
      <param name="pom" value="${tomcat.pom.path}/juli.pom"/>
    </antcall>
    <antcall target="maven-deploy"><!--Deploy Tribes-->
      <param name="file" value="${tomcat.lib.path}/catalina-tribes.jar"/>
      <param name="groupId" value="org.apache.tomcat"/>
      <param name="artifactId" value="tribes"/>
      <param name="pom" value="${tomcat.pom.path}/tribes.pom"/>
    </antcall>
    <antcall target="maven-deploy"><!--Deploy Jasper EL-->
      <param name="file" value="${tomcat.lib.path}/jasper-el.jar"/>
      <param name="groupId" value="org.apache.tomcat"/>
      <param name="artifactId" value="jasper-el"/>
      <param name="pom" value="${tomcat.pom.path}/jasper-el.pom"/>
    </antcall>
    <antcall target="maven-deploy"><!--Deploy Jasper JDT-->
      <param name="file" value="${tomcat.lib.path}/jasper-jdt.jar"/>
      <param name="groupId" value="org.apache.tomcat"/>
      <param name="artifactId" value="jasper-jdt"/>
      <param name="pom" value="${tomcat.pom.path}/jasper-jdt.pom"/>
    </antcall>
    <antcall target="maven-deploy"><!--Deploy Coyote-->
      <param name="file" value="${tomcat.lib.path}/tomcat-coyote.jar"/>
      <param name="groupId" value="org.apache.tomcat"/>
      <param name="artifactId" value="coyote"/>
      <param name="pom" value="${tomcat.pom.path}/coyote.pom"/>
    </antcall>
    <antcall target="maven-deploy"><!--Deploy Catalina-->
      <param name="file" value="${tomcat.lib.path}/catalina.jar"/>
      <param name="groupId" value="org.apache.tomcat"/>
      <param name="artifactId" value="catalina"/>
      <param name="pom" value="${tomcat.pom.path}/catalina.pom"/>
    </antcall>
    <antcall target="maven-deploy"><!--Deploy Catalina-HA-->
      <param name="file" value="${tomcat.lib.path}/catalina-ha.jar"/>
      <param name="groupId" value="org.apache.tomcat"/>
      <param name="artifactId" value="catalina-ha"/>
      <param name="pom" value="${tomcat.pom.path}/catalina-ha.pom"/>
    </antcall>
    <antcall target="maven-deploy"><!--Deploy Jasper-->
      <param name="file" value="${tomcat.lib.path}/jasper.jar"/>
      <param name="groupId" value="org.apache.tomcat"/>
      <param name="artifactId" value="jasper"/>
      <param name="pom" value="${tomcat.pom.path}/jasper.pom"/>
    </antcall>
    <antcall target="maven-deploy"><!--Deploy Extras Juli-->
      <param name="file" value="${tomcat.extras.path}/tomcat-juli.jar"/>
      <param name="groupId" value="org.apache.tomcat.extras"/>
      <param name="artifactId" value="juli"/>
      <param name="pom" value="${tomcat.pom.path}/juli-extras.pom"/>
    </antcall>
    <antcall target="maven-deploy"><!--Deploy Extras Juli Adapters-->
      <param name="file" value="${tomcat.extras.path}/tomcat-juli-adapters.jar"/>
      <param name="groupId" value="org.apache.tomcat.extras"/>
      <param name="artifactId" value="juli-adapters"/>
      <param name="pom" value="${tomcat.pom.path}/juli-adapters.pom"/>
    </antcall>
  </target>

  <target name="deploy-snapshot">
    <antcall target="generic-deploy">
      <param name="maven.repo.repositoryId" value="${maven.snapshot.repo.repositoryId}"/>
      <param name="maven.repo.url" value="${maven.snapshot.repo.url}"/>
      <param name="maven.deploy.version" value="${maven.snapshot.deploy.version}"/>
    </antcall>
  </target>

  <target name="deploy-release">
    <antcall target="generic-deploy">
      <param name="maven.repo.repositoryId" value="${maven.release.repo.repositoryId}"/>
      <param name="maven.repo.url" value="${maven.release.repo.url}"/>
      <param name="maven.deploy.version" value="${maven.release.deploy.version}"/>
    </antcall>
  </target>

</project>
