From e23fa4fbbedeb2821d0443321b570d51492aab82 Mon Sep 17 00:00:00 2001 From: Ioannis Canellos Date: Thu, 6 Apr 2023 16:46:43 +0300 Subject: [PATCH] fix: ImageUtil ':' handling.Add getGroup & getReg --- .../image/deployment/util/ImageUtil.java | 42 ++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/util/ImageUtil.java b/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/util/ImageUtil.java index af14fc233445c..0cedb27306351 100644 --- a/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/util/ImageUtil.java +++ b/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/util/ImageUtil.java @@ -15,12 +15,12 @@ private ImageUtil() { * Create an image from the individual parts. * * @param registry The registry. - * @param repository The repository. + * @param repository The group. * @param name The name. * @param tag The tag. * @return The image. */ - public static String getImage(Optional registry, String repository, String name, String tag) { + public static String getImage(Optional registry, String group, String name, String tag) { if (name == null || name.isEmpty()) { throw new IllegalArgumentException("Docker image name cannot be null!"); } @@ -29,12 +29,44 @@ public static String getImage(Optional registry, String repository, Stri } StringBuilder sb = new StringBuilder(); registry.ifPresent(r -> sb.append(r).append(SLASH)); - sb.append(repository).append(SLASH); + sb.append(group).append(SLASH); sb.append(name).append(COLN).append(tag); return sb.toString(); } + /** + * Return the image registry. + * + * @param image The docker image. + * @return The image registry. + */ + public static Optional getRegistry(String image) { + String[] parts = image.split(SLASH); + if (parts.length <= 2) { + //name:tag + //group/name:tag + return Optional.empty(); + } + return Optional.ofNullable(parts[0]); + } + + /** + * Return the image group. + * + * @param image The docker image. + * @return The image group. + */ + public static String getGroup(String image) { + String[] parts = image.split(SLASH); + if (parts.length <= 2) { + //name:tag + //group/name:tag + return parts[0]; + } + return parts[1]; + } + /** * Return the docker image repository. * @@ -72,7 +104,7 @@ public static String getName(String image) { } if (tagged.contains(COLN)) { - return tagged.substring(0, tagged.indexOf(COLN)); + return tagged.substring(0, tagged.lastIndexOf(COLN)); } return tagged; } @@ -85,7 +117,7 @@ public static String getName(String image) { */ public static String getTag(String image) { if (image.contains(COLN)) { - return image.substring(image.indexOf(COLN) + 1); + return image.substring(image.lastIndexOf(COLN) + 1); } return image; }