From f7d258f333e119aeec1e337333e5e9f897b2ba08 Mon Sep 17 00:00:00 2001 From: Pedro Igor Date: Wed, 3 Aug 2022 12:52:24 -0300 Subject: [PATCH] IDELauncher not recognizing CLI options at runtime Closes #13517 --- .../org/keycloak/quarkus/runtime/KeycloakMain.java | 6 +++--- .../runtime/cli/command/AbstractStartCommand.java | 2 +- .../org/keycloak/quarkus/_private/IDELauncher.java | 11 +++++------ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/KeycloakMain.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/KeycloakMain.java index 3a83461ace..eb6b0e557d 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/KeycloakMain.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/KeycloakMain.java @@ -80,7 +80,7 @@ public class KeycloakMain implements QuarkusApplication { return; } - start(errorHandler, errStream); + start(errorHandler, errStream, args); return; } @@ -94,7 +94,7 @@ public class KeycloakMain implements QuarkusApplication { return cliArgs.size() == 2 && cliArgs.get(0).equals(Start.NAME) && cliArgs.stream().anyMatch(OPTIMIZED_BUILD_OPTION_LONG::equals); } - public static void start(ExecutionExceptionHandler errorHandler, PrintWriter errStream) { + public static void start(ExecutionExceptionHandler errorHandler, PrintWriter errStream, String[] args) { ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); try { @@ -112,7 +112,7 @@ public class KeycloakMain implements QuarkusApplication { // as we are replacing the default exit handler, we need to force exit System.exit(exitCode); } - }); + }, args); } catch (Throwable cause) { errorHandler.error(errStream, String.format("Unexpected error when starting the server in (%s) mode", getKeycloakModeFromProfile(getProfileOrDefault("prod"))), diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/command/AbstractStartCommand.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/command/AbstractStartCommand.java index 3d935839e3..75ea3c5fe0 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/command/AbstractStartCommand.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/command/AbstractStartCommand.java @@ -34,7 +34,7 @@ public abstract class AbstractStartCommand extends AbstractCommand implements Ru public void run() { doBeforeRun(); CommandLine cmd = spec.commandLine(); - KeycloakMain.start((ExecutionExceptionHandler) cmd.getExecutionExceptionHandler(), cmd.getErr()); + KeycloakMain.start((ExecutionExceptionHandler) cmd.getExecutionExceptionHandler(), cmd.getErr(), cmd.getParseResult().originalArgs().toArray(new String[0])); } protected void doBeforeRun() { diff --git a/quarkus/server/src/main/java/org/keycloak/quarkus/_private/IDELauncher.java b/quarkus/server/src/main/java/org/keycloak/quarkus/_private/IDELauncher.java index ebdfc3152a..0dd254fb0a 100644 --- a/quarkus/server/src/main/java/org/keycloak/quarkus/_private/IDELauncher.java +++ b/quarkus/server/src/main/java/org/keycloak/quarkus/_private/IDELauncher.java @@ -1,12 +1,13 @@ package org.keycloak.quarkus._private; -import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; +import org.keycloak.quarkus.runtime.KeycloakMain; +import org.keycloak.quarkus.runtime.cli.Picocli; + import io.quarkus.runtime.Quarkus; /** @@ -28,7 +29,7 @@ import io.quarkus.runtime.Quarkus; public class IDELauncher { public static void main(String[] args) { - List devArgs = new ArrayList<>(); + List devArgs = new ArrayList<>(Picocli.parseArgs(args)); if (System.getProperty("kc.home.dir") == null) { // direct the auto-created files to the target folder, so they are cleaned by "mvn clean" @@ -37,12 +38,10 @@ public class IDELauncher { System.setProperty("kc.home.dir", path.toAbsolutePath().toString()); } - devArgs.addAll(Arrays.asList(args)); - if (devArgs.isEmpty()) { devArgs.add("start-dev"); } - Quarkus.run(devArgs.toArray(new String[devArgs.size()])); + Quarkus.run(KeycloakMain.class, devArgs.toArray(new String[devArgs.size()])); } }