From 57f4492c45f386f28af93de4357c44630d5bc133 Mon Sep 17 00:00:00 2001 From: Georgii Troitskii Date: Thu, 7 Dec 2023 17:23:34 +0100 Subject: [PATCH] Add ImageUtil class Retrieves image name and version from Maven property --- .../java/io/quarkus/test/utils/ImageUtil.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 quarkus-test-images/src/main/java/io/quarkus/test/utils/ImageUtil.java diff --git a/quarkus-test-images/src/main/java/io/quarkus/test/utils/ImageUtil.java b/quarkus-test-images/src/main/java/io/quarkus/test/utils/ImageUtil.java new file mode 100644 index 000000000..4cba0a698 --- /dev/null +++ b/quarkus-test-images/src/main/java/io/quarkus/test/utils/ImageUtil.java @@ -0,0 +1,36 @@ +package io.quarkus.test.utils; + +import java.util.HashMap; +import java.util.Map; + +public final class ImageUtil { + + private static final String COLON = ":"; + private static final Map PROPERTY_TO_IMAGE = new HashMap<>(); + + private ImageUtil() { + // util class + } + + public static String getImageVersion(String imageProperty) { + return getImage(imageProperty)[1]; + } + + public static String getImageName(String imageProperty) { + return getImage(imageProperty)[0]; + } + + private static String[] getImage(String imageProperty) { + return PROPERTY_TO_IMAGE.computeIfAbsent(imageProperty, ip -> { + final String image = System.getProperty(imageProperty); + if (image == null) { + throw new IllegalStateException(String.format("System property '%s' is missing.", imageProperty)); + } + if (!image.contains(COLON)) { + throw new IllegalStateException(String.format("'%s' is not valid Docker image", image)); + } + return image.split(COLON); + }); + } + +}