allow non-optimized commands to run without a separate java launch (#43591)

* fix: allow non-optimized commands to run without a separate java launch

closes: #43611

Signed-off-by: Steve Hawkins <shawkins@redhat.com>

* Update quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/command/AbstractAutoBuildCommand.java

Co-authored-by: Václav Muzikář <vaclav@muzikari.cz>
Signed-off-by: Steven Hawkins <shawkins@redhat.com>

---------

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Signed-off-by: Steven Hawkins <shawkins@redhat.com>
Co-authored-by: Václav Muzikář <vaclav@muzikari.cz>
This commit is contained in:
Steven Hawkins 2025-11-11 02:57:17 -05:00 committed by GitHub
parent 6926ef83f9
commit 9ef7ff22d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 20 additions and 16 deletions

View File

@ -178,8 +178,8 @@ public final class Environment {
return Boolean.getBoolean(KC_CONFIG_REBUILD_CHECK);
}
public static void setRebuildCheck() {
System.setProperty(KC_CONFIG_REBUILD_CHECK, "true");
public static void setRebuildCheck(boolean check) {
System.setProperty(KC_CONFIG_REBUILD_CHECK, Boolean.toString(check));
}
public static boolean isRebuilt() {

View File

@ -941,12 +941,11 @@ public class Picocli {
if (!Environment.isRebuilt() && command instanceof AbstractAutoBuildCommand
&& !cliArgs.contains(OPTIMIZED_BUILD_OPTION_LONG)) {
Environment.setRebuildCheck();
Environment.setRebuildCheck(true);
}
String profile = parsedCommand.map(AbstractCommand::getInitProfile)
.orElseGet(() -> Optional.ofNullable(org.keycloak.common.util.Environment.getProfile())
.orElse(Environment.PROD_PROFILE_VALUE));
String profile = Optional.ofNullable(org.keycloak.common.util.Environment.getProfile())
.or(() -> parsedCommand.map(AbstractCommand::getInitProfile)).orElse(Environment.PROD_PROFILE_VALUE);
Environment.setProfile(profile);
if (!cliArgs.contains(HelpAllMixin.HELP_ALL_OPTION)) {

View File

@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
@ -58,8 +59,16 @@ public abstract class AbstractAutoBuildCommand extends AbstractCommand {
if (isRebuildCheck()) {
if (requiresReAugmentation()) {
runReAugmentation();
return Optional.of(REBUILT_EXIT_CODE);
}
// clear the check, and change to the command runtime profile
String profile = org.keycloak.common.util.Environment.getProfile();
Environment.setRebuildCheck(false);
String runtimeProfile = getInitProfile();
if (!Objects.equals(profile, runtimeProfile)) {
Environment.setProfile(runtimeProfile);
Configuration.resetConfig();
}
return Optional.of(REBUILT_EXIT_CODE);
}
return Optional.empty();
}

View File

@ -52,10 +52,6 @@ public abstract class AbstractCommand implements Callable<Integer> {
* Get the effective profile used when the config is initialized
*/
public String getInitProfile() {
String configuredProfile = org.keycloak.common.util.Environment.getProfile();
if (configuredProfile != null) {
return configuredProfile; // the profile was already set by the cli or even ENV
}
if (Environment.isRebuildCheck()) {
// builds default to prod, if the profile is not overriden via the cli
return Environment.PROD_PROFILE_VALUE;

View File

@ -397,7 +397,7 @@ public class PicocliTest extends AbstractConfigurationTest {
private NonRunningPicocli build(Consumer<String> outChecker, String... args) {
int code = CommandLine.ExitCode.OK;
if (Stream.of(args).anyMatch("start-dev"::equals)) {
Environment.setRebuildCheck();
Environment.setRebuildCheck(true);
code = AbstractAutoBuildCommand.REBUILT_EXIT_CODE;
}
NonRunningPicocli nonRunningPicocli = pseudoLaunch(args);
@ -423,7 +423,7 @@ public class PicocliTest extends AbstractConfigurationTest {
build("build", "--db=dev-file");
NonRunningPicocli nonRunningPicocli = pseudoLaunch("export", "--db=dev-file", "--file=file");
assertEquals(AbstractAutoBuildCommand.REBUILT_EXIT_CODE, nonRunningPicocli.exitCode);
assertEquals(CommandLine.ExitCode.OK, nonRunningPicocli.exitCode);
assertFalse(nonRunningPicocli.reaug);
}
@ -450,7 +450,7 @@ public class PicocliTest extends AbstractConfigurationTest {
build("start-dev");
NonRunningPicocli nonRunningPicocli = pseudoLaunch("--profile=dev", "export", "--file=file");
assertEquals(AbstractAutoBuildCommand.REBUILT_EXIT_CODE, nonRunningPicocli.exitCode);
assertEquals(CommandLine.ExitCode.OK, nonRunningPicocli.exitCode);
assertFalse(nonRunningPicocli.reaug);
}

View File

@ -637,7 +637,7 @@ public class ConfigurationTest extends AbstractConfigurationTest {
@Test
public void testQuarkusLogPropDependentUponKeycloak() {
Environment.setRebuildCheck(); // will be reset by the system properties logic
Environment.setRebuildCheck(true); // will be reset by the system properties logic
ConfigArgsConfigSource.setCliArgs("--log-level=something:debug");
SmallRyeConfig config = createConfig();
assertEquals("DEBUG", config.getConfigValue("quarkus.log.category.\"something\".level").getValue());

View File

@ -361,7 +361,7 @@ public class LoggingConfigurationTest extends AbstractConfigurationTest {
@Test
public void testNestedBuildTimeLogging() {
Environment.setRebuildCheck(); // will be reset by the system properties logic
Environment.setRebuildCheck(true); // will be reset by the system properties logic
ConfigArgsConfigSource.setCliArgs("");
assertEquals("true", createConfig().getConfigValue("quarkus.log.console.enable").getValue());
}