maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rfscho...@apache.org
Subject svn commit: r1355671 - in /maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war: AbstractWarMojo.java Overlay.java overlay/OverlayManager.java
Date Sat, 30 Jun 2012 09:17:26 GMT
Author: rfscholte
Date: Sat Jun 30 09:17:25 2012
New Revision: 1355671

URL: http://svn.apache.org/viewvc?rev=1355671&view=rev
Log:
Improve generics

Modified:
    maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java
    maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/Overlay.java
    maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/overlay/OverlayManager.java

Modified: maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java?rev=1355671&r1=1355670&r2=1355671&view=diff
==============================================================================
--- maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java
(original)
+++ maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/AbstractWarMojo.java
Sat Jun 30 09:17:25 2012
@@ -24,7 +24,6 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.maven.archiver.MavenArchiveConfiguration;
@@ -55,6 +54,7 @@ import org.apache.maven.shared.filtering
 import org.codehaus.plexus.archiver.Archiver;
 import org.codehaus.plexus.archiver.jar.JarArchiver;
 import org.codehaus.plexus.archiver.manager.ArchiverManager;
+import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.StringUtils;
 
 /**
@@ -127,7 +127,7 @@ public abstract class AbstractWarMojo
      * Filters (property files) to include during the interpolation of the pom.xml.
      */
     @Parameter
-    private List filters;
+    private List<String> filters;
 
     /**
      * The path to the web.xml file to use.
@@ -236,7 +236,7 @@ public abstract class AbstractWarMojo
      * @since 2.1-alpha-1
      */
     @Parameter
-    private List overlays = new ArrayList();
+    private List<Overlay> overlays = new ArrayList<Overlay>();
 
     /**
      * A list of file extensions that should not be filtered.
@@ -245,7 +245,7 @@ public abstract class AbstractWarMojo
      * @since 2.1-alpha-2
      */
     @Parameter
