mirror of https://github.com/apache/maven.git
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:
parent
826413b74a
commit
5d46a03299
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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() );
|
||||
|
|
Loading…
Reference in New Issue