From 1dedf2f3c3717552d216e9280b2abbd2b4406d6d Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Sat, 11 Oct 2008 20:53:34 +0000 Subject: [PATCH] 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 --- .../it/AbstractMavenIntegrationTestCase.java | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) 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 2ad69f3125..9629a28f14 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 @@ -19,6 +19,7 @@ package org.apache.maven.it; * 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; @@ -44,7 +45,7 @@ public abstract class AbstractMavenIntegrationTestCase private boolean skip; - private DefaultArtifactVersion version; + private ArtifactVersion mavenVersion; private VersionRange versionRange; @@ -63,22 +64,37 @@ public abstract class AbstractMavenIntegrationTestCase throw (RuntimeException) new IllegalArgumentException( "Invalid version range: " + versionRangeStr ).initCause( e ); } - String v = System.getProperty( "maven.version" ); - if ( v != null ) + ArtifactVersion version = getMavenVersion(); + if ( version != null ) { - version = new DefaultArtifactVersion( v ); - if ( !versionRange.containsVersion( version ) ) - { - skip = true; - } + skip = !versionRange.containsVersion( version ); } else { 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 null 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 * 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 ) { + VersionRange versionRange; try { versionRange = VersionRange.createFromVersionSpec( versionRangeStr ); @@ -95,16 +112,15 @@ public abstract class AbstractMavenIntegrationTestCase throw (RuntimeException) new IllegalArgumentException( "Invalid version range: " + versionRangeStr ).initCause( e ); } - String v = System.getProperty( "maven.version" ); - if ( v != null ) + ArtifactVersion version = getMavenVersion(); + if ( version != null ) { - version = new DefaultArtifactVersion( v ); return versionRange.containsVersion( version ); } else { 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; } @@ -117,7 +133,7 @@ public abstract class AbstractMavenIntegrationTestCase if ( skip ) { - out.println( " Skipping (version " + version + " not in range " + versionRange + ")" ); + out.println( " Skipping - version " + getMavenVersion() + " not in range " + versionRange ); return; }