You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kr...@apache.org on 2010/05/10 21:13:52 UTC

svn commit: r942855 - in /maven/plugins/trunk/maven-ear-plugin: ./ src/main/java/org/apache/maven/plugin/ear/ src/main/java/org/apache/maven/plugin/ear/output/ src/main/java/org/apache/maven/plugin/ear/util/ src/test/java/org/apache/maven/plugin/ear/ou...

Author: krosenvold
Date: Mon May 10 19:13:52 2010
New Revision: 942855

URL: http://svn.apache.org/viewvc?rev=942855&view=rev
Log:
[MEAR-125] EAR plugin is not thread safe

Made thread-safe and added annotation.

Modified:
    maven/plugins/trunk/maven-ear-plugin/pom.xml
    maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java
    maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
    maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarExecutionContext.java
    maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModule.java
    maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModuleFactory.java
    maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java
    maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
    maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/JarModule.java
    maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/SarModule.java
    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/test/java/org/apache/maven/plugin/ear/output/FileNameMappingFactoryTest.java
    maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/ArtifactRepositoryTest.java
    maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/ArtifactTypeMappingServiceTest.java

Modified: maven/plugins/trunk/maven-ear-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/pom.xml?rev=942855&r1=942854&r2=942855&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-ear-plugin/pom.xml Mon May 10 19:13:52 2010
@@ -25,7 +25,7 @@ under the License.
   <parent>
     <artifactId>maven-plugins</artifactId>
     <groupId>org.apache.maven.plugins</groupId>
-    <version>17</version>
+    <version>18</version>
   </parent>
 
   <artifactId>maven-ear-plugin</artifactId>
@@ -71,11 +71,23 @@ under the License.
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-archiver</artifactId>
       <version>2.2</version>
+      <exclusions>
+        <exclusion> <!-- Just a small workaround until archiver can be released without dangerous plexus-io version -->
+          <groupId>org.codehaus.plexus</groupId>
+          <artifactId>plexus-archiver</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
+    <dependency> <!-- part of the same workaround. Remove this dep when uprading maven-archiver -->
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-archiver</artifactId>
+      <version>1.0</version>
+    </dependency>
+
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
-      <version>1.5.7</version>
+      <version>2.0.5</version>
     </dependency>
     <dependency>
       <groupId>org.apache.maven.shared</groupId>

Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java?rev=942855&r1=942854&r2=942855&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java Mon May 10 19:13:52 2010
@@ -64,6 +64,8 @@ public abstract class AbstractEarModule
 
     protected String altDeploymentDescriptor;
 
