Merge branch 'extra-start-dirs'
This commit is contained in:
commit
2dc10da3a4
|
@ -29,6 +29,7 @@ import java.net.HttpURLConnection;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -85,12 +86,14 @@ public class NPNModuleTest
|
|||
private static BaseHome basehome;
|
||||
|
||||
@BeforeClass
|
||||
public static void initBaseHome()
|
||||
public static void initBaseHome() throws IOException
|
||||
{
|
||||
File homeDir = MavenTestingUtils.getProjectDir("../spdy-http-server/src/main/config");
|
||||
File baseDir = MavenTestingUtils.getTargetTestingDir(NPNModuleTest.class.getName());
|
||||
FS.ensureEmpty(baseDir);
|
||||
basehome = new BaseHome(homeDir,baseDir);
|
||||
|
||||
String cmdLine[] = { "jetty.home="+homeDir.getAbsolutePath(),"jetty.base="+baseDir.getAbsolutePath() };
|
||||
basehome = new BaseHome(cmdLine);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,7 +102,7 @@ public class NPNModuleTest
|
|||
@Test
|
||||
public void testModuleValues() throws IOException
|
||||
{
|
||||
File modFile = basehome.getFile("modules/protonego-impl/" + modBootFile);
|
||||
Path modFile = basehome.getPath("modules/protonego-impl/" + modBootFile);
|
||||
Module mod = new Module(basehome,modFile);
|
||||
assertNotNull("module",mod);
|
||||
|
||||
|
@ -128,7 +131,7 @@ public class NPNModuleTest
|
|||
StringBuilder err = new StringBuilder();
|
||||
err.append("XBootClasspath mismatch between [files] and [exec]");
|
||||
err.append("\nThe following are inferred from your [files] definition in ");
|
||||
err.append(modFile.getAbsolutePath());
|
||||
err.append(modFile.toAbsolutePath().toString());
|
||||
err.append("\nbut are not referenced in your [exec] section");
|
||||
for (String entry : expectedBootClasspath)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
@ -31,8 +28,15 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Objects;
|
||||
|
||||
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.
|
||||
|
@ -45,48 +49,129 @@ import java.util.regex.Pattern;
|
|||
*/
|
||||
public class BaseHome
|
||||
{
|
||||
private final static EnumSet<FileVisitOption> SEARCH_VISIT_OPTIONS = EnumSet.of(FileVisitOption.FOLLOW_LINKS);;
|
||||
private final static int MAX_SEARCH_DEPTH = 30;
|
||||
|
||||
private File homeDir;
|
||||
private File baseDir;
|
||||
|
||||
public BaseHome()
|
||||
public static class SearchDir
|
||||
{
|
||||
try
|
||||
{
|
||||
this.baseDir = new File(System.getProperty("jetty.base",System.getProperty("user.dir",".")));
|
||||
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())
|
||||
{
|
||||
homeDir = new File(new URI(m.group(1))).getParentFile();
|
||||
}
|
||||
}
|
||||
homeDir = new File(System.getProperty("jetty.home",(homeDir == null?baseDir:homeDir).getAbsolutePath()));
|
||||
private Path dir;
|
||||
private String name;
|
||||
|
||||
baseDir = baseDir.getAbsoluteFile().getCanonicalFile();
|
||||
homeDir = homeDir.getAbsoluteFile().getCanonicalFile();
|
||||
}
|
||||
catch (IOException | URISyntaxException e)
|
||||
public SearchDir(String name)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Path getDir()
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
public Path resolve(Path subpath)
|
||||
{
|
||||
return dir.resolve(subpath);
|
||||
}
|
||||
|
||||
public Path resolve(String subpath)
|
||||
{
|
||||
return dir.resolve(FS.separators(subpath));
|
||||
}
|
||||
|
||||
public SearchDir setDir(File path)
|
||||
{
|
||||
if (path != null)
|
||||
{
|
||||
return setDir(path.toPath());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SearchDir setDir(Path path)
|
||||
{
|
||||
if (path != null)
|
||||
{
|
||||
this.dir = path.toAbsolutePath();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SearchDir setDir(String path)
|
||||
{
|
||||
if (path != null)
|
||||
{
|
||||
return setDir(FS.toPath(path));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public String toShortForm(Path path)
|
||||
{
|
||||
Path relative = dir.relativize(path);
|
||||
return String.format("${%s}%c%s",name,File.separatorChar,relative.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public BaseHome(File homeDir, File baseDir)
|
||||
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 final ConfigSources sources;
|
||||
private final Path homeDir;
|
||||
private final Path baseDir;
|
||||
|
||||
public BaseHome() throws IOException
|
||||
{
|
||||
try
|
||||
this(new String[0]);
|
||||
}
|
||||
|
||||
public BaseHome(String cmdLine[]) throws IOException
|
||||
{
|
||||
this(new CommandLineConfigSource(cmdLine));
|
||||
}
|
||||
|
||||
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.homeDir = homeDir.getCanonicalFile();
|
||||
this.baseDir = baseDir == null?this.homeDir:baseDir.getCanonicalFile();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
|
@ -95,12 +180,16 @@ public class BaseHome
|
|||
{
|
||||
return null;
|
||||
}
|
||||
return baseDir.getAbsolutePath();
|
||||
return baseDir.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #getBasePath()}
|
||||
*/
|
||||
@Deprecated
|
||||
public File getBaseDir()
|
||||
{
|
||||
return baseDir;
|
||||
return baseDir.toFile();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,10 +198,27 @@ public class BaseHome
|
|||
* @param path
|
||||
* the path to reference
|
||||
* @return the file reference
|
||||
* @deprecated use {@link #getBasePath(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public File getBaseFile(String path)
|
||||
{
|
||||
return new File(baseDir,FS.separators(path));
|
||||
return baseDir.resolve(path).toFile();
|
||||
}
|
||||
|
||||
public Path getBasePath()
|
||||
{
|
||||
return baseDir;
|
||||
}
|
||||
|
||||
public Path getBasePath(String path)
|
||||
{
|
||||
return baseDir.resolve(path);
|
||||
}
|
||||
|
||||
public ConfigSources getConfigSources()
|
||||
{
|
||||
return this.sources;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,30 +234,110 @@ public class BaseHome
|
|||
* @param path
|
||||
* the path to get.
|
||||
* @return the file reference.
|
||||
* @deprecated use {@link #getPath(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public File getFile(String path)
|
||||
{
|
||||
String rpath = FS.separators(path);
|
||||
return getPath(path).toAbsolutePath().toFile();
|
||||
}
|
||||
|
||||
// Relative to Base Directory First
|
||||
if (isBaseDifferent())
|
||||
public String getHome()
|
||||
{
|
||||
return homeDir.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #getHomePath()}
|
||||
*/
|
||||
@Deprecated
|
||||
public File getHomeDir()
|
||||
{
|
||||
return homeDir.toFile();
|
||||
}
|
||||
|
||||
public Path getHomePath()
|
||||
{
|
||||
return homeDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>extra-start-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())
|
||||
{
|
||||
File file = new File(baseDir,rpath);
|
||||
if (file.exists())
|
||||
if (FS.exists(apath))
|
||||
{
|
||||
return file;
|
||||
return apath;
|
||||
}
|
||||
}
|
||||
|
||||
// Then relative to Home Directory
|
||||
File file = new File(homeDir,rpath);
|
||||
if (file.exists())
|
||||
for (ConfigSource source : sources)
|
||||
{
|
||||
return file;
|
||||
if (source instanceof DirConfigSource)
|
||||
{
|
||||
DirConfigSource dirsource = (DirConfigSource)source;
|
||||
Path file = dirsource.getDir().resolve(apath);
|
||||
if (FS.exists(file))
|
||||
{
|
||||
return file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, as an absolute path
|
||||
return new File(rpath);
|
||||
// Finally, as an anonymous path
|
||||
return FS.toPath(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search specified Path with pattern and return hits
|
||||
*
|
||||
* @param dir
|
||||
* the path to a directory to start search from
|
||||
* @param searchDepth
|
||||
* the number of directories deep to perform the search
|
||||
* @param pattern
|
||||
* the raw pattern to use for the search (must be relative)
|
||||
* @return the list of Paths found
|
||||
* @throws IOException
|
||||
* if unable to search the path
|
||||
*/
|
||||
public List<Path> getPaths(Path dir, int searchDepth, String pattern) throws IOException
|
||||
{
|
||||
if (PathMatchers.isAbsolute(pattern))
|
||||
{
|
||||
throw new RuntimeException("Pattern cannot be absolute: " + pattern);
|
||||
}
|
||||
|
||||
List<Path> hits = new ArrayList<>();
|
||||
if (FS.isValidDirectory(dir))
|
||||
{
|
||||
PathMatcher matcher = PathMatchers.getMatcher(pattern);
|
||||
PathFinder finder = new PathFinder();
|
||||
finder.setFileMatcher(matcher);
|
||||
finder.setBase(dir);
|
||||
Files.walkFileTree(dir,SEARCH_VISIT_OPTIONS,searchDepth,finder);
|
||||
hits.addAll(finder.getHits());
|
||||
Collections.sort(hits,new NaturalSort.Paths());
|
||||
}
|
||||
return hits;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,11 +393,16 @@ public class BaseHome
|
|||
*/
|
||||
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))
|
||||
|
@ -226,29 +417,31 @@ public class BaseHome
|
|||
}
|
||||
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);
|
||||
|
||||
Path homePath = homeDir.toPath().resolve(relativePath);
|
||||
|
||||
if (FS.isValidDirectory(homePath))
|
||||
// walk config sources backwards ...
|
||||
ListIterator<ConfigSource> iter = sources.reverseListIterator();
|
||||
while (iter.hasPrevious())
|
||||
{
|
||||
finder.setBase(homePath);
|
||||
Files.walkFileTree(homePath,SEARCH_VISIT_OPTIONS,MAX_SEARCH_DEPTH,finder);
|
||||
}
|
||||
|
||||
if (isBaseDifferent())
|
||||
{
|
||||
Path basePath = baseDir.toPath().resolve(relativePath);
|
||||
if (FS.isValidDirectory(basePath))
|
||||
ConfigSource source = iter.previous();
|
||||
if (source instanceof DirConfigSource)
|
||||
{
|
||||
finder.setBase(basePath);
|
||||
Files.walkFileTree(basePath,SEARCH_VISIT_OPTIONS,MAX_SEARCH_DEPTH,finder);
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -256,142 +449,17 @@ public class BaseHome
|
|||
return hits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search specified Path with pattern and return hits
|
||||
*
|
||||
* @param dir
|
||||
* the path to a directory to start search from
|
||||
* @param searchDepth
|
||||
* the number of directories deep to perform the search
|
||||
* @param pattern
|
||||
* the raw pattern to use for the search (must be relative)
|
||||
* @return the list of Paths found
|
||||
* @throws IOException
|
||||
* if unable to search the path
|
||||
*/
|
||||
public List<Path> getPaths(Path dir, int searchDepth, String pattern) throws IOException
|
||||
{
|
||||
if (PathMatchers.isAbsolute(pattern))
|
||||
{
|
||||
throw new RuntimeException("Pattern cannot be absolute: " + pattern);
|
||||
}
|
||||
|
||||
List<Path> hits = new ArrayList<>();
|
||||
if (FS.isValidDirectory(dir))
|
||||
{
|
||||
PathMatcher matcher = PathMatchers.getMatcher(pattern);
|
||||
PathFinder finder = new PathFinder();
|
||||
finder.setFileMatcher(matcher);
|
||||
finder.setBase(dir);
|
||||
Files.walkFileTree(dir,SEARCH_VISIT_OPTIONS,searchDepth,finder);
|
||||
hits.addAll(finder.getHits());
|
||||
Collections.sort(hits,new NaturalSort.Paths());
|
||||
}
|
||||
return hits;
|
||||
}
|
||||
|
||||
public String getHome()
|
||||
{
|
||||
return homeDir.getAbsolutePath();
|
||||
}
|
||||
|
||||
public File getHomeDir()
|
||||
{
|
||||
return homeDir;
|
||||
}
|
||||
|
||||
public void initialize(StartArgs args)
|
||||
{
|
||||
Pattern jetty_home = Pattern.compile("(-D)?jetty.home=(.*)");
|
||||
Pattern jetty_base = Pattern.compile("(-D)?jetty.base=(.*)");
|
||||
|
||||
File homePath = null;
|
||||
File basePath = null;
|
||||
|
||||
for (String arg : args.getCommandLine())
|
||||
{
|
||||
Matcher home_match = jetty_home.matcher(arg);
|
||||
if (home_match.matches())
|
||||
{
|
||||
homePath = new File(home_match.group(2));
|
||||
}
|
||||
Matcher base_match = jetty_base.matcher(arg);
|
||||
if (base_match.matches())
|
||||
{
|
||||
basePath = new File(base_match.group(2));
|
||||
}
|
||||
}
|
||||
|
||||
if (homePath != null)
|
||||
{
|
||||
// logic if home is specified
|
||||
this.homeDir = homePath.getAbsoluteFile();
|
||||
if (basePath == null)
|
||||
{
|
||||
this.baseDir = homePath.getAbsoluteFile();
|
||||
args.getProperties().setProperty("jetty.base",this.baseDir.toString(),"<internal-fallback>");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.baseDir = basePath.getAbsoluteFile();
|
||||
}
|
||||
}
|
||||
else if (basePath != null)
|
||||
{
|
||||
// logic if home is undeclared
|
||||
this.baseDir = basePath.getAbsoluteFile();
|
||||
}
|
||||
|
||||
// Update System Properties
|
||||
args.addSystemProperty("jetty.home",this.homeDir.getAbsolutePath());
|
||||
args.addSystemProperty("jetty.base",this.baseDir.getAbsolutePath());
|
||||
}
|
||||
|
||||
public boolean isBaseDifferent()
|
||||
{
|
||||
return homeDir.compareTo(baseDir) != 0;
|
||||
}
|
||||
|
||||
public void setBaseDir(File dir)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.baseDir = dir.getCanonicalFile();
|
||||
System.setProperty("jetty.base",dir.getCanonicalPath());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
public void setHomeDir(File dir)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.homeDir = dir.getCanonicalFile();
|
||||
System.setProperty("jetty.home",dir.getCanonicalPath());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for <code>toShortForm(file.getCanonicalPath())</code>
|
||||
* Convenience method for <code>toShortForm(file.toPath())</code>
|
||||
*/
|
||||
public String toShortForm(File path)
|
||||
public String toShortForm(final File path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return toShortForm(path.getCanonicalPath());
|
||||
}
|
||||
catch (IOException ignore)
|
||||
{
|
||||
/* ignore */
|
||||
}
|
||||
return toShortForm(path.getAbsolutePath());
|
||||
return toShortForm(path.toPath());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -401,32 +469,48 @@ public class BaseHome
|
|||
* the path to shorten
|
||||
* @return the potentially shortened path
|
||||
*/
|
||||
public String toShortForm(String 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 String path)
|
||||
{
|
||||
if (path == null)
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
String value;
|
||||
|
||||
if (isBaseDifferent())
|
||||
{
|
||||
value = baseDir.getAbsolutePath();
|
||||
if (path.startsWith(value))
|
||||
{
|
||||
return "${jetty.base}" + path.substring(value.length());
|
||||
}
|
||||
}
|
||||
|
||||
value = homeDir.getAbsolutePath();
|
||||
|
||||
if (path.startsWith(value))
|
||||
{
|
||||
return "${jetty.home}" + path.substring(value.length());
|
||||
}
|
||||
|
||||
return path;
|
||||
return toShortForm(FS.toPath(path));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,145 +20,15 @@ package org.eclipse.jetty.start;
|
|||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class FS
|
||||
{
|
||||
@Deprecated
|
||||
public static class AllFilter implements FileFilter
|
||||
{
|
||||
public static final AllFilter INSTANCE = new AllFilter();
|
||||
|
||||
@Override
|
||||
public boolean accept(File pathname)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static class DirFilter implements FileFilter
|
||||
{
|
||||
public static final DirFilter INSTANCE = new DirFilter();
|
||||
|
||||
@Override
|
||||
public boolean accept(File path)
|
||||
{
|
||||
return path.isDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static class RelativeRegexFilter implements FileFilter
|
||||
{
|
||||
private final File baseDir;
|
||||
private final Pattern pattern;
|
||||
|
||||
public RelativeRegexFilter(File baseDir, Pattern pattern)
|
||||
{
|
||||
this.baseDir = baseDir;
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(File path)
|
||||
{
|
||||
// get relative path
|
||||
String relativePath = FS.toRelativePath(baseDir,path);
|
||||
|
||||
// see if it matches
|
||||
return (pattern.matcher(relativePath).matches());
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static class FilenameRegexFilter implements FileFilter
|
||||
{
|
||||
private final Pattern pattern;
|
||||
|
||||
public FilenameRegexFilter(String regex)
|
||||
{
|
||||
pattern = Pattern.compile(regex,Pattern.CASE_INSENSITIVE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(File path)
|
||||
{
|
||||
return path.isFile() && pattern.matcher(path.getName()).matches();
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static class FileNamesFilter implements FileFilter
|
||||
{
|
||||
private final String filenames[];
|
||||
|
||||
public FileNamesFilter(String... names)
|
||||
{
|
||||
this.filenames = names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(File path)
|
||||
{
|
||||
if (!path.isFile())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (String name : filenames)
|
||||
{
|
||||
if (name.equalsIgnoreCase(path.getName()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static class IniFilter extends FilenameRegexFilter
|
||||
{
|
||||
public IniFilter()
|
||||
{
|
||||
super("^.*\\.ini$");
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static class XmlFilter extends FilenameRegexFilter
|
||||
{
|
||||
public XmlFilter()
|
||||
{
|
||||
super("^.*\\.xml$");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isValidDirectory(Path path)
|
||||
{
|
||||
LinkOption lopts[] = new LinkOption[0];
|
||||
if (!Files.exists(path,lopts))
|
||||
{
|
||||
// doesn't exist, not a valid directory
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Files.isDirectory(path,lopts))
|
||||
{
|
||||
// not a directory (as expected)
|
||||
StartLog.warn("Not a directory: " + path);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean canReadDirectory(File path)
|
||||
{
|
||||
return (path.exists() && path.isDirectory() && path.canRead());
|
||||
|
@ -166,8 +36,7 @@ public class FS
|
|||
|
||||
public static boolean canReadDirectory(Path path)
|
||||
{
|
||||
LinkOption lopts[] = new LinkOption[0];
|
||||
return Files.exists(path,lopts) && Files.isDirectory(path,lopts) && Files.isReadable(path);
|
||||
return Files.exists(path) && Files.isDirectory(path) && Files.isReadable(path);
|
||||
}
|
||||
|
||||
public static boolean canReadFile(File path)
|
||||
|
@ -175,6 +44,16 @@ public class FS
|
|||
return (path.exists() && path.isFile() && path.canRead());
|
||||
}
|
||||
|
||||
public static boolean canReadFile(Path path)
|
||||
{
|
||||
return Files.exists(path) && Files.isRegularFile(path) && Files.isReadable(path);
|
||||
}
|
||||
|
||||
public static boolean canWrite(Path path)
|
||||
{
|
||||
return Files.isWritable(path);
|
||||
}
|
||||
|
||||
public static void close(Closeable c)
|
||||
{
|
||||
if (c == null)
|
||||
|
@ -192,6 +71,16 @@ public class FS
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean createNewFile(Path path) throws IOException
|
||||
{
|
||||
Path ret = Files.createFile(path);
|
||||
return Files.exists(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #ensureDirectoryExists(Path)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static void ensureDirectoryExists(File dir) throws IOException
|
||||
{
|
||||
if (dir.exists())
|
||||
|
@ -203,7 +92,21 @@ public class FS
|
|||
throw new IOException("Unable to create directory: " + dir.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
public static void ensureDirectoryExists(Path dir) throws IOException
|
||||
{
|
||||
if (exists(dir))
|
||||
{
|
||||
// exists already, nothing to do
|
||||
return;
|
||||
}
|
||||
Files.createDirectories(dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #ensureDirectoryWritable(Path)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static void ensureDirectoryWritable(File dir) throws IOException
|
||||
{
|
||||
if (!dir.exists())
|
||||
|
@ -216,6 +119,27 @@ public class FS
|
|||
}
|
||||
}
|
||||
|
||||
public static void ensureDirectoryWritable(Path dir) throws IOException
|
||||
{
|
||||
if (!Files.exists(dir))
|
||||
{
|
||||
throw new IOException("Path does not exist: " + dir.toAbsolutePath());
|
||||
}
|
||||
if (!Files.isDirectory(dir))
|
||||
{
|
||||
throw new IOException("Directory does not exist: " + dir.toAbsolutePath());
|
||||
}
|
||||
if (!Files.isWritable(dir))
|
||||
{
|
||||
throw new IOException("Unable to write to directory: " + dir.toAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean exists(Path path)
|
||||
{
|
||||
return Files.exists(path);
|
||||
}
|
||||
|
||||
public static boolean isFile(File file)
|
||||
{
|
||||
if (file == null)
|
||||
|
@ -225,16 +149,29 @@ public class FS
|
|||
return file.exists() && file.isFile();
|
||||
}
|
||||
|
||||
public static boolean isValidDirectory(Path path)
|
||||
{
|
||||
if (!Files.exists(path))
|
||||
{
|
||||
// doesn't exist, not a valid directory
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Files.isDirectory(path))
|
||||
{
|
||||
// not a directory (as expected)
|
||||
StartLog.warn("Not a directory: " + path);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isXml(String filename)
|
||||
{
|
||||
return filename.toLowerCase(Locale.ENGLISH).endsWith(".xml");
|
||||
}
|
||||
|
||||
public static String toRelativePath(File baseDir, File path)
|
||||
{
|
||||
return baseDir.toURI().relativize(path.toURI()).toASCIIString();
|
||||
}
|
||||
|
||||
public static String separators(String path)
|
||||
{
|
||||
StringBuilder ret = new StringBuilder();
|
||||
|
@ -252,8 +189,24 @@ public class FS
|
|||
return ret.toString();
|
||||
}
|
||||
|
||||
public static boolean exists(Path path)
|
||||
public static Path toPath(String path)
|
||||
{
|
||||
return Files.exists(path,new LinkOption[0]);
|
||||
return FileSystems.getDefault().getPath(FS.separators(path));
|
||||
}
|
||||
|
||||
public static String toRelativePath(File baseDir, File path)
|
||||
{
|
||||
return baseDir.toURI().relativize(path.toURI()).toASCIIString();
|
||||
}
|
||||
|
||||
public static void touch(Path path) throws IOException
|
||||
{
|
||||
FileTime now = FileTime.fromMillis(System.currentTimeMillis());
|
||||
Files.setLastModifiedTime(path,now);
|
||||
}
|
||||
|
||||
public static Path toRealPath(Path path) throws IOException
|
||||
{
|
||||
return path.toRealPath();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,8 @@ package org.eclipse.jetty.start;
|
|||
import static org.eclipse.jetty.start.UsageException.*;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -37,7 +36,10 @@ import java.net.InetAddress;
|
|||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -48,6 +50,8 @@ import java.util.Set;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.jetty.start.config.CommandLineConfigSource;
|
||||
|
||||
/**
|
||||
* Main start class.
|
||||
* <p>
|
||||
|
@ -131,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)
|
||||
|
@ -168,11 +171,12 @@ public class Main
|
|||
{
|
||||
try
|
||||
{
|
||||
File file = baseHome.getBaseFile(arg.location);
|
||||
Path file = baseHome.getBasePath(arg.location);
|
||||
|
||||
StartLog.debug("Module file %s %s",file.getAbsolutePath(),(file.exists()?"[Exists!]":""));
|
||||
if (file.exists())
|
||||
StartLog.debug("Module file %s %s",file.toAbsolutePath(),(FS.exists(file)?"[Exists!]":""));
|
||||
if (FS.exists(file))
|
||||
{
|
||||
// file already initialized / downloaded, skip it
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -182,10 +186,11 @@ public class Main
|
|||
|
||||
System.err.println("DOWNLOAD: " + url + " to " + arg.location);
|
||||
|
||||
FS.ensureDirectoryExists(file.getParentFile());
|
||||
FS.ensureDirectoryExists(file.getParent());
|
||||
|
||||
byte[] buf = new byte[8192];
|
||||
try (InputStream in = url.openStream(); OutputStream out = new FileOutputStream(file);)
|
||||
try (InputStream in = url.openStream();
|
||||
OutputStream out = Files.newOutputStream(file,StandardOpenOption.CREATE_NEW,StandardOpenOption.WRITE))
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
|
@ -205,11 +210,12 @@ public class Main
|
|||
else if (arg.location.endsWith("/"))
|
||||
{
|
||||
System.err.println("MKDIR: " + baseHome.toShortForm(file));
|
||||
file.mkdirs();
|
||||
FS.ensureDirectoryExists(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
StartLog.warn("MISSING: required file "+ baseHome.toShortForm(file));
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -334,10 +340,23 @@ public class Main
|
|||
modules.dumpEnabledTree();
|
||||
}
|
||||
|
||||
private void moduleIni(StartArgs args, String name, boolean topLevel, boolean appendStartIni) throws IOException
|
||||
/**
|
||||
* Build out INI file.
|
||||
* <p>
|
||||
* This applies equally for either <code>${jetty.base}/start.ini</code> or
|
||||
* <code>${jetty.base}/start.d/${name}.ini</code>
|
||||
*
|
||||
* @param args the arguments of what modules are enabled
|
||||
* @param name the name of the module to based the build of the ini
|
||||
* @param topLevel
|
||||
* @param appendStartIni true to append to <code>${jetty.base}/start.ini</code>,
|
||||
* false to create a <code>${jetty.base}/start.d/${name}.ini</code> entry instead.
|
||||
* @throws IOException
|
||||
*/
|
||||
private void buildIni(StartArgs args, String name, boolean topLevel, boolean appendStartIni) throws IOException
|
||||
{
|
||||
// Find the start.d relative to the base directory only.
|
||||
File start_d = baseHome.getBaseFile("start.d");
|
||||
Path start_d = baseHome.getBasePath("start.d");
|
||||
|
||||
// Is this a module?
|
||||
Modules modules = args.getAllModules();
|
||||
|
@ -349,12 +368,12 @@ public class Main
|
|||
}
|
||||
|
||||
// Find any named ini file and check it follows the convention
|
||||
File start_ini = baseHome.getBaseFile("start.ini");
|
||||
Path start_ini = baseHome.getBasePath("start.ini");
|
||||
String short_start_ini = baseHome.toShortForm(start_ini);
|
||||
File ini = new File(start_d,name + ".ini");
|
||||
Path ini = start_d.resolve(name + ".ini");
|
||||
String short_ini = baseHome.toShortForm(ini);
|
||||
StartIni module_ini = null;
|
||||
if (ini.exists())
|
||||
if (FS.exists(ini))
|
||||
{
|
||||
module_ini = new StartIni(ini);
|
||||
if (module_ini.getLineMatches(Pattern.compile("--module=(.*, *)*" + name)).size() == 0)
|
||||
|
@ -368,46 +387,30 @@ public class Main
|
|||
boolean has_ini_lines = module.getInitialise().size() > 0;
|
||||
|
||||
// If it is not enabled or is transitive with ini template lines or toplevel and doesn't exist
|
||||
if (!module.isEnabled() || (transitive && has_ini_lines) || (topLevel && !ini.exists() && !appendStartIni))
|
||||
if (!module.isEnabled() || (transitive && has_ini_lines) || (topLevel && !FS.exists(ini) && !appendStartIni))
|
||||
{
|
||||
// File BufferedWriter
|
||||
BufferedWriter writer = null;
|
||||
String source = null;
|
||||
PrintWriter out = null;
|
||||
try
|
||||
{
|
||||
if (appendStartIni)
|
||||
{
|
||||
if ((!start_ini.exists() && !start_ini.createNewFile()) || !start_ini.canWrite())
|
||||
{
|
||||
StartLog.warn("ERROR: Bad %s! ",start_ini);
|
||||
return;
|
||||
}
|
||||
source = short_start_ini;
|
||||
StartLog.info("%-15s initialised in %s (appended)",name,source);
|
||||
out = new PrintWriter(new FileWriter(start_ini,true));
|
||||
writer = Files.newBufferedWriter(start_ini,StandardCharsets.UTF_8,StandardOpenOption.CREATE,StandardOpenOption.APPEND);
|
||||
out = new PrintWriter(writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create the directory if needed
|
||||
FS.ensureDirectoryExists(start_d);
|
||||
FS.ensureDirectoryWritable(start_d);
|
||||
try
|
||||
{
|
||||
// Create a new ini file for it
|
||||
if (!ini.createNewFile())
|
||||
{
|
||||
StartLog.warn("ERROR: %s cannot be initialised in %s! ",name,short_ini);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
StartLog.warn("ERROR: Unable to create %s!",ini);
|
||||
StartLog.warn(e);
|
||||
return;
|
||||
}
|
||||
source = short_ini;
|
||||
StartLog.info("%-15s initialised in %s (created)",name,source);
|
||||
out = new PrintWriter(ini);
|
||||
writer = Files.newBufferedWriter(ini,StandardCharsets.UTF_8,StandardOpenOption.CREATE_NEW,StandardOpenOption.WRITE);
|
||||
out = new PrintWriter(writer);
|
||||
}
|
||||
|
||||
if (appendStartIni)
|
||||
|
@ -455,12 +458,14 @@ public class Main
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (ini.exists())
|
||||
else if (FS.exists(ini))
|
||||
{
|
||||
StartLog.info("%-15s initialised in %s",name,short_ini);
|
||||
}
|
||||
else
|
||||
{
|
||||
StartLog.info("%-15s initialised transitively",name);
|
||||
}
|
||||
|
||||
// Also list other places this module is enabled
|
||||
for (String source : module.getSources())
|
||||
|
@ -508,7 +513,7 @@ public class Main
|
|||
if (!done.contains(m.getName()))
|
||||
{
|
||||
complete=false;
|
||||
moduleIni(args,m.getName(),false,appendStartIni);
|
||||
buildIni(args,m.getName(),false,appendStartIni);
|
||||
done.add(m.getName());
|
||||
}
|
||||
}
|
||||
|
@ -542,61 +547,36 @@ public class Main
|
|||
|
||||
public StartArgs processCommandLine(String[] cmdLine) throws Exception
|
||||
{
|
||||
StartArgs args = new StartArgs(cmdLine);
|
||||
|
||||
// Processing Order is important!
|
||||
// ------------------------------------------------------------
|
||||
// 1) Directory Locations
|
||||
|
||||
// Set Home and Base at the start, as all other paths encountered
|
||||
// will be based off of them.
|
||||
baseHome.initialize(args);
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// 2) Start Logging
|
||||
StartLog.getInstance().initialize(baseHome,args);
|
||||
// 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());
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// 3) Load Inis
|
||||
File start_ini = baseHome.getBaseFile("start.ini");
|
||||
if (FS.canReadFile(start_ini))
|
||||
{
|
||||
StartLog.debug("Reading ${jetty.base}/start.ini - %s",start_ini);
|
||||
args.parse(baseHome,new StartIni(start_ini));
|
||||
}
|
||||
|
||||
File start_d = baseHome.getBaseFile("start.d");
|
||||
if (FS.canReadDirectory(start_d))
|
||||
{
|
||||
List<Path> paths = baseHome.getPaths(start_d.toPath(),1,"*.ini");
|
||||
Collections.sort(paths,new NaturalSort.Paths());
|
||||
for (Path path: paths)
|
||||
{
|
||||
StartLog.debug("Reading ${jetty.base}/start.d/%s - %s",path.getFileName(),path);
|
||||
args.parse(baseHome,new StartIni(path));
|
||||
}
|
||||
}
|
||||
|
||||
// 4) 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");
|
||||
args.parseCommandLine();
|
||||
StartArgs args = new StartArgs();
|
||||
args.parse(baseHome.getConfigSources());
|
||||
|
||||
// 5) Module Registration
|
||||
// ------------------------------------------------------------
|
||||
// 3) Module Registration
|
||||
Modules modules = new Modules();
|
||||
StartLog.debug("Registering all modules");
|
||||
modules.registerAll(baseHome, args);
|
||||
|
||||
// 6) Active Module Resolution
|
||||
// ------------------------------------------------------------
|
||||
// 4) Active Module Resolution
|
||||
for (String enabledModule : args.getEnabledModules())
|
||||
{
|
||||
List<String> sources = args.getSources(enabledModule);
|
||||
modules.enable(enabledModule,sources);
|
||||
List<String> msources = args.getSources(enabledModule);
|
||||
modules.enable(enabledModule,msources);
|
||||
}
|
||||
|
||||
StartLog.debug("Building Module Graph");
|
||||
|
@ -605,11 +585,13 @@ public class Main
|
|||
args.setAllModules(modules);
|
||||
List<Module> activeModules = modules.resolveEnabled();
|
||||
|
||||
// 7) Lib & XML Expansion / Resolution
|
||||
// ------------------------------------------------------------
|
||||
// 5) Lib & XML Expansion / Resolution
|
||||
args.expandLibs(baseHome);
|
||||
args.expandModules(baseHome,activeModules);
|
||||
|
||||
// 8) Resolve Extra XMLs
|
||||
// ------------------------------------------------------------
|
||||
// 6) Resolve Extra XMLs
|
||||
args.resolveExtraXmls(baseHome);
|
||||
|
||||
return args;
|
||||
|
@ -651,7 +633,7 @@ public class Main
|
|||
// Generate Module Graph File
|
||||
if (args.getModuleGraphFilename() != null)
|
||||
{
|
||||
File outputFile = baseHome.getBaseFile(args.getModuleGraphFilename());
|
||||
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());
|
||||
|
@ -683,25 +665,27 @@ public class Main
|
|||
}
|
||||
|
||||
// Initialize start.ini
|
||||
for (String module : args.getModuleStartIni())
|
||||
for (String module : args.getAddToStartIni())
|
||||
{
|
||||
moduleIni(args,module,true,true);
|
||||
buildIni(args,module,true,true);
|
||||
}
|
||||
|
||||
// Initialize start.d
|
||||
for (String module : args.getModuleStartdIni())
|
||||
for (String module : args.getAddToStartdIni())
|
||||
{
|
||||
moduleIni(args,module,true,false);
|
||||
buildIni(args,module,true,false);
|
||||
}
|
||||
|
||||
// Check ini files for download possibilities
|
||||
for (FileArg arg : args.getFiles())
|
||||
{
|
||||
File file = baseHome.getBaseFile(arg.location);
|
||||
if (!file.exists() && args.isDownload())
|
||||
Path file = baseHome.getBasePath(arg.location);
|
||||
if (!FS.exists(file) && args.isDownload())
|
||||
{
|
||||
initFile(arg);
|
||||
}
|
||||
|
||||
if (!file.exists())
|
||||
if (!FS.exists(file))
|
||||
{
|
||||
/* Startup should NEVER fail to run on missing content.
|
||||
* See Bug #427204
|
||||
|
|
|
@ -19,10 +19,11 @@
|
|||
package org.eclipse.jetty.start;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.text.CollationKey;
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
|
@ -75,7 +76,7 @@ public class Module
|
|||
}
|
||||
|
||||
/** The file of the module */
|
||||
private File file;
|
||||
private Path file;
|
||||
/** The name of this Module (as a filesystem reference) */
|
||||
private String fileRef;
|
||||
/**
|
||||
|
@ -108,12 +109,12 @@ public class Module
|
|||
/** List of sources that enabled this module */
|
||||
private final Set<String> sources = new HashSet<>();
|
||||
|
||||
public Module(BaseHome basehome, File file) throws FileNotFoundException, IOException
|
||||
public Module(BaseHome basehome, Path file) throws FileNotFoundException, IOException
|
||||
{
|
||||
this.file = file;
|
||||
|
||||
// Strip .mod
|
||||
this.fileRef = Pattern.compile(".mod$",Pattern.CASE_INSENSITIVE).matcher(file.getName()).replaceFirst("");
|
||||
this.fileRef = Pattern.compile(".mod$",Pattern.CASE_INSENSITIVE).matcher(file.getFileName().toString()).replaceFirst("");
|
||||
this.logicalName = fileRef;
|
||||
|
||||
init(basehome);
|
||||
|
@ -306,66 +307,63 @@ public class Module
|
|||
return;
|
||||
}
|
||||
|
||||
try (FileReader reader = new FileReader(file))
|
||||
try (BufferedReader buf = Files.newBufferedReader(file,StandardCharsets.UTF_8))
|
||||
{
|
||||
try (BufferedReader buf = new BufferedReader(reader))
|
||||
String sectionType = "";
|
||||
String line;
|
||||
while ((line = buf.readLine()) != null)
|
||||
{
|
||||
String sectionType = "";
|
||||
String line;
|
||||
while ((line = buf.readLine()) != null)
|
||||
line = line.trim();
|
||||
|
||||
Matcher sectionMatcher = section.matcher(line);
|
||||
|
||||
if (sectionMatcher.matches())
|
||||
{
|
||||
line = line.trim();
|
||||
|
||||
Matcher sectionMatcher = section.matcher(line);
|
||||
|
||||
if (sectionMatcher.matches())
|
||||
sectionType = sectionMatcher.group(1).trim().toUpperCase(Locale.ENGLISH);
|
||||
}
|
||||
else
|
||||
{
|
||||
// blank lines and comments are valid for ini-template section
|
||||
if ((line.length() == 0) || line.startsWith("#"))
|
||||
{
|
||||
sectionType = sectionMatcher.group(1).trim().toUpperCase(Locale.ENGLISH);
|
||||
if ("INI-TEMPLATE".equals(sectionType))
|
||||
{
|
||||
initialise.add(line);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// blank lines and comments are valid for ini-template section
|
||||
if ((line.length() == 0) || line.startsWith("#"))
|
||||
switch (sectionType)
|
||||
{
|
||||
if ("INI-TEMPLATE".equals(sectionType))
|
||||
{
|
||||
case "":
|
||||
// ignore (this would be entries before first section)
|
||||
break;
|
||||
case "DEPEND":
|
||||
parentNames.add(line);
|
||||
break;
|
||||
case "FILES":
|
||||
files.add(line);
|
||||
break;
|
||||
case "INI-TEMPLATE":
|
||||
initialise.add(line);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (sectionType)
|
||||
{
|
||||
case "":
|
||||
// ignore (this would be entries before first section)
|
||||
break;
|
||||
case "DEPEND":
|
||||
parentNames.add(line);
|
||||
break;
|
||||
case "FILES":
|
||||
files.add(line);
|
||||
break;
|
||||
case "INI-TEMPLATE":
|
||||
initialise.add(line);
|
||||
break;
|
||||
case "LIB":
|
||||
libs.add(line);
|
||||
break;
|
||||
case "NAME":
|
||||
logicalName = line;
|
||||
break;
|
||||
case "OPTIONAL":
|
||||
optionalParentNames.add(line);
|
||||
break;
|
||||
case "EXEC":
|
||||
jvmArgs.add(line);
|
||||
break;
|
||||
case "XML":
|
||||
xmls.add(line);
|
||||
break;
|
||||
default:
|
||||
throw new IOException("Unrecognized Module section: [" + sectionType + "]");
|
||||
}
|
||||
break;
|
||||
case "LIB":
|
||||
libs.add(line);
|
||||
break;
|
||||
case "NAME":
|
||||
logicalName = line;
|
||||
break;
|
||||
case "OPTIONAL":
|
||||
optionalParentNames.add(line);
|
||||
break;
|
||||
case "EXEC":
|
||||
jvmArgs.add(line);
|
||||
break;
|
||||
case "XML":
|
||||
xmls.add(line);
|
||||
break;
|
||||
default:
|
||||
throw new IOException("Unrecognized Module section: [" + sectionType + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,10 +18,13 @@
|
|||
|
||||
package org.eclipse.jetty.start;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -73,9 +76,10 @@ public class ModuleGraphWriter
|
|||
return val;
|
||||
}
|
||||
|
||||
public void write(Modules modules, File outputFile) throws IOException
|
||||
public void write(Modules modules, Path outputFile) throws IOException
|
||||
{
|
||||
try (FileWriter writer = new FileWriter(outputFile,false); PrintWriter out = new PrintWriter(writer);)
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(outputFile,StandardCharsets.UTF_8,StandardOpenOption.CREATE_NEW,StandardOpenOption.WRITE);
|
||||
PrintWriter out = new PrintWriter(writer);)
|
||||
{
|
||||
writeHeaderMessage(out,outputFile);
|
||||
|
||||
|
@ -112,7 +116,7 @@ public class ModuleGraphWriter
|
|||
}
|
||||
}
|
||||
|
||||
private void writeHeaderMessage(PrintWriter out, File outputFile)
|
||||
private void writeHeaderMessage(PrintWriter out, Path outputFile)
|
||||
{
|
||||
out.println("/*");
|
||||
out.println(" * GraphViz Graph of Jetty Modules");
|
||||
|
@ -121,7 +125,7 @@ public class ModuleGraphWriter
|
|||
out.println(" * GraphViz: http://graphviz.org/");
|
||||
out.println(" * ");
|
||||
out.println(" * To Generate Graph image using graphviz:");
|
||||
String filename = outputFile.getName();
|
||||
String filename = outputFile.getFileName().toString();
|
||||
String basename = filename.substring(0,filename.indexOf('.'));
|
||||
out.printf(" * $ dot -Tpng -Goverlap=false -o %s.png %s%n",basename,filename);
|
||||
out.println(" */");
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.start;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
@ -380,7 +379,7 @@ public class Modules implements Iterable<Module>
|
|||
{
|
||||
if (!modules.containsKey(name))
|
||||
{
|
||||
File file = basehome.getFile("modules/" + name + ".mod");
|
||||
Path file = basehome.getPath("modules/" + name + ".mod");
|
||||
if (FS.canReadFile(file))
|
||||
{
|
||||
Module parent = registerModule(basehome,args,file);
|
||||
|
@ -395,7 +394,7 @@ public class Modules implements Iterable<Module>
|
|||
{
|
||||
for (Path path : basehome.getPaths("modules/*.mod"))
|
||||
{
|
||||
registerModule(basehome,args,path.toFile());
|
||||
registerModule(basehome,args,path);
|
||||
}
|
||||
|
||||
// load missing post-expanded dependent modules
|
||||
|
@ -420,7 +419,7 @@ public class Modules implements Iterable<Module>
|
|||
|
||||
for (String missingParent : missingParents)
|
||||
{
|
||||
File file = basehome.getFile("modules/" + missingParent + ".mod");
|
||||
Path file = basehome.getPath("modules/" + missingParent + ".mod");
|
||||
if (FS.canReadFile(file))
|
||||
{
|
||||
Module module = registerModule(basehome,args,file);
|
||||
|
@ -435,7 +434,7 @@ public class Modules implements Iterable<Module>
|
|||
}
|
||||
}
|
||||
|
||||
private Module registerModule(BaseHome basehome, StartArgs args, File file) throws FileNotFoundException, IOException
|
||||
private Module registerModule(BaseHome basehome, StartArgs args, Path file) throws FileNotFoundException, IOException
|
||||
{
|
||||
if (!FS.canReadFile(file))
|
||||
{
|
||||
|
|
|
@ -29,11 +29,16 @@ import java.nio.file.attribute.BasicFileAttributes;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class PathFinder extends SimpleFileVisitor<Path>
|
||||
{
|
||||
// internal tracking of prior notified paths (to avoid repeated notification of same ignored path)
|
||||
private static Set<Path> NOTIFIED_PATHS = new HashSet<>();
|
||||
|
||||
private boolean includeDirsInResults = false;
|
||||
private Map<String, Path> hits = new HashMap<>();
|
||||
private Path basePath = null;
|
||||
|
@ -43,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);
|
||||
}
|
||||
|
||||
|
@ -134,7 +139,6 @@ public class PathFinder extends SimpleFileVisitor<Path>
|
|||
{
|
||||
if (fileMatcher.matches(file))
|
||||
{
|
||||
StartLog.debug("Found file: " + file);
|
||||
addHit(file);
|
||||
}
|
||||
else
|
||||
|
@ -149,7 +153,11 @@ public class PathFinder extends SimpleFileVisitor<Path>
|
|||
{
|
||||
if (exc instanceof FileSystemLoopException)
|
||||
{
|
||||
StartLog.warn("skipping detected filesystem loop: " + file);
|
||||
if (!NOTIFIED_PATHS.contains(file))
|
||||
{
|
||||
StartLog.warn("skipping detected filesystem loop: " + file);
|
||||
NOTIFIED_PATHS.add(file);
|
||||
}
|
||||
return FileVisitResult.SKIP_SUBTREE;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -18,10 +18,14 @@
|
|||
|
||||
package org.eclipse.jetty.start;
|
||||
|
||||
import static org.eclipse.jetty.start.UsageException.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Stack;
|
||||
|
@ -60,8 +64,91 @@ public final class Props implements Iterable<Prop>
|
|||
}
|
||||
|
||||
public static final String ORIGIN_SYSPROP = "<system-property>";
|
||||
|
||||
public static String getValue(String arg)
|
||||
{
|
||||
int idx = arg.indexOf('=');
|
||||
if (idx == (-1))
|
||||
{
|
||||
throw new UsageException(ERR_BAD_ARG,"Argument is missing a required value: %s",arg);
|
||||
}
|
||||
String value = arg.substring(idx + 1).trim();
|
||||
if (value.length() <= 0)
|
||||
{
|
||||
throw new UsageException(ERR_BAD_ARG,"Argument is missing a required value: %s",arg);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static List<String> getValues(String arg)
|
||||
{
|
||||
String v = getValue(arg);
|
||||
ArrayList<String> l = new ArrayList<>();
|
||||
for (String s : v.split(","))
|
||||
{
|
||||
if (s != null)
|
||||
{
|
||||
s = s.trim();
|
||||
if (s.length() > 0)
|
||||
{
|
||||
l.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
private Map<String, Prop> props = new HashMap<>();
|
||||
private List<String> sysPropTracking = new ArrayList<>();
|
||||
|
||||
public void addAll(Props other)
|
||||
{
|
||||
this.props.putAll(other.props);
|
||||
this.sysPropTracking.addAll(other.sysPropTracking);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a potential argument as a property.
|
||||
* <p>
|
||||
* If arg is not a property, ignore it.
|
||||
* @param arg the argument to parse for a potential property
|
||||
* @param source the source for this argument (to track origin of property from)
|
||||
*/
|
||||
public void addPossibleProperty(String arg, String source)
|
||||
{
|
||||
// Start property (syntax similar to System property)
|
||||
if (arg.startsWith("-D"))
|
||||
{
|
||||
String[] assign = arg.substring(2).split("=",2);
|
||||
switch (assign.length)
|
||||
{
|
||||
case 2:
|
||||
setSystemProperty(assign[0],assign[1]);
|
||||
setProperty(assign[0],assign[1],source);
|
||||
break;
|
||||
case 1:
|
||||
setSystemProperty(assign[0],"");
|
||||
setProperty(assign[0],"",source);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Is this a raw property declaration?
|
||||
int idx = arg.indexOf('=');
|
||||
if (idx >= 0)
|
||||
{
|
||||
String key = arg.substring(0,idx);
|
||||
String value = arg.substring(idx + 1);
|
||||
|
||||
setProperty(key,value,source);
|
||||
return;
|
||||
}
|
||||
|
||||
// All other strings are ignored
|
||||
}
|
||||
|
||||
public String cleanReference(String property)
|
||||
{
|
||||
|
@ -156,9 +243,14 @@ public final class Props implements Iterable<Prop>
|
|||
}
|
||||
|
||||
public Prop getProp(String key)
|
||||
{
|
||||
return getProp(key,true);
|
||||
}
|
||||
|
||||
public Prop getProp(String key, boolean searchSystemProps)
|
||||
{
|
||||
Prop prop = props.get(key);
|
||||
if (prop == null)
|
||||
if ((prop == null) && searchSystemProps)
|
||||
{
|
||||
// try system property
|
||||
prop = getSystemProperty(key);
|
||||
|
@ -214,6 +306,11 @@ public final class Props implements Iterable<Prop>
|
|||
return props.values().iterator();
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
props.clear();
|
||||
}
|
||||
|
||||
public void setProperty(Prop prop)
|
||||
{
|
||||
props.put(prop.key,prop);
|
||||
|
@ -249,4 +346,10 @@ public final class Props implements Iterable<Prop>
|
|||
// write normal properties file
|
||||
props.store(stream,comments);
|
||||
}
|
||||
|
||||
public void setSystemProperty(String key, String value)
|
||||
{
|
||||
System.setProperty(key,value);
|
||||
sysPropTracking.add(key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,23 +25,24 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
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;
|
||||
|
||||
/**
|
||||
* The Arguments required to start Jetty.
|
||||
*/
|
||||
public class StartArgs
|
||||
{
|
||||
public static final String CMD_LINE_SOURCE = "<command-line>";
|
||||
public static final String VERSION;
|
||||
|
||||
static
|
||||
|
@ -68,24 +69,41 @@ public class StartArgs
|
|||
|
||||
private static final String SERVER_MAIN = "org.eclipse.jetty.xml.XmlConfiguration";
|
||||
|
||||
private List<String> commandLine = new ArrayList<>();
|
||||
/** List of enabled modules */
|
||||
private Set<String> modules = new HashSet<>();
|
||||
/** Map of enabled modules to the source of where that activation occurred */
|
||||
private Map<String, List<String>> sources = new HashMap<>();
|
||||
/** Map of properties to where that property was declared */
|
||||
private Map<String, String> propertySource = new HashMap<>();
|
||||
/** List of all active [files] sections from enabled modules */
|
||||
private List<FileArg> files = new ArrayList<>();
|
||||
/** List of all active [lib] sectinos from enabled modules */
|
||||
private Classpath classpath;
|
||||
/** List of all active [xml] sections from enabled modules */
|
||||
private List<Path> xmls = new ArrayList<>();
|
||||
/** JVM arguments, found via commmand line and in all active [exec] sections from enabled modules */
|
||||
private List<String> jvmArgs = new ArrayList<>();
|
||||
|
||||
/** List of all xml references found directly on command line or start.ini */
|
||||
private List<String> xmlRefs = new ArrayList<>();
|
||||
private List<File> xmls = new ArrayList<>();
|
||||
|
||||
private Props properties = new Props();
|
||||
private Set<String> systemPropertyKeys = new HashSet<>();
|
||||
private List<String> jvmArgs = new ArrayList<>();
|
||||
private List<String> rawLibs = new ArrayList<>();
|
||||
private List<String> moduleStartdIni = new ArrayList<>();
|
||||
private List<String> moduleStartIni = new ArrayList<>();
|
||||
private Map<String, String> propertySource = new HashMap<>();
|
||||
|
||||
// jetty.base - build out commands
|
||||
/** --add-to-startd=[module,[module]] */
|
||||
private List<String> addToStartdIni = new ArrayList<>();
|
||||
/** --add-to-start=[module,[module]] */
|
||||
private List<String> addToStartIni = new ArrayList<>();
|
||||
|
||||
// module inspection commands
|
||||
/** --write-module-graph=[filename] */
|
||||
private String moduleGraphFilename;
|
||||
|
||||
/** Collection of all modules */
|
||||
private Modules allModules;
|
||||
// Should the server be run?
|
||||
/** Should the server be run? */
|
||||
private boolean run = true;
|
||||
private boolean download = false;
|
||||
private boolean help = false;
|
||||
|
@ -98,9 +116,8 @@ public class StartArgs
|
|||
|
||||
private boolean exec = false;
|
||||
|
||||
public StartArgs(String[] commandLineArgs)
|
||||
public StartArgs()
|
||||
{
|
||||
commandLine.addAll(Arrays.asList(commandLineArgs));
|
||||
classpath = new Classpath();
|
||||
}
|
||||
|
||||
|
@ -119,13 +136,13 @@ public class StartArgs
|
|||
System.setProperty(key,value);
|
||||
}
|
||||
|
||||
private void addUniqueXmlFile(String xmlRef, File xmlfile) throws IOException
|
||||
private void addUniqueXmlFile(String xmlRef, Path xmlfile) throws IOException
|
||||
{
|
||||
if (!FS.canReadFile(xmlfile))
|
||||
{
|
||||
throw new IOException("Cannot read file: " + xmlRef);
|
||||
}
|
||||
xmlfile = xmlfile.getCanonicalFile();
|
||||
xmlfile = FS.toRealPath(xmlfile);
|
||||
if (!xmls.contains(xmlfile))
|
||||
{
|
||||
xmls.add(xmlfile);
|
||||
|
@ -143,9 +160,9 @@ public class StartArgs
|
|||
return;
|
||||
}
|
||||
|
||||
for (File xml : xmls)
|
||||
for (Path xml : xmls)
|
||||
{
|
||||
System.out.printf(" %s%n",baseHome.toShortForm(xml.getAbsolutePath()));
|
||||
System.out.printf(" %s%n",baseHome.toShortForm(xml.toAbsolutePath()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,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();
|
||||
|
@ -260,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)
|
||||
*
|
||||
|
@ -309,7 +326,7 @@ public class StartArgs
|
|||
System.setProperty(key,val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expand any command line added <code>--lib</code> lib references.
|
||||
*
|
||||
|
@ -348,7 +365,7 @@ public class StartArgs
|
|||
StartLog.debug("rawlibref = " + rawlibref);
|
||||
String libref = properties.expand(rawlibref);
|
||||
StartLog.debug("expanded = " + libref);
|
||||
|
||||
|
||||
for (Path libpath : baseHome.getPaths(libref))
|
||||
{
|
||||
classpath.addComponent(libpath.toFile());
|
||||
|
@ -357,15 +374,15 @@ public class StartArgs
|
|||
|
||||
for (String jvmArg : module.getJvmArgs())
|
||||
{
|
||||
exec=true;
|
||||
exec = true;
|
||||
jvmArgs.add(jvmArg);
|
||||
}
|
||||
|
||||
|
||||
// Find and Expand XML files
|
||||
for (String xmlRef : module.getXmls())
|
||||
{
|
||||
// Straight Reference
|
||||
File xmlfile = baseHome.getFile(xmlRef);
|
||||
Path xmlfile = baseHome.getPath(xmlRef);
|
||||
addUniqueXmlFile(xmlRef,xmlfile);
|
||||
}
|
||||
|
||||
|
@ -378,6 +395,16 @@ public class StartArgs
|
|||
}
|
||||
}
|
||||
|
||||
public List<String> getAddToStartdIni()
|
||||
{
|
||||
return addToStartdIni;
|
||||
}
|
||||
|
||||
public List<String> getAddToStartIni()
|
||||
{
|
||||
return addToStartIni;
|
||||
}
|
||||
|
||||
public Modules getAllModules()
|
||||
{
|
||||
return allModules;
|
||||
|
@ -388,9 +415,9 @@ public class StartArgs
|
|||
return classpath;
|
||||
}
|
||||
|
||||
public List<String> getCommandLine()
|
||||
public Set<String> getEnabledModules()
|
||||
{
|
||||
return this.commandLine;
|
||||
return this.modules;
|
||||
}
|
||||
|
||||
public List<FileArg> getFiles()
|
||||
|
@ -398,11 +425,6 @@ public class StartArgs
|
|||
return files;
|
||||
}
|
||||
|
||||
public Set<String> getEnabledModules()
|
||||
{
|
||||
return this.modules;
|
||||
}
|
||||
|
||||
public List<String> getJvmArgs()
|
||||
{
|
||||
return jvmArgs;
|
||||
|
@ -456,9 +478,9 @@ public class StartArgs
|
|||
cmd.addRawArg(prop_file.getAbsolutePath());
|
||||
}
|
||||
|
||||
for (File xml : xmls)
|
||||
for (Path xml : xmls)
|
||||
{
|
||||
cmd.addRawArg(xml.getAbsolutePath());
|
||||
cmd.addRawArg(xml.toAbsolutePath().toString());
|
||||
}
|
||||
|
||||
return cmd;
|
||||
|
@ -475,16 +497,6 @@ public class StartArgs
|
|||
return moduleGraphFilename;
|
||||
}
|
||||
|
||||
public List<String> getModuleStartdIni()
|
||||
{
|
||||
return moduleStartdIni;
|
||||
}
|
||||
|
||||
public List<String> getModuleStartIni()
|
||||
{
|
||||
return moduleStartIni;
|
||||
}
|
||||
|
||||
public Props getProperties()
|
||||
{
|
||||
return properties;
|
||||
|
@ -495,40 +507,7 @@ public class StartArgs
|
|||
return sources.get(module);
|
||||
}
|
||||
|
||||
private String getValue(String arg)
|
||||
{
|
||||
int idx = arg.indexOf('=');
|
||||
if (idx == (-1))
|
||||
{
|
||||
throw new UsageException(ERR_BAD_ARG,"Argument is missing a required value: %s",arg);
|
||||
}
|
||||
String value = arg.substring(idx + 1).trim();
|
||||
if (value.length() <= 0)
|
||||
{
|
||||
throw new UsageException(ERR_BAD_ARG,"Argument is missing a required value: %s",arg);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private List<String> getValues(String arg)
|
||||
{
|
||||
String v = getValue(arg);
|
||||
ArrayList<String> l = new ArrayList<>();
|
||||
for (String s : v.split(","))
|
||||
{
|
||||
if (s != null)
|
||||
{
|
||||
s = s.trim();
|
||||
if (s.length() > 0)
|
||||
{
|
||||
l.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
public List<File> getXmlFiles()
|
||||
public List<Path> getXmlFiles()
|
||||
{
|
||||
return xmls;
|
||||
}
|
||||
|
@ -588,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;
|
||||
|
@ -628,20 +582,16 @@ public class StartArgs
|
|||
return version;
|
||||
}
|
||||
|
||||
public void parse(BaseHome baseHome, TextFile file)
|
||||
public void parse(ConfigSources sources)
|
||||
{
|
||||
String source;
|
||||
try
|
||||
ListIterator<ConfigSource> iter = sources.reverseListIterator();
|
||||
while (iter.hasPrevious())
|
||||
{
|
||||
source = baseHome.toShortForm(file.getFile());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new UsageException(ERR_BAD_ARG,"Bad file: %s",file);
|
||||
}
|
||||
for (String line : file)
|
||||
{
|
||||
parse(line,source);
|
||||
ConfigSource source = iter.previous();
|
||||
for (String arg : source.getArgs())
|
||||
{
|
||||
parse(arg,source.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -666,28 +616,25 @@ public class StartArgs
|
|||
|
||||
if ("--help".equals(arg) || "-?".equals(arg))
|
||||
{
|
||||
if (!CMD_LINE_SOURCE.equals(source))
|
||||
{
|
||||
throw new UsageException(ERR_BAD_ARG,"%s not allowed in %s",arg,source);
|
||||
}
|
||||
|
||||
help = true;
|
||||
run = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if ("--debug".equals(arg))
|
||||
if ("--debug".equals(arg) || arg.startsWith("--start-log-file"))
|
||||
{
|
||||
// valid, but handled in StartLog instead
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg.startsWith("--extra-start-dir="))
|
||||
{
|
||||
// valid, but handled in ConfigSources instead
|
||||
return;
|
||||
}
|
||||
|
||||
if ("--stop".equals(arg))
|
||||
{
|
||||
if (!CMD_LINE_SOURCE.equals(source))
|
||||
{
|
||||
throw new UsageException(ERR_BAD_ARG,"%s not allowed in %s",arg,source);
|
||||
}
|
||||
stopCommand = true;
|
||||
run = false;
|
||||
return;
|
||||
|
@ -695,7 +642,7 @@ public class StartArgs
|
|||
|
||||
if (arg.startsWith("--download="))
|
||||
{
|
||||
addFile(getValue(arg));
|
||||
addFile(Props.getValue(arg));
|
||||
run = false;
|
||||
download = true;
|
||||
return;
|
||||
|
@ -724,15 +671,12 @@ public class StartArgs
|
|||
|
||||
if ("--dry-run".equals(arg) || "--exec-print".equals(arg))
|
||||
{
|
||||
if (!CMD_LINE_SOURCE.equals(source))
|
||||
{
|
||||
throw new UsageException(ERR_BAD_ARG,"%s not allowed in %s",arg,source);
|
||||
}
|
||||
dryRun = true;
|
||||
run = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Enable forked execution of Jetty server
|
||||
if ("--exec".equals(arg))
|
||||
{
|
||||
exec = true;
|
||||
|
@ -740,11 +684,10 @@ public class StartArgs
|
|||
}
|
||||
|
||||
// Arbitrary Libraries
|
||||
|
||||
if (arg.startsWith("--lib="))
|
||||
{
|
||||
String cp = getValue(arg);
|
||||
|
||||
String cp = Props.getValue(arg);
|
||||
|
||||
if (cp != null)
|
||||
{
|
||||
StringTokenizer t = new StringTokenizer(cp,File.pathSeparator);
|
||||
|
@ -764,33 +707,28 @@ public class StartArgs
|
|||
return;
|
||||
}
|
||||
|
||||
if (arg.startsWith("--add-to-startd"))
|
||||
// jetty.base build-out : add to ${jetty.base}/start.d/
|
||||
if (arg.startsWith("--add-to-startd="))
|
||||
{
|
||||
if (!CMD_LINE_SOURCE.equals(source))
|
||||
{
|
||||
throw new UsageException(ERR_BAD_ARG,"%s not allowed in %s",arg,source);
|
||||
}
|
||||
moduleStartdIni.addAll(getValues(arg));
|
||||
addToStartdIni.addAll(Props.getValues(arg));
|
||||
run = false;
|
||||
download = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg.startsWith("--add-to-start"))
|
||||
// jetty.base build-out : add to ${jetty.base}/start.ini
|
||||
if (arg.startsWith("--add-to-start="))
|
||||
{
|
||||
if (!CMD_LINE_SOURCE.equals(source))
|
||||
{
|
||||
throw new UsageException(ERR_BAD_ARG,"%s not allowed in %s",arg,source);
|
||||
}
|
||||
moduleStartIni.addAll(getValues(arg));
|
||||
addToStartIni.addAll(Props.getValues(arg));
|
||||
run = false;
|
||||
download = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Enable a module
|
||||
if (arg.startsWith("--module="))
|
||||
{
|
||||
for (String moduleName : getValues(arg))
|
||||
for (String moduleName : Props.getValues(arg))
|
||||
{
|
||||
modules.add(moduleName);
|
||||
List<String> list = sources.get(moduleName);
|
||||
|
@ -804,9 +742,10 @@ public class StartArgs
|
|||
return;
|
||||
}
|
||||
|
||||
// Create graphviz output of module graph
|
||||
if (arg.startsWith("--write-module-graph="))
|
||||
{
|
||||
this.moduleGraphFilename = getValue(arg);
|
||||
this.moduleGraphFilename = Props.getValue(arg);
|
||||
run = false;
|
||||
return;
|
||||
}
|
||||
|
@ -850,14 +789,11 @@ public class StartArgs
|
|||
String key = arg.substring(0,idx);
|
||||
String value = arg.substring(idx + 1);
|
||||
|
||||
if (source != CMD_LINE_SOURCE)
|
||||
if (propertySource.containsKey(key))
|
||||
{
|
||||
if (propertySource.containsKey(key))
|
||||
{
|
||||
throw new UsageException(ERR_BAD_ARG,"Property %s in %s already set in %s",key,source,propertySource.get(key));
|
||||
}
|
||||
propertySource.put(key,source);
|
||||
StartLog.warn("Property %s in %s already set in %s",key,source,propertySource.get(key));
|
||||
}
|
||||
propertySource.put(key,source);
|
||||
|
||||
if ("OPTION".equals(key) || "OPTIONS".equals(key))
|
||||
{
|
||||
|
@ -889,26 +825,16 @@ public class StartArgs
|
|||
throw new UsageException(ERR_BAD_ARG,"Unrecognized argument: \"%s\" in %s",arg,source);
|
||||
}
|
||||
|
||||
public StartArgs parseCommandLine()
|
||||
{
|
||||
for (String line : commandLine)
|
||||
{
|
||||
parse(line,StartArgs.CMD_LINE_SOURCE);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void resolveExtraXmls(BaseHome baseHome) throws IOException
|
||||
{
|
||||
// Find and Expand XML files
|
||||
for (String xmlRef : xmlRefs)
|
||||
{
|
||||
// Straight Reference
|
||||
File xmlfile = baseHome.getFile(xmlRef);
|
||||
if (!xmlfile.exists())
|
||||
Path xmlfile = baseHome.getPath(xmlRef);
|
||||
if (!FS.exists(xmlfile))
|
||||
{
|
||||
xmlfile = baseHome.getFile("etc/" + xmlRef);
|
||||
xmlfile = baseHome.getPath("etc/" + xmlRef);
|
||||
}
|
||||
addUniqueXmlFile(xmlRef,xmlfile);
|
||||
}
|
||||
|
@ -919,13 +845,36 @@ 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()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("StartArgs [commandLine=");
|
||||
builder.append(commandLine);
|
||||
builder.append(", enabledModules=");
|
||||
builder.append("StartArgs [enabledModules=");
|
||||
builder.append(modules);
|
||||
builder.append(", xmlRefs=");
|
||||
builder.append(xmlRefs);
|
||||
|
@ -936,5 +885,4 @@ public class StartArgs
|
|||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.eclipse.jetty.start;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
|
@ -28,12 +27,14 @@ import java.nio.file.Path;
|
|||
*/
|
||||
public class StartIni extends TextFile
|
||||
{
|
||||
public StartIni(File file) throws FileNotFoundException, IOException
|
||||
private Path basedir;
|
||||
|
||||
public StartIni(File file) throws IOException
|
||||
{
|
||||
super(file);
|
||||
}
|
||||
|
||||
public StartIni(Path path) throws FileNotFoundException, IOException
|
||||
public StartIni(Path path) throws IOException
|
||||
{
|
||||
this(path.toFile());
|
||||
}
|
||||
|
@ -47,12 +48,33 @@ public class StartIni extends TextFile
|
|||
String value = line.substring(idx + 1);
|
||||
for (String part : value.split(","))
|
||||
{
|
||||
super.addUniqueLine("--module=" + part);
|
||||
super.addUniqueLine("--module=" + expandBaseDir(part));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
super.addUniqueLine(line);
|
||||
super.addUniqueLine(expandBaseDir(line));
|
||||
}
|
||||
}
|
||||
|
||||
private String expandBaseDir(String line)
|
||||
{
|
||||
if (line == null)
|
||||
{
|
||||
return line;
|
||||
}
|
||||
|
||||
return line.replace("${start.basedir}",basedir.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
basedir = getFile().getParentFile().toPath().toAbsolutePath();
|
||||
}
|
||||
|
||||
public Path getBaseDir()
|
||||
{
|
||||
return basedir;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,13 +18,15 @@
|
|||
|
||||
package org.eclipse.jetty.start;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Date;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.jetty.start.config.CommandLineConfigSource;
|
||||
|
||||
/**
|
||||
* Centralized Place for logging.
|
||||
|
@ -62,7 +64,7 @@ public class StartLog
|
|||
{
|
||||
System.err.printf("INFO: " + format + "%n",args);
|
||||
}
|
||||
|
||||
|
||||
public static void warn(String format, Object... args)
|
||||
{
|
||||
System.err.printf("WARNING: " + format + "%n",args);
|
||||
|
@ -72,7 +74,7 @@ public class StartLog
|
|||
{
|
||||
t.printStackTrace(System.err);
|
||||
}
|
||||
|
||||
|
||||
public static boolean isDebugEnabled()
|
||||
{
|
||||
return INSTANCE.debug;
|
||||
|
@ -80,17 +82,17 @@ public class StartLog
|
|||
|
||||
private boolean debug = false;
|
||||
|
||||
public void initialize(BaseHome baseHome, StartArgs args) throws IOException
|
||||
public void initialize(BaseHome baseHome, CommandLineConfigSource cmdLineSource) throws IOException
|
||||
{
|
||||
// Debug with boolean
|
||||
Pattern debugBoolPat = Pattern.compile("(-D)?debug=(.*)");
|
||||
// Log file name
|
||||
Pattern logFilePat = Pattern.compile("(-D)?start-log-file=(.*)");
|
||||
String dbgProp = cmdLineSource.getProperty("debug");
|
||||
if (dbgProp != null)
|
||||
{
|
||||
debug = Boolean.parseBoolean(dbgProp);
|
||||
}
|
||||
|
||||
// TODO: support backward compatible --daemon argument ??
|
||||
String logFileName = cmdLineSource.getProperty("start-log-file");
|
||||
|
||||
Matcher matcher;
|
||||
for (String arg : args.getCommandLine())
|
||||
for (String arg : cmdLineSource.getArgs())
|
||||
{
|
||||
if ("--debug".equals(arg))
|
||||
{
|
||||
|
@ -98,55 +100,55 @@ public class StartLog
|
|||
continue;
|
||||
}
|
||||
|
||||
matcher = debugBoolPat.matcher(arg);
|
||||
if (matcher.matches())
|
||||
if (arg.startsWith("--start-log-file"))
|
||||
{
|
||||
debug = Boolean.parseBoolean(matcher.group(2));
|
||||
logFileName = Props.getValue(arg);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
matcher = logFilePat.matcher(arg);
|
||||
if (matcher.matches())
|
||||
{
|
||||
String filename = matcher.group(2);
|
||||
File logfile = baseHome.getBaseFile(filename);
|
||||
initLogFile(logfile);
|
||||
}
|
||||
if (logFileName != null)
|
||||
{
|
||||
Path logfile = baseHome.getBasePath(logFileName);
|
||||
initLogFile(logfile);
|
||||
}
|
||||
}
|
||||
|
||||
public void initLogFile(File logfile) throws IOException
|
||||
public void initLogFile(Path logfile) throws IOException
|
||||
{
|
||||
if (logfile != null)
|
||||
{
|
||||
File logDir = logfile.getParentFile();
|
||||
if (!logDir.exists() || !logDir.canWrite())
|
||||
try
|
||||
{
|
||||
String err = String.format("Cannot write %s to directory %s [directory doesn't exist or is read-only]",logfile.getName(),
|
||||
logDir.getAbsolutePath());
|
||||
throw new UsageException(UsageException.ERR_LOGGING,new IOException(err));
|
||||
Path logDir = logfile.getParent();
|
||||
FS.ensureDirectoryWritable(logDir);
|
||||
|
||||
Path startLog = logfile;
|
||||
|
||||
if (!FS.exists(startLog) && !FS.createNewFile(startLog))
|
||||
{
|
||||
// Output about error is lost in majority of cases.
|
||||
throw new UsageException(UsageException.ERR_LOGGING,new IOException("Unable to create: " + startLog.toAbsolutePath()));
|
||||
}
|
||||
|
||||
if (!FS.canWrite(startLog))
|
||||
{
|
||||
// Output about error is lost in majority of cases.
|
||||
throw new UsageException(UsageException.ERR_LOGGING,new IOException("Unable to write to: " + startLog.toAbsolutePath()));
|
||||
}
|
||||
|
||||
System.out.println("Logging to " + logfile);
|
||||
|
||||
OutputStream out = Files.newOutputStream(startLog,StandardOpenOption.CREATE,StandardOpenOption.APPEND);
|
||||
PrintStream logger = new PrintStream(out);
|
||||
System.setOut(logger);
|
||||
System.setErr(logger);
|
||||
System.out.println("Establishing " + logfile + " on " + new Date());
|
||||
}
|
||||
|
||||
File startLog = logfile;
|
||||
|
||||
if (!startLog.exists() && !startLog.createNewFile())
|
||||
catch (IOException e)
|
||||
{
|
||||
// Output about error is lost in majority of cases.
|
||||
throw new UsageException(UsageException.ERR_LOGGING,new IOException("Unable to create: " + startLog.getAbsolutePath()));
|
||||
throw new UsageException(UsageException.ERR_LOGGING,e);
|
||||
}
|
||||
|
||||
if (!startLog.canWrite())
|
||||
{
|
||||
// Output about error is lost in majority of cases.
|
||||
throw new UsageException(UsageException.ERR_LOGGING,new IOException("Unable to write to: " + startLog.getAbsolutePath()));
|
||||
}
|
||||
|
||||
System.out.println("Logging to " + logfile);
|
||||
|
||||
PrintStream logger = new PrintStream(new FileOutputStream(startLog,false));
|
||||
System.setOut(logger);
|
||||
System.setErr(logger);
|
||||
System.out.println("Establishing " + logfile + " on " + new Date());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,245 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
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 ORIGIN_INTERNAL_FALLBACK = "<internal-fallback>";
|
||||
public static final String ORIGIN_CMD_LINE = "<command-line>";
|
||||
|
||||
private final List<String> args;
|
||||
private final Props props;
|
||||
private final Path homePath;
|
||||
private final Path basePath;
|
||||
|
||||
public CommandLineConfigSource(String rawargs[])
|
||||
{
|
||||
this.args = Arrays.asList(rawargs);
|
||||
this.props = new Props();
|
||||
for (String arg : args)
|
||||
{
|
||||
this.props.addPossibleProperty(arg,ORIGIN_CMD_LINE);
|
||||
}
|
||||
|
||||
// Setup ${jetty.base} and ${jetty.home}
|
||||
this.homePath = findJettyHomePath().toAbsolutePath();
|
||||
this.basePath = findJettyBasePath().toAbsolutePath();
|
||||
|
||||
// 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))
|
||||
{
|
||||
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 == ${user.dir}
|
||||
Path base = FS.toPath(this.props.getString("user.dir","."));
|
||||
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())
|
||||
{
|
||||
// ${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;
|
||||
}
|
||||
|
||||
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
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
CommandLineConfigSource other = (CommandLineConfigSource)obj;
|
||||
if (args == null)
|
||||
{
|
||||
if (other.args != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!args.equals(other.args))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getArgs()
|
||||
{
|
||||
return args;
|
||||
}
|
||||
|
||||
public Path getBasePath()
|
||||
{
|
||||
return basePath;
|
||||
}
|
||||
|
||||
public Path getHomePath()
|
||||
{
|
||||
return homePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
return ORIGIN_CMD_LINE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProperty(String key)
|
||||
{
|
||||
return props.getString(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Props getProps()
|
||||
{
|
||||
return props;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWeight()
|
||||
{
|
||||
return -1; // default value for command line
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = (prime * result) + ((args == null)?0:args.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setProperty(String key, String value, String origin)
|
||||
{
|
||||
this.props.setProperty(key,value,origin);
|
||||
}
|
||||
|
||||
public void setSystemProperty(String key, String value)
|
||||
{
|
||||
this.props.setSystemProperty(key,value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s[%s,args.length=%d]",this.getClass().getSimpleName(),getId(),getArgs().size());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.start.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.start.Props;
|
||||
|
||||
/**
|
||||
* A Configuration Source
|
||||
*/
|
||||
public interface ConfigSource
|
||||
{
|
||||
/**
|
||||
* The identifier for this source.
|
||||
* <p>
|
||||
* Used in end-user display of the source.
|
||||
*
|
||||
* @return the configuration source identifier.
|
||||
*/
|
||||
public String getId();
|
||||
|
||||
/**
|
||||
* The weight of this source, used for proper ordering of the config source search order.
|
||||
* <p>
|
||||
* Recommended Weights:
|
||||
* <pre>
|
||||
* -1 = the command line
|
||||
* 0 = the ${jetty.base} source
|
||||
* [1..n] = extra-start-dir entries from command line
|
||||
* [n+1..n] = extra-start-dir entries from start.ini (or start.d/*.ini)
|
||||
* 9999999 = the ${jetty.home} source
|
||||
* </pre>
|
||||
*
|
||||
* @return the weight of the config source. (lower value is more important)
|
||||
*/
|
||||
public int getWeight();
|
||||
|
||||
/**
|
||||
* The list of Arguments for this ConfigSource
|
||||
*
|
||||
* @return the list of Arguments for this ConfigSource
|
||||
*/
|
||||
public List<String> getArgs();
|
||||
|
||||
/**
|
||||
* The properties for this ConfigSource
|
||||
*
|
||||
* @return the properties for this ConfigSource
|
||||
*/
|
||||
public Props getProps();
|
||||
|
||||
/**
|
||||
* Return the value of the specified property.
|
||||
*
|
||||
* @param key the key to lookup
|
||||
* @return the value of the property, or null if not found
|
||||
*/
|
||||
public String getProperty(String key);
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.start.config;
|
||||
|
||||
import static org.eclipse.jetty.start.UsageException.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.ListIterator;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Weighted List of ConfigSources.
|
||||
* <p>
|
||||
*/
|
||||
public class ConfigSources implements Iterable<ConfigSource>
|
||||
{
|
||||
private static class WeightedConfigSourceComparator implements Comparator<ConfigSource>
|
||||
{
|
||||
@Override
|
||||
public int compare(ConfigSource o1, ConfigSource o2)
|
||||
{
|
||||
return o1.getWeight() - o2.getWeight();
|
||||
}
|
||||
}
|
||||
|
||||
private LinkedList<ConfigSource> sources = new LinkedList<>();
|
||||
private Props props = new Props();
|
||||
private AtomicInteger xtraSourceWeight = new AtomicInteger(1);
|
||||
|
||||
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 --extra-start-dir entries
|
||||
for (String arg : source.getArgs())
|
||||
{
|
||||
if (arg.startsWith("--extra-start-dir"))
|
||||
{
|
||||
String ref = getValue(arg);
|
||||
String dirName = props.expand(ref);
|
||||
Path dir = FS.toPath(dirName);
|
||||
DirConfigSource dirsource = new DirConfigSource(ref,dir,xtraSourceWeight.incrementAndGet(),true);
|
||||
add(dirsource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CommandLineConfigSource getCommandLineSource()
|
||||
{
|
||||
for (ConfigSource source : sources)
|
||||
{
|
||||
if (source instanceof CommandLineConfigSource)
|
||||
{
|
||||
return (CommandLineConfigSource)source;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Prop getProp(String key)
|
||||
{
|
||||
return props.getProp(key);
|
||||
}
|
||||
|
||||
public Props getProps()
|
||||
{
|
||||
return props;
|
||||
}
|
||||
|
||||
private String getValue(String arg)
|
||||
{
|
||||
int idx = arg.indexOf('=');
|
||||
if (idx == (-1))
|
||||
{
|
||||
throw new UsageException(ERR_BAD_ARG,"Argument is missing a required value: %s",arg);
|
||||
}
|
||||
String value = arg.substring(idx + 1).trim();
|
||||
if (value.length() <= 0)
|
||||
{
|
||||
throw new UsageException(ERR_BAD_ARG,"Argument is missing a required value: %s",arg);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ConfigSource> iterator()
|
||||
{
|
||||
return sources.iterator();
|
||||
}
|
||||
|
||||
public ListIterator<ConfigSource> reverseListIterator()
|
||||
{
|
||||
return sources.listIterator(sources.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.append(this.getClass().getSimpleName());
|
||||
str.append('[');
|
||||
boolean delim = false;
|
||||
for (ConfigSource source : sources)
|
||||
{
|
||||
if (delim)
|
||||
{
|
||||
str.append(',');
|
||||
}
|
||||
str.append(source.getId());
|
||||
delim = true;
|
||||
}
|
||||
str.append(']');
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
private void updateProps()
|
||||
{
|
||||
props.reset();
|
||||
|
||||
// add all properties from config sources (in reverse order)
|
||||
ListIterator<ConfigSource> iter = sources.listIterator(sources.size());
|
||||
while (iter.hasPrevious())
|
||||
{
|
||||
ConfigSource source = iter.previous();
|
||||
props.addAll(source.getProps());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,255 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.start.config;
|
||||
|
||||
import static org.eclipse.jetty.start.UsageException.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.PathMatcher;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.start.FS;
|
||||
import org.eclipse.jetty.start.NaturalSort;
|
||||
import org.eclipse.jetty.start.PathMatchers;
|
||||
import org.eclipse.jetty.start.Props;
|
||||
import org.eclipse.jetty.start.UsageException;
|
||||
import org.eclipse.jetty.start.Props.Prop;
|
||||
import org.eclipse.jetty.start.StartIni;
|
||||
import org.eclipse.jetty.start.StartLog;
|
||||
|
||||
/**
|
||||
* A Directory based {@link ConfigSource}.
|
||||
* <p>
|
||||
* Such as <code>${jetty.base}</code> or and <code>--extra-start-dir=[path]</code> sources.
|
||||
*/
|
||||
public class DirConfigSource implements ConfigSource
|
||||
{
|
||||
private static final List<String> BANNED_ARGS;
|
||||
|
||||
static
|
||||
{
|
||||
// Arguments that are not allowed to be in start.ini or start.d/{name}.ini files
|
||||
BANNED_ARGS = new ArrayList<>();
|
||||
BANNED_ARGS.add("--help");
|
||||
BANNED_ARGS.add("-?");
|
||||
BANNED_ARGS.add("--stop");
|
||||
BANNED_ARGS.add("--dry-run");
|
||||
BANNED_ARGS.add("--exec-print");
|
||||
BANNED_ARGS.add("--list-config");
|
||||
BANNED_ARGS.add("--list-classpath");
|
||||
BANNED_ARGS.add("--list-modules");
|
||||
BANNED_ARGS.add("--write-module-graph");
|
||||
BANNED_ARGS.add("--version");
|
||||
BANNED_ARGS.add("-v");
|
||||
BANNED_ARGS.add("--download");
|
||||
BANNED_ARGS.add("--create-files");
|
||||
BANNED_ARGS.add("--add-to-startd");
|
||||
BANNED_ARGS.add("--add-to-start");
|
||||
}
|
||||
|
||||
private final String id;
|
||||
private final Path dir;
|
||||
private final int weight;
|
||||
private final List<String> args;
|
||||
private final Props props;
|
||||
|
||||
/**
|
||||
* Create DirConfigSource with specified identifier and directory.
|
||||
*
|
||||
* @param id
|
||||
* the identifier for this {@link ConfigSource}
|
||||
* @param dir
|
||||
* the directory for this {@link ConfigSource}
|
||||
* @param weight
|
||||
* the configuration weight (used for search order)
|
||||
* @param canHaveArgs
|
||||
* true if this directory can have start.ini or start.d entries. (false for directories like ${jetty.home}, for example)
|
||||
* @throws IOException
|
||||
* if unable to load the configuration args
|
||||
*/
|
||||
public DirConfigSource(String id, Path dir, int weight, boolean canHaveArgs) throws IOException
|
||||
{
|
||||
this.id = id;
|
||||
this.dir = dir.toAbsolutePath();
|
||||
this.weight = weight;
|
||||
this.props = new Props();
|
||||
|
||||
this.args = new ArrayList<>();
|
||||
|
||||
if (canHaveArgs)
|
||||
{
|
||||
Path iniFile = dir.resolve("start.ini");
|
||||
if (FS.canReadFile(iniFile))
|
||||
{
|
||||
StartIni ini = new StartIni(iniFile);
|
||||
args.addAll(ini.getLines());
|
||||
parseAllArgs(ini.getLines(),iniFile.toString());
|
||||
}
|
||||
|
||||
Path startDdir = dir.resolve("start.d");
|
||||
|
||||
if (FS.canReadDirectory(startDdir))
|
||||
{
|
||||
DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>()
|
||||
{
|
||||
PathMatcher iniMatcher = PathMatchers.getMatcher("glob:**/start.d/*.ini");
|
||||
|
||||
@Override
|
||||
public boolean accept(Path entry) throws IOException
|
||||
{
|
||||
return iniMatcher.matches(entry);
|
||||
}
|
||||
};
|
||||
|
||||
List<Path> paths = new ArrayList<>();
|
||||
|
||||
for (Path diniFile : Files.newDirectoryStream(startDdir,filter))
|
||||
{
|
||||
if (FS.canReadFile(diniFile))
|
||||
{
|
||||
paths.add(diniFile);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(paths,new NaturalSort.Paths());
|
||||
|
||||
for (Path diniFile : paths)
|
||||
{
|
||||
StartLog.debug("Reading %s/start.d/%s - %s",id,diniFile.getFileName(),diniFile);
|
||||
StartIni ini = new StartIni(diniFile);
|
||||
args.addAll(ini.getLines());
|
||||
parseAllArgs(ini.getLines(),diniFile.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parseAllArgs(List<String> lines, String origin)
|
||||
{
|
||||
for (String line : lines)
|
||||
{
|
||||
String arg = line;
|
||||
int idx = line.indexOf('=');
|
||||
if (idx > 0)
|
||||
{
|
||||
arg = line.substring(0,idx);
|
||||
}
|
||||
if (BANNED_ARGS.contains(arg))
|
||||
{
|
||||
throw new UsageException(ERR_BAD_ARG,"%s not allowed in %s",arg,origin);
|
||||
}
|
||||
this.props.addPossibleProperty(line,origin);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
DirConfigSource other = (DirConfigSource)obj;
|
||||
if (dir == null)
|
||||
{
|
||||
if (other.dir != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!dir.equals(other.dir))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getArgs()
|
||||
{
|
||||
return args;
|
||||
}
|
||||
|
||||
public Path getDir()
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProperty(String key)
|
||||
{
|
||||
Prop prop = props.getProp(key,false);
|
||||
if (prop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return prop.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Props getProps()
|
||||
{
|
||||
return props;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWeight()
|
||||
{
|
||||
return weight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = (prime * result) + ((dir == null)?0:dir.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isPropertyBased()
|
||||
{
|
||||
return id.contains("${");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s[%s,%s,args.length=%d]",this.getClass().getSimpleName(),id,dir,getArgs().size());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.start.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* ${jetty.base} specific ConfigSource
|
||||
*/
|
||||
public class JettyBaseConfigSource extends DirConfigSource
|
||||
{
|
||||
// Standard weight for ${jetty.base}, so that it comes after command line, and before everything else
|
||||
private final static int WEIGHT = 0;
|
||||
|
||||
public JettyBaseConfigSource(Path dir) throws IOException
|
||||
{
|
||||
super("${jetty.base}",dir,WEIGHT,true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.start.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* ${jetty.home} specific ConfigSource
|
||||
*/
|
||||
public class JettyHomeConfigSource extends DirConfigSource
|
||||
{
|
||||
// Standard weight for ${jetty.home}, so that it comes after everything else
|
||||
private final static int WEIGHT = 9999999;
|
||||
|
||||
public JettyHomeConfigSource(Path dir) throws IOException
|
||||
{
|
||||
super("${jetty.home}",dir,WEIGHT,false);
|
||||
}
|
||||
}
|
|
@ -26,6 +26,9 @@ import java.nio.file.Path;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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.IO;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.junit.Assert;
|
||||
|
@ -92,18 +95,20 @@ public class BaseHomeTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetFile_OnlyHome() throws IOException
|
||||
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);
|
||||
File startIni = hb.getFile("/start.ini");
|
||||
BaseHome hb = new BaseHome(config);
|
||||
Path startIni = hb.getPath("start.ini");
|
||||
|
||||
String ref = hb.toShortForm(startIni);
|
||||
Assert.assertThat("Reference",ref,startsWith("${jetty.home}"));
|
||||
|
||||
String contents = IO.readToString(startIni);
|
||||
String contents = IO.readToString(startIni.toFile());
|
||||
Assert.assertThat("Contents",contents,containsString("Home Ini"));
|
||||
}
|
||||
|
||||
|
@ -111,9 +116,11 @@ public class BaseHomeTest
|
|||
public void testGetPaths_OnlyHome() throws IOException
|
||||
{
|
||||
File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home");
|
||||
File baseDir = null;
|
||||
|
||||
BaseHome hb = new BaseHome(homeDir,baseDir);
|
||||
ConfigSources config = new ConfigSources();
|
||||
config.add(new JettyHomeConfigSource(homeDir.toPath()));
|
||||
|
||||
BaseHome hb = new BaseHome(config);
|
||||
List<Path> paths = hb.getPaths("start.d/*");
|
||||
|
||||
List<String> expected = new ArrayList<>();
|
||||
|
@ -131,9 +138,11 @@ public class BaseHomeTest
|
|||
public void testGetPaths_OnlyHome_InisOnly() throws IOException
|
||||
{
|
||||
File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home");
|
||||
File baseDir = null;
|
||||
|
||||
BaseHome hb = new BaseHome(homeDir,baseDir);
|
||||
ConfigSources config = new ConfigSources();
|
||||
config.add(new JettyHomeConfigSource(homeDir.toPath()));
|
||||
|
||||
BaseHome hb = new BaseHome(config);
|
||||
List<Path> paths = hb.getPaths("start.d/*.ini");
|
||||
|
||||
List<String> expected = new ArrayList<>();
|
||||
|
@ -153,7 +162,11 @@ public class BaseHomeTest
|
|||
File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home");
|
||||
File baseDir = MavenTestingUtils.getTestResourceDir("hb.1/base");
|
||||
|
||||
BaseHome hb = new BaseHome(homeDir,baseDir);
|
||||
ConfigSources config = new ConfigSources();
|
||||
config.add(new JettyBaseConfigSource(baseDir.toPath()));
|
||||
config.add(new JettyHomeConfigSource(homeDir.toPath()));
|
||||
|
||||
BaseHome hb = new BaseHome(config);
|
||||
List<Path> paths = hb.getPaths("start.d/*.ini");
|
||||
|
||||
List<String> expected = new ArrayList<>();
|
||||
|
@ -177,18 +190,22 @@ public class BaseHomeTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetFile_Both() throws IOException
|
||||
public void testGetPath_Both() throws IOException
|
||||
{
|
||||
File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home");
|
||||
File baseDir = MavenTestingUtils.getTestResourceDir("hb.1/base");
|
||||
|
||||
BaseHome hb = new BaseHome(homeDir,baseDir);
|
||||
File startIni = hb.getFile("/start.ini");
|
||||
ConfigSources config = new ConfigSources();
|
||||
config.add(new JettyBaseConfigSource(baseDir.toPath()));
|
||||
config.add(new JettyHomeConfigSource(homeDir.toPath()));
|
||||
|
||||
BaseHome hb = new BaseHome(config);
|
||||
Path startIni = hb.getPath("start.ini");
|
||||
|
||||
String ref = hb.toShortForm(startIni);
|
||||
Assert.assertThat("Reference",ref,startsWith("${jetty.base}"));
|
||||
|
||||
String contents = IO.readToString(startIni);
|
||||
String contents = IO.readToString(startIni.toFile());
|
||||
Assert.assertThat("Contents",contents,containsString("Base Ini"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.io.FileNotFoundException;
|
|||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
@ -64,7 +65,7 @@ public class ConfigurationAssert
|
|||
}
|
||||
}
|
||||
List<String> actualXmls = new ArrayList<>();
|
||||
for (File xml : args.getXmlFiles())
|
||||
for (Path xml : args.getXmlFiles())
|
||||
{
|
||||
actualXmls.add(shorten(baseHome,xml,testResourcesDir));
|
||||
}
|
||||
|
@ -82,7 +83,7 @@ public class ConfigurationAssert
|
|||
List<String> actualLibs = new ArrayList<>();
|
||||
for (File path : args.getClasspath())
|
||||
{
|
||||
actualLibs.add(shorten(baseHome,path,testResourcesDir));
|
||||
actualLibs.add(shorten(baseHome,path.toPath(),testResourcesDir));
|
||||
}
|
||||
assertContainsUnordered("Libs",expectedLibs,actualLibs);
|
||||
|
||||
|
@ -99,7 +100,8 @@ public class ConfigurationAssert
|
|||
for (Prop prop : args.getProperties())
|
||||
{
|
||||
String name = prop.key;
|
||||
if ("jetty.home".equals(name) || "jetty.base".equals(name) || prop.origin.equals(Props.ORIGIN_SYSPROP))
|
||||
if ("jetty.home".equals(name) || "jetty.base".equals(name) ||
|
||||
"user.dir".equals(name) || prop.origin.equals(Props.ORIGIN_SYSPROP))
|
||||
{
|
||||
// strip these out from assertion, to make assertions easier.
|
||||
continue;
|
||||
|
@ -147,7 +149,7 @@ public class ConfigurationAssert
|
|||
assertContainsUnordered("Files/Dirs",expectedFiles,actualFiles);
|
||||
}
|
||||
|
||||
private static String shorten(BaseHome baseHome, File path, File testResourcesDir)
|
||||
private static String shorten(BaseHome baseHome, Path path, File testResourcesDir)
|
||||
{
|
||||
String value = baseHome.toShortForm(path);
|
||||
if (value.startsWith(testResourcesDir.getAbsolutePath()))
|
||||
|
@ -206,7 +208,7 @@ public class ConfigurationAssert
|
|||
}
|
||||
}
|
||||
|
||||
private static void assertOrdered(String msg, List<String> expectedList, List<String> actualList)
|
||||
public static void assertOrdered(String msg, List<String> expectedList, List<String> actualList)
|
||||
{
|
||||
// same size?
|
||||
boolean mismatch = expectedList.size() != actualList.size();
|
||||
|
|
|
@ -0,0 +1,559 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
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.start.Props.Prop;
|
||||
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.toolchain.test.FS;
|
||||
import org.eclipse.jetty.toolchain.test.TestingDir;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExtraStartTest
|
||||
{
|
||||
private static class MainResult
|
||||
{
|
||||
private Main main;
|
||||
private StartArgs args;
|
||||
|
||||
public void assertSearchOrder(List<String> expectedSearchOrder)
|
||||
{
|
||||
ConfigSources sources = main.getBaseHome().getConfigSources();
|
||||
List<String> actualOrder = new ArrayList<>();
|
||||
for (ConfigSource source : sources)
|
||||
{
|
||||
if (source instanceof DirConfigSource)
|
||||
{
|
||||
actualOrder.add(source.getId());
|
||||
}
|
||||
}
|
||||
ConfigurationAssert.assertOrdered("Search Order",expectedSearchOrder,actualOrder);
|
||||
}
|
||||
|
||||
public void assertProperty(String key, String expectedValue)
|
||||
{
|
||||
Prop prop = args.getProperties().getProp(key);
|
||||
String prefix = "Prop[" + key + "]";
|
||||
Assert.assertThat(prefix + " should have a value",prop,notNullValue());
|
||||
Assert.assertThat(prefix + " value",prop.value,is(expectedValue));
|
||||
}
|
||||
}
|
||||
|
||||
@Rule
|
||||
public TestingDir testdir = new TestingDir();
|
||||
|
||||
private MainResult runMain(File baseDir, File homeDir, String... cmdLineArgs) throws Exception
|
||||
{
|
||||
MainResult ret = new MainResult();
|
||||
ret.main = new Main();
|
||||
List<String> cmdLine = new ArrayList<>();
|
||||
cmdLine.add("jetty.home=" + homeDir.getAbsolutePath());
|
||||
cmdLine.add("jetty.base=" + baseDir.getAbsolutePath());
|
||||
// cmdLine.add("--debug");
|
||||
for (String arg : cmdLineArgs)
|
||||
{
|
||||
cmdLine.add(arg);
|
||||
}
|
||||
ret.args = ret.main.processCommandLine(cmdLine);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExtras() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1");
|
||||
|
||||
// Simple command line - no reference to extra-start-dirs
|
||||
MainResult result = runMain(base,home);
|
||||
|
||||
List<String> expectedSearchOrder = new ArrayList<>();
|
||||
expectedSearchOrder.add("${jetty.base}");
|
||||
expectedSearchOrder.add("${jetty.home}");
|
||||
result.assertSearchOrder(expectedSearchOrder);
|
||||
|
||||
result.assertProperty("jetty.host","127.0.0.1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandLine_1Extra() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// 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");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1");
|
||||
|
||||
// Simple command line reference to extra-start-dir
|
||||
MainResult result = runMain(base,home,
|
||||
// direct reference via path
|
||||
"--extra-start-dir=" + common.getAbsolutePath());
|
||||
|
||||
List<String> expectedSearchOrder = new ArrayList<>();
|
||||
expectedSearchOrder.add("${jetty.base}");
|
||||
expectedSearchOrder.add(common.getAbsolutePath());
|
||||
expectedSearchOrder.add("${jetty.home}");
|
||||
result.assertSearchOrder(expectedSearchOrder);
|
||||
|
||||
result.assertProperty("jetty.host","127.0.0.1");
|
||||
result.assertProperty("jetty.port","8080"); // from 'common'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandLine_1Extra_FromSimpleProp() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// 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");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1");
|
||||
|
||||
// Simple command line reference to extra-start-dir via property (also on command line)
|
||||
MainResult result = runMain(base,home,
|
||||
// property
|
||||
"my.common=" + common.getAbsolutePath(),
|
||||
// reference via property
|
||||
"--extra-start-dir=${my.common}");
|
||||
|
||||
List<String> expectedSearchOrder = new ArrayList<>();
|
||||
expectedSearchOrder.add("${jetty.base}");
|
||||
expectedSearchOrder.add("${my.common}"); // should see property use
|
||||
expectedSearchOrder.add("${jetty.home}");
|
||||
result.assertSearchOrder(expectedSearchOrder);
|
||||
|
||||
result.assertProperty("jetty.host","127.0.0.1");
|
||||
result.assertProperty("jetty.port","8080"); // from 'common'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandLine_1Extra_FromPropPrefix() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// Create opt
|
||||
File opt = testdir.getFile("opt");
|
||||
FS.ensureEmpty(opt);
|
||||
|
||||
// Create common
|
||||
File common = new File(opt,"common");
|
||||
FS.ensureEmpty(common);
|
||||
TestEnv.makeFile(common,"start.ini","jetty.port=8080");
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1");
|
||||
|
||||
String dirRef = "${my.opt}" + File.separator + "common";
|
||||
|
||||
// Simple command line reference to extra-start-dir via property (also on command line)
|
||||
MainResult result = runMain(base,home,
|
||||
// property to 'opt' dir
|
||||
"my.opt=" + opt.getAbsolutePath(),
|
||||
// reference via property prefix
|
||||
"--extra-start-dir=" + dirRef);
|
||||
|
||||
List<String> expectedSearchOrder = new ArrayList<>();
|
||||
expectedSearchOrder.add("${jetty.base}");
|
||||
expectedSearchOrder.add(dirRef); // should use property
|
||||
expectedSearchOrder.add("${jetty.home}");
|
||||
result.assertSearchOrder(expectedSearchOrder);
|
||||
|
||||
result.assertProperty("jetty.host","127.0.0.1");
|
||||
result.assertProperty("jetty.port","8080"); // from 'common'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandLine_1Extra_FromCompoundProp() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// Create opt
|
||||
File opt = testdir.getFile("opt");
|
||||
FS.ensureEmpty(opt);
|
||||
|
||||
// Create common
|
||||
File common = new File(opt,"common");
|
||||
FS.ensureEmpty(common);
|
||||
TestEnv.makeFile(common,"start.ini","jetty.port=8080");
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1");
|
||||
|
||||
String dirRef = "${my.opt}" + File.separator + "${my.dir}";
|
||||
|
||||
// Simple command line reference to extra-start-dir via property (also on command line)
|
||||
MainResult result = runMain(base,home,
|
||||
// property to 'opt' dir
|
||||
"my.opt=" + opt.getAbsolutePath(),
|
||||
// property to commmon dir name
|
||||
"my.dir=common",
|
||||
// reference via property prefix
|
||||
"--extra-start-dir=" + dirRef);
|
||||
|
||||
List<String> expectedSearchOrder = new ArrayList<>();
|
||||
expectedSearchOrder.add("${jetty.base}");
|
||||
expectedSearchOrder.add(dirRef); // should use property
|
||||
expectedSearchOrder.add("${jetty.home}");
|
||||
result.assertSearchOrder(expectedSearchOrder);
|
||||
|
||||
result.assertProperty("jetty.host","127.0.0.1");
|
||||
result.assertProperty("jetty.port","8080"); // from 'common'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefCommon() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// 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");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1",//
|
||||
"--extra-start-dir=" + common.getAbsolutePath());
|
||||
|
||||
MainResult result = runMain(base,home);
|
||||
|
||||
List<String> expectedSearchOrder = new ArrayList<>();
|
||||
expectedSearchOrder.add("${jetty.base}");
|
||||
expectedSearchOrder.add(common.getAbsolutePath());
|
||||
expectedSearchOrder.add("${jetty.home}");
|
||||
result.assertSearchOrder(expectedSearchOrder);
|
||||
|
||||
result.assertProperty("jetty.host","127.0.0.1");
|
||||
result.assertProperty("jetty.port","8080"); // from 'common'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefCommonAndCorp() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// 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");
|
||||
FS.ensureEmpty(corp);
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1",//
|
||||
"--extra-start-dir=" + common.getAbsolutePath(), //
|
||||
"--extra-start-dir=" + corp.getAbsolutePath());
|
||||
|
||||
MainResult result = runMain(base,home);
|
||||
|
||||
List<String> expectedSearchOrder = new ArrayList<>();
|
||||
expectedSearchOrder.add("${jetty.base}");
|
||||
expectedSearchOrder.add(common.getAbsolutePath());
|
||||
expectedSearchOrder.add(corp.getAbsolutePath());
|
||||
expectedSearchOrder.add("${jetty.home}");
|
||||
result.assertSearchOrder(expectedSearchOrder);
|
||||
|
||||
result.assertProperty("jetty.host","127.0.0.1");
|
||||
result.assertProperty("jetty.port","8080"); // from 'common'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefCommonRefCorp() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// Create corp
|
||||
File corp = testdir.getFile("corp");
|
||||
FS.ensureEmpty(corp);
|
||||
TestEnv.makeFile(corp,"start.ini","jetty.port=9090");
|
||||
|
||||
// Create common
|
||||
File common = testdir.getFile("common");
|
||||
FS.ensureEmpty(common);
|
||||
TestEnv.makeFile(common,"start.ini", //
|
||||
"--extra-start-dir=" + corp.getAbsolutePath(), //
|
||||
"jetty.port=8080");
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1",//
|
||||
"--extra-start-dir=" + common.getAbsolutePath());
|
||||
|
||||
MainResult result = runMain(base,home);
|
||||
|
||||
List<String> expectedSearchOrder = new ArrayList<>();
|
||||
expectedSearchOrder.add("${jetty.base}");
|
||||
expectedSearchOrder.add(common.getAbsolutePath());
|
||||
expectedSearchOrder.add(corp.getAbsolutePath());
|
||||
expectedSearchOrder.add("${jetty.home}");
|
||||
result.assertSearchOrder(expectedSearchOrder);
|
||||
|
||||
result.assertProperty("jetty.host","127.0.0.1");
|
||||
result.assertProperty("jetty.port","8080"); // from 'common'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefCommonRefCorp_FromSimpleProps() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// Create corp
|
||||
File corp = testdir.getFile("corp");
|
||||
FS.ensureEmpty(corp);
|
||||
TestEnv.makeFile(corp,"start.ini", //
|
||||
"jetty.port=9090");
|
||||
|
||||
// Create common
|
||||
File common = testdir.getFile("common");
|
||||
FS.ensureEmpty(common);
|
||||
TestEnv.makeFile(common,"start.ini", //
|
||||
"my.corp=" + corp.getAbsolutePath(), //
|
||||
"--extra-start-dir=${my.corp}", //
|
||||
"jetty.port=8080");
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1",//
|
||||
"my.common=" + common.getAbsolutePath(), //
|
||||
"--extra-start-dir=${my.common}");
|
||||
|
||||
MainResult result = runMain(base,home);
|
||||
|
||||
List<String> expectedSearchOrder = new ArrayList<>();
|
||||
expectedSearchOrder.add("${jetty.base}");
|
||||
expectedSearchOrder.add("${my.common}");
|
||||
expectedSearchOrder.add("${my.corp}");
|
||||
expectedSearchOrder.add("${jetty.home}");
|
||||
result.assertSearchOrder(expectedSearchOrder);
|
||||
|
||||
result.assertProperty("jetty.host","127.0.0.1");
|
||||
result.assertProperty("jetty.port","8080"); // from 'common'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefCommonRefCorp_CmdLineRef() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// Create devops
|
||||
File devops = testdir.getFile("devops");
|
||||
FS.ensureEmpty(devops);
|
||||
TestEnv.makeFile(devops,"start.ini", //
|
||||
"--module=logging", //
|
||||
"jetty.port=2222");
|
||||
|
||||
// Create corp
|
||||
File corp = testdir.getFile("corp");
|
||||
FS.ensureEmpty(corp);
|
||||
TestEnv.makeFile(corp,"start.ini", //
|
||||
"jetty.port=9090");
|
||||
|
||||
// Create common
|
||||
File common = testdir.getFile("common");
|
||||
FS.ensureEmpty(common);
|
||||
TestEnv.makeFile(common,"start.ini", //
|
||||
"--extra-start-dir=" + corp.getAbsolutePath(), //
|
||||
"jetty.port=8080");
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1",//
|
||||
"--extra-start-dir=" + common.getAbsolutePath());
|
||||
|
||||
MainResult result = runMain(base,home,
|
||||
// command line provided extra-start-dir ref
|
||||
"--extra-start-dir=" + devops.getAbsolutePath());
|
||||
|
||||
List<String> expectedSearchOrder = new ArrayList<>();
|
||||
expectedSearchOrder.add("${jetty.base}");
|
||||
expectedSearchOrder.add(devops.getAbsolutePath());
|
||||
expectedSearchOrder.add(common.getAbsolutePath());
|
||||
expectedSearchOrder.add(corp.getAbsolutePath());
|
||||
expectedSearchOrder.add("${jetty.home}");
|
||||
result.assertSearchOrder(expectedSearchOrder);
|
||||
|
||||
result.assertProperty("jetty.host","127.0.0.1");
|
||||
result.assertProperty("jetty.port","2222"); // from 'devops'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefCommonRefCorp_CmdLineProp() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// Create corp
|
||||
File corp = testdir.getFile("corp");
|
||||
FS.ensureEmpty(corp);
|
||||
TestEnv.makeFile(corp,"start.ini", //
|
||||
"jetty.port=9090");
|
||||
|
||||
// Create common
|
||||
File common = testdir.getFile("common");
|
||||
FS.ensureEmpty(common);
|
||||
TestEnv.makeFile(common,"start.ini", //
|
||||
"--extra-start-dir=" + corp.getAbsolutePath(), //
|
||||
"jetty.port=8080");
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1",//
|
||||
"--extra-start-dir=" + common.getAbsolutePath());
|
||||
|
||||
MainResult result = runMain(base,home,
|
||||
// command line property should override all others
|
||||
"jetty.port=7070");
|
||||
|
||||
List<String> expectedSearchOrder = new ArrayList<>();
|
||||
expectedSearchOrder.add("${jetty.base}");
|
||||
expectedSearchOrder.add(common.getAbsolutePath());
|
||||
expectedSearchOrder.add(corp.getAbsolutePath());
|
||||
expectedSearchOrder.add("${jetty.home}");
|
||||
result.assertSearchOrder(expectedSearchOrder);
|
||||
|
||||
result.assertProperty("jetty.host","127.0.0.1");
|
||||
result.assertProperty("jetty.port","7070"); // from command line
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadDoubleRef() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// Create common
|
||||
File common = testdir.getFile("common");
|
||||
FS.ensureEmpty(common);
|
||||
|
||||
// Create corp
|
||||
File corp = testdir.getFile("corp");
|
||||
FS.ensureEmpty(corp);
|
||||
TestEnv.makeFile(corp,"start.ini",
|
||||
// standard property
|
||||
"jetty.port=9090",
|
||||
// INTENTIONAL BAD Reference (duplicate)
|
||||
"--extra-start-dir=" + common.getAbsolutePath());
|
||||
|
||||
// Populate common
|
||||
TestEnv.makeFile(common,"start.ini",
|
||||
// standard property
|
||||
"jetty.port=8080",
|
||||
// reference to corp
|
||||
"--extra-start-dir=" + corp.getAbsolutePath());
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1",//
|
||||
"--extra-start-dir=" + common.getAbsolutePath());
|
||||
|
||||
try
|
||||
{
|
||||
runMain(base,home);
|
||||
Assert.fail("Should have thrown a UsageException");
|
||||
}
|
||||
catch (UsageException e)
|
||||
{
|
||||
Assert.assertThat("UsageException",e.getMessage(),containsString("Duplicate"));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,28 +18,34 @@
|
|||
|
||||
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").getAbsoluteFile();
|
||||
cmdLineArgs.add("user.dir=" + testJettyHome);
|
||||
cmdLineArgs.add("jetty.home=" + testJettyHome);
|
||||
cmdLineArgs.add("jetty.port=9090");
|
||||
|
||||
Main main = new Main();
|
||||
|
@ -74,7 +80,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 +104,9 @@ public class MainTest
|
|||
{
|
||||
List<String> cmdLineArgs = new ArrayList<>();
|
||||
|
||||
addUseCasesHome(cmdLineArgs);
|
||||
File homePath = MavenTestingUtils.getTestResourceDir("usecases/home").getAbsoluteFile();
|
||||
cmdLineArgs.add("jetty.home=" + homePath);
|
||||
cmdLineArgs.add("user.dir=" + homePath);
|
||||
|
||||
// JVM args
|
||||
cmdLineArgs.add("--exec");
|
||||
|
@ -118,7 +127,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");
|
||||
}
|
||||
|
@ -128,14 +139,17 @@ public class MainTest
|
|||
{
|
||||
List<String> cmdLineArgs = new ArrayList<>();
|
||||
|
||||
File homePath = MavenTestingUtils.getTestResourceDir("jetty home with spaces");
|
||||
File homePath = MavenTestingUtils.getTestResourceDir("jetty home with spaces").getAbsoluteFile();
|
||||
cmdLineArgs.add("user.dir=" + homePath);
|
||||
cmdLineArgs.add("jetty.home=" + homePath);
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,13 +18,16 @@
|
|||
|
||||
package org.eclipse.jetty.start;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.nio.file.Path;
|
||||
|
||||
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;
|
||||
|
@ -33,30 +36,39 @@ import org.junit.Test;
|
|||
|
||||
public class ModuleGraphWriterTest
|
||||
{
|
||||
@SuppressWarnings("unused")
|
||||
private final static List<String> TEST_SOURCE = Collections.singletonList("<test>");
|
||||
|
||||
private StartArgs DEFAULT_ARGS = new StartArgs(new String[]{"jetty.version=TEST"}).parseCommandLine();
|
||||
|
||||
@Rule
|
||||
public TestingDir testdir = new TestingDir();
|
||||
|
||||
@Test
|
||||
public void testGenerate_NothingEnabled() throws IOException
|
||||
{
|
||||
// Test Env
|
||||
File homeDir = MavenTestingUtils.getTestResourceDir("usecases/home");
|
||||
File baseDir = testdir.getEmptyDir();
|
||||
BaseHome basehome = new BaseHome(homeDir,baseDir);
|
||||
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();
|
||||
args.parse(config);
|
||||
|
||||
Modules modules = new Modules();
|
||||
modules.registerAll(basehome, DEFAULT_ARGS);
|
||||
modules.registerAll(basehome, args);
|
||||
modules.buildGraph();
|
||||
|
||||
File outputFile = new File(baseDir,"graph.dot");
|
||||
Path outputFile = basehome.getBasePath("graph.dot");
|
||||
|
||||
ModuleGraphWriter writer = new ModuleGraphWriter();
|
||||
writer.write(modules,outputFile);
|
||||
|
||||
Assert.assertThat("Output File Exists",outputFile.exists(),is(true));
|
||||
Assert.assertThat("Output File Exists",FS.exists(outputFile),is(true));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
@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"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,23 +27,47 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
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 ModulesTest
|
||||
{
|
||||
private final static List<String> TEST_SOURCE = Collections.singletonList("<test>");
|
||||
private StartArgs DEFAULT_ARGS = new StartArgs(new String[] { "jetty.version=TEST" }).parseCommandLine();
|
||||
|
||||
@Rule
|
||||
public TestingDir testdir = new TestingDir();
|
||||
|
||||
@Test
|
||||
public void testLoadAllModules() throws IOException
|
||||
{
|
||||
// Test Env
|
||||
File homeDir = MavenTestingUtils.getTestResourceDir("usecases/home");
|
||||
BaseHome basehome = new BaseHome(homeDir,homeDir);
|
||||
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);
|
||||
|
||||
StartArgs args = new StartArgs();
|
||||
args.parse(config);
|
||||
|
||||
// Test Modules
|
||||
Modules modules = new Modules();
|
||||
modules.registerAll(basehome,DEFAULT_ARGS);
|
||||
modules.registerAll(basehome,args);
|
||||
|
||||
List<String> moduleNames = new ArrayList<>();
|
||||
for (Module mod : modules)
|
||||
|
@ -66,11 +90,27 @@ public class ModulesTest
|
|||
@Test
|
||||
public void testEnableRegexSimple() throws IOException
|
||||
{
|
||||
// Test Env
|
||||
File homeDir = MavenTestingUtils.getTestResourceDir("usecases/home");
|
||||
BaseHome basehome = new BaseHome(homeDir,homeDir);
|
||||
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);
|
||||
|
||||
StartArgs args = new StartArgs();
|
||||
args.parse(config);
|
||||
|
||||
// Test Modules
|
||||
Modules modules = new Modules();
|
||||
modules.registerAll(basehome,DEFAULT_ARGS);
|
||||
modules.registerAll(basehome,args);
|
||||
modules.enable("[sj]{1}.*",TEST_SOURCE);
|
||||
|
||||
String expected[] = { "jmx", "stats", "spdy", "security", "jndi", "jsp", "servlet", "jaas", "server" };
|
||||
|
@ -81,12 +121,27 @@ public class ModulesTest
|
|||
@Test
|
||||
public void testResolve_ServerHttp() throws IOException
|
||||
{
|
||||
// Test Env
|
||||
File homeDir = MavenTestingUtils.getTestResourceDir("usecases/home");
|
||||
BaseHome basehome = new BaseHome(homeDir,homeDir);
|
||||
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);
|
||||
|
||||
StartArgs args = new StartArgs();
|
||||
args.parse(config);
|
||||
|
||||
// Register modules
|
||||
// Test Modules
|
||||
Modules modules = new Modules();
|
||||
modules.registerAll(basehome,DEFAULT_ARGS);
|
||||
modules.registerAll(basehome,args);
|
||||
modules.buildGraph();
|
||||
|
||||
// Enable 2 modules
|
||||
|
@ -137,12 +192,27 @@ public class ModulesTest
|
|||
@Test
|
||||
public void testResolve_WebSocket() throws IOException
|
||||
{
|
||||
// Test Env
|
||||
File homeDir = MavenTestingUtils.getTestResourceDir("usecases/home");
|
||||
BaseHome basehome = new BaseHome(homeDir,homeDir);
|
||||
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);
|
||||
|
||||
StartArgs args = new StartArgs();
|
||||
args.parse(config);
|
||||
|
||||
// Register modules
|
||||
// Test Modules
|
||||
Modules modules = new Modules();
|
||||
modules.registerAll(basehome,DEFAULT_ARGS);
|
||||
modules.registerAll(basehome,args);
|
||||
modules.buildGraph();
|
||||
// modules.dump();
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.start;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.FS;
|
||||
import org.eclipse.jetty.toolchain.test.IO;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.toolchain.test.OS;
|
||||
|
||||
public class TestEnv
|
||||
{
|
||||
public static void copyTestDir(String testResourceDir, File destDir) throws IOException
|
||||
{
|
||||
FS.ensureDirExists(destDir);
|
||||
File srcDir = MavenTestingUtils.getTestResourceDir(testResourceDir);
|
||||
IO.copyDir(srcDir,destDir);
|
||||
}
|
||||
|
||||
public static void makeFile(File dir, String relFilePath, String... contents) throws IOException
|
||||
{
|
||||
File outputFile = new File(dir,OS.separators(relFilePath));
|
||||
FS.ensureDirExists(outputFile.getParentFile());
|
||||
try (FileWriter writer = new FileWriter(outputFile); PrintWriter out = new PrintWriter(writer))
|
||||
{
|
||||
for (String content : contents)
|
||||
{
|
||||
out.println(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -60,6 +60,12 @@ public class TestUseCases
|
|||
{
|
||||
assertUseCase("home","base.jmx","assert-jmx.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithExtraStartDir_Logging() throws Exception
|
||||
{
|
||||
assertUseCase("home","base.with.extra.start.dirs","assert-extra-start-dir-logging.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithMissingNpnVersion() throws Exception
|
||||
|
|
|
@ -0,0 +1,599 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.start.config;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.start.ConfigurationAssert;
|
||||
import org.eclipse.jetty.start.Props.Prop;
|
||||
import org.eclipse.jetty.start.TestEnv;
|
||||
import org.eclipse.jetty.start.UsageException;
|
||||
import org.eclipse.jetty.toolchain.test.FS;
|
||||
import org.eclipse.jetty.toolchain.test.TestingDir;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ConfigSourcesTest
|
||||
{
|
||||
@Rule
|
||||
public TestingDir testdir = new TestingDir();
|
||||
|
||||
private void assertIdOrder(ConfigSources sources, String... expectedOrder)
|
||||
{
|
||||
List<String> actualList = new ArrayList<>();
|
||||
for (ConfigSource source : sources)
|
||||
{
|
||||
actualList.add(source.getId());
|
||||
}
|
||||
List<String> expectedList = Arrays.asList(expectedOrder);
|
||||
ConfigurationAssert.assertOrdered("ConfigSources.id order",expectedList,actualList);
|
||||
}
|
||||
|
||||
private void assertDirOrder(ConfigSources sources, File... expectedDirOrder)
|
||||
{
|
||||
List<String> actualList = new ArrayList<>();
|
||||
for (ConfigSource source : sources)
|
||||
{
|
||||
if (source instanceof DirConfigSource)
|
||||
{
|
||||
actualList.add(((DirConfigSource)source).getDir().toString());
|
||||
}
|
||||
}
|
||||
List<String> expectedList = new ArrayList<>();
|
||||
for (File path : expectedDirOrder)
|
||||
{
|
||||
expectedList.add(path.getAbsolutePath());
|
||||
}
|
||||
ConfigurationAssert.assertOrdered("ConfigSources.dir order",expectedList,actualList);
|
||||
}
|
||||
|
||||
private void assertProperty(ConfigSources sources, String key, String expectedValue)
|
||||
{
|
||||
Prop prop = sources.getProp(key);
|
||||
Assert.assertThat("getProp('" + key + "') should not be null",prop,notNullValue());
|
||||
Assert.assertThat("getProp('" + key + "')",prop.value,is(expectedValue));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrder_BasicConfig() throws IOException
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1");
|
||||
|
||||
ConfigSources sources = new ConfigSources();
|
||||
|
||||
String[] cmdLine = new String[0];
|
||||
sources.add(new CommandLineConfigSource(cmdLine));
|
||||
sources.add(new JettyBaseConfigSource(base.toPath()));
|
||||
sources.add(new JettyHomeConfigSource(home.toPath()));
|
||||
|
||||
assertIdOrder(sources,"<command-line>","${jetty.base}","${jetty.home}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrder_With1ExtraConfig() throws IOException
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// Create common
|
||||
File common = testdir.getFile("common");
|
||||
FS.ensureEmpty(common);
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1",//
|
||||
"--extra-start-dir=" + common.getAbsolutePath());
|
||||
|
||||
ConfigSources sources = new ConfigSources();
|
||||
|
||||
String[] cmdLine = new String[0];
|
||||
sources.add(new CommandLineConfigSource(cmdLine));
|
||||
sources.add(new JettyHomeConfigSource(home.toPath()));
|
||||
sources.add(new JettyBaseConfigSource(base.toPath()));
|
||||
|
||||
assertIdOrder(sources,"<command-line>","${jetty.base}",common.getAbsolutePath(),"${jetty.home}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandLine_1Extra_FromSimpleProp() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// 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");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1");
|
||||
|
||||
ConfigSources sources = new ConfigSources();
|
||||
|
||||
// Simple command line reference to extra-start-dir via property (also on command line)
|
||||
|
||||
String[] cmdLine = new String[] {
|
||||
// property
|
||||
"my.common=" + common.getAbsolutePath(),
|
||||
// reference via property
|
||||
"--extra-start-dir=${my.common}" };
|
||||
|
||||
sources.add(new CommandLineConfigSource(cmdLine));
|
||||
sources.add(new JettyHomeConfigSource(home.toPath()));
|
||||
sources.add(new JettyBaseConfigSource(base.toPath()));
|
||||
|
||||
assertIdOrder(sources,"<command-line>","${jetty.base}","${my.common}","${jetty.home}");
|
||||
|
||||
assertDirOrder(sources,base,common,home);
|
||||
|
||||
assertProperty(sources,"jetty.host","127.0.0.1");
|
||||
assertProperty(sources,"jetty.port","8080"); // from 'common'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandLine_1Extra_FromPropPrefix() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// Create opt
|
||||
File opt = testdir.getFile("opt");
|
||||
FS.ensureEmpty(opt);
|
||||
|
||||
// Create common
|
||||
File common = new File(opt,"common");
|
||||
FS.ensureEmpty(common);
|
||||
TestEnv.makeFile(common,"start.ini","jetty.port=8080");
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1");
|
||||
|
||||
String dirRef = "${my.opt}" + File.separator + "common";
|
||||
|
||||
ConfigSources sources = new ConfigSources();
|
||||
|
||||
// Simple command line reference to extra-start-dir via property (also on command line)
|
||||
String[] cmdLine = new String[] {
|
||||
// property to 'opt' dir
|
||||
"my.opt=" + opt.getAbsolutePath(),
|
||||
// reference via property prefix
|
||||
"--extra-start-dir=" + dirRef };
|
||||
|
||||
sources.add(new CommandLineConfigSource(cmdLine));
|
||||
sources.add(new JettyHomeConfigSource(home.toPath()));
|
||||
sources.add(new JettyBaseConfigSource(base.toPath()));
|
||||
|
||||
assertIdOrder(sources,"<command-line>","${jetty.base}",dirRef,"${jetty.home}");
|
||||
|
||||
assertDirOrder(sources,base,common,home);
|
||||
|
||||
assertProperty(sources,"jetty.host","127.0.0.1");
|
||||
assertProperty(sources,"jetty.port","8080"); // from 'common'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandLine_1Extra_FromCompoundProp() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// Create opt
|
||||
File opt = testdir.getFile("opt");
|
||||
FS.ensureEmpty(opt);
|
||||
|
||||
// Create common
|
||||
File common = new File(opt,"common");
|
||||
FS.ensureEmpty(common);
|
||||
TestEnv.makeFile(common,"start.ini","jetty.port=8080");
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1");
|
||||
|
||||
String dirRef = "${my.opt}" + File.separator + "${my.dir}";
|
||||
|
||||
ConfigSources sources = new ConfigSources();
|
||||
|
||||
// Simple command line reference to extra-start-dir via property (also on command line)
|
||||
|
||||
String[] cmdLine = new String[] {
|
||||
// property to 'opt' dir
|
||||
"my.opt=" + opt.getAbsolutePath(),
|
||||
// property to commmon dir name
|
||||
"my.dir=common",
|
||||
// reference via property prefix
|
||||
"--extra-start-dir=" + dirRef };
|
||||
|
||||
sources.add(new CommandLineConfigSource(cmdLine));
|
||||
sources.add(new JettyHomeConfigSource(home.toPath()));
|
||||
sources.add(new JettyBaseConfigSource(base.toPath()));
|
||||
|
||||
assertIdOrder(sources,"<command-line>","${jetty.base}",dirRef,"${jetty.home}");
|
||||
|
||||
assertDirOrder(sources,base,common,home);
|
||||
|
||||
assertProperty(sources,"jetty.host","127.0.0.1");
|
||||
assertProperty(sources,"jetty.port","8080"); // from 'common'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefCommon() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// 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");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1",//
|
||||
"--extra-start-dir=" + common.getAbsolutePath());
|
||||
|
||||
ConfigSources sources = new ConfigSources();
|
||||
|
||||
String cmdLine[] = new String[0];
|
||||
sources.add(new CommandLineConfigSource(cmdLine));
|
||||
sources.add(new JettyHomeConfigSource(home.toPath()));
|
||||
sources.add(new JettyBaseConfigSource(base.toPath()));
|
||||
|
||||
assertIdOrder(sources,"<command-line>","${jetty.base}",common.getAbsolutePath(),"${jetty.home}");
|
||||
|
||||
assertDirOrder(sources,base,common,home);
|
||||
|
||||
assertProperty(sources,"jetty.host","127.0.0.1");
|
||||
assertProperty(sources,"jetty.port","8080"); // from 'common'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefCommonAndCorp() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// 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");
|
||||
FS.ensureEmpty(corp);
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1",//
|
||||
"--extra-start-dir=" + common.getAbsolutePath(), //
|
||||
"--extra-start-dir=" + corp.getAbsolutePath());
|
||||
|
||||
ConfigSources sources = new ConfigSources();
|
||||
|
||||
String cmdLine[] = new String[0];
|
||||
sources.add(new CommandLineConfigSource(cmdLine));
|
||||
sources.add(new JettyHomeConfigSource(home.toPath()));
|
||||
sources.add(new JettyBaseConfigSource(base.toPath()));
|
||||
|
||||
assertIdOrder(sources,"<command-line>","${jetty.base}",
|
||||
common.getAbsolutePath(),
|
||||
corp.getAbsolutePath(),
|
||||
"${jetty.home}");
|
||||
|
||||
assertDirOrder(sources,base,common,corp,home);
|
||||
|
||||
assertProperty(sources,"jetty.host","127.0.0.1");
|
||||
assertProperty(sources,"jetty.port","8080"); // from 'common'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefCommonRefCorp() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// Create corp
|
||||
File corp = testdir.getFile("corp");
|
||||
FS.ensureEmpty(corp);
|
||||
TestEnv.makeFile(corp,"start.ini", //
|
||||
"jetty.port=9090");
|
||||
|
||||
// Create common
|
||||
File common = testdir.getFile("common");
|
||||
FS.ensureEmpty(common);
|
||||
TestEnv.makeFile(common,"start.ini", //
|
||||
"--extra-start-dir=" + corp.getAbsolutePath(), //
|
||||
"jetty.port=8080");
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1",//
|
||||
"--extra-start-dir=" + common.getAbsolutePath());
|
||||
|
||||
ConfigSources sources = new ConfigSources();
|
||||
|
||||
String cmdLine[] = new String[0];
|
||||
sources.add(new CommandLineConfigSource(cmdLine));
|
||||
sources.add(new JettyHomeConfigSource(home.toPath()));
|
||||
sources.add(new JettyBaseConfigSource(base.toPath()));
|
||||
|
||||
assertIdOrder(sources,"<command-line>","${jetty.base}",
|
||||
common.getAbsolutePath(),
|
||||
corp.getAbsolutePath(),
|
||||
"${jetty.home}");
|
||||
|
||||
assertDirOrder(sources,base,common,corp,home);
|
||||
|
||||
assertProperty(sources,"jetty.host","127.0.0.1");
|
||||
assertProperty(sources,"jetty.port","8080"); // from 'common'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefCommonRefCorp_FromSimpleProps() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// Create corp
|
||||
File corp = testdir.getFile("corp");
|
||||
FS.ensureEmpty(corp);
|
||||
TestEnv.makeFile(corp,"start.ini", //
|
||||
"jetty.port=9090");
|
||||
|
||||
// Create common
|
||||
File common = testdir.getFile("common");
|
||||
FS.ensureEmpty(common);
|
||||
TestEnv.makeFile(common,"start.ini", //
|
||||
"my.corp=" + corp.getAbsolutePath(), //
|
||||
"--extra-start-dir=${my.corp}", //
|
||||
"jetty.port=8080");
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1",//
|
||||
"my.common="+common.getAbsolutePath(), //
|
||||
"--extra-start-dir=${my.common}");
|
||||
|
||||
ConfigSources sources = new ConfigSources();
|
||||
|
||||
String cmdLine[] = new String[0];
|
||||
sources.add(new CommandLineConfigSource(cmdLine));
|
||||
sources.add(new JettyHomeConfigSource(home.toPath()));
|
||||
sources.add(new JettyBaseConfigSource(base.toPath()));
|
||||
|
||||
assertIdOrder(sources,"<command-line>",
|
||||
"${jetty.base}",
|
||||
"${my.common}",
|
||||
"${my.corp}",
|
||||
"${jetty.home}");
|
||||
|
||||
assertDirOrder(sources,base,common,corp,home);
|
||||
|
||||
assertProperty(sources,"jetty.host","127.0.0.1");
|
||||
assertProperty(sources,"jetty.port","8080"); // from 'common'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefCommonRefCorp_CmdLineRef() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// Create devops
|
||||
File devops = testdir.getFile("devops");
|
||||
FS.ensureEmpty(devops);
|
||||
TestEnv.makeFile(devops,"start.ini", //
|
||||
"--module=logging", //
|
||||
"jetty.port=2222");
|
||||
|
||||
// Create corp
|
||||
File corp = testdir.getFile("corp");
|
||||
FS.ensureEmpty(corp);
|
||||
TestEnv.makeFile(corp,"start.ini", //
|
||||
"jetty.port=9090");
|
||||
|
||||
// Create common
|
||||
File common = testdir.getFile("common");
|
||||
FS.ensureEmpty(common);
|
||||
TestEnv.makeFile(common,"start.ini", //
|
||||
"--extra-start-dir=" + corp.getAbsolutePath(), //
|
||||
"jetty.port=8080");
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1",//
|
||||
"--extra-start-dir=" + common.getAbsolutePath());
|
||||
|
||||
ConfigSources sources = new ConfigSources();
|
||||
|
||||
String cmdLine[] = new String[]{
|
||||
// command line provided extra-start-dir ref
|
||||
"--extra-start-dir=" + devops.getAbsolutePath()};
|
||||
sources.add(new CommandLineConfigSource(cmdLine));
|
||||
sources.add(new JettyHomeConfigSource(home.toPath()));
|
||||
sources.add(new JettyBaseConfigSource(base.toPath()));
|
||||
|
||||
assertIdOrder(sources,"<command-line>",
|
||||
"${jetty.base}",
|
||||
devops.getAbsolutePath(),
|
||||
common.getAbsolutePath(),
|
||||
corp.getAbsolutePath(),
|
||||
"${jetty.home}");
|
||||
|
||||
assertDirOrder(sources,base,devops,common,corp,home);
|
||||
|
||||
assertProperty(sources,"jetty.host","127.0.0.1");
|
||||
assertProperty(sources,"jetty.port","2222"); // from 'common'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefCommonRefCorp_CmdLineProp() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// Create corp
|
||||
File corp = testdir.getFile("corp");
|
||||
FS.ensureEmpty(corp);
|
||||
TestEnv.makeFile(corp,"start.ini", //
|
||||
"jetty.port=9090");
|
||||
|
||||
// Create common
|
||||
File common = testdir.getFile("common");
|
||||
FS.ensureEmpty(common);
|
||||
TestEnv.makeFile(common,"start.ini", //
|
||||
"--extra-start-dir=" + corp.getAbsolutePath(), //
|
||||
"jetty.port=8080");
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1",//
|
||||
"--extra-start-dir=" + common.getAbsolutePath());
|
||||
|
||||
ConfigSources sources = new ConfigSources();
|
||||
|
||||
String cmdLine[] = new String[]{
|
||||
// command line property should override all others
|
||||
"jetty.port=7070"
|
||||
};
|
||||
sources.add(new CommandLineConfigSource(cmdLine));
|
||||
sources.add(new JettyHomeConfigSource(home.toPath()));
|
||||
sources.add(new JettyBaseConfigSource(base.toPath()));
|
||||
|
||||
assertIdOrder(sources,"<command-line>","${jetty.base}",
|
||||
common.getAbsolutePath(),
|
||||
corp.getAbsolutePath(),
|
||||
"${jetty.home}");
|
||||
|
||||
assertDirOrder(sources,base,common,corp,home);
|
||||
|
||||
assertProperty(sources,"jetty.host","127.0.0.1");
|
||||
assertProperty(sources,"jetty.port","7070"); // from <command-line>
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadDoubleRef() throws Exception
|
||||
{
|
||||
// Create home
|
||||
File home = testdir.getFile("home");
|
||||
FS.ensureEmpty(home);
|
||||
TestEnv.copyTestDir("usecases/home",home);
|
||||
|
||||
// Create common
|
||||
File common = testdir.getFile("common");
|
||||
FS.ensureEmpty(common);
|
||||
|
||||
// Create corp
|
||||
File corp = testdir.getFile("corp");
|
||||
FS.ensureEmpty(corp);
|
||||
TestEnv.makeFile(corp,"start.ini",
|
||||
// standard property
|
||||
"jetty.port=9090",
|
||||
// INTENTIONAL BAD Reference (duplicate)
|
||||
"--extra-start-dir=" + common.getAbsolutePath());
|
||||
|
||||
// Populate common
|
||||
TestEnv.makeFile(common,"start.ini",
|
||||
// standard property
|
||||
"jetty.port=8080",
|
||||
// reference to corp
|
||||
"--extra-start-dir=" + corp.getAbsolutePath());
|
||||
|
||||
// Create base
|
||||
File base = testdir.getFile("base");
|
||||
FS.ensureEmpty(base);
|
||||
TestEnv.makeFile(base,"start.ini", //
|
||||
"jetty.host=127.0.0.1",//
|
||||
"--extra-start-dir=" + common.getAbsolutePath());
|
||||
|
||||
ConfigSources sources = new ConfigSources();
|
||||
|
||||
try
|
||||
{
|
||||
String cmdLine[] = new String[0];
|
||||
sources.add(new CommandLineConfigSource(cmdLine));
|
||||
sources.add(new JettyHomeConfigSource(home.toPath()));
|
||||
sources.add(new JettyBaseConfigSource(base.toPath()));
|
||||
|
||||
Assert.fail("Should have thrown a UsageException");
|
||||
}
|
||||
catch (UsageException e)
|
||||
{
|
||||
Assert.assertThat("UsageException",e.getMessage(),containsString("Duplicate"));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
--module=logging
|
|
@ -0,0 +1,18 @@
|
|||
# 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
|
||||
|
||||
# The LIBs we expect (order is irrelevant)
|
||||
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-schemas-3.1.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/servlet-api-3.1.jar
|
||||
|
||||
# The Properties we expect (order is irrelevant)
|
||||
PROP|jetty.port=9090
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
--extra-start-dir=${start.basedir}/../../extra-start-dirs/logging
|
||||
--module=server,http,jmx
|
||||
|
||||
jetty.port=9090
|
|
@ -358,15 +358,9 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Inc
|
|||
break;
|
||||
case CLOSED:
|
||||
IOState ioState = this.connection.getIOState();
|
||||
// The session only cares about abnormal close, as we need to notify
|
||||
// the endpoint of this close scenario.
|
||||
if (ioState.wasAbnormalClose())
|
||||
{
|
||||
CloseInfo close = ioState.getCloseInfo();
|
||||
LOG.debug("Detected abnormal close: {}", close);
|
||||
// notify local endpoint
|
||||
notifyClose(close.getStatusCode(), close.getReason());
|
||||
}
|
||||
CloseInfo close = ioState.getCloseInfo();
|
||||
// confirmed close of local endpoint
|
||||
notifyClose(close.getStatusCode(), close.getReason());
|
||||
break;
|
||||
case OPEN:
|
||||
// notify session listeners
|
||||
|
|
|
@ -121,9 +121,6 @@ public abstract class AbstractEventDriver implements IncomingFrames, EventDriver
|
|||
CloseFrame closeframe = (CloseFrame)frame;
|
||||
CloseInfo close = new CloseInfo(closeframe,validate);
|
||||
|
||||
// notify user websocket pojo
|
||||
onClose(close);
|
||||
|
||||
// process handshake
|
||||
session.getConnection().getIOState().onCloseRemote(close);
|
||||
|
||||
|
|
|
@ -114,16 +114,22 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
|||
|
||||
public class OnDisconnectCallback implements WriteCallback
|
||||
{
|
||||
private final boolean outputOnly;
|
||||
|
||||
public OnDisconnectCallback(boolean outputOnly) {
|
||||
this.outputOnly = outputOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeFailed(Throwable x)
|
||||
{
|
||||
disconnect();
|
||||
disconnect(outputOnly);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSuccess()
|
||||
{
|
||||
disconnect();
|
||||
disconnect(outputOnly);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -379,18 +385,18 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
|||
{
|
||||
// Fire out a close frame, indicating abnormal shutdown, then disconnect
|
||||
CloseInfo abnormal = new CloseInfo(StatusCode.SHUTDOWN,"Abnormal Close - " + ioState.getCloseInfo().getReason());
|
||||
outgoingFrame(abnormal.asFrame(),new OnDisconnectCallback(), BatchMode.OFF);
|
||||
outgoingFrame(abnormal.asFrame(),new OnDisconnectCallback(false), BatchMode.OFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Just disconnect
|
||||
this.disconnect();
|
||||
this.disconnect(false);
|
||||
}
|
||||
break;
|
||||
case CLOSING:
|
||||
CloseInfo close = ioState.getCloseInfo();
|
||||
// append close frame
|
||||
outgoingFrame(close.asFrame(),new OnDisconnectCallback(), BatchMode.OFF);
|
||||
// reply to close handshake from remote
|
||||
outgoingFrame(close.asFrame(),new OnDisconnectCallback(true), BatchMode.OFF);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue