FANDOM


Readings

Pattern to Specify Files and Directories

Ant Tasks

  • FindBugs Ant task
  • JXR Ant Task
    • An Ant task for the JXR report. Based on the JXR Maven plugin
    • License : the Apache License, Version 2.0
  • JavaNCSS Ant Task
    • Checks some basic code metrics and generates a report.
    • Easily automate JSHint validation on your Javascript code base with Apache Ant.
  • Ant Task for Doxygen
    • License : Apache License

Configuration Boilerplates

Typical Configuration collaborating with Maven

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project name="project.name" basedir="." default="echo.env"
  3.  xmlns:artifact="antlib:org.apache.maven.artifact.ant"
  4.  xmlns:antelope="antlib:ise.antelope.tasks"
  5.  xmlns:contrib="antlib:net.sf.antcontrib">
  6.  
  7.   <!-- Ant references :
  8.      Manual : http://ant.apache.org/manual/index.html
  9.      Path-like Structures : http://ant.apache.org/manual/using.html#path
  10.      Resource Collections : http://ant.apache.org/manual/Types/resources.html#collection
  11.  -->
  12.   <description>Title or descrption for this build file</description>
  13.  
  14.   <property environment="env" />
  15.  
  16.   <!-- Define Maven-Ant tasks -->
  17.   <!-- For more on Maven-Ant tasks, refer http://maven.apache.org/ant-tasks/ -->
  18.   <typedef resource="org/apache/maven/artifact/ant/antlib.xml"
  19.   uri="antlib:org.apache.maven.artifact.ant"
  20.   classpath="lib/maven-ant-tasks-2.1.3.jar">
  21.   </typedef>
  22.  
  23.   <artifact:dependencies pathId="ant.tasks.classpath">
  24.     <!-- libraries only necessary for Ant task not application. -->
  25.     <!-- Ant-Contrib tasks. For more, refer http://ant-contrib.sourceforge.net/tasks/ -->
  26.     <dependency groupId="ant-contrib" artifactId="ant-contrib" version="1.0b3" />
  27.     <!-- Antelope tasks. For more, refer http://antelope.stage.tigris.org/nonav/docs/manual/index.html -->
  28.     <dependency groupId="org.tigris.antelope" artifactId="antelopetasks" version="3.2.10" />
  29.     <dependency groupId="org.umlgraph" artifactId="umlgraph" version="5.6.6" />
  30.     <dependency groupId="com.lunatech.jax-doclets" artifactId="doclets" version="0.10.0" />
  31.     <remoteRepository id="centeral2" url="http://repo2.maven.org/maven2/" />
  32.   </artifact:dependencies>
  33.  
  34.   <!-- Define Ant-Contrib tasks -->
  35.   <taskdef resource="net/sf/antcontrib/antlib.xml" uri="antlib:net.sf.antcontrib"
  36.   classpathref="ant.tasks.classpath" />
  37.  
  38.   <!-- Define Antelope tasks -->
  39.   <taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask"
  40.   uri="antlib:ise.antelope.tasks" classpathref="ant.tasks.classpath" />
  41.   <taskdef name="if" classname="ise.antelope.tasks.IfTask"
  42.   uri="antlib:ise.antelope.tasks" classpathref="ant.tasks.classpath" />
  43.   <taskdef name="var" classname="ise.antelope.tasks.Variable"
  44.   uri="antlib:ise.antelope.tasks" classpathref="ant.tasks.classpath" />
  45.   <taskdef name="unset" classname="ise.antelope.tasks.Unset"
  46.   uri="antlib:ise.antelope.tasks" classpathref="ant.tasks.classpath" />
  47.  
  48.   <artifact:pom id="project.pom" file="${basedir}/pom.xml" />
  49.   <artifact:dependencies pomRefId="project.pom" pathId="project.classpath" />
  50.  
  51.   <target name="echo.env">
  52.     <!-- @todo How to sort the list -->
  53.     <pathconvert pathsep="${line.separator}" refid="project.classpath" property="project.classpath.list">
  54.       <mapper type="regexp" from="(.*\\\.m2\\repository\\)?(.*)" to="  \2" />
  55.     </pathconvert>
  56.  
  57.     <echo>Defined properties : </echo>
  58.     <echoproperties />
  59.     <echo>
  60.     </echo>
  61.     <echo>Classpath : </echo>
  62.     <echo>${project.classpath.list}</echo>
  63.   </target>
  64.  
  65.   <target name="check.env">
  66.     <fail unless="env.MAVEN_HOME">Environment variable MAVEN_HOME should be specified properly.</fail>
  67.   </target>
  68.  
  69. </project>

