Author: jvanzyl Date: Sat Dec 2 19:28:41 2006 New Revision: 481694 URL: http://svn.apache.org/viewvc?view=rev&rev=481694 Log: o using the plexus-resources component instead of the Locator copied in three plugins: clover, pmd, checkstyle. An experiment vicent and i tried here to measure the real cost of duplicated code.
Removed: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/Locator.java maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/LocatorTest.java Modified: maven/plugins/trunk/maven-pmd-plugin/pom.xml maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/PmdReportTest.java Modified: maven/plugins/trunk/maven-pmd-plugin/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/pom.xml?view=diff&rev=481694&r1=481693&r2=481694 ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/pom.xml (original) +++ maven/plugins/trunk/maven-pmd-plugin/pom.xml Sat Dec 2 19:28:41 2006 @@ -118,6 +118,11 @@ <artifactId>maven-plugin-testing-harness</artifactId> <version>1.0-beta-1</version> </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-resources</artifactId> + <version>1.0-alpha-4</version> + </dependency> </dependencies> <contributors> <contributor> 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?view=diff&rev=481694&r1=481693&r2=481694 ============================================================================== --- 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 Sat Dec 2 19:28:41 2006 @@ -52,6 +52,7 @@ import org.apache.maven.reporting.MavenReportException; import org.codehaus.doxia.sink.Sink; +import org.codehaus.plexus.resource.ResourceManager; /** * Implement the PMD report. @@ -64,7 +65,6 @@ public class PmdReport extends AbstractPmdReport { - /** * The target JDK to analyse based on. Should match the target used in the compiler plugin. Valid values are * currently <code>1.3</code>, <code>1.4</code>, <code>1.5</code>. @@ -104,25 +104,22 @@ */ private String sourceEncoding; - /** - * @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale) - */ + /** @component */ + private ResourceManager locator; + + /** @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale) */ public String getName( Locale locale ) { return getBundle( locale ).getString( "report.pmd.name" ); } - /** - * @see org.apache.maven.reporting.MavenReport#getDescription(java.util.Locale) - */ + /** @see org.apache.maven.reporting.MavenReport#getDescription(java.util.Locale) */ public String getDescription( Locale locale ) { return getBundle( locale ).getString( "report.pmd.description" ); } - /** - * @see org.apache.maven.reporting.AbstractMavenReport#executeReport(java.util.Locale) - */ + /** @see org.apache.maven.reporting.AbstractMavenReport#executeReport(java.util.Locale) */ public void executeReport( Locale locale ) throws MavenReportException { @@ -146,7 +143,6 @@ ruleContext.setReport( report ); reportSink.beginDocument(); - Locator locator = new Locator( getLog() ); RuleSetFactory ruleSetFactory = new RuleSetFactory(); ruleSetFactory.setMinimumPriority( this.minimumPriority ); RuleSet[] sets = new RuleSet[rulesets.length]; @@ -158,6 +154,7 @@ getLog().debug( "Preparing ruleset: " + set ); File ruleset = locator.resolveLocation( set, getLocationTemp( set ) ); InputStream rulesInput = new FileInputStream( ruleset ); + sets[idx] = ruleSetFactory.createRuleSet( rulesInput ); } } @@ -183,7 +180,6 @@ { File file = (File) i.next(); - // TODO: lazily call beginFile in case there are no rules reportSink.beginFile( file ); @@ -195,8 +191,7 @@ // PMD closes this Reader even though it did not open it so we have // to open a new one with every call to processFile(). Reader reader = hasEncoding ? new InputStreamReader( new FileInputStream( file ), - sourceEncoding ) - : new FileReader( file ); + sourceEncoding ) : new FileReader( file ); pmd.processFile( reader, sets[idx], ruleContext ); } catch ( UnsupportedEncodingException e1 ) @@ -205,18 +200,20 @@ } catch ( FileNotFoundException e2 ) { - getLog().warn("Error opening source file: " + file); - reportSink.ruleViolationAdded(new ProcessingErrorRuleViolation(file, e2.getLocalizedMessage()) ); + getLog().warn( "Error opening source file: " + file ); + reportSink.ruleViolationAdded( + new ProcessingErrorRuleViolation( file, e2.getLocalizedMessage() ) ); } catch ( Exception e3 ) { getLog().warn( "Failure executing PMD for: " + file, e3 ); - reportSink.ruleViolationAdded(new ProcessingErrorRuleViolation(file, e3.getLocalizedMessage()) ); + reportSink.ruleViolationAdded( + new ProcessingErrorRuleViolation( file, e3.getLocalizedMessage() ) ); } } reportSink.endFile( file ); } - + reportSink.endDocument(); if ( !isHtml() ) @@ -268,26 +265,24 @@ public PMD getPMD() { PMD pmd = new PMD(); - + if ( "1.5".equals( targetJdk ) ) { - pmd.setJavaVersion(SourceType.JAVA_15); + pmd.setJavaVersion( SourceType.JAVA_15 ); } else if ( "1.4".equals( targetJdk ) ) { - pmd.setJavaVersion(SourceType.JAVA_14); + pmd.setJavaVersion( SourceType.JAVA_14 ); } else if ( "1.3".equals( targetJdk ) ) { - pmd.setJavaVersion(SourceType.JAVA_13); + pmd.setJavaVersion( SourceType.JAVA_13 ); } - + return pmd; } - /** - * @see org.apache.maven.reporting.MavenReport#getOutputName() - */ + /** @see org.apache.maven.reporting.MavenReport#getOutputName() */ public String getOutputName() { return "pmd"; @@ -345,67 +340,81 @@ return renderer; } - - /** - * @author <a href="mailto:[EMAIL PROTECTED]">Doug Douglass</a> - */ - private static class ProcessingErrorRuleViolation implements IRuleViolation { - - private String filename; - - private String description; - - public ProcessingErrorRuleViolation(File file, String description) { - filename = file.getPath(); - this.description = description; - } - - public String getFilename() { - return this.filename; - } - - public int getBeginLine() { - return 0; - } - - public int getBeginColumn() { - return 0; - } - - public int getEndLine() { - return 0; - } - - public int getEndColumn() { - return 0; - } - - public Rule getRule() { - return null; - } - - public String getDescription() { - return this.description; - } - - public String getPackageName() { - return null; - } - - public String getMethodName() { - return null; - } - - public String getClassName() { - return null; - } - - public boolean isSuppressed() { - return false; - } - - public String getVariableName() { - return null; - } + + /** @author <a href="mailto:[EMAIL PROTECTED]">Doug Douglass</a> */ + private static class ProcessingErrorRuleViolation + implements IRuleViolation + { + + private String filename; + + private String description; + + public ProcessingErrorRuleViolation( File file, + String description ) + { + filename = file.getPath(); + this.description = description; + } + + public String getFilename() + { + return this.filename; + } + + public int getBeginLine() + { + return 0; + } + + public int getBeginColumn() + { + return 0; + } + + public int getEndLine() + { + return 0; + } + + public int getEndColumn() + { + return 0; + } + + public Rule getRule() + { + return null; + } + + public String getDescription() + { + return this.description; + } + + public String getPackageName() + { + return null; + } + + public String getMethodName() + { + return null; + } + + public String getClassName() + { + return null; + } + + public boolean isSuppressed() + { + return false; + } + + public String getVariableName() + { + return null; + } } } 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?view=diff&rev=481694&r1=481693&r2=481694 ============================================================================== --- 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 Sat Dec 2 19:28:41 2006 @@ -87,6 +87,7 @@ { File testPom = new File( getBasedir(), "src/test/resources/unit/custom-configuration/custom-configuration-plugin-config.xml" ); + PmdReport mojo = (PmdReport) lookupMojo( "pmd", testPom ); mojo.execute();