432321 - jetty-start / Allow defining extra start directories for common configurations

+ Identified test cases for extra-start-dir logic
+ Working on layered ConfigSource approach to handling extra-start-dir
This commit is contained in:
Joakim Erdfelt 2014-04-09 09:51:20 -07:00
parent a9c01d3607
commit 5ecf564dfa
12 changed files with 892 additions and 14 deletions

View File

@ -0,0 +1,49 @@
//
// ========================================================================
// 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.util.Arrays;
import java.util.List;
/**
* Configuration Source representing the Command Line arguments.
*/
public class CommandLineConfigSource implements ConfigSource
{
public static final String CMD_LINE_SOURCE = "<command-line>";
private final List<String> args;
public CommandLineConfigSource(String rawargs[])
{
args = Arrays.asList(rawargs);
}
@Override
public String getId()
{
return CMD_LINE_SOURCE;
}
@Override
public List<String> getArgs()
{
return args;
}
}

View File

@ -0,0 +1,43 @@
//
// ========================================================================
// 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.util.List;
/**
* 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 list of Arguments for this ConfigSource
*
* @return the list of Arguments for this ConfigSource
*/
public List<String> getArgs();
}

View File

@ -0,0 +1,111 @@
//
// ========================================================================
// 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.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.List;
/**
* 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 final String id;
private final Path dir;
private final List<String> args;
/**
* Create DirConfigSource with specified identifier and directory.
*
* @param id
* the identifier for this {@link ConfigSource}
* @param dir
* the directory for this {@link ConfigSource}
* @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, boolean canHaveArgs) throws IOException
{
this.id = id;
this.dir = dir;
this.args = new ArrayList<>();
if (canHaveArgs)
{
Path iniFile = dir.resolve("start.ini");
if (FS.canReadFile(iniFile))
{
StartIni ini = new StartIni(iniFile);
args.addAll(ini.getArgs());
}
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);
}
};
for (Path diniFile : Files.newDirectoryStream(startDdir,filter))
{
if (FS.canReadFile(diniFile))
{
StartIni ini = new StartIni(diniFile);
args.addAll(ini.getArgs());
}
}
}
}
}
public Path getDir()
{
return dir;
}
@Override
public String getId()
{
return id;
}
@Override
public List<String> getArgs()
{
return args;
}
}

View File

@ -175,6 +175,12 @@ public class FS
{
return (path.exists() && path.isFile() && path.canRead());
}
public static boolean canReadFile(Path path)
{
LinkOption lopts[] = new LinkOption[0];
return Files.exists(path,lopts) && Files.isRegularFile(path,lopts) && Files.isReadable(path);
}
public static void close(Closeable c)
{

View File

@ -29,6 +29,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -87,6 +88,9 @@ public class StartArgs
/** List of all xml references found directly on command line or start.ini */
private List<String> xmlRefs = new ArrayList<>();
/** List of extra Start Directories referenced */
private LinkedList<String> extraStartRefs = new LinkedList<>();
private Props properties = new Props();
private Set<String> systemPropertyKeys = new HashSet<>();
private List<String> rawLibs = new ArrayList<>();
@ -410,6 +414,11 @@ public class StartArgs
{
return this.commandLine;
}
public LinkedList<String> getExtraStartRefs()
{
return extraStartRefs;
}
public List<FileArg> getFiles()
{
@ -646,18 +655,19 @@ public class StartArgs
return version;
}
public void parse(BaseHome baseHome, TextFile file)
public void parse(BaseHome baseHome, StartIni ini)
{
String source;
try
{
source = baseHome.toShortForm(file.getFile());
source = baseHome.toShortForm(ini.getFile());
}
catch (Exception e)
{
throw new UsageException(ERR_BAD_ARG,"Bad file: %s",file);
throw new UsageException(ERR_BAD_ARG,"Bad file: %s",ini);
}
for (String line : file)
for (String line : ini)
{
parse(line,source);
}
@ -751,14 +761,22 @@ public class StartArgs
return;
}
// Enable forked execution of Jetty server
if ("--exec".equals(arg))
{
exec = true;
return;
}
// Arbitrary Libraries
// Add extra start dir
if (arg.startsWith("--extra-start-dir="))
{
String dirRef = getValue(arg);
extraStartRefs.add(dirRef);
return;
}
// Arbitrary Libraries
if (arg.startsWith("--lib="))
{
String cp = getValue(arg);
@ -782,7 +800,8 @@ 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))
{
@ -794,7 +813,8 @@ public class StartArgs
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))
{
@ -806,6 +826,7 @@ public class StartArgs
return;
}
// Enable a module
if (arg.startsWith("--module="))
{
for (String moduleName : getValues(arg))
@ -822,6 +843,7 @@ public class StartArgs
return;
}
// Create graphviz output of module graph
if (arg.startsWith("--write-module-graph="))
{
this.moduleGraphFilename = getValue(arg);

View File

@ -19,21 +19,23 @@
package org.eclipse.jetty.start;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
/**
* Simple Start .INI handler
*/
public class StartIni extends TextFile
public class StartIni extends TextFile implements ConfigSource
{
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 +49,47 @@ 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;
}
@Override
public String getId()
{
// TODO Auto-generated method stub
return null;
}
@Override
public List<String> getArgs()
{
// TODO Auto-generated method stub
return null;
}
}