Typical Configuration collaborating with Maven, Jetty and Subversion

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project name="project.name" basedir="." default="echo.env" xmlns:artifact="antlib:org.apache.maven.artifact.ant"
  3.  xmlns:antelope="antlib:ise.antelope.tasks" xmlns:contrib="antlib:net.sf.antcontrib">
  4.  
  5.   <!-- Ant references :
  6.       Manual : http://ant.apache.org/manual/index.html
  7.       Path-like Structures : http://ant.apache.org/manual/using.html#path
  8.       Resource Collections : http://ant.apache.org/manual/Types/resources.html#collection
  9.  -->
  10.   <description>Title or descrption for this build file</description>
  11.  
  12.   <property environment="env" />
  13.  
  14.   <!-- Define Maven-Ant tasks -->
  15.   <!-- For more on Maven-Ant tasks, refer http://maven.apache.org/ant-tasks/ -->
  16.   <typedef resource="org/apache/maven/artifact/ant/antlib.xml"
  17.    uri="antlib:org.apache.maven.artifact.ant"
  18.    classpath="lib/maven-ant-tasks-2.1.3.jar">
  19.   </typedef>
  20.  
  21.   <artifact:dependencies pathId="ant.tasks.classpath">
  22.     <!-- libraries only necessary for Ant task not application. -->
  23.     <!-- Ant-Contrib tasks. For more, refer http://ant-contrib.sourceforge.net/tasks/ -->
  24.     <dependency groupId="ant-contrib" artifactId="ant-contrib" version="1.0b3" />
  25.     <!-- Antelope tasks. For more, refer http://antelope.stage.tigris.org/nonav/docs/manual/index.html -->
  26.     <dependency groupId="org.tigris.antelope" artifactId="antelopetasks" version="3.2.10" />
  27.     <!-- SvnAnt tasks. For more, refer http://subclipse.tigris.org/svnant.html -->
  28.     <dependency groupId="org.tigris" artifactId="svnant" version="1.3.1" scope="system"
  29.      systemPath="${basedir}/lib/svnant.jar" />
  30.     <dependency groupId="org.tigris" artifactId="svn-client-adapter" version="0.9.102"
  31.      scope="system" systemPath="${basedir}/lib/svnClientAdapter.jar" />
  32.     <dependency groupId="org.tmatesoft.svnkit" artifactId="svnkit" version="1.8.10" />
  33.     <dependency groupId="org.tmatesoft.svnkit" artifactId="svnkit-javahl16" version="1.8.10" />
  34.     <!-- TestNG tasks. For more, refer http://testng.org/doc/ant.html -->
  35.     <dependency groupId="org.testng" artifactId="testng" version="6.8.21" />
  36.     <dependency groupId="org.mortbay.jetty" artifactId="jetty-runner" version="7.6.9.v20130131" />
  37.     <dependency groupId="org.eclipse.jetty" artifactId="jetty-jmx" version="7.6.9.v20130131" />
  38.     <dependency groupId="org.eclipse.jetty" artifactId="jetty-start" version="7.6.9.v20130131" />
  39.     <dependency groupId="org.umlgraph" artifactId="umlgraph" version="5.6.6" />
  40.     <dependency groupId="com.lunatech.jax-doclets" artifactId="doclets" version="0.10.0" />
  41.     <remoteRepository id="centeral2" url="http://repo2.maven.org/maven2/" />
  42.     <remoteRepository id="maven2-repository.dev.java.net" url="http://download.java.net/maven/2/" />
  43.     <remoteRepository id="tmatesoft-releases"
  44.      url="http://maven.tmatesoft.com/content/repositories/releases/" />
  45.     <remoteRepository id="evolvis-3rdparty" url="http://maven-repo.evolvis.org/3rdparty"
  46.      layout="default" />
  47.   </artifact:dependencies>
  48.  
  49.   <!-- Define Ant-Contrib tasks -->
  50.   <taskdef resource="net/sf/antcontrib/antlib.xml" uri="antlib:net.sf.antcontrib"
  51.    classpathref="ant.tasks.classpath" />
  52.  
  53.   <!-- Define Antelope tasks -->
  54.   <taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask"
  55.    uri="antlib:ise.antelope.tasks" classpathref="ant.tasks.classpath" />
  56.   <taskdef name="if" classname="ise.antelope.tasks.IfTask"
  57.    uri="antlib:ise.antelope.tasks" classpathref="ant.tasks.classpath" />
  58.   <taskdef name="var" classname="ise.antelope.tasks.Variable"
  59.    uri="antlib:ise.antelope.tasks" classpathref="ant.tasks.classpath" />
  60.   <taskdef name="unset" classname="ise.antelope.tasks.Unset"
  61.    uri="antlib:ise.antelope.tasks" classpathref="ant.tasks.classpath" />
  62.  
  63.   <!-- Define SvnAnt tasks -->
  64.   <typedef resource="org/tigris/subversion/svnant/svnantlib.xml"
  65.    classpathref="ant.tasks.classpath" />
  66.  
  67.   <!-- Define TestNG tasks -->
  68.   <taskdef resource="testngtasks" classpathref="ant.tasks.classpath" />
  69.  
  70.   <artifact:pom id="project.pom" file="${basedir}/pom.xml" />
  71.   <artifact:dependencies pomRefId="project.pom" pathId="project.classpath" />
  72.  
  73.   <target name="echo.env" depends="query.version.revision">
  74.     <!-- @todo How to sort the list -->
  75.     <pathconvert pathsep="${line.separator}" refid="project.classpath" property="project.classpath.list">
  76.       <mapper type="regexp" from="(.*\\\.m2\\repository\\)?(.*)" to="  \2" />
  77.     </pathconvert>
  78.  
  79.     <echo>Defined properties : </echo>
  80.     <echoproperties />
  81.     <echo>
  82.     </echo>
  83.     <echo>Classpath : </echo>
  84.     <echo>${project.classpath.list}</echo>
  85.     <echo>Parsed Version : </echo>
  86.     <echo> major : ${ver.major}</echo>
  87.     <echo> minor : ${ver.minor}</echo>
  88.     <echo> incremental : ${ver.incremental}</echo>
  89.     <echo> tail : ${ver.tail}</echo>
  90.     <echo>Max revision under this project : ${revision.max}</echo>
  91.   </target>
  92.  
  93.   <target name="check.env">
  94.     <fail unless="env.MAVEN_HOME">Environment variable MAVEN_HOME should be specified properly.</fail>
  95.   </target>
  96.  
  97.   <target name="query.version.revision">
  98.     <svnant:svnSetting id="svn.setting" svnkit="true" javahl="false" />
  99.     <svnant:svn refid="svn.setting">
  100.       <!-- wcversion will set properties of repository.url, revision.max, committed.max and et al.
  101.        For more, refer http://subclipse.tigris.org/svnant/svntask.html#wcversion -->
  102.       <wcversion path="${basedir}" />
  103.     </svnant:svn>
  104.     <contrib:propertyregex property="ver.wo.snapshot" input="${project.pom.version}"
  105.      regexp="([0-9]+(\.[0-9]+)?(\.[0-9]+)?)" select="\1" defaultValue="0.0.0" />
  106.      
  107.     <contrib:propertyregex property="ver.major" input="${project.pom.version}"
  108.      regexp="([0-9]+)(?:\.([0-9]+))?(?:\.([0-9]+))?(.+)?" select="\1" />
  109.     <contrib:propertyregex property="ver.minor" input="${project.pom.version}"
  110.      regexp="([0-9]+)(?:\.([0-9]+))?(?:\.([0-9]+))?(.+)?" select="\2" defaultValue="0" />
  111.     <contrib:propertyregex property="ver.incremental" input="${project.pom.version}"
  112.      regexp="([0-9]+)(?:\.([0-9]+))?(?:\.([0-9]+))?(.+)?" select="\3" defaultValue="0" />
  113.     <contrib:propertyregex property="ver.tail" input="${project.pom.version}"
  114.      regexp="([0-9]+)(?:\.([0-9]+))?(?:\.([0-9]+))?(.+)?" select="\4" defaultValue="0" />
  115.  
  116.     <antelope:if name="ver.minor" value="">
  117.       <antelope:unset name="ver.minor" />
  118.       <property name="ver.minor" value="0" />
  119.     </antelope:if>
  120.     <antelope:if name="ver.incremental" value="">
  121.       <antelope:unset name="ver.incremental" />
  122.       <property name="ver.incremental" value="0" />
  123.     </antelope:if>
  124.   </target>
  125. </project>

