Author: dkulp
Date: Sat Mar 10 20:19:49 2007
New Revision: 516848

URL: http://svn.apache.org/viewvc?view=rev&rev=516848
Log:
MPMD-28, MPMD-52, MPMD-44, MPDM-53
* Add maven.pmd.skip and maven.cpd.skip flags
* Added aggregate mode (with support for xrefs)
* Workaround bug in ResourceManager in reporting mode



Modified:
    
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdReport.java
    
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/CpdReport.java
    
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReportGenerator.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/PmdReport.java
    
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReportListener.java
    
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojo.java
    
maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/PmdReportTest.java
    
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failandwarnonpriority-plugin-config.xml
    
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failonpriority-plugin-config.xml
    
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-notfailonviolation-plugin-config.xml

Modified: 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdReport.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdReport.java?view=diff&rev=516848&r1=516847&r2=516848
==============================================================================
--- 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdReport.java
 (original)
+++ 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdReport.java
 Sat Mar 10 20:19:49 2007
@@ -25,6 +25,8 @@
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
 
 import org.apache.maven.artifact.handler.ArtifactHandler;
 import org.apache.maven.model.ReportPlugin;
@@ -99,6 +101,13 @@
      * @parameter default-value="${project.reporting.outputDirectory}/xref"
      */
     private File xrefLocation;
+    
+    /**
+     * Location of the Test Xrefs to link to.
+     *
+     * @parameter 
default-value="${project.reporting.outputDirectory}/xref-test"
+     */
+    private File xrefTestLocation;
 
     /**
      * A list of files to exclude from checking. Can contain ant-style 
wildcards and double wildcards.
@@ -154,6 +163,22 @@
      */
     protected boolean includeTests;
     
+    /**
+     * Whether to build an aggregated report at the root, or build individual 
reports.
+     *
+     * @parameter expression="${aggregate}" default-value="false"
+     * @since 2.2
+     */
+    protected boolean aggregate;
+        
+    
+    /**
+     * The projects in the reactor for aggregation report.
+     *
+     * @parameter expression="${reactorProjects}"
+     * @readonly
+     */
+    protected List reactorProjects;
 
     /**
      * @see org.apache.maven.reporting.AbstractMavenReport#getProject()
@@ -171,18 +196,20 @@
         return siteRenderer;
     }
 
-    protected String constructXRefLocation()
+    protected String constructXRefLocation( boolean test )
     {
         String location = null;
         if ( linkXRef )
         {
-            String relativePath = PathTool.getRelativePath( outputDirectory, 
xrefLocation.getAbsolutePath() );
+            File xrefLoc = test ? xrefTestLocation : xrefLocation;
+            
+            String relativePath = PathTool.getRelativePath( outputDirectory, 
xrefLoc.getAbsolutePath() );
             if ( StringUtils.isEmpty( relativePath ) )
             {
                 relativePath = ".";
             }
-            relativePath = relativePath + "/" + xrefLocation.getName();
-            if ( xrefLocation.exists() )
+            relativePath = relativePath + "/" + xrefLoc.getName();
+            if ( xrefLoc.exists() )
             {
                 // XRef was already generated by manual execution of a 
lifecycle binding
                 location = relativePath;
@@ -213,13 +240,20 @@
     /**
      * Convenience method to get the list of files where the PMD tool will be 
executed
      *
-     * @param includes contains the concatenated list of files to be included
      * @return a List of the files where the PMD tool will be executed
      * @throws java.io.IOException
      */
-    protected List getFilesToProcess( )
+    protected Map getFilesToProcess( )
         throws IOException
     {
+        String sourceXref = constructXRefLocation( false );
+        String testXref = includeTests ? constructXRefLocation( true ) : "";
+        
+        if ( aggregate && !project.isExecutionRoot() )
+        {
+            return Collections.EMPTY_MAP;
+        }
+
         if ( excludeRoots == null )
         {
             excludeRoots = Collections.EMPTY_LIST;
@@ -237,9 +271,29 @@
             }
         }
         
