Source

syntactic / convert / build.xml

<!-- vim: set ft=ant ts=2 sts=2 expandtab shiftwidth=2  : -->
<project name="syntactic-convert"  default="all" basedir="."  xmlns:ivy="antlib:org.apache.ivy.ant" >

  <property name="output"                location="output/ant"         />
  <property name="output.classes"        location="output/ant/classes" />
  <property name="output.classes.main"   location="${output.classes}/main" />
  <property name="output.classes.test"   location="${output.classes}/test" />
  <property name="output.junit"          location="output/ant/junit"   />
  <property name="output.dist"           location="output/ant/dist"   />

  <target name="all"   description="Compile code, run tests &amp; build jar file" depends="build, test, dist" />
  <target name="build" description="Compile code" depends="compile " />

 
  <!-- ******************
        Java Compilation 
       ****************** -->

  <path id="path.compile.main" >
     <pathelement location="../parser/output/ant/classes/parser" />
     <fileset dir="../lib/core/" >
        <include name="args4j-*.jar" />
     </fileset>
  </path>

  <path id="path.compile.test" >
     <pathelement location="${output.classes.main}" />
     <path refid="path.compile.main" />
     <fileset dir="../lib/test/" />
  </path>
 
  <macrodef name="compile">
    <element name="source" />
    <attribute name="out" />
    <attribute name="classpath" />
    <sequential>
      <mkdir dir="@{out}" />
      <javac 
          deprecation="false" 
          debug="true" 
          destdir="@{out}">

          <source />
          <classpath refid="@{classpath}" />
      </javac>
    </sequential>
  </macrodef>

  <target name="compile" depends="compile.main, compile.test" />

  <target name="compile.main" >
    <compile out="${output.classes.main}" classpath="path.compile.main" >
      <source>
        <src path="source/java/main" /> 
      </source>
    </compile>
  </target>

  <target name="compile.test" >
    <compile out="${output.classes.test}" classpath="path.compile.test" >
      <source>
        <src path="source/java/test" /> 
      </source>
    </compile>
  </target>

  <!-- ************
        Unit Tests 
       ************ -->

  <target name="test">
    <mkdir dir="${output.junit}" />
    <junit fork="yes" forkmode="once"  dir="${basedir}" haltonerror="false" failureproperty="junit.failure" errorproperty="junit.error" >
      <classpath>
        <pathelement location="${output.classes.main}" />
        <path refid="path.compile.main" />
        <pathelement location="${output.classes.test}" />
        <fileset dir="../lib/test" />
      </classpath>
      <batchtest todir="${output.junit}">
        <fileset dir="source/java/test">
          <include name="**/*Test.java"/>
        </fileset>
      </batchtest>
      <formatter type="xml" />
      <formatter type="plain" />
    </junit>
    <fail if="junit.failure" />
    <fail if="junit.error" />
  </target>

  <target name="dist.jar" depends="compile">
    <tstamp prefix="tstamp" >
      <format property="date" pattern="yyyy-MM-dd" locale="en,AU"/>
      <format property="time" pattern="HH:mm"      locale="en,AU"/>
    </tstamp>
    <exec executable="hg" outputproperty="hg.version" >
      <arg value="id" />
      <arg value="-i" />
    </exec>
    <mkdir dir="${output.dist}" />
    <jar destfile="${output.dist}/${ant.project.name}.jar">
      <manifest>
        <attribute name="Implementation-Revision" value="${hg.version}"/>
        <attribute name="Built-Date"              value="${tstamp.date} ${tstamp.time}"/>
      </manifest>
      <fileset dir="${output.classes.main}" />
    </jar>
  </target>

  <target name="dist.source" >
    <zip destfile="${output.dist}/${ant.project.name}-source.zip">
      <fileset dir="." includes="source/java/**" />
    </zip>
  </target>

  <target name="dist" depends="dist.jar, dist.source" />

  <target name="clean">
    <delete dir="${output}" />
  </target>

</project>