diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java index 9cf3123cd5..617ffa22bb 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java @@ -103,7 +103,9 @@ public class JdkVersionProfileActivator return isLeft ? 1 : -1; } - List valueTokens = new ArrayList( Arrays.asList( value.split( "\\." ) ) ); + value = value.replaceAll( "[^0-9\\.\\-\\_]", "" ); + + List valueTokens = new ArrayList( Arrays.asList( value.split( "[\\.\\-\\_]" ) ) ); List rangeValueTokens = new ArrayList( 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 ) ); diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java index 7c5204ff06..e06d9558d0 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java @@ -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" ) ) ); + } + }