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 c4a2e367861..8bcb36ea933 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 @@ -18,6 +18,7 @@ package org.eclipse.jetty.start; import java.io.BufferedReader; import java.io.File; +import java.io.FileFilter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -120,6 +121,11 @@ import java.util.TreeSet; *

* *

+ * Note: a special discovered section identifier [=path_to_directory/*] is allowed to auto-create section + * IDs, based on directory names found in the path specified in the "path_to_directory/" part of the identifier. + *

+ * + *

* 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 be used to pass in a list of tags, eg. : *

@@ -554,15 +560,26 @@ public class Config // handle options if (trim.startsWith("[") && trim.endsWith("]")) { - sections = Arrays.asList(trim.substring(1,trim.length() - 1).split(",")); - // Ensure section classpaths exist - for (String sectionId : sections) + String identifier = trim.substring(1,trim.length() - 1); + if (identifier.charAt(0) == '=') { - if (!_classpaths.containsKey(sectionId)) + // Special case: dynamic/discovered option section identifier. + processDynamicSectionIdentifier(identifier.substring(1)); + } + else + { + // Normal case: section identifier (possibly separated by commas) + sections = Arrays.asList(identifier.split(",")); + // Ensure section classpaths exist + for (String sectionId : sections) { - _classpaths.put(sectionId,new Classpath()); + if (!_classpaths.containsKey(sectionId)) + { + _classpaths.put(sectionId,new Classpath()); + } } } + continue; } try @@ -803,6 +820,37 @@ public class Config } } + private void processDynamicSectionIdentifier(String dynamicPathId) throws IOException + { + if (!dynamicPathId.endsWith("/*")) + { + String msg = "Dynamic Section IDs must end in \"/*\" to work. Ignoring: [=" + dynamicPathId + "]"; + System.err.println(msg); + throw new IOException(msg); + } + + String rawPath = fixPath(dynamicPathId.substring(0,dynamicPathId.length() - 1)); + File parentDir = new File(expand(rawPath)); + debug("Adding dynamic section entries based on path: " + parentDir); + File dirs[] = parentDir.listFiles(new FileFilter() + { + public boolean accept(File path) + { + return path.isDirectory(); + } + }); + + List sections = new ArrayList(); + for (File dir : dirs) + { + sections.clear(); + sections.add("All"); + String id = dir.getName(); + sections.add(id); + addJars(sections,dir,false); + } + } + private String fixPath(String path) { return path.replace('/',File.separatorChar); @@ -842,7 +890,7 @@ public class Config String ids[] = value.split(","); for (String id : ids) { - _activeOptions.add(id); + addActiveOption(id); } } _properties.put(name,value); @@ -866,23 +914,22 @@ public class Config public void addActiveOption(String option) { - _activeOptions.add(option); - setProperty("OPTIONS",join(_activeOptions,",")); + if (!_activeOptions.contains(option)) + { + _activeOptions.add(option); + } + _properties.put("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,",")); + _properties.put("OPTIONS",join(_activeOptions,",")); } private String join(Collection coll, String delim) 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 ecfda3f3173..e439654e3b1 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,6 +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 +# Default OPTIONS if not specified on the command line OPTIONS~=default,* ! property OPTIONS # Add a ext lib directory if it is there @@ -125,12 +126,6 @@ $(jetty.home)/lib/jetty-jmx-$(version).jar [All,ajp] $(jetty.home)/lib/jetty-ajp-$(version).jar ! available org.eclipse.jetty.ajp.Ajp13Connection -[All,slf4j] -$(jetty.home)/lib/slf4j/** exists $(jetty.home)/lib/slf4j - -[All,jsp,jsp-2.1] -$(jetty.home)/lib/jsp-2.1/** exists $(jetty.home)/lib/jsp-2.1 - [All,plus] $(jetty.home)/lib/jetty-jndi-${version}.jar ! available org.eclipse.jetty.jndi.ContextFactory $(jetty.home)/lib/jetty-jndi/** exists $(jetty.home)/lib/jetty-jndi @@ -148,4 +143,6 @@ $(jetty.home)/lib/jetty-client-$(version).jar $(jetty.home)/lib/security/jetty-policy-$(version).jar ! available org.eclipse.jetty.policy.JettyPolicy $(jetty.home)/lib/security/jetty.policy always +# Add all other sub-directories in /lib/ as options in a dynamic way +[=$(jetty.home)/lib/*]