You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2006/04/22 10:57:21 UTC

svn commit: r396098 - in /maven/plugins/trunk/maven-release-plugin/src: main/java/org/apache/maven/plugins/release/helpers/ main/java/org/apache/maven/plugins/release/versions/ test/java/org/apache/maven/plugins/release/versions/

Author: brett
Date: Sat Apr 22 01:57:19 2006
New Revision: 396098

URL: http://svn.apache.org/viewcvs?rev=396098&view=rev
Log:
improve version parser:
- increase test coverage
- make 0 significant in version
- other consistencies with Maven versioning scheme
- cleanup

Modified:
    maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/helpers/ProjectVersionResolver.java
    maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/versions/DefaultVersionInfo.java
    maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/versions/VersionInfo.java
    maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/versions/VersionParseException.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/helpers/ProjectVersionResolver.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/helpers/ProjectVersionResolver.java?rev=396098&r1=396097&r2=396098&view=diff
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/helpers/ProjectVersionResolver.java (original)
+++ maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/helpers/ProjectVersionResolver.java Sat Apr 22 01:57:19 2006
@@ -16,10 +16,6 @@
  * limitations under the License.
  */
 
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
 import org.apache.maven.artifact.ArtifactUtils;
 import org.apache.maven.model.Model;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -30,6 +26,10 @@
 import org.codehaus.plexus.components.interactivity.InputHandler;
 import org.codehaus.plexus.util.StringUtils;
 
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
 public class ProjectVersionResolver
 {
     private Map resolvedVersions = new HashMap();
@@ -63,26 +63,27 @@
 
         if ( interactive )
         {
-            projectVersion = getVersionFromUser("What is the release version for \"" + projectId + "\"?", projectVersion);
-        } 
-        else if ( StringUtils.isEmpty( projectVersion ) ) 
+            projectVersion =
+                getVersionFromUser( "What is the release version for \"" + projectId + "\"?", projectVersion );
+        }
+        else if ( StringUtils.isEmpty( projectVersion ) )
         {
-            throw new MojoExecutionException("Unable to determine release project version");
+            throw new MojoExecutionException( "Unable to determine release project version" );
         }
-        
+
         model.setVersion( projectVersion );
 
         resolvedVersions.put( projectId, projectVersion );
     }
 
-    private String getVersionFromUser(String promptText, String defaultVersionStr )
+    private String getVersionFromUser( String promptText, String defaultVersionStr )
         throws MojoExecutionException
     {
         if ( defaultVersionStr != null )
         {
             promptText = promptText + " [" + defaultVersionStr + "]";
         }
-        
+
         try
         {
             log.info( promptText );
@@ -94,9 +95,9 @@
         catch ( IOException e )
         {
             throw new MojoExecutionException( "Can't read version from user input.", e );
-        }        
+        }
     }
-    
+
     public String getResolvedVersion( String groupId, String artifactId )
     {
         String projectId = ArtifactUtils.versionlessKey( groupId, artifactId );
@@ -104,37 +105,39 @@
         return (String) resolvedVersions.get( projectId );
     }
 
-    public VersionInfo getVersionInfo( String version ) {
+    public VersionInfo getVersionInfo( String version )
+    {
         // TODO: Provide a way to override the implementation of VersionInfo
-        try 
+        try
         {
             return new DefaultVersionInfo( version );
-        } 
+        }
         catch ( VersionParseException e )
         {
             return null;
         }
-        
+
     }