Tips and Tricks

Print classpath in Ant build file

Sometimes, it can be convenient to print out classpath to console to confirm it is correctly setup in Ant build file. For this, you can use the expression ${toString:pathreference} like the following example

 <?xml version="1.0" encoding="UTF-8"?>
 <project name="shop1-hibernate-export" default="echo-env" basedir="."
 xmlns:artifact="antlib:org.apache.maven.artifact.ant">
 
  ...
 
  <!-- Get Maven Dependency -->
  <artifact:pom id="project.pom" file="${project.home}/pom.xml"/>
  <artifact:dependencies pomRefId="project.pom" pathId="dependency.classpath"/>
 
  <!-- Ant4Eclipse Tasks Definitions -->
  <taskdef resource="net/sf/ant4eclipse/antlib.xml" />
  <getEclipseClasspath pathId="eclipse.classpath" project="../../../../../.."/>
 
  <path id="project.classpath">
   <path refid="dependency.classpath"/>
   <path refid="eclipse.classpath"/>
  </path>
 
  <target name="echo-env">
   <echoproperties/>
   <echo>${toString:project.classpath}</echo>
  </target>
 
  <target name="generate-ddl">
 
  </target>
 
 </project>

Listing members of fileset or path-like structure line by line

For eye-checking or reporting purpose, sometimes it is necessary to list members of fileset each one in it's line. You can do this using pathconvert and echo tasks.

The following is snippet used to list non-java files in source directories of Maven projects (which are multi-module form).

  1. <target name="source.detect.nonjava">
  2.    <fileset id="nonjava" dir="..">
  3.       <include name="*/src/main/java/**"/>
  4.       <exclude name="**/*.java"/>
  5.    </fileset>
  6.    
  7.    <pathconvert pathsep="${line.separator}" property="nonjava.list" refid="nonjava">
  8.       <mapper type="regexp" from=".*\\(.*\\src\\main\\java\\.*)" to="\1"/>
  9.    </pathconvert>
  10.        
  11.    <echo>${nonjava.list}</echo>
  12. </target>

You can also list path-like structure line by line using <pathconvert> task.

  1. <path id="classpath.main">
  2.    <pathelement path="${java.class.path}" />
  3.    <path refid="maven.compile.classpath"/>
  4. </path>
  5. <pathconvert pathsep="${line.separator}" property="classpath.main.list" refid="classpath.main"/>
  6. <echo>${classpath.main.list}</echo>

Actually <pathconvert> can also be applied to dirset, filelist, or propertyset as well. For details, refer http://ant.apache.org/manual/Tasks/pathconvert.html

Including another path-like structure within a path-like structure

If you want include a path-like structure to another, you can use <path refid="..."> like this.

  1. <classpath id="classpath.base">
  2.   <pathelement location="..."/>
  3.   <pathelement location="..."/>
  4.   <fileset dir="...">
  5.     <include name="..."/>
  6.   </fileset>
  7. </classpath>
  8.  
  9. <classpath id="classpath.extended">
  10.   <path refid="classpath.base"/>
  11.   <pathelement location="..."/>
  12.   <fileset dir="...">
  13.     <include name="..."/>
  14.   </fileset>
  15. </classpath>

Note that you should not use <pathelement path="...">. The value of path attribute in pathelement is expected to be string corresponding to path not id of path-like structure. The following would cause error.

  1. <classpath id="classpath.base">
  2.   <pathelement location="..."/>
  3.   <pathelement location="..."/>
  4.   <fileset dir="...">
  5.     <include name="..."/>
  6.   </fileset>
  7. </classpath>
  8.  
  9. <classpath id="classpath.extended">
  10.   <pathelement path="classpath.base"/>
  11.   <pathelement location="..."/>
  12.   <fileset dir="...">
  13.     <include name="..."/>
  14.   </fileset>
  15. </classpath>

