From f00d5c82dfc671d75c73a96292ff1a1f560d2b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Thu, 10 Oct 2024 18:09:21 +0200 Subject: [PATCH] Fix code smell --- .../fabric8/crd/generator/cli/CRDGeneratorCLI.java | 2 +- .../cli/CRDGeneratorExecutionExceptionHandler.java | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) 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 bfa1ade80b3..6e1ebc4c4e0 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 18e38d411f6..d96eca6ff86 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);