-    
+
     public void incrementVersion( Model model, String projectId )
         throws MojoExecutionException
     {
         VersionInfo version = getVersionInfo( model.getVersion() );
-        
+
         if ( version != null && version.isSnapshot() )
         {
-            throw new MojoExecutionException( "The project " + projectId + " is a snapshot ("
-                + version.getVersionString() + "). It appears that the release version has not been committed." );
+            throw new MojoExecutionException( "The project " + projectId + " is a snapshot (" + model.getVersion() +
+                "). It appears that the release version has not been committed." );
         }
 
-        VersionInfo nextVersionInfo = ( version != null ) ? version.getNextVersion() : null;
-        
-        String nextVersion = (nextVersionInfo != null) ? nextVersionInfo.getSnapshotVersionString() : null;
-        
+        VersionInfo nextVersionInfo = version != null ? version.getNextVersion() : null;
+
+        String nextVersion = nextVersionInfo != null ? nextVersionInfo.getSnapshotVersionString() : null;
+
         if ( interactive )
         {
-            nextVersion = getVersionFromUser("What is the new development version for \"" + projectId + "\"?", nextVersion );            
+            nextVersion =
+                getVersionFromUser( "What is the new development version for \"" + projectId + "\"?", nextVersion );
         }
         else if ( nextVersion == null )
         {

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=396098&r1=396097&r2=396098&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 Sat Apr 22 01:57:19 2006
@@ -16,152 +16,151 @@
  * limitations under the License.
  */
 
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.codehaus.plexus.util.StringUtils;
-
-/** This compares and increments versions for a common java versioning scheme.
- * <p>
+/**
+ * This compares and increments versions for a common java versioning scheme.
+ * <p/>
  * The supported version scheme has the following parts.<br>
  * <code><i>component-digits-annotation-annotationRevision-buildSpecifier</i></code><br>
  * Example:<br>
  * <code>my-component-1.0.1-alpha-2-SNAPSHOT</code>
- * 
+ * <p/>
  * <ul>Terms:
- *  <li><i>component</i> - name of the versioned component (log4j, commons-lang, etc)
- *  <li><i>digits</i> - Numeric digits with at least one "." period. (1.0, 1.1, 1.01, 1.2.3, etc)
- *  <li><i>annotation</i> - Version annotation - Valid Values are (alpha, beta, RC).
- *   Use {@link DefaultVersionInfo#setAnnotationOrder(List)} to change the valid values.
- *  <li><i>annotationRevision</i> - Integer qualifier for the annotation. (4 as in RC-4)
- *  <li><i>buildSpecifier</i> - Additional specifier for build. (SNAPSHOT, or build number like "20041114.081234-2")
+ * <li><i>component</i> - name of the versioned component (log4j, commons-lang, etc)
+ * <li><i>digits</i> - Numeric digits with at least one "." period. (1.0, 1.1, 1.01, 1.2.3, etc)
+ * <li><i>annotationRevision</i> - Integer qualifier for the annotation. (4 as in RC-4)
+ * <li><i>buildSpecifier</i> - Additional specifier for build. (SNAPSHOT, or build number like "20041114.081234-2")
  * </ul>
  * <b>Digits is the only required piece of the version string, and must contain at lease one "." period.</b>
- * <p>
+ * <p/>
  * Implementation details:<br>
  * The separators "_" and "-" between components are also optional (though they are usually reccommended).<br>
  * Example:<br>
  * <code>log4j-1.2.9-beta-9-SNAPSHOT == log4j1.2.9beta9SNAPSHOT == log4j_1.2.9_beta_9_SNAPSHOT</code>
- * <p>
- * All numbers in the "digits" part of the version are considered Integers. Therefore 1.01.01 is the same as 1.1.1
- * Leading zeros are ignored when performing comparisons.
- *
+ * <p/>
+ * Leading zeros are significant when performing comparisons.
+ * <p/>
+ * TODO: remove component - 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
-    implements VersionInfo, Cloneable
+    implements VersionInfo
 {
-    protected String strVersion;
+    private final String strVersion;
+
+    private final String component;
 
-    protected String component;
+    private final List digits;
 
-    protected List digits;
+    private String annotation;
 
-    protected String annotation;
+    private String annotationRevision;
 
-    protected String annotationRevision;
+    private final String buildSpecifier;
 
-    protected String buildSpecifier;
+    private final String digitSeparator;
 
-    protected String digitSeparator;
+    private String annotationSeparator;
 
-    protected String annotationSeparator;
+    private String annotationRevSeparator;
 
-    protected String annotationRevSeparator;
+    private final String buildSeparator;
 
-    protected String buildSeparator;
-    
-    protected List annotationOrder;
-    
-    private final static int COMPONENT_INDEX = 1;
+    private static final int COMPONENT_INDEX = 1;
 
-    private final static int DIGIT_SEPARATOR_INDEX = 2;
+    private static final int DIGIT_SEPARATOR_INDEX = 2;
 
-    private final static int DIGITS_INDEX = 3;
+    private static final int DIGITS_INDEX = 3;
 
-    private final static int ANNOTATION_SEPARATOR_INDEX = 4;
+    private static final int ANNOTATION_SEPARATOR_INDEX = 4;
 
-    private final static int ANNOTATION_INDEX = 5;
+    private static final int ANNOTATION_INDEX = 5;
 
-    private final static int ANNOTATION_REV_SEPARATOR_INDEX = 6;
+    private static final int ANNOTATION_REV_SEPARATOR_INDEX = 6;
 
-    private final static int ANNOTATION_REVISION_INDEX = 7;
+    private static final int ANNOTATION_REVISION_INDEX = 7;
 
-    private final static int BUILD_SEPARATOR_INDEX = 8;
+    private static final int BUILD_SEPARATOR_INDEX = 8;
 
-    private final static int BUILD_SPECIFIER_INDEX = 9;
+    private static final int BUILD_SPECIFIER_INDEX = 9;
 
-    public static final String SNAPSHOT_IDENTIFIER = "SNAPSHOT";
-    
-    protected final static String DIGIT_SEPARATOR_STRING = ".";
+    private static final String SNAPSHOT_IDENTIFIER = "SNAPSHOT";
 
-    protected final static 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)
-        "([-_])?" +                 // optional - or _  (annotation separator)
-        "([a-zA-Z]*)" +             // alpha characters (looking for annotation - alpha, beta, RC, etc.)
-        "([-_])?" +                 // optional - or _  (annotation revision separator)
-        "(\\d*)" +                  // digits  (any digits after rc or beta is an annotation revision)
-        "(?:([-_])?(.*?))?$");      // - or _ followed everything else (build specifier)
-    
-    protected final static Pattern DIGIT_SEPARATOR_PATTERN = Pattern.compile( "(\\d+)\\.?" );
-    
-    /** Constructs this object and parses the supplied version string.
-     *  
+    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)
+            "([-_])?" +                 // optional - or _  (annotation separator)
+            "([a-zA-Z]*)" +             // alpha characters (looking for annotation - alpha, beta, RC, etc.)
+            "([-_])?" +                 // optional - or _  (annotation revision separator)
+            "(\\d*)" +                  // digits  (any digits after rc or beta is an annotation revision)
+            "(?:([-_])?(.*?))?$" );      // - or _ followed everything else (build specifier)
+
+    /**
+     * Constructs this object and parses the supplied version string.
+     *
      * @param version
      */
     public DefaultVersionInfo( String version )
         throws VersionParseException
     {
-        // TODO: How to handle M (Milestone) or 1.1b (Beta)
-        annotationOrder = Arrays.asList( new String[] { "ALPHA", "BETA", "RC" } );
+        strVersion = version;
 
-        parseVersion( version );
-    }
-    
-    /** Internal routine for parsing the supplied version string into its parts. 
-     * 
-     * @param version
-     */
-    protected void parseVersion( String version )
-        throws VersionParseException
-    {
-        this.strVersion = version;
+        // TODO: hack because it didn't support "SNAPSHOT"
+        if ( "SNAPSHOT".equals( version ) )
+        {
+            annotation = null;
+            component = null;
+            digits = null;
+            buildSpecifier = "SNAPSHOT";
+            digitSeparator = null;
+            buildSeparator = null;
+            return;
+        }
 
         Matcher m = STANDARD_PATTERN.matcher( strVersion );
         if ( m.matches() )
         {
-            setComponent( m.group( COMPONENT_INDEX ) );
-            this.digitSeparator = m.group( DIGIT_SEPARATOR_INDEX );
-            setDigits( parseDigits( m.group( DIGITS_INDEX ) ) );
+            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 ) ) )
             {
-                this.annotationSeparator = m.group( ANNOTATION_SEPARATOR_INDEX );
-                setAnnotation( m.group( ANNOTATION_INDEX ) );
+                annotationSeparator = m.group( ANNOTATION_SEPARATOR_INDEX );
+                annotation = nullIfEmpty( m.group( ANNOTATION_INDEX ) );
 
-                if ( StringUtils.isNotEmpty( m.group( ANNOTATION_REV_SEPARATOR_INDEX ) )
-                    && StringUtils.isEmpty( m.group( ANNOTATION_REVISION_INDEX ) ) )
+                if ( StringUtils.isNotEmpty( m.group( ANNOTATION_REV_SEPARATOR_INDEX ) ) &&
+                    StringUtils.isEmpty( m.group( ANNOTATION_REVISION_INDEX ) ) )
                 {
                     // The build separator was picked up as the annotation revision separator
-                    this.buildSeparator = m.group( ANNOTATION_REV_SEPARATOR_INDEX );
-                    setBuildSpecifier( m.group( BUILD_SPECIFIER_INDEX ) );
+                    buildSeparator = m.group( ANNOTATION_REV_SEPARATOR_INDEX );
+                    buildSpecifier = nullIfEmpty( m.group( BUILD_SPECIFIER_INDEX ) );
                 }
                 else
                 {
-                    this.annotationRevSeparator = m.group( ANNOTATION_REV_SEPARATOR_INDEX );
-                    setAnnotationRevision( m.group( ANNOTATION_REVISION_INDEX ) );
+                    annotationRevSeparator = m.group( ANNOTATION_REV_SEPARATOR_INDEX );
+                    annotationRevision = nullIfEmpty( m.group( ANNOTATION_REVISION_INDEX ) );
 
-                    this.buildSeparator = m.group( BUILD_SEPARATOR_INDEX );
-                    setBuildSpecifier( m.group( BUILD_SPECIFIER_INDEX ) );
+                    buildSeparator = m.group( BUILD_SEPARATOR_INDEX );
+                    buildSpecifier = nullIfEmpty( m.group( BUILD_SPECIFIER_INDEX ) );
                 }
             }
             else
             {
                 // Annotation was "SNAPSHOT" so populate the build specifier with that data
-                this.buildSeparator = m.group( ANNOTATION_SEPARATOR_INDEX );
-                setBuildSpecifier( m.group( ANNOTATION_INDEX ) );
+                buildSeparator = m.group( ANNOTATION_SEPARATOR_INDEX );
+                buildSpecifier = nullIfEmpty( m.group( ANNOTATION_INDEX ) );
             }
         }
         else
