maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r399330 - in /maven/plugins/trunk/maven-release-plugin/src: main/java/org/apache/maven/plugins/release/versions/DefaultVersionInfo.java test/java/org/apache/maven/plugins/release/versions/DefaultVersionInfoTest.java
Date Wed, 03 May 2006 15:20:23 GMT
Author: brett
Date: Wed May  3 08:19:56 2006
New Revision: 399330

URL: http://svn.apache.org/viewcvs?rev=399330&view=rev
Log:
[MRELEASE-95] allow parsing of single digit versions. Remove component from version parser.

Modified:
    maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/versions/DefaultVersionInfo.java
    maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/versions/DefaultVersionInfoTest.java

Modified: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/versions/DefaultVersionInfo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/versions/DefaultVersionInfo.java?rev=399330&r1=399329&r2=399330&view=diff
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/versions/DefaultVersionInfo.java
(original)
+++ maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/versions/DefaultVersionInfo.java
Wed May  3 08:19:56 2006
@@ -49,7 +49,6 @@
  * <p/>
  * Leading zeros are significant when performing comparisons.
  * <p/>
- * TODO: remove component field - it isn't relevant
  * TODO: this parser is better than DefaultArtifactVersion - replace it with this (but align
naming) and then remove this from here.
  */
 public class DefaultVersionInfo
