maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvan...@apache.org
Subject svn commit: r618194 - in /maven/artifact/branches/CAP/src: main/java/org/apache/maven/artifact/ main/java/org/apache/maven/artifact/factory/ main/java/org/apache/maven/artifact/resolver/ main/java/org/apache/maven/artifact/resolver/metadata/ test/java/...
Date Mon, 04 Feb 2008 07:59:25 GMT
Author: jvanzyl
Date: Sun Feb  3 23:59:22 2008
New Revision: 618194

URL: http://svn.apache.org/viewvc?rev=618194&view=rev
Log:
o removing the artifact factory, and reducing to a simpler set of constructors which yield
a valid artifact, full notes in the
  notes.txt file

Removed:
    maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/factory/
Modified:
    maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
    maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
    maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
    maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/resolver/metadata/DefaultMetadataResolver.java
    maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java
    maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java
    maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java
    maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java
    maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
    maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/resolver/conflict/AbstractConflictResolverTest.java

Modified: maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
URL: http://svn.apache.org/viewvc/maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/ArtifactUtils.java?rev=618194&r1=618193&r2=618194&view=diff
==============================================================================
--- maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
(original)
+++ maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
Sun Feb  3 23:59:22 2008
@@ -20,6 +20,7 @@
  */
 
 import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -128,31 +129,10 @@
     }
 
     public static Artifact copyArtifact( Artifact artifact )
+        throws InvalidVersionSpecificationException
     {
-        VersionRange range = artifact.getVersionRange();
-
-        // For some reason with the introduction of MNG-1577 we have the case in Yoko where
a depMan section has
-        // something like the following:
-        //
-        // <dependencyManagement>
-        //     <dependencies>
-        //         <!--  Yoko modules -->
-        //         <dependency>
-        //             <groupId>org.apache.yoko</groupId>
-        //             <artifactId>yoko-core</artifactId>
-        //             <version>${version}</version>
-        //         </dependency>
-        // ...
-        //
-        // And the range is not set so we'll check here and set it. jvz.
-
-        if ( range == null )
-        {
-            range = VersionRange.createFromVersion( artifact.getVersion() );
-        }
-        
-        DefaultArtifact clone = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(),
range.cloneOf(),
-            artifact.getScope(), artifact.getType(), artifact.getClassifier(), artifact.isOptional()
);
+        DefaultArtifact clone = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion(),
+            artifact.getType(), artifact.getClassifier(), artifact.isOptional(), artifact.getScope(),
null );
 
         clone.setRelease( artifact.isRelease() );
         clone.setResolvedVersion( artifact.getVersion() );

Modified: maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
URL: http://svn.apache.org/viewvc/maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/DefaultArtifact.java?rev=618194&r1=618193&r2=618194&view=diff
==============================================================================
--- maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
(original)
+++ maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
Sun Feb  3 23:59:22 2008
@@ -19,13 +19,13 @@
  * under the License.
  */
 
-import org.apache.maven.artifact.handler.ArtifactHandler;
 import org.apache.maven.artifact.metadata.ArtifactMetadata;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
 import org.apache.maven.artifact.versioning.ArtifactVersion;
 import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
 import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
 import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
