Version ranges not supported for parent artifacts

Fixes #21
Signed-off-by: Jason van Zyl <jason@tesla.io>
This commit is contained in:
Christian Schulte 2014-06-13 22:27:14 +02:00 committed by Jason van Zyl
parent af10f0efad
commit 57d79f3a3a
7 changed files with 259 additions and 0 deletions

View File

@ -106,6 +106,7 @@ public class IntegrationTestSuite
// -------------------------------------------------------------------------------------------------------------
// suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
suite.addTestSuite( MavenITmng2199ParentVersionRangeTest.class );
suite.addTestSuite( MavenITmng5640LifecycleParticipantAfterSessionEnd.class );
suite.addTestSuite( MavenITmng5639ImportScopePomResolutionTest.class );
suite.addTestSuite( MavenITmng5608ProfileActivationWarningTest.class );

View File

@ -0,0 +1,174 @@
/*
* Copyright 2014 The Apache Software Foundation.
*
* Licensed 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.
*/
package org.apache.maven.it;
import java.io.File;
import java.util.List;
import java.util.regex.Pattern;
import org.apache.maven.it.util.ResourceExtractor;
public class MavenITmng2199ParentVersionRangeTest
extends AbstractMavenIntegrationTestCase
{
public MavenITmng2199ParentVersionRangeTest()
{
super( "[3.2.2,)" );
}
public void testValidParentVersionRangeWithInclusiveUpperBound()
throws Exception
{
Verifier verifier = null;
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2199-parent-version-range/valid-inclusive-upper-bound" );
try
{
verifier = newVerifier( testDir.getAbsolutePath(), "remote" );
verifier.addCliOption( "-U" );
verifier.setAutoclean( false );
verifier.executeGoal( "verify" );
verifier.verifyErrorFreeLog();
}
finally
{
verifier.resetStreams();
}
}
public void testValidParentVersionRangeWithExclusiveUpperBound()
throws Exception
{
Verifier verifier = null;
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2199-parent-version-range/valid-exclusive-upper-bound" );
try
{
verifier = newVerifier( testDir.getAbsolutePath(), "remote" );
verifier.addCliOption( "-U" );
verifier.setAutoclean( false );
verifier.executeGoal( "verify" );
verifier.verifyErrorFreeLog();
}
finally
{
verifier.resetStreams();
}
}
public void testInvalidParentVersionRange()
throws Exception
{
Verifier verifier = null;
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2199-parent-version-range/invalid" );
try
{
verifier = newVerifier( testDir.getAbsolutePath(), "remote" );
verifier.setAutoclean( false );
verifier.addCliOption( "-U" );
verifier.executeGoal( "verify" );
fail( "Expected 'VerificationException' not thrown." );
}
catch ( final VerificationException e )
{
final List<String> lines = verifier.loadFile( new File( testDir, "log.txt" ), false );
int msg = indexOf( lines, ".*The requested version range.*does not specify an upper bound.*" );
assertTrue( "Expected error message not found.", msg >= 0 );
}
finally
{
verifier.resetStreams();
}
}
public void testValidParentVersionRangeInvalidVersionExpression()
throws Exception
{
Verifier verifier = null;
File testDir =
ResourceExtractor.simpleExtractResources( getClass(), "/mng-2199-parent-version-range/expression" );
try
{
verifier = newVerifier( testDir.getAbsolutePath(), "remote" );
verifier.setAutoclean( false );
verifier.addCliOption( "-U" );
verifier.executeGoal( "verify" );
fail( "Expected 'VerificationException' not thrown." );
}
catch ( final VerificationException e )
{
final List<String> lines = verifier.loadFile( new File( testDir, "log.txt" ), false );
int msg =
indexOf( lines,
".*Version must be a constant @ org.apache.maven.its.mng2199:expression:\\$\\{project.parent.version\\}.*" );
assertTrue( "Expected error message not found.", msg >= 0 );
}
finally
{
verifier.resetStreams();
}
}
public void testValidParentVersionRangeInvalidVersionInheritance()
throws Exception
{
Verifier verifier = null;
File testDir =
ResourceExtractor.simpleExtractResources( getClass(), "/mng-2199-parent-version-range/inherited" );
try
{
verifier = newVerifier( testDir.getAbsolutePath(), "remote" );
verifier.setAutoclean( false );
verifier.addCliOption( "-U" );
verifier.executeGoal( "verify" );
fail( "Expected 'VerificationException' not thrown." );
}
catch ( final VerificationException e )
{
final List<String> lines = verifier.loadFile( new File( testDir, "log.txt" ), false );
int msg =
indexOf( lines,
".*Version must be a constant @ org.apache.maven.its.mng2199:inherited:\\[unknown-version\\].*" );
assertTrue( "Expected error message not found.", msg >= 0 );
}
finally
{
verifier.resetStreams();
}
}
private static int indexOf( final List<String> logLines, final String regex )
{
final Pattern pattern = Pattern.compile( regex );
for ( int i = 0, l0 = logLines.size(); i < l0; i++ )
{
if ( pattern.matcher( logLines.get( i ) ).matches() )
{
return i;
}
}
return -1;
}
}

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache</groupId>
<artifactId>apache</artifactId>
<version>[1,14]</version>
</parent>
<groupId>org.apache.maven.its.mng2199</groupId>
<artifactId>expression</artifactId>
<version>${project.parent.version}</version>
<packaging>pom</packaging>
<name>Maven Integration Test :: MNG-2199 :: Invalid Version Expression</name>
<description>Verifies that the build fails when using a parent version range in combination with a version expression.</description>
</project>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache</groupId>
<artifactId>apache</artifactId>
<version>[1,14]</version>
</parent>
<groupId>org.apache.maven.its.mng2199</groupId>
<artifactId>inherited</artifactId>
<packaging>pom</packaging>
<name>Maven Integration Test :: MNG-2199 :: Version invalidly inherited</name>
<description>Verifies that the build fails when using a parent version range in combination with an inherited version.</description>
</project>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache</groupId>
<artifactId>apache</artifactId>
<version>[1,)</version>
</parent>
<groupId>org.apache.maven.its.mng2199</groupId>
<artifactId>invalid</artifactId>
<version>1</version>
<packaging>pom</packaging>
<name>Maven Integration Test :: MNG-2199 :: Valid POM</name>
<description>Verifies that the build fails when using an invalid parent version range without an upper bound.</description>
</project>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache</groupId>
<artifactId>apache</artifactId>
<version>[1,15)</version>
</parent>
<groupId>org.apache.maven.its.mng2199</groupId>
<artifactId>valid</artifactId>
<version>1</version>
<packaging>pom</packaging>
<name>Maven Integration Test :: MNG-2199 :: Valid POM</name>
<description>Verifies that the build succeeds when using a valid parent version range and a constant version.</description>
</project>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache</groupId>
<artifactId>apache</artifactId>
<version>[1,14]</version>
</parent>
<groupId>org.apache.maven.its.mng2199</groupId>
<artifactId>valid</artifactId>
<version>1</version>
<packaging>pom</packaging>
<name>Maven Integration Test :: MNG-2199 :: Valid POM</name>
<description>Verifies that the build succeeds when using a valid parent version range and a constant version.</description>
</project>