Merge branch '2.2.x'

Closes gh-20244
pull/20294/head
Scott Frederick 5 years ago
commit 23e781033c

@ -46,6 +46,7 @@ import org.apache.maven.shared.invoker.DefaultInvoker;
import org.apache.maven.shared.invoker.InvocationRequest;
import org.apache.maven.shared.invoker.InvocationResult;
import org.apache.maven.shared.invoker.Invoker;
import org.apache.maven.shared.invoker.InvokerLogger;
import org.apache.maven.shared.invoker.MavenInvocationException;
import static org.assertj.core.api.Assertions.assertThat;
@ -184,6 +185,7 @@ class MavenBuild {
buildLog.flush();
});
try {
invoker.getLogger().setThreshold(InvokerLogger.DEBUG);
InvocationResult result = invoker.execute(request);
assertThat(result.getExitCode()).as(contentOf(buildLogFile)).isEqualTo(expectedExitCode);
}

@ -71,7 +71,7 @@ class RunIntegrationTests {
}
@TestTemplate
void whenSystemPropertiesAreConfiguredTheyAreAvailableToTheApplication(MavenBuild mavenBuild) {
void whenSystemPropertiesAndJvmArgumentsAreConfiguredTheyAreAvailableToTheApplication(MavenBuild mavenBuild) {
mavenBuild.project("run-jvm-system-props").goals("spring-boot:run")
.execute((project) -> assertThat(buildLog(project)).contains("I haz been run"));
}
@ -82,6 +82,20 @@ class RunIntegrationTests {
.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
void whenProfilesAreConfiguredTheyArePassedToTheApplication(MavenBuild mavenBuild) {
mavenBuild.project("run-profiles").goals("spring-boot:run", "-X").execute(
@ -102,8 +116,8 @@ class RunIntegrationTests {
@TestTemplate
void whenAWorkingDirectoryIsConfiguredTheApplicationIsRunFromThatDirectory(MavenBuild mavenBuild) {
mavenBuild.project("run-working-directory").goals("spring-boot:run")
.execute((project) -> assertThat(buildLog(project)).contains("I haz been run"));
mavenBuild.project("run-working-directory").goals("spring-boot:run").execute(
(project) -> assertThat(buildLog(project)).containsPattern("I haz been run from.*/src/main/java"));
}
@TestTemplate
@ -129,6 +143,15 @@ class RunIntegrationTests {
"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) {
return contentOf(new File(project, "target/build.log"));
}

@ -0,0 +1,22 @@
<?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>

@ -0,0 +1,33 @@
/*
* 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 {
* @return a {@link RunArguments} defining the application arguments
*/
protected RunArguments resolveApplicationArguments() {
RunArguments runArguments = (this.commandlineArguments != null) ? new RunArguments(this.commandlineArguments)
: new RunArguments(this.arguments);
RunArguments runArguments = (this.arguments != null) ? new RunArguments(this.arguments)
: new RunArguments(this.commandlineArguments);
addActiveProfileArgument(runArguments);
return runArguments;
}

Loading…
Cancel
Save