You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2009/02/13 22:23:46 UTC
svn commit: r744245 [2/2] - in /maven/mercury/trunk/mercury-artifact/src:
main/java/org/apache/maven/mercury/artifact/
main/java/org/apache/maven/mercury/artifact/api/
main/java/org/apache/maven/mercury/artifact/version/
test/java/org/apache/maven/merc...
Modified: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/QualityRange.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/QualityRange.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/QualityRange.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/QualityRange.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,59 +19,70 @@
package org.apache.maven.mercury.artifact;
/**
- *
- *
* @author Oleg Gusakov
* @version $Id$
- *
*/
public class QualityRange
{
- public static final QualityRange SNAPSHOTS_ONLY = new QualityRange( Quality.SNAPSHOT_QUALITY, true, Quality.SNAPSHOT_TS_QUALITY, true );
- public static final QualityRange ALPHA_ONLY = new QualityRange( Quality.SNAPSHOT_QUALITY, false, Quality.BETA_QUALITY, false );
- public static final QualityRange BETA_ONLY = new QualityRange( Quality.ALPHA_QUALITY, false, Quality.RELEASE_QUALITY, false );
- public static final QualityRange RELEASES_ONLY = new QualityRange( Quality.RELEASE_QUALITY, true, Quality.RELEASE_QUALITY, true );
- public static final QualityRange ALL = new QualityRange( Quality.SNAPSHOT_QUALITY, true, Quality.RELEASE_QUALITY, true );
-
- protected Quality qualityFrom = Quality.SNAPSHOT_QUALITY;
- protected boolean fromInclusive = true;
- protected Quality qualityTo = Quality.RELEASE_QUALITY;
- protected boolean toInclusive = true;
-
- /**
- * @param qualityFrom
- * @param fromInclusive
- * @param qualityTo
- * @param toInclusive
- */
- public QualityRange(
- Quality qualityFrom,
- boolean fromInclusive,
- Quality qualityTo,
- boolean toInclusive )
- {
- this.qualityFrom = qualityFrom;
- this.fromInclusive = fromInclusive;
-
- this.qualityTo = qualityTo;
- this.toInclusive = toInclusive;
- }
-
- //---------------------------------------------------------------------------
- public boolean isAcceptedQuality( Quality quality )
- {
- if( quality == null )
- return false;
-
- int from = quality.compareTo( qualityFrom );
- if( from == 0 )
- return fromInclusive;
-
- int to = quality.compareTo( qualityTo );
- if( to == 0 )
- return toInclusive;
-
- return from > 0 && to < 0;
- }
+ public static final QualityRange SNAPSHOTS_ONLY =
+ new QualityRange( Quality.SNAPSHOT_QUALITY, true, Quality.SNAPSHOT_TS_QUALITY, true );
+
+ public static final QualityRange ALPHA_ONLY =
+ new QualityRange( Quality.SNAPSHOT_QUALITY, false, Quality.BETA_QUALITY, false );
+
+ public static final QualityRange BETA_ONLY =
+ new QualityRange( Quality.ALPHA_QUALITY, false, Quality.RELEASE_QUALITY, false );
+
+ public static final QualityRange RELEASES_ONLY =
+ new QualityRange( Quality.RELEASE_QUALITY, true, Quality.RELEASE_QUALITY, true );
+
+ public static final QualityRange ALL =
+ new QualityRange( Quality.SNAPSHOT_QUALITY, true, Quality.RELEASE_QUALITY, true );
+
+ protected Quality qualityFrom = Quality.SNAPSHOT_QUALITY;
+
+ protected boolean fromInclusive = true;
+
+ protected Quality qualityTo = Quality.RELEASE_QUALITY;
+
+ protected boolean toInclusive = true;
+
+ /**
+ * @param qualityFrom
+ * @param fromInclusive
+ * @param qualityTo
+ * @param toInclusive
+ */
+ public QualityRange( Quality qualityFrom, boolean fromInclusive, Quality qualityTo, boolean toInclusive )
+ {
+ this.qualityFrom = qualityFrom;
+ this.fromInclusive = fromInclusive;
+
+ this.qualityTo = qualityTo;
+ this.toInclusive = toInclusive;
+ }
+
+ // ---------------------------------------------------------------------------
+ public boolean isAcceptedQuality( Quality quality )
+ {
+ if ( quality == null )
+ {
+ return false;
+ }
+
+ int from = quality.compareTo( qualityFrom );
+ if ( from == 0 )
+ {
+ return fromInclusive;
+ }
+
+ int to = quality.compareTo( qualityTo );
+ if ( to == 0 )
+ {
+ return toInclusive;
+ }
+
+ return from > 0 && to < 0;
+ }
}
Modified: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/api/ArtifactListProcessor.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/api/ArtifactListProcessor.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/api/ArtifactListProcessor.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/api/ArtifactListProcessor.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -28,28 +28,32 @@
*
* @author Oleg Gusakov
* @version $Id$
- *
*/
public interface ArtifactListProcessor
{
- /** named functions - used to help processing in various parts of the system */
- public static final String [] FUNCTIONS = new String []
- {
- "tp" // transaction processing function, future use
- };
- public static final String FUNCTION_TP = FUNCTIONS[0];
-
- /** initialize it if required
- * @throws ArtifactListProcessorException */
- public void init( Map<String, String> env )
- throws ArtifactListProcessorException;
-
- /** configure it if required */
- public void configure( Object config )
- throws ArtifactListProcessorException;
-
- /** actually do that
- * @throws ArtifactListProcessorException */
- public List<ArtifactBasicMetadata> process( List<ArtifactBasicMetadata> artifacts )
- throws ArtifactListProcessorException;
+ /** named functions - used to help processing in various parts of the system */
+ public static final String[] FUNCTIONS = new String[] { "tp" // transaction processing function, future use
+ };
+
+ public static final String FUNCTION_TP = FUNCTIONS[0];
+
+ /**
+ * initialize it if required
+ *
+ * @throws ArtifactListProcessorException
+ */
+ public void init( Map<String, String> env )
+ throws ArtifactListProcessorException;
+
+ /** configure it if required */
+ public void configure( Object config )
+ throws ArtifactListProcessorException;
+
+ /**
+ * actually do that
+ *
+ * @throws ArtifactListProcessorException
+ */
+ public List<ArtifactBasicMetadata> process( List<ArtifactBasicMetadata> artifacts )
+ throws ArtifactListProcessorException;
}
Modified: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/api/ArtifactListProcessorException.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/api/ArtifactListProcessorException.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/api/ArtifactListProcessorException.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/api/ArtifactListProcessorException.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,54 +19,47 @@
package org.apache.maven.mercury.artifact.api;
/**
- *
- *
* @author Oleg Gusakov
* @version $Id$
- *
*/
public class ArtifactListProcessorException
-extends Exception
+ extends Exception
{
- /**
- *
- */
- public ArtifactListProcessorException()
- {
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param message
- */
- public ArtifactListProcessorException(
- String message )
- {
- super( message );
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param cause
- */
- public ArtifactListProcessorException(
- Throwable cause )
- {
- super( cause );
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param message
- * @param cause
+ /**
+ *
*/
- public ArtifactListProcessorException(
- String message,
- Throwable cause )
- {
- super( message, cause );
- // TODO Auto-generated constructor stub
- }
+ public ArtifactListProcessorException()
+ {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param message
+ */
+ public ArtifactListProcessorException( String message )
+ {
+ super( message );
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param cause
+ */
+ public ArtifactListProcessorException( Throwable cause )
+ {
+ super( cause );
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public ArtifactListProcessorException( String message, Throwable cause )
+ {
+ super( message, cause );
+ // TODO Auto-generated constructor stub
+ }
}
Modified: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/api/Configurable.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/api/Configurable.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/api/Configurable.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/api/Configurable.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,20 +19,19 @@
package org.apache.maven.mercury.artifact.api;
/**
- * provides a way to configure an object instance, if that object supports the idea
+ * provides a way to configure an object instance, if that object supports the idea
*
* @author Oleg Gusakov
* @version $Id$
- *
*/
public interface Configurable
{
- /**
- * configure this instance
- *
- * @param name of the configurable property
- * @param val configuration value
- */
- public void setOption( String name, String val );
+ /**
+ * configure this instance
+ *
+ * @param name of the configurable property
+ * @param val configuration value
+ */
+ public void setOption( String name, String val );
}
Modified: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/AttributeQuery.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/AttributeQuery.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/AttributeQuery.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/AttributeQuery.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,36 +19,40 @@
package org.apache.maven.mercury.artifact.version;
/**
- *
- *
* @author Oleg Gusakov
* @version $Id$
- *
*/
public class AttributeQuery
{
- public static final char EXRP_START = '{';
- public static final char EXRP_STOP = '}';
-
- private String expr;
-
- public AttributeQuery( String query )
- {
- if( query == null || query.indexOf( EXRP_START ) == -1 )
- return;
- int from = query.indexOf( EXRP_START );
- int to = query.indexOf( EXRP_STOP );
- }
-
- public static String stripExpression( String query )
- {
- if( query == null || query.indexOf( EXRP_START ) == -1 )
- return query;
-
- int from = query.indexOf( EXRP_START );
- if( from == 0 )
- return null;
+ public static final char EXRP_START = '{';
+
+ public static final char EXRP_STOP = '}';
+
+ private String expr;
+
+ public AttributeQuery( String query )
+ {
+ if ( query == null || query.indexOf( EXRP_START ) == -1 )
+ {
+ return;
+ }
+ int from = query.indexOf( EXRP_START );
+ int to = query.indexOf( EXRP_STOP );
+ }
+
+ public static String stripExpression( String query )
+ {
+ if ( query == null || query.indexOf( EXRP_START ) == -1 )
+ {
+ return query;
+ }
+
+ int from = query.indexOf( EXRP_START );
+ if ( from == 0 )
+ {
+ return null;
+ }
- return query.substring( 0, from );
- }
+ return query.substring( 0, from );
+ }
}
Modified: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/AttributeQueryException.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/AttributeQueryException.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/AttributeQueryException.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/AttributeQueryException.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,54 +19,47 @@
package org.apache.maven.mercury.artifact.version;
/**
- *
- *
* @author Oleg Gusakov
* @version $Id$
- *
*/
public class AttributeQueryException
extends Exception
{
- /**
- *
- */
- public AttributeQueryException()
- {
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param message
- */
- public AttributeQueryException(
- String message )
- {
- super( message );
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param cause
- */
- public AttributeQueryException(
- Throwable cause )
- {
- super( cause );
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param message
- * @param cause
+ /**
+ *
*/
- public AttributeQueryException(
- String message,
- Throwable cause )
- {
- super( message, cause );
- // TODO Auto-generated constructor stub
- }
+ public AttributeQueryException()
+ {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param message
+ */
+ public AttributeQueryException( String message )
+ {
+ super( message );
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param cause
+ */
+ public AttributeQueryException( Throwable cause )
+ {
+ super( cause );
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public AttributeQueryException( String message, Throwable cause )
+ {
+ super( message, cause );
+ // TODO Auto-generated constructor stub
+ }
}
Modified: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/ComparableVersion.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/ComparableVersion.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/ComparableVersion.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/ComparableVersion.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
@@ -27,11 +27,9 @@
/*
* Generic implementation of version comparison.
- *
+ *
* @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
- *
* @author <a href="mailto:hboutemy@apache.org">Herve Boutemy</a>
- *
* @version $Id$
*/
public class ComparableVersion
Modified: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/DefaultArtifactVersion.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/DefaultArtifactVersion.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/DefaultArtifactVersion.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/DefaultArtifactVersion.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
@@ -20,275 +20,278 @@
import org.apache.maven.mercury.artifact.Artifact;
import org.apache.maven.mercury.artifact.Quality;
-
/*
* Default implementation of artifact versioning.
- *
+ *
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
- *
+ *
* @version $Id$
*/
public class DefaultArtifactVersion
implements ArtifactVersion
{
- private String version;
-
- private Integer majorVersion;
-
- private Integer minorVersion;
-
- private Integer incrementalVersion;
-
- private Integer buildNumber;
-
- private String base;
-
- private String qualifier;
-
- private ComparableVersion comparable;
-
- private Quality quality = Quality.UNKNOWN_QUALITY;
-
- public DefaultArtifactVersion( String version )
- {
- this.version = version;
- parseVersion( version );
- parseQuality( version );
- }
-
- public String getBase()
- {
- return base;
- }
-
- public boolean sameBase( DefaultArtifactVersion v )
- {
- return base.equals( v.base );
- }
-
- public boolean sameBase( String vs )
- {
- DefaultArtifactVersion v = new DefaultArtifactVersion(vs);
- return base.equals( v.base );
- }
-
- @Override
- public int hashCode()
- {
- return 11 + comparable.hashCode();
- }
-
- @Override
- public boolean equals( Object other )
- {
- return compareTo( other ) == 0;
- }
-
- public int compareTo( Object o )
- {
- DefaultArtifactVersion otherVersion = (DefaultArtifactVersion) o;
- return this.comparable.compareTo( otherVersion.comparable );
- }
-
- public int getMajorVersion()
- {
- return majorVersion != null ? majorVersion : 0;
- }
-
- public int getMinorVersion()
- {
- return minorVersion != null ? minorVersion : 0;
- }
-
- public int getIncrementalVersion()
- {
- return incrementalVersion != null ? incrementalVersion : 0;
- }
-
- public int getBuildNumber()
- {
- return buildNumber != null ? buildNumber : 0;
- }
-
- public String getQualifier()
- {
- return qualifier;
- }
-
- public static boolean isVirtual( String version )
- {
- if( version== null )
- return false;
-
- if( version.endsWith( Artifact.LATEST_VERSION )
- || version.endsWith( Artifact.RELEASE_VERSION )
- || version.endsWith( Artifact.SNAPSHOT_VERSION )
- )
- return true;
-
- return false;
- }
-
- public final void parseVersion( String version )
- {
- comparable = new ComparableVersion( version );
-
- int index = version.indexOf( "-" );
-
- String part1;
- String part2 = null;
-
- if ( index < 0 )
- {
- part1 = version;
- }
- else
- {
- part1 = version.substring( 0, index );
- part2 = version.substring( index + 1 );
- }
-
- if ( part2 != null )
- {
- try
- {
- if ( ( part2.length() == 1 ) || !part2.startsWith( "0" ) )
- {
- buildNumber = Integer.valueOf( part2 );
- }
- else
- {
- qualifier = part2;
- }
- }
- catch ( NumberFormatException e )
- {
- qualifier = part2;
- }
- }
-
- if ( ( part1.indexOf( "." ) < 0 ) && !part1.startsWith( "0" ) )
- {
- try
- {
- majorVersion = Integer.valueOf( part1 );
- }
- catch ( NumberFormatException e )
- {
- // qualifier is the whole version, including "-"
- qualifier = version;
- buildNumber = null;
- }
- }
- else
- {
- boolean fallback = false;
- StringTokenizer tok = new StringTokenizer( part1, "." );
- try
- {
- majorVersion = getNextIntegerToken( tok );
- if ( tok.hasMoreTokens() )
- {
- minorVersion = getNextIntegerToken( tok );
- }
- if ( tok.hasMoreTokens() )
- {
- incrementalVersion = getNextIntegerToken( tok );
- }
- if ( tok.hasMoreTokens() )
- {
- fallback = true;
- }
-
- // string tokenzier won't detect these and ignores them
- if ( part1.indexOf( ".." ) >= 0 || part1.startsWith( "." ) || part1.endsWith( "." ) )
- {
- fallback = true;
- }
- }
- catch ( NumberFormatException e )
- {
- fallback = true;
- }
-
- if ( fallback )
- {
- // qualifier is the whole version, including "-"
- qualifier = version;
- base = "";
- majorVersion = null;
- minorVersion = null;
- incrementalVersion = null;
- buildNumber = null;
- }
- }
-
- if( base == null )
- {
- if( qualifier == null )
- base = version;
+ private String version;
+
+ private Integer majorVersion;
+
+ private Integer minorVersion;
+
+ private Integer incrementalVersion;
+
+ private Integer buildNumber;
+
+ private String base;
+
+ private String qualifier;
+
+ private ComparableVersion comparable;
+
+ private Quality quality = Quality.UNKNOWN_QUALITY;
+
+ public DefaultArtifactVersion( String version )
+ {
+ this.version = version;
+ parseVersion( version );
+ parseQuality( version );
+ }
+
+ public String getBase()
+ {
+ return base;
+ }
+
+ public boolean sameBase( DefaultArtifactVersion v )
+ {
+ return base.equals( v.base );
+ }
+
+ public boolean sameBase( String vs )
+ {
+ DefaultArtifactVersion v = new DefaultArtifactVersion( vs );
+ return base.equals( v.base );
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return 11 + comparable.hashCode();
+ }
+
+ @Override
+ public boolean equals( Object other )
+ {
+ return compareTo( other ) == 0;
+ }
+
+ public int compareTo( Object o )
+ {
+ DefaultArtifactVersion otherVersion = (DefaultArtifactVersion) o;
+ return this.comparable.compareTo( otherVersion.comparable );
+ }
+
+ public int getMajorVersion()
+ {
+ return majorVersion != null ? majorVersion : 0;
+ }
+
+ public int getMinorVersion()
+ {
+ return minorVersion != null ? minorVersion : 0;
+ }
+
+ public int getIncrementalVersion()
+ {
+ return incrementalVersion != null ? incrementalVersion : 0;
+ }
+
+ public int getBuildNumber()
+ {
+ return buildNumber != null ? buildNumber : 0;
+ }
+
+ public String getQualifier()
+ {
+ return qualifier;
+ }
+
+ public static boolean isVirtual( String version )
+ {
+ if ( version == null )
+ return false;
+
+ if ( version.endsWith( Artifact.LATEST_VERSION ) || version.endsWith( Artifact.RELEASE_VERSION )
+ || version.endsWith( Artifact.SNAPSHOT_VERSION ) )
+ return true;
+
+ return false;
+ }
+
+ public final void parseVersion( String version )
+ {
+ comparable = new ComparableVersion( version );
+
+ int index = version.indexOf( "-" );
+
+ String part1;
+ String part2 = null;
+
+ if ( index < 0 )
+ {
+ part1 = version;
+ }
else
{
- int ind = version.indexOf( qualifier );
- if( ind == 0 )
- base = qualifier;
- else
- base = version.substring( 0, version.indexOf( qualifier )-1 );
- }
- }
- }
-
- private static Integer getNextIntegerToken( StringTokenizer tok )
- {
- String s = tok.nextToken();
- if ( ( s.length() > 1 ) && s.startsWith( "0" ) )
- {
- throw new NumberFormatException( "Number part has a leading 0: '" + s + "'" );
- }
- return Integer.valueOf( s );
- }
-
- private void parseQuality( String version )
- {
- quality = new Quality( version );
- }
-
- @Override
- public String toString()
- {
- StringBuffer buf = new StringBuffer();
- if ( majorVersion != null )
- {
- buf.append( majorVersion );
- }
- if ( minorVersion != null )
- {
- buf.append( "." );
- buf.append( minorVersion );
- }
- if ( incrementalVersion != null )
- {
- buf.append( "." );
- buf.append( incrementalVersion );
- }
- if ( buildNumber != null )
- {
- buf.append( "-" );
- buf.append( buildNumber );
- }
- else if ( qualifier != null )
- {
- if ( buf.length() > 0 )
- {
- buf.append( "-" );
- }
- buf.append( qualifier );
- }
- return buf.toString();
- }
-
- public Quality getQuality()
- {
- return quality;
- }
+ part1 = version.substring( 0, index );
+ part2 = version.substring( index + 1 );
+ }
+
+ if ( part2 != null )
+ {
+ try
+ {
+ if ( ( part2.length() == 1 ) || !part2.startsWith( "0" ) )
+ {
+ buildNumber = Integer.valueOf( part2 );
+ }
+ else
+ {
+ qualifier = part2;
+ }
+ }
+ catch ( NumberFormatException e )
+ {
+ qualifier = part2;
+ }
+ }
+
+ if ( ( part1.indexOf( "." ) < 0 ) && !part1.startsWith( "0" ) )
+ {
+ try
+ {
+ majorVersion = Integer.valueOf( part1 );
+ }
+ catch ( NumberFormatException e )
+ {
+ // qualifier is the whole version, including "-"
+ qualifier = version;
+ buildNumber = null;
+ }
+ }
+ else
+ {
+ boolean fallback = false;
+ StringTokenizer tok = new StringTokenizer( part1, "." );
+ try
+ {
+ majorVersion = getNextIntegerToken( tok );
+ if ( tok.hasMoreTokens() )
+ {
+ minorVersion = getNextIntegerToken( tok );
+ }
+ if ( tok.hasMoreTokens() )
+ {
+ incrementalVersion = getNextIntegerToken( tok );
+ }
+ if ( tok.hasMoreTokens() )
+ {
+ fallback = true;
+ }
+
+ // string tokenzier won't detect these and ignores them
+ if ( part1.indexOf( ".." ) >= 0 || part1.startsWith( "." ) || part1.endsWith( "." ) )
+ {
+ fallback = true;
+ }
+ }
+ catch ( NumberFormatException e )
+ {
+ fallback = true;
+ }
+
+ if ( fallback )
+ {
+ // qualifier is the whole version, including "-"
+ qualifier = version;
+ base = "";
+ majorVersion = null;
+ minorVersion = null;
+ incrementalVersion = null;
+ buildNumber = null;
+ }
+ }
+
+ if ( base == null )
+ {
+ if ( qualifier == null )
+ {
+ base = version;
+ }
+ else
+ {
+ int ind = version.indexOf( qualifier );
+ if ( ind == 0 )
+ {
+ base = qualifier;
+ }
+ else
+ {
+ base = version.substring( 0, version.indexOf( qualifier ) - 1 );
+ }
+ }
+ }
+ }
+
+ private static Integer getNextIntegerToken( StringTokenizer tok )
+ {
+ String s = tok.nextToken();
+ if ( ( s.length() > 1 ) && s.startsWith( "0" ) )
+ {
+ throw new NumberFormatException( "Number part has a leading 0: '" + s + "'" );
+ }
+ return Integer.valueOf( s );
+ }
+
+ private void parseQuality( String version )
+ {
+ quality = new Quality( version );
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuffer buf = new StringBuffer();
+ if ( majorVersion != null )
+ {
+ buf.append( majorVersion );
+ }
+ if ( minorVersion != null )
+ {
+ buf.append( "." );
+ buf.append( minorVersion );
+ }
+ if ( incrementalVersion != null )
+ {
+ buf.append( "." );
+ buf.append( incrementalVersion );
+ }
+ if ( buildNumber != null )
+ {
+ buf.append( "-" );
+ buf.append( buildNumber );
+ }
+ else if ( qualifier != null )
+ {
+ if ( buf.length() > 0 )
+ {
+ buf.append( "-" );
+ }
+ buf.append( qualifier );
+ }
+ return buf.toString();
+ }
+
+ public Quality getQuality()
+ {
+ return quality;
+ }
}
Modified: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MavenVersionRange.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MavenVersionRange.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MavenVersionRange.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MavenVersionRange.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -26,205 +26,252 @@
/**
* Single range implementation, similar to OSGi specification:
- *
+ *
* [1.2.3, 4.5.6) 1.2.3 <= x < 4.5.6
* [1.2.3, 4.5.6] 1.2.3 <= x <= 4.5.6
* (1.2.3, 4.5.6) 1.2.3 < x < 4.5.6
* (1.2.3, 4.5.6] 1.2.3 < x <= 4.5.6
* 1.2.3 1.2.3 <= x - this one is configurable nowadays
- *
+ *
* @author Oleg Gusakov
* @version $Id$
*/
class MavenVersionRange
-implements VersionRange
+ implements VersionRange
{
- public static final String SYSTEM_PARAMETER_OSGI_VERSION = "maven.mercury.osgi.version";
- public static final String SYSTEM_PARAMETER_OSGI_VERSION_DEFAULT = "false";
- private boolean _osgiVersion = Boolean.parseBoolean( System.getProperty( SYSTEM_PARAMETER_OSGI_VERSION, SYSTEM_PARAMETER_OSGI_VERSION_DEFAULT ) );
-
- private static final DefaultArtifactVersion ZERO_VERSION = new DefaultArtifactVersion("0.0.0");
- private static final Language _lang = new DefaultLanguage( MavenVersionRange.class );
-
- QualityRange _toQualityRange = QualityRange.ALL;
-
- DefaultArtifactVersion _fromVersion = ZERO_VERSION;
- boolean _fromInclusive = true;
-
- DefaultArtifactVersion _toVersion;
- boolean _toInclusive = false;
-
- boolean _singleton = false;
-
- //--------------------------------------------------------------------------------------------
- protected MavenVersionRange( final String range, final QualityRange qRange )
- throws VersionException
- {
- this( range );
- setToQualityRange( qRange );
- }
- //--------------------------------------------------------------------------------------------
- protected MavenVersionRange( final String rangeIn )
- throws VersionException
- {
- String range = AttributeQuery.stripExpression( rangeIn );
-
- if( range == null || range.length() < 1 )
- return;
-
- if( range.indexOf(',') > 0 )
- {
- if( range.startsWith("[") )
- _fromInclusive = true;
- else if( range.startsWith("(") )
- _fromInclusive = false;
- else
- throw new VersionException( _lang.getMessage( "invalid.maven.version.range", range ) );
-
- if( range.endsWith("]") )
- _toInclusive = true;
- else if( range.endsWith(")") )
- _toInclusive = false;
- else
- throw new VersionException( _lang.getMessage( "invalid.maven.version.range", range ) );
-
- int ind = range.indexOf(',');
-
- String sFrom = range.substring(1,ind);
- if( sFrom != null && sFrom.length() > 0 )
- {
- String sFromT = sFrom.trim();
- if( sFromT != null && sFromT.length() > 0 )
- {
- checkForValidCharacters( sFromT );
- // TODO og: look for LATEST,RELEASE and SNAPSHOT
- Quality vq = new Quality( sFromT );
- if( vq.getQuality().equals( QualityEnum.snapshot )
- || vq.getQuality().equals( QualityEnum.unknown )
- )
- throw new VersionException( _lang.getMessage( "bad.version.sn", sFromT ) );
-
- _fromVersion = new DefaultArtifactVersion( sFromT );
- }
- }
-
- String sTo = range.substring( ind+1, range.length()-1 );
- if( sTo != null && sTo.length() > 0 )
- {
- String sToT = sTo.trim();
- if( sToT != null && sToT.length() > 0 )
- {
- checkForValidCharacters( sToT );
- _toVersion = new DefaultArtifactVersion( sToT );
- }
- }
-
- if( _fromVersion == null && _fromInclusive )
- throw new VersionException( _lang.getMessage( "invalid.maven.version.range.bad.from", range ) );
-
- if( _toVersion == null && _toInclusive )
- throw new VersionException( _lang.getMessage( "invalid.maven.version.range.bad.to", range ) );
-
- }
- else
- {
-
- checkForValidCharacters(range);
- _fromVersion = new DefaultArtifactVersion( range );
-
- _singleton = true;
-
- // good old maven version interpretation
- if( !_osgiVersion )
- {
- _toVersion = _fromVersion;
- _fromInclusive = true;
- _toInclusive = true;
- }
- }
- }
- //--------------------------------------------------------------------------------------------
- protected void setToQualityRange( QualityRange qRange )
- {
- this._toQualityRange = qRange;
- }
- //--------------------------------------------------------------------------------------------
- private void checkForValidCharacters( String v )
- throws VersionException
- {
- if( v == null || v.length() < 1 )
- throw new VersionException("empty version");
-
- int len = v.length();
-
- for( int i=0; i<len; i++ )
- {
- char c = v.charAt(0);
-
- if( c >= '0' && c <= '9' )
- continue;
-
- if( c >= 'A' && c <= 'Z' )
- continue;
-
- if( c >= 'a' && c <= 'z' )
- continue;
-
- if( c == '-' || c == '_' )
- continue;
-
- throw new VersionException( _lang.getMessage( "invalid.character", ""+c, v ) );
- }
- }
- //--------------------------------------------------------------------------------------------
- /* (non-Javadoc)
- * @see org.apache.maven.mercury.artifact.version.VersionRange#includes(java.lang.String)
- */
- public boolean includes( String version )
- {
- DefaultArtifactVersion ver = new DefaultArtifactVersion( version );
-
- int cmp1 = ver.compareTo( _fromVersion );
-
- if( cmp1 < 0 )
- return false;
-
- if( cmp1 == 0 )
- return _fromInclusive;
-
- if( _toVersion == null ) // eternity
- return true;
-
- int cmp2 = ver.compareTo( _toVersion );
-
- if( cmp2 < 0 )
- {
- if( ver.sameBase( _toVersion ) )
- {
- if( _toQualityRange.isAcceptedQuality( ver.getQuality() ) )
- return true;
+ public static final String SYSTEM_PARAMETER_OSGI_VERSION = "maven.mercury.osgi.version";
+
+ public static final String SYSTEM_PARAMETER_OSGI_VERSION_DEFAULT = "false";
+
+ private boolean _osgiVersion =
+ Boolean.parseBoolean( System.getProperty( SYSTEM_PARAMETER_OSGI_VERSION, SYSTEM_PARAMETER_OSGI_VERSION_DEFAULT ) );
+
+ private static final DefaultArtifactVersion ZERO_VERSION = new DefaultArtifactVersion( "0.0.0" );
+
+ private static final Language _lang = new DefaultLanguage( MavenVersionRange.class );
+
+ QualityRange _toQualityRange = QualityRange.ALL;
+
+ DefaultArtifactVersion _fromVersion = ZERO_VERSION;
+
+ boolean _fromInclusive = true;
+
+ DefaultArtifactVersion _toVersion;
+
+ boolean _toInclusive = false;
+
+ boolean _singleton = false;
+
+ // --------------------------------------------------------------------------------------------
+ protected MavenVersionRange( final String range, final QualityRange qRange )
+ throws VersionException
+ {
+ this( range );
+ setToQualityRange( qRange );
+ }
+
+ // --------------------------------------------------------------------------------------------
+ protected MavenVersionRange( final String rangeIn )
+ throws VersionException
+ {
+ String range = AttributeQuery.stripExpression( rangeIn );
+
+ if ( range == null || range.length() < 1 )
+ {
+ return;
+ }
+
+ if ( range.indexOf( ',' ) > 0 )
+ {
+ if ( range.startsWith( "[" ) )
+ {
+ _fromInclusive = true;
+ }
+ else if ( range.startsWith( "(" ) )
+ {
+ _fromInclusive = false;
+ }
+ else
+ {
+ throw new VersionException( _lang.getMessage( "invalid.maven.version.range", range ) );
+ }
+
+ if ( range.endsWith( "]" ) )
+ {
+ _toInclusive = true;
+ }
+ else if ( range.endsWith( ")" ) )
+ {
+ _toInclusive = false;
+ }
+ else
+ {
+ throw new VersionException( _lang.getMessage( "invalid.maven.version.range", range ) );
+ }
+
+ int ind = range.indexOf( ',' );
+
+ String sFrom = range.substring( 1, ind );
+ if ( sFrom != null && sFrom.length() > 0 )
+ {
+ String sFromT = sFrom.trim();
+ if ( sFromT != null && sFromT.length() > 0 )
+ {
+ checkForValidCharacters( sFromT );
+ // TODO og: look for LATEST,RELEASE and SNAPSHOT
+ Quality vq = new Quality( sFromT );
+ if ( vq.getQuality().equals( QualityEnum.snapshot ) || vq.getQuality().equals( QualityEnum.unknown ) )
+ {
+ throw new VersionException( _lang.getMessage( "bad.version.sn", sFromT ) );
+ }
+
+ _fromVersion = new DefaultArtifactVersion( sFromT );
+ }
+ }
+
+ String sTo = range.substring( ind + 1, range.length() - 1 );
+ if ( sTo != null && sTo.length() > 0 )
+ {
+ String sToT = sTo.trim();
+ if ( sToT != null && sToT.length() > 0 )
+ {
+ checkForValidCharacters( sToT );
+ _toVersion = new DefaultArtifactVersion( sToT );
+ }
+ }
+
+ if ( _fromVersion == null && _fromInclusive )
+ {
+ throw new VersionException( _lang.getMessage( "invalid.maven.version.range.bad.from", range ) );
+ }
+
+ if ( _toVersion == null && _toInclusive )
+ {
+ throw new VersionException( _lang.getMessage( "invalid.maven.version.range.bad.to", range ) );
+ }
+
+ }
+ else
+ {
+
+ checkForValidCharacters( range );
+ _fromVersion = new DefaultArtifactVersion( range );
+
+ _singleton = true;
+
+ // good old maven version interpretation
+ if ( !_osgiVersion )
+ {
+ _toVersion = _fromVersion;
+ _fromInclusive = true;
+ _toInclusive = true;
+ }
+ }
+ }
+
+ // --------------------------------------------------------------------------------------------
+ protected void setToQualityRange( QualityRange qRange )
+ {
+ this._toQualityRange = qRange;
+ }
+
+ // --------------------------------------------------------------------------------------------
+ private void checkForValidCharacters( String v )
+ throws VersionException
+ {
+ if ( v == null || v.length() < 1 )
+ {
+ throw new VersionException( "empty version" );
+ }
+
+ int len = v.length();
+
+ for ( int i = 0; i < len; i++ )
+ {
+ char c = v.charAt( 0 );
+
+ if ( c >= '0' && c <= '9' )
+ {
+ continue;
+ }
+
+ if ( c >= 'A' && c <= 'Z' )
+ {
+ continue;
+ }
+
+ if ( c >= 'a' && c <= 'z' )
+ {
+ continue;
+ }
+
+ if ( c == '-' || c == '_' )
+ {
+ continue;
+ }
+
+ throw new VersionException( _lang.getMessage( "invalid.character", "" + c, v ) );
+ }
+ }
+
+ // --------------------------------------------------------------------------------------------
+ /*
+ * (non-Javadoc)
+ * @see org.apache.maven.mercury.artifact.version.VersionRange#includes(java.lang.String)
+ */
+ public boolean includes( String version )
+ {
+ DefaultArtifactVersion ver = new DefaultArtifactVersion( version );
+
+ int cmp1 = ver.compareTo( _fromVersion );
+
+ if ( cmp1 < 0 )
+ {
+ return false;
+ }
+
+ if ( cmp1 == 0 )
+ {
+ return _fromInclusive;
+ }
+
+ if ( _toVersion == null ) // eternity
+ {
+ return true;
+ }
+
+ int cmp2 = ver.compareTo( _toVersion );
+
+ if ( cmp2 < 0 )
+ {
+ if ( ver.sameBase( _toVersion ) )
+ {
+ return _toQualityRange.isAcceptedQuality( ver.getQuality() );
+ }
+ return true;
+ }
+
+ if ( cmp2 == 0 )
+ {
+ return _toInclusive;
+ }
+
return false;
- }
- return true;
}
-
- if( cmp2 == 0 )
- return _toInclusive;
-
- return false;
- }
-
- public void setOption( String name, String val )
- {
- if( SYSTEM_PARAMETER_OSGI_VERSION.equals( name ) )
- _osgiVersion = Boolean.parseBoolean( System.getProperty( val, SYSTEM_PARAMETER_OSGI_VERSION_DEFAULT ) );
- }
-
- public boolean isSingleton()
- {
- return _singleton;
- }
-
- //--------------------------------------------------------------------------------------------
- //--------------------------------------------------------------------------------------------
+
+ public void setOption( String name, String val )
+ {
+ if ( SYSTEM_PARAMETER_OSGI_VERSION.equals( name ) )
+ {
+ _osgiVersion = Boolean.parseBoolean( System.getProperty( val, SYSTEM_PARAMETER_OSGI_VERSION_DEFAULT ) );
+ }
+ }
+
+ public boolean isSingleton()
+ {
+ return _singleton;
+ }
+
+ // --------------------------------------------------------------------------------------------
+ // --------------------------------------------------------------------------------------------
}
Modified: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MetadataVersionComparator.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MetadataVersionComparator.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MetadataVersionComparator.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/MetadataVersionComparator.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -29,22 +29,24 @@
*
* @author Oleg Gusakov
* @version $Id$
- *
*/
public class MetadataVersionComparator
-implements Comparator<ArtifactBasicMetadata>
+ implements Comparator<ArtifactBasicMetadata>
{
- private static final Language _lang = new DefaultLanguage( MetadataVersionComparator.class );
-
- public int compare( ArtifactBasicMetadata v1, ArtifactBasicMetadata v2 )
- {
- if( v1 == null || v2 == null )
- throw new IllegalArgumentException( _lang.getMessage( "null.version.to.compare", v1 == null ? "null" : v1.toString(), v2 == null ? "null" : v2.toString() ) );
-
- DefaultArtifactVersion av1 = new DefaultArtifactVersion( v1.getVersion() );
- DefaultArtifactVersion av2 = new DefaultArtifactVersion( v2.getVersion() );
-
- return av1.compareTo( av2 );
- }
+ private static final Language _lang = new DefaultLanguage( MetadataVersionComparator.class );
+
+ public int compare( ArtifactBasicMetadata v1, ArtifactBasicMetadata v2 )
+ {
+ if ( v1 == null || v2 == null )
+ {
+ throw new IllegalArgumentException( _lang.getMessage( "null.version.to.compare", v1 == null ? "null"
+ : v1.toString(), v2 == null ? "null" : v2.toString() ) );
+ }
+
+ DefaultArtifactVersion av1 = new DefaultArtifactVersion( v1.getVersion() );
+ DefaultArtifactVersion av2 = new DefaultArtifactVersion( v2.getVersion() );
+
+ return av1.compareTo( av2 );
+ }
}
Modified: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionComparator.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionComparator.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionComparator.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionComparator.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -28,22 +28,23 @@
*
* @author Oleg Gusakov
* @version $Id$
- *
*/
public class VersionComparator
-implements Comparator<String>
+ implements Comparator<String>
{
- private static final Language LANG = new DefaultLanguage( VersionComparator.class );
-
- public int compare( String v1, String v2 )
- {
- if( v1 == null || v2 == null )
- throw new IllegalArgumentException( LANG.getMessage( "null.version.to.compare", v1,v2 ) );
-
- DefaultArtifactVersion av1 = new DefaultArtifactVersion( v1 );
- DefaultArtifactVersion av2 = new DefaultArtifactVersion( v2 );
-
- return av1.compareTo( av2 );
- }
+ private static final Language LANG = new DefaultLanguage( VersionComparator.class );
+
+ public int compare( String v1, String v2 )
+ {
+ if ( v1 == null || v2 == null )
+ {
+ throw new IllegalArgumentException( LANG.getMessage( "null.version.to.compare", v1, v2 ) );
+ }
+
+ DefaultArtifactVersion av1 = new DefaultArtifactVersion( v1 );
+ DefaultArtifactVersion av2 = new DefaultArtifactVersion( v2 );
+
+ return av1.compareTo( av2 );
+ }
}
Modified: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionException.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionException.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionException.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionException.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,7 +19,6 @@
package org.apache.maven.mercury.artifact.version;
/**
- *
* @author Oleg Gusakov
* @version $Id$
*/
@@ -27,23 +26,23 @@
extends Exception
{
- public VersionException()
- {
- }
-
- public VersionException(String message)
- {
- super(message);
- }
-
- public VersionException(Throwable cause)
- {
- super(cause);
- }
-
- public VersionException(String message, Throwable cause)
- {
- super(message, cause);
- }
+ public VersionException()
+ {
+ }
+
+ public VersionException( String message )
+ {
+ super( message );
+ }
+
+ public VersionException( Throwable cause )
+ {
+ super( cause );
+ }
+
+ public VersionException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
}
Modified: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionQuery.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionQuery.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionQuery.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionQuery.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -22,42 +22,48 @@
/**
* multiple ranges. Not sure if we need need it - will delete later ..
- *
+ *
* @author Oleg Gusakov
* @version $Id$
*/
public class VersionQuery
{
- String [] _ranges;
-
- public VersionQuery( String query )
- {
-
- }
-
- private void parseRange( String query )
- {
- if( query == null || query.length() < 1 )
- return;
-
- StringTokenizer st = new StringTokenizer( query, "," );
- int nRanges = st.countTokens();
- if( nRanges < 1 )
- return;
-
- _ranges = new String [ nRanges ];
- int count = 0;
-
- while( st.hasMoreTokens() )
- _ranges[ count ++ ] = st.nextToken();
-
- }
+ String[] _ranges;
- /**
- *
+ public VersionQuery( String query )
+ {
+
+ }
+
+ private void parseRange( String query )
+ {
+ if ( query == null || query.length() < 1 )
+ {
+ return;
+ }
+
+ StringTokenizer st = new StringTokenizer( query, "," );
+ int nRanges = st.countTokens();
+ if ( nRanges < 1 )
+ {
+ return;
+ }
+
+ _ranges = new String[nRanges];
+ int count = 0;
+
+ while ( st.hasMoreTokens() )
+ {
+ _ranges[count++] = st.nextToken();
+ }
+
+ }
+
+ /**
+ *
*/
- public boolean within( String version )
- {
- return false;
- }
+ public boolean within( String version )
+ {
+ return false;
+ }
}
Modified: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionRange.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionRange.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionRange.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionRange.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,20 +25,20 @@
*
* @author Oleg Gusakov
* @version $Id$
- *
*/
public interface VersionRange
-extends Configurable
+ extends Configurable
{
- /**
- * returns true if the supplied version fits into the range
- *
- * @param version to test
- * @return
- */
- public boolean includes( String version );
- /**
- * @return true if the range is good old single version, not a true range
- */
- public boolean isSingleton();
+ /**
+ * returns true if the supplied version fits into the range
+ *
+ * @param version to test
+ * @return
+ */
+ public boolean includes( String version );
+
+ /**
+ * @return true if the range is good old single version, not a true range
+ */
+ public boolean isSingleton();
}
Modified: maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionRangeFactory.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionRangeFactory.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionRangeFactory.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/main/java/org/apache/maven/mercury/artifact/version/VersionRangeFactory.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -28,58 +28,60 @@
*
* @author Oleg Gusakov
* @version $Id$
- *
*/
public class VersionRangeFactory
{
-
- public static VersionRange create( final String version )
- throws VersionException
- {
- return new MavenVersionRange( version );
- }
-
- public static VersionRange create( final String version, final QualityRange qRange )
- throws VersionException
- {
- return new MavenVersionRange( version, qRange );
- }
- //--------------------------------------------------------------------------------------------
- /**
- * helpful latest version calculator
- *
- * @param versions
- * @param noSnapshots
- * @return
- */
- public static final String findLatest( final Collection<String> versions, final boolean noSnapshots )
- {
- DefaultArtifactVersion tempDav = null;
- DefaultArtifactVersion tempDav2 = null;
- String version = null;
- // find latest
- for( String vn : versions )
+ public static VersionRange create( final String version )
+ throws VersionException
+ {
+ return new MavenVersionRange( version );
+ }
+
+ public static VersionRange create( final String version, final QualityRange qRange )
+ throws VersionException
{
- // RELEASE?
- if( noSnapshots && vn.endsWith( Artifact.SNAPSHOT_VERSION ))
- continue;
-
- if( version == null )
- {
- version = vn;
- tempDav = new DefaultArtifactVersion( vn );
- continue;
- }
-
- tempDav2 = new DefaultArtifactVersion( vn );
- if( tempDav2.compareTo( tempDav ) > 0 )
- {
- version = vn;
- tempDav = tempDav2;
- }
+ return new MavenVersionRange( version, qRange );
+ }
+
+ // --------------------------------------------------------------------------------------------
+ /**
+ * helpful latest version calculator
+ *
+ * @param versions
+ * @param noSnapshots
+ * @return
+ */
+ public static final String findLatest( final Collection<String> versions, final boolean noSnapshots )
+ {
+ DefaultArtifactVersion tempDav = null;
+ DefaultArtifactVersion tempDav2 = null;
+ String version = null;
+
+ // find latest
+ for ( String vn : versions )
+ {
+ // RELEASE?
+ if ( noSnapshots && vn.endsWith( Artifact.SNAPSHOT_VERSION ) )
+ {
+ continue;
+ }
+
+ if ( version == null )
+ {
+ version = vn;
+ tempDav = new DefaultArtifactVersion( vn );
+ continue;
+ }
+
+ tempDav2 = new DefaultArtifactVersion( vn );
+ if ( tempDav2.compareTo( tempDav ) > 0 )
+ {
+ version = vn;
+ tempDav = tempDav2;
+ }
+ }
+ return version;
}
- return version;
- }
}
Modified: maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/DependencyFilterTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/DependencyFilterTest.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/DependencyFilterTest.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/DependencyFilterTest.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,84 +25,85 @@
import org.apache.maven.mercury.artifact.version.VersionException;
/**
- *
- *
* @author Oleg Gusakov
* @version $Id$
- *
*/
public class DependencyFilterTest
extends TestCase
{
- ArtifactBasicMetadata a1;
- ArtifactBasicMetadata a2;
- ArtifactBasicMetadata a3;
- ArtifactBasicMetadata a4;
-
- ArrayList<ArtifactBasicMetadata> inc;
- ArrayList<ArtifactBasicMetadata> exc;
-
- @Override
- protected void setUp()
- throws Exception
- {
- a1 = new ArtifactBasicMetadata("a:a:1.1");
- a2 = new ArtifactBasicMetadata("a:a:2.1");
- a3 = new ArtifactBasicMetadata("a:a:3.1");
- a4 = new ArtifactBasicMetadata("a:a:4.1");
-
- inc = new ArrayList<ArtifactBasicMetadata>();
- inc.add( new ArtifactBasicMetadata("a:a") );
- inc.add( new ArtifactBasicMetadata("b:b:2.0.0") );
-
- exc = new ArrayList<ArtifactBasicMetadata>();
- exc.add( new ArtifactBasicMetadata("c:c") );
- exc.add( new ArtifactBasicMetadata("b:b:2.0.1") );
-
- a2.setInclusions( inc );
-
- a3.setExclusions( exc );
-
- a4.setInclusions( inc );
- a4.setExclusions( exc );
- }
-
- public void testNoFilter()
- throws VersionException
- {
- assertTrue( a1.allowDependency( new ArtifactBasicMetadata("a:a:2.0.0") ) );
- assertTrue( a1.allowDependency( new ArtifactBasicMetadata("b:b:1.0.0") ) );
- assertTrue( a1.allowDependency( new ArtifactBasicMetadata("c:c:1.0.0") ) );
- }
-
- public void testInclusionsFilter()
- throws VersionException
- {
- assertTrue( a2.allowDependency( new ArtifactBasicMetadata("a:a:2.0.0") ) );
- assertFalse( a2.allowDependency( new ArtifactBasicMetadata("b:b:1.0.0") ) );
- assertTrue( a2.allowDependency( new ArtifactBasicMetadata("b:b:2.0.0") ) );
- assertFalse( a2.allowDependency( new ArtifactBasicMetadata("b:b:2.0.1") ) );
- assertFalse( a2.allowDependency( new ArtifactBasicMetadata("c:c:1.0.0") ) );
- }
-
- public void testExclusionsFilter()
- throws VersionException
- {
- assertTrue( a3.allowDependency( new ArtifactBasicMetadata("a:a:2.0.0") ) );
- assertTrue( a3.allowDependency( new ArtifactBasicMetadata("b:b:1.0.0") ) );
- assertFalse( a3.allowDependency( new ArtifactBasicMetadata("b:b:2.0.1") ) );
- assertFalse( a3.allowDependency( new ArtifactBasicMetadata("c:c:1.0.0") ) );
- }
-
- public void testInclusionsExclusionsFilter()
- throws VersionException
- {
- assertTrue( a4.allowDependency( new ArtifactBasicMetadata("a:a:2.0.0") ) );
- assertFalse( a4.allowDependency( new ArtifactBasicMetadata("b:b:1.0.0") ) );
- assertTrue( a4.allowDependency( new ArtifactBasicMetadata("b:b:2.0.0") ) );
- assertFalse( a4.allowDependency( new ArtifactBasicMetadata("b:b:2.0.1") ) );
- assertFalse( a4.allowDependency( new ArtifactBasicMetadata("b:b:3.0.1") ) );
- assertFalse( a4.allowDependency( new ArtifactBasicMetadata("c:c:1.0.0") ) );
- }
+ ArtifactBasicMetadata a1;
+
+ ArtifactBasicMetadata a2;
+
+ ArtifactBasicMetadata a3;
+
+ ArtifactBasicMetadata a4;
+
+ ArrayList<ArtifactBasicMetadata> inc;
+
+ ArrayList<ArtifactBasicMetadata> exc;
+
+ @Override
+ protected void setUp()
+ throws Exception
+ {
+ a1 = new ArtifactBasicMetadata( "a:a:1.1" );
+ a2 = new ArtifactBasicMetadata( "a:a:2.1" );
+ a3 = new ArtifactBasicMetadata( "a:a:3.1" );
+ a4 = new ArtifactBasicMetadata( "a:a:4.1" );
+
+ inc = new ArrayList<ArtifactBasicMetadata>();
+ inc.add( new ArtifactBasicMetadata( "a:a" ) );
+ inc.add( new ArtifactBasicMetadata( "b:b:2.0.0" ) );
+
+ exc = new ArrayList<ArtifactBasicMetadata>();
+ exc.add( new ArtifactBasicMetadata( "c:c" ) );
+ exc.add( new ArtifactBasicMetadata( "b:b:2.0.1" ) );
+
+ a2.setInclusions( inc );
+
+ a3.setExclusions( exc );
+
+ a4.setInclusions( inc );
+ a4.setExclusions( exc );
+ }
+
+ public void testNoFilter()
+ throws VersionException
+ {
+ assertTrue( a1.allowDependency( new ArtifactBasicMetadata( "a:a:2.0.0" ) ) );
+ assertTrue( a1.allowDependency( new ArtifactBasicMetadata( "b:b:1.0.0" ) ) );
+ assertTrue( a1.allowDependency( new ArtifactBasicMetadata( "c:c:1.0.0" ) ) );
+ }
+
+ public void testInclusionsFilter()
+ throws VersionException
+ {
+ assertTrue( a2.allowDependency( new ArtifactBasicMetadata( "a:a:2.0.0" ) ) );
+ assertFalse( a2.allowDependency( new ArtifactBasicMetadata( "b:b:1.0.0" ) ) );
+ assertTrue( a2.allowDependency( new ArtifactBasicMetadata( "b:b:2.0.0" ) ) );
+ assertFalse( a2.allowDependency( new ArtifactBasicMetadata( "b:b:2.0.1" ) ) );
+ assertFalse( a2.allowDependency( new ArtifactBasicMetadata( "c:c:1.0.0" ) ) );
+ }
+
+ public void testExclusionsFilter()
+ throws VersionException
+ {
+ assertTrue( a3.allowDependency( new ArtifactBasicMetadata( "a:a:2.0.0" ) ) );
+ assertTrue( a3.allowDependency( new ArtifactBasicMetadata( "b:b:1.0.0" ) ) );
+ assertFalse( a3.allowDependency( new ArtifactBasicMetadata( "b:b:2.0.1" ) ) );
+ assertFalse( a3.allowDependency( new ArtifactBasicMetadata( "c:c:1.0.0" ) ) );
+ }
+
+ public void testInclusionsExclusionsFilter()
+ throws VersionException
+ {
+ assertTrue( a4.allowDependency( new ArtifactBasicMetadata( "a:a:2.0.0" ) ) );
+ assertFalse( a4.allowDependency( new ArtifactBasicMetadata( "b:b:1.0.0" ) ) );
+ assertTrue( a4.allowDependency( new ArtifactBasicMetadata( "b:b:2.0.0" ) ) );
+ assertFalse( a4.allowDependency( new ArtifactBasicMetadata( "b:b:2.0.1" ) ) );
+ assertFalse( a4.allowDependency( new ArtifactBasicMetadata( "b:b:3.0.1" ) ) );
+ assertFalse( a4.allowDependency( new ArtifactBasicMetadata( "c:c:1.0.0" ) ) );
+ }
}
Modified: maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/QualityTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/QualityTest.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/QualityTest.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/QualityTest.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -21,96 +21,93 @@
import junit.framework.TestCase;
/**
- *
- *
* @author Oleg Gusakov
* @version $Id$
- *
*/
public class QualityTest
extends TestCase
{
-
- public void testParser()
- {
- Quality q = new Quality("a-b_a-1");
-
- assertNotNull( q.quality );
- assertEquals( QualityEnum.release, q.getQuality() );
- assertEquals( Quality.DEFAULT_QUANTITY, q.getQuantity() );
- }
-
- public void testSn1()
- {
- Quality q = new Quality("5.5-SNAPSHOT");
-
- assertNotNull( q.quality );
- assertEquals( QualityEnum.snapshot, q.getQuality() );
- assertEquals( Quality.DEFAULT_QUANTITY, q.getQuantity() );
- }
-
- public void testSn2()
- {
- Quality q = new Quality("5.5-20080815.231708-12");
-
- assertNotNull( q.quality );
- assertEquals( QualityEnum.snapshot, q.getQuality() );
- assertEquals( Quality.SNAPSHOT_TS_QUANTITY, q.getQuantity() );
- }
-
- public void testSn3()
- {
- Quality q = new Quality("5.5-20080815.231708-");
-
- assertNotNull( q.quality );
- assertEquals( QualityEnum.release, q.getQuality() );
- }
-
- public void testSn4()
- {
- Quality q = new Quality("5.5-20080815.23-15");
-
- assertNotNull( q.quality );
- assertEquals( QualityEnum.release, q.getQuality() );
- }
-
- public void testAlpha()
- {
- Quality q = new Quality("5.5-alpha-12");
-
- assertNotNull( q.quality );
- assertEquals( QualityEnum.alpha, q.getQuality() );
- assertEquals( 12, q.getQuantity() );
- }
-
- public void testBeta()
- {
- Quality q = new Quality("5.5-beta-1");
-
- assertNotNull( q.quality );
- assertEquals( QualityEnum.beta, q.getQuality() );
- assertEquals( 1, q.getQuantity() );
- }
-
- public void testCompateQ()
- {
- Quality u = Quality.UNKNOWN_QUALITY;
- Quality sn = new Quality("5.5-SNAPSHOT");
- Quality snts = new Quality("5.5-5.5-20080815.231708-12");
- Quality a1 = new Quality("5.5-5.5-alpha-1");
- Quality a2 = new Quality("5.5-5.5-alpha-20");
- Quality b1 = new Quality("5.5-5.5-beta-1");
- Quality b2 = new Quality("5.5-5.5-beta-10");
- Quality r = new Quality("5.5");
-
- assertTrue( u.compareTo( sn ) < 0 );
- assertTrue( sn.compareTo( snts ) == 0 );
- assertTrue( snts.compareTo( a1 ) < 0 );
- assertEquals( 0, a1.compareTo( a1 ) );
- assertTrue( a1.compareTo( a2 ) < 0 );
- assertTrue( a2.compareTo( b1 ) < 0 );
- assertTrue( b1.compareTo( b2 ) < 0 );
- assertTrue( b2.compareTo( r ) < 0 );
- assertEquals( 0, r.compareTo( r ) );
- }
+
+ public void testParser()
+ {
+ Quality q = new Quality( "a-b_a-1" );
+
+ assertNotNull( q.quality );
+ assertEquals( QualityEnum.release, q.getQuality() );
+ assertEquals( Quality.DEFAULT_QUANTITY, q.getQuantity() );
+ }
+
+ public void testSn1()
+ {
+ Quality q = new Quality( "5.5-SNAPSHOT" );
+
+ assertNotNull( q.quality );
+ assertEquals( QualityEnum.snapshot, q.getQuality() );
+ assertEquals( Quality.DEFAULT_QUANTITY, q.getQuantity() );
+ }
+
+ public void testSn2()
+ {
+ Quality q = new Quality( "5.5-20080815.231708-12" );
+
+ assertNotNull( q.quality );
+ assertEquals( QualityEnum.snapshot, q.getQuality() );
+ assertEquals( Quality.SNAPSHOT_TS_QUANTITY, q.getQuantity() );
+ }
+
+ public void testSn3()
+ {
+ Quality q = new Quality( "5.5-20080815.231708-" );
+
+ assertNotNull( q.quality );
+ assertEquals( QualityEnum.release, q.getQuality() );
+ }
+
+ public void testSn4()
+ {
+ Quality q = new Quality( "5.5-20080815.23-15" );
+
+ assertNotNull( q.quality );
+ assertEquals( QualityEnum.release, q.getQuality() );
+ }
+
+ public void testAlpha()
+ {
+ Quality q = new Quality( "5.5-alpha-12" );
+
+ assertNotNull( q.quality );
+ assertEquals( QualityEnum.alpha, q.getQuality() );
+ assertEquals( 12, q.getQuantity() );
+ }
+
+ public void testBeta()
+ {
+ Quality q = new Quality( "5.5-beta-1" );
+
+ assertNotNull( q.quality );
+ assertEquals( QualityEnum.beta, q.getQuality() );
+ assertEquals( 1, q.getQuantity() );
+ }
+
+ public void testCompateQ()
+ {
+ Quality u = Quality.UNKNOWN_QUALITY;
+ Quality sn = new Quality( "5.5-SNAPSHOT" );
+ Quality snts = new Quality( "5.5-5.5-20080815.231708-12" );
+ Quality a1 = new Quality( "5.5-5.5-alpha-1" );
+ Quality a2 = new Quality( "5.5-5.5-alpha-20" );
+ Quality b1 = new Quality( "5.5-5.5-beta-1" );
+ Quality b2 = new Quality( "5.5-5.5-beta-10" );
+ Quality r = new Quality( "5.5" );
+
+ assertTrue( u.compareTo( sn ) < 0 );
+ assertTrue( sn.compareTo( snts ) == 0 );
+ assertTrue( snts.compareTo( a1 ) < 0 );
+ assertEquals( 0, a1.compareTo( a1 ) );
+ assertTrue( a1.compareTo( a2 ) < 0 );
+ assertTrue( a2.compareTo( b1 ) < 0 );
+ assertTrue( b1.compareTo( b2 ) < 0 );
+ assertTrue( b2.compareTo( r ) < 0 );
+ assertEquals( 0, r.compareTo( r ) );
+ }
}
Modified: maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/version/MavenVersionRangeTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/version/MavenVersionRangeTest.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/version/MavenVersionRangeTest.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/version/MavenVersionRangeTest.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -24,110 +24,109 @@
import org.apache.maven.mercury.artifact.QualityRange;
/**
- *
* @author Oleg Gusakov
* @version $Id$
*/
public class MavenVersionRangeTest
extends TestCase
{
- MavenVersionRange range;
+ MavenVersionRange range;
- public void testSimple()
- throws VersionException
- {
- String rangeS = "[ 1.2.3 , 2.0.0 )";
- range = new MavenVersionRange( rangeS );
-
- assertTrue( "1.2.4 did not match the range "+rangeS, range.includes( "1.2.4" ) );
- assertTrue( "1.3.1 did not match the range "+rangeS, range.includes( "1.3.1" ) );
- assertTrue( "1.2.3 did not match the range "+rangeS, range.includes( "1.2.3" ) );
- assertFalse( "1.2.2 did matches the range "+rangeS, range.includes( "1.2.2" ) );
- assertFalse( "2.0.0 did matches the range "+rangeS, range.includes( "2.0.0" ) );
- assertFalse( "3.1.0 did matches the range "+rangeS, range.includes( "3.1.0" ) );
- }
-
- public void testEternity()
- throws VersionException
- {
- String rangeS = "[ 1.2.3 , )";
- range = new MavenVersionRange( rangeS );
-
- assertTrue( "1.2.4 did not match the range "+rangeS, range.includes( "1.2.4" ) );
- assertTrue( "1.3.1 did not match the range "+rangeS, range.includes( "1.3.1" ) );
- assertTrue( "1.2.3 did not match the range "+rangeS, range.includes( "1.2.3" ) );
- assertFalse( "1.2.2 does matches the range "+rangeS, range.includes( "1.2.2" ) );
- assertTrue( "2.0.0 does matches the range "+rangeS, range.includes( "2.0.0" ) );
- assertTrue( "3.1.0 does matches the range "+rangeS, range.includes( "3.1.0" ) );
- }
-
- public void test6Digits()
- throws VersionException
- {
- String rangeS = "[ 1.0.0.1.2.1 , )";
- range = new MavenVersionRange( rangeS );
-
- assertTrue( "1.0.0.1.2.1 did not match the range "+rangeS, range.includes( "1.0.0.1.2.1" ) );
- assertTrue( "1.0.0.1.2.2 did not match the range "+rangeS, range.includes( "1.0.0.1.2.2" ) );
- assertTrue( "1.0.0.1.3.0 did not match the range "+rangeS, range.includes( "1.0.0.1.3.0" ) );
- assertFalse( "1.0.0.1.2.0 does matches the range "+rangeS, range.includes( "1.0.0.1.2.0" ) );
- assertFalse( "1.0.0.1.2.1-alpha-1 does match the range "+rangeS, range.includes( "1.0.0.1.2.1-alpha-1" ) );
- assertTrue( "1.0.0.1.2.2-alpha-1 does not match the range "+rangeS, range.includes( "1.0.0.1.2.2-alpha-1" ) );
- }
-
- public void testAlphaNumeric()
- throws VersionException
- {
- String rangeS = "[1.0.0.0.22,)";
- range = new MavenVersionRange( rangeS );
-
- assertFalse( "1.0.0.0.9 does match the range "+rangeS, range.includes( "1.0.0.0.9" ) );
- }
-
- public void testEdge()
- throws VersionException
- {
- String rangeS = "[1.0,2.0)";
- range = new MavenVersionRange( rangeS );
-
- assertFalse( range.includes( "1.0-SNAPSHOT" ) );
- assertTrue( range.includes( "1.1-SNAPSHOT" ) );
- assertTrue( range.includes( "2.0-SNAPSHOT" ) );
- assertFalse( range.includes( "2.0-20080815.235653-15" ) ); // this is still considered a release :(
- assertTrue( range.includes( "2.0-alpha-1" ) );
- assertFalse( range.includes( "2.0" ) );
- }
-
- public void testBetaEdge()
- throws VersionException
- {
- String rangeS = "[1.0,2.0)";
- range = new MavenVersionRange( rangeS );
- range.setToQualityRange( new QualityRange( Quality.BETA_QUALITY, true, Quality.RELEASE_QUALITY, true ) );
-
- assertFalse( range.includes( "1.0-SNAPSHOT" ) );
- assertTrue( range.includes( "1.1-SNAPSHOT" ) );
- assertFalse( range.includes( "2.0-SNAPSHOT" ) );
- assertFalse( range.includes( "2.0-20080815.235653-15" ) );
- assertFalse( range.includes( "2.0-alpha-35" ) );
- assertTrue( range.includes( "2.0-beta-1" ) );
- assertFalse( range.includes( "2.0" ) );
- }
-
- public void testAlphaEdge()
- throws VersionException
- {
- String rangeS = "[1.0,2.0)";
- range = new MavenVersionRange( rangeS );
- range.setToQualityRange( new QualityRange( Quality.ALPHA_QUALITY, true, Quality.RELEASE_QUALITY, true ) );
-
- assertFalse( range.includes( "1.0-SNAPSHOT" ) );
- assertTrue( range.includes( "1.1-SNAPSHOT" ) );
- assertFalse( range.includes( "2.0-SNAPSHOT" ) );
- assertFalse( range.includes( "2.0-20080815.235653-15" ) );
- assertTrue( range.includes( "2.0-alpha-35" ) );
- assertTrue( range.includes( "2.0-beta-1" ) );
- assertFalse( range.includes( "2.0" ) );
- }
+ public void testSimple()
+ throws VersionException
+ {
+ String rangeS = "[ 1.2.3 , 2.0.0 )";
+ range = new MavenVersionRange( rangeS );
+
+ assertTrue( "1.2.4 did not match the range " + rangeS, range.includes( "1.2.4" ) );
+ assertTrue( "1.3.1 did not match the range " + rangeS, range.includes( "1.3.1" ) );
+ assertTrue( "1.2.3 did not match the range " + rangeS, range.includes( "1.2.3" ) );
+ assertFalse( "1.2.2 did matches the range " + rangeS, range.includes( "1.2.2" ) );
+ assertFalse( "2.0.0 did matches the range " + rangeS, range.includes( "2.0.0" ) );
+ assertFalse( "3.1.0 did matches the range " + rangeS, range.includes( "3.1.0" ) );
+ }
+
+ public void testEternity()
+ throws VersionException
+ {
+ String rangeS = "[ 1.2.3 , )";
+ range = new MavenVersionRange( rangeS );
+
+ assertTrue( "1.2.4 did not match the range " + rangeS, range.includes( "1.2.4" ) );
+ assertTrue( "1.3.1 did not match the range " + rangeS, range.includes( "1.3.1" ) );
+ assertTrue( "1.2.3 did not match the range " + rangeS, range.includes( "1.2.3" ) );
+ assertFalse( "1.2.2 does matches the range " + rangeS, range.includes( "1.2.2" ) );
+ assertTrue( "2.0.0 does matches the range " + rangeS, range.includes( "2.0.0" ) );
+ assertTrue( "3.1.0 does matches the range " + rangeS, range.includes( "3.1.0" ) );
+ }
+
+ public void test6Digits()
+ throws VersionException
+ {
+ String rangeS = "[ 1.0.0.1.2.1 , )";
+ range = new MavenVersionRange( rangeS );
+
+ assertTrue( "1.0.0.1.2.1 did not match the range " + rangeS, range.includes( "1.0.0.1.2.1" ) );
+ assertTrue( "1.0.0.1.2.2 did not match the range " + rangeS, range.includes( "1.0.0.1.2.2" ) );
+ assertTrue( "1.0.0.1.3.0 did not match the range " + rangeS, range.includes( "1.0.0.1.3.0" ) );
+ assertFalse( "1.0.0.1.2.0 does matches the range " + rangeS, range.includes( "1.0.0.1.2.0" ) );
+ assertFalse( "1.0.0.1.2.1-alpha-1 does match the range " + rangeS, range.includes( "1.0.0.1.2.1-alpha-1" ) );
+ assertTrue( "1.0.0.1.2.2-alpha-1 does not match the range " + rangeS, range.includes( "1.0.0.1.2.2-alpha-1" ) );
+ }
+
+ public void testAlphaNumeric()
+ throws VersionException
+ {
+ String rangeS = "[1.0.0.0.22,)";
+ range = new MavenVersionRange( rangeS );
+
+ assertFalse( "1.0.0.0.9 does match the range " + rangeS, range.includes( "1.0.0.0.9" ) );
+ }
+
+ public void testEdge()
+ throws VersionException
+ {
+ String rangeS = "[1.0,2.0)";
+ range = new MavenVersionRange( rangeS );
+
+ assertFalse( range.includes( "1.0-SNAPSHOT" ) );
+ assertTrue( range.includes( "1.1-SNAPSHOT" ) );
+ assertTrue( range.includes( "2.0-SNAPSHOT" ) );
+ assertFalse( range.includes( "2.0-20080815.235653-15" ) ); // this is still considered a release :(
+ assertTrue( range.includes( "2.0-alpha-1" ) );
+ assertFalse( range.includes( "2.0" ) );
+ }
+
+ public void testBetaEdge()
+ throws VersionException
+ {
+ String rangeS = "[1.0,2.0)";
+ range = new MavenVersionRange( rangeS );
+ range.setToQualityRange( new QualityRange( Quality.BETA_QUALITY, true, Quality.RELEASE_QUALITY, true ) );
+
+ assertFalse( range.includes( "1.0-SNAPSHOT" ) );
+ assertTrue( range.includes( "1.1-SNAPSHOT" ) );
+ assertFalse( range.includes( "2.0-SNAPSHOT" ) );
+ assertFalse( range.includes( "2.0-20080815.235653-15" ) );
+ assertFalse( range.includes( "2.0-alpha-35" ) );
+ assertTrue( range.includes( "2.0-beta-1" ) );
+ assertFalse( range.includes( "2.0" ) );
+ }
+
+ public void testAlphaEdge()
+ throws VersionException
+ {
+ String rangeS = "[1.0,2.0)";
+ range = new MavenVersionRange( rangeS );
+ range.setToQualityRange( new QualityRange( Quality.ALPHA_QUALITY, true, Quality.RELEASE_QUALITY, true ) );
+
+ assertFalse( range.includes( "1.0-SNAPSHOT" ) );
+ assertTrue( range.includes( "1.1-SNAPSHOT" ) );
+ assertFalse( range.includes( "2.0-SNAPSHOT" ) );
+ assertFalse( range.includes( "2.0-20080815.235653-15" ) );
+ assertTrue( range.includes( "2.0-alpha-35" ) );
+ assertTrue( range.includes( "2.0-beta-1" ) );
+ assertFalse( range.includes( "2.0" ) );
+ }
}
Modified: maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/version/QualityTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/version/QualityTest.java?rev=744245&r1=744244&r2=744245&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/version/QualityTest.java (original)
+++ maven/mercury/trunk/mercury-artifact/src/test/java/org/apache/maven/mercury/artifact/version/QualityTest.java Fri Feb 13 21:23:44 2009
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -23,26 +23,23 @@
import org.apache.maven.mercury.artifact.Quality;
/**
- *
- *
* @author Oleg Gusakov
* @version $Id$
- *
*/
public class QualityTest
extends TestCase
{
- Quality q;
-
- public void testEquality()
- {
- q = new Quality("LATEST");
- assertTrue( q.equals( Quality.FIXED_LATEST_QUALITY ) );
-
- q = new Quality("RELEASE");
- assertTrue( q.equals( Quality.FIXED_RELEASE_QUALITY ) );
-
- q = new Quality("1.1-SNAPSHOT");
- assertTrue( q.equals( Quality.SNAPSHOT_QUALITY ) );
- }
+ Quality q;
+
+ public void testEquality()
+ {
+ q = new Quality( "LATEST" );
+ assertTrue( q.equals( Quality.FIXED_LATEST_QUALITY ) );
+
+ q = new Quality( "RELEASE" );
+ assertTrue( q.equals( Quality.FIXED_RELEASE_QUALITY ) );
+
+ q = new Quality( "1.1-SNAPSHOT" );
+ assertTrue( q.equals( Quality.SNAPSHOT_QUALITY ) );
+ }
}