[KEYCLOAK-19686] - Windows support and recording if persisted properties

This commit is contained in:
Pedro Igor 2021-12-07 09:24:52 -03:00
parent 3602873df2
commit 43c46dbcf8
3 changed files with 71 additions and 36 deletions

View file

@ -40,18 +40,24 @@ if "%KEY%" == "--debug" (
shift
goto READ-ARGS
)
if not "%KEY:~0,2%"=="--" if "%KEY:~0,1%"=="-" (
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%"
)
if "%KEY:~0,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%"
set "CONFIG_ARGS=%CONFIG_ARGS% %KEY% %~2%"
)
shift
@ -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

View file

@ -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<String> cliArgs) {
CommandLine cmd = createCommandLine(cliArgs);
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<String> cliArgs) {

View file

@ -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;
}
}