diff --git a/distribution/server-x-dist/src/main/content/bin/kc.sh b/distribution/server-x-dist/src/main/content/bin/kc.sh index 55137594c8..2de77f3e60 100644 --- a/distribution/server-x-dist/src/main/content/bin/kc.sh +++ b/distribution/server-x-dist/src/main/content/bin/kc.sh @@ -82,11 +82,11 @@ CLASSPATH_OPTS="$DIRNAME/../lib/quarkus-run.jar" JAVA_RUN_OPTS="$JAVA_OPTS $SERVER_OPTS -cp $CLASSPATH_OPTS io.quarkus.bootstrap.runner.QuarkusEntryPoint ${CONFIG_ARGS#?}" if [[ $CONFIG_ARGS = *"--auto-build"* ]]; then - java -Dkc.config.rebuild-and-exit=true $JAVA_RUN_OPTS + eval java -Dkc.config.rebuild-and-exit=true $JAVA_RUN_OPTS EXIT_CODE=$? if [ $EXIT_CODE != 0 ]; then exit $EXIT_CODE fi fi -exec java ${JAVA_RUN_OPTS} \ No newline at end of file +eval exec java ${JAVA_RUN_OPTS} \ No newline at end of file diff --git a/quarkus/runtime/src/main/java/org/keycloak/cli/Picocli.java b/quarkus/runtime/src/main/java/org/keycloak/cli/Picocli.java index 6348e997cf..657183a9ae 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/cli/Picocli.java +++ b/quarkus/runtime/src/main/java/org/keycloak/cli/Picocli.java @@ -17,6 +17,8 @@ package org.keycloak.cli; +import static java.util.Arrays.asList; +import static org.keycloak.cli.command.AbstractStartCommand.AUTO_BUILD_OPTION; import static org.keycloak.configuration.Configuration.getConfig; import static org.keycloak.configuration.PropertyMappers.isBuildTimeProperty; import static org.keycloak.util.Environment.isDevMode; @@ -35,10 +37,10 @@ import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.function.IntFunction; +import java.util.regex.Pattern; import java.util.stream.Collectors; import org.jboss.logging.Logger; -import org.keycloak.cli.command.AbstractStartCommand; import org.keycloak.cli.command.Build; import org.keycloak.cli.command.Main; import org.keycloak.cli.command.Start; @@ -56,9 +58,12 @@ import picocli.CommandLine; public final class Picocli { private static final Logger logger = Logger.getLogger(Picocli.class); + private static final String ARG_SEPARATOR = ";;"; - private static final String ARG_PREFIX = "--"; + public static final String ARG_PREFIX = "--"; public static final char ARG_KEY_VALUE_SEPARATOR = '='; + public static final Pattern ARG_SPLIT = Pattern.compile(";;"); + public static final Pattern ARG_KEY_VALUE_SPLIT = Pattern.compile("="); private Picocli() { } @@ -99,8 +104,8 @@ public final class Picocli { } private static void runReAugmentationIfNeeded(List cliArgs, CommandLine cmd) { - if (cliArgs.contains(AbstractStartCommand.AUTO_BUILD_OPTION)) { - if (requiresReAugmentation(cliArgs, cmd)) { + if (cliArgs.contains(AUTO_BUILD_OPTION)) { + if (requiresReAugmentation(cmd)) { runReAugmentation(cliArgs, cmd); } @@ -110,18 +115,14 @@ public final class Picocli { } } - private static boolean requiresReAugmentation(List cliArgs, CommandLine cmd) { + private static boolean requiresReAugmentation(CommandLine cmd) { if (hasConfigChanges()) { cmd.getOut().println("Changes detected in configuration. Updating the server image."); - - List suggestedArgs = cliArgs.subList(1, cliArgs.size()); - - suggestedArgs.removeAll(Arrays.asList("--verbose", "-v", "--help", "-h")); - - cmd.getOut().printf("For an optional runtime and bypass this step, please run the '%s' command prior to starting the server:%n%n\t%s config %s%n", + cmd.getOut().printf("For an optional runtime and bypass this step, please run the '%s' command prior to starting the server:%n%n\t%s %s %s%n", Build.NAME, Environment.getCommand(), - String.join(" ", suggestedArgs) + "\n"); + Build.NAME, + String.join(" ", asList(ARG_SPLIT.split(Environment.getConfigArgs()))) + "\n"); return true; } @@ -226,7 +227,7 @@ public final class Picocli { CommandLine.Model.CommandSpec spec = CommandLine.Model.CommandSpec.forAnnotatedObject(new Main()) .name(Environment.getCommand()); - boolean addBuildOptionsToStartCommand = cliArgs.contains(AbstractStartCommand.AUTO_BUILD_OPTION); + boolean addBuildOptionsToStartCommand = cliArgs.contains(AUTO_BUILD_OPTION); addOption(spec, Start.NAME, addBuildOptionsToStartCommand); addOption(spec, StartDev.NAME, true); @@ -241,7 +242,7 @@ public final class Picocli { cmd.getHelpSectionMap().put(SECTION_KEY_COMMAND_LIST, new SubCommandListRenderer()); cmd.setExecutionExceptionHandler(new ExecutionExceptionHandler()); - + return cmd; } @@ -249,6 +250,7 @@ public final class Picocli { StringBuilder options = new StringBuilder(); Iterator iterator = argsList.iterator(); boolean expectValue = false; + List ignoredArgs = asList("--verbose", "-v", "--help", "-h", AUTO_BUILD_OPTION); while (iterator.hasNext()) { String key = iterator.next(); @@ -259,6 +261,10 @@ public final class Picocli { iterator.remove(); } + if (ignoredArgs.contains(key)) { + continue; + } + if (key.startsWith(ARG_PREFIX)) { if (options.length() > 0) { options.append(ARG_SEPARATOR); diff --git a/quarkus/runtime/src/main/java/org/keycloak/configuration/ConfigArgsConfigSource.java b/quarkus/runtime/src/main/java/org/keycloak/configuration/ConfigArgsConfigSource.java index e459006ada..09f8130827 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/configuration/ConfigArgsConfigSource.java +++ b/quarkus/runtime/src/main/java/org/keycloak/configuration/ConfigArgsConfigSource.java @@ -17,6 +17,9 @@ package org.keycloak.configuration; +import static org.keycloak.cli.Picocli.ARG_KEY_VALUE_SPLIT; +import static org.keycloak.cli.Picocli.ARG_PREFIX; +import static org.keycloak.cli.Picocli.ARG_SPLIT; import static org.keycloak.configuration.MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX; import static org.keycloak.configuration.MicroProfileConfigProvider.NS_QUARKUS_PREFIX; @@ -43,9 +46,6 @@ public class ConfigArgsConfigSource extends PropertiesConfigSource { private static final Logger log = Logger.getLogger(ConfigArgsConfigSource.class); - private static final Pattern ARG_SPLIT = Pattern.compile(";;"); - private static final Pattern ARG_KEY_VALUE_SPLIT = Pattern.compile("="); - private static final String ARG_PREFIX = "--"; private static final Pattern DOT_SPLIT = Pattern.compile("\\."); ConfigArgsConfigSource() { diff --git a/quarkus/runtime/src/main/java/org/keycloak/util/Environment.java b/quarkus/runtime/src/main/java/org/keycloak/util/Environment.java index c2ea900d12..c0a69e7d71 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/util/Environment.java +++ b/quarkus/runtime/src/main/java/org/keycloak/util/Environment.java @@ -84,7 +84,7 @@ public final class Environment { } public static String getConfigArgs() { - return System.getProperty(CLI_ARGS); + return System.getProperty(CLI_ARGS, ""); } public static String getProfile() {