From 62563beee7ab57f395602c56808202649a3e0e01 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Sun, 17 Apr 2016 23:16:33 +1000 Subject: [PATCH] Issue #515 Alternate start modules Added more test usecases --- .../java/org/eclipse/jetty/start/Main.java | 26 ++++++---- .../java/org/eclipse/jetty/start/Module.java | 8 ++- .../org/eclipse/jetty/start/TextFile.java | 6 +++ .../jetty/start/ConfigurationAssert.java | 7 +++ .../org/eclipse/jetty/start/TestUseCases.java | 51 +++++++++++++------ .../usecases/barebones.addToStartd.assert.txt | 18 +++++++ .../barebones.addToStartd.prepare.txt | 1 + .../usecases/barebones.addUnknown.assert.txt | 1 + .../usecases/barebones.addUnknown.prepare.txt | 1 + .../transientWithIniTemplate.assert.txt | 18 +++++++ .../transientWithIniTemplate.prepare.txt | 1 + .../transientWithIniTemplate/etc/d.xml | 0 .../transientWithIniTemplate/etc/t.xml | 0 .../modules/direct.mod | 8 +++ .../modules/transient.mod | 5 ++ .../transientWithIniTemplate/start.ini | 2 + .../transientWithoutIniTemplate.assert.txt | 20 ++++++++ .../transientWithoutIniTemplate.prepare.txt | 1 + .../transientWithoutIniTemplate/etc/d.xml | 0 .../transientWithoutIniTemplate/etc/t.xml | 0 .../modules/direct.mod | 8 +++ .../modules/transient.mod | 8 +++ .../transientWithoutIniTemplate/start.ini | 2 + 23 files changed, 165 insertions(+), 27 deletions(-) create mode 100644 jetty-start/src/test/resources/usecases/barebones.addToStartd.assert.txt create mode 100644 jetty-start/src/test/resources/usecases/barebones.addToStartd.prepare.txt create mode 100644 jetty-start/src/test/resources/usecases/barebones.addUnknown.assert.txt create mode 100644 jetty-start/src/test/resources/usecases/barebones.addUnknown.prepare.txt create mode 100644 jetty-start/src/test/resources/usecases/transientWithIniTemplate.assert.txt create mode 100644 jetty-start/src/test/resources/usecases/transientWithIniTemplate.prepare.txt create mode 100644 jetty-start/src/test/resources/usecases/transientWithIniTemplate/etc/d.xml create mode 100644 jetty-start/src/test/resources/usecases/transientWithIniTemplate/etc/t.xml create mode 100644 jetty-start/src/test/resources/usecases/transientWithIniTemplate/modules/direct.mod create mode 100644 jetty-start/src/test/resources/usecases/transientWithIniTemplate/modules/transient.mod create mode 100644 jetty-start/src/test/resources/usecases/transientWithIniTemplate/start.ini create mode 100644 jetty-start/src/test/resources/usecases/transientWithoutIniTemplate.assert.txt create mode 100644 jetty-start/src/test/resources/usecases/transientWithoutIniTemplate.prepare.txt create mode 100644 jetty-start/src/test/resources/usecases/transientWithoutIniTemplate/etc/d.xml create mode 100644 jetty-start/src/test/resources/usecases/transientWithoutIniTemplate/etc/t.xml create mode 100644 jetty-start/src/test/resources/usecases/transientWithoutIniTemplate/modules/direct.mod create mode 100644 jetty-start/src/test/resources/usecases/transientWithoutIniTemplate/modules/transient.mod create mode 100644 jetty-start/src/test/resources/usecases/transientWithoutIniTemplate/start.ini diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index 23897bb6b17..78c68d0417d 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -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()); } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java index c8713cbdf1d..20e89f1c7d7 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java @@ -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; diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java b/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java index 5443ec944e5..5944f998377 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java @@ -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 { } + public Stream stream() + { + return lines.stream(); + } + @Override public Iterator iterator() { diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java b/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java index af74ea259a8..655e2c17b99 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java @@ -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) diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java b/jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java index e050113f118..08a5f4e11c8 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java @@ -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 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 cmdLine = new ArrayList<>(); + cmdLine.add("--testing-mode"); + for (String arg : prepare) + cmdLine.add(arg); + main.start(main.processCommandLine(cmdLine)); + } + + Main main = new Main(); + List 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); diff --git a/jetty-start/src/test/resources/usecases/barebones.addToStartd.assert.txt b/jetty-start/src/test/resources/usecases/barebones.addToStartd.assert.txt new file mode 100644 index 00000000000..e5ec155bcea --- /dev/null +++ b/jetty-start/src/test/resources/usecases/barebones.addToStartd.assert.txt @@ -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 diff --git a/jetty-start/src/test/resources/usecases/barebones.addToStartd.prepare.txt b/jetty-start/src/test/resources/usecases/barebones.addToStartd.prepare.txt new file mode 100644 index 00000000000..ba1e8a118f1 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/barebones.addToStartd.prepare.txt @@ -0,0 +1 @@ +--add-to-startd=optional diff --git a/jetty-start/src/test/resources/usecases/barebones.addUnknown.assert.txt b/jetty-start/src/test/resources/usecases/barebones.addUnknown.assert.txt new file mode 100644 index 00000000000..273cda74390 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/barebones.addUnknown.assert.txt @@ -0,0 +1 @@ +EX|UsageException diff --git a/jetty-start/src/test/resources/usecases/barebones.addUnknown.prepare.txt b/jetty-start/src/test/resources/usecases/barebones.addUnknown.prepare.txt new file mode 100644 index 00000000000..2c371fd1e0b --- /dev/null +++ b/jetty-start/src/test/resources/usecases/barebones.addUnknown.prepare.txt @@ -0,0 +1 @@ +--add-to-startd=unknown diff --git a/jetty-start/src/test/resources/usecases/transientWithIniTemplate.assert.txt b/jetty-start/src/test/resources/usecases/transientWithIniTemplate.assert.txt new file mode 100644 index 00000000000..35c873e8cad --- /dev/null +++ b/jetty-start/src/test/resources/usecases/transientWithIniTemplate.assert.txt @@ -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 diff --git a/jetty-start/src/test/resources/usecases/transientWithIniTemplate.prepare.txt b/jetty-start/src/test/resources/usecases/transientWithIniTemplate.prepare.txt new file mode 100644 index 00000000000..a5522eb6350 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/transientWithIniTemplate.prepare.txt @@ -0,0 +1 @@ +--add-to-startd=direct diff --git a/jetty-start/src/test/resources/usecases/transientWithIniTemplate/etc/d.xml b/jetty-start/src/test/resources/usecases/transientWithIniTemplate/etc/d.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/transientWithIniTemplate/etc/t.xml b/jetty-start/src/test/resources/usecases/transientWithIniTemplate/etc/t.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/transientWithIniTemplate/modules/direct.mod b/jetty-start/src/test/resources/usecases/transientWithIniTemplate/modules/direct.mod new file mode 100644 index 00000000000..7bd97a0bde2 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/transientWithIniTemplate/modules/direct.mod @@ -0,0 +1,8 @@ +[xml] +etc/d.xml + +[depend] +transient + +[ini-template] +direct.option=direct diff --git a/jetty-start/src/test/resources/usecases/transientWithIniTemplate/modules/transient.mod b/jetty-start/src/test/resources/usecases/transientWithIniTemplate/modules/transient.mod new file mode 100644 index 00000000000..05fb78407ea --- /dev/null +++ b/jetty-start/src/test/resources/usecases/transientWithIniTemplate/modules/transient.mod @@ -0,0 +1,5 @@ +[xml] +etc/t.xml + +[optional] +main diff --git a/jetty-start/src/test/resources/usecases/transientWithIniTemplate/start.ini b/jetty-start/src/test/resources/usecases/transientWithIniTemplate/start.ini new file mode 100644 index 00000000000..dbfd730d55d --- /dev/null +++ b/jetty-start/src/test/resources/usecases/transientWithIniTemplate/start.ini @@ -0,0 +1,2 @@ +--module=main + diff --git a/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate.assert.txt b/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate.assert.txt new file mode 100644 index 00000000000..2afebfbb556 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate.assert.txt @@ -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 diff --git a/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate.prepare.txt b/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate.prepare.txt new file mode 100644 index 00000000000..a5522eb6350 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate.prepare.txt @@ -0,0 +1 @@ +--add-to-startd=direct diff --git a/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate/etc/d.xml b/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate/etc/d.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate/etc/t.xml b/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate/etc/t.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate/modules/direct.mod b/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate/modules/direct.mod new file mode 100644 index 00000000000..7bd97a0bde2 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate/modules/direct.mod @@ -0,0 +1,8 @@ +[xml] +etc/d.xml + +[depend] +transient + +[ini-template] +direct.option=direct diff --git a/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate/modules/transient.mod b/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate/modules/transient.mod new file mode 100644 index 00000000000..222f937fecc --- /dev/null +++ b/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate/modules/transient.mod @@ -0,0 +1,8 @@ +[xml] +etc/t.xml + +[optional] +main + +[ini-template] +transient.option=transient diff --git a/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate/start.ini b/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate/start.ini new file mode 100644 index 00000000000..dbfd730d55d --- /dev/null +++ b/jetty-start/src/test/resources/usecases/transientWithoutIniTemplate/start.ini @@ -0,0 +1,2 @@ +--module=main +