From 21e7b67cc73f9b7ab7741211989a5f7bfd868d35 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 8 Aug 2013 17:53:33 +1000 Subject: [PATCH] 414635 Modular start.d and jetty.base property --- .../src/main/config/etc/jetty-deploy.xml | 5 +- .../src/main/resources/etc/jetty-demo.xml | 2 +- .../resources/start.d/000-jvm.ini.available | 27 ++ .../src/main/resources/start.d/000-npn.ini | 17 + .../src/main/resources/start.d/010-ext.ini | 3 + .../start.d/010-jmx-remote.ini.available | 9 + .../main/resources/start.d/010-resources.ini | 3 + .../src/main/resources/start.d/100-jetty.ini | 19 + .../src/main/resources/start.d/110-jmx.ini | 7 + .../src/main/resources/start.d/110-jsp.ini | 5 + .../start.d/110-logging.ini.available | 9 + .../start.d/110-setuid.ini.available | 14 + .../src/main/resources/start.d/200-ssl.ini | 17 + .../main/resources/start.d/200-websocket.ini | 5 + .../src/main/resources/start.d/210-http.ini | 11 + .../src/main/resources/start.d/210-https.ini | 13 + .../src/main/resources/start.d/210-spdy.ini | 10 + .../resources/start.d/300-jaas.ini.available | 9 + .../resources/start.d/300-jndi.ini.available | 5 + .../src/main/resources/start.d/300-plus.ini | 6 + .../start.d/300-requestlog.ini.available | 11 + .../resources/start.d/310-annotations.ini | 9 + .../start.d/320-websocket-annotations.ini | 7 + .../resources/start.d/400-debug.ini.available | 1 + .../start.d/400-ipaccess.ini.available | 1 + .../start.d/400-lowresources.ini.available | 13 + .../start.d/400-rewrite.ini.available | 6 + .../resources/start.d/400-stats.ini.available | 1 + .../src/main/resources/start.d/500-deploy.ini | 5 + .../src/main/resources/start.d/900-demo.ini | 56 +-- .../src/main/resources/start.ini | 227 +----------- .../src/main/config/etc/jetty-ssl.xml | 4 +- .../java/org/eclipse/jetty/start/Config.java | 123 +++++-- .../java/org/eclipse/jetty/start/Main.java | 331 ++++++++++-------- .../org/eclipse/jetty/start/start.config | 174 ++++----- .../org/eclipse/jetty/start/usage.txt | 15 +- .../org/eclipse/jetty/start/ConfigTest.java | 7 +- .../org/eclipse/jetty/start/MainTest.java | 33 +- .../resources/jetty.home/start.d/10-jmx.ini | 2 +- .../jetty.home/start.d/20-websocket.ini | 3 +- .../src/test/resources/jetty.home/start.ini | 66 +--- 41 files changed, 662 insertions(+), 629 deletions(-) create mode 100644 jetty-distribution/src/main/resources/start.d/000-jvm.ini.available create mode 100644 jetty-distribution/src/main/resources/start.d/000-npn.ini create mode 100644 jetty-distribution/src/main/resources/start.d/010-ext.ini create mode 100644 jetty-distribution/src/main/resources/start.d/010-jmx-remote.ini.available create mode 100644 jetty-distribution/src/main/resources/start.d/010-resources.ini create mode 100644 jetty-distribution/src/main/resources/start.d/100-jetty.ini create mode 100644 jetty-distribution/src/main/resources/start.d/110-jmx.ini create mode 100644 jetty-distribution/src/main/resources/start.d/110-jsp.ini create mode 100644 jetty-distribution/src/main/resources/start.d/110-logging.ini.available create mode 100644 jetty-distribution/src/main/resources/start.d/110-setuid.ini.available create mode 100644 jetty-distribution/src/main/resources/start.d/200-ssl.ini create mode 100644 jetty-distribution/src/main/resources/start.d/200-websocket.ini create mode 100644 jetty-distribution/src/main/resources/start.d/210-http.ini create mode 100644 jetty-distribution/src/main/resources/start.d/210-https.ini create mode 100644 jetty-distribution/src/main/resources/start.d/210-spdy.ini create mode 100644 jetty-distribution/src/main/resources/start.d/300-jaas.ini.available create mode 100644 jetty-distribution/src/main/resources/start.d/300-jndi.ini.available create mode 100644 jetty-distribution/src/main/resources/start.d/300-plus.ini create mode 100644 jetty-distribution/src/main/resources/start.d/300-requestlog.ini.available create mode 100644 jetty-distribution/src/main/resources/start.d/310-annotations.ini create mode 100644 jetty-distribution/src/main/resources/start.d/320-websocket-annotations.ini create mode 100644 jetty-distribution/src/main/resources/start.d/400-debug.ini.available create mode 100644 jetty-distribution/src/main/resources/start.d/400-ipaccess.ini.available create mode 100644 jetty-distribution/src/main/resources/start.d/400-lowresources.ini.available create mode 100644 jetty-distribution/src/main/resources/start.d/400-rewrite.ini.available create mode 100644 jetty-distribution/src/main/resources/start.d/400-stats.ini.available create mode 100644 jetty-distribution/src/main/resources/start.d/500-deploy.ini diff --git a/jetty-deploy/src/main/config/etc/jetty-deploy.xml b/jetty-deploy/src/main/config/etc/jetty-deploy.xml index 1b46387213e..16e5253a86c 100644 --- a/jetty-deploy/src/main/config/etc/jetty-deploy.xml +++ b/jetty-deploy/src/main/config/etc/jetty-deploy.xml @@ -39,14 +39,14 @@ - /webapps + /webapps /etc/webdefault.xml 1 true - / + / - / + / diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java index 9ed3b1b4b13..7365199b7e7 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java @@ -45,6 +45,8 @@ import java.util.Set; import java.util.StringTokenizer; import java.util.TreeSet; +import org.omg.CORBA._PolicyStub; + /** *

* It allows an application to be started with the command "java -jar start.jar". @@ -184,14 +186,14 @@ public class Config private static final String _version; private static boolean DEBUG = false; - private static final Map __properties = new HashMap(); + private final Map _properties = new HashMap(); private final Map _classpaths = new HashMap(); private final List _xml = new ArrayList(); private String _classname = null; private int argCount = 0; - private final Set _activeOptions = new TreeSet(new Comparator() + private final Set _options = new TreeSet(new Comparator() { // Make sure "*" is always at the end of the list public int compare(String o1, String o2) @@ -208,17 +210,24 @@ public class Config } }); + public Classpath defineOption(String option) + { + Classpath cp = _classpaths.get(option); + if (cp == null) + { + cp = new Classpath(); + _classpaths.put(option,cp); + } + return cp; + } + private boolean addClasspathComponent(List sections, String component) { for (String section : sections) { - Classpath cp = _classpaths.get(section); - if (cp == null) - cp = new Classpath(); + Classpath cp = defineOption(section); boolean added = cp.addComponent(component); - _classpaths.put(section,cp); - if (!added) { // First failure means all failed. @@ -234,10 +243,6 @@ public class Config for (String section : sections) { Classpath cp = _classpaths.get(section); - if (cp == null) - { - cp = new Classpath(); - } if (!cp.addClasspath(path)) { // First failure means all failed. @@ -385,7 +390,7 @@ public class Config */ public Classpath getActiveClasspath() { - return getCombinedClasspath(_activeOptions); + return getCombinedClasspath(_options); } /** @@ -408,7 +413,7 @@ public class Config Classpath otherCp = _classpaths.get(optionId); if (otherCp == null) { - throw new IllegalArgumentException("No such OPTIONS: " + optionId); + throw new IllegalArgumentException("No such OPTION: " + optionId); } cp.overlay(otherCp); } @@ -421,12 +426,12 @@ public class Config return _classname; } - public static void clearProperties() + public void clearProperties() { - __properties.clear(); + _properties.clear(); } - public static Properties getProperties() + public Properties getProperties() { Properties properties = new Properties(); // Add System Properties First @@ -436,30 +441,30 @@ public class Config properties.put(name, System.getProperty(name)); } // Add Config Properties Next (overwriting any System Properties that exist) - for (String key : __properties.keySet()) { - properties.put(key,__properties.get(key)); + for (String key : _properties.keySet()) { + properties.put(key,_properties.get(key)); } return properties; } - public static String getProperty(String name) + public String getProperty(String name) { if ("version".equalsIgnoreCase(name)) { return _version; } // Search Config Properties First - if (__properties.containsKey(name)) { - return __properties.get(name); + if (_properties.containsKey(name)) { + return _properties.get(name); } // Return what exists in System.Properties otherwise. return System.getProperty(name); } - public static String getProperty(String name, String defaultValue) + public String getProperty(String name, String defaultValue) { // Search Config Properties First - if (__properties.containsKey(name)) - return __properties.get(name); + if (_properties.containsKey(name)) + return _properties.get(name); // Return what exists in System.Properties otherwise. return System.getProperty(name, defaultValue); } @@ -956,31 +961,46 @@ public class Config } if (name.equals("OPTIONS")) { - _activeOptions.clear(); + _options.clear(); String ids[] = value.split(","); for (String id : ids) + addOption(id); + } + if (name.equals("jetty.base")) + { + File base=new File(value); + try { - addActiveOption(id); + value=base.getCanonicalPath(); + } + catch(Exception e) + { + e.printStackTrace(); } } - __properties.put(name,value); + _properties.put(name,value); } - public void addActiveOption(String option) + public void addOption(String option) { - _activeOptions.add(option); - __properties.put("OPTIONS",join(_activeOptions,",")); + _options.add(option); + _properties.put("OPTIONS",join(_options,",")); + } + + public Set getKnownOptions() + { + return _classpaths.keySet(); } - public Set getActiveOptions() + public Set getOptions() { - return _activeOptions; + return _options; } - public void removeActiveOption(String option) + public void removeOption(String option) { - _activeOptions.remove(option); - __properties.put("OPTIONS",join(_activeOptions,",")); + _options.remove(option); + _properties.put("OPTIONS",join(_options,",")); } private String join(Collection coll, String delim) @@ -999,4 +1019,37 @@ public class Config return buf.toString(); } + public String getJettyHome() + { + return getProperty("jetty.home"); + } + + public String getJettyBase() + { + return getProperty("jetty.base"); + } + + public File getFileBaseHomeAbs(String filename) + { + File file; + + String base = getJettyBase(); + if (base!=null) + { + file=new File(base,filename); + if (file.exists()) + return file; + } + + file=new File(getJettyHome(),filename); + if (file.exists()) + return file; + + file=new File(filename); + if (file.exists()) + return file; + + return null; + + } } 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 3ea743ad778..c4e17cb2686 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 @@ -51,8 +51,6 @@ import java.util.Locale; import java.util.Properties; import java.util.Set; -import javax.naming.OperationNotSupportedException; - /*-------------------------------------------*/ /** *

@@ -82,19 +80,17 @@ public class Main private boolean _dryRun = false; private boolean _exec = false; private final Config _config = new Config(); - private final Set _sysProps = new HashSet(); - private final List _jvmArgs = new ArrayList(); + private final Set _sysProps = new HashSet<>(); + private final List _jvmArgs = new ArrayList<>(); + private final List _iniFiles = new ArrayList<>(); private String _startConfig = null; - private String _jettyHome; - public static void main(String[] args) { try { Main main = new Main(); - List arguments = main.expandCommandLine(args); - List xmls = main.processCommandLine(arguments); + List xmls = main.processCommandLine(args); if (xmls != null) main.start(xmls); } @@ -106,64 +102,36 @@ public class Main Main() throws IOException { - _jettyHome = System.getProperty("jetty.home","."); - _jettyHome = new File(_jettyHome).getCanonicalPath(); + String jetty_home=new File(System.getProperty("jetty.home",".")).getCanonicalPath(); + _config.setProperty("jetty.home",jetty_home); } - public List expandCommandLine(String[] args) throws Exception + Config getConfig() { - List arguments = new ArrayList(); - - // add the command line args and look for start.ini args - boolean ini = false; - for (String arg : args) - { + return _config; + } + + public List processCommandLine(String[] args) throws Exception + { + String source=""; + + // Handle default ini args + ArrayList arguments = new ArrayList<>(Arrays.asList(args)); + boolean ini=false; + for(String arg : arguments) if (arg.startsWith("--ini=") || arg.equals("--ini")) - { ini = true; - if (arg.length() > 6) - { - arguments.addAll(loadStartIni(new File(arg.substring(6)))); - } - } - else if (arg.startsWith("--config=")) - { - _startConfig = arg.substring(9); - } - else - { - arguments.add(arg); - } - } - - // if no non-option inis, add the start.ini and start.d if (!ini) - { - arguments.addAll(0,parseStartIniFiles()); - } - - return arguments; - } - - List parseStartIniFiles() - { - List ini_args = new ArrayList(); - File start_ini = new File(_jettyHome,"start.ini"); - if (start_ini.exists()) - ini_args.addAll(loadStartIni(start_ini)); - - return ini_args; - } - - public List processCommandLine(List arguments) throws Exception - { + arguments.add("--ini=start.ini"); + // The XML Configuration Files to initialize with List xmls = new ArrayList(); - // Process the arguments - int startup = 0; - for (String arg : arguments) + // Process the arguments in for loop so list of args can be extended. + for (int i=0;i 6) + { + String name=arg.substring(6); + File file=_config.getFileBaseHomeAbs(name); + arguments.addAll(i+1,loadStartIni(file,name)); + } + + continue; + } + + + if (arg.startsWith("--config=")) + { + _startConfig = arg.substring(9); + continue; + } + + // Special internal indicator that jetty was started by the jetty.sh Daemon if ("--daemon".equals(arg)) { @@ -278,17 +268,58 @@ public class Main switch (assign.length) { case 2: - if ("OPTIONS".equals(assign[0])) + if ("_SRC_".equals(assign[0])) + { + source=assign[1].trim(); + } + else if ("DEFINE".equals(assign[0])) { String opts[] = assign[1].split(","); for (String opt : opts) - _config.addActiveOption(opt.trim()); + _config.defineOption(opt.trim()); + } + else if ("DEPEND".equals(assign[0])) + { + String opts[] = assign[1].split(","); + for (String opt : opts) + { + opt=opt.trim(); + if (!_config.getOptions().contains(opt)) + { + System.err.printf("Missing Dependency: %s DEPEND %s%n",path(source),opt ); + usageExit(ERR_LOGGING); + } + } + } + else if ("EXCLUDE".equals(assign[0])) + { + String opts[] = assign[1].split(","); + for (String opt : opts) + { + opt=opt.trim(); + if (_config.getOptions().contains(opt)) + { + System.err.printf("Excluded Dependency: %s EXCLUDE %s%n",path(source),opt ); + usageExit(ERR_LOGGING); + } + } + } + else if ("OPTION".equals(assign[0])) + { + String opts[] = assign[1].split(","); + for (String opt : opts) + _config.addOption(opt.trim()); + } + else if ("OPTIONS".equals(assign[0])) + { + this._config.setProperty(assign[0],assign[1]); } else { this._config.setProperty(assign[0],assign[1]); } break; + case 1: this._config.setProperty(assign[0],null); break; @@ -398,15 +429,7 @@ public class Main } else if (info.equals("@CONFIGS")) { - File etc = new File(System.getProperty("jetty.home","."),"etc"); - if (!etc.exists() || !etc.isDirectory()) - { - System.out.print(indent); - System.out.println("Unable to find/list " + etc); - continue; - } - - File configs[] = etc.listFiles(new FileFilter() + FileFilter filter =new FileFilter() { public boolean accept(File path) { @@ -418,35 +441,55 @@ public class Main String name = path.getName().toLowerCase(Locale.ENGLISH); return (name.startsWith("jetty") && name.endsWith(".xml")); } - }); - + }; + + // list home etc + File etc = new File(_config.getJettyHome(),"etc"); + if (!etc.exists() || !etc.isDirectory()) + { + System.out.print(indent); + System.out.println("Unable to find/list " + etc); + continue; + } List configFiles = new ArrayList(); + File[] configs = etc.listFiles(filter); configFiles.addAll(Arrays.asList(configs)); + + // list base etc + if (!_config.getJettyHome().equals(_config.getJettyBase())) + { + etc = new File(_config.getJettyBase(),"etc"); + if (etc.exists() && etc.isDirectory()) + { + configs = etc.listFiles(filter); + configFiles.addAll(Arrays.asList(configs)); + } + } + Collections.sort(configFiles); for (File configFile : configFiles) - { - System.out.print(indent); - System.out.print("etc/"); - System.out.println(configFile.getName()); - } + System.out.printf("%s%s%n",indent,path(configFile)); } else if (info.equals("@STARTINI")) { - List ini = parseStartIniFiles(); - if (ini != null && ini.size() > 0) + for (File file : _iniFiles) { - for (String a : ini) + String path=path(file); + System.out.printf("%s%s:%n",indent,path); + + try (FileReader reader=new FileReader(file); BufferedReader in = new BufferedReader(reader);) { - System.out.print(indent); - System.out.println(a); + String arg; + while ((arg = in.readLine()) != null) + { + arg = arg.trim(); + if (arg.length() == 0 || arg.startsWith("#")) + continue; + System.out.printf("%s %s%n",indent,arg); + } } } - else - { - System.out.print(indent); - System.out.println("none"); - } } } else @@ -466,6 +509,29 @@ public class Main System.exit(EXIT_USAGE); } + String path(String path) + { + if (path==null) + return path; + if (path.startsWith(_config.getJettyHome())) + path = "${jetty.home}" + path.substring(_config.getJettyHome().length()); + if (_config.getJettyBase()!=null && path.startsWith(_config.getJettyBase())) + path = "${jetty.base}" + path.substring(_config.getJettyBase().length()); + return path; + } + + String path(File file) + { + try + { + return path(file.getCanonicalPath()); + } + catch (IOException e) + { + } + return path(file.getAbsolutePath()); + } + public void invokeMain(ClassLoader classloader, String classname, List args) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { @@ -550,12 +616,13 @@ public class Main { System.err.println("java.class.path=" + System.getProperty("java.class.path")); System.err.println("jetty.home=" + System.getProperty("jetty.home")); + System.err.println("jetty.base=" + System.getProperty("jetty.base")); System.err.println("java.home=" + System.getProperty("java.home")); System.err.println("java.io.tmpdir=" + System.getProperty("java.io.tmpdir")); System.err.println("java.class.path=" + classpath); System.err.println("classloader=" + cl); System.err.println("classloader.parent=" + cl.getParent()); - System.err.println("properties=" + Config.getProperties()); + System.err.println("properties=" + _config.getProperties()); } // Show the usage information and return @@ -689,23 +756,20 @@ public class Main return xmlFilename; } - File xml = new File(xmlFilename); - if (xml.exists() && xml.isFile()) - { + // Look for the file as absolute, jetty-base or jetty-home + File xml = _config.getFileBaseHomeAbs(xmlFilename); + if (xml!=null && xml.isFile()) return xml.getAbsolutePath(); - } - - xml = new File(_jettyHome,fixPath(xmlFilename)); - if (xml.exists() && xml.isFile()) - { + + // Try corrected / for \ + xml = _config.getFileBaseHomeAbs(fixPath(xmlFilename)); + if (xml!=null && xml.isFile()) return xml.getAbsolutePath(); - } - - xml = new File(_jettyHome,fixPath("etc/" + xmlFilename)); - if (xml.exists() && xml.isFile()) - { + + // Try in etc + xml = _config.getFileBaseHomeAbs("etc/"+xmlFilename); + if (xml!=null && xml.isFile()) return xml.getAbsolutePath(); - } throw new FileNotFoundException("Unable to find XML Config: " + xmlFilename); } @@ -718,7 +782,9 @@ public class Main { cmd.addArg(x); } - cmd.addRawArg("-Djetty.home=" + _jettyHome); + cmd.addRawArg("-Djetty.home=" + _config.getJettyHome()); + if (_config.getJettyBase()!=null) + cmd.addRawArg("-Djetty.base=" + _config.getJettyBase()); // Special Stop/Shutdown properties ensureSystemPropertySet("STOP.PORT"); @@ -736,7 +802,7 @@ public class Main cmd.addRawArg(_config.getMainClassname()); // Check if we need to pass properties as a file - Properties properties = Config.getProperties(); + Properties properties = _config.getProperties(); if (properties.size() > 0) { File prop_file = File.createTempFile("start",".properties"); @@ -748,7 +814,7 @@ public class Main for (String xml : xmls) { - cmd.addRawArg(xml); + cmd.addRawArg(xml); } return cmd; } @@ -767,7 +833,7 @@ public class Main return; // done } - Properties props = Config.getProperties(); + Properties props = _config.getProperties(); if (props.containsKey(key)) { String val = props.getProperty(key,null); @@ -841,7 +907,8 @@ public class Main System.out.println("Note: If using multiple options (eg: 'Server,servlet,webapp,jms,jmx') " + "then overlapping entries will not be repeated in the eventual classpath."); System.out.println(); - System.out.printf("${jetty.home} = %s%n",_jettyHome); + System.out.printf("${jetty.home} = %s%n",_config.getJettyHome()); + System.out.printf("${jetty.base} = %s%n",_config.getJettyBase()); System.out.println(); for (String sectionId : sectionIds) @@ -876,14 +943,7 @@ public class Main int i = 0; for (File element : sectionCP.getElements()) - { - String elementPath = element.getAbsolutePath(); - if (elementPath.startsWith(_jettyHome)) - { - elementPath = "${jetty.home}" + elementPath.substring(_jettyHome.length()); - } - System.out.printf("%2d: %20s | %s\n",i++,getVersion(element),elementPath); - } + System.out.printf("%2d: %20s | %s\n",i++,getVersion(element),path(element)); System.out.println(); } @@ -894,7 +954,7 @@ public class Main // Iterate through active classpath, and fetch Implementation Version from each entry (if present) // to dump to end user. - System.out.println("Active Options: " + _config.getActiveOptions()); + System.out.println("Active Options: " + _config.getOptions()); if (classpath.count() == 0) { @@ -908,14 +968,7 @@ public class Main int i = 0; for (File element : classpath.getElements()) - { - String elementPath = element.getAbsolutePath(); - if (elementPath.startsWith(_jettyHome)) - { - elementPath = "${jetty.home}" + elementPath.substring(_jettyHome.length()); - } - System.out.printf("%2d: %20s | %s\n",i++,getVersion(element),elementPath); - } + System.out.printf("%2d: %20s | %s\n",i++,getVersion(element),path(element)); } private String fixPath(String path) @@ -1003,13 +1056,6 @@ public class Main // parse the config _config.parse(cfgstream); - _jettyHome = Config.getProperty("jetty.home",_jettyHome); - if (_jettyHome != null) - { - _jettyHome = new File(_jettyHome).getCanonicalPath(); - System.setProperty("jetty.home",_jettyHome); - } - // Collect the configured xml configurations. List ret = new ArrayList(); ret.addAll(xmls); // add command line provided xmls first. @@ -1145,17 +1191,22 @@ public class Main /** * Convert a start.ini format file into an argument list. */ - List loadStartIni(File ini) + List loadStartIni(File ini,String name) { - if (!ini.exists()) + if (ini==null || !ini.exists() || ini.isDirectory() || !ini.canRead()) { - System.err.println("Warning - can't find ini file: " + ini); + System.err.println("Warning - bad ini file: " + name); // No start.ini found, skip load. return Collections.emptyList(); } + ini=ini.getAbsoluteFile(); + if (!_iniFiles.contains(ini)) + _iniFiles.add(ini); List args = new ArrayList(); + args.add("_SRC_="+name); + FileReader reader = null; BufferedReader buf = null; try @@ -1176,11 +1227,8 @@ public class Main { try { - File start_d = new File(arg); - if (!start_d.exists() || !start_d.isDirectory()) - start_d = new File(_jettyHome,arg); - - if (start_d.isDirectory()) + File start_d = _config.getFileBaseHomeAbs(arg); + if (start_d!=null && start_d.isDirectory()) { File[] inis = start_d.listFiles(new FilenameFilter() { @@ -1193,8 +1241,9 @@ public class Main Arrays.sort(inis); for (File i : inis) - args.addAll(loadStartIni(i)); - + args.addAll(loadStartIni(i,i.getAbsolutePath())); + + args.add("_SRC_="+name); continue; } } diff --git a/jetty-start/src/main/resources/org/eclipse/jetty/start/start.config b/jetty-start/src/main/resources/org/eclipse/jetty/start/start.config index 0fffaf178ec..cd4cdf55a41 100644 --- a/jetty-start/src/main/resources/org/eclipse/jetty/start/start.config +++ b/jetty-start/src/main/resources/org/eclipse/jetty/start/start.config @@ -4,18 +4,18 @@ # # Each line contains entry in the format: # -# SUBJECT [ [!] CONDITION [AND|OR] ]* +# SUBJECT [ [!] CONDITION [AND|OR] ]* # # where SUBJECT: -# ends with ".class" is the Main class to run. -# ends with ".xml" is a configuration file for the command line -# ends with "/" is a directory from which to add all jar and zip files. -# ends with "/*" is a directory from which to add all unconsidered jar and zip files. -# ends with "/**" is a directory from which to recursively add all unconsidered jar and zip files. -# Containing = are used to assign system properties. -# Containing ~= are used to assign start properties. -# Containing /= are used to assign a canonical path. -# all other subjects are treated as files to be added to the classpath. +# ends with ".class" is the Main class to run. +# ends with ".xml" is a configuration file for the command line +# ends with "/" is a directory from which to add all jar and zip files. +# ends with "/*" is a directory from which to add all unconsidered jar and zip files. +# ends with "/**" is a directory from which to recursively add all unconsidered jar and zip files. +# Containing = are used to assign system properties. +# Containing ~= are used to assign start properties. +# Containing /= are used to assign a canonical path. +# all other subjects are treated as files to be added to the classpath. # # ${name} is expanded to a start property # $(name) is expanded to either a start property or a system property. @@ -25,15 +25,15 @@ # the home directory. # # CONDITION is one of: -# always -# never -# available classname # true if class on classpath -# property name # true if set as start property -# system name # true if set as system property -# exists file # true if file/dir exists -# java OPERATOR version # java version compared to literal -# nargs OPERATOR number # number of command line args compared to literal -# OPERATOR := one of "<",">","<=",">=","==","!=" +# always +# never +# available classname # true if class on classpath +# property name # true if set as start property +# system name # true if set as system property +# exists file # true if file/dir exists +# java OPERATOR version # java version compared to literal +# nargs OPERATOR number # number of command line args compared to literal +# OPERATOR := one of "<",">","<=",">=","==","!=" # # CONTITIONS can be combined with AND OR or !, with AND being the assume # operator for a list of CONDITIONS. @@ -45,123 +45,135 @@ # [ssl,default] # # Clauses after a section header will only be included if they match one of the tags in the -# options property. By default options are set to "default,*" or the OPTIONS property may +# options property. By default options are set to "default,*" or the OPTIONS property may # be used to pass in a list of tags, eg. : # -# java -jar start.jar OPTIONS=jetty,jsp,ssl +# java -jar start.jar OPTIONS=jetty,jsp,ssl # # The tag '*' is always appended to the options, so any section with the * tag is always # applied. # # add a property defined classpath -${path}.path property path +${path}.path property path # add a property defined library directory -${lib}/** exists ${lib} +${lib}/** exists ${lib} # Try different settings of jetty.home until the start.jar is found. -jetty.home=. ! exists $(jetty.home)/start.jar -jetty.home=.. ! exists $(jetty.home)/start.jar -jetty.home=jetty-distribution/src/main/resources ! exists $(jetty.home)/start.jar -jetty.home=../jetty-distribution/src/main/resources ! exists $(jetty.home)/start.jar -jetty.home=. ! exists $(jetty.home)/start.jar -jetty.home/=$(jetty.home) exists $(jetty.home)/start.jar +jetty.home=. ! exists $(jetty.home)/start.jar +jetty.home=.. ! exists $(jetty.home)/start.jar +jetty.home=jetty-distribution/src/main/resources ! exists $(jetty.home)/start.jar +jetty.home=../jetty-distribution/src/main/resources ! exists $(jetty.home)/start.jar +jetty.home=. ! exists $(jetty.home)/start.jar +jetty.home/=$(jetty.home) exists $(jetty.home)/start.jar + +# Set the jetty.base property +jetty.base=$(jetty.base) system jetty.base # The main class to run org.eclipse.jetty.xml.XmlConfiguration.class -${start.class}.class property start.class +${start.class}.class property start.class # The default configuration files -$(jetty.home)/etc/jetty.xml nargs == 0 -./jetty-server/src/main/config/etc/jetty.xml nargs == 0 AND ! exists $(jetty.home)/etc/jetty.xml +$(jetty.base)/etc/jetty.xml nargs == 0 AND property jetty.base +$(jetty.home)/etc/jetty.xml nargs == 0 +./jetty-server/src/main/config/etc/jetty.xml nargs == 0 AND ! exists $(jetty.home)/etc/jetty.xml # Default OPTIONS if not specified on the command line -OPTIONS~=default,* ! property OPTIONS +OPTIONS~=default,* ! property OPTIONS # Add a resources directory if it is there [All,resources,default] +$(jetty.base)/resources/ property jetty.base $(jetty.home)/resources/ - + # Add jetty modules [*] -$(jetty.home)/lib/jetty-util-$(version).jar ! available org.eclipse.jetty.util.StringUtil -$(jetty.home)/lib/jetty-io-$(version).jar ! available org.eclipse.jetty.io.Buffer +$(jetty.home)/lib/jetty-util-$(version).jar ! available org.eclipse.jetty.util.StringUtil +$(jetty.home)/lib/jetty-io-$(version).jar ! available org.eclipse.jetty.io.Buffer [Server,All,xml,default] -$(jetty.home)/lib/jetty-xml-$(version).jar ! available org.eclipse.jetty.xml.XmlParser - +$(jetty.home)/lib/jetty-xml-$(version).jar ! available org.eclipse.jetty.xml.XmlParser + [Server,All,server,default] -$(jetty.home)/lib/servlet-api-3.1.jar ! available javax.servlet.ServletContext -$(jetty.home)/lib/jetty-schemas-3.1.jar -$(jetty.home)/lib/jetty-http-$(version).jar ! available org.eclipse.jetty.http.HttpParser -$(jetty.home)/lib/jetty-continuation-$(version).jar ! available org.eclipse.jetty.continuation.Continuation -$(jetty.home)/lib/jetty-server-$(version).jar ! available org.eclipse.jetty.server.Server - +$(jetty.home)/lib/servlet-api-3.1.jar ! available javax.servlet.ServletContext +$(jetty.home)/lib/jetty-schemas-3.1.jar +$(jetty.home)/lib/jetty-http-$(version).jar ! available org.eclipse.jetty.http.HttpParser +$(jetty.home)/lib/jetty-continuation-$(version).jar ! available org.eclipse.jetty.continuation.Continuation +$(jetty.home)/lib/jetty-server-$(version).jar ! available org.eclipse.jetty.server.Server + [Server,All,security,default] -$(jetty.home)/lib/jetty-security-$(version).jar ! available org.eclipse.jetty.security.LoginService - +$(jetty.home)/lib/jetty-security-$(version).jar ! available org.eclipse.jetty.security.LoginService + [Server,All,servlet,default] -$(jetty.home)/lib/servlet-api-3.0.jar ! available javax.servlet.ServletContext -$(jetty.home)/lib/jetty-servlet-$(version).jar ! available org.eclipse.jetty.servlet.ServletHandler +$(jetty.home)/lib/servlet-api-3.0.jar ! available javax.servlet.ServletContext +$(jetty.home)/lib/jetty-servlet-$(version).jar ! available org.eclipse.jetty.servlet.ServletHandler [servlets] -$(jetty.home)/lib/jetty-servlets-$(version).jar ! available org.eclipse.jetty.servlets.MultiPartFilter - +$(jetty.home)/lib/jetty-servlets-$(version).jar ! available org.eclipse.jetty.servlets.MultiPartFilter + [Server,All,webapp,default] -$(jetty.home)/lib/jetty-webapp-$(version).jar ! available org.eclipse.jetty.webapp.WebAppContext - +$(jetty.home)/lib/jetty-webapp-$(version).jar ! available org.eclipse.jetty.webapp.WebAppContext + [Server,All,deploy,default] -$(jetty.home)/lib/jetty-deploy-$(version).jar ! available org.eclipse.jetty.deploy.ContextDeployer - +$(jetty.home)/lib/jetty-deploy-$(version).jar ! available org.eclipse.jetty.deploy.ContextDeployer + [All,rewrite] -$(jetty.home)/lib/jetty-rewrite-$(version).jar ! available org.eclipse.jetty.rewrite.handler.RewriteHandler +$(jetty.home)/lib/jetty-rewrite-$(version).jar ! available org.eclipse.jetty.rewrite.handler.RewriteHandler [All,jmx] -$(jetty.home)/lib/jetty-jmx-$(version).jar ! available org.eclipse.jetty.jmx.MBeanContainer - +$(jetty.home)/lib/jetty-jmx-$(version).jar ! available org.eclipse.jetty.jmx.MBeanContainer + [All,ajp] -$(jetty.home)/lib/jetty-ajp-$(version).jar ! available org.eclipse.jetty.ajp.Ajp13Connection - +$(jetty.home)/lib/jetty-ajp-$(version).jar ! available org.eclipse.jetty.ajp.Ajp13Connection + [All,plus,jndi] -$(jetty.home)/lib/jetty-jndi-${version}.jar ! available org.eclipse.jetty.jndi.ContextFactory -$(jetty.home)/lib/jetty-plus-${version}.jar ! available org.eclipse.jetty.plus.jndi.NamingEntry -$(jetty.home)/lib/jndi/** exists $(jetty.home)/lib/jndi +$(jetty.home)/lib/jetty-jndi-${version}.jar ! available org.eclipse.jetty.jndi.ContextFactory +$(jetty.home)/lib/jetty-plus-${version}.jar ! available org.eclipse.jetty.plus.jndi.NamingEntry +$(jetty.home)/lib/jndi/** exists $(jetty.home)/lib/jndi [All,jaas] -$(jetty.home)/lib/jetty-jaas-${version}.jar ! available org.eclipse.jetty.jaas.JAASLoginService +$(jetty.home)/lib/jetty-jaas-${version}.jar ! available org.eclipse.jetty.jaas.JAASLoginService [All,annotations] -$(jetty.home)/lib/jetty-annotations-$(version).jar ! available org.eclipse.jetty.annotations.AnnotationParser -$(jetty.home)/lib/annotations/** exists $(jetty.home)/lib/annotations - +$(jetty.home)/lib/jetty-annotations-$(version).jar ! available org.eclipse.jetty.annotations.AnnotationParser +$(jetty.home)/lib/annotations/** exists $(jetty.home)/lib/annotations + [All,setuid] -$(jetty.home)/lib/jetty-setuid-$(version).jar ! available org.eclipse.jetty.setuid.SetUID -$(jetty.home)/lib/setuid/** - +$(jetty.home)/lib/jetty-setuid-$(version).jar ! available org.eclipse.jetty.setuid.SetUID +$(jetty.home)/lib/setuid/** + [All,policy] -$(jetty.home)/lib/jetty-policy-$(version).jar ! available org.eclipse.jetty.policy.JettyPolicy - +$(jetty.home)/lib/jetty-policy-$(version).jar ! available org.eclipse.jetty.policy.JettyPolicy + [All,client] -$(jetty.home)/lib/jetty-http-$(version).jar ! available org.eclipse.jetty.http.HttpParser -$(jetty.home)/lib/jetty-client-$(version).jar ! available org.eclipse.jetty.client.HttpClient +$(jetty.home)/lib/jetty-http-$(version).jar ! available org.eclipse.jetty.http.HttpParser +$(jetty.home)/lib/jetty-client-$(version).jar ! available org.eclipse.jetty.client.HttpClient [All,proxy] -$(jetty.home)/lib/jetty-proxy-$(version).jar ! available org.eclipse.jetty.proxy.ConnectHandler +$(jetty.home)/lib/jetty-proxy-$(version).jar ! available org.eclipse.jetty.proxy.ConnectHandler $(jetty.home)/lib/jetty-http-$(version).jar ! available org.eclipse.jetty.http.HttpParser -$(jetty.home)/lib/jetty-client-$(version).jar ! available org.eclipse.jetty.client.HttpClient +$(jetty.home)/lib/jetty-client-$(version).jar ! available org.eclipse.jetty.client.HttpClient [All,websocket] $(jetty.home)/lib/websocket/** - + [All,overlay,overlays] -$(jetty.home)/lib/jetty-overlay-deployer-$(version).jar ! available org.eclipse.jetty.overlay.OverlayedAppProvider - - +$(jetty.home)/lib/jetty-overlay-deployer-$(version).jar ! available org.eclipse.jetty.overlay.OverlayedAppProvider + + # Add ext if it exists -[Server,All,default,ext] +[Server,All,default,ext] +$(jetty.base)/lib/ext/** property jetty.base $(jetty.home)/lib/ext/** # Add all other sub-directories in /lib/ as options in a dynamic way -[All,=$(jetty.home)/lib/**] +[All,=$(jetty.base)/lib/**] +[All,=$(jetty.home)/lib/**] + +# Set property jetty.base and jetty.log as jetty.home if not set +jetty.base=${jetty.home} ! property jetty.base +jetty.logs=${jetty.base}/logs ! property jetty.logs + 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 e25a73d277c..d4109317082 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 @@ -76,13 +76,20 @@ System Properties: com.sun.management.jmxremote Enable remote JMX management in Sun JVMS. - Properties: These are set with a command line like "java -jar start.jar name=value" and only affect the start mechanism. Some of these are defined in the default start.config and will not be available if another configuration file is used. NOTE: Not all properties are listed here: + jetty.home=[directory] + Set the home directory of the jetty distribtion. + + jetty.base=[directory] + Set the jetty configuration directory. This is where the etc, webapps and start + files will be looked for. If not found in jetty.base, they are looked for in + jetty.home. + path=[directory] An additional class path element to add to the started class path. Typically this is used to add directories of classes and/or resources @@ -120,8 +127,8 @@ Properties: Available Configurations: - By convention, configuration files are kept in $JETTY_HOME/etc. - The known configuration files are: + By convention, configuration files are kept in ${jetty.base}/etc or + ${jetty.home}/etc The known configuration files are: @CONFIGS@ @@ -135,6 +142,6 @@ Defaults: If --ini options are provided on the command line, then start.ini will NOT be read. - The current start.ini arguments are: + The current start.ini files are: @STARTINI@ diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigTest.java index 59bbeaa74d8..6432e148e13 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigTest.java @@ -100,7 +100,6 @@ public class ConfigTest @Before public void reset() { - Config.clearProperties(); } /* @@ -115,7 +114,7 @@ public class ConfigTest Config cfg = new Config(); cfg.parse(buf); - Assert.assertEquals(getTestResourcesDir().getCanonicalPath(),Config.getProperty("test.resources.dir")); + Assert.assertEquals(getTestResourcesDir().getCanonicalPath(),cfg.getProperty("test.resources.dir")); } /* @@ -131,8 +130,8 @@ public class ConfigTest Config options = new Config(); options.parse(buf); - Assert.assertEquals("foo",Config.getProperty("test.jetty.start.text")); - Assert.assertEquals("Eatagramovabits",Config.getProperty("test.jetty.start.quote")); + Assert.assertEquals("foo",options.getProperty("test.jetty.start.text")); + Assert.assertEquals("Eatagramovabits",options.getProperty("test.jetty.start.quote")); } /* 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 4d399c04731..c4243260afe 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 @@ -30,9 +30,11 @@ import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; +import java.util.Set; import java.util.Vector; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; +import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; @@ -52,42 +54,19 @@ public class MainTest System.setProperty("jetty.home",testJettyHome.getAbsolutePath()); } - @Test - public void testLoadStartIni() throws IOException - { - Main main = new Main(); - List args = main.parseStartIniFiles(); - - assertEquals("Expected 5 uncommented lines in start.ini",9,args.size()); - assertEquals("First uncommented line in start.ini doesn't match expected result","OPTIONS=Server,jsp,resources,websocket,ext",args.get(0)); - assertEquals("Last uncommented line in start.ini doesn't match expected result","etc/jetty-contexts.xml",args.get(8)); - } - - @Test - public void testExpandCommandLine() throws Exception - { - Main main = new Main(); - List args = main.expandCommandLine(new String[] {}); - - assertEquals("start.ini OPTIONS","OPTIONS=Server,jsp,resources,websocket,ext",args.get(0)); - assertEquals("start.d/jmx OPTIONS","OPTIONS=jmx",args.get(2)); - assertEquals("start.d/jmx XML","etc/jetty-jmx.xml",args.get(3)); - assertEquals("start.d/websocket OPTIONS","OPTIONS=websocket",args.get(4)); - } - @Test public void testProcessCommandLine() throws Exception { Main main = new Main(); - List args = main.expandCommandLine(new String[] {}); - List xmls = main.processCommandLine(args); + List xmls = main.processCommandLine(new String[] {}); - System.err.println(args); - System.err.println(xmls); assertEquals("etc/jetty.xml",xmls.get(0)); assertEquals("etc/jetty-jmx.xml",xmls.get(1)); assertEquals("start.d","etc/jetty-testrealm.xml",xmls.get(2)); assertEquals("start.d","etc/jetty-contexts.xml",xmls.get(5)); + + Set options = main.getConfig().getOptions(); + assertThat(options,Matchers.contains("Server","ext","jmx","jsp","newOption","resources","websocket")); } @Test diff --git a/jetty-start/src/test/resources/jetty.home/start.d/10-jmx.ini b/jetty-start/src/test/resources/jetty.home/start.d/10-jmx.ini index 356fccd3906..c0a6f7cb959 100644 --- a/jetty-start/src/test/resources/jetty.home/start.d/10-jmx.ini +++ b/jetty-start/src/test/resources/jetty.home/start.d/10-jmx.ini @@ -9,7 +9,7 @@ #=========================================================== #----------------------------------------------------------- -OPTIONS=jmx +OPTION=jmx #----------------------------------------------------------- diff --git a/jetty-start/src/test/resources/jetty.home/start.d/20-websocket.ini b/jetty-start/src/test/resources/jetty.home/start.d/20-websocket.ini index 679a221dd71..f83b2b56906 100644 --- a/jetty-start/src/test/resources/jetty.home/start.d/20-websocket.ini +++ b/jetty-start/src/test/resources/jetty.home/start.d/20-websocket.ini @@ -9,5 +9,6 @@ #=========================================================== #----------------------------------------------------------- -OPTIONS=websocket +DEPEND=Server +OPTION=websocket #----------------------------------------------------------- \ No newline at end of file diff --git a/jetty-start/src/test/resources/jetty.home/start.ini b/jetty-start/src/test/resources/jetty.home/start.ini index eda5499d5cb..e00a8c72d1e 100644 --- a/jetty-start/src/test/resources/jetty.home/start.ini +++ b/jetty-start/src/test/resources/jetty.home/start.ini @@ -6,71 +6,13 @@ #=========================================================== - -#=========================================================== -# 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) -# -# Below are some recommended options for Sun's JRE -#----------------------------------------------------------- -# --exec -# -Dorg.apache.jasper.compiler.disablejsr199=true -# -Dcom.sun.management.jmxremote -# -Dorg.eclipse.jetty.util.log.IGNORED=true -# -Dorg.eclipse.jetty.util.log.stderr.DEBUG=true -# -Dorg.eclipse.jetty.util.log.stderr.SOURCE=true -# -Xmx2000m -# -Xmn512m -# -verbose:gc -# -XX:+PrintGCDateStamps -# -XX:+PrintGCTimeStamps -# -XX:+PrintGCDetails -# -XX:+PrintTenuringDistribution -# -XX:+PrintCommandLineFlags -# -XX:+DisableExplicitGC -# -XX:+UseConcMarkSweepGC -# -XX:ParallelCMSThreads=2 -# -XX:+CMSClassUnloadingEnabled -# -XX:+UseCMSCompactAtFullCollection -# -XX:CMSInitiatingOccupancyFraction=80 -#----------------------------------------------------------- - - -#=========================================================== -# Start classpath OPTIONS. -# These control what classes are on the classpath -# for a full listing do -# java -jar start.jar --list-options -# -# Enable classpath OPTIONS. Each options represents one or more jars -# to be added to the classpath. The options can be listed with --help -# or --list-options. -# By convention, options starting with a capital letter (eg Server) -# are aggregations of other available options. -# Directories in $JETTY_HOME/lib can be added as dynamic OPTIONS by -# convention. E.g. put some logging jars in $JETTY_HOME/lib/logging -# and make them available in the classpath by adding a "logging" OPTION -# like so: OPTIONS=Server,jsp,logging -#----------------------------------------------------------- OPTIONS=Server,jsp,resources,websocket,ext -#----------------------------------------------------------- - - -#=========================================================== -# Configuration files. -# For a full list of available configuration files do -# java -jar start.jar --help -#----------------------------------------------------------- etc/jetty.xml start.d/ -# etc/jetty-ssl.xml -# etc/jetty-requestlog.xml etc/jetty-deploy.xml -#etc/jetty-overlay.xml etc/jetty-webapps.xml etc/jetty-contexts.xml -#=========================================================== + +DEFINE=newOption +OPTION=newOption +DEPEND=newOption \ No newline at end of file