-    private List nonFilteredFileExtensions;
+    private List<String> nonFilteredFileExtensions;
 
     /**
      * @since 2.1-alpha-2
@@ -304,7 +304,7 @@ public abstract class AbstractWarMojo
      */
     protected String[] getExcludes()
     {
-        List excludeList = new ArrayList();
+        List<String> excludeList = new ArrayList<String>();
         if ( StringUtils.isNotEmpty( warSourceExcludes ) )
         {
             excludeList.addAll( Arrays.asList( StringUtils.split( warSourceExcludes, ","
) ) );
@@ -396,6 +396,7 @@ public abstract class AbstractWarMojo
      * @throws MojoFailureException   if an unexpected error occurred while packaging the
webapp
      * @throws IOException            if an error occurred while copying the files
      */
+    @SuppressWarnings( "unchecked" )
     public void buildWebapp( MavenProject project, File webappDirectory )
         throws MojoExecutionException, MojoFailureException, IOException
     {
@@ -415,8 +416,8 @@ public abstract class AbstractWarMojo
 
         final OverlayManager overlayManager =
             new OverlayManager( overlays, project, dependentWarIncludes, dependentWarExcludes,
currentProjectOverlay );
-        final List packagingTasks = getPackagingTasks( overlayManager );
-        List defaultFilterWrappers = null;
+        final List<WarPackagingTask> packagingTasks = getPackagingTasks( overlayManager
);
+        List<FileUtils.FilterWrapper> defaultFilterWrappers = null;
         try
         {
             MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution();
@@ -438,21 +439,16 @@ public abstract class AbstractWarMojo
                                                                             getNonFilteredFileExtensions(),
                                                                             filteringDeploymentDescriptors,
                                                                             this.artifactFactory
);
-        final Iterator it = packagingTasks.iterator();
-        while ( it.hasNext() )
+        for ( WarPackagingTask warPackagingTask : packagingTasks )
         {
-            WarPackagingTask warPackagingTask = (WarPackagingTask) it.next();
             warPackagingTask.performPackaging( context );
         }
 
         // Post packaging
-        final List postPackagingTasks = getPostPackagingTasks();
-        final Iterator it2 = postPackagingTasks.iterator();
-        while ( it2.hasNext() )
+        final List<WarPostPackagingTask> postPackagingTasks = getPostPackagingTasks();
+        for( WarPostPackagingTask task  : postPackagingTasks )
         {
-            WarPostPackagingTask task = (WarPostPackagingTask) it2.next();
             task.performPostPackaging( context );
-
         }
         getLog().info( "Webapp assembled in [" + ( System.currentTimeMillis() - startTime
) + " msecs]" );
 
@@ -466,20 +462,18 @@ public abstract class AbstractWarMojo
      * @return the list of packaging tasks
      * @throws MojoExecutionException if the packaging tasks could not be built
      */
-    private List getPackagingTasks( OverlayManager overlayManager )
+    private List<WarPackagingTask> getPackagingTasks( OverlayManager overlayManager
)
         throws MojoExecutionException
     {
-        final List packagingTasks = new ArrayList();
+        final List<WarPackagingTask> packagingTasks = new ArrayList<WarPackagingTask>();
         if ( useCache )
         {
             packagingTasks.add( new DependenciesAnalysisPackagingTask() );
         }
 
-        final List resolvedOverlays = overlayManager.getOverlays();
-        final Iterator it = resolvedOverlays.iterator();
-        while ( it.hasNext() )
+        final List<Overlay> resolvedOverlays = overlayManager.getOverlays();
+        for ( Overlay overlay : resolvedOverlays )
         {
-            Overlay overlay = (Overlay) it.next();
             if ( overlay.isCurrentProject() )
             {
                 packagingTasks.add( new WarProjectPackagingTask( webResources, webXml, containerConfigXML,
@@ -500,9 +494,9 @@ public abstract class AbstractWarMojo
      *
      * @return the list of post packaging tasks
      */
-    private List getPostPackagingTasks()
+    private List<WarPostPackagingTask> getPostPackagingTasks()
     {
-        final List postPackagingTasks = new ArrayList();
+        final List<WarPostPackagingTask> postPackagingTasks = new ArrayList<WarPostPackagingTask>();
         if ( useCache )
         {
             postPackagingTasks.add( new SaveWebappStructurePostPackagingTask( cacheFile )
);
@@ -526,15 +520,15 @@ public abstract class AbstractWarMojo
 
         private final OverlayManager overlayManager;
 
-        private final List filterWrappers;
+        private final List<FileUtils.FilterWrapper> filterWrappers;
 
-        private List nonFilteredFileExtensions;
+        private List<String> nonFilteredFileExtensions;
 
         private boolean filteringDeploymentDescriptors;
 
         public DefaultWarPackagingContext( File webappDirectory, final WebappStructure webappStructure,
-                                           final OverlayManager overlayManager, List filterWrappers,
-                                           List nonFilteredFileExtensions, boolean filteringDeploymentDescriptors,
+                                           final OverlayManager overlayManager, List<FileUtils.FilterWrapper>
filterWrappers,
+                                           List<String>  nonFilteredFileExtensions,
boolean filteringDeploymentDescriptors,
                                            ArtifactFactory artifactFactory )
         {
             this.webappDirectory = webappDirectory;
@@ -543,14 +537,12 @@ public abstract class AbstractWarMojo
             this.filterWrappers = filterWrappers;
             this.artifactFactory = artifactFactory;
             this.filteringDeploymentDescriptors = filteringDeploymentDescriptors;
-            this.nonFilteredFileExtensions = nonFilteredFileExtensions == null ? Collections.EMPTY_LIST
+            this.nonFilteredFileExtensions = nonFilteredFileExtensions == null ? Collections.<String>emptyList()
                                                                               : nonFilteredFileExtensions;
             // This is kinda stupid but if we loop over the current overlays and we request
the path structure
             // it will register it. This will avoid wrong warning messages in a later phase
-            final Iterator it = overlayManager.getOverlayIds().iterator();
-            while ( it.hasNext() )
+            for ( String overlayId : overlayManager.getOverlayIds() )
             {
-                String overlayId = (String) it.next();
                 webappStructure.getStructure( overlayId );
             }
         }
@@ -620,7 +612,7 @@ public abstract class AbstractWarMojo
             return jarArchiver;
         }
 
-        public List getFilters()
+        public List<String> getFilters()
         {
             return filters;
         }
@@ -630,7 +622,7 @@ public abstract class AbstractWarMojo
             return webappStructure;
         }
 
-        public List getOwnerIds()
+        public List<String> getOwnerIds()
         {
             return overlayManager.getOverlayIds();
         }
@@ -640,7 +632,7 @@ public abstract class AbstractWarMojo
             return mavenFileFilter;
         }
 
-        public List getFilterWrappers()
+        public List<FileUtils.FilterWrapper> getFilterWrappers()
         {
             return filterWrappers;
         }
@@ -736,12 +728,12 @@ public abstract class AbstractWarMojo
         this.outputFileNameMapping = outputFileNameMapping;
     }
 
-    public List getOverlays()
+    public List<Overlay> getOverlays()
     {
         return overlays;
     }
 
-    public void setOverlays( List overlays )
+    public void setOverlays( List<Overlay> overlays )
     {
         this.overlays = overlays;
     }
@@ -781,12 +773,12 @@ public abstract class AbstractWarMojo
         this.webResources = webResources;
     }
 
-    public List getFilters()
+    public List<String> getFilters()
     {
         return filters;
     }
 
-    public void setFilters( List filters )
+    public void setFilters( List<String> filters )
     {
         this.filters = filters;
     }
@@ -847,12 +839,12 @@ public abstract class AbstractWarMojo
         return archive;
     }
 
-    public List getNonFilteredFileExtensions()
+    public List<String> getNonFilteredFileExtensions()
     {
         return nonFilteredFileExtensions;
     }
 
-    public void setNonFilteredFileExtensions( List nonFilteredFileExtensions )
+    public void setNonFilteredFileExtensions( List<String> nonFilteredFileExtensions
)
     {
         this.nonFilteredFileExtensions = nonFilteredFileExtensions;
     }

Modified: maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/Overlay.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/Overlay.java?rev=1355671&r1=1355670&r2=1355671&view=diff
==============================================================================
--- maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/Overlay.java
(original)
+++ maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/Overlay.java
Sat Jun 30 09:17:25 2012
@@ -280,7 +280,7 @@ public class Overlay
 
     private String[] parse( String s )
     {
-        final List result = new ArrayList();
+        final List<String> result = new ArrayList<String>();
         if ( s == null )
         {
             return (String[]) result.toArray( new String[result.size()] );

Modified: maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/overlay/OverlayManager.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/overlay/OverlayManager.java?rev=1355671&r1=1355670&r2=1355671&view=diff
==============================================================================
--- maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/overlay/OverlayManager.java
(original)
+++ maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/overlay/OverlayManager.java
Sat Jun 30 09:17:25 2012
@@ -19,19 +19,18 @@ package org.apache.maven.plugin.war.over
  * under the License.
  */
 
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
-import org.apache.maven.plugin.war.Overlay;
-import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.util.StringUtils;
-
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Set;
 
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
+import org.apache.maven.plugin.war.Overlay;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.StringUtils;
+
 /**
  * Manages the overlays.
  *
@@ -41,11 +40,11 @@ import java.util.Set;
  */
 public class OverlayManager
 {
-    private final List overlays;
+    private final List<Overlay> overlays;
 
     private final MavenProject project;
 
-    private final List artifactsOverlays;
+    private final List<Artifact> artifactsOverlays;
 
     /**
      * Creates a manager with the specified overlays.
@@ -61,11 +60,11 @@ public class OverlayManager
      * @throws InvalidOverlayConfigurationException
      *          if the config is invalid
      */
-    public OverlayManager( List overlays, MavenProject project, String defaultIncludes, String
defaultExcludes,
+    public OverlayManager( List<Overlay> overlays, MavenProject project, String defaultIncludes,
String defaultExcludes,
                            Overlay currentProjectOverlay )
         throws InvalidOverlayConfigurationException
     {
-        this.overlays = new ArrayList();
+        this.overlays = new ArrayList<Overlay>();
         if ( overlays != null )
         {
             this.overlays.addAll( overlays );
@@ -85,7 +84,7 @@ public class OverlayManager
      *
      * @return the overlays
      */
-    public List getOverlays()
+    public List<Overlay> getOverlays()
     {
         return overlays;
     }
@@ -95,13 +94,11 @@ public class OverlayManager
      *
      * @return the overlay ids
      */
-    public List getOverlayIds()
+    public List<String> getOverlayIds()
     {
-        final Iterator it = overlays.iterator();
-        final List result = new ArrayList();
-        while ( it.hasNext() )
+        final List<String> result = new ArrayList<String>();
+        for ( Overlay overlay : overlays )
         {
-            Overlay overlay = (Overlay) it.next();
             result.add( overlay.getId() );
         }
         return result;
@@ -109,7 +106,7 @@ public class OverlayManager
     }
 
     /**
-     * Intializes the manager and validates the overlays configuration.
+     * Initializes the manager and validates the overlays configuration.
      *
      * @param defaultIncludes the default includes to use
      * @param defaultExcludes the default excludes to use
@@ -123,8 +120,8 @@ public class OverlayManager
 
         // Build the list of configured artifacts and makes sure that each overlay
         // refer to a valid artifact
-        final List configuredWarArtifacts = new ArrayList();
-        final ListIterator it = overlays.listIterator();
+        final List<Artifact> configuredWarArtifacts = new ArrayList<Artifact>();
+        final ListIterator<Overlay> it = overlays.listIterator();
         while ( it.hasNext() )
         {
             Overlay overlay = (Overlay) it.next();
@@ -155,10 +152,8 @@ public class OverlayManager
         }
 
         // Build the list of missing overlays
-        final Iterator it2 = artifactsOverlays.iterator();
-        while ( it2.hasNext() )
+        for ( Artifact artifact : artifactsOverlays )
         {
-            Artifact artifact = (Artifact) it2.next();
             if ( !configuredWarArtifacts.contains( artifact ) )
             {
                 // Add a default overlay for the given artifact which will be applied after
@@ -168,10 +163,8 @@ public class OverlayManager
         }
 
         // Final validation, make sure that the current project is in there. Otherwise add
it first
-        final Iterator it3 = overlays.iterator();
-        while ( it3.hasNext() )
+        for ( Overlay overlay : overlays )
         {
-            Overlay overlay = (Overlay) it3.next();
             if ( overlay.equals( currentProjectOverlay ) )
             {
                 return;
@@ -200,10 +193,9 @@ public class OverlayManager
             return null;
         }
 
-        for ( Iterator iterator = artifactsOverlays.iterator(); iterator.hasNext(); )
+        for ( Artifact artifact : artifactsOverlays )
         {
             // Handle classifier dependencies properly (clash management)
-            Artifact artifact = (Artifact) iterator.next();
             if ( compareOverlayWithArtifact( overlay, artifact ) )
             {
                 return artifact;
@@ -211,12 +203,12 @@ public class OverlayManager
         }
 
         // maybe its a project dependencies zip or an other type
-        Set projectArtifacts = this.project.getDependencyArtifacts();
+        @SuppressWarnings( "unchecked" )
+        Set<Artifact> projectArtifacts = this.project.getDependencyArtifacts();
         if ( projectArtifacts != null )
         {
-            for ( Iterator iterator = projectArtifacts.iterator(); iterator.hasNext(); )
+            for ( Artifact artifact : projectArtifacts )
             {
-                Artifact artifact = (Artifact) iterator.next();
                 if ( compareOverlayWithArtifact( overlay, artifact ) )
                 {
                     return artifact;
@@ -248,16 +240,15 @@ public class OverlayManager
      *
      * @return the overlays as artifacts objects
      */
-    private List getOverlaysAsArtifacts()
+    private List<Artifact> getOverlaysAsArtifacts()
     {
         ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME );
-        final Set artifacts = project.getArtifacts();
-        final Iterator it = artifacts.iterator();
+        @SuppressWarnings( "unchecked" )
+        final Set<Artifact> artifacts = project.getArtifacts();
 
-        final List result = new ArrayList();
-        while ( it.hasNext() )
+        final List<Artifact> result = new ArrayList<Artifact>();
+        for ( Artifact artifact : artifacts )
         {
-            Artifact artifact = (Artifact) it.next();
             if ( !artifact.isOptional() && filter.include( artifact ) &&
( "war".equals( artifact.getType() ) ) )
             {
                 result.add( artifact );



Mime
View raw message