Blame SOURCES/CLI-253-workaround.patch

297686
commit 77218790904f40395304669f5d79740f459c0a90 (HEAD -> cli-253, origin/cli-253)
297686
Author:     Michal Srb <msrb@redhat.com>
297686
AuthorDate: Mon Jun 22 15:01:30 2015 +0200
297686
Commit:     Michal Srb <msrb@redhat.com>
297686
CommitDate: Mon Jun 22 15:04:05 2015 +0200
297686
297686
    [CLI-253] Prevent "Unrecognized option: --null" when handling long opts in PosixParser
297686
297686
diff --git a/src/main/java/org/apache/commons/cli/Options.java b/src/main/java/org/apache/commons/cli/Options.java
297686
index 0ee4eea..1c38194 100644
297686
--- a/src/main/java/org/apache/commons/cli/Options.java
297686
+++ b/src/main/java/org/apache/commons/cli/Options.java
297686
@@ -224,6 +224,20 @@ public class Options implements Serializable
297686
     }
297686
 
297686
     /**
297686
+     * Retrieve the {@link Option} matching the long name specified.
297686
+     * The leading hyphens in the name are ignored (up to 2).
297686
+     *
297686
+     * @param opt long name of the {@link Option}
297686
+     * @return the option represented by opt
297686
+     */
297686
+    Option getLongOption(String opt)
297686
+    {
297686
+        opt = Util.stripLeadingHyphens(opt);
297686
+
297686
+        return longOpts.get(opt);
297686
+    }
297686
+
297686
+    /**
297686
      * Returns the options with a long name starting with the name specified.
297686
      * 
297686
      * @param opt the partial name of the option
297686
diff --git a/src/main/java/org/apache/commons/cli/PosixParser.java b/src/main/java/org/apache/commons/cli/PosixParser.java
297686
index c13a65e..14d2936 100644
297686
--- a/src/main/java/org/apache/commons/cli/PosixParser.java
297686
+++ b/src/main/java/org/apache/commons/cli/PosixParser.java
297686
@@ -131,7 +131,7 @@ public class PosixParser extends Parser
297686
                 }
297686
                 else
297686
                 {
297686
-                    currentOption = options.getOption(matchingOpts.get(0));
297686
+                    currentOption = options.getLongOption(matchingOpts.get(0));
297686
                     
297686
                     tokens.add("--" + currentOption.getLongOpt());
297686
                     if (pos != -1)
297686
diff --git a/src/test/java/org/apache/commons/cli/bug/BugCLI253Test.java b/src/test/java/org/apache/commons/cli/bug/BugCLI253Test.java
297686
new file mode 100644
297686
index 0000000..e37b7bc
297686
--- /dev/null
297686
+++ b/src/test/java/org/apache/commons/cli/bug/BugCLI253Test.java
297686
@@ -0,0 +1,44 @@
297686
+/*
297686
+ * Licensed to the Apache Software Foundation (ASF) under one or more
297686
+ * contributor license agreements.  See the NOTICE file distributed with
297686
+ * this work for additional information regarding copyright ownership.
297686
+ * The ASF licenses this file to You under the Apache License, Version 2.0
297686
+ * (the "License"); you may not use this file except in compliance with
297686
+ * the License.  You may obtain a copy of the License at
297686
+ *
297686
+ *      http://www.apache.org/licenses/LICENSE-2.0
297686
+ *
297686
+ * Unless required by applicable law or agreed to in writing, software
297686
+ * distributed under the License is distributed on an "AS IS" BASIS,
297686
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
297686
+ * See the License for the specific language governing permissions and
297686
+ * limitations under the License.
297686
+ */
297686
+
297686
+package org.apache.commons.cli.bug;
297686
+
297686
+import static org.junit.Assert.assertTrue;
297686
+
297686
+import org.apache.commons.cli.CommandLine;
297686
+import org.apache.commons.cli.Option;
297686
+import org.apache.commons.cli.Options;
297686
+import org.apache.commons.cli.ParseException;
297686
+import org.apache.commons.cli.PosixParser;
297686
+import org.junit.Test;
297686
+
297686
+@SuppressWarnings("deprecation") // tests some deprecated classes
297686
+public class BugCLI253Test {
297686
+
297686
+    @Test
297686
+    public void testGroovyUseCase() throws ParseException {
297686
+        CommandLine cli = new PosixParser().parse(getOptions(), new String[] { "--classpath" });
297686
+        assertTrue(cli.hasOption("--classpath"));
297686
+    }
297686
+
297686
+    private Options getOptions() {
297686
+        Options options = new Options();
297686
+        options.addOption(Option.builder("classpath").build());
297686
+        options.addOption(Option.builder("cp").longOpt("classpath").build());
297686
+        return options;
297686
+    }
297686
+}