+        List directories = new ArrayList(compileSourceRoots);
+        List testdirectories = new ArrayList();
+        if ( includeTests )
+        {
+            testdirectories.addAll(testSourceRoots);
+        }
+        if ( aggregate )
+        {
+            for ( Iterator i = reactorProjects.iterator(); i.hasNext(); )
+            {
+                MavenProject localProject = (MavenProject) i.next();
+                directories.addAll(localProject.getCompileSourceRoots());
+                if ( includeTests )
+                {
+                    
testdirectories.addAll(localProject.getTestCompileSourceRoots());
+                }
+            }
+  
+        }
+        
         String excluding = getIncludeExcludeString( excludes );
         String including = getIncludeExcludeString( includes );
-        List files = new ArrayList();
+        Map files = new TreeMap();
         
         if ( "".equals(including) )
         {
@@ -262,7 +316,7 @@
         }
         getLog().debug( "Excluded files: '" + excludesStr + "'" );
 
-        for ( Iterator it = compileSourceRoots.iterator(); it.hasNext();)
+        for ( Iterator it = directories.iterator(); it.hasNext();)
         {
             String root = (String)it.next();
             File sourceDirectory = new File(root);
@@ -270,25 +324,28 @@
                 && sourceDirectory.isDirectory()
                 && !excludeRootFiles.contains(sourceDirectory))
             {
-                files.addAll( FileUtils.getFiles( sourceDirectory, including, 
excludesStr.toString() ) );
+                List newfiles = FileUtils.getFiles( sourceDirectory, 
including, excludesStr.toString() );
+                for ( Iterator it2 = newfiles.iterator(); it2.hasNext(); )
+                {
+                    files.put( it2.next(), new Object[] { sourceDirectory , 
sourceXref });
+                }
             }
-        }
-        
-        if ( includeTests )
+        }        
+        for ( Iterator it = testdirectories.iterator(); it.hasNext();)
         {
-            for ( Iterator it = testSourceRoots.iterator(); it.hasNext();)
+            String root = (String)it.next();
+            File testDirectory = new File(root);
+            if ( testDirectory.exists()
+                && testDirectory.isDirectory()
+                && !excludeRootFiles.contains(testDirectory))
             {
-                String root = (String)it.next();
-                File sourceDirectory = new File(root);
-                
-                if ( sourceDirectory.exists()
-                    && sourceDirectory.isDirectory()
-                    && !excludeRootFiles.contains(sourceDirectory))
+                List newfiles = FileUtils.getFiles( testDirectory, including, 
excludesStr.toString() );
+                for ( Iterator it2 = newfiles.iterator(); it2.hasNext(); )
                 {
-                    files.addAll( FileUtils.getFiles( sourceDirectory, 
including, excludesStr.toString() ) );
+                    files.put( it2.next(), new Object[] { testDirectory , 
testXref });
                 }
             }
-        }
+        }        
         return files;
     }
 
@@ -328,9 +385,30 @@
      */
     public boolean canGenerateReport()
     {
-        ArtifactHandler artifactHandler = 
project.getArtifact().getArtifactHandler();
-        return "java".equals( artifactHandler.getLanguage() ) &&
-            new File( project.getBuild().getSourceDirectory() ).exists();
+        if ( aggregate && !project.isExecutionRoot() )
+        {
+            return false;
+        }
+
+        // if format is XML, we need to output it even if the file list is 
empty
+        // so the "check" goals can check for failures
+        if ( "xml".equals(format) )
+        {
+            return true;
+        }
+        try 
+        {
+            Map filesToProcess = getFilesToProcess( );
+            if ( filesToProcess.isEmpty() )
+            {
+                return false;
+            }
+        }
+        catch ( IOException e )
+        {
+            getLog().error(e);
+        }
+        return true;
     }
 
     /**

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?view=diff&rev=516848&r1=516847&r2=516848
==============================================================================
--- 
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 Mar 10 20:19:49 2007
@@ -24,6 +24,7 @@
 import java.io.FileReader;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -32,6 +33,7 @@
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.util.xml.pull.MXParser;
 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@@ -74,25 +76,38 @@
     private String language;
 
     /**
-     * The project source directory.
-     * 
-     * @parameter expression="${project.build.sourceDirectory}"
-     * @required
-     * @readonly
+     * Whether to build an aggregated report at the root, or build individual 
reports.
+     *
+     * @parameter expression="${aggregate}" default-value="false"
+     * @since 2.2
      */