@@ -94,27 +94,64 @@
 
     public DefaultArtifact( String groupId,
                             String artifactId,
-                            VersionRange versionRange,
-                            String scope,
+                            String version,
+                            String type )
+    {
+        this( groupId, artifactId, version, type, null, false, null, null );
+    }
+
+    public DefaultArtifact( String groupId,
+                            String artifactId,
+                            String version,
                             String type,
-                            String classifier )
+                            String scope )
     {
-        this( groupId, artifactId, versionRange, scope, type, classifier, false );
+        this( groupId, artifactId, version, type, null, false, scope, null );
     }
 
     public DefaultArtifact( String groupId,
                             String artifactId,
-                            VersionRange versionRange,
-                            String scope,
+                            String version,
+                            String type,
+                            String classifier,
+                            String scope )
+    {
+        this( groupId, artifactId, version, type, classifier, false, scope, null );
+    }
+
+    public DefaultArtifact( String groupId,
+                            String artifactId,
+                            String version,
                             String type,
                             String classifier,
-                            boolean optional )
+                            boolean optional,
+                            String scope,
+                            String inheritedScope )
     {
         this.groupId = groupId;
 
         this.artifactId = artifactId;
 
-        this.versionRange = versionRange;
+        if ( version == null )
+        {
+            throw new InvalidArtifactRTException( groupId, artifactId, version, type, "Version
cannot be null." );
+        }
+
+        if ( version.startsWith( "[" ) || version.startsWith( "(" ) )
+        {
+            try
+            {
+                this.versionRange = VersionRange.createFromVersionSpec( version );
+            }
+            catch ( InvalidVersionSpecificationException e )
+            {
+                throw new InvalidArtifactRTException( groupId, artifactId, version, type,
"Invalid version." );
+            }
+        }
+        else
+        {
+            this.versionRange = VersionRange.createFromVersion( version );
+        }
 
         selectVersionFromNewRangeIfAvailable();
 
@@ -125,6 +162,41 @@
         this.classifier = classifier;
 
         this.optional = optional;
+
+        String desiredScope = Artifact.SCOPE_RUNTIME;
+
+        if ( inheritedScope == null )
+        {
+            desiredScope = scope;
+        }
+        else if ( Artifact.SCOPE_TEST.equals( scope ) || Artifact.SCOPE_PROVIDED.equals(
scope ) )
+        {
+            // Why on earth would we want to return null? jvz
+            //return null;
+        }
+        else if ( Artifact.SCOPE_COMPILE.equals( scope ) && Artifact.SCOPE_COMPILE.equals(
inheritedScope ) )
+        {
+            // added to retain compile artifactScope. Remove if you want compile inherited
as runtime
+            desiredScope = Artifact.SCOPE_COMPILE;
+        }
+
+        if ( Artifact.SCOPE_TEST.equals( inheritedScope ) )
+        {
+            desiredScope = Artifact.SCOPE_TEST;
+        }
+
+        if ( Artifact.SCOPE_PROVIDED.equals( inheritedScope ) )
+        {
+            desiredScope = Artifact.SCOPE_PROVIDED;
+        }
+
+        if ( Artifact.SCOPE_SYSTEM.equals( scope ) )
+        {
+            // system scopes come through unchanged...
+            desiredScope = Artifact.SCOPE_SYSTEM;
+        }
+
+        scope = desiredScope;
 
         validateIdentity();
     }

Modified: maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
URL: http://svn.apache.org/viewvc/maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java?rev=618194&r1=618193&r2=618194&view=diff
==============================================================================
--- maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
(original)
+++ maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
Sun Feb  3 23:59:22 2008
@@ -20,7 +20,6 @@
  */
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.artifact.metadata.ArtifactMetadata;
 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
@@ -64,9 +63,6 @@
 
     /** @plexus.requirement */
     private ArtifactTransformationManager transformationManager;
-
-    /** @plexus.requirement */
-    protected ArtifactFactory artifactFactory;
 
     /** @plexus.requirement */
     private ArtifactCollector artifactCollector;

Modified: maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/resolver/metadata/DefaultMetadataResolver.java
URL: http://svn.apache.org/viewvc/maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/resolver/metadata/DefaultMetadataResolver.java?rev=618194&r1=618193&r2=618194&view=diff
==============================================================================
--- maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/resolver/metadata/DefaultMetadataResolver.java
(original)
+++ maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/resolver/metadata/DefaultMetadataResolver.java
Sun Feb  3 23:59:22 2008
@@ -5,7 +5,8 @@
 import java.util.List;
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
@@ -34,9 +35,6 @@
     ArtifactResolver artifactResolver;
 
     /** @plexus.requirement */
-    ArtifactFactory artifactFactory;
-
-    /** @plexus.requirement */
     MetadataSource metadataSource;
 
     /** @plexus.requirement */
@@ -84,14 +82,8 @@
     {
         try
         {
-
-            Artifact pomArtifact = artifactFactory.createArtifact(
-                  query.getGroupId()
-                , query.getArtifactId()
-                , query.getVersion()
-                , query.getScope()
-                , query.getType() == null ? "jar" : query.getType()
-            );
+            Artifact pomArtifact = new DefaultArtifact( query.getGroupId(), query.getArtifactId(),
query.getVersion(),
+                query.getType() == null ? "jar" : query.getType(), query.getScope() );
 
             getLogger().debug( "resolveMetadata request:"
                 + "\n> artifact   : " + pomArtifact.toString()
@@ -202,16 +194,14 @@
         	// TODO: optimize retrieval by zipping returns from repo managers (nexus)
         	for( ArtifactMetadata md : mdCollection )
 			{
-	            artifact = artifactFactory.createArtifact(
-	                  md.getGroupId()
-	                , md.getArtifactId()
-	                , md.getVersion()
-	                , md.getScope()
-	                , md.getType() == null ? "jar" : md.getType()
-	            );
-				artifactResolver.resolve( artifact, remoteRepositories , localRepository );
-				res.add(artifact);
-			}
+
+                artifact = new DefaultArtifact( md.getGroupId(), md.getArtifactId(), md.getVersion(),
+                    md.getType() == null ? "jar" : md.getType(), md.getScope() );
+
+                artifactResolver.resolve( artifact, remoteRepositories, localRepository );
+
+                res.add( artifact );
+            }
 			return res;
 		} catch (ArtifactNotFoundException e) {
 			e.printStackTrace();

Modified: maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java
URL: http://svn.apache.org/viewvc/maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java?rev=618194&r1=618193&r2=618194&view=diff
==============================================================================
--- maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java
(original)
+++ maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java
Sun Feb  3 23:59:22 2008
@@ -19,7 +19,6 @@
  * under the License.
  */
 
-import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
 import org.apache.maven.artifact.repository.DefaultArtifactRepository;
@@ -248,9 +247,7 @@
     protected Artifact createArtifact( String groupId, String artifactId, String version,
String type )
         throws Exception
     {
-        ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE
);
-
-        return artifactFactory.createBuildArtifact( groupId, artifactId, version, type );
+        return new DefaultArtifact( groupId, artifactId, version, type );
     }
 
     protected void deleteLocalArtifact( Artifact artifact )

Modified: maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java
URL: http://svn.apache.org/viewvc/maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java?rev=618194&r1=618193&r2=618194&view=diff
==============================================================================
--- maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java
(original)
+++ maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java
Sun Feb  3 23:59:22 2008
@@ -38,20 +38,16 @@
     private String snapshotSpecVersion = "1.0-SNAPSHOT";
     private String snapshotResolvedVersion = "1.0-20070606.010101-1";
 
-    private VersionRange versionRange;
-    private VersionRange snapshotVersionRange;
-
     private ArtifactHandlerMock artifactHandler;
 
     protected void setUp()
         throws Exception
     {
         super.setUp();
-        versionRange = VersionRange.createFromVersion( version );
-        artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, classifier
);
 
-        snapshotVersionRange = VersionRange.createFromVersion( snapshotResolvedVersion );
-        snapshotArtifact = new DefaultArtifact( groupId, artifactId, snapshotVersionRange,
scope, type, classifier );
+        artifact = new DefaultArtifact( groupId, artifactId, version, type, classifier, scope
);
+
+        snapshotArtifact = new DefaultArtifact( groupId, artifactId, snapshotResolvedVersion,
type, classifier, scope );
     }
 
     public void testGetVersionReturnsResolvedVersionOnSnapshot()
@@ -76,32 +72,37 @@
     }
 
     public void testGetDependencyConflictIdNullClassifier()
