[KEYCLOAK-19686] - Windows support and recording if persisted properties
This commit is contained in:
parent
3602873df2
commit
43c46dbcf8
3 changed files with 71 additions and 36 deletions
|
@ -31,30 +31,36 @@ if "%KEY%" == "" (
|
||||||
goto MAIN
|
goto MAIN
|
||||||
)
|
)
|
||||||
if "%KEY%" == "--debug" (
|
if "%KEY%" == "--debug" (
|
||||||
set "DEBUG_MODE=true"
|
set "DEBUG_MODE=true"
|
||||||
set "DEBUG_PORT_VAR=%~2"
|
set "DEBUG_PORT_VAR=%~2"
|
||||||
if "%DEBUG_PORT_VAR%" == "" (
|
if "%DEBUG_PORT_VAR%" == "" (
|
||||||
set DEBUG_PORT_VAR=8787
|
set DEBUG_PORT_VAR=8787
|
||||||
)
|
)
|
||||||
shift
|
shift
|
||||||
shift
|
shift
|
||||||
goto READ-ARGS
|
goto READ-ARGS
|
||||||
)
|
)
|
||||||
if not "%KEY:~0,2%"=="--" if "%KEY:~0,1%"=="-" (
|
if "%KEY%" == "start-dev" (
|
||||||
set "SERVER_OPTS=%SERVER_OPTS% %KEY%=%~2"
|
set "CONFIG_ARGS=%CONFIG_ARGS% --profile=dev %KEY% --auto-build"
|
||||||
shift
|
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%"=="-" (
|
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 "%KEY:~0,2%"=="--" if not "%KEY:~0,2%"=="-D" if "%KEY:~0,1%"=="-" (
|
||||||
if "%~2"=="" (
|
if "%~2"=="" (
|
||||||
set "CONFIG_ARGS=%CONFIG_ARGS% %KEY%"
|
set "CONFIG_ARGS=%CONFIG_ARGS% %KEY%"
|
||||||
) else (
|
) else (
|
||||||
set "CONFIG_ARGS=%CONFIG_ARGS% %KEY%=%~2%"
|
set "CONFIG_ARGS=%CONFIG_ARGS% %KEY% %~2%"
|
||||||
)
|
)
|
||||||
|
|
||||||
shift
|
shift
|
||||||
)
|
)
|
||||||
shift
|
shift
|
||||||
goto READ-ARGS
|
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
|
:END
|
|
@ -45,6 +45,7 @@ import java.util.function.Predicate;
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
import java.util.stream.Collectors;
|
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.Build;
|
||||||
import org.keycloak.quarkus.runtime.cli.command.Main;
|
import org.keycloak.quarkus.runtime.cli.command.Main;
|
||||||
import org.keycloak.quarkus.runtime.cli.command.Start;
|
import org.keycloak.quarkus.runtime.cli.command.Start;
|
||||||
|
@ -77,7 +78,11 @@ public final class Picocli {
|
||||||
public static void parseAndRun(List<String> cliArgs) {
|
public static void parseAndRun(List<String> cliArgs) {
|
||||||
CommandLine cmd = createCommandLine(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]));
|
cmd.execute(cliArgs.toArray(new String[0]));
|
||||||
}
|
}
|
||||||
|
@ -96,10 +101,6 @@ public final class Picocli {
|
||||||
runReAugmentation(cliArgs, cmd);
|
runReAugmentation(cliArgs, cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Boolean.getBoolean("kc.config.rebuild-and-exit")) {
|
|
||||||
System.exit(cmd.getCommandSpec().exitCodeOnSuccess());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isHelpCommand(List<String> cliArgs) {
|
private static boolean isHelpCommand(List<String> cliArgs) {
|
||||||
|
|
|
@ -17,13 +17,18 @@
|
||||||
|
|
||||||
package org.keycloak.quarkus.runtime.configuration;
|
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.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.nio.file.Path;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
import io.smallrye.config.PropertiesConfigSource;
|
import io.smallrye.config.PropertiesConfigSource;
|
||||||
import org.keycloak.quarkus.runtime.Environment;
|
import org.keycloak.quarkus.runtime.Environment;
|
||||||
|
@ -35,7 +40,7 @@ import org.keycloak.quarkus.runtime.Environment;
|
||||||
public final class PersistedConfigSource extends PropertiesConfigSource {
|
public final class PersistedConfigSource extends PropertiesConfigSource {
|
||||||
|
|
||||||
public static final String NAME = "PersistedConfigSource";
|
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 static final PersistedConfigSource INSTANCE = new PersistedConfigSource();
|
||||||
|
|
||||||
private PersistedConfigSource() {
|
private PersistedConfigSource() {
|
||||||
|
@ -91,17 +96,30 @@ public final class PersistedConfigSource extends PropertiesConfigSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static InputStream loadPersistedConfig() {
|
private static InputStream loadPersistedConfig() {
|
||||||
URL resource = Thread.currentThread().getContextClassLoader().getResource(PERSISTED_PROPERTIES);
|
Path homePath = Environment.getHomePath();
|
||||||
|
|
||||||
if (resource == null) {
|
if (homePath == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
File configFile = homePath.resolve("lib").resolve("quarkus").resolve("generated-bytecode.jar").toFile();
|
||||||
return resource.openStream();
|
|
||||||
} catch (Exception cause) {
|
|
||||||
throw new RuntimeException("Failed to resolve persisted propertied file", cause);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue