diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java b/maven-artifact/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java index fbc7423e23..e85bfaec0c 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java @@ -57,5 +57,5 @@ public interface ArtifactFactory Artifact createProjectArtifact( String groupId, String artifactId, String version, String scope ); - Artifact createExtensionArtifact( String groupId, String artifactId, String version ); + Artifact createExtensionArtifact( String groupId, String artifactId, VersionRange versionRange ); } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java b/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java index 39a9f277f5..ac131ea73f 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java @@ -86,9 +86,9 @@ public class DefaultArtifactFactory return createArtifact( groupId, artifactId, version, scope, "pom" ); } - public Artifact createExtensionArtifact( String groupId, String artifactId, String version ) + public Artifact createExtensionArtifact( String groupId, String artifactId, VersionRange versionRange ) { - return createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, "jar" ); + return createArtifact( groupId, artifactId, versionRange, Artifact.SCOPE_RUNTIME, "jar", null, null ); } public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type, diff --git a/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java b/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java index 8099f1cc66..06ee36bc68 100644 --- a/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java +++ b/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java @@ -23,6 +23,8 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.model.Extension; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.PlexusConstants; @@ -31,6 +33,7 @@ import org.codehaus.plexus.PlexusContainerException; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; +import org.codehaus.plexus.util.StringUtils; import java.util.Collections; import java.util.Iterator; @@ -53,21 +56,36 @@ public class DefaultExtensionManager private PlexusContainer container; public void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository ) - throws ArtifactResolutionException, PlexusContainerException + throws ArtifactResolutionException, PlexusContainerException, InvalidVersionSpecificationException { - // TODO: version may be null - Artifact artifact = artifactFactory.createExtensionArtifact( extension.getGroupId(), extension.getArtifactId(), - extension.getVersion() ); + // TODO: this is duplicated with DefaultMavenProjectBuilder. Push into artifact factory. + String version; - ArtifactResolutionResult result = artifactResolver.resolveTransitively( Collections.singleton( artifact ), - project.getArtifact(), - project.getRemoteArtifactRepositories(), - localRepository, - artifactMetadataSource ); - for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); ) + if ( StringUtils.isEmpty( extension.getVersion() ) ) { - Artifact a = (Artifact) i.next(); - container.addJarResource( a.getFile() ); + version = "RELEASE"; + } + else + { + version = extension.getVersion(); + } + + VersionRange versionRange = VersionRange.createFromVersionSpec( version ); + Artifact artifact = artifactFactory.createExtensionArtifact( extension.getGroupId(), extension.getArtifactId(), + versionRange ); + + if ( artifact != null ) + { + ArtifactResolutionResult result = artifactResolver.resolveTransitively( Collections.singleton( artifact ), + project.getArtifact(), + project.getRemoteArtifactRepositories(), + localRepository, + artifactMetadataSource ); + for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + container.addJarResource( a.getFile() ); + } } } diff --git a/maven-core/src/main/java/org/apache/maven/extension/ExtensionManager.java b/maven-core/src/main/java/org/apache/maven/extension/ExtensionManager.java index fce6a030b4..88bffc2584 100644 --- a/maven-core/src/main/java/org/apache/maven/extension/ExtensionManager.java +++ b/maven-core/src/main/java/org/apache/maven/extension/ExtensionManager.java @@ -18,6 +18,7 @@ package org.apache.maven.extension; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.model.Extension; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.PlexusContainerException; @@ -31,5 +32,5 @@ import org.codehaus.plexus.PlexusContainerException; public interface ExtensionManager { void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository ) - throws ArtifactResolutionException, PlexusContainerException; + throws ArtifactResolutionException, PlexusContainerException, InvalidVersionSpecificationException; } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index ffc0417402..6eb5838594 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -16,10 +16,11 @@ package org.apache.maven.lifecycle; * limitations under the License. */ -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.execution.MavenExecutionResponse; import org.apache.maven.execution.MavenSession; import org.apache.maven.extension.ExtensionManager; @@ -144,6 +145,10 @@ public class DefaultLifecycleExecutor { throw new LifecycleExecutionException( "Unable to initialise extensions", e ); } + catch ( InvalidVersionSpecificationException e ) + { + throw new LifecycleExecutionException( "Unable to initialise extensions", e ); + } finally { response.setFinish( new Date() );