Skip to content

Commit 620fe7a

Browse files
authored
Support for platform fields and ensure all manifests are resolved when getting index (#182)
2 parents b88c6ec + eb40148 commit 620fe7a

File tree

7 files changed

+475
-46
lines changed

7 files changed

+475
-46
lines changed

src/main/java/land/oras/Index.java

+30-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,20 @@ public class Index {
3434
private final String artifactType;
3535
private final List<ManifestDescriptor> manifests;
3636

37-
private Index(int schemaVersion, String mediaType, String artifactType, List<ManifestDescriptor> manifests) {
37+
/**
38+
* The manifest descriptor
39+
*/
40+
private final transient ManifestDescriptor descriptor;
41+
42+
private Index(
43+
int schemaVersion,
44+
String mediaType,
45+
String artifactType,
46+
List<ManifestDescriptor> manifests,
47+
ManifestDescriptor descriptor) {
3848
this.schemaVersion = schemaVersion;
3949
this.mediaType = mediaType;
50+
this.descriptor = descriptor;
4051
this.artifactType = artifactType;
4152
this.manifests = manifests;
4253
}
@@ -73,6 +84,23 @@ public List<ManifestDescriptor> getManifests() {
7384
return manifests;
7485
}
7586

87+
/**
88+
* Get the descriptor
89+
* @return The descriptor
90+
*/
91+
public ManifestDescriptor getDescriptor() {
92+
return descriptor;
93+
}
94+
95+
/**
96+
* Return a new index with the given descriptor
97+
* @param descriptor The descriptor
98+
* @return The manifest
99+
*/
100+
public Index withDescriptor(ManifestDescriptor descriptor) {
101+
return new Index(schemaVersion, mediaType, artifactType, manifests, descriptor);
102+
}
103+
76104
/**
77105
* Return the JSON representation of the index
78106
* @return The JSON string
@@ -96,6 +124,6 @@ public static Index fromJson(String json) {
96124
* @return The index
97125
*/
98126
public static Index fromManifests(List<ManifestDescriptor> descriptors) {
99-
return new Index(2, Const.DEFAULT_INDEX_MEDIA_TYPE, null, descriptors);
127+
return new Index(2, Const.DEFAULT_INDEX_MEDIA_TYPE, null, descriptors, null);
100128
}
101129
}

src/main/java/land/oras/ManifestDescriptor.java

+42-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package land.oras;
2222

23+
import java.util.Map;
2324
import land.oras.utils.JsonUtils;
2425
import org.jspecify.annotations.NullMarked;
2526
import org.jspecify.annotations.Nullable;
@@ -35,18 +36,32 @@ public final class ManifestDescriptor {
3536
private final String digest;
3637
private final long size;
3738

39+
@Nullable
40+
private final Map<String, String> platform;
41+
42+
@Nullable
43+
private final Map<String, String> annotations;
44+
3845
/**
3946
* Constructor
4047
* @param artifactType The optional artifact type
4148
* @param mediaType The media type
4249
* @param digest The digest
4350
* @param size The size
4451
*/
45-
private ManifestDescriptor(@Nullable String artifactType, String mediaType, String digest, long size) {
52+
private ManifestDescriptor(
53+
@Nullable String artifactType,
54+
String mediaType,
55+
String digest,
56+
long size,
57+
@Nullable Map<String, String> platform,
58+
@Nullable Map<String, String> annotations) {
4659
this.artifactType = artifactType;
4760
this.mediaType = mediaType;
4861
this.digest = digest;
4962
this.size = size;
63+
this.platform = platform;
64+
this.annotations = annotations;
5065
}
5166

5267
/**
@@ -81,6 +96,22 @@ public long getSize() {
8196
return size;
8297
}
8398

99+
/**
100+
* Get the platform
101+
* @return The platform
102+
*/
103+
public Map<String, String> getPlatform() {
104+
return platform;
105+
}
106+
107+
/**
108+
* Get the annotations
109+
* @return The annotations
110+
*/
111+
public Map<String, String> getAnnotations() {
112+
return annotations;
113+
}
114+
84115
/**
85116
* Return the JSON representation of the manifest
86117
* @return The JSON string
@@ -89,6 +120,15 @@ public String toJson() {
89120
return JsonUtils.toJson(this);
90121
}
91122

123+
/**
124+
* Create a manifest descriptor from a JSON string
125+
* @param json The JSON string
126+
* @return The manifest
127+
*/
128+
public static ManifestDescriptor fromJson(String json) {
129+
return JsonUtils.fromJson(json, ManifestDescriptor.class);
130+
}
131+
92132
/**
93133
* Return this manifest descriptor as a subject
94134
* @return The subject
@@ -105,6 +145,6 @@ public Subject toSubject() {
105145
* @return The subject
106146
*/
107147
public static ManifestDescriptor of(String mediaType, String digest, long size) {
108-
return new ManifestDescriptor(null, mediaType, digest, size);
148+
return new ManifestDescriptor(null, mediaType, digest, size, null, null);
109149
}
110150
}

0 commit comments

Comments
 (0)