From 3bcfddafaa85e2ad6279bbffb13d4fd676124c31 Mon Sep 17 00:00:00 2001 From: Christian Schulte Date: Sat, 30 Jan 2016 20:21:33 +0100 Subject: [PATCH] [MNG-4463] Dependency management import should support version ranges This closes #28 --- .../apache/maven/it/IntegrationTestSuite.java | 1 + ...pendencyManagementImportVersionRanges.java | 111 ++++++++++++++++++ .../mng-4463/exclusive-upper-bound/pom.xml | 76 ++++++++++++ .../mng-4463/inclusive-upper-bound/pom.xml | 76 ++++++++++++ .../resources/mng-4463/no-upper-bound/pom.xml | 54 +++++++++ 5 files changed, 318 insertions(+) create mode 100644 core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4463DependencyManagementImportVersionRanges.java create mode 100644 core-it-suite/src/test/resources/mng-4463/exclusive-upper-bound/pom.xml create mode 100644 core-it-suite/src/test/resources/mng-4463/inclusive-upper-bound/pom.xml create mode 100644 core-it-suite/src/test/resources/mng-4463/no-upper-bound/pom.xml diff --git a/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java b/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java index 1fa03f977..dd811f9fa 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java @@ -106,6 +106,7 @@ public static Test suite() // Tests that don't run stable and need to be fixed // ------------------------------------------------------------------------------------------------------------- // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137 + suite.addTestSuite( MavenITmng4463DependencyManagementImportVersionRanges.class ); suite.addTestSuite( MavenITmng7112ProjectsWithNonRecursiveTest.class ); suite.addTestSuite( MavenITmng7128BlockExternalHttpReactorTest.class ); suite.addTestSuite( MavenITmng6511OptionalProjectSelectionTest.class ); diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4463DependencyManagementImportVersionRanges.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4463DependencyManagementImportVersionRanges.java new file mode 100644 index 000000000..5a04496e2 --- /dev/null +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4463DependencyManagementImportVersionRanges.java @@ -0,0 +1,111 @@ +/* + * 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. + */ +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; +import static junit.framework.Assert.assertTrue; + +/** + * Integration tests for MNG-4463. + * + * @author Christian Schulte + */ +public class MavenITmng4463DependencyManagementImportVersionRanges + extends AbstractMavenIntegrationTestCase +{ + + public MavenITmng4463DependencyManagementImportVersionRanges() + { + super( "[4.0.0-alpha-1,)" ); + } + + public void testInclusiveUpperBoundResolvesToHighestVersion() + throws Exception + { + final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4463/inclusive-upper-bound" ); + final Verifier verifier = newVerifier( testDir.getAbsolutePath(), "remote" ); + verifier.setAutoclean( false ); + verifier.deleteDirectory( "target" ); + verifier.executeGoal( "validate" ); + verifier.verifyErrorFreeLog(); + verifier.resetStreams(); + + final List artifacts = verifier.loadLines( "target/compile.txt", "UTF-8" ); + assertTrue( artifacts.toString(), artifacts.contains( "org.apache.maven:maven-plugin-api:jar:3.0" ) ); + } + + public void testExclusiveUpperBoundResolvesToHighestVersion() + throws Exception + { + final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4463/exclusive-upper-bound" ); + final Verifier verifier = newVerifier( testDir.getAbsolutePath(), "remote" ); + verifier.setAutoclean( false ); + verifier.deleteDirectory( "target" ); + verifier.executeGoal( "validate" ); + verifier.verifyErrorFreeLog(); + verifier.resetStreams(); + + List artifacts = verifier.loadLines( "target/compile.txt", "UTF-8" ); + assertTrue( artifacts.toString(), artifacts.contains( "org.apache.maven:maven-plugin-api:jar:3.0" ) ); + } + + public void testFailureWithoutUpperBound() + throws Exception + { + final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4463/no-upper-bound" ); + final Verifier verifier = newVerifier( testDir.getAbsolutePath(), "remote" ); + + try + { + verifier.setAutoclean( false ); + verifier.deleteDirectory( "target" ); + verifier.executeGoal( "validate" ); + fail( "Expected 'VerificationException' not thrown." ); + } + catch ( final VerificationException e ) + { + final List lines = verifier.loadFile( new File( testDir, "log.txt" ), false ); + assertTrue( "Expected error message not found.", + indexOf( lines, ".*dependency version range.*does not specify an upper bound.*" ) >= 0 ); + } + finally + { + verifier.resetStreams(); + } + } + + private static int indexOf( final List 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; + } + +} diff --git a/core-it-suite/src/test/resources/mng-4463/exclusive-upper-bound/pom.xml b/core-it-suite/src/test/resources/mng-4463/exclusive-upper-bound/pom.xml new file mode 100644 index 000000000..54404ac24 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-4463/exclusive-upper-bound/pom.xml @@ -0,0 +1,76 @@ + + + + + + 4.0.0 + + org.apache.maven.its.mng4463 + test + 1.0 + jar + + Maven Integration Test :: MNG-4463 + + Tests that importing dependency management using version ranges + with exclusive upper bound resolves to the highest version. + + + + + + org.apache.maven + maven + (,3.0.1) + pom + import + + + + + + + org.apache.maven + maven-plugin-api + + + + + + + org.apache.maven.its.plugins + maven-it-plugin-dependency-resolution + 2.1-SNAPSHOT + + target/compile.txt + + + + test + validate + + compile + + + + + + + diff --git a/core-it-suite/src/test/resources/mng-4463/inclusive-upper-bound/pom.xml b/core-it-suite/src/test/resources/mng-4463/inclusive-upper-bound/pom.xml new file mode 100644 index 000000000..0e91b01e7 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-4463/inclusive-upper-bound/pom.xml @@ -0,0 +1,76 @@ + + + + + + 4.0.0 + + org.apache.maven.its.mng4463 + test + 1.0 + jar + + Maven Integration Test :: MNG-4463 + + Tests that importing dependency management using version ranges + with inclusive upper bound resolves to the highest version. + + + + + + org.apache.maven + maven + (,3.0] + pom + import + + + + + + + org.apache.maven + maven-plugin-api + + + + + + + org.apache.maven.its.plugins + maven-it-plugin-dependency-resolution + 2.1-SNAPSHOT + + target/compile.txt + + + + test + validate + + compile + + + + + + + diff --git a/core-it-suite/src/test/resources/mng-4463/no-upper-bound/pom.xml b/core-it-suite/src/test/resources/mng-4463/no-upper-bound/pom.xml new file mode 100644 index 000000000..53ec4e313 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-4463/no-upper-bound/pom.xml @@ -0,0 +1,54 @@ + + + + + + 4.0.0 + + org.apache.maven.its.mng4463 + test + 1.0 + jar + + Maven Integration Test :: MNG-4463 + + Tests that importing dependency management using version ranges + without upper bound fails. + + + + + + org.apache.maven + maven + (3.0,) + pom + import + + + + + + + org.apache.maven + maven-plugin-api + + +