Skip to content

Commit

Permalink
Merge pull request #975 from gtroitsk/image-util-class
Browse files Browse the repository at this point in the history
Add ImageUtil class
  • Loading branch information
gtroitsk authored Dec 10, 2023
2 parents 7bd92df + 57f4492 commit ebfabef
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<String, String[]> 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);
});
}

}

0 comments on commit ebfabef

Please sign in to comment.