-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #975 from gtroitsk/image-util-class
Add ImageUtil class
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
quarkus-test-images/src/main/java/io/quarkus/test/utils/ImageUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
|
||
} |