diff --git a/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftBuild.java b/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftBuild.java index 8956edbf3e03e..32ce09e05fcff 100644 --- a/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftBuild.java +++ b/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftBuild.java @@ -6,7 +6,7 @@ public class OpenshiftBuild implements BooleanSupplier { - private ContainerImageConfig containerImageConfig; + private final ContainerImageConfig containerImageConfig; OpenshiftBuild(ContainerImageConfig containerImageConfig) { this.containerImageConfig = containerImageConfig; diff --git a/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iBuild.java b/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iBuild.java index 9feb35ca3e96c..7ac85ef0ad4e1 100644 --- a/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iBuild.java +++ b/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iBuild.java @@ -6,7 +6,7 @@ public class S2iBuild implements BooleanSupplier { - private ContainerImageConfig containerImageConfig; + private final ContainerImageConfig containerImageConfig; S2iBuild(ContainerImageConfig containerImageConfig) { this.containerImageConfig = containerImageConfig; diff --git a/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/ContainerImageCapabilitiesUtil.java b/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/ContainerImageCapabilitiesUtil.java index d7591e4824036..c07c9b483f242 100644 --- a/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/ContainerImageCapabilitiesUtil.java +++ b/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/ContainerImageCapabilitiesUtil.java @@ -1,6 +1,5 @@ package io.quarkus.container.image.deployment; -import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Optional; @@ -11,14 +10,19 @@ public final class ContainerImageCapabilitiesUtil { - public final static Map CAPABILITY_TO_EXTENSION_NAME = new HashMap<>(); - static { - CAPABILITY_TO_EXTENSION_NAME.put(Capability.CONTAINER_IMAGE_JIB, "quarkus-container-image-jib"); - CAPABILITY_TO_EXTENSION_NAME.put(Capability.CONTAINER_IMAGE_DOCKER, "quarkus-container-image-docker"); - CAPABILITY_TO_EXTENSION_NAME.put(Capability.CONTAINER_IMAGE_S2I, "quarkus-container-image-s2i"); - CAPABILITY_TO_EXTENSION_NAME.put(Capability.CONTAINER_IMAGE_OPENSHIFT, "quarkus-container-image-openshift"); - CAPABILITY_TO_EXTENSION_NAME.put(Capability.CONTAINER_IMAGE_BUILDPACK, "quarkus-container-image-buildpack"); - } + public final static Map CAPABILITY_TO_EXTENSION_NAME = Map.of( + Capability.CONTAINER_IMAGE_JIB, "quarkus-container-image-jib", + Capability.CONTAINER_IMAGE_DOCKER, "quarkus-container-image-docker", + Capability.CONTAINER_IMAGE_S2I, "quarkus-container-image-s2i", + Capability.CONTAINER_IMAGE_OPENSHIFT, "quarkus-container-image-openshift", + Capability.CONTAINER_IMAGE_BUILDPACK, "quarkus-container-image-buildpack"); + + private final static Map CAPABILITY_TO_BUILDER_NAME = Map.of( + Capability.CONTAINER_IMAGE_JIB, "jib", + Capability.CONTAINER_IMAGE_DOCKER, "docker", + Capability.CONTAINER_IMAGE_S2I, "s2i", + Capability.CONTAINER_IMAGE_OPENSHIFT, "openshift", + Capability.CONTAINER_IMAGE_BUILDPACK, "buildpack"); private ContainerImageCapabilitiesUtil() { } @@ -32,16 +36,34 @@ public static Optional getActiveContainerImageCapability(Capabilities ca if (activeContainerImageCapabilities.size() > 1) { throw new IllegalStateException(String.join(" and ", activeContainerImageCapabilities) + " were detected, at most one container-image extension can be present.\n" - + "Either remove the unneeded ones, or select one by adding the property 'quarkus.container-image.builder=' in application.properties or as a system property."); + + "Either remove the unneeded ones, or select one by setting any of the following configuration properties: " + + createBuilderSelectionPropertySuggestion(capabilities)); } return activeContainerImageCapabilities.isEmpty() ? Optional.empty() : Optional.of(activeContainerImageCapabilities.iterator().next()); } + private static StringBuilder createBuilderSelectionPropertySuggestion(Capabilities capabilities) { + StringBuilder suggestion = new StringBuilder(); + boolean isFirst = true; + for (String capability : capabilities.getCapabilities()) { + if (!isContainerImageCapability(capability)) { + continue; + } + if (!isFirst) { + suggestion.append(", "); + } + isFirst = false; + suggestion.append('\'').append("quarkus.container-image.builder=") + .append(CAPABILITY_TO_BUILDER_NAME.get(capability)).append('\''); + } + return suggestion; + } + private static Set getContainerImageCapabilities(Capabilities capabilities) { Set activeContainerImageCapabilities = new HashSet<>(); for (String capability : capabilities.getCapabilities()) { - if (capability.toLowerCase().contains("container.image")) { + if (isContainerImageCapability(capability)) { if (!CAPABILITY_TO_EXTENSION_NAME.containsKey(capability)) { throw new IllegalArgumentException("Unknown container image capability: " + capability); } @@ -50,4 +72,8 @@ private static Set getContainerImageCapabilities(Capabilities capabiliti } return activeContainerImageCapabilities; } + + private static boolean isContainerImageCapability(String capability) { + return capability.toLowerCase().contains("container.image"); + } }