From f8fe3ea3cc31aacef49864b1de2f82c815aaa9ca Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Wed, 3 May 2023 19:39:42 +0200 Subject: [PATCH] [MRRESOURCES-131] Fix ITs for Maven 4 --- pom.xml | 2 ++ src/it/resources/bad-dependency-poms/pom.xml | 5 ++- .../remote/it/IT_BadDependencyPoms.java | 32 +++++------------- .../remote/it/IT_GetDependencyProjects.java | 33 ++++++------------- .../remote/it/support/BootstrapInstaller.java | 5 ++- 5 files changed, 27 insertions(+), 50 deletions(-) diff --git a/pom.xml b/pom.xml index f5c9a0e..37e0cc2 100644 --- a/pom.xml +++ b/pom.xml @@ -391,6 +391,8 @@ under the License. maven-invoker-plugin + + 3.5.1 install-descriptor diff --git a/src/it/resources/bad-dependency-poms/pom.xml b/src/it/resources/bad-dependency-poms/pom.xml index 3628b20..6464de1 100644 --- a/src/it/resources/bad-dependency-poms/pom.xml +++ b/src/it/resources/bad-dependency-poms/pom.xml @@ -34,7 +34,10 @@ under the License. test - file:///${it.dir}/repo + file:///${project.build.testOutputDirectory}/bad-dependency-poms/repo + + ignore + diff --git a/src/test/java/org/apache/maven/plugin/resources/remote/it/IT_BadDependencyPoms.java b/src/test/java/org/apache/maven/plugin/resources/remote/it/IT_BadDependencyPoms.java index 39a098a..ccb0856 100644 --- a/src/test/java/org/apache/maven/plugin/resources/remote/it/IT_BadDependencyPoms.java +++ b/src/test/java/org/apache/maven/plugin/resources/remote/it/IT_BadDependencyPoms.java @@ -40,32 +40,18 @@ public void test() throws IOException, URISyntaxException, VerificationException Verifier verifier = TestUtils.newVerifier(dir); verifier.deleteArtifacts("test"); - verifier.getSystemProperties().setProperty("it.dir", dir.getAbsolutePath()); - try { - verifier.executeGoal("generate-resources"); - } catch (VerificationException e) { - verifier.resetStreams(); + verifier.addCliArgument("generate-resources"); + verifier.execute(); - // We will get an exception from harness in case - // of execution failure (return code non zero). - // This is the case if we have missing artifacts - // as in this test case. - // This means we can't test the created file which will never - // contain the appropriate data we wan't to check for. - // So the only reliable way is to check the log output - // from maven which will print out message according to - // the missing artifacts. + verifier.verifyTextInLog( + "[WARNING] Invalid project model for artifact [test:missing:0.1]. It will be ignored by the remote resources Mojo."); + verifier.verifyTextInLog( + "[WARNING] Invalid project model for artifact [test:invalid:0.1]. It will be ignored by the remote resources Mojo"); - File output = new File(dir, "log.txt"); - String content = FileUtils.fileRead(output); + File output = new File(dir, "target/maven-shared-archive-resources/DEPENDENCIES"); + String content = FileUtils.fileRead(output); - assertTrue(content.contains( - "mvn install:install-file -DgroupId=test -DartifactId=pom -Dversion=0.2 -Dpackaging=jar")); - assertTrue(content.contains( - "mvn install:install-file -DgroupId=test -DartifactId=missing -Dversion=0.1 -Dpackaging=jar")); - assertTrue(content.contains( - "mvn install:install-file -DgroupId=test -DartifactId=invalid -Dversion=0.1 -Dpackaging=jar")); - } + assertTrue(content.contains("Dependency Id: test:pom:0.2")); } } diff --git a/src/test/java/org/apache/maven/plugin/resources/remote/it/IT_GetDependencyProjects.java b/src/test/java/org/apache/maven/plugin/resources/remote/it/IT_GetDependencyProjects.java index 8d071be..e178a84 100644 --- a/src/test/java/org/apache/maven/plugin/resources/remote/it/IT_GetDependencyProjects.java +++ b/src/test/java/org/apache/maven/plugin/resources/remote/it/IT_GetDependencyProjects.java @@ -45,32 +45,19 @@ public void test() throws IOException, URISyntaxException, VerificationException verifier.execute(); verifier.verifyErrorFreeLog(); - verifier = TestUtils.newVerifier(new File(dir, "project")); + File projectDir = new File(dir, "project"); + verifier = TestUtils.newVerifier(projectDir); verifier.deleteArtifacts("org.apache.maven.plugin.rresource.it.gdp"); - try { - verifier.addCliArgument("generate-resources"); - verifier.execute(); - } catch (VerificationException e) { - // We will get an exception from harness in case - // of execution failure (return code non zero). - // This is the case if we have missing artifacts - // as in this test case. - // This means we can't test the created file which will never - // contain the appropriate data we wan't to check for. - // So the only reliable way is to check the log output - // from maven which will print out message according to - // the missing artifacts. - File output = new File(verifier.getBasedir(), "log.txt"); - String content = FileUtils.fileRead(output); + verifier.addCliArgument("generate-resources"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + File output = new File(projectDir, "target/maven-shared-archive-resources/DEPENDENCIES"); + String content = FileUtils.fileRead(output); - assertTrue( - content.contains( - "mvn install:install-file -DgroupId=org.apache.maven.plugin.rresource.it.gdp -DartifactId=release -Dversion=1.0 -Dpackaging=jar")); - assertTrue( - content.contains( - "mvn install:install-file -DgroupId=org.apache.maven.plugin.rresource.it.gdp -DartifactId=snapshot -Dversion=1.0-SNAPSHOT -Dpackaging=jar")); - } + assertTrue(content.contains("Dependency Id: org.apache.maven.plugin.rresource.it.gdp:release:1.0")); + assertTrue(content.contains("Dependency Id: org.apache.maven.plugin.rresource.it.gdp:snapshot:1.0-SNAPSHOT")); } } diff --git a/src/test/java/org/apache/maven/plugin/resources/remote/it/support/BootstrapInstaller.java b/src/test/java/org/apache/maven/plugin/resources/remote/it/support/BootstrapInstaller.java index 77808e8..e6ff751 100644 --- a/src/test/java/org/apache/maven/plugin/resources/remote/it/support/BootstrapInstaller.java +++ b/src/test/java/org/apache/maven/plugin/resources/remote/it/support/BootstrapInstaller.java @@ -35,10 +35,9 @@ public static void install() throws IOException, URISyntaxException, Verificatio Verifier verifier = TestUtils.newVerifier(bootstrapDir); - verifier.executeGoal("deploy"); - + verifier.addCliArgument("deploy"); + verifier.execute(); verifier.verifyErrorFreeLog(); - verifier.resetStreams(); installed = true; }