maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adan...@apache.org
Subject svn commit: r1762991 - /maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/
Date Sat, 01 Oct 2016 09:30:08 GMT
Author: adangel
Date: Sat Oct  1 09:30:08 2016
New Revision: 1762991

URL: http://svn.apache.org/viewvc?rev=1762991&view=rev
Log:
[MPMD-162] PMD/CPD report does not take into account pmd.excludeFromFailureFile
Introduce a common interface ExcludeFromFile

Added:
    maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ExcludeFromFile.java
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/CpdViolationCheckMojo.java
    maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ExcludeDuplicationsFromFile.java
    maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ExcludeViolationsFromFile.java
    maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojo.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=1762991&r1=1762990&r2=1762991&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
Sat Oct  1 09:30:08 2016
@@ -29,7 +29,6 @@ import org.apache.maven.plugin.MojoExecu
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 /**
@@ -113,10 +112,7 @@ public abstract class AbstractPmdViolati
             return;
         }
 
-        if ( !StringUtils.isEmpty( excludeFromFailureFile ) )
-        {
-            loadExcludeFromFailuresData( excludeFromFailureFile );
-        }
+        loadExcludeFromFailuresData( excludeFromFailureFile );
         final File outputFile = new File( targetDirectory, filename );
 
         if ( outputFile.exists() )

Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdViolationCheckMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdViolationCheckMojo.java?rev=1762991&r1=1762990&r2=1762991&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdViolationCheckMojo.java
(original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdViolationCheckMojo.java
Sat Oct  1 09:30:08 2016
@@ -62,6 +62,9 @@ public class CpdViolationCheckMojo
     @Parameter( property = "cpd.failOnViolation", defaultValue = "true", required = true
)
     protected boolean failOnViolation;
 
+    /** Helper to exclude duplications from the result. */
+    private final ExcludeDuplicationsFromFile excludeDuplicationsFromFile = new ExcludeDuplicationsFromFile();
+
     /**
      * {@inheritDoc}
      */
@@ -112,7 +115,6 @@ public class CpdViolationCheckMojo
         return details.getDuplications();
     }
 
