Merge branch '2.7.x'

pull/29826/head
Andy Wilkinson 3 years ago
commit e52a5490bf

@ -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");
* 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.InputStreamReader;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.util.concurrent.Callable;
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.file.CopySpec;
import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.IConventionAware;
import org.gradle.api.plugins.ApplicationPlugin;
import org.gradle.api.plugins.JavaApplication;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.jvm.application.scripts.TemplateBasedScriptGenerator;
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.
@ -53,9 +46,9 @@ final class ApplicationPluginAction implements PluginApplicationAction {
JavaApplication javaApplication = project.getExtensions().getByType(JavaApplication.class);
DistributionContainer distributions = project.getExtensions().getByType(DistributionContainer.class);
Distribution distribution = distributions.create("boot");
configureBaseNameConvention(project, javaApplication, distribution);
CreateStartScripts bootStartScripts = project.getTasks().create("bootStartScripts",
determineCreateStartScriptsClass());
distribution.getDistributionBaseName()
.convention((project.provider(() -> javaApplication.getApplicationName() + "-boot")));
CreateStartScripts bootStartScripts = project.getTasks().create("bootStartScripts", CreateStartScripts.class);
bootStartScripts
.setDescription("Generates OS-specific start scripts to run the project as a Spring Boot application.");
((TemplateBasedScriptGenerator) bootStartScripts.getUnixStartScriptGenerator())
@ -79,45 +72,6 @@ final class ApplicationPluginAction implements PluginApplicationAction {
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, JavaApplication javaApplication,
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(() -> javaApplication.getApplicationName() + "-boot"));
return;
}
catch (Exception ex) {
// Continue
}
}
if (distribution instanceof IConventionAware) {
((IConventionAware) distribution).getConventionMapping().map("baseName",
() -> javaApplication.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
public Class<? extends Plugin<Project>> getPluginClass() {
return ApplicationPlugin.class;

@ -46,7 +46,6 @@ import org.gradle.api.tasks.bundling.Jar;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.jvm.toolchain.JavaToolchainService;
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.BootJar;
@ -158,15 +157,9 @@ final class JavaPluginAction implements PluginApplicationAction {
}
private void configureToolchainConvention(Project project, BootRun run) {
if (isGradle67OrLater()) {
JavaToolchainSpec toolchain = project.getExtensions().getByType(JavaPluginExtension.class).getToolchain();
JavaToolchainService toolchainService = project.getExtensions().getByType(JavaToolchainService.class);
run.getJavaLauncher().convention(toolchainService.launcherFor(toolchain));
}
}
private boolean isGradle67OrLater() {
return GradleVersion.current().getBaseVersion().compareTo(GradleVersion.version("6.7")) >= 0;
JavaToolchainSpec toolchain = project.getExtensions().getByType(JavaPluginExtension.class).getToolchain();
JavaToolchainService toolchainService = project.getExtensions().getByType(JavaToolchainService.class);
run.getJavaLauncher().convention(toolchainService.launcherFor(toolchain));
}
private JavaPluginExtension javaPluginExtension(Project project) {

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

@ -1,38 +0,0 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.gradle.tasks.application;
import org.gradle.api.tasks.Optional;
import org.gradle.jvm.application.tasks.CreateStartScripts;
/**
* Customization of {@link CreateStartScripts} that makes the {@link #getMainClassName()
* main class name} optional.
*
* @author Andy Wilkinson
* @since 2.0.0
*/
public class CreateBootStartScripts extends CreateStartScripts {
@Override
@Optional
@Deprecated
public String getMainClassName() {
return super.getMainClassName();
}
}

@ -1,20 +0,0 @@
/*
* 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Classes related to Gradle's application features.
*/
package org.springframework.boot.gradle.tasks.application;

@ -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");
* you may not use this file except in compliance with the License.
@ -91,14 +91,9 @@ public class BootRun extends JavaExec {
}
private boolean isJava13OrLater() {
try {
Property<JavaLauncher> javaLauncher = this.getJavaLauncher();
if (javaLauncher.isPresent()) {
return javaLauncher.get().getMetadata().getLanguageVersion().asInt() >= 13;
}
}
catch (NoSuchMethodError ex) {
// Continue
Property<JavaLauncher> javaLauncher = this.getJavaLauncher();
if (javaLauncher.isPresent()) {
return javaLauncher.get().getMetadata().getLanguageVersion().asInt() >= 13;
}
for (Method method : String.class.getMethods()) {
if (method.getName().equals("stripIndent")) {

Loading…
Cancel
Save