Author: adangel Date: Sun Aug 7 09:47:03 2016 New Revision: 1755431 URL: http://svn.apache.org/viewvc?rev=1755431&view=rev Log: Remove dummy rule - if no rulesets are specified, PMD is not executed now
Removed: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/rules/DummyRule.java maven/plugins/trunk/maven-pmd-plugin/src/main/resources/rulesets/dummy.xml Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java 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=1755431&r1=1755430&r2=1755431&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 Sun Aug 7 09:47:03 2016 @@ -304,20 +304,13 @@ public class PmdReport renderer = new PmdCollectingRenderer(); PMDConfiguration pmdConfiguration = getPMDConfiguration(); - RuleContext ruleContext = new RuleContext(); - - RuleSetFactory ruleSetFactory = new RuleSetFactory(); - ruleSetFactory.setMinimumPriority( RulePriority.valueOf( this.minimumPriority ) ); - - // Workaround for https://sourceforge.net/p/pmd/bugs/1155/: add a dummy ruleset. - String[] presentRulesets = rulesets.length > 0 ? rulesets : new String[] { "/rulesets/dummy.xml" }; - String[] sets = new String[presentRulesets.length]; + String[] sets = new String[rulesets.length]; try { - for ( int idx = 0; idx < presentRulesets.length; idx++ ) + for ( int idx = 0; idx < rulesets.length; idx++ ) { - String set = presentRulesets[idx]; + String set = rulesets[idx]; getLog().debug( "Preparing ruleset: " + set ); RuleSetReferenceId id = new RuleSetReferenceId( set ); File ruleset = locator.getResourceAsFile( id.getRuleSetFileName(), getLocationTemp( set ) ); @@ -371,25 +364,13 @@ public class PmdReport dataSources.add( new FileDataSource( f ) ); } - try + if ( sets.length > 0 ) { - getLog().debug( "Executing PMD..." ); - PMD.processFiles( pmdConfiguration, ruleSetFactory, dataSources, ruleContext, - Arrays.<Renderer>asList( renderer ) ); - - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "PMD finished. Found " + renderer.getViolations().size() + " violations." ); - } + processFilesWithPMD( pmdConfiguration, dataSources ); } - catch ( Exception e ) + else { - String message = "Failure executing PMD: " + e.getLocalizedMessage(); - if ( !skipPmdError ) - { - throw new MavenReportException( message, e ); - } - getLog().warn( message, e ); + getLog().debug( "Skipping PMD execution as no rulesets are defined." ); } if ( renderer.hasErrors() ) @@ -424,6 +405,35 @@ public class PmdReport } } + private void processFilesWithPMD( PMDConfiguration pmdConfiguration, List<DataSource> dataSources ) + throws MavenReportException + { + RuleSetFactory ruleSetFactory = new RuleSetFactory(); + ruleSetFactory.setMinimumPriority( RulePriority.valueOf( this.minimumPriority ) ); + RuleContext ruleContext = new RuleContext(); + + try + { + getLog().debug( "Executing PMD..." ); + PMD.processFiles( pmdConfiguration, ruleSetFactory, dataSources, ruleContext, + Arrays.<Renderer>asList( renderer ) ); + + if ( getLog().isDebugEnabled() ) + { + getLog().debug( "PMD finished. Found " + renderer.getViolations().size() + " violations." ); + } + } + catch ( Exception e ) + { + String message = "Failure executing PMD: " + e.getLocalizedMessage(); + if ( !skipPmdError ) + { + throw new MavenReportException( message, e ); + } + getLog().warn( message, e ); + } + } + private Report generateReport( Locale locale ) throws MavenReportException {