Author: dkulp
Date: Sun Mar 11 19:42:34 2007
New Revision: 517080

URL: http://svn.apache.org/viewvc?view=rev&rev=517080
Log:
Fix some codestyle/checkstyle issues
Fix all PMD issues
Second attempt to workaround problem with ResourceManager is reporting.


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/PmdFileInfo.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

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=517080&r1=517079&r2=517080
==============================================================================
--- 
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
 Sun Mar 11 19:42:34 2007
@@ -9,7 +9,7 @@
  * "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
+ *   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
@@ -28,7 +28,6 @@
 import java.util.Map;
 import java.util.TreeMap;
 
-import org.apache.maven.artifact.handler.ArtifactHandler;
 import org.apache.maven.model.ReportPlugin;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.reporting.AbstractMavenReport;
@@ -258,16 +257,16 @@
         {
             excludeRoots = Collections.EMPTY_LIST;
         }
-        List excludeRootFiles = new ArrayList(excludeRoots.size());
+        List excludeRootFiles = new ArrayList( excludeRoots.size() );
         
-        for (Iterator it = excludeRoots.iterator(); it.hasNext();) 
+        for ( Iterator it = excludeRoots.iterator(); it.hasNext(); ) 
         {
-            String root = (String)it.next();
-            File file = new File(root);
+            String root = (String) it.next();
+            File file = new File( root );
             if ( file.exists()
-                && file.isDirectory())
+                && file.isDirectory() )
             {
-                excludeRootFiles.add(file);
+                excludeRootFiles.add( file );
             }
         }
         
@@ -276,8 +275,8 @@
         for ( Iterator i = compileSourceRoots.iterator(); i.hasNext(); )
         {
             String root = (String) i.next();
-            File sroot = new File(root);
-            directories.add( new PmdFileInfo( project, sroot, sourceXref) );
+            File sroot = new File( root );
+            directories.add( new PmdFileInfo( project, sroot, sourceXref ) );
         }
         
         if ( includeTests )
@@ -285,8 +284,8 @@
             for ( Iterator i = testSourceRoots.iterator(); i.hasNext(); )
             {
                 String root = (String) i.next();
-                File sroot = new File(root);
-                directories.add( new PmdFileInfo( project, sroot, testXref) );
+                File sroot = new File( root );
+                directories.add( new PmdFileInfo( project, sroot, testXref ) );
             }
         }
         if ( aggregate )
@@ -297,16 +296,16 @@
                 for ( Iterator i2 = 
localProject.getCompileSourceRoots().iterator(); i2.hasNext(); )
                 {
                     String root = (String) i2.next();
-                    File sroot = new File(root);
-                    directories.add( new PmdFileInfo( localProject, sroot, 
sourceXref) );
+                    File sroot = new File( root );
+                    directories.add( new PmdFileInfo( localProject, sroot, 
sourceXref ) );
                 }
                 if ( includeTests )
                 {
                     for ( Iterator i2 = 
localProject.getTestCompileSourceRoots().iterator(); i2.hasNext(); )
                     {
                         String root = (String) i2.next();
-                        File sroot = new File(root);
-                        directories.add( new PmdFileInfo( localProject, sroot, 
testXref) );
+                        File sroot = new File( root );
+                        directories.add( new PmdFileInfo( localProject, sroot, 
testXref ) );
                     }
                 }
             }
@@ -317,7 +316,7 @@
         String including = getIncludeExcludeString( includes );
         Map files = new TreeMap();
         
-        if ( "".equals(including) )
+        if ( "".equals( including ) )
         {
             including = "**/*.java";
         }
@@ -338,18 +337,18 @@
         }
         getLog().debug( "Excluded files: '" + excludesStr + "'" );
 
-        for ( Iterator it = directories.iterator(); it.hasNext();)
+        for ( Iterator it = directories.iterator(); it.hasNext(); )
         {
             PmdFileInfo finfo = (PmdFileInfo) it.next();
             File sourceDirectory = finfo.getSourceDirectory();
             if ( sourceDirectory.exists()
                 && sourceDirectory.isDirectory()
-                && !excludeRootFiles.contains(sourceDirectory))
+                && !excludeRootFiles.contains( sourceDirectory ) )
             {
                 List newfiles = FileUtils.getFiles( sourceDirectory, 
including, excludesStr.toString() );
                 for ( Iterator it2 = newfiles.iterator(); it2.hasNext(); )
                 {
-                    files.put( it2.next(), finfo);
+                    files.put( it2.next(), finfo );
                 }
             }
         }        
@@ -400,7 +399,7 @@
 
         // 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) )
+        if ( "xml".equals( format ) )
         {
             return true;
         }
