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 9f7fc6c62a8..18d1187da31 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 @@ -18,7 +18,6 @@ package org.eclipse.jetty.start; -import static org.eclipse.jetty.start.UsageException.ERR_BAD_GRAPH; import static org.eclipse.jetty.start.UsageException.ERR_INVOKE_MAIN; import static org.eclipse.jetty.start.UsageException.ERR_NOT_STOPPED; import static org.eclipse.jetty.start.UsageException.ERR_UNKNOWN; @@ -205,7 +204,7 @@ public class Main StartLog.debug("%s - %s",invoked_class,invoked_class.getPackage().getImplementationVersion()); - CommandLineBuilder cmd = args.getMainArgs(baseHome,false); + CommandLineBuilder cmd = args.getMainArgs(false); String argArray[] = cmd.getArgs().toArray(new String[0]); StartLog.debug("Command Line Args: %s",cmd.toString()); @@ -223,7 +222,7 @@ public class Main StartLog.endStartLog(); // Dump Jetty Home / Base - args.dumpEnvironment(baseHome); + args.dumpEnvironment(); // Dump JVM Args args.dumpJvmArgs(); @@ -238,7 +237,7 @@ public class Main dumpClasspathWithVersions(args.getClasspath()); // Dump Resolved XMLs - args.dumpActiveXmls(baseHome); + args.dumpActiveXmls(); } public void listModules(StartArgs args) @@ -288,7 +287,7 @@ public class Main // the various start inis // and then the raw command line arguments StartLog.debug("Parsing collected arguments"); - StartArgs args = new StartArgs(); + StartArgs args = new StartArgs(baseHome); args.parse(baseHome.getConfigSources()); // ------------------------------------------------------------ @@ -330,17 +329,17 @@ public class Main // ------------------------------------------------------------ // 5) Lib & XML Expansion / Resolution - args.expandLibs(baseHome); - args.expandModules(baseHome,activeModules); + args.expandLibs(); + args.expandModules(activeModules); // ------------------------------------------------------------ // 6) Resolve Extra XMLs - args.resolveExtraXmls(baseHome); + args.resolveExtraXmls(); // ------------------------------------------------------------ // 9) Resolve Property Files - args.resolvePropertyFiles(baseHome); + args.resolvePropertyFiles(); return args; } @@ -391,7 +390,7 @@ public class Main // Show Command Line to execute Jetty if (args.isDryRun()) { - CommandLineBuilder cmd = args.getMainArgs(baseHome,true); + CommandLineBuilder cmd = args.getMainArgs(true); System.out.println(cmd.toString(StartLog.isDebugEnabled()?" \\\n":" ")); } @@ -419,7 +418,7 @@ public class Main // execute Jetty in another JVM if (args.isExec()) { - CommandLineBuilder cmd = args.getMainArgs(baseHome,true); + CommandLineBuilder cmd = args.getMainArgs(true); cmd.debug(); ProcessBuilder pbuilder = new ProcessBuilder(cmd.getArgs()); StartLog.endStartLog(); 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 31d5fe6c376..a68d9a1fe21 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 @@ -528,7 +528,7 @@ public class Module implements Comparable { String name = m.group(2); Prop p = props.getProp(name); - if (p!=null && CommandLineConfigSource.ORIGIN_CMD_LINE.equals(p.origin)) + if (p!=null && p.origin.startsWith(CommandLineConfigSource.ORIGIN_CMD_LINE)) { StartLog.info("%-15s property set %s=%s",this._name,name,p.value); out.printf("%s=%s%n",name,p.value); diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java index aa3715c42ab..5e699aa2fd4 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java @@ -112,6 +112,8 @@ public class StartArgs private static final String SERVER_MAIN = "org.eclipse.jetty.xml.XmlConfiguration"; + private final BaseHome baseHome; + /** List of enabled modules */ private List modules = new ArrayList<>(); @@ -182,8 +184,9 @@ public class StartArgs private boolean approveAllLicenses = false; - public StartArgs() + public StartArgs(BaseHome baseHome) { + this.baseHome = baseHome; classpath = new Classpath(); } @@ -234,7 +237,7 @@ public class StartArgs } } - public void dumpActiveXmls(BaseHome baseHome) + public void dumpActiveXmls() { System.out.println(); System.out.println("Jetty Active XMLs:"); @@ -251,7 +254,7 @@ public class StartArgs } } - public void dumpEnvironment(BaseHome baseHome) + public void dumpEnvironment() { // Java Details System.out.println(); @@ -442,7 +445,7 @@ public class StartArgs * @throws IOException * if unable to expand the libraries */ - public void expandLibs(BaseHome baseHome) throws IOException + public void expandLibs() throws IOException { StartLog.debug("Expanding Libs"); for (String rawlibref : rawLibs) @@ -464,14 +467,12 @@ public class StartArgs /** * Build up the Classpath and XML file references based on enabled Module list. * - * @param baseHome - * the base home in use * @param activeModules * the active (selected) modules * @throws IOException * if unable to expand the modules */ - public void expandModules(BaseHome baseHome, List activeModules) throws IOException + public void expandModules(List activeModules) throws IOException { StartLog.debug("Expanding Modules"); for (Module module : activeModules) @@ -543,7 +544,7 @@ public class StartArgs return jvmArgs; } - public CommandLineBuilder getMainArgs(BaseHome baseHome, boolean addJavaInit) throws IOException + public CommandLineBuilder getMainArgs(boolean addJavaInit) throws IOException { CommandLineBuilder cmd = new CommandLineBuilder(); @@ -851,6 +852,28 @@ public class StartArgs return; } + if (arg.startsWith("--commands=")) + { + Path commands = baseHome.getPath(Props.getValue(arg)); + + if (!Files.exists(commands) || !Files.isReadable(commands)) + throw new UsageException(ERR_BAD_ARG,"--commands file must be readable: %s",commands); + try + { + TextFile file = new TextFile(commands); + StartLog.info("reading commands from %s",baseHome.toShortForm(commands)); + String s = source+"|"+baseHome.toShortForm(commands); + for (String line: file) + { + parse(line,s); + } + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } + if (arg.startsWith("--include-jetty-dir=")) { // valid, but handled in ConfigSources instead @@ -1133,7 +1156,7 @@ public class StartArgs } } - public void resolveExtraXmls(BaseHome baseHome) throws IOException + public void resolveExtraXmls() throws IOException { // Find and Expand XML files for (String xmlRef : xmlRefs) @@ -1148,7 +1171,7 @@ public class StartArgs } } - public void resolvePropertyFiles(BaseHome baseHome) throws IOException + public void resolvePropertyFiles() throws IOException { // Find and Expand property files for (String propertyFileRef : propertyFileRefs) diff --git a/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt b/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt index d6c5932edf2..65e84a80de9 100644 --- a/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt +++ b/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt @@ -40,6 +40,10 @@ Command Line Options: properties to the sub process. This allows the generated properties file to be saved and reused. Without this option, a temporary file is used. + + --commands= + Use each line of the file as arguments on the command + line. Debug and Start Logging: ------------------------ diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/ModuleGraphWriterTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/ModuleGraphWriterTest.java index c750733e9ec..192f3bbc9d8 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/ModuleGraphWriterTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/ModuleGraphWriterTest.java @@ -57,7 +57,7 @@ public class ModuleGraphWriterTest // Initialize BaseHome basehome = new BaseHome(config); - StartArgs args = new StartArgs(); + StartArgs args = new StartArgs(basehome); args.parse(config); Modules modules = new Modules(basehome, args); diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/ModulesTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/ModulesTest.java index e30c26183d5..bae8becba9f 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/ModulesTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/ModulesTest.java @@ -63,7 +63,7 @@ public class ModulesTest // Initialize BaseHome basehome = new BaseHome(config); - StartArgs args = new StartArgs(); + StartArgs args = new StartArgs(basehome); args.parse(config); // Test Modules @@ -121,7 +121,7 @@ public class ModulesTest // Initialize BaseHome basehome = new BaseHome(config); - StartArgs args = new StartArgs(); + StartArgs args = new StartArgs(basehome); args.parse(config); // Test Modules @@ -158,7 +158,7 @@ public class ModulesTest // Initialize BaseHome basehome = new BaseHome(config); - StartArgs args = new StartArgs(); + StartArgs args = new StartArgs(basehome); args.parse(config); // Test Modules diff --git a/jetty-start/src/test/resources/usecases/parameterized.commands.assert.txt b/jetty-start/src/test/resources/usecases/parameterized.commands.assert.txt new file mode 100644 index 00000000000..eadc75d87bc --- /dev/null +++ b/jetty-start/src/test/resources/usecases/parameterized.commands.assert.txt @@ -0,0 +1,17 @@ +## The XMLs we expect (order is important) +XML|${jetty.home}/etc/base.xml +XML|${jetty.home}/etc/main.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|name=value +PROP|name0=changed0 +PROP|name1=changed1 + +# Files / Directories to create +EXISTS|start.d/parameterized.ini diff --git a/jetty-start/src/test/resources/usecases/parameterized.commands.prepare.txt b/jetty-start/src/test/resources/usecases/parameterized.commands.prepare.txt new file mode 100644 index 00000000000..d9de4cf59ff --- /dev/null +++ b/jetty-start/src/test/resources/usecases/parameterized.commands.prepare.txt @@ -0,0 +1,3 @@ +other=value +name=changed +--commands=etc/commands.txt \ No newline at end of file diff --git a/jetty-start/src/test/resources/usecases/parameterized/etc/commands.txt b/jetty-start/src/test/resources/usecases/parameterized/etc/commands.txt new file mode 100644 index 00000000000..aa292749197 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/parameterized/etc/commands.txt @@ -0,0 +1,5 @@ +name0=changed0 +name1=changed1 +--add-to-start=parameterized + +# ignore this \ No newline at end of file