mirror of https://github.com/apache/maven.git
PR: MNG-1335
Added ArtifactFactory.cloneArtifact(..) +implementation, and made MavenProject(MavenProject) use that to create a copy of the project's artifact. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@330080 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1329000ae6
commit
777d747d1a
|
@ -23,6 +23,8 @@ public interface ArtifactFactory
|
|||
{
|
||||
String ROLE = ArtifactFactory.class.getName();
|
||||
|
||||
Artifact cloneArtifact( Artifact artifact );
|
||||
|
||||
// TODO: deprecate and chase down (probably used for copying only)
|
||||
Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type );
|
||||
|
||||
|
|
|
@ -22,6 +22,9 @@ import org.apache.maven.artifact.handler.ArtifactHandler;
|
|||
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
|
||||
import org.apache.maven.artifact.versioning.VersionRange;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultArtifactFactory
|
||||
implements ArtifactFactory
|
||||
{
|
||||
|
@ -32,6 +35,44 @@ public class DefaultArtifactFactory
|
|||
{
|
||||
}
|
||||
|
||||
public Artifact cloneArtifact( Artifact artifact )
|
||||
{
|
||||
VersionRange range = artifact.getVersionRange();
|
||||
DefaultArtifact clone = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), range.cloneOf(),
|
||||
artifact.getScope(), artifact.getType(), artifact.getClassifier(),
|
||||
artifact.getArtifactHandler(), artifact.isOptional() );
|
||||
clone.setRelease( artifact.isRelease() );
|
||||
clone.setResolvedVersion( artifact.getVersion() );
|
||||
clone.setResolved( artifact.isResolved() );
|
||||
clone.setFile( artifact.getFile() );
|
||||
|
||||
clone.setAvailableVersions( copyList( artifact.getAvailableVersions() ) );
|
||||
clone.setBaseVersion( artifact.getBaseVersion() );
|
||||
clone.setDependencyFilter( artifact.getDependencyFilter() );
|
||||
clone.setDependencyTrail( copyList( artifact.getDependencyTrail() ) );
|
||||
clone.setDownloadUrl( artifact.getDownloadUrl() );
|
||||
clone.setRepository( artifact.getRepository() );
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
private List copyList( List original )
|
||||
{
|
||||
List copy = null;
|
||||
|
||||
if ( original != null )
|
||||
{
|
||||
copy = new ArrayList();
|
||||
|
||||
if ( !original.isEmpty() )
|
||||
{
|
||||
copy.addAll( original );
|
||||
}
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type )
|
||||
{
|
||||
return createArtifact( groupId, artifactId, version, scope, type, null, null );
|
||||
|
|
|
@ -53,6 +53,23 @@ public class VersionRange
|
|||
return restrictions;
|
||||
}
|
||||
|
||||
public VersionRange cloneOf()
|
||||
{
|
||||
List copiedRestrictions = null;
|
||||
|
||||
if ( restrictions != null )
|
||||
{
|
||||
copiedRestrictions = new ArrayList();
|
||||
|
||||
if ( !restrictions.isEmpty() )
|
||||
{
|
||||
copiedRestrictions.addAll( restrictions );
|
||||
}
|
||||
}
|
||||
|
||||
return new VersionRange( recommendedVersion, copiedRestrictions );
|
||||
}
|
||||
|
||||
public static VersionRange createFromVersionSpec( String spec )
|
||||
throws InvalidVersionSpecificationException
|
||||
{
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.apache.maven.artifact.Artifact;
|
|||
import org.apache.maven.artifact.ArtifactUtils;
|
||||
import org.apache.maven.artifact.DependencyResolutionRequiredException;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.artifact.factory.DefaultArtifactFactory;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.model.Build;
|
||||
|
@ -186,8 +187,7 @@ public class MavenProject
|
|||
|
||||
this.executionRoot = project.executionRoot;
|
||||
|
||||
// TODO: need to clone this too?
|
||||
this.artifact = project.artifact;
|
||||
this.artifact = new DefaultArtifactFactory().cloneArtifact( project.artifact );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue