From 6d84c6542573c9a139a5ec52f023f08c57982f80 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Wed, 29 Jan 2020 11:20:35 +0100 Subject: [PATCH 01/24] [MNG-4660] Add integration test to show that --resume-from works --- .../apache/maven/it/IntegrationTestSuite.java | 1 + .../it/MavenITmng4660ResumeFromTest.java | 74 +++++++++++++++++++ .../mng-4660-resume-from/module-a/pom.xml | 36 +++++++++ .../mng-4660-resume-from/module-b/pom.xml | 44 +++++++++++ .../java/org/apache/maven/it/TestCase.java | 33 +++++++++ .../resources/mng-4660-resume-from/pom.xml | 62 ++++++++++++++++ 6 files changed, 250 insertions(+) create mode 100644 core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java create mode 100644 core-it-suite/src/test/resources/mng-4660-resume-from/module-a/pom.xml create mode 100644 core-it-suite/src/test/resources/mng-4660-resume-from/module-b/pom.xml create mode 100644 core-it-suite/src/test/resources/mng-4660-resume-from/module-b/src/test/java/org/apache/maven/it/TestCase.java create mode 100644 core-it-suite/src/test/resources/mng-4660-resume-from/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 924e1fe41..f72268345 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 @@ -234,6 +234,7 @@ public static Test suite() suite.addTestSuite( MavenITmng4679SnapshotUpdateInPluginTest.class ); suite.addTestSuite( MavenITmng4677DisabledPluginConfigInheritanceTest.class ); suite.addTestSuite( MavenITmng4666CoreRealmImportTest.class ); + suite.addTestSuite( MavenITmng4660ResumeFromTest.class ); suite.addTestSuite( MavenITmng4654ArtifactHandlerForMainArtifactTest.class ); suite.addTestSuite( MavenITmng4644StrictPomParsingRejectsMisplacedTextTest.class ); // suite.addTestSuite( MavenITmng4633DualCompilerExecutionsWeaveModeTest.class ); diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java new file mode 100644 index 000000000..c1cbf660c --- /dev/null +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java @@ -0,0 +1,74 @@ +package org.apache.maven.it; + +/* + * 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. + */ + +import org.apache.maven.it.util.ResourceExtractor; + +import java.io.File; + +/** + * This is a test case for MNG-4660. + * + * @author Maarten Mulders + * @author Martin Kanters + */ +public class MavenITmng4660ResumeFromTest extends AbstractMavenIntegrationTestCase { + public MavenITmng4660ResumeFromTest() + { + // TODO Update version range once bug has been fixed! + super( "[3.6.3,)" ); + } + + /** + * Test that the --resume-from flag resolves dependencies inside the same Maven project + * without having them installed first. + */ + public void testIt() throws Exception + { + final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4660-resume-from" ); + + final Verifier verifier1 = newVerifier( testDir.getAbsolutePath() ); + verifier1.deleteDirectory( "target" ); + verifier1.deleteArtifacts( "org.apache.maven.its.mng4660" ); + + try + { + verifier1.executeGoal("verify"); + fail( "Expected this invocation to fail" ); // See TestCase.java + } + catch ( final VerificationException ve ) + { + verifier1.verifyTextInLog( "Deliberately fail test case" ); + } + finally + { + verifier1.resetStreams(); + } + + final Verifier verifier2 = newVerifier( testDir.getAbsolutePath() ); + verifier2.setAutoclean( false ); + verifier2.addCliOption( "--resume-from" ); + verifier2.addCliOption( ":module-b" ); + verifier2.executeGoal( "compile" ); // to prevent the unit test from failing (again) + + verifier2.verifyErrorFreeLog(); + verifier2.resetStreams(); + } +} diff --git a/core-it-suite/src/test/resources/mng-4660-resume-from/module-a/pom.xml b/core-it-suite/src/test/resources/mng-4660-resume-from/module-a/pom.xml new file mode 100644 index 000000000..f6e2caa98 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-4660-resume-from/module-a/pom.xml @@ -0,0 +1,36 @@ + + + + + + + 4.0.0 + + module-a + + + org.apache.maven.its.mng4660 + parent + 1.0 + + + diff --git a/core-it-suite/src/test/resources/mng-4660-resume-from/module-b/pom.xml b/core-it-suite/src/test/resources/mng-4660-resume-from/module-b/pom.xml new file mode 100644 index 000000000..e00e63b5c --- /dev/null +++ b/core-it-suite/src/test/resources/mng-4660-resume-from/module-b/pom.xml @@ -0,0 +1,44 @@ + + + + + + + 4.0.0 + + module-b + + + org.apache.maven.its.mng4660 + parent + 1.0 + + + + + org.apache.maven.its.mng4660 + module-a + 1.0 + + + + diff --git a/core-it-suite/src/test/resources/mng-4660-resume-from/module-b/src/test/java/org/apache/maven/it/TestCase.java b/core-it-suite/src/test/resources/mng-4660-resume-from/module-b/src/test/java/org/apache/maven/it/TestCase.java new file mode 100644 index 000000000..0fe241b00 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-4660-resume-from/module-b/src/test/java/org/apache/maven/it/TestCase.java @@ -0,0 +1,33 @@ +package org.apache.maven.it; + +/* + * 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. + */ + +import org.junit.Test; + +import static org.junit.Assert.fail; + +public class TestCase +{ + @Test + public void testCase() + { + fail( "Deliberately fail test case" ); + } +} \ No newline at end of file diff --git a/core-it-suite/src/test/resources/mng-4660-resume-from/pom.xml b/core-it-suite/src/test/resources/mng-4660-resume-from/pom.xml new file mode 100644 index 000000000..5fa0e49fe --- /dev/null +++ b/core-it-suite/src/test/resources/mng-4660-resume-from/pom.xml @@ -0,0 +1,62 @@ + + + + + + 4.0.0 + + org.apache.maven.its.mng4660 + parent + 1.0 + + pom + + + UTF-8 + 1.8 + 1.8 + + + + module-a + module-b + + + + + junit + junit + 4.4 + test + + + + + + + maven-compiler-plugin + 3.8.1 + + + + + From 34874103a672f4f010d87cd3796dfab443267400 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Wed, 29 Jan 2020 15:10:43 +0100 Subject: [PATCH 02/24] [MNG-4660] Change order of modules in POM --- core-it-suite/src/test/resources/mng-4660-resume-from/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-it-suite/src/test/resources/mng-4660-resume-from/pom.xml b/core-it-suite/src/test/resources/mng-4660-resume-from/pom.xml index 5fa0e49fe..a2d0bcdfc 100644 --- a/core-it-suite/src/test/resources/mng-4660-resume-from/pom.xml +++ b/core-it-suite/src/test/resources/mng-4660-resume-from/pom.xml @@ -37,8 +37,8 @@ under the License. - module-a module-b + module-a From 2f7a4b79e20e7a511910d7f6cb1507e14e1381df Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Wed, 29 Jan 2020 15:11:17 +0100 Subject: [PATCH 03/24] [MNG-4660] Introduce a compile-time dependency from module B to A --- .../java/org/apache/maven/it/Example.java | 24 +++++++++++++++++++ .../java/org/apache/maven/it/TestCase.java | 1 + 2 files changed, 25 insertions(+) create mode 100644 core-it-suite/src/test/resources/mng-4660-resume-from/module-a/src/main/java/org/apache/maven/it/Example.java diff --git a/core-it-suite/src/test/resources/mng-4660-resume-from/module-a/src/main/java/org/apache/maven/it/Example.java b/core-it-suite/src/test/resources/mng-4660-resume-from/module-a/src/main/java/org/apache/maven/it/Example.java new file mode 100644 index 000000000..1608aba21 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-4660-resume-from/module-a/src/main/java/org/apache/maven/it/Example.java @@ -0,0 +1,24 @@ +package org.apache.maven.it; + +/* + * 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. + */ + +public class Example +{ +} \ No newline at end of file diff --git a/core-it-suite/src/test/resources/mng-4660-resume-from/module-b/src/test/java/org/apache/maven/it/TestCase.java b/core-it-suite/src/test/resources/mng-4660-resume-from/module-b/src/test/java/org/apache/maven/it/TestCase.java index 0fe241b00..932ff5167 100644 --- a/core-it-suite/src/test/resources/mng-4660-resume-from/module-b/src/test/java/org/apache/maven/it/TestCase.java +++ b/core-it-suite/src/test/resources/mng-4660-resume-from/module-b/src/test/java/org/apache/maven/it/TestCase.java @@ -28,6 +28,7 @@ public class TestCase @Test public void testCase() { + final Example example = new Example(); fail( "Deliberately fail test case" ); } } \ No newline at end of file From fab1d19250dbecc19d001a30a2e52a7ab51fc528 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Fri, 14 Feb 2020 12:05:03 +0100 Subject: [PATCH 04/24] [MNG-4660] Rename test method so it's more descriptive --- .../java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java index c1cbf660c..7405cac3d 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java @@ -40,7 +40,7 @@ public MavenITmng4660ResumeFromTest() * Test that the --resume-from flag resolves dependencies inside the same Maven project * without having them installed first. */ - public void testIt() throws Exception + public void testShouldResolveDependenciesFromEarlierBuild() throws Exception { final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4660-resume-from" ); From dfe3c4b5425432b8e4aec876febf760361bf0eb4 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Fri, 14 Feb 2020 12:06:13 +0100 Subject: [PATCH 05/24] [MNG-4660] No longer necessary to first install the whole project locally --- .../java/org/apache/maven/it/MavenITmng6090CIFriendlyTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6090CIFriendlyTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6090CIFriendlyTest.java index 77b72481f..d561ef53a 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6090CIFriendlyTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6090CIFriendlyTest.java @@ -19,7 +19,6 @@ * under the License. */ -import org.apache.maven.it.Verifier; import org.apache.maven.it.util.ResourceExtractor; import java.io.File; @@ -61,7 +60,7 @@ public void testitShouldResolveTheDependencies() verifier.addCliOption( "-Drevision=1.2" ); verifier.setLogFileName( "install-log.txt" ); - verifier.executeGoals( Arrays.asList( "clean", "install" ) ); + verifier.executeGoal( "verify" ); verifier.verifyErrorFreeLog(); verifier.resetStreams(); From a19298486a3b6fe93a26d742b2a2fb1408576328 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Fri, 14 Feb 2020 13:29:38 +0100 Subject: [PATCH 06/24] [MNG-4660] Only run test for Maven 3.7.0-SNAPSHOT and up --- .../java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java index 7405cac3d..6a1788a54 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java @@ -33,7 +33,7 @@ public class MavenITmng4660ResumeFromTest extends AbstractMavenIntegrationTestCa public MavenITmng4660ResumeFromTest() { // TODO Update version range once bug has been fixed! - super( "[3.6.3,)" ); + super( "[3.7.0-SNAPSHOT,)" ); } /** From 60e6f0012dc421d3688f5716b21333e381d5ba03 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Fri, 14 Feb 2020 13:29:59 +0100 Subject: [PATCH 07/24] [MNG-4660] Remove TODO --- .../java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java index 6a1788a54..a1c6ec1dd 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java @@ -32,7 +32,6 @@ public class MavenITmng4660ResumeFromTest extends AbstractMavenIntegrationTestCase { public MavenITmng4660ResumeFromTest() { - // TODO Update version range once bug has been fixed! super( "[3.7.0-SNAPSHOT,)" ); } From 2f8a1070e9b906cde4c442260ba84ea192a9152c Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Fri, 14 Feb 2020 15:18:43 +0100 Subject: [PATCH 08/24] [MNG-4660] Formatting --- .../java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java index a1c6ec1dd..a30febf4e 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java @@ -49,7 +49,7 @@ public void testShouldResolveDependenciesFromEarlierBuild() throws Exception try { - verifier1.executeGoal("verify"); + verifier1.executeGoal( "verify" ); fail( "Expected this invocation to fail" ); // See TestCase.java } catch ( final VerificationException ve ) From 0cd4d82748b9c7008b8d12b3d7c62ae695fc7726 Mon Sep 17 00:00:00 2001 From: Martin Kanters Date: Sat, 22 Feb 2020 10:05:09 -0500 Subject: [PATCH 09/24] [MNG-4660] Corrected the Maven version to be 3.7.0 instead of -SNAPSHOT. --- .../java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java index a30febf4e..d43e79672 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java @@ -32,7 +32,7 @@ public class MavenITmng4660ResumeFromTest extends AbstractMavenIntegrationTestCase { public MavenITmng4660ResumeFromTest() { - super( "[3.7.0-SNAPSHOT,)" ); + super( "[3.7.0,)" ); } /** From 78dc7721179eaa176b7c371c85472ae3878e3917 Mon Sep 17 00:00:00 2001 From: Martin Kanters Date: Sat, 22 Feb 2020 10:07:18 -0500 Subject: [PATCH 10/24] [MNG-4660] Reverted the change in the other integration test --- .../java/org/apache/maven/it/MavenITmng6090CIFriendlyTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6090CIFriendlyTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6090CIFriendlyTest.java index d561ef53a..c1abf34f1 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6090CIFriendlyTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6090CIFriendlyTest.java @@ -60,7 +60,7 @@ public void testitShouldResolveTheDependencies() verifier.addCliOption( "-Drevision=1.2" ); verifier.setLogFileName( "install-log.txt" ); - verifier.executeGoal( "verify" ); + verifier.executeGoals( Arrays.asList( "clean", "install" ) ); verifier.verifyErrorFreeLog(); verifier.resetStreams(); From 0ddc3659a53f17bd9a7190cdf5c7d062e81cd8e6 Mon Sep 17 00:00:00 2001 From: Martin Kanters Date: Mon, 9 Mar 2020 09:34:58 +0100 Subject: [PATCH 11/24] [MNG-4660] Putting our integration test on top of the list, to order the tests from new to old (and not alphabetically on ticket number) --- .../src/test/java/org/apache/maven/it/IntegrationTestSuite.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f72268345..09aeb180c 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 @@ -107,6 +107,7 @@ public static Test suite() // ------------------------------------------------------------------------------------------------------------- // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137 + suite.addTestSuite( MavenITmng4660ResumeFromTest.class ); suite.addTestSuite( MavenITmng6759TransitiveDependencyRepositoriesTest.class ); suite.addTestSuite( MavenITmng6720FailFastTest.class ); suite.addTestSuite( MavenITmng6558ToolchainsBuildingEventTest.class ); @@ -234,7 +235,6 @@ public static Test suite() suite.addTestSuite( MavenITmng4679SnapshotUpdateInPluginTest.class ); suite.addTestSuite( MavenITmng4677DisabledPluginConfigInheritanceTest.class ); suite.addTestSuite( MavenITmng4666CoreRealmImportTest.class ); - suite.addTestSuite( MavenITmng4660ResumeFromTest.class ); suite.addTestSuite( MavenITmng4654ArtifactHandlerForMainArtifactTest.class ); suite.addTestSuite( MavenITmng4644StrictPomParsingRejectsMisplacedTextTest.class ); // suite.addTestSuite( MavenITmng4633DualCompilerExecutionsWeaveModeTest.class ); From b6dfce33d012973093086ae628da0cf1209d84a5 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Mon, 9 Mar 2020 14:46:59 +0100 Subject: [PATCH 12/24] [MNG-4660] Run test twice, once with packaged and once without packaged artifact --- .../it/MavenITmng4660ResumeFromTest.java | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java index d43e79672..6d2b471aa 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java @@ -38,8 +38,9 @@ public MavenITmng4660ResumeFromTest() /** * Test that the --resume-from flag resolves dependencies inside the same Maven project * without having them installed first. + * This test case uses the target/classes folder of module-a. */ - public void testShouldResolveDependenciesFromEarlierBuild() throws Exception + public void testShouldResolveUnpackagedArtifactFromEarlierBuild() throws Exception { final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4660-resume-from" ); @@ -49,7 +50,44 @@ public void testShouldResolveDependenciesFromEarlierBuild() throws Exception try { - verifier1.executeGoal( "verify" ); + verifier1.executeGoal( "test" ); // The test goal will not create a packaged artifact + fail( "Expected this invocation to fail" ); // See TestCase.java + } + catch ( final VerificationException ve ) + { + verifier1.verifyTextInLog( "Deliberately fail test case" ); + } + finally + { + verifier1.resetStreams(); + } + + final Verifier verifier2 = newVerifier( testDir.getAbsolutePath() ); + verifier2.setAutoclean( false ); + verifier2.addCliOption( "--resume-from" ); + verifier2.addCliOption( ":module-b" ); + verifier2.executeGoal( "compile" ); // to prevent the unit test from failing (again) + + verifier2.verifyErrorFreeLog(); + verifier2.resetStreams(); + } + + /** + * Test that the --resume-from flag resolves dependencies inside the same Maven project + * without having them installed first. + * This test case uses the packaged artifact of module-a. + */ + public void testShouldResolvePackagedArtifactFromEarlierBuild() throws Exception + { + final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4660-resume-from" ); + + final Verifier verifier1 = newVerifier( testDir.getAbsolutePath() ); + verifier1.deleteDirectory( "target" ); + verifier1.deleteArtifacts( "org.apache.maven.its.mng4660" ); + + try + { + verifier1.executeGoal( "verify" ); // The verify goal will create a packaged artifact fail( "Expected this invocation to fail" ); // See TestCase.java } catch ( final VerificationException ve ) From 726117ce369d40644bc4a21d65d4dd02ccbb1136 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Thu, 26 Mar 2020 14:02:42 +0100 Subject: [PATCH 13/24] [MNG-4660] Test case for checking whether a packaged artifact is up to date with the compiled artifact --- .../apache/maven/it/IntegrationTestSuite.java | 1 + ...avenITmng4660OutdatedPackagedArtifact.java | 91 +++++++++++++++++++ .../module-a/pom.xml | 36 ++++++++ .../java/org/apache/maven/it/Example.java | 24 +++++ .../module-b/pom.xml | 44 +++++++++ .../org/apache/maven/it/AnotherExample.java | 28 ++++++ .../java/org/apache/maven/it/TestCase.java | 31 +++++++ .../pom.xml | 62 +++++++++++++ .../org/apache/maven/it/AnotherExample.java | 28 ++++++ 9 files changed, 345 insertions(+) create mode 100644 core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java create mode 100644 core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-a/pom.xml create mode 100644 core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-a/src/main/java/org/apache/maven/it/Example.java create mode 100644 core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/pom.xml create mode 100644 core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/src/main/java/org/apache/maven/it/AnotherExample.java create mode 100644 core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/src/test/java/org/apache/maven/it/TestCase.java create mode 100644 core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/pom.xml create mode 100644 core-it-suite/src/test/resources/mng-4660-resume-from/module-b/src/main/java/org/apache/maven/it/AnotherExample.java 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 09aeb180c..3f0cbc8d1 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 @@ -108,6 +108,7 @@ public static Test suite() // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137 suite.addTestSuite( MavenITmng4660ResumeFromTest.class ); + suite.addTestSuite( MavenITmng4660OutdatedPackagedArtifact.class ); suite.addTestSuite( MavenITmng6759TransitiveDependencyRepositoriesTest.class ); suite.addTestSuite( MavenITmng6720FailFastTest.class ); suite.addTestSuite( MavenITmng6558ToolchainsBuildingEventTest.class ); diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java new file mode 100644 index 000000000..289a357c9 --- /dev/null +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java @@ -0,0 +1,91 @@ +package org.apache.maven.it; + +/* + * 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. + */ + +import org.apache.maven.it.util.ResourceExtractor; +import org.apache.maven.shared.utils.io.FileUtils; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * This is a test case for a new check introduced with MNG-4660. + * That check verifies if a packaged artifact within the Reactor is up-to-date with the outputDirectory of the same project. + * + * @author Maarten Mulders + * @author Martin Kanters + */ +public class MavenITmng4660OutdatedPackagedArtifact extends AbstractMavenIntegrationTestCase { + public MavenITmng4660OutdatedPackagedArtifact() + { + super( "[3.7.0,)" ); + } + + /** + * Test that Maven logs a warning when a packaged artifact is found that is older than the outputDirectory of the + * same artifact. + */ + public void testShouldWarnWhenPackagedArtifactIsOutdated() throws Exception + { + final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4660-outdated-packaged-artifact" ); + + // 1. Package the whole project + final Verifier verifier1 = newVerifier( testDir.getAbsolutePath() ); + verifier1.deleteDirectory( "target" ); + verifier1.deleteArtifacts( "org.apache.maven.its.mng4660" ); + + verifier1.executeGoal( "package" ); + + verifier1.verifyErrorFreeLog(); + verifier1.resetStreams(); + + + // 2. Create a properties file with some content and compile only that module (module A). + final Verifier verifier2 = newVerifier( testDir.getAbsolutePath() ); + + final Path resourcesDirectory = Files.createDirectories( Paths.get( testDir.toString(), "module-a", "src", "main", "resources" ) ); + System.err.println( "Created directory " + resourcesDirectory.toAbsolutePath().toString() ); + final Path fileToWrite = resourcesDirectory.resolve( "example.properties" ); + FileUtils.fileWrite( fileToWrite.toString(), "x=42" ); + System.err.println( "Wrote file " + fileToWrite.toAbsolutePath().toString() ); + + verifier2.setAutoclean( false ); + verifier2.addCliOption( "--projects" ); + verifier2.addCliOption( ":module-a" ); + verifier2.executeGoal( "compile" ); + + verifier2.verifyErrorFreeLog(); + verifier2.resetStreams(); + + // 3. Resume project build from module B, that depends on module A we just touched. Its packaged artifact + // is no longer in sync with its compiled artifacts. + final Verifier verifier3 = newVerifier( testDir.getAbsolutePath() ); + verifier3.setAutoclean( false ); + verifier3.addCliOption( "--resume-from" ); + verifier3.addCliOption( ":module-b" ); + verifier3.executeGoal( "compile" ); + + verifier3.verifyErrorFreeLog(); + verifier3.verifyTextInLog( "Packaged artifact is not up-to-date" ); + verifier3.resetStreams(); + } +} diff --git a/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-a/pom.xml b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-a/pom.xml new file mode 100644 index 000000000..f6e2caa98 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-a/pom.xml @@ -0,0 +1,36 @@ + + + + + + + 4.0.0 + + module-a + + + org.apache.maven.its.mng4660 + parent + 1.0 + + + diff --git a/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-a/src/main/java/org/apache/maven/it/Example.java b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-a/src/main/java/org/apache/maven/it/Example.java new file mode 100644 index 000000000..1608aba21 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-a/src/main/java/org/apache/maven/it/Example.java @@ -0,0 +1,24 @@ +package org.apache.maven.it; + +/* + * 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. + */ + +public class Example +{ +} \ No newline at end of file diff --git a/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/pom.xml b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/pom.xml new file mode 100644 index 000000000..e00e63b5c --- /dev/null +++ b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/pom.xml @@ -0,0 +1,44 @@ + + + + + + + 4.0.0 + + module-b + + + org.apache.maven.its.mng4660 + parent + 1.0 + + + + + org.apache.maven.its.mng4660 + module-a + 1.0 + + + + diff --git a/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/src/main/java/org/apache/maven/it/AnotherExample.java b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/src/main/java/org/apache/maven/it/AnotherExample.java new file mode 100644 index 000000000..20ab1874a --- /dev/null +++ b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/src/main/java/org/apache/maven/it/AnotherExample.java @@ -0,0 +1,28 @@ +package org.apache.maven.it; + +/* + * 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. + */ + +public class AnotherExample +{ + public AnotherExample() + { + new Example(); + } +} \ No newline at end of file diff --git a/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/src/test/java/org/apache/maven/it/TestCase.java b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/src/test/java/org/apache/maven/it/TestCase.java new file mode 100644 index 000000000..74a4579e5 --- /dev/null +++ b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/src/test/java/org/apache/maven/it/TestCase.java @@ -0,0 +1,31 @@ +package org.apache.maven.it; + +/* + * 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. + */ + +import org.junit.Test; + +public class TestCase +{ + @Test + public void testCase() + { + final Example example = new Example(); + } +} \ No newline at end of file diff --git a/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/pom.xml b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/pom.xml new file mode 100644 index 000000000..a2d0bcdfc --- /dev/null +++ b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/pom.xml @@ -0,0 +1,62 @@ + + + + + + 4.0.0 + + org.apache.maven.its.mng4660 + parent + 1.0 + + pom + + + UTF-8 + 1.8 + 1.8 + + + + module-b + module-a + + + + + junit + junit + 4.4 + test + + + + + + + maven-compiler-plugin + 3.8.1 + + + + + diff --git a/core-it-suite/src/test/resources/mng-4660-resume-from/module-b/src/main/java/org/apache/maven/it/AnotherExample.java b/core-it-suite/src/test/resources/mng-4660-resume-from/module-b/src/main/java/org/apache/maven/it/AnotherExample.java new file mode 100644 index 000000000..20ab1874a --- /dev/null +++ b/core-it-suite/src/test/resources/mng-4660-resume-from/module-b/src/main/java/org/apache/maven/it/AnotherExample.java @@ -0,0 +1,28 @@ +package org.apache.maven.it; + +/* + * 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. + */ + +public class AnotherExample +{ + public AnotherExample() + { + new Example(); + } +} \ No newline at end of file From 0c0896683b5b227bc2db913a5d5bd048dabdab55 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Fri, 27 Mar 2020 11:01:35 +0100 Subject: [PATCH 14/24] [MNG-4660] Remove System.err.println invocations --- .../apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java index 289a357c9..d1686963c 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java @@ -63,10 +63,8 @@ public void testShouldWarnWhenPackagedArtifactIsOutdated() throws Exception final Verifier verifier2 = newVerifier( testDir.getAbsolutePath() ); final Path resourcesDirectory = Files.createDirectories( Paths.get( testDir.toString(), "module-a", "src", "main", "resources" ) ); - System.err.println( "Created directory " + resourcesDirectory.toAbsolutePath().toString() ); final Path fileToWrite = resourcesDirectory.resolve( "example.properties" ); FileUtils.fileWrite( fileToWrite.toString(), "x=42" ); - System.err.println( "Wrote file " + fileToWrite.toAbsolutePath().toString() ); verifier2.setAutoclean( false ); verifier2.addCliOption( "--projects" ); From 405b475dd675a8c6356da2e8f5b4c4540f548555 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Fri, 27 Mar 2020 11:04:31 +0100 Subject: [PATCH 15/24] [MNG-4660] Rename method so it better describes the test Also update the Javadoc a bit to better explain what the scenario is in this case. --- .../org/apache/maven/it/MavenITmng4660ResumeFromTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java index 6d2b471aa..b223812a9 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660ResumeFromTest.java @@ -38,9 +38,10 @@ public MavenITmng4660ResumeFromTest() /** * Test that the --resume-from flag resolves dependencies inside the same Maven project * without having them installed first. - * This test case uses the target/classes folder of module-a. + * This test case uses the target/classes folder of module-a, for the situation where + * module-a has not been packaged. */ - public void testShouldResolveUnpackagedArtifactFromEarlierBuild() throws Exception + public void testShouldResolveOutputDirectoryFromEarlierBuild() throws Exception { final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4660-resume-from" ); From daac6871b5da843d0b9dcbf221fdac1956b1bae8 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Fri, 27 Mar 2020 11:30:37 +0100 Subject: [PATCH 16/24] [MNG-4660] Revert unrelated change --- .../java/org/apache/maven/it/MavenITmng6090CIFriendlyTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6090CIFriendlyTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6090CIFriendlyTest.java index c1abf34f1..77b72481f 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6090CIFriendlyTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6090CIFriendlyTest.java @@ -19,6 +19,7 @@ * under the License. */ +import org.apache.maven.it.Verifier; import org.apache.maven.it.util.ResourceExtractor; import java.io.File; From 44bb379ab75c4964c4767ca37b8eceeba53773b9 Mon Sep 17 00:00:00 2001 From: Martin Kanters Date: Sat, 28 Mar 2020 20:09:03 +0100 Subject: [PATCH 17/24] [MNG-4660] Removed the dependency on the compiler plugin --- .../MavenITmng4660OutdatedPackagedArtifact.java | 1 - .../mng-4660-outdated-packaged-artifact/pom.xml | 15 ++++++--------- .../test/resources/mng-4660-resume-from/pom.xml | 15 ++++++--------- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java index d1686963c..99dabf7b3 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java @@ -58,7 +58,6 @@ public void testShouldWarnWhenPackagedArtifactIsOutdated() throws Exception verifier1.verifyErrorFreeLog(); verifier1.resetStreams(); - // 2. Create a properties file with some content and compile only that module (module A). final Verifier verifier2 = newVerifier( testDir.getAbsolutePath() ); diff --git a/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/pom.xml b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/pom.xml index a2d0bcdfc..22df1eb38 100644 --- a/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/pom.xml +++ b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/pom.xml @@ -30,6 +30,12 @@ under the License. pom + Maven Integration Test :: MNG-4660 + + This is a test case for a new check which verifies if a packaged artifact + within the Reactor is up-to-date with the outputDirectory of the same project. + + UTF-8 1.8 @@ -50,13 +56,4 @@ under the License. - - - - maven-compiler-plugin - 3.8.1 - - - - diff --git a/core-it-suite/src/test/resources/mng-4660-resume-from/pom.xml b/core-it-suite/src/test/resources/mng-4660-resume-from/pom.xml index a2d0bcdfc..98e4f82b4 100644 --- a/core-it-suite/src/test/resources/mng-4660-resume-from/pom.xml +++ b/core-it-suite/src/test/resources/mng-4660-resume-from/pom.xml @@ -30,6 +30,12 @@ under the License. pom + Maven Integration Test :: MNG-4660 + + Test that the --resume-from flag resolves dependencies inside the same Maven project + without having them installed first. + + UTF-8 1.8 @@ -50,13 +56,4 @@ under the License. - - - - maven-compiler-plugin - 3.8.1 - - - - From 4d928bb9333f1206e47fa7c91699d749553768a8 Mon Sep 17 00:00:00 2001 From: Martin Kanters Date: Sat, 28 Mar 2020 21:37:52 +0100 Subject: [PATCH 18/24] [MNG-4660] Changed junit dependencies to version 4.12, which is the same as the testsuite itself is using. --- .../test/resources/mng-4660-outdated-packaged-artifact/pom.xml | 2 +- core-it-suite/src/test/resources/mng-4660-resume-from/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/pom.xml b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/pom.xml index 22df1eb38..565b2fc7a 100644 --- a/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/pom.xml +++ b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/pom.xml @@ -51,7 +51,7 @@ under the License. junit junit - 4.4 + 4.12 test diff --git a/core-it-suite/src/test/resources/mng-4660-resume-from/pom.xml b/core-it-suite/src/test/resources/mng-4660-resume-from/pom.xml index 98e4f82b4..1589fd08d 100644 --- a/core-it-suite/src/test/resources/mng-4660-resume-from/pom.xml +++ b/core-it-suite/src/test/resources/mng-4660-resume-from/pom.xml @@ -51,7 +51,7 @@ under the License. junit junit - 4.4 + 4.12 test From 5a15824f8f354fa7208082c1acde2cf74a9b7fcf Mon Sep 17 00:00:00 2001 From: rfscholte Date: Tue, 31 Mar 2020 21:36:04 +0200 Subject: [PATCH 19/24] Add assertions to analyze failing Linux+JDK8 --- ...avenITmng4660OutdatedPackagedArtifact.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java index 99dabf7b3..de00b93b3 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java @@ -55,22 +55,24 @@ public void testShouldWarnWhenPackagedArtifactIsOutdated() throws Exception verifier1.executeGoal( "package" ); + Path module1Jar = testDir.toPath().resolve( "module-a/target/module-a-1.0.jar" ).toAbsolutePath(); verifier1.verifyErrorFreeLog(); + verifier1.assertFilePresent( module1Jar.toString() ); verifier1.resetStreams(); // 2. Create a properties file with some content and compile only that module (module A). final Verifier verifier2 = newVerifier( testDir.getAbsolutePath() ); - - final Path resourcesDirectory = Files.createDirectories( Paths.get( testDir.toString(), "module-a", "src", "main", "resources" ) ); - final Path fileToWrite = resourcesDirectory.resolve( "example.properties" ); - FileUtils.fileWrite( fileToWrite.toString(), "x=42" ); + verifier2.deleteDirectory( "module-a/target/classes" ); verifier2.setAutoclean( false ); verifier2.addCliOption( "--projects" ); verifier2.addCliOption( ":module-a" ); verifier2.executeGoal( "compile" ); + Path module1Class = testDir.toPath().resolve( "module-a/target/classes/org/apache/maven/it/Example.class" ) + .toAbsolutePath(); verifier2.verifyErrorFreeLog(); + verifier2.assertFilePresent( module1Class.toString() ); verifier2.resetStreams(); // 3. Resume project build from module B, that depends on module A we just touched. Its packaged artifact @@ -82,7 +84,19 @@ public void testShouldWarnWhenPackagedArtifactIsOutdated() throws Exception verifier3.executeGoal( "compile" ); verifier3.verifyErrorFreeLog(); - verifier3.verifyTextInLog( "Packaged artifact is not up-to-date" ); + try + { + verifier3.verifyTextInLog( "Packaged artifact is not up-to-date" ); + } + catch ( VerificationException e ) + { + String message = e.getMessage() + System.lineSeparator(); + message += " " + module1Jar.getFileName() + " > " + Files.getLastModifiedTime( module1Jar ) + + System.lineSeparator(); + message += " " + module1Class.getFileName() + " > " + Files.getLastModifiedTime( module1Class ) + + System.lineSeparator(); + throw new VerificationException( message, e.getCause() ); + } verifier3.resetStreams(); } } From 7d07a92518af307a741a6805bd059779988f920a Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Tue, 7 Apr 2020 14:14:41 +0200 Subject: [PATCH 20/24] [MNG-4660] Add dependency on full Hamcrest package --- core-it-suite/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core-it-suite/pom.xml b/core-it-suite/pom.xml index 183021904..2850f66d9 100644 --- a/core-it-suite/pom.xml +++ b/core-it-suite/pom.xml @@ -91,6 +91,12 @@ under the License. 4.12 + + org.hamcrest + hamcrest-all + 1.3 + test + org.codehaus.plexus plexus-utils From 6555381f1a50cef526c05747743de85350d8065a Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Tue, 7 Apr 2020 14:16:39 +0200 Subject: [PATCH 21/24] [MNG-4660] Additional assertions on files being present --- .../it/MavenITmng4660OutdatedPackagedArtifact.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java index de00b93b3..d3b4c91f0 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java @@ -27,6 +27,9 @@ import java.nio.file.Path; import java.nio.file.Paths; +import static org.junit.Assert.assertThat; +import static org.hamcrest.Matchers.greaterThan; + /** * This is a test case for a new check introduced with MNG-4660. * That check verifies if a packaged artifact within the Reactor is up-to-date with the outputDirectory of the same project. @@ -62,13 +65,21 @@ public void testShouldWarnWhenPackagedArtifactIsOutdated() throws Exception // 2. Create a properties file with some content and compile only that module (module A). final Verifier verifier2 = newVerifier( testDir.getAbsolutePath() ); - verifier2.deleteDirectory( "module-a/target/classes" ); + final Path resourcesDirectory = Files.createDirectories( Paths.get( testDir.toString(), "module-a", "src", "main", "resources" ) ); + final Path fileToWrite = resourcesDirectory.resolve( "example.properties" ); + FileUtils.fileWrite( fileToWrite.toString(), "x=42" ); verifier2.setAutoclean( false ); verifier2.addCliOption( "--projects" ); verifier2.addCliOption( ":module-a" ); verifier2.executeGoal( "compile" ); + Path module1PropertiesFile = testDir.toPath().resolve( "module-a/target/classes/example.properties" ) + .toAbsolutePath(); + + verifier2.assertFilePresent( module1PropertiesFile.toString() ); + assertThat( Files.getLastModifiedTime( module1PropertiesFile ), greaterThan ( Files.getLastModifiedTime( module1Jar ) ) ); + Path module1Class = testDir.toPath().resolve( "module-a/target/classes/org/apache/maven/it/Example.class" ) .toAbsolutePath(); verifier2.verifyErrorFreeLog(); From 38d5503fcffec78380d10c197bcf9a6c05beb84c Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Tue, 7 Apr 2020 19:34:43 +0200 Subject: [PATCH 22/24] [MNG-4660] Base assertions and detailed failure message on the same info --- .../maven/it/MavenITmng4660OutdatedPackagedArtifact.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java index d3b4c91f0..ea8100f12 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java @@ -78,7 +78,8 @@ public void testShouldWarnWhenPackagedArtifactIsOutdated() throws Exception .toAbsolutePath(); verifier2.assertFilePresent( module1PropertiesFile.toString() ); - assertThat( Files.getLastModifiedTime( module1PropertiesFile ), greaterThan ( Files.getLastModifiedTime( module1Jar ) ) ); + assertThat( Files.getLastModifiedTime( module1PropertiesFile ), + greaterThan ( Files.getLastModifiedTime( module1Jar ) ) ); Path module1Class = testDir.toPath().resolve( "module-a/target/classes/org/apache/maven/it/Example.class" ) .toAbsolutePath(); @@ -102,9 +103,9 @@ public void testShouldWarnWhenPackagedArtifactIsOutdated() throws Exception catch ( VerificationException e ) { String message = e.getMessage() + System.lineSeparator(); - message += " " + module1Jar.getFileName() + " > " + Files.getLastModifiedTime( module1Jar ) + message += " " + module1Jar.getFileName() + " -> " + Files.getLastModifiedTime( module1Jar ) + System.lineSeparator(); - message += " " + module1Class.getFileName() + " > " + Files.getLastModifiedTime( module1Class ) + message += " " + module1PropertiesFile.getFileName() + " -> " + Files.getLastModifiedTime( module1PropertiesFile ) + System.lineSeparator(); throw new VerificationException( message, e.getCause() ); } From 65ffad5e430307fc490abe70a2975c95a2e686bc Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Tue, 7 Apr 2020 19:35:40 +0200 Subject: [PATCH 23/24] [MNG-4660] Add small delay between two Verifier invocations. It also makes sure we're not hit by tests that run so fast, that the difference in file modification time is too small to observe. Some combinations of Java version, OS and filesystem return that value with "just" second precision, which is not detailed enough. --- .../maven/it/MavenITmng4660OutdatedPackagedArtifact.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java index ea8100f12..983a11283 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java @@ -63,6 +63,11 @@ public void testShouldWarnWhenPackagedArtifactIsOutdated() throws Exception verifier1.assertFilePresent( module1Jar.toString() ); verifier1.resetStreams(); + // Simulating the delay between two invocations. It also makes sure we're not hit by tests that run so fast, + // that the difference in file modification time (see below) is too small to observe. Some combinations of OS + // and filesystem return that value with "just" second precision, which is not detailed enough. + Thread.sleep(1_000); + // 2. Create a properties file with some content and compile only that module (module A). final Verifier verifier2 = newVerifier( testDir.getAbsolutePath() ); final Path resourcesDirectory = Files.createDirectories( Paths.get( testDir.toString(), "module-a", "src", "main", "resources" ) ); From a6c54d5912a4a34e7cce2d500e05628ba49b65fe Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Tue, 7 Apr 2020 21:29:38 +0200 Subject: [PATCH 24/24] [MNG-4660] Share a bit more context why we're doing the ugly Thread.sleep --- .../it/MavenITmng4660OutdatedPackagedArtifact.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java index 983a11283..afc46de50 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java @@ -63,10 +63,13 @@ public void testShouldWarnWhenPackagedArtifactIsOutdated() throws Exception verifier1.assertFilePresent( module1Jar.toString() ); verifier1.resetStreams(); - // Simulating the delay between two invocations. It also makes sure we're not hit by tests that run so fast, - // that the difference in file modification time (see below) is too small to observe. Some combinations of OS - // and filesystem return that value with "just" second precision, which is not detailed enough. - Thread.sleep(1_000); + if ( System.getProperty( "java.version", "" ).startsWith( "1." ) ) + { + // Simulating the delay between two invocations. It also makes sure we're not hit by tests that run so fast, + // that the difference in file modification time (see below) is too small to observe. Java 8 on Linux and + // macOS returns that value with "just" second precision, which is not detailed enough. + Thread.sleep( 1_000 ); + } // 2. Create a properties file with some content and compile only that module (module A). final Verifier verifier2 = newVerifier( testDir.getAbsolutePath() );