use of org.eclipse.jetty.start.config.DirConfigSource 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.DirConfigSource 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.DirConfigSource 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.DirConfigSource 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