From 1c84cb7298ea77bc02ff80218db2473665145f5d Mon Sep 17 00:00:00 2001 From: Marko Mackic Date: Sun, 17 Oct 2021 21:33:45 +0200 Subject: [PATCH] Revert "[#1319] Bugfix: Avoid `DuplicateOptionAnnotationsException` when parent has inherited mixed-in help options and the built-in `HelpCommand` subcommand." This reverts commit 1a95bf266e8df8a10b56eacebec86092242c8d90. --- RELEASE-NOTES.md | 1 - .../processing/tests/Issue1319Test.java | 24 ------------------- .../picocli/issue1319/InheritHelpApp.java | 16 ------------- src/main/java/picocli/CommandLine.java | 8 ++----- .../java/picocli/InheritedOptionTest.java | 1 + 5 files changed, 3 insertions(+), 47 deletions(-) delete mode 100644 picocli-annotation-processing-tests/src/test/java/picocli/annotation/processing/tests/Issue1319Test.java delete mode 100644 picocli-annotation-processing-tests/src/test/resources/picocli/issue1319/InheritHelpApp.java diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 0b7cf0cf2..8f351ba2a 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -26,7 +26,6 @@ Picocli follows [semantic versioning](http://semver.org/). * [#1303] Bugfix: Prevent `IllegalArgumentException: argument type mismatch` error in method subcommands with inherited mixed-in standard help options. Thanks to [Andreas Deininger](https://github.com/deining) for raising this. * [#1300] Bugfix: Avoid spurious warning "Could not set initial value for field boolean" when reusing `CommandLine` with ArgGroup. Thanks to [Yashodhan Ghadge](https://github.com/codexetreme) for raising this. * [#1316] Bugfix: Avoid `DuplicateOptionAnnotationsException` thrown on `mixinStandardHelpOptions` for subcommands when parent has `scope = INHERIT` by `picocli-codegen` annotation processor. Thanks to [Philippe Charles](https://github.com/charphi) for raising this. -* [#1319] Bugfix: Avoid `DuplicateOptionAnnotationsException` when parent has inherited mixed-in help options and the built-in `HelpCommand` subcommand. Thanks to [Andreas Deininger](https://github.com/deining) for raising this. * [#1320][#1321] Bugfix/Enhancement: Use system properties `sun.stdout.encoding` and `sun.stderr.encoding` when creating the `PrintWriters` returned by `CommandLine::getOut` and `CommandLine::getErr`. Thanks to [Philippe Charles](https://github.com/charphi) for the investigation and the pull request. * [#1296] DOC: add Kotlin code samples to user manual; other user manual improvements. Thanks to [Andreas Deininger](https://github.com/deining) for the pull request. * [#1299] DOC: Link to `IParameterPreprocessor` from `IParameterConsumer` javadoc. Thanks to [Andreas Deininger](https://github.com/deining) for the pull request. diff --git a/picocli-annotation-processing-tests/src/test/java/picocli/annotation/processing/tests/Issue1319Test.java b/picocli-annotation-processing-tests/src/test/java/picocli/annotation/processing/tests/Issue1319Test.java deleted file mode 100644 index 561b400f2..000000000 --- a/picocli-annotation-processing-tests/src/test/java/picocli/annotation/processing/tests/Issue1319Test.java +++ /dev/null @@ -1,24 +0,0 @@ -package picocli.annotation.processing.tests; - -import com.google.testing.compile.Compilation; -import com.google.testing.compile.JavaFileObjects; -import org.junit.Test; - -import javax.annotation.processing.Processor; - -import static com.google.testing.compile.CompilationSubject.assertThat; -import static com.google.testing.compile.Compiler.javac; - -public class Issue1319Test { - @Test - public void testIssue1319() { - Processor processor = new AnnotatedCommandSourceGeneratorProcessor(); - Compilation compilation = - javac() - .withProcessors(processor) - .compile(JavaFileObjects.forResource( - "picocli/issue1319/InheritHelpApp.java")); - - assertThat(compilation).succeeded(); - } -} diff --git a/picocli-annotation-processing-tests/src/test/resources/picocli/issue1319/InheritHelpApp.java b/picocli-annotation-processing-tests/src/test/resources/picocli/issue1319/InheritHelpApp.java deleted file mode 100644 index 6773ededc..000000000 --- a/picocli-annotation-processing-tests/src/test/resources/picocli/issue1319/InheritHelpApp.java +++ /dev/null @@ -1,16 +0,0 @@ -package picocli.issue1319; - -import picocli.CommandLine; - -@CommandLine.Command(scope = CommandLine.ScopeType.INHERIT - , mixinStandardHelpOptions = true - , subcommands = { CommandLine.HelpCommand.class } -) -class InheritHelpApp { - int subFoo; - - @CommandLine.Command() - void sub(@CommandLine.Option(names = "-foo") int foo) { - subFoo = foo; - } -} diff --git a/src/main/java/picocli/CommandLine.java b/src/main/java/picocli/CommandLine.java index 8c621668d..226bceaa2 100644 --- a/src/main/java/picocli/CommandLine.java +++ b/src/main/java/picocli/CommandLine.java @@ -7156,12 +7156,8 @@ public CommandSpec negatableOptionTransformer(INegatableOptionTransformer newVal * @see Command#mixinStandardHelpOptions() */ public CommandSpec mixinStandardHelpOptions(boolean newValue) { if (newValue) { - CommandSpec mixin = CommandSpec.forAnnotatedObject(new AutoHelpMixin(), new DefaultFactory()); - boolean overlap = false; - for (String key : mixin.optionsMap().keySet()) { - if (optionsMap().containsKey(key)) { overlap = true; break; } - } - if (!overlap) { // #1316, 1319 avoid DuplicateOptionAnnotationsException + if (!mixins.containsKey(AutoHelpMixin.KEY)) { // #1316 avoid DuplicateOptionAnnotationsException + CommandSpec mixin = CommandSpec.forAnnotatedObject(new AutoHelpMixin(), new DefaultFactory()); mixin.inherited = this.inherited(); addMixin(AutoHelpMixin.KEY, mixin); } diff --git a/src/test/java/picocli/InheritedOptionTest.java b/src/test/java/picocli/InheritedOptionTest.java index 8d38d6457..2c5113d90 100644 --- a/src/test/java/picocli/InheritedOptionTest.java +++ b/src/test/java/picocli/InheritedOptionTest.java @@ -558,6 +558,7 @@ class Example { } new CommandLine(new Example()); // succeeds without error } + @Ignore("Needs fix for #1319") @Test public void testIssue1319() { @Command(scope = CommandLine.ScopeType.INHERIT