Merge branch 'master' of ssh://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project

This commit is contained in:
Greg Wilkins 2012-01-31 11:08:11 +11:00
commit cafdf291ee
2 changed files with 29 additions and 24 deletions

View File

@ -541,29 +541,31 @@ public class Main
// Show Command Line to execute Jetty // Show Command Line to execute Jetty
if (_dryRun) if (_dryRun)
{ {
System.out.println(buildCommandLine(classpath,configuredXmls)); CommandLineBuilder cmd = buildCommandLine(classpath,configuredXmls);
System.out.println(cmd.toString());
return; return;
} }
// execute Jetty in another JVM // execute Jetty in another JVM
if (_exec) if (_exec)
{ {
String cmd = buildCommandLine(classpath,configuredXmls); CommandLineBuilder cmd = buildCommandLine(classpath,configuredXmls);
final Process process = Runtime.getRuntime().exec(cmd); ProcessBuilder pbuilder = new ProcessBuilder(cmd.getArgs());
Runtime.getRuntime().addShutdownHook(new Thread() final Process process = pbuilder.start();
try
{ {
@Override copyInThread(process.getErrorStream(),System.err);
public void run() copyInThread(process.getInputStream(),System.out);
{ copyInThread(System.in,process.getOutputStream());
Config.debug("Destroying " + process); monitor.setProcess(process);
process.destroy(); process.waitFor();
} }
}); finally
copyInThread(process.getErrorStream(),System.err); {
copyInThread(process.getInputStream(),System.out); Config.debug("Destroying " + process);
copyInThread(System.in,process.getOutputStream()); process.destroy();
monitor.setProcess(process); }
process.waitFor();
return; return;
} }
@ -659,7 +661,7 @@ public class Main
throw new FileNotFoundException("Unable to find XML Config: " + xmlFilename); throw new FileNotFoundException("Unable to find XML Config: " + xmlFilename);
} }
String buildCommandLine(Classpath classpath, List<String> xmls) throws IOException CommandLineBuilder buildCommandLine(Classpath classpath, List<String> xmls) throws IOException
{ {
CommandLineBuilder cmd = new CommandLineBuilder(findJavaBin()); CommandLineBuilder cmd = new CommandLineBuilder(findJavaBin());
@ -693,7 +695,7 @@ public class Main
cmd.addArg(xml); cmd.addArg(xml);
} }
return cmd.toString(); return cmd;
} }
private String findJavaBin() private String findJavaBin()

View File

@ -13,8 +13,8 @@
package org.eclipse.jetty.start; package org.eclipse.jetty.start;
import static org.junit.Assert.assertEquals; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.*;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -90,10 +91,12 @@ public class MainTest
Main main = new Main(); Main main = new Main();
main.addJvmArgs(jvmArgs); main.addJvmArgs(jvmArgs);
String commandLine = main.buildCommandLine(new Classpath(""),xmls); CommandLineBuilder cmd = main.buildCommandLine(new Classpath(""),xmls);
assertTrue("CommandLine shouldn't be null",commandLine != null); Assert.assertThat("CommandLineBuilder shouldn't be null", cmd, notNullValue());
assertTrue("CommandLine should contain jvmArgs",commandLine.contains("--exec -Xms1024m -Xmx1024m")); String commandLine = cmd.toString();
assertTrue("CommandLine should contain xmls",commandLine.contains("jetty.xml jetty-jmx.xml jetty-logging.xml")); Assert.assertThat("CommandLine shouldn't be null", commandLine, notNullValue());
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"));
} }