Issue #1139 read command line from file
This commit is contained in:
parent
95eef4e98c
commit
7a741f93ee
|
@ -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();
|
||||
|
|
|
@ -528,7 +528,7 @@ public class Module implements Comparable<Module>
|
|||
{
|
||||
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);
|
||||
|
|
|
@ -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<String> 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<Module> activeModules) throws IOException
|
||||
public void expandModules(List<Module> 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)
|
||||
|
|
|
@ -41,6 +41,10 @@ Command Line Options:
|
|||
generated properties file to be saved and reused.
|
||||
Without this option, a temporary file is used.
|
||||
|
||||
--commands=<filename>
|
||||
Use each line of the file as arguments on the command
|
||||
line.
|
||||
|
||||
Debug and Start Logging:
|
||||
------------------------
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -0,0 +1,3 @@
|
|||
other=value
|
||||
name=changed
|
||||
--commands=etc/commands.txt
|
|
@ -0,0 +1,5 @@
|
|||
name0=changed0
|
||||
name1=changed1
|
||||
--add-to-start=parameterized
|
||||
|
||||
# ignore this
|
Loading…
Reference in New Issue