From 3f2706f1594928809a8345a4982ecfd380005e11 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 11 Aug 2009 02:28:58 +0000 Subject: [PATCH] Updating start.jar to have OPTIONS default in start.config. git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@681 7e9141cc-0065-0410-87d8-b60c137991c4 --- .../java/org/eclipse/jetty/start/Config.java | 299 +++++++++++------- .../java/org/eclipse/jetty/start/Main.java | 40 +-- .../org/eclipse/jetty/start/start.config | 3 +- 3 files changed, 202 insertions(+), 140 deletions(-) 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 2ea5a995653..c4a2e367861 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 @@ -36,6 +36,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -164,6 +165,22 @@ public class Config private List _xml = new ArrayList(); private Set _policies = new HashSet(); private String _classname = null; + private Set _activeOptions = new TreeSet(new Comparator() + { + // Make sure "*" is always at the end of the list + public int compare(String o1, String o2) + { + if ("*".equals(o1)) + { + return 1; + } + if ("*".equals(o2)) + { + return -1; + } + return o1.compareTo(o2); + } + }); private Map _properties = new HashMap(); private int argCount = 0; @@ -335,6 +352,17 @@ public class Config return _classpaths.get(DEFAULT_SECTION); } + /** + * Get the active classpath, as dictated by OPTIONS= entries. + * + * @return the Active classpath + * @see #getCombinedClasspath(Collection) + */ + public Classpath getActiveClasspath() + { + return getCombinedClasspath(_activeOptions); + } + /** * Get the combined classpath representing the default classpath plus all named sections. * @@ -434,7 +462,7 @@ public class Config } catch (ClassNotFoundException e) { - debug(e); + debug("ClassNotFoundException (parent class loader): " + classname); } // Try section classloaders instead @@ -462,7 +490,7 @@ public class Config } catch (ClassNotFoundException e) { - debug(e); + debug("ClassNotFoundException (section class loader: " + sectionId + "): " + classname); } } return false; @@ -644,115 +672,123 @@ public class Config String value = fixPath(file.substring(i + 2)); debug(" " + property + "~=" + value); setProperty(property,value); + continue; } - else - // Setting of start property with canonical path - if (subject.indexOf("/=") > 0) + + // Setting of start property with canonical path + if (subject.indexOf("/=") > 0) + { + int i = file.indexOf("/="); + String property = file.substring(0,i); + String value = fixPath(file.substring(i + 2)); + String canonical = new File(value).getCanonicalPath(); + debug(" " + property + "/=" + value + "==" + canonical); + setProperty(property,canonical); + continue; + } + + // Setting of system property + if (subject.indexOf("=") > 0) + { + int i = file.indexOf("="); + String property = file.substring(0,i); + String value = fixPath(file.substring(i + 1)); + debug(" " + property + "=" + value); + System.setProperty(property,value); + continue; + } + + // Add all unconsidered JAR and ZIP files to classpath + if (subject.endsWith("/*")) + { + // directory of JAR files - only add jars and zips within the directory + File dir = new File(fixPath(file.substring(0,file.length() - 1))); + addJars(sections,dir,false); + continue; + } + + // Recursively add all unconsidered JAR and ZIP files to classpath + if (subject.endsWith("/**")) + { + //directory hierarchy of jar files - recursively add all jars and zips in the hierarchy + File dir = new File(fixPath(file.substring(0,file.length() - 2))); + addJars(sections,dir,true); + continue; + } + + // Add raw classpath directory to classpath + if (subject.endsWith("/")) + { + // class directory + File cd = new File(fixPath(file)); + String d = cd.getCanonicalPath(); + boolean added = addClasspathComponent(sections,d); + debug((added?" CLASSPATH+=":" !") + d); + continue; + } + + // Add XML configuration + if (subject.toLowerCase().endsWith(".xml")) + { + // Config file + File f = new File(fixPath(file)); + if (f.exists()) + _xml.add(f.getCanonicalPath()); + debug(" ARGS+=" + f); + continue; + } + + // Set the main class to execute (overrides any previously set) + if (subject.toLowerCase().endsWith(".class")) + { + // Class + String cn = expand(subject.substring(0,subject.length() - 6)); + if (cn != null && cn.length() > 0) { - int i = file.indexOf("/="); - String property = file.substring(0,i); - String value = fixPath(file.substring(i + 2)); - String canonical = new File(value).getCanonicalPath(); - debug(" " + property + "/=" + value + "==" + canonical); - setProperty(property,canonical); + debug(" CLASS=" + cn); + _classname = cn; } - else - // Setting of system property - if (subject.indexOf("=") > 0) - { - int i = file.indexOf("="); - String property = file.substring(0,i); - String value = fixPath(file.substring(i + 1)); - debug(" " + property + "=" + value); - System.setProperty(property,value); - } - else - // Add all unconsidered JAR and ZIP files to classpath - if (subject.endsWith("/*")) - { - // directory of JAR files - only add jars and zips within the directory - File dir = new File(fixPath(file.substring(0,file.length() - 1))); - addJars(sections,dir,false); - } - else - // Recursively add all unconsidered JAR and ZIP files to classpath - if (subject.endsWith("/**")) - { - //directory hierarchy of jar files - recursively add all jars and zips in the hierarchy - File dir = new File(fixPath(file.substring(0,file.length() - 2))); - addJars(sections,dir,true); - } - else - // Add raw classpath directory to classpath - if (subject.endsWith("/")) - { - // class directory - File cd = new File(fixPath(file)); - String d = cd.getCanonicalPath(); - boolean added = addClasspathComponent(sections,d); - debug((added?" CLASSPATH+=":" !") + d); - } - else - // Add XML configuration - if (subject.toLowerCase().endsWith(".xml")) - { - // Config file - File f = new File(fixPath(file)); - if (f.exists()) - _xml.add(f.getCanonicalPath()); - debug(" ARGS+=" + f); - } - else - // Set the main class to execute (overrides any previously set) - if (subject.toLowerCase().endsWith(".class")) - { - // Class - String cn = expand(subject.substring(0,subject.length() - 6)); - if (cn != null && cn.length() > 0) - { - debug(" CLASS=" + cn); - _classname = cn; - } - } - else - // Add raw classpath entry - if (subject.toLowerCase().endsWith(".path")) - { - // classpath (jetty.class.path?) to add to runtime classpath - String cn = expand(subject.substring(0,subject.length() - 5)); - if (cn != null && cn.length() > 0) - { - debug(" PATH=" + cn); - addClasspathPath(sections,cn); - } - } - else - // Add Security Policy file reference - if (subject.toLowerCase().endsWith(".policy")) - { - //policy file to parse - String cn = expand(subject.substring(0,subject.length())); - if (cn != null && cn.length() > 0) - { - debug(" POLICY=" + cn); - _policies.add(fixPath(cn)); - } - } - else - { - // single JAR file - File f = new File(fixPath(file)); - if (f.exists()) - { - String d = f.getCanonicalPath(); - boolean added = addClasspathComponent(sections,d); - if (!added) - { - added = addClasspathPath(sections,expand(subject)); - } - debug((added?" CLASSPATH+=":" !") + d); - } - } + continue; + } + + // Add raw classpath entry + if (subject.toLowerCase().endsWith(".path")) + { + // classpath (jetty.class.path?) to add to runtime classpath + String cn = expand(subject.substring(0,subject.length() - 5)); + if (cn != null && cn.length() > 0) + { + debug(" PATH=" + cn); + addClasspathPath(sections,cn); + } + continue; + } + + // Add Security Policy file reference + if (subject.toLowerCase().endsWith(".policy")) + { + //policy file to parse + String cn = expand(subject.substring(0,subject.length())); + if (cn != null && cn.length() > 0) + { + debug(" POLICY=" + cn); + _policies.add(fixPath(cn)); + } + continue; + } + + // single JAR file + File f = new File(fixPath(file)); + if (f.exists()) + { + String d = f.getCanonicalPath(); + boolean added = addClasspathComponent(sections,d); + if (!added) + { + added = addClasspathPath(sections,expand(subject)); + } + debug((added?" CLASSPATH+=":" !") + d); + } } catch (Exception e) { @@ -800,6 +836,15 @@ public class Config { DEBUG = Boolean.parseBoolean(value); } + if (name.equals("OPTIONS")) + { + _activeOptions.clear(); + String ids[] = value.split(","); + for (String id : ids) + { + _activeOptions.add(id); + } + } _properties.put(name,value); } @@ -818,4 +863,42 @@ public class Config throw new ClassCastException("Unable to cast to " + Policy.class.getName() + " : " + policyClass.getClass().getName()); } + + public void addActiveOption(String option) + { + _activeOptions.add(option); + setProperty("OPTIONS",join(_activeOptions,",")); + } + + public Set getActiveOptions() + { + if (!_activeOptions.isEmpty()) + { + _activeOptions.add("*"); + } + return _activeOptions; + } + + public void removeActiveOption(String option) + { + _activeOptions.remove(option); + setProperty("OPTIONS",join(_activeOptions,",")); + } + + private String join(Collection coll, String delim) + { + StringBuffer buf = new StringBuffer(); + + Iterator i = coll.iterator(); + boolean hasNext = i.hasNext(); + while (hasNext) + { + buf.append(String.valueOf(i.next())); + hasNext = i.hasNext(); + if (hasNext) + buf.append(delim); + } + + return buf.toString(); + } } 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 2a2c9575e40..d990db79741 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 @@ -59,7 +59,6 @@ public class Main private boolean _dryRun = false; private boolean _secure = false; private boolean _fromDaemon = false; - private List _activeOptions = new ArrayList(); private Config _config = new Config(); private String _jettyHome; @@ -98,8 +97,8 @@ public class Main if ("--stop".equals(arg)) { - int port = Integer.parseInt(_config.getProperty("STOP.PORT","-1")); - String key = _config.getProperty("STOP.KEY",null); + int port = Integer.parseInt(System.getProperty("STOP.PORT","-1")); + String key = System.getProperty("STOP.KEY",null); stop(port,key); return; } @@ -185,12 +184,8 @@ public class Main String ids[] = prop[1].split(","); for (String id : ids) { - if (!_activeOptions.contains(id)) - { - _activeOptions.add(id); - } + _config.addActiveOption(id); } - _activeOptions.addAll(Arrays.asList(ids)); } else { @@ -464,18 +459,11 @@ public class Main // Setup Start / Stop Monitoring startMonitor(); - // Default options (if not specified) - if (_activeOptions.isEmpty()) - { - _activeOptions.add("default"); - _activeOptions.add("*"); - } - // Add mandatory options for secure mode if (_secure) { - addMandatoryOption("secure"); - addMandatoryOption("security"); + _config.addActiveOption("secure"); + _config.addActiveOption("security"); } // Default XMLs (if not specified) @@ -497,7 +485,7 @@ public class Main xmls = resolveXmlConfigs(xmls); // Get Desired Classpath based on user provided Active Options. - Classpath classpath = _config.getCombinedClasspath(_activeOptions); + Classpath classpath = _config.getActiveClasspath(); System.setProperty("java.class.path",classpath.toString()); ClassLoader cl = classpath.getClassLoader(); @@ -595,14 +583,6 @@ public class Main throw new FileNotFoundException("Unable to find XML Config: " + xmlFilename); } - private void addMandatoryOption(String id) - { - if (!_activeOptions.contains(id)) - { - _activeOptions.add(id); - } - } - private void showDryRun(Classpath classpath, List xmls) { StringBuffer cmd = new StringBuffer(); @@ -732,7 +712,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: " + _activeOptions); + System.out.println("Active Options: " + _config.getActiveOptions()); if (classpath.count() == 0) { @@ -833,7 +813,7 @@ public class Main _config.setArgCount(xmls.size()); // What start.config should we use? - String cfgName = _config.getProperty("START","org/eclipse/jetty/start/start.config"); + String cfgName = System.getProperty("START","org/eclipse/jetty/start/start.config"); Config.debug("config=" + cfgName); // Look up config as resource first. @@ -866,8 +846,8 @@ public class Main private void startMonitor() { - int port = Integer.parseInt(_config.getProperty("STOP.PORT","-1")); - String key = _config.getProperty("STOP.KEY",null); + int port = Integer.parseInt(System.getProperty("STOP.PORT","-1")); + String key = System.getProperty("STOP.KEY",null); Monitor.monitor(port,key); } 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 0104f8e73f6..ecfda3f3173 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 @@ -76,7 +76,7 @@ ${start.class}.class property start.class $(jetty.home)/etc/jetty.xml nargs == 0 ./jetty-server/src/main/config/etc/jetty.xml nargs == 0 AND ! exists $(jetty.home)/etc/jetty.xml - +OPTIONS~=default,* ! property OPTIONS # Add a ext lib directory if it is there [All,ext,default] @@ -149,4 +149,3 @@ $(jetty.home)/lib/security/jetty-policy-$(version).jar $(jetty.home)/lib/security/jetty.policy always -