fix: skip rebuild if using the tools command (#24858)

closes #24551

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
This commit is contained in:
Steven Hawkins 2023-11-21 10:19:00 -05:00 committed by GitHub
parent 765e4838e9
commit 59823a301a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 9 deletions

View file

@ -60,6 +60,7 @@ import org.keycloak.quarkus.runtime.cli.command.ImportRealmMixin;
import org.keycloak.quarkus.runtime.cli.command.Main;
import org.keycloak.quarkus.runtime.cli.command.ShowConfig;
import org.keycloak.quarkus.runtime.cli.command.StartDev;
import org.keycloak.quarkus.runtime.cli.command.Tools;
import org.keycloak.quarkus.runtime.configuration.ConfigArgsConfigSource;
import org.keycloak.quarkus.runtime.configuration.Configuration;
import org.keycloak.quarkus.runtime.configuration.PersistedConfigSource;
@ -129,11 +130,19 @@ public final class Picocli {
private static int runReAugmentationIfNeeded(List<String> cliArgs, CommandLine cmd) {
int exitCode = 0;
if (shouldSkipRebuild(cliArgs)) {
CommandLine currentCommandSpec = getCurrentCommandSpec(cliArgs, cmd.getCommandSpec());
if (currentCommandSpec == null) {
return exitCode; // possible if using --version or the user made a mistake
}
String currentCommandName = currentCommandSpec.getCommandName();
if (shouldSkipRebuild(cliArgs, currentCommandName)) {
return exitCode;
}
if (cliArgs.contains(StartDev.NAME)) {
if (currentCommandName.equals(StartDev.NAME)) {
String profile = Environment.getProfile();
if (profile == null) {
@ -141,24 +150,22 @@ public final class Picocli {
Environment.forceDevProfile();
}
}
if (requiresReAugmentation(getCurrentCommandSpec(cliArgs, cmd.getCommandSpec()))) {
if (requiresReAugmentation(currentCommandSpec)) {
exitCode = runReAugmentation(cliArgs, cmd);
}
return exitCode;
}
private static boolean shouldSkipRebuild(List<String> cliArgs) {
private static boolean shouldSkipRebuild(List<String> cliArgs, String currentCommandName) {
return cliArgs.contains("--help")
|| cliArgs.contains("-h")
|| cliArgs.contains("--help-all")
|| cliArgs.contains(ShowConfig.NAME);
|| currentCommandName.equals(ShowConfig.NAME)
|| currentCommandName.equals(Tools.NAME);
}
public static boolean requiresReAugmentation(CommandLine cmdCommand) {
if (cmdCommand == null) {
return false; // possible if using --version or the user made a mistake
}
private static boolean requiresReAugmentation(CommandLine cmdCommand) {
if (hasConfigChanges(cmdCommand)) {
if (!ConfigArgsConfigSource.getAllCliArgs().contains(StartDev.NAME) && "dev".equals(getConfig().getOptionalValue("kc.profile", String.class).orElse(null))) {
return false;

View file

@ -24,4 +24,6 @@ import picocli.CommandLine.Command;
subcommands = {Completion.class})
public class Tools {
public static final String NAME = "tools";
}

View file

@ -0,0 +1,38 @@
/*
* Copyright 2023 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.it.cli.dist;
import io.quarkus.test.junit.main.Launch;
import io.quarkus.test.junit.main.LaunchResult;
import org.junit.jupiter.api.Test;
import org.keycloak.it.junit5.extension.DistributionTest;
import static org.junit.jupiter.api.Assertions.assertTrue;
@DistributionTest
public class ToolsCommandDistTest {
@Test
@Launch({ "tools", "completion" })
void initialCompletionShouldSucceed(LaunchResult result) {
assertTrue(result.getOutput().contains("Define a completion specification"),
() -> "The Output:\n" + result.getOutput() + "doesn't contains the expected string.");
}
}