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