+    protected EarExecutionContext earExecutionContext;
+
     /**
      * Empty constructor to be used when the module
      * is built based on the configuration.
@@ -86,6 +88,11 @@ public abstract class AbstractEarModule
         this.bundleDir = null;
     }
 
+    public void setEarExecutionContext( EarExecutionContext earExecutionContext )
+    {
+        this.earExecutionContext = earExecutionContext;
+    }
+
     public void resolveArtifact( Set artifacts )
         throws EarPluginException, MojoFailureException
     {
@@ -98,7 +105,7 @@ public abstract class AbstractEarModule
                 throw new MojoFailureException(
                     "Could not resolve artifact[" + groupId + ":" + artifactId + ":" + getType() + "]" );
             }
-            final ArtifactRepository ar = EarExecutionContext.getInstance().getArtifactRepository();
+            final ArtifactRepository ar = earExecutionContext.getArtifactRepository();
             artifact = ar.getUniqueArtifact( groupId, artifactId, getType(), classifier );
             // Artifact has not been found
             if ( artifact == null )
@@ -193,7 +200,7 @@ public abstract class AbstractEarModule
     {
         if ( bundleFileName == null )
         {
-            bundleFileName = EarExecutionContext.getInstance().getFileNameMapping().mapFileName( artifact );
+            bundleFileName = earExecutionContext.getFileNameMapping().mapFileName( artifact );
         }
         return bundleFileName;
     }

Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java?rev=942855&r1=942854&r2=942855&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java Mon May 10 19:13:52 2010
@@ -159,9 +159,11 @@ public abstract class AbstractEarMojo
         throws MojoExecutionException, MojoFailureException
     {
         getLog().debug( "Resolving artifact type mappings ..." );
+        ArtifactTypeMappingService typeMappingService;
         try
         {
-            ArtifactTypeMappingService.getInstance().configure( artifactTypeMappings );
+            typeMappingService = new ArtifactTypeMappingService();
+            typeMappingService.configure( artifactTypeMappings );
         }
         catch ( EarPluginException e )
         {
@@ -183,8 +185,9 @@ public abstract class AbstractEarMojo
         }
 
         getLog().debug( "Initializing ear execution context" );
-        EarExecutionContext.getInstance().initialize( project, mainArtifactId, defaultLibBundleDir, jbossConfiguration,
-                                                      fileNameMapping );
+        EarExecutionContext earExecutionContext =
+            new EarExecutionContext( project, mainArtifactId, defaultLibBundleDir, jbossConfiguration,
+                                     fileNameMapping, typeMappingService);
 
         getLog().debug( "Resolving ear modules ..." );
         allModules = new ArrayList();
@@ -199,6 +202,7 @@ public abstract class AbstractEarMojo
                 {
                     module = modules[i];
                     getLog().debug( "Resolving ear module[" + module + "]" );
+                    module.setEarExecutionContext(  earExecutionContext );
                     module.resolveArtifact( project.getArtifacts() );
                     allModules.add( module );
                 }
@@ -224,7 +228,9 @@ public abstract class AbstractEarMojo
                     filter.include( artifact ) )
                 {
                     EarModule module = EarModuleFactory.newEarModule( artifact, version, defaultLibBundleDir,
-                                                                      includeLibInApplicationXml );
+                                                                      includeLibInApplicationXml,
+                                                                      typeMappingService);
+                    module.setEarExecutionContext( earExecutionContext );
                     allModules.add( module );
                 }
             }

Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarExecutionContext.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarExecutionContext.java?rev=942855&r1=942854&r2=942855&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarExecutionContext.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarExecutionContext.java Mon May 10 19:13:52 2010
@@ -22,6 +22,7 @@ package org.apache.maven.plugin.ear;
 import org.apache.maven.plugin.ear.output.FileNameMapping;
 import org.apache.maven.plugin.ear.output.FileNameMappingFactory;
 import org.apache.maven.plugin.ear.util.ArtifactRepository;
+import org.apache.maven.plugin.ear.util.ArtifactTypeMappingService;
 import org.apache.maven.project.MavenProject;
 
 /**
@@ -32,15 +33,6 @@ import org.apache.maven.project.MavenPro
  */
 public class EarExecutionContext
 {
-    private static final EarExecutionContext INSTANCE = new EarExecutionContext();
-
-    public static EarExecutionContext getInstance()
-    {
-        return INSTANCE;
-    }
-
-    // Singleton implementation
-
     private String defaultLibBundleDir;
 
     private JbossConfiguration jbossConfiguration;
@@ -50,8 +42,11 @@ public class EarExecutionContext
     private ArtifactRepository artifactRepository;
 
 
-    private EarExecutionContext()
+    public EarExecutionContext( MavenProject project, String mainArtifactId, String defaultLibBundleDir,
+                                JbossConfiguration jbossConfiguration, String fileNameMappingName,
+                                ArtifactTypeMappingService typeMappingService )
     {
+        initialize( project, mainArtifactId, defaultLibBundleDir, jbossConfiguration, fileNameMappingName, typeMappingService );
 
     }
 
@@ -60,11 +55,6 @@ public class EarExecutionContext
         return defaultLibBundleDir;
     }
 
-    public JbossConfiguration getJbossConfiguration()
-    {
-        return jbossConfiguration;
-    }
-
     public boolean isJbossConfigured()
     {
         return jbossConfiguration != null;
@@ -80,19 +70,20 @@ public class EarExecutionContext
         return artifactRepository;
     }
 
