IDELauncher not recognizing CLI options at runtime

Closes #13517
This commit is contained in:
Pedro Igor 2022-08-03 12:52:24 -03:00
parent 333a4c900f
commit f7d258f333
3 changed files with 9 additions and 10 deletions

View file

@ -80,7 +80,7 @@ public class KeycloakMain implements QuarkusApplication {
return; return;
} }
start(errorHandler, errStream); start(errorHandler, errStream, args);
return; 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); 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(); ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
try { try {
@ -112,7 +112,7 @@ public class KeycloakMain implements QuarkusApplication {
// as we are replacing the default exit handler, we need to force exit // as we are replacing the default exit handler, we need to force exit
System.exit(exitCode); System.exit(exitCode);
} }
}); }, args);
} catch (Throwable cause) { } catch (Throwable cause) {
errorHandler.error(errStream, errorHandler.error(errStream,
String.format("Unexpected error when starting the server in (%s) mode", getKeycloakModeFromProfile(getProfileOrDefault("prod"))), String.format("Unexpected error when starting the server in (%s) mode", getKeycloakModeFromProfile(getProfileOrDefault("prod"))),

View file

@ -34,7 +34,7 @@ public abstract class AbstractStartCommand extends AbstractCommand implements Ru
public void run() { public void run() {
doBeforeRun(); doBeforeRun();
CommandLine cmd = spec.commandLine(); 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() { protected void doBeforeRun() {

View file

@ -1,12 +1,13 @@
package org.keycloak.quarkus._private; package org.keycloak.quarkus._private;
import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import org.keycloak.quarkus.runtime.KeycloakMain;
import org.keycloak.quarkus.runtime.cli.Picocli;
import io.quarkus.runtime.Quarkus; import io.quarkus.runtime.Quarkus;
/** /**
@ -28,7 +29,7 @@ import io.quarkus.runtime.Quarkus;
public class IDELauncher { public class IDELauncher {
public static void main(String[] args) { public static void main(String[] args) {
List<String> devArgs = new ArrayList<>(); List<String> devArgs = new ArrayList<>(Picocli.parseArgs(args));
if (System.getProperty("kc.home.dir") == null) { if (System.getProperty("kc.home.dir") == null) {
// direct the auto-created files to the target folder, so they are cleaned by "mvn clean" // 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()); System.setProperty("kc.home.dir", path.toAbsolutePath().toString());
} }
devArgs.addAll(Arrays.asList(args));
if (devArgs.isEmpty()) { if (devArgs.isEmpty()) {
devArgs.add("start-dev"); devArgs.add("start-dev");
} }
Quarkus.run(devArgs.toArray(new String[devArgs.size()])); Quarkus.run(KeycloakMain.class, devArgs.toArray(new String[devArgs.size()]));
} }
} }