@@ -169,202 +168,158 @@
             throw new VersionParseException( "Unable to parse the version string: \"" + version + "\"" );
         }
     }
-    
-    public boolean isSnapshot()
+
+    public DefaultVersionInfo( String component, List digits, String annotation, String annotationRevision,
+                               String buildSpecifier, String digitSeparator, String annotationSeparator,
+                               String annotationRevSeparator, String buildSeparator )
     {
-        return SNAPSHOT_IDENTIFIER.equalsIgnoreCase( this.buildSpecifier );
+        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;
+        this.strVersion = getVersionString( this, buildSpecifier, buildSeparator );
     }
 
-    public VersionInfo getNextVersion()
+    public boolean isSnapshot()
     {
-        DefaultVersionInfo result;
-
-        try
+        // TODO: ripped from Artifact. Should be in ArtifactVersion -> move.
+        Matcher m = Artifact.VERSION_FILE_PATTERN.matcher( strVersion );
+        if ( m.matches() )
         {
-            result = (DefaultVersionInfo) this.clone();
+            return true;
         }
-        catch ( CloneNotSupportedException e )
+        else
         {
-            return null;
+            return strVersion.endsWith( Artifact.SNAPSHOT_VERSION ) || strVersion.equals( Artifact.LATEST_VERSION );
         }
+    }
 
-        if ( StringUtils.isNumeric( result.annotationRevision ) )
-        {
-            result.annotationRevision = incrementVersionString( result.annotationRevision );
-        }
-        else if ( result.digits != null && !result.digits.isEmpty() )
+    public VersionInfo getNextVersion()
+    {
+        List digits = new ArrayList( this.digits );
+        String annotationRevision = this.annotationRevision;
+        if ( StringUtils.isNumeric( annotationRevision ) )
         {
-            try
-            {
-                List digits = result.digits;
-                digits.set( digits.size() - 1, incrementVersionString( (String) digits.get( digits.size() - 1 ) ) );
-            }
-            catch ( NumberFormatException e )
-            {
-                return null;
-            }
+            annotationRevision = incrementVersionString( annotationRevision );
         }
         else
         {
-            return null;
+            digits.set( digits.size() - 1, incrementVersionString( (String) digits.get( digits.size() - 1 ) ) );
         }
 
-        return result;
+        return new DefaultVersionInfo( component, digits, annotation, annotationRevision, buildSpecifier,
+                                       digitSeparator, annotationSeparator, annotationRevSeparator, buildSeparator );
     }
-    
-    /** Compares this {@link DefaultVersionInfo} to the supplied {@link DefaultVersionInfo}
+
+    /**
+     * Compares this {@link DefaultVersionInfo} to the supplied {@link DefaultVersionInfo}
      * to determine which version is greater.
-     * <p>
-     * Decision order is: digits, annotation, annotationRev, buildSpecifier.
-     * <p>
-     * Presence of an annotation is considered to be less than an equivalent version without an annotation.<br>
-     * Example: 1.0 is greater than 1.0-alpha.<br> 
-     * <p> 
-     * The {@link DefaultVersionInfo#getAnnotationOrder()} is used in determining the rank order of annotations.<br>
-     * For example: alpha &lt; beta &lt; RC &lt release 
-     * 
-     * @param that
-     * @return
+     *
+     * @param obj the comparison version
+     * @return the comparison value
      * @throws IllegalArgumentException if the components differ between the objects or if either of the annotations can not be determined.
      */
     public int compareTo( Object obj )
     {
-        if ( !( obj instanceof DefaultVersionInfo ) )
-            throw new ClassCastException( "DefaultVersionInfo object expected" );
-
         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 + "\"" );
+            throw new IllegalArgumentException( "Cannot perform comparison on different components: \"" + this
+                .component + "\" compared to \"" + that.component + "\"" );
         }
 
-        if ( !this.digits.equals( that.digits ) )
+        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 ) &&
+            strVersion.charAt( that.strVersion.length() ) != '-' )
         {
-            for ( int i = 0; i < this.digits.size(); i++ )
-            {
-                if ( i >= that.digits.size() )
-                {
-                    // We've gone past the end of the digit list of that. We are greater
-                    return 1;
-                }
-
-                if ( !StringUtils.equals( (String) this.digits.get( i ), (String) that.digits.get( i ) ) )
-                {
-                    return compareToAsIntegers( (String) this.digits.get( i ), (String) that.digits.get( i ) );
-                }
-            }
-
-            if ( this.digits.size() < that.digits.size() )
-            {
-                // The lists were equal up to the end of this list. The other has more digits so it is greater.
-                return -1;
-            }
+            result = 1;
         }
-
-        if ( !StringUtils.equalsIgnoreCase( this.annotation, that.annotation ) )
+        else if ( that.strVersion.startsWith( strVersion ) && !strVersion.equals( that.strVersion ) &&
+            that.strVersion.charAt( strVersion.length() ) != '-' )
         {
-            // Having an annotation vs. not is considered to be less than.
-            // a 1.0-alpha is less than 1.0
-            if ( this.annotation != null && that.annotation == null )
-            {
-                return -1;
-            }
-            else if ( this.annotation == null && that.annotation != null )
-            {
-                return 1;
-            }
-            else
-            {
-                int nThis = annotationOrder.indexOf( this.annotation.toUpperCase() );
-                int nThat = annotationOrder.indexOf( that.annotation.toUpperCase() );
-
-                if ( nThis == -1 || nThat == -1 )
-                {
-                    throw new IllegalArgumentException( "Cannot perform comparison on unknown annotation: \""
-                        + this.annotation + "\" compared to \"" + that.annotation + "\"" );
-                }
-
-                return nThis - nThat;
-            }
+            result = -1;
         }
-
-        if ( !StringUtils.equals( this.annotationRevision, that.annotationRevision ) )
+        else
         {
-            return compareToAsIntegers( this.annotationRevision, that.annotationRevision );
-        }
+            // TODO: this is a workaround for a bug in DefaultArtifactVersion - fix there - it should not consider case in comparing the qualifier
+            String thisVersion = strVersion.toLowerCase();
+            String thatVersion = that.strVersion.toLowerCase();
 
-        if ( !StringUtils.equals( this.buildSpecifier, that.buildSpecifier ) )
-        {
-            if ( this.buildSpecifier == null && that.buildSpecifier != null )
-            {
-                return 1;
-            }
-            else if ( this.buildSpecifier != null && that.buildSpecifier == null )
-            {
-                return -1;
-            }
-            else
-            {
-                // Just do a simple string comparison?
-                return this.buildSpecifier.compareTo( that.buildSpecifier );
-            }
+            result = new DefaultArtifactVersion( thisVersion ).compareTo( new DefaultArtifactVersion( thatVersion ) );
         }
-
-        return 0;
+        return result;
     }
 
-    private int compareToAsIntegers( String s1, String s2 )
+    public boolean equals( Object obj )
     {
-        int n1 = StringUtils.isEmpty( s1 ) ? -1 : Integer.parseInt( s1 );
-        int n2 = StringUtils.isEmpty( s2 ) ? -1 : Integer.parseInt( s2 );
+        if ( !( obj instanceof DefaultVersionInfo ) )
+        {
+            return false;
+        }
 
-        return n1 - n2;
+        return compareTo( obj ) == 0;
     }
-    
-    /** Takes a string and increments it as an integer.  
+
+    /**
+     * Takes a string and increments it as an integer.
      * Preserves any lpad of "0" zeros.
-     * 
+     *
      * @param s
-     * @return
      */
     protected String incrementVersionString( String s )
     {
-        if ( StringUtils.isEmpty( s ) )
+        int n = Integer.valueOf( s ).intValue() + 1;
+        String value = String.valueOf( n );
+        if ( value.length() < s.length() )
         {
-            return null;
+            // String was left-padded with zeros
+            value = StringUtils.leftPad( value, s.length(), "0" );
         }
+        return value;
+    }
 
-        try
-        {
-            Integer n = new Integer( Integer.parseInt( s ) + 1 );
-            if ( n.toString().length() < s.length() )
-            {
-                // String was left-padded with zeros
-                return StringUtils.leftPad( n.toString(), s.length(), "0" );
-            }
-            return n.toString();
-        }
-        catch ( NumberFormatException e )
+    public String getSnapshotVersionString()
+    {
+        String baseVersion = getReleaseVersionString();
+
+        if ( baseVersion.length() > 0 )
         {
-            return null;
+            baseVersion += "-";
         }
+
+        return baseVersion + Artifact.SNAPSHOT_VERSION;
     }
-    
-    public String getSnapshotVersionString() 
-    {
-        return getVersionString(this, SNAPSHOT_IDENTIFIER, StringUtils.defaultString( this.buildSeparator, "-" ) );
-    }
-    
+
     public String getReleaseVersionString()
     {
-        return getVersionString( this, null, null );
+        String baseVersion = strVersion;
+
+        Matcher m = Artifact.VERSION_FILE_PATTERN.matcher( baseVersion );
+        if ( m.matches() )
+        {
+            baseVersion = m.group( 1 );
+        }
+        else if ( baseVersion.endsWith( "-" + Artifact.SNAPSHOT_VERSION ) )
+        {
+            baseVersion = baseVersion.substring( 0, baseVersion.length() - Artifact.SNAPSHOT_VERSION.length() - 1 );
+        }
+        else if ( baseVersion.equals( Artifact.SNAPSHOT_VERSION ) )
+        {
+            baseVersion = "";
+        }
+        return baseVersion;
     }
 
-    public String getVersionString()
+    public String toString()
     {
-        return getVersionString( this, this.buildSpecifier, this.buildSeparator );
+        return strVersion;
     }
 
     protected static String getVersionString( DefaultVersionInfo info, String buildSpecifier, String buildSeparator )
@@ -409,66 +364,35 @@
 
         return sb.toString();
     }
-    
-    /** Simply joins the items in the list with "." period
-     * 
+
+    /**
+     * Simply joins the items in the list with "." period
+     *
      * @param digits
-     * @return
      */
     protected static String joinDigitString( List digits )
     {
-        if ( digits == null )
-        {
-            return null;
-        }
-
         return StringUtils.join( digits.iterator(), DIGIT_SEPARATOR_STRING );
     }
 
-    /** Splits the string on "." and returns a list 
+    /**
+     * Splits the string on "." and returns a list
      * containing each digit.
-     * 
+     *
      * @param strDigits
-     * @return
      */
-    protected List parseDigits( String strDigits )
+    private List parseDigits( String strDigits )
     {
-        if ( StringUtils.isEmpty( strDigits ) )
-        {
-            return null;
-        }
-
-        String[] strings = StringUtils.split( strDigits, DIGIT_SEPARATOR_STRING );
-        return Arrays.asList( strings );
+        return Arrays.asList( StringUtils.split( strDigits, DIGIT_SEPARATOR_STRING ) );
     }
 
     //--------------------------------------------------
     // Getters & Setters
     //--------------------------------------------------
 
-    private String nullIfEmpty( String s )
+    private static String nullIfEmpty( String s )
     {
-        return ( StringUtils.isEmpty( s ) ) ? null : s;
-    }
-
-    public String getAnnotation()
-    {
-        return annotation;
-    }
-
-    protected void setAnnotation( String annotation )
-    {
-        this.annotation = nullIfEmpty( annotation );
-    }
-
-    public String getAnnotationRevision()
-    {
-        return annotationRevision;
-    }
-
-    protected void setAnnotationRevision( String annotationRevision )
-    {
-        this.annotationRevision = nullIfEmpty( annotationRevision );
+        return StringUtils.isEmpty( s ) ? null : s;
     }
 
     public String getComponent()
@@ -476,39 +400,24 @@
         return component;
     }
 
-    protected void setComponent( String component )
-    {
-        this.component = nullIfEmpty( component );
-    }
-
     public List getDigits()
     {
         return digits;
     }
 
-    protected void setDigits( List digits )
-    {
-        this.digits = digits;
-    }
-
-    public String getBuildSpecifier()
-    {
-        return buildSpecifier;
-    }
-
-    protected void setBuildSpecifier( String buildSpecifier )
+    public String getAnnotation()
     {
-        this.buildSpecifier = nullIfEmpty( buildSpecifier );
+        return annotation;
     }
 
-    public List getAnnotationOrder()
+    public String getAnnotationRevision()
     {
-        return annotationOrder;
+        return annotationRevision;
     }
 
-    protected void setAnnotationOrder( List annotationOrder )
+    public String getBuildSpecifier()
     {
-        this.annotationOrder = annotationOrder;
+        return buildSpecifier;
     }
 
 }

Modified: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/versions/VersionInfo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/versions/VersionInfo.java?rev=396098&r1=396097&r2=396098&view=diff
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/versions/VersionInfo.java (original)
+++ maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/versions/VersionInfo.java Sat Apr 22 01:57:19 2006
@@ -16,36 +16,38 @@
  * limitations under the License.
  */
 
+/**
+ * @todo this has an overlap with ArtifactVersion in maven-artifact - would be good to migrate this there.
+ */
 public interface VersionInfo
     extends Comparable
 {
-    /** Returns a string representing the version without modification.
-     * 
-     * @return
-     */
-    public String getVersionString();
 
-    /** Returns a string representing the version with a snapshot specification
-     * 
+    /**
+     * Returns a string representing the version with a snapshot specification
+     *
      * @return
      */
-    public String getSnapshotVersionString();
+    String getSnapshotVersionString();
 
-    /** Returns a string representing the version without a snapshot specification.
-     * 
+    /**
+     * Returns a string representing the version without a snapshot specification.
+     *
      * @return
      */
-    public String getReleaseVersionString();
+    String getReleaseVersionString();
 
-    /** Returns a {@link VersionInfo} object which represents the next version of this object.
-     * 
+    /**
+     * Returns a {@link VersionInfo} object which represents the next version of this object.
+     *
      * @return
      */
-    public VersionInfo getNextVersion();
+    VersionInfo getNextVersion();
 
-    /** Returns whether this represents a snapshot version. ("xxx-SNAPSHOT");
-     * 
+    /**
+     * Returns whether this represents a snapshot version. ("xxx-SNAPSHOT");
+     *
      * @return
      */
-    public boolean isSnapshot();
+    boolean isSnapshot();
 }

Modified: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/versions/VersionParseException.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/versions/VersionParseException.java?rev=396098&r1=396097&r2=396098&view=diff
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/versions/VersionParseException.java (original)
+++ maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/versions/VersionParseException.java Sat Apr 22 01:57:19 2006
@@ -19,23 +19,8 @@
 public class VersionParseException
     extends Exception
 {
-    public VersionParseException()
-    {
-        super();
-    }
-
     public VersionParseException( String message )
     {
         super( message );
-    }
-
-    public VersionParseException( String message, Throwable cause )
-    {
-        super( message, cause );
-    }
-
-    public VersionParseException( Throwable cause )
-    {
-        super( cause );
     }
 }

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=396098&r1=396097&r2=396098&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 Sat Apr 22 01:57:19 2006
@@ -21,10 +21,10 @@
 public class DefaultVersionInfoTest
     extends PlexusTestCase
 {
-    public void testParse() 
+    public void testParse()
         throws Exception
     {
-        testParse( "1.0", null, "1.0", null, null, null );
+        checkParsing( "1.0", null, "1.0", null, null, null );
     }
 
     public void testParseWithBadVersion()
@@ -32,213 +32,250 @@
     {
         try
         {
-            testParse( "SNAPSHOT", null, null, null, null, "SNAPSHOT" );
+            checkParsing( "foo", null, null, null, null, "foo" );
             fail( "version is incorrect, must fail." );
         }
-        catch( VersionParseException e )
+        catch ( VersionParseException e )
         {
         }
     }
-        
-    public void testParseMultiDigit() 
+
+    public void testParseMultiDigit()
         throws Exception
-    {        
-        testParse( "99.99", null, "99.99", null, null, null );
-        testParse( "990.990.990", null, "990.990.990", null, null, null );
+    {
+        checkParsing( "99.99", null, "99.99", null, null, null );
+        checkParsing( "990.990.990", null, "990.990.990", null, null, null );
     }
-    
-    public void testParseComponent() 
+
+    public void testParseComponent()
         throws Exception
-    {        
-        testParse( "my-component-99.99",     "my-component", "99.99",    null, null, null );
-        testParse( "my-component_99.99",     "my-component", "99.99",    null, null, null );
-        testParse( "my-component1.2.3",      "my-component", "1.2.3",    null, null, null );
-        testParse( "my-component11.22.33",   "my-component", "11.22.33", null, null, null );
+    {
+        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 );
     }
-    
-    public void testParseSnapshotVersion() 
+
+    public void testParseSnapshotVersion()
         throws Exception
     {
-        testParse( "1.0-beta-4-SNAPSHOT", null, "1.0", "beta", "4", "SNAPSHOT" );        
-        testParse( "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", null, "1.0", "beta", "4", "SNAPSHOT" );
     }
-    
-    public void testParseAnnotationVersion() 
+
+    public void testParseAnnotationVersion()
         throws Exception
     {
-        testParse( "1.0-beta-4-SNAPSHOT",   null, "1.0",    "beta", "4",    "SNAPSHOT" );
-        testParse( "1.0-beta-4",            null, "1.0",    "beta", "4",    null );
-        testParse( "1.2.3-beta-99",         null, "1.2.3",  "beta", "99",   null );
-        testParse( "1.2.3-beta99",          null, "1.2.3",  "beta", "99",   null );
-        testParse( "1.2.3-beta99-SNAPSHOT", null, "1.2.3",  "beta", "99",   "SNAPSHOT" );
-        testParse( "1.2.3-RC4",             null, "1.2.3",  "RC",   "4",    null );
+        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 );
     }
-    
-    public void testParseSeparators() 
+
+    public void testParseSeparators()
         throws Exception
     {
-        testParse("log4j-1.2.9-beta-9-SNAPSHOT", "log4j", "1.2.9", "beta", "9", "SNAPSHOT");
-        testParse("log4j1.2.9beta9SNAPSHOT", "log4j", "1.2.9", "beta", "9", "SNAPSHOT");
-        testParse("log4j1.2.9beta-9SNAPSHOT", "log4j", "1.2.9", "beta", "9", "SNAPSHOT");
-        testParse("log4j_1.2.9_beta_9_SNAPSHOT", "log4j", "1.2.9", "beta", "9", "SNAPSHOT");
+        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" );
     }
-    
-    public void testParseAnnotationNoVersionButSnapshot() 
+
+    public void testParseAnnotationNoVersionButSnapshot()
         throws Exception
     {
-        testParse( "1.0-beta-SNAPSHOT",   null, "1.0",   "beta", null,   "SNAPSHOT" );        
-        testParse( "1.2.3-beta99",        null, "1.2.3", "beta", "99",   null );
-        testParse( "1.2.3-RC4-SNAPSHOT",  null, "1.2.3", "RC",   "4",    "SNAPSHOT" );
+        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" );
     }
-    
-    public void testParseAnnotationVersionWithRevision() 
+
+    public void testParseAnnotationVersionWithRevision()
         throws Exception
     {
-        testParse( "1.0-beta-4-SNAPSHOT",   null, "1.0",   "beta", "4",  "SNAPSHOT" );
-        testParse( "1.0-beta-4",            null, "1.0",   "beta", "4",  null );
-        testParse( "1.2.3-beta-99",         null, "1.2.3", "beta", "99", null );
-        testParse( "1.2.3-beta99",          null, "1.2.3", "beta", "99", null );
-        testParse( "1.2.3-RC4",             null, "1.2.3", "RC",   "4",  null );
+        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 );
+    }
+
+    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" );
+    }
 
