forked from oras-project/oras-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManifest.java
More file actions
161 lines (144 loc) · 4.15 KB
/
Manifest.java
File metadata and controls
161 lines (144 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package land.oras;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import land.oras.utils.Const;
import land.oras.utils.JsonUtils;
import org.jspecify.annotations.NullUnmarked;
/**
* Class for manifest
*/
@NullUnmarked
public final class Manifest {
private final int schemaVersion;
private final String mediaType;
private final String artifactType;
private final Config config;
private final List<Layer> layers;
private final Map<String, String> annotations;
/**
* Constructor
* @param schemaVersion The schema version
* @param mediaType The media type
* @param config The config
* @param layers The layers
* @param annotations The annotations
*/
private Manifest(
int schemaVersion,
String mediaType,
String artifactType,
Config config,
List<Layer> layers,
Annotations annotations) {
this.schemaVersion = schemaVersion;
this.mediaType = mediaType;
this.artifactType = artifactType;
this.config = config;
this.layers = layers;
this.annotations = Map.copyOf(annotations.manifestAnnotations());
}
/**
* Get the schema version
* @return The schema version
*/
public int getSchemaVersion() {
return schemaVersion;
}
/**
* Get the media type
* @return The media type
*/
public String getMediaType() {
return mediaType;
}
/**
* Get the artifact type
* @return The artifact type
*/
public String getArtifactType() {
return artifactType;
}
/**
* Get the config
* @return The config
*/
public Config getConfig() {
return config;
}
/**
* Get the layers
* @return The layers
*/
public List<Layer> getLayers() {
return Collections.unmodifiableList(layers);
}
/**
* Get the annotations
* @return The annotations
*/
public Map<String, String> getAnnotations() {
if (annotations == null) {
return Map.of();
}
return Collections.unmodifiableMap(annotations);
}
/**
* Return a new manifest with the given artifact type
* @param artifactType The artifact type
* @return The manifest
*/
public Manifest withArtifactType(String artifactType) {
return new Manifest(
schemaVersion, mediaType, artifactType, config, layers, Annotations.ofManifest(annotations));
}
/**
* Return a new manifest with the given layers
* @param layers The layers
* @return The manifest
*/
public Manifest withLayers(List<Layer> layers) {
return new Manifest(
schemaVersion, mediaType, artifactType, config, layers, Annotations.ofManifest(annotations));
}
/**
* Return a new manifest with the given config
* @param config The config
* @return The manifest
*/
public Manifest withConfig(Config config) {
return new Manifest(
schemaVersion, mediaType, artifactType, config, layers, Annotations.ofManifest(annotations));
}
/**
* Return a new manifest with the given annotations
* @param annotations The annotations
* @return The manifest
*/
public Manifest withAnnotations(Map<String, String> annotations) {
return new Manifest(
schemaVersion, mediaType, artifactType, config, layers, Annotations.ofManifest(annotations));
}
/**
* Return the JSON representation of the manifest
* @return The JSON string
*/
public String toJson() {
return JsonUtils.toJson(this);
}
/**
* Create a manifest from a JSON string
* @param json The JSON string
* @return The manifest
*/
public static Manifest fromJson(String json) {
return JsonUtils.fromJson(json, Manifest.class);
}
/**
* Return a copy of an empty manifest
* @return The empty manifest
*/
public static Manifest empty() {
return new Manifest(2, Const.DEFAULT_MANIFEST_MEDIA_TYPE, null, Config.empty(), List.of(), Annotations.empty());
}
}