maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject [20/50] git commit: added more generics
Date Sat, 01 Dec 2012 10:39:55 GMT
added more generics

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-2/branches/maven-2.2.x@1096343 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/c0e53b5f
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/c0e53b5f
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/c0e53b5f

Branch: refs/heads/maven-2.2.x
Commit: c0e53b5f2b1d84e3a17d4ac6db825cad22308ce9
Parents: 8643b0d
Author: Herve Boutemy <hboutemy@apache.org>
Authored: Sun Apr 24 16:24:39 2011 +0000
Committer: Herve Boutemy <hboutemy@apache.org>
Committed: Sun Apr 24 16:24:39 2011 +0000

----------------------------------------------------------------------
 .../org/apache/maven/artifact/ArtifactUtils.java   |   23 ++---
 .../maven/plugin/descriptor/MojoDescriptor.java    |   24 ++---
 .../maven/plugin/descriptor/PluginDescriptor.java  |   68 +++++++--------
 3 files changed, 52 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/c0e53b5f/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
----------------------------------------------------------------------
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java b/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
index e0c7a3e..b622773 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
@@ -23,7 +23,6 @@ import org.apache.maven.artifact.versioning.VersionRange;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -86,16 +85,14 @@ public final class ArtifactUtils
             + baseVersion;
     }
 
-    public static Map artifactMapByVersionlessId( Collection artifacts )
+    public static Map<String, Artifact> artifactMapByVersionlessId( Collection<Artifact>
artifacts )
     {
-        Map artifactMap = new LinkedHashMap();
+        Map<String, Artifact> artifactMap = new LinkedHashMap<String, Artifact>();
 
         if ( artifacts != null )
         {
-            for ( Iterator it = artifacts.iterator(); it.hasNext(); )
+            for ( Artifact artifact : artifacts )
             {
-                Artifact artifact = (Artifact) it.next();
-
                 artifactMap.put( versionlessKey( artifact ), artifact );
             }
         }
@@ -103,16 +100,14 @@ public final class ArtifactUtils
         return artifactMap;
     }
 
-    public static Map artifactMapByArtifactId( Collection artifacts )
+    public static Map<String, Artifact> artifactMapByArtifactId( Collection<Artifact>
artifacts )
     {
-        Map artifactMap = new LinkedHashMap();
+        Map<String, Artifact> artifactMap = new LinkedHashMap<String, Artifact>();
 
         if ( artifacts != null )
         {
-            for ( Iterator it = artifacts.iterator(); it.hasNext(); )
+            for ( Artifact artifact : artifacts )
             {
-                Artifact artifact = (Artifact) it.next();
-
                 artifactMap.put( artifact.getId(), artifact );
             }
         }
@@ -141,13 +136,13 @@ public final class ArtifactUtils
         return clone;
     }
 
