Commit ffc99b03 authored by Andy Wilkinson's avatar Andy Wilkinson

Remove use of deprecated Gradle API from plugin's public API

This commit removes the use of the incubating PropertyState and
Provider API that was introduced in Gradle 4.0 and deprecated in
Gradle 4.3. A not-deprecated-but-still-incubating replacement was
introduced in Gradle 4.3. The short life of PropertyState and Provider
has made me wary of using an incubating Gradle API in our public API
as it may not be stable for long. Therefore, this commit does not move
to the replacement as it is incubating. Instead, it falls back to
using Gradle's convention mapping. This is internal API, but its use
is not part of our public API and I perceive the risk of using it to
be lower than using the deprecated and/or incubating API alternatives.

Closes gh-11640
parent 5e17fc77
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 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.
...@@ -106,9 +106,9 @@ public class SpringBootExtension { ...@@ -106,9 +106,9 @@ public class SpringBootExtension {
properties.setArtifact(determineArtifactBaseName()); properties.setArtifact(determineArtifactBaseName());
} }
}); });
bootBuildInfo.setDestinationDir(this.project bootBuildInfo.getConventionMapping().map("destinationDir",
.provider(() -> new File(determineMainSourceSetResourcesOutputDir(), () -> new File(determineMainSourceSetResourcesOutputDir(),
"META-INF"))); "META-INF"));
}); });
if (configurer != null) { if (configurer != null) {
configurer.execute(bootBuildInfo); configurer.execute(bootBuildInfo);
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 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.
...@@ -68,10 +68,10 @@ final class ApplicationPluginAction implements PluginApplicationAction { ...@@ -68,10 +68,10 @@ final class ApplicationPluginAction implements PluginApplicationAction {
bootStartScripts.setClasspath(configuration.getArtifacts().getFiles()); bootStartScripts.setClasspath(configuration.getArtifacts().getFiles());
} }
}); });
bootStartScripts.setOutputDir( bootStartScripts.getConventionMapping().map("outputDir",
project.provider(() -> new File(project.getBuildDir(), "bootScripts"))); () -> new File(project.getBuildDir(), "bootScripts"));
bootStartScripts.setApplicationName( bootStartScripts.getConventionMapping().map("applicationName",
project.provider(() -> applicationConvention.getApplicationName())); () -> applicationConvention.getApplicationName());
CopySpec binCopySpec = project.copySpec().into("bin").from(bootStartScripts); CopySpec binCopySpec = project.copySpec().into("bin").from(bootStartScripts);
binCopySpec.setFileMode(0x755); binCopySpec.setFileMode(0x755);
distribution.getContents().with(binCopySpec); distribution.getContents().with(binCopySpec);
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 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.
...@@ -16,13 +16,7 @@ ...@@ -16,13 +16,7 @@
package org.springframework.boot.gradle.tasks.application; package org.springframework.boot.gradle.tasks.application;
import java.io.File;
import org.gradle.api.provider.PropertyState;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Optional; import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.jvm.application.tasks.CreateStartScripts; import org.gradle.jvm.application.tasks.CreateStartScripts;
/** /**
...@@ -33,54 +27,10 @@ import org.gradle.jvm.application.tasks.CreateStartScripts; ...@@ -33,54 +27,10 @@ import org.gradle.jvm.application.tasks.CreateStartScripts;
*/ */
public class CreateBootStartScripts extends CreateStartScripts { public class CreateBootStartScripts extends CreateStartScripts {
private final PropertyState<File> outputDir = getProject().property(File.class);
private final PropertyState<String> applicationName = getProject()
.property(String.class);
@Override @Override
@Optional @Optional
public String getMainClassName() { public String getMainClassName() {
return super.getMainClassName(); return super.getMainClassName();
} }
@Input
@Override
public String getApplicationName() {
return this.applicationName.getOrNull();
}
@Override
public void setApplicationName(String applicationName) {
this.applicationName.set(applicationName);
}
/**
* Sets the application name to the value from the given
* {@code applicationNameProvider}.
* @param applicationNameProvider the provider of the application name
*/
public void setApplicationName(Provider<String> applicationNameProvider) {
this.applicationName.set(applicationNameProvider);
}
@Override
@OutputDirectory
public File getOutputDir() {
return this.outputDir.getOrNull();
}
@Override
public void setOutputDir(File outputDir) {
this.outputDir.set(outputDir);
}
/**
* Sets the output directory to the value from the given {@code outputDirProvider}.
* @param outputDirProvider the provider of the output directory
*/
public void setOutputDir(Provider<File> outputDirProvider) {
this.outputDir.set(outputDirProvider);
}
} }
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 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.
...@@ -26,8 +26,6 @@ import org.gradle.api.Action; ...@@ -26,8 +26,6 @@ import org.gradle.api.Action;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.Task; import org.gradle.api.Task;
import org.gradle.api.internal.ConventionTask; import org.gradle.api.internal.ConventionTask;
import org.gradle.api.provider.PropertyState;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Input; import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.OutputDirectory; import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.TaskAction;
...@@ -46,7 +44,7 @@ public class BuildInfo extends ConventionTask { ...@@ -46,7 +44,7 @@ public class BuildInfo extends ConventionTask {
private final BuildInfoProperties properties = new BuildInfoProperties(getProject()); private final BuildInfoProperties properties = new BuildInfoProperties(getProject());
private PropertyState<File> destinationDir = getProject().property(File.class); private File destinationDir;
/** /**
* Generates the {@code build-info.properties} file in the configured * Generates the {@code build-info.properties} file in the configured
...@@ -78,7 +76,7 @@ public class BuildInfo extends ConventionTask { ...@@ -78,7 +76,7 @@ public class BuildInfo extends ConventionTask {
*/ */
@OutputDirectory @OutputDirectory
public File getDestinationDir() { public File getDestinationDir() {
return this.destinationDir.isPresent() ? this.destinationDir.get() return this.destinationDir != null ? this.destinationDir
: getProject().getBuildDir(); : getProject().getBuildDir();
} }
...@@ -87,16 +85,7 @@ public class BuildInfo extends ConventionTask { ...@@ -87,16 +85,7 @@ public class BuildInfo extends ConventionTask {
* @param destinationDir the destination directory * @param destinationDir the destination directory
*/ */
public void setDestinationDir(File destinationDir) { public void setDestinationDir(File destinationDir) {
this.destinationDir.set(destinationDir); this.destinationDir = destinationDir;
}
/**
* Sets the directory to which the {@code build-info.properties} file will be written
* to the value from the given {@code destinationDirProvider}.
* @param destinationDirProvider the provider of the destination directory
*/
public void setDestinationDir(Provider<File> destinationDirProvider) {
this.destinationDir.set(destinationDirProvider);
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment