geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [03/46] geode git commit: GEODE-2104: Fix parsing of options following --J
Date Mon, 12 Dec 2016 22:36:06 GMT
GEODE-2104: Fix parsing of options following --J

This closes #286


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/4a913fe7
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/4a913fe7
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/4a913fe7

Branch: refs/heads/feature/GEODE-1930
Commit: 4a913fe7a65ea4d5d91ff04f671bf94205b60b62
Parents: bb3db4a
Author: Jared Stewart <jstewart@pivotal.io>
Authored: Tue Nov 15 10:57:11 2016 -0800
Committer: Kirk Lund <klund@apache.org>
Committed: Tue Nov 15 17:02:09 2016 -0800

----------------------------------------------------------------------
 .../internal/cli/util/HyphenFormatter.java      |  6 +-
 .../internal/cli/util/HyphenFormatterTest.java  | 66 ++++++++++++++++++++
 2 files changed, 69 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/4a913fe7/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/HyphenFormatter.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/HyphenFormatter.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/HyphenFormatter.java
index 80816e9..7f7bf5c 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/HyphenFormatter.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/HyphenFormatter.java
@@ -15,6 +15,7 @@
 package org.apache.geode.management.internal.cli.util;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -24,7 +25,7 @@ import java.util.regex.Pattern;
  */
 public class HyphenFormatter {
 
-  private static final String OPTION_PATTERN = "\\-\\-[a-zA-Z]+\\-?[a-zA-Z]*\\=";
+  private static final String OPTION_PATTERN = "--[a-zA-Z]+[a-zA-Z\\-]*=*";
 
   private static final String QUOTE = "\"";
   private static final String EQUAL_HYPHEN = "=-";
@@ -67,13 +68,12 @@ public class HyphenFormatter {
 
   private List<String> split(String cmd) {
     List<String> strings = new ArrayList<>();
-
     Matcher matcher = Pattern.compile(OPTION_PATTERN).matcher(cmd);
 
     int index = 0; // first index of --option=
 
     while (matcher.find()) {
-      if (matcher.start() - index > 0) {
+      if (matcher.start() > index) {
         String option = cmd.substring(index, matcher.start()).trim();
         strings.add(option);
       }

http://git-wip-us.apache.org/repos/asf/geode/blob/4a913fe7/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/HyphenFormatterTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/HyphenFormatterTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/HyphenFormatterTest.java
index c9a3268..55fe9cf 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/HyphenFormatterTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/HyphenFormatterTest.java
@@ -207,4 +207,70 @@ public class HyphenFormatterTest {
     assertThat(formattedCmd).as(cmd).isEqualTo(expected);
   }
 
+  @Test
+  public void optionAfterOneJOption() {
+    String cmd = "start locator --name=loc1 --J=-Dfoo=bar --http-service=8080";
+    String formattedCmd = this.formatter.formatCommand(cmd);
+    String expected = "start locator --name=loc1 --J=\"-Dfoo=bar\" --http-service=8080";
+    assertThat(formattedCmd).as(cmd).isEqualTo(expected);
+  }
+
+  @Test
+  public void optionWithMoreThanOneHyphen() {
+    String cmd = "start locator --name=loc1 --http-service-port=8080";
+    String formattedCmd = this.formatter.formatCommand(cmd);
+    String expected = "start locator --name=loc1 --http-service-port=8080";
+    assertThat(formattedCmd).as(cmd).isEqualTo(expected);
+  }
+
+  @Test
+  public void optionWithOneHyphenAfterOneJOption() {
+    String cmd = "start server --name=me3 --J=-Dgemfire.jmx-manager=true --redis-port=8080";
+    String formattedCmd = this.formatter.formatCommand(cmd);
+    String expected =
+        "start server --name=me3 --J=\"-Dgemfire.jmx-manager=true\" --redis-port=8080";
+    assertThat(formattedCmd).as(cmd).isEqualTo(expected);
+  }
+
+  @Test // reproduces GEODE-2104
+  public void optionWithMoreThanOneHyphenAfterOneJOption() {
+    String cmd = "start server --name=me3 --J=-Dgemfire.jmx-manager=true --http-service-port=8080";
+    String formattedCmd = this.formatter.formatCommand(cmd);
+    String expected =
+        "start server --name=me3 --J=\"-Dgemfire.jmx-manager=true\" --http-service-port=8080";
+    assertThat(formattedCmd).as(cmd).isEqualTo(expected);
+  }
+
+  @Test
+  public void optionWithOneHyphenAfterTwoJOptions() {
+    String cmd =
+        "start server --name=me3 --J=-Dgemfire.jmx-manager=true --J=-Dgemfire.jmx-manager-start=true
--redis-port=8080";
+    String formattedCmd = this.formatter.formatCommand(cmd);
+    String expected =
+        "start server --name=me3 --J=\"-Dgemfire.jmx-manager=true\" --J=\"-Dgemfire.jmx-manager-start=true\"
--redis-port=8080";
+    assertThat(formattedCmd).as(cmd).isEqualTo(expected);
+  }
+
+  @Test // reproduces GEODE-2104
+  public void optionWithMoreThanOneHyphenAfterTwoJOptions() {
+    String cmd =
+        "start server --name=me3 --J=-Dgemfire.jmx-manager=true --J=-Dgemfire.jmx-manager-start=true
--http-service-port=8080";
+    String formattedCmd = this.formatter.formatCommand(cmd);
+    String expected =
+        "start server --name=me3 --J=\"-Dgemfire.jmx-manager=true\" --J=\"-Dgemfire.jmx-manager-start=true\"
--http-service-port=8080";
+    assertThat(formattedCmd).as(cmd).isEqualTo(expected);
+  }
+
+  @Test // reproduces GEODE-2075
+  public void optionWithMoreThanOneHyphenWithoutValueAfterJOptions() {
+    String cmd =
+        "start server --name=Server2 --log-level=config --J=-Dgemfire.locators=localhost[10334]
--disable-default-server";
+    String formattedCmd = this.formatter.formatCommand(cmd);
+    String expected =
+        "start server --name=Server2 --log-level=config --J=\"-Dgemfire.locators=localhost[10334]\"
--disable-default-server";
+    assertThat(formattedCmd).as(cmd).isEqualTo(expected);
+  }
+
+
+
 }


Mime
View raw message