You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by lt...@apache.org on 2006/11/06 15:52:27 UTC

svn commit: r471752 - in /maven/maven-1/plugins/trunk/pmd: plugin.jelly src/plugin-resources/pmd-priority.jsl xdocs/changes.xml xdocs/properties.xml

Author: ltheussl
Date: Mon Nov  6 06:52:27 2006
New Revision: 471752

URL: http://svn.apache.org/viewvc?view=rev&rev=471752
Log:
Add an alternative jsl stylesheet. Thanks to James Dempsey.

Added:
    maven/maven-1/plugins/trunk/pmd/src/plugin-resources/pmd-priority.jsl
Modified:
    maven/maven-1/plugins/trunk/pmd/plugin.jelly
    maven/maven-1/plugins/trunk/pmd/xdocs/changes.xml
    maven/maven-1/plugins/trunk/pmd/xdocs/properties.xml

Modified: maven/maven-1/plugins/trunk/pmd/plugin.jelly
URL: http://svn.apache.org/viewvc/maven/maven-1/plugins/trunk/pmd/plugin.jelly?view=diff&rev=471752&r1=471751&r2=471752
==============================================================================
--- maven/maven-1/plugins/trunk/pmd/plugin.jelly (original)
+++ maven/maven-1/plugins/trunk/pmd/plugin.jelly Mon Nov  6 06:52:27 2006
@@ -172,6 +172,7 @@
       <j:set var="stylesheet" value="${plugin.resources}/pmd.jsl"/>
     </j:if>
     <echo>Converting the PMD report to xdoc ...</echo>
+    <echo>Using stylesheet: ${stylesheet}</echo>
 
     <doc:jsl
       input="${maven.build.dir}/pmd-raw-report.xml"

Added: maven/maven-1/plugins/trunk/pmd/src/plugin-resources/pmd-priority.jsl
URL: http://svn.apache.org/viewvc/maven/maven-1/plugins/trunk/pmd/src/plugin-resources/pmd-priority.jsl?view=auto&rev=471752
==============================================================================
--- maven/maven-1/plugins/trunk/pmd/src/plugin-resources/pmd-priority.jsl (added)
+++ maven/maven-1/plugins/trunk/pmd/src/plugin-resources/pmd-priority.jsl Mon Nov  6 06:52:27 2006
@@ -0,0 +1,263 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * ========================================================================
+ * 
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * ========================================================================
+-->
+<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"/>
+  <!-- Force the jxr plugin to be loaded - even if it's not used in the project -->
+  <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>.
+          </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>
+          <table>
+            <tr>
+              <th>Files</th>
+              <th>Errors</th>
+            </tr>
+            <tr>
+              <td>
+                <doc:formatAsNumber string="${fileCount}" pattern="0"/>
+              </td>
+              <td>
+                <j:set var="breakdown" value="" />
+                <j:forEach indexVar="pri" begin="1" end="9" step="1">
+                  <j:set var="priCount"><x:expr select="count(file/violation[@priority=${pri}])"/></j:set>
+                  <j:if test="${priCount > 0}">
+                    <j:if test="${breakdown.length() > 0}">
+                      <j:set var="breakdown" value="${breakdown}, " />
+                    </j:if>
+                    <j:if test="${breakdown.length() == 0}">
+                      <j:set var="breakdown" value="(" />
+                    </j:if>
+
+                    <j:set var="breakdown" value="${breakdown}P${pri}:${priCount}" />
+                  </j:if>
+                </j:forEach>
+                <j:set var="breakdown" value="${breakdown})" />
+                <doc:formatAsNumber string="${errorCount}" pattern="0"/>  ${breakdown}
+              </td>
+            </tr>
+          </table>
+        </section>
+        <section name="Files">
+          <table>
+            <tr>
+              <th>Files</th>
+              <th>Violations</th>
+            </tr>
+            <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 in jexl. -->
+              <j:set var="name" value="${file.attribute('name').getValue()}"/>
+              <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="${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>
+                    <j:set var="breakdown" value="" />
+                    <j:forEach indexVar="pri" begin="1" end="9" step="1">
+                      <j:set var="priCount"><x:expr select="count($file/violation[@priority=$pri])"/></j:set>
+                      <j:if test="${priCount > 0}">
+                        <j:if test="${breakdown.length() > 0}">
+                          <j:set var="breakdown" value="${breakdown}, " />
+                        </j:if>
+                        <j:if test="${breakdown.length() == 0}">
+                          <j:set var="breakdown" value="(" />
+                        </j:if>
+
+                        <j:set var="breakdown" value="${breakdown}P${pri}:${priCount}" />
+                      </j:if>
+                    </j:forEach>
+                    <j:set var="breakdown" value="${breakdown})" />
+                    <doc:formatAsNumber string="${errorCount}" pattern="0"/>  ${breakdown}
+                  </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="/"/>
+          <!-- JXR is activated ? -->
+          <j:set var="jxrActivated" value="false"/>
+          <j:forEach var="report" items="${pom.reports}">
+            <j:if test="${report.equals('maven-jxr-plugin')}">
+              <j:set var="jxrActivated" value="true"/>
+            </j:if>
+          </j:forEach>
+          <!-- 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="/"/>
+            <j:choose>
+              <j:when test="${jxrActivated and jxrDestDir.startsWith(docsDestDir)}">
+	            <!-- We create a relative path to the jxr files -->
+	            <!-- ${maven.jxr.destdir} should be a subdirectory of ${maven.docs.dest} -->
+				<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>
+                <!-- Do not generate the link -->
+                  <j:set var="jxrDestDir" value=""/>
+              </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="/"/>
+            <maven:get var="xrefGeneratedForTests" plugin="maven-jxr-plugin" property="maven.jxr.include.testXref"/>
+            <j:choose>
+              <j:when test="${jxrActivated and xrefGeneratedForTests and jxrTestDestDir.startsWith(docsDestDir)}">
+	            <!-- We create a relative path to the jxr files for tests -->
+	            <!-- ${maven.jxr.destdir.test} should be a subdirectory of ${maven.docs.dest} -->
+				<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>
+                <!-- Do not generate the link -->
+                  <j:set var="jxrTestDestDir" value=""/>
+              </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="jxrPath" value=""/>
+              <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="${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="/"/>
+              <subsection name="${name}">
+                <table>
+                  <tr>
+                    <th>Pri</th>
+                    <th>Violation</th>
+                    <th>Line</th>
+                  </tr>
+                  <x:set var="errors" select="$file/violation" sort="@priority"/>
+                  <j:forEach var="error" items="${errors}">
+                    <tr>
+                      <td>
+                        <j:set var="priority" value="${error.attribute('priority').getValue()}"/>
+                        ${priority}
+                      </td>
+                      <td>
+                        <j:set var="externalInfoUrl" value="${error.attribute('externalInfoUrl').getValue()}"/>
+                        <j:set var="errorMessage" value="${error.StringValue}"/>
+                        ${htmlescape.getText(errorMessage)} - <a href="${externalInfoUrl}" target="_blank">details...</a>
+                      </td>
+                      <td>
+                        <j:set var="line" value="${error.attribute('line').getValue()}"/>
+                        <j:set var="lastIndex" value="${name.lastIndexOf('.java')}"/>
+                        <j:set var="jxrPathLen" value="${jxrPath.length()}"/>
+                        <j:choose>
+                          <j:when test="${lastIndex > 0 and jxrPathLen > 0}">
+                            <j:set var="index" value="${mavenTool.toInteger(lastIndex.toString())}"/>
+                            <j:set var="nameWithoutJavaExtension" value="${name.substring(0, index)}"/>
+                            <util:replace var="nameWithoutJavaExtension" value="${nameWithoutJavaExtension}" oldChar="\\" newChar="/"/>
+                            <a href="${jxrPath}/${nameWithoutJavaExtension}.html#${line}">${line}</a>
+                          </j:when>
+                          <j:otherwise>
+                            ${line}
+                          </j:otherwise>
+                        </j:choose>
+                      </td>
+                    </tr>
+                  </j:forEach>
+                </table>
+              </subsection>
+            </j:if>
+          </j:forEach>
+        </section>
+      </body>
+    </document>
+  </jsl:template>
+</jsl:stylesheet>
\ No newline at end of file

