432321 - jetty-start / Allow defining extra start directories for common configurations

+ Final work for unit testing happiness
+ BaseHome is now configured via ConfigSources (as intended)
+ StartArgs now parses the ConfigSources list (in reverse)
+ CommandLineConfigSource now does all of the ${jetty.base} and
  ${jetty.home} determination (from properties and env, with
  fallbacks)
This commit is contained in:
Joakim Erdfelt 2014-04-11 14:26:35 -07:00
parent eff78efe3c
commit 8f733169f5
16 changed files with 378 additions and 358 deletions

View File

@ -20,9 +20,6 @@ package org.eclipse.jetty.start;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
@ -33,13 +30,13 @@ import java.util.EnumSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.jetty.start.config.CommandLineConfigSource;
import org.eclipse.jetty.start.config.ConfigSource;
import org.eclipse.jetty.start.config.ConfigSources;
import org.eclipse.jetty.start.config.DirConfigSource;
import org.eclipse.jetty.start.config.JettyBaseConfigSource;
import org.eclipse.jetty.start.config.JettyHomeConfigSource;
/**
* File access for <code>${jetty.home}</code>, <code>${jetty.base}</code>, directories.
@ -110,87 +107,71 @@ public class BaseHome
return String.format("${%s}%c%s",name,File.separatorChar,relative.toString());
}
}
private static final String JETTY_BASE = "jetty.base";
private static final String JETTY_HOME = "jetty.home";;
public static final String JETTY_BASE = "jetty.base";
public static final String JETTY_HOME = "jetty.home";
private final static EnumSet<FileVisitOption> SEARCH_VISIT_OPTIONS = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
private final static int MAX_SEARCH_DEPTH = Integer.getInteger("org.eclipse.jetty.start.searchDepth",10);
private Path homeDir;
private ConfigSources sources;
private Path baseDir;
private final ConfigSources sources;
private final Path homeDir;
private final Path baseDir;
public BaseHome()
public BaseHome() throws IOException
{
try
{
// find ${jetty.base} and ${jetty.home} from environment.
// overrides from command line (and the like) come later.
// in the .initialize() step
// default is ${user.dir}
this.baseDir = FS.toPath(System.getProperty("user.dir","."));
// if ${jetty.base} declared, use it
String jettyBase = System.getProperty(JETTY_BASE);
if (jettyBase != null)
{
this.baseDir = FS.toPath(jettyBase);
}
// find ${jetty.home}
// default location is based on lookup for BaseHome (from jetty's start.jar)
URL jarfile = this.getClass().getClassLoader().getResource("org/eclipse/jetty/start/BaseHome.class");
if (jarfile != null)
{
Matcher m = Pattern.compile("jar:(file:.*)!/org/eclipse/jetty/start/BaseHome.class").matcher(jarfile.toString());
if (m.matches())
{
// ${jetty.home} is relative to found BaseHome class
this.homeDir = new File(new URI(m.group(1))).getParentFile().toPath();
}
}
// if we can't locate BaseHome, then assume home == base
if (this.homeDir == null)
{
this.homeDir = baseDir.toAbsolutePath();
}
// if ${jetty.home} declared, use it
String jettyHome = System.getProperty(JETTY_HOME);
if (jettyHome != null)
{
this.homeDir = FS.toPath(jettyHome);
}
// Resolve to absolute paths
this.homeDir = this.homeDir.toAbsolutePath();
this.baseDir = this.baseDir.toAbsolutePath();
}
catch (URISyntaxException e)
{
throw new RuntimeException(e);
}
this(new String[0]);
}
public BaseHome(File homeDir, File baseDir)
public BaseHome(String cmdLine[]) throws IOException
{
Objects.requireNonNull(homeDir,"Home Dir cannot be null");
this(new CommandLineConfigSource(cmdLine));
}
this.homeDir = homeDir.toPath();
this.baseDir = homeDir.toPath(); // default
if (baseDir != null)
public BaseHome(CommandLineConfigSource cmdLineSource) throws IOException
{
StartLog.getInstance().initialize(this,cmdLineSource);
sources = new ConfigSources();
sources.add(cmdLineSource);
this.homeDir = cmdLineSource.getHomePath();
this.baseDir = cmdLineSource.getBasePath();
sources.add(new JettyBaseConfigSource(cmdLineSource.getBasePath()));
sources.add(new JettyHomeConfigSource(cmdLineSource.getHomePath()));
System.setProperty(JETTY_HOME,homeDir.toAbsolutePath().toString());
System.setProperty(JETTY_BASE,baseDir.toAbsolutePath().toString());
}
public BaseHome(ConfigSources sources)
{
this.sources = sources;
Path home = null;
Path base = null;
for (ConfigSource source : sources)
{
this.baseDir = baseDir.toPath();
if (source instanceof CommandLineConfigSource)
{
CommandLineConfigSource cmdline = (CommandLineConfigSource)source;
home = cmdline.getHomePath();
base = cmdline.getBasePath();
}
else if (source instanceof JettyBaseConfigSource)
{
base = ((JettyBaseConfigSource)source).getDir();
}
else if (source instanceof JettyHomeConfigSource)
{
home = ((JettyHomeConfigSource)source).getDir();
}
}
// Resolve to absolute paths
this.homeDir = this.homeDir.toAbsolutePath();
this.baseDir = this.baseDir.toAbsolutePath();
Objects.requireNonNull(home,"jetty.home cannot be null");
this.homeDir = home;
this.baseDir = (base != null)?base:home;
System.setProperty(JETTY_HOME,homeDir.toAbsolutePath().toString());
System.setProperty(JETTY_BASE,baseDir.toAbsolutePath().toString());
}
public String getBase()
@ -468,53 +449,11 @@ public class BaseHome
return hits;
}
public void initialize(ConfigSources config)
{
CommandLineConfigSource cmdLine = config.getCommandLineSource();
if (cmdLine != null)
{
this.homeDir = cmdLine.getHomePath();
this.baseDir = cmdLine.getBasePath();
}
this.sources = config;
}
public boolean isBaseDifferent()
{
return homeDir.compareTo(baseDir) != 0;
}
/**
* @deprecated use {@link #setBaseDir(Path)}
*/
@Deprecated
public void setBaseDir(File dir)
{
setBaseDir(dir.toPath());
}
public void setBaseDir(Path dir)
{
this.baseDir = dir.toAbsolutePath();
System.setProperty(JETTY_BASE,dir.toString());
}
/**
* @deprecated use {@link #setHomeDir(Path)}
*/
@Deprecated
public void setHomeDir(File dir)
{
setHomeDir(dir.toPath());
}
public void setHomeDir(Path dir)
{
this.homeDir = dir.toAbsolutePath();
System.setProperty(JETTY_HOME,dir.toString());
}
/**
* Convenience method for <code>toShortForm(file.toPath())</code>
*/

View File

@ -306,15 +306,6 @@ public class FS
return ret.toString();
}
public static Path toOptionalPath(String path)
{
if (path == null)
{
return null;
}
return toPath(path);
}
public static Path toPath(String path)
{
return FileSystems.getDefault().getPath(FS.separators(path));

View File

@ -51,9 +51,6 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.jetty.start.config.CommandLineConfigSource;
import org.eclipse.jetty.start.config.ConfigSources;
import org.eclipse.jetty.start.config.JettyBaseConfigSource;
import org.eclipse.jetty.start.config.JettyHomeConfigSource;
/**
* Main start class.
@ -138,11 +135,10 @@ public class Main
System.exit(exit);
}
private final BaseHome baseHome;
private BaseHome baseHome;
Main() throws IOException
{
baseHome = new BaseHome();
}
private void copyInThread(final InputStream in, final OutputStream out)
@ -551,45 +547,32 @@ public class Main
public StartArgs processCommandLine(String[] cmdLine) throws Exception
{
ConfigSources sources = new ConfigSources();
// Processing Order is important!
// ------------------------------------------------------------
// 1) Directory Locations
// 1) Configuration Locations
CommandLineConfigSource cmdLineSource = new CommandLineConfigSource(cmdLine);
sources.add(cmdLineSource);
sources.add(new JettyBaseConfigSource(cmdLineSource.getBasePath()));
sources.add(new JettyHomeConfigSource(cmdLineSource.getHomePath()));
// Set Home and Base at the start, as many other paths encountered
// will be based off of them.
baseHome.initialize(sources);
// ------------------------------------------------------------
// 2) Start Logging
StartLog.getInstance().initialize(baseHome,cmdLineSource);
baseHome = new BaseHome(cmdLineSource);
StartLog.debug("jetty.home=%s",baseHome.getHome());
StartLog.debug("jetty.base=%s",baseHome.getBase());
// ------------------------------------------------------------
// 3) Parse everything provided.
// 2) Parse everything provided.
// This would be the directory information +
// the various start inis
// and then the raw command line arguments
StartLog.debug("Parsing collected arguments");
StartArgs args = new StartArgs();
args.parse(sources);
args.parse(baseHome.getConfigSources());
// ------------------------------------------------------------
// 4) Module Registration
// 3) Module Registration
Modules modules = new Modules();
StartLog.debug("Registering all modules");
modules.registerAll(baseHome, args);
// ------------------------------------------------------------
// 5) Active Module Resolution
// 4) Active Module Resolution
for (String enabledModule : args.getEnabledModules())
{
List<String> msources = args.getSources(enabledModule);
@ -603,12 +586,12 @@ public class Main
List<Module> activeModules = modules.resolveEnabled();
// ------------------------------------------------------------
// 6) Lib & XML Expansion / Resolution
// 5) Lib & XML Expansion / Resolution
args.expandLibs(baseHome);
args.expandModules(baseHome,activeModules);
// ------------------------------------------------------------
// 7) Resolve Extra XMLs
// 6) Resolve Extra XMLs
args.resolveExtraXmls(baseHome);
return args;

View File

@ -48,7 +48,7 @@ public class PathFinder extends SimpleFileVisitor<Path>
private void addHit(Path path)
{
String relPath = basePath.relativize(path).toString();
StartLog.debug("addHit(" + path + ") = [" + relPath + "," + path + "]");
StartLog.debug("Found [" + relPath + "] " + path);
hits.put(relPath,path);
}
@ -139,7 +139,6 @@ public class PathFinder extends SimpleFileVisitor<Path>
{
if (fileMatcher.matches(file))
{
StartLog.debug("Found file: " + file);
addHit(file);
}
else

View File

@ -29,11 +29,13 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import org.eclipse.jetty.start.Props.Prop;
import org.eclipse.jetty.start.config.ConfigSource;
import org.eclipse.jetty.start.config.ConfigSources;
/**
@ -66,7 +68,7 @@ public class StartArgs
}
private static final String SERVER_MAIN = "org.eclipse.jetty.xml.XmlConfiguration";
/** List of enabled modules */
private Set<String> modules = new HashSet<>();
/** Map of enabled modules to the source of where that activation occurred */
@ -84,7 +86,7 @@ public class StartArgs
/** List of all xml references found directly on command line or start.ini */
private List<String> xmlRefs = new ArrayList<>();
private Props properties = new Props();
private Set<String> systemPropertyKeys = new HashSet<>();
private List<String> rawLibs = new ArrayList<>();
@ -247,6 +249,30 @@ public class StartArgs
}
}
private void dumpProperty(String key)
{
Prop prop = properties.getProp(key);
if (prop == null)
{
System.out.printf(" %s (not defined)%n",key);
}
else
{
System.out.printf(" %s = %s%n",key,properties.expand(prop.value));
if (StartLog.isDebugEnabled())
{
System.out.printf(" origin: %s%n",prop.origin);
while (prop.overrides != null)
{
prop = prop.overrides;
System.out.printf(" (overrides)%n");
System.out.printf(" %s = %s%n",key,properties.expand(prop.value));
System.out.printf(" origin: %s%n",prop.origin);
}
}
}
}
public void dumpSystemProperties()
{
System.out.println();
@ -275,30 +301,6 @@ public class StartArgs
System.out.printf(" %s = %s%n",key,System.getProperty(key));
}
private void dumpProperty(String key)
{
Prop prop = properties.getProp(key);
if (prop == null)
{
System.out.printf(" %s (not defined)%n",key);
}
else
{
System.out.printf(" %s = %s%n",key,properties.expand(prop.value));
if (StartLog.isDebugEnabled())
{
System.out.printf(" origin: %s%n",prop.origin);
while (prop.overrides != null)
{
prop = prop.overrides;
System.out.printf(" (overrides)%n");
System.out.printf(" %s = %s%n",key,properties.expand(prop.value));
System.out.printf(" origin: %s%n",prop.origin);
}
}
}
}
/**
* Ensure that the System Properties are set (if defined as a System property, or start.config property, or start.ini property)
*
@ -393,6 +395,16 @@ public class StartArgs
}
}
public List<String> getAddToStartdIni()
{
return addToStartdIni;
}
public List<String> getAddToStartIni()
{
return addToStartIni;
}
public Modules getAllModules()
{
return allModules;
@ -403,16 +415,16 @@ public class StartArgs
return classpath;
}
public List<FileArg> getFiles()
{
return files;
}
public Set<String> getEnabledModules()
{
return this.modules;
}
public List<FileArg> getFiles()
{
return files;
}
public List<String> getJvmArgs()
{
return jvmArgs;
@ -485,16 +497,6 @@ public class StartArgs
return moduleGraphFilename;
}
public List<String> getAddToStartdIni()
{
return addToStartdIni;
}
public List<String> getAddToStartIni()
{
return addToStartIni;
}
public Props getProperties()
{
return properties;
@ -565,31 +567,6 @@ public class StartArgs
return listModules;
}
private void setProperty(String key, String value, String source)
{
// Special / Prevent override from start.ini's
if (key.equals("jetty.home"))
{
properties.setProperty("jetty.home",System.getProperty("jetty.home"),source);
return;
}
// Special / Prevent override from start.ini's
if (key.equals("jetty.base"))
{
properties.setProperty("jetty.base",System.getProperty("jetty.base"),source);
return;
}
// Normal
properties.setProperty(key,value,source);
}
public void setRun(boolean run)
{
this.run = run;
}
public boolean isRun()
{
return run;
@ -605,6 +582,19 @@ public class StartArgs
return version;
}
public void parse(ConfigSources sources)
{
ListIterator<ConfigSource> iter = sources.reverseListIterator();
while (iter.hasPrevious())
{
ConfigSource source = iter.previous();
for (String arg : source.getArgs())
{
parse(arg,source.getId());
}
}
}
public void parse(final String rawarg, String source)
{
if (rawarg == null)
@ -639,7 +629,7 @@ public class StartArgs
if (arg.startsWith("--extra-start-dir="))
{
// valid, but handled in ConfigSources instead
// valid, but handled in ConfigSources instead
return;
}
@ -855,6 +845,31 @@ public class StartArgs
this.allModules = allModules;
}
private void setProperty(String key, String value, String source)
{
// Special / Prevent override from start.ini's
if (key.equals("jetty.home"))
{
properties.setProperty("jetty.home",System.getProperty("jetty.home"),source);
return;
}
// Special / Prevent override from start.ini's
if (key.equals("jetty.base"))
{
properties.setProperty("jetty.base",System.getProperty("jetty.base"),source);
return;
}
// Normal
properties.setProperty(key,value,source);
}
public void setRun(boolean run)
{
this.run = run;
}
@Override
public String toString()
{
@ -870,9 +885,4 @@ public class StartArgs
builder.append("]");
return builder.toString();
}
public void parse(ConfigSources sources)
{
// TODO Auto-generated method stub
}
}

View File

@ -18,19 +18,29 @@
package org.eclipse.jetty.start.config;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.jetty.start.BaseHome;
import org.eclipse.jetty.start.FS;
import org.eclipse.jetty.start.Props;
import org.eclipse.jetty.start.Props.Prop;
import org.eclipse.jetty.start.UsageException;
/**
* Configuration Source representing the Command Line arguments.
*/
public class CommandLineConfigSource implements ConfigSource
{
public static final String CMD_LINE_SOURCE = "<command-line>";
public static final String ORIGIN_INTERNAL_FALLBACK = "<internal-fallback>";
public static final String ORIGIN_CMD_LINE = "<command-line>";
private final List<String> args;
private final Props props;
@ -43,28 +53,99 @@ public class CommandLineConfigSource implements ConfigSource
this.props = new Props();
for (String arg : args)
{
this.props.addPossibleProperty(arg,CMD_LINE_SOURCE);
this.props.addPossibleProperty(arg,ORIGIN_CMD_LINE);
}
Path home = FS.toOptionalPath(getProperty("jetty.home"));
Path base = FS.toOptionalPath(getProperty("jetty.base"));
// Setup ${jetty.base} and ${jetty.home}
this.homePath = findJettyHomePath().toAbsolutePath();
this.basePath = findJettyBasePath().toAbsolutePath();
if (home != null)
// Update System Properties
setSystemProperty(BaseHome.JETTY_HOME,homePath.toAbsolutePath().toString());
setSystemProperty(BaseHome.JETTY_BASE,basePath.toAbsolutePath().toString());
}
private final Path findJettyBasePath()
{
// If a jetty property is defined, use it
Prop prop = this.props.getProp(BaseHome.JETTY_BASE,false);
if (prop != null && !isEmpty(prop.value))
{
// logic if home is specified
if (base == null)
return FS.toPath(prop.value);
}
// If a system property is defined, use it
String val = System.getProperty(BaseHome.JETTY_BASE);
if (!isEmpty(val))
{
return FS.toPath(val);
}
// Lastly, fall back to base == home
Path base = this.homePath.toAbsolutePath();
setProperty(BaseHome.JETTY_BASE,base.toString(),ORIGIN_INTERNAL_FALLBACK);
return base;
}
private final Path findJettyHomePath()
{
// If a jetty property is defined, use it
Prop prop = this.props.getProp(BaseHome.JETTY_HOME,false);
if (prop != null && !isEmpty(prop.value))
{
return FS.toPath(prop.value);
}
// If a system property is defined, use it
String val = System.getProperty(BaseHome.JETTY_HOME);
if (!isEmpty(val))
{
return FS.toPath(val);
}
// Attempt to find path relative to content in jetty's start.jar
// based on lookup for the Main class (from jetty's start.jar)
String classRef = "org/eclipse/jetty/start/Main.class";
URL jarfile = this.getClass().getClassLoader().getResource(classRef);
if (jarfile != null)
{
Matcher m = Pattern.compile("jar:(file:.*)!/" + classRef).matcher(jarfile.toString());
if (m.matches())
{
base = home;
setProperty("jetty.base",base.toString(),"<internal-fallback>");
// ${jetty.home} is relative to found BaseHome class
try
{
return new File(new URI(m.group(1))).getParentFile().toPath();
}
catch (URISyntaxException e)
{
throw new UsageException(UsageException.ERR_UNKNOWN,e);
}
}
}
this.homePath = home;
this.basePath = base;
// Lastly, fall back to ${user.dir} default
Path home = FS.toPath(System.getProperty("user.dir","."));
setProperty(BaseHome.JETTY_HOME,home.toString(),ORIGIN_INTERNAL_FALLBACK);
return home;
}
// Update System Properties
setSystemProperty("jetty.home",homePath.toAbsolutePath().toString());
setSystemProperty("jetty.base",basePath.toAbsolutePath().toString());
private boolean isEmpty(String value)
{
if (value == null)
{
return true;
}
int len = value.length();
for (int i = 0; i < len; i++)
{
int c = value.codePointAt(i);
if (!Character.isWhitespace(c))
{
return false;
}
}
return true;
}
@Override
@ -116,7 +197,7 @@ public class CommandLineConfigSource implements ConfigSource
@Override
public String getId()
{
return CMD_LINE_SOURCE;
return ORIGIN_CMD_LINE;
}
@Override

