diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng2199ParentVersionRangeTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng2199ParentVersionRangeTest.java index 16ac91cc72..4f1b3aa013 100644 --- a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng2199ParentVersionRangeTest.java +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng2199ParentVersionRangeTest.java @@ -32,8 +32,11 @@ public class MavenITmng2199ParentVersionRangeTest public void testValidParentVersionRangeWithInclusiveUpperBound() throws Exception { + failingMavenVersions( "(3.2.2,3.5.0)" ); Verifier verifier = null; - File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2199-parent-version-range/valid-inclusive-upper-bound" ); + File testDir = + ResourceExtractor.simpleExtractResources( getClass(), + "/mng-2199-parent-version-range/valid-inclusive-upper-bound" ); try { @@ -43,18 +46,31 @@ public class MavenITmng2199ParentVersionRangeTest verifier.executeGoal( "verify" ); verifier.verifyErrorFreeLog(); + + // All Maven versions not supporting remote parent version ranges will log a warning message whenever + // building a parent fails. The build succeeds without any parent. If that warning message appears in the + // log, parent resolution failed. + final List lines = verifier.loadFile( new File( testDir, "log.txt" ), false ); + assertFalse( "Unxpected error message found.", + indexOf( lines, ".*Failed to build parent project.*" ) >= 0 ); + } finally { - verifier.resetStreams(); + if ( verifier != null ) + { + verifier.resetStreams(); + } } } public void testValidParentVersionRangeWithExclusiveUpperBound() throws Exception { + failingMavenVersions( "(3.2.2,3.5.0)" ); Verifier verifier = null; - File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2199-parent-version-range/valid-exclusive-upper-bound" ); + File testDir = ResourceExtractor.simpleExtractResources( + getClass(), "/mng-2199-parent-version-range/valid-exclusive-upper-bound" ); try { @@ -64,14 +80,25 @@ public class MavenITmng2199ParentVersionRangeTest verifier.executeGoal( "verify" ); verifier.verifyErrorFreeLog(); + + // All Maven versions not supporting remote parent version ranges will log a warning message whenever + // building a parent fails. The build succeeds without any parent. If that warning message appears in the + // log, parent resolution failed. + final List lines = verifier.loadFile( new File( testDir, "log.txt" ), false ); + assertFalse( "Unxpected error message found.", + indexOf( lines, ".*Failed to build parent project.*" ) >= 0 ); + } finally { - verifier.resetStreams(); + if ( verifier != null ) + { + verifier.resetStreams(); + } } } - public void testInvalidParentVersionRange() + public void testInvalidParentVersionRangeWithoutUpperBound() throws Exception { Verifier verifier = null; @@ -87,13 +114,18 @@ public class MavenITmng2199ParentVersionRangeTest } catch ( final VerificationException e ) { + assertNotNull( verifier ); final List 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 ); + assertTrue( "Expected error message not found.", + indexOf( lines, ".*(parent)? version range.*does not specify an upper bound.*" ) >= 0 ); + } finally { - verifier.resetStreams(); + if ( verifier != null ) + { + verifier.resetStreams(); + } } } @@ -101,8 +133,8 @@ public class MavenITmng2199ParentVersionRangeTest throws Exception { Verifier verifier = null; - File testDir = - ResourceExtractor.simpleExtractResources( getClass(), "/mng-2199-parent-version-range/expression" ); + File testDir = ResourceExtractor.simpleExtractResources( + getClass(), "/mng-2199-parent-version-range/expression" ); try { @@ -114,16 +146,17 @@ public class MavenITmng2199ParentVersionRangeTest } catch ( final VerificationException e ) { + assertNotNull( verifier ); final List 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\\}.*" ); - + int msg = indexOf( lines, ".*Version must be a constant.*org.apache.maven.its.mng2199:expression.*" ); assertTrue( "Expected error message not found.", msg >= 0 ); } finally { - verifier.resetStreams(); + if ( verifier != null ) + { + verifier.resetStreams(); + } } } @@ -131,8 +164,8 @@ public class MavenITmng2199ParentVersionRangeTest throws Exception { Verifier verifier = null; - File testDir = - ResourceExtractor.simpleExtractResources( getClass(), "/mng-2199-parent-version-range/inherited" ); + File testDir = ResourceExtractor.simpleExtractResources( + getClass(), "/mng-2199-parent-version-range/inherited" ); try { @@ -144,37 +177,175 @@ public class MavenITmng2199ParentVersionRangeTest } catch ( final VerificationException e ) { + assertNotNull( verifier ); final List 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\\].*" ); - + int msg = indexOf( lines, ".*Version must be a constant.*org.apache.maven.its.mng2199:inherited.*" ); assertTrue( "Expected error message not found.", msg >= 0 ); } finally { - verifier.resetStreams(); + if ( verifier != null ) + { + verifier.resetStreams(); + } } } public void testValidLocalParentVersionRange() throws Exception { + failingMavenVersions( "(,3.3.0),(3.3.9,3.5.0)" ); Verifier verifier = null; - File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2199-parent-version-range/local-parent" ); + File testDir = ResourceExtractor.simpleExtractResources( + getClass(), "/mng-2199-parent-version-range/valid-local/child" ); + + try + { + verifier = newVerifier( testDir.getAbsolutePath() ); + verifier.executeGoal( "verify" ); + verifier.verifyErrorFreeLog(); + + // All Maven versions not supporting remote parent version ranges will log a warning message whenever + // building a parent fails. The build succeeds without any parent. If that warning message appears in the + // log, parent resolution failed. For this test, this really just tests the project on disk getting tested + // is not corrupt. It's expected to find the local parent and not fall back to remote resolution. If it + // falls back to remote resolution, this just catches the test project to be broken. + final List lines = verifier.loadFile( new File( testDir, "log.txt" ), false ); + assertFalse( "Unxpected error message found.", + indexOf( lines, ".*Failed to build parent project.*" ) >= 0 ); + + } + finally + { + if ( verifier != null ) + { + verifier.resetStreams(); + } + } + } + + public void testInvalidLocalParentVersionRange() + throws Exception + { + failingMavenVersions( "[3.3.0,3.3.9)" ); + // Fallback to remote resolution not tested here. Remote parent expected to not be available anywhere. + Verifier verifier = null; + File testDir = ResourceExtractor.simpleExtractResources( + getClass(), "/mng-2199-parent-version-range/invalid-local/child" ); + + try + { + verifier = newVerifier( testDir.getAbsolutePath() ); + verifier.executeGoal( "verify" ); + fail( "Expected 'VerificationException' not thrown." ); + } + catch ( final VerificationException e ) + { + assertNotNull( verifier ); + final List lines = verifier.loadFile( new File( testDir, "log.txt" ), false ); + int msg = indexOf( lines, + ".*Non-resolvable parent POM org.apache.maven.its.mng2199:local-parent:\\[2,3\\].*" ); + assertTrue( "Expected error message not found.", msg >= 0 ); + } + finally + { + if ( verifier != null ) + { + verifier.resetStreams(); + } + } + } + + public void testInvalidLocalParentVersionRangeFallingBackToRemote() + throws Exception + { + failingMavenVersions( "[3.3.9]" ); + Verifier verifier = null; + File testDir = ResourceExtractor.simpleExtractResources( + getClass(), "/mng-2199-parent-version-range/local-fallback-to-remote/child" ); try { verifier = newVerifier( testDir.getAbsolutePath(), "remote" ); - verifier.addCliOption( "-U" ); - verifier.setAutoclean( false ); - verifier.executeGoal( "verify" ); verifier.verifyErrorFreeLog(); + + // All Maven versions not supporting remote parent version ranges will log a warning message whenever + // building a parent fails. The build succeeds without any parent. If that warning message appears in the + // log, parent resolution failed. For this test, local parent resolution falls back to remote parent + // resolution with a version range in use. If the warning message is in the logs, that remote parent + // resolution failed unexpectedly. + final List lines = verifier.loadFile( new File( testDir, "log.txt" ), false ); + assertFalse( "Unxpected error message found.", + indexOf( lines, ".*Failed to build parent project.*" ) >= 0 ); + } finally { - verifier.resetStreams(); + if ( verifier != null ) + { + verifier.resetStreams(); + } + } + } + + public void testValidLocalParentVersionRangeInvalidVersionExpression() + throws Exception + { + failingMavenVersions( "(,3.5.0)" ); + Verifier verifier = null; + File testDir = ResourceExtractor.simpleExtractResources( + getClass(), "/mng-2199-parent-version-range/expression-local/child" ); + + try + { + verifier = newVerifier( testDir.getAbsolutePath() ); + verifier.executeGoal( "verify" ); + fail( "Expected 'VerificationException' not thrown." ); + } + catch ( final VerificationException e ) + { + assertNotNull( verifier ); + final List lines = verifier.loadFile( new File( testDir, "log.txt" ), false ); + int msg = indexOf( lines, ".*Version must be a constant.*org.apache.maven.its.mng2199:expression.*" ); + assertTrue( "Expected error message not found.", msg >= 0 ); + } + finally + { + if ( verifier != null ) + { + verifier.resetStreams(); + } + } + } + + public void testValidLocalParentVersionRangeInvalidVersionInheritance() + throws Exception + { + failingMavenVersions( "(,3.5.0)" ); + Verifier verifier = null; + File testDir = ResourceExtractor.simpleExtractResources( + getClass(), "/mng-2199-parent-version-range/inherited-local/child" ); + + try + { + verifier = newVerifier( testDir.getAbsolutePath() ); + verifier.executeGoal( "verify" ); + fail( "Expected 'VerificationException' not thrown." ); + } + catch ( final VerificationException e ) + { + assertNotNull( verifier ); + final List lines = verifier.loadFile( new File( testDir, "log.txt" ), false ); + int msg = indexOf( lines, ".*Version must be a constant.*org.apache.maven.its.mng2199:inherited.*" ); + assertTrue( "Expected error message not found.", msg >= 0 ); + } + finally + { + if ( verifier != null ) + { + verifier.resetStreams(); + } } } @@ -192,4 +363,5 @@ public class MavenITmng2199ParentVersionRangeTest return -1; } + } diff --git a/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/expression-local/child/pom.xml b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/expression-local/child/pom.xml new file mode 100644 index 0000000000..39a2210b69 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/expression-local/child/pom.xml @@ -0,0 +1,12 @@ + + + + org.apache.maven.its.mng2199 + local-parent + [1,2] + + 4.0.0 + expression + + ${project.parent.version} + diff --git a/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/expression-local/pom.xml b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/expression-local/pom.xml new file mode 100644 index 0000000000..dfa12d6d09 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/expression-local/pom.xml @@ -0,0 +1,10 @@ + + + 4.0.0 + org.apache.maven.its.mng2199 + local-parent + 1 + pom + Maven Integration Test :: MNG-2199 :: Invalid Local Version Expression + Verifies that the build fails when using a parent version range in combination with a version expression for local parent resolution. + diff --git a/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/inherited-local/child/pom.xml b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/inherited-local/child/pom.xml new file mode 100644 index 0000000000..9d54edd7ad --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/inherited-local/child/pom.xml @@ -0,0 +1,11 @@ + + + + org.apache.maven.its.mng2199 + local-parent + [1,2] + + 4.0.0 + inherited + + diff --git a/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/inherited-local/pom.xml b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/inherited-local/pom.xml new file mode 100644 index 0000000000..bcf66bf116 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/inherited-local/pom.xml @@ -0,0 +1,10 @@ + + + 4.0.0 + org.apache.maven.its.mng2199 + local-parent + 1 + pom + Maven Integration Test :: MNG-2199 :: Invalid Local Version Inheritance + Verifies that the build fails when using a parent version range in combination with an inherited version. + diff --git a/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/invalid-local/child/pom.xml b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/invalid-local/child/pom.xml new file mode 100644 index 0000000000..d9498d5425 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/invalid-local/child/pom.xml @@ -0,0 +1,12 @@ + + + + org.apache.maven.its.mng2199 + local-parent + + [2,3] + + 4.0.0 + invalid + 1 + diff --git a/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/invalid-local/pom.xml b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/invalid-local/pom.xml new file mode 100644 index 0000000000..4e646fcb3d --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/invalid-local/pom.xml @@ -0,0 +1,10 @@ + + + 4.0.0 + org.apache.maven.its.mng2199 + local-parent + 1 + pom + Maven Integration Test :: MNG-2199 :: Invalid Local Parent Version + Verifies that the build fails when using a parent version range not matching what is on disk (fallback to remote is not tested here - the parent does not exist anywhere but on disk). + diff --git a/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/local-fallback-to-remote/child/pom.xml b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/local-fallback-to-remote/child/pom.xml new file mode 100644 index 0000000000..346df47a7f --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/local-fallback-to-remote/child/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + + + org.apache + apache + + [1,15) + + org.apache.maven.its.mng2199 + valid + 1 + pom + + Maven Integration Test :: MNG-2199 :: Valid POM + Verifies that the build succeeds by falling back to remote parent resolution when the local parent does not mach the range. + diff --git a/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/local-fallback-to-remote/pom.xml b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/local-fallback-to-remote/pom.xml new file mode 100644 index 0000000000..fa4eb5203e --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/local-fallback-to-remote/pom.xml @@ -0,0 +1,8 @@ + + + 4.0.0 + org.apache + apache + DOES NOT EXIST + pom + diff --git a/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/local-parent/pom.xml b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/local-parent/pom.xml deleted file mode 100644 index 1238de157a..0000000000 --- a/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/local-parent/pom.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - 4.0.0 - - org.apache.maven.its.mng2199 - local-parent - 1.1 - pom - - Maven Integration Test :: MNG-2199 :: Local Parent POM - Verifies that the build succeeds when using a valid parent version range that matches local parent. - - - module - - diff --git a/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/local-parent/module/pom.xml b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/valid-local/child/pom.xml similarity index 70% rename from its/core-it-suite/src/test/resources/mng-2199-parent-version-range/local-parent/module/pom.xml rename to its/core-it-suite/src/test/resources/mng-2199-parent-version-range/valid-local/child/pom.xml index 85769ce5af..e61f9085e8 100644 --- a/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/local-parent/module/pom.xml +++ b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/valid-local/child/pom.xml @@ -1,13 +1,11 @@ - 4.0.0 - org.apache.maven.its.mng2199 local-parent - [1.0,2) + [1,2] - - local-parent-module - + 4.0.0 + valid + 3.4.5 diff --git a/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/valid-local/pom.xml b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/valid-local/pom.xml new file mode 100644 index 0000000000..559f3aecef --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-2199-parent-version-range/valid-local/pom.xml @@ -0,0 +1,10 @@ + + + 4.0.0 + org.apache.maven.its.mng2199 + local-parent + 1 + pom + Maven Integration Test :: MNG-2199 :: Valid Local Parent Version Range + Verifies that the build succeeds when using a parent version range for local parent resolution. +