diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8230CIFriendlyTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8230CIFriendlyTest.java new file mode 100644 index 0000000000..271bd7fba6 --- /dev/null +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8230CIFriendlyTest.java @@ -0,0 +1,183 @@ +/* + * 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.Objects; +import java.util.Properties; + +import org.apache.maven.shared.verifier.VerificationException; +import org.apache.maven.shared.verifier.Verifier; +import org.apache.maven.shared.verifier.util.ResourceExtractor; +import org.junit.jupiter.api.Test; + +/** + * This is a test set for MNG-8230. + */ +class MavenITmng8230CIFriendlyTest extends AbstractMavenIntegrationTestCase { + + private static final String PROPERTIES = "target/expression.properties"; + + MavenITmng8230CIFriendlyTest() { + super("[4.0.0-beta-5,)"); + } + + /** + * Verify that CI friendly version work when using project properties + * + * @throws Exception in case of failure + */ + @Test + void testitCiFriendlyWithProjectProperties() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-8230-ci-friendly-and-gav"); + + File basedir = new File(testDir, "cif-with-project-props"); + Verifier verifier = newVerifier(basedir.getAbsolutePath()); + verifier.addCliArgument("-Dexpression.outputFile=" + new File(basedir, PROPERTIES).getPath()); + verifier.addCliArgument("-Dexpression.expressions=project/version"); + verifier.addCliArgument("org.apache.maven.its.plugins:maven-it-plugin-expression:2.1-SNAPSHOT:eval"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + verifier.verifyFilePresent(PROPERTIES); + Properties props = verifier.loadProperties(PROPERTIES); + assertEquals(props.getProperty("project.version"), "1.0-SNAPSHOT"); + } + + /** + * Verify that CI friendly version work when using project properties + * + * @throws Exception in case of failure + */ + @Test + void testitCiFriendlyWithProjectPropertiesOverride() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-8230-ci-friendly-and-gav"); + + File basedir = new File(testDir, "cif-with-project-props"); + Verifier verifier = newVerifier(basedir.getAbsolutePath()); + verifier.addCliArgument("-Dexpression.outputFile=" + new File(basedir, PROPERTIES).getPath()); + verifier.addCliArgument("-Dexpression.expressions=project/version"); + verifier.addCliArgument("org.apache.maven.its.plugins:maven-it-plugin-expression:2.1-SNAPSHOT:eval"); + verifier.addCliArgument("-Dci-version=1.1-SNAPSHOT"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + verifier.verifyFilePresent(PROPERTIES); + Properties props = verifier.loadProperties(PROPERTIES); + assertEquals(props.getProperty("project.version"), "1.1-SNAPSHOT"); + } + + /** + * Verify that CI friendly version work when using user properties + * + * @throws Exception in case of failure + */ + @Test + void testitCiFriendlyWithUserProperties() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-8230-ci-friendly-and-gav"); + + File basedir = new File(testDir, "cif-with-user-props"); + Verifier verifier = newVerifier(basedir.getAbsolutePath()); + + verifier.addCliArgument("-Dexpression.outputFile=" + new File(basedir, PROPERTIES).getPath()); + verifier.addCliArgument("-Dexpression.expressions=project/version"); + verifier.addCliArgument("org.apache.maven.its.plugins:maven-it-plugin-expression:2.1-SNAPSHOT:eval"); + verifier.addCliArgument("-Dci-version=1.1-SNAPSHOT"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + verifier.verifyFilePresent(PROPERTIES); + Properties props = verifier.loadProperties(PROPERTIES); + assertEquals(props.getProperty("project.version"), "1.1-SNAPSHOT"); + } + + /** + * Verify that CI friendly version fails if the properties are not given + * + * @throws Exception in case of failure + */ + @Test + void testitCiFriendlyWithUserPropertiesNotGiven() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-8230-ci-friendly-and-gav"); + + File basedir = new File(testDir, "cif-with-user-props"); + Verifier verifier = newVerifier(basedir.getAbsolutePath()); + verifier.addCliArgument("-Dexpression.outputFile=" + new File(basedir, PROPERTIES).getPath()); + verifier.addCliArgument("-Dexpression.expressions=project/version"); + verifier.addCliArgument("org.apache.maven.its.plugins:maven-it-plugin-expression:2.1-SNAPSHOT:eval"); + try { + verifier.execute(); + fail("Expected failure"); + } catch (VerificationException e) { + assertTrue( + e.getMessage(), + e.getMessage() + .contains( + "'version' contains an expression but should be a constant. @ myGroup:parent:${ci-version}")); + } + } + + @Test + void testitExpressionInGroupId() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-8230-ci-friendly-and-gav"); + + File basedir = new File(testDir, "exp-in-groupid"); + Verifier verifier = newVerifier(basedir.getAbsolutePath()); + verifier.addCliArgument("-Dexpression.outputFile=" + new File(basedir, PROPERTIES).getPath()); + verifier.addCliArgument("-Dexpression.expressions=project/version"); + verifier.addCliArgument("org.apache.maven.its.plugins:maven-it-plugin-expression:2.1-SNAPSHOT:eval"); + try { + verifier.execute(); + fail("Expected failure"); + } catch (VerificationException e) { + assertTrue( + e.getMessage(), + e.getMessage() + .contains( + "'groupId' contains an expression but should be a constant. @ ${foo}:myArtifact:1.0-SNAPSHOT")); + } + } + + @Test + void testitExpressionInArtifactId() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-8230-ci-friendly-and-gav"); + + File basedir = new File(testDir, "exp-in-artifactid"); + Verifier verifier = newVerifier(basedir.getAbsolutePath()); + verifier.addCliArgument("-Dexpression.outputFile=" + new File(basedir, PROPERTIES).getPath()); + verifier.addCliArgument("-Dexpression.expressions=project/version"); + verifier.addCliArgument("org.apache.maven.its.plugins:maven-it-plugin-expression:2.1-SNAPSHOT:eval"); + try { + verifier.execute(); + fail("Expected failure"); + } catch (VerificationException e) { + assertTrue( + e.getMessage(), + e.getMessage() + .contains( + "'artifactId' contains an expression but should be a constant. @ myGroup:${foo}:1.0-SNAPSHOT")); + } + } + + void verifyExactLine(Verifier verifier, String line) throws Exception { + List lines = verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false); + if (lines.stream().noneMatch(s -> Objects.equals(s, line))) { + throw new VerificationException( + "Could not find line: '" + line + "' in output log:\n" + String.join("\n", lines)); + } + } +} diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java b/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java index 3524aae655..1619516d83 100644 --- a/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java @@ -120,6 +120,7 @@ public class TestSuiteOrdering implements ClassOrderer { * the tests are to finishing. Newer tests are also more likely to fail, so this is * a fail fast technique as well. */ + suite.addTestSuite(MavenITmng8230CIFriendlyTest.class); suite.addTestSuite(MavenITmng7255InferredGroupIdTest.class); suite.addTestSuite(MavenITmng8220ExtensionWithDITest.class); suite.addTestSuite(MavenITmng8181CentralRepoTest.class); diff --git a/its/core-it-suite/src/test/resources/mng-8230-ci-friendly-and-gav/cif-with-project-props/child/pom.xml b/its/core-it-suite/src/test/resources/mng-8230-ci-friendly-and-gav/cif-with-project-props/child/pom.xml new file mode 100644 index 0000000000..6d3d27d610 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8230-ci-friendly-and-gav/cif-with-project-props/child/pom.xml @@ -0,0 +1,6 @@ + + + 4.1.0 + + child + diff --git a/its/core-it-suite/src/test/resources/mng-8230-ci-friendly-and-gav/cif-with-project-props/pom.xml b/its/core-it-suite/src/test/resources/mng-8230-ci-friendly-and-gav/cif-with-project-props/pom.xml new file mode 100644 index 0000000000..32b20471a8 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8230-ci-friendly-and-gav/cif-with-project-props/pom.xml @@ -0,0 +1,13 @@ + + + 4.1.0 + + myGroup + parent + ${ci-version} + pom + + + 1.0-SNAPSHOT + + diff --git a/its/core-it-suite/src/test/resources/mng-8230-ci-friendly-and-gav/cif-with-user-props/child/pom.xml b/its/core-it-suite/src/test/resources/mng-8230-ci-friendly-and-gav/cif-with-user-props/child/pom.xml new file mode 100644 index 0000000000..6d3d27d610 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8230-ci-friendly-and-gav/cif-with-user-props/child/pom.xml @@ -0,0 +1,6 @@ + + + 4.1.0 + + child + diff --git a/its/core-it-suite/src/test/resources/mng-8230-ci-friendly-and-gav/cif-with-user-props/pom.xml b/its/core-it-suite/src/test/resources/mng-8230-ci-friendly-and-gav/cif-with-user-props/pom.xml new file mode 100644 index 0000000000..6d2c7e5423 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8230-ci-friendly-and-gav/cif-with-user-props/pom.xml @@ -0,0 +1,9 @@ + + + 4.1.0 + + myGroup + parent + ${ci-version} + pom + diff --git a/its/core-it-suite/src/test/resources/mng-8230-ci-friendly-and-gav/exp-in-artifactid/pom.xml b/its/core-it-suite/src/test/resources/mng-8230-ci-friendly-and-gav/exp-in-artifactid/pom.xml new file mode 100644 index 0000000000..5952bd8984 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8230-ci-friendly-and-gav/exp-in-artifactid/pom.xml @@ -0,0 +1,8 @@ + + + 4.1.0 + + myGroup + ${foo} + 1.0-SNAPSHOT + diff --git a/its/core-it-suite/src/test/resources/mng-8230-ci-friendly-and-gav/exp-in-groupid/pom.xml b/its/core-it-suite/src/test/resources/mng-8230-ci-friendly-and-gav/exp-in-groupid/pom.xml new file mode 100644 index 0000000000..0e0cbede92 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8230-ci-friendly-and-gav/exp-in-groupid/pom.xml @@ -0,0 +1,8 @@ + + + 4.1.0 + + ${foo} + myArtifact + 1.0-SNAPSHOT +