lcsim/src/org/lcsim/job
diff -u -r1.60 -r1.61
--- JobControlManager.java 17 May 2012 01:11:58 -0000 1.60
+++ JobControlManager.java 17 May 2012 01:38:13 -0000 1.61
@@ -57,61 +57,50 @@
import org.lcsim.util.xml.JDOMExpressionFactory;
/**
- * Provides a frontend for running LCSim jobs using an XML steering file.
+ * This class provides a frontend for running and managing LCSim jobs using an XML steering format.
*
- * The command line syntax is
- * <code>java -jar ./lib/lcsim-bin.jar -pPropFile.prop -Dvar=value steeringFile.xml</code>.
+ * The command line syntax is:
*
- * The <code>p</code> option is for loading external variable definitions from a
- * properties file. An unlimited number of properties files can be specified.
+ * <code>java -jar ./lib/lcsim-bin.jar steeringFile.xml [options]</code>
*
- * The <code>D</code> option can be used to set variable definitions that will be
- * substituted into the XML file. An unlimited number of command-line variable
- * definitions are allowed.
+ * To see the available command line options with descriptions, run with "-h" as the only option.
*
- * The <code>v</code> option turns on verbose mode.
+ * In the XML file, variables have the format <code>${variableName}</code>. No nested variable definitions are
+ * allowed (e.g. no variables within variables).
*
- * In the XML file, variables have the format <code>${[varname]}</code>. No nested variable
- * definitions are allowed (e.g. no variables within variables).
+ * Command-line parameters that can be defined using switches are overridden by the corresponding settings in
+ * the job XML file, if they are present. This means that if these parameters are to be taken from the CL, the
+ * matching settings should be left out of the XML job file. This is not the case, however, for input files
+ * specified by the "-i" option, which are appeneded to the ones listed in the steering file.
*
- * Command-line parameters that can be defined using switches are overridden by the
- * corresponding settings in the job XML file, if they are present. This means that
- * if these parameters are to be taken from the CL, the matching settings should be
- * left out of the XML job file.
- *
- * A single <code>JobControlManager</code> should be used to execute one job, after
- * which it should be discarded. If the {@link #run()} method is called twice on
- * the same manager, a fatal exception will be thrown.
- *
- * @version $Id: JobControlManager.java,v 1.60 2012/05/17 01:11:58 jeremy Exp $
+ * @version $Id: JobControlManager.java,v 1.61 2012/05/17 01:38:13 jeremy Exp $
* @author Jeremy McCormick
*/
-// TODO: Do proper logging using Java Logger class.
+// TODO: Do proper logging using Java Logger class rather than just a PrintStream.
// TODO: Add command line option for including input files as paths or URLs.
-public class JobControlManager
-{
+public class JobControlManager {
// The LCIO record loop.
private LCSimLoop loop;
-
+
// Driver management.
private Map<String, Driver> driverMap = new LinkedHashMap<String, Driver>();
- private List<Driver> driverExec = new ArrayList<Driver>();
- private Map<String, String> availableDrivers = new HashMap<String, String>();
-
- // Run parameters.
- private List<File> inputFiles = new ArrayList<File>();
- private int maxEvents = -1;
- private int skipEvents = -1;
- private File rewriteFile;
-
- // Variables and constants.
- private Map<String, String> variableMap = new HashMap<String, String>();
- private Map<String, Double> constantsMap = new HashMap<String, Double>();
-
- // Boolean job options.
+ private List<Driver> driverExec = new ArrayList<Driver>();
+ private Map<String, String> availableDrivers = new HashMap<String, String>();
+
+ // Run parameters.
+ private List<File> inputFiles = new ArrayList<File>();
+ private int maxEvents = -1;
+ private int skipEvents = -1;
+ private File rewriteFile;
+
+ // Variables and constants.
+ private Map<String, String> variableMap = new HashMap<String, String>();
+ private Map<String, Double> constantsMap = new HashMap<String, Double>();
+
+ // Boolean job options.
private boolean performDryRun;
private boolean rewrite;
-
+
// Settings effecting logging verbosity.
private boolean printInputFiles;
private boolean printDriverStatistics;
@@ -120,193 +109,189 @@
private boolean printDriversDetailed;
private boolean printVersion;
private boolean verbose;
-
+
// File caching.
private File cacheDirectory;
- private FileCache fileCache; // Start with default dir.
-
+ private FileCache fileCache; // Start with default dir.
+
// True once job parameters are setup from CL and XML.
private boolean wasSetup;
-
- // The manager's class loader.
- private ClassLoader loader;
-
- // The log stream for messages.
- PrintStream logStream = System.out;
-
- // Root node of XML job file.
- private Element root;
-
- // XML utils.
- private JDOMExpressionFactory factory = new JDOMExpressionFactory();
- private ParameterConverters paramConverter = new ParameterConverters(factory);
-
- // Command line options.
- private static final Options options = createCommandLineOptions();
-
- // Reg exp to extract variables from a string with the form "${varName}".
- private static final Pattern varPattern = Pattern.compile("[$][{][a-zA-Z_-]*[}]");
-
- private DriverAdapter driverAdapter = null;
-
- /**
- * The default constructor.
- */
- public JobControlManager() {
- try {
- fileCache = new FileCache();
- } catch (IOException x) {
- throw new RuntimeException(x);
- }
+
+ // The manager's class loader.
+ private ClassLoader loader;
+
+ // The log stream for messages.
+ PrintStream logStream = System.out;
+
+ // Root node of XML job file.
+ private Element root;
+
+ // XML utils.
+ private JDOMExpressionFactory factory = new JDOMExpressionFactory();
+ private ParameterConverters paramConverter = new ParameterConverters(factory);
+
+ // Command line options.
+ private static final Options options = createCommandLineOptions();
+
+ // Reg exp to extract variables from a string with the form "${varName}".
+ private static final Pattern varPattern = Pattern.compile("[$][{][a-zA-Z_-]*[}]");
+
+ private DriverAdapter driverAdapter = null;
+
+ /**
+ * The default constructor.
+ */
+ public JobControlManager() {
+ try {
+ fileCache = new FileCache();
+ } catch (IOException x) {
+ throw new RuntimeException(x);
+ }
LCSimConditionsManagerImplementation.register();
- }
-
- /**
- * Run the manager using a main. Takes command-line options (see class description).
- * @param args The command line arguments.
- */
- public static void main(String args[]) {
- JobControlManager mgr = new JobControlManager();
+ }
+
+ /**
+ * Run the manager using a main. Takes command-line options (use -h option to see them).
+ *
+ * @param args The command line arguments.
+ */
+ public static void main(String args[]) {
+ JobControlManager mgr = new JobControlManager();
if (args.length == 0) {
mgr.logStream.println("java -jar lcsim-bin.jar [options] steeringFile.xml");
HelpFormatter help = new HelpFormatter();
help.printHelp(" ", options);
System.exit(1);
}
- mgr.parseCommandLineOptions(args);
- mgr.run();
- }
-
- /**
- * Create the command line options.
- * @return The command line options for the manager.
- */
- private static Options createCommandLineOptions()
- {
- Options options = new Options();
- options.addOption(new Option("p", true, "Load a properties file containing variable definitions"));
- options.addOption(new Option("D", true, "Define a variable with form [name]=[value]"));
- options.addOption(new Option("w", true, "Rewrite the XML file with variables resolved"));
- options.addOption(new Option("v", false, "Turn on verbose mode"));
- options.addOption(new Option("s", true, "Set the number of events to skip."));
- options.addOption(new Option("n", true, "Set the max number of events to process."));
- options.addOption(new Option("x", false, "Perform a dry run which does not process events"));
- options.addOption(new Option("q", false, "Turn on quiet mode."));
- options.addOption(new Option("i", true, "Add an LCIO input file to process."));
- return options;
- }
-
- /**
- * Parse command-line options and setup job state from them. This method
- * calls {@link #setup(File)} to load the steering paramters from an XML file,
- * after processing other command line options. This method is private so that
- * callers must all use the {@link #main(String[])} routine as the primary
- * entry point.
- *
- * @param args The command line arguments.
- */
- private void parseCommandLineOptions(String args[])
- {
- // Setup parser.
- CommandLineParser parser = new PosixParser();
-
- // CommandLine to be loaded.
- CommandLine cl = null;
-
- // Parse CL arguments.
- try {
- cl = parser.parse(options, args);
- } catch (ParseException x) {
- throw new RuntimeException("Problem parsing command line options.", x);
- }
-
- // Turn on verbose mode. This setting may be overridden by control section from XML.
- if (cl.hasOption("v")) {
+ mgr.parseCommandLineOptions(args);
+ mgr.run();
+ }
+
+ /**
+ * Create the command line options.
+ *
+ * @return The command line options for the manager.
+ */
+ private static Options createCommandLineOptions() {
+ Options options = new Options();
+ options.addOption(new Option("p", true, "Load a properties file containing variable definitions"));
+ options.addOption(new Option("D", true, "Define a variable with form [name]=[value]"));
+ options.addOption(new Option("w", true, "Rewrite the XML file with variables resolved"));
+ options.addOption(new Option("v", false, "Turn on verbose mode"));
+ options.addOption(new Option("s", true, "Set the number of events to skip."));
+ options.addOption(new Option("n", true, "Set the max number of events to process."));
+ options.addOption(new Option("x", false, "Perform a dry run which does not process events"));
+ options.addOption(new Option("q", false, "Turn on quiet mode."));
+ options.addOption(new Option("i", true, "Add an LCIO input file to process."));
+ return options;
+ }
+
+ /**
+ * Parse command-line options and setup job state from them. This method calls {@link #setup(File)} to
+ * load the steering paramters from an XML file, after processing other command line options. This method
+ * is private so that callers must all use the {@link #main(String[])} routine as the primary entry point.
+ *
+ * @param args The command line arguments.
+ */
+ private void parseCommandLineOptions(String args[]) {
+ // Setup parser.
+ CommandLineParser parser = new PosixParser();
+
+ // CommandLine to be loaded.
+ CommandLine cl = null;
+
+ // Parse CL arguments.
+ try {
+ cl = parser.parse(options, args);
+ } catch (ParseException x) {
+ throw new RuntimeException("Problem parsing command line options.", x);
+ }
+
+ // Turn on verbose mode. This setting may be overridden by control section from XML.
+ if (cl.hasOption("v")) {
setVerbose(true);
}
- // Turn on quiet mode. If "-v" is also specified, this will have no effect.
+ // Turn on quiet mode. If "-v" is also specified, this will have no effect.
else if (cl.hasOption("q")) {
setVerbose(false);
}
-
- // Load properties file containing variable definitions.
- if (cl.hasOption("p")) {
- String[] propValues = cl.getOptionValues("p");
- for (String propFileName : propValues) {
- InputStream in = null;
- try {
- in = new FileInputStream(propFileName);
- }
- catch (FileNotFoundException e) {
- throw new RuntimeException(e);
- }
- Properties props = new Properties();
- try {
- props.load(in);
+
+ // Load properties file containing variable definitions.
+ if (cl.hasOption("p")) {
+ String[] propValues = cl.getOptionValues("p");
+ for (String propFileName : propValues) {
+ InputStream in = null;
+ try {
+ in = new FileInputStream(propFileName);
+ } catch (FileNotFoundException e) {
+ throw new RuntimeException(e);
}
- catch (IOException e) {
+ Properties props = new Properties();
+ try {
+ props.load(in);
+ } catch (IOException e) {
throw new RuntimeException(e);
}
- for (Entry<Object,Object> entry : props.entrySet()) {
+ for (Entry<Object, Object> entry : props.entrySet()) {
String key = (String) entry.getKey();
String value = (String) entry.getValue();
addVariableDefinition(key, value);
}
- }
- }
-
- // Process user variable definitions.
- if (cl.hasOption("D")) {
- String[] defValues = cl.getOptionValues("D");
- for (String def : defValues) {
- String[] s = def.split("=");
- if (s.length != 2) {
- throw new RuntimeException("Bad variable format: " + def);
- }
- String key = s[0];
- String value = s[1];
- addVariableDefinition(key, value);
- }
- }
-
- // Rewrite XML file with variables resolved.
- if (cl.hasOption("w")) {
- this.rewrite = true;
- String rewritePath = cl.getOptionValue("w");
- this.rewriteFile = new File(rewritePath);
- if (this.rewriteFile.exists()) {
- throw new RuntimeException("Rewrite file already exists: " + rewritePath);
- }
- }
-
- // Set max number of events to run.
- if (cl.hasOption("n")) {
- this.maxEvents = Integer.valueOf(cl.getOptionValue("n"));
- }
-
- // Set number of events to skip.
- if (cl.hasOption("s")) {
- this.skipEvents = Integer.valueOf(cl.getOptionValue("s"));
- }
-
- // Perform a dry run, not processing any events but doing job setup.
- if (cl.hasOption("x")) {
- this.performDryRun = true;
- }
-
- // The path to the XML steering file, which has no command switch.
- if (cl.getArgList().size() == 0) {
- throw new RuntimeException("Missing LCSim XML file argument.");
- } else if (cl.getArgList().size() > 1) {
- throw new RuntimeException("Too many extra arguments.");
- }
-
- // Setup the XML steering file and check for its existence.
- File xmlRunControlFile = new File((String) cl.getArgList().get(0));
+ }
+ }
+
+ // Process user variable definitions.
+ if (cl.hasOption("D")) {
+ String[] defValues = cl.getOptionValues("D");
+ for (String def : defValues) {
+ String[] s = def.split("=");
+ if (s.length != 2) {
+ throw new RuntimeException("Bad variable format: " + def);
+ }
+ String key = s[0];
+ String value = s[1];
+ addVariableDefinition(key, value);
+ }
+ }
+
+ // Rewrite XML file with variables resolved.
+ if (cl.hasOption("w")) {
+ this.rewrite = true;
+ String rewritePath = cl.getOptionValue("w");
+ this.rewriteFile = new File(rewritePath);
+ if (this.rewriteFile.exists()) {
+ throw new RuntimeException("Rewrite file already exists: " + rewritePath);
+ }
+ }
+
+ // Set max number of events to run.
+ if (cl.hasOption("n")) {
+ this.maxEvents = Integer.valueOf(cl.getOptionValue("n"));
+ }
+
+ // Set number of events to skip.
+ if (cl.hasOption("s")) {
+ this.skipEvents = Integer.valueOf(cl.getOptionValue("s"));
+ }
+
+ // Perform a dry run, not processing any events but doing job setup.
+ if (cl.hasOption("x")) {
+ this.performDryRun = true;
+ }
+
+ // Check that there is exactly one extra argument for the XML steering file.
+ if (cl.getArgList().size() == 0) {
+ throw new RuntimeException("Missing LCSim XML file argument.");
+ } else if (cl.getArgList().size() > 1) {
+ throw new RuntimeException("Too many extra arguments.");
+ }
+
+ // Setup the XML steering file and check for its existence.
+ File xmlRunControlFile = new File((String) cl.getArgList().get(0));
if (!xmlRunControlFile.exists()) {
throw new RuntimeException("The steering file " + args[0] + " does not exist!");
}
-
+
// Local LCIO files to process.
if (cl.hasOption("i")) {
String[] files = cl.getOptionValues("i");
@@ -318,208 +303,202 @@
inputFiles.add(new File(fileName));
}
}
-
- // Setup job parameters from XML now that CL options are all processed.
- setup(xmlRunControlFile);
- }
-
- /**
- * Add a variable definition to be substituted into the job's XML file.
- * This method is public so that caller's not using the CL can still
- * define necessary variables for the steering file.
- * @param key The variable name.
- * @param value The variable's value.
- */
- public void addVariableDefinition(String key, String value)
- {
- if (verbose) {
- logStream.println(key + " = " + value);
- }
- if (!this.variableMap.containsKey(key))
- {
- variableMap.put(key, value);
+
+ // Setup job parameters from XML now that CL options are all processed.
+ setup(xmlRunControlFile);
+ }
+
+ /**
+ * Add a variable definition to be substituted into the job's XML file. This method is public so that
+ * caller's not using the CL can still define necessary variables for the steering file.
+ *
+ * @param key The variable name.
+ * @param value The variable's value.
+ */
+ public void addVariableDefinition(String key, String value) {
+ if (verbose) {
+ logStream.println(key + " = " + value);
}
- else
- {
+ if (!this.variableMap.containsKey(key)) {
+ variableMap.put(key, value);
+ } else {
throw new RuntimeException("Duplicate variable definition: " + key);
}
- }
+ }
+
+ /**
+ * Execute a job using the current parameters.
+ */
+ public boolean run() {
+ // If setup was not called first, then abort the job.
+ if (!wasSetup) {
+ logStream.println("Aborting job! Setup was never called.");
+ return false;
+ }
+
+ if (printVersion) {
+ (new LCSimVersion()).printOut(logStream);
+ logStream.println();
+ }
+
+ // Dry run selected. No events will be processed here.
+ if (performDryRun) {
+ logStream.println("Executed dry run. No events processed!");
+ return false;
+ }
+
+ // Setup lcsim loop before running.
+ getLCSimLoop();
+
+ try {
+ // Add the LCIO files to the loop.
+ loop.setLCIORecordSource(new LCIOEventSource(this.getClass().getSimpleName(), inputFiles));
+
+ // Driver statistics printout.
+ PrintStream statsStream = null;
+ if (printDriverStatistics) {
+ statsStream = logStream;
+ }
+
+ if (verbose) {
+ logStream.println("Start time: " + (new Date()));
+ logStream.println();
+ }
+
+ if (skipEvents > 0) {
+ if (verbose) {
+ logStream.println("Skipping " + skipEvents + " events.");
+ }
+ loop.skip(skipEvents);
+ }
+
+ // Execute the loop.
+ loop.loop(maxEvents, statsStream);
+
+ if (verbose) {
+ logStream.println();
+ logStream.println("End time: " + (new Date()));
+ }
+ }
+ // Record source was exhausted before max events was hit.
+ catch (LoopSourceExhaustedException x) {
+ logStream.println(x.getMessage());
+ }
+ // Catch other fatal exceptions thrown from the loop.
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ // Cleanup the loop.
+ loop.dispose();
+ loop = null;
+
+ // Job was successful.
+ return true;
+ }
+
+ /**
+ * Get the <code>LCSimLoop</code> of this JobManager.
+ *
+ * @return The LCSimLoop.
+ */
+ public LCSimLoop getLCSimLoop() {
+ if (loop == null) {
+ loop = new LCSimLoop();
+ // Add the drivers to the loop.
+ for (Driver driver : driverExec) {
+ loop.add(driver);
+ }
+ }
+ return loop;
+ }
+
+ /**
+ * Return a list of Drivers to be executed. This can be used from an external framework like JAS3. The
+ * list will be empty unless the <code>setup()</code> method has been called.
+ *
+ * @return A <code>List</code> of <code>Drivers</code>.
+ */
+ public List<Driver> getDriverExecList() {
+ return this.driverExec;
+ }
+
+ /**
+ * Setup job parameters from a <code>File</code>.
+ *
+ * @param file
+ */
+ public void setup(File file) {
+ try {
+ setup((new FileInputStream(file)));
+ } catch (FileNotFoundException x) {
+ throw new RuntimeException(x);
+ }
+ }
+
+ /**
+ * Setup job parameters from an embedded resource. This method calls {@link #setup(InputStream)}.
+ */
+ public void setup(String resourceURL) {
+ setup(this.getClass().getResourceAsStream(resourceURL));
+ }
+
+ /**
+ * Setup job parameters from an <code>InputStream</code> with XML text.
+ *
+ * @param in The XML input stream.
+ */
+ public void setup(InputStream in) {
- /**
- * Execute a job using the current parameters.
- */
- public boolean run()
- {
- // If setup was not called first, then abort the job.
- if (!wasSetup) {
- logStream.println("Aborting job! Setup was never called.");
- return false;
- }
-
- if (printVersion) {
- (new LCSimVersion()).printOut(logStream);
- logStream.println();
- }
-
- // Dry run selected. No events will be processed here.
- if (performDryRun) {
- logStream.println("Executed dry run. No events processed!");
- return false;
- }
-
- // Setup lcsim loop before running.
- getLCSimLoop();
-
- try {
- // Add the LCIO files to the loop.
- loop.setLCIORecordSource(new LCIOEventSource(this.getClass().getSimpleName(), inputFiles));
-
- // Driver statistics printout.
- PrintStream statsStream = null;
- if (printDriverStatistics) {
- statsStream = logStream;
- }
-
- if (verbose) {
- logStream.println("Start time: " + (new Date()));
- logStream.println();
- }
-
- if (skipEvents > 0) {
- if (verbose) {
- logStream.println("Skipping " + skipEvents + " events.");
- }
- loop.skip(skipEvents);
- }
-
- // Execute the loop.
- loop.loop(maxEvents, statsStream);
-
- if (verbose) {
- logStream.println();
- logStream.println("End time: " + (new Date()));
- }
- }
- // Record source was exhausted before max events was hit.
- catch (LoopSourceExhaustedException x) {
- logStream.println(x.getMessage());
- }
- // Catch other fatal exceptions thrown from the loop.
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
-
- // Cleanup the loop.
- loop.dispose();
- loop = null;
-
- // Job was successful.
- return true;
- }
-
- /**
- * Get the <code>LCSimLoop</code> of this JobManager.
- * @return The LCSimLoop.
- */
- public LCSimLoop getLCSimLoop() {
- if (loop == null) {
- loop = new LCSimLoop();
- // Add the drivers to the loop.
- for (Driver driver : driverExec) {
- loop.add(driver);
- }
- }
- return loop;
- }
-
- /**
- * Return a list of Drivers to be executed. This can be used from an external
- * framework like JAS3. The list will be empty unless the <code>setup()</code>
- * method has been called.
- * @return A <code>List</code> of <code>Drivers</code>.
- */
- public List<Driver> getDriverExecList() {
- return this.driverExec;
- }
-
- /**
- * Setup job parameters from a <code>File</code>.
- * @param file
- */
- public void setup(File file)
- {
- try {
- setup((new FileInputStream(file)));
- } catch (FileNotFoundException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * Setup job parameters from an embedded resource.
- * This method calls {@link #setup(InputStream)}.
- */
- public void setup(String resourceURL) {
- setup(this.getClass().getResourceAsStream(resourceURL));
- }
-
- /**
- * Setup job parameters from an <code>InputStream</code> with XML text.
- * @param in The XML input stream.
- */
- public void setup(InputStream in) {
-
- // Make the Document builder.
- SAXBuilder builder = new SAXBuilder();
-
- // Setup XML schema validation.
- builder.setEntityResolver(new ClasspathEntityResolver());
+ // Make the Document builder.
+ SAXBuilder builder = new SAXBuilder();
+
+ // Setup XML schema validation.
+ builder.setEntityResolver(new ClasspathEntityResolver());
builder.setValidation(true);
builder.setFeature("http://apache.org/xml/features/validation/schema", true);
-
- // Setup expression resolution.
- builder.setFactory(factory);
-
- // Build the document.
- Document doc = null;
- try {
- doc = builder.build(in);
- } catch (Exception x) {
- throw new RuntimeException(x);
- }
-
- // Setup the JobControlManager from the XML file.
- setup(doc);
- }
-
- /**
- * Setup the job parameters from an XML Document. Though it isn't
- * publically accessible, this method contains the primary logic for setting
- * up job parameters from an XML file. The other setup methods, namely,
- * {@link #setup(InputStream)}, {@link #setup(String)} and {@link #setup(File)},
- * all eventually call this method.
+
+ // Setup expression resolution.
+ builder.setFactory(factory);
+
+ // Build the document.
+ Document doc = null;
+ try {
+ doc = builder.build(in);
+ } catch (Exception x) {
+ throw new RuntimeException(x);
+ }
+
+ // Setup the JobControlManager from the XML file.
+ setup(doc);
+ }
+
+ /**
+ * Setup the job parameters from an XML Document. Though it isn't publically accessible, this method
+ * contains the primary logic for setting up job parameters from an XML file. The other setup methods,
+ * namely, {@link #setup(InputStream)}, {@link #setup(String)} and {@link #setup(File)}, all eventually
+ * call this method.
+ *
* @param doc The lcsim recon XML document describing the job.
*/
- private void setup(Document doc)
- {
+ private void setup(Document doc) {
if (wasSetup) {
logStream.println("Ignoring call to setup as it was already called.");
return;
}
-
+
// Set the root element.
root = doc.getRootElement();
-
+
// Do variable substitutions.
substituteVariables(doc);
-
- // Rewrite XML after variable substitution. Correctness of values,
+
+ // Rewrite XML after variable substitution. Correctness of values,
// such as existence of input file paths, is NOT checked.
if (this.rewrite) {
rewriteXMLSteering(doc);
}
-
+
// Setup the job control parameters.
setupJobControlParameters();
@@ -527,19 +506,19 @@
if (printSystemProperties) {
printSystemProperties(logStream);
}
-
+
// Setup the class loader.
setupClassLoader();
-
+
// Setup units.
setupUnits();
-
+
// Process the variable definitions.
processConstants();
-
+
// Check for required conditions.
checkConditions();
-
+
// Setup drivers with parameters and execution order.
setupDrivers();
@@ -548,7 +527,7 @@
// Setup the input files.
setupInputFiles();
-
+
// Check if a dry run should be performed when no input files are present.
if (inputFiles.size() == 0) {
performDryRun = true;
@@ -558,107 +537,103 @@
// Flag JobManager as setup.
wasSetup = true;
}
-
- /**
- * Perform variable substitution within all text data in a entire document.
- * @param doc The XML document.
- */
- private void substituteVariables(Document doc)
- {
- substituteVariables(doc.getRootElement());
- }
-
- /**
- * Substitute values from the <code>variableMap</code> into an XML element
- * and all its children, recursively.
- *
- * @param element The XML element.
- * @throw RuntimeException If a variable does not exist in the <code>variableMap</code>.
- */
- private void substituteVariables(Element element)
- {
- String text = element.getTextNormalize();
- if (text.length() != 0)
- {
- // Create a new matcher.
- Matcher match = varPattern.matcher(text);
-
- // No variables were used.
- if (!match.find())
- return;
-
- // Text data on which to perform substitutions.
+
+ /**
+ * Perform variable substitution within all text data in a entire document.
+ *
+ * @param doc The XML document.
+ */
+ private void substituteVariables(Document doc) {
+ substituteVariables(doc.getRootElement());
+ }
+
+ /**
+ * Substitute values from the <code>variableMap</code> into an XML element and all its children,
+ * recursively.
+ *
+ * @param element The XML element.
+ * @throw RuntimeException If a variable does not exist in the <code>variableMap</code>.
+ */
+ private void substituteVariables(Element element) {
+ String text = element.getTextNormalize();
+ if (text.length() != 0) {
+ // Create a new matcher.
+ Matcher match = varPattern.matcher(text);
+
+ // No variables were used.
+ if (!match.find())
+ return;
+
+ // Text data on which to perform substitutions.
String newText = new String(text);
-
+
// Reset the matcher.
- match.reset();
-
- // Loop over the matches.
+ match.reset();
+
+ // Loop over the matches.
while (match.find()) {
-
+
// Variable string with ${...} enclosure included.
String var = match.group();
-
+
// The name of the variable for lookup.
String varName = var.substring(2, var.length() - 1);
-
+
// The value of the variable.
String varValue = variableMap.get(varName);
-
+
// If a variable was not defined, then the application will immediately exit here.
- if (varValue == null)
- {
+ if (varValue == null) {
throw new RuntimeException("Variable not defined: " + varName);
}
-
+
// Substitute this variable's value into the text.
newText = newText.replace(var, varValue);
}
-
+
// Set this element's new text value.
element.setText(newText);
- }
-
- // Recursively process all child elements of this one.
- for (Iterator it = element.getChildren().iterator(); it.hasNext(); ) {
- substituteVariables((Element)it.next());
- }
- }
-
- /**
- * Rewrite the XML steering file after resolving variables (done externally).
- * The output path is set by command line argument to "-w".
- * @param doc The XML steering doc with variables substituted.
- */
- private void rewriteXMLSteering(Document doc) {
- if (verbose) {
- logStream.println("Rewriting XML to " + this.rewriteFile + " ...");
- }
- XMLOutputter outputter = new XMLOutputter();
- outputter.setFormat(Format.getPrettyFormat());
- try {
- FileOutputStream out = new FileOutputStream(this.rewriteFile);
- outputter.output(doc, out);
- out.close();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Setup the drivers from the XML job file,
- * adding them to the JobManager's <code>driverMap</code> .
+ }
+
+ // Recursively process all child elements of this one.
[truncated at 1000 lines; 1380 more skipped]