Skip to content

Commit 76e42ff

Browse files
Correct grouping of custom buildpacks
This commit corrects the order.toml file that is generated and added to the builder when building an image using custom buildpacks with the Maven or Gradle plugin in order to support buildpacks that depend on detection as a group. Fixes gh-25378
1 parent 9c24ca0 commit 76e42ff

File tree

9 files changed

+45
-58
lines changed

9 files changed

+45
-58
lines changed

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/Buildpacks.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,20 @@ void addOrderLayerContent(Layout layout) throws IOException {
6363

6464
private String getOrderToml() {
6565
StringBuilder builder = new StringBuilder();
66+
builder.append("[[order]]\n\n");
6667
for (Buildpack buildpack : this.buildpacks) {
6768
appendToOrderToml(builder, buildpack.getCoordinates());
6869
}
6970
return builder.toString();
7071
}
7172

7273
private void appendToOrderToml(StringBuilder builder, BuildpackCoordinates coordinates) {
73-
builder.append("[[order]]\n");
74-
builder.append("group = [\n");
75-
builder.append(" { ");
76-
builder.append("id = \"" + coordinates.getId() + "\"");
74+
builder.append(" [[order.group]]\n");
75+
builder.append(" id = \"" + coordinates.getId() + "\"\n");
7776
if (StringUtils.hasText(coordinates.getVersion())) {
78-
builder.append(", version = \"" + coordinates.getVersion() + "\"");
77+
builder.append(" version = \"" + coordinates.getVersion() + "\"\n");
7978
}
80-
builder.append(" }\n");
81-
builder.append("]\n\n");
79+
builder.append("\n");
8280
}
8381

8482
static Buildpacks of(List<Buildpack> buildpacks) {

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpacksTests.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,18 @@ private void assertThatOrderLayerContentIsCorrect(Layer layer) throws IOExceptio
9494
private String getExpectedToml() {
9595
StringBuilder toml = new StringBuilder();
9696
toml.append("[[order]]\n");
97-
toml.append("group = [\n");
98-
toml.append(" { id = \"example/buildpack1\", version = \"0.0.1\" }\n");
99-
toml.append("]\n\n");
100-
toml.append("[[order]]\n");
101-
toml.append("group = [\n");
102-
toml.append(" { id = \"example/buildpack2\", version = \"0.0.2\" }\n");
103-
toml.append("]\n\n");
104-
toml.append("[[order]]\n");
105-
toml.append("group = [\n");
106-
toml.append(" { id = \"example/buildpack3\" }\n");
107-
toml.append("]\n\n");
97+
toml.append("\n");
98+
toml.append(" [[order.group]]\n");
99+
toml.append(" id = \"example/buildpack1\"\n");
100+
toml.append(" version = \"0.0.1\"\n");
101+
toml.append("\n");
102+
toml.append(" [[order.group]]\n");
103+
toml.append(" id = \"example/buildpack2\"\n");
104+
toml.append(" version = \"0.0.2\"\n");
105+
toml.append("\n");
106+
toml.append(" [[order.group]]\n");
107+
toml.append(" id = \"example/buildpack3\"\n");
108+
toml.append("\n");
108109
return toml.toString();
109110
}
110111

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/EphemeralBuilderTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ void getArchiveContainsBuildpackLayers() throws Exception {
146146
assertBuildpackLayerContent(builder, 2, "/cnb/buildpacks/example_buildpack3/0.0.3/buildpack.toml");
147147
File orderDirectory = unpack(getLayer(builder.getArchive(), 3), "order");
148148
assertThat(new File(orderDirectory, "cnb/order.toml")).usingCharset(StandardCharsets.UTF_8)
149-
.hasContent(content("order-versions.toml"));
149+
.hasContent(content("order.toml"));
150150
}
151151

152152
private void assertBuildpackLayerContent(EphemeralBuilder builder, int index, String s) throws Exception {

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/resources/org/springframework/boot/buildpack/platform/build/order-versions.toml

Lines changed: 0 additions & 15 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
[[order]]
2-
group = [
3-
{ id = "example/buildpack1" }
4-
]
52

6-
[[order]]
7-
group = [
8-
{ id = "example/buildpack2" }
9-
]
3+
[[order.group]]
4+
id = "example/buildpack1"
5+
version = "0.0.1"
106

11-
[[order]]
12-
group = [
13-
{ id = "example/buildpack3" }
14-
]
7+
[[order.group]]
8+
id = "example/buildpack2"
9+
version = "0.0.2"
10+
11+
[[order.group]]
12+
id = "example/buildpack3"
13+
version = "0.0.3"
1514

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ void buildsImageWithBuildpackFromTarGzip() throws IOException {
203203
}
204204

205205
@TestTemplate
206-
void buildsImageWithBuildpackFromImage() throws IOException {
206+
void buildsImageWithBuildpacksFromImages() throws IOException {
207207
writeMainClass();
208208
writeLongNameResource();
209209
BuildResult result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT");

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithBuildpackFromImage.gradle

Lines changed: 0 additions & 11 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
plugins {
2+
id 'java'
3+
id 'org.springframework.boot' version '{version}'
4+
}
5+
6+
sourceCompatibility = '1.8'
7+
targetCompatibility = '1.8'
8+
9+
bootBuildImage {
10+
buildpacks = ["gcr.io/paketo-buildpacks/bellsoft-liberica:latest",
11+
"gcr.io/paketo-buildpacks/executable-jar:latest",
12+
"gcr.io/paketo-buildpacks/spring-boot:latest"]
13+
}

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/build-image-custom-buildpacks/pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
<configuration>
2525
<image>
2626
<buildpacks>
27-
<buildpack>paketo-buildpacks/java</buildpack>
27+
<buildpack>gcr.io/paketo-buildpacks/bellsoft-liberica:latest</buildpack>
28+
<buildpack>gcr.io/paketo-buildpacks/executable-jar:latest</buildpack>
29+
<buildpack>gcr.io/paketo-buildpacks/spring-boot:latest</buildpack>
2830
</buildpacks>
2931
</image>
3032
</configuration>

0 commit comments

Comments
 (0)