Issue #515 Alternate start modules

Added more test usecases
This commit is contained in:
Greg Wilkins 2016-04-17 23:16:33 +10:00
parent 6829bec09e
commit 62563beee7
23 changed files with 165 additions and 27 deletions

View File

@ -66,29 +66,31 @@ public class Main
public static void main(String[] args)
{
boolean test=false;
try
{
Main main = new Main();
StartArgs startArgs = main.processCommandLine(args);
test=startArgs.isTestingModeEnabled();
main.start(startArgs);
}
catch (UsageException e)
{
System.err.println(e.getMessage());
usageExit(e.getCause(),e.getExitCode());
usageExit(e.getCause(),e.getExitCode(),test);
}
catch (Throwable e)
{
usageExit(e,UsageException.ERR_UNKNOWN);
usageExit(e,UsageException.ERR_UNKNOWN,test);
}
}
static void usageExit(int exit)
{
usageExit(null,exit);
usageExit(null,exit, false);
}
static void usageExit(Throwable t, int exit)
static void usageExit(Throwable t, int exit, boolean test)
{
if (t != null)
{
@ -97,7 +99,11 @@ public class Main
System.err.println();
System.err.println("Usage: java -jar start.jar [options] [properties] [configs]");
System.err.println(" java -jar start.jar --help # for more information");
System.exit(exit);
if (test)
System.err.println("EXIT: "+exit);
else
System.exit(exit);
}
private BaseHome baseHome;
@ -456,7 +462,7 @@ public class Main
}
catch (Exception e)
{
usageExit(e,ERR_INVOKE_MAIN);
usageExit(e,ERR_INVOKE_MAIN,startupArgs.isTestingModeEnabled());
}
}
@ -543,11 +549,11 @@ public class Main
}
catch (ConnectException e)
{
usageExit(e,ERR_NOT_STOPPED);
usageExit(e,ERR_NOT_STOPPED,startupArgs.isTestingModeEnabled());
}
catch (Exception e)
{
usageExit(e,ERR_UNKNOWN);
usageExit(e,ERR_UNKNOWN,startupArgs.isTestingModeEnabled());
}
}
@ -605,11 +611,11 @@ public class Main
catch (UsageException e)
{
System.err.println(e.getMessage());
usageExit(e.getCause(),e.getExitCode());
usageExit(e.getCause(),e.getExitCode(),startupArgs.isTestingModeEnabled());
}
catch (Throwable e)
{
usageExit(e,UsageException.ERR_UNKNOWN);
usageExit(e,UsageException.ERR_UNKNOWN,startupArgs.isTestingModeEnabled());
}
}

View File

@ -318,9 +318,11 @@ public class Module
case "DESCRIPTION":
_description.add(line);
break;
case "DEPEND":
case "DEPEND":
case "DEPENDS":
_depends.add(line);
break;
case "FILE":
case "FILES":
_files.add(line);
break;
@ -332,13 +334,17 @@ public class Module
_iniTemplate.add(line);
break;
case "LIB":
case "LIBS":
_libs.add(line);
break;
case "LICENSE":
case "LICENSES":
case "LICENCE":
case "LICENCES":
_license.add(line);
break;
case "NAME":
case "PROVIDE":
case "PROVIDES":
_provides.add(line);
break;

View File