-    private static List copyList( List original )
+    private static <T> List<T> copyList( List<T> original )
     {
-        List copy = null;
+        List<T> copy = null;
 
         if ( original != null )
         {
-            copy = new ArrayList();
+            copy = new ArrayList<T>();
 
             if ( !original.isEmpty() )
             {

http://git-wip-us.apache.org/repos/asf/maven/blob/c0e53b5f/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java
----------------------------------------------------------------------
diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java
b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java
index dc93db2..b565486 100644
--- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java
+++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java
@@ -25,7 +25,6 @@ import org.codehaus.plexus.configuration.PlexusConfiguration;
 import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
 
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -57,9 +56,9 @@ public class MojoDescriptor
 
     private static final String DEFAULT_LANGUAGE = "java";
 
-    private List parameters;
+    private List<Parameter> parameters;
 
-    private Map parameterMap;
+    private Map<String, Parameter> parameterMap;
 
     /** By default, the execution strategy is "once-per-session" */
     private String executionStrategy = SINGLE_PASS_EXEC_STRATEGY;
@@ -107,7 +106,7 @@ public class MojoDescriptor
     /**  Plugin descriptor */
     private PluginDescriptor pluginDescriptor;
 
-    /**  By default, the Mojo is herited */
+    /**  By default, the Mojo is inherited */
     private boolean inheritedByDefault = true;
 
     /**  By default, the Mojo could not be invoke directly */
@@ -164,7 +163,7 @@ public class MojoDescriptor
     /**
      * @return the list of parameters
      */
-    public List getParameters()
+    public List<Parameter> getParameters()
     {
         return parameters;
     }
@@ -173,12 +172,11 @@ public class MojoDescriptor
      * @param parameters the new list of parameters
      * @throws DuplicateParameterException if any
      */
-    public void setParameters( List parameters )
+    public void setParameters( List<Parameter> parameters )
         throws DuplicateParameterException
     {
-        for ( Iterator it = parameters.iterator(); it.hasNext(); )
+        for ( Parameter parameter : parameters )
         {
-            Parameter parameter = (Parameter) it.next();
             addParameter( parameter );
         }
     }
@@ -199,7 +197,7 @@ public class MojoDescriptor
 
         if ( parameters == null )
         {
-            parameters = new LinkedList();
+            parameters = new LinkedList<Parameter>();
         }
 
         parameters.add( parameter );
@@ -210,18 +208,16 @@ public class MojoDescriptor
     /**
      * @return the list parameters as a Map
      */
-    public Map getParameterMap()
+    public Map<String, Parameter> getParameterMap()
     {
         if ( parameterMap == null )
         {
-            parameterMap = new HashMap();
+            parameterMap = new HashMap<String, Parameter>();
 
             if ( parameters != null )
             {
-                for ( Iterator iterator = parameters.iterator(); iterator.hasNext(); )
+                for ( Parameter pd : parameters )
                 {
-                    Parameter pd = (Parameter) iterator.next();
-
                     parameterMap.put( pd.getName(), pd );
                 }
             }

http://git-wip-us.apache.org/repos/asf/maven/blob/c0e53b5f/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java
----------------------------------------------------------------------
diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java
b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java
index 5726146..6c7cbf5 100644
--- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java
+++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java
@@ -27,15 +27,15 @@ import org.apache.maven.plugin.lifecycle.io.xpp3.LifecycleMappingsXpp3Reader;
 import org.codehaus.classworlds.ClassRealm;
 import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
 import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.InputStreamReader;
+import java.io.Reader;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -47,6 +47,9 @@ import java.util.Set;
 public class PluginDescriptor
     extends ComponentSetDescriptor
 {
+
+    private static final String LIFECYCLE_DESCRIPTOR = "META-INF/maven/lifecycle.xml";
+
     private String groupId;
 
     private String artifactId;
@@ -61,16 +64,16 @@ public class PluginDescriptor
     
     private Artifact pluginArtifact;
 
-    private List artifacts;
+    private List<Artifact> artifacts;
 
-    private Map lifecycleMappings;
+    private Map<String, Lifecycle> lifecycleMappings;
 
     private ClassRealm classRealm;
 
     // calculated on-demand.
-    private Map artifactMap;
+    private Map<String, Artifact> artifactMap;
 
-    private Set introducedDependencyArtifacts;
+    private Set<Artifact> introducedDependencyArtifacts;
 
     private String name;
 
@@ -80,7 +83,8 @@ public class PluginDescriptor
     //
     // ----------------------------------------------------------------------
 
-    public List getMojos()
+    @SuppressWarnings( { "unchecked", "rawtypes" } )
+    public List<MojoDescriptor> getMojos()
     {
         return getComponents();
     }
@@ -92,7 +96,7 @@ public class PluginDescriptor
         // this relies heavily on the equals() and hashCode() for ComponentDescriptor,
         // which uses role:roleHint for identity...and roleHint == goalPrefix:goal.
         // role does not vary for Mojos.
-        List mojos = getComponents();
+        List<MojoDescriptor> mojos = getMojos();
 
         if ( mojos != null && mojos.contains( mojoDescriptor ) )
         {
@@ -232,12 +236,12 @@ public class PluginDescriptor
         this.inheritedByDefault = inheritedByDefault;
     }
 
-    public List getArtifacts()
+    public List<Artifact> getArtifacts()
     {
         return artifacts;
     }
 
-    public void setArtifacts( List artifacts )
+    public void setArtifacts( List<Artifact> artifacts )
     {
         this.artifacts = artifacts;
 
@@ -245,7 +249,7 @@ public class PluginDescriptor
         artifactMap = null;
     }
 
-    public Map getArtifactMap()
+    public Map<String, Artifact> getArtifactMap()
     {
         if ( artifactMap == null )
         {
@@ -278,18 +282,15 @@ public class PluginDescriptor
         }
 
         // TODO: could we use a map? Maybe if the parent did that for components too, as
this is too vulnerable to
-        // changes above not being propogated to the map
-
-        MojoDescriptor mojoDescriptor = null;
-        for ( Iterator i = getMojos().iterator(); i.hasNext() && mojoDescriptor ==
null; )
+        // changes above not being propagated to the map
+        for ( MojoDescriptor desc : getMojos() )
         {
-            MojoDescriptor desc = (MojoDescriptor) i.next();
             if ( goal.equals( desc.getGoal() ) )
             {
-                mojoDescriptor = desc;
+                return desc;
             }
         }
-        return mojoDescriptor;
+        return null;
     }
 
     public Lifecycle getLifecycleMapping( String lifecycle )
@@ -297,36 +298,32 @@ public class PluginDescriptor
     {
         if ( lifecycleMappings == null )
         {
-            LifecycleMappingsXpp3Reader reader = new LifecycleMappingsXpp3Reader();
-            InputStreamReader r = null;
             LifecycleConfiguration config;
 
+            Reader reader = null;
             try
             {
-                InputStream resourceAsStream = classRealm.getResourceAsStream( "/META-INF/maven/lifecycle.xml"
);
+                InputStream resourceAsStream = classRealm.getResourceAsStream( LIFECYCLE_DESCRIPTOR
);
                 if ( resourceAsStream == null )
                 {
-                    throw new FileNotFoundException( "Unable to find /META-INF/maven/lifecycle.xml
in the plugin" );
+                    throw new FileNotFoundException( "Unable to find " + LIFECYCLE_DESCRIPTOR
+ " in the plugin" );
                 }
-                r = new InputStreamReader( resourceAsStream );
-                config = reader.read( r, true );
+                reader = ReaderFactory.newXmlReader( resourceAsStream );
+                config = new LifecycleMappingsXpp3Reader().read( reader, true );
             }
             finally
             {
-                IOUtil.close( r );
+                IOUtil.close( reader );
             }
 
-            Map map = new HashMap();
+            lifecycleMappings = new HashMap<String, Lifecycle>();
 
-            for ( Iterator i = config.getLifecycles().iterator(); i.hasNext(); )
+            for ( Lifecycle l : config.getLifecycles() )
             {
-                Lifecycle l = (Lifecycle) i.next();
-                map.put( l.getId(), l );
+                lifecycleMappings.put( l.getId(), l );
             }
-
-            lifecycleMappings = map;
         }
-        return (Lifecycle) lifecycleMappings.get( lifecycle );
+        return lifecycleMappings.get( lifecycle );
     }
 
     public void setClassRealm( ClassRealm classRealm )
@@ -339,14 +336,15 @@ public class PluginDescriptor
         return classRealm;
     }
 
-    public void setIntroducedDependencyArtifacts( Set introducedDependencyArtifacts )
+    public void setIntroducedDependencyArtifacts( Set<Artifact> introducedDependencyArtifacts
)
     {
         this.introducedDependencyArtifacts = introducedDependencyArtifacts;
     }
 
-    public Set getIntroducedDependencyArtifacts()
+    public Set<Artifact> getIntroducedDependencyArtifacts()
     {
-        return introducedDependencyArtifacts != null ? introducedDependencyArtifacts : Collections.EMPTY_SET;
+        return ( introducedDependencyArtifacts != null ) ? introducedDependencyArtifacts
+                        : Collections.<Artifact> emptySet();
     }
 
     public void setName( String name )


Mime
View raw message