Skip to content

Commit 9e39b99

Browse files
committed
Add "lifecycle" property to v2 and v3 buildpacks
1 parent 008e8c2 commit 9e39b99

File tree

10 files changed

+114
-0
lines changed

10 files changed

+114
-0
lines changed

cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/buildpacks/ReactorBuildpacksTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.nio.charset.Charset;
3131
import java.time.Duration;
3232
import java.util.Collections;
33+
import org.cloudfoundry.client.v3.LifecycleType;
3334
import org.cloudfoundry.client.v3.Link;
3435
import org.cloudfoundry.client.v3.Metadata;
3536
import org.cloudfoundry.client.v3.Pagination;
@@ -99,6 +100,7 @@ void create() {
99100
.position(42)
100101
.enabled(true)
101102
.locked(false)
103+
.lifecycle(LifecycleType.BUILDPACK)
102104
.metadata(
103105
Metadata.builder()
104106
.annotations(Collections.emptyMap())
@@ -179,6 +181,7 @@ void get() {
179181
.position(42)
180182
.enabled(true)
181183
.locked(false)
184+
.lifecycle(LifecycleType.BUILDPACK)
182185
.metadata(
183186
Metadata.builder()
184187
.annotations(Collections.emptyMap())
@@ -250,6 +253,7 @@ void list() {
250253
.position(1)
251254
.enabled(true)
252255
.locked(false)
256+
.lifecycle(LifecycleType.BUILDPACK)
253257
.metadata(
254258
Metadata.builder()
255259
.annotations(Collections.emptyMap())
@@ -315,6 +319,7 @@ void update() {
315319
.position(42)
316320
.enabled(true)
317321
.locked(false)
322+
.lifecycle(LifecycleType.BUILDPACK)
318323
.metadata(
319324
Metadata.builder()
320325
.annotations(Collections.emptyMap())
@@ -407,6 +412,7 @@ void upload() throws IOException {
407412
.position(42)
408413
.enabled(true)
409414
.locked(false)
415+
.lifecycle(LifecycleType.BUILDPACK)
410416
.metadata(
411417
Metadata.builder()
412418
.annotations(Collections.emptyMap())

cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/buildpacks/GET_response.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"position": 1,
2626
"enabled": true,
2727
"locked": false,
28+
"lifecycle": "buildpack",
2829
"metadata": {
2930
"labels": {},
3031
"annotations": {}

cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/buildpacks/GET_{id}_response.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"position": 42,
1010
"enabled": true,
1111
"locked": false,
12+
"lifecycle": "buildpack",
1213
"metadata": {
1314
"labels": {},
1415
"annotations": {}

cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/buildpacks/PATCH_{id}_response.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"position": 42,
1010
"enabled": true,
1111
"locked": false,
12+
"lifecycle": "buildpack",
1213
"metadata": {
1314
"labels": {},
1415
"annotations": {}

cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/buildpacks/POST_response.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"position": 42,
1010
"enabled": true,
1111
"locked": false,
12+
"lifecycle": "buildpack",
1213
"metadata": {
1314
"labels": {},
1415
"annotations": {}

cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/buildpacks/POST_{id}_upload_response.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"position": 42,
1010
"enabled": true,
1111
"locked": false,
12+
"lifecycle": "buildpack",
1213
"metadata": {
1314
"labels": {},
1415
"annotations": {}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2013-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+
* http://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.cloudfoundry.client.v2.buildpacks;
18+
19+
import com.fasterxml.jackson.annotation.JsonCreator;
20+
import com.fasterxml.jackson.annotation.JsonValue;
21+
22+
/**
23+
* The lifecycle type
24+
*/
25+
public enum LifecycleType {
26+
BUILDPACK("buildpack"),
27+
28+
DOCKER("docker"),
29+
30+
CNB("cnb");
31+
32+
private final String value;
33+
34+
private LifecycleType(String value) {
35+
this.value = value;
36+
}
37+
38+
@JsonCreator
39+
public static LifecycleType from(String s) {
40+
switch (s.toLowerCase()) {
41+
case "buildpack":
42+
return BUILDPACK;
43+
case "docker":
44+
return DOCKER;
45+
case "cnb":
46+
return CNB;
47+
default:
48+
throw new IllegalArgumentException(String.format("Unknown lifecycle type: %s", s));
49+
}
50+
}
51+
52+
@JsonValue
53+
public String getValue() {
54+
return this.value;
55+
}
56+
57+
@Override
58+
public String toString() {
59+
return getValue();
60+
}
61+
}

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v2/buildpacks/_BuildpackEntity.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,11 @@ abstract class _BuildpackEntity {
7070
@Nullable
7171
abstract String getStack();
7272

73+
/**
74+
* The lifecycle
75+
*/
76+
@JsonProperty("lifecycle")
77+
@Nullable
78+
abstract LifecycleType getLifecycle();
79+
7380
}

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/buildpacks/Buildpack.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.fasterxml.jackson.annotation.JsonProperty;
2020
import org.cloudfoundry.Nullable;
21+
import org.cloudfoundry.client.v3.LifecycleType;
2122
import org.cloudfoundry.client.v3.Metadata;
2223
import org.cloudfoundry.client.v3.Resource;
2324

@@ -76,4 +77,11 @@ public abstract class Buildpack extends Resource {
7677
*/
7778
@JsonProperty("state")
7879
public abstract BuildpackState getState();
80+
81+
/**
82+
* The lifecycle
83+
*/
84+
@JsonProperty("lifecycle")
85+
@Nullable
86+
public abstract LifecycleType getLifecycle();
7987
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.cloudfoundry.client.v2.buildpacks;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import com.fasterxml.jackson.core.JsonProcessingException;
6+
import com.fasterxml.jackson.databind.ObjectMapper;
7+
import org.junit.jupiter.api.Test;
8+
9+
class BuildpackEntityTest {
10+
@Test
11+
void jsonSerialization() throws JsonProcessingException {
12+
ObjectMapper mapper = new ObjectMapper();
13+
BuildpackEntity originalBuildpack =
14+
BuildpackEntity.builder()
15+
.enabled(false)
16+
.locked(true)
17+
.name("test-buildpack")
18+
.position(42)
19+
.lifecycle(LifecycleType.BUILDPACK)
20+
.build();
21+
22+
String serialized = mapper.writeValueAsString(originalBuildpack);
23+
BuildpackEntity deserialized = mapper.readValue(serialized, BuildpackEntity.class);
24+
25+
assertThat(deserialized).isEqualTo(originalBuildpack);
26+
}
27+
}

0 commit comments

Comments
 (0)