mirror of https://github.com/apache/maven.git
[MNG-3092] Version ranges with non-snapshot bounds can contain snapshot versions
Submitted by: Mark Hobson git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@931890 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ed256dc2e8
commit
5ffd89030c
|
@ -1,6 +1,5 @@
|
|||
package org.apache.maven.artifact.versioning;
|
||||
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -20,6 +19,8 @@ package org.apache.maven.artifact.versioning;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
|
||||
/**
|
||||
* Describes a restriction in versioning.
|
||||
*
|
||||
|
@ -71,9 +72,17 @@ public class Restriction
|
|||
|
||||
public boolean containsVersion( ArtifactVersion version )
|
||||
{
|
||||
boolean snapshot = isSnapshot( version );
|
||||
|
||||
if ( lowerBound != null )
|
||||
{
|
||||
int comparison = lowerBound.compareTo( version );
|
||||
|
||||
if ( snapshot && comparison == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( ( comparison == 0 ) && !lowerBoundInclusive )
|
||||
{
|
||||
return false;
|
||||
|
@ -86,6 +95,12 @@ public class Restriction
|
|||
if ( upperBound != null )
|
||||
{
|
||||
int comparison = upperBound.compareTo( version );
|
||||
|
||||
if ( snapshot && comparison == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( ( comparison == 0 ) && !upperBoundInclusive )
|
||||
{
|
||||
return false;
|
||||
|
@ -95,9 +110,20 @@ public class Restriction
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( lowerBound != null || upperBound != null )
|
||||
{
|
||||
return !snapshot;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isSnapshot( ArtifactVersion version )
|
||||
{
|
||||
return Artifact.SNAPSHOT_VERSION.equals( version.getQualifier() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
|
|
|
@ -56,7 +56,7 @@ public class VersionRangeTest
|
|||
Artifact artifact = null;
|
||||
|
||||
VersionRange range = VersionRange.createFromVersionSpec( "(,1.0]" );
|
||||
List restrictions = range.getRestrictions();
|
||||
List<Restriction> restrictions = range.getRestrictions();
|
||||
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
|
||||
Restriction restriction = (Restriction) restrictions.get( 0 );
|
||||
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
|
||||
|
@ -148,7 +148,7 @@ public class VersionRangeTest
|
|||
range = VersionRange.createFromVersionSpec( "[1.0,)" );
|
||||
assertFalse( range.containsVersion( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) );
|
||||
|
||||
range = VersionRange.createFromVersionSpec( "[1.0,1.1]" );
|
||||
range = VersionRange.createFromVersionSpec( "[1.0,1.1-SNAPSHOT]" );
|
||||
assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.1-SNAPSHOT" ) ) );
|
||||
|
||||
range = VersionRange.createFromVersionSpec( "[5.0.9.0,5.0.10.0)" );
|
||||
|
@ -182,7 +182,7 @@ public class VersionRangeTest
|
|||
// TODO: current policy is to retain the original version - is this correct, do we need strategies or is that handled elsewhere?
|
||||
// assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() );
|
||||
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.0", mergedRange.getRecommendedVersion().toString() );
|
||||
List restrictions = mergedRange.getRestrictions();
|
||||
List<Restriction> restrictions = mergedRange.getRestrictions();
|
||||
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
|
||||
Restriction restriction = (Restriction) restrictions.get( 0 );
|
||||
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
|
||||
|
@ -655,6 +655,37 @@ public class VersionRangeTest
|
|||
assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() );
|
||||
}
|
||||
|
||||
public void testReleaseRangeBoundsCannotContainSnapshots()
|
||||
throws InvalidVersionSpecificationException
|
||||
{
|
||||
VersionRange range = VersionRange.createFromVersionSpec( "[1.0,1.2]" );
|
||||
|
||||
assertFalse( range.containsVersion( new DefaultArtifactVersion( "1.1-SNAPSHOT" ) ) );
|
||||
assertFalse( range.containsVersion( new DefaultArtifactVersion( "1.2-SNAPSHOT" ) ) );
|
||||
}
|
||||
|
||||
public void testSnapshotRangeBoundsCanContainSnapshots()
|
||||
throws InvalidVersionSpecificationException
|
||||
{
|
||||
VersionRange range = VersionRange.createFromVersionSpec( "[1.0,1.2-SNAPSHOT]" );
|
||||
|
||||
assertFalse( range.containsVersion( new DefaultArtifactVersion( "1.1-SNAPSHOT" ) ) );
|
||||
assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.2-SNAPSHOT" ) ) );
|
||||
|
||||
range = VersionRange.createFromVersionSpec( "[1.0-SNAPSHOT,1.2]" );
|
||||
|
||||
assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) );
|
||||
assertFalse( range.containsVersion( new DefaultArtifactVersion( "1.1-SNAPSHOT" ) ) );
|
||||
}
|
||||
|
||||
public void testSnapshotSoftVersionCanContainSnapshot()
|
||||
throws InvalidVersionSpecificationException
|
||||
{
|
||||
VersionRange range = VersionRange.createFromVersionSpec( "1.0-SNAPSHOT" );
|
||||
|
||||
assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) );
|
||||
}
|
||||
|
||||
private void checkInvalidRange( String version )
|
||||
{
|
||||
try
|
||||
|
|
Loading…
Reference in New Issue