You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2010/02/08 18:06:16 UTC

svn commit: r907726 - in /maven/plugins/trunk/maven-compiler-plugin: ./ src/main/java/org/apache/maven/plugin/

Author: jdcasey
Date: Mon Feb  8 17:06:16 2010
New Revision: 907726

URL: http://svn.apache.org/viewvc?rev=907726&view=rev
Log:
[MCOMPILER-117] Converting to use Java 1.5 syntax.

Modified:
    maven/plugins/trunk/maven-compiler-plugin/pom.xml
    maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java
    maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilationFailureException.java
    maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilerMojo.java
    maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/TestCompilerMojo.java

Modified: maven/plugins/trunk/maven-compiler-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/pom.xml?rev=907726&r1=907725&r2=907726&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-compiler-plugin/pom.xml Mon Feb  8 17:06:16 2010
@@ -122,6 +122,21 @@
       <scope>test</scope>
     </dependency>
   </dependencies>
+  
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>2.1</version>
+          <configuration>
+            <source>1.5</source>
+            <target>1.5</target>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
 
   <profiles>
     <profile>

Modified: maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java?rev=907726&r1=907725&r2=907726&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java (original)
+++ maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java Mon Feb  8 17:06:16 2010
@@ -196,7 +196,7 @@
      * @parameter
      * @since 2.0.1
      */