@ -29,6 +29,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.regex.Pattern;
import java.util.stream.Stream;
/**
* Simple common abstraction for Text files, that consist of a series of lines.
@ -109,6 +110,11 @@ public class TextFile implements Iterable<String>
{
}
public Stream<String> stream()
{
return lines.stream();
}
@Override
public Iterator<String> iterator()
{

View File

@ -35,6 +35,8 @@ import java.util.Set;
import org.eclipse.jetty.start.Props.Prop;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.hamcrest.Matchers;
import org.hamcrest.core.StringStartsWith;
import org.junit.Assert;
public class ConfigurationAssert
@ -166,6 +168,11 @@ public class ConfigurationAssert
}
}
assertContainsUnordered("Files/Dirs",expectedFiles,actualFiles);
textFile.stream()
.filter(s->s.startsWith("EXISTS|"))
.map(s->baseHome.getPath(s.substring(7)).toFile())
.forEach(f->Assert.assertTrue(f+" exists",f.exists()));
}
private static String shorten(BaseHome baseHome, Path path, Path testResourcesDir)

View File

@ -64,7 +64,7 @@ public class TestUseCases
{
String caseName=assertTxt.getName().replace(".assert.txt","");
String baseName=caseName.split("\\.")[0];
ret.add(new Object[] {caseName,baseName, assertTxt, lines(new File(usecases,caseName+".cmdline.txt"))});
ret.add(new Object[] {caseName,baseName, assertTxt, lines(new File(usecases,caseName+".prepare.txt")),lines(new File(usecases,caseName+".cmdline.txt"))});
}
return ret;
@ -87,30 +87,49 @@ public class TestUseCases
public File assertFile;
@Parameter(3)
public String[] prepare;
@Parameter(4)
public String[] commandLineArgs;
@Test
public void testUseCase() throws Exception
{
Path homeDir = MavenTestingUtils.getTestResourceDir("dist-home").toPath().toRealPath();
Path baseDir = MavenTestingUtils.getTestResourceDir("usecases/" + baseName).toPath().toRealPath();
Main main = new Main();
List<String> cmdLine = new ArrayList<>();
cmdLine.add("jetty.home=" + homeDir.toString());
cmdLine.add("jetty.base=" + baseDir.toString());
// cmdLine.add("--debug");
if (commandLineArgs != null)
{
for (String arg : commandLineArgs)
{
cmdLine.add(arg);
}
}
Path baseSrcDir = MavenTestingUtils.getTestResourceDir("usecases/" + baseName).toPath().toRealPath();
Path baseDir = MavenTestingUtils.getTargetTestingPath(caseName);
if (baseDir.toFile().exists())
org.eclipse.jetty.toolchain.test.FS.cleanDirectory(baseDir);
else
baseDir.toFile().mkdirs();
org.eclipse.jetty.toolchain.test.IO.copyDir(baseSrcDir.toFile(),baseDir.toFile());
System.setProperty("jetty.home",homeDir.toString());
System.setProperty("jetty.base",baseDir.toString());
try
{
if (prepare != null && prepare.length>0)
{
Main main = new Main();
List<String> cmdLine = new ArrayList<>();
cmdLine.add("--testing-mode");
for (String arg : prepare)
cmdLine.add(arg);
main.start(main.processCommandLine(cmdLine));
}
Main main = new Main();
List<String> cmdLine = new ArrayList<>();
// cmdLine.add("--debug");
if (commandLineArgs != null)
{
for (String arg : commandLineArgs)
cmdLine.add(arg);
}
StartArgs args = main.processCommandLine(cmdLine);
BaseHome baseHome = main.getBaseHome();
ConfigurationAssert.assertConfiguration(baseHome,args,assertFile);

View File

@ -0,0 +1,18 @@
## The XMLs we expect (order is important)
XML|${jetty.home}/etc/base.xml
XML|${jetty.home}/etc/main.xml
XML|etc/optional.xml
# The LIBs we expect (order is irrelevant)
LIB|${jetty.home}/lib/base.jar
LIB|${jetty.home}/lib/main.jar
LIB|${jetty.home}/lib/other.jar
LIB|${jetty.home}/lib/optional.jar
# The Properties we expect (order is irrelevant)
PROP|main.prop=value0
PROP|optional.prop=value0
# Files / Directories to create
FILE|maindir/
EXISTS|start.d/optional.ini

View File

@ -0,0 +1 @@
--add-to-startd=optional

View File

@ -0,0 +1 @@
EX|UsageException

View File

@ -0,0 +1 @@
--add-to-startd=unknown

View File

@ -0,0 +1,18 @@
## The XMLs we expect (order is important)
XML|${jetty.home}/etc/base.xml
XML|${jetty.home}/etc/main.xml
XML|etc/t.xml
XML|etc/d.xml
# The LIBs we expect (order is irrelevant)
LIB|${jetty.home}/lib/base.jar
LIB|${jetty.home}/lib/main.jar
LIB|${jetty.home}/lib/other.jar
# The Properties we expect (order is irrelevant)
PROP|main.prop=value0
PROP|direct.option=direct
# Files / Directories to create
FILE|maindir/
EXISTS|start.d/direct.ini

View File

@ -0,0 +1 @@
--add-to-startd=direct

View File

@ -0,0 +1,8 @@
[xml]
etc/d.xml
[depend]
transient
[ini-template]
direct.option=direct

View File

@ -0,0 +1,5 @@
[xml]
etc/t.xml
[optional]
main

View File

@ -0,0 +1,2 @@
--module=main

View File

@ -0,0 +1,20 @@
## The XMLs we expect (order is important)
XML|${jetty.home}/etc/base.xml
XML|${jetty.home}/etc/main.xml
XML|etc/t.xml
XML|etc/d.xml
# The LIBs we expect (order is irrelevant)
LIB|${jetty.home}/lib/base.jar
LIB|${jetty.home}/lib/main.jar
LIB|${jetty.home}/lib/other.jar
# The Properties we expect (order is irrelevant)
PROP|main.prop=value0
PROP|transient.option=transient
PROP|direct.option=direct
# Files / Directories to create
FILE|maindir/
EXISTS|start.d/direct.ini
EXISTS|start.d/transient.ini

View File

@ -0,0 +1 @@
--add-to-startd=direct

View File

@ -0,0 +1,8 @@
[xml]
etc/d.xml
[depend]
transient
[ini-template]
direct.option=direct

View File

@ -0,0 +1,8 @@
[xml]
etc/t.xml
[optional]
main
[ini-template]
transient.option=transient

View File

@ -0,0 +1,2 @@
--module=main