<project name="checkstyle" default="checkstyle.checkstyle" basedir=".">

  <!-- set global properties for this build -->
  <property name="target.dir" value="${basedir}/target" />
  <property name="version" value="5.4-SNAPSHOT" />
  <property name="checkstyle.dir"
            value="src/checkstyle/com/puppycrawl/tools/checkstyle" />

  <!-- override using -Dgui.target= if you wish to load a source file from startup -->
  <property name="gui.target" value=""/>

  <path id="run.classpath">
    <pathelement location="${target.dir}/checkstyle-${version}-all.jar"/>
  </path>

  <target name="checkstyle.checkstyle"
          description="Runs checkstyle against it's own sources">
    <taskdef name="checkstyle"
             classname="com.puppycrawl.tools.checkstyle.CheckStyleTask">
      <classpath refid="run.classpath"/>
    </taskdef>
    <delete file="${target.dir}/cachefile" />

    <property name="checkstyle.pattern.todo" value="NOTHingWillMatCH_-"/>
    <property name="check.config" location="checkstyle_checks.xml"/>
    <property name="translation.severity" value="ignore"/>
    <checkstyle config="${check.config}"
                failOnViolation="false"
                failureProperty="checkstyle.failure.property"
                >
      <fileset dir="src"
               includes="checkstyle/**/*.java,checkstyle/**/*.properties,xdocs/**/*.xml,tests/**/*Test.java"
               excludes="**/Generated*.java,**/gui/*"/>
      <formatter type="plain"/>
      <formatter type="xml" toFile="${target.dir}/cs_errors.xml"/>
      <classpath refid="run.classpath"/>
      <property key="checkstyle.cache.file" file="${target.dir}/cachefile"/>
      <property key="checkstyle.header.file" file="java.header"/>
      <property key="checkstyle.importcontrol.file" file="import-control.xml"/>
      <property key="checkstyle.suppressions.file"
                file="suppressions.xml"/>
    </checkstyle>

    <fail if="checkstyle.failure.property"
          message="Checkstyle failed: ${checkstyle.failure.property}"
          />
  </target>

  <!-- Run the GUI -->
  <target name="run.gui"
          description="Run the GUI for displaying a tree">
    <java classname="com.puppycrawl.tools.checkstyle.gui.Main"
          fork="yes" classpathref="run.classpath">
          <arg line="${gui.target}"/>
    </java>
  </target>

  <target name="validate.xml"
          description="Validates checkstyle XML file">
    <xmlvalidate file="checkstyle_checks.xml">
      <xmlcatalog>
        <dtd
          publicId="-//Puppy Crawl//DTD Check Configuration 1.1//EN"
          location="${checkstyle.dir}/configuration_1_1.dtd"/>
      </xmlcatalog>
    </xmlvalidate>
  </target>

  <target name="checkstyle.sun_checks"
          description="Runs checkstyle using sun_checks.xml">
    <taskdef name="checkstyle"
             classname="com.puppycrawl.tools.checkstyle.CheckStyleTask">
      <classpath refid="run.classpath"/>
    </taskdef>

    <property name="check.config" location="sun_checks.xml"/>
    <checkstyle config="${check.config}"
                failOnViolation="true"
                >
      <fileset dir="src/checkstyle"
               includes="**/*.java,**/*.properties"
               excludes="**/Generated*.java,**/gui/*"/>
      <formatter type="plain"/>
      <classpath refid="run.classpath"/>
    </checkstyle>
  </target>

  <target name="checkstyle.style"
          description="Runs checkstyle against it's own sources to test generation of error reports">
    <taskdef name="checkstyle"
             classname="com.puppycrawl.tools.checkstyle.CheckStyleTask">
      <classpath refid="run.classpath"/>
    </taskdef>
    <delete file="${target.dir}/cachefile" />

    <property name="checkstyle.pattern.todo" value="NOTHingWillMatCH_-"/>
    <property name="check.config" location="checkstyle_checks.xml"/>
    <property name="translation.severity" value="ignore"/>
    <checkstyle failonviolation="false" config="${check.config}">
      <fileset dir="src/checkstyle"
               includes="**/*.java,**/*.properties"
               excludes="**/Generated*.java,**/gui/*"/>
      <formatter type="xml" toFile="${target.dir}/cs_errors.xml"/>
      <classpath refid="run.classpath"/>
      <property key="checkstyle.cache.file" file="${target.dir}/cachefile"/>
      <property key="checkstyle.header.file" file="java.header"/>
      <property key="checkstyle.importcontrol.file" file="import-control.xml"/>
      <property key="checkstyle.suppressions.file"
                file="suppressions.xml"/>
    </checkstyle>
    <mkdir dir="${target.dir}/style/frames"/>
    <mkdir dir="${target.dir}/style/noframes"/>
    <mkdir dir="${target.dir}/style/noframes-sorted"/>
    <mkdir dir="${target.dir}/style/simple"/>
    <mkdir dir="${target.dir}/style/csv"/>
    <mkdir dir="target/style/author"/>
    <style basedir="${target.dir}"
           destdir="${target.dir}/style/noframes"
           includes="cs_errors.xml"
           style="contrib/checkstyle-noframes.xsl"/>
    <style basedir="${target.dir}"
           destdir="${target.dir}/style/noframes-sorted"
           includes="cs_errors.xml"
           style="contrib/checkstyle-noframes-sorted.xsl"/>
    <style basedir="${target.dir}"
           destdir="${target.dir}/style/frames"
           includes="cs_errors.xml"
           style="contrib/checkstyle-frames.xsl"/>
    <style basedir="${target.dir}"
           destdir="${target.dir}/style/simple"
           includes="cs_errors.xml"
           style="contrib/checkstyle-simple.xsl"/>
    <style out="${target.dir}/style/csv/report-csv.txt"
           in="${target.dir}/cs_errors.xml"
           style="contrib/checkstyle-csv.xsl"/>
    <style basedir="target"
           destdir="target/style/author"
           includes="cs_errors.xml"
           style="contrib/checkstyle-author.xsl"/>
  </target>

  <?ignore
  <!-- A GRAVEYARD OF IDEAS BELOW -->

  <!-- runs the command line version on a file -->
  <target name="run.checkstyle"
          description="Runs the command line version on a file">
    <java classname="com.puppycrawl.tools.checkstyle.Main"
          fork="yes"
          dir="."
          classpathref="run.classpath">
      <sysproperty key="checkstyle.allow.tabs" value="yes"/>
      <arg value="-c"/>
      <arg file="checkstyle_checks.xml"/>
      <arg value="src/testinputs/com/puppycrawl/tools/checkstyle/InputSimple.java"/>
    </java>
    <java classname="com.puppycrawl.tools.checkstyle.Main"
          fork="yes"
          dir="."
          classpathref="run.classpath">
      <arg value="-c"/>
      <arg file="checkstyle_checks.xml"/>
      <arg value="-r"/>
      <arg file="src/checkstyle/com/puppycrawl/tools/checkstyle/api"/>
    </java>
  </target>

  <target name="checkstyle.run" depends="compile.checkstyle"
          description="Runs checkstyle.">
    <taskdef name="checkstyle"
             classname="com.puppycrawl.tools.checkstyle.CheckStyleTask">
      <classpath refid="run.classpath"/>
    </taskdef>
    <delete file="${target.dir}/cachefile" />

    <property name="checkstyle.pattern.todo" value="NOTHingWillMatCH_-"/>
    <property name="check.config" location="checkstyle_checks.xml"/>
    <property name="translation.severity" value="ignore"/>
    <checkstyle config="${custom.config}" file="${file.to.check}">
      <formatter type="plain"/>
      <formatter type="xml" toFile="${target.dir}/cs_errors.xml"/>
      <classpath refid="run.classpath"/>
    </checkstyle>
  </target>
  ?>
</project>
