Adding dynamic OPTIONS options discovery.

* Adding new dynamic classpath section identifier using syntax discussed
  on irc.  [=path_to_dir/*]

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@704 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Joakim Erdfelt 2009-08-12 20:14:54 +00:00
parent 536e5522c8
commit 0f56762ce8
2 changed files with 63 additions and 19 deletions

View File

@ -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;
* </p>
*
* <p>
* Note: a special discovered section identifier <code>[=path_to_directory/*]</code> 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.
* </p>
*
* <p>
* 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. :
* </p>
@ -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<String> sections = new ArrayList<String>();
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<String> 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)

View File

@ -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/*]