Add support for Spring Loaded in Maven and Gradle

Requires Loaded 1.1.5 (or better).

For Maven you can just add springloaded to the dependencies of the
spring-boot plugin (and also set MAVEN_OPTS=-noverify).

For Gradle add springloaded to the build dependencies (-noverify
can be added by the plugin).

In both cases there is also support for adding an arbitrary java agent
via configuration. Samples are provided in
spring-boot-sample-[simple,web-ui].

The ApplicationPlugin is only added if there is no JavaExec task
already present, and additionally it computes its own man class if
none is provided. So "gradle run" and "gradle bootRun" look
superficially similar, but "bootRun" has extra options, including
the agent and Loaded support.

Fixes gh-251, gh-183
This commit is contained in:
Dave Syer
2013-12-27 08:35:19 +00:00
parent f888567c1d
commit 77bac876ce
14 changed files with 463 additions and 34 deletions

View File

@@ -0,0 +1,53 @@
/*
* Copyright 2012-2013 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.loader.tools;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.util.List;
import com.sun.tools.attach.VirtualMachine;
/**
* @author Dave Syer
*/
public abstract class AgentAttacher {
public static void attach(File agent) {
String nameOfRunningVM = ManagementFactory.getRuntimeMXBean().getName();
int p = nameOfRunningVM.indexOf('@');
String pid = nameOfRunningVM.substring(0, p);
try {
VirtualMachine vm = VirtualMachine.attach(pid);
vm.loadAgent(agent.getAbsolutePath());
vm.detach();
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
public static List<String> commandLineArguments() {
return ManagementFactory.getRuntimeMXBean().getInputArguments();
}
public static boolean hasNoVerify() {
return commandLineArguments().contains("-Xverify:none");
}
}