<project name="d2u" default="dist" basedir="."> <description> More than a DOS to UNIX conversion of line ends. </description> <property name="project.name" value="d2u" /> <!-- program version --> <property name="version" value="1.02" /> <!-- set global properties for this build --> <property name="build" location="."/> <!-- directory layout for this build: . +- src +- grammar +- classes +- dist +- javadoc the following properties reflect this hierarchy --> <!-- the src directory in this example --> <property name="src" location="src"/> <!-- name of the package --> <property name="package" value="org/myorg/${project.name}"/> <!-- where to write/find token files --> <property name="token.lib" location="${src}/${package}" /> <!-- where to find the grammar files in this example the grammar file is placed in a separat directory. Some people might prefer to locate it in the source directory. To do so, just change location="grammar" into location="${src}" if you like. --> <property name="grammar" location="grammar"/> <!-- where to write compiled sources --> <property name="classes" location="classes"/> <!-- distribution directory --> <property name="dist" location="dist" /> <!-- where to write java doc files --> <property name="doc" location="${dist}/javadoc"/> <!-- Inquire environment variables --> <property environment="envList"/> <!-- Get environment variable ANTLR_HOME --> <property name="antlrHome" value="${envList.ANTLR_HOME}"/> <!-- A convenience macro which invokes antlr Be aware that JVM arguments can be specified via the jvmarg directive --> <macrodef name="antlr3"> <attribute name="grammar.name"/> <attribute name="package" default="${package}"/> <attribute name="verbose" default="True"/> <attribute name="debug" default="False"/> <attribute name="multithreaded" default="True"/> <sequential> <echo message="antlr ${grammar}/@{grammar.name}" /> <antlr:ant-antlr3 xmlns:antlr="antlib:org/apache/tools/ant/antlr" target="${grammar}/@{grammar.name}" outputdirectory="${src}/@{package}" libdirectory="${src}/@{package}" multithreaded="@{multithreaded}" verbose="@{verbose}" debug="@{debug}"> <jvmarg value="-Xmx512M"/> </antlr:ant-antlr3> </sequential> </macrodef> <!-- Check if ANTLR_HOME environment variable is set --> <condition property="antlrHome.isset"> <isset property="envList.ANTLR_HOME"/> </condition> <target name="init" depends="antlr_home"> <!-- Create the time stamp --> <tstamp /> <!-- Create the build directory structure used by compile --> <mkdir dir="${grammar}" /> <mkdir dir="${src}/${package}" /> <mkdir dir="${classes}/${package}" /> <mkdir dir="${classes}/META-INF" /> <mkdir dir="${dist}" /> <mkdir dir="${doc}/${package}" /> </target> <target name="antlr_home"> <fail message="ANTLR_HOME environment variable not defined"> <condition> <not> <isset property="antlrHome.isset"/> </not> </condition> </fail> <whichresource property="antlr.jar.location" class="org.antlr.Tool" classpathref="antlr.path"/> <fail message="Antlr library not found via ANTLR_HOME='${antlrHome}'"> <condition> <not> <isset property="antlr.jar.location"/> </not> </condition> </fail> <echo>Anltr found via environment variable ANTLR_HOME: ${antlr.jar.location}</echo> </target> <!-- Use wildcards in pattern definition --> <!-- to be independent of antlr versions --> <patternset id="antlr.libs"> <include name="antlr-*.jar" /> </patternset> <!-- Looking for archives in ANTLR_HOME --> <path id="antlr.path"> <fileset dir="${antlrHome}" casesensitive="yes"> <patternset refid="antlr.libs" /> </fileset> </path> <!-- Antlr is called here --> <!-- The antlr3 macro is doing the work --> <target name="antlr" depends="init"> <antlr3 grammar.name="d2u.g"/> </target> <target name="compile" depends="init, antlr" description="compile"> <!-- Compile the java code from ${src} into ${classes} --> <javac debug="true" srcdir="${src}" destdir="${classes}" listfiles="Yes" deprecation="Yes"> <compilerarg value="-Xlint:unchecked"/> <classpath> <path refid="antlr.path"/> </classpath> </javac> </target> <target name="manifest"> <manifest file="${classes}/META-INF/MANIFEST.MF"> <attribute name="Main-Class" value="org.myorg.${project.name}.Main" /> </manifest> </target> <target name="dist" depends="compile, manifest" description="generate for distribution"> <jar jarfile="${dist}/${project.name}.jar" basedir="${classes}" manifest="${classes}/META-INF/MANIFEST.MF"/> </target> <target name="doc" depends="init" description="generate documentation"> <javadoc destdir="${doc}" author="true" version="true" use="true" windowtitle="${project.name}" sourcepath="${src}" Protected="All" Private="All" Public="All" linksource="yes" breakiterator="Yes"> <classpath> <path refid="antlr.path"/> </classpath> </javadoc> </target> <target name="run" depends="dist"> <echo message="Convert line ends from dos to mac format"/> <echo message="Input is read from d2u.stg. Output is written to tmp.ant"/> <java classname="org.myorg.${project.name}.Main" input="d2u.stg" output="tmp.ant" fork="true" failonerror="true" maxmemory="128m"> <arg value="mac"/> <classpath> <path refid="antlr.path"/> <pathelement path="${dist}/${project.name}.jar"/> </classpath> </java> </target> <target name="clean" description="clean up"> <delete> <fileset dir="${src}" includes="**/*.class,**/*.tokens,**/*.g*" /> <fileset dir="${classes}" /> <fileset dir="${dist}" includes="**/*.jar" /> <fileset dir="${doc}" /> </delete> </target> <target name="all" depends="init, clean, compile, dist, doc, run" description="do all"/> </project>