Skip to content

Commit 6d8c333

Browse files
committed
Replace convention mappings with PropertyState and Provider
Closes gh-9891
1 parent 6eee9de commit 6d8c333

File tree

4 files changed

+71
-16
lines changed

4 files changed

+71
-16
lines changed

spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/dsl/SpringBootExtension.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.boot.gradle.dsl;
1818

1919
import java.io.File;
20-
import java.util.concurrent.Callable;
2120

2221
import org.gradle.api.Action;
2322
import org.gradle.api.Project;
@@ -87,11 +86,9 @@ public void buildInfo(Action<BuildInfo> configurer) {
8786
properties.setArtifact(determineArtifactBaseName());
8887
}
8988
});
90-
bootBuildInfo.getConventionMapping()
91-
.map("destinationDir",
92-
(Callable<File>) () -> new File(
93-
determineMainSourceSetResourcesOutputDir(),
94-
"META-INF"));
89+
bootBuildInfo.setDestinationDir(this.project
90+
.provider(() -> new File(determineMainSourceSetResourcesOutputDir(),
91+
"META-INF")));
9592
});
9693
if (configurer != null) {
9794
configurer.execute(bootBuildInfo);

spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ public void execute(Project project) {
6868
bootStartScripts.setClasspath(configuration.getArtifacts().getFiles());
6969
}
7070
});
71-
bootStartScripts.getConventionMapping().map("outputDir",
72-
() -> new File(project.getBuildDir(), "bootScripts"));
73-
bootStartScripts.getConventionMapping().map("applicationName",
74-
() -> applicationConvention.getApplicationName());
71+
bootStartScripts.setOutputDir(
72+
project.provider(() -> new File(project.getBuildDir(), "bootScripts")));
73+
bootStartScripts.setApplicationName(
74+
project.provider(() -> applicationConvention.getApplicationName()));
7575
CopySpec binCopySpec = project.copySpec().into("bin").from(bootStartScripts);
7676
binCopySpec.setFileMode(0x755);
7777
distribution.getContents().with(binCopySpec);

spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/application/CreateBootStartScripts.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616

1717
package org.springframework.boot.gradle.tasks.application;
1818

19+
import java.io.File;
20+
21+
import org.gradle.api.provider.PropertyState;
22+
import org.gradle.api.provider.Provider;
23+
import org.gradle.api.tasks.Input;
1924
import org.gradle.api.tasks.Optional;
25+
import org.gradle.api.tasks.OutputDirectory;
2026
import org.gradle.jvm.application.tasks.CreateStartScripts;
2127

2228
/**
@@ -27,10 +33,54 @@
2733
*/
2834
public class CreateBootStartScripts extends CreateStartScripts {
2935

36+
private final PropertyState<File> outputDir = getProject().property(File.class);
37+
38+
private final PropertyState<String> applicationName = getProject()
39+
.property(String.class);
40+
3041
@Override
3142
@Optional
3243
public String getMainClassName() {
3344
return super.getMainClassName();
3445
}
3546

47+
@Input
48+
@Override
49+
public String getApplicationName() {
50+
return this.applicationName.getOrNull();
51+
}
52+
53+
@Override
54+
public void setApplicationName(String applicationName) {
55+
this.applicationName.set(applicationName);
56+
}
57+
58+
/**
59+
* Sets the application name to the value from the given
60+
* {@code applicationNameProvider}.
61+
* @param applicationNameProvider the provider of the application name
62+
*/
63+
public void setApplicationName(Provider<String> applicationNameProvider) {
64+
this.applicationName.set(applicationNameProvider);
65+
}
66+
67+
@Override
68+
@OutputDirectory
69+
public File getOutputDir() {
70+
return this.outputDir.getOrNull();
71+
}
72+
73+
@Override
74+
public void setOutputDir(File outputDir) {
75+
this.outputDir.set(outputDir);
76+
}
77+
78+
/**
79+
* Sets the output directory to the value from the given {@code outputDirProvider}.
80+
* @param outputDirProvider the provider of the output directory
81+
*/
82+
public void setOutputDir(Provider<File> outputDirProvider) {
83+
this.outputDir.set(outputDirProvider);
84+
}
85+
3686
}

spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfo.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.gradle.api.Project;
2727
import org.gradle.api.Task;
2828
import org.gradle.api.internal.ConventionTask;
29+
import org.gradle.api.provider.PropertyState;
30+
import org.gradle.api.provider.Provider;
2931
import org.gradle.api.tasks.Input;
3032
import org.gradle.api.tasks.OutputDirectory;
3133
import org.gradle.api.tasks.TaskAction;
@@ -44,7 +46,7 @@ public class BuildInfo extends ConventionTask {
4446

4547
private final BuildInfoProperties properties = new BuildInfoProperties(getProject());
4648

47-
private File destinationDir;
49+
private PropertyState<File> destinationDir = getProject().property(File.class);
4850

4951
/**
5052
* Generates the {@code build-info.properties} file in the configured
@@ -76,23 +78,30 @@ public void generateBuildProperties() {
7678
*/
7779
@OutputDirectory
7880
public File getDestinationDir() {
79-
return this.destinationDir != null ? this.destinationDir
81+
return this.destinationDir.isPresent() ? this.destinationDir.get()
8082
: getProject().getBuildDir();
8183
}
8284

8385
/**
8486
* Sets the directory to which the {@code build-info.properties} file will be written.
85-
*
8687
* @param destinationDir the destination directory
8788
*/
8889
public void setDestinationDir(File destinationDir) {
89-
this.destinationDir = destinationDir;
90+
this.destinationDir.set(destinationDir);
91+
}
92+
93+
/**
94+
* Sets the directory to which the {@code build-info.properties} file will be written
95+
* to the value from the given {@code destinationDirProvider}.
96+
* @param destinationDirProvider the provider of the destination directory
97+
*/
98+
public void setDestinationDir(Provider<File> destinationDirProvider) {
99+
this.destinationDir.set(destinationDirProvider);
90100
}
91101

92102
/**
93103
* Returns the {@link BuildInfoProperties properties} that will be included in the
94104
* {@code build-info.properties} file.
95-
*
96105
* @return the properties
97106
*/
98107
@Input
@@ -102,7 +111,6 @@ public BuildInfoProperties getProperties() {
102111

103112
/**
104113
* Executes the given {@code action} on the {@link #getProperties()} properties.
105-
*
106114
* @param action the action
107115
*/
108116
public void properties(Action<BuildInfoProperties> action) {

0 commit comments

Comments
 (0)