From 3e3db16646f398d4af15001e1b5ef65e3596ab2f Mon Sep 17 00:00:00 2001 From: Valentin Delaye Date: Mon, 23 Feb 2026 14:17:39 +0100 Subject: [PATCH] Add withArtifactType for Index Signed-off-by: Valentin Delaye --- src/main/java/land/oras/Index.java | 10 ++++++++++ src/test/java/land/oras/IndexTest.java | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/main/java/land/oras/Index.java b/src/main/java/land/oras/Index.java index f0cbef31..d4670806 100644 --- a/src/main/java/land/oras/Index.java +++ b/src/main/java/land/oras/Index.java @@ -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 diff --git a/src/test/java/land/oras/IndexTest.java b/src/test/java/land/oras/IndexTest.java index 261f098e..d61c0e3c 100644 --- a/src/test/java/land/oras/IndexTest.java +++ b/src/test/java/land/oras/IndexTest.java @@ -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 =