PR: MNG-614

don't select RELEASE - use the version information

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@291575 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-09-26 07:16:52 +00:00
parent 5637c28498
commit 19ebd621e7
2 changed files with 71 additions and 14 deletions

View File

@ -428,7 +428,7 @@ public class VersionRange
public boolean isSelectedVersionKnown() public boolean isSelectedVersionKnown()
throws OverConstrainedVersionException throws OverConstrainedVersionException
{ {
boolean value; boolean value = false;
if ( recommendedVersion != null ) if ( recommendedVersion != null )
{ {
value = true; value = true;
@ -443,12 +443,7 @@ public class VersionRange
{ {
Restriction restriction = (Restriction) restrictions.get( restrictions.size() - 1 ); Restriction restriction = (Restriction) restrictions.get( restrictions.size() - 1 );
if ( restriction.getUpperBound() == null ) if ( restriction.getUpperBound() != null )
{
// RELEASE version, considered known
value = true;
}
else
{ {
value = restriction.isUpperBoundInclusive(); value = restriction.isUpperBoundInclusive();
} }

View File

@ -24,10 +24,12 @@ import org.apache.maven.artifact.metadata.ResolutionGroup;
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.artifact.resolver.filter.ExclusionSetFilter; 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.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.artifact.versioning.VersionRange;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -287,7 +289,7 @@ public class DefaultArtifactCollectorTest
} }
} }
public void testUnboundedRange() public void testUnboundedRangeWhenVersionUnavailable()
throws ArtifactResolutionException, InvalidVersionSpecificationException throws ArtifactResolutionException, InvalidVersionSpecificationException
{ {
ArtifactSpec a = createArtifact( "a", "1.0" ); ArtifactSpec a = createArtifact( "a", "1.0" );
@ -295,12 +297,48 @@ public class DefaultArtifactCollectorTest
a.addDependency( "c", "[2.0,]" ); a.addDependency( "c", "[2.0,]" );
b.addDependency( "c", "[1.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 ); ArtifactResolutionResult res = collect( a );
ArtifactSpec c = createArtifact( "c", "RELEASE" ); assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, c.artifact} ), res.getArtifacts() );
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact, c.artifact} ), assertEquals( "Check version", "2.0", getArtifact( "c", res.getArtifacts() ).getVersion() );
res.getArtifacts() ); }
assertEquals( "Check version", "RELEASE", 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() public void testResolveManagedVersion()
@ -533,7 +571,7 @@ public class DefaultArtifactCollectorTest
{ {
spec = new ArtifactSpec(); spec = new ArtifactSpec();
spec.artifact = artifact; spec.artifact = artifact;
source.artifacts.put( source.getKey( artifact ), spec ); source.addArtifact( spec );
} }
return spec; return spec;
} }
@ -584,6 +622,8 @@ public class DefaultArtifactCollectorTest
{ {
private Map artifacts = new HashMap(); private Map artifacts = new HashMap();
private Map versions = new HashMap();
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository,
List remoteRepositories ) List remoteRepositories )
throws ArtifactMetadataRetrievalException throws ArtifactMetadataRetrievalException
@ -648,7 +688,29 @@ public class DefaultArtifactCollectorTest
List remoteRepositories ) List remoteRepositories )
throws ArtifactMetadataRetrievalException 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() ) );
}
} }
} }
} }