From dfbc2e5ef311db93d9df58653d04517a2f52e330 Mon Sep 17 00:00:00 2001 From: Aniruddh Laxman Korde Date: Thu, 22 Jan 2026 09:59:26 +0530 Subject: [PATCH 1/4] Refactor: Introduce CopyOptions class to replace boolean flag Signed-off-by: Aniruddh Laxman Korde --- C/oci-layout | 1 + src/main/java/land/oras/CopyOptions.java | 30 ++++++++++++++++++++++++ src/main/java/land/oras/CopyUtils.java | 27 +++++++++++++++++---- 3 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 C/oci-layout create mode 100644 src/main/java/land/oras/CopyOptions.java diff --git a/C/oci-layout b/C/oci-layout new file mode 100644 index 00000000..bda19f87 --- /dev/null +++ b/C/oci-layout @@ -0,0 +1 @@ +{"imageLayoutVersion":"1.0.0","repositories":{"repositories":["C"]}} \ No newline at end of file diff --git a/src/main/java/land/oras/CopyOptions.java b/src/main/java/land/oras/CopyOptions.java new file mode 100644 index 00000000..338081f5 --- /dev/null +++ b/src/main/java/land/oras/CopyOptions.java @@ -0,0 +1,30 @@ +package land.oras; + +/** + * Options for the copy operation. + */ +public class CopyOptions { + + /** + * Whether to copy referrers recursively. + */ + private boolean recursive; + + // TODO: In the future, we will add 'depth' and 'filter' here! + + /** + * Constructor + * @param recursive true to copy referrers, false otherwise + */ + public CopyOptions(boolean recursive) { + this.recursive = recursive; + } + + /** + * Gets the recursive setting. + * @return true if recursive + */ + public boolean isRecursive() { + return recursive; + } +} \ No newline at end of file diff --git a/src/main/java/land/oras/CopyUtils.java b/src/main/java/land/oras/CopyUtils.java index 42f4e3cc..06ebea4a 100644 --- a/src/main/java/land/oras/CopyUtils.java +++ b/src/main/java/land/oras/CopyUtils.java @@ -44,13 +44,32 @@ private CopyUtils() { // Utils class } + /** - * Copy a container from source to target. + * Copy a container from source to target (Old Method - Backward Compatibility). * @param source The source OCI * @param sourceRef The source reference * @param target The target OCI * @param targetRef The target reference * @param recursive Whether to copy referrers recursively + */ + public static , TargetRefType extends Ref<@NonNull TargetRefType>> + void copy( + OCI source, + SourceRefType sourceRef, + OCI target, + TargetRefType targetRef, + boolean recursive) { + // This converts the old boolean into your new class! + copy(source, sourceRef, target, targetRef, new CopyOptions(recursive)); + } + /** + * Copy a container from source to target. + * @param source The source OCI + * @param sourceRef The source reference + * @param target The target OCI + * @param targetRef The target reference + * @param options The copy options * @param The source reference type * @param The target reference type */ @@ -60,7 +79,7 @@ void copy( SourceRefType sourceRef, OCI target, TargetRefType targetRef, - boolean recursive) { + CopyOptions options) { try { @@ -94,12 +113,12 @@ void copy( // Push the manifest target.pushManifest(targetRef.withDigest(tag), manifest); - if (recursive) { + if (options.isRecursive()) { LOG.debug("Recursively copy referrers"); Referrers referrers = source.getReferrers(sourceRef.withDigest(manifestDigest), null); for (ManifestDescriptor referer : referrers.getManifests()) { LOG.info("Copy reference {}", referer.getDigest()); - copy(source, sourceRef.withDigest(referer.getDigest()), target, targetRef, recursive); + copy(source, sourceRef.withDigest(referer.getDigest()), target, targetRef, options); } } From d457ad2504e68165e39b157aacf08c72765f83cd Mon Sep 17 00:00:00 2001 From: Aniruddh Laxman Korde Date: Thu, 22 Jan 2026 12:26:43 +0530 Subject: [PATCH 2/4] style: Apply spotless formatting --- src/main/java/land/oras/CopyOptions.java | 2 +- src/main/java/land/oras/CopyUtils.java | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/land/oras/CopyOptions.java b/src/main/java/land/oras/CopyOptions.java index 338081f5..7b9f7759 100644 --- a/src/main/java/land/oras/CopyOptions.java +++ b/src/main/java/land/oras/CopyOptions.java @@ -27,4 +27,4 @@ public CopyOptions(boolean recursive) { public boolean isRecursive() { return recursive; } -} \ No newline at end of file +} diff --git a/src/main/java/land/oras/CopyUtils.java b/src/main/java/land/oras/CopyUtils.java index 06ebea4a..20460649 100644 --- a/src/main/java/land/oras/CopyUtils.java +++ b/src/main/java/land/oras/CopyUtils.java @@ -44,7 +44,6 @@ private CopyUtils() { // Utils class } - /** * Copy a container from source to target (Old Method - Backward Compatibility). * @param source The source OCI @@ -54,12 +53,12 @@ private CopyUtils() { * @param recursive Whether to copy referrers recursively */ public static , TargetRefType extends Ref<@NonNull TargetRefType>> - void copy( - OCI source, - SourceRefType sourceRef, - OCI target, - TargetRefType targetRef, - boolean recursive) { + void copy( + OCI source, + SourceRefType sourceRef, + OCI target, + TargetRefType targetRef, + boolean recursive) { // This converts the old boolean into your new class! copy(source, sourceRef, target, targetRef, new CopyOptions(recursive)); } From 600663920915744b27cec297f605ff602edc7452 Mon Sep 17 00:00:00 2001 From: Aniruddh Laxman Korde Date: Thu, 22 Jan 2026 12:45:35 +0530 Subject: [PATCH 3/4] chore: remove accidental file --- C/oci-layout | 1 - 1 file changed, 1 deletion(-) delete mode 100644 C/oci-layout diff --git a/C/oci-layout b/C/oci-layout deleted file mode 100644 index bda19f87..00000000 --- a/C/oci-layout +++ /dev/null @@ -1 +0,0 @@ -{"imageLayoutVersion":"1.0.0","repositories":{"repositories":["C"]}} \ No newline at end of file From b50579ba7b5a3cc73d5a8f322f8f2e3758d8666c Mon Sep 17 00:00:00 2001 From: Aniruddh Laxman Korde Date: Thu, 22 Jan 2026 14:29:57 +0530 Subject: [PATCH 4/4] refactor: convert CopyOptions to record with builder --- src/main/java/land/oras/CopyOptions.java | 63 +++++++++++++++++------- 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/src/main/java/land/oras/CopyOptions.java b/src/main/java/land/oras/CopyOptions.java index 7b9f7759..1fc93055 100644 --- a/src/main/java/land/oras/CopyOptions.java +++ b/src/main/java/land/oras/CopyOptions.java @@ -1,30 +1,57 @@ +/* + * Copyright The ORAS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package land.oras; /** - * Options for the copy operation. + * Options for copy operations. + * + * @param recursive true to recursively copy artifacts */ -public class CopyOptions { +public record CopyOptions(boolean recursive) { /** - * Whether to copy referrers recursively. + * Creates a new builder for CopyOptions. + * @return a new builder */ - private boolean recursive; - - // TODO: In the future, we will add 'depth' and 'filter' here! - - /** - * Constructor - * @param recursive true to copy referrers, false otherwise - */ - public CopyOptions(boolean recursive) { - this.recursive = recursive; + public static Builder builder() { + return new Builder(); } /** - * Gets the recursive setting. - * @return true if recursive + * Builder for CopyOptions. */ - public boolean isRecursive() { - return recursive; + public static class Builder { + private boolean recursive; + + /** + * Sets whether to recursively copy artifacts. + * @param recursive true to recursively copy + * @return this builder + */ + public Builder recursive(boolean recursive) { + this.recursive = recursive; + return this; + } + + /** + * Builds the CopyOptions. + * @return the CopyOptions + */ + public CopyOptions build() { + return new CopyOptions(recursive); + } } -} +} \ No newline at end of file