You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Schwartz, Ran" <ra...@hp.com> on 2008/08/26 00:06:41 UTC

Checkstyle

Has anyone configured checkstyle to get to work through Ant or their command line? I am having issues with it. Even the most basic of examples would be of help.

Thanks,
Ran

AW: Checkstyle

Posted by Ja...@rzf.fin-nrw.de.
Here a snippet from our build.
We have three sourcefolders (src/main, src/test, src/junit), so I'll iterate over src/* later.


Line 2: Use Ants AntLib capability to load the checkstyle tasks. For that they must be on Ants classpath. E.g. in ANT_HOME/lib, or added by "-lib" option (or via an Ivy dependency).

Line 4: Create a property "skip.checkstyle" if the flagfile is newer than all sources and the cs-config file. This is a top level Ant task so it will be executed on each build and before all targets.

Line 11: The CS-Target. It will be skipped if the property skip.checkstyle is set (to some value) which means "no CS-Config-Change and no newer sources" which means: "work already done".

Line 12: Standard Ant behaviour: create the target directory.

Line 13: Create the flag file for comparison in Line 4. This makes the build faster.

Line 14+15: Ok, here I iterate over the three sourcefolders and just get the directory name (c:/bla/bla/myproject/src/main --> main).

Line 24: Start of Checkstyle. Some properties are loaded from props-file.

Line 28: I change the taskname for better logging: display the name of the sourcefolder, like
  [mkdir]   bla bla
  [cs:main] bla bla

Line 30: Use the XML-Formatter of CS, so I can generate real reports later.

Line 31: Which files should be scanned - just my java sources?

Line 34-47: HTML-Generation. I use the XSL of Ant 1.7.1 (on that time not released, but now :-) and tweak a little bit with the paths.

Line 50-53: Little "hacking": unset all properties needed in the loop.



Jan



:0000: <?xml version="1.0" encoding="ISO-8859-1"?>
:0001: <project
:0002:   xmlns:cs="antlib:com.puppycrawl.tools.checkstyle"
:0003: >
:0004:     <!-- Skip Checkstyle if sources and config are older than last run -->
:0005:     <uptodate property="skip.checkstyle" targetfile="${checkstyle.dir}/flag.txt">
:0006:         <srcfiles dir="${java.src}" includes="**/*.java"/>
:0007:         <srcfiles dir="${junit.src}" includes="**/*.java"/>
:0008:         <srcfiles file="${checkstyle.config}"/>
:0009:     </uptodate>
:0010:     
:0011:     <target name="checkstyle" unless="skip.checkstyle">
:0012:         <mkdir dir="${checkstyle.dir}"/>
:0013:         <echo file="${checkstyle.dir}/flag.txt" message="Checkstyle-Flagfile. CS-Run ${tstamp.datum} ${tstamp.zeit}"/>
:0014:         <ac:for param="dir">
:0015:             <dirset dir="src" includes="*"/>
:0016:             <sequential>
:0017:                 <basename property="dir"  file="@{dir}"/>
:0018:                 <property name="todir"    value="${checkstyle.dir}/${dir}"/>
:0019:                 <property name="taskname" value="cs::${dir}"/>
:0020: 
:0021:                 <mkdir dir="${todir}" taskname="${taskname}"/>
:0022:                 <!-- Starte Checkstyle mit Ausgabe als XML -->
:0023:                 <cs:checkstyle
:0024:                   config="${checkstyle.config}"
:0025:                   failOnViolation="${checkstyle.failOnViolation}"
:0026:                   packageNamesFile="${checkstyle.packagesnames}"
:0027:                   taskname="${taskname}"
:0028:                 >
:0029:                     <formatter type="xml" toFile="${todir}/raw.xml"/>
:0030:                     <fileset dir="@{dir}" includes="**/*.java"/>
:0031:                 </cs:checkstyle>
:0032:                 <!-- Das XSL löscht 'basedir' aus dem Namen. Location expandiert zum absoluten Pfad -->
:0033:                 <property name="checkstyle.basedir" location="@{dir}"/>
:0034:                 <!-- HTML-Erzeugung -->
:0035:                 <!--
:0036:                    Genutzt wird das XSL aus Ant 1.7.1 (noch nicht released) wegen der Pfad-Probleme
:0037:                    auf Windows-Rechnern.
:0038:                 -->
:0039:                 <xslt in="${todir}/raw.xml"
:0040:                       out="${todir}/output.txt"
:0041:                       style="${checkstyle.xsl}"
:0042:                       taskname="${taskname}"
:0043:                 >
:0044:                     <param name="basedir" expression="${checkstyle.basedir}${file.separator}"/>
:0045:                     <param name="title" expression="${dir}"/>
:0046:                 </xslt>
:0047: 
:0048:                 <!-- Lösche die Variablen für den nächsten Schleifendurchlauf -->
:0049:                 <ac:var name="dir" unset="true"/>
:0050:                 <ac:var name="todir" unset="true"/>
:0051:                 <ac:var name="taskname" unset="true"/>
:0052:                 <ac:var name="checkstyle.basedir" unset="true"/>
:0053:             </sequential>
:0054:         </ac:for>
:0055:     </target>
:0056: 
:0057: </project> 

> -----Ursprüngliche Nachricht-----
> Von: Schwartz, Ran [mailto:ran.schwartz@hp.com] 
> Gesendet: Dienstag, 26. August 2008 00:07
> An: Ant Users List
> Betreff: Checkstyle
> 
> Has anyone configured checkstyle to get to work through Ant 
> or their command line? I am having issues with it. Even the 
> most basic of examples would be of help.
> 
> Thanks,
> Ran
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org