[KEYCLOAK-19459] - Supporting options with spaces
This commit is contained in:
parent
fa1544a25e
commit
82e4f9a314
4 changed files with 26 additions and 20 deletions
|
@ -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#?}"
|
JAVA_RUN_OPTS="$JAVA_OPTS $SERVER_OPTS -cp $CLASSPATH_OPTS io.quarkus.bootstrap.runner.QuarkusEntryPoint ${CONFIG_ARGS#?}"
|
||||||
|
|
||||||
if [[ $CONFIG_ARGS = *"--auto-build"* ]]; then
|
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=$?
|
EXIT_CODE=$?
|
||||||
if [ $EXIT_CODE != 0 ]; then
|
if [ $EXIT_CODE != 0 ]; then
|
||||||
exit $EXIT_CODE
|
exit $EXIT_CODE
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec java ${JAVA_RUN_OPTS}
|
eval exec java ${JAVA_RUN_OPTS}
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
package org.keycloak.cli;
|
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.Configuration.getConfig;
|
||||||
import static org.keycloak.configuration.PropertyMappers.isBuildTimeProperty;
|
import static org.keycloak.configuration.PropertyMappers.isBuildTimeProperty;
|
||||||
import static org.keycloak.util.Environment.isDevMode;
|
import static org.keycloak.util.Environment.isDevMode;
|
||||||
|
@ -35,10 +37,10 @@ import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.IntFunction;
|
import java.util.function.IntFunction;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
import org.keycloak.cli.command.AbstractStartCommand;
|
|
||||||
import org.keycloak.cli.command.Build;
|
import org.keycloak.cli.command.Build;
|
||||||
import org.keycloak.cli.command.Main;
|
import org.keycloak.cli.command.Main;
|
||||||
import org.keycloak.cli.command.Start;
|
import org.keycloak.cli.command.Start;
|
||||||
|
@ -56,9 +58,12 @@ import picocli.CommandLine;
|
||||||
public final class Picocli {
|
public final class Picocli {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(Picocli.class);
|
private static final Logger logger = Logger.getLogger(Picocli.class);
|
||||||
|
|
||||||
private static final String ARG_SEPARATOR = ";;";
|
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 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() {
|
private Picocli() {
|
||||||
}
|
}
|
||||||
|
@ -99,8 +104,8 @@ public final class Picocli {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void runReAugmentationIfNeeded(List<String> cliArgs, CommandLine cmd) {
|
private static void runReAugmentationIfNeeded(List<String> cliArgs, CommandLine cmd) {
|
||||||
if (cliArgs.contains(AbstractStartCommand.AUTO_BUILD_OPTION)) {
|
if (cliArgs.contains(AUTO_BUILD_OPTION)) {
|
||||||
if (requiresReAugmentation(cliArgs, cmd)) {
|
if (requiresReAugmentation(cmd)) {
|
||||||
runReAugmentation(cliArgs, cmd);
|
runReAugmentation(cliArgs, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,18 +115,14 @@ public final class Picocli {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean requiresReAugmentation(List<String> cliArgs, CommandLine cmd) {
|
private static boolean requiresReAugmentation(CommandLine cmd) {
|
||||||
if (hasConfigChanges()) {
|
if (hasConfigChanges()) {
|
||||||
cmd.getOut().println("Changes detected in configuration. Updating the server image.");
|
cmd.getOut().println("Changes detected in configuration. Updating the server image.");
|
||||||
|
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",
|
||||||
List<String> 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",
|
|
||||||
Build.NAME,
|
Build.NAME,
|
||||||
Environment.getCommand(),
|
Environment.getCommand(),
|
||||||
String.join(" ", suggestedArgs) + "\n");
|
Build.NAME,
|
||||||
|
String.join(" ", asList(ARG_SPLIT.split(Environment.getConfigArgs()))) + "\n");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -226,7 +227,7 @@ public final class Picocli {
|
||||||
CommandLine.Model.CommandSpec spec = CommandLine.Model.CommandSpec.forAnnotatedObject(new Main())
|
CommandLine.Model.CommandSpec spec = CommandLine.Model.CommandSpec.forAnnotatedObject(new Main())
|
||||||
.name(Environment.getCommand());
|
.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, Start.NAME, addBuildOptionsToStartCommand);
|
||||||
addOption(spec, StartDev.NAME, true);
|
addOption(spec, StartDev.NAME, true);
|
||||||
|
@ -241,7 +242,7 @@ public final class Picocli {
|
||||||
|
|
||||||
cmd.getHelpSectionMap().put(SECTION_KEY_COMMAND_LIST, new SubCommandListRenderer());
|
cmd.getHelpSectionMap().put(SECTION_KEY_COMMAND_LIST, new SubCommandListRenderer());
|
||||||
cmd.setExecutionExceptionHandler(new ExecutionExceptionHandler());
|
cmd.setExecutionExceptionHandler(new ExecutionExceptionHandler());
|
||||||
|
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,6 +250,7 @@ public final class Picocli {
|
||||||
StringBuilder options = new StringBuilder();
|
StringBuilder options = new StringBuilder();
|
||||||
Iterator<String> iterator = argsList.iterator();
|
Iterator<String> iterator = argsList.iterator();
|
||||||
boolean expectValue = false;
|
boolean expectValue = false;
|
||||||
|
List<String> ignoredArgs = asList("--verbose", "-v", "--help", "-h", AUTO_BUILD_OPTION);
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
String key = iterator.next();
|
String key = iterator.next();
|
||||||
|
@ -259,6 +261,10 @@ public final class Picocli {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ignoredArgs.contains(key)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (key.startsWith(ARG_PREFIX)) {
|
if (key.startsWith(ARG_PREFIX)) {
|
||||||
if (options.length() > 0) {
|
if (options.length() > 0) {
|
||||||
options.append(ARG_SEPARATOR);
|
options.append(ARG_SEPARATOR);
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
|
|
||||||
package org.keycloak.configuration;
|
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_KEYCLOAK_PREFIX;
|
||||||
import static org.keycloak.configuration.MicroProfileConfigProvider.NS_QUARKUS_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 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("\\.");
|
private static final Pattern DOT_SPLIT = Pattern.compile("\\.");
|
||||||
|
|
||||||
ConfigArgsConfigSource() {
|
ConfigArgsConfigSource() {
|
||||||
|
|
|
@ -84,7 +84,7 @@ public final class Environment {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getConfigArgs() {
|
public static String getConfigArgs() {
|
||||||
return System.getProperty(CLI_ARGS);
|
return System.getProperty(CLI_ARGS, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getProfile() {
|
public static String getProfile() {
|
||||||
|
|
Loading…
Reference in a new issue