0

I am using PMD source code analyzer (PMD) for my java web project through ant task. The computer is offline (not connected to the Internet). Part of ant task is as follows:

<target name="pmd">

  <taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask">
    <classpath>
      <fileset dir="E:/pmd-bin-6.41.0/lib">
        <include name="*.jar"/>
      </fileset>
    </classpath>
  </taskdef>

  <pmd shortfilenames="true" cachelocation="pmd.cache" encoding="UTF-8">

    <ruleset>web/resources/category/java/bestpractices.xml</ruleset>

    <formatter type="html" tofile="report.html">
    </formatter>

    <fileset dir="src/java/">
      <include name="**/*.java"/>
    </fileset>
  </pmd>
</target>

When I run pmd target, report.html file is generated ok. The html file basically lists <fileName, lineNumber, description> triplets.

e.g.

foo.java...43...The initializer for variable "tempIDNo" is never used (overwritten on lin 67)

The description in this html file has a link as file:///E:ws/project/${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#unusedassignment which does not work. E:ws/project/ is the folder where my project resides.

As a matter of fact, I have all the necessary html files (such as pmd_rules_java_bestpractices.html) unzipped in E:/pmd-doc-6.41.0 folder.

Could you please help me how to set up description link in html file to show local folder?

Thank you.

sen.a
  • 1

1 Answers1

0

Here is the solution I have come up with:

  1. (Using suggestion from (How can I create a link to a local file on a locally-run web page?)) Before ant pmd target define property pmd.website.baseurl
    <propery name="pmd.website.baseurl" value="file:///E:/pmd-doc-6.41.0"/>
  1. (Using usage/suggestion from (https://ant.apache.org/manual/Types/filterchain.html#expandproperties), ANT replacing strings in specified files using file with properties ) Change inside target as follows
...
<pmd ...>...
</pmd>
<copy file="report.html" tofile="report2.html">
  <filterchain>
    <filterreader classname="org.apache.tools.ant.filters.ExpandProperties"/>
  </filterchain>
</copy> ...
  1. Run the ant target.
sen.a
  • 1