@@ -57,8 +56,6 @@
 {
     private final String strVersion;
 
-    private final String component;
-
     private final List digits;
 
     private String annotation;
@@ -67,40 +64,32 @@
 
     private final String buildSpecifier;
 
-    private final String digitSeparator;
-
     private String annotationSeparator;
 
     private String annotationRevSeparator;
 
     private final String buildSeparator;
 
-    private static final int COMPONENT_INDEX = 1;
-
-    private static final int DIGIT_SEPARATOR_INDEX = 2;
-
-    private static final int DIGITS_INDEX = 3;
+    private static final int DIGITS_INDEX = 1;
 
-    private static final int ANNOTATION_SEPARATOR_INDEX = 4;
+    private static final int ANNOTATION_SEPARATOR_INDEX = 2;
 
-    private static final int ANNOTATION_INDEX = 5;
+    private static final int ANNOTATION_INDEX = 3;
 
-    private static final int ANNOTATION_REV_SEPARATOR_INDEX = 6;
+    private static final int ANNOTATION_REV_SEPARATOR_INDEX = 4;
 
-    private static final int ANNOTATION_REVISION_INDEX = 7;
+    private static final int ANNOTATION_REVISION_INDEX = 5;
 
-    private static final int BUILD_SEPARATOR_INDEX = 8;
+    private static final int BUILD_SEPARATOR_INDEX = 6;
 
-    private static final int BUILD_SPECIFIER_INDEX = 9;
+    private static final int BUILD_SPECIFIER_INDEX = 7;
 
     private static final String SNAPSHOT_IDENTIFIER = "SNAPSHOT";
 
     private static final String DIGIT_SEPARATOR_STRING = ".";
 
-    private static final Pattern STANDARD_PATTERN =
-        Pattern.compile( "^(.*?)" +                  // non greedy .* to grab the component.
-            "([-_])?" +                 // optional - or _  (digits separator)
-            "((?:\\d+[.])+\\d+)" +      // digit(s) and '.' repeated - followed by digit
(version digits 1.22.0, etc)
+    private static final Pattern STANDARD_PATTERN = Pattern.compile(
+        "^((?:\\d+\\.)*\\d+)" +      // digit(s) and '.' repeated - followed by digit (version
digits 1.22.0, etc)
             "([-_])?" +                 // optional - or _  (annotation separator)
             "([a-zA-Z]*)" +             // alpha characters (looking for annotation - alpha,
beta, RC, etc.)
             "([-_])?" +                 // optional - or _  (annotation revision separator)
@@ -121,10 +110,8 @@
         if ( "SNAPSHOT".equals( version ) )
         {
             annotation = null;
-            component = null;
             digits = null;
             buildSpecifier = "SNAPSHOT";
-            digitSeparator = null;
             buildSeparator = null;
             return;
         }
@@ -132,8 +119,6 @@
         Matcher m = STANDARD_PATTERN.matcher( strVersion );
         if ( m.matches() )
         {
-            component = nullIfEmpty( m.group( COMPONENT_INDEX ) );
-            digitSeparator = m.group( DIGIT_SEPARATOR_INDEX );
             digits = parseDigits( m.group( DIGITS_INDEX ) );
             if ( !SNAPSHOT_IDENTIFIER.equals( m.group( ANNOTATION_INDEX ) ) )
             {
@@ -169,16 +154,13 @@
         }
     }
 
-    public DefaultVersionInfo( String component, List digits, String annotation, String annotationRevision,
-                               String buildSpecifier, String digitSeparator, String annotationSeparator,
-                               String annotationRevSeparator, String buildSeparator )
+    public DefaultVersionInfo( List digits, String annotation, String annotationRevision,
String buildSpecifier,
+                               String annotationSeparator, String annotationRevSeparator,
String buildSeparator )
     {
-        this.component = component;
         this.digits = digits;
         this.annotation = annotation;
         this.annotationRevision = annotationRevision;
         this.buildSpecifier = buildSpecifier;
-        this.digitSeparator = digitSeparator;
         this.annotationSeparator = annotationSeparator;
         this.annotationRevSeparator = annotationRevSeparator;
         this.buildSeparator = buildSeparator;
@@ -212,8 +194,8 @@
             digits.set( digits.size() - 1, incrementVersionString( (String) digits.get( digits.size()
- 1 ) ) );
         }
 
-        return new DefaultVersionInfo( component, digits, annotation, annotationRevision,
buildSpecifier,
-                                       digitSeparator, annotationSeparator, annotationRevSeparator,
buildSeparator );
+        return new DefaultVersionInfo( digits, annotation, annotationRevision, buildSpecifier,
annotationSeparator,
+                                       annotationRevSeparator, buildSeparator );
     }
 
     /**
@@ -228,12 +210,6 @@
     {
         DefaultVersionInfo that = (DefaultVersionInfo) obj;
 
-        if ( !StringUtils.equals( this.component, that.component ) )
-        {
-            throw new IllegalArgumentException( "Cannot perform comparison on different components:
\"" + this
-                .component + "\" compared to \"" + that.component + "\"" );
-        }
-
         int result;
         // TODO: this is a workaround for a bug in DefaultArtifactVersion - fix there - 1.01
< 1.01.01
         if ( strVersion.startsWith( that.strVersion ) && !strVersion.equals( that.strVersion
) &&
@@ -326,14 +302,8 @@
     {
         StringBuffer sb = new StringBuffer();
 
-        if ( StringUtils.isNotEmpty( info.component ) )
-        {
-            sb.append( info.component );
-        }
-
         if ( info.digits != null )
         {
-            sb.append( StringUtils.defaultString( info.digitSeparator ) );
             sb.append( joinDigitString( info.digits ) );
         }
 
@@ -393,11 +363,6 @@
     private static String nullIfEmpty( String s )
     {
         return StringUtils.isEmpty( s ) ? null : s;
-    }
-
-    public String getComponent()
-    {
-        return component;
     }
 
     public List getDigits()

Modified: maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/versions/DefaultVersionInfoTest.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/versions/DefaultVersionInfoTest.java?rev=399330&r1=399329&r2=399330&view=diff
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/versions/DefaultVersionInfoTest.java
(original)
+++ maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/versions/DefaultVersionInfoTest.java
Wed May  3 08:19:56 2006
@@ -24,7 +24,7 @@
     public void testParse()
         throws Exception
     {
-        checkParsing( "1.0", null, "1.0", null, null, null );
+        checkParsing( "1.0", "1.0", null, null, null );
     }
 
     public void testParseWithBadVersion()
@@ -32,7 +32,7 @@
     {
         try
         {
-            checkParsing( "foo", null, null, null, null, "foo" );
+            checkParsing( "foo", null, null, null, "foo" );
             fail( "version is incorrect, must fail." );
         }
         catch ( VersionParseException e )
@@ -43,98 +43,87 @@
     public void testParseMultiDigit()
         throws Exception
     {
-        checkParsing( "99.99", null, "99.99", null, null, null );
-        checkParsing( "990.990.990", null, "990.990.990", null, null, null );
-    }
-
-    public void testParseComponent()
-        throws Exception
-    {
-        checkParsing( "my-component-99.99", "my-component", "99.99", null, null, null );
-        checkParsing( "my-component_99.99", "my-component", "99.99", null, null, null );
-        checkParsing( "my-component1.2.3", "my-component", "1.2.3", null, null, null );
-        checkParsing( "my-component11.22.33", "my-component", "11.22.33", null, null, null
);
+        checkParsing( "99.99", "99.99", null, null, null );
+        checkParsing( "990.990.990", "990.990.990", null, null, null );
     }
 
     public void testParseSnapshotVersion()
         throws Exception
     {
-        checkParsing( "1.0-beta-4-SNAPSHOT", null, "1.0", "beta", "4", "SNAPSHOT" );
-        checkParsing( "1.0-beta-4_SNAPSHOT", null, "1.0", "beta", "4", "SNAPSHOT" );
+        checkParsing( "1.0-beta-4-SNAPSHOT", "1.0", "beta", "4", "SNAPSHOT" );
+        checkParsing( "1.0-beta-4_SNAPSHOT", "1.0", "beta", "4", "SNAPSHOT" );
     }
 
     public void testParseAnnotationVersion()
         throws Exception
     {
-        checkParsing( "1.0-beta-4-SNAPSHOT", null, "1.0", "beta", "4", "SNAPSHOT" );
-        checkParsing( "1.0-beta-4", null, "1.0", "beta", "4", null );
-        checkParsing( "1.2.3-beta-99", null, "1.2.3", "beta", "99", null );
-        checkParsing( "1.2.3-beta99", null, "1.2.3", "beta", "99", null );
-        checkParsing( "1.2.3-beta99-SNAPSHOT", null, "1.2.3", "beta", "99", "SNAPSHOT" );
-        checkParsing( "1.2.3-RC4", null, "1.2.3", "RC", "4", null );
+        checkParsing( "1.0-beta-4-SNAPSHOT", "1.0", "beta", "4", "SNAPSHOT" );
+        checkParsing( "1.0-beta-4", "1.0", "beta", "4", null );
+        checkParsing( "1.2.3-beta-99", "1.2.3", "beta", "99", null );
+        checkParsing( "1.2.3-beta99", "1.2.3", "beta", "99", null );
+        checkParsing( "1.2.3-beta99-SNAPSHOT", "1.2.3", "beta", "99", "SNAPSHOT" );
+        checkParsing( "1.2.3-RC4", "1.2.3", "RC", "4", null );
     }
 
     public void testParseSeparators()
         throws Exception
     {
-        checkParsing( "log4j-1.2.9-beta-9-SNAPSHOT", "log4j", "1.2.9", "beta", "9", "SNAPSHOT"
);
-        checkParsing( "log4j1.2.9beta9SNAPSHOT", "log4j", "1.2.9", "beta", "9", "SNAPSHOT"
);
-        checkParsing( "log4j1.2.9beta-9SNAPSHOT", "log4j", "1.2.9", "beta", "9", "SNAPSHOT"
);
-        checkParsing( "log4j_1.2.9_beta_9_SNAPSHOT", "log4j", "1.2.9", "beta", "9", "SNAPSHOT"
);
+        checkParsing( "1.2.9-beta-9-SNAPSHOT", "1.2.9", "beta", "9", "SNAPSHOT" );
+        checkParsing( "1.2.9beta9SNAPSHOT", "1.2.9", "beta", "9", "SNAPSHOT" );
+        checkParsing( "1.2.9beta-9SNAPSHOT", "1.2.9", "beta", "9", "SNAPSHOT" );
+        checkParsing( "1.2.9_beta_9_SNAPSHOT", "1.2.9", "beta", "9", "SNAPSHOT" );
     }
 
     public void testParseAnnotationNoVersionButSnapshot()
         throws Exception
     {
-        checkParsing( "1.0-beta-SNAPSHOT", null, "1.0", "beta", null, "SNAPSHOT" );
-        checkParsing( "1.2.3-beta99", null, "1.2.3", "beta", "99", null );
-        checkParsing( "1.2.3-RC4-SNAPSHOT", null, "1.2.3", "RC", "4", "SNAPSHOT" );
+        checkParsing( "1.0-beta-SNAPSHOT", "1.0", "beta", null, "SNAPSHOT" );
+        checkParsing( "1.2.3-beta99", "1.2.3", "beta", "99", null );
+        checkParsing( "1.2.3-RC4-SNAPSHOT", "1.2.3", "RC", "4", "SNAPSHOT" );
     }
 
     public void testParseAnnotationVersionWithRevision()
         throws Exception
     {
-        checkParsing( "1.0-beta-4-SNAPSHOT", null, "1.0", "beta", "4", "SNAPSHOT" );
-        checkParsing( "1.0-beta-4", null, "1.0", "beta", "4", null );
-        checkParsing( "1.2.3-beta-99", null, "1.2.3", "beta", "99", null );
-        checkParsing( "1.2.3-beta99", null, "1.2.3", "beta", "99", null );
-        checkParsing( "1.2.3-RC4", null, "1.2.3", "RC", "4", null );
-
-        checkParsing( "mycomponent-1.2.3-RC4", "mycomponent", "1.2.3", "RC", "4", null );
-        checkParsing( "mycomponent-1.2.3-RC4", "mycomponent", "1.2.3", "RC", "4", null );
-        checkParsing( "log4j-1.2.9", "log4j", "1.2.9", null, null, null );
+        checkParsing( "1.0-beta-4-SNAPSHOT", "1.0", "beta", "4", "SNAPSHOT" );
+        checkParsing( "1.0-beta-4", "1.0", "beta", "4", null );
+        checkParsing( "1.2.3-beta-99", "1.2.3", "beta", "99", null );
+        checkParsing( "1.2.3-beta99", "1.2.3", "beta", "99", null );
+        checkParsing( "1.2.3-RC4", "1.2.3", "RC", "4", null );
+
+        checkParsing( "1.2.9", "1.2.9", null, null, null );
     }
 
     public void testParseAnnotationVersionWithoutRevision()
         throws Exception
     {
-        checkParsing( "1.0-beta", null, "1.0", "beta", null, null );
-        checkParsing( "1.0-beta-SNAPSHOT", null, "1.0", "beta", null, "SNAPSHOT" );
+        checkParsing( "1.0-beta", "1.0", "beta", null, null );
+        checkParsing( "1.0-beta-SNAPSHOT", "1.0", "beta", null, "SNAPSHOT" );
     }
 
     public void testParseAnnotationRevisionOnly()
         throws Exception
     {
-        checkParsing( "1.0-4", null, "1.0", null, "4", null );
+        checkParsing( "1.0-4", "1.0", null, "4", null );
     }
 
     public void testParseLeadingZeros()
         throws Exception
     {
-        checkParsing( "1.01-beta-04-SNAPSHOT", null, "1.01", "beta", "04", "SNAPSHOT" );
-        checkParsing( "01.01.001-beta-04-SNAPSHOT", null, "01.01.001", "beta", "04", "SNAPSHOT"
);
+        checkParsing( "1.01-beta-04-SNAPSHOT", "1.01", "beta", "04", "SNAPSHOT" );
+        checkParsing( "01.01.001-beta-04-SNAPSHOT", "01.01.001", "beta", "04", "SNAPSHOT"
);
     }
 
     public void testParseBuildNumber()
         throws Exception
     {
-        checkParsing( "plexus-logging-provider-test-1.0-alpha-2-20051013.095555-2", "plexus-logging-provider-test",
-                      "1.0", "alpha", "2", "20051013.095555-2" );
+        checkParsing( "1.0-alpha-2-20051013.095555-2", "1.0", "alpha", "2", "20051013.095555-2"
);
     }
 
     public void testNextVersion()
         throws Exception
     {
+        checkNextVersion( "1", "2" );
         checkNextVersion( "1.01", "1.02" );
         checkNextVersion( "1.9", "1.10" );
         checkNextVersion( "1.09", "1.10" );
@@ -143,19 +132,6 @@
         checkNextVersion( "1.99", "1.100" );
     }
 
-    public void testInvalidComponentComparison()
-        throws VersionParseException
-    {
-        try
-        {
-            checkVersionLessThanVersion( "foo-1.0", "bar-1.0" );
-            fail( "Should have failed" );
-        }
-        catch ( IllegalArgumentException e )
-        {
-        }
-    }
-
     public void testNextAnnotationRevision()
         throws Exception
     {
@@ -220,6 +196,9 @@
     public void testGetReleaseVersion()
         throws Exception
     {
+        checkGetReleaseVersion( "1-SNAPSHOT", "1" );
+        checkGetReleaseVersion( "1", "1" );
+
         checkGetReleaseVersion( "1.01", "1.01" );
         checkGetReleaseVersion( "1.01-beta", "1.01-beta" );
         checkGetReleaseVersion( "1.01-beta-04", "1.01-beta-04" );
@@ -231,6 +210,7 @@
     public void testGetSnapshotVersion()
         throws Exception
     {
+        checkGetSnapshotVersion( "1", "1-SNAPSHOT" );
         checkGetSnapshotVersion( "1.01", "1.01-SNAPSHOT" );
         checkGetSnapshotVersion( "1.01-beta", "1.01-beta-SNAPSHOT" );
         checkGetSnapshotVersion( "1.01-beta-04", "1.01-beta-04-SNAPSHOT" );
@@ -269,14 +249,13 @@
         assertEquals( expected, v.getSnapshotVersionString() );
     }
 
-    private static void checkParsing( String strVersion, String component, String digits,
String annotation,
-                                      String annotationRevision, String buildSpecifier )
+    private static void checkParsing( String strVersion, String digits, String annotation,
String annotationRevision,
+                                      String buildSpecifier )
         throws Exception
     {
         DefaultVersionInfo v = new DefaultVersionInfo( strVersion );
 
         assertEquals( strVersion, v.toString() );
-        assertEquals( component, v.getComponent() );
         assertEquals( digits, DefaultVersionInfo.joinDigitString( v.getDigits() ) );
         assertEquals( annotation, v.getAnnotation() );
         assertEquals( annotationRevision, v.getAnnotationRevision() );



Mime
View raw message