You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by de...@apache.org on 2014/03/11 10:10:32 UTC

svn commit: r1576238 - in /maven/plugins/trunk/maven-pmd-plugin/src: it/MPMD-181-benchmark/ it/MPMD-181-benchmark/src/ it/MPMD-181-benchmark/src/main/ it/MPMD-181-benchmark/src/main/java/ it/MPMD-181-benchmark/src/main/java/com/ it/MPMD-181-benchmark/s...

Author: dennisl
Date: Tue Mar 11 09:10:32 2014
New Revision: 1576238

URL: http://svn.apache.org/r1576238
Log:
[MPMD-181] Add flag to capture Benchmark information
Submitted by: Anthony Whitford
Reviewed by: Dennis Lundberg

- I adjusted the code to comply with our code style
- I also added a couple of ITs

Added:
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/invoker.properties   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/pom.xml   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/src/
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/src/main/
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/src/main/java/
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/src/main/java/com/
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/src/main/java/com/mycompany/
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/src/main/java/com/mycompany/app/
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/src/main/java/com/mycompany/app/Hello.java   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/verify.groovy   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/invoker.properties   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/pom.xml   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/src/
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/src/main/
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/src/main/java/
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/src/main/java/com/
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/src/main/java/com/mycompany/
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/src/main/java/com/mycompany/app/
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/src/main/java/com/mycompany/app/Hello.java   (with props)
    maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/verify.groovy   (with props)
Modified:
    maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java

Added: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/invoker.properties?rev=1576238&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/invoker.properties (added)
+++ maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/invoker.properties Tue Mar 11 09:10:32 2014
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals = clean verify pmd:pmd

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/invoker.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/invoker.properties
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author Id

Added: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/pom.xml?rev=1576238&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/pom.xml (added)
+++ maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/pom.xml Tue Mar 11 09:10:32 2014
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugin.pmd.its</groupId>
+  <artifactId>MPMD-181-benchmark</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <description>
+    Verify that a benchmark file is produced.
+  </description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-pmd-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <benchmark>true</benchmark>
+          <benchmarkOutputFilename>${project.build.directory}/my-own-pmd-benchmark.txt</benchmarkOutputFilename>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author Id

Added: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/src/main/java/com/mycompany/app/Hello.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/src/main/java/com/mycompany/app/Hello.java?rev=1576238&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/src/main/java/com/mycompany/app/Hello.java (added)
+++ maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/src/main/java/com/mycompany/app/Hello.java Tue Mar 11 09:10:32 2014
@@ -0,0 +1,28 @@
+package com.mycompany.app;
+
+/*
+ * 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.
+ */
+
+public class Hello
+{
+    public static void main( String[] args )
+    {
+        System.out.println( args[0] );
+    }
+}

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/src/main/java/com/mycompany/app/Hello.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/src/main/java/com/mycompany/app/Hello.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author Id

Added: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/verify.groovy
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/verify.groovy?rev=1576238&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/verify.groovy (added)
+++ maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/verify.groovy Tue Mar 11 09:10:32 2014
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+File defaultBenchmarkFile = new File( basedir, 'target/pmd-benchmark.txt' )
+assert !defaultBenchmarkFile.exists()
+
+File customBenchmarkFile = new File( basedir, 'target/my-own-pmd-benchmark.txt' )
+assert customBenchmarkFile.exists()

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/verify.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-benchmark/verify.groovy
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author Id

Added: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/invoker.properties?rev=1576238&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/invoker.properties (added)
+++ maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/invoker.properties Tue Mar 11 09:10:32 2014
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals = clean verify pmd:pmd

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/invoker.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/invoker.properties
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author Id

Added: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/pom.xml?rev=1576238&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/pom.xml (added)
+++ maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/pom.xml Tue Mar 11 09:10:32 2014
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugin.pmd.its</groupId>
+  <artifactId>MPMD-181-no-benchmark</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <description>
+    Verify that no benchmark file is produced.
+  </description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-pmd-plugin</artifactId>
+        <version>@project.version@</version>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author Id

Added: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/src/main/java/com/mycompany/app/Hello.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/src/main/java/com/mycompany/app/Hello.java?rev=1576238&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/src/main/java/com/mycompany/app/Hello.java (added)
+++ maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/src/main/java/com/mycompany/app/Hello.java Tue Mar 11 09:10:32 2014
@@ -0,0 +1,28 @@
+package com.mycompany.app;
+
+/*
+ * 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.
+ */
+
+public class Hello
+{
+    public static void main( String[] args )
+    {
+        System.out.println( args[0] );
+    }
+}

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/src/main/java/com/mycompany/app/Hello.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/src/main/java/com/mycompany/app/Hello.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author Id

Added: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/verify.groovy
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/verify.groovy?rev=1576238&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/verify.groovy (added)
+++ maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/verify.groovy Tue Mar 11 09:10:32 2014
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+File defaultBenchmarkFile = new File( basedir, 'target/pmd-benchmark.txt' )
+assert !defaultBenchmarkFile.exists()
+
+File customBenchmarkFile = new File( basedir, 'target/my-own-pmd-benchmark.txt' )
+assert !customBenchmarkFile.exists()

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/verify.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pmd-plugin/src/it/MPMD-181-no-benchmark/verify.groovy
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author Id

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=1576238&r1=1576237&r2=1576238&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 Tue Mar 11 09:10:32 2014
@@ -26,6 +26,8 @@ import net.sourceforge.pmd.RuleContext;
 import net.sourceforge.pmd.RulePriority;
 import net.sourceforge.pmd.RuleSetFactory;
 import net.sourceforge.pmd.RuleSetReferenceId;
+import net.sourceforge.pmd.benchmark.Benchmarker;
+import net.sourceforge.pmd.benchmark.TextReport;
 import net.sourceforge.pmd.lang.LanguageVersion;
 import net.sourceforge.pmd.renderers.CSVRenderer;
 import net.sourceforge.pmd.renderers.HTMLRenderer;
@@ -50,9 +52,11 @@ import org.codehaus.plexus.util.ReaderFa
 import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
+import java.io.PrintStream;
 import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -130,6 +134,18 @@ public class PmdReport
     private boolean typeResolution;
 
     /**
+     * Controls whether PMD will track benchmark information.
+     */
+    @Parameter( property = "pmd.benchmark", defaultValue = "false" )
+    private boolean benchmark;
+
+    /**
+     * Benchmark output filename.
+     */
+    @Parameter( property = "pmd.benchmarkOutputFilename", defaultValue = "${project.build.directory}/pmd-benchmark.txt" )
+    private String benchmarkOutputFilename;
+
+    /**
      */
     @Component
     private ResourceManager locator;
@@ -360,6 +376,26 @@ public class PmdReport
         {
             writeNonHtml( reportListener.asReport() );
         }
+
+        if ( benchmark ) {
+            PrintStream benchmarkFileStream = null;
+            try
+            {
+                benchmarkFileStream = new PrintStream( benchmarkOutputFilename );
+                ( new TextReport() ).generate( Benchmarker.values(), benchmarkFileStream );
+            }
+            catch ( FileNotFoundException fnfe )
+            {
+                getLog().error( "Unable to generate benchmark file: " + benchmarkOutputFilename, fnfe );
+            }
+            finally
+            {
+                if ( null != benchmarkFileStream )
+                {
+                    benchmarkFileStream.close();
+                }
+            }
+        }
     }
 
     private Report generateReport( Locale locale )
@@ -513,6 +549,8 @@ public class PmdReport
             }
         }
 
+        configuration.setBenchmark( benchmark );
+
         return configuration;
     }