View File

@ -98,13 +98,11 @@ public class BaseHomeTest
public void testGetPath_OnlyHome() throws IOException
{
File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home");
File baseDir = null;
ConfigSources config = new ConfigSources();
config.add(new JettyHomeConfigSource(homeDir.toPath()));
BaseHome hb = new BaseHome(homeDir,baseDir);
hb.initialize(config);
BaseHome hb = new BaseHome(config);
Path startIni = hb.getPath("start.ini");
String ref = hb.toShortForm(startIni);
@ -118,13 +116,11 @@ public class BaseHomeTest
public void testGetPaths_OnlyHome() throws IOException
{
File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home");
File baseDir = null;
ConfigSources config = new ConfigSources();
config.add(new JettyHomeConfigSource(homeDir.toPath()));
BaseHome hb = new BaseHome(homeDir,baseDir);
hb.initialize(config);
BaseHome hb = new BaseHome(config);
List<Path> paths = hb.getPaths("start.d/*");
List<String> expected = new ArrayList<>();
@ -142,13 +138,11 @@ public class BaseHomeTest
public void testGetPaths_OnlyHome_InisOnly() throws IOException
{
File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home");
File baseDir = null;
ConfigSources config = new ConfigSources();
config.add(new JettyHomeConfigSource(homeDir.toPath()));
BaseHome hb = new BaseHome(homeDir,baseDir);
hb.initialize(config);
BaseHome hb = new BaseHome(config);
List<Path> paths = hb.getPaths("start.d/*.ini");
List<String> expected = new ArrayList<>();
@ -172,8 +166,7 @@ public class BaseHomeTest
config.add(new JettyBaseConfigSource(baseDir.toPath()));
config.add(new JettyHomeConfigSource(homeDir.toPath()));
BaseHome hb = new BaseHome(homeDir,baseDir);
hb.initialize(config);
BaseHome hb = new BaseHome(config);
List<Path> paths = hb.getPaths("start.d/*.ini");
List<String> expected = new ArrayList<>();
@ -206,8 +199,7 @@ public class BaseHomeTest
config.add(new JettyBaseConfigSource(baseDir.toPath()));
config.add(new JettyHomeConfigSource(homeDir.toPath()));
BaseHome hb = new BaseHome(homeDir,baseDir);
hb.initialize(config);
BaseHome hb = new BaseHome(config);
Path startIni = hb.getPath("start.ini");
String ref = hb.toShortForm(startIni);

View File

@ -275,6 +275,7 @@ public class ExtraStartTest
// Create common
File common = testdir.getFile("common");
FS.ensureEmpty(common);
TestEnv.makeFile(common,"start.ini","jetty.port=8080");
// Create base
File base = testdir.getFile("base");
@ -306,6 +307,7 @@ public class ExtraStartTest
// Create common
File common = testdir.getFile("common");
FS.ensureEmpty(common);
TestEnv.makeFile(common,"start.ini","jetty.port=8080");
// Create corp
File corp = testdir.getFile("corp");
@ -343,8 +345,7 @@ public class ExtraStartTest
// Create corp
File corp = testdir.getFile("corp");
FS.ensureEmpty(corp);
TestEnv.makeFile(corp,"start.ini", //
"jetty.port=9090");
TestEnv.makeFile(corp,"start.ini","jetty.port=9090");
// Create common
File common = testdir.getFile("common");

View File

@ -18,28 +18,33 @@
package org.eclipse.jetty.start;
import static org.hamcrest.Matchers.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
public class MainTest
{
private void addUseCasesHome(List<String> cmdLineArgs)
@Before
public void clearSystemProperties()
{
File testJettyHome = MavenTestingUtils.getTestResourceDir("usecases/home");
cmdLineArgs.add("jetty.home=" + testJettyHome);
System.setProperty("jetty.home","");
System.setProperty("jetty.base","");
}
@Test
public void testBasicProcessing() throws Exception
{
List<String> cmdLineArgs = new ArrayList<>();
addUseCasesHome(cmdLineArgs);
File testJettyHome = MavenTestingUtils.getTestResourceDir("usecases/home");
cmdLineArgs.add("jetty.home=" + testJettyHome);
cmdLineArgs.add("jetty.port=9090");
Main main = new Main();
@ -74,7 +79,8 @@ public class MainTest
public void testListConfig() throws Exception
{
List<String> cmdLineArgs = new ArrayList<>();
addUseCasesHome(cmdLineArgs);
File testJettyHome = MavenTestingUtils.getTestResourceDir("usecases/home");
cmdLineArgs.add("jetty.home=" + testJettyHome);
cmdLineArgs.add("jetty.port=9090");
cmdLineArgs.add("--list-config");
// cmdLineArgs.add("--debug");
@ -97,7 +103,8 @@ public class MainTest
{
List<String> cmdLineArgs = new ArrayList<>();
addUseCasesHome(cmdLineArgs);
File homePath = MavenTestingUtils.getTestResourceDir("usecases/home");
cmdLineArgs.add("jetty.home=" + homePath);
// JVM args
cmdLineArgs.add("--exec");
@ -118,7 +125,9 @@ public class MainTest
StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[cmdLineArgs.size()]));
BaseHome baseHome = main.getBaseHome();
System.err.println(args);
Assert.assertThat("jetty.home", baseHome.getHome(), is(homePath.getAbsolutePath()));
Assert.assertThat("jetty.base", baseHome.getBase(), is(homePath.getAbsolutePath()));
ConfigurationAssert.assertConfiguration(baseHome,args,"assert-home-with-jvm.txt");
}
@ -134,8 +143,10 @@ public class MainTest
Main main = new Main();
StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[cmdLineArgs.size()]));
BaseHome baseHome = main.getBaseHome();
System.err.println(args);
Assert.assertThat("jetty.home", baseHome.getHome(), is(homePath.getAbsolutePath()));
Assert.assertThat("jetty.base", baseHome.getBase(), is(homePath.getAbsolutePath()));
ConfigurationAssert.assertConfiguration(baseHome,args,"assert-home-with-spaces.txt");
}
}

