Skip to content

Commit f032690

Browse files
Add support for CNB platform API 0.9
Fixes gh-30566
1 parent ff40c8b commit f032690

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
package org.springframework.boot.buildpack.platform.build;
1818

1919
import java.util.Arrays;
20-
import java.util.List;
21-
import java.util.stream.Collectors;
20+
import java.util.stream.IntStream;
2221

2322
import org.springframework.util.StringUtils;
2423

@@ -32,8 +31,7 @@ final class ApiVersions {
3231
/**
3332
* The platform API versions supported by this release.
3433
*/
35-
static final ApiVersions SUPPORTED_PLATFORMS = new ApiVersions(ApiVersion.of(0, 3), ApiVersion.of(0, 4),
36-
ApiVersion.of(0, 5), ApiVersion.of(0, 6), ApiVersion.of(0, 7), ApiVersion.of(0, 8));
34+
static final ApiVersions SUPPORTED_PLATFORMS = ApiVersions.of(0, IntStream.rangeClosed(3, 9));
3735

3836
private final ApiVersion[] apiVersions;
3937

@@ -92,8 +90,12 @@ public String toString() {
9290
* @throws IllegalArgumentException if any values could not be parsed
9391
*/
9492
static ApiVersions parse(String... values) {
95-
List<ApiVersion> versions = Arrays.stream(values).map(ApiVersion::parse).collect(Collectors.toList());
96-
return new ApiVersions(versions.toArray(new ApiVersion[] {}));
93+
return new ApiVersions(Arrays.stream(values).map(ApiVersion::parse).toArray(ApiVersion[]::new));
94+
}
95+
96+
static ApiVersions of(int major, IntStream minorsInclusive) {
97+
return new ApiVersions(
98+
minorsInclusive.mapToObj((minor) -> ApiVersion.of(major, minor)).toArray(ApiVersion[]::new));
9799
}
98100

99101
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.buildpack.platform.build;
1818

19+
import java.util.stream.IntStream;
20+
1921
import org.junit.jupiter.api.Test;
2022

2123
import static org.assertj.core.api.Assertions.assertThat;
@@ -65,6 +67,12 @@ void findLatestWhenNoneSupportedThrowsException() {
6567
"Detected platform API versions '1.3,1.4' are not included in supported versions '1.1,1.2'");
6668
}
6769

70+
@Test
71+
void createFromRange() {
72+
ApiVersions versions = ApiVersions.of(1, IntStream.rangeClosed(2, 7));
73+
assertThat(versions.toString()).isEqualTo("1.2,1.3,1.4,1.5,1.6,1.7");
74+
}
75+
6876
@Test
6977
void toStringReturnsString() {
7078
assertThat(ApiVersions.parse("1.1", "2.2", "3.3").toString()).isEqualTo("1.1,2.2,3.3");

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ void executeWhenPlatformApiNotSupportedThrowsException() throws Exception {
161161
given(this.docker.container().create(any(), any())).willAnswer(answerWithGeneratedContainerId());
162162
given(this.docker.container().wait(any())).willReturn(ContainerStatus.of(0, null));
163163
assertThatIllegalStateException()
164-
.isThrownBy(() -> createLifecycle("builder-metadata-unsupported-api.json").execute()).withMessage(
165-
"Detected platform API versions '0.2' are not included in supported versions '0.3,0.4,0.5,0.6,0.7,0.8'");
164+
.isThrownBy(() -> createLifecycle("builder-metadata-unsupported-api.json").execute())
165+
.withMessageContaining("Detected platform API versions '0.2' are not included in supported versions");
166166
}
167167

168168
@Test
@@ -171,8 +171,9 @@ void executeWhenMultiplePlatformApisNotSupportedThrowsException() throws Excepti
171171
given(this.docker.container().create(any(), any())).willAnswer(answerWithGeneratedContainerId());
172172
given(this.docker.container().wait(any())).willReturn(ContainerStatus.of(0, null));
173173
assertThatIllegalStateException()
174-
.isThrownBy(() -> createLifecycle("builder-metadata-unsupported-apis.json").execute()).withMessage(
175-
"Detected platform API versions '0.1,0.2' are not included in supported versions '0.3,0.4,0.5,0.6,0.7,0.8'");
174+
.isThrownBy(() -> createLifecycle("builder-metadata-unsupported-apis.json").execute())
175+
.withMessageContaining(
176+
"Detected platform API versions '0.1,0.2' are not included in supported versions");
176177
}
177178

178179
@Test

0 commit comments

Comments
 (0)