Author: vsiveton
Date: Thu Aug 13 11:57:24 2009
New Revision: 803850

URL: http://svn.apache.org/viewvc?rev=803850&view=rev
Log:
MPMD-102: Bump to Doxia 1.0

o using doxia 1.0
o upgrade code

Added:
    
maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/AbstractPmdReportTest.java
   (with props)
Modified:
    maven/plugins/trunk/maven-pmd-plugin/pom.xml
    
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/CpdReportGenerator.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/test/java/org/apache/maven/plugin/pmd/CpdReportTest.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?rev=803850&r1=803849&r2=803850&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-pmd-plugin/pom.xml Thu Aug 13 11:57:24 2009
@@ -61,7 +61,8 @@
   </issueManagement>
 
   <properties>
-    <mavenVersion>2.0</mavenVersion>
+    <mavenVersion>2.0.6</mavenVersion>
+    <doxiaVersion>1.0</doxiaVersion>
   </properties>
 
   <dependencies>
@@ -89,7 +90,24 @@
     <dependency>
       <groupId>org.apache.maven.reporting</groupId>
       <artifactId>maven-reporting-impl</artifactId>
-      <version>${mavenVersion}</version>
+      <version>2.0.4.2</version>
+    </dependency>
+
+    <!-- doxia -->
+    <dependency>
+      <groupId>org.apache.maven.doxia</groupId>
+      <artifactId>doxia-sink-api</artifactId>
+      <version>${doxiaVersion}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.doxia</groupId>
+      <artifactId>doxia-decoration-model</artifactId>
+      <version>${doxiaVersion}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.doxia</groupId>
+      <artifactId>doxia-site-renderer</artifactId>
+      <version>${doxiaVersion}</version>
     </dependency>
 
     <!-- plexus -->
@@ -111,6 +129,13 @@
       <version>4.2.4</version>
     </dependency>
 
+    <!-- misc -->
+    <dependency>
+      <groupId>xerces</groupId>
+      <artifactId>xmlParserAPIs</artifactId>
+      <version>2.6.2</version>
+    </dependency>
+
     <!-- test -->
     <dependency>
       <groupId>org.apache.maven.shared</groupId>

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?rev=803850&r1=803849&r2=803850&view=diff
==============================================================================
--- 
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
 Thu Aug 13 11:57:24 2009
@@ -32,10 +32,10 @@
 import java.util.Map;
 import java.util.TreeMap;
 
+import org.apache.maven.doxia.siterenderer.Renderer;
 import org.apache.maven.model.ReportPlugin;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.reporting.AbstractMavenReport;
-import org.codehaus.doxia.site.renderer.SiteRenderer;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.PathTool;
 import org.codehaus.plexus.util.StringUtils;
@@ -60,7 +60,7 @@
      * The output directory for the final HTML report. Note that this 
parameter is only evaluated if the goal is run
      * directly from the command line or during the default lifecycle. If the 
goal is run indirectly as part of a site
      * generation, the output directory configured in the Maven Site Plugin is 
used instead.
-     * 
+     *
      * @parameter expression="${project.reporting.outputDirectory}"
      * @required
      */
@@ -71,7 +71,7 @@
      *
      * @component
      */
-    private SiteRenderer siteRenderer;
+    private Renderer siteRenderer;
 
     /**
      * The project to analyse.
@@ -106,7 +106,7 @@
      * @parameter default-value="${project.reporting.outputDirectory}/xref"
      */
     private File xrefLocation;
-    
+
     /**
      * Location of the Test Xrefs to link to.
      *
@@ -119,21 +119,21 @@
      * exclusion patterns only operate on the path of a source file relative 
to its source root directory. In other
      * words, files are excluded based on their package and/or class name. If 
you want to exclude entire source root
      * directories, use the parameter <code>excludeRoots</code> instead.
-     * 
+     *
      * @parameter
      * @since 2.2
      */
     private String[] excludes;
 
     /**
-     * A list of files to include from checking. Can contain Ant-style 
wildcards and double wildcards.  
+     * A list of files to include from checking. Can contain Ant-style 
wildcards and double wildcards.
      * Defaults to **\/*.java.
      *
      * @parameter
      * @since 2.2
      */
     private String[] includes;
