You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2010/01/02 13:54:12 UTC

svn commit: r895185 - in /maven/maven-3/trunk/maven-model-builder/src: main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java

Author: bentmann
Date: Sat Jan  2 12:54:12 2010
New Revision: 895185

URL: http://svn.apache.org/viewvc?rev=895185&view=rev
Log:
[MNG-4512] [regression] Profile activation based on JDK version range fails if current version is close to range boundary

Modified:
    maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java
    maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java

Modified: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java?rev=895185&r1=895184&r2=895185&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java (original)
+++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivator.java Sat Jan  2 12:54:12 2010
@@ -103,7 +103,9 @@
             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 @@
             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 ) );

Modified: maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java?rev=895185&r1=895184&r2=895185&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java (original)
+++ maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java Sat Jan  2 12:54:12 2010
@@ -74,8 +74,9 @@
         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 @@
         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.3,1.6)" );
+        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" ) ) );
+    }
 
-        assertActivation( true, profile, newContext( null, newProperties( "1.5.0_16" ) ) );
+    public void testVersionRangeExclusiveBounds()
+        throws Exception
+    {
+        Profile profile = newProfile( "(1.3,1.6)" );
 
         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" ) ) );
     }
 
 }