use of org.eclipse.jetty.start.config.CommandLineConfigSource in project jetty.project by eclipse.
the class Main method processCommandLine.
public StartArgs processCommandLine(String[] cmdLine) throws Exception {
// Processing Order is important!
// ------------------------------------------------------------
// 1) Configuration Locations
CommandLineConfigSource cmdLineSource = new CommandLineConfigSource(cmdLine);
baseHome = new BaseHome(cmdLineSource);
StartLog.debug("jetty.home=%s", baseHome.getHome());
StartLog.debug("jetty.base=%s", baseHome.getBase());
// ------------------------------------------------------------
// 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(baseHome);
args.parse(baseHome.getConfigSources());
// ------------------------------------------------------------
// 3) Module Registration
Modules modules = new Modules(baseHome, args);
StartLog.debug("Registering all modules");
modules.registerAll();
// 4) Active Module Resolution
for (String enabledModule : args.getEnabledModules()) {
for (String source : args.getSources(enabledModule)) {
String shortForm = baseHome.toShortForm(source);
modules.enable(enabledModule, shortForm);
}
}
args.setAllModules(modules);
List<Module> activeModules = modules.getEnabled();
final Version START_VERSION = new Version(StartArgs.VERSION);
for (Module enabled : activeModules) {
if (enabled.getVersion().isNewerThan(START_VERSION)) {
throw new UsageException(UsageException.ERR_BAD_GRAPH, "Module [" + enabled.getName() + "] specifies jetty version [" + enabled.getVersion() + "] which is newer than this version of jetty [" + START_VERSION + "]");
}
}
for (String name : args.getSkipFileValidationModules()) {
Module module = modules.get(name);
module.setSkipFilesValidation(true);
}
// ------------------------------------------------------------
// 5) Lib & XML Expansion / Resolution
args.expandSystemProperties();
args.expandLibs();
args.expandModules(activeModules);
// ------------------------------------------------------------
// 6) Resolve Extra XMLs
args.resolveExtraXmls();
// ------------------------------------------------------------
// 9) Resolve Property Files
args.resolvePropertyFiles();
return args;
}
use of org.eclipse.jetty.start.config.CommandLineConfigSource in project jetty.project by eclipse.
the class ModulesTest method testLoadAllModules.
@Test
public void testLoadAllModules() throws IOException {
// Test Env
File homeDir = MavenTestingUtils.getTestResourceDir("dist-home");
File baseDir = testdir.getEmptyPathDir().toFile();
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);
StartArgs args = new StartArgs(basehome);
args.parse(config);
// Test Modules
Modules modules = new Modules(basehome, args);
modules.registerAll();
// Check versions
assertThat("java.version.platform", args.getProperties().getString("java.version.platform"), anyOf(equalTo("8"), equalTo("9")));
List<String> moduleNames = new ArrayList<>();
for (Module mod : modules) {
// skip alpn-boot in this test (as its behavior is jdk specific)
if (mod.getName().equals("alpn-boot")) {
continue;
}
moduleNames.add(mod.getName());
}
List<String> expected = new ArrayList<>();
expected.add("base");
expected.add("extra");
expected.add("main");
expected.add("optional");
ConfigurationAssert.assertContainsUnordered("All Modules", expected, moduleNames);
}
use of org.eclipse.jetty.start.config.CommandLineConfigSource in project jetty.project by eclipse.
the class ModuleGraphWriterTest method testGenerate_NothingEnabled.
@Test
public void testGenerate_NothingEnabled() throws IOException {
// Test Env
Path homeDir = MavenTestingUtils.getTestResourcePathDir("dist-home");
Path baseDir = testdir.getEmptyPathDir();
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));
config.add(new JettyBaseConfigSource(baseDir));
// Initialize
BaseHome basehome = new BaseHome(config);
StartArgs args = new StartArgs(basehome);
args.parse(config);
Modules modules = new Modules(basehome, args);
modules.registerAll();
Path outputFile = basehome.getBasePath("graph.dot");
ModuleGraphWriter writer = new ModuleGraphWriter();
writer.write(modules, outputFile);
Assert.assertThat("Output File Exists", FS.exists(outputFile), is(true));
}
use of org.eclipse.jetty.start.config.CommandLineConfigSource in project jetty.project by eclipse.
the class ModuleTest method testLoadMain.
@Test
public void testLoadMain() throws IOException {
// Test Env
Path homeDir = MavenTestingUtils.getTestResourcePathDir("dist-home");
Path baseDir = testdir.getEmptyPathDir();
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));
config.add(new JettyBaseConfigSource(baseDir));
// Initialize
BaseHome basehome = new BaseHome(config);
File file = MavenTestingUtils.getTestResourceFile("dist-home/modules/main.mod");
Module module = new Module(basehome, file.toPath());
Assert.assertThat("Module Name", module.getName(), is("main"));
Assert.assertThat("Module Depends Size", module.getDepends().size(), is(1));
Assert.assertThat("Module Depends", module.getDepends(), containsInAnyOrder("base"));
Assert.assertThat("Module Xmls Size", module.getXmls().size(), is(1));
Assert.assertThat("Module Lib Size", module.getLibs().size(), is(2));
Assert.assertThat("Module Lib", module.getLibs(), contains("lib/main.jar", "lib/other.jar"));
}
use of org.eclipse.jetty.start.config.CommandLineConfigSource in project jetty.project by eclipse.
the class ModulesTest method testLoadShallowModulesOnly.
/**
* Test loading of only shallow modules, not deep references.
* In other words. ${search-dir}/modules/*.mod should be the only
* valid references, but ${search-dir}/alt/foo/modules/*.mod should
* not be considered valid.
* @throws IOException on test failures
*/
@Test
public void testLoadShallowModulesOnly() throws IOException {
// Test Env
File homeDir = MavenTestingUtils.getTestResourceDir("jetty home with spaces");
// intentionally setup top level resources dir (as this would have many
// deep references)
File baseDir = MavenTestingUtils.getTestResourcesDir();
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);
StartArgs args = new StartArgs(basehome);
args.parse(config);
// Test Modules
Modules modules = new Modules(basehome, args);
modules.registerAll();
List<String> moduleNames = new ArrayList<>();
for (Module mod : modules) {
moduleNames.add(mod.getName());
}
List<String> expected = new ArrayList<>();
expected.add("base");
ConfigurationAssert.assertContainsUnordered("All Modules", expected, moduleNames);
}
Aggregations