You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2012/01/08 14:53:35 UTC

svn commit: r1228846 - in /maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear: output/ util/

Author: rfscholte
Date: Sun Jan  8 13:53:34 2012
New Revision: 1228846

URL: http://svn.apache.org/viewvc?rev=1228846&view=rev
Log:
Add more generics

Modified:
    maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FileNameMappingFactory.java
    maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/ArtifactRepository.java
    maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/ArtifactTypeMappingService.java
    maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/EarMavenArchiver.java
    maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/JavaEEVersion.java

Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FileNameMappingFactory.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FileNameMappingFactory.java?rev=1228846&r1=1228845&r2=1228846&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FileNameMappingFactory.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FileNameMappingFactory.java Sun Jan  8 13:53:34 2012
@@ -74,7 +74,7 @@ public class FileNameMappingFactory
         }
         try
         {
-            final Class c = Class.forName( nameOrClass );
+            final Class<?> c = Class.forName( nameOrClass );
             return (FileNameMapping) c.newInstance();
         }
         catch ( ClassNotFoundException e )
@@ -98,4 +98,4 @@ public class FileNameMappingFactory
                 "Specified class[" + nameOrClass + "] does not implement[" + FileNameMapping.class.getName() + "]" );
         }
     }
-}
+}
\ No newline at end of file

Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/ArtifactRepository.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/ArtifactRepository.java?rev=1228846&r1=1228845&r2=1228846&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/ArtifactRepository.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/ArtifactRepository.java Sun Jan  8 13:53:34 2012
@@ -19,12 +19,11 @@ package org.apache.maven.plugin.ear.util
  * under the License.
  */
 
-import org.apache.maven.artifact.Artifact;
-
-import java.util.Iterator;
 import java.util.Set;
 import java.util.TreeSet;
 
+import org.apache.maven.artifact.Artifact;
+
 /**
  * An artifact repository used to resolve {@link org.apache.maven.plugin.ear.EarModule}.
  *
@@ -33,7 +32,7 @@ import java.util.TreeSet;
  */
 public class ArtifactRepository
 {
-    private final Set artifacts;
+    private final Set<Artifact> artifacts;
 
     private final String mainArtifactId;
 
@@ -46,7 +45,7 @@ public class ArtifactRepository
      * @param mainArtifactId             the id to use for the main artifact (no classifier)
      * @param artifactTypeMappingService
      */
-    public ArtifactRepository( Set artifacts, String mainArtifactId,
+    public ArtifactRepository( Set<Artifact> artifacts, String mainArtifactId,
                                ArtifactTypeMappingService artifactTypeMappingService )
     {
         this.artifacts = artifacts;
@@ -73,21 +72,19 @@ public class ArtifactRepository
      */
     public Artifact getUniqueArtifact( String groupId, String artifactId, String type, String classifier )
     {
-        final Set candidates = getArtifacts( groupId, artifactId, type );
+        final Set<Artifact> candidates = getArtifacts( groupId, artifactId, type );
         if ( candidates.size() == 0 )
         {
             return null;
         }
         else if ( candidates.size() == 1 && classifier == null )
         {
-            return (Artifact) candidates.iterator().next();
+            return candidates.iterator().next();
         }
         else if ( classifier != null )
         {
-            final Iterator it = candidates.iterator();
-            while ( it.hasNext() )
+            for ( Artifact a : candidates )
             {
-                Artifact a = (Artifact) it.next();
                 if ( a.getClassifier() == null && classifier.equals( mainArtifactId ) )
                 {
                     return a;
@@ -131,14 +128,11 @@ public class ArtifactRepository
      * @param type       the type
      * @return the artifacts or an empty set if no artifact were found
      */
-    public Set getArtifacts( String groupId, String artifactId, String type )
+    public Set<Artifact> getArtifacts( String groupId, String artifactId, String type )
     {
-        final Set result = new TreeSet();
-        final Iterator it = artifacts.iterator();
-        while ( it.hasNext() )
+        final Set<Artifact> result = new TreeSet<Artifact>();
+        for ( Artifact a : artifacts )
         {
-            Artifact a = (Artifact) it.next();
-
             // If the groupId, the artifactId and if the
             // artifact's type is known, then we have found a candidate.
             if ( a.getGroupId().equals( groupId ) && a.getArtifactId().equals( artifactId )
@@ -150,4 +144,4 @@ public class ArtifactRepository
         }
         return result;
     }
-}
+}
\ No newline at end of file

Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/ArtifactTypeMappingService.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/ArtifactTypeMappingService.java?rev=1228846&r1=1228845&r2=1228846&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/ArtifactTypeMappingService.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/ArtifactTypeMappingService.java Sun Jan  8 13:53:34 2012
@@ -19,18 +19,17 @@ package org.apache.maven.plugin.ear.util
  * under the License.
  */
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.maven.plugin.ear.EarModuleFactory;
 import org.apache.maven.plugin.ear.EarPluginException;
 import org.apache.maven.plugin.ear.UnknownArtifactTypeException;
 import org.codehaus.plexus.configuration.PlexusConfiguration;
 import org.codehaus.plexus.configuration.PlexusConfigurationException;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 /**
  * Allows to map custom artifact type to standard type.
  *
@@ -46,15 +45,15 @@ public class ArtifactTypeMappingService
     static final String MAPPING_ATTRIBUTE = "mapping";
 
     // A standard type to a list of customType
-    private final Map typeMappings;
+    private final Map<String, List<String>> typeMappings;
 
     // The user-defined mapping for direct access
-    private final Map customMappings;
+    private final Map<String, String> customMappings;
 
     public ArtifactTypeMappingService()
     {
-        this.typeMappings = new HashMap();
-        this.customMappings = new HashMap();
+        this.typeMappings = new HashMap<String, List<String>>();
+        this.customMappings = new HashMap<String, String>();
         init();
     }
 
@@ -102,7 +101,7 @@ public class ArtifactTypeMappingService
                 customMappings.put( customType, mapping );
 
                 // Register the custom mapping to its standard type
-                List typeMapping = (List) typeMappings.get( mapping );
+                List<String> typeMapping = typeMappings.get( mapping );
                 typeMapping.add( customType );
             }
         }
@@ -124,7 +123,7 @@ public class ArtifactTypeMappingService
                 "Artifact type[" + standardType + "] is not a standard Ear artifact type["
                     + EarModuleFactory.getStandardArtifactTypes() + "]" );
         }
-        final List typeMappings = (List) this.typeMappings.get( standardType );
+        final List<String> typeMappings = this.typeMappings.get( standardType );
         return typeMappings.contains( customType );
 
     }
@@ -167,14 +166,11 @@ public class ArtifactTypeMappingService
         customMappings.clear();
 
         // Initialize the mapping with the standard artifact types
-        final Iterator it = EarModuleFactory.getStandardArtifactTypes().iterator();
-        while ( it.hasNext() )
+        for ( String type : EarModuleFactory.getStandardArtifactTypes() )
         {
-            String type = (String) it.next();
-            List typeMapping = new ArrayList();
+            List<String> typeMapping = new ArrayList<String>();
             typeMapping.add( type );
             this.typeMappings.put( type, typeMapping );
         }
-
     }
-}
+}
\ No newline at end of file

Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/EarMavenArchiver.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/EarMavenArchiver.java?rev=1228846&r1=1228845&r2=1228846&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/EarMavenArchiver.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/EarMavenArchiver.java Sun Jan  8 13:53:34 2012
@@ -19,6 +19,9 @@ package org.apache.maven.plugin.ear.util
  * under the License.
  */
 
+import java.util.List;
+import java.util.Set;
+
 import org.apache.maven.archiver.MavenArchiveConfiguration;
 import org.apache.maven.archiver.MavenArchiver;
 import org.apache.maven.artifact.DependencyResolutionRequiredException;
@@ -27,10 +30,6 @@ import org.apache.maven.project.MavenPro
 import org.codehaus.plexus.archiver.jar.Manifest;
 import org.codehaus.plexus.archiver.jar.ManifestException;
 
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
 /**
  * A custom {@link MavenArchiver} implementation that takes care
  * of setting the right classpath value according to the actual
@@ -43,7 +42,7 @@ public class EarMavenArchiver
 {
     public static final String CLASS_PATH_KEY = "Class-Path";
 
-    private final List earModules;
+    private final List<EarModule> earModules;
 
 
     /**
@@ -52,7 +51,7 @@ public class EarMavenArchiver
      *
      * @param earModules the intitialized list of ear modules
      */
-    public EarMavenArchiver( List earModules )
+    public EarMavenArchiver( List<EarModule> earModules )
     {
         this.earModules = earModules;
     }
@@ -97,10 +96,8 @@ public class EarMavenArchiver
     protected String generateClassPathEntry( String classPathPrefix )
     {
         final StringBuffer classpath = new StringBuffer();
-        final Iterator it = earModules.iterator();
-        while ( it.hasNext() )
+        for ( final EarModule earModule : earModules )
         {
-            final EarModule earModule = (EarModule) it.next();
             if ( !earModule.isExcluded() )
             {
                 classpath.append( classPathPrefix ).append( earModule.getUri() ).append( " " );
@@ -113,10 +110,10 @@ public class EarMavenArchiver
     {
         if ( config.getManifestEntries() != null )
         {
-            final Set keys = config.getManifestEntries().keySet();
-            for ( Iterator iter = keys.iterator(); iter.hasNext(); )
+            @SuppressWarnings( "unchecked" )
+            final Set<String> keys = config.getManifestEntries().keySet();
+            for ( String key : keys )
             {
-                String key = (String) iter.next();
                 String value = (String) config.getManifestEntries().get( key );
                 if ( "Class-Path".equals( key ) && value != null )
                 {

Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/JavaEEVersion.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/JavaEEVersion.java?rev=1228846&r1=1228845&r2=1228846&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/JavaEEVersion.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/JavaEEVersion.java Sun Jan  8 13:53:34 2012
@@ -28,7 +28,7 @@ import java.util.Map;
  * @author Stephane Nicoll
  */
 public class JavaEEVersion
-    implements Comparable
+    implements Comparable<JavaEEVersion>
 {
 
     private static final String VERSION_1_3 = "1.3";
@@ -39,7 +39,7 @@ public class JavaEEVersion
 
     private static final String VERSION_6 = "6";
 
-    private static final Map versionsMap = new HashMap();
+    private static final Map<String, JavaEEVersion> versionsMap = new HashMap<String, JavaEEVersion>();
 
 
     /**
@@ -166,18 +166,12 @@ public class JavaEEVersion
             || VERSION_6.equals( version );
     }
 
-    public int compareTo( Object other )
+    public int compareTo( JavaEEVersion otherVersion )
     {
-        if ( other == null )
+        if ( otherVersion == null )
         {
             throw new IllegalArgumentException( "other object to compare to could not be null." );
         }
-        if ( !( other instanceof JavaEEVersion ) )
-        {
-            throw new IllegalArgumentException(
-                "other object to compare must be a JavaEEVersion but was [" + other.getClass().getName() + "]" );
-        }
-        final JavaEEVersion otherVersion = (JavaEEVersion) other;
         return index.compareTo( otherVersion.index );
     }
-}
+}
\ No newline at end of file