#238 basedir problem with Ant task

release_3.1
closed
nobody
None
5
2012-10-10
2003-07-02
Leif Mortenson
No

I am using Checkstyle with the Ant task and have
declared the basedir in my checkstyle_checks.xml file.
The problem I am having is that the ant task always
using fully qualified paths to the files. This results
in the fully qualified path being shown in the
checkstyle reports. I would like to be able strip this
off with the basedir setting. Would it be possible to
make sure that the fully qualified base directories are
also stripped off in the event that a relative path
such as "src/java" is specified as the basedir, but the
file path is fully qualified?
It is not possible to hard code the fully qualified
path into the
checkstyle_checks.xml file because it needs to run on
various machines and OSs.

I attempted to set something up by doing a token
replacement into the checkstyle_checks.xml file. But I
was running into problems due to checkstyle not
correctly the forward or backwards slashes.

In ant, I define java.dir as ${basedir}/src/java The
problem is
that this resolves to C:\MySrc\App/src/java on windows
machines and checkstyle will not recognize that this is
the same basedir as C:\MySrc\App\src\java

Thanks in advance. Love your great product.
Cheers,
Leif

Discussion

  • Logged In: YES
    user_id=746148

    TThe follows works for me
    <property key="checkstyle.basedir"
    file="${basedir}/src/checkstyle/com/puppycrawl/tools/checkst
    yle"/>

     
  • Leif Mortenson
    Leif Mortenson
    2003-07-03

    Logged In: YES
    user_id=228081

    Thanks, it took me a while and lots of digging through code
    to figure out what you were talking about. I had not
    realized that it was possible to do ant style replacements
    within the checkstyle_checks.xml file. Must have missed
    that in the docs someplace. Thanks for the help though. :-)

    In case someone else runs into the same problem:
    Set the property in the in the ant task:
    <taskdef name="checkstyle"
    classname="com.puppycrawl.tools.checkstyle.CheckStyleTask">
    <classpath refid="project.class.path"/>
    </taskdef>
    <checkstyle config="${src.dir}/checkstyle_checks.xml"
    failOnViolation="false">
    <property key="checkstyle.basedir" file="${java.dir}"/>
    <property key="basedir" file="${java.dir}"/>
    <fileset dir="${java.dir}">
    <include name="*/.java"/>
    </fileset>
    <formatter type="plain"/>
    <formatter type="xml"
    toFile="${build.dir}/checkstyle/checkstyle-results.xml"/>
    </checkstyle>

    Then in the checkstyle_checks.xml file, set the basedir
    using the property specified above:
    <module name="Checker">
    <property name="basedir" value="${checkstyle.basedir}"/>
    <property name="localeCountry" value="US"/>
    <property name="localeLanguage" value="en"/>

    Cheers,
    Leif

     
  • Lars Kühne
    Lars Kühne
    2003-07-03

    Logged In: YES
    user_id=401384

    Leif's problem is solved, closing