Merge branch '2.5.x' into 2.6.x

Closes gh-29805
pull/30003/head
Andy Wilkinson 3 years ago
commit 85d14cdb2c

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,7 +20,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.lang.reflect.Method;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import org.gradle.api.GradleException; import org.gradle.api.GradleException;
@ -30,16 +29,10 @@ import org.gradle.api.distribution.Distribution;
import org.gradle.api.distribution.DistributionContainer; import org.gradle.api.distribution.DistributionContainer;
import org.gradle.api.file.CopySpec; import org.gradle.api.file.CopySpec;
import org.gradle.api.file.FileCollection; import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.IConventionAware;
import org.gradle.api.plugins.ApplicationPlugin; import org.gradle.api.plugins.ApplicationPlugin;
import org.gradle.api.plugins.ApplicationPluginConvention; import org.gradle.api.plugins.ApplicationPluginConvention;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.jvm.application.scripts.TemplateBasedScriptGenerator; import org.gradle.jvm.application.scripts.TemplateBasedScriptGenerator;
import org.gradle.jvm.application.tasks.CreateStartScripts; import org.gradle.jvm.application.tasks.CreateStartScripts;
import org.gradle.util.GradleVersion;
import org.springframework.boot.gradle.tasks.application.CreateBootStartScripts;
/** /**
* Action that is executed in response to the {@link ApplicationPlugin} being applied. * Action that is executed in response to the {@link ApplicationPlugin} being applied.
@ -54,9 +47,9 @@ final class ApplicationPluginAction implements PluginApplicationAction {
.getPlugin(ApplicationPluginConvention.class); .getPlugin(ApplicationPluginConvention.class);
DistributionContainer distributions = project.getExtensions().getByType(DistributionContainer.class); DistributionContainer distributions = project.getExtensions().getByType(DistributionContainer.class);
Distribution distribution = distributions.create("boot"); Distribution distribution = distributions.create("boot");
configureBaseNameConvention(project, applicationConvention, distribution); distribution.getDistributionBaseName()
CreateStartScripts bootStartScripts = project.getTasks().create("bootStartScripts", .convention((project.provider(() -> applicationConvention.getApplicationName() + "-boot")));
determineCreateStartScriptsClass()); CreateStartScripts bootStartScripts = project.getTasks().create("bootStartScripts", CreateStartScripts.class);
bootStartScripts bootStartScripts
.setDescription("Generates OS-specific start scripts to run the project as a Spring Boot application."); .setDescription("Generates OS-specific start scripts to run the project as a Spring Boot application.");
((TemplateBasedScriptGenerator) bootStartScripts.getUnixStartScriptGenerator()) ((TemplateBasedScriptGenerator) bootStartScripts.getUnixStartScriptGenerator())
@ -81,45 +74,6 @@ final class ApplicationPluginAction implements PluginApplicationAction {
distribution.getContents().with(binCopySpec); distribution.getContents().with(binCopySpec);
} }
private Class<? extends CreateStartScripts> determineCreateStartScriptsClass() {
return isGradle64OrLater() ? CreateStartScripts.class : CreateBootStartScripts.class;
}
private boolean isGradle64OrLater() {
return GradleVersion.current().getBaseVersion().compareTo(GradleVersion.version("6.4")) >= 0;
}
@SuppressWarnings("unchecked")
private void configureBaseNameConvention(Project project, ApplicationPluginConvention applicationConvention,
Distribution distribution) {
Method getDistributionBaseName = findMethod(distribution.getClass(), "getDistributionBaseName");
if (getDistributionBaseName != null) {
try {
Property<String> distributionBaseName = (Property<String>) distribution.getClass()
.getMethod("getDistributionBaseName").invoke(distribution);
distributionBaseName.getClass().getMethod("convention", Provider.class).invoke(distributionBaseName,
project.provider(() -> applicationConvention.getApplicationName() + "-boot"));
return;
}
catch (Exception ex) {
// Continue
}
}
if (distribution instanceof IConventionAware) {
((IConventionAware) distribution).getConventionMapping().map("baseName",
() -> applicationConvention.getApplicationName() + "-boot");
}
}
private static Method findMethod(Class<?> type, String name) {
for (Method candidate : type.getMethods()) {
if (candidate.getName().equals(name)) {
return candidate;
}
}
return null;
}
@Override @Override
public Class<? extends Plugin<Project>> getPluginClass() { public Class<? extends Plugin<Project>> getPluginClass() {
return ApplicationPlugin.class; return ApplicationPlugin.class;

@ -47,7 +47,6 @@ import org.gradle.api.tasks.bundling.Jar;
import org.gradle.api.tasks.compile.JavaCompile; import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.jvm.toolchain.JavaToolchainService; import org.gradle.jvm.toolchain.JavaToolchainService;
import org.gradle.jvm.toolchain.JavaToolchainSpec; import org.gradle.jvm.toolchain.JavaToolchainSpec;
import org.gradle.util.GradleVersion;
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage; import org.springframework.boot.gradle.tasks.bundling.BootBuildImage;
import org.springframework.boot.gradle.tasks.bundling.BootJar; import org.springframework.boot.gradle.tasks.bundling.BootJar;
@ -158,16 +157,10 @@ final class JavaPluginAction implements PluginApplicationAction {
} }
private void configureToolchainConvention(Project project, BootRun run) { private void configureToolchainConvention(Project project, BootRun run) {
if (isGradle67OrLater()) {
JavaToolchainSpec toolchain = project.getExtensions().getByType(JavaPluginExtension.class).getToolchain(); JavaToolchainSpec toolchain = project.getExtensions().getByType(JavaPluginExtension.class).getToolchain();
JavaToolchainService toolchainService = project.getExtensions().getByType(JavaToolchainService.class); JavaToolchainService toolchainService = project.getExtensions().getByType(JavaToolchainService.class);
run.getJavaLauncher().convention(toolchainService.launcherFor(toolchain)); run.getJavaLauncher().convention(toolchainService.launcherFor(toolchain));
} }
}
private boolean isGradle67OrLater() {
return GradleVersion.current().getBaseVersion().compareTo(GradleVersion.version("6.7")) >= 0;
}
private JavaPluginConvention javaPluginConvention(Project project) { private JavaPluginConvention javaPluginConvention(Project project) {
return project.getConvention().getPlugin(JavaPluginConvention.class); return project.getConvention().getPlugin(JavaPluginConvention.class);

@ -176,19 +176,13 @@ public class ResolveMainClassName extends DefaultTask {
return resolveMainClassNameProvider; return resolveMainClassNameProvider;
} }
@SuppressWarnings("deprecation")
private static String getJavaApplicationMainClass(Convention convention) { private static String getJavaApplicationMainClass(Convention convention) {
JavaApplication javaApplication = convention.findByType(JavaApplication.class); JavaApplication javaApplication = convention.findByType(JavaApplication.class);
if (javaApplication == null) { if (javaApplication == null) {
return null; return null;
} }
try {
return javaApplication.getMainClass().getOrNull(); return javaApplication.getMainClass().getOrNull();
} }
catch (NoSuchMethodError ex) {
return javaApplication.getMainClassName();
}
}
private static final class ClassNameReader implements Transformer<String, RegularFile> { private static final class ClassNameReader implements Transformer<String, RegularFile> {

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,7 +25,9 @@ import org.gradle.jvm.application.tasks.CreateStartScripts;
* *
* @author Andy Wilkinson * @author Andy Wilkinson
* @since 2.0.0 * @since 2.0.0
* @deprecated since 2.5.10 for removal in 2.8.0 in favor of {@link CreateStartScripts}.
*/ */
@Deprecated
public class CreateBootStartScripts extends CreateStartScripts { public class CreateBootStartScripts extends CreateStartScripts {
@Override @Override

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -66,14 +66,9 @@ public class BuildInfoProperties implements Serializable {
} }
private Provider<String> projectVersion(Project project) { private Provider<String> projectVersion(Project project) {
try {
Provider<String> externalVersionProperty = project.getProviders().gradleProperty("version") Provider<String> externalVersionProperty = project.getProviders().gradleProperty("version")
.forUseAtConfigurationTime(); .forUseAtConfigurationTime();
externalVersionProperty.getOrNull(); externalVersionProperty.getOrNull();
}
catch (NoSuchMethodError ex) {
// Gradle < 6.5
}
return project.provider(() -> project.getVersion().toString()); return project.provider(() -> project.getVersion().toString());
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -89,15 +89,10 @@ public class BootRun extends JavaExec {
} }
private boolean isJava13OrLater() { private boolean isJava13OrLater() {
try {
Property<JavaLauncher> javaLauncher = this.getJavaLauncher(); Property<JavaLauncher> javaLauncher = this.getJavaLauncher();
if (javaLauncher.isPresent()) { if (javaLauncher.isPresent()) {
return javaLauncher.get().getMetadata().getLanguageVersion().asInt() >= 13; return javaLauncher.get().getMetadata().getLanguageVersion().asInt() >= 13;
} }
}
catch (NoSuchMethodError ex) {
// Continue
}
for (Method method : String.class.getMethods()) { for (Method method : String.class.getMethods()) {
if (method.getName().equals("stripIndent")) { if (method.getName().equals("stripIndent")) {
return true; return true;

Loading…
Cancel
Save