-    protected Map compilerArguments;
+    protected Map<String, String> compilerArguments;
 
     /**
      * <p>
@@ -274,9 +274,9 @@
 
     protected abstract SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding );
 
-    protected abstract List getClasspathElements();
+    protected abstract List<String> getClasspathElements();
 
-    protected abstract List getCompileSourceRoots();
+    protected abstract List<String> getCompileSourceRoots();
 
     protected abstract File getOutputDirectory();
     
@@ -286,8 +286,9 @@
     
     protected abstract String getCompilerArgument();
     
-    protected abstract Map getCompilerArguments();
+    protected abstract Map<String, String> getCompilerArguments();
 
+    @SuppressWarnings( "unchecked" )
     public void execute()
         throws MojoExecutionException, CompilationFailureException
     {
@@ -331,7 +332,7 @@
         //
         // ----------------------------------------------------------------------
 
-        List compileSourceRoots = removeEmptyCompileSourceRoots( getCompileSourceRoots() );
+        List<String> compileSourceRoots = removeEmptyCompileSourceRoots( getCompileSourceRoots() );
 
         if ( compileSourceRoots.isEmpty() )
         {
@@ -390,18 +391,17 @@
 
         compilerConfiguration.setSourceEncoding( encoding );
         
-        Map effectiveCompilerArguments = getCompilerArguments();
+        Map<String, String> effectiveCompilerArguments = getCompilerArguments();
 
         String effectiveCompilerArgument = getCompilerArgument();
 
         if ( ( effectiveCompilerArguments != null ) || ( effectiveCompilerArgument != null ) )
         {
-            LinkedHashMap cplrArgsCopy = new LinkedHashMap();
+            LinkedHashMap<String, String> cplrArgsCopy = new LinkedHashMap<String, String>();
             if ( effectiveCompilerArguments != null )
             {
-                for ( Iterator i = effectiveCompilerArguments.entrySet().iterator(); i.hasNext(); )
+                for ( Map.Entry<String, String> me : effectiveCompilerArguments.entrySet() )
                 {
-                    Map.Entry me = (Map.Entry) i.next();
                     String key = (String) me.getKey();
                     String value = (String) me.getValue();
                     if ( !key.startsWith( "-" ) )
@@ -462,7 +462,7 @@
         compilerConfiguration.setOutputFileName( outputFileName );
 
         // TODO: have an option to always compile (without need to clean)
-        Set staleSources;
+        Set<File> staleSources;
 
         boolean canUpdateTarget;
 
@@ -480,7 +480,7 @@
                 // TODO: This second scan for source files is sub-optimal
                 String inputFileEnding = compiler.getInputFileEnding( compilerConfiguration );
 
-                Set sources = computeStaleSources( compilerConfiguration, compiler,
+                Set<File> sources = computeStaleSources( compilerConfiguration, compiler,
                                                    getSourceInclusionScanner( inputFileEnding ) );
 
                 compilerConfiguration.setSourceFiles( sources );
@@ -510,19 +510,15 @@
         {
             getLog().debug( "Classpath:" );
 
-            for ( Iterator it = getClasspathElements().iterator(); it.hasNext(); )
+            for ( String s : getClasspathElements() )
             {
-                String s = (String) it.next();
-
                 getLog().debug( " " + s );
             }
 
             getLog().debug( "Source roots:" );
 
-            for ( Iterator it = getCompileSourceRoots().iterator(); it.hasNext(); )
+            for ( String root : getCompileSourceRoots() )
             {
-                String root = (String) it.next();
-
                 getLog().debug( " " + root );
             }
 
@@ -568,7 +564,7 @@
                                + ", i.e. build is platform dependent!" );
         }
 
-        List messages;
+        List<CompilerError> messages;
 
         try
         {
@@ -582,14 +578,15 @@
 
         boolean compilationError = false;
 
-        for ( Iterator i = messages.iterator(); i.hasNext(); )
+        if ( messages != null )
         {
-            CompilerError message = (CompilerError) i.next();
-
-            if ( message.isError() )
+            for ( CompilerError message : messages )
             {
-                compilationError = true;
-                break;
+                if ( message.isError() )
+                {
+                    compilationError = true;
+                    break;
+                }
             }
         }
 
@@ -600,12 +597,9 @@
             getLog().info( "-------------------------------------------------------------" );
             if ( messages != null )
             {
-                for ( Iterator i = messages.iterator(); i.hasNext(); )
+                for ( CompilerError message : messages )
                 {
-                    CompilerError message = (CompilerError) i.next();
-
                     getLog().error( message.toString() );
-
                 }
                 getLog().info( messages.size() + ( ( messages.size() > 1 ) ? " errors " : "error" ) );
                 getLog().info( "-------------------------------------------------------------" );
@@ -614,10 +608,8 @@
         }
         else
         {
-            for ( Iterator i = messages.iterator(); i.hasNext(); )
+            for ( CompilerError message : messages )
             {
-                CompilerError message = (CompilerError) i.next();
-
                 getLog().warn( message.toString() );
             }
         }
@@ -667,7 +659,8 @@
         return true;
     }
 
-    private Set computeStaleSources( CompilerConfiguration compilerConfiguration, Compiler compiler,
+    @SuppressWarnings( "unchecked" )
+    private Set<File> computeStaleSources( CompilerConfiguration compilerConfiguration, Compiler compiler,
                                      SourceInclusionScanner scanner )
         throws MojoExecutionException, CompilerException
     {
@@ -698,12 +691,10 @@
 
         scanner.addSourceMapping( mapping );
 
-        Set staleSources = new HashSet();
+        Set<File> staleSources = new HashSet<File>();
 
-        for ( Iterator it = getCompileSourceRoots().iterator(); it.hasNext(); )
+        for ( String sourceRoot : getCompileSourceRoots() )
         {
-            String sourceRoot = (String) it.next();
-
             File rootFile = new File( sourceRoot );
 
             if ( !rootFile.isDirectory() )
@@ -729,15 +720,14 @@
      * @todo also in ant plugin. This should be resolved at some point so that it does not need to
      * be calculated continuously - or should the plugins accept empty source roots as is?
      */
-    private static List removeEmptyCompileSourceRoots( List compileSourceRootsList )
+    private static List<String> removeEmptyCompileSourceRoots( List<String> compileSourceRootsList )
     {
-        List newCompileSourceRootsList = new ArrayList();
+        List<String> newCompileSourceRootsList = new ArrayList<String>();
         if ( compileSourceRootsList != null )
         {
             // copy as I may be modifying it
-            for ( Iterator i = compileSourceRootsList.iterator(); i.hasNext(); )
+            for ( String srcDir : compileSourceRootsList )
             {
-                String srcDir = (String) i.next();
                 if ( !newCompileSourceRootsList.contains( srcDir ) && new File( srcDir ).exists() )
                 {
                     newCompileSourceRootsList.add( srcDir );

Modified: maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilationFailureException.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilationFailureException.java?rev=907726&r1=907725&r2=907726&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilationFailureException.java (original)
+++ maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilationFailureException.java Mon Feb  8 17:06:16 2010
@@ -21,7 +21,6 @@
 
 import org.codehaus.plexus.compiler.CompilerError;
 
-import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -29,25 +28,27 @@
  * @version $Id$
  * @since 2.0
  */
+@SuppressWarnings( "serial" )
 public class CompilationFailureException
     extends MojoFailureException
 {
     private static final String LS = System.getProperty( "line.separator" );
 
-    public CompilationFailureException( List messages )
+    public CompilationFailureException( List<CompilerError> messages )
     {
         super( null, shortMessage( messages ), longMessage( messages ) );
     }
 
-    public static String longMessage( List messages )
+    public static String longMessage( List<CompilerError> messages )
     {
         StringBuffer sb = new StringBuffer();
 
-        for ( Iterator it = messages.iterator(); it.hasNext(); )
+        if ( messages != null )
         {
-            CompilerError compilerError = (CompilerError) it.next();
-
-            sb.append( compilerError ).append( LS );
+            for ( CompilerError compilerError : messages )
+            {
+                sb.append( compilerError ).append( LS );
+            }
         }
         return sb.toString();
     }
@@ -59,7 +60,7 @@
      * @return the short error message
      * @since 2.0.2
      */
-    public static String shortMessage( List messages )
+    public static String shortMessage( List<CompilerError> messages )
     {
         StringBuffer sb = new StringBuffer();
 

Modified: maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilerMojo.java?rev=907726&r1=907725&r2=907726&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilerMojo.java (original)
+++ maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilerMojo.java Mon Feb  8 17:06:16 2010
@@ -51,7 +51,7 @@
      * @required
      * @readonly
      */
-    private List compileSourceRoots;
+    private List<String> compileSourceRoots;
 
     /**
      * Project classpath.
@@ -60,7 +60,7 @@
      * @required
      * @readonly
      */
-    private List classpathElements;
+    private List<String> classpathElements;
 
     /**
      * The directory for compiled classes.
@@ -86,21 +86,21 @@
      *
      * @parameter
      */
-    private Set includes = new HashSet();
+    private Set<String> includes = new HashSet<String>();
 
     /**
      * A list of exclusion filters for the compiler.
      *
      * @parameter
      */
-    private Set excludes = new HashSet();
+    private Set<String> excludes = new HashSet<String>();
 
-    protected List getCompileSourceRoots()
+    protected List<String> getCompileSourceRoots()
     {
         return compileSourceRoots;
     }
 
-    protected List getClasspathElements()
+    protected List<String> getClasspathElements()
     {
         return classpathElements;
     }
@@ -174,7 +174,7 @@
       return compilerArgument;
     }
 
-    protected Map getCompilerArguments()
+    protected Map<String, String> getCompilerArguments()
     {
       return compilerArguments;
     }

Modified: maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/TestCompilerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/TestCompilerMojo.java?rev=907726&r1=907725&r2=907726&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/TestCompilerMojo.java (original)
+++ maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/TestCompilerMojo.java Mon Feb  8 17:06:16 2010
@@ -58,7 +58,7 @@
      * @required
      * @readonly
      */
-    private List compileSourceRoots;
+    private List<String> compileSourceRoots;
 
     /**
      * Project test classpath.
@@ -67,7 +67,7 @@
      * @required
      * @readonly
      */
-    private List classpathElements;
+    private List<String> classpathElements;
 
     /**
      * The directory where compiled test classes go.
@@ -83,14 +83,14 @@
      *
      * @parameter
      */
-    private Set testIncludes = new HashSet();
+    private Set<String> testIncludes = new HashSet<String>();
 
     /**
      * A list of exclusion filters for the compiler.
      *
      * @parameter
      */
-    private Set testExcludes = new HashSet();
+    private Set<String> testExcludes = new HashSet<String>();
 
     /**
      * The -source argument for the test Java compiler.
@@ -121,7 +121,7 @@
      * @parameter
      * @since 2.1
      */
-    private Map testCompilerArguments;
+    private Map<String, String> testCompilerArguments;
 
     /**
      * <p>
@@ -150,12 +150,12 @@
         }
     }
 
-    protected List getCompileSourceRoots()
+    protected List<String> getCompileSourceRoots()
     {
         return compileSourceRoots;
     }
 
-    protected List getClasspathElements()
+    protected List<String> getClasspathElements()
     {
         return classpathElements;
     }
@@ -221,7 +221,7 @@
       return testCompilerArgument == null ? compilerArgument : testCompilerArgument;
     }
 
-    protected Map getCompilerArguments()
+    protected Map<String, String> getCompilerArguments()
     {
       return testCompilerArguments == null ? compilerArguments : testCompilerArguments;
     }