You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by br...@apache.org on 2005/09/26 09:17:05 UTC

svn commit: r291575 - in /maven/components/trunk/maven-artifact/src: main/java/org/apache/maven/artifact/versioning/VersionRange.java test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java

Author: brett
Date: Mon Sep 26 00:16:52 2005
New Revision: 291575

URL: http://svn.apache.org/viewcvs?rev=291575&view=rev
Log:
PR: MNG-614
don't select RELEASE - use the version information

Modified:
    maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java
    maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java

Modified: maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java?rev=291575&r1=291574&r2=291575&view=diff
==============================================================================
--- maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java (original)
+++ maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java Mon Sep 26 00:16:52 2005
@@ -428,7 +428,7 @@
     public boolean isSelectedVersionKnown()
         throws OverConstrainedVersionException
     {
-        boolean value;
+        boolean value = false;
         if ( recommendedVersion != null )
         {
             value = true;
@@ -443,12 +443,7 @@
             {
                 Restriction restriction = (Restriction) restrictions.get( restrictions.size() - 1 );
 
-                if ( restriction.getUpperBound() == null )
-                {
-                    // RELEASE version, considered known
-                    value = true;
-                }
-                else
+                if ( restriction.getUpperBound() != null )
                 {
                     value = restriction.isUpperBoundInclusive();
                 }

Modified: maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java?rev=291575&r1=291574&r2=291575&view=diff
==============================================================================
--- maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java (original)
+++ maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java Mon Sep 26 00:16:52 2005
@@ -24,10 +24,12 @@
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
 import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
 import org.apache.maven.artifact.versioning.VersionRange;
 import org.codehaus.plexus.PlexusTestCase;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
@@ -287,7 +289,7 @@
         }
     }
 
-    public void testUnboundedRange()
+    public void testUnboundedRangeWhenVersionUnavailable()
         throws ArtifactResolutionException, InvalidVersionSpecificationException
     {
         ArtifactSpec a = createArtifact( "a", "1.0" );
@@ -295,12 +297,48 @@
         a.addDependency( "c", "[2.0,]" );
         b.addDependency( "c", "[1.0,]" );
 
+        try
+        {
+            ArtifactResolutionResult res = collect( a );
+            fail( "Should not succeed collecting, got: " + res.getArtifacts() );
+        }
+        catch ( ArtifactResolutionException expected )
+        {
+            assertTrue( true );
+        }
+    }
+
+    public void testUnboundedRangeBelowLastRelease()
+        throws ArtifactResolutionException, InvalidVersionSpecificationException
+    {
+        ArtifactSpec a = createArtifact( "a", "1.0" );
+        createArtifact( "c", "1.5" );
+        ArtifactSpec c = createArtifact( "c", "2.0" );
+        createArtifact( "c", "1.1" );
+        a.addDependency( "c", "[1.0,)" );
+
         ArtifactResolutionResult res = collect( a );
 
-        ArtifactSpec c = createArtifact( "c", "RELEASE" );
-        assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact, c.artifact} ),
-                      res.getArtifacts() );
-        assertEquals( "Check version", "RELEASE", getArtifact( "c", res.getArtifacts() ).getVersion() );
+        assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, c.artifact} ), res.getArtifacts() );
+        assertEquals( "Check version", "2.0", getArtifact( "c", res.getArtifacts() ).getVersion() );
+    }
+
+    public void testUnboundedRangeAboveLastRelease()
+        throws ArtifactResolutionException, InvalidVersionSpecificationException
+    {
+        ArtifactSpec a = createArtifact( "a", "1.0" );
+        createArtifact( "c", "2.0" );
+        a.addDependency( "c", "[10.0,)" );
+
+        try
+        {
+            ArtifactResolutionResult res = collect( a );
+            fail( "Should not succeed collecting, got: " + res.getArtifacts() );
+        }
+        catch ( ArtifactResolutionException expected )
+        {
+            assertTrue( true );
+        }
     }
 
     public void testResolveManagedVersion()
@@ -533,7 +571,7 @@
         {
             spec = new ArtifactSpec();
             spec.artifact = artifact;
-            source.artifacts.put( source.getKey( artifact ), spec );
+            source.addArtifact( spec );
         }
         return spec;
     }
@@ -584,6 +622,8 @@
     {
         private Map artifacts = new HashMap();
 
+        private Map versions = new HashMap();
+
         public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository,
                                          List remoteRepositories )
             throws ArtifactMetadataRetrievalException
@@ -648,7 +688,29 @@
                                                List remoteRepositories )
             throws ArtifactMetadataRetrievalException
         {
-            throw new UnsupportedOperationException( "Cannot get available versions in this test case" );
+            List artifactVersions = (List) versions.get( artifact.getDependencyConflictId() );
+            if ( artifactVersions == null )
+            {
+                artifactVersions = Collections.EMPTY_LIST;
+            }
+            return artifactVersions;
+        }
+
+        public void addArtifact( ArtifactSpec spec )
+        {
+            artifacts.put( getKey( spec.artifact ), spec );
+
+            String key = spec.artifact.getDependencyConflictId();
+            List artifactVersions = (List) versions.get( key );
+            if ( artifactVersions == null )
+            {
+                artifactVersions = new ArrayList();
+                versions.put( key, artifactVersions );
+            }
+            if ( spec.artifact.getVersion() != null )
+            {
+                artifactVersions.add( new DefaultArtifactVersion( spec.artifact.getVersion() ) );
+            }
         }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org