[Esbox-commits] r1906 - in branches/work_Ed: org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests

eswartz at garage.maemo.org eswartz at garage.maemo.org
Thu Jul 30 18:47:37 EEST 2009


Author: eswartz
Date: 2009-07-30 18:47:20 +0300 (Thu, 30 Jul 2009)
New Revision: 1906

Modified:
   branches/work_Ed/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1ProcessLauncher.java
   branches/work_Ed/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/TestSB1ProcessLauncher.java
Log:
Fix ESbox #4350.  Number sequential run.sh scripts so we can run simultaneous processes under SB1.

Modified: branches/work_Ed/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1ProcessLauncher.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1ProcessLauncher.java	2009-07-30 14:06:36 UTC (rev 1905)
+++ branches/work_Ed/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1ProcessLauncher.java	2009-07-30 15:47:20 UTC (rev 1906)
@@ -13,6 +13,7 @@
 import org.eclipse.core.filesystem.EFS;
 import org.eclipse.core.filesystem.IFileStore;
 import org.eclipse.core.runtime.*;
+import org.maemo.esbox.internal.scratchbox.sb1.Activator;
 import org.maemo.esbox.internal.scratchbox.sb1.core.SB1PreferenceConstants;
 import org.maemo.esbox.internal.scratchbox.sb1.core.Scratchbox1SDK;
 import org.maemo.esbox.internal.scratchbox.sb1.core.Scratchbox1SDKTarget;
@@ -39,15 +40,19 @@
 public class Scratchbox1ProcessLauncher extends AbstractSDKTargetProcessLauncher implements
 		IProcessLauncher {
 
+	private static int gRunScriptCounter;
+	
 	/**
 	 * The name of a file copied from the plugin to the sb environment
 	 * which we generate to wrap the program. 
 	 */
-	private static final String RUN_SCRIPT_NAME = "run.sh";
+	private static final String RUN_SCRIPT_NAME = "run";
 
 	private Scratchbox1SDKTarget sdkTarget;
 
 	private String runScriptContents;
+
+	private String runScriptName;
 	public Scratchbox1ProcessLauncher(Scratchbox1SDKTarget sdkTarget,
 			ProcessLauncherParameters params) {
 		super(params, sdkTarget);
@@ -73,7 +78,12 @@
 		
 		// it better not be null
 		substitutor.define("RUN_SCRIPT_DIRECTORY", targetRunScriptPath.toPortableString());
-		substitutor.define("RUN_SCRIPT", RUN_SCRIPT_NAME);
+		
+		// hack: for unit tests: we won't run #setupForLaunch() first
+		if (runScriptName == null) 
+			runScriptName = "run.sh";
+		
+		substitutor.define("RUN_SCRIPT", runScriptName);
 
 		// get the Scratchbox invocation pattern
 		String commandPattern = sdkTarget
@@ -122,8 +132,24 @@
 		
 		IPath runScriptLocation = getRunScriptLocation(sdkTarget);
 		
-		IFileStore store = sdkTarget.getMachine().getFileSystemAccess().getFileStore(
-				runScriptLocation.append(RUN_SCRIPT_NAME));
+		// make a unique run.sh script name, so we can run multiple programs simultaneously
+		runScriptName = RUN_SCRIPT_NAME + (gRunScriptCounter++) + ".sh";
+		
+		final IFileStore store = sdkTarget.getMachine().getFileSystemAccess().getFileStore(
+				runScriptLocation.append(runScriptName));
+
+		// remove the script when we're done
+		queueStreamMonitor(new StreamMonitorAdapter() {
+			@Override
+			public void processExited(int exitCode) {
+				try {
+					store.delete(0, null);
+				} catch (CoreException e) {
+					Activator.getErrorLogger().logError("Error removing  " + runScriptName, e);
+				}
+			}
+		});
+		
 		try {
 			store.getParent().mkdir(0, null);
 			

Modified: branches/work_Ed/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/TestSB1ProcessLauncher.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/TestSB1ProcessLauncher.java	2009-07-30 14:06:36 UTC (rev 1905)
+++ branches/work_Ed/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/TestSB1ProcessLauncher.java	2009-07-30 15:47:20 UTC (rev 1906)
@@ -26,7 +26,9 @@
 import org.maemo.mica.common.core.process.CommandLineArguments;
 import org.maemo.mica.common.core.process.IProcessLauncher;
 import org.maemo.mica.common.core.process.IProcessLauncherFactory;
+import org.maemo.mica.common.core.process.IProcessMonitor;
 import org.maemo.mica.common.core.process.ProcessLauncherParameters;
+import org.maemo.mica.common.core.process.StreamLineMonitorAdapter;
 import org.maemo.mica.common.core.process.ProcessLauncherUtils.LaunchResults;
 import org.maemo.mica.common.core.sdk.ISDK;
 import org.maemo.mica.common.core.sdk.ISDKProvider;
@@ -198,5 +200,46 @@
 			}
 		});
 	}
+	
+	@Test
+	public void testSimultaneousProcesses() throws Exception {
+		runOverTargets(new IRunner() {
+			
+			public void run(ISDKTarget target) throws Exception {
+				IProcessLauncher launcher = target.getProcessLauncherFactory().createProcessLauncher(
+						ProcessLauncherParameters.create("sh", "-c", "sleep 10; echo a b c d e f g h i j k l m n o p q r s t u v w x y z"));
+				
+				final String[] gotLine = { null };
+				StreamLineMonitorAdapter echoChecker = new StreamLineMonitorAdapter() {
+					public void handleLine(String line, boolean errorStream) throws InterruptedException {
+						gotLine[0] = line;
+					}
+				};
+				
+				// launch in background
+				launcher.queueStreamMonitor(echoChecker);
+				launcher.createProcess(null);
+				IProcessMonitor monitor = launcher.createProcessMonitor();
+				monitor.runNonBlocking();
+				
+				// now, launch something else
+				LaunchResults results = createAndLaunchStockProcessForScript(
+						target, null, "ls", null);
 
+				assertEquals(0, results.exitCode);
+				assertEquals("", results.stderr.toString());
+				assertTrue(results.toString().length() > 0);
+				
+				// now, wait for the other one to finish
+
+				monitor.waitForCompletion(null);
+				assertEquals(0, monitor.getExitValue());
+				
+				// if this doesn't match, it should be some random garbage
+				// from another process or a bash shell error
+				assertEquals("a b c d e f g h i j k l m n o p q r s t u v w x y z", gotLine[0]);
+			}
+		});
+	}
+
 }



More information about the Esbox-commits mailing list