Skip to content

Commit 0ed32cf

Browse files
authored
chore(spawn-docker-jdk): replace Jackson with base-json (#27)
1 parent 27f53a8 commit 0ed32cf

42 files changed

Lines changed: 550 additions & 704 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pom.xml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@
6868

6969
<!-- Module Dependency Versions -->
7070
<assertj.version>3.27.7</assertj.version>
71-
<base.version>0.23.1</base.version>
71+
<base.version>0.24.0</base.version>
7272
<byte-buddy.version>1.18.4</byte-buddy.version>
73-
<codemodel.version>0.21.1</codemodel.version>
74-
<jackson-core.version>2.21.2</jackson-core.version>
73+
<codemodel.version>0.21.2</codemodel.version>
7574
<junit.version>6.0.3</junit.version>
7675
<jakarta-inject.version>2.0.1</jakarta-inject.version>
7776
<mockito.version>5.23.0</mockito.version>
@@ -236,22 +235,19 @@
236235
<version>${codemodel.version}</version>
237236
</dependency>
238237

238+
<!-- Upstream: base.build (extra) -->
239+
<dependency>
240+
<groupId>build.base</groupId>
241+
<artifactId>base-json</artifactId>
242+
<version>${base.version}</version>
243+
</dependency>
244+
239245
<!-- Third-party -->
240246
<dependency>
241247
<groupId>net.bytebuddy</groupId>
242248
<artifactId>byte-buddy</artifactId>
243249
<version>${byte-buddy.version}</version>
244250
</dependency>
245-
<dependency>
246-
<groupId>com.fasterxml.jackson.core</groupId>
247-
<artifactId>jackson-core</artifactId>
248-
<version>${jackson-core.version}</version>
249-
</dependency>
250-
<dependency>
251-
<groupId>com.fasterxml.jackson.core</groupId>
252-
<artifactId>jackson-databind</artifactId>
253-
<version>${jackson-core.version}</version>
254-
</dependency>
255251
<dependency>
256252
<groupId>jakarta.inject</groupId>
257253
<artifactId>jakarta.inject-api</artifactId>

spawn-docker-jdk/pom.xml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,8 @@
7373
</dependency>
7474

7575
<dependency>
76-
<groupId>com.fasterxml.jackson.core</groupId>
77-
<artifactId>jackson-core</artifactId>
78-
</dependency>
79-
80-
<dependency>
81-
<groupId>com.fasterxml.jackson.core</groupId>
82-
<artifactId>jackson-databind</artifactId>
76+
<groupId>build.base</groupId>
77+
<artifactId>base-json</artifactId>
8378
</dependency>
8479

8580
<!-- Test Dependencies -->

spawn-docker-jdk/src/main/java/build/spawn/docker/jdk/AbstractSession.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import build.base.flow.Publicist;
2626
import build.base.flow.Publisher;
2727
import build.base.flow.SubscriberRegistry;
28+
import build.base.json.JsonObject;
2829
import build.base.option.Email;
2930
import build.base.option.Password;
3031
import build.base.option.Username;
@@ -51,7 +52,6 @@
5152
import build.spawn.docker.option.DockerAPIVersion;
5253
import build.spawn.docker.option.DockerRegistry;
5354
import build.spawn.docker.option.IdentityToken;
54-
import com.fasterxml.jackson.databind.ObjectMapper;
5555

5656
import java.nio.charset.StandardCharsets;
5757
import java.nio.file.Path;
@@ -142,9 +142,6 @@ protected AbstractSession(final InjectionFramework injectionFramework,
142142
this.eventSubscriber = new CompletingSubscriber<>();
143143
this.publicist.subscribe(this.eventSubscriber);
144144

145-
// establish an ObjectMapper for working with JSON
146-
final ObjectMapper objectMapper = new ObjectMapper();
147-
148145
// establish the dependency injection context
149146
this.context = injectionFramework
150147
.newContext();
@@ -155,7 +152,6 @@ protected AbstractSession(final InjectionFramework injectionFramework,
155152
this.context.bind(Session.class).to(this);
156153
this.context.bind(AbstractSession.class).to(this);
157154
this.context.bind((Class) getClass()).to(this);
158-
this.context.bind(ObjectMapper.class).to(objectMapper);
159155
this.context.bind(Configuration.class).to(this.configuration);
160156
this.context.bind(Publicist.class).to(this.publicist);
161157
this.context.bind(Publisher.class).to(this.publicist);
@@ -178,23 +174,23 @@ protected AbstractSession(final InjectionFramework injectionFramework,
178174
.to(identityToken);
179175

180176
// establish the Authentication JSON
181-
final var json = objectMapper.createObjectNode();
177+
final var jsonBuilder = JsonObject.builder();
182178

183179
if (identityToken.isEmpty()) {
184180
this.configuration.getOptionalValue(Username.class)
185-
.ifPresent(username -> json.put("username", username));
181+
.ifPresent(username -> jsonBuilder.put("username", username));
186182
this.configuration.getOptionalValue(Password.class)
187-
.ifPresent(password -> json.put("password", password));
183+
.ifPresent(password -> jsonBuilder.put("password", password));
188184
this.configuration.getOptionalValue(Email.class)
189-
.ifPresent(email -> json.put("email", email));
185+
.ifPresent(email -> jsonBuilder.put("email", email));
190186
this.configuration.getOptionalValue(DockerRegistry.class)
191-
.ifPresent(url -> json.put("serveraddress", url.getHost()));
187+
.ifPresent(url -> jsonBuilder.put("serveraddress", url.getHost()));
192188
}
193189
else {
194-
json.put("identitytoken", identityToken.get());
190+
jsonBuilder.put("identitytoken", identityToken.get());
195191
}
196192

197-
xRegistryAuth = Optional.of(json.toString());
193+
xRegistryAuth = Optional.of(jsonBuilder.build().toJsonString());
198194
}
199195
else {
200196
// determine the Configuration-provided IdentityToken
@@ -211,9 +207,11 @@ protected AbstractSession(final InjectionFramework injectionFramework,
211207
xRegistryAuth = Optional.empty();
212208
}
213209
else {
214-
final var json = objectMapper.createObjectNode();
215-
json.put("identitytoken", identityToken.get());
216-
xRegistryAuth = Optional.of(json.toString());
210+
xRegistryAuth = Optional.of(
211+
JsonObject.builder()
212+
.put("identitytoken", identityToken.get())
213+
.build()
214+
.toJsonString());
217215
}
218216
}
219217

spawn-docker-jdk/src/main/java/build/spawn/docker/jdk/command/Authenticate.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* Licensed under the Apache License, Version 2.0 (the "License");
1010
* you may not use this file except in compliance with the License.
1111
* You may obtain a copy of the License at
12-
*
12+
*
1313
* http://www.apache.org/licenses/LICENSE-2.0
14-
*
14+
*
1515
* Unless required by applicable law or agreed to in writing, software
1616
* distributed under the License is distributed on an "AS IS" BASIS,
1717
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,14 +22,15 @@
2222

2323
import build.base.configuration.Configuration;
2424
import build.base.foundation.Strings;
25+
import build.base.json.Json;
26+
import build.base.json.JsonObject;
2527
import build.base.option.Email;
2628
import build.base.option.Password;
2729
import build.base.option.Username;
2830
import build.spawn.docker.Session;
2931
import build.spawn.docker.jdk.HttpTransport;
3032
import build.spawn.docker.option.DockerRegistry;
3133
import build.spawn.docker.option.IdentityToken;
32-
import com.fasterxml.jackson.databind.ObjectMapper;
3334
import jakarta.inject.Inject;
3435

3536
import java.io.IOException;
@@ -45,12 +46,6 @@
4546
public class Authenticate
4647
extends AbstractBlockingCommand<IdentityToken> {
4748

48-
/**
49-
* The {@link ObjectMapper} for parsing json.
50-
*/
51-
@Inject
52-
private ObjectMapper objectMapper;
53-
5449
/**
5550
* The {@link Username} for authentication.
5651
*/
@@ -79,27 +74,27 @@ public class Authenticate
7974
protected HttpTransport.Request createRequest() {
8075

8176
// establish an ObjectNode containing the auth json
82-
final var node = this.objectMapper.createObjectNode();
77+
final var builder = JsonObject.builder()
78+
.put("username", this.username.get())
79+
.put("password", this.password.get())
80+
.put("serveraddress", this.dockerRegistry.get().toString());
8381

84-
node.put("username", this.username.get());
85-
node.put("password", this.password.get());
8682
this.configuration.getOptionalValue(Email.class)
87-
.ifPresent(email -> node.put("email", email));
88-
node.put("serveraddress", this.dockerRegistry.get().toString());
83+
.ifPresent(email -> builder.put("email", email));
8984

9085
return HttpTransport.Request
91-
.post("/auth", node.toString().getBytes(StandardCharsets.UTF_8))
86+
.post("/auth", builder.build().toJsonString().getBytes(StandardCharsets.UTF_8))
9287
.withContentType("application/json");
9388
}
9489

9590
@Override
9691
protected IdentityToken createResult(final HttpTransport.Response response)
9792
throws IOException {
9893

99-
final var body = response.bodyString();
100-
final var json = this.objectMapper.readTree(body);
101-
102-
final var identityToken = json.get("IdentityToken").asText();
94+
final var json = Json.parse(response.bodyString()).asObject();
95+
final var identityToken = json.has("IdentityToken")
96+
? json.getString("IdentityToken")
97+
: "";
10398

10499
return Strings.isEmpty(identityToken)
105100
? IdentityToken.of(this.password.get())

spawn-docker-jdk/src/main/java/build/spawn/docker/jdk/command/BuildImage.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* Licensed under the Apache License, Version 2.0 (the "License");
1010
* you may not use this file except in compliance with the License.
1111
* You may obtain a copy of the License at
12-
*
12+
*
1313
* http://www.apache.org/licenses/LICENSE-2.0
14-
*
14+
*
1515
* Unless required by applicable law or agreed to in writing, software
1616
* distributed under the License is distributed on an "AS IS" BASIS,
1717
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,12 +22,10 @@
2222

2323
import build.base.configuration.Configuration;
2424
import build.base.flow.CompletingSubscriber;
25+
import build.base.json.JsonValue;
2526
import build.spawn.docker.Image;
2627
import build.spawn.docker.jdk.HttpTransport;
2728
import build.spawn.docker.option.ImageName;
28-
import com.fasterxml.jackson.databind.JsonNode;
29-
import com.fasterxml.jackson.databind.ObjectMapper;
30-
import jakarta.inject.Inject;
3129

3230
import java.io.IOException;
3331
import java.nio.file.Files;
@@ -56,12 +54,6 @@ public class BuildImage
5654
*/
5755
private final Configuration configuration;
5856

59-
/**
60-
* The {@link ObjectMapper} for parsing json.
61-
*/
62-
@Inject
63-
private ObjectMapper objectMapper;
64-
6557
/**
6658
* Constructs a {@link BuildImage} {@link Command}.
6759
*
@@ -97,17 +89,17 @@ protected Optional<String> createResult(final HttpTransport.Response response)
9789

9890
// establish the CompletingObserver observe when image ID has been generated
9991
// (we want to capture {"aux":{"ID":"sha256:f65c628a75fe8b3e982165d1a4ceaf521fadab8da2136702c59e184d7be3e243"})
100-
final var completingSubscriber = new CompletingSubscriber<JsonNode>();
92+
final var completingSubscriber = new CompletingSubscriber<JsonValue>();
10193
final var onImageBuilt = completingSubscriber.when(
102-
json -> json.get("aux") != null,
103-
json -> json.get("aux").get("ID").asText());
94+
json -> json.asObject().has("aux"),
95+
json -> json.get("aux").getString("ID"));
10496

10597
final CompletableFuture<?> onSuccess = completingSubscriber.when(
106-
json -> json.get("stream") != null,
107-
json -> json.get("stream").asText().contains("Successful"));
98+
json -> json.asObject().has("stream"),
99+
json -> json.getString("stream").contains("Successful"));
108100

109101
// process the entire InputStream from the Response to essentially wait for the image to be created
110-
final JsonNodeInputStreamProcessor processor = new JsonNodeInputStreamProcessor(this.objectMapper);
102+
final var processor = new JsonNodeInputStreamProcessor();
111103
processor.process(response.bodyStream(), completingSubscriber);
112104

113105
// we've completed building when the ImageId is available and "Successful" has been observed

0 commit comments

Comments
 (0)