-
Notifications
You must be signed in to change notification settings - Fork 40.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support commas embedded in command line arguments from Maven plugin
See gh-18688
- Loading branch information
Showing
10 changed files
with
277 additions
and
2 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...g-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-commandline/invoker.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
invoker.mavenOpts=-Dspring-boot.run.arguments='--management.endpoints.web.exposure.include=prometheus,info,health,metrics,--spring.profiles.active=foo,bar' |
30 changes: 30 additions & 0 deletions
30
...oject/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-commandline/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.springframework.boot.maven.it</groupId> | ||
<artifactId>run-arguments-commandline</artifactId> | ||
<version>0.0.1.BUILD-SNAPSHOT</version> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>@java.version@</maven.compiler.source> | ||
<maven.compiler.target>@java.version@</maven.compiler.target> | ||
</properties> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>@project.groupId@</groupId> | ||
<artifactId>@project.artifactId@</artifactId> | ||
<version>@project.version@</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>run</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
38 changes: 38 additions & 0 deletions
38
...ven-plugin/src/it/run-arguments-commandline/src/main/java/org/test/SampleApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2012-2019 the original author or authors. | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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.test; | ||
|
||
import java.util.Arrays; | ||
|
||
public class SampleApplication { | ||
|
||
public static void main(String[] args) { | ||
if (args.length < 2) { | ||
throw new IllegalArgumentException("Missing arguments " + Arrays.toString(args) + ""); | ||
} | ||
if (!args[0].startsWith("--management.endpoints.web.exposure.include=")) { | ||
throw new IllegalArgumentException("Invalid argument " + args[0]); | ||
} | ||
if (!args[1].startsWith("--spring.profiles.active=")) { | ||
throw new IllegalArgumentException("Invalid argument " + args[1]); | ||
} | ||
String endpoints = args[0].split("=")[1]; | ||
String profile = args[1].split("=")[1]; | ||
System.out.println("I haz been run with profile(s) '" + profile + "' and endpoint(s) '" + endpoints + "'"); | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
...spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments-commandline/verify.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def file = new File(basedir, "build.log") | ||
return file.text.contains("I haz been run with profile(s) 'foo,bar' and endpoint(s) 'prometheus,info,health,metrics'") |
36 changes: 36 additions & 0 deletions
36
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.springframework.boot.maven.it</groupId> | ||
<artifactId>run-arguments</artifactId> | ||
<version>0.0.1.BUILD-SNAPSHOT</version> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>@java.version@</maven.compiler.source> | ||
<maven.compiler.target>@java.version@</maven.compiler.target> | ||
</properties> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>@project.groupId@</groupId> | ||
<artifactId>@project.artifactId@</artifactId> | ||
<version>@project.version@</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>run</goal> | ||
</goals> | ||
<configuration> | ||
<arguments> | ||
<argument>--management.endpoints.web.exposure.include=prometheus,info</argument> | ||
<argument>--spring.profiles.active=foo,bar</argument> | ||
</arguments> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
38 changes: 38 additions & 0 deletions
38
...ring-boot-maven-plugin/src/it/run-arguments/src/main/java/org/test/SampleApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2012-2019 the original author or authors. | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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.test; | ||
|
||
import java.util.Arrays; | ||
|
||
public class SampleApplication { | ||
|
||
public static void main(String[] args) { | ||
if (args.length < 2) { | ||
throw new IllegalArgumentException("Missing arguments " + Arrays.toString(args) + ""); | ||
} | ||
if (!args[0].startsWith("--management.endpoints.web.exposure.include=")) { | ||
throw new IllegalArgumentException("Invalid argument " + args[0]); | ||
} | ||
if (!args[1].startsWith("--spring.profiles.active=")) { | ||
throw new IllegalArgumentException("Invalid argument " + args[1]); | ||
} | ||
String endpoints = args[0].split("=")[1]; | ||
String profile = args[1].split("=")[1]; | ||
System.out.println("I haz been run with profile(s) '" + profile + "' and endpoint(s) '" + endpoints + "'"); | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
...oot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/run-arguments/verify.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def file = new File(basedir, "build.log") | ||
return file.text.contains("I haz been run with profile(s) 'foo,bar' and endpoint(s) 'prometheus,info'") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ApplicationArguments.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2012-2019 the original author or authors. | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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.springframework.boot.maven; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Utility class to parse and collect application arguments. | ||
* | ||
* @author Dmytro Nosan | ||
*/ | ||
class ApplicationArguments { | ||
|
||
private final List<String> arguments; | ||
|
||
ApplicationArguments(String[] arguments) { | ||
this.arguments = parse(arguments); | ||
} | ||
|
||
String[] asArray() { | ||
return this.arguments.toArray(new String[0]); | ||
} | ||
|
||
private static List<String> parse(String[] args) { | ||
if (args == null || args.length == 0) { | ||
return Collections.emptyList(); | ||
} | ||
List<String> result = new ArrayList<>(); | ||
for (String line : new RunArguments(String.join(",", args)).getArgs()) { | ||
String[] tokens = line.split(",--"); | ||
result.add(tokens[0]); | ||
for (int i = 1; i < tokens.length; i++) { | ||
result.add("--" + tokens[i]); | ||
} | ||
} | ||
return Collections.unmodifiableList(result); | ||
} | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
...t-maven-plugin/src/test/java/org/springframework/boot/maven/ApplicationArgumentsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2012-2019 the original author or authors. | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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.springframework.boot.maven; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.assertj.core.api.ListAssert; | ||
import org.assertj.core.api.ObjectArrayAssert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Tests for {@link ApplicationArguments}. | ||
* | ||
* @author Dmytro Nosan | ||
*/ | ||
class ApplicationArgumentsTest { | ||
|
||
@Test | ||
void parseMavenSplitArgs() { | ||
assertArgs("'--management.include=prometheus", "health", "info'", "'--spring.profiles.active=foo", "bar'") | ||
.containsExactly("--management.include=prometheus,health,info", "--spring.profiles.active=foo,bar"); | ||
} | ||
|
||
@Test | ||
void parseArgs() { | ||
assertThat(assertArgs("'--management.include=prometheus,info'", "'--spring.profiles.active=foo,bar'") | ||
.containsExactly("--management.include=prometheus,info", "--spring.profiles.active=foo,bar")); | ||
} | ||
|
||
@Test | ||
void parseArgumentsAsLine() { | ||
assertArgs("'--management.include=prometheus,info,--spring.profiles.active=foo,bar'") | ||
.containsExactly("--management.include=prometheus,info", "--spring.profiles.active=foo,bar"); | ||
} | ||
|
||
@Test | ||
void parseOneArg() { | ||
assertArgs("'--management.include=prometheus,info'").containsExactly("--management.include=prometheus,info"); | ||
} | ||
|
||
@Test | ||
void parseNull() { | ||
assertArgs((String[]) null).isEmpty(); | ||
} | ||
|
||
@Test | ||
void parseEmpty() { | ||
assertArgs().isEmpty(); | ||
} | ||
|
||
private static ObjectArrayAssert<String> assertArgs(String... args) { | ||
return assertThat(new ApplicationArguments(args).asArray()); | ||
} | ||
|
||
} |