Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 22nd, 2012  |  syntax: None  |  size: 7.99 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <project name="example_app" default="build" xmlns:ivy="antlib:org.apache.ivy.ant" xmlns:ac="antlib:net.sf.antcontrib">
  4.  
  5.     <property file="${basedir}/build.properties"/>
  6.     <property file="${basedir}/build.local.properties"/>
  7.  
  8.     <path id="antcontrib.path">
  9.         <fileset dir="${antcontrib.dir}"/>
  10.     </path>
  11.     <taskdef resource="net/sf/antcontrib/antlib.xml" uri="antlib:net.sf.antcontrib" classpathref="antcontrib.path"/>
  12.  
  13.  
  14.     <!-- ... -->
  15.  
  16.  
  17.     <!--===================================================
  18.        Dependency management targets
  19.      =====================================================-->
  20.     <path id="ivy.lib.path">
  21.         <fileset dir="${ivy.lib.dir}" includes="*.jar"/>
  22.     </path>
  23.     <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
  24.  
  25.     <!-- Delete dependencies -->
  26.     <target name="clean-deps"
  27.             description="Delete all dependencies, including the directories they were extracted into."
  28.             depends="delete-dep-archive-dir, delete-dep-dirs">
  29.     </target>
  30.  
  31.     <target name="delete-dep-archive-dir">
  32.         <delete dir="${deparchive.dir}"/>
  33.     </target>
  34.  
  35.     <target name="delete-dep-dirs" depends="-get-dep-dir-list" if="dep-dir-list">
  36.         <ac:foreach list="${dep-dir-list}" target="delete-dep-dir" param="module" />
  37.     </target>
  38.  
  39.     <target name="delete-dep-dir">
  40.         <ac:propertycopy name="dep-dir" from="dep.${module}.dir"/>
  41.         <delete dir="${dep-dir}"/>
  42.     </target>
  43.  
  44.     <target name="clean-dep-cache"
  45.             description="Clear the Ivy cache.">
  46.         <ivy:cleancache />
  47.     </target>
  48.  
  49.     <!-- Retrieve and extract dependencies -->
  50.     <target name="get-deps" description="Get dependencies from the Ivy repository.">
  51.         <ivy:retrieve pattern="${deparchive.dir}/[artifact]-[revision].[ext]"/>
  52.     </target>
  53.  
  54.     <!-- Extract a dependency archive into a directory -->
  55.     <target name="extract-dep">
  56.         <ac:propertycopy property="extract-to-dir" from="dep.${dep.artifact}.dir" override="true" silent="true"/>
  57.         <echo message="Extracting ${dep.artifact}..."/>
  58.         <delete dir="${extract-to-dir}"/>
  59.         <ac:if>
  60.             <equals arg1="${dep.type}" arg2="tgz"/>
  61.             <then>
  62.                 <untar src="${dep.to}" dest="${extract-to-dir}" compression="gzip"/>
  63.             </then>
  64.             <ac:elseif>
  65.                 <equals arg1="${dep.type}" arg2="zip"/>
  66.                 <then>
  67.                     <unzip src="${dep.to}" dest="${extract-to-dir}" compression="gzip"/>
  68.                 </then>
  69.             </ac:elseif>
  70.             <ac:else>
  71.                 <echo msg="I don't know how to extract artifacts of type '${dep.type}'."/>
  72.                 <fail/>
  73.             </ac:else>
  74.         </ac:if>
  75.     </target>
  76.  
  77.     <!-- Publish dependencies -->
  78.     <target name="publish-deps" description="Package up dependencies and publish to Ivy repository."
  79.             depends="-get-dep-dir-list, -get-ivy-ssh-login" if="dep-dir-list">
  80.         <ac:foreach list="${dep-dir-list}" target="publish-dep" param="pub.module" inheritall="true"/>
  81.     </target>
  82.  
  83.     <!-- Get the list of dependency directories -->
  84.     <target name="-get-dep-dir-list">
  85.         <ac:propertyselector property="dep-dir-list" match="dep\.([^\.]*)\.dir" select="\1" />
  86.     </target>
  87.  
  88.     <!-- Prompt the user for SSH login credentials for the Ivy repo -->
  89.     <target name="-get-ivy-ssh-login">
  90.         <echo message="Please enter SSH credentials for the Ivy repository."/>
  91.         <input message="Username: " addproperty="repo.ssh.user"/>
  92.         <input message="Password: " addproperty="repo.ssh.pass">
  93.             <handler classname="org.apache.tools.ant.input.SecureInputHandler"/>
  94.         </input>
  95.         <sshexec username="${repo.ssh.user}" password="${repo.ssh.pass}" host="${repo.server}" port="${repo.ssh.port}" command="test 0"/>
  96.     </target>
  97.  
  98.     <!-- Publish a single dependency archive to the repository. -->
  99.     <target name="publish-dep" depends="package-dep, -check-dep-already-in-repo" if="dep-archive-exists" unless="dep-already-in-repo">
  100.         <echo>Publishing ${pub.module} to the repository...</echo>
  101.         <property name="pub.ivy.file" value="${module.dir}/ivy.xml"/>
  102.         <property name="pub.status" value="release"/>
  103.         <property name="pub.resolver" value="ssh"/>
  104.  
  105.         <ivy:publish revision="${pub.version}" status="${pub.status}" resolver="${pub.resolver}"
  106.                      module="${pub.module}" organisation="${pub.org}"
  107.                      srcivypattern="${pub.ivy.file}"
  108.                      overwrite="false"
  109.                      update="true"
  110.                 >
  111.             <artifacts pattern="${pub.archive.path}"/>
  112.         </ivy:publish>
  113.     </target>
  114.  
  115.     <!-- Check if the current version of a dependency already exists in the repository. -->
  116.     <target name="-check-dep-already-in-repo" if="dep-archive-exists">
  117.         <ivy:listmodules organisation="${pub.org}" module="${pub.module}" revision="${pub.version}" property="dep-already-in-repo" value="true"/>
  118.         <ac:if>
  119.             <isset property="dep-already-in-repo"/>
  120.             <then>
  121.                 <echo>${pub.module} ${pub.version} already exists in the repository.</echo>
  122.                 <echo>Skipping publishing of ${pub.module}.</echo>
  123.             </then>
  124.         </ac:if>
  125.     </target>
  126.  
  127.     <!-- Package up the dependency directory into an archive file -->
  128.     <target name="package-dep" depends="-parse-dep-ivy-file, -check-dep-archive-exists" if="dep-dir-exists" unless="dep-archive-exists">
  129.         <echo>Packaging ${pub.module}...</echo>
  130.         <mkdir dir="${deparchive.dir}"/>
  131.         <tar basedir="${module.dir}" destfile="${pub.archive.path}" compression="gzip"/>
  132.         <property name="dep-archive-exists" value="true"/>
  133.     </target>
  134.  
  135.     <!-- Parse some properties out of the dependency's ivy.xml file -->
  136.     <target name="-parse-dep-ivy-file" depends="-check-dep-dir-exists" if="dep-dir-exists">
  137.         <exec executable="bash" outputproperty="pub.version" errorproperty="err" resultproperty="result">
  138.             <arg value="-c"/>
  139.             <arg value="grep 'revision=' ${module.dir}/ivy.xml | sed -e 's/.*revision="\(\S*\)".*/\1/g'"/>
  140.         </exec>
  141.         <exec executable="bash" outputproperty="pub.org" errorproperty="err" resultproperty="result">
  142.             <arg value="-c"/>
  143.             <arg value="grep 'organisation=' ${module.dir}/ivy.xml | sed -e 's/.*organisation="\(\S*\)".*/\1/g'"/>
  144.         </exec>
  145.  
  146.         <fail message="Unable to determine ${pub.module} revision or organisation. Ensure the 'revision' and 'organisation' attributes are specified in ${module.dir}/ivy.xml.">
  147.             <condition>
  148.                 <or>
  149.                     <equals arg1="${pub.version}" arg2=""/>
  150.                     <equals arg1="${pub.org}" arg2=""/>
  151.                 </or>
  152.             </condition>
  153.         </fail>
  154.     </target>
  155.  
  156.     <!-- Check if a dependency directory exists -->
  157.     <target name="-check-dep-dir-exists">
  158.         <ac:propertycopy property="module.dir" from="dep.${pub.module}.dir"/>
  159.         <ac:if>
  160.             <available file="${module.dir}" type="dir"/>
  161.             <then>
  162.                 <property name="dep-dir-exists" value="true"/>
  163.             </then>
  164.             <else>
  165.                 <echo>${module.dir} specified in build.properties does not exist.</echo>
  166.                 <echo>Skipping ${pub.module}.</echo>
  167.             </else>
  168.         </ac:if>
  169.     </target>
  170.  
  171.     <!-- Check if a dependency archive file already exists in the archive directory -->
  172.     <target name="-check-dep-archive-exists">
  173.         <property name="pub.archive.path" value="${deparchive.dir}/${pub.module}-${pub.version}.tgz"/>
  174.         <ac:if>
  175.             <available file="${pub.archive.path}"/>
  176.             <then>
  177.                 <property name="dep-archive-exists" value="true"/>
  178.                 <echo>${pub.archive.path} already exists.</echo>
  179.                 <echo>Skipping packaging of ${pub.module}.</echo>
  180.                 <echo>Delete the archive manually if you want to recreate it.</echo>
  181.             </then>
  182.         </ac:if>
  183.     </target>
  184.  
  185. </project>