View File

@ -55,8 +55,7 @@ public class ModuleGraphWriterTest
config.add(new JettyBaseConfigSource(baseDir.toPath()));
// Initialize
BaseHome basehome = new BaseHome();
basehome.initialize(config);
BaseHome basehome = new BaseHome(config);
StartArgs args = new StartArgs();
args.parse(config);

View File

@ -18,36 +18,53 @@
package org.eclipse.jetty.start;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.*;
import java.io.File;
import java.io.IOException;
import org.eclipse.jetty.start.config.CommandLineConfigSource;
import org.eclipse.jetty.start.config.ConfigSources;
import org.eclipse.jetty.start.config.JettyBaseConfigSource;
import org.eclipse.jetty.start.config.JettyHomeConfigSource;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.TestingDir;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
public class ModuleTest
{
private Module loadTestHomeModule(String moduleFileName) throws IOException
{
File file = MavenTestingUtils.getTestResourceFile("usecases/home/modules/" + moduleFileName);
return new Module(new BaseHome(),file.toPath());
}
@Rule
public TestingDir testdir = new TestingDir();
@Test
public void testLoadWebSocket() throws IOException
{
Module Module = loadTestHomeModule("websocket.mod");
Assert.assertThat("Module Name",Module.getName(),is("websocket"));
Assert.assertThat("Module Parents Size",Module.getParentNames().size(),is(2));
Assert.assertThat("Module Parents",Module.getParentNames(),containsInAnyOrder("annotations","server"));
Assert.assertThat("Module Xmls Size",Module.getXmls().size(),is(1));
Assert.assertThat("Module Xmls",Module.getXmls(),contains("etc/jetty-websockets.xml"));
Assert.assertThat("Module Options Size",Module.getLibs().size(),is(1));
Assert.assertThat("Module Options",Module.getLibs(),contains("lib/websocket/*.jar"));
// Test Env
File homeDir = MavenTestingUtils.getTestResourceDir("usecases/home");
File baseDir = testdir.getEmptyDir();
String cmdLine[] = new String[] {"jetty.version=TEST"};
// Configuration
CommandLineConfigSource cmdLineSource = new CommandLineConfigSource(cmdLine);
ConfigSources config = new ConfigSources();
config.add(cmdLineSource);
config.add(new JettyHomeConfigSource(homeDir.toPath()));
config.add(new JettyBaseConfigSource(baseDir.toPath()));
// Initialize
BaseHome basehome = new BaseHome(config);
File file = MavenTestingUtils.getTestResourceFile("usecases/home/modules/websocket.mod");
Module module = new Module(basehome,file.toPath());
Assert.assertThat("Module Name",module.getName(),is("websocket"));
Assert.assertThat("Module Parents Size",module.getParentNames().size(),is(2));
Assert.assertThat("Module Parents",module.getParentNames(),containsInAnyOrder("annotations","server"));
Assert.assertThat("Module Xmls Size",module.getXmls().size(),is(1));
Assert.assertThat("Module Xmls",module.getXmls(),contains("etc/jetty-websockets.xml"));
Assert.assertThat("Module Options Size",module.getLibs().size(),is(1));
Assert.assertThat("Module Options",module.getLibs(),contains("lib/websocket/*.jar"));
}
}

