diff --git a/.fakeJettyHome.sh b/.fakeJettyHome.sh index 4be7ee46ff1..5924a273bce 100755 --- a/.fakeJettyHome.sh +++ b/.fakeJettyHome.sh @@ -45,3 +45,5 @@ cd .. cd webapps ln -s ../test-jetty-webapp/target/*.war test.war cd .. + +ln -s jetty-distribution/src/main/resources/start.ini . diff --git a/VERSION.txt b/VERSION.txt index 87a0e57cfbf..38330de1a33 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -4,6 +4,7 @@ jetty-7.0.0-SNAPSHOT + JETTY-1084 Disable GzipFilter for HEAD requests + JETTY-1086 Added UncheckedPrintWriter to avoid ignored EOFs + JETTY-1087 Chunked SSL non blocking input + + 287496 Use start.ini always and added --exec jetty-7.0.0.RC4 18 August 2009 diff --git a/jetty-distribution/src/main/resources/start.ini b/jetty-distribution/src/main/resources/start.ini new file mode 100644 index 00000000000..e47ccec0dbb --- /dev/null +++ b/jetty-distribution/src/main/resources/start.ini @@ -0,0 +1,29 @@ +#=========================================================== +# Jetty start.jar arguments +#----------------------------------------------------------- +# Each line of this file is prepended to the command line +# arguments # of a call to: +# java -jar start.jar [arg...] +# +# If the arguements in this file include JVM arguments +# (eg -Xmx512m) or JVM System properties (eg com.sun.???), +# then these will not take affect unless the --exec +# parameter is included or if the output from --dry-run +# is executed like: +# eval $(java -jar start.jar --dry-run) +# +#=========================================================== + +#=========================================================== +# The following is an example of the ini args to run the +# server with a heap size, JMX remote enabled, JMX mbeans +# and ssl +#----------------------------------------------------------- +# --exec +# -Xmx512m +# -Dcom.sun.management.jmxremote +# OPTIONS=Server,jmx +# etc/jetty-jmx.xml +# etc/jetty.xml +# etc/jetty-ssl.xml +#=========================================================== diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index a709cfcd099..050730c834d 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -33,6 +33,7 @@ import java.security.Policy; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.TimeZone; @@ -57,9 +58,12 @@ public class Main private boolean _dumpVersions = false; private boolean _listOptions = false; private boolean _dryRun = false; + private boolean _exec = false; private boolean _secure = false; private boolean _fromDaemon = false; private final Config _config = new Config(); + private Set _sysProps = new HashSet(); + private List _xArgs = new ArrayList(); private String _jettyHome; @@ -81,13 +85,11 @@ public class Main try { List arguments = new ArrayList(); - + + arguments.addAll(loadStartIni()); // Add Arguments from start.ini (if it exists) if (args.length>0) arguments.addAll(Arrays.asList(args)); // Add Arguments on Command Line - else - // if no command line args - arguments.addAll(loadStartIni()); // Add Arguments from start.ini (if it exists) - + // The XML Configuration Files to initialize with List xmls = new ArrayList(); @@ -125,6 +127,12 @@ public class Main continue; } + if ("--exec".equals(arg)) + { + _exec = true; + continue; + } + // Special internal indicator that jetty was started by the jetty.sh Daemon if ("--fromDaemon".equals(arg)) { @@ -141,10 +149,46 @@ public class Main continue; } - // Process property spec - if (arg.indexOf('=') >= 0) + if (arg.startsWith("-X")) { - processProperty(arg); + _xArgs.add(arg); + continue; + } + + if (arg.startsWith("-D")) + { + String[] assign = arg.substring(2).split("=",2); + _sysProps.add(assign[0]); + switch(assign.length) + { + case 2: + System.setProperty(assign[0],assign[1]); + break; + case 1: + System.setProperty(assign[0],""); + break; + default: + break; + } + continue; + } + + // Is this a Property? + else if (arg.indexOf('=') >= 0) + { + String[] assign = arg.split("=",2); + + switch(assign.length) + { + case 2: + this._config.setProperty(assign[0],assign[1]); + break; + case 1: + this._config.setProperty(assign[0],null); + break; + default: + break; + } continue; } @@ -152,6 +196,15 @@ public class Main xmls.add(arg); } + // Special case for OPTIONS property + String options = _config.getProperty("OPTIONS"); + if (options!=null) + { + String ids[] = options.split(","); + for (String id : ids) + _config.addActiveOption(id); + } + start(xmls); } catch (Throwable t) @@ -161,55 +214,14 @@ public class Main } } - private void processProperty(String arg) - { - String[] prop = arg.split("=",2); - - if (prop[0].startsWith("-D")) - { - // Process System Property - if (prop.length == 2) - { - setSystemProperty(prop[0].substring(2),prop[1]); - } - else - { - System.err.println("Unable to set value-less System Property: " + prop[0]); - } - } - else - { - // Process Startup Property - if (prop.length == 2) - { - // Special case (the Config section id options) - if ("OPTIONS".equals(prop[0])) - { - String ids[] = prop[1].split(","); - for (String id : ids) - { - _config.addActiveOption(id); - } - } - else - { - _config.setProperty(prop[0],prop[1]); - } - } - else - { - _config.setProperty(prop[0],null); - } - } - } - /** * If a start.ini is present in the CWD, then load it into the argument list. */ private List loadStartIni() { - File startIniFile = new File("start.ini"); - if (!startIniFile.exists()) + String jettyHome=System.getProperty("jetty.home"); + File startIniFile = (jettyHome!=null)? new File(jettyHome,"start.ini"):new File("start.ini"); + if (!startIniFile.exists() || !startIniFile.canRead()) { // No start.ini found, skip load. return Collections.emptyList(); @@ -227,43 +239,10 @@ public class Main String arg; while ((arg = buf.readLine()) != null) { - // Is this a Property? - if (arg.indexOf('=') >= 0) - { - // A System Property? - if (arg.startsWith("-D")) - { - String[] assign = arg.substring(2).split("=",2); - - if (assign.length == 2) - { - System.setProperty(assign[0],assign[1]); - } - else - { - System.err.printf("Unable to set System Property '%s', no value provided%n",assign[0]); - } - } - else - // Nah, it's a normal property - { - String[] assign = arg.split("=",2); - - if (assign.length == 2) - { - this._config.setProperty(assign[0],assign[1]); - } - else - { - this._config.setProperty(assign[0],null); - } - } - } - else - // A normal argument - { - args.add(arg); - } + arg=arg.trim(); + if (arg.length()==0 || arg.startsWith("#")) + continue; + args.add(arg); } } catch (IOException e) @@ -279,11 +258,6 @@ public class Main return args; } - private void setSystemProperty(String key, String value) - { - _config.setProperty(key,value); - } - private void usage() { String usageResource = "org/eclipse/jetty/start/usage.txt"; @@ -413,12 +387,10 @@ public class Main String argArray[] = args.toArray(new String[0]); - Class[] method_param_types = new Class[] - { argArray.getClass() }; + Class[] method_param_types = new Class[] { argArray.getClass() }; Method main = invoked_class.getDeclaredMethod("main",method_param_types); - Object[] method_params = new Object[] - { argArray }; + Object[] method_params = new Object[] { argArray }; main.invoke(null,method_params); } @@ -457,7 +429,7 @@ public class Main } /* ------------------------------------------------------------ */ - public void start(List xmls) throws FileNotFoundException + public void start(List xmls) throws FileNotFoundException,IOException,InterruptedException { // Setup Start / Stop Monitoring startMonitor(); @@ -528,9 +500,24 @@ public class Main // Show Command Line to execute Jetty if (_dryRun) { - showDryRun(classpath,xmls); + System.out.println(buildCommandLine(classpath,xmls)); return; } + + // Show Command Line to execute Jetty + if (_exec) + { + String cmd = buildCommandLine(classpath,xmls); + Process process = Runtime.getRuntime().exec(cmd); + copyInThread(process.getErrorStream(),System.err); + copyInThread(process.getInputStream(),System.out); + copyInThread(System.in,process.getOutputStream()); + process.waitFor(); + return; + } + + if (_xArgs.size()>0 || _sysProps.size()>0) + System.err.println("WARNING: System properties and/or JVM args set. Consider using --dry-run or --exec"); // Set current context class loader to what is selected. Thread.currentThread().setContextClassLoader(cl); @@ -564,6 +551,31 @@ public class Main } } + private void copyInThread(final InputStream in,final OutputStream out) + { + new Thread(new Runnable() + { + public void run() + { + try + { + byte[] buf=new byte[1024]; + int len=in.read(buf); + while(len>0) + { + out.write(buf,0,len); + len=in.read(buf); + } + } + catch(IOException e) + { + e.printStackTrace(); + } + } + + }).start(); + } + private String resolveXmlConfig(String xmlFilename) throws FileNotFoundException { File xml = new File(xmlFilename); @@ -587,20 +599,28 @@ public class Main throw new FileNotFoundException("Unable to find XML Config: " + xmlFilename); } - private void showDryRun(Classpath classpath, List xmls) + private String buildCommandLine(Classpath classpath, List xmls) { - StringBuffer cmd = new StringBuffer(); - + StringBuilder cmd = new StringBuilder(); cmd.append(findJavaBin()); - cmd.append(" -cp ").append(classpath.toString()); + for (String x:_xArgs) + cmd.append(' ').append(x); cmd.append(" -Djetty.home=").append(_jettyHome); - cmd.append(" ").append(_config.getMainClassname()); + for (String p:_sysProps) + { + cmd.append(" -D").append(p); + String v=System.getProperty(p); + if (v!=null) + cmd.append('=').append(v); + } + cmd.append(" -cp ").append(classpath.toString()); + cmd.append(' ').append(_config.getMainClassname()); for (String xml : xmls) { - cmd.append(" ").append(xml); + cmd.append(' ').append(xml); } - System.out.println(cmd); + return cmd.toString(); } private String findJavaBin() diff --git a/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt b/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt index cc3f5658268..8bcbcd87a98 100644 --- a/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt +++ b/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt @@ -7,15 +7,32 @@ Common Options: --stop Stop the running Jetty instance. Advanced Options: + + --list-options List available options, then exit. + (see OPTION property in section below) + + --dry-run Print the command line that the start.jar generates, + then exit. This may be used to generate command lines + when the start.ini includes -X or -D arguments. + On unix, the resulting command line can be run with + eval $(java -jar start.jar --dry-run) + This is more efficient than the --exec option, which + creates a second JVM instance + + --exec Run the generated command line (see --dry-run) in + a sub processes. This can be used when start.ini + contains -X or -D arguments, but creates an extra + JVM instance. + --secure Enable Security: * JVM Security Manager * Security Policies * Secure Logging * Audit Logging - --dry-run Print the command line that the start.jar generates, - then exit. - --list-options List available options, then exit. - (see OPTION property in section below) + + +If the file start.ini exists in the working directory, then it's each line +of it's contents is prepended to the as an argument to the command line. Properties: Execution properties, similar in scope to JVM Properties. @@ -50,6 +67,7 @@ NOTE: Not all properties are listed here. just the direct dependencies of the option (eg jsp includes just jetty-jsp module and it's dependencies). (default: "default,*") + @OPTIONS@ Configs: