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 2012/08/27 23:08:48 UTC

svn commit: r1377866 - in /maven/plugins/trunk/maven-resources-plugin/src: main/java/org/apache/maven/plugin/resources/ test/java/org/apache/maven/plugin/resources/ test/java/org/apache/maven/plugin/resources/filters/ test/java/org/apache/maven/plugin/...

Author: hboutemy
Date: Mon Aug 27 21:08:48 2012
New Revision: 1377866

URL: http://svn.apache.org/viewvc?rev=1377866&view=rev
Log:
o ensure close stream
o generics

Modified:
    maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/CopyResourcesMojo.java
    maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/PropertyUtils.java
    maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java
    maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/AbstractPropertyUtilsTest.java
    maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/ResourcesMojoTest.java
    maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/filters/ItFilter.java
    maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/stub/MavenProjectBuildStub.java

Modified: maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/CopyResourcesMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/CopyResourcesMojo.java?rev=1377866&r1=1377865&r2=1377866&view=diff
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/CopyResourcesMojo.java (original)
+++ maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/CopyResourcesMojo.java Mon Aug 27 21:08:48 2012
@@ -19,6 +19,7 @@ package org.apache.maven.plugin.resource
  * under the License.
  */
 
+import org.apache.maven.model.Resource;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 
@@ -30,27 +31,24 @@ import java.util.List;
  * 
  * @author Olivier Lamy
  * @since 2.3
- *
  */
-@Mojo( name = "copy-resources", threadSafe = true)
+@Mojo( name = "copy-resources", threadSafe = true )
 public class CopyResourcesMojo
     extends ResourcesMojo
 {
     
     /**
      * The output directory into which to copy the resources.
-     *
      */
-    @Parameter(required = true)
+    @Parameter( required = true )
     private File outputDirectory;
 
     /**
      * The list of resources we want to transfer. See the Maven Model for a
      * description of how to code the resources element.
-     *
      */
-    @Parameter(required = true)
-    private List resources;
+    @Parameter( required = true )
+    private List<Resource> resources;
 
 
     public File getOutputDirectory()
@@ -63,22 +61,22 @@ public class CopyResourcesMojo
         this.outputDirectory = outputDirectory;
     }
 
-    public List getResources()
+    public List<Resource> getResources()
     {
         return resources;
     }
 
-    public void setResources( List resources )
+    public void setResources( List<Resource> resources )
     {
         this.resources = resources;
     }
 
-    public List getFilters()
+    public List<String> getFilters()
     {
         return filters;
     }
 
-    public void setFilters( List filters )
+    public void setFilters( List<String> filters )
     {
         this.filters = filters;
     }    

Modified: maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/PropertyUtils.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/PropertyUtils.java?rev=1377866&r1=1377865&r2=1377866&view=diff
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/PropertyUtils.java (original)
+++ maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/PropertyUtils.java Mon Aug 27 21:08:48 2012
@@ -86,7 +86,7 @@ public final class PropertyUtils
         // as can be verified by replacing the implementation of #loadPropertyFile(File, boolean, boolean)
         // with the commented variant I have provided that reuses this method.
 
-        for ( Iterator iter = fileProps.keySet().iterator(); iter.hasNext(); )
+        for ( Iterator<?> iter = fileProps.keySet().iterator(); iter.hasNext(); )
         {
             final String k = (String) iter.next();
             final String propValue = getPropertyValue( k, combinedProps );

Modified: maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java?rev=1377866&r1=1377865&r2=1377866&view=diff
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java (original)
+++ maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java Mon Aug 27 21:08:48 2012
@@ -44,7 +44,6 @@ import java.io.File;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
 
@@ -252,7 +251,7 @@ public class ResourcesMojo
                                    + ", i.e. build is platform dependent!" );
             }
 
-            List filters = getCombinedFiltersList();
+            List<String> filters = getCombinedFiltersList();
 
             MavenResourcesExecution mavenResourcesExecution =
                 new MavenResourcesExecution( getResources(), getOutputDirectory(), project, encoding, filters,
@@ -317,9 +316,8 @@ public class ResourcesMojo
 
         if ( mavenFilteringHints != null )
         {
-            for ( Iterator ite = mavenFilteringHints.iterator(); ite.hasNext(); )
+            for ( String hint : mavenFilteringHints )
             {
-                String hint = (String) ite.next();
                 try
                 {
                     mavenFilteringComponents.add(

Modified: maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/AbstractPropertyUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/AbstractPropertyUtilsTest.java?rev=1377866&r1=1377865&r2=1377866&view=diff
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/AbstractPropertyUtilsTest.java (original)
+++ maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/AbstractPropertyUtilsTest.java Mon Aug 27 21:08:48 2012
@@ -22,15 +22,16 @@ package org.apache.maven.plugin.resource
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.Enumeration;
 import java.util.Properties;
 
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.codehaus.plexus.util.IOUtil;
 
 /**
  * Base class for propertyutils test case
  */
-
 public abstract class AbstractPropertyUtilsTest
     extends AbstractMojoTestCase
 {
@@ -68,7 +69,7 @@ public abstract class AbstractPropertyUt
     {
         boolean bRetVal = false;
 
-        Enumeration propKeys = prop.keys();
+        Enumeration<?> propKeys = prop.keys();
         String key;
 
         while ( propKeys.hasMoreElements() )
@@ -93,14 +94,20 @@ public abstract class AbstractPropertyUt
     private void loadValidationProperties( File validationPropFile )
     {
         validationProp = new Properties();
+        InputStream in = null;
 
         try
         {
-            validationProp.load( new FileInputStream( validationPropFile ) );
+            in = new FileInputStream( validationPropFile );
+            validationProp.load( in );
         }
         catch ( IOException ex )
         {
             // TODO: do error handling
         }
+        finally
+        {
+            IOUtil.close( in );
+        }
     }
 }

Modified: maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/ResourcesMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/ResourcesMojoTest.java?rev=1377866&r1=1377865&r2=1377866&view=diff
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/ResourcesMojoTest.java (original)
+++ maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/ResourcesMojoTest.java Mon Aug 27 21:08:48 2012
@@ -23,12 +23,14 @@ import org.apache.maven.execution.MavenS
 import org.apache.maven.plugin.resources.stub.MavenProjectResourcesStub;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
 
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileReader;
 import java.io.IOException;
+import java.io.Reader;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Properties;
@@ -639,7 +641,16 @@ public class ResourcesMojoTest
     {
         assertTrue( FileUtils.fileExists( fileName ) );
 
-        assertEquals( data, new BufferedReader( new FileReader( fileName ) ).readLine() );
+        Reader reader = null;
+        try
+        {
+            reader = new FileReader( fileName );
+            assertEquals( data, new BufferedReader( reader ).readLine() );
+        }
+        finally
+        {
+            IOUtil.close( reader );
+        }
     }
 
 }

Modified: maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/filters/ItFilter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/filters/ItFilter.java?rev=1377866&r1=1377865&r2=1377866&view=diff
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/filters/ItFilter.java (original)
+++ maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/filters/ItFilter.java Mon Aug 27 21:08:48 2012
@@ -89,7 +89,7 @@ public class ItFilter
         try
         {
             File f = new File( mavenResourcesExecution.getOutputDirectory(), "foo.txt" );
-            List lines = new ArrayList();
+            List<String> lines = new ArrayList<String>();
             
             lines.add( "foo" );
             lines.add( "version="+mavenResourcesExecution.getMavenProject().getVersion() );

Modified: maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/stub/MavenProjectBuildStub.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/stub/MavenProjectBuildStub.java?rev=1377866&r1=1377865&r2=1377866&view=diff
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/stub/MavenProjectBuildStub.java (original)
+++ maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/stub/MavenProjectBuildStub.java Mon Aug 27 21:08:48 2012
@@ -51,11 +51,11 @@ public class MavenProjectBuildStub
 
     protected String targetTestResourcesDirectory;
 
-    protected ArrayList fileList;
+    protected ArrayList<String> fileList;
 
-    protected ArrayList directoryList;
+    protected ArrayList<String> directoryList;
 
-    protected HashMap dataMap;
+    protected HashMap<String, String> dataMap;
 
     public MavenProjectBuildStub( String key )
         throws Exception
@@ -63,9 +63,9 @@ public class MavenProjectBuildStub
         super( key );
 
         build = new Build();
-        fileList = new ArrayList();
-        directoryList = new ArrayList();
-        dataMap = new HashMap();
+        fileList = new ArrayList<String>();
+        directoryList = new ArrayList<String>();
+        dataMap = new HashMap<String, String>();
         setupBuild();
     }
 
@@ -161,7 +161,7 @@ public class MavenProjectBuildStub
         build.setOutputDirectory( outputDirectory );
         build.setTestOutputDirectory( testOutputDirectory );
     }
-    
+
     public void cleanBuildEnvironment()
         throws Exception
     {
@@ -169,17 +169,17 @@ public class MavenProjectBuildStub
         {
             FileUtils.deleteDirectory( resourcesDirectory );
         }
-        
+
         if ( FileUtils.fileExists( testResourcesDirectory ) )
         {
             FileUtils.deleteDirectory( testResourcesDirectory );
         }
-        
+
         if ( FileUtils.fileExists( outputDirectory ) )
         {
             FileUtils.deleteDirectory( outputDirectory );
         }
-        
+
         if ( FileUtils.fileExists( testOutputDirectory ) )
         {
             FileUtils.deleteDirectory( testOutputDirectory );
@@ -221,9 +221,9 @@ public class MavenProjectBuildStub
     {
         File currentDirectory;
 
-        for ( int nIndex = 0; nIndex < directoryList.size(); nIndex++ )
+        for ( String directory : directoryList )
         {
-            currentDirectory = new File( parent, "/" + (String) directoryList.get( nIndex ) );
+            currentDirectory = new File( parent, "/" + directory );
 
             if ( !currentDirectory.exists() )
             {
@@ -231,7 +231,7 @@ public class MavenProjectBuildStub
             }
 
             // duplicate dir structure in test resources
-            currentDirectory = new File( testparent, "/" + (String) directoryList.get( nIndex ) );
+            currentDirectory = new File( testparent, "/" + directory );
 
             if ( !currentDirectory.exists() )
             {
@@ -244,9 +244,9 @@ public class MavenProjectBuildStub
     {
         File currentFile;
 
-        for ( int nIndex = 0; nIndex < fileList.size(); nIndex++ )
+        for ( String file : fileList )
         {
-            currentFile = new File( parent, (String) fileList.get( nIndex ) );
+            currentFile = new File( parent, file );
 
             // create the necessary parent directories
             // before we create the files
@@ -269,7 +269,7 @@ public class MavenProjectBuildStub
             }
 
             // duplicate file in test resources
-            currentFile = new File( testparent, (String) fileList.get( nIndex ) );
+            currentFile = new File( testparent, file );
 
             if ( !currentFile.getParentFile().exists() )
             {