You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2010/04/21 00:09:47 UTC

svn commit: r936084 - in /maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd: CpdReport.java PmdReport.java

Author: hboutemy
Date: Tue Apr 20 22:09:47 2010
New Revision: 936084

URL: http://svn.apache.org/viewvc?rev=936084&view=rev
Log:
code refactoring

Modified:
    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/PmdReport.java

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?rev=936084&r1=936083&r2=936084&view=diff
==============================================================================
--- 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 Tue Apr 20 22:09:47 2010
@@ -111,44 +111,7 @@ public class CpdReport
             {
                 Thread.currentThread().setContextClassLoader( this.getClass().getClassLoader() );
 
-                CPD cpd = new CPD( minimumTokens, new JavaLanguage() );
-                Map files = null;
-                try
-                {
-                    files = getFilesToProcess();
-
-                    if ( StringUtils.isNotEmpty( getSourceEncoding() ) )
-                    {
-                        cpd.setEncoding( getSourceEncoding() );
-
-                        // test encoding as CPD will convert exception into a RuntimeException
-                        WriterFactory.newWriter( new ByteArrayOutputStream(), getSourceEncoding() );
-                    }
-                    else if ( !files.isEmpty() )
-                    {
-                        getLog().warn(
-                                       "File encoding has not been set, using platform encoding "
-                                           + WriterFactory.FILE_ENCODING + ", i.e. build is platform dependent!" );
-                    }
-
-                    for ( Iterator it = files.keySet().iterator(); it.hasNext(); )
-                    {
-                        cpd.add( (File) it.next() );
-                    }
-                }
-                catch ( UnsupportedEncodingException e )
-                {
-                    throw new MavenReportException( "Encoding '" + getSourceEncoding() + "' is not supported.", e );
-                }
-                catch ( IOException e )
-                {
-                    throw new MavenReportException( e.getMessage(), e );
-                }
-                cpd.go();
-
-                CpdReportGenerator gen =
-                    new CpdReportGenerator( getSink(), files, getBundle( locale ), aggregate );
-                gen.generate( cpd.getMatches() );
+                CPD cpd = generateReport( locale );
 
                 if ( !isHtml() )
                 {
@@ -163,6 +126,51 @@ public class CpdReport
         }
     }
 
+    private CPD generateReport( Locale locale )
+        throws MavenReportException
+    {
+        CPD cpd = new CPD( minimumTokens, new JavaLanguage() );
+        Map files = null;
+        try
+        {
+            files = getFilesToProcess();
+
+            if ( StringUtils.isNotEmpty( getSourceEncoding() ) )
+            {
+                cpd.setEncoding( getSourceEncoding() );
+
+                // test encoding as CPD will convert exception into a RuntimeException
+                WriterFactory.newWriter( new ByteArrayOutputStream(), getSourceEncoding() );
+            }
+            else if ( !files.isEmpty() )
+            {
+                getLog().warn(
+                               "File encoding has not been set, using platform encoding "
+                                   + WriterFactory.FILE_ENCODING + ", i.e. build is platform dependent!" );
+            }
+
+            for ( Iterator it = files.keySet().iterator(); it.hasNext(); )
+            {
+                cpd.add( (File) it.next() );
+            }
+        }
+        catch ( UnsupportedEncodingException e )
+        {
+            throw new MavenReportException( "Encoding '" + getSourceEncoding() + "' is not supported.", e );
+        }
+        catch ( IOException e )
+        {
+            throw new MavenReportException( e.getMessage(), e );
+        }
+        cpd.go();
+
+        CpdReportGenerator gen =
+            new CpdReportGenerator( getSink(), files, getBundle( locale ), aggregate );
+        gen.generate( cpd.getMatches() );
+
+        return cpd;
+    }
+
     void writeNonHtml( CPD cpd )
         throws MavenReportException
     {

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=936084&r1=936083&r2=936084&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 Tue Apr 20 22:09:47 2010
@@ -169,7 +169,7 @@ public class PmdReport
 
                 if ( !isHtml() )
                 {
-                    renderPmdFormat( report );
+                    writeNonHtml( report );
                 }
             }
             finally
@@ -326,7 +326,7 @@ public class PmdReport
      * @param report
      * @throws MavenReportException
      */
-    private void renderPmdFormat( Report report )
+    private void writeNonHtml( Report report )
         throws MavenReportException
     {
         Renderer r = createRenderer();