Skip to content

Commit 0cb31b1

Browse files
committed
Update JSON definitions and parsing
This makes an update to accept the new definitions that are coming from the v3 API, and also adjusts the lifetime of JSON parsers to close them more promptly.
1 parent c239699 commit 0cb31b1

File tree

2 files changed

+55
-33
lines changed

2 files changed

+55
-33
lines changed

net.adoptopenjdk.v3.vanilla/src/main/java/net/adoptopenjdk/v3/vanilla/internal/AOV3AST.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public static final class AOV3ListBinaryAssetViewJSON implements AOV3ASTMemberTy
102102

103103
@JsonProperty(value = "release_name", required = true)
104104
String releaseName;
105+
106+
@JsonProperty(value = "version", required = false)
107+
AOV3ReleaseVersionJSON versionData;
105108
}
106109

107110
@JsonDeserialize

net.adoptopenjdk.v3.vanilla/src/main/java/net/adoptopenjdk/v3/vanilla/internal/AOV3ResponseParser.java

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@
4848
import java.util.stream.Collectors;
4949
import java.util.stream.Stream;
5050

51+
import static net.adoptopenjdk.v3.vanilla.internal.AOV3AST.AOV3AvailableReleasesJSON;
52+
import static net.adoptopenjdk.v3.vanilla.internal.AOV3AST.AOV3BinaryJSON;
53+
import static net.adoptopenjdk.v3.vanilla.internal.AOV3AST.AOV3InstallerJSON;
54+
import static net.adoptopenjdk.v3.vanilla.internal.AOV3AST.AOV3ListBinaryAssetViewJSON;
55+
import static net.adoptopenjdk.v3.vanilla.internal.AOV3AST.AOV3PackageJSON;
56+
import static net.adoptopenjdk.v3.vanilla.internal.AOV3AST.AOV3ReleaseJSON;
57+
import static net.adoptopenjdk.v3.vanilla.internal.AOV3AST.AOV3ReleaseNamesJSON;
58+
import static net.adoptopenjdk.v3.vanilla.internal.AOV3AST.AOV3ReleaseVersionJSON;
59+
import static net.adoptopenjdk.v3.vanilla.internal.AOV3AST.AOV3ReleaseVersionsJSON;
60+
import static net.adoptopenjdk.v3.vanilla.internal.AOV3AST.AOV3SourceJSON;
61+
5162
public final class AOV3ResponseParser implements AOV3ResponseParserType
5263
{
5364
private static final Logger LOG =
@@ -75,7 +86,7 @@ public AOV3ResponseParser(
7586
}
7687

7788
private static AOV3Binary toBinary(
78-
final AOV3AST.AOV3BinaryJSON binary)
89+
final AOV3BinaryJSON binary)
7990
{
8091
final var architecture =
8192
AOV3Architecture.of(
@@ -134,7 +145,7 @@ private static AOV3Binary toBinary(
134145
}
135146

136147
private static AOV3Installer toInstaller(
137-
final AOV3AST.AOV3InstallerJSON installer)
148+
final AOV3InstallerJSON installer)
138149
{
139150
final var checksum =
140151
Optional.ofNullable(installer.checksum);
@@ -165,7 +176,7 @@ private static AOV3Installer toInstaller(
165176
}
166177

167178
private static AOV3Package toPackage(
168-
final AOV3AST.AOV3PackageJSON package_)
179+
final AOV3PackageJSON package_)
169180
{
170181
final var checksum =
171182
Optional.ofNullable(package_.checksum);
@@ -194,7 +205,7 @@ private static AOV3Package toPackage(
194205
}
195206

196207
private static AOV3VersionData toVersionData(
197-
final AOV3AST.AOV3ReleaseVersionJSON versionData)
208+
final AOV3ReleaseVersionJSON versionData)
198209
{
199210
return AOV3VersionData.builder()
200211
.setAdoptBuildNumber(versionData.adoptBuildNumber)
@@ -222,7 +233,7 @@ private static OffsetDateTime toOffsetDateTime(
222233
}
223234

224235
private static AOV3Source toSource(
225-
final AOV3AST.AOV3SourceJSON source)
236+
final AOV3SourceJSON source)
226237
{
227238
return AOV3Source.builder()
228239
.setLink(source.link)
@@ -232,7 +243,7 @@ private static AOV3Source toSource(
232243
}
233244

234245
private AOV3Release toRelease(
235-
final AOV3AST.AOV3ReleaseJSON release)
246+
final AOV3ReleaseJSON release)
236247
{
237248
final var builder = AOV3Release.builder();
238249

@@ -296,17 +307,18 @@ private AOV3Release toRelease(
296307
public AOV3AvailableReleases parseAvailableReleases()
297308
throws AOV3ExceptionParseFailed
298309
{
299-
try {
300-
final AOV3AST.AOV3AvailableReleasesJSON ast =
301-
this.objectMapper.readerFor(AOV3AST.AOV3AvailableReleasesJSON.class)
302-
.readValue(this.stream);
310+
final var factory = this.objectMapper.getFactory();
311+
try (final var parser = factory.createParser(this.stream)) {
312+
final var ast =
313+
this.objectMapper.readValue(parser, AOV3AvailableReleasesJSON.class);
303314

304315
return AOV3AvailableReleases.builder()
305316
.addAllAvailableLTSReleases(ast.availableLTSReleases)
306317
.addAllAvailableReleases(ast.availableReleases)
307318
.setMostRecentFeatureRelease(ast.mostRecentFeatureRelease)
308319
.setMostRecentLTSRelease(ast.mostRecentLTS)
309320
.build();
321+
310322
} catch (final IOException e) {
311323
throw new AOV3ExceptionParseFailed(e);
312324
}
@@ -316,11 +328,10 @@ public AOV3AvailableReleases parseAvailableReleases()
316328
public List<String> parseReleaseNames()
317329
throws AOV3ExceptionParseFailed
318330
{
319-
try {
320-
final AOV3AST.AOV3ReleaseNamesJSON ast =
321-
this.objectMapper.readerFor(AOV3AST.AOV3ReleaseNamesJSON.class)
322-
.readValue(this.stream);
323-
331+
final var factory = this.objectMapper.getFactory();
332+
try (final var parser = factory.createParser(this.stream)) {
333+
final var ast =
334+
this.objectMapper.readValue(parser, AOV3ReleaseNamesJSON.class);
324335
return List.copyOf(ast.releases);
325336
} catch (final IOException e) {
326337
throw new AOV3ExceptionParseFailed(e);
@@ -331,10 +342,10 @@ public List<String> parseReleaseNames()
331342
public List<AOV3VersionData> parseReleaseVersions()
332343
throws AOV3ExceptionParseFailed
333344
{
334-
try {
335-
final AOV3AST.AOV3ReleaseVersionsJSON ast =
336-
this.objectMapper.readerFor(AOV3AST.AOV3ReleaseVersionsJSON.class)
337-
.readValue(this.stream);
345+
final var factory = this.objectMapper.getFactory();
346+
try (final var parser = factory.createParser(this.stream)) {
347+
final AOV3ReleaseVersionsJSON ast =
348+
this.objectMapper.readValue(parser, AOV3ReleaseVersionsJSON.class);
338349

339350
return ast.versions.stream()
340351
.flatMap(this::tryToVersionData)
@@ -345,7 +356,7 @@ public List<AOV3VersionData> parseReleaseVersions()
345356
}
346357

347358
private Stream<? extends AOV3VersionData> tryToVersionData(
348-
final AOV3AST.AOV3ReleaseVersionJSON version)
359+
final AOV3ReleaseVersionJSON version)
349360
{
350361
try {
351362
return Stream.of(toVersionData(version));
@@ -367,11 +378,15 @@ private Stream<? extends AOV3VersionData> tryToVersionData(
367378
public List<AOV3Release> parseAssetsForRelease()
368379
throws AOV3ExceptionParseFailed
369380
{
370-
try {
371-
final List<AOV3AST.AOV3ReleaseJSON> ast =
372-
this.objectMapper.readerFor(new TypeReference<List<AOV3AST.AOV3ReleaseJSON>>()
373-
{
374-
}).readValue(this.stream);
381+
final var factory = this.objectMapper.getFactory();
382+
try (final var parser = factory.createParser(this.stream)) {
383+
final TypeReference<List<AOV3ReleaseJSON>> typeReference =
384+
new TypeReference<>()
385+
{
386+
};
387+
388+
final List<AOV3ReleaseJSON> ast =
389+
this.objectMapper.readValue(parser, typeReference);
375390

376391
return ast.stream()
377392
.flatMap(this::tryToRelease)
@@ -385,11 +400,15 @@ public List<AOV3Release> parseAssetsForRelease()
385400
public List<AOV3ListBinaryAssetView> parseAssetsForLatest()
386401
throws AOV3ExceptionParseFailed
387402
{
388-
try {
389-
final List<AOV3AST.AOV3ListBinaryAssetViewJSON> ast =
390-
this.objectMapper.readerFor(new TypeReference<List<AOV3AST.AOV3ListBinaryAssetViewJSON>>()
391-
{
392-
}).readValue(this.stream);
403+
final var factory = this.objectMapper.getFactory();
404+
try (final var parser = factory.createParser(this.stream)) {
405+
final TypeReference<List<AOV3ListBinaryAssetViewJSON>> typeReference =
406+
new TypeReference<>()
407+
{
408+
};
409+
410+
final List<AOV3ListBinaryAssetViewJSON> ast =
411+
this.objectMapper.readValue(parser, typeReference);
393412

394413
return ast.stream()
395414
.flatMap(this::tryToListBinaryAssetView)
@@ -400,7 +419,7 @@ public List<AOV3ListBinaryAssetView> parseAssetsForLatest()
400419
}
401420

402421
private Stream<? extends AOV3ListBinaryAssetView> tryToListBinaryAssetView(
403-
final AOV3AST.AOV3ListBinaryAssetViewJSON view)
422+
final AOV3ListBinaryAssetViewJSON view)
404423
{
405424
try {
406425
return Stream.of(toListBinaryAssetView(view));
@@ -418,7 +437,7 @@ private Stream<? extends AOV3ListBinaryAssetView> tryToListBinaryAssetView(
418437
}
419438

420439
private static AOV3ListBinaryAssetView toListBinaryAssetView(
421-
final AOV3AST.AOV3ListBinaryAssetViewJSON view)
440+
final AOV3ListBinaryAssetViewJSON view)
422441
{
423442
final var builder = AOV3ListBinaryAssetView.builder();
424443

@@ -431,7 +450,7 @@ private static AOV3ListBinaryAssetView toListBinaryAssetView(
431450
}
432451

433452
private Stream<? extends AOV3Release> tryToRelease(
434-
final AOV3AST.AOV3ReleaseJSON release)
453+
final AOV3ReleaseJSON release)
435454
{
436455
try {
437456
return Stream.of(this.toRelease(release));

0 commit comments

Comments
 (0)