[MNG-4512] [regression] Profile activation based on JDK version range fails if current version is close to range boundary

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@895185 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2010-01-02 12:54:12 +00:00
parent 42b849deda
commit 8cb042536e
2 changed files with 81 additions and 8 deletions

View File

@ -103,7 +103,9 @@ public class JdkVersionProfileActivator
return isLeft ? 1 : -1;
}
List<String> valueTokens = new ArrayList<String>( Arrays.asList( value.split( "\\." ) ) );
value = value.replaceAll( "[^0-9\\.\\-\\_]", "" );
List<String> valueTokens = new ArrayList<String>( Arrays.asList( value.split( "[\\.\\-\\_]" ) ) );
List<String> rangeValueTokens = new ArrayList<String>( Arrays.asList( rangeValue.value.split( "\\." ) ) );
int max = Math.max( valueTokens.size(), rangeValueTokens.size() );
@ -119,7 +121,7 @@ public class JdkVersionProfileActivator
return 0;
}
for ( int i = 0; i < valueTokens.size(); i++ )
for ( int i = 0; i < valueTokens.size() && i < rangeValueTokens.size(); i++ )
{
int x = Integer.parseInt( valueTokens.get( i ) );
int y = Integer.parseInt( rangeValueTokens.get( i ) );

View File

@ -74,8 +74,9 @@ public class JdkVersionProfileActivatorTest
Profile profile = newProfile( "1.4" );
assertActivation( true, profile, newContext( null, newProperties( "1.4" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.4.2" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.4.2_09" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.4.2_09-b03" ) ) );
assertActivation( false, profile, newContext( null, newProperties( "1.3" ) ) );
@ -88,26 +89,96 @@ public class JdkVersionProfileActivatorTest
Profile profile = newProfile( "!1.4" );
assertActivation( false, profile, newContext( null, newProperties( "1.4" ) ) );
assertActivation( false, profile, newContext( null, newProperties( "1.4.2" ) ) );
assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09" ) ) );
assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09-b03" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.3" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) );
}
public void testVersionRange()
public void testVersionRangeInclusiveBounds()
throws Exception
{
Profile profile = newProfile( "[1.5,1.6]" );
assertActivation( false, profile, newContext( null, newProperties( "1.4" ) ) );
assertActivation( false, profile, newContext( null, newProperties( "1.4.2" ) ) );
assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09" ) ) );
assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09-b03" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5.0" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09-b03" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5.1" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.6" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.6.0" ) ) );
// TODO: controversial, needs discussion
// assertActivation( true, profile, newContext( null, newProperties( "1.6.0_09" ) ) );
// assertActivation( true, profile, newContext( null, newProperties( "1.6.0_09-b03" ) ) );
}
public void testVersionRangeExclusiveBounds()
throws Exception
{
Profile profile = newProfile( "(1.3,1.6)" );
assertActivation( true, profile, newContext( null, newProperties( "1.5.0_16" ) ) );
assertActivation( false, profile, newContext( null, newProperties( "1.3" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.3.1" ) ) );
// TODO: controversial, needs discussion
// assertActivation( true, profile, newContext( null, newProperties( "1.3.1" ) ) );
// assertActivation( true, profile, newContext( null, newProperties( "1.3.1_09" ) ) );
// assertActivation( true, profile, newContext( null, newProperties( "1.3.1_09-b03" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5.0" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09-b03" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5.1" ) ) );
assertActivation( false, profile, newContext( null, newProperties( "1.6" ) ) );
}
public void testVersionRangeInclusiveLowerBound()
throws Exception
{
Profile profile = newProfile( "[1.5,)" );
assertActivation( false, profile, newContext( null, newProperties( "1.4" ) ) );
assertActivation( false, profile, newContext( null, newProperties( "1.4.2" ) ) );
assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09" ) ) );
assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09-b03" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5.0" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09-b03" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5.1" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.6" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.6.0" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.6.0_09" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.6.0_09-b03" ) ) );
}
public void testVersionRangeExclusiveUpperBound()
throws Exception
{
Profile profile = newProfile( "(,1.6)" );
assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5.0" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09-b03" ) ) );
assertActivation( true, profile, newContext( null, newProperties( "1.5.1" ) ) );
assertActivation( false, profile, newContext( null, newProperties( "1.6" ) ) );
assertActivation( false, profile, newContext( null, newProperties( "1.6.0" ) ) );
assertActivation( false, profile, newContext( null, newProperties( "1.6.0_09" ) ) );
assertActivation( false, profile, newContext( null, newProperties( "1.6.0_09-b03" ) ) );
}
}