If you really want to use pathelement all the way, you can use toString function. The following would work.

  1. <classpath id="classpath.base">
  2.   <pathelement location="..."/>
  3.   <pathelement location="..."/>
  4.   <fileset dir="...">
  5.     <include name="..."/>
  6.   </fileset>
  7. </classpath>
  8.  
  9. <classpath id="classpath.extended">
  10.   <pathelement path="${toString:classpath.base}"/>
  11.   <pathelement location="..."/>
  12.   <fileset dir="...">
  13.     <include name="..."/>
  14.   </fileset>
  15. </classpath>

Note that ${java.class.path} which can be evaluated from default system properties of Java is just string corresponding to classpath and maven.plugin.classpath which is defined implicitly with maven-antrun-plugin is id of path-like structure. So, you should use them like the following.

  1. <classpath>
  2.   <pathelement path="${java.class.path}"/>
  3.   <path refid="maven.plugin.classpath"/>
  4.   <fileset dir="...">
  5.     <include name="..."/>
  6.   </fileset>
  7. </classpath>

Printing environment variables

To identify all the environment variables and their values defined within the process the current Ant build is running, you can use echo task with environment attribute.

...
<property environment='env'/>
<echoproperties/>
...

The above property task makes properties for all the environment variables in current process with the property names prefixed by 'env'.

Applying pattern to Copy task

As of Ant 1.7.1, copy task with only file attribute seems to ignore the glob or regexp mapper defined to the task. In this case you should use nested fileset element.

The following task wouldn't work as is expected.

  1. <copy file="${commons-lang:commons-lang:jar}"
  2.      todir="${targetdir}"
  3.      enablemultiplemappings="true">
  4.   <mapper type="regexp" from="^(.*)\.jar$$" to="\1.zip"/>
  5. </copy>

But the following task would work.

  1. <copy todir="${targetdir}"
  2.      flatten="true" overwrite="true" verbose="true"
  3.      enablemultiplemappings="true">
  4.   <fileset file="${commons-lang:commons-lang:jar}"/>
  5.   <mapper type="regexp" from="^(.*)\.jar$$" to="\1.zip"/>
  6. </copy>

Concatenating values of multiple properties into a property

Unlike what the name implies, pathconvert task can concatenate values of several properties into a property along with the nested propertyset task. pathconvert can work with nested resource collection. For more, refer http://ant.apache.org/manual/Tasks/pathconvert.html.

The following sample create a phones property of which value is the concatenation of the values by phone.home, phone.mobile and phone.office and separated by comma.

<pathconvert property="phones" pathsep=",">
   <propertyset>
      <propertyref name="phones.home"/>
      <propertyref name="phones.mobile"/>
      <propertyref name="phones.office"/>
   </propertyset>
</pathconvert>

When names of properties to concatenate have a certain pattern like above, you can use prefix or regex instead of name with propertyref task. For more about propertyset, refer http://ant.apache.org/manual/Types/propertyset.html

<pathconvert property="phones" pathsep=",">
   <propertyset>
      <propertyref prefix="phones."/>
   </propertyset>
</pathconvert>

If you want concatenate only home and mobile phone numbers.

<pathconvert property="phones.personal" pathsep=",">
   <propertyset>
      <propertyref regex="phones\.(home|mobile)"/>
   </propertyset>
</pathconvert>

Adding or removing files into/from a JAR file

You can remove files from a archive file by repacking the archive file using zip or jar task. When repacking the archive, new files can be added also.

The following sample removes log4j module and SLF4J/log4j binding module from the ActiveMQ Web Console artifact and adds logback modules using jar task.

  1.    ...
  2.    <target name="prepare.activemq.webconsole">
  3.       <description>Copy a slightly modified(removed slf4j-log4j12-*.jar and log4j12-*.jar within) JAR file of ActiveMQ WebConsole and make necessary directories</description>
  4.       <delete file="${project.pom.build.directory}/activemq-web-console-wo-log4j.war"/>
  5.       <jar destfile="${project.pom.build.directory}/activemq-web-console-wo-log4j.war" update="false">
  6.          <zipfileset src="${org.apache.activemq:activemq-web-console:war}"
  7.            excludes="WEB-INF/lib/slf4j-log4j12-*.jar,WEB-INF/lib/log4j-*.jar"/>
  8.          <mappedresources>
  9.             <resources>
  10.                <file name="${ch.qos.logback:logback-classic:jar}"/>
  11.                <file name="${ch.qos.logback:logback-core:jar}"/>
  12.                <file name="${org.codehaus.janino:janino:jar}"/>
  13.             </resources>
  14.             <chainedmapper>
  15.                <flattenmapper/>
  16.                <globmapper from="*" to="WEB-INF/lib/*"/>
  17.             </chainedmapper>
  18.          </mappedresources>
  19.          <mappedresources>
  20.             <resources>
  21.                <file name="${basedir}/src/test/resources/logback-test.xml"/>
  22.             </resources>
  23.             <chainedmapper>
  24.                <flattenmapper/>
  25.                <globmapper from="logback-test.xml" to="WEB-INF/classes/logback.xml"/>
  26.             </chainedmapper>
  27.          </mappedresources>
  28.       </jar>
  29.       <copy file="${project.pom.build.directory}/activemq-web-console-wo-log4j.war"
  30.            todir="${env.TEMP}" overwrite="true" flatten="true"/>
  31.       <mkdir dir="${env.TEMP}/activemq"/>
  32.    </target>

Querying properties in POM

You can query the property values defined via Maven POM using Maven-Ant tasks.

  1. <project name="thirdstage.exercise.akka" basedir="."
  2.   default="echo.env" xmlns:artifact="antlib:org.apache.maven.artifact.ant"
  3.   xmlns:antelope="antlib:ise.antelope.tasks" xmlns:contrib="antlib:net.sf.antcontrib">
  4.  
  5.    <property environment="env" />
  6.  
  7.    <typedef resource="org/apache/maven/artifact/ant/antlib.xml"
  8.      uri="antlib:org.apache.maven.artifact.ant" classpath="lib/maven-ant-tasks-2.1.3.jar">
  9.    </typedef>
  10.  
  11.    <taskdef resource="net/sf/antcontrib/antlib.xml"
  12.      uri="antlib:net.sf.antcontrib" classpathref="ant.tasks.classpath" />
  13.  
  14.    <artifact:pom id="project.pom" file="${basedir}/pom.xml" />
  15.    <artifact:dependencies pomRefId="project.pom" pathId="project.classpath" />
  16.  
  17.    <target name="echo.env">
  18.       <pathconvert pathsep="${line.separator}" refid="project.classpath" property="project.classpath.list">
  19.          <mapper type="regexp" from="(.*\\\.m2\\repository\\)?(.*)" to="  \2" />
  20.       </pathconvert>
  21.       <echo>Defined properties : </echo>
  22.       <echoproperties />
  23.       <echo> </echo>
  24.       <echo>Maven properties</echo>
  25.       <echo>   java.version = ${project.pom.properties.java.version}</echo>
  26.       <echo>   spring.version = ${project.pom.properties.spring.version}</echo>
  27.       <echo>   mybatis.version = ${project.pom.properties.mybatis.version}</echo>
  28.       <echo>   akka.version = ${project.pom.properties.akka.version}</echo>
  29.       <echo>   camel.version = ${project.pom.properties.camel.version}</echo>
  30.       <echo>   activemq.version = ${project.pom.properties.activemq.version}</echo>
  31.       <echo>   jetty.version = ${project.pom.properties.jetty.version}</echo>
  32.       <echo> </echo>
  33.       <echo>Classpath : </echo>
  34.       <echo>${project.classpath.list}</echo>
  35.    </target>
  36. </project>

Where the pom.xml is

  1. <project xmlns="http://maven.apache.org/POM/4.0.0"
  2.   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4.  
  5.    ...
  6.  
  7.    <properties>
  8.       <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  9.       <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  10.       <skipTests>false</skipTests>
  11.       <maven.deploy.skip>true</maven.deploy.skip>
  12.       <maven.javadoc.skip>false</maven.javadoc.skip>
  13.       <maven.site.deploy.skip>true</maven.site.deploy.skip>
  14.       <findbugs.skip>true</findbugs.skip>
  15.       <checkstyle.skip>true</checkstyle.skip>
  16.       <java.version>1.7</java.version>
  17.       <slf4j.version>1.7.12</slf4j.version>
  18.       <logback.version>1.1.3</logback.version>
  19.       <junit.version>4.8.2</junit.version>
  20.       <testng.version>6.9.10</testng.version>
  21.       <commons.lang3.version>3.4</commons.lang3.version>
  22.       <httpcomponents.version>4.5.2</httpcomponents.version>
  23.       <spring.version>4.0.9.RELEASE</spring.version>
  24.       <mybatis.version>3.2.8</mybatis.version>
  25.       <jackson.version>2.5.4</jackson.version>
  26.       <akka.version>2.3.15</akka.version>
  27.       <camel.version>2.17.0</camel.version>
  28.       <activemq.version>5.13.2</activemq.version>
  29.       <jetty.version>9.2.16.v20160414</jetty.version>
  30.       <dependency.locations.enabled>false</dependency.locations.enabled>
  31.    </properties>
  32.  
  33.    ...
  34. </project>

Querying revision number of subversion

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project name="project.name"
  3.  basedir="." default="echo.env"
  4.  xmlns:artifact="antlib:org.apache.maven.artifact.ant"
  5.  xmlns:antelope="antlib:ise.antelope.tasks"
  6.  xmlns:antcontrib="antlib:net.sf.antcontrib">
  7.  
  8.   <property environment="env"/>
  9.  
  10.   <!-- Define Maven-Ant tasks -->
  11.   <!-- For more on Maven-Ant tasks, refer http://maven.apache.org/ant-tasks/ -->
  12.   <typedef resource="org/apache/maven/artifact/ant/antlib.xml"
  13.   uri="antlib:org.apache.maven.artifact.ant"
  14.   classpath="lib/maven-ant-tasks-2.1.3.jar">
  15.   </typedef>
  16.  
  17.   <artifact:dependencies pathId="ant-only.classpath">
  18.     <!-- SvnAnt tasks. For more, refer http://subclipse.tigris.org/svnant.html -->
  19.     <dependency groupId="org.tigris" artifactId="svnant" version="1.3.1" scope="system" systemPath="${basedir}/lib/svnant.jar"/>
  20.     <dependency groupId="org.tigris" artifactId="svn-client-adapter" version="0.9.102" scope="system" systemPath="${basedir}/lib/svnClientAdapter.jar"/>
  21.     <dependency groupId="org.tmatesoft.svnkit" artifactId="svnkit" version="1.7.11"/>
  22.     <dependency groupId="org.tmatesoft.svnkit" artifactId="svnkit-javahl16" version="1.7.11"/>
  23.     <remoteRepository id="centeral2" url="http://repo2.maven.org/maven2/"/>
  24.     <remoteRepository id="maven2-repository.dev.java.net" url="http://download.java.net/maven/2/"/>
  25.     <remoteRepository id="tmatesoft-releases" url="http://maven.tmatesoft.com/content/repositories/releases/"/>
  26.   </artifact:dependencies>
  27.  
  28.   <!-- Define SvnAnt tasks -->
  29.   <typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="ant-only.classpath"/>
  30.  
  31.   <target name="echo.env" depends="query.svn.revision">
  32.     <echo>Max revision under this project : ${revision.max}</echo>
  33.   </target>
  34.  
  35.   <target name="query.svn.revision">
  36.     <svnSetting id="svn.setting" svnkit="true" javahl="false"/>
  37.     <svn refid="svn.setting">
  38.       <wcversion path="${basedir}"/>
  39.     </svn>
  40.   </target>
  41.  
  42. </project>

