Skip to content

Commit 322615d

Browse files
committed
Merge branch '2.4.x' into 2.5.x
Closes gh-28199
2 parents 51c3758 + 8c3820f commit 322615d

File tree

4 files changed

+84
-18
lines changed

4 files changed

+84
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.build;
18+
19+
import org.gradle.api.DefaultTask;
20+
import org.gradle.api.file.DirectoryProperty;
21+
import org.gradle.api.model.ObjectFactory;
22+
import org.gradle.api.provider.Property;
23+
import org.gradle.api.tasks.Input;
24+
import org.gradle.api.tasks.InputDirectory;
25+
import org.gradle.api.tasks.OutputDirectory;
26+
import org.gradle.api.tasks.TaskAction;
27+
28+
/**
29+
* Tasks for syncing the source code of a Spring Boot application, filtering its
30+
* {@code build.gradle} to set the version of its {@code org.springframework.boot} plugin.
31+
*
32+
* @author Andy Wilkinson
33+
*/
34+
public class SyncAppSource extends DefaultTask {
35+
36+
private final DirectoryProperty sourceDirectory;
37+
38+
private final DirectoryProperty destinationDirectory;
39+
40+
private final Property<String> pluginVersion;
41+
42+
public SyncAppSource() {
43+
ObjectFactory objects = getProject().getObjects();
44+
this.sourceDirectory = objects.directoryProperty();
45+
this.destinationDirectory = objects.directoryProperty();
46+
this.pluginVersion = objects.property(String.class)
47+
.convention(getProject().provider(() -> getProject().getVersion().toString()));
48+
}
49+
50+
@TaskAction
51+
void syncAppSources() {
52+
getProject().sync((copySpec) -> {
53+
copySpec.from(this.sourceDirectory);
54+
copySpec.into(this.destinationDirectory);
55+
copySpec.filter((line) -> line.replace("id \"org.springframework.boot\"",
56+
"id \"org.springframework.boot\" version \"" + getProject().getVersion() + "\""));
57+
});
58+
}
59+
60+
@InputDirectory
61+
public DirectoryProperty getSourceDirectory() {
62+
return this.sourceDirectory;
63+
}
64+
65+
@OutputDirectory
66+
public DirectoryProperty getDestinationDirectory() {
67+
return this.destinationDirectory;
68+
}
69+
70+
@Input
71+
public Property<String> getPluginVersion() {
72+
return this.pluginVersion;
73+
}
74+
75+
}

Diff for: spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/build.gradle

+3-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ task syncMavenRepository(type: Sync) {
2626
into "${buildDir}/int-test-maven-repository"
2727
}
2828

29-
task syncAppSource(type: Sync) {
30-
from "spring-boot-launch-script-tests-app"
31-
into "${buildDir}/spring-boot-launch-script-tests-app"
32-
filter { line ->
33-
line.replace("id \"org.springframework.boot\"", "id \"org.springframework.boot\" version \"${project.version}\"")
34-
}
29+
task syncAppSource(type: org.springframework.boot.build.SyncAppSource) {
30+
sourceDirectory = file("spring-boot-launch-script-tests-app")
31+
destinationDirectory = file("${buildDir}/spring-boot-launch-script-tests-app")
3532
}
3633

3734
task buildApp(type: GradleBuild) {

Diff for: spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/build.gradle

+3-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@ task syncMavenRepository(type: Sync) {
2727
into "${buildDir}/int-test-maven-repository"
2828
}
2929

30-
task syncAppSource(type: Sync) {
31-
from "spring-boot-loader-tests-app"
32-
into "${buildDir}/spring-boot-loader-tests-app"
33-
filter { line ->
34-
line.replace("id \"org.springframework.boot\"", "id \"org.springframework.boot\" version \"${project.version}\"")
35-
}
30+
task syncAppSource(type: org.springframework.boot.build.SyncAppSource) {
31+
sourceDirectory = file("spring-boot-loader-tests-app")
32+
destinationDirectory = file("${buildDir}/spring-boot-loader-tests-app")
3633
}
3734

3835
task buildApp(type: GradleBuild) {

Diff for: spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/build.gradle

+3-6
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,9 @@ task syncTestRepository(type: Sync) {
3636
}
3737
}
3838

39-
task syncAppSource(type: Sync) {
40-
from "spring-boot-server-tests-app"
41-
into "${buildDir}/spring-boot-server-tests-app"
42-
filter { line ->
43-
line.replace("id \"org.springframework.boot\"", "id \"org.springframework.boot\" version \"${project.version}\"")
44-
}
39+
task syncAppSource(type: org.springframework.boot.build.SyncAppSource) {
40+
sourceDirectory = file("spring-boot-server-tests-app")
41+
destinationDirectory = file("${buildDir}/spring-boot-server-tests-app")
4542
}
4643

4744
task buildApps(type: GradleBuild) {

0 commit comments

Comments
 (0)