-    protected void initialize( MavenProject project, String mainArtifactId, String defaultLibBundleDir, JbossConfiguration jbossConfiguration,
-                               String fileNameMappingName )
+    private void initialize( MavenProject project, String mainArtifactId, String defaultLibBundleDir, JbossConfiguration jbossConfiguration,
+                             String fileNameMappingName, ArtifactTypeMappingService typeMappingService )
     {
-        this.artifactRepository = new ArtifactRepository( project.getArtifacts(), mainArtifactId);
+        this.artifactRepository = new ArtifactRepository( project.getArtifacts(), mainArtifactId,
+                                                          typeMappingService );
         this.defaultLibBundleDir = defaultLibBundleDir;
         this.jbossConfiguration = jbossConfiguration;
         if ( fileNameMappingName == null || fileNameMappingName.trim().length() == 0 )
         {
-            this.fileNameMapping = FileNameMappingFactory.INSTANCE.getDefaultFileNameMapping();
+            this.fileNameMapping = FileNameMappingFactory.getDefaultFileNameMapping();
         }
         else
         {
-            this.fileNameMapping = FileNameMappingFactory.INSTANCE.getFileNameMapping( fileNameMappingName );
+            this.fileNameMapping = FileNameMappingFactory.getFileNameMapping( fileNameMappingName );
         }
     }
 }

Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModule.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModule.java?rev=942855&r1=942854&r2=942855&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModule.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModule.java Mon May 10 19:13:52 2010
@@ -109,4 +109,6 @@ public interface EarModule
     public void resolveArtifact( Set artifacts )
         throws EarPluginException, MojoFailureException;
 