View File

@ -60,8 +60,7 @@ public class ModulesTest
config.add(new JettyBaseConfigSource(baseDir.toPath()));
// Initialize
BaseHome basehome = new BaseHome();
basehome.initialize(config);
BaseHome basehome = new BaseHome(config);
StartArgs args = new StartArgs();
args.parse(config);
@ -104,8 +103,7 @@ public class ModulesTest
config.add(new JettyBaseConfigSource(baseDir.toPath()));
// Initialize
BaseHome basehome = new BaseHome();
basehome.initialize(config);
BaseHome basehome = new BaseHome(config);
StartArgs args = new StartArgs();
args.parse(config);
@ -136,8 +134,7 @@ public class ModulesTest
config.add(new JettyBaseConfigSource(baseDir.toPath()));
// Initialize
BaseHome basehome = new BaseHome();
basehome.initialize(config);
BaseHome basehome = new BaseHome(config);
StartArgs args = new StartArgs();
args.parse(config);
@ -208,8 +205,7 @@ public class ModulesTest
config.add(new JettyBaseConfigSource(baseDir.toPath()));
// Initialize
BaseHome basehome = new BaseHome();
basehome.initialize(config);
BaseHome basehome = new BaseHome(config);
StartArgs args = new StartArgs();
args.parse(config);

