The following example demonstrates how you can make use of the Jalopy Ant task.
Note that the format target depends on the compile
target. This way we can make sure that the provided class path covers the complete type
information.
Example 4.11. Example Ant build file
<?xml version="1.0" ?> <project name="myProject" default="format" basedir="."> <property name="dir.compile" value="${basedir}/build/classes" /> <property name="dir.lib" value="${basedir}/lib" /> <property name="dir.src.java" value="${basedir}/src/main/java" /> <!-- ==================================================================== --> <!-- Defines the project class path --> <!-- ==================================================================== --> <path id="project.classpath" > <!-- our compilation directory --> <pathelement location="${dir.compile}" /> <!-- needed 3rd party libraries --> <fileset dir="${dir.lib}" > <include name="**/*.jar" /> </fileset> </path> <!-- ==================================================================== --> <!-- Compiles the project sources --> <!-- ==================================================================== --> <target name="compile"> <javac destdir="${dir.compile}" classpathref="project.classpath"> <src path="${dir.src.java}" /> </javac> </target> <!-- ==================================================================== --> <!-- Formats the project source --> <!-- ==================================================================== --> <target name="format" depends="compile"> <!-- Load the task using explicit class path. Please note that it’s sufficient to reference the Jalopy Ant library JAR if the core engine JAR sits in the same directory (which should be the norm) --> <typedef resource="com/triemax/antlib.xml" classpath="${basedir}/../deps/jalopy-ant-1.9.3.jar" /> <!-- Invokes Jalopy as follows: - load the code convention from the given url - the import optimization feature will work (if enabled in the code convention), because a class path reference is given - all formatted files will have unix file format (\n) - override the convention to use alder32 checksums of files as history policy - override the convention to use loglevel 'info' - the task will use 4 worker threads - the user environment variable 'author' is set and the value 'John Doo' assigned Since Jalopy 1.3 an include pattern is no longer necessary if you want to format all supported source files of a directory structure --> <jalopy convention="http://shared-server/cisco-omg.xml" classpathref="project.classpath" fileformat="unix" history="adler32" loglevel="info" threads="4"> <variable name="author" value="John Doo" /> <fileset dir="${dir.src.java}"> <include name="**/*.java" /> </fileset> </jalopy> </target> </project>