+        throws Exception
     {
-        artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, null
);
+        artifact = new DefaultArtifact( groupId, artifactId, version, type, null, scope );
         assertEquals( groupId + ":" + artifactId + ":" + type, artifact.getDependencyConflictId()
);
     }
 
     public void testGetDependencyConflictIdNullScope()
+        throws Exception
     {
         artifact.setScope( null );
         assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier, artifact.getDependencyConflictId()
);
     }
 
     public void testToString()
+        throws Exception
     {
         assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier + ":" +
version + ":" + scope,
                       artifact.toString() );
     }
 
     public void testToStringNullGroupId()
+        throws Exception
     {
         artifact.setGroupId( null );
         assertEquals( artifactId + ":" + type + ":" + classifier + ":" + version + ":" +
scope, artifact.toString() );
     }
 
     public void testToStringNullClassifier()
+        throws Exception
     {
-        artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, null
);
+        artifact = new DefaultArtifact( groupId, artifactId, version, type, null, scope );
         assertEquals( groupId + ":" + artifactId + ":" + type + ":" + version + ":" + scope,
artifact.toString() );
     }
 
@@ -110,5 +111,4 @@
         artifact.setScope( null );
         assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier + ":" +
version, artifact.toString() );
     }
-
 }

Modified: maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java
URL: http://svn.apache.org/viewvc/maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java?rev=618194&r1=618193&r2=618194&view=diff
==============================================================================
--- maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java
(original)
+++ maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/factory/DefaultArtifactFactoryTest.java
Sun Feb  3 23:59:22 2008
@@ -20,6 +20,7 @@
  */
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
 import org.apache.maven.artifact.versioning.VersionRange;
 import org.codehaus.plexus.PlexusTestCase;
 
