Author: jvanzyl
Date: Sat Sep 15 14:28:38 2007
New Revision: 575987

URL: http://svn.apache.org/viewvc?rev=575987&view=rev
Log:
MNG-1323 making extensions work inside a reactor
Submitted by: Piotr Tabor

Added:
    
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRealmManager.java
   (with props)
    
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginRealmManager.java
   (with props)
    
maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/DefaultPluginRealmManagerTest.java
   (with props)
Modified:
    
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
    
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java
    
maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml

Modified: 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
URL: 
http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java?rev=575987&r1=575986&r2=575987&view=diff
==============================================================================
--- 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
 (original)
+++ 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
 Sat Sep 15 14:28:38 2007
@@ -105,6 +105,8 @@
 
         RESERVED_GROUP_IDS = rgids;
     }
+    
+    protected PluginRealmManager pluginRealmManager;
 
     protected PlexusContainer container;
 
@@ -377,67 +379,70 @@
     {
         // TODO When/if we go to project-level plugin instances (like for 
plugin-level deps in the
         // POM), we need to undo this somehow.
-        ClassRealm pluginRealm = container.getComponentRealm( 
projectPlugin.getKey() );
 
-        if ( ( pluginRealm != null ) && ( pluginRealm != 
container.getContainerRealm() ) )
-        {
-            getLogger().debug(
-                               "Realm already exists for: " + 
projectPlugin.getKey()
-                                               + ". Skipping addition..." );
-            // we've already discovered this plugin, and configured it, so 
skip it this time.
-
-            return;
-        }
-
-        // 
----------------------------------------------------------------------------
-        // Realm creation for a plugin
-        // 
----------------------------------------------------------------------------
-
-        ClassRealm componentRealm = null;
-
-        try
-        {
-            List jars = new ArrayList();
-
-            for ( Iterator i = artifacts.iterator(); i.hasNext(); )
-            {
-                Artifact artifact = (Artifact) i.next();
-
-                jars.add( artifact.getFile() );
-            }
-
-            jars.add( pluginArtifact.getFile() );
-
-            // Now here we need the artifact coreArtifactFilter stuff
-
-            componentRealm = container.createComponentRealm( 
projectPlugin.getKey(), jars );
-
-            // adding for MNG-3012 to try to work around problems with Xpp3Dom 
(from plexus-utils)
-            // spawning a ClassCastException when a mojo calls 
plugin.getConfiguration() from maven-model...
-            componentRealm.importFrom( componentRealm.getParentRealm().getId(),
-                                       Xpp3Dom.class.getName() );
-            componentRealm.importFrom( componentRealm.getParentRealm().getId(),
-                                       "org.codehaus.plexus.util.xml.pull" );
-
-            // Adding for MNG-2878, since maven-reporting-impl was removed 
from the
-            // internal list of artifacts managed by maven, the classloader is 
different
-            // between maven-reporting-impl and maven-reporting-api...so this 
resource
-            // is not available from the AbstractMavenReport since it uses:
-            // getClass().getResourceAsStream( "/default-report.xml" )
-            // (maven-reporting-impl version 2.0; line 134; affects: 
checkstyle plugin, and probably others)
-            componentRealm.importFrom( 
componentRealm.getParentRealm().getId(), "/default-report.xml" );
-        }
-        catch ( PlexusContainerException e )
-        {
-            throw new PluginManagerException( "Failed to create realm for 
plugin '" + projectPlugin
-                                              + ".", e );
-        }
-        catch ( NoSuchRealmException e )
-        {
-            throw new PluginManagerException(
-                                              "Failed to import Xpp3Dom from 
parent realm for plugin: '"
-                                                              + projectPlugin 
+ ".", e );
-        }
+       ClassRealm componentRealm = 
pluginRealmManager.getOrCreateRealm(projectPlugin, pluginArtifact, artifacts);
+       
+//        ClassRealm pluginRealm = container.getComponentRealm( 
projectPlugin.getKey()+":"+projectPlugin.getVersion() );
+
+//        if ( ( pluginRealm != null ) && ( pluginRealm != 
container.getContainerRealm() ) )
+//        {
+//            getLogger().debug(
+//                               "Realm already exists for: " + 
projectPlugin.getKey()
+//                                               + ". Skipping addition..." );
+//            // we've already discovered this plugin, and configured it, so 
skip it this time.
+//
+//            return;
+//        }
+//
+//        // 
----------------------------------------------------------------------------
+//        // Realm creation for a plugin
+//        // 
----------------------------------------------------------------------------
+//
+//        ClassRealm componentRealm = null;
+//
+//        try
+//        {
+//            List jars = new ArrayList();
+//
+//            for ( Iterator i = artifacts.iterator(); i.hasNext(); )
+//            {
+//                Artifact artifact = (Artifact) i.next();
+//
+//                jars.add( artifact.getFile() );
+//            }
+//
+//            jars.add( pluginArtifact.getFile() );
+//
+//            // Now here we need the artifact coreArtifactFilter stuff
+//
+//            componentRealm = container.createComponentRealm( 
projectPlugin.getKey()+projectPlugin.getVersion(), jars );
+//
+//            // adding for MNG-3012 to try to work around problems with 
Xpp3Dom (from plexus-utils)
+//            // spawning a ClassCastException when a mojo calls 
plugin.getConfiguration() from maven-model...
+//            componentRealm.importFrom( 
componentRealm.getParentRealm().getId(),
+//                                       Xpp3Dom.class.getName() );
+//            componentRealm.importFrom( 
componentRealm.getParentRealm().getId(),
+//                                       "org.codehaus.plexus.util.xml.pull" );
+//
+//            // Adding for MNG-2878, since maven-reporting-impl was removed 
from the
+//            // internal list of artifacts managed by maven, the classloader 
is different
+//            // between maven-reporting-impl and maven-reporting-api...so 
this resource
+//            // is not available from the AbstractMavenReport since it uses:
+//            // getClass().getResourceAsStream( "/default-report.xml" )
+//            // (maven-reporting-impl version 2.0; line 134; affects: 
checkstyle plugin, and probably others)
+//            componentRealm.importFrom( 
componentRealm.getParentRealm().getId(), "/default-report.xml" );
+//        }
+//        catch ( PlexusContainerException e )
+//        {
+//            throw new PluginManagerException( "Failed to create realm for 
plugin '" + projectPlugin
+//                                              + ".", e );
+//        }
+//        catch ( NoSuchRealmException e )
+//        {
+//            throw new PluginManagerException(
+//                                              "Failed to import Xpp3Dom from 
parent realm for plugin: '"
+//                                                              + 
projectPlugin + ".", e );
+//        }
 
         // 
