I'm still having trouble with this. I wrote a sample class to show my
problem. The issue is that all the contains calls are correct except
that a singular version ie "2.0.5" always returns true. Is this an
artifact bug, or am I doing something wrong? According to the javadoc
for the method (shown in my original post below) the singular version is
allowed as a version range.

Output:
is 2.0.5 contained in 2.0.5 ->true      CORRECT
is 2.0.5 contained in 2.0.6 ->true      WRONG
is 2.0.5 contained in [2.0,2.1] ->true CORRECT
is 2.0.5 contained in [2.0,2.0.3] ->false CORRECT
is 2.0.5 contained in [2.0,2.0.5] ->true CORRECT
is 2.0.5 contained in [2.0,2.0.5) ->false CORRECT
Source:
/**
 * 
 */
package org.apache.maven.plugin.enforcer;

import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import
org.apache.maven.artifact.versioning.InvalidVersionSpecificationExceptio
n;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

/**
 * @author brianf
 * 
 */
public class test
{
    public static void main( String[] args )
        throws MojoExecutionException, MojoFailureException,
InvalidVersionSpecificationException
    {
        ArtifactVersion actualVersion = new DefaultArtifactVersion(
"2.0.5" );
        enforceVersion( "2.0.5", actualVersion );
        enforceVersion( "2.0.6", actualVersion );
        enforceVersion( "[2.0,2.1]", actualVersion );
        enforceVersion( "[2.0,2.0.3]", actualVersion );
        enforceVersion( "[2.0,2.0.5]", actualVersion );
        enforceVersion( "[2.0,2.0.5)", actualVersion );
    }

    public static void enforceVersion( String requiredVersionRange,
ArtifactVersion actualVersion )
        throws MojoExecutionException, MojoFailureException,
InvalidVersionSpecificationException
    {
        VersionRange vr = null;

        vr = VersionRange.createFromVersionSpec( requiredVersionRange );

        boolean result = vr.containsVersion( actualVersion );
        System.out.println( "is "+actualVersion+" contained in
"+requiredVersionRange+" ->" + result );
    }
}

-----Original Message-----
From: Brian E. Fox [mailto:[EMAIL PROTECTED] 
Sent: Sunday, February 18, 2007 8:15 PM
To: Maven Developers List
Subject: version range question

According to the javadoc for VersionRange.createFromVersionSpec, a
singular version (ie "2.0.4") is allowed:

 

/**

     * Create a version range from a string representation

     * 

     * Some spec examples are

     * <ul>

     *   <li><code>1.0</code> Version 1.0</li>

     *   <li><code>[1.0,2.0)</code> Versions 1.0 (included) to 2.0 (not
included)</li>

     *   <li><code>[1.0,2.0]</code> Versions 1.0 to 2.0 (both
included)</li>

     *   <li><code>[1.5,)</code> Versions 1.5 and higher</li>

     *   <li><code>(,1.0],[1.2,)</code> Versions up to 1.0 (included)
and 1.2 or higher</li>

     * </ul>

     * 

     * @param spec string representation of a version or version range

     * @return a new [EMAIL PROTECTED] VersionRange} object that represents the
spec

     * @throws InvalidVersionSpecificationException

     */

 

However, if I create a version range using
createFromVersionSpec("2.0.4") and then call, vr.containsVersion(2.0.5)
the result is true. However, if I use createFromVersion("2.0.4") and
then use vr.containsVersion("2.0.5"), I get the expected false. 

 

So is this a bug in the Spec method? What is the difference between the
two supposed to be? It seems like the fromVersion method can handle the
spec strings also so I'm confused why there are two.

 

Thanks,

Brian

 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to