diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/JdkMatcher.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/JdkMatcher.java index d2d9c6b4c6..877c0fee7e 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/JdkMatcher.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/JdkMatcher.java @@ -74,8 +74,13 @@ public class JdkMatcher private static int getRelationOrder( String value, RangeValue rangeValue, boolean isLeft ) { - List valueTokens = Arrays.asList( value.split( "." ) ); - List rangeValueTokens = Arrays.asList( rangeValue.value.split( "." ) ); + if ( rangeValue.value.length() <= 0 ) + { + return isLeft ? 1 : -1; + } + + 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() ); addZeroTokens( valueTokens, max ); @@ -83,13 +88,17 @@ public class JdkMatcher if ( value.equals( rangeValue.value ) ) { - return ( rangeValue.isClosed() ) ? 0 : -1; + if ( !rangeValue.isClosed() ) + { + return isLeft ? -1 : 1; + } + return 0; } for ( int i = 0; i < valueTokens.size(); i++ ) { - int x = Integer.getInteger( valueTokens.get( i ) ); - int y = Integer.getInteger( rangeValueTokens.get( i ) ); + int x = Integer.parseInt( valueTokens.get( i ) ); + int y = Integer.parseInt( rangeValueTokens.get( i ) ); if ( x < y ) { return -1; @@ -99,6 +108,10 @@ public class JdkMatcher return 1; } } + if ( !rangeValue.isClosed() ) + { + return isLeft ? -1 : 1; + } return 0; } @@ -140,7 +153,10 @@ public class JdkMatcher { ranges.add( new RangeValue( token.replace( ")", "" ), false ) ); } - + else if ( token.length() <= 0 ) + { + ranges.add( new RangeValue( "", false ) ); + } } if ( ranges.size() < 2 ) { @@ -170,5 +186,10 @@ public class JdkMatcher { return isClosed; } + + public String toString() + { + return value; + } } } diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/JdkMatcherTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/JdkMatcherTest.java index aedb053910..c1e8a57e1e 100644 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/JdkMatcherTest.java +++ b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/JdkMatcherTest.java @@ -145,8 +145,9 @@ public class JdkMatcherTest { props.add(new InterpolatorProperty("${java.specification.version}" , "1.5")); JdkMatcher matcher = new JdkMatcher(); - assertTrue(matcher.isMatch(modelContainer, props)); + assertFalse(matcher.isMatch(modelContainer, props)); } + @org.junit.Test public void jdkVersionRange_OpenRightEdge() { List modelProperties = new ArrayList(); @@ -195,26 +196,6 @@ public class JdkMatcherTest { assertFalse(matcher.isMatch(modelContainer, props)); } - /* FIXME: Instead of re-inventing the version comparison logic for the JdkMatcher, can't we recycle stuff from - //* the old artifact code of from Mercury? - @org.junit.Test - public void jdkVersionRange_WithExclusionPoint() - { - List modelProperties = new ArrayList(); - modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.xUri, null ) ); - modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.Activation.xUri, null ) ); - modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.Activation.jdk, "(,1.5.2),(1.5.2,)" ) ); - - ModelContainer modelContainer = new DefaultModelContainer( modelProperties ); - - List props = new ArrayList(); - props.add( new InterpolatorProperty( "${java.specification.version}", "1.5" ) ); - - JdkMatcher matcher = new JdkMatcher(); - assertTrue( matcher.isMatch( modelContainer, props ) ); - } - //*/ - @org.junit.Test public void jdkVersionNotFound() { List modelProperties = new ArrayList();