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.
@@ -89,13 +89,11 @@ public class SpringBootExtension {
* @param configurer the task configurer
*/
public void buildInfo(Action<BuildInfo> configurer) {
BuildInfo bootBuildInfo = this.project.getTasks().create("bootBuildInfo",
BuildInfo.class);
BuildInfo bootBuildInfo = this.project.getTasks().create("bootBuildInfo", BuildInfo.class);
bootBuildInfo.setGroup(BasePlugin.BUILD_GROUP);
bootBuildInfo.setDescription("Generates a META-INF/build-info.properties file.");
this.project.getPlugins().withType(JavaPlugin.class, (plugin) -> {
this.project.getTasks().getByName(JavaPlugin.CLASSES_TASK_NAME)
.dependsOn(bootBuildInfo);
this.project.getTasks().getByName(JavaPlugin.CLASSES_TASK_NAME).dependsOn(bootBuildInfo);
this.project.afterEvaluate((evaluated) -> {
BuildInfoProperties properties = bootBuildInfo.getProperties();
if (properties.getArtifact() == null) {
@@ -103,8 +101,7 @@ public class SpringBootExtension {
}
});
bootBuildInfo.getConventionMapping().map("destinationDir",
() -> new File(determineMainSourceSetResourcesOutputDir(),
"META-INF"));
() -> new File(determineMainSourceSetResourcesOutputDir(), "META-INF"));
});
if (configurer != null) {
configurer.execute(bootBuildInfo);
@@ -112,9 +109,8 @@ public class SpringBootExtension {
}
private File determineMainSourceSetResourcesOutputDir() {
return this.project.getConvention().getPlugin(JavaPluginConvention.class)
.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput()
.getResourcesDir();
return this.project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets()
.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput().getResourcesDir();
}
private String determineArtifactBaseName() {

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.
@@ -47,37 +47,31 @@ final class ApplicationPluginAction implements PluginApplicationAction {
public void execute(Project project) {
ApplicationPluginConvention applicationConvention = project.getConvention()
.getPlugin(ApplicationPluginConvention.class);
DistributionContainer distributions = project.getExtensions()
.getByType(DistributionContainer.class);
DistributionContainer distributions = project.getExtensions().getByType(DistributionContainer.class);
Distribution distribution = distributions.create("boot");
if (distribution instanceof IConventionAware) {
((IConventionAware) distribution).getConventionMapping().map("baseName",
() -> applicationConvention.getApplicationName() + "-boot");
}
CreateBootStartScripts bootStartScripts = project.getTasks()
.create("bootStartScripts", CreateBootStartScripts.class);
bootStartScripts.setDescription("Generates OS-specific start scripts to run the"
+ " project as a Spring Boot application.");
CreateBootStartScripts bootStartScripts = project.getTasks().create("bootStartScripts",
CreateBootStartScripts.class);
bootStartScripts.setDescription(
"Generates OS-specific start scripts to run the" + " project as a Spring Boot application.");
((TemplateBasedScriptGenerator) bootStartScripts.getUnixStartScriptGenerator())
.setTemplate(project.getResources().getText()
.fromString(loadResource("/unixStartScript.txt")));
.setTemplate(project.getResources().getText().fromString(loadResource("/unixStartScript.txt")));
((TemplateBasedScriptGenerator) bootStartScripts.getWindowsStartScriptGenerator())
.setTemplate(project.getResources().getText()
.fromString(loadResource("/windowsStartScript.txt")));
.setTemplate(project.getResources().getText().fromString(loadResource("/windowsStartScript.txt")));
project.getConfigurations().all((configuration) -> {
if ("bootArchives".equals(configuration.getName())) {
CopySpec libCopySpec = project.copySpec().into("lib")
.from((Callable<FileCollection>) () -> configuration
.getArtifacts().getFiles());
.from((Callable<FileCollection>) () -> configuration.getArtifacts().getFiles());
libCopySpec.setFileMode(0644);
distribution.getContents().with(libCopySpec);
bootStartScripts.setClasspath(configuration.getArtifacts().getFiles());
}
});
bootStartScripts.getConventionMapping().map("outputDir",
() -> new File(project.getBuildDir(), "bootScripts"));
bootStartScripts.getConventionMapping().map("applicationName",
applicationConvention::getApplicationName);
bootStartScripts.getConventionMapping().map("outputDir", () -> new File(project.getBuildDir(), "bootScripts"));
bootStartScripts.getConventionMapping().map("applicationName", applicationConvention::getApplicationName);
bootStartScripts.getConventionMapping().map("defaultJvmOpts",
applicationConvention::getApplicationDefaultJvmArgs);
CopySpec binCopySpec = project.copySpec().into("bin").from(bootStartScripts);
@@ -91,8 +85,7 @@ final class ApplicationPluginAction implements PluginApplicationAction {
}
private String loadResource(String name) {
try (InputStreamReader reader = new InputStreamReader(
getClass().getResourceAsStream(name))) {
try (InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream(name))) {
char[] buffer = new char[4096];
int read = 0;
StringWriter writer = new StringWriter();

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.
@@ -33,8 +33,7 @@ final class DependencyManagementPluginAction implements PluginApplicationAction
@Override
public void execute(Project project) {
project.getExtensions().findByType(DependencyManagementExtension.class)
.imports((importsHandler) -> importsHandler
.mavenBom(SpringBootPlugin.BOM_COORDINATES));
.imports((importsHandler) -> importsHandler.mavenBom(SpringBootPlugin.BOM_COORDINATES));
}
@Override

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.
@@ -77,25 +77,20 @@ final class JavaPluginAction implements PluginApplicationAction {
}
private void configureBuildTask(Project project) {
project.getTasks().getByName(BasePlugin.ASSEMBLE_TASK_NAME)
.dependsOn(this.singlePublishedArtifact);
project.getTasks().getByName(BasePlugin.ASSEMBLE_TASK_NAME).dependsOn(this.singlePublishedArtifact);
}
private BootJar configureBootJarTask(Project project) {
BootJar bootJar = project.getTasks().create(SpringBootPlugin.BOOT_JAR_TASK_NAME,
BootJar.class);
bootJar.setDescription("Assembles an executable jar archive containing the main"
+ " classes and their dependencies.");
BootJar bootJar = project.getTasks().create(SpringBootPlugin.BOOT_JAR_TASK_NAME, BootJar.class);
bootJar.setDescription(
"Assembles an executable jar archive containing the main" + " classes and their dependencies.");
bootJar.setGroup(BasePlugin.BUILD_GROUP);
bootJar.classpath((Callable<FileCollection>) () -> {
JavaPluginConvention convention = project.getConvention()
.getPlugin(JavaPluginConvention.class);
SourceSet mainSourceSet = convention.getSourceSets()
.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
JavaPluginConvention convention = project.getConvention().getPlugin(JavaPluginConvention.class);
SourceSet mainSourceSet = convention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
return mainSourceSet.getRuntimeClasspath();
});
bootJar.conventionMapping("mainClassName",
new MainClassConvention(project, bootJar::getClasspath));
bootJar.conventionMapping("mainClassName", new MainClassConvention(project, bootJar::getClasspath));
return bootJar;
}
@@ -105,30 +100,26 @@ final class JavaPluginAction implements PluginApplicationAction {
}
private void configureBootRunTask(Project project) {
JavaPluginConvention javaConvention = project.getConvention()
.getPlugin(JavaPluginConvention.class);
JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
BootRun run = project.getTasks().create("bootRun", BootRun.class);
run.setDescription("Runs this project as a Spring Boot application.");
run.setGroup(ApplicationPlugin.APPLICATION_GROUP);
run.classpath(javaConvention.getSourceSets()
.findByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath());
run.classpath(javaConvention.getSourceSets().findByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath());
run.getConventionMapping().map("jvmArgs", () -> {
if (project.hasProperty("applicationDefaultJvmArgs")) {
return project.property("applicationDefaultJvmArgs");
}
return Collections.emptyList();
});
run.conventionMapping("main",
new MainClassConvention(project, run::getClasspath));
run.conventionMapping("main", new MainClassConvention(project, run::getClasspath));
}
private void configureUtf8Encoding(Project project) {
project.afterEvaluate((evaluated) -> evaluated.getTasks()
.withType(JavaCompile.class, (compile) -> {
if (compile.getOptions().getEncoding() == null) {
compile.getOptions().setEncoding("UTF-8");
}
}));
project.afterEvaluate((evaluated) -> evaluated.getTasks().withType(JavaCompile.class, (compile) -> {
if (compile.getOptions().getEncoding() == null) {
compile.getOptions().setEncoding("UTF-8");
}
}));
}
private void configureParametersCompilerArg(Project project) {
@@ -141,8 +132,8 @@ final class JavaPluginAction implements PluginApplicationAction {
}
private void configureAdditionalMetadataLocations(Project project) {
project.afterEvaluate((evaluated) -> evaluated.getTasks()
.withType(JavaCompile.class, this::configureAdditionalMetadataLocations));
project.afterEvaluate((evaluated) -> evaluated.getTasks().withType(JavaCompile.class,
this::configureAdditionalMetadataLocations));
}
private void configureAdditionalMetadataLocations(JavaCompile compile) {
@@ -163,35 +154,27 @@ final class JavaPluginAction implements PluginApplicationAction {
}
JavaCompile compile = (JavaCompile) task;
if (hasConfigurationProcessorOnClasspath(compile)) {
findMatchingSourceSet(compile).ifPresent(
(sourceSet) -> configureAdditionalMetadataLocations(compile,
sourceSet));
findMatchingSourceSet(compile)
.ifPresent((sourceSet) -> configureAdditionalMetadataLocations(compile, sourceSet));
}
}
private boolean hasConfigurationProcessorOnClasspath(JavaCompile compile) {
Set<File> files = (compile.getOptions().getAnnotationProcessorPath() != null)
? compile.getOptions().getAnnotationProcessorPath().getFiles()
: compile.getClasspath().getFiles();
return files.stream().map(File::getName).anyMatch(
(name) -> name.startsWith("spring-boot-configuration-processor"));
? compile.getOptions().getAnnotationProcessorPath().getFiles() : compile.getClasspath().getFiles();
return files.stream().map(File::getName)
.anyMatch((name) -> name.startsWith("spring-boot-configuration-processor"));
}
private Optional<SourceSet> findMatchingSourceSet(JavaCompile compile) {
return compile
.getProject().getConvention().getPlugin(JavaPluginConvention.class)
.getSourceSets().stream().filter((sourceSet) -> sourceSet
.getCompileJavaTaskName().equals(compile.getName()))
.findFirst();
return compile.getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().stream()
.filter((sourceSet) -> sourceSet.getCompileJavaTaskName().equals(compile.getName())).findFirst();
}
private void configureAdditionalMetadataLocations(JavaCompile compile,
SourceSet sourceSet) {
String locations = StringUtils.collectionToCommaDelimitedString(
sourceSet.getResources().getSrcDirs());
compile.getOptions().getCompilerArgs().add(
"-Aorg.springframework.boot.configurationprocessor.additionalMetadataLocations="
+ locations);
private void configureAdditionalMetadataLocations(JavaCompile compile, SourceSet sourceSet) {
String locations = StringUtils.collectionToCommaDelimitedString(sourceSet.getResources().getSrcDirs());
compile.getOptions().getCompilerArgs()
.add("-Aorg.springframework.boot.configurationprocessor.additionalMetadataLocations=" + locations);
}
}

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.
@@ -33,10 +33,8 @@ class KotlinPluginAction implements PluginApplicationAction {
@Override
public void execute(Project project) {
String kotlinVersion = project.getPlugins().getPlugin(KotlinPluginWrapper.class)
.getKotlinPluginVersion();
ExtraPropertiesExtension extraProperties = project.getExtensions()
.getExtraProperties();
String kotlinVersion = project.getPlugins().getPlugin(KotlinPluginWrapper.class).getKotlinPluginVersion();
ExtraPropertiesExtension extraProperties = project.getExtensions().getExtraProperties();
if (!extraProperties.has("kotlin.version")) {
extraProperties.set("kotlin.version", kotlinVersion);
}

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.
@@ -49,10 +49,8 @@ final class MainClassConvention implements Callable<Object> {
@Override
public Object call() throws Exception {
SpringBootExtension springBootExtension = this.project.getExtensions()
.findByType(SpringBootExtension.class);
if (springBootExtension != null
&& springBootExtension.getMainClassName() != null) {
SpringBootExtension springBootExtension = this.project.getExtensions().findByType(SpringBootExtension.class);
if (springBootExtension != null && springBootExtension.getMainClassName() != null) {
return springBootExtension.getMainClassName();
}
if (this.project.hasProperty("mainClassName")) {
@@ -65,16 +63,14 @@ final class MainClassConvention implements Callable<Object> {
}
private String resolveMainClass() {
return this.classpathSupplier.get().filter(File::isDirectory).getFiles().stream()
.map(this::findMainClass).filter(Objects::nonNull).findFirst()
.orElseThrow(() -> new InvalidUserDataException(
return this.classpathSupplier.get().filter(File::isDirectory).getFiles().stream().map(this::findMainClass)
.filter(Objects::nonNull).findFirst().orElseThrow(() -> new InvalidUserDataException(
"Main class name has not been configured and it could not be resolved"));
}
private String findMainClass(File file) {
try {
return MainClassFinder.findSingleMainClass(file,
SPRING_BOOT_APPLICATION_CLASS_NAME);
return MainClassFinder.findSingleMainClass(file, SPRING_BOOT_APPLICATION_CLASS_NAME);
}
catch (IOException ex) {
return null;

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.
@@ -85,8 +85,8 @@ public class SpringBootPlugin implements Plugin<Project> {
private void verifyGradleVersion() {
if (GradleVersion.current().compareTo(GradleVersion.version("4.4")) < 0) {
throw new GradleException("Spring Boot plugin requires Gradle 4.4 or later."
+ " The current version is " + GradleVersion.current());
throw new GradleException("Spring Boot plugin requires Gradle 4.4 or later." + " The current version is "
+ GradleVersion.current());
}
}
@@ -95,27 +95,20 @@ public class SpringBootPlugin implements Plugin<Project> {
}
private Configuration createBootArchivesConfiguration(Project project) {
Configuration bootArchives = project.getConfigurations()
.create(BOOT_ARCHIVES_CONFIGURATION_NAME);
Configuration bootArchives = project.getConfigurations().create(BOOT_ARCHIVES_CONFIGURATION_NAME);
bootArchives.setDescription("Configuration for Spring Boot archive artifacts.");
return bootArchives;
}
private void registerPluginActions(Project project, Configuration bootArchives) {
SinglePublishedArtifact singlePublishedArtifact = new SinglePublishedArtifact(
bootArchives.getArtifacts());
List<PluginApplicationAction> actions = Arrays.asList(
new JavaPluginAction(singlePublishedArtifact),
new WarPluginAction(singlePublishedArtifact),
new MavenPluginAction(bootArchives.getUploadTaskName()),
new DependencyManagementPluginAction(), new ApplicationPluginAction(),
new KotlinPluginAction());
SinglePublishedArtifact singlePublishedArtifact = new SinglePublishedArtifact(bootArchives.getArtifacts());
List<PluginApplicationAction> actions = Arrays.asList(new JavaPluginAction(singlePublishedArtifact),
new WarPluginAction(singlePublishedArtifact), new MavenPluginAction(bootArchives.getUploadTaskName()),
new DependencyManagementPluginAction(), new ApplicationPluginAction(), new KotlinPluginAction());
for (PluginApplicationAction action : actions) {
Class<? extends Plugin<? extends Project>> pluginClass = action
.getPluginClass();
Class<? extends Plugin<? extends Project>> pluginClass = action.getPluginClass();
if (pluginClass != null) {
project.getPlugins().withType(pluginClass,
(plugin) -> action.execute(project));
project.getPlugins().withType(pluginClass, (plugin) -> action.execute(project));
}
}
}
@@ -126,29 +119,25 @@ public class SpringBootPlugin implements Plugin<Project> {
ResolvableDependencies incoming = configuration.getIncoming();
incoming.afterResolve((resolvableDependencies) -> {
if (incoming.equals(resolvableDependencies)) {
unresolvedDependenciesAnalyzer.analyze(configuration
.getResolvedConfiguration().getLenientConfiguration()
.getUnresolvedModuleDependencies());
unresolvedDependenciesAnalyzer.analyze(configuration.getResolvedConfiguration()
.getLenientConfiguration().getUnresolvedModuleDependencies());
}
});
});
project.getGradle().buildFinished(
(buildResult) -> unresolvedDependenciesAnalyzer.buildFinished(project));
project.getGradle().buildFinished((buildResult) -> unresolvedDependenciesAnalyzer.buildFinished(project));
}
private static String determineSpringBootVersion() {
String implementationVersion = DependencyManagementPluginAction.class.getPackage()
.getImplementationVersion();
String implementationVersion = DependencyManagementPluginAction.class.getPackage().getImplementationVersion();
if (implementationVersion != null) {
return implementationVersion;
}
URL codeSourceLocation = DependencyManagementPluginAction.class
.getProtectionDomain().getCodeSource().getLocation();
URL codeSourceLocation = DependencyManagementPluginAction.class.getProtectionDomain().getCodeSource()
.getLocation();
try {
URLConnection connection = codeSourceLocation.openConnection();
if (connection instanceof JarURLConnection) {
return getImplementationVersion(
((JarURLConnection) connection).getJarFile());
return getImplementationVersion(((JarURLConnection) connection).getJarFile());
}
try (JarFile jarFile = new JarFile(new File(codeSourceLocation.toURI()))) {
return getImplementationVersion(jarFile);
@@ -160,8 +149,7 @@ public class SpringBootPlugin implements Plugin<Project> {
}
private static String getImplementationVersion(JarFile jarFile) throws IOException {
return jarFile.getManifest().getMainAttributes()
.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
return jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION);
}
}

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.
@@ -42,8 +42,8 @@ class UnresolvedDependenciesAnalyzer {
void analyze(Set<UnresolvedDependency> unresolvedDependencies) {
this.dependenciesWithNoVersion = unresolvedDependencies.stream()
.map((unresolvedDependency) -> unresolvedDependency.getSelector())
.filter(this::hasNoVersion).collect(Collectors.toSet());
.map((unresolvedDependency) -> unresolvedDependency.getSelector()).filter(this::hasNoVersion)
.collect(Collectors.toSet());
}
void buildFinished(Project project) {
@@ -52,11 +52,9 @@ class UnresolvedDependenciesAnalyzer {
StringBuilder message = new StringBuilder();
message.append("\nDuring the build, one or more dependencies that were "
+ "declared without a version failed to resolve:\n");
this.dependenciesWithNoVersion
.forEach((dependency) -> message.append(" " + dependency + "\n"));
message.append("\nDid you forget to apply the "
+ "io.spring.dependency-management plugin to the " + project.getName()
+ " project?\n");
this.dependenciesWithNoVersion.forEach((dependency) -> message.append(" " + dependency + "\n"));
message.append("\nDid you forget to apply the " + "io.spring.dependency-management plugin to the "
+ project.getName() + " project?\n");
logger.warn(message.toString());
}
}

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.
@@ -47,21 +47,18 @@ class WarPluginAction implements PluginApplicationAction {
@Override
public void execute(Project project) {
project.getTasks().getByName(WarPlugin.WAR_TASK_NAME).setEnabled(false);
BootWar bootWar = project.getTasks().create(SpringBootPlugin.BOOT_WAR_TASK_NAME,
BootWar.class);
BootWar bootWar = project.getTasks().create(SpringBootPlugin.BOOT_WAR_TASK_NAME, BootWar.class);
bootWar.setGroup(BasePlugin.BUILD_GROUP);
bootWar.setDescription("Assembles an executable war archive containing webapp"
+ " content, and the main classes and their dependencies.");
bootWar.providedClasspath(providedRuntimeConfiguration(project));
ArchivePublishArtifact artifact = new ArchivePublishArtifact(bootWar);
this.singlePublishedArtifact.addCandidate(artifact);
bootWar.conventionMapping("mainClassName",
new MainClassConvention(project, bootWar::getClasspath));
bootWar.conventionMapping("mainClassName", new MainClassConvention(project, bootWar::getClasspath));
}
private Configuration providedRuntimeConfiguration(Project project) {
return project.getConfigurations()
.getByName(WarPlugin.PROVIDED_RUNTIME_CONFIGURATION_NAME);
return project.getConfigurations().getByName(WarPlugin.PROVIDED_RUNTIME_CONFIGURATION_NAME);
}
}

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.
@@ -53,14 +53,13 @@ public class BuildInfo extends ConventionTask {
@TaskAction
public void generateBuildProperties() {
try {
new BuildPropertiesWriter(new File(getDestinationDir(),
"build-info.properties")).writeBuildProperties(new ProjectDetails(
this.properties.getGroup(),
(this.properties.getArtifact() != null)
? this.properties.getArtifact() : "unspecified",
this.properties.getVersion(), this.properties.getName(),
this.properties.getTime(),
coerceToStringValues(this.properties.getAdditional())));
new BuildPropertiesWriter(new File(getDestinationDir(), "build-info.properties"))
.writeBuildProperties(
new ProjectDetails(this.properties.getGroup(),
(this.properties.getArtifact() != null) ? this.properties.getArtifact()
: "unspecified",
this.properties.getVersion(), this.properties.getName(), this.properties.getTime(),
coerceToStringValues(this.properties.getAdditional())));
}
catch (IOException ex) {
throw new TaskExecutionException(this, ex);
@@ -74,8 +73,7 @@ public class BuildInfo extends ConventionTask {
*/
@OutputDirectory
public File getDestinationDir() {
return (this.destinationDir != null) ? this.destinationDir
: getProject().getBuildDir();
return (this.destinationDir != null) ? this.destinationDir : getProject().getBuildDir();
}
/**

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.
@@ -172,8 +172,7 @@ public class BuildInfoProperties implements Serializable {
}
BuildInfoProperties other = (BuildInfoProperties) obj;
boolean result = true;
result = result
&& nullSafeEquals(this.additionalProperties, other.additionalProperties);
result = result && nullSafeEquals(this.additionalProperties, other.additionalProperties);
result = result && nullSafeEquals(this.artifact, other.artifact);
result = result && nullSafeEquals(this.group, other.group);
result = result && nullSafeEquals(this.name, other.name);
@@ -196,10 +195,8 @@ public class BuildInfoProperties implements Serializable {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.additionalProperties == null) ? 0
: this.additionalProperties.hashCode());
result = prime * result
+ ((this.artifact == null) ? 0 : this.artifact.hashCode());
result = prime * result + ((this.additionalProperties == null) ? 0 : this.additionalProperties.hashCode());
result = prime * result + ((this.artifact == null) ? 0 : this.artifact.hashCode());
result = prime * result + ((this.group == null) ? 0 : this.group.hashCode());
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
result = prime * result + ((this.version == null) ? 0 : this.version.hashCode());

View File

@@ -71,21 +71,18 @@ class BootArchiveSupport {
private boolean excludeDevtools = true;
BootArchiveSupport(String loaderMainClass,
Function<FileCopyDetails, ZipCompression> compressionResolver) {
BootArchiveSupport(String loaderMainClass, Function<FileCopyDetails, ZipCompression> compressionResolver) {
this.loaderMainClass = loaderMainClass;
this.compressionResolver = compressionResolver;
this.requiresUnpack.include(Specs.satisfyNone());
configureExclusions();
}
void configureManifest(Jar jar, String mainClassName, String springBootClasses,
String springBootLib) {
void configureManifest(Jar jar, String mainClassName, String springBootClasses, String springBootLib) {
Attributes attributes = jar.getManifest().getAttributes();
attributes.putIfAbsent("Main-Class", this.loaderMainClass);
attributes.putIfAbsent("Start-Class", mainClassName);
attributes.computeIfAbsent("Spring-Boot-Version",
(key) -> determineSpringBootVersion());
attributes.computeIfAbsent("Spring-Boot-Version", (key) -> determineSpringBootVersion());
attributes.putIfAbsent("Spring-Boot-Classes", springBootClasses);
attributes.putIfAbsent("Spring-Boot-Lib", springBootLib);
}
@@ -96,9 +93,8 @@ class BootArchiveSupport {
}
CopyAction createCopyAction(Jar jar) {
CopyAction copyAction = new BootZipCopyAction(jar.getArchivePath(),
jar.isPreserveFileTimestamps(), isUsingDefaultLoader(jar),
this.requiresUnpack.getAsSpec(), this.exclusions.getAsExcludeSpec(),
CopyAction copyAction = new BootZipCopyAction(jar.getArchivePath(), jar.isPreserveFileTimestamps(),
isUsingDefaultLoader(jar), this.requiresUnpack.getAsSpec(), this.exclusions.getAsExcludeSpec(),
this.launchScript, this.compressionResolver, jar.getMetadataCharset());
if (!jar.isReproducibleFileOrder()) {
return copyAction;
@@ -107,8 +103,7 @@ class BootArchiveSupport {
}
private boolean isUsingDefaultLoader(Jar jar) {
return DEFAULT_LAUNCHER_CLASSES
.contains(jar.getManifest().getAttributes().get("Main-Class"));
return DEFAULT_LAUNCHER_CLASSES.contains(jar.getManifest().getAttributes().get("Main-Class"));
}
LaunchScriptConfiguration getLaunchScript() {
@@ -176,8 +171,7 @@ class BootArchiveSupport {
public WorkResult execute(CopyActionProcessingStream stream) {
return this.delegate.execute((action) -> {
Map<RelativePath, FileCopyDetailsInternal> detailsByPath = new TreeMap<>();
stream.process((details) -> detailsByPath.put(details.getRelativePath(),
details));
stream.process((details) -> detailsByPath.put(details.getRelativePath(), details));
detailsByPath.values().forEach(action::processFile);
});
}

View File

@@ -38,8 +38,8 @@ import org.gradle.api.tasks.bundling.Jar;
*/
public class BootJar extends Jar implements BootArchive {
private final BootArchiveSupport support = new BootArchiveSupport(
"org.springframework.boot.loader.JarLauncher", this::resolveZipCompression);
private final BootArchiveSupport support = new BootArchiveSupport("org.springframework.boot.loader.JarLauncher",
this::resolveZipCompression);
private final CopySpec bootInf;
@@ -59,23 +59,20 @@ public class BootJar extends Jar implements BootArchive {
(details) -> details.setRelativePath(details.getRelativeSourcePath()));
getRootSpec().eachFile((details) -> {
String pathString = details.getRelativePath().getPathString();
if (pathString.startsWith("BOOT-INF/lib/")
&& !this.support.isZip(details.getFile())) {
if (pathString.startsWith("BOOT-INF/lib/") && !this.support.isZip(details.getFile())) {
details.exclude();
}
});
}
private Action<CopySpec> classpathFiles(Spec<File> filter) {
return (copySpec) -> copySpec
.from((Callable<Iterable<File>>) () -> (this.classpath != null)
? this.classpath.filter(filter) : Collections.emptyList());
return (copySpec) -> copySpec.from((Callable<Iterable<File>>) () -> (this.classpath != null)
? this.classpath.filter(filter) : Collections.emptyList());
}
@Override
public void copy() {
this.support.configureManifest(this, getMainClassName(), "BOOT-INF/classes/",
"BOOT-INF/lib/");
this.support.configureManifest(this, getMainClassName(), "BOOT-INF/classes/", "BOOT-INF/lib/");
super.copy();
}
@@ -87,8 +84,7 @@ public class BootJar extends Jar implements BootArchive {
@Override
public String getMainClassName() {
if (this.mainClassName == null) {
String manifestStartClass = (String) getManifest().getAttributes()
.get("Start-Class");
String manifestStartClass = (String) getManifest().getAttributes().get("Start-Class");
if (manifestStartClass != null) {
setMainClassName(manifestStartClass);
}
@@ -134,8 +130,7 @@ public class BootJar extends Jar implements BootArchive {
@Override
public void classpath(Object... classpath) {
FileCollection existingClasspath = this.classpath;
this.classpath = getProject().files(
(existingClasspath != null) ? existingClasspath : Collections.emptyList(),
this.classpath = getProject().files((existingClasspath != null) ? existingClasspath : Collections.emptyList(),
classpath);
}

View File

@@ -39,8 +39,8 @@ import org.gradle.api.tasks.bundling.War;
*/
public class BootWar extends War implements BootArchive {
private final BootArchiveSupport support = new BootArchiveSupport(
"org.springframework.boot.loader.WarLauncher", this::resolveZipCompression);
private final BootArchiveSupport support = new BootArchiveSupport("org.springframework.boot.loader.WarLauncher",
this::resolveZipCompression);
private String mainClassName;
@@ -51,15 +51,13 @@ public class BootWar extends War implements BootArchive {
*/
public BootWar() {
getWebInf().into("lib-provided",
(copySpec) -> copySpec.from(
(Callable<Iterable<File>>) () -> (this.providedClasspath != null)
? this.providedClasspath : Collections.emptyList()));
(copySpec) -> copySpec.from((Callable<Iterable<File>>) () -> (this.providedClasspath != null)
? this.providedClasspath : Collections.emptyList()));
getRootSpec().filesMatching("module-info.class",
(details) -> details.setRelativePath(details.getRelativeSourcePath()));
getRootSpec().eachFile((details) -> {
String pathString = details.getRelativePath().getPathString();
if ((pathString.startsWith("WEB-INF/lib/")
|| pathString.startsWith("WEB-INF/lib-provided/"))
if ((pathString.startsWith("WEB-INF/lib/") || pathString.startsWith("WEB-INF/lib-provided/"))
&& !this.support.isZip(details.getFile())) {
details.exclude();
}
@@ -68,8 +66,7 @@ public class BootWar extends War implements BootArchive {
@Override
public void copy() {
this.support.configureManifest(this, getMainClassName(), "WEB-INF/classes/",
"WEB-INF/lib/");
this.support.configureManifest(this, getMainClassName(), "WEB-INF/classes/", "WEB-INF/lib/");
super.copy();
}
@@ -81,8 +78,7 @@ public class BootWar extends War implements BootArchive {
@Override
public String getMainClassName() {
if (this.mainClassName == null) {
String manifestStartClass = (String) getManifest().getAttributes()
.get("Start-Class");
String manifestStartClass = (String) getManifest().getAttributes().get("Start-Class");
if (manifestStartClass != null) {
setMainClassName(manifestStartClass);
}
@@ -139,9 +135,8 @@ public class BootWar extends War implements BootArchive {
*/
public void providedClasspath(Object... classpath) {
FileCollection existingClasspath = this.providedClasspath;
this.providedClasspath = getProject().files(
(existingClasspath != null) ? existingClasspath : Collections.emptyList(),
classpath);
this.providedClasspath = getProject()
.files((existingClasspath != null) ? existingClasspath : Collections.emptyList(), classpath);
}
/**
@@ -186,8 +181,7 @@ public class BootWar extends War implements BootArchive {
*/
protected ZipCompression resolveZipCompression(FileCopyDetails details) {
String relativePath = details.getRelativePath().getPathString();
if (relativePath.startsWith("WEB-INF/lib/")
|| relativePath.startsWith("WEB-INF/lib-provided/")) {
if (relativePath.startsWith("WEB-INF/lib/") || relativePath.startsWith("WEB-INF/lib-provided/")) {
return ZipCompression.STORED;
}
return ZipCompression.DEFLATED;

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.
@@ -53,8 +53,8 @@ import org.springframework.boot.loader.tools.FileUtils;
*/
class BootZipCopyAction implements CopyAction {
static final long CONSTANT_TIME_FOR_ZIP_ENTRIES = new GregorianCalendar(1980,
Calendar.FEBRUARY, 1, 0, 0, 0).getTimeInMillis();
static final long CONSTANT_TIME_FOR_ZIP_ENTRIES = new GregorianCalendar(1980, Calendar.FEBRUARY, 1, 0, 0, 0)
.getTimeInMillis();
private final File output;
@@ -72,10 +72,9 @@ class BootZipCopyAction implements CopyAction {
private final String encoding;
BootZipCopyAction(File output, boolean preserveFileTimestamps,
boolean includeDefaultLoader, Spec<FileTreeElement> requiresUnpack,
Spec<FileTreeElement> exclusions, LaunchScriptConfiguration launchScript,
Function<FileCopyDetails, ZipCompression> compressionResolver,
BootZipCopyAction(File output, boolean preserveFileTimestamps, boolean includeDefaultLoader,
Spec<FileTreeElement> requiresUnpack, Spec<FileTreeElement> exclusions,
LaunchScriptConfiguration launchScript, Function<FileCopyDetails, ZipCompression> compressionResolver,
String encoding) {
this.output = output;
this.preserveFileTimestamps = preserveFileTimestamps;
@@ -104,8 +103,7 @@ class BootZipCopyAction implements CopyAction {
throw new GradleException("Failed to create " + this.output, ex);
}
try {
stream.process(new ZipStreamAction(zipStream, this.output,
this.preserveFileTimestamps, this.requiresUnpack,
stream.process(new ZipStreamAction(zipStream, this.output, this.preserveFileTimestamps, this.requiresUnpack,
createExclusionSpec(loaderEntries), this.compressionResolver));
}
finally {
@@ -120,13 +118,11 @@ class BootZipCopyAction implements CopyAction {
}
@SuppressWarnings("unchecked")
private Spec<FileTreeElement> createExclusionSpec(
Spec<FileTreeElement> loaderEntries) {
private Spec<FileTreeElement> createExclusionSpec(Spec<FileTreeElement> loaderEntries) {
return Specs.union(loaderEntries, this.exclusions);
}
private Spec<FileTreeElement> writeLoaderClassesIfNecessary(
ZipArchiveOutputStream out) {
private Spec<FileTreeElement> writeLoaderClassesIfNecessary(ZipArchiveOutputStream out) {
if (!this.includeDefaultLoader) {
return Specs.satisfyNone();
}
@@ -134,8 +130,8 @@ class BootZipCopyAction implements CopyAction {
}
private Spec<FileTreeElement> writeLoaderClasses(ZipArchiveOutputStream out) {
try (ZipInputStream in = new ZipInputStream(getClass()
.getResourceAsStream("/META-INF/loader/spring-boot-loader.jar"))) {
try (ZipInputStream in = new ZipInputStream(
getClass().getResourceAsStream("/META-INF/loader/spring-boot-loader.jar"))) {
Set<String> entries = new HashSet<>();
java.util.zip.ZipEntry entry;
while ((entry = in.getNextEntry()) != null) {
@@ -160,15 +156,13 @@ class BootZipCopyAction implements CopyAction {
}
}
private void writeDirectory(ZipArchiveEntry entry, ZipArchiveOutputStream out)
throws IOException {
private void writeDirectory(ZipArchiveEntry entry, ZipArchiveOutputStream out) throws IOException {
prepareEntry(entry, UnixStat.DIR_FLAG | UnixStat.DEFAULT_DIR_PERM);
out.putArchiveEntry(entry);
out.closeArchiveEntry();
}
private void writeClass(ZipArchiveEntry entry, ZipInputStream in,
ZipArchiveOutputStream out) throws IOException {
private void writeClass(ZipArchiveEntry entry, ZipInputStream in, ZipArchiveOutputStream out) throws IOException {
prepareEntry(entry, UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM);
out.putArchiveEntry(entry);
byte[] buffer = new byte[4096];
@@ -189,19 +183,18 @@ class BootZipCopyAction implements CopyAction {
private void writeLaunchScriptIfNecessary(FileOutputStream fileStream) {
try {
if (this.launchScript != null) {
fileStream.write(new DefaultLaunchScript(this.launchScript.getScript(),
this.launchScript.getProperties()).toByteArray());
fileStream
.write(new DefaultLaunchScript(this.launchScript.getScript(), this.launchScript.getProperties())
.toByteArray());
this.output.setExecutable(true);
}
}
catch (IOException ex) {
throw new GradleException("Failed to write launch script to " + this.output,
ex);
throw new GradleException("Failed to write launch script to " + this.output, ex);
}
}
private static final class ZipStreamAction
implements CopyActionProcessingStreamAction {
private static final class ZipStreamAction implements CopyActionProcessingStreamAction {
private final ZipArchiveOutputStream zipStream;
@@ -215,9 +208,8 @@ class BootZipCopyAction implements CopyAction {
private final Function<FileCopyDetails, ZipCompression> compressionType;
private ZipStreamAction(ZipArchiveOutputStream zipStream, File output,
boolean preserveFileTimestamps, Spec<FileTreeElement> requiresUnpack,
Spec<FileTreeElement> exclusions,
private ZipStreamAction(ZipArchiveOutputStream zipStream, File output, boolean preserveFileTimestamps,
Spec<FileTreeElement> requiresUnpack, Spec<FileTreeElement> exclusions,
Function<FileCopyDetails, ZipCompression> compressionType) {
this.zipStream = zipStream;
this.output = output;
@@ -241,14 +233,12 @@ class BootZipCopyAction implements CopyAction {
}
}
catch (IOException ex) {
throw new GradleException(
"Failed to add " + details + " to " + this.output, ex);
throw new GradleException("Failed to add " + details + " to " + this.output, ex);
}
}
private void createDirectory(FileCopyDetailsInternal details) throws IOException {
ZipArchiveEntry archiveEntry = new ZipArchiveEntry(
details.getRelativePath().getPathString() + '/');
ZipArchiveEntry archiveEntry = new ZipArchiveEntry(details.getRelativePath().getPathString() + '/');
archiveEntry.setUnixMode(UnixStat.DIR_FLAG | details.getMode());
archiveEntry.setTime(getTime(details));
this.zipStream.putArchiveEntry(archiveEntry);
@@ -269,8 +259,8 @@ class BootZipCopyAction implements CopyAction {
this.zipStream.closeArchiveEntry();
}
private void prepareStoredEntry(FileCopyDetailsInternal details,
ZipArchiveEntry archiveEntry) throws IOException {
private void prepareStoredEntry(FileCopyDetailsInternal details, ZipArchiveEntry archiveEntry)
throws IOException {
archiveEntry.setMethod(java.util.zip.ZipEntry.STORED);
archiveEntry.setSize(details.getSize());
archiveEntry.setCompressedSize(details.getSize());
@@ -278,14 +268,12 @@ class BootZipCopyAction implements CopyAction {
details.copyTo(crcStream);
archiveEntry.setCrc(crcStream.getCrc());
if (this.requiresUnpack.isSatisfiedBy(details)) {
archiveEntry
.setComment("UNPACK:" + FileUtils.sha1Hash(details.getFile()));
archiveEntry.setComment("UNPACK:" + FileUtils.sha1Hash(details.getFile()));
}
}
private long getTime(FileCopyDetails details) {
return this.preserveFileTimestamps ? details.getLastModified()
: CONSTANT_TIME_FOR_ZIP_ENTRIES;
return this.preserveFileTimestamps ? details.getLastModified() : CONSTANT_TIME_FOR_ZIP_ENTRIES;
}
}

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,10 +51,10 @@ public class LaunchScriptConfiguration implements Serializable {
LaunchScriptConfiguration(AbstractArchiveTask archiveTask) {
Project project = archiveTask.getProject();
putIfMissing(this.properties, "initInfoProvides", archiveTask.getBaseName());
putIfMissing(this.properties, "initInfoShortDescription",
removeLineBreaks(project.getDescription()), archiveTask.getBaseName());
putIfMissing(this.properties, "initInfoDescription",
augmentLineBreaks(project.getDescription()), archiveTask.getBaseName());
putIfMissing(this.properties, "initInfoShortDescription", removeLineBreaks(project.getDescription()),
archiveTask.getBaseName());
putIfMissing(this.properties, "initInfoDescription", augmentLineBreaks(project.getDescription()),
archiveTask.getBaseName());
}
/**
@@ -132,24 +132,20 @@ public class LaunchScriptConfiguration implements Serializable {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((this.properties == null) ? 0 : this.properties.hashCode());
result = prime * result + ((this.properties == null) ? 0 : this.properties.hashCode());
result = prime * result + ((this.script == null) ? 0 : this.script.hashCode());
return result;
}
private String removeLineBreaks(String string) {
return (string != null) ? WHITE_SPACE_PATTERN.matcher(string).replaceAll(" ")
: null;
return (string != null) ? WHITE_SPACE_PATTERN.matcher(string).replaceAll(" ") : null;
}
private String augmentLineBreaks(String string) {
return (string != null) ? LINE_FEED_PATTERN.matcher(string).replaceAll("\n# ")
: null;
return (string != null) ? LINE_FEED_PATTERN.matcher(string).replaceAll("\n# ") : null;
}
private void putIfMissing(Map<String, String> properties, String key,
String... valueCandidates) {
private void putIfMissing(Map<String, String> properties, String key, String... valueCandidates) {
if (!properties.containsKey(key)) {
for (String candidate : valueCandidates) {
if (candidate != null && !candidate.isEmpty()) {

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.
@@ -37,8 +37,7 @@ public class BootRun extends JavaExec {
* @param sourceSet the source set
*/
public void sourceResources(SourceSet sourceSet) {
setClasspath(getProject()
.files(sourceSet.getResources().getSrcDirs(), getClasspath())
setClasspath(getProject().files(sourceSet.getResources().getSrcDirs(), getClasspath())
.filter((file) -> !file.equals(sourceSet.getOutput().getResourcesDir())));
}

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.
@@ -32,8 +32,7 @@ public class BootRunApplication {
public static void main(String[] args) {
int i = 1;
for (String entry : ManagementFactory.getRuntimeMXBean().getClassPath()
.split(File.pathSeparator)) {
for (String entry : ManagementFactory.getRuntimeMXBean().getClassPath().split(File.pathSeparator)) {
System.out.println(i++ + ". " + entry);
}
}

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.
@@ -40,8 +40,7 @@ public class GettingStartedDocumentationTests {
@Test
public void typicalPluginsAppliesExceptedPlugins() {
this.gradleBuild.script("src/main/gradle/getting-started/typical-plugins")
.build("verify");
this.gradleBuild.script("src/main/gradle/getting-started/typical-plugins").build("verify");
}
}

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.
@@ -44,20 +44,16 @@ public class IntegratingWithActuatorDocumentationTests {
@Test
public void basicBuildInfo() throws IOException {
this.gradleBuild
.script("src/main/gradle/integrating-with-actuator/build-info-basic")
.build("bootBuildInfo");
assertThat(new File(this.gradleBuild.getProjectDir(),
"build/resources/main/META-INF/build-info.properties")).isFile();
this.gradleBuild.script("src/main/gradle/integrating-with-actuator/build-info-basic").build("bootBuildInfo");
assertThat(new File(this.gradleBuild.getProjectDir(), "build/resources/main/META-INF/build-info.properties"))
.isFile();
}
@Test
public void buildInfoCustomValues() throws IOException {
this.gradleBuild.script(
"src/main/gradle/integrating-with-actuator/build-info-custom-values")
this.gradleBuild.script("src/main/gradle/integrating-with-actuator/build-info-custom-values")
.build("bootBuildInfo");
File file = new File(this.gradleBuild.getProjectDir(),
"build/resources/main/META-INF/build-info.properties");
File file = new File(this.gradleBuild.getProjectDir(), "build/resources/main/META-INF/build-info.properties");
assertThat(file).isFile();
Properties properties = buildInfoProperties(file);
assertThat(properties).containsEntry("build.artifact", "example-app");
@@ -68,11 +64,9 @@ public class IntegratingWithActuatorDocumentationTests {
@Test
public void buildInfoAdditional() throws IOException {
this.gradleBuild
.script("src/main/gradle/integrating-with-actuator/build-info-additional")
this.gradleBuild.script("src/main/gradle/integrating-with-actuator/build-info-additional")
.build("bootBuildInfo");
File file = new File(this.gradleBuild.getProjectDir(),
"build/resources/main/META-INF/build-info.properties");
File file = new File(this.gradleBuild.getProjectDir(), "build/resources/main/META-INF/build-info.properties");
assertThat(file).isFile();
Properties properties = buildInfoProperties(file);
assertThat(properties).containsEntry("build.a", "alpha");

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,32 +41,26 @@ public class ManagingDependenciesDocumentationTests {
@Test
public void dependenciesExampleEvaluatesSuccessfully() {
this.gradleBuild.script("src/main/gradle/managing-dependencies/dependencies")
.build();
this.gradleBuild.script("src/main/gradle/managing-dependencies/dependencies").build();
}
@Test
public void customManagedVersions() {
assertThat(this.gradleBuild
.script("src/main/gradle/managing-dependencies/custom-version")
.build("slf4jVersion").getOutput()).contains("1.7.20");
assertThat(this.gradleBuild.script("src/main/gradle/managing-dependencies/custom-version").build("slf4jVersion")
.getOutput()).contains("1.7.20");
}
@Test
public void dependencyManagementInIsolation() {
assertThat(this.gradleBuild
.script("src/main/gradle/managing-dependencies/configure-bom")
.build("dependencyManagement").getOutput())
.contains("org.springframework.boot:spring-boot-starter ");
assertThat(this.gradleBuild.script("src/main/gradle/managing-dependencies/configure-bom")
.build("dependencyManagement").getOutput()).contains("org.springframework.boot:spring-boot-starter ");
}
@Test
public void dependencyManagementInIsolationWithPluginsBlock() {
Assume.assumeTrue(this.gradleBuild.getDsl() == Dsl.KOTLIN);
assertThat(this.gradleBuild.script(
"src/main/gradle/managing-dependencies/configure-bom-with-plugins")
.build("dependencyManagement").getOutput())
.contains("org.springframework.boot:spring-boot-starter ");
assertThat(this.gradleBuild.script("src/main/gradle/managing-dependencies/configure-bom-with-plugins")
.build("dependencyManagement").getOutput()).contains("org.springframework.boot:spring-boot-starter ");
}
}

View File

@@ -54,14 +54,12 @@ public class PackagingDocumentationTests {
@Test
public void warContainerDependencyEvaluatesSuccessfully() {
this.gradleBuild.script("src/main/gradle/packaging/war-container-dependency")
.build();
this.gradleBuild.script("src/main/gradle/packaging/war-container-dependency").build();
}
@Test
public void bootJarMainClass() throws IOException {
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-main-class")
.build("bootJar");
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-main-class").build("bootJar");
File file = new File(this.gradleBuild.getProjectDir(),
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
assertThat(file).isFile();
@@ -73,8 +71,7 @@ public class PackagingDocumentationTests {
@Test
public void bootJarManifestMainClass() throws IOException {
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-manifest-main-class")
.build("bootJar");
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-manifest-main-class").build("bootJar");
File file = new File(this.gradleBuild.getProjectDir(),
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
assertThat(file).isFile();
@@ -86,8 +83,7 @@ public class PackagingDocumentationTests {
@Test
public void applicationPluginMainClass() throws IOException {
this.gradleBuild.script("src/main/gradle/packaging/application-plugin-main-class")
.build("bootJar");
this.gradleBuild.script("src/main/gradle/packaging/application-plugin-main-class").build("bootJar");
File file = new File(this.gradleBuild.getProjectDir(),
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
assertThat(file).isFile();
@@ -99,8 +95,7 @@ public class PackagingDocumentationTests {
@Test
public void springBootDslMainClass() throws IOException {
this.gradleBuild.script("src/main/gradle/packaging/spring-boot-dsl-main-class")
.build("bootJar");
this.gradleBuild.script("src/main/gradle/packaging/spring-boot-dsl-main-class").build("bootJar");
File file = new File(this.gradleBuild.getProjectDir(),
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
assertThat(file).isFile();
@@ -112,23 +107,19 @@ public class PackagingDocumentationTests {
@Test
public void bootWarIncludeDevtools() throws IOException {
jarFile(new File(this.gradleBuild.getProjectDir(),
"spring-boot-devtools-1.2.3.RELEASE.jar"));
this.gradleBuild.script("src/main/gradle/packaging/boot-war-include-devtools")
.build("bootWar");
jarFile(new File(this.gradleBuild.getProjectDir(), "spring-boot-devtools-1.2.3.RELEASE.jar"));
this.gradleBuild.script("src/main/gradle/packaging/boot-war-include-devtools").build("bootWar");
File file = new File(this.gradleBuild.getProjectDir(),
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".war");
assertThat(file).isFile();
try (JarFile jar = new JarFile(file)) {
assertThat(jar.getEntry("WEB-INF/lib/spring-boot-devtools-1.2.3.RELEASE.jar"))
.isNotNull();
assertThat(jar.getEntry("WEB-INF/lib/spring-boot-devtools-1.2.3.RELEASE.jar")).isNotNull();
}
}
@Test
public void bootJarRequiresUnpack() throws IOException {
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-requires-unpack")
.build("bootJar");
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-requires-unpack").build("bootJar");
File file = new File(this.gradleBuild.getProjectDir(),
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
assertThat(file).isFile();
@@ -141,36 +132,28 @@ public class PackagingDocumentationTests {
@Test
public void bootJarIncludeLaunchScript() throws IOException {
this.gradleBuild
.script("src/main/gradle/packaging/boot-jar-include-launch-script")
.build("bootJar");
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-include-launch-script").build("bootJar");
File file = new File(this.gradleBuild.getProjectDir(),
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
assertThat(file).isFile();
assertThat(FileCopyUtils.copyToString(new FileReader(file)))
.startsWith("#!/bin/bash");
assertThat(FileCopyUtils.copyToString(new FileReader(file))).startsWith("#!/bin/bash");
}
@Test
public void bootJarLaunchScriptProperties() throws IOException {
this.gradleBuild
.script("src/main/gradle/packaging/boot-jar-launch-script-properties")
.build("bootJar");
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-launch-script-properties").build("bootJar");
File file = new File(this.gradleBuild.getProjectDir(),
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
assertThat(file).isFile();
assertThat(FileCopyUtils.copyToString(new FileReader(file)))
.contains("example-app.log");
assertThat(FileCopyUtils.copyToString(new FileReader(file))).contains("example-app.log");
}
@Test
public void bootJarCustomLaunchScript() throws IOException {
File customScriptFile = new File(this.gradleBuild.getProjectDir(),
"src/custom.script");
File customScriptFile = new File(this.gradleBuild.getProjectDir(), "src/custom.script");
customScriptFile.getParentFile().mkdirs();
FileCopyUtils.copy("custom", new FileWriter(customScriptFile));
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-custom-launch-script")
.build("bootJar");
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-custom-launch-script").build("bootJar");
File file = new File(this.gradleBuild.getProjectDir(),
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
assertThat(file).isFile();
@@ -179,8 +162,7 @@ public class PackagingDocumentationTests {
@Test
public void bootWarPropertiesLauncher() throws IOException {
this.gradleBuild.script("src/main/gradle/packaging/boot-war-properties-launcher")
.build("bootWar");
this.gradleBuild.script("src/main/gradle/packaging/boot-war-properties-launcher").build("bootWar");
File file = new File(this.gradleBuild.getProjectDir(),
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".war");
assertThat(file).isFile();
@@ -192,8 +174,7 @@ public class PackagingDocumentationTests {
@Test
public void bootJarAndJar() {
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-and-jar")
.build("assemble");
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-and-jar").build("assemble");
File jar = new File(this.gradleBuild.getProjectDir(),
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
assertThat(jar).isFile();

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,17 +41,14 @@ public class PublishingDocumentationTests {
@Test
public void mavenUpload() throws IOException {
assertThat(this.gradleBuild.script("src/main/gradle/publishing/maven")
.build("deployerRepository").getOutput())
.contains("https://repo.example.com");
assertThat(this.gradleBuild.script("src/main/gradle/publishing/maven").build("deployerRepository").getOutput())
.contains("https://repo.example.com");
}
@Test
public void mavenPublish() throws IOException {
assertThat(this.gradleBuild.script("src/main/gradle/publishing/maven-publish")
.build("publishingConfiguration").getOutput())
.contains("MavenPublication")
.contains("https://repo.example.com");
assertThat(this.gradleBuild.script("src/main/gradle/publishing/maven-publish").build("publishingConfiguration")
.getOutput()).contains("MavenPublication").contains("https://repo.example.com");
}
}

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.
@@ -42,33 +42,26 @@ public class RunningDocumentationTests {
@Test
public void bootRunMain() throws IOException {
assertThat(this.gradleBuild.script("src/main/gradle/running/boot-run-main")
.build("configuredMainClass").getOutput())
.contains("com.example.ExampleApplication");
assertThat(this.gradleBuild.script("src/main/gradle/running/boot-run-main").build("configuredMainClass")
.getOutput()).contains("com.example.ExampleApplication");
}
@Test
public void applicationPluginMainClassName() {
assertThat(this.gradleBuild
.script("src/main/gradle/running/application-plugin-main-class-name")
.build("configuredMainClass").getOutput())
.contains("com.example.ExampleApplication");
assertThat(this.gradleBuild.script("src/main/gradle/running/application-plugin-main-class-name")
.build("configuredMainClass").getOutput()).contains("com.example.ExampleApplication");
}
@Test
public void springBootDslMainClassName() throws IOException {
assertThat(this.gradleBuild
.script("src/main/gradle/running/spring-boot-dsl-main-class-name")
.build("configuredMainClass").getOutput())
.contains("com.example.ExampleApplication");
assertThat(this.gradleBuild.script("src/main/gradle/running/spring-boot-dsl-main-class-name")
.build("configuredMainClass").getOutput()).contains("com.example.ExampleApplication");
}
@Test
public void bootRunSourceResources() throws IOException {
assertThat(this.gradleBuild
.script("src/main/gradle/running/boot-run-source-resources")
.build("configuredClasspath").getOutput())
.contains(new File("src/main/resources").getPath());
assertThat(this.gradleBuild.script("src/main/gradle/running/boot-run-source-resources")
.build("configuredClasspath").getOutput()).contains(new File("src/main/resources").getPath());
}
}

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.
@@ -43,24 +43,21 @@ public class BuildInfoDslIntegrationTests {
@Test
public void basicJar() throws IOException {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace")
.task(":bootBuildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
Properties properties = buildInfoProperties();
assertThat(properties).containsEntry("build.name",
this.gradleBuild.getProjectDir().getName());
assertThat(properties).containsEntry("build.artifact",
this.gradleBuild.getProjectDir().getName());
assertThat(properties).containsEntry("build.name", this.gradleBuild.getProjectDir().getName());
assertThat(properties).containsEntry("build.artifact", this.gradleBuild.getProjectDir().getName());
assertThat(properties).containsEntry("build.group", "com.example");
assertThat(properties).containsEntry("build.version", "1.0");
}
@Test
public void jarWithCustomName() throws IOException {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace")
.task(":bootBuildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
Properties properties = buildInfoProperties();
assertThat(properties).containsEntry("build.name",
this.gradleBuild.getProjectDir().getName());
assertThat(properties).containsEntry("build.name", this.gradleBuild.getProjectDir().getName());
assertThat(properties).containsEntry("build.artifact", "foo");
assertThat(properties).containsEntry("build.group", "com.example");
assertThat(properties).containsEntry("build.version", "1.0");
@@ -68,24 +65,21 @@ public class BuildInfoDslIntegrationTests {
@Test
public void basicWar() throws IOException {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace")
.task(":bootBuildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
Properties properties = buildInfoProperties();
assertThat(properties).containsEntry("build.name",
this.gradleBuild.getProjectDir().getName());
assertThat(properties).containsEntry("build.artifact",
this.gradleBuild.getProjectDir().getName());
assertThat(properties).containsEntry("build.name", this.gradleBuild.getProjectDir().getName());
assertThat(properties).containsEntry("build.artifact", this.gradleBuild.getProjectDir().getName());
assertThat(properties).containsEntry("build.group", "com.example");
assertThat(properties).containsEntry("build.version", "1.0");
}
@Test
public void warWithCustomName() throws IOException {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace")
.task(":bootBuildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
Properties properties = buildInfoProperties();
assertThat(properties).containsEntry("build.name",
this.gradleBuild.getProjectDir().getName());
assertThat(properties).containsEntry("build.name", this.gradleBuild.getProjectDir().getName());
assertThat(properties).containsEntry("build.artifact", "foo");
assertThat(properties).containsEntry("build.group", "com.example");
assertThat(properties).containsEntry("build.version", "1.0");
@@ -93,13 +87,11 @@ public class BuildInfoDslIntegrationTests {
@Test
public void additionalProperties() throws IOException {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace")
.task(":bootBuildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
Properties properties = buildInfoProperties();
assertThat(properties).containsEntry("build.name",
this.gradleBuild.getProjectDir().getName());
assertThat(properties).containsEntry("build.artifact",
this.gradleBuild.getProjectDir().getName());
assertThat(properties).containsEntry("build.name", this.gradleBuild.getProjectDir().getName());
assertThat(properties).containsEntry("build.artifact", this.gradleBuild.getProjectDir().getName());
assertThat(properties).containsEntry("build.group", "com.example");
assertThat(properties).containsEntry("build.version", "1.0");
assertThat(properties).containsEntry("build.a", "alpha");
@@ -108,13 +100,12 @@ public class BuildInfoDslIntegrationTests {
@Test
public void classesDependency() throws IOException {
assertThat(this.gradleBuild.build("classes", "--stacktrace")
.task(":bootBuildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("classes", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
}
private Properties buildInfoProperties() {
File file = new File(this.gradleBuild.getProjectDir(),
"build/resources/main/META-INF/build-info.properties");
File file = new File(this.gradleBuild.getProjectDir(), "build/resources/main/META-INF/build-info.properties");
assertThat(file).isFile();
Properties properties = new Properties();
try (FileReader reader = new FileReader(file)) {

View File

@@ -38,9 +38,8 @@ import org.springframework.boot.gradle.testkit.GradleBuild;
*/
public final class GradleCompatibilitySuite extends Suite {
private static final List<String> GRADLE_VERSIONS = Arrays.asList("default", "4.5.1",
"4.6", "4.7", "4.8.1", "4.9", "4.10.3", "5.0", "5.1.1", "5.2.1", "5.3.1",
"5.4.1");
private static final List<String> GRADLE_VERSIONS = Arrays.asList("default", "4.5.1", "4.6", "4.7", "4.8.1", "4.9",
"4.10.3", "5.0", "5.1.1", "5.2.1", "5.3.1", "5.4.1");
public GradleCompatibilitySuite(Class<?> clazz) throws InitializationError {
super(clazz, createRunners(clazz));
@@ -54,13 +53,11 @@ public final class GradleCompatibilitySuite extends Suite {
return runners;
}
private static final class GradleCompatibilityClassRunner
extends BlockJUnit4ClassRunner {
private static final class GradleCompatibilityClassRunner extends BlockJUnit4ClassRunner {
private final String gradleVersion;
private GradleCompatibilityClassRunner(Class<?> klass, String gradleVersion)
throws InitializationError {
private GradleCompatibilityClassRunner(Class<?> klass, String gradleVersion) throws InitializationError {
super(klass);
this.gradleVersion = gradleVersion;
}

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.
@@ -54,8 +54,7 @@ public final class GradleMultiDslSuite extends Suite {
private final GradleBuild gradleBuild;
private GradleDslClassRunner(Class<?> klass, GradleBuild gradleBuild)
throws InitializationError {
private GradleDslClassRunner(Class<?> klass, GradleBuild gradleBuild) throws InitializationError {
super(klass);
this.gradleBuild = gradleBuild;
}

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,120 +51,100 @@ public class ApplicationPluginActionIntegrationTests {
@Test
public void noBootDistributionWithoutApplicationPluginApplied() {
assertThat(this.gradleBuild.build("distributionExists", "-PdistributionName=boot")
.getOutput()).contains("boot exists = false");
assertThat(this.gradleBuild.build("distributionExists", "-PdistributionName=boot").getOutput())
.contains("boot exists = false");
}
@Test
public void applyingApplicationPluginCreatesBootDistribution() {
assertThat(this.gradleBuild.build("distributionExists", "-PdistributionName=boot",
"-PapplyApplicationPlugin").getOutput()).contains("boot exists = true");
assertThat(this.gradleBuild.build("distributionExists", "-PdistributionName=boot", "-PapplyApplicationPlugin")
.getOutput()).contains("boot exists = true");
}
@Test
public void noBootStartScriptsTaskWithoutApplicationPluginApplied() {
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootStartScripts")
.getOutput()).contains("bootStartScripts exists = false");
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootStartScripts").getOutput())
.contains("bootStartScripts exists = false");
}
@Test
public void applyingApplicationPluginCreatesBootStartScriptsTask() {
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootStartScripts",
"-PapplyApplicationPlugin").getOutput())
.contains("bootStartScripts exists = true");
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootStartScripts", "-PapplyApplicationPlugin")
.getOutput()).contains("bootStartScripts exists = true");
}
@Test
public void createsBootStartScriptsTaskUsesApplicationPluginsDefaultJvmOpts() {
assertThat(this.gradleBuild
.build("startScriptsDefaultJvmOpts", "-PapplyApplicationPlugin")
.getOutput()).contains(
"bootStartScripts defaultJvmOpts = [-Dcom.example.a=alpha, -Dcom.example.b=bravo]");
assertThat(this.gradleBuild.build("startScriptsDefaultJvmOpts", "-PapplyApplicationPlugin").getOutput())
.contains("bootStartScripts defaultJvmOpts = [-Dcom.example.a=alpha, -Dcom.example.b=bravo]");
}
@Test
public void zipDistributionForJarCanBeBuilt() throws IOException {
assertThat(
this.gradleBuild.build("bootDistZip").task(":bootDistZip").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("bootDistZip").task(":bootDistZip").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
String name = this.gradleBuild.getProjectDir().getName();
File distribution = new File(this.gradleBuild.getProjectDir(),
"build/distributions/" + name + "-boot.zip");
File distribution = new File(this.gradleBuild.getProjectDir(), "build/distributions/" + name + "-boot.zip");
assertThat(distribution).isFile();
assertThat(zipEntryNames(distribution)).containsExactlyInAnyOrder(name + "-boot/",
name + "-boot/lib/", name + "-boot/lib/" + name + ".jar",
name + "-boot/bin/", name + "-boot/bin/" + name,
assertThat(zipEntryNames(distribution)).containsExactlyInAnyOrder(name + "-boot/", name + "-boot/lib/",
name + "-boot/lib/" + name + ".jar", name + "-boot/bin/", name + "-boot/bin/" + name,
name + "-boot/bin/" + name + ".bat");
}
@Test
public void tarDistributionForJarCanBeBuilt() throws IOException {
assertThat(
this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
String name = this.gradleBuild.getProjectDir().getName();
File distribution = new File(this.gradleBuild.getProjectDir(),
"build/distributions/" + name + "-boot.tar");
File distribution = new File(this.gradleBuild.getProjectDir(), "build/distributions/" + name + "-boot.tar");
assertThat(distribution).isFile();
assertThat(tarEntryNames(distribution)).containsExactlyInAnyOrder(name + "-boot/",
name + "-boot/lib/", name + "-boot/lib/" + name + ".jar",
name + "-boot/bin/", name + "-boot/bin/" + name,
assertThat(tarEntryNames(distribution)).containsExactlyInAnyOrder(name + "-boot/", name + "-boot/lib/",
name + "-boot/lib/" + name + ".jar", name + "-boot/bin/", name + "-boot/bin/" + name,
name + "-boot/bin/" + name + ".bat");
}
@Test
public void zipDistributionForWarCanBeBuilt() throws IOException {
assertThat(
this.gradleBuild.build("bootDistZip").task(":bootDistZip").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("bootDistZip").task(":bootDistZip").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
String name = this.gradleBuild.getProjectDir().getName();
File distribution = new File(this.gradleBuild.getProjectDir(),
"build/distributions/" + name + "-boot.zip");
File distribution = new File(this.gradleBuild.getProjectDir(), "build/distributions/" + name + "-boot.zip");
assertThat(distribution).isFile();
assertThat(zipEntryNames(distribution)).containsExactlyInAnyOrder(name + "-boot/",
name + "-boot/lib/", name + "-boot/lib/" + name + ".war",
name + "-boot/bin/", name + "-boot/bin/" + name,
assertThat(zipEntryNames(distribution)).containsExactlyInAnyOrder(name + "-boot/", name + "-boot/lib/",
name + "-boot/lib/" + name + ".war", name + "-boot/bin/", name + "-boot/bin/" + name,
name + "-boot/bin/" + name + ".bat");
}
@Test
public void tarDistributionForWarCanBeBuilt() throws IOException {
assertThat(
this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
String name = this.gradleBuild.getProjectDir().getName();
File distribution = new File(this.gradleBuild.getProjectDir(),
"build/distributions/" + name + "-boot.tar");
File distribution = new File(this.gradleBuild.getProjectDir(), "build/distributions/" + name + "-boot.tar");
assertThat(distribution).isFile();
assertThat(tarEntryNames(distribution)).containsExactlyInAnyOrder(name + "-boot/",
name + "-boot/lib/", name + "-boot/lib/" + name + ".war",
name + "-boot/bin/", name + "-boot/bin/" + name,
assertThat(tarEntryNames(distribution)).containsExactlyInAnyOrder(name + "-boot/", name + "-boot/lib/",
name + "-boot/lib/" + name + ".war", name + "-boot/bin/", name + "-boot/bin/" + name,
name + "-boot/bin/" + name + ".bat");
}
@Test
public void applicationNameCanBeUsedToCustomizeDistributionName() throws IOException {
assertThat(
this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
File distribution = new File(this.gradleBuild.getProjectDir(),
"build/distributions/custom-boot.tar");
assertThat(this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
File distribution = new File(this.gradleBuild.getProjectDir(), "build/distributions/custom-boot.tar");
assertThat(distribution).isFile();
String name = this.gradleBuild.getProjectDir().getName();
assertThat(tarEntryNames(distribution)).containsExactlyInAnyOrder("custom-boot/",
"custom-boot/lib/", "custom-boot/lib/" + name + ".jar",
"custom-boot/bin/", "custom-boot/bin/custom",
assertThat(tarEntryNames(distribution)).containsExactlyInAnyOrder("custom-boot/", "custom-boot/lib/",
"custom-boot/lib/" + name + ".jar", "custom-boot/bin/", "custom-boot/bin/custom",
"custom-boot/bin/custom.bat");
}
@Test
public void scriptsHaveCorrectPermissions() throws IOException {
assertThat(
this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
String name = this.gradleBuild.getProjectDir().getName();
File distribution = new File(this.gradleBuild.getProjectDir(),
"build/distributions/" + name + "-boot.tar");
File distribution = new File(this.gradleBuild.getProjectDir(), "build/distributions/" + name + "-boot.tar");
assertThat(distribution).isFile();
tarEntries(distribution, (entry) -> {
int filePermissions = entry.getMode() & 0777;
@@ -190,8 +170,7 @@ public class ApplicationPluginActionIntegrationTests {
private List<String> tarEntryNames(File distribution) throws IOException {
List<String> entryNames = new ArrayList<>();
try (TarArchiveInputStream input = new TarArchiveInputStream(
new FileInputStream(distribution))) {
try (TarArchiveInputStream input = new TarArchiveInputStream(new FileInputStream(distribution))) {
TarArchiveEntry entry;
while ((entry = input.getNextTarEntry()) != null) {
entryNames.add(entry.getName());
@@ -200,10 +179,8 @@ public class ApplicationPluginActionIntegrationTests {
return entryNames;
}
private void tarEntries(File distribution, Consumer<TarArchiveEntry> consumer)
throws IOException {
try (TarArchiveInputStream input = new TarArchiveInputStream(
new FileInputStream(distribution))) {
private void tarEntries(File distribution, Consumer<TarArchiveEntry> consumer) throws IOException {
try (TarArchiveInputStream input = new TarArchiveInputStream(new FileInputStream(distribution))) {
TarArchiveEntry entry;
while ((entry = input.getNextTarEntry()) != null) {
consumer.accept(entry);

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.
@@ -45,35 +45,28 @@ public class DependencyManagementPluginActionIntegrationTests {
@Test
public void noDependencyManagementIsAppliedByDefault() {
assertThat(this.gradleBuild.build("doesNotHaveDependencyManagement")
.task(":doesNotHaveDependencyManagement").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("doesNotHaveDependencyManagement").task(":doesNotHaveDependencyManagement")
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
}
@Test
public void bomIsImportedWhenDependencyManagementPluginIsApplied() {
assertThat(this.gradleBuild
.build("hasDependencyManagement", "-PapplyDependencyManagementPlugin")
.task(":hasDependencyManagement").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("hasDependencyManagement", "-PapplyDependencyManagementPlugin")
.task(":hasDependencyManagement").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
}
@Test
public void helpfulErrorWhenVersionlessDependencyFailsToResolve() throws IOException {
File examplePackage = new File(this.gradleBuild.getProjectDir(),
"src/main/java/com/example");
File examplePackage = new File(this.gradleBuild.getProjectDir(), "src/main/java/com/example");
examplePackage.mkdirs();
FileSystemUtils.copyRecursively(new File("src/test/java/com/example"),
examplePackage);
FileSystemUtils.copyRecursively(new File("src/test/java/com/example"), examplePackage);
BuildResult result = this.gradleBuild.buildAndFail("compileJava");
assertThat(result.task(":compileJava").getOutcome())
.isEqualTo(TaskOutcome.FAILED);
assertThat(result.task(":compileJava").getOutcome()).isEqualTo(TaskOutcome.FAILED);
String output = result.getOutput();
assertThat(output).contains("During the build, one or more dependencies that "
+ "were declared without a version failed to resolve:");
assertThat(output).contains("org.springframework.boot:spring-boot-starter-web:");
assertThat(output).contains("Did you forget to apply the "
+ "io.spring.dependency-management plugin to the "
assertThat(output).contains("Did you forget to apply the " + "io.spring.dependency-management plugin to the "
+ this.gradleBuild.getProjectDir().getName() + " project?");
}

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,9 +51,8 @@ public class JavaPluginActionIntegrationTests {
@Test
public void applyingJavaPluginCreatesBootJarTask() {
assertThat(this.gradleBuild
.build("taskExists", "-PtaskName=bootJar", "-PapplyJavaPlugin")
.getOutput()).contains("bootJar exists = true");
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootJar", "-PapplyJavaPlugin").getOutput())
.contains("bootJar exists = true");
}
@Test
@@ -64,16 +63,14 @@ public class JavaPluginActionIntegrationTests {
@Test
public void applyingJavaPluginCreatesBootRunTask() {
assertThat(this.gradleBuild
.build("taskExists", "-PtaskName=bootRun", "-PapplyJavaPlugin")
.getOutput()).contains("bootRun exists = true");
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootRun", "-PapplyJavaPlugin").getOutput())
.contains("bootRun exists = true");
}
@Test
public void javaCompileTasksUseUtf8Encoding() {
assertThat(this.gradleBuild.build("javaCompileEncoding", "-PapplyJavaPlugin")
.getOutput()).contains("compileJava = UTF-8")
.contains("compileTestJava = UTF-8");
assertThat(this.gradleBuild.build("javaCompileEncoding", "-PapplyJavaPlugin").getOutput())
.contains("compileJava = UTF-8").contains("compileTestJava = UTF-8");
}
@Test
@@ -108,8 +105,7 @@ public class JavaPluginActionIntegrationTests {
public void errorMessageIsHelpfulWhenMainClassCannotBeResolved() {
BuildResult result = this.gradleBuild.buildAndFail("build", "-PapplyJavaPlugin");
assertThat(result.task(":bootJar").getOutcome()).isEqualTo(TaskOutcome.FAILED);
assertThat(result.getOutput()).contains(
"Main class name has not been configured and it could not be resolved");
assertThat(result.getOutput()).contains("Main class name has not been configured and it could not be resolved");
}
@Test
@@ -120,42 +116,33 @@ public class JavaPluginActionIntegrationTests {
File buildLibs = new File(this.gradleBuild.getProjectDir(), "build/libs");
assertThat(buildLibs.listFiles()).containsExactlyInAnyOrder(
new File(buildLibs, this.gradleBuild.getProjectDir().getName() + ".jar"),
new File(buildLibs,
this.gradleBuild.getProjectDir().getName() + "-boot.jar"));
new File(buildLibs, this.gradleBuild.getProjectDir().getName() + "-boot.jar"));
}
@Test
public void additionalMetadataLocationsConfiguredWhenProcessorIsPresent()
throws IOException {
public void additionalMetadataLocationsConfiguredWhenProcessorIsPresent() throws IOException {
createMinimalMainSource();
File libs = new File(this.gradleBuild.getProjectDir(), "libs");
libs.mkdirs();
new JarOutputStream(new FileOutputStream(
new File(libs, "spring-boot-configuration-processor-1.2.3.jar"))).close();
new JarOutputStream(new FileOutputStream(new File(libs, "spring-boot-configuration-processor-1.2.3.jar")))
.close();
BuildResult result = this.gradleBuild.build("compileJava");
assertThat(result.task(":compileJava").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.getOutput()).contains(
"compileJava compiler args: [-parameters, -Aorg.springframework.boot."
+ "configurationprocessor.additionalMetadataLocations="
+ new File(this.gradleBuild.getProjectDir(), "src/main/resources")
.getCanonicalPath());
assertThat(result.task(":compileJava").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.getOutput()).contains("compileJava compiler args: [-parameters, -Aorg.springframework.boot."
+ "configurationprocessor.additionalMetadataLocations="
+ new File(this.gradleBuild.getProjectDir(), "src/main/resources").getCanonicalPath());
}
@Test
public void additionalMetadataLocationsNotConfiguredWhenProcessorIsAbsent()
throws IOException {
public void additionalMetadataLocationsNotConfiguredWhenProcessorIsAbsent() throws IOException {
createMinimalMainSource();
BuildResult result = this.gradleBuild.build("compileJava");
assertThat(result.task(":compileJava").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.getOutput())
.contains("compileJava compiler args: [-parameters]");
assertThat(result.task(":compileJava").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.getOutput()).contains("compileJava compiler args: [-parameters]");
}
private void createMinimalMainSource() throws IOException {
File examplePackage = new File(this.gradleBuild.getProjectDir(),
"src/main/java/com/example");
File examplePackage = new File(this.gradleBuild.getProjectDir(), "src/main/java/com/example");
examplePackage.mkdirs();
new File(examplePackage, "Application.java").createNewFile();
}

View File

@@ -38,29 +38,26 @@ public class KotlinPluginActionIntegrationTests {
@Test
public void noKotlinVersionPropertyWithoutKotlinPlugin() {
assertThat(this.gradleBuild.build("kotlinVersion").getOutput())
.contains("Kotlin version: none");
assertThat(this.gradleBuild.build("kotlinVersion").getOutput()).contains("Kotlin version: none");
}
@Test
public void kotlinVersionPropertyIsSet() {
String output = this.gradleBuild.build("kotlinVersion", "dependencies",
"--configuration", "compileClasspath").getOutput();
String output = this.gradleBuild.build("kotlinVersion", "dependencies", "--configuration", "compileClasspath")
.getOutput();
assertThat(output).containsPattern("Kotlin version: [0-9]\\.[0-9]\\.[0-9]+");
}
@Test
public void kotlinCompileTasksUseJavaParametersFlagByDefault() {
assertThat(this.gradleBuild.build("kotlinCompileTasksJavaParameters").getOutput())
.contains("compileKotlin java parameters: true")
.contains("compileTestKotlin java parameters: true");
.contains("compileKotlin java parameters: true").contains("compileTestKotlin java parameters: true");
}
@Test
public void kotlinCompileTasksCanOverrideDefaultJavaParametersFlag() {
assertThat(this.gradleBuild.build("kotlinCompileTasksJavaParameters").getOutput())
.contains("compileKotlin java parameters: false")
.contains("compileTestKotlin java parameters: false");
.contains("compileKotlin java parameters: false").contains("compileTestKotlin java parameters: false");
}
}

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.
@@ -41,36 +41,33 @@ public class MainClassConventionTests {
@Before
public void createConvention() throws IOException {
this.project = ProjectBuilder.builder().withProjectDir(this.temp.newFolder())
.build();
this.project = ProjectBuilder.builder().withProjectDir(this.temp.newFolder()).build();
this.convention = new MainClassConvention(this.project, () -> null);
}
@Test
public void mainClassNameProjectPropertyIsUsed() throws Exception {
this.project.getExtensions().getByType(ExtraPropertiesExtension.class)
.set("mainClassName", "com.example.MainClass");
this.project.getExtensions().getByType(ExtraPropertiesExtension.class).set("mainClassName",
"com.example.MainClass");
assertThat(this.convention.call()).isEqualTo("com.example.MainClass");
}
@Test
public void springBootExtensionMainClassNameIsUsed() throws Exception {
SpringBootExtension extension = this.project.getExtensions().create("springBoot",
SpringBootExtension.class, this.project);
SpringBootExtension extension = this.project.getExtensions().create("springBoot", SpringBootExtension.class,
this.project);
extension.setMainClassName("com.example.MainClass");
assertThat(this.convention.call()).isEqualTo("com.example.MainClass");
}
@Test
public void springBootExtensionMainClassNameIsUsedInPreferenceToMainClassNameProjectProperty()
throws Exception {
this.project.getExtensions().getByType(ExtraPropertiesExtension.class)
.set("mainClassName", "com.example.ProjectPropertyMainClass");
SpringBootExtension extension = this.project.getExtensions().create("springBoot",
SpringBootExtension.class, this.project);
public void springBootExtensionMainClassNameIsUsedInPreferenceToMainClassNameProjectProperty() throws Exception {
this.project.getExtensions().getByType(ExtraPropertiesExtension.class).set("mainClassName",
"com.example.ProjectPropertyMainClass");
SpringBootExtension extension = this.project.getExtensions().create("springBoot", SpringBootExtension.class,
this.project);
extension.setMainClassName("com.example.SpringBootExtensionMainClass");
assertThat(this.convention.call())
.isEqualTo("com.example.SpringBootExtensionMainClass");
assertThat(this.convention.call()).isEqualTo("com.example.SpringBootExtensionMainClass");
}
}

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.
@@ -38,8 +38,7 @@ public class MavenPluginActionIntegrationTests {
@Test
public void clearsConf2ScopeMappingsOfUploadBootArchivesTask() {
assertThat(this.gradleBuild.build("conf2ScopeMappings").getOutput())
.contains("Conf2ScopeMappings = 0");
assertThat(this.gradleBuild.build("conf2ScopeMappings").getOutput()).contains("Conf2ScopeMappings = 0");
}
}

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.
@@ -40,8 +40,8 @@ public class SpringBootPluginIntegrationTests {
@Test
public void failFastWithVersionOfGradleLowerThanRequired() {
BuildResult result = this.gradleBuild.gradleVersion("4.3").buildAndFail();
assertThat(result.getOutput()).contains("Spring Boot plugin requires Gradle 4.4"
+ " or later. The current version is Gradle 4.3");
assertThat(result.getOutput())
.contains("Spring Boot plugin requires Gradle 4.4" + " or later. The current version is Gradle 4.3");
}
@Test
@@ -55,19 +55,17 @@ public class SpringBootPluginIntegrationTests {
}
@Test
public void unresolvedDependenciesAreAnalyzedWhenDependencyResolutionFails()
throws IOException {
public void unresolvedDependenciesAreAnalyzedWhenDependencyResolutionFails() throws IOException {
createMinimalMainSource();
BuildResult result = this.gradleBuild.buildAndFail("compileJava");
assertThat(result.getOutput()).contains(
"During the build, one or more dependencies that were declared without a"
assertThat(result.getOutput())
.contains("During the build, one or more dependencies that were declared without a"
+ " version failed to resolve:")
.contains(" org.springframework.boot:spring-boot-starter:");
}
private void createMinimalMainSource() throws IOException {
File examplePackage = new File(this.gradleBuild.getProjectDir(),
"src/main/java/com/example");
File examplePackage = new File(this.gradleBuild.getProjectDir(), "src/main/java/com/example");
examplePackage.mkdirs();
new File(examplePackage, "Application.java").createNewFile();
}

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.
@@ -48,9 +48,8 @@ public class WarPluginActionIntegrationTests {
@Test
public void applyingWarPluginCreatesBootWarTask() {
assertThat(this.gradleBuild
.build("taskExists", "-PtaskName=bootWar", "-PapplyWarPlugin")
.getOutput()).contains("bootWar exists = true");
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootWar", "-PapplyWarPlugin").getOutput())
.contains("bootWar exists = true");
}
@Test
@@ -68,16 +67,14 @@ public class WarPluginActionIntegrationTests {
File buildLibs = new File(this.gradleBuild.getProjectDir(), "build/libs");
assertThat(buildLibs.listFiles()).containsExactlyInAnyOrder(
new File(buildLibs, this.gradleBuild.getProjectDir().getName() + ".war"),
new File(buildLibs,
this.gradleBuild.getProjectDir().getName() + "-boot.war"));
new File(buildLibs, this.gradleBuild.getProjectDir().getName() + "-boot.war"));
}
@Test
public void errorMessageIsHelpfulWhenMainClassCannotBeResolved() {
BuildResult result = this.gradleBuild.buildAndFail("build", "-PapplyWarPlugin");
assertThat(result.task(":bootWar").getOutcome()).isEqualTo(TaskOutcome.FAILED);
assertThat(result.getOutput()).contains(
"Main class name has not been configured and it could not be resolved");
assertThat(result.getOutput()).contains("Main class name has not been configured and it could not be resolved");
}
}

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.
@@ -45,21 +45,18 @@ public class BuildInfoIntegrationTests {
@Test
public void defaultValues() {
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
Properties buildInfoProperties = buildInfoProperties();
assertThat(buildInfoProperties).containsKey("build.time");
assertThat(buildInfoProperties).containsEntry("build.artifact", "unspecified");
assertThat(buildInfoProperties).containsEntry("build.group", "");
assertThat(buildInfoProperties).containsEntry("build.name",
this.gradleBuild.getProjectDir().getName());
assertThat(buildInfoProperties).containsEntry("build.name", this.gradleBuild.getProjectDir().getName());
assertThat(buildInfoProperties).containsEntry("build.version", "unspecified");
}
@Test
public void basicExecution() {
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
Properties buildInfoProperties = buildInfoProperties();
assertThat(buildInfoProperties).containsKey("build.time");
assertThat(buildInfoProperties).containsEntry("build.artifact", "foo");
@@ -71,32 +68,28 @@ public class BuildInfoIntegrationTests {
@Test
public void notUpToDateWhenExecutedTwiceAsTimeChanges() {
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
}
@Test
public void upToDateWhenExecutedTwiceWithFixedTime() {
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo")
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo")
.getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE);
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo").getOutcome())
.isEqualTo(TaskOutcome.UP_TO_DATE);
}
@Test
public void notUpToDateWhenExecutedTwiceWithFixedTimeAndChangedProjectVersion() {
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo")
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
BuildResult result = this.gradleBuild.build("buildInfo", "-PnullTime",
"-PprojectVersion=0.2.0");
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
BuildResult result = this.gradleBuild.build("buildInfo", "-PnullTime", "-PprojectVersion=0.2.0");
assertThat(result.task(":buildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
}
private Properties buildInfoProperties() {
File file = new File(this.gradleBuild.getProjectDir(),
"build/build-info.properties");
File file = new File(this.gradleBuild.getProjectDir(), "build/build-info.properties");
assertThat(file).isFile();
Properties properties = new Properties();
try (FileReader reader = new FileReader(file)) {

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.
@@ -112,8 +112,7 @@ public class BuildInfoTests {
Instant now = Instant.now();
BuildInfo task = createTask(createProject("test"));
task.getProperties().setTime(now);
assertThat(buildInfoProperties(task)).containsEntry("build.time",
DateTimeFormatter.ISO_INSTANT.format(now));
assertThat(buildInfoProperties(task)).containsEntry("build.time", DateTimeFormatter.ISO_INSTANT.format(now));
}
@Test
@@ -128,8 +127,7 @@ public class BuildInfoTests {
private Project createProject(String projectName) {
try {
File projectDir = this.temp.newFolder(projectName);
return ProjectBuilder.builder().withProjectDir(projectDir)
.withName(projectName).build();
return ProjectBuilder.builder().withProjectDir(projectDir).withName(projectName).build();
}
catch (IOException ex) {
throw new RuntimeException(ex);
@@ -142,8 +140,7 @@ public class BuildInfoTests {
private Properties buildInfoProperties(BuildInfo task) {
task.generateBuildProperties();
return buildInfoProperties(
new File(task.getDestinationDir(), "build-info.properties"));
return buildInfoProperties(new File(task.getDestinationDir(), "build-info.properties"));
}
private Properties buildInfoProperties(File file) {

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,80 +51,72 @@ public abstract class AbstractBootArchiveIntegrationTests {
}
@Test
public void basicBuild() throws InvalidRunnerConfigurationException,
UnexpectedBuildFailure, IOException {
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
public void basicBuild() throws InvalidRunnerConfigurationException, UnexpectedBuildFailure, IOException {
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
}
@Test
public void reproducibleArchive() throws InvalidRunnerConfigurationException,
UnexpectedBuildFailure, IOException, InterruptedException {
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
File jar = new File(this.gradleBuild.getProjectDir(), "build/libs")
.listFiles()[0];
public void reproducibleArchive()
throws InvalidRunnerConfigurationException, UnexpectedBuildFailure, IOException, InterruptedException {
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
File jar = new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0];
String firstHash = FileUtils.sha1Hash(jar);
Thread.sleep(1500);
assertThat(this.gradleBuild.build("clean", this.taskName)
.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("clean", this.taskName).task(":" + this.taskName).getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
String secondHash = FileUtils.sha1Hash(jar);
assertThat(firstHash).isEqualTo(secondHash);
}
@Test
public void upToDateWhenBuiltTwice() throws InvalidRunnerConfigurationException,
UnexpectedBuildFailure, IOException {
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
.getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE);
public void upToDateWhenBuiltTwice()
throws InvalidRunnerConfigurationException, UnexpectedBuildFailure, IOException {
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
.isEqualTo(TaskOutcome.UP_TO_DATE);
}
@Test
public void upToDateWhenBuiltTwiceWithLaunchScriptIncluded()
throws InvalidRunnerConfigurationException, UnexpectedBuildFailure,
IOException {
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", this.taskName)
.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", this.taskName)
.task(":" + this.taskName).getOutcome())
.isEqualTo(TaskOutcome.UP_TO_DATE);
throws InvalidRunnerConfigurationException, UnexpectedBuildFailure, IOException {
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", this.taskName).task(":" + this.taskName)
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", this.taskName).task(":" + this.taskName)
.getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE);
}
@Test
public void notUpToDateWhenLaunchScriptWasNotIncludedAndThenIsIncluded() {
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", this.taskName).task(":" + this.taskName)
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", this.taskName)
.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
}
@Test
public void notUpToDateWhenLaunchScriptWasIncludedAndThenIsNotIncluded() {
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", this.taskName).task(":" + this.taskName)
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", this.taskName)
.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
}
@Test
public void notUpToDateWhenLaunchScriptPropertyChanges() {
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true",
"-PlaunchScriptProperty=foo", this.taskName).task(":" + this.taskName)
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true",
"-PlaunchScriptProperty=bar", this.taskName).task(":" + this.taskName)
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", "-PlaunchScriptProperty=foo", this.taskName)
.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", "-PlaunchScriptProperty=bar", this.taskName)
.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
}
@Test
public void applicationPluginMainClassNameIsUsed() throws IOException {
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
try (JarFile jarFile = new JarFile(
new File(this.gradleBuild.getProjectDir(), "build/libs")
.listFiles()[0])) {
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
try (JarFile jarFile = new JarFile(new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0])) {
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class"))
.isEqualTo("com.example.CustomMain");
}
@@ -132,11 +124,9 @@ public abstract class AbstractBootArchiveIntegrationTests {
@Test
public void springBootExtensionMainClassNameIsUsed() throws IOException {
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
try (JarFile jarFile = new JarFile(
new File(this.gradleBuild.getProjectDir(), "build/libs")
.listFiles()[0])) {
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
try (JarFile jarFile = new JarFile(new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0])) {
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class"))
.isEqualTo("com.example.CustomMain");
}
@@ -144,8 +134,8 @@ public abstract class AbstractBootArchiveIntegrationTests {
@Test
public void duplicatesAreHandledGracefully() throws IOException {
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
}
}

View File

@@ -73,8 +73,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
private T task;
protected AbstractBootArchiveTests(Class<T> taskClass, String launcherClass,
String libPath, String classesPath) {
protected AbstractBootArchiveTests(Class<T> taskClass, String launcherClass, String libPath, String classesPath) {
this.taskClass = taskClass;
this.launcherClass = launcherClass;
this.libPath = libPath;
@@ -84,12 +83,9 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
@Before
public void createTask() {
try {
this.project = ProjectBuilder.builder().withProjectDir(this.temp.newFolder())
.build();
this.project
.setDescription("Test project for " + this.taskClass.getSimpleName());
this.task = configure(
this.project.getTasks().create("testArchive", this.taskClass));
this.project = ProjectBuilder.builder().withProjectDir(this.temp.newFolder()).build();
this.project.setDescription("Test project for " + this.taskClass.getSimpleName());
this.task = configure(this.project.getTasks().create("testArchive", this.taskClass));
}
catch (IOException ex) {
throw new RuntimeException(ex);
@@ -102,17 +98,12 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.execute();
assertThat(this.task.getArchivePath()).exists();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getManifest().getMainAttributes().getValue("Main-Class"))
.isEqualTo(this.launcherClass);
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class"))
.isEqualTo("com.example.Main");
assertThat(jarFile.getManifest().getMainAttributes()
.getValue("Spring-Boot-Classes")).isEqualTo(this.classesPath);
assertThat(
jarFile.getManifest().getMainAttributes().getValue("Spring-Boot-Lib"))
.isEqualTo(this.libPath);
assertThat(jarFile.getManifest().getMainAttributes()
.getValue("Spring-Boot-Version")).isNotNull();
assertThat(jarFile.getManifest().getMainAttributes().getValue("Main-Class")).isEqualTo(this.launcherClass);
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class")).isEqualTo("com.example.Main");
assertThat(jarFile.getManifest().getMainAttributes().getValue("Spring-Boot-Classes"))
.isEqualTo(this.classesPath);
assertThat(jarFile.getManifest().getMainAttributes().getValue("Spring-Boot-Lib")).isEqualTo(this.libPath);
assertThat(jarFile.getManifest().getMainAttributes().getValue("Spring-Boot-Version")).isNotNull();
}
}
@@ -131,16 +122,13 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
public void classpathFoldersArePackagedBeneathClassesPath() throws IOException {
this.task.setMainClassName("com.example.Main");
File classpathFolder = this.temp.newFolder();
File applicationClass = new File(classpathFolder,
"com/example/Application.class");
File applicationClass = new File(classpathFolder, "com/example/Application.class");
applicationClass.getParentFile().mkdirs();
applicationClass.createNewFile();
this.task.classpath(classpathFolder);
this.task.execute();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(
jarFile.getEntry(this.classesPath + "com/example/Application.class"))
.isNotNull();
assertThat(jarFile.getEntry(this.classesPath + "com/example/Application.class")).isNotNull();
}
}
@@ -151,20 +139,16 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
File moduleInfoClass = new File(classpathFolder, "module-info.class");
moduleInfoClass.getParentFile().mkdirs();
moduleInfoClass.createNewFile();
File applicationClass = new File(classpathFolder,
"com/example/Application.class");
File applicationClass = new File(classpathFolder, "com/example/Application.class");
applicationClass.getParentFile().mkdirs();
applicationClass.createNewFile();
this.task.classpath(classpathFolder);
this.task.execute();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(
jarFile.getEntry(this.classesPath + "com/example/Application.class"))
.isNotNull();
assertThat(jarFile.getEntry(this.classesPath + "com/example/Application.class")).isNotNull();
assertThat(jarFile.getEntry("com/example/Application.class")).isNull();
assertThat(jarFile.getEntry("module-info.class")).isNotNull();
assertThat(jarFile.getEntry(this.classesPath + "/module-info.class"))
.isNull();
assertThat(jarFile.getEntry(this.classesPath + "/module-info.class")).isNull();
}
}
@@ -207,24 +191,18 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.setMainClassName("com.example.Main");
this.task.execute();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(
"org/springframework/boot/loader/LaunchedURLClassLoader.class"))
.isNotNull();
assertThat(jarFile.getEntry("org/springframework/boot/loader/LaunchedURLClassLoader.class")).isNotNull();
assertThat(jarFile.getEntry("org/springframework/boot/loader/")).isNotNull();
}
}
@Test
public void loaderIsWrittenToTheRootOfTheJarWhenUsingThePropertiesLauncher()
throws IOException {
public void loaderIsWrittenToTheRootOfTheJarWhenUsingThePropertiesLauncher() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.execute();
this.task.getManifest().getAttributes().put("Main-Class",
"org.springframework.boot.loader.PropertiesLauncher");
this.task.getManifest().getAttributes().put("Main-Class", "org.springframework.boot.loader.PropertiesLauncher");
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(
"org/springframework/boot/loader/LaunchedURLClassLoader.class"))
.isNotNull();
assertThat(jarFile.getEntry("org/springframework/boot/loader/LaunchedURLClassLoader.class")).isNotNull();
assertThat(jarFile.getEntry("org/springframework/boot/loader/")).isNotNull();
}
}
@@ -236,8 +214,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.requiresUnpack("**/one.jar");
this.task.execute();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(this.libPath + "one.jar").getComment())
.startsWith("UNPACK:");
assertThat(jarFile.getEntry(this.libPath + "one.jar").getComment()).startsWith("UNPACK:");
assertThat(jarFile.getEntry(this.libPath + "two.jar").getComment()).isNull();
}
}
@@ -249,8 +226,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.requiresUnpack((element) -> element.getName().endsWith("two.jar"));
this.task.execute();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(this.libPath + "two.jar").getComment())
.startsWith("UNPACK:");
assertThat(jarFile.getEntry(this.libPath + "two.jar").getComment()).startsWith("UNPACK:");
assertThat(jarFile.getEntry(this.libPath + "one.jar").getComment()).isNull();
}
}
@@ -267,8 +243,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
assertThat(Files.readAllBytes(this.task.getArchivePath().toPath()))
.startsWith(new DefaultLaunchScript(null, properties).toByteArray());
try {
Set<PosixFilePermission> permissions = Files
.getPosixFilePermissions(this.task.getArchivePath().toPath());
Set<PosixFilePermission> permissions = Files.getPosixFilePermissions(this.task.getArchivePath().toPath());
assertThat(permissions).contains(PosixFilePermission.OWNER_EXECUTE);
}
catch (UnsupportedOperationException ex) {
@@ -280,12 +255,10 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
public void customLaunchScriptCanBePrepended() throws IOException {
this.task.setMainClassName("com.example.Main");
File customScript = this.temp.newFile("custom.script");
Files.write(customScript.toPath(), Arrays.asList("custom script"),
StandardOpenOption.CREATE);
Files.write(customScript.toPath(), Arrays.asList("custom script"), StandardOpenOption.CREATE);
this.task.launchScript((configuration) -> configuration.setScript(customScript));
this.task.execute();
assertThat(Files.readAllBytes(this.task.getArchivePath().toPath()))
.startsWith("custom script".getBytes());
assertThat(Files.readAllBytes(this.task.getArchivePath().toPath())).startsWith("custom script".getBytes());
}
@Test
@@ -293,46 +266,38 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.setMainClassName("com.example.Main");
this.task.launchScript((configuration) -> {
configuration.getProperties().put("initInfoProvides", "provides");
configuration.getProperties().put("initInfoShortDescription",
"short description");
configuration.getProperties().put("initInfoShortDescription", "short description");
configuration.getProperties().put("initInfoDescription", "description");
});
this.task.execute();
byte[] bytes = Files.readAllBytes(this.task.getArchivePath().toPath());
assertThat(bytes).containsSequence("Provides: provides".getBytes());
assertThat(bytes)
.containsSequence("Short-Description: short description".getBytes());
assertThat(bytes).containsSequence("Short-Description: short description".getBytes());
assertThat(bytes).containsSequence("Description: description".getBytes());
}
@Test
public void customMainClassInTheManifestIsHonored() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.getManifest().getAttributes().put("Main-Class",
"com.example.CustomLauncher");
this.task.getManifest().getAttributes().put("Main-Class", "com.example.CustomLauncher");
this.task.execute();
assertThat(this.task.getArchivePath()).exists();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getManifest().getMainAttributes().getValue("Main-Class"))
.isEqualTo("com.example.CustomLauncher");
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class"))
.isEqualTo("com.example.Main");
assertThat(jarFile.getEntry(
"org/springframework/boot/loader/LaunchedURLClassLoader.class"))
.isNull();
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class")).isEqualTo("com.example.Main");
assertThat(jarFile.getEntry("org/springframework/boot/loader/LaunchedURLClassLoader.class")).isNull();
}
}
@Test
public void customStartClassInTheManifestIsHonored() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.getManifest().getAttributes().put("Start-Class",
"com.example.CustomMain");
this.task.getManifest().getAttributes().put("Start-Class", "com.example.CustomMain");
this.task.execute();
assertThat(this.task.getArchivePath()).exists();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getManifest().getMainAttributes().getValue("Main-Class"))
.isEqualTo(this.launcherClass);
assertThat(jarFile.getManifest().getMainAttributes().getValue("Main-Class")).isEqualTo(this.launcherClass);
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class"))
.isEqualTo("com.example.CustomMain");
}
@@ -348,8 +313,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
assertThat(entry.getTime())
.isEqualTo(BootZipCopyAction.CONSTANT_TIME_FOR_ZIP_ENTRIES);
assertThat(entry.getTime()).isEqualTo(BootZipCopyAction.CONSTANT_TIME_FOR_ZIP_ENTRIES);
}
}
}
@@ -382,8 +346,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.execute();
assertThat(this.task.getArchivePath()).exists();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(this.libPath + "spring-boot-devtools-0.1.2.jar"))
.isNull();
assertThat(jarFile.getEntry(this.libPath + "spring-boot-devtools-0.1.2.jar")).isNull();
}
}
@@ -395,8 +358,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.execute();
assertThat(this.task.getArchivePath()).exists();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(this.libPath + "spring-boot-devtools-0.1.2.jar"))
.isNotNull();
assertThat(jarFile.getEntry(this.libPath + "spring-boot-devtools-0.1.2.jar")).isNotNull();
}
}
@@ -422,23 +384,19 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
}
@Test
public void loaderIsWrittenFirstThenApplicationClassesThenLibraries()
throws IOException {
public void loaderIsWrittenFirstThenApplicationClassesThenLibraries() throws IOException {
this.task.setMainClassName("com.example.Main");
File classpathFolder = this.temp.newFolder();
File applicationClass = new File(classpathFolder,
"com/example/Application.class");
File applicationClass = new File(classpathFolder, "com/example/Application.class");
applicationClass.getParentFile().mkdirs();
applicationClass.createNewFile();
this.task.classpath(classpathFolder, jarFile("first-library.jar"),
jarFile("second-library.jar"), jarFile("third-library.jar"));
this.task.classpath(classpathFolder, jarFile("first-library.jar"), jarFile("second-library.jar"),
jarFile("third-library.jar"));
this.task.requiresUnpack("second-library.jar");
this.task.execute();
assertThat(getEntryNames(this.task.getArchivePath())).containsSubsequence(
"org/springframework/boot/loader/",
this.classesPath + "com/example/Application.class",
this.libPath + "first-library.jar", this.libPath + "second-library.jar",
this.libPath + "third-library.jar");
assertThat(getEntryNames(this.task.getArchivePath())).containsSubsequence("org/springframework/boot/loader/",
this.classesPath + "com/example/Application.class", this.libPath + "first-library.jar",
this.libPath + "second-library.jar", this.libPath + "third-library.jar");
}
protected File jarFile(String name) throws IOException {

View File

@@ -32,16 +32,14 @@ import static org.assertj.core.api.Assertions.assertThat;
public class BootJarTests extends AbstractBootArchiveTests<BootJar> {
public BootJarTests() {
super(BootJar.class, "org.springframework.boot.loader.JarLauncher",
"BOOT-INF/lib/", "BOOT-INF/classes/");
super(BootJar.class, "org.springframework.boot.loader.JarLauncher", "BOOT-INF/lib/", "BOOT-INF/classes/");
}
@Test
public void contentCanBeAddedToBootInfUsingCopySpecFromGetter() throws IOException {
BootJar bootJar = getTask();
bootJar.setMainClassName("com.example.Application");
bootJar.getBootInf().into("test")
.from(new File("build.gradle").getAbsolutePath());
bootJar.getBootInf().into("test").from(new File("build.gradle").getAbsolutePath());
bootJar.execute();
try (JarFile jarFile = new JarFile(bootJar.getArchivePath())) {
assertThat(jarFile.getJarEntry("BOOT-INF/test/build.gradle")).isNotNull();
@@ -52,8 +50,7 @@ public class BootJarTests extends AbstractBootArchiveTests<BootJar> {
public void contentCanBeAddedToBootInfUsingCopySpecAction() throws IOException {
BootJar bootJar = getTask();
bootJar.setMainClassName("com.example.Application");
bootJar.bootInf((copySpec) -> copySpec.into("test")
.from(new File("build.gradle").getAbsolutePath()));
bootJar.bootInf((copySpec) -> copySpec.into("test").from(new File("build.gradle").getAbsolutePath()));
bootJar.execute();
try (JarFile jarFile = new JarFile(bootJar.getArchivePath())) {
assertThat(jarFile.getJarEntry("BOOT-INF/test/build.gradle")).isNotNull();

View File

@@ -32,8 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
public BootWarTests() {
super(BootWar.class, "org.springframework.boot.loader.WarLauncher",
"WEB-INF/lib/", "WEB-INF/classes/");
super(BootWar.class, "org.springframework.boot.loader.WarLauncher", "WEB-INF/lib/", "WEB-INF/classes/");
}
@Test
@@ -72,37 +71,30 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
}
@Test
public void devtoolsJarIsExcludedByDefaultWhenItsOnTheProvidedClasspath()
throws IOException {
public void devtoolsJarIsExcludedByDefaultWhenItsOnTheProvidedClasspath() throws IOException {
getTask().setMainClassName("com.example.Main");
getTask().providedClasspath(this.temp.newFile("spring-boot-devtools-0.1.2.jar"));
getTask().execute();
assertThat(getTask().getArchivePath()).exists();
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
assertThat(jarFile
.getEntry("WEB-INF/lib-provided/spring-boot-devtools-0.1.2.jar"))
.isNull();
assertThat(jarFile.getEntry("WEB-INF/lib-provided/spring-boot-devtools-0.1.2.jar")).isNull();
}
}
@Test
public void devtoolsJarCanBeIncludedWhenItsOnTheProvidedClasspath()
throws IOException {
public void devtoolsJarCanBeIncludedWhenItsOnTheProvidedClasspath() throws IOException {
getTask().setMainClassName("com.example.Main");
getTask().providedClasspath(jarFile("spring-boot-devtools-0.1.2.jar"));
getTask().setExcludeDevtools(false);
getTask().execute();
assertThat(getTask().getArchivePath()).exists();
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
assertThat(jarFile
.getEntry("WEB-INF/lib-provided/spring-boot-devtools-0.1.2.jar"))
.isNotNull();
assertThat(jarFile.getEntry("WEB-INF/lib-provided/spring-boot-devtools-0.1.2.jar")).isNotNull();
}
}
@Test
public void webappResourcesInDirectoriesThatOverlapWithLoaderCanBePackaged()
throws IOException {
public void webappResourcesInDirectoriesThatOverlapWithLoaderCanBePackaged() throws IOException {
File webappFolder = this.temp.newFolder("src", "main", "webapp");
File orgFolder = new File(webappFolder, "org");
orgFolder.mkdir();
@@ -123,8 +115,8 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
getTask().classpath(jarFile("library.jar"));
getTask().providedClasspath(jarFile("provided-library.jar"));
getTask().execute();
assertThat(getEntryNames(getTask().getArchivePath())).containsSubsequence(
"WEB-INF/lib/library.jar", "WEB-INF/lib-provided/provided-library.jar");
assertThat(getEntryNames(getTask().getArchivePath())).containsSubsequence("WEB-INF/lib/library.jar",
"WEB-INF/lib-provided/provided-library.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.
@@ -44,50 +44,50 @@ public class LaunchScriptConfigurationTests {
@Test
public void initInfoProvidesUsesArchiveBaseNameByDefault() {
given(this.task.getBaseName()).willReturn("base-name");
assertThat(new LaunchScriptConfiguration(this.task).getProperties())
.containsEntry("initInfoProvides", "base-name");
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoProvides",
"base-name");
}
@Test
public void initInfoShortDescriptionUsesDescriptionByDefault() {
given(this.project.getDescription()).willReturn("Project description");
assertThat(new LaunchScriptConfiguration(this.task).getProperties())
.containsEntry("initInfoShortDescription", "Project description");
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoShortDescription",
"Project description");
}
@Test
public void initInfoShortDescriptionUsesArchiveBaseNameWhenDescriptionIsNull() {
given(this.task.getBaseName()).willReturn("base-name");
assertThat(new LaunchScriptConfiguration(this.task).getProperties())
.containsEntry("initInfoShortDescription", "base-name");
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoShortDescription",
"base-name");
}
@Test
public void initInfoShortDescriptionUsesSingleLineVersionOfMultiLineProjectDescription() {
given(this.project.getDescription()).willReturn("Project\ndescription");
assertThat(new LaunchScriptConfiguration(this.task).getProperties())
.containsEntry("initInfoShortDescription", "Project description");
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoShortDescription",
"Project description");
}
@Test
public void initInfoDescriptionUsesArchiveBaseNameWhenDescriptionIsNull() {
given(this.task.getBaseName()).willReturn("base-name");
assertThat(new LaunchScriptConfiguration(this.task).getProperties())
.containsEntry("initInfoDescription", "base-name");
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoDescription",
"base-name");
}
@Test
public void initInfoDescriptionUsesProjectDescriptionByDefault() {
given(this.project.getDescription()).willReturn("Project description");
assertThat(new LaunchScriptConfiguration(this.task).getProperties())
.containsEntry("initInfoDescription", "Project description");
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoDescription",
"Project description");
}
@Test
public void initInfoDescriptionUsesCorrectlyFormattedMultiLineProjectDescription() {
given(this.project.getDescription()).willReturn("The\nproject\ndescription");
assertThat(new LaunchScriptConfiguration(this.task).getProperties())
.containsEntry("initInfoDescription", "The\n# project\n# description");
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoDescription",
"The\n# project\n# description");
}
}

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.
@@ -45,23 +45,20 @@ public class MavenIntegrationTests {
@Test
public void bootJarCanBeUploaded() throws FileNotFoundException, IOException {
BuildResult result = this.gradleBuild.build("uploadBootArchives");
assertThat(result.task(":uploadBootArchives").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.task(":uploadBootArchives").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(artifactWithSuffix("jar")).isFile();
assertThat(artifactWithSuffix("pom")).is(pomWith().groupId("com.example")
.artifactId(this.gradleBuild.getProjectDir().getName()).version("1.0")
.noPackaging().noDependencies());
.artifactId(this.gradleBuild.getProjectDir().getName()).version("1.0").noPackaging().noDependencies());
}
@Test
public void bootWarCanBeUploaded() throws IOException {
BuildResult result = this.gradleBuild.build("uploadBootArchives");
assertThat(result.task(":uploadBootArchives").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.task(":uploadBootArchives").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(artifactWithSuffix("war")).isFile();
assertThat(artifactWithSuffix("pom")).is(pomWith().groupId("com.example")
.artifactId(this.gradleBuild.getProjectDir().getName()).version("1.0")
.packaging("war").noDependencies());
assertThat(artifactWithSuffix("pom"))
.is(pomWith().groupId("com.example").artifactId(this.gradleBuild.getProjectDir().getName())
.version("1.0").packaging("war").noDependencies());
}
private File artifactWithSuffix(String suffix) {

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.
@@ -49,8 +49,7 @@ public class MavenPublishingIntegrationTests {
assertThat(result.task(":publish").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(artifactWithSuffix("jar")).isFile();
assertThat(artifactWithSuffix("pom")).is(pomWith().groupId("com.example")
.artifactId(this.gradleBuild.getProjectDir().getName()).version("1.0")
.noPackaging().noDependencies());
.artifactId(this.gradleBuild.getProjectDir().getName()).version("1.0").noPackaging().noDependencies());
}
@Test
@@ -58,9 +57,9 @@ public class MavenPublishingIntegrationTests {
BuildResult result = this.gradleBuild.build("publish");
assertThat(result.task(":publish").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(artifactWithSuffix("war")).isFile();
assertThat(artifactWithSuffix("pom")).is(pomWith().groupId("com.example")
.artifactId(this.gradleBuild.getProjectDir().getName()).version("1.0")
.packaging("war").noDependencies());
assertThat(artifactWithSuffix("pom"))
.is(pomWith().groupId("com.example").artifactId(this.gradleBuild.getProjectDir().getName())
.version("1.0").packaging("war").noDependencies());
}
private File artifactWithSuffix(String suffix) {

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.
@@ -44,8 +44,8 @@ class PomCondition extends Condition<File> {
}
private PomCondition(Set<String> expectedContents, Set<String> notExpectedContents) {
super(new TextDescription("Pom file containing %s and not containing %s",
expectedContents, notExpectedContents));
super(new TextDescription("Pom file containing %s and not containing %s", expectedContents,
notExpectedContents));
this.expectedContents = expectedContents;
this.notExpectedContents = notExpectedContents;
}
@@ -73,8 +73,8 @@ class PomCondition extends Condition<File> {
@Override
public Description description() {
return new TextDescription("Pom file containing %s and not containing %s",
this.expectedContents, this.notExpectedContents);
return new TextDescription("Pom file containing %s and not containing %s", this.expectedContents,
this.notExpectedContents);
}
PomCondition groupId(String groupId) {
@@ -83,8 +83,7 @@ class PomCondition extends Condition<File> {
}
PomCondition artifactId(String artifactId) {
this.expectedContents
.add(String.format("<artifactId>%s</artifactId>", artifactId));
this.expectedContents.add(String.format("<artifactId>%s</artifactId>", artifactId));
return this;
}

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.
@@ -48,12 +48,9 @@ public class BootRunIntegrationTests {
new File(this.gradleBuild.getProjectDir(), "src/main/resources").mkdirs();
BuildResult result = this.gradleBuild.build("bootRun");
assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.getOutput())
.contains("1. " + canonicalPathOf("build/classes/java/main"));
assertThat(result.getOutput())
.contains("2. " + canonicalPathOf("build/resources/main"));
assertThat(result.getOutput())
.doesNotContain(canonicalPathOf("src/main/resources"));
assertThat(result.getOutput()).contains("1. " + canonicalPathOf("build/classes/java/main"));
assertThat(result.getOutput()).contains("2. " + canonicalPathOf("build/resources/main"));
assertThat(result.getOutput()).doesNotContain(canonicalPathOf("src/main/resources"));
}
@Test
@@ -61,54 +58,42 @@ public class BootRunIntegrationTests {
copyApplication();
BuildResult result = this.gradleBuild.build("bootRun");
assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.getOutput())
.contains("1. " + canonicalPathOf("src/main/resources"));
assertThat(result.getOutput())
.contains("2. " + canonicalPathOf("build/classes/java/main"));
assertThat(result.getOutput())
.doesNotContain(canonicalPathOf("build/resources/main"));
assertThat(result.getOutput()).contains("1. " + canonicalPathOf("src/main/resources"));
assertThat(result.getOutput()).contains("2. " + canonicalPathOf("build/classes/java/main"));
assertThat(result.getOutput()).doesNotContain(canonicalPathOf("build/resources/main"));
}
@Test
public void springBootExtensionMainClassNameIsUsed() throws IOException {
BuildResult result = this.gradleBuild.build("echoMainClassName");
assertThat(result.task(":echoMainClassName").getOutcome())
.isEqualTo(TaskOutcome.UP_TO_DATE);
assertThat(result.getOutput())
.contains("Main class name = com.example.CustomMainClass");
assertThat(result.task(":echoMainClassName").getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE);
assertThat(result.getOutput()).contains("Main class name = com.example.CustomMainClass");
}
@Test
public void applicationPluginMainClassNameIsUsed() throws IOException {
BuildResult result = this.gradleBuild.build("echoMainClassName");
assertThat(result.task(":echoMainClassName").getOutcome())
.isEqualTo(TaskOutcome.UP_TO_DATE);
assertThat(result.getOutput())
.contains("Main class name = com.example.CustomMainClass");
assertThat(result.task(":echoMainClassName").getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE);
assertThat(result.getOutput()).contains("Main class name = com.example.CustomMainClass");
}
@Test
public void applicationPluginMainClassNameIsNotUsedWhenItIsNull() throws IOException {
copyApplication();
BuildResult result = this.gradleBuild.build("echoMainClassName");
assertThat(result.task(":echoMainClassName").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.getOutput())
.contains("Main class name = com.example.BootRunApplication");
assertThat(result.task(":echoMainClassName").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.getOutput()).contains("Main class name = com.example.BootRunApplication");
}
@Test
public void applicationPluginJvmArgumentsAreUsed() throws IOException {
BuildResult result = this.gradleBuild.build("echoJvmArguments");
assertThat(result.task(":echoJvmArguments").getOutcome())
.isEqualTo(TaskOutcome.UP_TO_DATE);
assertThat(result.getOutput())
.contains("JVM arguments = [-Dcom.foo=bar, -Dcom.bar=baz]");
assertThat(result.task(":echoJvmArguments").getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE);
assertThat(result.getOutput()).contains("JVM arguments = [-Dcom.foo=bar, -Dcom.bar=baz]");
}
private void copyApplication() throws IOException {
File output = new File(this.gradleBuild.getProjectDir(),
"src/main/java/com/example");
File output = new File(this.gradleBuild.getProjectDir(), "src/main/java/com/example");
output.mkdirs();
FileSystemUtils.copyRecursively(new File("src/test/java/com/example"), output);
}

View File

@@ -59,8 +59,7 @@ import org.springframework.util.FileCopyUtils;
*/
public class GradleBuild implements TestRule {
private static final Pattern GRADLE_VERSION_PATTERN = Pattern
.compile("\\[Gradle .+\\]");
private static final Pattern GRADLE_VERSION_PATTERN = Pattern.compile("\\[Gradle .+\\]");
private final TemporaryFolder temp = new TemporaryFolder();
@@ -116,8 +115,7 @@ public class GradleBuild implements TestRule {
private URL getScriptForTestMethod(Description description) {
String name = description.getTestClass().getSimpleName() + "-"
+ removeGradleVersion(description.getMethodName())
+ this.dsl.getExtension();
+ removeGradleVersion(description.getMethodName()) + this.dsl.getExtension();
return description.getTestClass().getResource(name);
}
@@ -138,10 +136,8 @@ public class GradleBuild implements TestRule {
}
private List<File> pluginClasspath() {
return Arrays.asList(new File("bin"), new File("build/classes/java/main"),
new File("build/resources/main"),
new File(pathOfJarContaining(LaunchScript.class)),
new File(pathOfJarContaining(ClassVisitor.class)),
return Arrays.asList(new File("bin"), new File("build/classes/java/main"), new File("build/resources/main"),
new File(pathOfJarContaining(LaunchScript.class)), new File(pathOfJarContaining(ClassVisitor.class)),
new File(pathOfJarContaining(DependencyManagementPlugin.class)),
new File(pathOfJarContaining(PropertiesKt.class)),
new File(pathOfJarContaining(KotlinCompilerRunner.class)),
@@ -155,8 +151,7 @@ public class GradleBuild implements TestRule {
}
public GradleBuild script(String script) {
this.script = script.endsWith(this.dsl.getExtension()) ? script
: script + this.dsl.getExtension();
this.script = script.endsWith(this.dsl.getExtension()) ? script : script + this.dsl.getExtension();
return this;
}
@@ -181,10 +176,8 @@ public class GradleBuild implements TestRule {
public GradleRunner prepareRunner(String... arguments) throws IOException {
String scriptContent = FileCopyUtils.copyToString(new FileReader(this.script))
.replace("{version}", getBootVersion())
.replace("{dependency-management-plugin-version}",
getDependencyManagementPluginVersion());
FileCopyUtils.copy(scriptContent, new FileWriter(
new File(this.projectDir, "build" + this.dsl.getExtension())));
.replace("{dependency-management-plugin-version}", getDependencyManagementPluginVersion());
FileCopyUtils.copy(scriptContent, new FileWriter(new File(this.projectDir, "build" + this.dsl.getExtension())));
GradleRunner gradleRunner = GradleRunner.create().withProjectDir(this.projectDir)
.withPluginClasspath(pluginClasspath());
if (this.dsl != Dsl.KOTLIN) {
@@ -223,29 +216,24 @@ public class GradleBuild implements TestRule {
private static String getBootVersion() {
return evaluateExpression(
"/*[local-name()='project']/*[local-name()='parent']/*[local-name()='version']"
+ "/text()");
"/*[local-name()='project']/*[local-name()='parent']/*[local-name()='version']" + "/text()");
}
private static String getDependencyManagementPluginVersion() {
try (FileReader pomReader = new FileReader(".flattened-pom.xml")) {
Document pom = DocumentBuilderFactory.newInstance().newDocumentBuilder()
.parse(new InputSource(pomReader));
Document pom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(pomReader));
NodeList dependencyElements = pom.getElementsByTagName("dependency");
for (int i = 0; i < dependencyElements.getLength(); i++) {
Element dependency = (Element) dependencyElements.item(i);
if (dependency.getElementsByTagName("artifactId").item(0).getTextContent()
.equals("dependency-management-plugin")) {
return dependency.getElementsByTagName("version").item(0)
.getTextContent();
return dependency.getElementsByTagName("version").item(0).getTextContent();
}
}
throw new IllegalStateException(
"dependency management plugin version not found");
throw new IllegalStateException("dependency management plugin version not found");
}
catch (Exception ex) {
throw new IllegalStateException(
"Failed to find dependency management plugin version", ex);
throw new IllegalStateException("Failed to find dependency management plugin version", ex);
}
}