@@ -69,17 +69,29 @@ public final class ContainerRef extends Ref<ContainerRef> {
6969 */
7070 private final @ Nullable String digest ;
7171
72+ /**
73+ * Whether the container reference is unqualified without registry
74+ */
75+ private final boolean unqualified ;
76+
7277 /**
7378 * Private constructor
7479 * @param registry The registry where the container is stored.
80+ * @param unqualified Whether the container reference is unqualified without registry
7581 * @param namespace The namespace of the container.
7682 * @param repository The repository where the container is stored
7783 * @param tag The tag of the container.
7884 * @param digest The digest of the container.
7985 */
8086 private ContainerRef (
81- String registry , @ Nullable String namespace , String repository , String tag , @ Nullable String digest ) {
87+ String registry ,
88+ boolean unqualified ,
89+ @ Nullable String namespace ,
90+ String repository ,
91+ String tag ,
92+ @ Nullable String digest ) {
8293 super (tag );
94+ this .unqualified = unqualified ;
8395 this .registry = registry ;
8496 this .namespace = namespace ;
8597 this .repository = repository ;
@@ -94,6 +106,28 @@ public String getRegistry() {
94106 return registry ;
95107 }
96108
109+ /**
110+ * Get the effective registry based on given target
111+ * @param target The target registry
112+ * @return The effective registry
113+ */
114+ public String getEffectiveRegistry (Registry target ) {
115+ if (isUnqualified ()) {
116+ if (target .getRegistry () != null ) {
117+ return target .getRegistry ();
118+ }
119+ }
120+ return registry ;
121+ }
122+
123+ /**
124+ * Whether the container reference is unqualified without registry
125+ * @return True if unqualified
126+ */
127+ public boolean isUnqualified () {
128+ return unqualified ;
129+ }
130+
97131 /**
98132 * Get the full repository name including the namespace if any
99133 * @param registry The registry
@@ -181,7 +215,7 @@ public String getRepository() {
181215
182216 @ Override
183217 public ContainerRef withDigest (String digest ) {
184- return new ContainerRef (registry , namespace , repository , tag , digest );
218+ return new ContainerRef (registry , unqualified , namespace , repository , tag , digest );
185219 }
186220
187221 @ Override
@@ -329,11 +363,13 @@ public static ContainerRef parse(String name) {
329363 String repository = matcher .group (3 );
330364 String tag = matcher .group (4 );
331365 String digest = matcher .group (5 );
366+ boolean unqualified = false ;
332367 if (repository == null ) {
333368 throw new IllegalArgumentException ("You are minimally required to include a <namespace>/<repository>" );
334369 }
335370 if (registry == null ) {
336371 registry = Const .DEFAULT_REGISTRY ;
372+ unqualified = true ;
337373 }
338374 if (tag == null ) {
339375 tag = Const .DEFAULT_TAG ;
@@ -348,7 +384,7 @@ public static ContainerRef parse(String name) {
348384 SupportedAlgorithm .fromDigest (digest );
349385 }
350386
351- return new ContainerRef (registry , namespace , repository , tag , digest );
387+ return new ContainerRef (registry , unqualified , namespace , repository , tag , digest );
352388 }
353389
354390 /**
@@ -357,7 +393,7 @@ public static ContainerRef parse(String name) {
357393 * @return The container reference
358394 */
359395 public ContainerRef forRegistry (String registry ) {
360- return new ContainerRef (registry , namespace , repository , tag , digest );
396+ return new ContainerRef (registry , false , namespace , repository , tag , digest );
361397 }
362398
363399 /**
@@ -368,6 +404,7 @@ public ContainerRef forRegistry(String registry) {
368404 public ContainerRef forRegistry (Registry registry ) {
369405 return new ContainerRef (
370406 registry .getRegistry () != null ? registry .getRegistry () : this .registry ,
407+ false , // not unqualified if registry is set
371408 namespace ,
372409 repository ,
373410 tag ,
0 commit comments