@@ -29,15 +30,17 @@
     
     public void testPropagationOfSystemScopeRegardlessOfInheritedScope() throws Exception
     {
-        ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
-        
-        Artifact artifact = factory.createDependencyArtifact( "test-grp", "test-artifact",
VersionRange.createFromVersion("1.0"), "type", null, "system", "provided" );
-        Artifact artifact2 = factory.createDependencyArtifact( "test-grp", "test-artifact-2",
VersionRange.createFromVersion("1.0"), "type", null, "system", "test" );
-        Artifact artifact3 = factory.createDependencyArtifact( "test-grp", "test-artifact-3",
VersionRange.createFromVersion("1.0"), "type", null, "system", "runtime" );
-        Artifact artifact4 = factory.createDependencyArtifact( "test-grp", "test-artifact-4",
VersionRange.createFromVersion("1.0"), "type", null, "system", "compile" );
+        Artifact artifact = new DefaultArtifact( "test-grp", "test-artifact", "1.0", "type",
+            null, false, "system", "provided" );
+        Artifact artifact2 = new DefaultArtifact( "test-grp", "test-artifact-2", "1.0", "type",
+            null, false, "system", "test" );
+        Artifact artifact3 = new DefaultArtifact( "test-grp", "test-artifact-3", "1.0", "type",
+            null, false, "system", "runtime" );
+        Artifact artifact4 = new DefaultArtifact( "test-grp", "test-artifact-4", "1.0", "type",
+            null, false, "system", "compile" );
         
         // this one should never happen in practice...
-        Artifact artifact5 = factory.createDependencyArtifact( "test-grp", "test-artifact-5",
VersionRange.createFromVersion("1.0"), "type", null, "system", "system" );
+        Artifact artifact5 = new DefaultArtifact( "test-grp", "test-artifact-5", "1.0", "type",
null, false, "system", "system" );
         
         assertEquals( "system", artifact.getScope() );
         assertEquals( "system", artifact2.getScope() );

Modified: maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java
URL: http://svn.apache.org/viewvc/maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java?rev=618194&r1=618193&r2=618194&view=diff
==============================================================================
--- maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java
(original)
+++ maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java
Sun Feb  3 23:59:22 2008
@@ -137,8 +137,7 @@
         try
         {
             tmpFile.deleteOnExit();
-            Artifact artifact = new DefaultArtifact( "sample.group", "sample-art", VersionRange
-                .createFromVersion( "1.0" ), "artifactScope", "type", "classifier" );
+            Artifact artifact = new DefaultArtifact( "sample.group", "sample-art", "1.0",
"type", "artifactScope" );
             artifact.setFile( tmpFile );
             ArtifactRepository repo = new DefaultArtifactRepository( "id", "noop://url",
                                                                      new ArtifactRepositoryLayoutStub()
);

Modified: maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
URL: http://svn.apache.org/viewvc/maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java?rev=618194&r1=618193&r2=618194&view=diff
==============================================================================
--- maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
(original)
+++ maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
Sun Feb  3 23:59:22 2008
@@ -31,7 +31,7 @@
 import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.DefaultArtifact;
 import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
 import org.apache.maven.artifact.metadata.ResolutionGroup;
@@ -55,8 +55,6 @@
 {
     private ArtifactCollector artifactCollector;
 
-    private ArtifactFactory artifactFactory;
-
     private ArtifactSpec projectArtifact;
 
     private Source source;
@@ -69,7 +67,7 @@
         super.setUp();
 
         this.source = new Source();
-        this.artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+
         this.artifactCollector = (ArtifactCollector) lookup( ArtifactCollector.ROLE );
 
         this.projectArtifact = createArtifactSpec( "project", "1.0", null );
@@ -289,15 +287,19 @@
         throws ArtifactResolutionException, InvalidVersionSpecificationException
     {
         ArtifactSpec a = createArtifactSpec( "a", "1.0" );
+
         ArtifactSpec b = a.addDependency( "b", "1.0" );
+
         a.addDependency( "c", "[2.0,2.5]" );
+
         b.addDependency( "c", "[1.0,3.0]" );
+
         ArtifactSpec c = createArtifactSpec( "c", "2.5" );
 
         ArtifactResolutionResult res = collect( a );
 
-        assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact,
c.artifact} ),
-                      res.getArtifacts() );
+        assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact,
c.artifact} ), res.getArtifacts() );
+
         assertEquals( "Check version", "2.5", getArtifact( "c", res.getArtifacts() ).getVersion()
);
     }
 
