From c501a7ed20dba500d75d0f6dfaf099a89751ac49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Barto=C5=A1?= Date: Mon, 19 Feb 2024 11:01:25 +0100 Subject: [PATCH] Disable Groovy Closures when bootstrapping Picocli (#27050) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #19285 Signed-off-by: Martin Bartoš --- quarkus/dist/src/main/content/bin/kc.bat | 2 +- quarkus/dist/src/main/content/bin/kc.sh | 1 + .../quarkus/runtime/cli/DefaultFactory.java | 29 ------------------- .../keycloak/quarkus/runtime/cli/Picocli.java | 2 +- .../it/cli/dist/JavaOptsScriptTest.java | 7 +++++ 5 files changed, 10 insertions(+), 31 deletions(-) delete mode 100644 quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/DefaultFactory.java diff --git a/quarkus/dist/src/main/content/bin/kc.bat b/quarkus/dist/src/main/content/bin/kc.bat index a832bbc54d..a0d0e996f0 100644 --- a/quarkus/dist/src/main/content/bin/kc.bat +++ b/quarkus/dist/src/main/content/bin/kc.bat @@ -19,7 +19,7 @@ if "%OS%" == "Windows_NT" ( set DIRNAME=.\ ) -set SERVER_OPTS=-Djava.util.logging.manager=org.jboss.logmanager.LogManager -Dquarkus-log-max-startup-records=10000 +set SERVER_OPTS=-Djava.util.logging.manager=org.jboss.logmanager.LogManager -Dquarkus-log-max-startup-records=10000 -Dpicocli.disable.closures=true set DEBUG_MODE=false set DEBUG_PORT_VAR=8787 diff --git a/quarkus/dist/src/main/content/bin/kc.sh b/quarkus/dist/src/main/content/bin/kc.sh index 610bb9a4f0..d79871f374 100644 --- a/quarkus/dist/src/main/content/bin/kc.sh +++ b/quarkus/dist/src/main/content/bin/kc.sh @@ -37,6 +37,7 @@ abs_path () { SERVER_OPTS="-Dkc.home.dir='$(abs_path '..')'" SERVER_OPTS="$SERVER_OPTS -Djboss.server.config.dir='$(abs_path '../conf')'" SERVER_OPTS="$SERVER_OPTS -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +SERVER_OPTS="$SERVER_OPTS -Dpicocli.disable.closures=true" SERVER_OPTS="$SERVER_OPTS -Dquarkus-log-max-startup-records=10000" CLASSPATH_OPTS="'$(abs_path "../lib/quarkus-run.jar")'" diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/DefaultFactory.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/DefaultFactory.java deleted file mode 100644 index f5d4f22578..0000000000 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/DefaultFactory.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2021 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.quarkus.runtime.cli; - -import picocli.CommandLine.IFactory; - -public class DefaultFactory implements IFactory { - - @Override - public K create(Class cls) throws Exception { - // picocli tries different approaches for creating instances, this is what we need - return cls.getDeclaredConstructor().newInstance(); - } -} diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/Picocli.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/Picocli.java index f36770aa76..35cafddfe5 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/Picocli.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/Picocli.java @@ -482,7 +482,7 @@ public final class Picocli { } public static CommandLine createCommandLine(List cliArgs) { - CommandSpec spec = CommandSpec.forAnnotatedObject(new Main(), new DefaultFactory()).name(Environment.getCommand()); + CommandSpec spec = CommandSpec.forAnnotatedObject(new Main()).name(Environment.getCommand()); for (CommandLine subCommand : spec.subcommands().values()) { CommandSpec subCommandSpec = subCommand.getCommandSpec(); diff --git a/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/JavaOptsScriptTest.java b/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/JavaOptsScriptTest.java index a02239b6ee..26aa07fd38 100644 --- a/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/JavaOptsScriptTest.java +++ b/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/JavaOptsScriptTest.java @@ -105,4 +105,11 @@ public class JavaOptsScriptTest { assertThat(output, matchesPattern("(?s).*Using JAVA_OPTS: " + DEFAULT_OPTS + " -Dfoo=bar.*")); } + @Test + @Launch({ "start-dev", "-Dpicocli.trace=info" }) + void testPicocliClosuresDisabled(LaunchResult result) { + String output = result.getErrorOutput(); // not sure why picocli logs are printed to err + assertThat(output, containsString("DefaultFactory: groovy Closures in annotations are disabled and will not be loaded")); + } + }