lcsim/src/org/lcsim/job
diff -u -r1.42 -r1.43
--- JobControlManager.java 3 Jun 2010 03:04:35 -0000 1.42
+++ JobControlManager.java 4 Jun 2010 19:05:03 -0000 1.43
@@ -46,7 +46,7 @@
* The command line syntax is <code>java -jar ./lib/lcsim.jar steeringFile.xml</code>.
*
* @author jeremym
- * @verbose $id: $
+ * @verbose $Id: JobControlManager.java,v 1.43 2010/06/04 19:05:03 jeremy Exp $
*/
public class JobControlManager
{
@@ -355,47 +355,69 @@
}
logStream.println("-- End System Properties");
logStream.println();
- }
+ }
+
+ private File processFileText(String fileText, List<File> fileList)
+ {
+ Element fileElement = new Element("file");
+ fileElement.setText(fileText.trim());
+ return processFileElement(fileElement, fileList);
+ }
+
+ private File processFileElement(Element fileElement, List<File> fileList)
+ {
+ String fileLoc = fileElement.getText().trim();
+ File file = null;
+
+ // Try to process the file text as a URL.
+ try
+ {
+ URL fileURL = new URL(fileLoc);
+
+ // Local file URL.
+ if (fileLoc.startsWith("file:"))
+ {
+ file = new File(fileURL.getPath());
+ }
+ // Remote file URL.
+ else
+ {
+ try
+ {
+ file = this.fileCache.getCachedFile(fileURL);
+ }
+ catch (IOException x)
+ {
+ throw new RuntimeException("Unable to fetch file " + fileLoc + " to the cache directory.", x);
+ }
+ }
+ }
+ // Text is not a URL. Attempt to process as local file.
+ catch (MalformedURLException x)
+ {
+ file = new File(fileLoc);
+ }
+
+ // Add to list.
+ if (fileList != null)
+ {
+ fileList.add(file);
+ }
+
+ return file;
+ }
@SuppressWarnings("unchecked")
private void setupInputFiles()
{
- // Read local files.
+ // Process the <file> elements.
List<Element> files = root.getChild("inputFiles").getChildren("file");
- for (Element file : files)
- {
- String fileLoc = file.getText().trim();
- File nextFile = new File(fileLoc);
- inputFiles.add(nextFile);
- }
-
- // Read file URLs.
- List<Element> fileUrls = root.getChild("inputFiles").getChildren("fileUrl");
- for (Element fileUrl : fileUrls)
- {
- URL url;
- try
- {
- url = new URL(fileUrl.getText());
- }
- catch (MalformedURLException x)
- {
- throw new RuntimeException(x);
- }
-
- File nextFile;
- try
- {
- nextFile = fileCache.getCachedFile(url);
- }
- catch (IOException x)
- {
- throw new RuntimeException(x);
- }
- inputFiles.add(nextFile);
+ for (Element fileElem : files)
+ {
+ processFileElement(fileElem, this.inputFiles);
}
- // Read lists of file locations.
+ // Read lists of file locations given by <fileList> elements.
List<Element> fileLists = root.getChild("inputFiles").getChildren("fileList");
for (Element fileList : fileLists)
{
@@ -412,41 +434,10 @@
String line = null;
try
{
+ // Read the next file, turn the text into an XML element, and process it using common method.
while (( line = input.readLine()) != null)
{
- File nextFile = new File(line.trim());
- inputFiles.add(nextFile);
- }
- }
- catch (IOException x)
- {
- throw new RuntimeException(x);
- }
- }
-
- // Read lists of file URLs.
- List<Element> fileUrlLists = root.getChild("inputFiles").getChildren("fileUrlList");
- for (Element fileUrlList : fileUrlLists)
- {
- String filePath = fileUrlList.getText();
- BufferedReader input;
- try
- {
- input = new BufferedReader(new FileReader(new File(filePath)));
- }
- catch (FileNotFoundException x)
- {
- throw new RuntimeException(x);
- }
- String line = null;
- try
- {
- while ((line = input.readLine()) != null)
- {
-
- URL url = new URL(line);
- File nextFile = fileCache.getCachedFile(url);
- inputFiles.add(nextFile);
+ processFileText(line.trim(), inputFiles);
}
}
catch (IOException x)
@@ -469,11 +460,11 @@
for (Element file : fsFiles)
{
String filePath = basedir + File.separator + file.getText().trim();
- inputFiles.add(new File(filePath));
+ processFileText(filePath, inputFiles);
}
}
- // Read fileRegExps.
+ // Read fileRegExps, which may only reference local files.
List<Element> fileRegExps = (List<Element>)root.getChild("inputFiles").getChildren("fileRegExp");
for (Element fileRegExp : fileRegExps)
{