Author: rob.stryker(a)jboss.com
Date: 2012-05-31 03:13:47 -0400 (Thu, 31 May 2012)
New Revision: 41566
Modified:
branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/ArgsUtil.java
branches/jbosstools-3.3.x/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/ArgsUtilTest.java
Log:
JBIDE-12001 to cr1
Modified:
branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/ArgsUtil.java
===================================================================
---
branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/ArgsUtil.java 2012-05-31
05:44:15 UTC (rev 41565)
+++
branches/jbosstools-3.3.x/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/ArgsUtil.java 2012-05-31
07:13:47 UTC (rev 41566)
@@ -146,8 +146,11 @@
}
public static String setArg(String allArgs, String shortOpt, String longOpt, String
value ) {
- if( value != null && value.contains(SPACE))
- value = QUOTE + value + QUOTE;
+ if( value != null && value.contains(SPACE)) {
+ // avoid double quotes
+ if( !(value.startsWith(QUOTE) && value.endsWith(QUOTE)))
+ value = QUOTE + value + QUOTE;
+ }
return setArg(allArgs, shortOpt, longOpt, value, false);
}
@@ -180,8 +183,12 @@
*/
public static String setArg(String allArgs, String[] shortOpt, String[] longOpt, String
value, boolean addQuotes ) {
String originalValue = value;
- if( addQuotes )
+ String rawValue = originalValue;
+ if( value != null && addQuotes )
value = QUOTE + value + QUOTE;
+ else
+ rawValue = getRawValue(value);
+
boolean found = false;
String[] args = parse(allArgs);
String retVal = EMPTY;
@@ -196,7 +203,7 @@
if( value != null ) {
String newVal = null;
if( args[i].startsWith(QUOTE)) {
- newVal = QUOTE + longOpt[0] + EQ + originalValue + QUOTE;
+ newVal = QUOTE + longOpt[0] + EQ + rawValue + QUOTE;
} else {
newVal = longOpt[0] + EQ + value;
}
@@ -219,4 +226,11 @@
return retVal;
}
+ private static String getRawValue(String original) {
+ if( original != null && original.startsWith(QUOTE) &&
original.endsWith(QUOTE)) {
+ original = original.substring(1);
+ original = original.substring(0, original.length()-1);
+ }
+ return original;
+ }
}
\ No newline at end of file
Modified:
branches/jbosstools-3.3.x/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/ArgsUtilTest.java
===================================================================
---
branches/jbosstools-3.3.x/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/ArgsUtilTest.java 2012-05-31
05:44:15 UTC (rev 41565)
+++
branches/jbosstools-3.3.x/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/util/ArgsUtilTest.java 2012-05-31
07:13:47 UTC (rev 41566)
@@ -11,10 +11,14 @@
package org.jboss.ide.eclipse.as.test.util;
import org.jboss.ide.eclipse.as.core.util.ArgsUtil;
+import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeConstants;
import junit.framework.TestCase;
public class ArgsUtilTest extends TestCase {
+ private static String QUOTE = "\"";
+ private static String EQ = "=";
+
public void testParse() {
assertEquals(1, ArgsUtil.parse("").length);
assertEquals(1, ArgsUtil.parse("a").length);
@@ -104,6 +108,37 @@
}
+
+ public void testOuterQuoteMultipleSet() {
+ String argId = "-Dtest";
+ String folder = "my folder";
+ String args = QUOTE + argId + EQ + folder + QUOTE;
+ String args2 = ArgsUtil.setArg(args, null, argId, folder);
+ assertTrue(args2.trim().equals(args));
+
+ String args3 = ArgsUtil.setArg(args2, null, argId, folder + "2");
+ assertTrue(args3.trim().equals(QUOTE + argId + EQ + folder + "2" + QUOTE));
+ }
+
+ public void testInnerQuotesMultipleSet() {
+ String argId = "-Dtest";
+ String folder = "my folder";
+ String args = argId + EQ + QUOTE + folder + QUOTE;
+ String args2 = ArgsUtil.setArg(args, null, argId, folder + "2");
+ assertTrue(args2.trim().equals(argId + EQ + QUOTE + folder + "2" + QUOTE));
+ args2 = ArgsUtil.setArg(args2, null, argId, folder + "3");
+ assertTrue(args2.trim().equals(argId + EQ + QUOTE + folder + "3" + QUOTE));
+ }
+
+ public void testSetToNulLWithQuotes() {
+ String argId = "-Dtest";
+ String folder = "my folder";
+
+ String args = QUOTE + argId + EQ + folder + QUOTE;
+ String args2 = ArgsUtil.setArg(args, null, argId, null, true);
+ assertTrue(args2.trim().equals(""));
+ }
+
// Just for testing, simply split this string into a bunch of options.
// So I don't need to make new arrays all the time...
public String[] split(String val) {