@@ -414,7 +413,7 @@
         }
         catch ( IOException e )
         {
-            getLog().error(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=517080&r1=517079&r2=517080
==============================================================================
--- 
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
 Sun Mar 11 19:42:34 2007
@@ -24,7 +24,6 @@
 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;

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=517080&r1=517079&r2=517080
==============================================================================
--- 
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
 Sun Mar 11 19:42:34 2007
@@ -9,7 +9,7 @@
  * "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
+ *   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
@@ -24,11 +24,9 @@
 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;
 
 import net.sourceforge.pmd.cpd.CPD;
 import net.sourceforge.pmd.cpd.CSVRenderer;
@@ -89,7 +87,7 @@
     {
         if ( !skip && canGenerateReport() )
         {         
-            CPD cpd = new CPD(minimumTokens, new JavaLanguage());
+            CPD cpd = new CPD( minimumTokens, new JavaLanguage() );
             Map files = null;
             try
             {
@@ -99,9 +97,9 @@
                     cpd.add( (File) it.next() );
                 }
             }
-            catch (IOException e)
+            catch ( IOException e )
             {
-                throw new MavenReportException(e.getMessage(), e);
+                throw new MavenReportException( e.getMessage(), e );
             }
             cpd.go();
 
@@ -121,7 +119,7 @@
                     writer.close();
                     
                     
-                    File siteDir = new File(targetDirectory, "site");
+                    File siteDir = new File( targetDirectory, "site" );
                     siteDir.mkdirs();
                     writer = new FileWriter( new File( siteDir,
                                                          "cpd." + format ) );

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=517080&r1=517079&r2=517080
==============================================================================
--- 
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
 Sun Mar 11 19:42:34 2007
@@ -9,7 +9,7 @@
  * "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
+ *   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
@@ -173,8 +173,8 @@
 
             if ( xrefLocation != null )
             {
-                sink.link( xrefLocation + "/" + filename1.replaceAll( 
"\\.java$", ".html" ).replace( '\\', '/' ) + "#" +
-                    line1 );
+                sink.link( xrefLocation + "/" + filename1.replaceAll( 
"\\.java$", ".html" ).replace( '\\', '/' ) 
+                           + "#" + line1 );
             }
             sink.text( String.valueOf( line1 ) );
             if ( xrefLocation != null )
@@ -202,8 +202,8 @@
             
             if ( xrefLocation != null )
             {
-                sink.link( xrefLocation2 + "/" + filename2.replaceAll( 
"\\.java$", ".html" ).replace( '\\', '/' ) + "#" +
-                    line2 );
+                sink.link( xrefLocation2 + "/" + filename2.replaceAll( 
"\\.java$", ".html" ).replace( '\\', '/' ) 
+                           + "#" + line2 );
             }
             sink.text( String.valueOf( line2 ) );
             if ( xrefLocation != null )
@@ -218,8 +218,9 @@
 
             
             int colspan = 2;
-            if ( aggregate ) {
-                colspan = 3;
+            if ( aggregate ) 
+            {
+                ++colspan;
             }        
             // TODO Cleaner way to do this?
             sink.rawText( "<td colspan='" + colspan + "'>" );

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=517080&r1=517079&r2=517080
==============================================================================
--- 
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
 Sun Mar 11 19:42:34 2007
@@ -71,21 +71,21 @@
         
         StringBuffer buff = new StringBuffer( 100 );
         buff.append( "CPD " + severity + ": Found " );
-        buff.append(lines).append(" lines of duplicated code at locations:");
+        buff.append( lines ).append( " lines of duplicated code at locations:" 
);
         this.getLog().info( buff.toString() );
         
-        buff.setLength(0);
-        buff.append("    ");
-        Map file = (Map)item.get( "file" );
+        buff.setLength( 0 );
+        buff.append( "    " );
+        Map file = (Map) item.get( "file" );
         buff.append( file.get( "path" ) );
-        buff.append(" line ").append( file.get("line") );
+        buff.append( " line " ).append( file.get( "line" ) );
         this.getLog().info( buff.toString() );
         
-        buff.setLength(0);
-        buff.append("    ");
-        file = (Map)item.get( "file1" );
+        buff.setLength( 0 );
+        buff.append( "    " );
+        file = (Map) item.get( "file1" );
         buff.append( file.get( "path" ) );
-        buff.append(" line ").append( file.get("line") );
+        buff.append( " line " ).append( file.get( "line" ) );
         this.getLog().info( buff.toString() );
     }
 
@@ -119,7 +119,7 @@
                     if ( msgs.containsKey( nm ) )
                     {
                         int cnt = 1;
-                        while ( msgs.containsKey( nm + cnt) )
+                        while ( msgs.containsKey( nm + cnt ) )
                         {
                             ++cnt;
                         }
@@ -128,6 +128,7 @@
                     msgs.put( nm, getErrorDetails( xpp ) );
                     break;
                 }
+            default:
             }
             tp = xpp.next();
         }

Modified: 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdFileInfo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdFileInfo.java?view=diff&rev=517080&r1=517079&r2=517080
==============================================================================
--- 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdFileInfo.java
 (original)
+++ 
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdFileInfo.java
 Sun Mar 11 19:42:34 2007
@@ -9,7 +9,7 @@
  * "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
+ *   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
@@ -23,16 +23,17 @@
 
 import org.apache.maven.project.MavenProject;
 
-public class PmdFileInfo {
+public class PmdFileInfo 
+{
     
-    MavenProject project;
-    File sourceDir;
-    String xref;
+    private MavenProject project;
+    private File sourceDir;
+    private String xref;
     
     
-    public PmdFileInfo(MavenProject project,
+    public PmdFileInfo( MavenProject project,
                        File dir,
-                       String x) 
+                       String x ) 
     {
         this.project = project;
         this.sourceDir = dir;

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=517080&r1=517079&r2=517080
==============================================================================
--- 
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 Mar 11 19:42:34 2007
@@ -9,7 +9,7 @@
  * "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
+ *   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
@@ -31,12 +31,11 @@
 import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
 import java.io.Writer;
+import java.net.URL;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.ResourceBundle;
-import java.util.Collections;
 
 import net.sourceforge.pmd.IRuleViolation;
 import net.sourceforge.pmd.PMD;
@@ -56,8 +55,8 @@
 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;
 import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
+import org.codehaus.plexus.util.FileUtils;
 
 /**
  * Implement the PMD report.
@@ -100,7 +99,7 @@
      *
      * @parameter
      */
-    private String[] rulesets = new String[]{"rulesets/basic.xml", 
"rulesets/unusedcode.xml", "rulesets/imports.xml",};
+    private String[] rulesets = new String[]{"rulesets/basic.xml", 
"rulesets/unusedcode.xml", "rulesets/imports.xml", };
 
     /**
      * The file encoding to use when reading the java source.
@@ -155,22 +154,43 @@
                 {
                     String set = rulesets[idx];
                     getLog().debug( "Preparing ruleset: " + set );
-                    File ruleset = locator.getResourceAsFile( set, 
getLocationTemp( set ) );
-                    InputStream rulesInput = null;
-                    if ( null == ruleset)
+                    File ruleset = null;
+                    Exception exception = null;
+                    try
+                    {
+                        ruleset = locator.getResourceAsFile( set, 
getLocationTemp( set ) );
+
+                    }
+                    catch ( ResourceNotFoundException e )
                     {
-                        //  workaround bug in resource manager when run in 
reporting mode
-                        rulesInput = 
this.getClass().getClassLoader().getResourceAsStream( set );
+                        exception = e;
                     }
-                    else
+                    catch ( FileResourceCreationException e )
                     {
-                        rulesInput = new FileInputStream( ruleset );
+                        exception = e;
                     }
-                    if ( null == rulesInput )
+                    //  workaround bug in resource manager when run in 
reporting mode
+                    // in reporting mode, the current classloader isn't in the 
ResourceManager.
+                    if (exception != null)
+                    {
+                        URL url = 
this.getClass().getClassLoader().getResource( set );
+                        if ( url != null )
+                        {
+                            ruleset = new File( getLocationTemp( set ) );
+                            FileUtils.copyURLToFile( url, ruleset );
+                        }
+                        else
+                        {
+                            throw new MavenReportException( 
exception.getMessage(), exception );
+                        }
+                    }
+                    
+                    if ( null == ruleset )
                     {
                         throw new MavenReportException( "Cold not resolve " + 
set );
                     }
 
+                    InputStream rulesInput = new FileInputStream( ruleset );
                     sets[idx] = ruleSetFactory.createRuleSet( rulesInput );
                 }
             }
@@ -178,14 +198,6 @@
             {
                 throw new MavenReportException( e.getMessage(), e );
             }
-            catch (ResourceNotFoundException e)
-            {
-                throw new MavenReportException( e.getMessage(), e );
-            }
-            catch (FileResourceCreationException e)
-            {
-                throw new MavenReportException( e.getMessage(), e );
-            }
 
             boolean hasEncoding = sourceEncoding != null;
 
@@ -256,7 +268,7 @@
                     writer.write( buffer, 0, buffer.length() );
                     writer.close();
 
-                    File siteDir = new File(targetDirectory, "site");
+                    File siteDir = new File( targetDirectory, "site" );
                     siteDir.mkdirs();
                     writer = new FileWriter( new File( siteDir,
                                                          "pmd." + format ) );

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=517080&r1=517079&r2=517080
==============================================================================
--- 
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
 Sun Mar 11 19:42:34 2007
@@ -9,7 +9,7 @@
  * "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
+ *   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
@@ -113,8 +113,8 @@
         {
             public int compare( Object o1, Object o2 )
             {
-                return ( (IRuleViolation) o1 ).getBeginLine() -
-                    ( (IRuleViolation) o2 ).getBeginLine();
+                return ( (IRuleViolation) o1 ).getBeginLine() 
+                    - ( (IRuleViolation) o2 ).getBeginLine();
             }
         } );
 

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=517080&r1=517079&r2=517080
==============================================================================
--- 
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
 Sun Mar 11 19:42:34 2007
@@ -9,7 +9,7 @@
  * "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
+ *   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


Reply via email to