From 5e1900531f61d1f35512ea0eab1455d4aed114c0 Mon Sep 17 00:00:00 2001 From: f64116045 Date: Wed, 29 Jul 2026 08:51:26 +0800 Subject: [PATCH 1/3] HDDS-15558. Add CLI option style regression test --- .../ozone/shell/TestCliOptionStyle.java | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestCliOptionStyle.java diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestCliOptionStyle.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestCliOptionStyle.java new file mode 100644 index 00000000000..c1a52647dd9 --- /dev/null +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestCliOptionStyle.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.hadoop.ozone.shell; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; +import java.util.stream.Stream; +import org.apache.hadoop.hdds.cli.DeprecatedCliOption; +import org.apache.hadoop.ozone.admin.OzoneAdmin; +import org.apache.hadoop.ozone.conf.OzoneGetConf; +import org.apache.hadoop.ozone.debug.OzoneDebug; +import org.apache.hadoop.ozone.freon.Freon; +import org.apache.hadoop.ozone.genconf.GenerateOzoneRequiredConfigurations; +import org.apache.hadoop.ozone.local.OzoneLocal; +import org.apache.hadoop.ozone.repair.OzoneRepair; +import org.apache.hadoop.ozone.shell.s3.S3Shell; +import org.apache.hadoop.ozone.shell.tenant.TenantShell; +import org.apache.hadoop.ozone.utils.AutoCompletion; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import picocli.CommandLine; +import picocli.CommandLine.Model.OptionSpec; + +/** + * Tests that newly added CLI options follow the preferred naming style. + */ +class TestCliOptionStyle { + + private static final Pattern CAMEL_CASE = Pattern.compile("--.*[A-Z].*"); + private static final Pattern UNDER_SCORE = Pattern.compile("--.*_.*"); + + @ParameterizedTest + @MethodSource("commands") + void onlyKnownOptionsUseDeprecatedStyles(CommandLine command) { + List unknownDeprecatedStyleOptions = new ArrayList<>(); + + collectUnknownDeprecatedStyleOptions(command, command.getCommandName(), + unknownDeprecatedStyleOptions); + + assertThat(unknownDeprecatedStyleOptions) + .as("Options with deprecated styles should be listed in DeprecatedCliOption") + .isEmpty(); + } + + private static Stream commands() { + return Stream.of( + new OzoneAdmin().getCmd(), + new OzoneDebug().getCmd(), + new OzoneRepair().getCmd(), + new OzoneShell().getCmd(), + new S3Shell().getCmd(), + new TenantShell().getCmd(), + new Freon().getCmd(), + new OzoneGetConf().getCmd(), + new OzoneLocal().getCmd(), + new OzoneRatis().getCmd(), + new GenerateOzoneRequiredConfigurations().getCmd(), + new AutoCompletion().getCmd() + ); + } + + private static void collectUnknownDeprecatedStyleOptions(CommandLine command, + String path, List collector) { + for (OptionSpec option : command.getCommandSpec().options()) { + for (String name : option.names()) { + if (hasDeprecatedStyle(name) && !isKnownDeprecatedOption(name)) { + collector.add(path + ": " + name); + } + } + } + + for (Map.Entry subcommand : + command.getSubcommands().entrySet()) { + collectUnknownDeprecatedStyleOptions(subcommand.getValue(), + path + " " + subcommand.getKey(), collector); + } + } + + private static boolean hasDeprecatedStyle(String option) { + if (option.startsWith("--")) { + return CAMEL_CASE.matcher(option).matches() + || UNDER_SCORE.matcher(option).matches(); + } + return option.startsWith("-") && option.length() > 2; + } + + private static boolean isKnownDeprecatedOption(String option) { + StringWriter err = new StringWriter(); + String replacement = DeprecatedCliOption.toNonDeprecated(option, + new PrintWriter(err, true)); + return !replacement.equals(option); + } +} From ffde5064f4ecea852a84cc2b43dc0e31e40dc4b0 Mon Sep 17 00:00:00 2001 From: f64116045 Date: Thu, 30 Jul 2026 08:52:37 +0800 Subject: [PATCH 2/3] HDDS-15558. Use annotation processor for CLI option style check --- .../annotations/CliOptionStyleProcessor.java | 175 ++++++++++++++++++ hadoop-hdds/cli-common/pom.xml | 11 ++ hadoop-hdds/server-scm/pom.xml | 6 + hadoop-ozone/cli-admin/pom.xml | 11 ++ hadoop-ozone/cli-debug/pom.xml | 11 ++ hadoop-ozone/cli-repair/pom.xml | 11 ++ hadoop-ozone/cli-shell/pom.xml | 11 ++ hadoop-ozone/freon/pom.xml | 11 ++ hadoop-ozone/iceberg/pom.xml | 18 +- hadoop-ozone/insight/pom.xml | 17 +- .../ozone/shell/TestCliOptionStyle.java | 114 ------------ hadoop-ozone/ozone-manager/pom.xml | 11 +- hadoop-ozone/tools/pom.xml | 11 ++ hadoop-ozone/vapor/pom.xml | 11 ++ 14 files changed, 306 insertions(+), 123 deletions(-) create mode 100644 hadoop-hdds/annotations/src/main/java/org/apache/ozone/annotations/CliOptionStyleProcessor.java delete mode 100644 hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestCliOptionStyle.java diff --git a/hadoop-hdds/annotations/src/main/java/org/apache/ozone/annotations/CliOptionStyleProcessor.java b/hadoop-hdds/annotations/src/main/java/org/apache/ozone/annotations/CliOptionStyleProcessor.java new file mode 100644 index 00000000000..2d0c64f0eb0 --- /dev/null +++ b/hadoop-hdds/annotations/src/main/java/org/apache/ozone/annotations/CliOptionStyleProcessor.java @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.ozone.annotations; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; +import java.util.regex.Pattern; +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.util.SimpleAnnotationValueVisitor8; +import javax.tools.Diagnostic; + +/** + * Validates that picocli options use the preferred Ozone CLI option style. + */ +@SupportedAnnotationTypes(CliOptionStyleProcessor.OPTION_ANNOTATION) +public class CliOptionStyleProcessor extends AbstractProcessor { + + static final String OPTION_ANNOTATION = "picocli.CommandLine.Option"; + private static final String NAMES_ATTRIBUTE = "names"; + private static final Pattern CAMEL_CASE = Pattern.compile("--.*[A-Z].*"); + private static final Pattern UNDER_SCORE = Pattern.compile("--.*_.*"); + + // Keep this in sync with DeprecatedCliOption in hdds-cli-common. This module + // cannot depend on CLI common, as CLI common runs this processor at compile + // time. + private static final Set KNOWN_DEPRECATED_OPTIONS = + new HashSet<>(Arrays.asList( + "-conf", + "-id", + "-host", + "-nodeid", + "-hostname", + "-al", + "-ffc", + "-fst", + "-tawt", + "-tact", + "-pct", + "-pt", + "--accessId", + "--bufferSize", + "--column_family", + "--dnSchema", + "--expectedGeneration", + "--fileCount", + "--fileSize", + "--filterByFactor", + "--filterByState", + "--keySize", + "--maxDatanodesPercentageToInvolvePerIteration", + "--maxSizeEnteringTargetInGB", + "--maxSizeLeavingSourceInGB", + "--maxSizeToMovePerIterationInGB", + "--nameLen", + "--newLeaderId", + "--numOfBuckets", + "--numOfKeys", + "--numOfThreads", + "--numOfValidateThreads", + "--numOfVolumes", + "--onlyFileNames", + "--replicationFactor", + "--replicationType", + "--scmHost", + "--secretKey", + "--segmentPath", + "--validateWrites" + )); + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latestSupported(); + } + + @Override + public boolean process(Set annotations, + RoundEnvironment roundEnv) { + for (TypeElement annotation : annotations) { + if (OPTION_ANNOTATION.contentEquals(annotation.getQualifiedName())) { + roundEnv.getElementsAnnotatedWith(annotation) + .forEach(this::checkOptionNames); + } + } + return false; + } + + private void checkOptionNames(Element element) { + for (AnnotationMirror annotation : element.getAnnotationMirrors()) { + if (isOptionAnnotation(annotation)) { + checkOptionNames(element, annotation); + } + } + } + + private boolean isOptionAnnotation(AnnotationMirror annotation) { + return OPTION_ANNOTATION.contentEquals( + annotation.getAnnotationType().asElement().toString()); + } + + private void checkOptionNames(Element element, AnnotationMirror annotation) { + for (Entry entry : + annotation.getElementValues().entrySet()) { + if (entry.getKey().getSimpleName().contentEquals(NAMES_ATTRIBUTE)) { + checkOptionNameValues(element, annotation, entry.getValue()); + } + } + } + + private void checkOptionNameValues(Element element, AnnotationMirror annotation, + AnnotationValue value) { + value.accept(new SimpleAnnotationValueVisitor8() { + @Override + public Void visitArray(List values, + Void unused) { + values.forEach(v -> checkOptionNameValues(element, annotation, v)); + return null; + } + + @Override + public Void visitString(String option, Void unused) { + checkOptionName(option, element, annotation, value); + return null; + } + }, null); + } + + private void checkOptionName(String option, Element element, + AnnotationMirror annotation, AnnotationValue value) { + if (hasDeprecatedStyle(option) && !isKnownDeprecatedOption(option)) { + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, + String.format("CLI option '%s' uses a deprecated style. New options " + + "should use --dash-separated-style long names or " + + "single-character short names.", option), + element, annotation, value); + } + } + + private static boolean hasDeprecatedStyle(String option) { + if (option.startsWith("--")) { + return CAMEL_CASE.matcher(option).matches() + || UNDER_SCORE.matcher(option).matches(); + } + return option.startsWith("-") && option.length() > 2; + } + + private static boolean isKnownDeprecatedOption(String option) { + return KNOWN_DEPRECATED_OPTIONS.contains(option); + } +} diff --git a/hadoop-hdds/cli-common/pom.xml b/hadoop-hdds/cli-common/pom.xml index 38de9741a1e..1ace7bb68ac 100644 --- a/hadoop-hdds/cli-common/pom.xml +++ b/hadoop-hdds/cli-common/pom.xml @@ -51,6 +51,11 @@ org.slf4j slf4j-api + + org.apache.ozone + hdds-annotation-processing + provided + @@ -67,6 +72,11 @@ maven-compiler-plugin + + org.apache.ozone + hdds-annotation-processing + ${hdds.version} + org.kohsuke.metainf-services metainf-services @@ -80,6 +90,7 @@ org.kohsuke.metainf_services.AnnotationProcessorImpl + org.apache.ozone.annotations.CliOptionStyleProcessor picocli.codegen.aot.graalvm.processor.NativeImageConfigGeneratorProcessor diff --git a/hadoop-hdds/server-scm/pom.xml b/hadoop-hdds/server-scm/pom.xml index 8c5293d9efa..5a8a779e4e2 100644 --- a/hadoop-hdds/server-scm/pom.xml +++ b/hadoop-hdds/server-scm/pom.xml @@ -169,6 +169,11 @@ org.slf4j slf4j-api + + org.apache.ozone + hdds-annotation-processing + provided + org.apache.ozone hdds-docs @@ -255,6 +260,7 @@ org.apache.hadoop.hdds.conf.ConfigFileGenerator + org.apache.ozone.annotations.CliOptionStyleProcessor org.apache.ozone.annotations.ReplicateAnnotationProcessor diff --git a/hadoop-ozone/cli-admin/pom.xml b/hadoop-ozone/cli-admin/pom.xml index 0fad986a5b8..a9fbfe69280 100644 --- a/hadoop-ozone/cli-admin/pom.xml +++ b/hadoop-ozone/cli-admin/pom.xml @@ -128,6 +128,11 @@ org.slf4j slf4j-api + + org.apache.ozone + hdds-annotation-processing + provided + org.kohsuke.metainf-services @@ -166,6 +171,11 @@ maven-compiler-plugin + + org.apache.ozone + hdds-annotation-processing + ${hdds.version} + org.kohsuke.metainf-services metainf-services @@ -179,6 +189,7 @@ org.kohsuke.metainf_services.AnnotationProcessorImpl + org.apache.ozone.annotations.CliOptionStyleProcessor picocli.codegen.aot.graalvm.processor.NativeImageConfigGeneratorProcessor diff --git a/hadoop-ozone/cli-debug/pom.xml b/hadoop-ozone/cli-debug/pom.xml index 63b54ec94b6..f7d574804c2 100644 --- a/hadoop-ozone/cli-debug/pom.xml +++ b/hadoop-ozone/cli-debug/pom.xml @@ -204,6 +204,11 @@ org.xerial sqlite-jdbc + + org.apache.ozone + hdds-annotation-processing + provided + org.kohsuke.metainf-services @@ -262,6 +267,11 @@ maven-compiler-plugin + + org.apache.ozone + hdds-annotation-processing + ${hdds.version} + org.kohsuke.metainf-services metainf-services @@ -275,6 +285,7 @@ org.kohsuke.metainf_services.AnnotationProcessorImpl + org.apache.ozone.annotations.CliOptionStyleProcessor picocli.codegen.aot.graalvm.processor.NativeImageConfigGeneratorProcessor diff --git a/hadoop-ozone/cli-repair/pom.xml b/hadoop-ozone/cli-repair/pom.xml index 1e79d1ad13e..9d83143d3a0 100644 --- a/hadoop-ozone/cli-repair/pom.xml +++ b/hadoop-ozone/cli-repair/pom.xml @@ -138,6 +138,11 @@ org.slf4j slf4j-api + + org.apache.ozone + hdds-annotation-processing + provided + org.kohsuke.metainf-services @@ -201,6 +206,11 @@ maven-compiler-plugin + + org.apache.ozone + hdds-annotation-processing + ${hdds.version} + org.kohsuke.metainf-services metainf-services @@ -214,6 +224,7 @@ org.kohsuke.metainf_services.AnnotationProcessorImpl + org.apache.ozone.annotations.CliOptionStyleProcessor picocli.codegen.aot.graalvm.processor.NativeImageConfigGeneratorProcessor diff --git a/hadoop-ozone/cli-shell/pom.xml b/hadoop-ozone/cli-shell/pom.xml index 015ad13b59b..b03bbe033d6 100644 --- a/hadoop-ozone/cli-shell/pom.xml +++ b/hadoop-ozone/cli-shell/pom.xml @@ -115,6 +115,11 @@ org.slf4j slf4j-api + + org.apache.ozone + hdds-annotation-processing + provided + org.kohsuke.metainf-services @@ -154,6 +159,11 @@ maven-compiler-plugin + + org.apache.ozone + hdds-annotation-processing + ${hdds.version} + org.kohsuke.metainf-services metainf-services @@ -167,6 +177,7 @@ org.kohsuke.metainf_services.AnnotationProcessorImpl + org.apache.ozone.annotations.CliOptionStyleProcessor picocli.codegen.aot.graalvm.processor.NativeImageConfigGeneratorProcessor diff --git a/hadoop-ozone/freon/pom.xml b/hadoop-ozone/freon/pom.xml index 9bde7cf3395..9637ec3200d 100644 --- a/hadoop-ozone/freon/pom.xml +++ b/hadoop-ozone/freon/pom.xml @@ -138,6 +138,11 @@ org.slf4j slf4j-api + + org.apache.ozone + hdds-annotation-processing + provided + org.kohsuke.metainf-services @@ -166,6 +171,11 @@ maven-compiler-plugin + + org.apache.ozone + hdds-annotation-processing + ${hdds.version} + org.kohsuke.metainf-services metainf-services @@ -179,6 +189,7 @@ org.kohsuke.metainf_services.AnnotationProcessorImpl + org.apache.ozone.annotations.CliOptionStyleProcessor picocli.codegen.aot.graalvm.processor.NativeImageConfigGeneratorProcessor diff --git a/hadoop-ozone/iceberg/pom.xml b/hadoop-ozone/iceberg/pom.xml index d881afce137..8171192901e 100644 --- a/hadoop-ozone/iceberg/pom.xml +++ b/hadoop-ozone/iceberg/pom.xml @@ -109,7 +109,6 @@ - org.apache.ozone hdds-cli-common @@ -127,6 +126,12 @@ org.slf4j slf4j-api + + + org.apache.ozone + hdds-annotation-processing + provided + org.apache.hadoop hadoop-mapreduce-client-core @@ -208,7 +213,16 @@ org.apache.maven.plugins maven-compiler-plugin - none + + + org.apache.ozone + hdds-annotation-processing + ${hdds.version} + + + + org.apache.ozone.annotations.CliOptionStyleProcessor + diff --git a/hadoop-ozone/insight/pom.xml b/hadoop-ozone/insight/pom.xml index 35f4f67b8a0..cc68cb5fe7a 100644 --- a/hadoop-ozone/insight/pom.xml +++ b/hadoop-ozone/insight/pom.xml @@ -100,6 +100,11 @@ jakarta.xml.bind-api provided + + org.apache.ozone + hdds-annotation-processing + provided + org.glassfish.jaxb jaxb-runtime @@ -126,8 +131,16 @@ org.apache.maven.plugins maven-compiler-plugin - - none + + + org.apache.ozone + hdds-annotation-processing + ${hdds.version} + + + + org.apache.ozone.annotations.CliOptionStyleProcessor + diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestCliOptionStyle.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestCliOptionStyle.java deleted file mode 100644 index c1a52647dd9..00000000000 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestCliOptionStyle.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.hadoop.ozone.shell; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; -import java.util.stream.Stream; -import org.apache.hadoop.hdds.cli.DeprecatedCliOption; -import org.apache.hadoop.ozone.admin.OzoneAdmin; -import org.apache.hadoop.ozone.conf.OzoneGetConf; -import org.apache.hadoop.ozone.debug.OzoneDebug; -import org.apache.hadoop.ozone.freon.Freon; -import org.apache.hadoop.ozone.genconf.GenerateOzoneRequiredConfigurations; -import org.apache.hadoop.ozone.local.OzoneLocal; -import org.apache.hadoop.ozone.repair.OzoneRepair; -import org.apache.hadoop.ozone.shell.s3.S3Shell; -import org.apache.hadoop.ozone.shell.tenant.TenantShell; -import org.apache.hadoop.ozone.utils.AutoCompletion; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; -import picocli.CommandLine; -import picocli.CommandLine.Model.OptionSpec; - -/** - * Tests that newly added CLI options follow the preferred naming style. - */ -class TestCliOptionStyle { - - private static final Pattern CAMEL_CASE = Pattern.compile("--.*[A-Z].*"); - private static final Pattern UNDER_SCORE = Pattern.compile("--.*_.*"); - - @ParameterizedTest - @MethodSource("commands") - void onlyKnownOptionsUseDeprecatedStyles(CommandLine command) { - List unknownDeprecatedStyleOptions = new ArrayList<>(); - - collectUnknownDeprecatedStyleOptions(command, command.getCommandName(), - unknownDeprecatedStyleOptions); - - assertThat(unknownDeprecatedStyleOptions) - .as("Options with deprecated styles should be listed in DeprecatedCliOption") - .isEmpty(); - } - - private static Stream commands() { - return Stream.of( - new OzoneAdmin().getCmd(), - new OzoneDebug().getCmd(), - new OzoneRepair().getCmd(), - new OzoneShell().getCmd(), - new S3Shell().getCmd(), - new TenantShell().getCmd(), - new Freon().getCmd(), - new OzoneGetConf().getCmd(), - new OzoneLocal().getCmd(), - new OzoneRatis().getCmd(), - new GenerateOzoneRequiredConfigurations().getCmd(), - new AutoCompletion().getCmd() - ); - } - - private static void collectUnknownDeprecatedStyleOptions(CommandLine command, - String path, List collector) { - for (OptionSpec option : command.getCommandSpec().options()) { - for (String name : option.names()) { - if (hasDeprecatedStyle(name) && !isKnownDeprecatedOption(name)) { - collector.add(path + ": " + name); - } - } - } - - for (Map.Entry subcommand : - command.getSubcommands().entrySet()) { - collectUnknownDeprecatedStyleOptions(subcommand.getValue(), - path + " " + subcommand.getKey(), collector); - } - } - - private static boolean hasDeprecatedStyle(String option) { - if (option.startsWith("--")) { - return CAMEL_CASE.matcher(option).matches() - || UNDER_SCORE.matcher(option).matches(); - } - return option.startsWith("-") && option.length() > 2; - } - - private static boolean isKnownDeprecatedOption(String option) { - StringWriter err = new StringWriter(); - String replacement = DeprecatedCliOption.toNonDeprecated(option, - new PrintWriter(err, true)); - return !replacement.equals(option); - } -} diff --git a/hadoop-ozone/ozone-manager/pom.xml b/hadoop-ozone/ozone-manager/pom.xml index 169751a8eb8..0715e3e9563 100644 --- a/hadoop-ozone/ozone-manager/pom.xml +++ b/hadoop-ozone/ozone-manager/pom.xml @@ -233,6 +233,11 @@ org.yaml snakeyaml + + org.apache.ozone + hdds-annotation-processing + provided + org.apache.ozone hdds-docs @@ -266,11 +271,6 @@ test-jar test - - org.apache.ozone - hdds-annotation-processing - test - org.apache.ozone hdds-common @@ -334,6 +334,7 @@ org.apache.hadoop.hdds.conf.ConfigFileGenerator + org.apache.ozone.annotations.CliOptionStyleProcessor org.apache.ozone.annotations.OmRequestFeatureValidatorProcessor org.apache.ozone.annotations.RegisterValidatorProcessor diff --git a/hadoop-ozone/tools/pom.xml b/hadoop-ozone/tools/pom.xml index 3ffab37b2b2..9e26438e94f 100644 --- a/hadoop-ozone/tools/pom.xml +++ b/hadoop-ozone/tools/pom.xml @@ -98,6 +98,11 @@ org.slf4j slf4j-api + + org.apache.ozone + hdds-annotation-processing + provided + org.kohsuke.metainf-services @@ -173,6 +178,11 @@ maven-compiler-plugin + + org.apache.ozone + hdds-annotation-processing + ${hdds.version} + org.kohsuke.metainf-services metainf-services @@ -186,6 +196,7 @@ org.kohsuke.metainf_services.AnnotationProcessorImpl + org.apache.ozone.annotations.CliOptionStyleProcessor picocli.codegen.aot.graalvm.processor.NativeImageConfigGeneratorProcessor diff --git a/hadoop-ozone/vapor/pom.xml b/hadoop-ozone/vapor/pom.xml index 78342bc6b0a..41f7132fa3f 100644 --- a/hadoop-ozone/vapor/pom.xml +++ b/hadoop-ozone/vapor/pom.xml @@ -150,6 +150,11 @@ org.slf4j slf4j-api + + org.apache.ozone + hdds-annotation-processing + provided + org.kohsuke.metainf-services @@ -178,6 +183,11 @@ maven-compiler-plugin + + org.apache.ozone + hdds-annotation-processing + ${hdds.version} + org.kohsuke.metainf-services metainf-services @@ -191,6 +201,7 @@ org.kohsuke.metainf_services.AnnotationProcessorImpl + org.apache.ozone.annotations.CliOptionStyleProcessor picocli.codegen.aot.graalvm.processor.NativeImageConfigGeneratorProcessor From 4a30c28adca517320116aae559ce3162d3bc296b Mon Sep 17 00:00:00 2001 From: f64116045 Date: Thu, 30 Jul 2026 14:33:03 +0800 Subject: [PATCH 3/3] HDDS-15558. Remove deprecated CLI option allowlist --- .../annotations/CliOptionStyleProcessor.java | 54 +------------------ .../admin/om/LifecycleResumeSubCommand.java | 5 +- .../admin/om/LifecycleStatusSubCommand.java | 5 +- .../admin/om/LifecycleSuspendSubCommand.java | 5 +- 4 files changed, 7 insertions(+), 62 deletions(-) diff --git a/hadoop-hdds/annotations/src/main/java/org/apache/ozone/annotations/CliOptionStyleProcessor.java b/hadoop-hdds/annotations/src/main/java/org/apache/ozone/annotations/CliOptionStyleProcessor.java index 2d0c64f0eb0..0aec138dd7d 100644 --- a/hadoop-hdds/annotations/src/main/java/org/apache/ozone/annotations/CliOptionStyleProcessor.java +++ b/hadoop-hdds/annotations/src/main/java/org/apache/ozone/annotations/CliOptionStyleProcessor.java @@ -17,8 +17,6 @@ package org.apache.ozone.annotations; -import java.util.Arrays; -import java.util.HashSet; import java.util.List; import java.util.Map.Entry; import java.util.Set; @@ -46,53 +44,6 @@ public class CliOptionStyleProcessor extends AbstractProcessor { private static final Pattern CAMEL_CASE = Pattern.compile("--.*[A-Z].*"); private static final Pattern UNDER_SCORE = Pattern.compile("--.*_.*"); - // Keep this in sync with DeprecatedCliOption in hdds-cli-common. This module - // cannot depend on CLI common, as CLI common runs this processor at compile - // time. - private static final Set KNOWN_DEPRECATED_OPTIONS = - new HashSet<>(Arrays.asList( - "-conf", - "-id", - "-host", - "-nodeid", - "-hostname", - "-al", - "-ffc", - "-fst", - "-tawt", - "-tact", - "-pct", - "-pt", - "--accessId", - "--bufferSize", - "--column_family", - "--dnSchema", - "--expectedGeneration", - "--fileCount", - "--fileSize", - "--filterByFactor", - "--filterByState", - "--keySize", - "--maxDatanodesPercentageToInvolvePerIteration", - "--maxSizeEnteringTargetInGB", - "--maxSizeLeavingSourceInGB", - "--maxSizeToMovePerIterationInGB", - "--nameLen", - "--newLeaderId", - "--numOfBuckets", - "--numOfKeys", - "--numOfThreads", - "--numOfValidateThreads", - "--numOfVolumes", - "--onlyFileNames", - "--replicationFactor", - "--replicationType", - "--scmHost", - "--secretKey", - "--segmentPath", - "--validateWrites" - )); - @Override public SourceVersion getSupportedSourceVersion() { return SourceVersion.latestSupported(); @@ -152,7 +103,7 @@ public Void visitString(String option, Void unused) { private void checkOptionName(String option, Element element, AnnotationMirror annotation, AnnotationValue value) { - if (hasDeprecatedStyle(option) && !isKnownDeprecatedOption(option)) { + if (hasDeprecatedStyle(option)) { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, String.format("CLI option '%s' uses a deprecated style. New options " + "should use --dash-separated-style long names or " @@ -169,7 +120,4 @@ private static boolean hasDeprecatedStyle(String option) { return option.startsWith("-") && option.length() > 2; } - private static boolean isKnownDeprecatedOption(String option) { - return KNOWN_DEPRECATED_OPTIONS.contains(option); - } } diff --git a/hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/LifecycleResumeSubCommand.java b/hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/LifecycleResumeSubCommand.java index 69f6c66a90d..a25840ced70 100644 --- a/hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/LifecycleResumeSubCommand.java +++ b/hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/LifecycleResumeSubCommand.java @@ -38,13 +38,13 @@ public class LifecycleResumeSubCommand implements Callable { private LifecycleSubCommand parent; @CommandLine.Option( - names = {"-id", "--service-id"}, + names = {"--service-id"}, description = "Ozone Manager Service ID" ) private String omServiceId; @CommandLine.Option( - names = {"-host", "--service-host"}, + names = {"--service-host"}, description = "Ozone Manager Host" ) private String omHost; @@ -70,4 +70,3 @@ protected PrintStream out() { return System.out; } } - diff --git a/hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/LifecycleStatusSubCommand.java b/hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/LifecycleStatusSubCommand.java index a443471391a..ea0ce071c55 100644 --- a/hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/LifecycleStatusSubCommand.java +++ b/hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/LifecycleStatusSubCommand.java @@ -39,13 +39,13 @@ public class LifecycleStatusSubCommand implements Callable { private LifecycleSubCommand parent; @CommandLine.Option( - names = {"-id", "--service-id"}, + names = {"--service-id"}, description = "Ozone Manager Service ID" ) private String omServiceId; @CommandLine.Option( - names = {"-host", "--service-host"}, + names = {"--service-host"}, description = "Ozone Manager Host" ) private String omHost; @@ -86,4 +86,3 @@ protected PrintStream out() { return System.out; } } - diff --git a/hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/LifecycleSuspendSubCommand.java b/hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/LifecycleSuspendSubCommand.java index 8a420c3d41b..86d4513d588 100644 --- a/hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/LifecycleSuspendSubCommand.java +++ b/hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/LifecycleSuspendSubCommand.java @@ -39,13 +39,13 @@ public class LifecycleSuspendSubCommand implements Callable { private LifecycleSubCommand parent; @CommandLine.Option( - names = {"-id", "--service-id"}, + names = {"--service-id"}, description = "Ozone Manager Service ID" ) private String omServiceId; @CommandLine.Option( - names = {"-host", "--service-host"}, + names = {"--service-host"}, description = "Ozone Manager Host" ) private String omHost; @@ -73,4 +73,3 @@ protected PrintStream out() { return System.out; } } -