allow version spec/release version of an extension

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@225480 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-07-27 08:27:48 +00:00
parent 826413b74a
commit 5d46a03299
5 changed files with 42 additions and 18 deletions

View File

@ -57,5 +57,5 @@ public interface ArtifactFactory
Artifact createProjectArtifact( String groupId, String artifactId, String version, String scope ); 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 );
} }

View File

@ -86,9 +86,9 @@ public class DefaultArtifactFactory
return createArtifact( groupId, artifactId, version, scope, "pom" ); 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, public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type,

View File

@ -23,6 +23,8 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver; 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.model.Extension;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusConstants; 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.Context;
import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.util.StringUtils;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
@ -53,21 +56,36 @@ public class DefaultExtensionManager
private PlexusContainer container; private PlexusContainer container;
public void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository ) public void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository )
throws ArtifactResolutionException, PlexusContainerException throws ArtifactResolutionException, PlexusContainerException, InvalidVersionSpecificationException
{ {
// TODO: version may be null // TODO: this is duplicated with DefaultMavenProjectBuilder. Push into artifact factory.
Artifact artifact = artifactFactory.createExtensionArtifact( extension.getGroupId(), extension.getArtifactId(), String version;
extension.getVersion() );
ArtifactResolutionResult result = artifactResolver.resolveTransitively( Collections.singleton( artifact ), if ( StringUtils.isEmpty( extension.getVersion() ) )
project.getArtifact(),
project.getRemoteArtifactRepositories(),
localRepository,
artifactMetadataSource );
for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
{ {
Artifact a = (Artifact) i.next(); version = "RELEASE";
container.addJarResource( a.getFile() ); }
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() );
}
} }
} }

View File

@ -18,6 +18,7 @@ package org.apache.maven.extension;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.model.Extension; import org.apache.maven.model.Extension;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusContainerException; import org.codehaus.plexus.PlexusContainerException;
@ -31,5 +32,5 @@ import org.codehaus.plexus.PlexusContainerException;
public interface ExtensionManager public interface ExtensionManager
{ {
void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository ) void addExtension( Extension extension, MavenProject project, ArtifactRepository localRepository )
throws ArtifactResolutionException, PlexusContainerException; throws ArtifactResolutionException, PlexusContainerException, InvalidVersionSpecificationException;
} }

View File

@ -16,10 +16,11 @@ package org.apache.maven.lifecycle;
* limitations under the License. * 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.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; 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.MavenExecutionResponse;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.extension.ExtensionManager; import org.apache.maven.extension.ExtensionManager;
@ -144,6 +145,10 @@ public class DefaultLifecycleExecutor
{ {
throw new LifecycleExecutionException( "Unable to initialise extensions", e ); throw new LifecycleExecutionException( "Unable to initialise extensions", e );
} }
catch ( InvalidVersionSpecificationException e )
{
throw new LifecycleExecutionException( "Unable to initialise extensions", e );
}
finally finally
{ {
response.setFinish( new Date() ); response.setFinish( new Date() );