View File

@ -36,7 +36,7 @@ public class PathFinderTest
public void testFindInis() throws IOException
{
File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home");
Path homePath = homeDir.toPath();
Path homePath = homeDir.toPath().toAbsolutePath();
PathFinder finder = new PathFinder();
finder.setFileMatcher("glob:**/*.ini");
@ -53,7 +53,7 @@ public class PathFinderTest
expected.add("${jetty.home}/start.ini");
FSTest.toOsSeparators(expected);
BaseHome hb = new BaseHome(homeDir,null);
BaseHome hb = new BaseHome(new String[] { "jetty.home=" + homePath.toString() });
BaseHomeTest.assertPathList(hb,"Files found",expected,finder);
}
@ -61,6 +61,7 @@ public class PathFinderTest
public void testFindMods() throws IOException
{
File homeDir = MavenTestingUtils.getTestResourceDir("usecases/home");
Path homePath = homeDir.toPath().toAbsolutePath();
List<String> expected = new ArrayList<>();
File modulesDir = new File(homeDir,"modules");
@ -81,7 +82,7 @@ public class PathFinderTest
Files.walkFileTree(modulesPath,EnumSet.of(FileVisitOption.FOLLOW_LINKS),1,finder);
BaseHome hb = new BaseHome(homeDir,null);
BaseHome hb = new BaseHome(new String[] { "jetty.home=" + homePath.toString() });
BaseHomeTest.assertPathList(hb,"Files found",expected,finder);
}
}

