use of org.eclipse.jetty.start.config.ConfigSource in project jetty.project by eclipse.
the class BaseHome method toShortForm.
/**
* Replace/Shorten arbitrary path with property strings <code>"${jetty.home}"</code> or <code>"${jetty.base}"</code> where appropriate.
*
* @param path
* the path to shorten
* @return the potentially shortened path
*/
public String toShortForm(final Path path) {
Path apath = path.toAbsolutePath();
for (ConfigSource source : sources) {
if (source instanceof DirConfigSource) {
DirConfigSource dirsource = (DirConfigSource) source;
Path dir = dirsource.getDir();
if (apath.startsWith(dir)) {
if (dirsource.isPropertyBased()) {
Path relative = dir.relativize(apath);
return String.format("%s%c%s", dirsource.getId(), File.separatorChar, relative.toString());
} else {
return apath.toString();
}
}
}
}
return apath.toString();
}
use of org.eclipse.jetty.start.config.ConfigSource in project jetty.project by eclipse.
the class Main method start.
public void start(StartArgs args) throws IOException, InterruptedException {
StartLog.debug("StartArgs: %s", args);
// Get Desired Classpath based on user provided Active Options.
Classpath classpath = args.getClasspath();
System.setProperty("java.class.path", classpath.toString());
// Show the usage information and return
if (args.isHelp()) {
usage(true);
}
// Show the version information and return
if (args.isListClasspath()) {
dumpClasspathWithVersions(classpath);
}
// Show configuration
if (args.isListConfig()) {
listConfig(args);
}
// Show modules
if (args.getListModules() != null) {
listModules(args);
}
// Generate Module Graph File
if (args.getModuleGraphFilename() != null) {
Path outputFile = baseHome.getBasePath(args.getModuleGraphFilename());
System.out.printf("Generating GraphViz Graph of Jetty Modules at %s%n", baseHome.toShortForm(outputFile));
ModuleGraphWriter writer = new ModuleGraphWriter();
writer.config(args.getProperties());
writer.write(args.getAllModules(), outputFile);
}
// Show Command Line to execute Jetty
if (args.isDryRun()) {
CommandLineBuilder cmd = args.getMainArgs(true);
System.out.println(cmd.toString(StartLog.isDebugEnabled() ? " \\\n" : " "));
}
if (args.isStopCommand()) {
doStop(args);
}
if (args.isUpdateIni()) {
for (ConfigSource config : baseHome.getConfigSources()) {
System.out.printf("ConfigSource %s%n", config.getId());
for (StartIni ini : config.getStartInis()) {
for (String line : ini.getAllLines()) {
Matcher m = Module.SET_PROPERTY.matcher(line);
if (m.matches() && m.groupCount() == 3) {
String name = m.group(2);
String value = m.group(3);
Prop p = args.getProperties().getProp(name);
if (p != null && ("#".equals(m.group(1)) || !value.equals(p.value))) {
ini.update(baseHome, args.getProperties());
break;
}
}
}
}
}
}
// Check base directory
BaseBuilder baseBuilder = new BaseBuilder(baseHome, args);
if (baseBuilder.build())
StartLog.info("Base directory was modified");
else if (args.isCreateFiles() || !args.getStartModules().isEmpty())
StartLog.info("Base directory was not modified");
// Check module dependencies
args.getAllModules().checkEnabledModules();
// Informational command line, don't run jetty
if (!args.isRun()) {
return;
}
// execute Jetty in another JVM
if (args.isExec()) {
CommandLineBuilder cmd = args.getMainArgs(true);
cmd.debug();
ProcessBuilder pbuilder = new ProcessBuilder(cmd.getArgs());
StartLog.endStartLog();
final Process process = pbuilder.start();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
StartLog.debug("Destroying " + process);
process.destroy();
}
});
copyInThread(process.getErrorStream(), System.err);
copyInThread(process.getInputStream(), System.out);
copyInThread(System.in, process.getOutputStream());
process.waitFor();
// exit JVM when child process ends.
System.exit(0);
return;
}
if (args.hasJvmArgs() || args.hasSystemProperties()) {
StartLog.warn("System properties and/or JVM args set. Consider using --dry-run or --exec");
}
ClassLoader cl = classpath.getClassLoader();
Thread.currentThread().setContextClassLoader(cl);
// Invoke the Main Class
try {
invokeMain(cl, args);
} catch (Throwable e) {
e.printStackTrace();
usageExit(e, ERR_INVOKE_MAIN, args.isTestingModeEnabled());
}
}
use of org.eclipse.jetty.start.config.ConfigSource in project jetty.project by eclipse.
the class BaseHome method getPaths.
/**
* Get a List of {@link Path}s from a provided pattern.
* <p>
* Resolution Steps:
* <ol>
* <li>If the pattern starts with "regex:" or "glob:" then a standard {@link PathMatcher} is built using
* {@link java.nio.file.FileSystem#getPathMatcher(String)} as a file search.</li>
* <li>If pattern starts with a known filesystem root (using information from {@link java.nio.file.FileSystem#getRootDirectories()}) then this is assumed to
* be a absolute file system pattern.</li>
* <li>All other patterns are treated as relative to BaseHome information:
* <ol>
* <li>Search ${jetty.home} first</li>
* <li>Search ${jetty.base} for overrides</li>
* </ol>
* </li>
* </ol>
* <p>
* Pattern examples:
* <dl>
* <dt><code>lib/logging/*.jar</code></dt>
* <dd>Relative pattern, not recursive, search <code>${jetty.home}</code> then <code>${jetty.base}</code> for lib/logging/*.jar content</dd>
*
* <dt><code>lib/**/*-dev.jar</code></dt>
* <dd>Relative pattern, recursive search <code>${jetty.home}</code> then <code>${jetty.base}</code> for files under <code>lib</code> ending in
* <code>-dev.jar</code></dd>
*
* <dt><code>etc/jetty.xml</code></dt>
* <dd>Relative pattern, no glob, search for <code>${jetty.home}/etc/jetty.xml</code> then <code>${jetty.base}/etc/jetty.xml</code></dd>
*
* <dt><code>glob:/opt/app/common/*-corp.jar</code></dt>
* <dd>PathMapper pattern, glob, search <code>/opt/app/common/</code> for <code>*-corp.jar</code></dd>
*
* </dl>
*
* <p>
* Notes:
* <ul>
* <li>FileSystem case sensitivity is implementation specific (eg: linux is case-sensitive, windows is case-insensitive).<br>
* See {@link java.nio.file.FileSystem#getPathMatcher(String)} for more details</li>
* <li>Pattern slashes are implementation neutral (use '/' always and you'll be fine)</li>
* <li>Recursive searching is limited to 30 levels deep (not configurable)</li>
* <li>File System loops are detected and skipped</li>
* </ul>
*
* @param pattern
* the pattern to search.
* @return the collection of paths found
* @throws IOException
* if error during search operation
*/
public List<Path> getPaths(String pattern) throws IOException {
StartLog.debug("getPaths('%s')", pattern);
List<Path> hits = new ArrayList<>();
if (PathMatchers.isAbsolute(pattern)) {
// Perform absolute path pattern search
// The root to start search from
Path root = PathMatchers.getSearchRoot(pattern);
// The matcher for file hits
PathMatcher matcher = PathMatchers.getMatcher(pattern);
if (FS.isValidDirectory(root)) {
PathFinder finder = new PathFinder();
finder.setIncludeDirsInResults(true);
finder.setFileMatcher(matcher);
finder.setBase(root);
Files.walkFileTree(root, SEARCH_VISIT_OPTIONS, MAX_SEARCH_DEPTH, finder);
hits.addAll(finder.getHits());
}
} else {
// Perform relative path pattern search
Path relativePath = PathMatchers.getSearchRoot(pattern);
PathMatcher matcher = PathMatchers.getMatcher(pattern);
PathFinder finder = new PathFinder();
finder.setIncludeDirsInResults(true);
finder.setFileMatcher(matcher);
// walk config sources backwards ...
ListIterator<ConfigSource> iter = sources.reverseListIterator();
while (iter.hasPrevious()) {
ConfigSource source = iter.previous();
if (source instanceof DirConfigSource) {
DirConfigSource dirsource = (DirConfigSource) source;
Path dir = dirsource.getDir();
Path deepDir = dir.resolve(relativePath);
if (FS.isValidDirectory(deepDir)) {
finder.setBase(dir);
Files.walkFileTree(deepDir, SEARCH_VISIT_OPTIONS, MAX_SEARCH_DEPTH, finder);
}
}
}
hits.addAll(finder.getHits());
}
Collections.sort(hits, new NaturalSort.Paths());
return hits;
}
use of org.eclipse.jetty.start.config.ConfigSource in project jetty.project by eclipse.
the class BaseHome method getPath.
/**
* Get a specific path reference.
* <p>
* Path references are searched based on the config source search order.
* <ol>
* <li>If provided path is an absolute reference., and exists, return that reference</li>
* <li>If exists relative to <code>${jetty.base}</code>, return that reference</li>
* <li>If exists relative to and <code>include-jetty-dir</code> locations, return that reference</li>
* <li>If exists relative to <code>${jetty.home}</code>, return that reference</li>
* <li>Return standard {@link Path} reference obtained from {@link java.nio.file.FileSystem#getPath(String, String...)} (no exists check performed)</li>
* </ol>
*
* @param path
* the path to get.
* @return the path reference.
*/
public Path getPath(final String path) {
Path apath = FS.toPath(path);
if (apath.isAbsolute()) {
if (FS.exists(apath)) {
return apath;
}
}
for (ConfigSource source : sources) {
if (source instanceof DirConfigSource) {
DirConfigSource dirsource = (DirConfigSource) source;
Path file = dirsource.getDir().resolve(apath);
if (FS.exists(file)) {
return file;
}
}
}
// Finally, as an anonymous path
return FS.toPath(path);
}
use of org.eclipse.jetty.start.config.ConfigSource in project jetty.project by eclipse.
the class StartArgs method dumpEnvironment.
public void dumpEnvironment() {
// Java Details
System.out.println();
System.out.println("Java Environment:");
System.out.println("-----------------");
dumpSystemProperty("java.home");
dumpSystemProperty("java.vm.vendor");
dumpSystemProperty("java.vm.version");
dumpSystemProperty("java.vm.name");
dumpSystemProperty("java.vm.info");
dumpSystemProperty("java.runtime.name");
dumpSystemProperty("java.runtime.version");
dumpSystemProperty("java.io.tmpdir");
dumpSystemProperty("user.dir");
dumpSystemProperty("user.language");
dumpSystemProperty("user.country");
// Jetty Environment
System.out.println();
System.out.println("Jetty Environment:");
System.out.println("-----------------");
dumpProperty("jetty.version");
dumpProperty("jetty.tag.version");
dumpProperty("jetty.home");
dumpProperty("jetty.base");
// Jetty Configuration Environment
System.out.println();
System.out.println("Config Search Order:");
System.out.println("--------------------");
for (ConfigSource config : baseHome.getConfigSources()) {
System.out.printf(" %s", config.getId());
if (config instanceof DirConfigSource) {
DirConfigSource dirsource = (DirConfigSource) config;
if (dirsource.isPropertyBased()) {
System.out.printf(" -> %s", dirsource.getDir());
}
}
System.out.println();
}
// Jetty Se
System.out.println();
}
Aggregations