-    
+
     /**
      * The directories containing the sources to be compiled.
      *
@@ -142,7 +142,7 @@
      * @readonly
      */
     private List compileSourceRoots;
-    
+
     /**
      * The directories containing the test-sources to be compiled.
      *
@@ -151,7 +151,7 @@
      * @readonly
      */
     private List testSourceRoots;
-    
+
     /**
      * The project source directories that should be excluded.
      *
@@ -159,7 +159,7 @@
      * @since 2.2
      */
     private File[] excludeRoots;
-    
+
     /**
      * Run PMD on the tests.
      *
@@ -167,7 +167,7 @@
      * @since 2.2
      */
     protected boolean includeTests;
-    
+
     /**
      * Whether to build an aggregated report at the root, or build individual 
reports.
      *
@@ -175,8 +175,8 @@
      * @since 2.2
      */
     protected boolean aggregate;
-        
-    
+
+
     /**
      * The projects in the reactor for aggregation report.
      *
@@ -196,7 +196,7 @@
     /**
      * @see org.apache.maven.reporting.AbstractMavenReport#getSiteRenderer()
      */
-    protected SiteRenderer getSiteRenderer()
+    protected Renderer getSiteRenderer()
     {
         return siteRenderer;
     }
@@ -207,7 +207,7 @@
         if ( linkXRef )
         {
             File xrefLoc = test ? xrefTestLocation : xrefLocation;
-            
+
             String relativePath = PathTool.getRelativePath( 
outputDirectory.getAbsolutePath(), xrefLoc.getAbsolutePath() );
             if ( StringUtils.isEmpty( relativePath ) )
             {
@@ -253,7 +253,7 @@
     {
         String sourceXref = constructXRefLocation( false );
         String testXref = includeTests ? constructXRefLocation( true ) : "";
-        
+
         if ( aggregate && !project.isExecutionRoot() )
         {
             return Collections.EMPTY_MAP;
@@ -264,8 +264,8 @@
             excludeRoots = new File[0];
         }
         Collection excludeRootFiles = new HashSet( excludeRoots.length );
-        
-        for ( int i = 0; i < excludeRoots.length; i++ ) 
+
+        for ( int i = 0; i < excludeRoots.length; i++ )
         {
             File file = excludeRoots[i];
             if ( file.isDirectory() )
@@ -273,16 +273,16 @@
                 excludeRootFiles.add( file );
             }
         }
-        
+
         List directories = new ArrayList();
-        
+
         for ( Iterator i = compileSourceRoots.iterator(); i.hasNext(); )
         {
             String root = (String) i.next();
             File sroot = new File( root );
             directories.add( new PmdFileInfo( project, sroot, sourceXref ) );
         }
-        
+
         if ( includeTests )
         {
             for ( Iterator i = testSourceRoots.iterator(); i.hasNext(); )
@@ -313,9 +313,9 @@
                     }
                 }
             }
-  
+
         }
-        
+
         String excluding = getExcludes();
         getLog().debug( "Exclusions: " + excluding );
         String including = getIncludes();
@@ -335,14 +335,14 @@
                     files.put( it2.next(), finfo );
                 }
             }
-        }        
-                
+        }
+
         return files;
     }
 
     /**
      * Gets the comma separated list of effective include patterns.
-     * 
+     *
      * @return The comma separated list of effective include patterns, never 
<code>null</code>.
      */
     private String getIncludes()
@@ -361,7 +361,7 @@
 
     /**
      * Gets the comma separated list of effective exclude patterns.
-     * 
+     *
      * @return The comma separated list of effective exclude patterns, never 
<code>null</code>.
      */
     private String getExcludes()
@@ -400,7 +400,7 @@
         {
             return true;
         }
