From c886434a34107af01ae3cf70645e8e7d8aaa9ede Mon Sep 17 00:00:00 2001 From: Waldemar Sojka Date: Wed, 20 Oct 2021 14:03:32 +0200 Subject: [PATCH 1/5] Added setter for Builder.option (#33) * added separate setter for Builder.opt * added setter for option name with validation * fixed checkstyle error --- src/main/java/org/apache/commons/cli/Option.java | 14 +++++++++++++- .../java/org/apache/commons/cli/OptionTest.java | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/cli/Option.java b/src/main/java/org/apache/commons/cli/Option.java index 4a8590782..dfaff0ebc 100644 --- a/src/main/java/org/apache/commons/cli/Option.java +++ b/src/main/java/org/apache/commons/cli/Option.java @@ -51,7 +51,7 @@ public class Option implements Cloneable, Serializable { public static final class Builder { /** The name of the option */ - private final String option; + private String option; /** description of the option */ private String description; @@ -87,6 +87,18 @@ private Builder(final String option) throws IllegalArgumentException { this.option = OptionValidator.validate(option); } + /** + * Sets the name of the Option. + * + * @param opt the name of the Option + * @return this builder, to allow method chaining + * @throws IllegalArgumentException if there are any non valid Option characters in {@code opt} + */ + public Builder opt(String opt) throws IllegalArgumentException { + this.option = OptionValidator.validate(opt); + return this; + } + /** * Sets the display name for the argument value. * diff --git a/src/test/java/org/apache/commons/cli/OptionTest.java b/src/test/java/org/apache/commons/cli/OptionTest.java index 286aa3aaf..21859fea9 100644 --- a/src/test/java/org/apache/commons/cli/OptionTest.java +++ b/src/test/java/org/apache/commons/cli/OptionTest.java @@ -109,6 +109,8 @@ public void testBuilderMethods() { String.class); checkOption(Option.builder("a").desc("desc").type(Integer.class).build(), "a", "desc", null, Option.UNINITIALIZED, null, false, false, defaultSeparator, Integer.class); + checkOption(Option.builder().opt("a").desc("desc").type(Integer.class).build(), "a", "desc", null, Option.UNINITIALIZED, null, false, false, + defaultSeparator, Integer.class); } @Test From 591af95e0a51d067f69f0ddf1a0ac54ef5c04842 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Wed, 20 Oct 2021 08:11:13 -0400 Subject: [PATCH 2/5] Added setter for Builder.option #33. - Rename new method - Add missing @since tag to new method. - Sort new members. --- src/changes/changes.xml | 3 +++ .../java/org/apache/commons/cli/Option.java | 25 ++++++++++--------- .../org/apache/commons/cli/OptionTest.java | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 799eb910b..720c41692 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -60,6 +60,9 @@ TypeHandler should throw ParseException for an unsupported class. + + Added setter for Builder.option #33. + Update Java from version 5 to 7. diff --git a/src/main/java/org/apache/commons/cli/Option.java b/src/main/java/org/apache/commons/cli/Option.java index dfaff0ebc..7db03723e 100644 --- a/src/main/java/org/apache/commons/cli/Option.java +++ b/src/main/java/org/apache/commons/cli/Option.java @@ -87,18 +87,6 @@ private Builder(final String option) throws IllegalArgumentException { this.option = OptionValidator.validate(option); } - /** - * Sets the name of the Option. - * - * @param opt the name of the Option - * @return this builder, to allow method chaining - * @throws IllegalArgumentException if there are any non valid Option characters in {@code opt} - */ - public Builder opt(String opt) throws IllegalArgumentException { - this.option = OptionValidator.validate(opt); - return this; - } - /** * Sets the display name for the argument value. * @@ -187,6 +175,19 @@ public Builder numberOfArgs(final int numberOfArgs) { return this; } + /** + * Sets the name of the Option. + * + * @param option the name of the Option + * @return this builder, to allow method chaining + * @throws IllegalArgumentException if there are any non valid Option characters in {@code opt} + * @since 1.5 + */ + public Builder option(String option) throws IllegalArgumentException { + this.option = OptionValidator.validate(option); + return this; + } + /** * Sets whether the Option can have an optional argument. * diff --git a/src/test/java/org/apache/commons/cli/OptionTest.java b/src/test/java/org/apache/commons/cli/OptionTest.java index 21859fea9..643cbd9e5 100644 --- a/src/test/java/org/apache/commons/cli/OptionTest.java +++ b/src/test/java/org/apache/commons/cli/OptionTest.java @@ -109,7 +109,7 @@ public void testBuilderMethods() { String.class); checkOption(Option.builder("a").desc("desc").type(Integer.class).build(), "a", "desc", null, Option.UNINITIALIZED, null, false, false, defaultSeparator, Integer.class); - checkOption(Option.builder().opt("a").desc("desc").type(Integer.class).build(), "a", "desc", null, Option.UNINITIALIZED, null, false, false, + checkOption(Option.builder().option("a").desc("desc").type(Integer.class).build(), "a", "desc", null, Option.UNINITIALIZED, null, false, false, defaultSeparator, Integer.class); } From 43117d3b1ee95f7adb4cf968917c9ea2eb670f20 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Wed, 20 Oct 2021 08:12:54 -0400 Subject: [PATCH 3/5] biz.aQute.bnd:biz.aQute.bndlib 5.3.0 -> 6.0.0 --- pom.xml | 2 +- src/changes/changes.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index f9612ef5f..0dd5975fd 100644 --- a/pom.xml +++ b/pom.xml @@ -216,7 +216,7 @@ 3.0.0-M5 3.0.0-M5 5.1.2 - 5.3.0 + 6.0.0 4.4.2.1 4.4.2 1.20 diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 720c41692..d7d56a72c 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -107,7 +107,7 @@ Bump maven-bundle-plugin 5.1.1 -> 5.1.2. - Bump biz.aQute.bndlib.version 5.1.2 -> 5.3.0. + Bump biz.aQute.bndlib.version 5.1.2 -> 6.0.0. Bump spotbugs from 4.4.1 to 4.4.2 #70. From 2df55d424f80c096d0916a733c8c5292c4b1fdf5 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Wed, 20 Oct 2021 08:15:18 -0400 Subject: [PATCH 4/5] Typo. --- src/main/java/org/apache/commons/cli/Parser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/cli/Parser.java b/src/main/java/org/apache/commons/cli/Parser.java index b43c50f6e..a28d47aba 100644 --- a/src/main/java/org/apache/commons/cli/Parser.java +++ b/src/main/java/org/apache/commons/cli/Parser.java @@ -31,7 +31,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more */ @Deprecated public abstract class Parser implements CommandLineParser { - /** commandline instance */ + /** CommandLine instance */ protected CommandLine cmd; /** current Options */ From 69dd16f5348514607101931c982ff2c377dd02bf Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Wed, 20 Oct 2021 08:16:07 -0400 Subject: [PATCH 5/5] Remove unused exception. --- src/test/java/org/apache/commons/cli/DefaultParserTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/apache/commons/cli/DefaultParserTest.java b/src/test/java/org/apache/commons/cli/DefaultParserTest.java index afba65184..0fd835a16 100644 --- a/src/test/java/org/apache/commons/cli/DefaultParserTest.java +++ b/src/test/java/org/apache/commons/cli/DefaultParserTest.java @@ -32,7 +32,7 @@ public void setUp() { } @Test - public void testBuilder() throws Exception { + public void testBuilder() { parser = DefaultParser.builder() .setStripLeadingAndTrailingQuotes(false) .setAllowPartialMatching(false)