Merge branch '1.5.x' into 2.0.x

This commit is contained in:
Andy Wilkinson
2019-06-07 10:46:31 +01:00
2320 changed files with 23858 additions and 39476 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* 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.
@@ -90,8 +90,8 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
this.excludeArtifactIds = excludeArtifactIds;
}
protected Set<Artifact> filterDependencies(Set<Artifact> dependencies,
FilterArtifacts filters) throws MojoExecutionException {
protected Set<Artifact> filterDependencies(Set<Artifact> dependencies, FilterArtifacts filters)
throws MojoExecutionException {
try {
Set<Artifact> filtered = new LinkedHashSet<>(dependencies);
filtered.retainAll(filters.filter(dependencies));
@@ -112,10 +112,8 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
for (ArtifactsFilter additionalFilter : additionalFilters) {
filters.addFilter(additionalFilter);
}
filters.addFilter(
new ArtifactIdFilter("", cleanFilterConfig(this.excludeArtifactIds)));
filters.addFilter(
new MatchingGroupIdFilter(cleanFilterConfig(this.excludeGroupIds)));
filters.addFilter(new ArtifactIdFilter("", cleanFilterConfig(this.excludeArtifactIds)));
filters.addFilter(new MatchingGroupIdFilter(cleanFilterConfig(this.excludeGroupIds)));
if (this.includes != null && !this.includes.isEmpty()) {
filters.addFilter(new IncludeFilter(this.includes));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* 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.
@@ -183,8 +183,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
* @return {@code true} if the application process should be forked
*/
protected boolean isFork() {
return (Boolean.TRUE.equals(this.fork)
|| (this.fork == null && enableForkByDefault()));
return (Boolean.TRUE.equals(this.fork) || (this.fork == null && enableForkByDefault()));
}
/**
@@ -208,11 +207,9 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
return this.workingDirectory != null;
}
private void run(String startClassName)
throws MojoExecutionException, MojoFailureException {
private void run(String startClassName) throws MojoExecutionException, MojoFailureException {
boolean fork = isFork();
this.project.getProperties().setProperty("_spring.boot.fork.enabled",
Boolean.toString(fork));
this.project.getProperties().setProperty("_spring.boot.fork.enabled", Boolean.toString(fork));
if (fork) {
doRunWithForkedJvm(startClassName);
}
@@ -232,16 +229,14 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
getLog().warn("Fork mode disabled, ignoring agent");
}
if (hasJvmArgs()) {
getLog().warn("Fork mode disabled, ignoring JVM argument(s) ["
+ this.jvmArguments + "]");
getLog().warn("Fork mode disabled, ignoring JVM argument(s) [" + this.jvmArguments + "]");
}
if (hasWorkingDirectorySet()) {
getLog().warn("Fork mode disabled, ignoring working directory configuration");
}
}
private void doRunWithForkedJvm(String startClassName)
throws MojoExecutionException, MojoFailureException {
private void doRunWithForkedJvm(String startClassName) throws MojoExecutionException, MojoFailureException {
List<String> args = new ArrayList<>();
addAgents(args);
addJvmArgs(args);
@@ -357,8 +352,8 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
}
}
if (mainClass == null) {
throw new MojoExecutionException("Unable to find a suitable main class, "
+ "please add a 'mainClass' property");
throw new MojoExecutionException(
"Unable to find a suitable main class, " + "please add a 'mainClass' property");
}
return mainClass;
}
@@ -390,8 +385,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
for (Resource resource : this.project.getResources()) {
File directory = new File(resource.getDirectory());
urls.add(directory.toURI().toURL());
FileUtils.removeDuplicatesFromOutputDirectory(this.classesDirectory,
directory);
FileUtils.removeDuplicatesFromOutputDirectory(this.classesDirectory, directory);
}
}
}
@@ -400,12 +394,9 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
urls.add(this.classesDirectory.toURI().toURL());
}
private void addDependencies(List<URL> urls)
throws MalformedURLException, MojoExecutionException {
FilterArtifacts filters = (this.useTestClasspath ? getFilters()
: getFilters(new TestArtifactFilter()));
Set<Artifact> artifacts = filterDependencies(this.project.getArtifacts(),
filters);
private void addDependencies(List<URL> urls) throws MalformedURLException, MojoExecutionException {
FilterArtifacts filters = (this.useTestClasspath ? getFilters() : getFilters(new TestArtifactFilter()));
Set<Artifact> artifacts = filterDependencies(this.project.getArtifacts(), filters);
for (Artifact artifact : artifacts) {
if (artifact.getFile() != null) {
urls.add(artifact.getFile().toURI().toURL());
@@ -461,9 +452,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
synchronized (this.monitor) {
if (this.exception != null) {
throw new MojoExecutionException(
"An exception occurred while running. "
+ this.exception.getMessage(),
this.exception);
"An exception occurred while running. " + this.exception.getMessage(), this.exception);
}
}
}
@@ -498,9 +487,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
}
catch (NoSuchMethodException ex) {
Exception wrappedEx = new Exception(
"The specified mainClass doesn't contain a "
+ "main method with appropriate signature.",
ex);
"The specified mainClass doesn't contain a " + "main method with appropriate signature.", ex);
thread.getThreadGroup().uncaughtException(thread, wrappedEx);
}
catch (Exception ex) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* 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.
@@ -59,8 +59,7 @@ public class ArtifactsLibraries implements Libraries {
private final Log log;
public ArtifactsLibraries(Set<Artifact> artifacts, Collection<Dependency> unpacks,
Log log) {
public ArtifactsLibraries(Set<Artifact> artifacts, Collection<Dependency> unpacks, Log log) {
this.artifacts = artifacts;
this.unpacks = unpacks;
this.log = log;
@@ -78,8 +77,7 @@ public class ArtifactsLibraries implements Libraries {
name = artifact.getGroupId() + "-" + name;
this.log.debug("Renamed to: " + name);
}
callback.library(new Library(name, artifact.getFile(), scope,
isUnpackRequired(artifact)));
callback.library(new Library(name, artifact.getFile(), scope, isUnpackRequired(artifact)));
}
}
}

View File

@@ -41,8 +41,7 @@ import org.springframework.boot.loader.tools.BuildPropertiesWriter.ProjectDetail
* @author Stephane Nicoll
* @since 1.4.0
*/
@Mojo(name = "build-info", defaultPhase = LifecyclePhase.GENERATE_RESOURCES,
threadSafe = true)
@Mojo(name = "build-info", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true)
public class BuildInfoMojo extends AbstractMojo {
@Component
@@ -57,8 +56,7 @@ public class BuildInfoMojo extends AbstractMojo {
/**
* The location of the generated build-info.properties.
*/
@Parameter(
defaultValue = "${project.build.outputDirectory}/META-INF/build-info.properties")
@Parameter(defaultValue = "${project.build.outputDirectory}/META-INF/build-info.properties")
private File outputFile;
/**
@@ -71,16 +69,13 @@ public class BuildInfoMojo extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
new BuildPropertiesWriter(this.outputFile)
.writeBuildProperties(new ProjectDetails(this.project.getGroupId(),
this.project.getArtifactId(), this.project.getVersion(),
this.project.getName(), Instant.now(),
this.additionalProperties));
new BuildPropertiesWriter(this.outputFile).writeBuildProperties(new ProjectDetails(
this.project.getGroupId(), this.project.getArtifactId(), this.project.getVersion(),
this.project.getName(), Instant.now(), this.additionalProperties));
this.buildContext.refresh(this.outputFile);
}
catch (NullAdditionalPropertyValueException ex) {
throw new MojoFailureException(
"Failed to generate build-info.properties. " + ex.getMessage(), ex);
throw new MojoFailureException("Failed to generate build-info.properties. " + ex.getMessage(), ex);
}
catch (Exception ex) {
throw new MojoExecutionException(ex.getMessage(), ex);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* 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.
@@ -74,8 +74,8 @@ public abstract class DependencyFilter extends AbstractArtifactsFilter {
if (!dependency.getArtifactId().equals(artifact.getArtifactId())) {
return false;
}
return (dependency.getClassifier() == null || artifact.getClassifier() != null
&& dependency.getClassifier().equals(artifact.getClassifier()));
return (dependency.getClassifier() == null
|| artifact.getClassifier() != null && dependency.getClassifier().equals(artifact.getClassifier()));
}
protected final List<? extends FilterableDependency> getFilters() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* 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.
@@ -58,8 +58,8 @@ public class PropertiesMergingResourceTransformer implements ResourceTransformer
}
@Override
public void processResource(String resource, InputStream inputStream,
List<Relocator> relocators) throws IOException {
public void processResource(String resource, InputStream inputStream, List<Relocator> relocators)
throws IOException {
Properties properties = new Properties();
properties.load(inputStream);
inputStream.close();

View File

@@ -58,8 +58,7 @@ import org.springframework.boot.loader.tools.Repackager.MainClassTimeoutWarningL
* @author Dave Syer
* @author Stephane Nicoll
*/
@Mojo(name = "repackage", defaultPhase = LifecyclePhase.PACKAGE, requiresProject = true,
threadSafe = true,
@Mojo(name = "repackage", defaultPhase = LifecyclePhase.PACKAGE, requiresProject = true, threadSafe = true,
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME)
public class RepackageMojo extends AbstractDependencyFilterMojo {
@@ -214,10 +213,8 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
File source = this.project.getArtifact().getFile();
File target = getTargetFile();
Repackager repackager = getRepackager(source);
Set<Artifact> artifacts = filterDependencies(this.project.getArtifacts(),
getFilters(getAdditionalFilters()));
Libraries libraries = new ArtifactsLibraries(artifacts, this.requiresUnpack,
getLog());
Set<Artifact> artifacts = filterDependencies(this.project.getArtifacts(), getFilters(getAdditionalFilters()));
Libraries libraries = new ArtifactsLibraries(artifacts, this.requiresUnpack, getLog());
try {
LaunchScript launchScript = getLaunchScript();
repackager.repackage(target, libraries, launchScript);
@@ -236,14 +233,13 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
if (!this.outputDirectory.exists()) {
this.outputDirectory.mkdirs();
}
return new File(this.outputDirectory, this.finalName + classifier + "."
+ this.project.getArtifact().getArtifactHandler().getExtension());
return new File(this.outputDirectory,
this.finalName + classifier + "." + this.project.getArtifact().getArtifactHandler().getExtension());
}
private Repackager getRepackager(File source) {
Repackager repackager = new Repackager(source, this.layoutFactory);
repackager.addMainClassTimeoutWarningListener(
new LoggingMainClassTimeoutWarningListener());
repackager.addMainClassTimeoutWarningListener(new LoggingMainClassTimeoutWarningListener());
repackager.setMainClass(this.mainClass);
if (this.layout != null) {
getLog().info("Layout: " + this.layout);
@@ -269,8 +265,7 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
private LaunchScript getLaunchScript() throws IOException {
if (this.executable || this.embeddedLaunchScript != null) {
return new DefaultLaunchScript(this.embeddedLaunchScript,
buildLaunchScriptProperties());
return new DefaultLaunchScript(this.embeddedLaunchScript, buildLaunchScriptProperties());
}
return null;
}
@@ -281,11 +276,9 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
properties.putAll(this.embeddedLaunchScriptProperties);
}
putIfMissing(properties, "initInfoProvides", this.project.getArtifactId());
putIfMissing(properties, "initInfoShortDescription", this.project.getName(),
this.project.getArtifactId());
putIfMissing(properties, "initInfoDescription",
removeLineBreaks(this.project.getDescription()), this.project.getName(),
this.project.getArtifactId());
putIfMissing(properties, "initInfoShortDescription", this.project.getName(), this.project.getArtifactId());
putIfMissing(properties, "initInfoDescription", removeLineBreaks(this.project.getDescription()),
this.project.getName(), this.project.getArtifactId());
return properties;
}
@@ -293,8 +286,7 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
return (description != null) ? description.replaceAll("\\s+", " ") : null;
}
private void putIfMissing(Properties properties, String key,
String... valueCandidates) {
private void putIfMissing(Properties properties, String key, String... valueCandidates) {
if (!properties.containsKey(key)) {
for (String candidate : valueCandidates) {
if (candidate != null && !candidate.isEmpty()) {
@@ -317,10 +309,8 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
private void attachArtifact(File source, File repackaged) {
if (this.classifier != null) {
getLog().info("Attaching archive: " + repackaged + ", with classifier: "
+ this.classifier);
this.projectHelper.attachArtifact(this.project, this.project.getPackaging(),
this.classifier, repackaged);
getLog().info("Attaching archive: " + repackaged + ", with classifier: " + this.classifier);
this.projectHelper.attachArtifact(this.project, this.project.getPackaging(), this.classifier, repackaged);
}
else if (!source.equals(repackaged)) {
this.project.getArtifact().setFile(repackaged);
@@ -328,8 +318,7 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
}
}
private class LoggingMainClassTimeoutWarningListener
implements MainClassTimeoutWarningListener {
private class LoggingMainClassTimeoutWarningListener implements MainClassTimeoutWarningListener {
@Override
public void handleTimeoutWarning(long duration, String mainMethod) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* 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.
@@ -62,8 +62,7 @@ class RunArguments {
return CommandLineUtils.translateCommandline(arguments);
}
catch (Exception ex) {
throw new IllegalArgumentException(
"Failed to parse arguments [" + arguments + "]", ex);
throw new IllegalArgumentException("Failed to parse arguments [" + arguments + "]", ex);
}
}

View File

@@ -65,19 +65,15 @@ public class RunMojo extends AbstractRunMojo {
}
@Override
protected void runWithForkedJvm(File workingDirectory, List<String> args)
throws MojoExecutionException {
protected void runWithForkedJvm(File workingDirectory, List<String> args) throws MojoExecutionException {
try {
RunProcess runProcess = new RunProcess(workingDirectory,
new JavaExecutable().toString());
Runtime.getRuntime()
.addShutdownHook(new Thread(new RunProcessKiller(runProcess)));
RunProcess runProcess = new RunProcess(workingDirectory, new JavaExecutable().toString());
Runtime.getRuntime().addShutdownHook(new Thread(new RunProcessKiller(runProcess)));
int exitCode = runProcess.run(true, args.toArray(new String[0]));
if (exitCode == 0 || exitCode == EXIT_CODE_SIGINT) {
return;
}
throw new MojoExecutionException(
"Application finished with exit code: " + exitCode);
throw new MojoExecutionException("Application finished with exit code: " + exitCode);
}
catch (Exception ex) {
throw new MojoExecutionException("Could not exec java", ex);
@@ -85,11 +81,9 @@ public class RunMojo extends AbstractRunMojo {
}
@Override
protected void runWithMavenJvm(String startClassName, String... arguments)
throws MojoExecutionException {
protected void runWithMavenJvm(String startClassName, String... arguments) throws MojoExecutionException {
IsolatedThreadGroup threadGroup = new IsolatedThreadGroup(startClassName);
Thread launchThread = new Thread(threadGroup,
new LaunchRunner(startClassName, arguments), "main");
Thread launchThread = new Thread(threadGroup, new LaunchRunner(startClassName, arguments), "main");
launchThread.setContextClassLoader(new URLClassLoader(getClassPathUrls()));
launchThread.start();
join(threadGroup);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* 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.
@@ -66,12 +66,10 @@ class SpringApplicationAdminClient {
return false; // Instance not available yet
}
catch (AttributeNotFoundException ex) {
throw new IllegalStateException("Unexpected: attribute 'Ready' not available",
ex);
throw new IllegalStateException("Unexpected: attribute 'Ready' not available", ex);
}
catch (ReflectionException ex) {
throw new MojoExecutionException("Failed to retrieve Ready attribute",
ex.getCause());
throw new MojoExecutionException("Failed to retrieve Ready attribute", ex.getCause());
}
catch (MBeanException | IOException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
@@ -84,8 +82,7 @@ class SpringApplicationAdminClient {
* @throws IOException if an I/O error occurs
* @throws InstanceNotFoundException if the lifecycle mbean cannot be found
*/
public void stop()
throws MojoExecutionException, IOException, InstanceNotFoundException {
public void stop() throws MojoExecutionException, IOException, InstanceNotFoundException {
try {
this.connection.invoke(this.objectName, "shutdown", null, null);
}

View File

@@ -49,8 +49,7 @@ import org.springframework.boot.loader.tools.RunProcess;
* @since 1.3.0
* @see StopMojo
*/
@Mojo(name = "start", requiresProject = true,
defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST,
@Mojo(name = "start", requiresProject = true, defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST,
requiresDependencyResolution = ResolutionScope.TEST)
public class StartMojo extends AbstractRunMojo {
@@ -102,11 +101,9 @@ public class StartMojo extends AbstractRunMojo {
}
}
private RunProcess runProcess(File workingDirectory, List<String> args)
throws MojoExecutionException {
private RunProcess runProcess(File workingDirectory, List<String> args) throws MojoExecutionException {
try {
RunProcess runProcess = new RunProcess(workingDirectory,
new JavaExecutable().toString());
RunProcess runProcess = new RunProcess(workingDirectory, new JavaExecutable().toString());
runProcess.run(false, args.toArray(new String[0]));
return runProcess;
}
@@ -120,8 +117,7 @@ public class StartMojo extends AbstractRunMojo {
RunArguments applicationArguments = super.resolveApplicationArguments();
applicationArguments.getArgs().addLast(ENABLE_MBEAN_PROPERTY);
if (isFork()) {
applicationArguments.getArgs()
.addLast(JMX_NAME_PROPERTY_PREFIX + this.jmxName);
applicationArguments.getArgs().addLast(JMX_NAME_PROPERTY_PREFIX + this.jmxName);
}
return applicationArguments;
}
@@ -142,18 +138,16 @@ public class StartMojo extends AbstractRunMojo {
}
@Override
protected void runWithMavenJvm(String startClassName, String... arguments)
throws MojoExecutionException {
protected void runWithMavenJvm(String startClassName, String... arguments) throws MojoExecutionException {
IsolatedThreadGroup threadGroup = new IsolatedThreadGroup(startClassName);
Thread launchThread = new Thread(threadGroup,
new LaunchRunner(startClassName, arguments), startClassName + ".main()");
Thread launchThread = new Thread(threadGroup, new LaunchRunner(startClassName, arguments),
startClassName + ".main()");
launchThread.setContextClassLoader(new URLClassLoader(getClassPathUrls()));
launchThread.start();
waitForSpringApplication(this.wait, this.maxAttempts);
}
private void waitForSpringApplication(long wait, int maxAttempts)
throws MojoExecutionException {
private void waitForSpringApplication(long wait, int maxAttempts) throws MojoExecutionException {
SpringApplicationAdminClient client = new SpringApplicationAdminClient(
ManagementFactory.getPlatformMBeanServer(), this.jmxName);
getLog().debug("Waiting for spring application to start...");
@@ -161,8 +155,7 @@ public class StartMojo extends AbstractRunMojo {
if (client.isReady()) {
return;
}
String message = "Spring application is not ready yet, waiting " + wait
+ "ms (attempt " + (i + 1) + ")";
String message = "Spring application is not ready yet, waiting " + wait + "ms (attempt " + (i + 1) + ")";
getLog().debug(message);
synchronized (this.lock) {
try {
@@ -170,18 +163,15 @@ public class StartMojo extends AbstractRunMojo {
}
catch (InterruptedException ex) {
Thread.currentThread().interrupt();
throw new IllegalStateException(
"Interrupted while waiting for Spring Boot app to start.");
throw new IllegalStateException("Interrupted while waiting for Spring Boot app to start.");
}
}
}
throw new MojoExecutionException(
"Spring application did not start before the configured timeout ("
+ (wait * maxAttempts) + "ms");
"Spring application did not start before the configured timeout (" + (wait * maxAttempts) + "ms");
}
private void waitForSpringApplication()
throws MojoFailureException, MojoExecutionException {
private void waitForSpringApplication() throws MojoFailureException, MojoExecutionException {
try {
if (isFork()) {
waitForForkedSpringApplication();
@@ -191,26 +181,20 @@ public class StartMojo extends AbstractRunMojo {
}
}
catch (IOException ex) {
throw new MojoFailureException("Could not contact Spring Boot application",
ex);
throw new MojoFailureException("Could not contact Spring Boot application", ex);
}
catch (Exception ex) {
throw new MojoExecutionException(
"Could not figure out if the application has started", ex);
throw new MojoExecutionException("Could not figure out if the application has started", ex);
}
}
private void waitForForkedSpringApplication()
throws IOException, MojoFailureException, MojoExecutionException {
private void waitForForkedSpringApplication() throws IOException, MojoFailureException, MojoExecutionException {
try {
getLog().debug("Connecting to local MBeanServer at port " + this.jmxPort);
try (JMXConnector connector = execute(this.wait, this.maxAttempts,
new CreateJmxConnector(this.jmxPort))) {
try (JMXConnector connector = execute(this.wait, this.maxAttempts, new CreateJmxConnector(this.jmxPort))) {
if (connector == null) {
throw new MojoExecutionException(
"JMX MBean server was not reachable before the configured "
+ "timeout (" + (this.wait * this.maxAttempts)
+ "ms");
throw new MojoExecutionException("JMX MBean server was not reachable before the configured "
+ "timeout (" + (this.wait * this.maxAttempts) + "ms");
}
getLog().debug("Connected to local MBeanServer at port " + this.jmxPort);
MBeanServerConnection connection = connector.getMBeanServerConnection();
@@ -221,21 +205,18 @@ public class StartMojo extends AbstractRunMojo {
throw ex;
}
catch (Exception ex) {
throw new MojoExecutionException(
"Failed to connect to MBean server at port " + this.jmxPort, ex);
throw new MojoExecutionException("Failed to connect to MBean server at port " + this.jmxPort, ex);
}
}
private void doWaitForSpringApplication(MBeanServerConnection connection)
throws IOException, MojoExecutionException, MojoFailureException {
final SpringApplicationAdminClient client = new SpringApplicationAdminClient(
connection, this.jmxName);
final SpringApplicationAdminClient client = new SpringApplicationAdminClient(connection, this.jmxName);
try {
execute(this.wait, this.maxAttempts, () -> (client.isReady() ? true : null));
}
catch (ReflectionException ex) {
throw new MojoExecutionException("Unable to retrieve 'ready' attribute",
ex.getCause());
throw new MojoExecutionException("Unable to retrieve 'ready' attribute", ex.getCause());
}
catch (Exception ex) {
throw new MojoFailureException("Could not invoke shutdown operation", ex);
@@ -252,16 +233,14 @@ public class StartMojo extends AbstractRunMojo {
* @return the result
* @throws Exception in case of execution errors
*/
public <T> T execute(long wait, int maxAttempts, Callable<T> callback)
throws Exception {
public <T> T execute(long wait, int maxAttempts, Callable<T> callback) throws Exception {
getLog().debug("Waiting for spring application to start...");
for (int i = 0; i < maxAttempts; i++) {
T result = callback.call();
if (result != null) {
return result;
}
String message = "Spring application is not ready yet, waiting " + wait
+ "ms (attempt " + (i + 1) + ")";
String message = "Spring application is not ready yet, waiting " + wait + "ms (attempt " + (i + 1) + ")";
getLog().debug(message);
synchronized (this.lock) {
try {
@@ -269,14 +248,12 @@ public class StartMojo extends AbstractRunMojo {
}
catch (InterruptedException ex) {
Thread.currentThread().interrupt();
throw new IllegalStateException(
"Interrupted while waiting for Spring Boot app to start.");
throw new IllegalStateException("Interrupted while waiting for Spring Boot app to start.");
}
}
}
throw new MojoExecutionException(
"Spring application did not start before the configured " + "timeout ("
+ (wait * maxAttempts) + "ms");
"Spring application did not start before the configured " + "timeout (" + (wait * maxAttempts) + "ms");
}
private class CreateJmxConnector implements Callable<JMXConnector> {
@@ -294,8 +271,7 @@ public class StartMojo extends AbstractRunMojo {
}
catch (IOException ex) {
if (hasCauseWithType(ex, ConnectException.class)) {
String message = "MBean server at port " + this.port
+ " is not up yet...";
String message = "MBean server at port " + this.port + " is not up yet...";
getLog().debug(message);
return null;
}
@@ -304,8 +280,7 @@ public class StartMojo extends AbstractRunMojo {
}
private boolean hasCauseWithType(Throwable t, Class<? extends Exception> type) {
return type.isAssignableFrom(t.getClass())
|| t.getCause() != null && hasCauseWithType(t.getCause(), type);
return type.isAssignableFrom(t.getClass()) || t.getCause() != null && hasCauseWithType(t.getCause(), type);
}
}

View File

@@ -38,8 +38,7 @@ import org.apache.maven.project.MavenProject;
* @author Stephane Nicoll
* @since 1.3.0
*/
@Mojo(name = "stop", requiresProject = true,
defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST)
@Mojo(name = "stop", requiresProject = true, defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST)
public class StopMojo extends AbstractMojo {
/**
@@ -104,15 +103,12 @@ public class StopMojo extends AbstractMojo {
if (this.fork != null) {
return this.fork;
}
String property = this.project.getProperties()
.getProperty("_spring.boot.fork.enabled");
String property = this.project.getProperties().getProperty("_spring.boot.fork.enabled");
return Boolean.valueOf(property);
}
private void stopForkedProcess()
throws IOException, MojoFailureException, MojoExecutionException {
try (JMXConnector connector = SpringApplicationAdminClient
.connect(this.jmxPort)) {
private void stopForkedProcess() throws IOException, MojoFailureException, MojoExecutionException {
try (JMXConnector connector = SpringApplicationAdminClient.connect(this.jmxPort)) {
MBeanServerConnection connection = connector.getMBeanServerConnection();
doStop(connection);
}
@@ -122,16 +118,13 @@ public class StopMojo extends AbstractMojo {
doStop(ManagementFactory.getPlatformMBeanServer());
}
private void doStop(MBeanServerConnection connection)
throws IOException, MojoExecutionException {
private void doStop(MBeanServerConnection connection) throws IOException, MojoExecutionException {
try {
new SpringApplicationAdminClient(connection, this.jmxName).stop();
}
catch (InstanceNotFoundException ex) {
throw new MojoExecutionException(
"Spring application lifecycle JMX bean not found (fork is "
+ this.fork + "). Could not stop application gracefully",
ex);
throw new MojoExecutionException("Spring application lifecycle JMX bean not found (fork is " + this.fork
+ "). Could not stop application gracefully", ex);
}
}