-        try 
+        try
         {
             Map filesToProcess = getFilesToProcess( );
             if ( filesToProcess.isEmpty() )

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?rev=803850&r1=803849&r2=803850&view=diff
==============================================================================
--- 
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
 Thu Aug 13 11:57:24 2009
@@ -27,8 +27,8 @@
 import net.sourceforge.pmd.PMD;
 import net.sourceforge.pmd.cpd.Match;
 
+import org.apache.maven.doxia.sink.Sink;
 import org.apache.maven.project.MavenProject;
-import org.codehaus.doxia.sink.Sink;
 import org.codehaus.plexus.util.StringUtils;
 
 /**
@@ -44,7 +44,7 @@
     private Map fileMap;
 
     private ResourceBundle bundle;
-    
+
     private boolean aggregate;
 
     public CpdReportGenerator( Sink sink, Map fileMap, ResourceBundle bundle, 
boolean aggregate )
@@ -113,20 +113,22 @@
 
         if ( !matches.hasNext() )
         {
+            sink.paragraph();
             sink.text( bundle.getString( "report.cpd.noProblems" ) );
+            sink.paragraph_();
         }
 
         while ( matches.hasNext() )
         {
             Match match = (Match) matches.next();
             String filename1 = match.getFirstMark().getTokenSrcID();
-            
+
             File file = new File( filename1 );
             PmdFileInfo fileInfo = (PmdFileInfo) fileMap.get( file );
             File sourceDirectory = fileInfo.getSourceDirectory();
             String xrefLocation = fileInfo.getXrefLocation();
             MavenProject projectFile1 = fileInfo.getProject();
-            
+
             filename1 = StringUtils.substring( filename1, 
sourceDirectory.getAbsolutePath().length() + 1 );
 
             String filename2 = match.getSecondMark().getTokenSrcID();
@@ -141,7 +143,6 @@
             int line1 = match.getFirstMark().getBeginLine();
             int line2 = match.getSecondMark().getBeginLine();
 
-            sink.paragraph();
             sink.table();
             sink.tableRow();
             sink.tableHeaderCell();
@@ -173,7 +174,7 @@
 
             if ( xrefLocation != null )
             {
-                sink.link( xrefLocation + "/" + filename1.replaceAll( 
"\\.java$", ".html" ).replace( '\\', '/' ) 
+                sink.link( xrefLocation + "/" + filename1.replaceAll( 
"\\.java$", ".html" ).replace( '\\', '/' )
                            + "#" + line1 );
             }
             sink.text( String.valueOf( line1 ) );
@@ -197,12 +198,12 @@
                 sink.tableCell_();
             }
             sink.tableCell();
-            
-            
-            
+
+
+
             if ( xrefLocation != null )
             {
-                sink.link( xrefLocation2 + "/" + filename2.replaceAll( 
"\\.java$", ".html" ).replace( '\\', '/' ) 
+                sink.link( xrefLocation2 + "/" + filename2.replaceAll( 
"\\.java$", ".html" ).replace( '\\', '/' )
                            + "#" + line2 );
             }
             sink.text( String.valueOf( line2 ) );
@@ -216,12 +217,12 @@
             // Source snippet
             sink.tableRow();
 
-            
+
             int colspan = 2;
-            if ( aggregate ) 
+            if ( aggregate )
             {
                 ++colspan;
-            }        
+            }
             // TODO Cleaner way to do this?
             sink.rawText( "<td colspan='" + colspan + "'>" );
             sink.verbatim( false );
@@ -229,8 +230,7 @@
             sink.verbatim_();
             sink.rawText( "</td>" );
             sink.tableRow_();
-            sink.table();
-            sink.paragraph_();
+            sink.table_();
         }
 
         sink.section1_();

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=803850&r1=803849&r2=803850&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
 Thu Aug 13 11:57:24 2009
@@ -49,8 +49,8 @@
 import net.sourceforge.pmd.renderers.TextRenderer;
 import net.sourceforge.pmd.renderers.XMLRenderer;
 
+import org.apache.maven.doxia.sink.Sink;
 import org.apache.maven.reporting.MavenReportException;
-import org.codehaus.doxia.sink.Sink;
 import org.codehaus.plexus.resource.ResourceManager;
 import org.codehaus.plexus.resource.loader.FileResourceCreationException;
 import org.codehaus.plexus.resource.loader.FileResourceLoader;
@@ -75,7 +75,7 @@
      * <p>
      * <b>Note:</b> support for <code>1.6</code> was added in version 2.3 of 
this plugin.
      * </p>
-     * 
+     *
      * @parameter expression="${targetJdk}"
      */
     private String targetJdk;
@@ -109,7 +109,7 @@
 
     /**
      * The file encoding to use when reading the Java sources.
-     * 
+     *
      * @parameter expression="${encoding}" 
default-value="${project.build.sourceEncoding}"
      */
     private String sourceEncoding;
@@ -120,8 +120,8 @@
      * @readonly
      */
     private ResourceManager locator;
-    
-    
+
+
     /** @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale) 
*/
     public String getName( Locale locale )
     {
@@ -138,7 +138,7 @@
     {
         rulesets = rules;
     }
-    
+
     /** @see 
org.apache.maven.reporting.AbstractMavenReport#executeReport(java.util.Locale) 
*/
     public void executeReport( Locale locale )
         throws MavenReportException
@@ -170,18 +170,18 @@
             try
             {
                 Thread.currentThread().setContextClassLoader( 
this.getClass().getClassLoader() );
-                
+
                 Sink sink = getSink();
-    
+
                 PMD pmd = getPMD();
                 RuleContext ruleContext = new RuleContext();
                 Report report = new Report();
                 PmdReportListener reportSink = new PmdReportListener( sink, 
getBundle( locale ), aggregate );
-    
+
                 report.addListener( reportSink );
                 ruleContext.setReport( report );
                 reportSink.beginDocument();
-    
+
                 RuleSetFactory ruleSetFactory = new RuleSetFactory();
                 ruleSetFactory.setMinimumPriority( this.minimumPriority );
                 RuleSet[] sets = new RuleSet[rulesets.length];
@@ -192,12 +192,12 @@
                         String set = rulesets[idx];
                         getLog().debug( "Preparing ruleset: " + set );
                         File ruleset = locator.getResourceAsFile( set, 
getLocationTemp( set ) );
-                        
+
                         if ( null == ruleset )
                         {
                             throw new MavenReportException( "Could not resolve 
" + set );
                         }
-    
+
                         InputStream rulesInput = new FileInputStream( ruleset 
);
                         try
                         {
@@ -221,7 +221,7 @@
                 {
                     throw new MavenReportException( e.getMessage(), e );
                 }
-    
+
                 Map files;
                 try
                 {
@@ -304,15 +304,15 @@
                     }
                     reportSink.endFile( file );
                 }
-    
+
                 reportSink.endDocument();
-    
+
                 if ( !isHtml() )
                 {
                     // Use the PMD renderers to render in any format aside 
from HTML.
                     Renderer r = createRenderer();
                     StringWriter stringwriter = new StringWriter();
-                    
+
                     try
                     {
                         r.setWriter( stringwriter );
@@ -320,11 +320,11 @@
                         r.renderFileReport( report );
                         r.end();
                         String buffer = stringwriter.toString();
-                        
+
                         Writer writer = new FileWriter( new File( 
targetDirectory, "pmd." + format ) );
                         writer.write( buffer, 0, buffer.length() );
                         writer.close();
-    
+
                         File siteDir = getReportOutputDirectory();
                         siteDir.mkdirs();
                         writer = new FileWriter( new File( siteDir,

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?rev=803850&r1=803849&r2=803850&view=diff
==============================================================================
--- 
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
 Thu Aug 13 11:57:24 2009
@@ -32,7 +32,7 @@
 import net.sourceforge.pmd.ReportListener;
 import net.sourceforge.pmd.stat.Metric;
 
-import org.codehaus.doxia.sink.Sink;
+import org.apache.maven.doxia.sink.Sink;
 import org.codehaus.plexus.util.StringUtils;
 
 /**
@@ -57,7 +57,7 @@
     private List violations = new ArrayList();
 
     private boolean aggregate;
-    
+
     // The number of erroneous files
     private int fileCount = 0;
 
@@ -82,7 +82,7 @@
             sink.section2();
             sink.sectionTitle2();
             String title = currentFilename;
-            if ( aggregate ) 
+            if ( aggregate )
             {
                 title = fileInfo.getProject().getName() + " - " + 
currentFilename;
             }
@@ -113,7 +113,7 @@
         {
             public int compare( Object o1, Object o2 )
             {
-                return ( (IRuleViolation) o1 ).getBeginLine() 
+                return ( (IRuleViolation) o1 ).getBeginLine()
                     - ( (IRuleViolation) o2 ).getBeginLine();
             }
         } );

Added: 
maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/AbstractPmdReportTest.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/AbstractPmdReportTest.java?rev=803850&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/AbstractPmdReportTest.java
 (added)
+++ 
maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/AbstractPmdReportTest.java
 Thu Aug 13 11:57:24 2009
@@ -0,0 +1,73 @@
+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 java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Locale;
+
+import org.apache.maven.doxia.site.decoration.DecorationModel;
+import org.apache.maven.doxia.siterenderer.RendererException;
+import org.apache.maven.doxia.siterenderer.SiteRenderingContext;
+import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.WriterFactory;
+
+/**
+ * @author <a href="mailto:vincent.sive...@gmail.com";>Vincent Siveton</a>
+ * @version $Id$
+ * @since 2.5
+ */
+public abstract class AbstractPmdReportTest
+    extends AbstractMojoTestCase
+{
+    /**
+     * Renderer the sink from the report mojo.
+     *
+     * @param mojo not null
+     * @param outputHtml not null
+     * @throws RendererException if any
+     * @throws IOException if any
+     */
+    protected void renderer( AbstractPmdReport mojo, File outputHtml )
+        throws RendererException, IOException
+    {
+        Writer writer = null;
+        SiteRenderingContext context = new SiteRenderingContext();
+        context.setDecoration( new DecorationModel() );
+        context.setTemplateName( 
"org/apache/maven/doxia/siterenderer/resources/default-site.vm" );
+        context.setLocale( Locale.ENGLISH );
+
+        try
+        {
+            outputHtml.getParentFile().mkdirs();
+            writer = WriterFactory.newXmlWriter( outputHtml );
+
+            mojo.getSiteRenderer().generateDocument( writer, 
(SiteRendererSink) mojo.getSink(),
+                                                           context );
+        }
+        finally
+        {
+            IOUtil.close( writer );
+        }
+    }
+}

Propchange: 
maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/AbstractPmdReportTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/AbstractPmdReportTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: 
maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/CpdReportTest.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/CpdReportTest.java?rev=803850&r1=803849&r2=803850&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/CpdReportTest.java
 (original)
+++ 
maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/CpdReportTest.java
 Thu Aug 13 11:57:24 2009
@@ -36,17 +36,18 @@
 import net.sourceforge.pmd.cpd.Match;
 import net.sourceforge.pmd.cpd.TokenEntry;
 
-import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 import org.codehaus.plexus.util.FileUtils;
 import org.w3c.dom.Document;
 
 /**
  * @author <a href="mailto:och...@apache.org";>Maria Odea Ching</a>
  */
-public class CpdReportTest extends AbstractMojoTestCase
+public class CpdReportTest
+    extends AbstractPmdReportTest
 {
 
-    protected void setUp() throws Exception
+    protected void setUp()
+        throws Exception
     {
         super.setUp();
         FileUtils.deleteDirectory( new File( getBasedir(), "target/test/unit" 
) );
@@ -54,10 +55,11 @@
 
     /**
      * Test CPDReport given the default configuration
-     * 
+     *
      * @throws Exception
      */
-    public void testDefaultConfiguration() throws Exception
+    public void testDefaultConfiguration()
+        throws Exception
     {
         File testPom =
             new File( getBasedir(),
@@ -70,10 +72,12 @@
         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
 
         generatedFile = new File( getBasedir(), 
"target/test/unit/default-configuration/target/site/cpd.html" );
+        renderer( mojo, generatedFile );
         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
 
         // check the contents of cpd.html
-        String str = readFile( new File( getBasedir(), 
"target/test/unit/default-configuration/target/site/cpd.html" ) );
+        String str =
+            readFile( new File( getBasedir(), 
"target/test/unit/default-configuration/target/site/cpd.html" ) );
         assertTrue( str.toLowerCase().indexOf( "AppSample.java".toLowerCase() 
) != -1 );
 
         str = readFile( new File( getBasedir(), 
"target/test/unit/default-configuration/target/site/cpd.html" ) );
@@ -89,10 +93,11 @@
 
     /**
      * Test CPDReport using custom configuration
-     * 
+     *
      * @throws Exception
      */
-    public void testCustomConfiguration() throws Exception
+    public void testCustomConfiguration()
+        throws Exception
     {
         File testPom =
             new File( getBasedir(),
@@ -105,10 +110,12 @@
         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
 
         generatedFile = new File( getBasedir(), 
"target/test/unit/custom-configuration/target/site/cpd.html" );
+        renderer( mojo, generatedFile );
         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
 
         // Contents that should NOT be in the report
-        String str = readFile( new File( getBasedir(), 
"target/test/unit/custom-configuration/target/site/cpd.html" ) );
+        String str =
+            readFile( new File( getBasedir(), 
"target/test/unit/custom-configuration/target/site/cpd.html" ) );
         assertTrue( str.toLowerCase().indexOf( "/Sample.java".toLowerCase() ) 
== -1 );
 
         str = readFile( new File( getBasedir(), 
"target/test/unit/custom-configuration/target/site/cpd.html" ) );
@@ -128,15 +135,17 @@
 
     /**
      * Test CPDReport with invalid format
-     * 
+     *
      * @throws Exception
      */
-    public void testInvalidFormat() throws Exception
+    public void testInvalidFormat()
+        throws Exception
     {
         try
         {
             File testPom =
-                new File( getBasedir(), 
"src/test/resources/unit/invalid-format/cpd-invalid-format-plugin-config.xml" );
+                new File( getBasedir(),
+                          
"src/test/resources/unit/invalid-format/cpd-invalid-format-plugin-config.xml" );
             CpdReport mojo = (CpdReport) lookupMojo( "cpd", testPom );
             mojo.execute();
 
@@ -149,20 +158,22 @@
 
     }
 
-    protected void tearDown() throws Exception
+    protected void tearDown()
+        throws Exception
     {
 
     }
 
     /**
      * Read the contents of the specified file object into a string
-     * 
+     *
      * @param file
      *            the file to be read
      * @return a String object that contains the contents of the file
      * @throws java.io.IOException
      */
-    private String readFile( File file ) throws IOException
+    private String readFile( File file )
+        throws IOException
     {
         String str = "", strTmp = "";
         BufferedReader in = new BufferedReader( new FileReader( file ) );
@@ -176,7 +187,8 @@
         return str;
     }
 
-    public void testWriteNonHtml() throws Exception
+    public void testWriteNonHtml()
+        throws Exception
     {
         File testPom =
             new File( getBasedir(),
@@ -188,7 +200,7 @@
         TokenEntry tSecondEntry = new TokenEntry( "public java", 
"MyClass3.java", 55 );
         List tList = new ArrayList();
         Match tMatch = new Match( 2, tFirstEntry, tSecondEntry );
-        tMatch.setSourceCodeSlice( "// ----- ACCESSEURS  avec éléments -----");
+        tMatch.setSourceCodeSlice( "// ----- ACCESSEURS  avec �l�ments 
-----" );
         tList.add( tMatch );
 
         CPD tCpd = new MockCpd( 100, new JavaLanguage(), tList.iterator() );
@@ -204,7 +216,8 @@
         assertNotNull( pmdCpdDocument );
     }
 
-    public static class MockCpd extends CPD
+    public static class MockCpd
+        extends CPD
     {
 
         private Iterator matches;

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?rev=803850&r1=803849&r2=803850&view=diff
==============================================================================
--- 
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
 Thu Aug 13 11:57:24 2009
@@ -19,7 +19,6 @@
  * under the License.
  */
 
-import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 import org.codehaus.plexus.util.FileUtils;
 
 import java.io.BufferedReader;
@@ -32,7 +31,7 @@
  * @author <a href="mailto:och...@apache.org";>Maria Odea Ching</a>
  */
 public class PmdReportTest
-    extends AbstractMojoTestCase
+    extends AbstractPmdReportTest
 {
     protected void setUp()
         throws Exception
@@ -40,7 +39,7 @@
         super.setUp();
         FileUtils.deleteDirectory( new File( getBasedir(), "target/test/unit" 
) );
     }
-    
+
     public void testDefaultConfiguration()
         throws Exception
     {
@@ -67,63 +66,65 @@
         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
 
         generatedFile = new File( getBasedir(), 
"target/test/unit/default-configuration/target/site/pmd.html" );
+        renderer( mojo, generatedFile );
         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
 
         //check if there's a link to the JXR files
         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 );
     }
 
-    
+
     public void testFileURL()
         throws Exception
     {
         FileUtils.copyDirectoryStructure(
             new File( getBasedir(), 
"src/test/resources/unit/default-configuration/jxr-files" ),
             new File( getBasedir(), 
"target/test/unit/default-configuration/target/site" ) );
-    
+
         File testPom = new File( getBasedir(),
                                  
"src/test/resources/unit/default-configuration/default-configuration-plugin-config.xml"
 );
         PmdReport mojo = (PmdReport) lookupMojo( "pmd", testPom );
-        
+
         URL url = getClass().getClassLoader().getResource( 
"rulesets/basic.xml" );
         URL url2 = getClass().getClassLoader().getResource( 
"rulesets/unusedcode.xml" );
         URL url3 = getClass().getClassLoader().getResource( 
"rulesets/imports.xml" );
         mojo.setRulesets( new String[] { url.toString(), url2.toString() , 
url3.toString() } );
-        
+
         mojo.execute();
-    
+
         //check if the PMD files were generated
         File generatedFile = new File( getBasedir(), 
"target/test/unit/default-configuration/target/pmd.xml" );
         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
-    
+
         generatedFile = new File( getBasedir(), 
"target/test/unit/default-configuration/target/basic.xml" );
         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
-    
+
         generatedFile = new File( getBasedir(), 
"target/test/unit/default-configuration/target/imports.xml" );
         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
-    
+
         generatedFile = new File( getBasedir(), 
"target/test/unit/default-configuration/target/unusedcode.xml" );
         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
-    
+
         generatedFile = new File( getBasedir(), 
"target/test/unit/default-configuration/target/site/pmd.html" );
+        renderer( mojo, generatedFile );
         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
-    
+
         //check if there's a link to the JXR files
         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 );
-    }  
-    
+    }
+
     /**
      * With custom rulesets
      *
@@ -146,15 +147,17 @@
         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
 
         generatedFile = new File( getBasedir(), 
"target/test/unit/custom-configuration/target/site/pmd.html" );
+        renderer( mojo, generatedFile );
+        renderer( mojo, generatedFile );
         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
 
         //check if custom ruleset was applied
         String str = readFile( new File( getBasedir(), 
"target/test/unit/custom-configuration/target/site/pmd.html" ) );
         assertTrue( str.toLowerCase().indexOf( "Avoid using if statements 
without curly braces".toLowerCase() ) != -1 );
-        
+
         assertTrue(
             str.toLowerCase().indexOf( "Avoid using if...else statements 
without curly braces".toLowerCase() ) != -1 );
-        
+
         assertTrue("unnecessary constructor should not be triggered because of 
low priority",
             str.toLowerCase().indexOf( "Avoid unnecessary constructors - the 
compiler will generate these for you".toLowerCase() ) == -1 );
 
@@ -174,7 +177,6 @@
         mojo.execute();
 
         File basedir = new File( getBasedir(), 
"target/test/unit/skip-configuration" );
-        assertTrue( FileUtils.fileExists( basedir.getAbsolutePath() ) );
 
         // verify the generated files do not exist because PMD was skipped
         File generatedFile = new File( getBasedir(), 
"target/test/unit/skip-configuration/target/pmd.csv" );


Reply via email to