@@ -305,7 +307,9 @@
         throws ArtifactResolutionException, InvalidVersionSpecificationException
     {
         ArtifactSpec a = createArtifactSpec( "a", "1.0" );
+
         ArtifactSpec b = a.addDependency( "b", "1.0" );
+
         a.addDependency( "c", "[2.4,3.0]" );
 
         b.addDependency( "c", "[1.0,2.0]" );
@@ -319,8 +323,11 @@
         throws ArtifactResolutionException, InvalidVersionSpecificationException
     {
         ArtifactSpec a = createArtifactSpec( "a", "1.0" );
+
         ArtifactSpec b = a.addDependency( "b", "1.0" );
+
         a.addDependency( "c", "[2.0,]" );
+
         b.addDependency( "c", "[1.0,]" );
 
         ArtifactResolutionResult res = collect( a );
@@ -332,14 +339,19 @@
         throws ArtifactResolutionException, InvalidVersionSpecificationException
     {
         ArtifactSpec a = createArtifactSpec( "a", "1.0" );
+
         createArtifactSpec( "c", "1.5" );
+
         ArtifactSpec c = createArtifactSpec( "c", "2.0" );
+
         createArtifactSpec( "c", "1.1" );
+
         a.addDependency( "c", "[1.0,)" );
 
         ArtifactResolutionResult res = collect( a );
 
         assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, c.artifact}
), res.getArtifacts() );
+
         assertEquals( "Check version", "2.0", getArtifact( "c", res.getArtifacts() ).getVersion()
);
     }
 
@@ -347,7 +359,9 @@
         throws ArtifactResolutionException, InvalidVersionSpecificationException
     {
         ArtifactSpec a = createArtifactSpec( "a", "1.0" );
+
         createArtifactSpec( "c", "2.0" );
+
         a.addDependency( "c", "[10.0,)" );
 
         ArtifactResolutionResult res = collect( a );
@@ -359,12 +373,15 @@
         throws ArtifactResolutionException, InvalidVersionSpecificationException
     {
         ArtifactSpec a = createArtifactSpec( "a", "1.0" );
+
         a.addDependency( "b", "3.0", Artifact.SCOPE_RUNTIME );
 
         Artifact managedVersion = createArtifactSpec( "b", "5.0" ).artifact;
+
         Artifact modifiedB = createArtifactSpec( "b", "5.0", Artifact.SCOPE_RUNTIME ).artifact;
 
         ArtifactResolutionResult res = collect( a, managedVersion );
+
         assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, modifiedB}
), res.getArtifacts() );
     }
 
@@ -374,6 +391,7 @@
         ArtifactSpec a = createArtifactSpec( "a", "1.0" );
 
         Artifact artifact = projectArtifact.artifact;
+
         Artifact managedVersion = createArtifactSpec( artifact.getArtifactId(), "2.0" ).artifact;
 
         ArtifactResolutionResult result = collect( a, managedVersion );
@@ -389,6 +407,7 @@
         throws ArtifactResolutionException, InvalidVersionSpecificationException
     {
         ArtifactSpec a = createArtifactSpec( "a", "1.0" );
+
         ArtifactSpec c = createArtifactSpec( "c", "3.0", Artifact.SCOPE_TEST );
 
         a.addDependency( "c", "2.0", Artifact.SCOPE_COMPILE );
@@ -396,10 +415,11 @@
         Artifact modifiedC = createArtifactSpec( "c", "3.0", Artifact.SCOPE_COMPILE ).artifact;
 
         ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, c.artifact}
) );
+
         assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, modifiedC}
), res.getArtifacts() );
+
         Artifact artifact = getArtifact( "c", res.getArtifacts() );
