diff --git a/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java b/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java index 5ebf110c17..3eda1d7b57 100644 --- a/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java +++ b/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java @@ -31,6 +31,8 @@ import java.io.PrintStream; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import junit.framework.TestCase; @@ -63,12 +65,21 @@ public abstract class AbstractMavenIntegrationTestCase private VersionRange versionRange; + private String matchPattern; + protected AbstractMavenIntegrationTestCase() { } protected AbstractMavenIntegrationTestCase( String versionRangeStr ) { + this( versionRangeStr, "(.*?)-(RC[0-9]+|SNAPSHOT|RC[0-9]+-SNAPSHOT)" ); + } + + protected AbstractMavenIntegrationTestCase( String versionRangeStr, String matchPattern ) + { + this.matchPattern = matchPattern; + try { versionRange = VersionRange.createFromVersionSpec( versionRangeStr ); @@ -81,7 +92,7 @@ public abstract class AbstractMavenIntegrationTestCase ArtifactVersion version = getMavenVersion(); if ( version != null ) { - skip = !versionRange.containsVersion( removeSnapshot( version ) ); + skip = !versionRange.containsVersion( removePattern( version ) ); } else { @@ -129,7 +140,7 @@ public abstract class AbstractMavenIntegrationTestCase ArtifactVersion version = getMavenVersion(); if ( version != null ) { - return versionRange.containsVersion( removeSnapshot( version ) ); + return versionRange.containsVersion( removePattern( version ) ); } else { @@ -226,12 +237,15 @@ public abstract class AbstractMavenIntegrationTestCase return localRepo; } - private static ArtifactVersion removeSnapshot( ArtifactVersion version ) + protected ArtifactVersion removePattern( ArtifactVersion version ) { String v = version.toString(); - if ( v.endsWith( "-SNAPSHOT" ) ) + + Matcher m = Pattern.compile( matchPattern ).matcher( v ); + + if ( m.matches() ) { - return new DefaultArtifactVersion( v.substring( 0, v.length() - 9 ) ); + return new DefaultArtifactVersion( m.group( 1 ) ); } return version; } diff --git a/its/core-it-support/maven-it-helper/src/test/java/org/apache/maven/it/MavenIntegrationTestCaseTest.java b/its/core-it-support/maven-it-helper/src/test/java/org/apache/maven/it/MavenIntegrationTestCaseTest.java new file mode 100644 index 0000000000..ebc48ce305 --- /dev/null +++ b/its/core-it-support/maven-it-helper/src/test/java/org/apache/maven/it/MavenIntegrationTestCaseTest.java @@ -0,0 +1,52 @@ +package org.apache.maven.it; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding 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 the License. + */ + +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.it.util.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.util.Locale; + +import junit.framework.TestCase; + +public class MavenIntegrationTestCaseTest + extends TestCase +{ + public void testRemovePattern() + { + AbstractMavenIntegrationTestCase test = new AbstractMavenIntegrationTestCase( "[2.0,)" ) {}; + assertEquals( "2.1.0-M1", test.removePattern( new DefaultArtifactVersion( "2.1.0-M1" ) ).toString() ); + assertEquals( "2.1.0-M1", test.removePattern( new DefaultArtifactVersion( "2.1.0-M1-SNAPSHOT" ) ).toString() ); + assertEquals( "2.1.0-M1", test.removePattern( new DefaultArtifactVersion( "2.1.0-M1-RC1" ) ).toString() ); + assertEquals( "2.1.0-M1", test.removePattern( new DefaultArtifactVersion( "2.1.0-M1-RC1-SNAPSHOT" ) ).toString() ); + assertEquals( "2.0.10", test.removePattern( new DefaultArtifactVersion( "2.0.10" ) ).toString() ); + assertEquals( "2.0.10", test.removePattern( new DefaultArtifactVersion( "2.0.10-SNAPSHOT" ) ).toString() ); + assertEquals( "2.0.10", test.removePattern( new DefaultArtifactVersion( "2.0.10-RC1" ) ).toString() ); + assertEquals( "2.0.10", test.removePattern( new DefaultArtifactVersion( "2.0.10-RC1-SNAPSHOT" ) ).toString() ); + } +}