Source

syntactic / parser / build.xml

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

  <property name="javacc.home" value="/Users/tim/Development/Libraries/javacc/javacc-5.0/"/>

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

  <property name="java.parser.package" value="org/adjective/syntactic/parser" />

  <target name="all"   description="Builds parser + runs tests" depends="build, test, dist" />
  <target name="build" description="Builds parser" depends="grammar, compile " />

  <target name="grammar" depends="jjtree,javacc" />

  <target name="jjtree" >
    <mkdir dir="${output}/grammar" />
    <mkdir dir="${output.java}/${java.parser.package}/ast" />
    <jjtree 
        target="source/grammar/java.jjt"
        outputfile="../../../../../../grammar/Parser.jj"
        outputdirectory="${output.java}/${java.parser.package}/ast" 
        javacchome="${javacc.home}" />


    <replaceregexp 
      file="${output.java}/${java.parser.package}/ast/JavaParserVisitor.java"  
      match="JavaParserVisitor$" 
      flags="m"
      replace="JavaParserVisitor&lt;R,T&gt;" />

    <replace file="${output.java}/${java.parser.package}/ast/Node.java" >
      <replacefilter token="JavaParserVisitor " value="JavaParserVisitor&lt;R,T&gt; " />
      <replacefilter token="public R jjtAccept" value="public &lt;R,T&gt; R jjtAccept" />
    </replace>

  </target>

  <target name="javacc" >
    <mkdir dir="${output.java}/${java.parser.package}/jj" />
    <uptodate 
      property="javacc.uptodate" 
      srcfile="${output.grammar}/Parser.jj"
      targetfile="${output.java}/${java.parser.package}/jj/JavaParser.java"
    />
    <antcall target="javacc.internal" />
  </target>

  <target name="javacc.internal" unless="javacc.uptodate">
    <javacc
        target="${output.grammar}/Parser.jj" 
        outputdirectory="${output.java}/${java.parser.package}/jj" 
        javacchome="${javacc.home}" />
  </target>

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

  <path id="path.compile.parser" />

  <path id="path.compile.test" >
     <pathelement location="${output.classes.parser}" />
     <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.parser, compile.test" />

  <target name="compile.parser" >
    <compile out="${output.classes.parser}" classpath="path.compile.parser" >
      <source>
        <src path="${output.java}" /> 
        <src path="source/java/parser" /> 
      </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>

  <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.parser}" />
        <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="grammar,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.parser}" />
    </jar>
  </target>

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

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

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

</project>