Merge branch '2.0.x' into 2.1.x

Closes gh-17078
This commit is contained in:
Andy Wilkinson
2019-06-07 10:50:34 +01:00
2691 changed files with 27746 additions and 46049 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.
@@ -75,8 +75,8 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
this.excludeGroupIds = excludeGroupIds;
}
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));
@@ -97,8 +97,7 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
for (ArtifactsFilter additionalFilter : additionalFilters) {
filters.addFilter(additionalFilter);
}
filters.addFilter(
new MatchingGroupIdFilter(cleanFilterConfig(this.excludeGroupIds)));
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.
@@ -203,8 +203,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()));
}
/**
@@ -213,8 +212,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
* @see #logDisabledFork()
*/
protected boolean enableForkByDefault() {
return hasAgent() || hasJvmArgs() || hasEnvVariables()
|| hasWorkingDirectorySet();
return hasAgent() || hasJvmArgs() || hasEnvVariables() || hasWorkingDirectorySet();
}
private boolean hasAgent() {
@@ -223,24 +221,20 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
private boolean hasJvmArgs() {
return (this.jvmArguments != null && !this.jvmArguments.isEmpty())
|| (this.systemPropertyVariables != null
&& !this.systemPropertyVariables.isEmpty());
|| (this.systemPropertyVariables != null && !this.systemPropertyVariables.isEmpty());
}
private boolean hasEnvVariables() {
return (this.environmentVariables != null
&& !this.environmentVariables.isEmpty());
return (this.environmentVariables != null && !this.environmentVariables.isEmpty());
}
private boolean hasWorkingDirectorySet() {
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);
}
@@ -262,29 +256,24 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
}
if (hasJvmArgs()) {
RunArguments runArguments = resolveJvmArguments();
getLog().warn("Fork mode disabled, ignoring JVM argument(s) [" + Arrays
.stream(runArguments.asArray()).collect(Collectors.joining(" "))
+ "]");
getLog().warn("Fork mode disabled, ignoring JVM argument(s) ["
+ Arrays.stream(runArguments.asArray()).collect(Collectors.joining(" ")) + "]");
}
if (hasWorkingDirectorySet()) {
getLog().warn(
"Fork mode disabled, ignoring working directory configuration");
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);
addClasspath(args);
args.add(startClassName);
addArgs(args);
runWithForkedJvm(
(this.workingDirectory != null) ? this.workingDirectory
: this.project.getBasedir(),
args, determineEnvironmentVariables());
runWithForkedJvm((this.workingDirectory != null) ? this.workingDirectory : this.project.getBasedir(), args,
determineEnvironmentVariables());
}
/**
@@ -296,8 +285,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
* @throws MojoFailureException in case of MOJO failures
*/
protected abstract void runWithForkedJvm(File workingDirectory, List<String> args,
Map<String, String> environmentVariables)
throws MojoExecutionException, MojoFailureException;
Map<String, String> environmentVariables) throws MojoExecutionException, MojoFailureException;
/**
* Run with the current VM, using the specified arguments.
@@ -422,8 +410,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;
}
@@ -455,8 +443,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);
}
}
}
@@ -465,12 +452,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());
@@ -480,8 +464,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
private void logArguments(String message, String[] args) {
if (getLog().isDebugEnabled()) {
getLog().debug(
Arrays.stream(args).collect(Collectors.joining(" ", message, "")));
getLog().debug(Arrays.stream(args).collect(Collectors.joining(" ", message, "")));
}
}
@@ -525,9 +508,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);
}
}
}
@@ -562,9 +543,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

@@ -60,8 +60,7 @@ import org.springframework.boot.loader.tools.Repackager.MainClassTimeoutWarningL
* @author Stephane Nicoll
* @author Björn Lindström
*/
@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 {
@@ -220,10 +219,8 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
Artifact source = getSourceArtifact();
File target = getTargetFile();
Repackager repackager = getRepackager(source.getFile());
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);
@@ -248,8 +245,7 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
private Artifact getArtifact(String classifier) {
if (classifier != null) {
for (Artifact attachedArtifact : this.project.getAttachedArtifacts()) {
if (classifier.equals(attachedArtifact.getClassifier())
&& attachedArtifact.getFile() != null
if (classifier.equals(attachedArtifact.getClassifier()) && attachedArtifact.getFile() != null
&& attachedArtifact.getFile().isFile()) {
return attachedArtifact;
}
@@ -266,14 +262,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);
@@ -299,8 +294,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;
}
@@ -311,21 +305,17 @@ 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;
}
private String removeLineBreaks(String description) {
return (description != null)
? WHITE_SPACE_PATTERN.matcher(description).replaceAll(" ") : null;
return (description != null) ? WHITE_SPACE_PATTERN.matcher(description).replaceAll(" ") : 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()) {
@@ -341,35 +331,30 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
attachArtifact(source, target);
}
else if (source.getFile().equals(target) && original.exists()) {
String artifactId = (this.classifier != null)
? "artifact with classifier " + this.classifier : "main artifact";
getLog().info(String.format("Updating %s %s to %s", artifactId,
source.getFile(), original));
String artifactId = (this.classifier != null) ? "artifact with classifier " + this.classifier
: "main artifact";
getLog().info(String.format("Updating %s %s to %s", artifactId, source.getFile(), original));
source.setFile(original);
}
else if (this.classifier != null) {
getLog().info("Creating repackaged archive " + target + " with classifier "
+ this.classifier);
getLog().info("Creating repackaged archive " + target + " with classifier " + this.classifier);
}
}
private void attachArtifact(Artifact source, File target) {
if (this.classifier != null && !source.getFile().equals(target)) {
getLog().info("Attaching repackaged archive " + target + " with classifier "
+ this.classifier);
this.projectHelper.attachArtifact(this.project, this.project.getPackaging(),
this.classifier, target);
getLog().info("Attaching repackaged archive " + target + " with classifier " + this.classifier);
this.projectHelper.attachArtifact(this.project, this.project.getPackaging(), this.classifier, target);
}
else {
String artifactId = (this.classifier != null)
? "artifact with classifier " + this.classifier : "main artifact";
String artifactId = (this.classifier != null) ? "artifact with classifier " + this.classifier
: "main artifact";
getLog().info("Replacing " + artifactId + " with repackaged archive");
source.setFile(target);
}
}
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