Modified: maven/maven-1/plugins/trunk/pmd/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/maven/maven-1/plugins/trunk/pmd/xdocs/changes.xml?view=diff&rev=471752&r1=471751&r2=471752
==============================================================================
--- maven/maven-1/plugins/trunk/pmd/xdocs/changes.xml (original)
+++ maven/maven-1/plugins/trunk/pmd/xdocs/changes.xml Mon Nov  6 06:52:27 2006
@@ -25,6 +25,7 @@
   </properties>
   <body>
     <release version="1.10-SNAPSHOT" date="In SVN">
+      <action dev="ltheussl" type="add" due-to="James Dempsey">Add an alternative jsl stylesheet that includes priority information.</action>
       <action dev="ltheussl" type="add" issue="MPPMD-27">Allow custom JSL stylesheet to be defined via a property.</action>
       <action dev="aheritier" type="update">Update dependencies to unify them between plugins. The following dependencies are updated : jaxen v1.0-FCS-full to 1.1-beta-9. The following dependencies are removed : saxpath.</action>
       <action dev="aheritier" type="update">Upgrade to pmd-3.7.</action>

Modified: maven/maven-1/plugins/trunk/pmd/xdocs/properties.xml
URL: http://svn.apache.org/viewvc/maven/maven-1/plugins/trunk/pmd/xdocs/properties.xml?view=diff&rev=471752&r1=471751&r2=471752
==============================================================================
--- maven/maven-1/plugins/trunk/pmd/xdocs/properties.xml (original)
+++ maven/maven-1/plugins/trunk/pmd/xdocs/properties.xml Mon Nov  6 06:52:27 2006
@@ -128,6 +128,9 @@
           <td>
             A custom stylesheet to use for the report.
             Default is <code>${plugin.resources}/pmd.jsl</code>.
+            An alternative stylesheet is supplied that includes
+            priority information of pmd violations. To use it, set
+            <code>maven.pmd.stylesheet=${plugin.resources}/pmd-priority.jsl</code>.
           </td>
         </tr>
       </table>