diff --git a/crd-generator/cli/src/main/java/io/fabric8/crd/generator/cli/CRDGeneratorCLI.java b/crd-generator/cli/src/main/java/io/fabric8/crd/generator/cli/CRDGeneratorCLI.java index bfa1ade80b..6e1ebc4c4e 100644 --- a/crd-generator/cli/src/main/java/io/fabric8/crd/generator/cli/CRDGeneratorCLI.java +++ b/crd-generator/cli/src/main/java/io/fabric8/crd/generator/cli/CRDGeneratorCLI.java @@ -311,7 +311,7 @@ static CommandLine createCommandLine() { static CommandLine createCommandLine(CRDGeneratorCLI crdGeneratorCLI) { return new CommandLine(crdGeneratorCLI) - .setExecutionExceptionHandler(new CRDGeneratorExecutionExceptionHandler(crdGeneratorCLI)); + .setExecutionExceptionHandler(new CRDGeneratorExecutionExceptionHandler(crdGeneratorCLI::getDiagText)); } } diff --git a/crd-generator/cli/src/main/java/io/fabric8/crd/generator/cli/CRDGeneratorExecutionExceptionHandler.java b/crd-generator/cli/src/main/java/io/fabric8/crd/generator/cli/CRDGeneratorExecutionExceptionHandler.java index 18e38d411f..d96eca6ff8 100644 --- a/crd-generator/cli/src/main/java/io/fabric8/crd/generator/cli/CRDGeneratorExecutionExceptionHandler.java +++ b/crd-generator/cli/src/main/java/io/fabric8/crd/generator/cli/CRDGeneratorExecutionExceptionHandler.java @@ -20,14 +20,16 @@ import org.slf4j.LoggerFactory; import picocli.CommandLine; +import java.util.function.Supplier; + class CRDGeneratorExecutionExceptionHandler implements CommandLine.IExecutionExceptionHandler { private static final Logger log = LoggerFactory.getLogger(CRDGeneratorExecutionExceptionHandler.class); - private final CRDGeneratorCLI crdGeneratorCLI; + private final Supplier diagTextSupplier; - CRDGeneratorExecutionExceptionHandler(CRDGeneratorCLI crdGeneratorCLI) { - this.crdGeneratorCLI = crdGeneratorCLI; + CRDGeneratorExecutionExceptionHandler(Supplier diagTextSupplier) { + this.diagTextSupplier = diagTextSupplier; } @Override @@ -44,7 +46,7 @@ public int handleExecutionException( "Check the list of classpath elements and add further JAR archives " + "or directories containing required classes " + "e.g. with `-cp my-dep.jar` or `-cp target/classes/`."); - commandLine.getErr().print(crdGeneratorCLI.getDiagText()); + commandLine.getErr().print(diagTextSupplier.get()); return CRDGeneratorExitCode.CR_CLASS_LOADING; } @@ -53,12 +55,12 @@ public int handleExecutionException( commandLine.getErr().println("Check JAR files and directories considered to be scanned " + "as well as your filters. At least one Custom Resource class " + "must be retained after filtering."); - commandLine.getErr().print(crdGeneratorCLI.getDiagText()); + commandLine.getErr().print(diagTextSupplier.get()); return CRDGeneratorExitCode.NO_CR_CLASSES_RETAINED; } if (log.isDebugEnabled()) { - commandLine.getErr().println(crdGeneratorCLI.getDiagText()); + commandLine.getErr().println(diagTextSupplier.get()); } log.trace(ex.getMessage(), ex);