Author: aheritier Date: Thu Feb 2 07:26:46 2006 New Revision: 374409 URL: http://svn.apache.org/viewcvs?rev=374409&view=rev Log: Use properties maven.jxr.destdir and maven.jxr.destdir.test to generate links from the PMD report to jxr files. Fix NullPointerException if pom.build.sourceDirectory or pom.build.unitTestSourceDirectory are not defined.
Modified: maven/maven-1/plugins/trunk/pmd/src/plugin-resources/pmd.jsl maven/maven-1/plugins/trunk/pmd/xdocs/changes.xml Modified: maven/maven-1/plugins/trunk/pmd/src/plugin-resources/pmd.jsl URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/pmd/src/plugin-resources/pmd.jsl?rev=374409&r1=374408&r2=374409&view=diff ============================================================================== --- maven/maven-1/plugins/trunk/pmd/src/plugin-resources/pmd.jsl (original) +++ maven/maven-1/plugins/trunk/pmd/src/plugin-resources/pmd.jsl Thu Feb 2 07:26:46 2006 @@ -1,5 +1,4 @@ <?xml version="1.0"?> - <!-- * ======================================================================== * @@ -19,38 +18,35 @@ * * ======================================================================== --> - -<jsl:stylesheet - select="$doc" - xmlns:j="jelly:core" - xmlns:jsl="jelly:jsl" - xmlns:util="jelly:util" - xmlns:x="jelly:xml" - xmlns:doc="doc" - xmlns="dummy" trim="false"> - +<jsl:stylesheet + select="$doc" + xmlns:j="jelly:core" + xmlns:jsl="jelly:jsl" + xmlns:util="jelly:util" + xmlns:x="jelly:xml" + xmlns:doc="doc" + xmlns:maven="jelly:maven" + xmlns="dummy" + trim="false"> <!-- This needs to be instantiated here to be available in the template matches --> <j:useBean var="mavenTool" class="org.apache.maven.util.MavenTool"/> <j:useBean var="htmlescape" class="org.apache.velocity.anakia.Escape"/> <j:useBean var="fileutil" class="org.apache.velocity.texen.util.FileUtil"/> <j:useBean var="pathtool" class="org.apache.maven.util.DVSLPathTool"/> - + <!-- Make sure the jxr plugin is loaded --> + <maven:set plugin="maven-jxr-plugin" property="foo" value="bar"/> <jsl:template match="pmd"> <document> - <properties> <title>PMD Results</title> </properties> - <body> <section name="PMD Results"> <p> The following document contains the results of - <a - href="http://pmd.sourceforge.net/">PMD</a>. + <a href="http://pmd.sourceforge.net/">PMD</a>. </p> </section> - <section name="Summary"> <j:set var="fileCount"><x:expr select="count(file)"/></j:set> <j:set var="errorCount"><x:expr select="count(file/violation)"/></j:set> @@ -60,71 +56,127 @@ <th>Errors</th> </tr> <tr> - <td><doc:formatAsNumber string="${fileCount}" pattern="0"/></td> - <td><doc:formatAsNumber string="${errorCount}" pattern="0"/></td> + <td> + <doc:formatAsNumber string="${fileCount}" pattern="0"/> + </td> + <td> + <doc:formatAsNumber string="${errorCount}" pattern="0"/> + </td> </tr> </table> </section> - <section name="Files"> <table> <tr> <th>Files</th> <th>Violations</th> </tr> - <j:set var="fullSrcDir" value="${pom.build.sourceDirectory}"/> - <j:set var="srcDir" value="${fileutil.file(fullSrcDir).getCanonicalPath()}"/> - <j:set var="srcDirLength" value="${srcDir.length() + 1}"/> - <j:set var="fullTstDir" value="${pom.build.unitTestSourceDirectory}"/> - <j:set var="tstDir" value="${fileutil.file(fullTstDir).getCanonicalPath()}"/> - <j:set var="tstDirLength" value="${tstDir.length() + 1}"/> + <j:if test="${pom.build.sourceDirectory != null}"> + <j:set var="fullSrcDir" value="${pom.build.sourceDirectory}"/> + <j:set var="srcDir" value="${fileutil.file(fullSrcDir).getCanonicalPath()}"/> + <j:set var="srcDirLength" value="${srcDir.length() + 1}"/> + </j:if> + <j:if test="${pom.build.unitTestSourceDirectory != null}"> + <j:set var="fullTstDir" value="${pom.build.unitTestSourceDirectory}"/> + <j:set var="tstDir" value="${fileutil.file(fullTstDir).getCanonicalPath()}"/> + <j:set var="tstDirLength" value="${tstDir.length() + 1}"/> + </j:if> <x:set var="files" select="file"/> <!-- x:forEach is busted --> <j:forEach var="file" items="${files}"> <!-- Type coercion doesn't work worth a fuck in jexl. --> <j:set var="name" value="${file.attribute('name').getValue()}"/> - <j:set var="srcRelPathLen" value="${pathtool.getRelativePath(srcDir,name).length()}"/> - <j:set var="tstRelPathLen" value="${pathtool.getRelativePath(tstDir,name).length()}"/> - <j:if test="${srcRelPathLen > 0}"> - <j:set var="name" value="${name.substring(mavenTool.toInteger(srcDirLength.toString()))}"/> + <j:if test="${pom.build.sourceDirectory != null}"> + <j:set var="srcRelPathLen" value="${pathtool.getRelativePath(srcDir,name).length()}"/> + <j:if test="${srcRelPathLen > 0}"> + <j:set var="name" value="${name.substring(mavenTool.toInteger(srcDirLength.toString()))}"/> + </j:if> </j:if> - <j:if test="${tstRelPathLen > 0}"> - <j:set var="name" value="${name.substring(mavenTool.toInteger(tstDirLength.toString()))}"/> + <j:if test="${pom.build.unitTestSourceDirectory != null}"> + <j:set var="tstRelPathLen" value="${pathtool.getRelativePath(tstDir,name).length()}"/> + <j:if test="${tstRelPathLen > 0}"> + <j:set var="name" value="${name.substring(mavenTool.toInteger(tstDirLength.toString()))}"/> + </j:if> </j:if> <util:replace var="name" value="${name}" oldChar="\\" newChar="/"/> <!--- +1 is for the trailing slash above --> <j:set var="errorCount"><x:expr select="count($file/violation)"/></j:set> - <j:if test="${errorCount != 0}"> <tr> <td> <a href="#${name}">${name}</a> </td> - <td><doc:formatAsNumber string="${errorCount}" pattern="0"/></td> + <td> + <doc:formatAsNumber string="${errorCount}" pattern="0"/> + </td> </tr> </j:if> </j:forEach> </table> - + <!-- Where documentations are generated --> + <j:set var="docsDestDir" value="${maven.docs.dest}"/> + <util:replace var="docsDestDir" value="${docsDestDir}" oldChar="\\" newChar="/"/> + <!-- I don't think this test is useful but .... in the case of.. --> + <j:if test="${pom.build.sourceDirectory != null}"> + <!-- Where JXR files are generated for the code --> + <j:set var="jxrDestDir" value="${maven.jxr.destdir}"/> + <util:replace var="jxrDestDir" value="${jxrDestDir}" oldChar="\\" newChar="/"/> + <!-- We create a relative path to the jxr files --> + <!-- ${maven.jxr.destdir} should be a subdirectory of ${maven.docs.dest} --> + <j:choose> + <j:when test="${jxrDestDir.startsWith(docsDestDir)}"> + <j:set var="jxrDestDir" value="${jxrDestDir.substring(docsDestDir.length(),jxrDestDir.length())}"/> + <!-- remove first slash if needed --> + <j:if test="${jxrDestDir.startsWith('/')}"> + <j:set var="jxrDestDir" value="${jxrDestDir.substring(1,jxrDestDir.length())}"/> + </j:if> + </j:when> + <j:otherwise> + <!-- Use a default value :-( --> + <j:set var="jxrDestDir" value="xref2"/> + </j:otherwise> + </j:choose> + </j:if> + <j:if test="${pom.build.unitTestSourceDirectory != null}"> + <!-- Where JXR files are generated for the tests --> + <j:set var="jxrTestDestDir" value="${maven.jxr.destdir.test}"/> + <util:replace var="jxrTestDestDir" value="${jxrTestDestDir}" oldChar="\\" newChar="/"/> + <!-- We create a relative path to the jxr files for tests --> + <!-- ${maven.jxr.destdir.test} should be a subdirectory of ${maven.docs.dest} --> + <j:choose> + <j:when test="${jxrTestDestDir.startsWith(docsDestDir)}"> + <j:set var="jxrTestDestDir" value="${jxrTestDestDir.substring(docsDestDir.length(),jxrTestDestDir.length())}"/> + <!-- remove first slash if needed --> + <j:if test="${jxrTestDestDir.startsWith('/')}"> + <j:set var="jxrTestDestDir" value="${jxrTestDestDir.substring(1,jxrTestDestDir.length())}"/> + </j:if> + </j:when> + <j:otherwise> + <!-- Use a default value :-( --> + <j:set var="jxrTestDestDir" value="xref-test2"/> + </j:otherwise> + </j:choose> + </j:if> <j:forEach var="file" items="${files}"> <x:set var="errorCount" select="count($file/violation)"/> <j:if test="${errorCount != 0}"> <j:set var="name" value="${file.attribute('name').getValue()}"/> - <j:set var="srcRelPathLen" value="${pathtool.getRelativePath(srcDir,name).length()}"/> - <j:set var="tstRelPathLen" value="${pathtool.getRelativePath(tstDir,name).length()}"/> <j:set var="jxrPath" value=""/> - <j:if test="${srcRelPathLen > 0}"> - <j:set var="name" value="${name.substring(mavenTool.toInteger(srcDirLength.toString()))}"/> - <!-- FIXME: this should be determined by ${maven.jxr.destdir} --> - <j:set var="jxrPath" value="xref"/> + <j:if test="${pom.build.sourceDirectory != null}"> + <j:set var="srcRelPathLen" value="${pathtool.getRelativePath(srcDir,name).length()}"/> + <j:if test="${srcRelPathLen > 0}"> + <j:set var="name" value="${name.substring(mavenTool.toInteger(srcDirLength.toString()))}"/> + <j:set var="jxrPath" value="${jxrDestDir}"/> + </j:if> </j:if> - <j:if test="${tstRelPathLen > 0}"> - <j:set var="name" value="${name.substring(mavenTool.toInteger(tstDirLength.toString()))}"/> - <!-- FIXME: this should be determined by ${maven.jxr.destdir.test} --> - <j:set var="jxrPath" value="xref-test"/> + <j:if test="${pom.build.unitTestSourceDirectory != null}"> + <j:set var="tstRelPathLen" value="${pathtool.getRelativePath(tstDir,name).length()}"/> + <j:if test="${tstRelPathLen > 0}"> + <j:set var="name" value="${name.substring(mavenTool.toInteger(tstDirLength.toString()))}"/> + <j:set var="jxrPath" value="${jxrTestDestDir}"/> + </j:if> </j:if> - <util:replace var="name" value="${name}" oldChar="\\" newChar="/"/> - + <util:replace var="name" value="${name}" oldChar="\\" newChar="/"/> <subsection name="${name}"> <table> <tr> @@ -164,4 +216,4 @@ </body> </document> </jsl:template> -</jsl:stylesheet> +</jsl:stylesheet> \ No newline at end of file Modified: maven/maven-1/plugins/trunk/pmd/xdocs/changes.xml URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/pmd/xdocs/changes.xml?rev=374409&r1=374408&r2=374409&view=diff ============================================================================== --- maven/maven-1/plugins/trunk/pmd/xdocs/changes.xml (original) +++ maven/maven-1/plugins/trunk/pmd/xdocs/changes.xml Thu Feb 2 07:26:46 2006 @@ -25,6 +25,8 @@ </properties> <body> <release version="1.8-SNAPSHOT" date="In SVN"> + <action dev="aheritier" type="update">Use properties maven.jxr.destdir and maven.jxr.destdir.test to generate links from the PMD report to jxr files.</action> + <action dev="aheritier" type="fix">Fix NullPointerException if pom.build.sourceDirectory or pom.build.unitTestSourceDirectory are not defined.</action> <action dev="aheritier" type="update">Upgrade to pmd-3.4.</action> </release> <release version="1.7" date="2005-08-05">