From 9749f4cbe4686bffd0d759ad2c3e3d49a8c8d226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Str=C3=A4hle?= Date: Sun, 6 Oct 2024 18:01:29 +0200 Subject: [PATCH] Fix code smell and avoid cycle in exception use --- .../crd/generator/cli/CRDGeneratorCLI.java | 20 ------------------- .../cli/CRDGeneratorCliException.java | 11 ++++++++++ ...CRDGeneratorExecutionExceptionHandler.java | 2 +- .../CustomResourceClassNotFoundException.java | 11 ++++++++++ 4 files changed, 23 insertions(+), 21 deletions(-) create mode 100644 crd-generator/cli/src/main/java/io/fabric8/crd/generator/cli/CRDGeneratorCliException.java create mode 100644 crd-generator/cli/src/main/java/io/fabric8/crd/generator/cli/CustomResourceClassNotFoundException.java 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 6f4861161a7..bfa1ade80b3 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 @@ -314,24 +314,4 @@ static CommandLine createCommandLine(CRDGeneratorCLI crdGeneratorCLI) { .setExecutionExceptionHandler(new CRDGeneratorExecutionExceptionHandler(crdGeneratorCLI)); } - /** - * Exception to indicate that no custom resource classes - * have been retained after scanning and filtering. - */ - static class CustomResourceClassNotFoundException extends CRDGeneratorCliException { - CustomResourceClassNotFoundException() { - super("No Custom Resource class retained after filtering"); - } - } - - private static class CRDGeneratorCliException extends RuntimeException { - CRDGeneratorCliException(String message) { - super(message); - } - - CRDGeneratorCliException(String message, Throwable cause) { - super(message, cause); - } - } - } diff --git a/crd-generator/cli/src/main/java/io/fabric8/crd/generator/cli/CRDGeneratorCliException.java b/crd-generator/cli/src/main/java/io/fabric8/crd/generator/cli/CRDGeneratorCliException.java new file mode 100644 index 00000000000..8b80bed3223 --- /dev/null +++ b/crd-generator/cli/src/main/java/io/fabric8/crd/generator/cli/CRDGeneratorCliException.java @@ -0,0 +1,11 @@ +package io.fabric8.crd.generator.cli; + +class CRDGeneratorCliException extends RuntimeException { + CRDGeneratorCliException(String message) { + super(message); + } + + CRDGeneratorCliException(String message, Throwable cause) { + super(message, cause); + } +} 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 4ad22fb53b1..18e38d411f6 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 @@ -48,7 +48,7 @@ public int handleExecutionException( return CRDGeneratorExitCode.CR_CLASS_LOADING; } - if (ex instanceof CRDGeneratorCLI.CustomResourceClassNotFoundException) { + if (ex instanceof CustomResourceClassNotFoundException) { commandLine.getErr().println(); commandLine.getErr().println("Check JAR files and directories considered to be scanned " + "as well as your filters. At least one Custom Resource class " + diff --git a/crd-generator/cli/src/main/java/io/fabric8/crd/generator/cli/CustomResourceClassNotFoundException.java b/crd-generator/cli/src/main/java/io/fabric8/crd/generator/cli/CustomResourceClassNotFoundException.java new file mode 100644 index 00000000000..bbb28aca0f1 --- /dev/null +++ b/crd-generator/cli/src/main/java/io/fabric8/crd/generator/cli/CustomResourceClassNotFoundException.java @@ -0,0 +1,11 @@ +package io.fabric8.crd.generator.cli; + +/** + * Exception to indicate that no custom resource classes have been retained after scanning and + * filtering. + */ +class CustomResourceClassNotFoundException extends CRDGeneratorCliException { + CustomResourceClassNotFoundException() { + super("No Custom Resource class retained after filtering"); + } +}