-    private File sourceDirectory;
-
+    protected boolean aggregate;
+    
     /**
      * Print details of check failures to build output
      * 
      * @parameter expression="${pmd.verbose}" default-value="false"
      */
     private boolean verbose;
+    
+    /**
+     * The project to analyse.
+     *
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    protected MavenProject project;
 
     protected void executeCheck( String filename, String tagName, String key, 
int failurePriority )
         throws MojoFailureException, MojoExecutionException
     {
-        if ( "java".equals( language ) && sourceDirectory.exists() )
+        if ( aggregate && !project.isExecutionRoot() )
+        {
+            return;
+        }
+        
+        if ( "java".equals( language ) || aggregate )
         {
             File outputFile = new File( targetDirectory, filename );
             if ( outputFile.exists() )

Modified: 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReport.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReport.java?view=diff&rev=516848&r1=516847&r2=516848
==============================================================================
--- 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReport.java
 (original)
+++ 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReport.java
 Sat Mar 10 20:19:49 2007
@@ -23,8 +23,10 @@
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 import java.util.ResourceBundle;
 import java.util.Collections;
 
@@ -88,13 +90,13 @@
         if ( !skip && canGenerateReport() )
         {         
             CPD cpd = new CPD(minimumTokens, new JavaLanguage());
+            Map files = null;
             try
             {
-                List files = getFilesToProcess( );
-                Collections.sort( files );
-                for ( int i = 0; i < files.size(); i++ )
+                files = getFilesToProcess( );
+                for ( Iterator it = files.keySet().iterator(); it.hasNext(); ) 
                 {
-                    cpd.add( (File) files.get( i ) );
+                    cpd.add( (File) it.next() );
                 }
             }
             catch (IOException e)
@@ -103,9 +105,8 @@
             }
             cpd.go();
 
-            String src = getProject().getBuild().getSourceDirectory();
             CpdReportGenerator gen =
-                new CpdReportGenerator( getSink(), src, getBundle( locale ), 
constructXRefLocation() );
+                new CpdReportGenerator( getSink(), files, getBundle( locale ) 
);
             gen.generate( cpd.getMatches() );
 
             if ( !isHtml() )

Modified: 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReportGenerator.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReportGenerator.java?view=diff&rev=516848&r1=516847&r2=516848
==============================================================================
--- 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReportGenerator.java
 (original)
+++ 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReportGenerator.java
 Sat Mar 10 20:19:49 2007
@@ -19,7 +19,9 @@
  * under the License.
  */
 
+import java.io.File;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.ResourceBundle;
 
 import net.sourceforge.pmd.PMD;
