mirror of https://github.com/apache/maven.git
Changing the location of the Artifact-cloning method from org.apache.maven.artifact.factory.ArtifactFactory.cloneArtifact(..) to org.apache.maven.artifact.ArtifactUtils.copyArtifact(..), which is now a static method. This separates the copy method from a specific artifact implementation, while at the same time avoiding embedding of this method in a component instance.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@330342 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b9bef589d8
commit
350076bdb9
|
@ -16,9 +16,13 @@ package org.apache.maven.artifact;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.versioning.VersionRange;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public final class ArtifactUtils
|
public final class ArtifactUtils
|
||||||
|
@ -99,4 +103,42 @@ public final class ArtifactUtils
|
||||||
return artifactMap;
|
return artifactMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Artifact copyArtifact( 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 static List copyList( List original )
|
||||||
|
{
|
||||||
|
List copy = null;
|
||||||
|
|
||||||
|
if ( original != null )
|
||||||
|
{
|
||||||
|
copy = new ArrayList();
|
||||||
|
|
||||||
|
if ( !original.isEmpty() )
|
||||||
|
{
|
||||||
|
copy.addAll( original );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,6 @@ public interface ArtifactFactory
|
||||||
{
|
{
|
||||||
String ROLE = ArtifactFactory.class.getName();
|
String ROLE = ArtifactFactory.class.getName();
|
||||||
|
|
||||||
Artifact cloneArtifact( Artifact artifact );
|
|
||||||
|
|
||||||
// TODO: deprecate and chase down (probably used for copying only)
|
// TODO: deprecate and chase down (probably used for copying only)
|
||||||
Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type );
|
Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type );
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,6 @@ 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.versioning.VersionRange;
|
import org.apache.maven.artifact.versioning.VersionRange;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DefaultArtifactFactory
|
public class DefaultArtifactFactory
|
||||||
implements ArtifactFactory
|
implements ArtifactFactory
|
||||||
{
|
{
|
||||||
|
@ -35,44 +32,6 @@ 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 )
|
public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type )
|
||||||
{
|
{
|
||||||
return createArtifact( groupId, artifactId, version, scope, type, null, null );
|
return createArtifact( groupId, artifactId, version, scope, type, null, null );
|
||||||
|
|
|
@ -20,7 +20,6 @@ import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.ArtifactUtils;
|
import org.apache.maven.artifact.ArtifactUtils;
|
||||||
import org.apache.maven.artifact.DependencyResolutionRequiredException;
|
import org.apache.maven.artifact.DependencyResolutionRequiredException;
|
||||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
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.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||||
import org.apache.maven.model.Build;
|
import org.apache.maven.model.Build;
|
||||||
|
@ -187,7 +186,7 @@ public class MavenProject
|
||||||
|
|
||||||
this.executionRoot = project.executionRoot;
|
this.executionRoot = project.executionRoot;
|
||||||
|
|
||||||
this.artifact = new DefaultArtifactFactory().cloneArtifact( project.artifact );
|
this.artifact = ArtifactUtils.copyArtifact( project.artifact );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue