Do not run build when executing import and export commands (#13942)

Closes #13940
This commit is contained in:
Pedro Igor 2022-08-25 08:43:18 -03:00 committed by GitHub
parent 1c5a77ef19
commit 2b9a0bff51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 14 deletions

View file

@ -52,6 +52,8 @@ import org.keycloak.config.MultiOption;
import org.keycloak.config.OptionCategory;
import org.keycloak.quarkus.runtime.cli.command.AbstractStartCommand;
import org.keycloak.quarkus.runtime.cli.command.Build;
import org.keycloak.quarkus.runtime.cli.command.Export;
import org.keycloak.quarkus.runtime.cli.command.Import;
import org.keycloak.quarkus.runtime.cli.command.ImportRealmMixin;
import org.keycloak.quarkus.runtime.cli.command.Main;
import org.keycloak.quarkus.runtime.cli.command.Start;
@ -102,24 +104,31 @@ public final class Picocli {
private static int runReAugmentationIfNeeded(List<String> cliArgs, CommandLine cmd) {
int exitCode = 0;
if (!isHelpCommand(cliArgs)) {
if (cliArgs.contains(StartDev.NAME)) {
String profile = Environment.getProfile();
if (shouldSkipRebuild(cliArgs)) {
return exitCode;
}
if (profile == null) {
// force the server image to be set with the dev profile
Environment.forceDevProfile();
}
}
if (requiresReAugmentation(cmd)) {
exitCode = runReAugmentation(cliArgs, cmd);
if (cliArgs.contains(StartDev.NAME)) {
String profile = Environment.getProfile();
if (profile == null) {
// force the server image to be set with the dev profile
Environment.forceDevProfile();
}
}
if (requiresReAugmentation(cmd)) {
exitCode = runReAugmentation(cliArgs, cmd);
}
return exitCode;
}
private static boolean isHelpCommand(List<String> cliArgs) {
return cliArgs.contains("--help") || cliArgs.contains("-h") || cliArgs.contains("--help-all");
private static boolean shouldSkipRebuild(List<String> cliArgs) {
return cliArgs.contains("--help")
|| cliArgs.contains("-h")
|| cliArgs.contains("--help-all")
|| cliArgs.contains(Export.NAME)
|| cliArgs.contains(Import.NAME);
}
public static boolean requiresReAugmentation(CommandLine cmd) {

View file

@ -22,11 +22,13 @@ import static org.keycloak.exportimport.ExportImportConfig.ACTION_EXPORT;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
@Command(name = "export",
@Command(name = Export.NAME,
header = "Export data from realms to a file or directory.",
description = "%nExport data from realms to a file or directory.")
public final class Export extends AbstractExportImportCommand implements Runnable {
public static final String NAME = "export";
@Option(names = "--users",
arity = "1",
description = "Set how users should be exported. Possible values are: skip, realm_file, same_file, different_files.",

View file

@ -24,11 +24,13 @@ import static org.keycloak.exportimport.Strategy.OVERWRITE_EXISTING;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
@Command(name = "import",
@Command(name = Import.NAME,
header = "Import data from a directory or a file.",
description = "%nImport data from a directory or a file.")
public final class Import extends AbstractExportImportCommand implements Runnable {
public static final String NAME = "import";
@Option(names = "--override",
arity = "1",
description = "Set if existing data should be skipped or overridden.",

View file

@ -35,6 +35,7 @@ public class ExportDistTest {
CLIResult cliResult = (CLIResult) result;
cliResult.assertMessage("Export of realm 'master' requested.");
cliResult.assertMessage("Export finished successfully");
cliResult.assertNoMessage("Changes detected in configuration");
}
@Test

View file

@ -49,5 +49,6 @@ public class ImportDistTest {
CLIResult cliResult = (CLIResult) result;
cliResult.assertMessage("Realm 'master' imported");
cliResult.assertMessage("Import finished successfully");
cliResult.assertNoMessage("Changes detected in configuration");
}
}