Disable Groovy Closures when bootstrapping Picocli (#27050)

Closes #19285

Signed-off-by: Martin Bartoš <mabartos@redhat.com>
This commit is contained in:
Martin Bartoš 2024-02-19 11:01:25 +01:00 committed by GitHub
parent 5f797e3e71
commit c501a7ed20
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 10 additions and 31 deletions

View file

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

View file

@ -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")'"

View file

@ -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> K create(Class<K> cls) throws Exception {
// picocli tries different approaches for creating instances, this is what we need
return cls.getDeclaredConstructor().newInstance();
}
}

View file

@ -482,7 +482,7 @@ public final class Picocli {
}
public static CommandLine createCommandLine(List<String> 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();

View file

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