Merge branch '2.0.x' into 2.1.x
Closes gh-17078
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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())));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user