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.

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@374409 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
aheritier 2006-02-02 15:26:46 +00:00
parent 4acd5315cd
commit b68b6a0bc3
2 changed files with 102 additions and 48 deletions

View File

@ -1,5 +1,4 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!-- <!--
* ======================================================================== * ========================================================================
* *
@ -19,7 +18,6 @@
* *
* ======================================================================== * ========================================================================
--> -->
<jsl:stylesheet <jsl:stylesheet
select="$doc" select="$doc"
xmlns:j="jelly:core" xmlns:j="jelly:core"
@ -27,30 +25,28 @@
xmlns:util="jelly:util" xmlns:util="jelly:util"
xmlns:x="jelly:xml" xmlns:x="jelly:xml"
xmlns:doc="doc" xmlns:doc="doc"
xmlns="dummy" trim="false"> xmlns:maven="jelly:maven"
xmlns="dummy"
trim="false">
<!-- This needs to be instantiated here to be available in the template matches --> <!-- 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="mavenTool" class="org.apache.maven.util.MavenTool"/>
<j:useBean var="htmlescape" class="org.apache.velocity.anakia.Escape"/> <j:useBean var="htmlescape" class="org.apache.velocity.anakia.Escape"/>
<j:useBean var="fileutil" class="org.apache.velocity.texen.util.FileUtil"/> <j:useBean var="fileutil" class="org.apache.velocity.texen.util.FileUtil"/>
<j:useBean var="pathtool" class="org.apache.maven.util.DVSLPathTool"/> <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"> <jsl:template match="pmd">
<document> <document>
<properties> <properties>
<title>PMD Results</title> <title>PMD Results</title>
</properties> </properties>
<body> <body>
<section name="PMD Results"> <section name="PMD Results">
<p> <p>
The following document contains the results of The following document contains the results of
<a <a href="http://pmd.sourceforge.net/">PMD</a>.
href="http://pmd.sourceforge.net/">PMD</a>.
</p> </p>
</section> </section>
<section name="Summary"> <section name="Summary">
<j:set var="fileCount"><x:expr select="count(file)"/></j:set> <j:set var="fileCount"><x:expr select="count(file)"/></j:set>
<j:set var="errorCount"><x:expr select="count(file/violation)"/></j:set> <j:set var="errorCount"><x:expr select="count(file/violation)"/></j:set>
@ -60,71 +56,127 @@
<th>Errors</th> <th>Errors</th>
</tr> </tr>
<tr> <tr>
<td><doc:formatAsNumber string="${fileCount}" pattern="0"/></td> <td>
<td><doc:formatAsNumber string="${errorCount}" pattern="0"/></td> <doc:formatAsNumber string="${fileCount}" pattern="0"/>
</td>
<td>
<doc:formatAsNumber string="${errorCount}" pattern="0"/>
</td>
</tr> </tr>
</table> </table>
</section> </section>
<section name="Files"> <section name="Files">
<table> <table>
<tr> <tr>
<th>Files</th> <th>Files</th>
<th>Violations</th> <th>Violations</th>
</tr> </tr>
<j:set var="fullSrcDir" value="${pom.build.sourceDirectory}"/> <j:if test="${pom.build.sourceDirectory != null}">
<j:set var="srcDir" value="${fileutil.file(fullSrcDir).getCanonicalPath()}"/> <j:set var="fullSrcDir" value="${pom.build.sourceDirectory}"/>
<j:set var="srcDirLength" value="${srcDir.length() + 1}"/> <j:set var="srcDir" value="${fileutil.file(fullSrcDir).getCanonicalPath()}"/>
<j:set var="fullTstDir" value="${pom.build.unitTestSourceDirectory}"/> <j:set var="srcDirLength" value="${srcDir.length() + 1}"/>
<j:set var="tstDir" value="${fileutil.file(fullTstDir).getCanonicalPath()}"/> </j:if>
<j:set var="tstDirLength" value="${tstDir.length() + 1}"/> <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:set var="files" select="file"/>
<!-- x:forEach is busted --> <!-- x:forEach is busted -->
<j:forEach var="file" items="${files}"> <j:forEach var="file" items="${files}">
<!-- Type coercion doesn't work worth a fuck in jexl. --> <!-- Type coercion doesn't work worth a fuck in jexl. -->
<j:set var="name" value="${file.attribute('name').getValue()}"/> <j:set var="name" value="${file.attribute('name').getValue()}"/>
<j:set var="srcRelPathLen" value="${pathtool.getRelativePath(srcDir,name).length()}"/> <j:if test="${pom.build.sourceDirectory != null}">
<j:set var="tstRelPathLen" value="${pathtool.getRelativePath(tstDir,name).length()}"/> <j:set var="srcRelPathLen" value="${pathtool.getRelativePath(srcDir,name).length()}"/>
<j:if test="${srcRelPathLen > 0}"> <j:if test="${srcRelPathLen > 0}">
<j:set var="name" value="${name.substring(mavenTool.toInteger(srcDirLength.toString()))}"/> <j:set var="name" value="${name.substring(mavenTool.toInteger(srcDirLength.toString()))}"/>
</j:if>
</j:if> </j:if>
<j:if test="${tstRelPathLen > 0}"> <j:if test="${pom.build.unitTestSourceDirectory != null}">
<j:set var="name" value="${name.substring(mavenTool.toInteger(tstDirLength.toString()))}"/> <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> </j:if>
<util:replace var="name" value="${name}" oldChar="\\" newChar="/"/> <util:replace var="name" value="${name}" oldChar="\\" newChar="/"/>
<!--- +1 is for the trailing slash above --> <!--- +1 is for the trailing slash above -->
<j:set var="errorCount"><x:expr select="count($file/violation)"/></j:set> <j:set var="errorCount"><x:expr select="count($file/violation)"/></j:set>
<j:if test="${errorCount != 0}"> <j:if test="${errorCount != 0}">
<tr> <tr>
<td> <td>
<a href="#${name}">${name}</a> <a href="#${name}">${name}</a>
</td> </td>
<td><doc:formatAsNumber string="${errorCount}" pattern="0"/></td> <td>
<doc:formatAsNumber string="${errorCount}" pattern="0"/>
</td>
</tr> </tr>
</j:if> </j:if>
</j:forEach> </j:forEach>
</table> </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}"> <j:forEach var="file" items="${files}">
<x:set var="errorCount" select="count($file/violation)"/> <x:set var="errorCount" select="count($file/violation)"/>
<j:if test="${errorCount != 0}"> <j:if test="${errorCount != 0}">
<j:set var="name" value="${file.attribute('name').getValue()}"/> <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:set var="jxrPath" value=""/>
<j:if test="${srcRelPathLen > 0}"> <j:if test="${pom.build.sourceDirectory != null}">
<j:set var="name" value="${name.substring(mavenTool.toInteger(srcDirLength.toString()))}"/> <j:set var="srcRelPathLen" value="${pathtool.getRelativePath(srcDir,name).length()}"/>
<!-- FIXME: this should be determined by ${maven.jxr.destdir} --> <j:if test="${srcRelPathLen > 0}">
<j:set var="jxrPath" value="xref"/> <j:set var="name" value="${name.substring(mavenTool.toInteger(srcDirLength.toString()))}"/>
<j:set var="jxrPath" value="${jxrDestDir}"/>
</j:if>
</j:if> </j:if>
<j:if test="${tstRelPathLen > 0}"> <j:if test="${pom.build.unitTestSourceDirectory != null}">
<j:set var="name" value="${name.substring(mavenTool.toInteger(tstDirLength.toString()))}"/> <j:set var="tstRelPathLen" value="${pathtool.getRelativePath(tstDir,name).length()}"/>
<!-- FIXME: this should be determined by ${maven.jxr.destdir.test} --> <j:if test="${tstRelPathLen > 0}">
<j:set var="jxrPath" value="xref-test"/> <j:set var="name" value="${name.substring(mavenTool.toInteger(tstDirLength.toString()))}"/>
<j:set var="jxrPath" value="${jxrTestDestDir}"/>
</j:if>
</j:if> </j:if>
<util:replace var="name" value="${name}" oldChar="\\" newChar="/"/> <util:replace var="name" value="${name}" oldChar="\\" newChar="/"/>
<subsection name="${name}"> <subsection name="${name}">
<table> <table>
<tr> <tr>

View File

@ -25,6 +25,8 @@
</properties> </properties>
<body> <body>
<release version="1.8-SNAPSHOT" date="In SVN"> <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> <action dev="aheritier" type="update">Upgrade to pmd-3.4.</action>
</release> </release>
<release version="1.7" date="2005-08-05"> <release version="1.7" date="2005-08-05">