-        testParse( "mycomponent-1.2.3-RC4", "mycomponent", "1.2.3", "RC", "4",  null );
-        testParse( "mycomponent-1.2.3-RC4", "mycomponent", "1.2.3", "RC", "4",  null );
-        testParse( "log4j-1.2.9",           "log4j",       "1.2.9", null, null, null );
+    public void testParseAnnotationRevisionOnly()
+        throws Exception
+    {
+        checkParsing( "1.0-4", null, "1.0", null, "4", null );
     }
-    
-    public void testParseLeadingZeros() 
+
+    public void testParseLeadingZeros()
         throws Exception
     {
-        testParse( "1.01-beta-04-SNAPSHOT",   null, "1.01",   "beta", "04",  "SNAPSHOT" );        
-        testParse( "01.01.001-beta-04-SNAPSHOT",   null, "01.01.001",   "beta", "04",  "SNAPSHOT" );
+        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" );
     }
-    
-    public void testParseBuildNumber() 
+
+    public void testParseBuildNumber()
         throws Exception
-    {        
-        testParse( "plexus-logging-provider-test-1.0-alpha-2-20051013.095555-2", 
-                   "plexus-logging-provider-test", "1.0", "alpha", "2", "20051013.095555-2" );
+    {
+        checkParsing( "plexus-logging-provider-test-1.0-alpha-2-20051013.095555-2", "plexus-logging-provider-test",
+                      "1.0", "alpha", "2", "20051013.095555-2" );
     }
-    
-    public void testNextVersion() 
+
+    public void testNextVersion()
         throws Exception
     {
-        testNextVersion( "1.01",  "1.02" );
-        testNextVersion( "1.9",   "1.10" );
-        testNextVersion( "1.09",  "1.10" );
-        testNextVersion( "1.009", "1.010" );
-        
-        testNextVersion( "1.99", "1.100" );
+        checkNextVersion( "1.01", "1.02" );
+        checkNextVersion( "1.9", "1.10" );
+        checkNextVersion( "1.09", "1.10" );
+        checkNextVersion( "1.009", "1.010" );
+
+        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() 
+
+    public void testNextAnnotationRevision()
         throws Exception
     {
-        testNextVersion( "1.01-beta-04", "1.01-beta-05" );
-        testNextVersion( "1.01-beta-04-SNAPSHOT", "1.01-beta-05-SNAPSHOT" );
-        testNextVersion( "9.99.999-beta-9-SNAPSHOT", "9.99.999-beta-10-SNAPSHOT" );
-        testNextVersion( "9.99.999-beta-09-SNAPSHOT", "9.99.999-beta-10-SNAPSHOT" );
-        testNextVersion( "9.99.999-beta-009-SNAPSHOT", "9.99.999-beta-010-SNAPSHOT" );
-        testNextVersion( "9.99.999-beta9-SNAPSHOT", "9.99.999-beta10-SNAPSHOT" );        
+        checkNextVersion( "1.01-beta-04", "1.01-beta-05" );
+        checkNextVersion( "1.01-beta-04-SNAPSHOT", "1.01-beta-05-SNAPSHOT" );
+        checkNextVersion( "9.99.999-beta-9-SNAPSHOT", "9.99.999-beta-10-SNAPSHOT" );
+        checkNextVersion( "9.99.999-beta-09-SNAPSHOT", "9.99.999-beta-10-SNAPSHOT" );
+        checkNextVersion( "9.99.999-beta-009-SNAPSHOT", "9.99.999-beta-010-SNAPSHOT" );
+        checkNextVersion( "9.99.999-beta9-SNAPSHOT", "9.99.999-beta10-SNAPSHOT" );
     }
-    
-    public void testCompareToDigitsOnly() 
+
+    public void testCompareToDigitsOnly()
         throws Exception
     {
-        testVersionLessThanVersion( "1.01", "1.02" );
-        testVersionLessThanVersion( "1.01", "1.00009" );
-        testVersionLessThanVersion( "1.01.99", "1.0002" );
-        testVersionLessThanVersion( "1.01", "1.01.01" );
-        
-        testVersionEqualVersion( "1.01", "1.1" );
-        testVersionEqualVersion( "1.01", "1.01" );
-        testVersionEqualVersion( "1.01", "1.001" );
-        
+        checkVersionLessThanVersion( "1.01", "1.02" );
+        checkVersionLessThanVersion( "1.00009", "1.01" );
+        checkVersionLessThanVersion( "1.01", "1.01.01" );
+
+        checkVersionLessThanVersion( "1.01", "1.1" );
+        checkVersionEqualVersion( "1.01", "1.01" );
+        checkVersionLessThanVersion( "1.001", "1.01" );
     }
-    
-    public void testCompareToAnnotation() 
+
+    public void testCompareToAnnotation()
         throws Exception
     {
-        testVersionLessThanVersion( "1.01-alpha",   "1.01" );
-        testVersionLessThanVersion( "1.01-alpha",   "1.01-beta" );
-        testVersionLessThanVersion( "1.01-beta",    "1.01-RC1");
-        testVersionLessThanVersion( "1.01-beta",    "1.01-RC" );
-        testVersionLessThanVersion( "1.01-alpha-4", "1.01.1-beta-1" );
-        testVersionLessThanVersion( "1.01-alpha-4-SNAPSHOT", "1.01-beta");
-        
-        testVersionEqualVersion( "1.01-alpha-4-SNAPSHOT", "1.01-alpha-004-SNAPSHOT");        
+        checkVersionLessThanVersion( "1.01-alpha", "1.01" );
+        checkVersionLessThanVersion( "1.01-alpha", "1.01-beta" );
+        checkVersionLessThanVersion( "1.01-beta", "1.01-RC1" );
+        checkVersionLessThanVersion( "1.01-beta", "1.01-RC" );
+        checkVersionLessThanVersion( "1.01-alpha-4", "1.01.1-beta-1" );
+        checkVersionLessThanVersion( "1.01-alpha-4-SNAPSHOT", "1.01-beta" );
+        checkVersionLessThanVersion( "1.01-alpha-4-SNAPSHOT", "1.01-alpha-4" );
+        checkVersionLessThanVersion( "1.01-alpha-4", "1.01-alpha-5-SNAPSHOT" );
+
+        checkVersionLessThanVersion( "1.01-alpha-004-SNAPSHOT", "1.01-alpha-4-SNAPSHOT" );
     }
-    
-    public void testCompareToAnnotationRevision() 
+
+    public void testCompareToAnnotationRevision()
         throws Exception
     {
-        testVersionLessThanVersion( "1.01-beta-04-SNAPSHOT",    "1.01-beta-05-SNAPSHOT" );
-        testVersionLessThanVersion( "1.01-beta-0004-SNAPSHOT",  "1.01-beta-5-SNAPSHOT" );
-        testVersionLessThanVersion( "1.01-beta-4-SNAPSHOT",     "1.01.1-beta-4-SNAPSHOT" );
-        
-        testVersionEqualVersion( "1.01-beta-4-SNAPSHOT", "1.01-beta-0004-SNAPSHOT");
-        testVersionEqualVersion( "1.01-beta4",           "1.01-beta-0004");        
-        
-        testVersionLessThanVersion( "1.01-beta9", "1.01-RC1");
-        testVersionLessThanVersion( "1.01-beta9", "1.01-RC-1");
+        checkVersionLessThanVersion( "1.01-beta-04-SNAPSHOT", "1.01-beta-05-SNAPSHOT" );
+        checkVersionLessThanVersion( "1.01-beta-0004-SNAPSHOT", "1.01-beta-5-SNAPSHOT" );
+        checkVersionLessThanVersion( "1.01-beta-4-SNAPSHOT", "1.01.1-beta-4-SNAPSHOT" );
+
+        checkVersionLessThanVersion( "1.01-beta-0004-SNAPSHOT", "1.01-beta-4-SNAPSHOT" );
     }
-    
-    public void testCompareToBuildSpecifier() 
+
+    public void testCompareToBuildSpecifier()
         throws Exception
     {
-        testVersionLessThanVersion( "1.01-SNAPSHOT",         "1.01" );        
-        testVersionLessThanVersion( "1.01-beta-04-SNAPSHOT", "1.01-beta-04" );
-        
-        testVersionEqualVersion( "1.01-beta-04-SNAPSHOT", "1.01-beta-04-SNAPSHOT" );
-        
-        testVersionLessThanVersion( "1.01-beta-04-20051112.134500-2", "1.01-beta-04-SNAPSHOT");
-        testVersionLessThanVersion( "1.01-beta-04-20051112.134500-1", "1.01-beta-04-20051112.134500-2" );
-        testVersionLessThanVersion( "1.01-beta-04-20051112.134500-1", "1.01-beta-04-20051113.134500-1" );
+        checkVersionLessThanVersion( "1.01-SNAPSHOT", "1.01" );
+        checkVersionLessThanVersion( "1.01-beta-04-SNAPSHOT", "1.01-beta-04" );
+
+        checkVersionEqualVersion( "1.01-beta-04-SNAPSHOT", "1.01-beta-04-SNAPSHOT" );
+
+        checkVersionLessThanVersion( "1.01-beta-04-20051112.134500-2", "1.01-beta-04-SNAPSHOT" );
+        checkVersionLessThanVersion( "1.01-beta-04-20051112.134500-1", "1.01-beta-04-20051112.134500-2" );
+        checkVersionLessThanVersion( "1.01-beta-04-20051112.134500-1", "1.01-beta-04-20051113.134500-1" );
     }
-    
+
     public void testGetReleaseVersion()
         throws Exception
     {
-        testGetReleaseVersion( "1.01",          "1.01" );
-        testGetReleaseVersion( "1.01-beta",     "1.01-beta" );
-        testGetReleaseVersion( "1.01-beta-04",  "1.01-beta-04" );
-        
-        testGetReleaseVersion( "1.01-beta-04-SNAPSHOT",          "1.01-beta-04" );
-        testGetReleaseVersion( "1.01-beta-04-20051112.134500-1", "1.01-beta-04" );        
+        checkGetReleaseVersion( "1.01", "1.01" );
+        checkGetReleaseVersion( "1.01-beta", "1.01-beta" );
+        checkGetReleaseVersion( "1.01-beta-04", "1.01-beta-04" );
+
+        checkGetReleaseVersion( "1.01-beta-04-SNAPSHOT", "1.01-beta-04" );
+        checkGetReleaseVersion( "1.01-beta-04-20051112.134500-1", "1.01-beta-04" );
     }
-    
+
     public void testGetSnapshotVersion()
         throws Exception
     {
-        testGetSnapshotVersion( "1.01",          "1.01-SNAPSHOT" );
-        testGetSnapshotVersion( "1.01-beta",     "1.01-beta-SNAPSHOT" );
-        testGetSnapshotVersion( "1.01-beta-04",  "1.01-beta-04-SNAPSHOT" );
-        
-        testGetSnapshotVersion( "1.01-beta-04-SNAPSHOT",          "1.01-beta-04-SNAPSHOT" );
-        testGetSnapshotVersion( "1.01-beta-04-20051112.134500-1", "1.01-beta-04-SNAPSHOT" );        
-        testGetSnapshotVersion( "1.01-beta-04_20051112.134500-1", "1.01-beta-04_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" );
+
+        checkGetSnapshotVersion( "SNAPSHOT", "SNAPSHOT" );
+        // TODO: bug in Artifact pattern
+//        checkGetSnapshotVersion( "20051112.134500-1", "SNAPSHOT" );
+        checkGetSnapshotVersion( "1.01-beta-04-SNAPSHOT", "1.01-beta-04-SNAPSHOT" );
+        checkGetSnapshotVersion( "1.01-beta-04-20051112.134500-1", "1.01-beta-04-SNAPSHOT" );
+        checkGetSnapshotVersion( "1.01-beta-04_20051112.134500-1", "1.01-beta-04_20051112.134500-1-SNAPSHOT" );
+    }
+
+    public void testSnapshot()
+        throws VersionParseException
+    {
+        assertFalse( new DefaultVersionInfo( "1.01" ).isSnapshot() );
+        assertFalse( new DefaultVersionInfo( "1.01-beta" ).isSnapshot() );
+        assertFalse( new DefaultVersionInfo( "1.01-beta-04" ).isSnapshot() );
+
+        assertTrue( new DefaultVersionInfo( "1.01-beta-04-SNAPSHOT" ).isSnapshot() );
+        assertTrue( new DefaultVersionInfo( "1.01-beta-04-20051112.134500-1" ).isSnapshot() );
+        assertFalse( new DefaultVersionInfo( "1.01-beta-04_20051112.134500-1" ).isSnapshot() );
     }
-    
-    private void testGetReleaseVersion(String strVersion, String expected)
+
+    private static void checkGetReleaseVersion( String strVersion, String expected )
         throws Exception
     {
-        DefaultVersionInfo v = new DefaultVersionInfo( strVersion );
-        assertEquals(expected, v.getReleaseVersionString());
+        VersionInfo v = new DefaultVersionInfo( strVersion );
+        assertEquals( expected, v.getReleaseVersionString() );
     }
-    
-    private void testGetSnapshotVersion(String strVersion, String expected)
+
+    private static void checkGetSnapshotVersion( String strVersion, String expected )
         throws Exception
     {
-        DefaultVersionInfo v = new DefaultVersionInfo( strVersion );
-        assertEquals(expected, v.getSnapshotVersionString());
+        VersionInfo v = new DefaultVersionInfo( strVersion );
+        assertEquals( expected, v.getSnapshotVersionString() );
     }
-    
-    private void testParse( String strVersion, String component, String digits, String annotation,
-                           String annotationRevision, String buildSpecifier )
+
+    private static void checkParsing( String strVersion, String component, String digits, String annotation,
+                                      String annotationRevision, String buildSpecifier )
         throws Exception
     {
         DefaultVersionInfo v = new DefaultVersionInfo( strVersion );
 
-        assertEquals( strVersion, v.getVersionString() );
+        assertEquals( strVersion, v.toString() );
         assertEquals( component, v.getComponent() );
         assertEquals( digits, DefaultVersionInfo.joinDigitString( v.getDigits() ) );
         assertEquals( annotation, v.getAnnotation() );
@@ -246,43 +283,47 @@
         assertEquals( buildSpecifier, v.getBuildSpecifier() );
     }
 
-    private void testNextVersion( String strVersion, String nextVersion )
+    private static void checkNextVersion( String strVersion, String nextVersion )
         throws Exception
     {
-        DefaultVersionInfo v = new DefaultVersionInfo( strVersion );
+        VersionInfo v = new DefaultVersionInfo( strVersion );
         VersionInfo nextV = v.getNextVersion();
 
         assertNotNull( nextV );
-        assertEquals( nextVersion, nextV.getVersionString() );
+        assertEquals( nextVersion, nextV.toString() );
     }
 
-    private void testVersionLessThanVersion( String lesserVersion, String greaterVersion )
-        throws Exception
+    private static void checkVersionLessThanVersion( String lesserVersion, String greaterVersion )
+        throws VersionParseException
     {
-        testCompareTo( lesserVersion, greaterVersion, false );
-
+        checkCompareTo( lesserVersion, greaterVersion, -1 );
+        checkCompareTo( greaterVersion, lesserVersion, +1 );
     }
-    
-    private void testVersionEqualVersion( String version1, String version2 )
+
+    private static void checkVersionEqualVersion( String version1, String version2 )
         throws Exception
     {
-        testCompareTo( version1, version2, true );
-        
+        checkCompareTo( version1, version2, 0 );
     }
 
-    private void testCompareTo( String lesserVersion, String greaterVersion, boolean equal )
-        throws Exception
+    private static void checkCompareTo( String lesserVersion, String greaterVersion, int comparison )
+        throws VersionParseException
     {
-        DefaultVersionInfo lesserV = new DefaultVersionInfo( lesserVersion );
-        DefaultVersionInfo greaterV = new DefaultVersionInfo( greaterVersion );
+        VersionInfo lesserV = new DefaultVersionInfo( lesserVersion );
+        VersionInfo greaterV = new DefaultVersionInfo( greaterVersion );
 
-        if ( equal )
+        if ( comparison == 0 )
         {
-            assertEquals( lesserV.compareTo( greaterV ), 0 );
+            assertEquals( 0, lesserV.compareTo( greaterV ) );
+            assertEquals( lesserV, greaterV );
         }
-        else
+        else if ( comparison < 0 )
         {
             assertTrue( lesserV.compareTo( greaterV ) < 0 );
+        }
+        else if ( comparison > 0 )
+        {
+            assertTrue( lesserV.compareTo( greaterV ) > 0 );
         }
     }
 }