-    private final ExcludeDuplicationsFromFile excludeDuplicationsFromFile = new ExcludeDuplicationsFromFile();
     @Override
     protected boolean isExcludedFromFailure( final Duplication errorDetail )
     {

Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ExcludeDuplicationsFromFile.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ExcludeDuplicationsFromFile.java?rev=1762991&r1=1762990&r2=1762991&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ExcludeDuplicationsFromFile.java
(original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ExcludeDuplicationsFromFile.java
Sat Oct  1 09:30:08 2016
@@ -27,6 +27,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.pmd.model.CpdFile;
 import org.apache.maven.plugin.pmd.model.Duplication;
@@ -41,18 +42,12 @@ import net.sourceforge.pmd.cpd.Match;
  *
  * @author Andreas Dangel
  */
-public class ExcludeDuplicationsFromFile
+public class ExcludeDuplicationsFromFile implements ExcludeFromFile<Duplication>
 {
 
     private final List<Set<String>> exclusionList = new ArrayList<>();
 
-    /**
-     * Checks whether the given {@link Duplication} is excluded.
-     * Note: The exclusion must have been loaded before via {@link #loadExcludeFromFailuresData(String)}.
-     * 
-     * @param errorDetail the duplication to check
-     * @return <code>true</code> if the given duplication should be excluded,
<code>false</code> otherwise.
-     */
+    @Override
     public boolean isExcludedFromFailure( final Duplication errorDetail )
     {
         final Set<String> uniquePaths = new HashSet<>();
@@ -118,15 +113,15 @@ public class ExcludeDuplicationsFromFile
         return false;
     }
 
-    /**
-     * Loads the CPD exclusions from the given file.
-     *
-     * @param excludeFromFailureFile the file to load the exclusions from
-     * @throws MojoExecutionException if the file couldn't be loaded
-     */
+    @Override
     public void loadExcludeFromFailuresData( final String excludeFromFailureFile )
             throws MojoExecutionException
     {
+        if ( StringUtils.isEmpty( excludeFromFailureFile ) )
+        {
+            return;
+        }
+
         try ( LineNumberReader reader = new LineNumberReader( new FileReader( excludeFromFailureFile
) ) )
         {
             String line;
@@ -154,10 +149,7 @@ public class ExcludeDuplicationsFromFile
         return result;
     }
 
-    /**
-     * Determines how many exclusions are considered.
-     * @return the number of active exclusions
-     */
+    @Override
     public int countExclusions()
     {
         return exclusionList.size();

Added: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ExcludeFromFile.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ExcludeFromFile.java?rev=1762991&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ExcludeFromFile.java
(added)
+++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ExcludeFromFile.java
Sat Oct  1 09:30:08 2016
@@ -0,0 +1,53 @@
+package org.apache.maven.plugin.pmd;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * @param <D> type of violation to exclude, e.g. {@link Violation} or {@link Duplication}.
+ * @author Andreas Dangel
+ */
+public interface ExcludeFromFile<D>
+{
+    /**
+     * Loads the exclude definitions from the given file.
+     *
+     * @param excludeFromFailureFile the path to the properties file
+     * @throws MojoExecutionException if the properties file couldn't be loaded
+     */
+    void loadExcludeFromFailuresData( final String excludeFromFailureFile ) throws MojoExecutionException;
+
+    /**
+     * Determines how many exclusions are considered.
+     * @return the number of active exclusions
+     */
+    int countExclusions();
+
+    /**
+     * Checks whether the given violation is excluded. Note: the exclusions must have been
+     * loaded before via {@link #loadExcludeFromFailuresData(String)}.
+     *
+     * @param errorDetail the violation to check
+     * @return <code>true</code> if the violation should be excluded, <code>false</code>
otherwise.
+     */
+    boolean isExcludedFromFailure( final D errorDetail );
+
+}

Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ExcludeViolationsFromFile.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ExcludeViolationsFromFile.java?rev=1762991&r1=1762990&r2=1762991&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ExcludeViolationsFromFile.java
(original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ExcludeViolationsFromFile.java
Sat Oct  1 09:30:08 2016
@@ -43,16 +43,11 @@ import net.sourceforge.pmd.RuleViolation
  *
  * @author Andreas Dangel
  */
-public class ExcludeViolationsFromFile
+public class ExcludeViolationsFromFile implements ExcludeFromFile<Violation>
 {
     private Map<String, Set<String>> excludeFromFailureClasses = new HashMap<>();
-    
-    /**
-     * Loads the exclude definitions from the given file.
-     *
-     * @param excludeFromFailureFile the path to the properties file
-     * @throws MojoExecutionException if the properties file couldn't be loaded
-     */
+
+    @Override
     public void loadExcludeFromFailuresData( final String excludeFromFailureFile )
         throws MojoExecutionException
     {
@@ -96,13 +91,7 @@ public class ExcludeViolationsFromFile
         }
     }
 
-    /**
-     * Checks whether the given {@link Violation} is excluded. Note: the exclusions must
have been
-     * loaded before via {@link #loadExcludeFromFailuresData(String)}.
-     *
-     * @param errorDetail the violation to check
-     * @return <code>true</code> if the violation should be excluded, <code>false</code>
otherwise.
-     */
+    @Override
     public boolean isExcludedFromFailure( final Violation errorDetail )
     {
         final String className = extractClassName( errorDetail.getViolationPackage(), errorDetail.getViolationClass(),
@@ -124,10 +113,7 @@ public class ExcludeViolationsFromFile
         return isExcludedFromFailure( className, errorDetail.getRule().getName() );
     }
 
-    /**
-     * Determines how many exclusions are considered.
-     * @return the number of active exclusions
-     */
+    @Override
     public int countExclusions()
     {
         int result = 0;

Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojo.java?rev=1762991&r1=1762990&r2=1762991&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojo.java
(original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojo.java
Sat Oct  1 09:30:08 2016
@@ -63,6 +63,7 @@ public class PmdViolationCheckMojo
     @Parameter( property = "pmd.skip", defaultValue = "false" )
     private boolean skip;
 
+    /** Helper to exclude violations from the result. */
     private final ExcludeViolationsFromFile excludeFromFile = new ExcludeViolationsFromFile();
 
     /**



Mime
View raw message