Skip to content

Commit 9c9880d

Browse files
aschemanclaude
andcommitted
Add IT for mvn script expanding ${...} in CLI arguments
The eval in the mvn script causes shell expansion of ${...} patterns in user-provided arguments. This regression test exercises the actual launcher script via setForkJvm(true) and verifies that ${...} is not expanded by the shell. Related: #11978 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent cee2209 commit 9c9880d

2 files changed

Lines changed: 115 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.it;
20+
21+
import java.nio.file.Path;
22+
import java.util.Properties;
23+
24+
import org.junit.jupiter.api.Test;
25+
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
28+
/**
29+
* This is a test set for <a href="https://github.com/apache/maven/issues/11978">gh-11978</a>.
30+
*
31+
* Verifies that the launcher script does not expand <code>${...}</code> patterns
32+
* in CLI arguments. Regression test for the {@code eval exec} shell expansion
33+
* that broke any argument containing Maven property placeholders.
34+
*/
35+
class MavenITgh11978PlaceholderInCliArgTest extends AbstractMavenIntegrationTestCase {
36+
37+
@Test
38+
void testIt() throws Exception {
39+
Path basedir = extractResources("/gh-11978-placeholder-in-cli-arg")
40+
.getAbsoluteFile()
41+
.toPath();
42+
43+
Verifier verifier = newVerifier(basedir.toString());
44+
verifier.setForkJvm(true); // NOTE: We want to go through the launcher script
45+
// CLI argument with ${...} placeholder that the shell must NOT expand
46+
verifier.addCliArgument("-Dtest.placeholder=value_${some.placeholder}");
47+
verifier.addCliArgument("validate");
48+
verifier.execute();
49+
verifier.verifyErrorFreeLog();
50+
51+
Properties props = verifier.loadProperties("target/pom.properties");
52+
// Maven property substitution then resolves ${some.placeholder} (empty here).
53+
// The key point: the script did not crash with "bad substitution" and the
54+
// literal ${...} arrived at Java for Maven to handle.
55+
assertEquals("-value_-", props.getProperty("project.properties.pom.placeholder"));
56+
}
57+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<groupId>org.apache.maven.its.gh11978</groupId>
24+
<artifactId>test</artifactId>
25+
<version>1.0</version>
26+
27+
<name>Maven Integration Test :: GH-11978</name>
28+
<description>Verify that the launcher script does not expand ${...} placeholders in CLI arguments.</description>
29+
30+
<properties>
31+
<pom.placeholder>-${test.placeholder}-</pom.placeholder>
32+
</properties>
33+
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<groupId>org.apache.maven.its.plugins</groupId>
38+
<artifactId>maven-it-plugin-expression</artifactId>
39+
<version>2.1-SNAPSHOT</version>
40+
<executions>
41+
<execution>
42+
<id>test</id>
43+
<goals>
44+
<goal>eval</goal>
45+
</goals>
46+
<phase>validate</phase>
47+
<configuration>
48+
<outputFile>target/pom.properties</outputFile>
49+
<expressions>
50+
<expression>project/properties</expression>
51+
</expressions>
52+
</configuration>
53+
</execution>
54+
</executions>
55+
</plugin>
56+
</plugins>
57+
</build>
58+
</project>

0 commit comments

Comments
 (0)