@@ -38,18 +40,15 @@
 {
     private Sink sink;
 
-    private String sourceDirectory;
+    private Map fileMap;
 
     private ResourceBundle bundle;
 
-    private String xrefLocation;
-
-    public CpdReportGenerator( Sink sink, String sourceDirectory, 
ResourceBundle bundle, String xrefLocation )
+    public CpdReportGenerator( Sink sink, Map fileMap, ResourceBundle bundle )
     {
         this.sink = sink;
-        this.sourceDirectory = sourceDirectory;
+        this.fileMap = fileMap;
         this.bundle = bundle;
-        this.xrefLocation = xrefLocation;
     }
 
     /**
@@ -117,10 +116,20 @@
         {
             Match match = (Match) matches.next();
             String filename1 = match.getFirstMark().getTokenSrcID();
-            filename1 = StringUtils.substring( filename1, 
sourceDirectory.length() + 1 );
+            
+            File file = new File( filename1 );
+            Object fileInfo[] = (Object[]) fileMap.get( file );
+            File sourceDirectory = (File) fileInfo[0];
+            String xrefLocation = (String) fileInfo[1];
+            
+            filename1 = StringUtils.substring( filename1, 
sourceDirectory.getAbsolutePath().length() + 1 );
 
             String filename2 = match.getSecondMark().getTokenSrcID();
-            filename2 = StringUtils.substring( filename2, 
sourceDirectory.length() + 1 );
+            file = new File( filename2 );
+            fileInfo = (Object[]) fileMap.get( file );
+            sourceDirectory = (File) fileInfo[0];
+            String xrefLocation2 = (String) fileInfo[1];
+            filename2 = StringUtils.substring( filename2, 
sourceDirectory.getAbsolutePath().length() + 1 );
 
             String code = match.getSourceCodeSlice();
             int line1 = match.getFirstMark().getBeginLine();
@@ -166,7 +175,7 @@
             sink.tableCell();
             if ( xrefLocation != null )
             {
-                sink.link( xrefLocation + "/" + filename2.replaceAll( 
"\\.java$", ".html" ).replace( '\\', '/' ) + "#" +
+                sink.link( xrefLocation2 + "/" + filename2.replaceAll( 
"\\.java$", ".html" ).replace( '\\', '/' ) + "#" +
                     line2 );
             }
             sink.text( String.valueOf( line2 ) );

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?view=diff&rev=516848&r1=516847&r2=516848
==============================================================================
--- 
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 Mar 10 20:19:49 2007
@@ -20,6 +20,7 @@
  */
 
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.maven.plugin.MojoExecutionException;
@@ -37,13 +38,25 @@
 public class CpdViolationCheckMojo
     extends AbstractPmdViolationCheckMojo
 {
+
+    /**
+     * Skip the CPD violation checks.  Most useful on the command line
+     * via "-Dmaven.cpd.skip=true".
+     *
+     * @parameter expression="${maven.cpd.skip}" default-value="false"
+     */
+    private boolean skip;
+    
     /**
      * @see org.apache.maven.plugin.AbstractMojo#execute()
      */
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
-        executeCheck( "cpd.xml", "duplication", "CPD duplication",10 );
+        if ( !skip )
+        {
+            executeCheck( "cpd.xml", "duplication", "CPD duplication", 0 );
+        }
     }
     
     /**
@@ -54,7 +67,6 @@
     protected void printError( Map item, String severity )
     {
         // TODO Auto-generated method stub
-        
     }
 
     protected Map getErrorDetails( XmlPullParser xpp )

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=516848&r1=516847&r2=516848
==============================================================================
--- 
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 Mar 10 20:19:49 2007
@@ -33,6 +33,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 import java.util.ResourceBundle;
 import java.util.Collections;
 
@@ -53,6 +54,7 @@
 import org.apache.maven.reporting.MavenReportException;
 import org.codehaus.doxia.sink.Sink;
 import org.codehaus.plexus.resource.ResourceManager;
+import org.codehaus.plexus.resource.loader.FileResourceLoader;
 
 /**
  * Implement the PMD report.
@@ -104,9 +106,14 @@
      */
     private String sourceEncoding;
 
-    /** @component */
+    /**
+     * @component
+     * @required
+     * @readonly
+     */
     private ResourceManager locator;
-
+    
+    
     /** @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale) 
*/
     public String getName( Locale locale )
     {
@@ -131,13 +138,7 @@
             RuleContext ruleContext = new RuleContext();
             Report report = new Report();
             // TODO: use source roots instead
-            String sourceDirectory = project.getBuild().getSourceDirectory();
-            PmdReportListener reportSink = new PmdReportListener( sink, 
sourceDirectory, getBundle( locale ) );
-            String location = constructXRefLocation();
-            if ( location != null )
-            {
-                reportSink.setXrefLocation( location );
-            }
+            PmdReportListener reportSink = new PmdReportListener( sink, 
getBundle( locale ) );
 
             report.addListener( reportSink );
             ruleContext.setReport( report );
@@ -153,7 +154,20 @@
                     String set = rulesets[idx];
                     getLog().debug( "Preparing ruleset: " + set );
                     File ruleset = locator.resolveLocation( set, 
getLocationTemp( set ) );
-                    InputStream rulesInput = new FileInputStream( ruleset );
+                    InputStream rulesInput = null;
+                    if ( null == ruleset)
+                    {
+                        //  workaround bug in resource manager when run in 
reporting mode
+                        rulesInput = 
this.getClass().getClassLoader().getResourceAsStream( set );
+                    }
+                    else
+                    {
+                        rulesInput = new FileInputStream( ruleset );
+                    }
+                    if ( null == rulesInput )
+                    {
+                        throw new MavenReportException( "Cold not resolve " + 
set );
+                    }
 
                     sets[idx] = ruleSetFactory.createRuleSet( rulesInput );
                 }
@@ -165,24 +179,28 @@
 
             boolean hasEncoding = sourceEncoding != null;
 
-            List files;
+            Map files;
             try
             {
                 files = getFilesToProcess( );
-                Collections.sort( files );
             }
             catch ( IOException e )
             {
-                throw new MavenReportException( "Can't parse " + 
sourceDirectory, e );
+                throw new MavenReportException( "Can't get file list", e );
             }
 
-            for ( Iterator i = files.iterator(); i.hasNext(); )
+            for ( Iterator i = files.entrySet().iterator(); i.hasNext(); )
             {
-                File file = (File) i.next();
+                Map.Entry entry = (Map.Entry) i.next();
+                File file = (File) entry.getKey();
+                Object fileInfo[] = (Object[]) entry.getValue();
+                File sourceDir = (File) fileInfo[0];
+                String xrefLoc = (String) fileInfo[1];
 
                 // TODO: lazily call beginFile in case there are no rules
 
-                reportSink.beginFile( file );
+                reportSink.beginFile( file , sourceDir );
+                reportSink.setXrefLocation( xrefLoc );
                 ruleContext.setSourceCodeFilename( file.getAbsolutePath() );
                 for ( int idx = 0; idx < rulesets.length; idx++ )
                 {

Modified: 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReportListener.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReportListener.java?view=diff&rev=516848&r1=516847&r2=516848
==============================================================================
--- 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReportListener.java
 (original)
+++ 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReportListener.java
 Sat Mar 10 20:19:49 2007
@@ -46,8 +46,6 @@
 {
     private Sink sink;
 
-    private String sourceDirectory;
-
     private String currentFilename;
 
     private boolean fileInitialized;
@@ -63,10 +61,9 @@
 
     //private List metrics = new ArrayList();
 
-    public PmdReportListener( Sink sink, String sourceDirectory, 
ResourceBundle bundle )
+    public PmdReportListener( Sink sink, ResourceBundle bundle )
     {
         this.sink = sink;
-        this.sourceDirectory = sourceDirectory;
         this.bundle = bundle;
     }
 
@@ -194,9 +191,9 @@
         // TODO files summary
     }
 
-    public void beginFile( File file )
+    public void beginFile( File file, File sourceDir )
     {
-        currentFilename = StringUtils.substring( file.getAbsolutePath(), 
sourceDirectory.length() + 1 );
+        currentFilename = StringUtils.substring( file.getAbsolutePath(), 
sourceDir.getAbsolutePath().length() + 1 );
         currentFilename = StringUtils.replace( currentFilename, "\\", "/" );
         fileInitialized = false;
     }

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?view=diff&rev=516848&r1=516847&r2=516848
==============================================================================
--- 
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 Mar 10 20:19:49 2007
@@ -50,12 +50,23 @@
     private int failurePriority;
 
     /**
+     * Skip the PMD checks.  Most useful on the command line
+     * via "-Dmaven.pmd.skip=true".
+     *
+     * @parameter expression="${maven.pmd.skip}" default-value="false"
+     */
+    private boolean skip;
+    
+    /**
      * @see org.apache.maven.plugin.AbstractMojo#execute()
      */
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
-        executeCheck( "pmd.xml", "violation", "PMD violation", failurePriority 
);
+        if ( !skip )
+        {
+            executeCheck( "pmd.xml", "violation", "PMD violation", 
failurePriority );
+        }
     }
 
     /**

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=516848&r1=516847&r2=516848
==============================================================================
--- 
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 Mar 10 20:19:49 2007
@@ -72,6 +72,7 @@
         String str =
             readFile( new File( getBasedir(), 
"target/test/unit/default-configuration/target/site/pmd.html" ) );
 
+        
         assertTrue( str.indexOf( "/xref/def/configuration/App.html#31" ) != -1 
);
 
         assertTrue( str.indexOf( "/xref/def/configuration/AppSample.html#45" ) 
!= -1 );

Modified: 
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failandwarnonpriority-plugin-config.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failandwarnonpriority-plugin-config.xml?view=diff&rev=516848&r1=516847&r2=516848
==============================================================================
--- 
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failandwarnonpriority-plugin-config.xml
 (original)
+++ 
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failandwarnonpriority-plugin-config.xml
 Sat Mar 10 20:19:49 2007
@@ -33,7 +33,6 @@
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-pmd-plugin</artifactId>
         <configuration>
-           
<sourceDirectory>${basedir}/src/test/resources/unit/default-configuration</sourceDirectory>
            
<targetDirectory>${basedir}/target/test/unit/default-configuration/target</targetDirectory>
            <failOnViolation>true</failOnViolation>
            <failurePriority>3</failurePriority>  

Modified: 
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failonpriority-plugin-config.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failonpriority-plugin-config.xml?view=diff&rev=516848&r1=516847&r2=516848
==============================================================================
--- 
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failonpriority-plugin-config.xml
 (original)
+++ 
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-failonpriority-plugin-config.xml
 Sat Mar 10 20:19:49 2007
@@ -34,7 +34,6 @@
         <artifactId>maven-pmd-plugin</artifactId>
         <configuration>
           <!-- project 
implementation="org.apache.maven.plugin.pmd.stubs.DefaultConfigurationMavenProjectStub"/-->
-          
<sourceDirectory>${basedir}/src/test/resources/unit/default-configuration</sourceDirectory>
           
<targetDirectory>${basedir}/target/test/unit/default-configuration/target</targetDirectory>
           <failOnViolation>true</failOnViolation>
           <failurePriority>1</failurePriority>  

Modified: 
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-notfailonviolation-plugin-config.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-notfailonviolation-plugin-config.xml?view=diff&rev=516848&r1=516847&r2=516848
==============================================================================
--- 
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-notfailonviolation-plugin-config.xml
 (original)
+++ 
maven/plugins/trunk/maven-pmd-plugin/src/test/resources/unit/default-configuration/pmd-check-notfailonviolation-plugin-config.xml
 Sat Mar 10 20:19:49 2007
@@ -34,7 +34,6 @@
         <artifactId>maven-pmd-plugin</artifactId>
         <configuration>
           <!-- project 
implementation="org.apache.maven.plugin.pmd.stubs.DefaultConfigurationMavenProjectStub"/-->
-          
<sourceDirectory>${basedir}/src/test/resources/unit/default-configuration</sourceDirectory>
           
<targetDirectory>${basedir}/target/test/unit/default-configuration/target</targetDirectory>
           <failOnViolation>false</failOnViolation>
             <verbose>false</verbose>  


Reply via email to