-        // local wins now, and irrelevant if not local as test/provided aren't transitive
-//        assertEquals( "Check artifactScope", Artifact.SCOPE_COMPILE, artifact.getArtifactScope()
);
+
         assertEquals( "Check artifactScope", Artifact.SCOPE_TEST, artifact.getScope() );
     }
 
@@ -407,6 +427,7 @@
         throws ArtifactResolutionException, InvalidVersionSpecificationException
     {
         ArtifactSpec a = createArtifactSpec( "a", "1.0" );
+
         ArtifactSpec c = createArtifactSpec( "c", "3.0", Artifact.SCOPE_TEST );
 
         a.addDependency( "c", "2.0", Artifact.SCOPE_RUNTIME );
@@ -414,10 +435,11 @@
         Artifact modifiedC = createArtifactSpec( "c", "3.0", Artifact.SCOPE_RUNTIME ).artifact;
 
         ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, c.artifact}
) );
+
         assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, modifiedC}
), res.getArtifacts() );
+
         Artifact artifact = getArtifact( "c", res.getArtifacts() );
-        // local wins now, and irrelevant if not local as test/provided aren't transitive
-//        assertEquals( "Check artifactScope", Artifact.SCOPE_RUNTIME, artifact.getArtifactScope()
);
+
         assertEquals( "Check artifactScope", Artifact.SCOPE_TEST, artifact.getScope() );
     }
 
@@ -425,7 +447,9 @@
         throws ArtifactResolutionException, InvalidVersionSpecificationException
     {
         ArtifactSpec root = createArtifactSpec( "root", "1.0" );
+
         ArtifactSpec a = root.addDependency( "a", "1.0" );
+
         root.addDependency( "c", "3.0", Artifact.SCOPE_RUNTIME );
 
         a.addDependency( "c", "2.0", Artifact.SCOPE_COMPILE );
@@ -433,9 +457,11 @@
         Artifact modifiedC = createArtifactSpec( "c", "3.0", Artifact.SCOPE_COMPILE ).artifact;
 
         ArtifactResolutionResult res = collect( createSet( new Object[]{root.artifact} )
);
+
         assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, root.artifact,
modifiedC} ),
                       res.getArtifacts() );
         Artifact artifact = getArtifact( "c", res.getArtifacts() );
+
         assertEquals( "Check artifactScope", Artifact.SCOPE_COMPILE, artifact.getScope()
);
     }
 
@@ -443,6 +469,7 @@
         throws ArtifactResolutionException, InvalidVersionSpecificationException
     {
         ArtifactSpec a = createArtifactSpec( "a", "1.0" );
+
         ArtifactSpec c = createArtifactSpec( "c", "3.0", Artifact.SCOPE_PROVIDED );
 
         a.addDependency( "c", "2.0", Artifact.SCOPE_COMPILE );
@@ -450,10 +477,11 @@
         Artifact modifiedC = createArtifactSpec( "c", "3.0", Artifact.SCOPE_COMPILE ).artifact;
 
         ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, c.artifact}
) );
+
         assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, modifiedC}
), res.getArtifacts() );
+
         Artifact artifact = getArtifact( "c", res.getArtifacts() );
-        // local wins now, and irrelevant if not local as test/provided aren't transitive
-//        assertEquals( "Check artifactScope", Artifact.SCOPE_COMPILE, artifact.getArtifactScope()
);
+
         assertEquals( "Check artifactScope", Artifact.SCOPE_PROVIDED, artifact.getScope()
);
     }
 
@@ -461,6 +489,7 @@
         throws ArtifactResolutionException, InvalidVersionSpecificationException
     {
         ArtifactSpec a = createArtifactSpec( "a", "1.0" );
+
         ArtifactSpec c = createArtifactSpec( "c", "3.0", Artifact.SCOPE_PROVIDED );
 
         a.addDependency( "c", "2.0", Artifact.SCOPE_RUNTIME );
@@ -468,10 +497,11 @@
         Artifact modifiedC = createArtifactSpec( "c", "3.0", Artifact.SCOPE_RUNTIME ).artifact;
 
         ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, c.artifact}
) );
+
         assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, modifiedC}
), res.getArtifacts() );
+
         Artifact artifact = getArtifact( "c", res.getArtifacts() );
