Showing posts with label ant. Show all posts
Showing posts with label ant. Show all posts

Thursday, 7 October 2010

Ant conditional on OS + Ant calling maven

How to get the OS dependent command so we can lauch scripts.

(windows needs to launch its scripts with a /c as the first parameter

  <condition property="command" value="cmd">
    <os family="windows" />
  </condition>
  <condition property="command" value="sh">
    <os family="unix" />
  </condition>
  <condition property="commandParam" value="/c">
    <os family="windows" />
  </condition>
  <condition property="commandParam" value="">
    <os family="unix" />
  </condition>


Now you can run a maven file like this


  <exec executable="${command}">
   <arg value="mvn" />
   <arg value="${commandParam}" />
   <arg value="-f../integration/pom.xml" />
  </exec>

Friday, 1 October 2010

Ant Conditional Property

Defining a new Ant task with a conditional property:

This is a way of doing 'ifs' with Ant.


<macrodef name="copy-and-filter">
    <attribute name="sys"/>
    <attribute name="target"/>
    <attribute name="source"/>
    <sequential>
      <condition property="myProp" value="JUST1">
        <equals arg1="@{sys}" arg2="MySystem"/>
      </condition>
      <condition property="myProp" value="NOT1">
        <equals arg1="@{sys}" arg2="SomeOtherSystem"/>
      </condition>
      <copy tofile="@{target}" file="@{source}">
        <filterset onmissingfiltersfile="ignore" recurse="true">
          <filter token="replaceThis" value="${myProp}"/>
          <filtersfile file="myfilters/filterFile@{sys}.properties"/>
        </filterset>
      </copy>
    </sequential>
  </macrodef>


The conditional property myProp will be set depending on the values of the @sys@ attribute passed in.

All filters in the file: filtersFile@sys@ so you can specify a different file for each sys property.

Wednesday, 25 August 2010

SCPing multiple files with Ant

Firstly SCP and SSH aren't included with Ant by default. We need to get the jsch.jar and include it

Please remember that wildcards dont work in Ant. We should use a fileset instead:

Example Ant code:

<scp todir="user:password@somehost:/home/somewhere">
  <fileset dir="src_dir">
    <include name="**/*.java"/>
  </fileset>
</scp>


... and finally a lovely list of Ant Tasks

Thursday, 20 August 2009

A sample ant build file


<project name="experiment" default="full-build">
    
    <property name="junit.dir" location=""/>
    <property name="src.dir" value="src" />
    <property name="lib.dir" value="lib"/>
    <property name="build.dir" location="build"/>
    
    <property name="build.test.classes.dir" location="${build.dir}/test/classes"/>
    <property name="build.test.output.dir" location="${build.dir}/test/output"/>
    <property name="src.unit-test.dir" location="test.src"/>
    
    <path id="build-classpath">
        <fileset dir="${lib.dir}" includes="*.jar" />
    </path>
    
    <path id="test-classpath">
        <fileset dir="${lib.dir}" includes="*.jar" />
        <path location="${build.dir}"/>
        <path location="${build.test.classes.dir}"/>
    </path>
    
    <target name="full-build" depends="clean, init, compile-main, test" />
    
    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>
    
    <target name="init">
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${build.test.classes.dir}"/>
        <mkdir dir="${build.test.output.dir}"/>
    </target>
    
    <target name="compile-main" depends="init">
        <javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="build-classpath" />
    
    <mkdir dir="${project.build.outputDirectory}/..datastore" />
    <copy todir="${project.build.outputDirectory}/../config">
        <fileset dir="config" />
    </copy>
</target>
    
    <target name="test" depends="compile-test">
        <junit printsummary="yes" failureproperty="test.fail" fork="true"  haltonfailure="yes" dir="${junit.dir}">
            <classpath refid="test-classpath"/>
            <formatter type="xml"/>
            <batchtest fork="yes" todir="${build.test.output.dir}">
                <fileset dir="${src.unit-test.dir}">
                    <include name="**/*Test.java"/>
                </fileset>
            </batchtest>
        </junit>
    </target>
    
    <target name="compile-test" depends="compile-main">
        <javac srcdir="${src.unit-test.dir}" destdir="${build.test.classes.dir}" classpathref="test-classpath" />
    </target>

</project>