use of org.eclipse.jetty.start.UsageException in project jetty.project by eclipse.
the class CommandLineConfigSource method findJettyHomePath.
private final Path findJettyHomePath() {
// If a jetty property is defined, use it
Prop prop = this.props.getProp(BaseHome.JETTY_HOME, false);
if (prop != null && !Utils.isBlank(prop.value)) {
return FS.toPath(prop.value);
}
// If a system property is defined, use it
String val = System.getProperty(BaseHome.JETTY_HOME);
if (!Utils.isBlank(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()) {
// ${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);
}
}
}
// 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;
}
use of org.eclipse.jetty.start.UsageException in project jetty.project by eclipse.
the class ConfigSourcesTest method testBadDoubleRef.
@Test
public void testBadDoubleRef() throws Exception {
// Create home
Path home = testdir.getPathFile("home");
FS.ensureEmpty(home);
TestEnv.copyTestDir("dist-home", home);
// Create common
Path common = testdir.getPathFile("common");
FS.ensureEmpty(common);
// Create corp
Path corp = testdir.getPathFile("corp");
FS.ensureEmpty(corp);
TestEnv.makeFile(corp, "start.ini", // standard property
"jetty.http.port=9090", // INTENTIONAL BAD Reference (duplicate)
"--include-jetty-dir=" + common.toString());
// Populate common
TestEnv.makeFile(common, "start.ini", // standard property
"jetty.http.port=8080", // reference to corp
"--include-jetty-dir=" + corp.toString());
// Create base
Path base = testdir.getPathFile("base");
FS.ensureEmpty(base);
//
TestEnv.makeFile(//
base, //
"start.ini", //
"jetty.http.host=127.0.0.1", "--include-jetty-dir=" + common.toString());
ConfigSources sources = new ConfigSources();
try {
String[] cmdLine = new String[0];
sources.add(new CommandLineConfigSource(cmdLine));
sources.add(new JettyHomeConfigSource(home));
sources.add(new JettyBaseConfigSource(base));
Assert.fail("Should have thrown a UsageException");
} catch (UsageException e) {
Assert.assertThat("UsageException", e.getMessage(), containsString("Duplicate"));
}
}
use of org.eclipse.jetty.start.UsageException in project jetty.project by eclipse.
the class ConfigSources method add.
public void add(ConfigSource source) throws IOException {
if (sources.contains(source)) {
// TODO: needs a better/more clear error message
throw new UsageException(ERR_BAD_ARG, "Duplicate Configuration Source Reference: " + source);
}
sources.add(source);
Collections.sort(sources, new WeightedConfigSourceComparator());
updateProps();
// look for --include-jetty-dir entries
for (RawArgs.Entry arg : source.getArgs()) {
if (arg.startsWith("--include-jetty-dir")) {
String ref = getValue(arg.getLine());
String dirName = props.expand(ref);
Path dir = FS.toPath(dirName).normalize().toAbsolutePath();
DirConfigSource dirsource = new DirConfigSource(ref, dir, sourceWeight.incrementAndGet(), true);
add(dirsource);
}
}
}
Aggregations