o Cured "Skipping (version ${maven.version} not in range (2.0.8,))" when using -Dtest=

git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@703729 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2008-10-11 20:53:34 +00:00
parent ff0df914e2
commit 1dedf2f3c3
1 changed files with 30 additions and 14 deletions

View File

@ -19,6 +19,7 @@ package org.apache.maven.it;
* under the License. * under the License.
*/ */
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.artifact.versioning.VersionRange;
@ -44,7 +45,7 @@ public abstract class AbstractMavenIntegrationTestCase
private boolean skip; private boolean skip;
private DefaultArtifactVersion version; private ArtifactVersion mavenVersion;
private VersionRange versionRange; private VersionRange versionRange;
@ -63,22 +64,37 @@ public abstract class AbstractMavenIntegrationTestCase
throw (RuntimeException) new IllegalArgumentException( "Invalid version range: " + versionRangeStr ).initCause( e ); throw (RuntimeException) new IllegalArgumentException( "Invalid version range: " + versionRangeStr ).initCause( e );
} }
String v = System.getProperty( "maven.version" ); ArtifactVersion version = getMavenVersion();
if ( v != null ) if ( version != null )
{ {
version = new DefaultArtifactVersion( v ); skip = !versionRange.containsVersion( version );
if ( !versionRange.containsVersion( version ) )
{
skip = true;
}
} }
else else
{ {
out.println( "WARNING: " + getITName() + ": version range '" + versionRange out.println( "WARNING: " + getITName() + ": version range '" + versionRange
+ "' supplied but no maven version - not skipping test." ); + "' supplied but no Maven version - not skipping test." );
} }
} }
/**
* Gets the Maven version used to run this test.
*
* @return The Maven version or <code>null</code> if unknown.
*/
private ArtifactVersion getMavenVersion()
{
if ( mavenVersion == null )
{
String v = System.getProperty( "maven.version" );
// NOTE: If the version looks like "${...}" it has been configured from an undefined expression
if ( v != null && v.length() > 0 && !v.startsWith( "${" ) )
{
mavenVersion = new DefaultArtifactVersion( v );
}
}
return mavenVersion;
}
/** /**
* This allows fine-grained control over execution of individual test methods * This allows fine-grained control over execution of individual test methods
* by allowing tests to adjust to the current maven version, or else simply avoid * by allowing tests to adjust to the current maven version, or else simply avoid
@ -86,6 +102,7 @@ public abstract class AbstractMavenIntegrationTestCase
*/ */
protected boolean matchesVersionRange( String versionRangeStr ) protected boolean matchesVersionRange( String versionRangeStr )
{ {
VersionRange versionRange;
try try
{ {
versionRange = VersionRange.createFromVersionSpec( versionRangeStr ); versionRange = VersionRange.createFromVersionSpec( versionRangeStr );
@ -95,16 +112,15 @@ public abstract class AbstractMavenIntegrationTestCase
throw (RuntimeException) new IllegalArgumentException( "Invalid version range: " + versionRangeStr ).initCause( e ); throw (RuntimeException) new IllegalArgumentException( "Invalid version range: " + versionRangeStr ).initCause( e );
} }
String v = System.getProperty( "maven.version" ); ArtifactVersion version = getMavenVersion();
if ( v != null ) if ( version != null )
{ {
version = new DefaultArtifactVersion( v );
return versionRange.containsVersion( version ); return versionRange.containsVersion( version );
} }
else else
{ {
out.println( "WARNING: " + getITName() + ": version range '" + versionRange out.println( "WARNING: " + getITName() + ": version range '" + versionRange
+ "' supplied but no maven version found - returning true for match check." ); + "' supplied but no Maven version found - returning true for match check." );
return true; return true;
} }
@ -117,7 +133,7 @@ public abstract class AbstractMavenIntegrationTestCase
if ( skip ) if ( skip )
{ {
out.println( " Skipping (version " + version + " not in range " + versionRange + ")" ); out.println( " Skipping - version " + getMavenVersion() + " not in range " + versionRange );
return; return;
} }