View File

@ -1,38 +1,38 @@
# The XMLs we expect (order is important)
XML|${jetty.home}/etc/jetty-jmx.xml
XML|${jetty.home}/etc/jetty.xml
XML|${jetty.home}/etc/jetty-http.xml
XML|${jetty.home}/etc/jetty-plus.xml
XML|${jetty.home}/etc/jetty-annotations.xml
XML|${jetty.home}/etc/jetty-websockets.xml
XML|${jetty.home}/etc/jetty-logging.xml
XML|${jetty.base}/etc/jetty-jmx.xml
XML|${jetty.base}/etc/jetty.xml
XML|${jetty.base}/etc/jetty-http.xml
XML|${jetty.base}/etc/jetty-plus.xml
XML|${jetty.base}/etc/jetty-annotations.xml
XML|${jetty.base}/etc/jetty-websockets.xml
XML|${jetty.base}/etc/jetty-logging.xml
# The LIBs we expect (order is irrelevant)
LIB|${jetty.home}/lib/annotations/javax.annotation-api-1.2.jar
LIB|${jetty.home}/lib/annotations/org.objectweb.asm-TEST.jar
LIB|${jetty.home}/lib/jetty-annotations-TEST.jar
LIB|${jetty.home}/lib/jetty-continuation-TEST.jar
LIB|${jetty.home}/lib/jetty-http-TEST.jar
LIB|${jetty.home}/lib/jetty-io-TEST.jar
LIB|${jetty.home}/lib/jetty-jmx-TEST.jar
LIB|${jetty.home}/lib/jetty-jndi-TEST.jar
LIB|${jetty.home}/lib/jetty-plus-TEST.jar
LIB|${jetty.home}/lib/jetty-schemas-3.1.jar
LIB|${jetty.home}/lib/jetty-security-TEST.jar
LIB|${jetty.home}/lib/jetty-server-TEST.jar
LIB|${jetty.home}/lib/jetty-util-TEST.jar
LIB|${jetty.home}/lib/jetty-xml-TEST.jar
LIB|${jetty.home}/lib/jndi/javax.activation-1.1.jar
LIB|${jetty.home}/lib/jndi/javax.transaction-api-1.2.jar
LIB|${jetty.home}/lib/servlet-api-3.1.jar
LIB|${jetty.home}/lib/websocket/javax.websocket-api-1.0.jar
LIB|${jetty.home}/lib/websocket/javax-websocket-client-impl-TEST.jar
LIB|${jetty.home}/lib/websocket/javax-websocket-server-impl-TEST.jar
LIB|${jetty.home}/lib/websocket/websocket-api-TEST.jar
LIB|${jetty.home}/lib/websocket/websocket-client-TEST.jar
LIB|${jetty.home}/lib/websocket/websocket-common-TEST.jar
LIB|${jetty.home}/lib/websocket/websocket-server-TEST.jar
LIB|${jetty.home}/lib/websocket/websocket-servlet-TEST.jar
LIB|${jetty.base}/lib/annotations/javax.annotation-api-1.2.jar
LIB|${jetty.base}/lib/annotations/org.objectweb.asm-TEST.jar
LIB|${jetty.base}/lib/jetty-annotations-TEST.jar
LIB|${jetty.base}/lib/jetty-continuation-TEST.jar
LIB|${jetty.base}/lib/jetty-http-TEST.jar
LIB|${jetty.base}/lib/jetty-io-TEST.jar
LIB|${jetty.base}/lib/jetty-jmx-TEST.jar
LIB|${jetty.base}/lib/jetty-jndi-TEST.jar
LIB|${jetty.base}/lib/jetty-plus-TEST.jar
LIB|${jetty.base}/lib/jetty-schemas-3.1.jar
LIB|${jetty.base}/lib/jetty-security-TEST.jar
LIB|${jetty.base}/lib/jetty-server-TEST.jar
LIB|${jetty.base}/lib/jetty-util-TEST.jar
LIB|${jetty.base}/lib/jetty-xml-TEST.jar
LIB|${jetty.base}/lib/jndi/javax.activation-1.1.jar
LIB|${jetty.base}/lib/jndi/javax.transaction-api-1.2.jar
LIB|${jetty.base}/lib/servlet-api-3.1.jar
LIB|${jetty.base}/lib/websocket/javax.websocket-api-1.0.jar
LIB|${jetty.base}/lib/websocket/javax-websocket-client-impl-TEST.jar
LIB|${jetty.base}/lib/websocket/javax-websocket-server-impl-TEST.jar
LIB|${jetty.base}/lib/websocket/websocket-api-TEST.jar
LIB|${jetty.base}/lib/websocket/websocket-client-TEST.jar
LIB|${jetty.base}/lib/websocket/websocket-common-TEST.jar
LIB|${jetty.base}/lib/websocket/websocket-server-TEST.jar
LIB|${jetty.base}/lib/websocket/websocket-servlet-TEST.jar
LIB|${maven-test-resources}/extra-resources
LIB|${maven-test-resources}/extra-libs/example.jar