-        // local wins now, and irrelevant if not local as test/provided aren't transitive
-//        assertEquals( "Check artifactScope", Artifact.SCOPE_RUNTIME, artifact.getArtifactScope()
);
+
         assertEquals( "Check artifactScope", Artifact.SCOPE_PROVIDED, artifact.getScope()
);
     }
 
@@ -479,10 +509,13 @@
         throws ArtifactResolutionException, InvalidVersionSpecificationException
     {
         ArtifactSpec a = createArtifactSpec( "a", "1.0", Artifact.SCOPE_PROVIDED );
+
         ArtifactSpec b = createArtifactSpec( "b", "1.0" );
+
         b.addDependency( "c", "3.0", Artifact.SCOPE_PROVIDED );
 
         ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, b.artifact}
) );
+
         assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact}
), res.getArtifacts() );
     }
 
@@ -490,10 +523,13 @@
         throws ArtifactResolutionException, InvalidVersionSpecificationException
     {
         ArtifactSpec a = createArtifactSpec( "a", "1.0" );
+
         ArtifactSpec b = createArtifactSpec( "b", "1.0" );
+
         b.addDependency( "c", "3.0", true );
 
         ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, b.artifact}
) );
+
         assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact}
), res.getArtifacts() );
     }
 
@@ -505,6 +541,7 @@
         ArtifactSpec b = createArtifactSpec( "b", "1.0", true );
 
         ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, b.artifact}
) );
+
         assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact}
), res.getArtifacts() );
     }
 
@@ -551,6 +588,7 @@
         throws ArtifactResolutionException, InvalidVersionSpecificationException
     {
         checkScopeUpdateDirect( farthestScope, nearestScope, expectedScope );
+
         checkScopeUpdateTransitively( farthestScope, nearestScope, expectedScope );
     }
 
@@ -654,24 +692,14 @@
         throws ArtifactResolutionException, InvalidVersionSpecificationException
     {
         ArtifactSpec a = createArtifactSpec( "a", "1.0" );
+
         a.addDependency( "b", "[1.0,)" );
+
         createArtifactSpec( "b", "1.0-SNAPSHOT" );
 
         ArtifactResolutionResult res = collect( a );
 
         assertTrue( res.hasVersionRangeViolations() );
-
-        /*
-        try
-        {
-            ArtifactResolutionResult res = collect( a );
-            fail( "Expected b not to resolve: " + res );
-        }
-        catch ( OverConstrainedVersionException e )
-        {
-            assertTrue( e.getMessage().indexOf( "[1.0-SNAPSHOT]" ) < e.getMessage().indexOf(
"[1.0,)" ) );
-        }
-        */
     }
 
     private Artifact getArtifact( String id, Set artifacts )
