Commit 23e78103 authored by Scott Frederick's avatar Scott Frederick

Merge branch '2.2.x'

Closes gh-20244
parents e7c265bc 625b40aa
...@@ -46,6 +46,7 @@ import org.apache.maven.shared.invoker.DefaultInvoker; ...@@ -46,6 +46,7 @@ import org.apache.maven.shared.invoker.DefaultInvoker;
import org.apache.maven.shared.invoker.InvocationRequest; import org.apache.maven.shared.invoker.InvocationRequest;
import org.apache.maven.shared.invoker.InvocationResult; import org.apache.maven.shared.invoker.InvocationResult;
import org.apache.maven.shared.invoker.Invoker; import org.apache.maven.shared.invoker.Invoker;
import org.apache.maven.shared.invoker.InvokerLogger;
import org.apache.maven.shared.invoker.MavenInvocationException; import org.apache.maven.shared.invoker.MavenInvocationException;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -184,6 +185,7 @@ class MavenBuild { ...@@ -184,6 +185,7 @@ class MavenBuild {
buildLog.flush(); buildLog.flush();
}); });
try { try {
invoker.getLogger().setThreshold(InvokerLogger.DEBUG);
InvocationResult result = invoker.execute(request); InvocationResult result = invoker.execute(request);
assertThat(result.getExitCode()).as(contentOf(buildLogFile)).isEqualTo(expectedExitCode); assertThat(result.getExitCode()).as(contentOf(buildLogFile)).isEqualTo(expectedExitCode);
} }
......
...@@ -71,7 +71,7 @@ class RunIntegrationTests { ...@@ -71,7 +71,7 @@ class RunIntegrationTests {
} }
@TestTemplate @TestTemplate
void whenSystemPropertiesAreConfiguredTheyAreAvailableToTheApplication(MavenBuild mavenBuild) { void whenSystemPropertiesAndJvmArgumentsAreConfiguredTheyAreAvailableToTheApplication(MavenBuild mavenBuild) {
mavenBuild.project("run-jvm-system-props").goals("spring-boot:run") mavenBuild.project("run-jvm-system-props").goals("spring-boot:run")
.execute((project) -> assertThat(buildLog(project)).contains("I haz been run")); .execute((project) -> assertThat(buildLog(project)).contains("I haz been run"));
} }
...@@ -82,6 +82,20 @@ class RunIntegrationTests { ...@@ -82,6 +82,20 @@ class RunIntegrationTests {
.execute((project) -> assertThat(buildLog(project)).contains("I haz been run")); .execute((project) -> assertThat(buildLog(project)).contains("I haz been run"));
} }
@TestTemplate
void whenCommandLineSpecifiesJvmArgumentsTheyAreAvailableToTheApplication(MavenBuild mavenBuild) {
mavenBuild.project("run-jvmargs-commandline").goals("spring-boot:run")
.systemProperty("spring-boot.run.jvmArguments", "\"-Dfoo=value1\" \"-Dbar=value2\"")
.execute((project) -> assertThat(buildLog(project)).contains("I haz been run"));
}
@TestTemplate
void whenPomAndCommandLineSpecifyJvmArgumentsThenPomOverrides(MavenBuild mavenBuild) {
mavenBuild.project("run-jvmargs").goals("spring-boot:run")
.systemProperty("spring-boot.run.jvmArguments", "\"-Dfoo=value-from-cmd\"")
.execute((project) -> assertThat(buildLog(project)).contains("I haz been run"));
}
@TestTemplate @TestTemplate
void whenProfilesAreConfiguredTheyArePassedToTheApplication(MavenBuild mavenBuild) { void whenProfilesAreConfiguredTheyArePassedToTheApplication(MavenBuild mavenBuild) {
mavenBuild.project("run-profiles").goals("spring-boot:run", "-X").execute( mavenBuild.project("run-profiles").goals("spring-boot:run", "-X").execute(
...@@ -102,8 +116,8 @@ class RunIntegrationTests { ...@@ -102,8 +116,8 @@ class RunIntegrationTests {
@TestTemplate @TestTemplate
void whenAWorkingDirectoryIsConfiguredTheApplicationIsRunFromThatDirectory(MavenBuild mavenBuild) { void whenAWorkingDirectoryIsConfiguredTheApplicationIsRunFromThatDirectory(MavenBuild mavenBuild) {
mavenBuild.project("run-working-directory").goals("spring-boot:run") mavenBuild.project("run-working-directory").goals("spring-boot:run").execute(
.execute((project) -> assertThat(buildLog(project)).contains("I haz been run")); (project) -> assertThat(buildLog(project)).containsPattern("I haz been run from.*/src/main/java"));
} }
@TestTemplate @TestTemplate
...@@ -129,6 +143,15 @@ class RunIntegrationTests { ...@@ -129,6 +143,15 @@ class RunIntegrationTests {
"I haz been run with profile(s) 'foo,bar' and endpoint(s) 'prometheus,info,health,metrics'")); "I haz been run with profile(s) 'foo,bar' and endpoint(s) 'prometheus,info,health,metrics'"));
} }
@TestTemplate
void whenPomAndCommandLineSpecifyRunArgumentsThenPomOverrides(MavenBuild mavenBuild) {
mavenBuild.project("run-arguments").goals("spring-boot:run")
.systemProperty("spring-boot.run.arguments",
"--management.endpoints.web.exposure.include=one,two,three --spring.profiles.active=test")
.execute((project) -> assertThat(buildLog(project))
.contains("I haz been run with profile(s) 'foo,bar' and endpoint(s) 'prometheus,info'"));
}
private String buildLog(File project) { private String buildLog(File project) {
return contentOf(new File(project, "target/build.log")); return contentOf(new File(project, "target/build.log"));
} }
......
<?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-jvmargs-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>
</plugin>
</plugins>
</build>
</project>
/*
* Copyright 2012-2020 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;
public class SampleApplication {
public static void main(String[] args) {
String foo = System.getProperty("foo");
if (!"value1".equals(foo)) {
throw new IllegalStateException("foo system property mismatch (got [" + foo + "]");
}
String bar = System.getProperty("bar");
if (!"value2".equals(bar)) {
throw new IllegalStateException("bar system property mismatch (got [" + bar + "]");
}
System.out.println("I haz been run");
}
}
...@@ -317,8 +317,8 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo { ...@@ -317,8 +317,8 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
* @return a {@link RunArguments} defining the application arguments * @return a {@link RunArguments} defining the application arguments
*/ */
protected RunArguments resolveApplicationArguments() { protected RunArguments resolveApplicationArguments() {
RunArguments runArguments = (this.commandlineArguments != null) ? new RunArguments(this.commandlineArguments) RunArguments runArguments = (this.arguments != null) ? new RunArguments(this.arguments)
: new RunArguments(this.arguments); : new RunArguments(this.commandlineArguments);
addActiveProfileArgument(runArguments); addActiveProfileArgument(runArguments);
return runArguments; return runArguments;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment