jetty-start / HomeBase -> BaseHome and fix to ini expansion order
This commit is contained in:
parent
8e66da396e
commit
f08aa88fbd
|
@ -36,19 +36,19 @@ import java.util.Objects;
|
|||
* <p>
|
||||
* The <code>${jetty.base}</code> directory is where the execution specific configuration and webapps are obtained from.
|
||||
*/
|
||||
public class HomeBase
|
||||
public class BaseHome
|
||||
{
|
||||
private File homeDir;
|
||||
private File baseDir;
|
||||
|
||||
public HomeBase()
|
||||
public BaseHome()
|
||||
{
|
||||
String userDir = System.getProperty("user.dir");
|
||||
this.homeDir = new File(System.getProperty("jetty.home",userDir));
|
||||
this.baseDir = new File(System.getProperty("jetty.base",homeDir.getAbsolutePath()));
|
||||
}
|
||||
|
||||
public HomeBase(File homeDir, File baseDir)
|
||||
public BaseHome(File homeDir, File baseDir)
|
||||
{
|
||||
this.homeDir = homeDir;
|
||||
this.baseDir = baseDir==null?homeDir:baseDir;
|
||||
|
@ -259,12 +259,7 @@ public class HomeBase
|
|||
return path;
|
||||
}
|
||||
|
||||
String value = homeDir.getAbsolutePath();
|
||||
|
||||
if (path.startsWith(value))
|
||||
{
|
||||
return "${jetty.home}" + path.substring(value.length());
|
||||
}
|
||||
String value;
|
||||
|
||||
if (isBaseDifferent())
|
||||
{
|
||||
|
@ -274,6 +269,14 @@ public class HomeBase
|
|||
return "${jetty.base}" + path.substring(value.length());
|
||||
}
|
||||
}
|
||||
|
||||
value = homeDir.getAbsolutePath();
|
||||
|
||||
if (path.startsWith(value))
|
||||
{
|
||||
return "${jetty.home}" + path.substring(value.length());
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
|
@ -49,8 +49,8 @@ import java.util.TreeSet;
|
|||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The behaviour of Main is controlled by the <code>"org/eclipse/start/start.config"</code> file obtained as a resource
|
||||
* or file. This can be overridden with the START system property. The format of each line in this file is:
|
||||
* The behaviour of Main is controlled by the <code>"org/eclipse/start/start.config"</code> file obtained as a resource or file. This can be overridden with the
|
||||
* START system property. The format of each line in this file is:
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
|
@ -101,18 +101,15 @@ import java.util.TreeSet;
|
|||
* <li><code>exists file</code> - true if file/dir exists</li>
|
||||
* <li><code>java OPERATOR version</code> - java version compared to literal</li>
|
||||
* <li><code>nargs OPERATOR number</code> - number of command line args compared to literal</li>
|
||||
* <li>OPERATOR := one of <code>"<"</code>,<code>">"</code>,<code>"<="</code>,<code>">="</code>,
|
||||
* <code>"=="</code>,<code>"!="</code></li>
|
||||
* <li>OPERATOR := one of <code>"<"</code>,<code>">"</code>,<code>"<="</code>,<code>">="</code>, <code>"=="</code>,<code>"!="</code></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>
|
||||
* CONDITIONS can be combined with <code>AND</code> <code>OR</code> or <code>!</code>, with <code>AND</code> being the
|
||||
* assume operator for a list of CONDITIONS.
|
||||
* CONDITIONS can be combined with <code>AND</code> <code>OR</code> or <code>!</code>, with <code>AND</code> being the assume operator for a list of CONDITIONS.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* Classpath operations are evaluated on the fly, so once a class or jar is added to the classpath, subsequent available
|
||||
* conditions will see that class.
|
||||
* Classpath operations are evaluated on the fly, so once a class or jar is added to the classpath, subsequent available conditions will see that class.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
|
@ -120,13 +117,13 @@ 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.
|
||||
* 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. :
|
||||
* 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>
|
||||
*
|
||||
* <pre>
|
||||
|
@ -148,11 +145,10 @@ public class Config
|
|||
{
|
||||
String ver = System.getProperty("jetty.version",null);
|
||||
|
||||
if(ver == null) {
|
||||
if (ver == null)
|
||||
{
|
||||
Package pkg = Config.class.getPackage();
|
||||
if (pkg != null &&
|
||||
"Eclipse.org - Jetty".equals(pkg.getImplementationVendor()) &&
|
||||
(pkg.getImplementationVersion() != null))
|
||||
if (pkg != null && "Eclipse.org - Jetty".equals(pkg.getImplementationVendor()) && (pkg.getImplementationVersion() != null))
|
||||
{
|
||||
ver = pkg.getImplementationVersion();
|
||||
}
|
||||
|
@ -174,7 +170,7 @@ public class Config
|
|||
private static boolean DEBUG = false;
|
||||
private static Config __instance;
|
||||
|
||||
private final HomeBase _homebase;
|
||||
private final BaseHome _homebase;
|
||||
private final Map<String, String> _properties = new HashMap<String, String>();
|
||||
private final Map<String, Classpath> _classpaths = new HashMap<String, Classpath>();
|
||||
private final List<String> _xml = new ArrayList<String>();
|
||||
|
@ -202,12 +198,12 @@ public class Config
|
|||
public Config()
|
||||
{
|
||||
__instance = this;
|
||||
_homebase = new HomeBase();
|
||||
_homebase = new BaseHome();
|
||||
setProperty("jetty.home",_homebase.getHome());
|
||||
setProperty("jetty.base",_homebase.getBase());
|
||||
}
|
||||
|
||||
public HomeBase getHomeBase()
|
||||
public BaseHome getBaseHome()
|
||||
{
|
||||
return _homebase;
|
||||
}
|
||||
|
@ -380,8 +376,7 @@ public class Config
|
|||
*
|
||||
* @param optionIds
|
||||
* the list of section ids to fetch
|
||||
* @return the {@link Classpath} representing combination all of the selected sectionIds, combined with the default
|
||||
* section id, and '*' special id.
|
||||
* @return the {@link Classpath} representing combination all of the selected sectionIds, combined with the default section id, and '*' special id.
|
||||
*/
|
||||
public Classpath getCombinedClasspath(Collection<String> optionIds)
|
||||
{
|
||||
|
@ -417,12 +412,14 @@ public class Config
|
|||
Properties properties = new Properties();
|
||||
// Add System Properties First
|
||||
Enumeration<?> ensysprop = System.getProperties().propertyNames();
|
||||
while(ensysprop.hasMoreElements()) {
|
||||
while (ensysprop.hasMoreElements())
|
||||
{
|
||||
String name = (String)ensysprop.nextElement();
|
||||
properties.put(name,System.getProperty(name));
|
||||
}
|
||||
// Add Config Properties Next (overwriting any System Properties that exist)
|
||||
for (String key : __instance._properties.keySet()) {
|
||||
for (String key : __instance._properties.keySet())
|
||||
{
|
||||
properties.put(key,__instance._properties.get(key));
|
||||
}
|
||||
return properties;
|
||||
|
@ -430,11 +427,13 @@ public class Config
|
|||
|
||||
public String getProperty(String name)
|
||||
{
|
||||
if ("version".equalsIgnoreCase(name)) {
|
||||
if ("version".equalsIgnoreCase(name))
|
||||
{
|
||||
return __version;
|
||||
}
|
||||
// Search Config Properties First
|
||||
if (_properties.containsKey(name)) {
|
||||
if (_properties.containsKey(name))
|
||||
{
|
||||
return _properties.get(name);
|
||||
}
|
||||
// Return what exists in System.Properties otherwise.
|
||||
|
@ -543,7 +542,8 @@ public class Config
|
|||
/**
|
||||
* Parse the configuration
|
||||
*
|
||||
* @param stream the stream to read from
|
||||
* @param stream
|
||||
* the stream to read from
|
||||
* @throws IOException
|
||||
*/
|
||||
public void parse(InputStream stream) throws IOException
|
||||
|
@ -598,7 +598,6 @@ public class Config
|
|||
option_ids.add(optionId);
|
||||
}
|
||||
|
||||
|
||||
// Process Dynamic
|
||||
for (String optionId : options)
|
||||
{
|
||||
|
|
|
@ -121,21 +121,26 @@ public class Main implements IncludeListener
|
|||
{
|
||||
String source = "";
|
||||
|
||||
// Handle default ini args
|
||||
ArrayList<String> arguments = new ArrayList<>(Arrays.asList(args));
|
||||
boolean ini = false;
|
||||
for (String arg : arguments)
|
||||
{
|
||||
if (arg.startsWith("--ini=") || arg.equals("--ini"))
|
||||
{
|
||||
ini = true;
|
||||
}
|
||||
}
|
||||
if (!ini)
|
||||
{
|
||||
|
||||
// Ensure ini is declared
|
||||
if(findArgumentPrefix(arguments, "--ini=") == null) {
|
||||
arguments.add(0,"--ini=start.ini");
|
||||
}
|
||||
|
||||
// Set Home and Base at the start, as all other paths encountered
|
||||
// will be based off of them.
|
||||
String home = findArgumentPrefix(arguments, "-Djetty.home=");
|
||||
if(home != null) {
|
||||
String value = home.replaceFirst("^[^=]*=","");
|
||||
_config.getBaseHome().setHomeDir(new File(value));
|
||||
}
|
||||
String base = findArgumentPrefix(arguments, "-Djetty.base=");
|
||||
if(base != null) {
|
||||
String value = base.replaceFirst("^[^=]*=","");
|
||||
_config.getBaseHome().setBaseDir(new File(value));
|
||||
}
|
||||
|
||||
// The XML Configuration Files to initialize with
|
||||
List<String> xmls = new ArrayList<String>();
|
||||
|
||||
|
@ -216,11 +221,10 @@ public class Main implements IncludeListener
|
|||
|
||||
if (arg.startsWith("--ini=") || arg.equals("--ini"))
|
||||
{
|
||||
ini = true;
|
||||
if (arg.length() > 6)
|
||||
{
|
||||
String name = arg.substring(6);
|
||||
File file = _config.getHomeBase().getFile(name);
|
||||
File file = _config.getBaseHome().getFile(name);
|
||||
StartIni startini = new StartIni(file,this);
|
||||
_iniFiles.add(file);
|
||||
arguments.addAll(i + 1,startini.getLines());
|
||||
|
@ -378,12 +382,24 @@ public class Main implements IncludeListener
|
|||
return xmls;
|
||||
}
|
||||
|
||||
private String findArgumentPrefix(ArrayList<String> arguments, String prefix)
|
||||
{
|
||||
for (String arg : arguments)
|
||||
{
|
||||
if (arg.startsWith(prefix))
|
||||
{
|
||||
return arg;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StartIni> onIniInclude(String path) throws IOException
|
||||
{
|
||||
List<StartIni> included = new ArrayList<>();
|
||||
|
||||
HomeBase hb = _config.getHomeBase();
|
||||
BaseHome hb = _config.getBaseHome();
|
||||
|
||||
// Allow --enable and --disable to work
|
||||
_iniIncludePaths.add(path);
|
||||
|
@ -498,7 +514,7 @@ public class Main implements IncludeListener
|
|||
};
|
||||
|
||||
// list etc
|
||||
List<File> configFiles = _config.getHomeBase().listFiles("etc",filter);
|
||||
List<File> configFiles = _config.getBaseHome().listFiles("etc",filter);
|
||||
|
||||
for (File configFile : configFiles)
|
||||
{
|
||||
|
@ -509,7 +525,7 @@ public class Main implements IncludeListener
|
|||
{
|
||||
for (File file : _iniFiles)
|
||||
{
|
||||
String path = _config.getHomeBase().toShortForm(file);
|
||||
String path = _config.getBaseHome().toShortForm(file);
|
||||
System.out.printf("%s%s%n",indent,path);
|
||||
|
||||
if (Config.isDebug())
|
||||
|
@ -542,12 +558,12 @@ public class Main implements IncludeListener
|
|||
|
||||
private String path(String path)
|
||||
{
|
||||
return _config.getHomeBase().toShortForm(path);
|
||||
return _config.getBaseHome().toShortForm(path);
|
||||
}
|
||||
|
||||
private String path(File file)
|
||||
{
|
||||
return _config.getHomeBase().toShortForm(file);
|
||||
return _config.getBaseHome().toShortForm(file);
|
||||
}
|
||||
|
||||
public void invokeMain(ClassLoader classloader, String classname, List<String> args) throws IllegalAccessException, InvocationTargetException,
|
||||
|
@ -622,7 +638,7 @@ public class Main implements IncludeListener
|
|||
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());
|
||||
}
|
||||
|
||||
for (String m : _enable)
|
||||
|
@ -753,14 +769,14 @@ public class Main implements IncludeListener
|
|||
}
|
||||
|
||||
// Try normal locations
|
||||
File xml = _config.getHomeBase().getFile(xmlFilename);
|
||||
File xml = _config.getBaseHome().getFile(xmlFilename);
|
||||
if (FS.isFile(xml))
|
||||
{
|
||||
return xml.getAbsolutePath();
|
||||
}
|
||||
|
||||
// Try again, but prefixed with "etc/"
|
||||
xml = _config.getHomeBase().getFile("etc/" + xmlFilename);
|
||||
xml = _config.getBaseHome().getFile("etc/" + xmlFilename);
|
||||
if (FS.isFile(xml))
|
||||
{
|
||||
return xml.getAbsolutePath();
|
||||
|
@ -777,8 +793,8 @@ public class Main implements IncludeListener
|
|||
{
|
||||
cmd.addArg(x);
|
||||
}
|
||||
cmd.addRawArg("-Djetty.home=" + _config.getHomeBase().getHome());
|
||||
cmd.addRawArg("-Djetty.base=" + _config.getHomeBase().getBase());
|
||||
cmd.addRawArg("-Djetty.home=" + _config.getBaseHome().getHome());
|
||||
cmd.addRawArg("-Djetty.base=" + _config.getBaseHome().getBase());
|
||||
|
||||
// Special Stop/Shutdown properties
|
||||
ensureSystemPropertySet("STOP.PORT");
|
||||
|
@ -796,7 +812,7 @@ public class Main implements IncludeListener
|
|||
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");
|
||||
|
@ -826,7 +842,7 @@ public class Main implements IncludeListener
|
|||
return; // done
|
||||
}
|
||||
|
||||
Properties props = _config.getProperties();
|
||||
Properties props = Config.getProperties();
|
||||
if (props.containsKey(key))
|
||||
{
|
||||
String val = props.getProperty(key,null);
|
||||
|
@ -900,8 +916,8 @@ public class Main implements IncludeListener
|
|||
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",_config.getHomeBase().getHome());
|
||||
System.out.printf("${jetty.base} = %s%n",_config.getHomeBase().getBase());
|
||||
System.out.printf("${jetty.home} = %s%n",_config.getBaseHome().getHome());
|
||||
System.out.printf("${jetty.base} = %s%n",_config.getBaseHome().getBase());
|
||||
System.out.println();
|
||||
|
||||
for (String sectionId : sectionIds)
|
||||
|
@ -1188,7 +1204,7 @@ public class Main implements IncludeListener
|
|||
|
||||
FileFilter disabledModuleFilter = new FS.FilenameRegexFilter("(\\d\\d\\d-)?"+Pattern.quote(module)+"\\.ini(\\.disabled)?");
|
||||
|
||||
HomeBase hb = _config.getHomeBase();
|
||||
BaseHome hb = _config.getBaseHome();
|
||||
|
||||
// walk all ini include paths that were used
|
||||
boolean found = false;
|
||||
|
@ -1247,7 +1263,7 @@ public class Main implements IncludeListener
|
|||
|
||||
FileFilter disabledModuleFilter = new FS.FilenameRegexFilter("(\\d\\d\\d-)?"+Pattern.quote(module)+"\\.ini(\\.disabled)?");
|
||||
|
||||
HomeBase hb = _config.getHomeBase();
|
||||
BaseHome hb = _config.getBaseHome();
|
||||
|
||||
// walk all ini include paths that were used
|
||||
boolean found = false;
|
||||
|
|
|
@ -90,7 +90,7 @@ public class StartIni implements Iterable<String>
|
|||
}
|
||||
else
|
||||
{
|
||||
// Collect HomeBase resolved included StartIni's
|
||||
// Collect BaseHome resolved included StartIni's
|
||||
for (StartIni included : listener.onIniInclude(line))
|
||||
{
|
||||
// Merge each line with prior lines to prevent duplicates
|
||||
|
|
|
@ -30,9 +30,9 @@ import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
|||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HomeBaseTest
|
||||
public class BaseHomeTest
|
||||
{
|
||||
private void assertFileList(HomeBase hb, String message, List<String> expected, List<File> files)
|
||||
private void assertFileList(BaseHome hb, String message, List<String> expected, List<File> files)
|
||||
{
|
||||
List<String> actual = new ArrayList<>();
|
||||
for (File file : files)
|
||||
|
@ -48,7 +48,7 @@ public class HomeBaseTest
|
|||
File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home");
|
||||
File baseDir = null;
|
||||
|
||||
HomeBase hb = new HomeBase(homeDir,baseDir);
|
||||
BaseHome hb = new BaseHome(homeDir,baseDir);
|
||||
File startIni = hb.getFile("/start.ini");
|
||||
|
||||
String ref = hb.toShortForm(startIni);
|
||||
|
@ -64,7 +64,7 @@ public class HomeBaseTest
|
|||
File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home");
|
||||
File baseDir = null;
|
||||
|
||||
HomeBase hb = new HomeBase(homeDir,baseDir);
|
||||
BaseHome hb = new BaseHome(homeDir,baseDir);
|
||||
List<File> files = hb.listFiles("/start.d");
|
||||
|
||||
List<String> expected = new ArrayList<>();
|
||||
|
@ -83,7 +83,7 @@ public class HomeBaseTest
|
|||
File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home");
|
||||
File baseDir = null;
|
||||
|
||||
HomeBase hb = new HomeBase(homeDir,baseDir);
|
||||
BaseHome hb = new BaseHome(homeDir,baseDir);
|
||||
List<File> files = hb.listFiles("/start.d", new FS.IniFilter());
|
||||
|
||||
List<String> expected = new ArrayList<>();
|
||||
|
@ -102,7 +102,7 @@ public class HomeBaseTest
|
|||
File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home");
|
||||
File baseDir = MavenTestingUtils.getTestResourceDir("hb.1/base");
|
||||
|
||||
HomeBase hb = new HomeBase(homeDir,baseDir);
|
||||
BaseHome hb = new BaseHome(homeDir,baseDir);
|
||||
List<File> files = hb.listFiles("/start.d");
|
||||
|
||||
List<String> expected = new ArrayList<>();
|
||||
|
@ -122,7 +122,7 @@ public class HomeBaseTest
|
|||
File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home");
|
||||
File baseDir = MavenTestingUtils.getTestResourceDir("hb.1/base");
|
||||
|
||||
HomeBase hb = new HomeBase(homeDir,baseDir);
|
||||
BaseHome hb = new BaseHome(homeDir,baseDir);
|
||||
File startIni = hb.getFile("/start.ini");
|
||||
|
||||
String ref = hb.toShortForm(startIni);
|
Loading…
Reference in New Issue