diff --git a/distribution/server-x-dist/src/main/content/bin/kc.bat b/distribution/server-x-dist/src/main/content/bin/kc.bat index 1a3937ae68..db0b31c0cb 100644 --- a/distribution/server-x-dist/src/main/content/bin/kc.bat +++ b/distribution/server-x-dist/src/main/content/bin/kc.bat @@ -31,30 +31,36 @@ if "%KEY%" == "" ( goto MAIN ) if "%KEY%" == "--debug" ( - set "DEBUG_MODE=true" - set "DEBUG_PORT_VAR=%~2" - if "%DEBUG_PORT_VAR%" == "" ( - set DEBUG_PORT_VAR=8787 - ) - shift - shift - goto READ-ARGS + set "DEBUG_MODE=true" + set "DEBUG_PORT_VAR=%~2" + if "%DEBUG_PORT_VAR%" == "" ( + set DEBUG_PORT_VAR=8787 + ) + shift + shift + goto READ-ARGS ) -if not "%KEY:~0,2%"=="--" if "%KEY:~0,1%"=="-" ( - set "SERVER_OPTS=%SERVER_OPTS% %KEY%=%~2" - shift +if "%KEY%" == "start-dev" ( + set "CONFIG_ARGS=%CONFIG_ARGS% --profile=dev %KEY% --auto-build" + shift + shift + goto READ-ARGS +) +if not "%KEY:~0,2%"=="--" if "%KEY:~0,2%"=="-D" ( + set "SERVER_OPTS=%SERVER_OPTS% %KEY%=%~2" + shift ) if not "%KEY:~0,2%"=="--" if not "%KEY:~0,1%"=="-" ( - set "CONFIG_ARGS=%CONFIG_ARGS% %KEY%" + set "CONFIG_ARGS=%CONFIG_ARGS% %KEY%" ) -if "%KEY:~0,2%"=="--" ( - if "%~2"=="" ( - set "CONFIG_ARGS=%CONFIG_ARGS% %KEY%" - ) else ( - set "CONFIG_ARGS=%CONFIG_ARGS% %KEY%=%~2%" - ) +if "%KEY:~0,2%"=="--" if not "%KEY:~0,2%"=="-D" if "%KEY:~0,1%"=="-" ( + if "%~2"=="" ( + set "CONFIG_ARGS=%CONFIG_ARGS% %KEY%" + ) else ( + set "CONFIG_ARGS=%CONFIG_ARGS% %KEY% %~2%" + ) - shift + shift ) shift goto READ-ARGS @@ -103,8 +109,18 @@ if "x%JAVA_HOME%" == "x" ( ) ) -set "CLASSPATH_OPTS=%DIRNAME%..\lib\quarkus-run.jar;%DIRNAME%..\lib\lib\main\*.*" +set "CLASSPATH_OPTS=%DIRNAME%..\lib\quarkus-run.jar" -"%JAVA%" %JAVA_OPTS% -Dkc.home.dir="%DIRNAME%.." -Djboss.server.config.dir="%DIRNAME%..\conf" -Dkeycloak.theme.dir="%DIRNAME%..\themes" %SERVER_OPTS% -cp "%CLASSPATH_OPTS%" io.quarkus.bootstrap.runner.QuarkusEntryPoint %CONFIG_ARGS% +set "JAVA_RUN_OPTS=%JAVA_OPTS% -Dkc.home.dir="%DIRNAME%.." -Djboss.server.config.dir="%DIRNAME%..\conf" -Dkeycloak.theme.dir="%DIRNAME%..\themes" %SERVER_OPTS% -cp "%CLASSPATH_OPTS%" io.quarkus.bootstrap.runner.QuarkusEntryPoint %CONFIG_ARGS%" + +SetLocal EnableDelayedExpansion + +set "AUTO_BUILD_OPTION=auto-build" + +if not "!CONFIG_ARGS:%AUTO_BUILD_OPTION%=!"=="!CONFIG_ARGS!" ( + %JAVA% -Dkc.config.rebuild-and-exit=true %JAVA_RUN_OPTS% +) + +"%JAVA%" %JAVA_RUN_OPTS% :END \ No newline at end of file diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/Picocli.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/Picocli.java index fb7bdc3de5..992629a22d 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/Picocli.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/Picocli.java @@ -45,6 +45,7 @@ import java.util.function.Predicate; import java.util.function.UnaryOperator; import java.util.stream.Collectors; +import io.quarkus.runtime.Quarkus; import org.keycloak.quarkus.runtime.cli.command.Build; import org.keycloak.quarkus.runtime.cli.command.Main; import org.keycloak.quarkus.runtime.cli.command.Start; @@ -77,7 +78,11 @@ public final class Picocli { public static void parseAndRun(List cliArgs) { CommandLine cmd = createCommandLine(cliArgs); - runReAugmentationIfNeeded(cliArgs, cmd); + if (Boolean.getBoolean("kc.config.rebuild-and-exit")) { + runReAugmentationIfNeeded(cliArgs, cmd); + Quarkus.asyncExit(cmd.getCommandSpec().exitCodeOnSuccess()); + return; + } cmd.execute(cliArgs.toArray(new String[0])); } @@ -96,10 +101,6 @@ public final class Picocli { runReAugmentation(cliArgs, cmd); } } - - if (Boolean.getBoolean("kc.config.rebuild-and-exit")) { - System.exit(cmd.getCommandSpec().exitCodeOnSuccess()); - } } private static boolean isHelpCommand(List cliArgs) { diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/PersistedConfigSource.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/PersistedConfigSource.java index 63673276eb..b9260d752f 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/PersistedConfigSource.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/PersistedConfigSource.java @@ -17,13 +17,18 @@ package org.keycloak.quarkus.runtime.configuration; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.net.URL; +import java.nio.file.Path; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Properties; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; import io.smallrye.config.PropertiesConfigSource; import org.keycloak.quarkus.runtime.Environment; @@ -35,7 +40,7 @@ import org.keycloak.quarkus.runtime.Environment; public final class PersistedConfigSource extends PropertiesConfigSource { public static final String NAME = "PersistedConfigSource"; - public static final String PERSISTED_PROPERTIES = "/META-INF/keycloak-persisted.properties"; + public static final String PERSISTED_PROPERTIES = "META-INF/keycloak-persisted.properties"; private static final PersistedConfigSource INSTANCE = new PersistedConfigSource(); private PersistedConfigSource() { @@ -91,17 +96,30 @@ public final class PersistedConfigSource extends PropertiesConfigSource { } private static InputStream loadPersistedConfig() { - URL resource = Thread.currentThread().getContextClassLoader().getResource(PERSISTED_PROPERTIES); + Path homePath = Environment.getHomePath(); - if (resource == null) { + if (homePath == null) { return null; } - try { - return resource.openStream(); - } catch (Exception cause) { - throw new RuntimeException("Failed to resolve persisted propertied file", cause); - } - } + File configFile = homePath.resolve("lib").resolve("quarkus").resolve("generated-bytecode.jar").toFile(); + if (!configFile.exists()) { + return null; + } + + try (ZipInputStream is = new ZipInputStream(new FileInputStream(configFile))) { + ZipEntry entry; + + while ((entry = is.getNextEntry()) != null) { + if (entry.getName().equals(PERSISTED_PROPERTIES)) { + return new ByteArrayInputStream(is.readAllBytes()); + } + } + } catch (Exception cause) { + throw new RuntimeException("Failed to load persisted properties from " + configFile, cause); + } + + return null; + } }