Generating HTML documentation for XML schema using xs3p

  1.   <target name="generate.schemadoc.onem2m"
  2.          description="Generate XML schema documentation (Javadoc like) for oneM2M">
  3.     <antelope:if>
  4.       <bool>
  5.         <not>
  6.           <available file="${project.pom.build.directory}/xs3p/xs3p.xsl" />
  7.         </not>
  8.       </bool>
  9.       <mkdir dir="${project.pom.build.directory}/xs3p" />
  10.       <unzip src="${project.pom.basedir}/lib/xs3p-1.1.5.zip" dest="${project.pom.build.directory}/xs3p">
  11.         <patternset includes="*.xsd *.xsl *.dtd" />
  12.       </unzip>
  13.     </antelope:if>
  14.  
  15.     <mkdir dir="${project.pom.build.directory}/onem2m/schema-doc" />
  16.     <delete file="${project.pom.build.directory}/onem2m/schema-doc/links.xml" />
  17.  
  18.     <!-- create links.xml file first -->
  19.     <echo file="${project.pom.build.directory}/onem2m/schema-doc/links.xml"
  20.      append="false">&lt;?xml version="1.0"?&gt;</echo>
  21.     <echo file="${project.pom.build.directory}/onem2m/schema-doc/links.xml"
  22.      append="true">&lt;links xmlns="http://titanium.dstc.edu.au/xml/xs3p"&gt;
  23.     </echo>
  24.     <antcontrib:for param="xsd">
  25.       <path><fileset dir="${onem2m.schemas.basedir}" includes="*.xsd" /></path>
  26.       <sequential>
  27.         <antelope:grep in="@{xsd}" regex=".*(CDT-\w*-v1_0_0)\.xsd" group="1" property="name" dotall="true" />
  28.         <echoxml file="${project.pom.build.directory}/onem2m/schema-doc/links.xml" append="true">
  29.           <schema file-location="${name}.xsd" docfile-location="${name}.html" />
  30.         </echoxml>
  31.       </sequential>
  32.     </antcontrib:for>
  33.     <echo file="${project.pom.build.directory}/onem2m/schema-doc/links.xml"
  34.      append="true">&lt;/links&gt;</echo>
  35.  
  36.     <antcontrib:for param="xsd">
  37.       <path><fileset dir="${onem2m.schemas.basedir}" includes="*.xsd" /></path>
  38.       <sequential>
  39.         <antelope:grep in="@{xsd}" regex=".*(CDT-\w*-v1_0_0)\.xsd" group="1" property="name" dotall="true" />
  40.         <java classname="org.apache.xalan.xslt.Process"
  41.              fork="true"
  42.              dir="${project.pom.build.directory}/onem2m/schema-doc">
  43.           <classpath>
  44.             <pathelement location="${xalan:xalan:jar}" />
  45.           </classpath>
  46.           <arg value="-IN" />
  47.           <arg value="@{xsd}" />
  48.           <arg value="-XSL" />
  49.           <arg value="${project.pom.build.directory}/xs3p/xs3p.xsl" />
  50.           <arg value="-OUT" />
  51.           <arg value="${project.pom.build.directory}/onem2m/schema-doc/${name}.html" />
  52.           <arg value="-PARAM" />
  53.           <arg value="searchImportedSchemas" />
  54.           <arg value="true" />
  55.           <arg value="-PARAM" />
  56.           <arg value="searchIncludedSchemas" />
  57.           <arg value="true" />
  58.           <arg value="-PARAM" />
  59.           <arg value="linksFile" />
  60.           <arg value="${project.pom.build.directory}/onem2m/schema-doc/links.xml" />
  61.         </java>
  62.       </sequential>
  63.     </antcontrib:for>
  64.   </target>


Launch a executable via environment variable for the location

To assure location transparency, it is preferred to define the base location for an application as an environment variable. In this case, to launch the application the existence of it can be verified using <condition> task beforehand.

  1.    <target name="kafka-manager.start">
  2.       <fail message="Kafka Manager should be installed and environment varialbe of 'KAFKA_MANAGER_HOME' for it should be defined to run this target">
  3.          <condition>
  4.             <or>
  5.                <not><isset property="env.KAFKA_MANAGER_HOME"/></not>
  6.                <not><available file="${env.KAFKA_MANAGER_HOME}\bin\kafka_manager.bat"/></not>
  7.             </or>
  8.          </condition>
  9.       </fail>
  10.       <exec executable="cmd" dir="${env.KAFKA_MANAGER_HOME}">
  11.          <arg value="/c"/>
  12.          <arg value="bin\kafka_manager.bat"/>
  13.       </exec>
  14.    </target>