View File

@ -206,7 +206,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();

View File

@ -0,0 +1,580 @@
//
// ========================================================================
// 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.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jetty.start.Props.Prop;
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;
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)
{
List<String> actualOrder = new ArrayList<>();
actualOrder.add("${jetty.base}");
List<String> startRefs = args.getExtraStartRefs();
if (startRefs.size() > 0)
{
actualOrder.addAll(startRefs);
}
actualOrder.add("${jetty.home}");
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 void copyTestDir(String testResourceDir, File destDir) throws IOException
{
FS.ensureDirExists(destDir);
File srcDir = MavenTestingUtils.getTestResourceDir(testResourceDir);
IO.copyDir(srcDir,destDir);
}
private 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);
}
}
}
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);
copyTestDir("usecases/home",home);
// Create base
File base = testdir.getFile("base");
FS.ensureEmpty(base);
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);
copyTestDir("usecases/home",home);
// Create common
File common = testdir.getFile("common");
FS.ensureEmpty(common);
makeFile(common,"start.ini","jetty.port=8080");
// Create base
File base = testdir.getFile("base");
FS.ensureEmpty(base);
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);
copyTestDir("usecases/home",home);
// Create common
File common = testdir.getFile("common");
FS.ensureEmpty(common);
makeFile(common,"start.ini","jetty.port=8080");
// Create base
File base = testdir.getFile("base");
FS.ensureEmpty(base);
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);
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);
makeFile(common,"start.ini","jetty.port=8080");
// Create base
File base = testdir.getFile("base");
FS.ensureEmpty(base);
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);
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);
makeFile(common,"start.ini","jetty.port=8080");
// Create base
File base = testdir.getFile("base");
FS.ensureEmpty(base);
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);
copyTestDir("usecases/home",home);
// Create common
File common = testdir.getFile("common");
FS.ensureEmpty(common);
// Create base
File base = testdir.getFile("base");
FS.ensureEmpty(base);
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);
copyTestDir("usecases/home",home);
// Create common
File common = testdir.getFile("common");
FS.ensureEmpty(common);
// Create corp
File corp = testdir.getFile("corp");
FS.ensureEmpty(corp);
// Create base
File base = testdir.getFile("base");
FS.ensureEmpty(base);
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);
copyTestDir("usecases/home",home);
// Create corp
File corp = testdir.getFile("corp");
FS.ensureEmpty(corp);
makeFile(corp,"start.ini", //
"jetty.port=9090");
// Create common
File common = testdir.getFile("common");
FS.ensureEmpty(common);
makeFile(common,"start.ini", //
"--extra-start-dir=" + corp.getAbsolutePath(), //
"jetty.port=8080");
// Create base
File base = testdir.getFile("base");
FS.ensureEmpty(base);
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);
copyTestDir("usecases/home",home);
// Create corp
File corp = testdir.getFile("corp");
FS.ensureEmpty(corp);
makeFile(corp,"start.ini", //
"jetty.port=9090");
// Create common
File common = testdir.getFile("common");
FS.ensureEmpty(common);
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);
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);
copyTestDir("usecases/home",home);
// Create devops
File devops = testdir.getFile("devops");
FS.ensureEmpty(devops);
makeFile(devops,"start.ini", //
"--module=logging", //
"jetty.port=2222");
// Create corp
File corp = testdir.getFile("corp");
FS.ensureEmpty(corp);
makeFile(corp,"start.ini", //
"jetty.port=9090");
// Create common
File common = testdir.getFile("common");
FS.ensureEmpty(common);
makeFile(common,"start.ini", //
"--extra-start-dir=" + corp.getAbsolutePath(), //
"jetty.port=8080");
// Create base
File base = testdir.getFile("base");
FS.ensureEmpty(base);
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);
copyTestDir("usecases/home",home);
// Create corp
File corp = testdir.getFile("corp");
FS.ensureEmpty(corp);
makeFile(corp,"start.ini", //
"jetty.port=9090");
// Create common
File common = testdir.getFile("common");
FS.ensureEmpty(common);
makeFile(common,"start.ini", //
"--extra-start-dir=" + corp.getAbsolutePath(), //
"jetty.port=8080");
// Create base
File base = testdir.getFile("base");
FS.ensureEmpty(base);
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);
copyTestDir("usecases/home",home);
// Create common
File common = testdir.getFile("common");
FS.ensureEmpty(common);
// Create corp
File corp = testdir.getFile("corp");
FS.ensureEmpty(corp);
makeFile(corp,"start.ini",
// standard property
"jetty.port=9090",
// INTENTIONAL BAD Reference (duplicate)
"--extra-start-dir=" + common.getAbsolutePath());
// Populate common
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);
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"));
}
}
}

View File

@ -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

View File

@ -0,0 +1 @@
--module=logging

View File

@ -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

View File

@ -0,0 +1,5 @@
--extra-start-dir=${start.basedir}/../../extra-start-dirs/logging
--module=server,http,jmx
jetty.port=9090