From 350076bdb96c1898caedf411586162eabe60fd53 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Wed, 2 Nov 2005 20:10:40 +0000 Subject: [PATCH] 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 --- .../apache/maven/artifact/ArtifactUtils.java | 42 +++++++++++++++++++ .../artifact/factory/ArtifactFactory.java | 2 - .../factory/DefaultArtifactFactory.java | 41 ------------------ .../apache/maven/project/MavenProject.java | 3 +- 4 files changed, 43 insertions(+), 45 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java b/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java index 1589767005..d8c4f1eaff 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java @@ -16,9 +16,13 @@ package org.apache.maven.artifact; * limitations under the License. */ +import org.apache.maven.artifact.versioning.VersionRange; + +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; public final class ArtifactUtils @@ -99,4 +103,42 @@ public final class ArtifactUtils 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; + } + } 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 9b11cf008e..1b6b831b90 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 @@ -23,8 +23,6 @@ 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 ); 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 715687570f..8c3fddc016 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 @@ -22,9 +22,6 @@ 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 { @@ -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 ) { return createArtifact( groupId, artifactId, version, scope, type, null, null ); diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java index 46bfc1e5e5..5f0a7b9a75 100644 --- a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java @@ -20,7 +20,6 @@ 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; @@ -187,7 +186,7 @@ public class MavenProject this.executionRoot = project.executionRoot; - this.artifact = new DefaultArtifactFactory().cloneArtifact( project.artifact ); + this.artifact = ArtifactUtils.copyArtifact( project.artifact ); } // ----------------------------------------------------------------------