+    public void setEarExecutionContext(EarExecutionContext earExecutionContext);
+
 }

Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModuleFactory.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModuleFactory.java?rev=942855&r1=942854&r2=942855&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModuleFactory.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarModuleFactory.java Mon May 10 19:13:52 2010
@@ -23,6 +23,7 @@ import org.apache.maven.artifact.Artifac
 import org.apache.maven.plugin.ear.util.ArtifactTypeMappingService;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -33,20 +34,22 @@ import java.util.List;
  */
 public final class EarModuleFactory
 {
-    public final static List standardArtifactTypes = new ArrayList();
+    public final static List standardArtifactTypes;
 
     static
     {
-        standardArtifactTypes.add( "jar" );
-        standardArtifactTypes.add( "ejb" );
-        standardArtifactTypes.add( "ejb3" );
-        standardArtifactTypes.add( "par" );
-        standardArtifactTypes.add( "ejb-client" );
-        standardArtifactTypes.add( "rar" );
-        standardArtifactTypes.add( "war" );
-        standardArtifactTypes.add( "sar" );
-        standardArtifactTypes.add( "wsr" );
-        standardArtifactTypes.add( "har" );
+        List temp = new ArrayList();
+        temp.add( "jar" );
+        temp.add( "ejb" );
+        temp.add( "ejb3" );
+        temp.add( "par" );
+        temp.add( "ejb-client" );
+        temp.add( "rar" );
+        temp.add( "war" );
+        temp.add( "sar" );
+        temp.add( "wsr" );
+        temp.add( "har" );
+        standardArtifactTypes = Collections.unmodifiableList(  temp );
     }
 
     /**
@@ -56,17 +59,19 @@ public final class EarModuleFactory
      *
      * @param artifact                the artifact
      * @param javaEEVersion           the javaEE version to use
-     * @param defaultLibBundleDir     the default bundle dir for {@link JarModule}
-     * @param includeInApplicationXml should {@link JarModule} be included in application Xml
+     * @param defaultLibBundleDir     the default bundle dir for {@link org.apache.maven.plugin.ear.JarModule}
+     * @param includeInApplicationXml should {@link org.apache.maven.plugin.ear.JarModule} be included in application Xml
+     * @param typeMappingService    The artifact type mapping service
      * @return an ear module for this artifact
      * @throws UnknownArtifactTypeException if the artifact is not handled
      */
     public static EarModule newEarModule( Artifact artifact, String javaEEVersion, String defaultLibBundleDir,
-                                          Boolean includeInApplicationXml )
+                                          Boolean includeInApplicationXml,
+                                          ArtifactTypeMappingService typeMappingService )
         throws UnknownArtifactTypeException
     {
         // Get the standard artifact type based on default config and user-defined mapping(s)
-        final String artifactType = ArtifactTypeMappingService.getInstance().getStandardType( artifact.getType() );
+        final String artifactType = typeMappingService.getStandardType( artifact.getType() );
 
         if ( "jar".equals( artifactType ) )
         {

Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java?rev=942855&r1=942854&r2=942855&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java Mon May 10 19:13:52 2010
@@ -53,6 +53,7 @@ import java.util.List;
  * @version $Id$
  * @goal ear
  * @phase package
+ * @threadSafe
  * @requiresDependencyResolution test
  */
 public class EarMojo

Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java?rev=942855&r1=942854&r2=942855&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java Mon May 10 19:13:52 2010
@@ -37,6 +37,7 @@ import java.util.List;
  * @version $Id$
  * @goal generate-application-xml
  * @phase generate-resources
+ * @threadSafe
  * @requiresDependencyResolution test
  */
 public class GenerateApplicationXmlMojo

Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/JarModule.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/JarModule.java?rev=942855&r1=942854&r2=942855&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/JarModule.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/JarModule.java Mon May 10 19:13:52 2010
@@ -82,7 +82,7 @@ public class JarModule
 
         // If the defaultLibBundleDir is set and no bundle dir is
         // set, set the default as bundle dir
-        setLibBundleDir( EarExecutionContext.getInstance().getDefaultLibBundleDir() );
+        setLibBundleDir( earExecutionContext.getDefaultLibBundleDir() );
     }
 
     public String getType()

Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/SarModule.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/SarModule.java?rev=942855&r1=942854&r2=942855&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/SarModule.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/SarModule.java Mon May 10 19:13:52 2010
@@ -47,7 +47,7 @@ public class SarModule
     public void appendModule( XMLWriter writer, String version )
     {
         // If JBoss is not configured, add the module as a connector element
-        if ( !EarExecutionContext.getInstance().isJbossConfigured() )
+        if ( !earExecutionContext.isJbossConfigured() )
         {
             writer.startElement( MODULE_ELEMENT );
             writer.startElement( SAR_MODULE );

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=942855&r1=942854&r2=942855&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 Mon May 10 19:13:52 2010
@@ -36,24 +36,17 @@ import java.util.Map;
  */
 public class FileNameMappingFactory
 {
-    public static final String STANDARD_FILE_NAME_MAPPING = "standard";
+    static final String STANDARD_FILE_NAME_MAPPING = "standard";
 
-    public static final String FULL_FILE_NAME_MAPPING = "full";
-
-    public static final FileNameMappingFactory INSTANCE = new FileNameMappingFactory();
-
-    private final Map mappings;
+    static final String FULL_FILE_NAME_MAPPING = "full";
 
     private FileNameMappingFactory()
     {
-        mappings = new HashMap();
-        mappings.put( STANDARD_FILE_NAME_MAPPING, new StandardFileNameMapping() );
-        mappings.put( FULL_FILE_NAME_MAPPING, new FullFileNameMapping() );
     }
 
-    public FileNameMapping getDefaultFileNameMapping()
+    public static FileNameMapping getDefaultFileNameMapping()
     {
-        return getFileNameMapping( STANDARD_FILE_NAME_MAPPING );
+        return new StandardFileNameMapping() ;
     }
 
     /**
@@ -64,22 +57,19 @@ public class FileNameMappingFactory
      * @return the file name mapping implementation
      * @throws IllegalStateException if the implementation is not found
      */
-    public FileNameMapping getFileNameMapping( final String nameOrClass )
+    public static FileNameMapping getFileNameMapping( final String nameOrClass )
         throws IllegalStateException
     {
-        // Check if it's there yet
-        if ( mappings.containsKey( nameOrClass ) )
-        {
-            return (FileNameMapping) mappings.get( nameOrClass );
+        if (STANDARD_FILE_NAME_MAPPING.equals( nameOrClass )){
+            return getDefaultFileNameMapping();
+        }
+        if (FULL_FILE_NAME_MAPPING.equals(  nameOrClass )){
+            return new FullFileNameMapping();
         }
-        else
-        {
             try
             {
                 final Class c = Class.forName( nameOrClass );
-                final FileNameMapping fnm = (FileNameMapping) c.newInstance();
-                mappings.put( nameOrClass, fnm );
-                return fnm;
+                return (FileNameMapping) c.newInstance();
             }
             catch ( ClassNotFoundException e )
             {
@@ -101,6 +91,5 @@ public class FileNameMappingFactory
                 throw new IllegalStateException( "Specified class[" + nameOrClass + "] does not implement[" +
                     FileNameMapping.class.getName() + "]" );
             }
-        }
     }
 }

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=942855&r1=942854&r2=942855&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 Mon May 10 19:13:52 2010
@@ -44,12 +44,14 @@ public class ArtifactRepository
      *
      * @param artifacts the artifacts
      * @param mainArtifactId the id to use for the main artifact (no classifier)
+     * @param artifactTypeMappingService
      */
-    public ArtifactRepository( Set artifacts, String mainArtifactId )
+    public ArtifactRepository( Set artifacts, String mainArtifactId,
+                               ArtifactTypeMappingService artifactTypeMappingService )
     {
         this.artifacts = artifacts;
         this.mainArtifactId = mainArtifactId;
-        this.artifactTypeMappingService = ArtifactTypeMappingService.getInstance();
+        this.artifactTypeMappingService = artifactTypeMappingService;
     }
 
     /**

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=942855&r1=942854&r2=942855&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 Mon May 10 19:13:52 2010
@@ -45,30 +45,22 @@ public class ArtifactTypeMappingService
 
     static final String MAPPING_ATTRIBUTE = "mapping";
 
-    private static final ArtifactTypeMappingService INSTANCE = new ArtifactTypeMappingService();
-
-    public static ArtifactTypeMappingService getInstance()
-    {
-        return INSTANCE;
-    }
-
     // A standard type to a list of customType
     private final Map typeMappings;
 
     // The user-defined mapping for direct access
     private final Map customMappings;
 
-    private ArtifactTypeMappingService()
+    public ArtifactTypeMappingService( )
     {
         this.typeMappings = new HashMap();
         this.customMappings = new HashMap();
+        init();
     }
 
     public void configure( final PlexusConfiguration plexusConfiguration )
         throws EarPluginException, PlexusConfigurationException
     {
-        // Initializes the typeMappings with default values
-        init();
 
         // No user defined configuration
         if ( plexusConfiguration == null )

Modified: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/FileNameMappingFactoryTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/FileNameMappingFactoryTest.java?rev=942855&r1=942854&r2=942855&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/FileNameMappingFactoryTest.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/FileNameMappingFactoryTest.java Mon May 10 19:13:52 2010
@@ -46,7 +46,7 @@ public class FileNameMappingFactoryTest
 
     public void testDefaultFileNameMapping()
     {
-        final FileNameMapping actual = FileNameMappingFactory.INSTANCE.getDefaultFileNameMapping();
+        final FileNameMapping actual = FileNameMappingFactory.getDefaultFileNameMapping();
         assertNotNull( actual );
         assertEquals( StandardFileNameMapping.class, actual.getClass() );
     }
@@ -54,7 +54,7 @@ public class FileNameMappingFactoryTest
     public void testGetFileNameMappingByName()
     {
         final FileNameMapping actual =
-            FileNameMappingFactory.INSTANCE.getFileNameMapping( FileNameMappingFactory.STANDARD_FILE_NAME_MAPPING );
+            FileNameMappingFactory.getFileNameMapping( FileNameMappingFactory.STANDARD_FILE_NAME_MAPPING );
         assertNotNull( actual );
         assertEquals( StandardFileNameMapping.class, actual.getClass() );
     }
@@ -62,13 +62,13 @@ public class FileNameMappingFactoryTest
     public void testGetFileNameMappingByName2()
     {
         final FileNameMapping actual =
-            FileNameMappingFactory.INSTANCE.getFileNameMapping( FileNameMappingFactory.FULL_FILE_NAME_MAPPING );
+            FileNameMappingFactory.getFileNameMapping( FileNameMappingFactory.FULL_FILE_NAME_MAPPING );
         assertNotNull( actual );
         assertEquals( FullFileNameMapping.class, actual.getClass() );
     }
 
     public void testGetFileNameMappingByClass() {
-        final FileNameMapping actual = FileNameMappingFactory.INSTANCE.getFileNameMapping(StandardFileNameMapping.class.getName());
+        final FileNameMapping actual = FileNameMappingFactory.getFileNameMapping(StandardFileNameMapping.class.getName());
         assertNotNull( actual);
         assertEquals( StandardFileNameMapping.class, actual.getClass());
     }
@@ -76,7 +76,7 @@ public class FileNameMappingFactoryTest
     public void testGetFileNameMappingByClass2()
     {
         final FileNameMapping actual =
-            FileNameMappingFactory.INSTANCE.getFileNameMapping( FullFileNameMapping.class.getName() );
+            FileNameMappingFactory.getFileNameMapping( FullFileNameMapping.class.getName() );
         assertNotNull( actual );
         assertEquals( FullFileNameMapping.class, actual.getClass() );
     }
@@ -85,7 +85,7 @@ public class FileNameMappingFactoryTest
     {
         try
         {
-            FileNameMappingFactory.INSTANCE.getFileNameMapping( "com.foo.bar" );
+            FileNameMappingFactory.getFileNameMapping( "com.foo.bar" );
             fail("Should have failed");
         }
         catch ( IllegalStateException e )

Modified: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/ArtifactRepositoryTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/ArtifactRepositoryTest.java?rev=942855&r1=942854&r2=942855&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/ArtifactRepositoryTest.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/ArtifactRepositoryTest.java Mon May 10 19:13:52 2010
@@ -20,6 +20,8 @@ package org.apache.maven.plugin.ear.util
  */
 
 import org.apache.maven.plugin.ear.AbstractEarTest;
+import org.apache.maven.plugin.ear.EarPluginException;
+import org.codehaus.plexus.configuration.PlexusConfigurationException;
 
 /**
  * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
@@ -34,7 +36,6 @@ public class ArtifactRepositoryTest
         throws Exception
     {
         super.setUp();
-        ArtifactTypeMappingService.getInstance().configure( null );
     }
 
 
@@ -42,7 +43,9 @@ public class ArtifactRepositoryTest
 
     public void testEmptyRepository()
     {
-        ArtifactRepository repo = new ArtifactRepository( createArtifacts( null ), MAIN_ARTIFACT_ID );
+        ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService();
+        ArtifactRepository repo = new ArtifactRepository( createArtifacts( null ), MAIN_ARTIFACT_ID,
+                                                          artifactTypeMappingService );
         assertNull( repo.getUniqueArtifact( "ear", "ar", "jar" ) );
         assertNull( repo.getUniqueArtifact( "ear", "ar", "jar", null ) );
         assertNull( repo.getUniqueArtifact( "ear", "ar", "jar", "class" ) );
@@ -50,16 +53,20 @@ public class ArtifactRepositoryTest
 
     public void testRepositoryWithOneUnclassifiedArtifact()
     {
+        ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService();
         ArtifactRepository repo =
-            new ArtifactRepository( createArtifacts( new String[]{"myartifact"} ), MAIN_ARTIFACT_ID );
+            new ArtifactRepository( createArtifacts( new String[]{"myartifact"} ), MAIN_ARTIFACT_ID,
+                                    artifactTypeMappingService );
         assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) );
         assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", null ) );
     }
 
     public void testRepositoryWithOneClassifiedArtifact()
     {
+        ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService();
         ArtifactRepository repo = new ArtifactRepository(
-            createArtifacts( new String[]{"myartifact"}, null, null, new String[]{"classified"} ), MAIN_ARTIFACT_ID );
+            createArtifacts( new String[]{"myartifact"}, null, null, new String[]{"classified"} ), MAIN_ARTIFACT_ID,
+            artifactTypeMappingService );
         assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) );
         assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "classified" ) );
         assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "wrong" ) );
@@ -67,9 +74,11 @@ public class ArtifactRepositoryTest
 
     public void testRepositoryWithMultipleClassifiedArtifacts()
     {
+        ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService();
         ArtifactRepository repo = new ArtifactRepository(
             createArtifacts( new String[]{"myartifact", "myartifact", "myartifact"}, null, null,
-                             new String[]{"class1", "class2", "class3"} ), MAIN_ARTIFACT_ID );
+                             new String[]{"class1", "class2", "class3"} ), MAIN_ARTIFACT_ID,
+            artifactTypeMappingService );
 
         assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) );
         assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class1" ) );
@@ -79,10 +88,12 @@ public class ArtifactRepositoryTest
     }
 
     public void testRepositoryWithMultipleClassifiedArtifactsAndMainArtifact()
+        throws PlexusConfigurationException, EarPluginException
     {
+        ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService();
         ArtifactRepository repo = new ArtifactRepository(
             createArtifacts( new String[]{"myartifact", "myartifact", "myartifact"}, null, null,
-                             new String[]{"class1", "class2", null} ), MAIN_ARTIFACT_ID );
+                             new String[]{"class1", "class2", null} ), MAIN_ARTIFACT_ID, artifactTypeMappingService );
 
         assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) );
         assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class1" ) );

Modified: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/ArtifactTypeMappingServiceTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/ArtifactTypeMappingServiceTest.java?rev=942855&r1=942854&r2=942855&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/ArtifactTypeMappingServiceTest.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/ArtifactTypeMappingServiceTest.java Mon May 10 19:13:52 2010
@@ -105,7 +105,7 @@ public class ArtifactTypeMappingServiceT
 
             rootConfig.addChild( childConfig );
             rootConfig.addChild( childConfig2 );
-            ArtifactTypeMappingService service = ArtifactTypeMappingService.getInstance();
+            ArtifactTypeMappingService service = new ArtifactTypeMappingService();
             service.configure( rootConfig );
             fail( "Should have failed" );
         }
@@ -131,7 +131,7 @@ public class ArtifactTypeMappingServiceT
             childConfig.setAttribute( "mapping", "notAStandardType" );
 
             rootConfig.addChild( childConfig );
-            ArtifactTypeMappingService service = ArtifactTypeMappingService.getInstance();
+            ArtifactTypeMappingService service = new ArtifactTypeMappingService();
             service.configure( rootConfig );
             fail( "Should have failed" );
         }
@@ -156,7 +156,7 @@ public class ArtifactTypeMappingServiceT
             childConfig.setAttribute( "mapping", "ejb" );
 
             rootConfig.addChild( childConfig );
-            ArtifactTypeMappingService service = ArtifactTypeMappingService.getInstance();
+            ArtifactTypeMappingService service = new ArtifactTypeMappingService();
             service.configure( rootConfig );
             fail( "Should have failed" );
         }
@@ -181,7 +181,7 @@ public class ArtifactTypeMappingServiceT
             childConfig.setAttribute( "type", "generic" );
 
             rootConfig.addChild( childConfig );
-            ArtifactTypeMappingService service = ArtifactTypeMappingService.getInstance();
+            ArtifactTypeMappingService service = new ArtifactTypeMappingService();
             service.configure( rootConfig );
             fail( "Should have failed" );
         }
@@ -208,7 +208,7 @@ public class ArtifactTypeMappingServiceT
             childConfig.setAttribute( "type", "MyRar" );
             childConfig.setAttribute( "mapping", "rar" );
             rootConfig.addChild( childConfig );
-            ArtifactTypeMappingService service = ArtifactTypeMappingService.getInstance();
+            ArtifactTypeMappingService service = new ArtifactTypeMappingService();
             service.configure( rootConfig );
 
             return service;
@@ -233,7 +233,7 @@ public class ArtifactTypeMappingServiceT
     {
         try
         {
-            ArtifactTypeMappingService service = ArtifactTypeMappingService.getInstance();
+            ArtifactTypeMappingService service = new ArtifactTypeMappingService();
             service.configure( new XmlPlexusConfiguration( "dummy" ) );
 
             return service;