Add `withArtifactType` for Index by jonesbusy · Pull Request #590 · oras-project/oras-java

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add withArtifactType for Index #590

Changes from all commits

Commits

File filter

Filter by extension

Conversations

Failed to load comments.

Loading

Jump to

Jump to file

Failed to load files.

Loading

Diff view
Diff view

10 changes: 10 additions & 0 deletions src/main/java/land/oras/Index.java

Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ public ManifestDescriptor getDescriptor() {
return null;
}

/**
* Return a new index with the given artifact type
* @param artifactType The artifact type
* @return The index
*/
public Index withArtifactType(String artifactType) {
return new Index(
schemaVersion, mediaType, artifactType, manifests, annotations, subject, descriptor, registry, json);
}

/**
* Return a new index with the given descriptor
* @param descriptor The descriptor
Expand Down

12 changes: 12 additions & 0 deletions src/test/java/land/oras/IndexTest.java

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ void shouldReadAndWriteIndex() {
result);
}

@Test
void shouldAddArtifactType() {
Index index = Index.fromManifests(List.of());
index = index.withArtifactType("application/vnd.opentofu.provider");
assertNotNull(index.getArtifactType());
assertEquals(
"application/vnd.opentofu.provider", index.getArtifactType().getMediaType());
assertEquals(
"{\"schemaVersion\":2,\"mediaType\":\"application/vnd.oci.image.index.v1+json\",\"artifactType\":\"application/vnd.opentofu.provider\",\"manifests\":[]}",
index.toJson());
}

@Test
void shouldReadAndWriteIndexWithAnnotations() {
String json =
Expand Down