Author: michaelo
Date: Thu Jan 29 20:43:02 2015
New Revision: 1655851

URL: http://svn.apache.org/r1655851
Log:
[MPMD-199] Support PMD functionality on JSP files

Added:
    maven/plugins/trunk/maven-pmd-plugin/src/site/apt/examples/jspReport.apt.vm 
  (with props)
    
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/jsp/
    
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/jsp-configuration-plugin-config.xml
   (with props)
    
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/jsp/sample.jsp
Modified:
    
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java
    
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java
    maven/plugins/trunk/maven-pmd-plugin/src/site/apt/index.apt.vm
    maven/plugins/trunk/maven-pmd-plugin/src/site/site.xml
    
maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/PmdReportTest.java

Modified: 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java?rev=1655851&r1=1655850&r2=1655851&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java
 Thu Jan 29 20:43:02 2015
@@ -106,7 +106,9 @@ public abstract class AbstractPmdViolati
             return;
         }
 
-        if ( "java".equals( language ) || aggregate )
+       if ( "java".equals( language )
+                || "jsp".equals( language )
+                || aggregate )
         {
             if ( !StringUtils.isEmpty( excludeFromFailureFile ) )
             {

Modified: 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java?rev=1655851&r1=1655850&r2=1655851&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java
 (original)
+++ 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java
 Thu Jan 29 20:43:02 2015
@@ -549,6 +549,11 @@ public class PmdReport
         {
             languageVersion = LanguageRegistry.findLanguageVersionByTerseName( 
"ecmascript" );
         }
+        else if ( "jsp".equals( language ) )
+        {
+            languageVersion = LanguageRegistry.findLanguageVersionByTerseName( 
"jsp" );
+        }
+
         if ( languageVersion != null )
         {
             getLog().debug( "Using language " + languageVersion );

Added: 
maven/plugins/trunk/maven-pmd-plugin/src/site/apt/examples/jspReport.apt.vm
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/site/apt/examples/jspReport.apt.vm?rev=1655851&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/site/apt/examples/jspReport.apt.vm 
(added)
+++ maven/plugins/trunk/maven-pmd-plugin/src/site/apt/examples/jspReport.apt.vm 
Thu Jan 29 20:43:02 2015
@@ -0,0 +1,100 @@
+------
+Analyzing JSP Code
+------
+Thomas Williamson
+------
+2015-01-19
+------
+
+~~ Licensed to the Apache Software Foundation (ASF) under one
+~~ or more contributor license agreements.  See the NOTICE file
+~~ distributed with this work for additional information
+~~ regarding copyright ownership.  The ASF licenses this file
+~~ to you 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.
+
+~~ NOTE: For help with the syntax of this file, see:
+~~ http://maven.apache.org/doxia/references/apt-format.html
+
+Analyzing JSP Code
+
+  The PMD plugin analyzes by default Java. You can configure it to analyze 
Java Server Pages files instead
+  as shown below.
+
+  The example assumes that the JSP source code is stored in various 
subdirectories under the source directory
+  <<<src/main/webapp>>> and enables the built-in JSP ruleset(<basic>).
+
+  Note that this example runs two plugins: build-helper-maven-plugin and 
maven-pmd-plugin. Because the JSP files are
+  not in the original source directory (typically <<<src/main/java>>>) the 
build-helper plugin is used to add the
+  additional directory to the list of source directories which PMD will search.
+
+  Here is a section of a sample pom.xml file. This POM sets up a profile 
called "pmd" which will run the two plugins
+  when activated. The result should be a file in <<<target/site>>> called 
pmd.html, which will contain a report of
+  the problems detected by PMD.
+
+
+ <<<mvn generate-sources site>>>
+
++-----+
+<project>
+  ...
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <version>1.7</version>
+        <configuration>
+          <sources>
+            <source>${basedir}/src/main/webapp</source>
+          </sources>
+        </configuration>
+        <executions>
+          <execution>
+            <goals>
+              <goal>add-source</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-pmd-plugin</artifactId>
+        <version>${project.version}</version>
+        <configuration>
+          <language>jsp</language>
+          <rulesets>
+            <ruleset>jsp-basic</ruleset>
+          </rulesets>
+          <includes>
+            <include>**/*.jsp</include>
+          </includes>
+        </configuration>
+        <depdendencies>
+          <dependency>
+            <groupId>net.sourceforge.pmd</groupId>
+            <artifactId>pmd-jsp</artifactId>
+            <version>${pmdVersion}</version>
+          </dependency>
+        </dependencies>
+      </plugin>
+    </plugins>
+  </reporting>
+  ...
+</project>
++-----+

Propchange: 
maven/plugins/trunk/maven-pmd-plugin/src/site/apt/examples/jspReport.apt.vm
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-pmd-plugin/src/site/apt/examples/jspReport.apt.vm
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: maven/plugins/trunk/maven-pmd-plugin/src/site/apt/index.apt.vm
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/site/apt/index.apt.vm?rev=1655851&r1=1655850&r2=1655851&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/site/apt/index.apt.vm (original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/site/apt/index.apt.vm Thu Jan 29 
20:43:02 2015
@@ -85,4 +85,6 @@ ${project.name}
 
   * {{{./examples/javascriptReport.html}Analyzing JavaScript Code}}
 
+  * {{{./examples/jspReport.html}Analyzing Java Server Pages Code}}
+
   []

Modified: maven/plugins/trunk/maven-pmd-plugin/src/site/site.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/site/site.xml?rev=1655851&r1=1655850&r2=1655851&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/site/site.xml (original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/site/site.xml Thu Jan 29 20:43:02 
2015
@@ -38,6 +38,7 @@ under the License.
       <item name="Using Rule Sets" href="examples/usingRuleSets.html"/>
       <item name="Violation Checking" href="examples/violationChecking.html"/>
       <item name="Analyzing JavaScript" href="examples/javascriptReport.html"/>
+      <item name="Analyzing Java Server Pages" href="examples/jspReport.html"/>
       <item name="Violations Exclusions" 
href="examples/violation-exclusions.html"/>
     </menu>
   </body>

Modified: 
maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/PmdReportTest.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/PmdReportTest.java?rev=1655851&r1=1655850&r2=1655851&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/PmdReportTest.java
 (original)
+++ 
maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/PmdReportTest.java
 Thu Jan 29 20:43:02 2015
@@ -402,4 +402,31 @@ public class PmdReportTest
         assertFalse( str.contains( "Avoid unused private fields such as 
'unusedVar2'." ) );
     }
 
+    public void testJspConfiguration()
+            throws Exception
+    {
+        File testPom = new File( getBasedir(),
+                
"src/test/resources/unit/default-configuration/jsp-configuration-plugin-config.xml"
 );
+        PmdReport mojo = (PmdReport) lookupMojo( "pmd", testPom );
+        mojo.execute();
+
+        // check if the PMD files were generated
+        File generatedFile = new File( getBasedir(), 
"target/test/unit/default-configuration/target/pmd.xml" );
+        assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
+
+        // these are the rulesets, that have been applied...
+        generatedFile = new File( getBasedir(), 
"target/test/unit/default-configuration/target/jsp-basic.xml" );
+        assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
+
+        generatedFile = new File( getBasedir(), 
"target/test/unit/default-configuration/target/site/pmd.html" );
+        renderer( mojo, generatedFile );
+        assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
+
+        String str = readFile( generatedFile );
+        assertTrue(str.contains("JSP file should use UTF-8 encoding"));
+        assertTrue(str.contains("Using unsanitized JSP expression can lead to 
Cross Site Scripting (XSS) attacks"));
+        assertTrue(str.contains("Avoid having style information in JSP 
files."));
+    }
+
+
 }

Added: 
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/jsp-configuration-plugin-config.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/jsp-configuration-plugin-config.xml?rev=1655851&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/jsp-configuration-plugin-config.xml
 (added)
+++ 
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/jsp-configuration-plugin-config.xml
 Thu Jan 29 20:43:02 2015
@@ -0,0 +1,55 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<project>
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>def.configuration</groupId>
+    <artifactId>default-configuration</artifactId>
+    <packaging>jar</packaging>
+    <version>1.0-SNAPSHOT</version>
+    <inceptionYear>2006</inceptionYear>
+    <name>Maven PMD Plugin Javascript Configuration Test</name>
+    <url>http://maven.apache.org</url>
+    <build>
+        <finalName>default-configuration</finalName>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-pmd-plugin</artifactId>
+                <configuration>
+                    <project 
implementation="org.apache.maven.plugin.pmd.stubs.DefaultConfigurationMavenProjectStub"/>
+                    
<outputDirectory>${basedir}/target/test/unit/default-configuration/target/site</outputDirectory>
+                    
<targetDirectory>${basedir}/target/test/unit/default-configuration/target</targetDirectory>
+                    <format>xml</format>
+                    <sourceEncoding>UTF-8</sourceEncoding>
+                    <language>jsp</language>
+                    <rulesets>
+                        <ruleset>jsp-basic</ruleset>
+                    </rulesets>
+                    <includes>
+                        <include>**/*.jsp</include>
+                    </includes>
+                    <compileSourceRoots>
+                        
<compileSourceRoot>${basedir}/src/test/resources/unit/default-configuration/jsp</compileSourceRoot>
+                    </compileSourceRoots>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

Propchange: 
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/jsp-configuration-plugin-config.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/jsp/sample.jsp
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/jsp/sample.jsp?rev=1655851&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/jsp/sample.jsp
 (added)
+++ 
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/jsp/sample.jsp
 Thu Jan 29 20:43:02 2015
@@ -0,0 +1,26 @@
+<%-- This file will fail the Apache Rat tests if it does not contain the 
license,
+therefore, the license is included.  --%>
+
+<%--
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you 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.
+--%>
+
+<%-- Introduce unsanitized JSP expression --%>
+${my.variable.is.bad}
+<%-- Introduce inline style --%>
+<p align="center">Inline Styles are bad.</p>
\ No newline at end of file


Reply via email to