Home | Manual |
This page generated: 20120315-0623

The Jalopy task can take a few parameters to control the runtime behavior of Jalopy. If omitted, your current preferences settings will be used.

Nested FileSets can and should be used to specify the source files and/or directories.

Table 5.1. Jalopy Ant task parameters

AttributeDescriptionRequired
backupIndicates whether backup copies for all file sources should be kept.No
classpathrevThe classpath to setup the class repository with, given as a reference to a path defined elsewhere. If you want the import optimization feature to work, you have to specify the classpath reference you use to compile your sources here.No
conventionSets the location to the convention file to use - given either relative to the project's basedir or as an absolute local path or internet address. If omitted, the current settings are used, if available. Otherwise the Jalopy build-in defaults will be used.No
destdirSets the destination directory to create/copy all formatting output into. If the given directory does not exist, it will be created. If this attribute is ommitted, all input files will simply be overriden.No
encodingSets the encoding that controls how Jalopy interprets text files containing characters beyond the ASCII character set. Defaults to the platform default encoding.No
failonerrorIndicates whether a run should be held if errors occured. Defaults to "true".No
fileSpecifies a single source file to format.Yes, if no fileset is specified.
fileformatSets the file format of the output files. The file format controls what end of line character is used. Either one of "UNIX", "DOS", MAC", "DEFAULT" or "AUTO" can be used. Defaults to "AUTO" (case insensitive).No
forceIndicates whether the formatting of files should be forced, even if the file is up-to-date.No
historySpecifies the history policy to use. Either one of "COMMENT", "FILE" or "NONE" can be used. No
javadocIndicates whether Javadoc related messages should be printed.No
loglevelSpecifies the logging level for message output. Either one of "ERROR", "WARN", "INFO" or "DEBUG" can be used.No
styleDEPRECATED. See conventionNo
threadsSpecifies the number of processing threads to use. Integer between 1 - 8. No

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 be sure that the given classpathref does cover all types used in your sources (and this is an absolute necessity for the import optimization feature to work reliable).

Example 5.1. Example Ant build file

<?xml version="1.0" ?>
<project name="myProject" default="format" basedir="." >

  <property name="dir.jalopy" value="/mystuff/jalopy/bin" />
  <property name="dir.lib" value="${basedir}/ext/lib" />
  <property name="dir.compile" value="${basedir}/tmp~/build/classes" />
  <property name="dir.src.java" value="${basedir}/src/java" />

  <!-- ==================================================================== -->
  <!-- Defines the Jalopy task                                              -->
  <!-- ==================================================================== -->
  <taskdef name="jalopy"
           classname="de.hunsicker.jalopy.plugin.ant.AntPlugin">
    <!--

      we did not copy the needed .jars into the /lib directory of Ant in order
      to avoid possible classpath issues, so we have to specify a lookup
      classpath here

      -->
    <classpath>
      <fileset dir="${dir.jalopy}">
        <include name="*.jar" />
      </fileset>
    </classpath>
  </taskdef>


  <!-- ==================================================================== -->
  <!-- Defines the project classpath                                        -->
  <!-- ==================================================================== -->
  <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"
          depends="init">
    <javac destdir="${dir.compile}"
           fork="true">
      <classpath refid="project.classpath" />
      <src path="${dir.src.java}" />
    </javac>
  </target>


  <!-- ==================================================================== -->
  <!-- Formats all source files                                             -->
  <!-- ==================================================================== -->
  <target name="format" depends="compile">

    <!--

      Invokes Jalopy as follows:

      - All formatted files will have unix fileformat (\n)
      - Load your code convention from the given url
      - Override the convention to use the file history feature
      - Override the convention to use alder32 checksums of files for history testing
      - Override the convention to use loglevel "info"
      - Override the convention to use 2 threads
      - The import optimization feature will work (if enabled in the active
        convention), because a classpath reference is specified

        Don't forget to setup an include pattern as Jalopy truly expects
        valid Java source files as input!

      -->
    <jalopy fileformat="unix"
            convention="http://www.foo.com/myConvention.xml"
            history="file"
            historymethod="adler32"
            loglevel="info"
            threads="2"
            classpathref="project.classpath">
      <fileset dir="${dir.src.java}">
        <include name="**/*.java" />
      </fileset>
    </jalopy>
  </target>
</project>

to top