Author: jvanzyl
Date: Sun Mar 25 11:11:10 2007
New Revision: 522316

URL: http://svn.apache.org/viewvc?view=rev&rev=522316
Log:
MNG-2900 We need to provide the same mechanism for extensions that we do for 
plugin so that we protect
         ourselves from ourselves ... extensions just like plugins have 
undeclared dependencies.


Modified:
    
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java
    
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
    
maven/components/branches/maven-2.0.x/maven-core/src/main/resources/META-INF/plexus/components.xml

Modified: 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java?view=diff&rev=522316&r1=522315&r2=522316
==============================================================================
--- 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java
 (original)
+++ 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java
 Sun Mar 25 11:11:10 2007
@@ -20,10 +20,14 @@
  */
 
 import org.apache.maven.MavenArtifactFilterManager;
+import org.apache.maven.plugin.DefaultPluginManager;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.metadata.ResolutionGroup;
+import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
@@ -45,6 +49,8 @@
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
 
 /**
  * Used to locate extensions.
@@ -59,6 +65,8 @@
 {
     private ArtifactResolver artifactResolver;
 
+    private ArtifactFactory artifactFactory;
+
     private ArtifactMetadataSource artifactMetadataSource;
 
     private PlexusContainer container;
@@ -82,13 +90,32 @@
         {
             ArtifactFilter filter = new ProjectArtifactExceptionFilter( 
artifactFilter, project.getArtifact() );
 
-            ArtifactResolutionResult result = 
artifactResolver.resolveTransitively( Collections.singleton( artifact ),
+            ResolutionGroup resolutionGroup;
+            try
+            {
+                resolutionGroup = artifactMetadataSource.retrieve( artifact, 
localRepository,
+                                                                   
project.getRemoteArtifactRepositories() );
+            }
+            catch ( ArtifactMetadataRetrievalException e )
+            {
+                throw new ArtifactResolutionException( "Unable to download 
metadata from repository for plugin '" +
+                    artifact.getId() + "': " + e.getMessage(), artifact, e );
+            }
+
+            // We use the same hack here to make sure that plexus 1.1 is 
available for extensions that do
+            // not declare plexus-utils but need it. MNG-2900
+            DefaultPluginManager.checkPlexusUtils( resolutionGroup, 
artifactFactory );
+
+            Set dependencies = new HashSet( resolutionGroup.getArtifacts() );
+
+            dependencies.add( artifact );
+
+            ArtifactResolutionResult result = 
artifactResolver.resolveTransitively( dependencies,
                                                                                
     project.getArtifact(),
                                                                                
     project.getManagedVersionMap(),
                                                                                
     localRepository,
                                                                                
     project.getRemoteArtifactRepositories(),
                                                                                
     artifactMetadataSource, filter );
-
             // create a child container for the extension
             // TODO: this could surely be simpler/different on trunk with the 
new classworlds
             PlexusContainer extensionContainer = getExtensionContainer();

Modified: 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java?view=diff&rev=522316&r1=522315&r2=522316
==============================================================================
--- 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
 (original)
+++ 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
 Sun Mar 25 11:11:10 2007
@@ -642,53 +642,7 @@
                     pluginArtifact.getId() + "': " + e.getMessage(), 
pluginArtifact, e );
             }
 
-            // 
----------------------------------------------------------------------------
-            // If the plugin already declares a dependency on plexus-utils 
then we're all
-            // set as the plugin author is aware of its use. If we don't have 
a dependency
-            // on plexus-utils then we must protect users from stupid plugin 
authors who
-            // did not declare a direct dependency on plexus-utils because the 
version
-            // Maven uses is hidden from downstream use. We will also bump up 
any
-            // anything below 1.1 to 1.1 as this mimics the behaviour in 2.0.5 
where
-            // plexus-utils 1.1 was being forced into use.
-            // 
----------------------------------------------------------------------------
-
-            VersionRange vr = null;
-
-            try
-            {
-                vr = VersionRange.createFromVersionSpec( "[1.1,)" );
-            }
-            catch ( InvalidVersionSpecificationException e )
-            {
-                // Won't happen
-            }
-
-            boolean plexusUtilsPresent = false;
-
-            for ( Iterator i = resolutionGroup.getArtifacts().iterator(); 
i.hasNext(); )
-            {
-                Artifact a = (Artifact) i.next();
-
-                if ( a.getArtifactId().equals( "plexus-utils" ) &&
-                    vr.containsVersion( new DefaultArtifactVersion( 
a.getVersion() ) ) )
-                {
-                    plexusUtilsPresent = true;
-
-                    break;
-                }
-            }
-
-            if ( !plexusUtilsPresent )
-            {
-                // We will add plexus-utils as every plugin was getting this 
anyway from Maven itself. We will set the
-                // version to the latest version we know that works as of the 
2.0.6 release. We set the scope to compile
-                // as the resolution process will turn this into runtime. We 
are trying to mimic what was happening
-                // prior to hiding plexus-utils. jvz.
-
-                resolutionGroup.getArtifacts().add( 
artifactFactory.createArtifact( "org.codehaus.plexus",
-                                                                               
     "plexus-utils", "1.1",
-                                                                               
     Artifact.SCOPE_COMPILE, "jar" ) );
-            }
+            checkPlexusUtils( resolutionGroup, artifactFactory );
 
             Set dependencies = new HashSet( resolutionGroup.getArtifacts() );
             dependencies.addAll( 
pluginDescriptor.getIntroducedDependencyArtifacts() );
@@ -739,6 +693,57 @@
             allResolved.addAll( unresolved );
 
             pluginDescriptor.setArtifacts( allResolved );
+        }
+    }
+
+    public static void checkPlexusUtils( ResolutionGroup resolutionGroup, 
ArtifactFactory artifactFactory )
+    {
+        // 
----------------------------------------------------------------------------
+        // If the plugin already declares a dependency on plexus-utils then 
we're all
+        // set as the plugin author is aware of its use. If we don't have a 
dependency
+        // on plexus-utils then we must protect users from stupid plugin 
authors who
+        // did not declare a direct dependency on plexus-utils because the 
version
+        // Maven uses is hidden from downstream use. We will also bump up any
+        // anything below 1.1 to 1.1 as this mimics the behaviour in 2.0.5 
where
+        // plexus-utils 1.1 was being forced into use.
+        // 
----------------------------------------------------------------------------
+
+        VersionRange vr = null;
+
+        try
+        {
+            vr = VersionRange.createFromVersionSpec( "[1.1,)" );
+        }
+        catch ( InvalidVersionSpecificationException e )
+        {
+            // Won't happen
+        }
+
+        boolean plexusUtilsPresent = false;
+
+        for ( Iterator i = resolutionGroup.getArtifacts().iterator(); 
i.hasNext(); )
+        {
+            Artifact a = (Artifact) i.next();
+
+            if ( a.getArtifactId().equals( "plexus-utils" ) &&
+                vr.containsVersion( new DefaultArtifactVersion( a.getVersion() 
) ) )
+            {
+                plexusUtilsPresent = true;
+
+                break;
+            }
+        }
+
+        if ( !plexusUtilsPresent )
+        {
+            // We will add plexus-utils as every plugin was getting this 
anyway from Maven itself. We will set the
+            // version to the latest version we know that works as of the 
2.0.6 release. We set the scope to compile
+            // as the resolution process will turn this into runtime. We are 
trying to mimic what was happening
+            // prior to hiding plexus-utils. jvz.
+
+            resolutionGroup.getArtifacts().add( 
artifactFactory.createArtifact( "org.codehaus.plexus",
+                                                                               
 "plexus-utils", "1.1",
+                                                                               
 Artifact.SCOPE_COMPILE, "jar" ) );
         }
     }
 

Modified: 
maven/components/branches/maven-2.0.x/maven-core/src/main/resources/META-INF/plexus/components.xml
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-core/src/main/resources/META-INF/plexus/components.xml?view=diff&rev=522316&r1=522315&r2=522316
==============================================================================
--- 
maven/components/branches/maven-2.0.x/maven-core/src/main/resources/META-INF/plexus/components.xml
 (original)
+++ 
maven/components/branches/maven-2.0.x/maven-core/src/main/resources/META-INF/plexus/components.xml
 Sun Mar 25 11:11:10 2007
@@ -61,6 +61,9 @@
           <role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
         </requirement>
         <requirement>
+          <role>org.apache.maven.artifact.factory.ArtifactFactory</role>
+        </requirement>
+        <requirement>
           
<role>org.apache.maven.artifact.metadata.ArtifactMetadataSource</role>
         </requirement>
         <requirement>


Reply via email to