aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Becker2012-02-01 04:22:11 (EST)
committerThomas Becker2012-08-20 13:16:03 (EDT)
commit1721a56c6d9586c8b90df78bf16db930011d6e97 (patch)
treeabe828abcfb9f26b0d9670515782c276a08babd3
parent7b61f5f04d2950613a3d82d15b3d5263325a495f (diff)
downloadorg.eclipse.jetty.project-1721a56c6d9586c8b90df78bf16db930011d6e97.zip
org.eclipse.jetty.project-1721a56c6d9586c8b90df78bf16db930011d6e97.tar.gz
org.eclipse.jetty.project-1721a56c6d9586c8b90df78bf16db930011d6e97.tar.bz2
369349: directory with spaces --dry-run fix
-rw-r--r--jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java12
-rw-r--r--jetty-start/src/test/java/org/eclipse/jetty/start/CommandLineBuilderTest.java27
-rw-r--r--jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java36
3 files changed, 51 insertions, 24 deletions
diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java b/jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java
index ba2e8b9..3ea9ba7 100644
--- a/jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java
+++ b/jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java
@@ -35,7 +35,8 @@ public class CommandLineBuilder
*/
public void addArg(String arg)
{
- args.add(quote(arg));
+ if (arg != null)
+ args.add(quote(arg));
}
/**
@@ -78,7 +79,8 @@ public class CommandLineBuilder
*/
public void addRawArg(String arg)
{
- args.add(arg);
+ if (arg != null)
+ args.add(arg);
}
public List<String> getArgs()
@@ -100,7 +102,7 @@ public class CommandLineBuilder
return arg;
}
StringBuilder buf = new StringBuilder();
-// buf.append('"');
+ // buf.append('"');
boolean escaped = false;
for (char c : arg.toCharArray())
{
@@ -111,7 +113,7 @@ public class CommandLineBuilder
escaped = (c == '\\');
buf.append(c);
}
-// buf.append('"');
+ // buf.append('"');
return buf.toString();
}
@@ -127,7 +129,7 @@ public class CommandLineBuilder
{
buf.append(' ');
}
- buf.append(arg);
+ buf.append(quote(arg));
delim = true;
}
diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/CommandLineBuilderTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/CommandLineBuilderTest.java
index c4ff43e..7219422 100644
--- a/jetty-start/src/test/java/org/eclipse/jetty/start/CommandLineBuilderTest.java
+++ b/jetty-start/src/test/java/org/eclipse/jetty/start/CommandLineBuilderTest.java
@@ -12,22 +12,29 @@ package org.eclipse.jetty.start;
//You may elect to redistribute this code under either of these licenses.
//========================================================================
-import static org.hamcrest.Matchers.*;
+import static org.hamcrest.Matchers.is;
+
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
public class CommandLineBuilderTest
{
- @Test
- public void testSimpleCommandline()
+ private CommandLineBuilder cmd = new CommandLineBuilder("java");
+
+ @Before
+ public void setUp()
{
- CommandLineBuilder cmd = new CommandLineBuilder("java");
cmd.addEqualsArg("-Djava.io.tmpdir","/home/java/temp dir/");
cmd.addArg("--version");
-
- Assert.assertThat(cmd.toString(), is("java -Djava.io.tmpdir=/home/java/temp\\ dir/ --version"));
}
-
+
+ @Test
+ public void testSimpleCommandline()
+ {
+ Assert.assertThat(cmd.toString(),is("java -Djava.io.tmpdir=/home/java/temp\\ dir/ --version"));
+ }
+
@Test
public void testQuotingSimple()
{
@@ -46,6 +53,12 @@ public class CommandLineBuilderTest
assertQuoting("/opt/jetty 7 \"special\"/home","/opt/jetty\\ 7\\ \\\"special\\\"/home");
}
+ @Test
+ public void testToStringIsQuotedEvenIfArgsAreNotQuotedForProcessBuilder()
+ {
+ System.out.println(cmd.toString());
+ }
+
private void assertQuoting(String raw, String expected)
{
String actual = CommandLineBuilder.quote(raw);
diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java
index f84c8ea..8ad2d45 100644
--- a/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java
+++ b/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java
@@ -13,10 +13,6 @@
package org.eclipse.jetty.start;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.junit.Assert.assertEquals;
-
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
@@ -25,10 +21,16 @@ import java.util.List;
import java.util.Vector;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
/* ------------------------------------------------------------ */
/**
*/
@@ -96,14 +98,24 @@ public class MainTest
Classpath classpath = nastyWayToCreateAClasspathObject("/jetty/home with spaces/");
CommandLineBuilder cmd = main.buildCommandLine(classpath,xmls);
- Assert.assertThat("CommandLineBuilder shouldn't be null",cmd,notNullValue());
- String commandLine = cmd.toString();
- Assert.assertThat("CommandLine shouldn't be null",commandLine,notNullValue());
- Assert.assertThat("Classpath should be correctly quoted and match expected value",commandLine,
- containsString("-cp /jetty/home with spaces/somejar.jar:/jetty/home with spaces/someotherjar.jar"));
- Assert.assertThat("CommandLine should contain jvmArgs",commandLine,containsString("--exec -Xms1024m -Xmx1024m"));
- Assert.assertThat("CommandLine should contain xmls",commandLine,containsString("jetty.xml jetty-jmx.xml jetty-logging.xml"));
+ assertThat("CommandLineBuilder shouldn't be null",cmd,notNullValue());
+
+ List<String> commandArgs = cmd.getArgs();
+ assertThat("commandArgs should contain 11 elements",commandArgs.size(),equalTo(11));
+ assertThat("args does not contain -cp",commandArgs,hasItems("-cp"));
+ assertThat("Classpath should be correctly quoted and match expected value",commandArgs,
+ hasItems("/jetty/home with spaces/somejar.jar:/jetty/home with spaces/someotherjar.jar"));
+ assertThat("args does not contain --exec",commandArgs,hasItems("--exec"));
+ assertThat("CommandLine should contain jvmArgs",commandArgs,hasItems("-Xms1024m"));
+ assertThat("CommandLine should contain jvmArgs", commandArgs, hasItems("-Xmx1024m"));
+ assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty.xml"));
+ assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty-jmx.xml"));
+ assertThat("CommandLine should contain xmls", commandArgs, hasItems("jetty-logging.xml"));
+ String commandLine = cmd.toString();
+ assertThat("cmd.toString() should be properly escaped",commandLine,containsString("-cp /jetty/home\\ with\\ " +
+ "spaces/somejar.jar:/jetty/home\\ with\\ spaces/someotherjar.jar"));
+ assertThat("cmd.toString() doesn't contain xml config files",commandLine,containsString(" jetty.xml jetty-jmx.xml jetty-logging.xml"));
}
private Classpath nastyWayToCreateAClasspathObject(String jettyHome) throws NoSuchFieldException, IllegalAccessException