o Fixed JDK activator

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@752157 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-03-10 16:34:00 +00:00
parent d18e2ca531
commit db85e427b9
2 changed files with 29 additions and 27 deletions

View File

@ -74,8 +74,13 @@ public class JdkMatcher
private static int getRelationOrder( String value, RangeValue rangeValue, boolean isLeft ) private static int getRelationOrder( String value, RangeValue rangeValue, boolean isLeft )
{ {
List<String> valueTokens = Arrays.asList( value.split( "." ) ); if ( rangeValue.value.length() <= 0 )
List<String> rangeValueTokens = Arrays.asList( rangeValue.value.split( "." ) ); {
return isLeft ? 1 : -1;
}
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() ); int max = Math.max( valueTokens.size(), rangeValueTokens.size() );
addZeroTokens( valueTokens, max ); addZeroTokens( valueTokens, max );
@ -83,13 +88,17 @@ public class JdkMatcher
if ( value.equals( rangeValue.value ) ) 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++ ) for ( int i = 0; i < valueTokens.size(); i++ )
{ {
int x = Integer.getInteger( valueTokens.get( i ) ); int x = Integer.parseInt( valueTokens.get( i ) );
int y = Integer.getInteger( rangeValueTokens.get( i ) ); int y = Integer.parseInt( rangeValueTokens.get( i ) );
if ( x < y ) if ( x < y )
{ {
return -1; return -1;
@ -99,6 +108,10 @@ public class JdkMatcher
return 1; return 1;
} }
} }
if ( !rangeValue.isClosed() )
{
return isLeft ? -1 : 1;
}
return 0; return 0;
} }
@ -140,7 +153,10 @@ public class JdkMatcher
{ {
ranges.add( new RangeValue( token.replace( ")", "" ), false ) ); ranges.add( new RangeValue( token.replace( ")", "" ), false ) );
} }
else if ( token.length() <= 0 )
{
ranges.add( new RangeValue( "", false ) );
}
} }
if ( ranges.size() < 2 ) if ( ranges.size() < 2 )
{ {
@ -170,5 +186,10 @@ public class JdkMatcher
{ {
return isClosed; return isClosed;
} }
public String toString()
{
return value;
}
} }
} }

View File

@ -145,8 +145,9 @@ public class JdkMatcherTest {
props.add(new InterpolatorProperty("${java.specification.version}" , "1.5")); props.add(new InterpolatorProperty("${java.specification.version}" , "1.5"));
JdkMatcher matcher = new JdkMatcher(); JdkMatcher matcher = new JdkMatcher();
assertTrue(matcher.isMatch(modelContainer, props)); assertFalse(matcher.isMatch(modelContainer, props));
} }
@org.junit.Test @org.junit.Test
public void jdkVersionRange_OpenRightEdge() { public void jdkVersionRange_OpenRightEdge() {
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>(); List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
@ -195,26 +196,6 @@ public class JdkMatcherTest {
assertFalse(matcher.isMatch(modelContainer, props)); 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<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
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<InterpolatorProperty> props = new ArrayList<InterpolatorProperty>();
props.add( new InterpolatorProperty( "${java.specification.version}", "1.5" ) );
JdkMatcher matcher = new JdkMatcher();
assertTrue( matcher.isMatch( modelContainer, props ) );
}
//*/
@org.junit.Test @org.junit.Test
public void jdkVersionNotFound() { public void jdkVersionNotFound() {
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>(); List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();