Add saveResultsToBundle() for -bundle option
diff --git a/taverna-commandline-api/src/main/java/net/sf/taverna/t2/commandline/options/CommandLineOptions.java b/taverna-commandline-api/src/main/java/net/sf/taverna/t2/commandline/options/CommandLineOptions.java
index 3473297..dd8e20f 100644
--- a/taverna-commandline-api/src/main/java/net/sf/taverna/t2/commandline/options/CommandLineOptions.java
+++ b/taverna-commandline-api/src/main/java/net/sf/taverna/t2/commandline/options/CommandLineOptions.java
@@ -95,6 +95,8 @@
 	public boolean hasLogFile();
 
 	public boolean hasOption(String option);
+	
+	public boolean hasSaveResultsToBundle() ;
 
 	public String inputDelimiter(String inputName);
 
@@ -112,4 +114,6 @@
 	 */
 	public boolean saveResultsToDirectory();
 
+	public String saveResultsToBundle();
+
 }
\ No newline at end of file
diff --git a/taverna-commandline-common/src/main/java/net/sf/taverna/t2/commandline/CommandLineTool.java b/taverna-commandline-common/src/main/java/net/sf/taverna/t2/commandline/CommandLineTool.java
index 9d8c5fc..368527d 100644
--- a/taverna-commandline-common/src/main/java/net/sf/taverna/t2/commandline/CommandLineTool.java
+++ b/taverna-commandline-common/src/main/java/net/sf/taverna/t2/commandline/CommandLineTool.java
@@ -26,6 +26,7 @@
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.sql.SQLException;
 import java.util.HashMap;
 import java.util.Map;
@@ -170,6 +171,15 @@
 			 setupDatabase(commandLineOptions);
 
 			if (commandLineOptions.getWorkflow() != null) {
+				
+				/* Set context class loader to us, 
+				 * so that things such as JSON-LD caching of
+				 * robundle works.
+				 */
+				
+				Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+				
+				
 				/*
 				 * Initialise Credential Manager and SSL stuff quite early as
 				 * parsing and validating the workflow may require it
@@ -251,7 +261,8 @@
 					try {
 						Thread.sleep(500);
 					} catch (InterruptedException e) {
-						// Ignore
+						System.err.println("Interrupted while waiting for workflow to finish");
+						return 1;
 					}
 				}
 
@@ -278,6 +289,16 @@
 						}
 					}
 				}
+				if (commandLineOptions.saveResultsToBundle() != null) {
+					Path bundlePath = Paths.get(commandLineOptions.saveResultsToBundle());
+					DataBundles.closeAndSaveBundle(runService.getDataBundle(runId), bundlePath);
+					System.out.println("Workflow Run Bundle saved to: " + bundlePath.toAbsolutePath());
+				} else {
+					System.out.println("Workflow Run Bundle: " + runService.getDataBundle(runId).getSource());
+					// For debugging we'll leave it in /tmp for now
+					runService.getDataBundle(runId).setDeleteOnClose(false);
+					DataBundles.closeBundle(runService.getDataBundle(runId));
+				}
 
 				if (report.getState().equals(State.FAILED)) {
 					System.out.println("Workflow failed - see report below.");
diff --git a/taverna-commandline-common/src/main/java/net/sf/taverna/t2/commandline/data/InputsHandler.java b/taverna-commandline-common/src/main/java/net/sf/taverna/t2/commandline/data/InputsHandler.java
index 795376a..bcaa7fb 100644
--- a/taverna-commandline-common/src/main/java/net/sf/taverna/t2/commandline/data/InputsHandler.java
+++ b/taverna-commandline-common/src/main/java/net/sf/taverna/t2/commandline/data/InputsHandler.java
@@ -27,6 +27,7 @@
 import java.net.URL;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.nio.file.StandardOpenOption;
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -106,7 +107,11 @@
 	public Bundle registerInputs(Map<String, InputWorkflowPort> portMap,
 			CommandLineOptions options, InvocationContext context) throws InvalidOptionException,
 			ReadInputException, IOException {
-		Bundle inputDataBundle = DataBundles.createBundle();
+		Bundle inputDataBundle;
+		inputDataBundle = DataBundles.createBundle();
+		inputDataBundle.setDeleteOnClose(false);
+		System.out.println("Bundle: " + inputDataBundle.getSource());
+		
 		Path inputs = DataBundles.getInputs(inputDataBundle);
 
 		URL url;