@@ -679,6 +707,7 @@
         for ( Iterator i = artifacts.iterator(); i.hasNext(); )
         {
             Artifact a = (Artifact) i.next();
+
             if ( a.getArtifactId().equals( id ) && a.getGroupId().equals( GROUP_ID
) )
             {
                 return a;
@@ -740,20 +769,20 @@
         return createArtifactSpec( id, version, scope, null, false );
     }
 
-    private ArtifactSpec createArtifactSpec( String id, String version, String scope, String
inheritedScope,
-                                         boolean optional )
+    private ArtifactSpec createArtifactSpec( String id, String version, String scope, String
inheritedScope, boolean optional )
         throws InvalidVersionSpecificationException
     {
-        VersionRange versionRange = VersionRange.createFromVersionSpec( version );
-        Artifact artifact = artifactFactory.createDependencyArtifact( GROUP_ID, id, versionRange,
"jar", null, scope,
-                                                                      inheritedScope, optional
);
+        Artifact artifact = new DefaultArtifact( GROUP_ID, id, version, "jar", null, optional,
scope, inheritedScope );
+
         ArtifactSpec spec = null;
+
         if ( artifact != null )
         {
             spec = new ArtifactSpec();
             spec.artifact = artifact;
             source.addArtifact( spec );
         }
+
         return spec;
     }
 
@@ -794,6 +823,7 @@
             throws InvalidVersionSpecificationException
         {
             ArtifactSpec dep = createArtifactSpec( id, version, scope, this.artifact.getScope(),
optional );
+
             return addDependency( dep );
         }
 
@@ -820,7 +850,7 @@
             ArtifactSpec a = (ArtifactSpec) artifacts.get( key );
             try
             {
-                return new ResolutionGroup( artifact, createArtifacts( artifactFactory, a.dependencies,
+                return new ResolutionGroup( artifact, createArtifacts( a.dependencies,
                                                                        artifact.getScope(),
                                                                        artifact.getDependencyFilter()
),
                                                       Collections.EMPTY_LIST );
@@ -836,8 +866,7 @@
             return artifact.getDependencyConflictId();
         }
 
-        private Set createArtifacts( ArtifactFactory artifactFactory, Set dependencies, String
inheritedScope,
-                                     ArtifactFilter dependencyFilter )
+        private Set createArtifacts( Set dependencies, String inheritedScope, ArtifactFilter
dependencyFilter )
             throws InvalidVersionSpecificationException
         {
             Set projectArtifacts = new HashSet();
@@ -846,27 +875,17 @@
             {
                 Artifact d = (Artifact) i.next();
 
-                VersionRange versionRange;
-                if ( d.getVersionRange() != null )
-                {
-                    versionRange = d.getVersionRange();
-                }
-                else
-                {
-                    versionRange = VersionRange.createFromVersionSpec( d.getVersion() );
-                }
                 Artifact artifact;
+                
                 if ( d.getScope().equals( Artifact.SCOPE_TEST ) || d.getScope().equals( Artifact.SCOPE_PROVIDED
) )
                 {
                     /* don't call createDependencyArtifact as it'll ignore test and provided
scopes */
-                    artifact = artifactFactory.createArtifact( d.getGroupId(), d.getArtifactId(),
d.getVersion(), d
-                        .getScope(), d.getType() );
+                    artifact = new DefaultArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(),
d.getType(), d.getScope() );
+                    //artifact = null;
                 }
                 else
                 {
-                    artifact = artifactFactory.createDependencyArtifact( d.getGroupId(),
d.getArtifactId(),
-                                                                         versionRange, d.getType(),
d.getClassifier(),
-                                                                         d.getScope(), inheritedScope,
d.isOptional() );
+                    artifact = new DefaultArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(),
d.getType(), d.getClassifier(), d.isOptional(), d.getScope(), inheritedScope );
                 }
 
                 if ( artifact != null && ( dependencyFilter == null || dependencyFilter.include(
artifact ) ) )

Modified: maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/resolver/conflict/AbstractConflictResolverTest.java
URL: http://svn.apache.org/viewvc/maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/resolver/conflict/AbstractConflictResolverTest.java?rev=618194&r1=618193&r2=618194&view=diff
==============================================================================
--- maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/resolver/conflict/AbstractConflictResolverTest.java
(original)
+++ maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/resolver/conflict/AbstractConflictResolverTest.java
Sun Feb  3 23:59:22 2008
@@ -20,7 +20,7 @@
  */
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.DefaultArtifact;
 import org.apache.maven.artifact.resolver.ResolutionNode;
 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
 import org.apache.maven.artifact.versioning.VersionRange;
@@ -48,8 +48,6 @@
     protected Artifact b1;
 
     private final String roleHint;
-    
-    private ArtifactFactory artifactFactory;
 
     private ConflictResolver conflictResolver;
     
@@ -70,7 +68,6 @@
     {
         super.setUp();
 
-        artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
         conflictResolver = (ConflictResolver) lookup( ConflictResolver.ROLE, roleHint );
         
         a1 = createArtifact( "a", "1.0" );
@@ -87,7 +84,6 @@
         a2 = null;
         b1 = null;
         
-        artifactFactory = null;
         conflictResolver = null;
         
         super.tearDown();
@@ -134,10 +130,7 @@
 
     protected Artifact createArtifact( String id, String version, String scope, String inheritedScope,
boolean optional )
         throws InvalidVersionSpecificationException
-    {
-        VersionRange versionRange = VersionRange.createFromVersionSpec( version );
-        
-        return artifactFactory.createDependencyArtifact( GROUP_ID, id, versionRange, "jar",
null, scope,
-                                                         inheritedScope, optional );
+    {        
+        return new DefaultArtifact( GROUP_ID, id, version, "jar" , null, optional, scope,
inheritedScope );
     }
 }



Mime
View raw message