From f8583ceabd24c78f064f601aae7c02eb482a8ed5 Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 21 Jul 2025 23:51:57 +1000 Subject: [PATCH 1/2] Add test cases for apache/maven#10937 Test that adding pipes to either MAVEN_OPTS or jvm.config does not break anything --- ...enITgh10937QuotedPipesInMavenOptsTest.java | 56 ++++++++++++++++++ .../apache/maven/it/TestSuiteOrdering.java | 2 + .../gh-10937-pipes-maven-opts/.mvn/jvm.config | 1 + .../gh-10937-pipes-maven-opts/pom.xml | 59 +++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 core-it-suite/src/test/java/org/apache/maven/it/MavenITgh10937QuotedPipesInMavenOptsTest.java create mode 100644 core-it-suite/src/test/resources/gh-10937-pipes-maven-opts/.mvn/jvm.config create mode 100644 core-it-suite/src/test/resources/gh-10937-pipes-maven-opts/pom.xml diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh10937QuotedPipesInMavenOptsTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh10937QuotedPipesInMavenOptsTest.java new file mode 100644 index 000000000..d79c4bfe7 --- /dev/null +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh10937QuotedPipesInMavenOptsTest.java @@ -0,0 +1,56 @@ +/* + * 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.Properties; + +import org.apache.maven.shared.verifier.Verifier; +import org.apache.maven.shared.verifier.util.ResourceExtractor; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * This is a test set for gh-10937. + */ +class MavenITgh10937QuotedPipesInMavenOptsTest extends AbstractMavenIntegrationTestCase { + + MavenITgh10937QuotedPipesInMavenOptsTest() { + super("[3.0.0,)"); + } + + /** + * Verify the dependency management of the consumer POM is computed correctly + */ + @Test + void testIt() throws Exception { + File basedir = ResourceExtractor.simpleExtractResources(getClass(), "/gh-10937-pipes-maven-opts"); + + Verifier verifier = newVerifier(basedir.getAbsolutePath()); + verifier.setEnvironmentVariable("MAVEN_OPTS", "-Dprop.maven-opts=\"foo|bar\""); + verifier.addCliArguments("validate"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + Properties props = verifier.loadProperties("target/pom.properties"); + assertEquals("foo|bar", props.getProperty("project.properties.pom.prop.jvm-opts")); + assertEquals("foo|bar", props.getProperty("project.properties.pom.prop.maven-opts")); + } +} diff --git a/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java b/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java index 0cd88ba47..ecc524039 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java @@ -120,6 +120,8 @@ public TestSuiteOrdering() { * the tests are to finishing. Newer tests are also more likely to fail, so this is * a fail fast technique as well. */ + + suite.addTestSuite(MavenITgh10937QuotedPipesInMavenOptsTest.class); suite.addTestSuite(MavenITmng8106OverlappingDirectoryRolesTest.class); suite.addTestSuite(MavenITmng7939PluginsValidationExcludesTest.class); suite.addTestSuite(MavenITmng7804PluginExecutionOrderTest.class); diff --git a/core-it-suite/src/test/resources/gh-10937-pipes-maven-opts/.mvn/jvm.config b/core-it-suite/src/test/resources/gh-10937-pipes-maven-opts/.mvn/jvm.config new file mode 100644 index 000000000..10fc239d8 --- /dev/null +++ b/core-it-suite/src/test/resources/gh-10937-pipes-maven-opts/.mvn/jvm.config @@ -0,0 +1 @@ +-Dprop.jvm-opts="foo|bar" \ No newline at end of file diff --git a/core-it-suite/src/test/resources/gh-10937-pipes-maven-opts/pom.xml b/core-it-suite/src/test/resources/gh-10937-pipes-maven-opts/pom.xml new file mode 100644 index 000000000..d1ef2ca10 --- /dev/null +++ b/core-it-suite/src/test/resources/gh-10937-pipes-maven-opts/pom.xml @@ -0,0 +1,59 @@ + + + + 4.0.0 + + org.apache.maven.its.gh10937 + test + 1.0 + + Maven Integration Test :: GH-10937 + Verify that JVM args can contain pipes. + + + ${prop.maven-opts} + ${prop.jvm-opts} + + + + + + org.apache.maven.its.plugins + maven-it-plugin-expression + 2.1-SNAPSHOT + + + test + + eval + + validate + + target/pom.properties + + project/properties + + + + + + + + From acf981b85d546b67467f98fbd66f384bb7238e92 Mon Sep 17 00:00:00 2001 From: Bob Date: Tue, 22 Jul 2025 01:36:40 +1000 Subject: [PATCH 2/2] Add test cases for apache/maven#10937 Test that adding pipes to either MAVEN_OPTS or jvm.config does not break anything --- .../it/MavenITgh10937QuotedPipesInMavenOptsTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh10937QuotedPipesInMavenOptsTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh10937QuotedPipesInMavenOptsTest.java index d79c4bfe7..bea3532fe 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh10937QuotedPipesInMavenOptsTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh10937QuotedPipesInMavenOptsTest.java @@ -21,6 +21,7 @@ import java.io.File; import java.util.Properties; +import org.apache.maven.shared.utils.StringUtils; import org.apache.maven.shared.verifier.Verifier; import org.apache.maven.shared.verifier.util.ResourceExtractor; import org.junit.jupiter.api.Test; @@ -50,7 +51,10 @@ void testIt() throws Exception { verifier.verifyErrorFreeLog(); Properties props = verifier.loadProperties("target/pom.properties"); - assertEquals("foo|bar", props.getProperty("project.properties.pom.prop.jvm-opts")); - assertEquals("foo|bar", props.getProperty("project.properties.pom.prop.maven-opts")); + // Strip quotes because the bash startup script in 3.9.x preserves them while cmd does not + // In this test we only care that the pipe does not cause issues and is retained, + // not what happens to the surrounding quotes. + assertEquals("foo|bar", StringUtils.strip(props.getProperty("project.properties.pom.prop.jvm-opts"), "\"")); + assertEquals("foo|bar", StringUtils.strip(props.getProperty("project.properties.pom.prop.maven-opts"), "\"")); } }