@@ -67,19 +67,16 @@ public class RunMojo extends AbstractRunMojo {
}
@Override
protected void runWithForkedJvm(File workingDirectory, List<String> args,
Map<String, String> environmentVariables) throws MojoExecutionException {
protected void runWithForkedJvm(File workingDirectory, List<String> args, Map<String, String> environmentVariables)
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, environmentVariables);
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);
@@ -87,11 +84,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

@@ -50,8 +50,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 {
@@ -91,8 +90,7 @@ public class StartMojo extends AbstractRunMojo {
private final Object lock = new Object();
@Override
protected void runWithForkedJvm(File workingDirectory, List<String> args,
Map<String, String> environmentVariables)
protected void runWithForkedJvm(File workingDirectory, List<String> args, Map<String, String> environmentVariables)
throws MojoExecutionException, MojoFailureException {
RunProcess runProcess = runProcess(workingDirectory, args, environmentVariables);
try {
@@ -104,11 +102,10 @@ public class StartMojo extends AbstractRunMojo {
}
}
private RunProcess runProcess(File workingDirectory, List<String> args,
Map<String, String> environmentVariables) throws MojoExecutionException {
private RunProcess runProcess(File workingDirectory, List<String> args, Map<String, String> environmentVariables)
throws MojoExecutionException {
try {
RunProcess runProcess = new RunProcess(workingDirectory,
new JavaExecutable().toString());
RunProcess runProcess = new RunProcess(workingDirectory, new JavaExecutable().toString());
runProcess.run(false, args, environmentVariables);
return runProcess;
}
@@ -122,8 +119,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;
}
@@ -144,18 +140,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...");
@@ -163,8 +157,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 {
@@ -172,18 +165,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();
@@ -193,26 +183,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();
@@ -223,21 +207,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);
@@ -254,16 +235,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 {
@@ -271,14 +250,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> {
@@ -296,8 +273,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;
}
@@ -306,8 +282,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);
}
}

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.
@@ -99,8 +99,7 @@ public class ArtifactsLibrariesTests {
Dependency unpack = new Dependency();
unpack.setGroupId("gid");
unpack.setArtifactId("aid");
this.libs = new ArtifactsLibraries(this.artifacts, Collections.singleton(unpack),
mock(Log.class));
this.libs = new ArtifactsLibraries(this.artifacts, Collections.singleton(unpack), mock(Log.class));
this.libs.doWithLibraries(this.callback);
verify(this.callback).library(this.libraryCaptor.capture());
assertThat(this.libraryCaptor.getValue().isUnpackRequired()).isTrue();
@@ -128,10 +127,8 @@ public class ArtifactsLibrariesTests {
this.libs = new ArtifactsLibraries(this.artifacts, null, mock(Log.class));
this.libs.doWithLibraries(this.callback);
verify(this.callback, times(2)).library(this.libraryCaptor.capture());
assertThat(this.libraryCaptor.getAllValues().get(0).getName())
.isEqualTo("g1-artifact-1.0.jar");
assertThat(this.libraryCaptor.getAllValues().get(1).getName())
.isEqualTo("g2-artifact-1.0.jar");
assertThat(this.libraryCaptor.getAllValues().get(0).getName()).isEqualTo("g1-artifact-1.0.jar");
assertThat(this.libraryCaptor.getAllValues().get(1).getName()).isEqualTo("g2-artifact-1.0.jar");
}
}

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.
@@ -41,34 +41,29 @@ public class DependencyFilterMojoTests {
@Test
public void filterDependencies() throws MojoExecutionException {
TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(
Collections.emptyList(), "com.foo");
TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(Collections.emptyList(), "com.foo");
Artifact artifact = createArtifact("com.bar", "one");
Set<Artifact> artifacts = mojo.filterDependencies(
createArtifact("com.foo", "one"), createArtifact("com.foo", "two"),
artifact);
Set<Artifact> artifacts = mojo.filterDependencies(createArtifact("com.foo", "one"),
createArtifact("com.foo", "two"), artifact);
assertThat(artifacts).hasSize(1);
assertThat(artifacts.iterator().next()).isSameAs(artifact);
}
@Test
public void filterGroupIdExactMatch() throws MojoExecutionException {
TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(
Collections.emptyList(), "com.foo");
TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(Collections.emptyList(), "com.foo");
Artifact artifact = createArtifact("com.foo.bar", "one");
Set<Artifact> artifacts = mojo.filterDependencies(
createArtifact("com.foo", "one"), createArtifact("com.foo", "two"),
artifact);
Set<Artifact> artifacts = mojo.filterDependencies(createArtifact("com.foo", "one"),
createArtifact("com.foo", "two"), artifact);
assertThat(artifacts).hasSize(1);
assertThat(artifacts.iterator().next()).isSameAs(artifact);
}
@Test
public void filterScopeKeepOrder() throws MojoExecutionException {
TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(
Collections.emptyList(), "",
TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(Collections.emptyList(), "",
new ScopeFilter(null, Artifact.SCOPE_SYSTEM));
Artifact one = createArtifact("com.foo", "one");
Artifact two = createArtifact("com.foo", "two", Artifact.SCOPE_SYSTEM);
@@ -79,8 +74,7 @@ public class DependencyFilterMojoTests {
@Test
public void filterGroupIdKeepOrder() throws MojoExecutionException {
TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(
Collections.emptyList(), "com.foo");
TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(Collections.emptyList(), "com.foo");
Artifact one = createArtifact("com.foo", "one");
Artifact two = createArtifact("com.bar", "two");
Artifact three = createArtifact("com.bar", "three");
@@ -94,8 +88,7 @@ public class DependencyFilterMojoTests {
Exclude exclude = new Exclude();
exclude.setGroupId("com.bar");
exclude.setArtifactId("two");
TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(
Collections.singletonList(exclude), "");
TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(Collections.singletonList(exclude), "");
Artifact one = createArtifact("com.foo", "one");
Artifact two = createArtifact("com.bar", "two");
Artifact three = createArtifact("com.bar", "three");
@@ -108,8 +101,7 @@ public class DependencyFilterMojoTests {
return createArtifact(groupId, artifactId, null);
}
private static Artifact createArtifact(String groupId, String artifactId,
String scope) {
private static Artifact createArtifact(String groupId, String artifactId, String scope) {
Artifact a = mock(Artifact.class);
given(a.getGroupId()).willReturn(groupId);
given(a.getArtifactId()).willReturn(artifactId);
@@ -119,20 +111,18 @@ public class DependencyFilterMojoTests {
return a;
}
private static final class TestableDependencyFilterMojo
extends AbstractDependencyFilterMojo {
private static final class TestableDependencyFilterMojo extends AbstractDependencyFilterMojo {
private final ArtifactsFilter[] additionalFilters;
private TestableDependencyFilterMojo(List<Exclude> excludes,
String excludeGroupIds, ArtifactsFilter... additionalFilters) {
private TestableDependencyFilterMojo(List<Exclude> excludes, String excludeGroupIds,
ArtifactsFilter... additionalFilters) {
setExcludes(excludes);
setExcludeGroupIds(excludeGroupIds);
this.additionalFilters = additionalFilters;
}
public Set<Artifact> filterDependencies(Artifact... artifacts)
throws MojoExecutionException {
public Set<Artifact> filterDependencies(Artifact... artifacts) throws MojoExecutionException {
Set<Artifact> input = new LinkedHashSet<>(Arrays.asList(artifacts));
return filterDependencies(input, getFilters(this.additionalFilters));
}

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.
@@ -39,15 +39,14 @@ public class EnvVariablesTests {
@Test
public void asArray() {
assertThat(new EnvVariables(getTestArgs()).asArray()).contains("key=My Value",
"key1= tt ", "key2= ", "key3=");
assertThat(new EnvVariables(getTestArgs()).asArray()).contains("key=My Value", "key1= tt ", "key2= ",
"key3=");
}
@Test
public void asMap() {
assertThat(new EnvVariables(getTestArgs()).asMap()).containsExactly(
entry("key", "My Value"), entry("key1", " tt "), entry("key2", " "),
entry("key3", ""));
assertThat(new EnvVariables(getTestArgs()).asMap()).containsExactly(entry("key", "My Value"),
entry("key1", " tt "), entry("key2", " "), entry("key3", ""));
}
private Map<String, String> getTestArgs() {

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.
@@ -40,17 +40,14 @@ public class ExcludeFilterTests {
@Test
public void excludeSimple() throws ArtifactFilterException {
ExcludeFilter filter = new ExcludeFilter(
Arrays.asList(createExclude("com.foo", "bar")));
Set result = filter
.filter(Collections.singleton(createArtifact("com.foo", "bar")));
ExcludeFilter filter = new ExcludeFilter(Arrays.asList(createExclude("com.foo", "bar")));
Set result = filter.filter(Collections.singleton(createArtifact("com.foo", "bar")));
assertThat(result).isEmpty();
}
@Test
public void excludeGroupIdNoMatch() throws ArtifactFilterException {
ExcludeFilter filter = new ExcludeFilter(
Arrays.asList(createExclude("com.foo", "bar")));
ExcludeFilter filter = new ExcludeFilter(Arrays.asList(createExclude("com.foo", "bar")));
Artifact artifact = createArtifact("com.baz", "bar");
Set result = filter.filter(Collections.singleton(artifact));
assertThat(result).hasSize(1);
@@ -59,8 +56,7 @@ public class ExcludeFilterTests {
@Test
public void excludeArtifactIdNoMatch() throws ArtifactFilterException {
ExcludeFilter filter = new ExcludeFilter(
Arrays.asList(createExclude("com.foo", "bar")));
ExcludeFilter filter = new ExcludeFilter(Arrays.asList(createExclude("com.foo", "bar")));
Artifact artifact = createArtifact("com.foo", "biz");
Set result = filter.filter(Collections.singleton(artifact));
assertThat(result).hasSize(1);
@@ -69,17 +65,14 @@ public class ExcludeFilterTests {
@Test
public void excludeClassifier() throws ArtifactFilterException {
ExcludeFilter filter = new ExcludeFilter(
Arrays.asList(createExclude("com.foo", "bar", "jdk5")));
Set result = filter
.filter(Collections.singleton(createArtifact("com.foo", "bar", "jdk5")));
ExcludeFilter filter = new ExcludeFilter(Arrays.asList(createExclude("com.foo", "bar", "jdk5")));
Set result = filter.filter(Collections.singleton(createArtifact("com.foo", "bar", "jdk5")));
assertThat(result).isEmpty();
}
@Test
public void excludeClassifierNoTargetClassifier() throws ArtifactFilterException {
ExcludeFilter filter = new ExcludeFilter(
Arrays.asList(createExclude("com.foo", "bar", "jdk5")));
ExcludeFilter filter = new ExcludeFilter(Arrays.asList(createExclude("com.foo", "bar", "jdk5")));
Artifact artifact = createArtifact("com.foo", "bar");
Set result = filter.filter(Collections.singleton(artifact));
assertThat(result).hasSize(1);
@@ -88,8 +81,7 @@ public class ExcludeFilterTests {
@Test
public void excludeClassifierNoMatch() throws ArtifactFilterException {
ExcludeFilter filter = new ExcludeFilter(
Arrays.asList(createExclude("com.foo", "bar", "jdk5")));
ExcludeFilter filter = new ExcludeFilter(Arrays.asList(createExclude("com.foo", "bar", "jdk5")));
Artifact artifact = createArtifact("com.foo", "bar", "jdk6");
Set result = filter.filter(Collections.singleton(artifact));
assertThat(result).hasSize(1);
@@ -98,9 +90,8 @@ public class ExcludeFilterTests {
@Test
public void excludeMulti() throws ArtifactFilterException {
ExcludeFilter filter = new ExcludeFilter(Arrays.asList(
createExclude("com.foo", "bar"), createExclude("com.foo", "bar2"),
createExclude("org.acme", "app")));
ExcludeFilter filter = new ExcludeFilter(Arrays.asList(createExclude("com.foo", "bar"),
createExclude("com.foo", "bar2"), createExclude("org.acme", "app")));
Set<Artifact> artifacts = new HashSet<>();
artifacts.add(createArtifact("com.foo", "bar"));
artifacts.add(createArtifact("com.foo", "bar"));
@@ -125,8 +116,7 @@ public class ExcludeFilterTests {
return exclude;
}
private Artifact createArtifact(String groupId, String artifactId,
String classifier) {
private Artifact createArtifact(String groupId, String artifactId, String classifier) {
Artifact a = mock(Artifact.class);
given(a.getGroupId()).willReturn(groupId);
given(a.getArtifactId()).willReturn(artifactId);

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.
@@ -39,8 +39,7 @@ public class IncludeFilterTests {
@Test
public void includeSimple() throws ArtifactFilterException {
IncludeFilter filter = new IncludeFilter(
Arrays.asList(createInclude("com.foo", "bar")));
IncludeFilter filter = new IncludeFilter(Arrays.asList(createInclude("com.foo", "bar")));
Artifact artifact = createArtifact("com.foo", "bar");
Set result = filter.filter(Collections.singleton(artifact));
assertThat(result).hasSize(1);
@@ -49,8 +48,7 @@ public class IncludeFilterTests {
@Test
public void includeGroupIdNoMatch() throws ArtifactFilterException {
IncludeFilter filter = new IncludeFilter(
Arrays.asList(createInclude("com.foo", "bar")));
IncludeFilter filter = new IncludeFilter(Arrays.asList(createInclude("com.foo", "bar")));
Artifact artifact = createArtifact("com.baz", "bar");
Set result = filter.filter(Collections.singleton(artifact));
assertThat(result).isEmpty();
@@ -58,8 +56,7 @@ public class IncludeFilterTests {
@Test
public void includeArtifactIdNoMatch() throws ArtifactFilterException {
IncludeFilter filter = new IncludeFilter(
Arrays.asList(createInclude("com.foo", "bar")));
IncludeFilter filter = new IncludeFilter(Arrays.asList(createInclude("com.foo", "bar")));
Artifact artifact = createArtifact("com.foo", "biz");
Set result = filter.filter(Collections.singleton(artifact));
assertThat(result).isEmpty();
@@ -67,8 +64,7 @@ public class IncludeFilterTests {
@Test
public void includeClassifier() throws ArtifactFilterException {
IncludeFilter filter = new IncludeFilter(
Arrays.asList(createInclude("com.foo", "bar", "jdk5")));
IncludeFilter filter = new IncludeFilter(Arrays.asList(createInclude("com.foo", "bar", "jdk5")));
Artifact artifact = createArtifact("com.foo", "bar", "jdk5");
Set result = filter.filter(Collections.singleton(artifact));
assertThat(result).hasSize(1);
@@ -77,8 +73,7 @@ public class IncludeFilterTests {
@Test
public void includeClassifierNoTargetClassifier() throws ArtifactFilterException {
IncludeFilter filter = new IncludeFilter(
Arrays.asList(createInclude("com.foo", "bar", "jdk5")));
IncludeFilter filter = new IncludeFilter(Arrays.asList(createInclude("com.foo", "bar", "jdk5")));
Artifact artifact = createArtifact("com.foo", "bar");
Set result = filter.filter(Collections.singleton(artifact));
assertThat(result).isEmpty();
@@ -86,8 +81,7 @@ public class IncludeFilterTests {
@Test
public void includeClassifierNoMatch() throws ArtifactFilterException {
IncludeFilter filter = new IncludeFilter(
Arrays.asList(createInclude("com.foo", "bar", "jdk5")));
IncludeFilter filter = new IncludeFilter(Arrays.asList(createInclude("com.foo", "bar", "jdk5")));
Artifact artifact = createArtifact("com.foo", "bar", "jdk6");
Set result = filter.filter(Collections.singleton(artifact));
assertThat(result).isEmpty();
@@ -95,9 +89,8 @@ public class IncludeFilterTests {
@Test
public void includeMulti() throws ArtifactFilterException {
IncludeFilter filter = new IncludeFilter(Arrays.asList(
createInclude("com.foo", "bar"), createInclude("com.foo", "bar2"),
createInclude("org.acme", "app")));
IncludeFilter filter = new IncludeFilter(Arrays.asList(createInclude("com.foo", "bar"),
createInclude("com.foo", "bar2"), createInclude("org.acme", "app")));
Set<Artifact> artifacts = new HashSet<>();
artifacts.add(createArtifact("com.foo", "bar"));
artifacts.add(createArtifact("com.foo", "bar"));
@@ -121,8 +114,7 @@ public class IncludeFilterTests {
return include;
}
private Artifact createArtifact(String groupId, String artifactId,
String classifier) {
private Artifact createArtifact(String groupId, String artifactId, String classifier) {
Artifact a = mock(Artifact.class);
given(a.getGroupId()).willReturn(groupId);
given(a.getArtifactId()).willReturn(artifactId);

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.
@@ -36,25 +36,21 @@ public class PropertiesMergingResourceTransformerTests {
@Test
public void testProcess() throws Exception {
assertThat(this.transformer.hasTransformedResource()).isFalse();
this.transformer.processResource("foo",
new ByteArrayInputStream("foo=bar".getBytes()), null);
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null);
assertThat(this.transformer.hasTransformedResource()).isTrue();
}
@Test
public void testMerge() throws Exception {
this.transformer.processResource("foo",
new ByteArrayInputStream("foo=bar".getBytes()), null);
this.transformer.processResource("bar",
new ByteArrayInputStream("foo=spam".getBytes()), null);
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null);
this.transformer.processResource("bar", new ByteArrayInputStream("foo=spam".getBytes()), null);
assertThat(this.transformer.getData().getProperty("foo")).isEqualTo("bar,spam");
}
@Test
public void testOutput() throws Exception {
this.transformer.setResource("foo");
this.transformer.processResource("foo",
new ByteArrayInputStream("foo=bar".getBytes()), null);
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null);
ByteArrayOutputStream out = new ByteArrayOutputStream();
JarOutputStream os = new JarOutputStream(out);
this.transformer.modifyOutputStream(os);

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.
@@ -64,12 +64,10 @@ public class RunArgumentsTests {
@Test
public void parseDebugFlags() {
String[] args = parseArgs(
"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005");
String[] args = parseArgs("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005");
assertThat(args.length).isEqualTo(2);
assertThat(args[0]).isEqualTo("-Xdebug");
assertThat(args[1]).isEqualTo(
"-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005");
assertThat(args[1]).isEqualTo("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005");
}
@Test

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.
@@ -39,8 +39,7 @@ public class SystemPropertyFormatterTests {
@Test
public void parseKeyWithValue() {
assertThat(SystemPropertyFormatter.format("key1", "value1"))
.isEqualTo("-Dkey1=\"value1\"");
assertThat(SystemPropertyFormatter.format("key1", "value1")).isEqualTo("-Dkey1=\"value1\"");
}
@Test
@@ -50,8 +49,7 @@ public class SystemPropertyFormatterTests {
@Test
public void parseKeyWithOnlySpaces() {
assertThat(SystemPropertyFormatter.format("key1", " "))
.isEqualTo("-Dkey1=\" \"");
assertThat(SystemPropertyFormatter.format("key1", " ")).isEqualTo("-Dkey1=\" \"");
}
}

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.
@@ -51,13 +51,12 @@ public final class Verify {
new JarArchiveVerification(file, SAMPLE_APP).verify();
}
public static void verifyJar(File file, String main, String... scriptContents)
throws Exception {
public static void verifyJar(File file, String main, String... scriptContents) throws Exception {
verifyJar(file, main, true, scriptContents);
}
public static void verifyJar(File file, String main, boolean executable,
String... scriptContents) throws Exception {
public static void verifyJar(File file, String main, boolean executable, String... scriptContents)
throws Exception {
new JarArchiveVerification(file, main).verify(executable, scriptContents);
}
@@ -73,8 +72,8 @@ public final class Verify {
new ModuleArchiveVerification(file).verify();
}
public static Properties verifyBuildInfo(File file, String group, String artifact,
String name, String version) throws IOException {
public static Properties verifyBuildInfo(File file, String group, String artifact, String name, String version)
throws IOException {
FileSystemResource resource = new FileSystemResource(file);
Properties properties = PropertiesLoaderUtils.loadProperties(resource);
assertThat(properties.get("build.group")).isEqualTo(group);
@@ -112,21 +111,18 @@ public final class Verify {
public void assertHasNoEntryNameStartingWith(String entry) {
for (String name : this.content.keySet()) {
if (name.startsWith(entry)) {
throw new IllegalStateException("Entry starting with " + entry
+ " should not have been found");
throw new IllegalStateException("Entry starting with " + entry + " should not have been found");
}
}
}
public void assertHasNonUnpackEntry(String entryName) {
assertThat(hasNonUnpackEntry(entryName))
.as("Entry starting with " + entryName + " was an UNPACK entry")
assertThat(hasNonUnpackEntry(entryName)).as("Entry starting with " + entryName + " was an UNPACK entry")
.isTrue();
}
public void assertHasUnpackEntry(String entryName) {
assertThat(hasUnpackEntry(entryName))
.as("Entry starting with " + entryName + " was not an UNPACK entry")
assertThat(hasUnpackEntry(entryName)).as("Entry starting with " + entryName + " was not an UNPACK entry")
.isTrue();
}
@@ -140,11 +136,9 @@ public final class Verify {
}
private ZipEntry getEntryStartingWith(String entryName) {
return this.content.entrySet().stream()
.filter((entry) -> entry.getKey().startsWith(entryName))
return this.content.entrySet().stream().filter((entry) -> entry.getKey().startsWith(entryName))
.map(Map.Entry::getValue).findFirst()
.orElseThrow(() -> new IllegalStateException(
"Unable to find entry starting with " + entryName));
.orElseThrow(() -> new IllegalStateException("Unable to find entry starting with " + entryName));
}
public boolean hasEntry(String entry) {
@@ -177,14 +171,12 @@ public final class Verify {
verify(true);
}
public void verify(boolean executable, String... scriptContents)
throws Exception {
public void verify(boolean executable, String... scriptContents) throws Exception {
assertThat(this.file).exists().isFile();
if (scriptContents.length > 0 && executable) {
String contents = new String(FileCopyUtils.copyToByteArray(this.file));
contents = contents.substring(0, contents
.indexOf(new String(new byte[] { 0x50, 0x4b, 0x03, 0x04 })));
contents = contents.substring(0, contents.indexOf(new String(new byte[] { 0x50, 0x4b, 0x03, 0x04 })));
for (String content : scriptContents) {
assertThat(contents).contains(content);
}
@@ -192,8 +184,7 @@ public final class Verify {
if (!executable) {
String contents = new String(FileCopyUtils.copyToByteArray(this.file));
assertThat(contents).as("Is executable")
.startsWith(new String(new byte[] { 0x50, 0x4b, 0x03, 0x04 }));
assertThat(contents).as("Is executable").startsWith(new String(new byte[] { 0x50, 0x4b, 0x03, 0x04 }));
}
try (ZipFile zipFile = new ZipFile(this.file)) {
@@ -207,8 +198,7 @@ public final class Verify {
}
private void verifyManifest(ArchiveVerifier verifier) throws Exception {
Manifest manifest = new Manifest(
verifier.getEntryContent("META-INF/MANIFEST.MF"));
Manifest manifest = new Manifest(verifier.getEntryContent("META-INF/MANIFEST.MF"));
verifyManifest(manifest);
}
@@ -231,22 +221,18 @@ public final class Verify {
verifier.assertHasEntryNameStartingWith("BOOT-INF/lib/spring-context");
verifier.assertHasEntryNameStartingWith("BOOT-INF/lib/spring-core");
verifier.assertHasEntryNameStartingWith("BOOT-INF/lib/javax.servlet-api-4");
assertThat(verifier
.hasEntry("org/springframework/boot/loader/JarLauncher.class"))
.as("Unpacked launcher classes").isTrue();
assertThat(verifier
.hasEntry("BOOT-INF/classes/org/test/SampleApplication.class"))
.as("Own classes").isTrue();
assertThat(verifier.hasEntry("org/springframework/boot/loader/JarLauncher.class"))
.as("Unpacked launcher classes").isTrue();
assertThat(verifier.hasEntry("BOOT-INF/classes/org/test/SampleApplication.class")).as("Own classes")
.isTrue();
}
@Override
protected void verifyManifest(Manifest manifest) throws Exception {
assertThat(manifest.getMainAttributes().getValue("Main-Class"))
.isEqualTo("org.springframework.boot.loader.JarLauncher");
assertThat(manifest.getMainAttributes().getValue("Start-Class"))
.isEqualTo(this.main);
assertThat(manifest.getMainAttributes().getValue("Not-Used"))
.isEqualTo("Foo");
assertThat(manifest.getMainAttributes().getValue("Start-Class")).isEqualTo(this.main);
assertThat(manifest.getMainAttributes().getValue("Not-Used")).isEqualTo("Foo");
}
}
@@ -262,14 +248,11 @@ public final class Verify {
super.verifyZipEntries(verifier);
verifier.assertHasEntryNameStartingWith("WEB-INF/lib/spring-context");
verifier.assertHasEntryNameStartingWith("WEB-INF/lib/spring-core");
verifier.assertHasEntryNameStartingWith(
"WEB-INF/lib-provided/javax.servlet-api-4");
assertThat(verifier
.hasEntry("org/" + "springframework/boot/loader/JarLauncher.class"))
.as("Unpacked launcher classes").isTrue();
assertThat(verifier
.hasEntry("WEB-INF/classes/org/" + "test/SampleApplication.class"))
.as("Own classes").isTrue();
verifier.assertHasEntryNameStartingWith("WEB-INF/lib-provided/javax.servlet-api-4");
assertThat(verifier.hasEntry("org/" + "springframework/boot/loader/JarLauncher.class"))
.as("Unpacked launcher classes").isTrue();
assertThat(verifier.hasEntry("WEB-INF/classes/org/" + "test/SampleApplication.class")).as("Own classes")
.isTrue();
assertThat(verifier.hasEntry("index.html")).as("Web content").isTrue();
}
@@ -277,10 +260,8 @@ public final class Verify {
protected void verifyManifest(Manifest manifest) throws Exception {
assertThat(manifest.getMainAttributes().getValue("Main-Class"))
.isEqualTo("org.springframework.boot.loader.WarLauncher");
assertThat(manifest.getMainAttributes().getValue("Start-Class"))
.isEqualTo("org.test.SampleApplication");
assertThat(manifest.getMainAttributes().getValue("Not-Used"))
.isEqualTo("Foo");
assertThat(manifest.getMainAttributes().getValue("Start-Class")).isEqualTo("org.test.SampleApplication");
assertThat(manifest.getMainAttributes().getValue("Not-Used")).isEqualTo("Foo");
}
}
@@ -295,10 +276,8 @@ public final class Verify {
protected void verifyManifest(Manifest manifest) throws Exception {
assertThat(manifest.getMainAttributes().getValue("Main-Class"))
.isEqualTo("org.springframework.boot.loader.PropertiesLauncher");
assertThat(manifest.getMainAttributes().getValue("Start-Class"))
.isEqualTo("org.test.SampleApplication");
assertThat(manifest.getMainAttributes().getValue("Not-Used"))
.isEqualTo("Foo");
assertThat(manifest.getMainAttributes().getValue("Start-Class")).isEqualTo("org.test.SampleApplication");
assertThat(manifest.getMainAttributes().getValue("Not-Used")).isEqualTo("Foo");
}
}
@@ -315,11 +294,9 @@ public final class Verify {
verifier.assertHasEntryNameStartingWith("lib/spring-context");
verifier.assertHasEntryNameStartingWith("lib/spring-core");
verifier.assertHasNoEntryNameStartingWith("lib/javax.servlet-api");
assertThat(verifier
.hasEntry("org/" + "springframework/boot/loader/JarLauncher.class"))
.as("Unpacked launcher classes").isFalse();
assertThat(verifier.hasEntry("org/" + "test/SampleModule.class"))
.as("Own classes").isTrue();
assertThat(verifier.hasEntry("org/" + "springframework/boot/loader/JarLauncher.class"))
.as("Unpacked launcher classes").isFalse();
assertThat(verifier.hasEntry("org/" + "test/SampleModule.class")).as("Own classes").isTrue();
}
@Override