From c75782424c0053a6082cffdc9627cb49736677e2 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 21 Aug 2014 16:25:37 +0100 Subject: [PATCH 1/2] Add jar that should have been added as part of 69c61d0 --- .../gradle/MultiProjectRepackagingTests.java | 5 +---- .../multi-project-repackage/common/lib/foo.jar | Bin 0 -> 2533 bytes 2 files changed, 1 insertion(+), 4 deletions(-) create mode 100644 spring-boot-integration-tests/src/test/resources/multi-project-repackage/common/lib/foo.jar diff --git a/spring-boot-integration-tests/src/test/java/org/springframework/boot/gradle/MultiProjectRepackagingTests.java b/spring-boot-integration-tests/src/test/java/org/springframework/boot/gradle/MultiProjectRepackagingTests.java index 7097735589..3743779136 100644 --- a/spring-boot-integration-tests/src/test/java/org/springframework/boot/gradle/MultiProjectRepackagingTests.java +++ b/spring-boot-integration-tests/src/test/java/org/springframework/boot/gradle/MultiProjectRepackagingTests.java @@ -24,7 +24,6 @@ import org.gradle.tooling.ProjectConnection; import org.junit.BeforeClass; import org.junit.Test; import org.springframework.boot.dependency.tools.ManagedDependencies; -import org.springframework.util.FileCopyUtils; import static org.hamcrest.Matchers.notNullValue; import static org.junit.Assert.assertThat; @@ -48,10 +47,8 @@ public class MultiProjectRepackagingTests { @Test public void repackageWithTransitiveFileDependency() throws Exception { - FileCopyUtils.copy(new File("src/test/resources/foo.jar"), new File( - "target/multi-project-repackage/foo.jar")); project.newBuild().forTasks("clean", "build") - .withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run(); + .withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true").run(); File buildLibs = new File("target/multi-project-repackage/main/build/libs"); JarFile jarFile = new JarFile(new File(buildLibs, "main.jar")); assertThat(jarFile.getEntry("lib/commons-logging-1.1.3.jar"), notNullValue()); diff --git a/spring-boot-integration-tests/src/test/resources/multi-project-repackage/common/lib/foo.jar b/spring-boot-integration-tests/src/test/resources/multi-project-repackage/common/lib/foo.jar new file mode 100644 index 0000000000000000000000000000000000000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 15:25:02 +0100 Subject: [PATCH 2/2] Preserve JVM args when auto-configuring a Java agent in Gradle bootRun Fixes #1411 --- .../boot/gradle/ProjectCreator.java | 2 + .../boot/gradle/SpringLoadedTests.java | 98 +++++++++++++++++++ .../spring-loaded-jvm-args/build.gradle | 30 ++++++ .../src/main/java/test/Application.java | 25 +++++ .../boot/gradle/agent/AgentTasksEnhancer.java | 5 + 5 files changed, 160 insertions(+) create mode 100644 spring-boot-integration-tests/src/test/java/org/springframework/boot/gradle/SpringLoadedTests.java create mode 100644 spring-boot-integration-tests/src/test/resources/spring-loaded-jvm-args/build.gradle create mode 100644 spring-boot-integration-tests/src/test/resources/spring-loaded-jvm-args/src/main/java/test/Application.java diff --git a/spring-boot-integration-tests/src/test/java/org/springframework/boot/gradle/ProjectCreator.java b/spring-boot-integration-tests/src/test/java/org/springframework/boot/gradle/ProjectCreator.java index 8fffb5677a..8bea9ef803 100644 --- a/spring-boot-integration-tests/src/test/java/org/springframework/boot/gradle/ProjectCreator.java +++ b/spring-boot-integration-tests/src/test/java/org/springframework/boot/gradle/ProjectCreator.java @@ -46,6 +46,8 @@ public class ProjectCreator { } GradleConnector gradleConnector = GradleConnector.newConnector(); + gradleConnector.useGradleVersion("1.12"); + ((DefaultGradleConnector) gradleConnector).embedded(true); return gradleConnector.forProjectDirectory(projectDirectory).connect(); } diff --git a/spring-boot-integration-tests/src/test/java/org/springframework/boot/gradle/SpringLoadedTests.java b/spring-boot-integration-tests/src/test/java/org/springframework/boot/gradle/SpringLoadedTests.java new file mode 100644 index 0000000000..5cd2f78ab4 --- /dev/null +++ b/spring-boot-integration-tests/src/test/java/org/springframework/boot/gradle/SpringLoadedTests.java @@ -0,0 +1,98 @@ +/* + * Copyright 2012-2014 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 + * + * 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.springframework.boot.gradle; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.gradle.tooling.ProjectConnection; +import org.junit.Test; +import org.springframework.boot.dependency.tools.ManagedDependencies; + +import static org.junit.Assert.fail; + +/** + * Integration tests for the Gradle plugin's Spring Loaded support + * + * @author Andy Wilkinson + */ +public class SpringLoadedTests { + + private static final String BOOT_VERSION = ManagedDependencies.get() + .find("spring-boot").getVersion(); + + private static final String SPRING_LOADED_VERSION = ManagedDependencies.get() + .find("springloaded").getVersion(); + + @Test + public void defaultJvmArgsArePreservedWhenLoadedAgentIsConfigured() + throws IOException { + ProjectConnection project = new ProjectCreator() + .createProject("spring-loaded-jvm-args"); + project.newBuild() + .forTasks("bootRun") + .withArguments("-PbootVersion=" + BOOT_VERSION, + "-PspringLoadedVersion=" + SPRING_LOADED_VERSION, "--stacktrace") + .run(); + + List output = getOutput(); + assertOutputContains("-DSOME_ARG=someValue", output); + assertOutputContains("-Xverify:none", output); + assertOutputMatches( + "-javaagent:.*springloaded-" + SPRING_LOADED_VERSION + ".jar", output); + } + + private List getOutput() throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(new File( + "target/spring-loaded-jvm-args/build/output.txt"))); + try { + List lines = new ArrayList(); + + String line; + + while ((line = reader.readLine()) != null) { + lines.add(line); + } + return lines; + } + finally { + reader.close(); + } + } + + private void assertOutputContains(String requiredOutput, List actualOutput) { + for (String line : actualOutput) { + if (line.equals(requiredOutput)) { + return; + } + } + fail("Required output '" + requiredOutput + "' not found in " + actualOutput); + } + + private void assertOutputMatches(String requiredPattern, List actualOutput) { + for (String line : actualOutput) { + if (line.matches(requiredPattern)) { + return; + } + } + fail("Required pattern '" + requiredPattern + "' not matched in " + actualOutput); + } +} diff --git a/spring-boot-integration-tests/src/test/resources/spring-loaded-jvm-args/build.gradle b/spring-boot-integration-tests/src/test/resources/spring-loaded-jvm-args/build.gradle new file mode 100644 index 0000000000..7cc675f6ab --- /dev/null +++ b/spring-boot-integration-tests/src/test/resources/spring-loaded-jvm-args/build.gradle @@ -0,0 +1,30 @@ +buildscript { + repositories { + mavenLocal() + mavenCentral() + } + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:${project.bootVersion}") + classpath("org.springframework:springloaded:${project.springLoadedVersion}") + } +} + +apply plugin: 'java' +apply plugin: 'spring-boot' + +repositories { + mavenLocal() + mavenCentral() +} + +dependencies { + compile("org.springframework.boot:spring-boot-starter") +} + +applicationDefaultJvmArgs = [ + "-DSOME_ARG=someValue" +] + +jar { + baseName = 'spring-loaded-jvm-args' +} \ No newline at end of file diff --git a/spring-boot-integration-tests/src/test/resources/spring-loaded-jvm-args/src/main/java/test/Application.java b/spring-boot-integration-tests/src/test/resources/spring-loaded-jvm-args/src/main/java/test/Application.java new file mode 100644 index 0000000000..12b8be6e6d --- /dev/null +++ b/spring-boot-integration-tests/src/test/resources/spring-loaded-jvm-args/src/main/java/test/Application.java @@ -0,0 +1,25 @@ +package test; + +import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.lang.management.ManagementFactory; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.util.Assert; + +public class Application { + + public static void main(String[] args) throws Exception { + PrintWriter writer = new PrintWriter(new FileWriter(new File("build/output.txt"))); + for (String argument: ManagementFactory.getRuntimeMXBean().getInputArguments()) { + writer.println(argument); + } + writer.close(); + } +} diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/agent/AgentTasksEnhancer.java b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/agent/AgentTasksEnhancer.java index b830cd9c64..ad4ea061cc 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/agent/AgentTasksEnhancer.java +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/agent/AgentTasksEnhancer.java @@ -108,6 +108,11 @@ public class AgentTasksEnhancer implements Action { if (this.noverify != null && this.noverify) { exec.jvmArgs("-noverify"); } + Iterable defaultJvmArgs = exec.getConventionMapping().getConventionValue( + null, "jvmArgs", false); + if (defaultJvmArgs != null) { + exec.jvmArgs(defaultJvmArgs); + } } }