Add unqualified flag on container ref by jonesbusy · Pull Request #397 · oras-project/oras-java
Expand Up
@@ -69,17 +69,29 @@ public final class ContainerRef extends Ref<ContainerRef> {
*/
private final @Nullable String digest;
/** * Whether the container reference is unqualified without registry */ private final boolean unqualified;
/** * Private constructor * @param registry The registry where the container is stored. * @param unqualified Whether the container reference is unqualified without registry * @param namespace The namespace of the container. * @param repository The repository where the container is stored * @param tag The tag of the container. * @param digest The digest of the container. */ private ContainerRef( String registry, @Nullable String namespace, String repository, String tag, @Nullable String digest) { String registry, boolean unqualified, @Nullable String namespace, String repository, String tag, @Nullable String digest) { super(tag); this.unqualified = unqualified; this.registry = registry; this.namespace = namespace; this.repository = repository; Expand All @@ -94,6 +106,28 @@ public String getRegistry() { return registry; }
/** * Get the effective registry based on given target * @param target The target registry * @return The effective registry */ public String getEffectiveRegistry(Registry target) { if (isUnqualified()) { if (target.getRegistry() != null) { return target.getRegistry(); } } return registry; }
/** * Whether the container reference is unqualified without registry * @return True if unqualified */ public boolean isUnqualified() { return unqualified; }
/** * Get the full repository name including the namespace if any * @param registry The registry Expand Down Expand Up @@ -181,7 +215,7 @@ public String getRepository() {
@Override public ContainerRef withDigest(String digest) { return new ContainerRef(registry, namespace, repository, tag, digest); return new ContainerRef(registry, unqualified, namespace, repository, tag, digest); }
@Override Expand Down Expand Up @@ -329,11 +363,13 @@ public static ContainerRef parse(String name) { String repository = matcher.group(3); String tag = matcher.group(4); String digest = matcher.group(5); boolean unqualified = false; if (repository == null) { throw new IllegalArgumentException("You are minimally required to include a <namespace>/<repository>"); } if (registry == null) { registry = Const.DEFAULT_REGISTRY; unqualified = true; } if (tag == null) { tag = Const.DEFAULT_TAG; Expand All @@ -348,7 +384,7 @@ public static ContainerRef parse(String name) { SupportedAlgorithm.fromDigest(digest); }
return new ContainerRef(registry, namespace, repository, tag, digest); return new ContainerRef(registry, unqualified, namespace, repository, tag, digest); }
/** Expand All @@ -357,7 +393,7 @@ public static ContainerRef parse(String name) { * @return The container reference */ public ContainerRef forRegistry(String registry) { return new ContainerRef(registry, namespace, repository, tag, digest); return new ContainerRef(registry, false, namespace, repository, tag, digest); }
/** Expand All @@ -368,6 +404,7 @@ public ContainerRef forRegistry(String registry) { public ContainerRef forRegistry(Registry registry) { return new ContainerRef( registry.getRegistry() != null ? registry.getRegistry() : this.registry, false, // not unqualified if registry is set namespace, repository, tag, Expand Down
/** * Whether the container reference is unqualified without registry */ private final boolean unqualified;
/** * Private constructor * @param registry The registry where the container is stored. * @param unqualified Whether the container reference is unqualified without registry * @param namespace The namespace of the container. * @param repository The repository where the container is stored * @param tag The tag of the container. * @param digest The digest of the container. */ private ContainerRef( String registry, @Nullable String namespace, String repository, String tag, @Nullable String digest) { String registry, boolean unqualified, @Nullable String namespace, String repository, String tag, @Nullable String digest) { super(tag); this.unqualified = unqualified; this.registry = registry; this.namespace = namespace; this.repository = repository; Expand All @@ -94,6 +106,28 @@ public String getRegistry() { return registry; }
/** * Get the effective registry based on given target * @param target The target registry * @return The effective registry */ public String getEffectiveRegistry(Registry target) { if (isUnqualified()) { if (target.getRegistry() != null) { return target.getRegistry(); } } return registry; }
/** * Whether the container reference is unqualified without registry * @return True if unqualified */ public boolean isUnqualified() { return unqualified; }
/** * Get the full repository name including the namespace if any * @param registry The registry Expand Down Expand Up @@ -181,7 +215,7 @@ public String getRepository() {
@Override public ContainerRef withDigest(String digest) { return new ContainerRef(registry, namespace, repository, tag, digest); return new ContainerRef(registry, unqualified, namespace, repository, tag, digest); }
@Override Expand Down Expand Up @@ -329,11 +363,13 @@ public static ContainerRef parse(String name) { String repository = matcher.group(3); String tag = matcher.group(4); String digest = matcher.group(5); boolean unqualified = false; if (repository == null) { throw new IllegalArgumentException("You are minimally required to include a <namespace>/<repository>"); } if (registry == null) { registry = Const.DEFAULT_REGISTRY; unqualified = true; } if (tag == null) { tag = Const.DEFAULT_TAG; Expand All @@ -348,7 +384,7 @@ public static ContainerRef parse(String name) { SupportedAlgorithm.fromDigest(digest); }
return new ContainerRef(registry, namespace, repository, tag, digest); return new ContainerRef(registry, unqualified, namespace, repository, tag, digest); }
/** Expand All @@ -357,7 +393,7 @@ public static ContainerRef parse(String name) { * @return The container reference */ public ContainerRef forRegistry(String registry) { return new ContainerRef(registry, namespace, repository, tag, digest); return new ContainerRef(registry, false, namespace, repository, tag, digest); }
/** Expand All @@ -368,6 +404,7 @@ public ContainerRef forRegistry(String registry) { public ContainerRef forRegistry(Registry registry) { return new ContainerRef( registry.getRegistry() != null ? registry.getRegistry() : this.registry, false, // not unqualified if registry is set namespace, repository, tag, Expand Down