----------------------------------------------------------------------------
         // The PluginCollector will now know about the plugin we are trying to 
load

Added: 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRealmManager.java
URL: 
http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRealmManager.java?rev=575987&view=auto
==============================================================================
--- 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRealmManager.java
 (added)
+++ 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRealmManager.java
 Sat Sep 15 14:28:38 2007
@@ -0,0 +1,153 @@
+package org.apache.maven.plugin;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.PlexusContainerException;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
+import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
+/**
+ * @author <a href="mailto:[EMAIL PROTECTED]">Piotr Tabor</a>
+ */
+public class DefaultPluginRealmManager
+    extends AbstractLogEnabled
+    implements PluginRealmManager
+{
+    private PlexusContainer container;
+
+    public ClassRealm getOrCreateRealm( Plugin projectPlugin, Artifact 
pluginArtifact, Set artifacts )
+        throws PluginManagerException
+    {
+        Set allArtifacts = new HashSet( artifacts );
+        allArtifacts.add( pluginArtifact );
+
+        List/* <URL> */pluginJars = generateJarsListForArtifacts( allArtifacts 
);
+
+        String realmKey = generateChildContainerName( projectPlugin, 
allArtifacts );
+        ClassRealm pluginRealm = container.getComponentRealm( realmKey );
+
+        if ( ( pluginRealm != null ) && ( pluginRealm != 
container.getContainerRealm() ) )
+        {
+            getLogger().debug( "Realm already exists for: " + realmKey + ". 
Skipping addition..." );
+            /*
+             * we've already discovered this plugin, and configured it, so 
skip it this time.
+             */
+            return pluginRealm;
+        }
+
+        // 
----------------------------------------------------------------------------
+        // Realm creation for a plugin
+        // 
----------------------------------------------------------------------------
+
+        ClassRealm componentRealm = null;
+
+        try
+        {
+            // Now here we need the artifact coreArtifactFilter
+            // stuff
+
+            componentRealm = container.createComponentRealm( realmKey, 
pluginJars );
+
+            /*
+             * adding for MNG-3012 to try to work around problems with Xpp3Dom 
(from plexus-utils spawning a
+             * ClassCastException when a mojo calls plugin.getConfiguration() 
from maven-model...
+             */
+            componentRealm.importFrom( 
componentRealm.getParentRealm().getId(), Xpp3Dom.class.getName() );
+            componentRealm.importFrom( 
componentRealm.getParentRealm().getId(), "org.codehaus.plexus.util.xml.pull" );
+
+            /*
+             * Adding for MNG-2878, since maven-reporting-impl was removed 
from the internal list of artifacts managed
+             * by maven, the classloader is different between 
maven-reporting-impl and maven-reporting-api...so this
+             * resource is not available from the AbstractMavenReport since it 
uses: getClass().getResourceAsStream(
+             * "/default-report.xml" ) (maven-reporting-impl version 2.0; line 
134; affects: checkstyle plugin, and
+             * probably others)
+             */
+            componentRealm.importFrom( 
componentRealm.getParentRealm().getId(), "/default-report.xml" );
+
+        }
+        catch ( PlexusContainerException e )
+        {
+            throw new PluginManagerException( "Failed to create realm for 
plugin '" + projectPlugin + ".", e );
+        }
+        catch ( NoSuchRealmException e )
+        {
+            throw new PluginManagerException( "Failed to import Xpp3Dom from 
parent realm for plugin: '" +
+                projectPlugin + ".", e );
+        }
+
+        getLogger().debug( "Realm for plugin: " + realmKey + ":\n" + 
componentRealm );
+
+        // 
----------------------------------------------------------------------------
+        // The PluginCollector will now know about the plugin we
+        // are trying to load
+        // 
----------------------------------------------------------------------------
+
+        return componentRealm;
+    }
+
+    List/* <URL> */generateJarsListForArtifacts( Set/* <Artifact> */artifacts )
+    {
+        List/* <URL> */jars = new ArrayList();
+
+        for ( Iterator i = artifacts.iterator(); i.hasNext(); )
+        {
+            Artifact artifact = (Artifact) i.next();
+
+            jars.add( artifact.getFile() );
+        }
+
+        return jars;
+    }
+
+
+    private static String generateChildContainerName( Plugin plugin, Set 
artifacts )
+    {
+        return plugin.getKey() + ":" + plugin.getVersion() + ":" + 
getHashOfArtifacts( artifacts );
+    }
+
+    static long getHashOfArtifacts( Set a )
+    {
+        long i = 1;
+        Iterator/* <Artifact> */iterator = a.iterator();
+        while ( iterator.hasNext() )
+        {
+            Artifact artifact = (Artifact) iterator.next();
+            i = ( i * artifact.hashCode() ) % 2147483647 /* big prime */;
+        }
+        return i;
+    }
+}

Propchange: 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRealmManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRealmManager.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java
URL: 
http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java?rev=575987&r1=575986&r2=575987&view=diff
==============================================================================
--- 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java
 (original)
+++ 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java
 Sat Sep 15 14:28:38 2007
@@ -26,23 +26,33 @@
 import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 
+import com.sun.jmx.remote.util.OrderClassLoaders;
+
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
 
 public class MavenPluginCollector
     extends AbstractLogEnabled
     implements ComponentDiscoveryListener
 {
+    /**
+     * Map from pluginDescriptor.getKey (groupId:artifactId) into (ordered) 
map from version into pluginDescriptor
+     * Internal map is ordered to make sure that builds are determinic (used 
pluginVersion is determined)
+     */
+    private Map/* <String,OrderedMap<String,PluginDescriptor>> 
*/pluginDescriptors = new HashMap();
 
-    private Set pluginsInProcess = new HashSet();
-
-    private Map pluginDescriptors = new HashMap();
-
-    private Map pluginIdsByPrefix = new HashMap();
+    private Map/* <String,OrderedMap<String,PluginDescriptor>> 
*/pluginIdsByPrefix = new HashMap();
 
+    public String getId()
+    {
+        return "maven-plugin-collector";
+    }
+    
     // ----------------------------------------------------------------------
     // Mojo discovery
     // ----------------------------------------------------------------------
@@ -53,66 +63,125 @@
         if ( componentSetDescriptor instanceof PluginDescriptor )
         {
             PluginDescriptor pluginDescriptor = (PluginDescriptor) 
componentSetDescriptor;
-
-            // TODO: see comment in getPluginDescriptor
-            String key = Plugin.constructKey( pluginDescriptor.getGroupId(), 
pluginDescriptor.getArtifactId() );
             
-            if ( !pluginsInProcess.contains( key ) )
-            {
-                pluginsInProcess.add( key );
-
-                getLogger().debug( this + ": Discovered plugin: " + key );
-                
-                pluginDescriptors.put( key, pluginDescriptor );
-
-                // TODO: throw an (not runtime) exception if there is a prefix 
overlap - means doing so elsewhere
-                // we also need to deal with multiple versions somehow - 
currently, first wins
-                if ( !pluginIdsByPrefix.containsKey( 
pluginDescriptor.getGoalPrefix() ) )
-                {
-                    pluginIdsByPrefix.put( pluginDescriptor.getGoalPrefix(), 
pluginDescriptor );
-                }
-            }
+            putIntoPluginDescriptors( pluginDescriptor );
+            putIntoPluginIdsByPrefix( pluginDescriptor );
         }
     }
 
-    public String getId()
+    public PluginDescriptor getPluginDescriptor( Plugin plugin )
     {
-        return "maven-plugin-collector";    
+        SortedMap/* <String,PluginDescriptor> */pluginVersions = (SortedMap) 
pluginDescriptors.get( plugin.getKey() );
+        if ( pluginVersions != null )
+        {
+            PluginDescriptor res;
+            if ( plugin.getVersion() != null )
+            {
+                res = (PluginDescriptor) pluginVersions.get( 
plugin.getVersion() );
+            }
+            else
+            {
+                res = getDefaultPluginDescriptorVersion( pluginVersions );
+            }
+           return res;
+        }
+        else
+        {
+            return null;
+        }
     }
 
-    public PluginDescriptor getPluginDescriptor( Plugin plugin )
+    private PluginDescriptor getDefaultPluginDescriptorVersion( SortedMap 
pluginVersions )
     {
-        // TODO: include version, but can't do this in the plugin manager as 
it is not resolved to the right version
-        // at that point. Instead, move the duplication check to the artifact 
container, or store it locally based on
-        // the unresolved version?
-        return (PluginDescriptor) pluginDescriptors.get( plugin.getKey() );
+        if ( pluginVersions.size() > 0 )
+        {
+            return (PluginDescriptor) pluginVersions.get( 
pluginVersions.lastKey() );
+        }
+        else
+        {
+            return null;
+        }
     }
 
     public boolean isPluginInstalled( Plugin plugin )
     {
         // TODO: see comment in getPluginDescriptor
-        return pluginDescriptors.containsKey( plugin.getKey() );
+        return getPluginDescriptor( plugin ) != null;
     }
 
     public PluginDescriptor getPluginDescriptorForPrefix( String prefix )
     {
-        return (PluginDescriptor) pluginIdsByPrefix.get( prefix );
+        return getPluginDescriptorForPrefix( prefix, null );
     }
 
-    public void flushPluginDescriptor( Plugin plugin )
+    public PluginDescriptor getPluginDescriptorForPrefix( String prefix, 
String version )
     {
-        pluginsInProcess.remove( plugin.getKey() );
-        pluginDescriptors.remove( plugin.getKey() );
-        
-        for ( Iterator it = pluginIdsByPrefix.entrySet().iterator(); 
it.hasNext(); )
+        SortedMap/* <String,PluginDescriptor> */pluginVersions = (SortedMap) 
pluginIdsByPrefix.get( prefix );
+        if ( pluginVersions != null )
         {
-            Map.Entry entry = (Map.Entry) it.next();
-            
-            if ( plugin.getKey().equals( entry.getValue() ) )
+            PluginDescriptor res;
+            if ( version != null )
+            {
+                res = (PluginDescriptor) pluginVersions.get( version );
+            }
+            else
             {
-                it.remove();
+                res = getDefaultPluginDescriptorVersion( pluginVersions );
             }
+            return res;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+//    public void flushPluginDescriptor( Plugin plugin )
+//    {
+//        getPluginDescriptor( plugin ).cleanPluginDescriptor();
+//    }
+
+    /**
+     * Puts given pluginDescriptor into pluginDescriptors map (if the map does 
not contains plugin for specified maven
+     * version)
+     * 
+     * @param pluginDescriptor
+     */
+    protected void putIntoPluginDescriptors( PluginDescriptor pluginDescriptor 
)
+    {
+        String key = Plugin.constructKey( pluginDescriptor.getGroupId(), 
pluginDescriptor.getArtifactId() );
+
+        SortedMap/* <String,PluginDescriptor> */descriptorsVersions = 
(SortedMap) pluginDescriptors.get( key );
+        if ( descriptorsVersions == null )
+        {
+            descriptorsVersions = new TreeMap();
+            pluginDescriptors.put( key, descriptorsVersions );
+        }
+
+        putIntoVersionsMap( descriptorsVersions, pluginDescriptor );
+    }
+
+    protected void putIntoVersionsMap( SortedMap/* 
<String(version),PluginDescriptor> */pluginVersions,
+                                       PluginDescriptor pluginDescriptor )
+    {
+        if ( !pluginVersions.containsKey( pluginDescriptor.getVersion() ) )
+        {
+            pluginVersions.put( pluginDescriptor.getVersion(), 
pluginDescriptor );
+        }
+    }
+
+    protected void putIntoPluginIdsByPrefix( PluginDescriptor pluginDescriptor 
)
+    {
+        String goalPrefix = pluginDescriptor.getGoalPrefix();
+
+        SortedMap/* <String,PluginDescriptor> */descriptorsVersions = 
(SortedMap) pluginIdsByPrefix.get( goalPrefix );
+        if ( descriptorsVersions == null )
+        {
+            descriptorsVersions = new TreeMap();
+            pluginIdsByPrefix.put( goalPrefix, descriptorsVersions );
         }
+
+        putIntoVersionsMap( descriptorsVersions, pluginDescriptor );
     }
 
 }

Added: 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginRealmManager.java
URL: 
http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginRealmManager.java?rev=575987&view=auto
==============================================================================
--- 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginRealmManager.java
 (added)
+++ 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginRealmManager.java
 Sat Sep 15 14:28:38 2007
@@ -0,0 +1,18 @@
+package org.apache.maven.plugin;
+
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Plugin;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
+
+/**
+ * 
+ * @author <a href="mailto:[EMAIL PROTECTED]">Piotr Tabor</a>
+ */
+public interface PluginRealmManager
+{
+    public static final String ROLE=PluginRealmManager.class.getName();
+    
+    public ClassRealm getOrCreateRealm( Plugin projectPlugin, Artifact 
pluginArtifact, Set artifacts ) throws PluginManagerException;
+}
\ No newline at end of file

Propchange: 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginRealmManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginRealmManager.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: 
maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml
URL: 
http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml?rev=575987&r1=575986&r2=575987&view=diff
==============================================================================
--- 
maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml
 (original)
+++ 
maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml
 Sat Sep 15 14:28:38 2007
@@ -64,7 +64,10 @@
         <requirement>
           <role>org.apache.maven.plugin.MavenPluginCollector</role>
         </requirement>
-        <requirement>
+       <requirement>  
+         <role>org.apache.maven.plugin.PluginRealmManager</role>
+        </requirement>
+       <requirement>
           <role>org.apache.maven.plugin.version.PluginVersionManager</role>
           <role-hint>default</role-hint>
         </requirement>
@@ -728,5 +731,14 @@
         </requirement>
       </requirements>
     </component>
+    <component>
+      <role>org.apache.maven.plugin.PluginRealmManager</role>
+      
<implementation>org.apache.maven.plugin.DefaultPluginRealmManager</implementation>
+      <requirements>
+        <requirement>
+          <role>org.codehaus.plexus.PlexusContainer</role>
+        </requirement>
+      </requirements>
+    </component>    
   </components>
 </component-set>

Added: 
maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/DefaultPluginRealmManagerTest.java
URL: 
http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/DefaultPluginRealmManagerTest.java?rev=575987&view=auto
==============================================================================
--- 
maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/DefaultPluginRealmManagerTest.java
 (added)
+++ 
maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/DefaultPluginRealmManagerTest.java
 Sat Sep 15 14:28:38 2007
@@ -0,0 +1,130 @@
+package org.apache.maven.plugin;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.codehaus.plexus.PlexusTestCase;
+
+public class DefaultPluginRealmManagerTest
+    extends PlexusTestCase
+{
+    public void testCreateComponent()
+        throws Exception
+    {
+        assertNotNull( "Cannot lookup component: " + PluginRealmManager.ROLE, 
lookup( PluginRealmManager.ROLE ) );
+    }
+
+    public void testGenerateJarsListForArtifactsEmpty()
+        throws Exception
+    {
+        DefaultPluginRealmManager defaultPluginRealmManager = new 
DefaultPluginRealmManager();
+
+        assertEquals( "List of jars generated by empty set should be empty", 0,
+                      defaultPluginRealmManager.generateJarsListForArtifacts( 
Collections.EMPTY_SET ).size() );
+    }
+
+    public void testGenerateJarsListForArtifacts()
+        throws Exception
+    {
+        DefaultPluginRealmManager defaultPluginRealmManager = new 
DefaultPluginRealmManager();
+
+        /*Different artifactId*/
+        List/* <Artifact> */result =
+            defaultPluginRealmManager.generateJarsListForArtifacts( 
createArtifactSet( HashSet.class, 5 ) );
+        checkListOfNumeredFiles( 5, result );
+        
+        /*Different groups*/
+        result =
+            defaultPluginRealmManager.generateJarsListForArtifacts( 
createArtifactSetGroups( HashSet.class, 6 ) );
+        checkListOfNumeredFiles( 6, result );
+        
+        /*Different versions*/
+        result =
+            defaultPluginRealmManager.generateJarsListForArtifacts( 
createArtifactSetVersions( HashSet.class, 4 ) );
+        checkListOfNumeredFiles( 4, result );
+    }
+
+    public void testGetHashOfArtifacts() throws Exception
+    {
+        assertEquals("Hash code of empty set should be always the same", 
DefaultPluginRealmManager.getHashOfArtifacts( Collections.EMPTY_SET), 
DefaultPluginRealmManager.getHashOfArtifacts( Collections.EMPTY_SET));
+        assertEquals("Hash code should be the same for the same content of 
artifacts 
list",DefaultPluginRealmManager.getHashOfArtifacts(createArtifactSet(HashSet.class,5)),DefaultPluginRealmManager.getHashOfArtifacts(createArtifactSet(HashSet.class,5)));
+        assertEquals("Hash code should not depend on set 
implementation",DefaultPluginRealmManager.getHashOfArtifacts(createArtifactSet(HashSet.class,5)),DefaultPluginRealmManager.getHashOfArtifacts(createArtifactSet(TreeSet.class,5)));
+    
+        assertTrue( "Hash should be different for different content",  
DefaultPluginRealmManager.getHashOfArtifacts(createArtifactSet(HashSet.class,5))!=DefaultPluginRealmManager.getHashOfArtifacts(createArtifactSet(TreeSet.class,6)));
+    }
+    
+
+    // =========================== Helpers 
====================================================
+
+    private void checkListOfNumeredFiles( int count, List/* <File> */result )
+        throws MalformedURLException
+    {
+        assertEquals( "Unexpected size of created urls list: ", count, 
result.size() );
+        for ( int i = 0; i < count; i++ )
+        {
+            File expectedFile = createNumberedFile( i );
+            assertTrue( "Expected url not found: " + expectedFile + " in: " + 
result, result.contains( expectedFile ) );
+        }
+    }
+
+    protected Artifact createArtifact( String groupId, String artifactId, 
String version )
+        throws Exception
+    {
+        ArtifactFactory artifactFactory = (ArtifactFactory) lookup( 
ArtifactFactory.ROLE );
+
+        // TODO: used to be SCOPE_COMPILE, check
+        return artifactFactory.createBuildArtifact( groupId, artifactId, 
version, "jar" );
+    }
+
+    protected Set/* <Artifact> */createArtifactSet( Class/* <? extends Set> 
*/setClass, int count )
+        throws Exception
+    {
+        Set/* <Artifact> */artifactSet = (Set) setClass.newInstance();
+        for ( int i = 0; i < count; i++ )
+        {
+            Artifact artifact = createArtifact( "testGroup", "testArtifact_" + 
i, "1.0" );
+            artifact.setFile( createNumberedFile( i ) );
+            artifactSet.add( artifact );
+        }
+        return artifactSet;
+    }
+
+    protected Set/* <Artifact> */createArtifactSetVersions( Class/* <? extends 
Set> */setClass, int count )
+        throws Exception
+    {
+        Set/* <Artifact> */artifactSet = (Set) setClass.newInstance();
+        for ( int i = 0; i < count; i++ )
+        {
+            Artifact artifact = createArtifact( "testGroup", "testArtifact", i 
+ ".0" );
+            artifact.setFile( createNumberedFile( i ) );
+            artifactSet.add( artifact );
+        }
+        return artifactSet;
+    }
+
+    protected Set/* <Artifact> */createArtifactSetGroups( Class/* <? extends 
Set> */setClass, int count )
+        throws Exception
+    {
+        Set/* <Artifact> */artifactSet = (Set) setClass.newInstance();
+        for ( int i = 0; i < count; i++ )
+        {
+            Artifact artifact = createArtifact( "testGroup" + i, 
"testArtifact_", "1.0" );
+            artifact.setFile( createNumberedFile( i ) );
+            artifactSet.add( artifact );
+        }
+        return artifactSet;
+    }
+
+    protected File createNumberedFile( int i )
+    {
+        return new File( "/not_existing_file_" + i + ".jar" );
+    }
+}

Propchange: 
maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/DefaultPluginRealmManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/DefaultPluginRealmManagerTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"


Reply via email to