View File

@ -2,7 +2,7 @@
# No XMLs in this home
# The LIBs we expect (order is irrelevant)
LIB|${jetty.home}/lib/example of a library with spaces.jar
LIB|${jetty.base}/lib/example of a library with spaces.jar
# The Properties we expect (order is irrelevant)
PROP|test.message=Hello

View File

@ -1,37 +1,37 @@
# The XMLs we expect (order is important)
XML|${jetty.home}/etc/jetty-jmx.xml
XML|${jetty.home}/etc/jetty.xml
XML|${jetty.home}/etc/jetty-http.xml
XML|${jetty.home}/etc/jetty-plus.xml
XML|${jetty.home}/etc/jetty-annotations.xml
XML|${jetty.home}/etc/jetty-websockets.xml
XML|${jetty.base}/etc/jetty-jmx.xml
XML|${jetty.base}/etc/jetty.xml
XML|${jetty.base}/etc/jetty-http.xml
XML|${jetty.base}/etc/jetty-plus.xml
XML|${jetty.base}/etc/jetty-annotations.xml
XML|${jetty.base}/etc/jetty-websockets.xml
# The LIBs we expect (order is irrelevant)
LIB|${jetty.home}/lib/annotations/javax.annotation-api-1.2.jar
LIB|${jetty.home}/lib/annotations/org.objectweb.asm-TEST.jar
LIB|${jetty.home}/lib/jetty-annotations-TEST.jar
LIB|${jetty.home}/lib/jetty-continuation-TEST.jar
LIB|${jetty.home}/lib/jetty-http-TEST.jar
LIB|${jetty.home}/lib/jetty-io-TEST.jar
LIB|${jetty.home}/lib/jetty-jmx-TEST.jar
LIB|${jetty.home}/lib/jetty-jndi-TEST.jar
LIB|${jetty.home}/lib/jetty-plus-TEST.jar
LIB|${jetty.home}/lib/jetty-schemas-3.1.jar
LIB|${jetty.home}/lib/jetty-security-TEST.jar
LIB|${jetty.home}/lib/jetty-server-TEST.jar
LIB|${jetty.home}/lib/jetty-util-TEST.jar
LIB|${jetty.home}/lib/jetty-xml-TEST.jar
LIB|${jetty.home}/lib/jndi/javax.activation-1.1.jar
LIB|${jetty.home}/lib/jndi/javax.transaction-api-1.2.jar
LIB|${jetty.home}/lib/servlet-api-3.1.jar
LIB|${jetty.home}/lib/websocket/javax.websocket-api-1.0.jar
LIB|${jetty.home}/lib/websocket/javax-websocket-client-impl-TEST.jar
LIB|${jetty.home}/lib/websocket/javax-websocket-server-impl-TEST.jar
LIB|${jetty.home}/lib/websocket/websocket-api-TEST.jar
LIB|${jetty.home}/lib/websocket/websocket-client-TEST.jar
LIB|${jetty.home}/lib/websocket/websocket-common-TEST.jar
LIB|${jetty.home}/lib/websocket/websocket-server-TEST.jar
LIB|${jetty.home}/lib/websocket/websocket-servlet-TEST.jar
LIB|${jetty.base}/lib/annotations/javax.annotation-api-1.2.jar
LIB|${jetty.base}/lib/annotations/org.objectweb.asm-TEST.jar
LIB|${jetty.base}/lib/jetty-annotations-TEST.jar
LIB|${jetty.base}/lib/jetty-continuation-TEST.jar
LIB|${jetty.base}/lib/jetty-http-TEST.jar
LIB|${jetty.base}/lib/jetty-io-TEST.jar
LIB|${jetty.base}/lib/jetty-jmx-TEST.jar
LIB|${jetty.base}/lib/jetty-jndi-TEST.jar
LIB|${jetty.base}/lib/jetty-plus-TEST.jar
LIB|${jetty.base}/lib/jetty-schemas-3.1.jar
LIB|${jetty.base}/lib/jetty-security-TEST.jar
LIB|${jetty.base}/lib/jetty-server-TEST.jar
LIB|${jetty.base}/lib/jetty-util-TEST.jar
LIB|${jetty.base}/lib/jetty-xml-TEST.jar
LIB|${jetty.base}/lib/jndi/javax.activation-1.1.jar
LIB|${jetty.base}/lib/jndi/javax.transaction-api-1.2.jar
LIB|${jetty.base}/lib/servlet-api-3.1.jar
LIB|${jetty.base}/lib/websocket/javax.websocket-api-1.0.jar
LIB|${jetty.base}/lib/websocket/javax-websocket-client-impl-TEST.jar
LIB|${jetty.base}/lib/websocket/javax-websocket-server-impl-TEST.jar
LIB|${jetty.base}/lib/websocket/websocket-api-TEST.jar
LIB|${jetty.base}/lib/websocket/websocket-client-TEST.jar
LIB|${jetty.base}/lib/websocket/websocket-common-TEST.jar
LIB|${jetty.base}/lib/websocket/websocket-server-TEST.jar
LIB|${jetty.base}/lib/websocket/websocket-servlet-TEST.jar
# The Properties we expect (order is irrelevant)
PROP|jetty.port=9090