[Esbox-commits] r2229 - in branches/work_Ed: org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core org.maemo.esbox.vm/src/org/maemo/esbox/internal/vm org.maemo.esbox.vm.qemu/src/org/maemo/esbox/internal/vm/qemu org.maemo.esbox.vm.virtualbox/src/org/maemo/esbox/internal/vm/virtualbox org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware

eswartz at garage.maemo.org eswartz at garage.maemo.org
Thu Sep 24 23:29:57 EEST 2009


Author: eswartz
Date: 2009-09-24 23:29:52 +0300 (Thu, 24 Sep 2009)
New Revision: 2229

Added:
   branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core/LaunchedMachineInfo.java
Modified:
   branches/work_Ed/org.maemo.esbox.vm.qemu/src/org/maemo/esbox/internal/vm/qemu/QemuMachineController.java
   branches/work_Ed/org.maemo.esbox.vm.virtualbox/src/org/maemo/esbox/internal/vm/virtualbox/VirtualBoxMachineController.java
   branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareMachineController.java
   branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareSettingsPreferencePage.java
   branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core/BaseLaunchableVirtualMachineController.java
   branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core/BaseVirtualMachineController.java
   branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/vm/ManualVirtualMachineController.java
Log:
Updates for OS X host, and allow "I Launched it" button to work better.

Modified: branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core/BaseLaunchableVirtualMachineController.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core/BaseLaunchableVirtualMachineController.java	2009-09-24 19:39:57 UTC (rev 2228)
+++ branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core/BaseLaunchableVirtualMachineController.java	2009-09-24 20:29:52 UTC (rev 2229)
@@ -17,7 +17,6 @@
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
@@ -33,7 +32,6 @@
 import org.maemo.mica.common.core.machine.MachineManager;
 import org.maemo.mica.common.core.machine.MachineRegistry;
 import org.maemo.mica.common.core.process.*;
-import org.maemo.mica.common.core.process.ProcessLauncherUtils.LaunchResults;
 import org.maemo.mica.common.core.sdk.ISDK;
 import org.maemo.mica.common.core.sdk.SDKManager;
 import org.maemo.mica.internal.api.common.core.SudoWrappedProcessLauncherFactory;
@@ -112,86 +110,6 @@
 	 */
 	abstract protected ProcessLauncherParameters constructLaunchParameters();
 
-	static public class LaunchedMachineInfo {
-		public LaunchedMachineInfo(
-				IVirtualMachineConfiguration configuration,
-				IProcessLauncher processLauncher) {
-			this.configuration = configuration;
-			this.launcher = processLauncher;
-			this.monitor = processLauncher.createProcessMonitor();
-			this.streamGrabber = new StringBuilderStreamTextMonitor(false);
-			this.monitor.addMonitor(streamGrabber);
-		}
-		public LaunchedMachineInfo(IStatus failedStatus) {
-			this.failedStatus = failedStatus;
-		}
-
-		public IProcessLauncher launcher;
-		public IProcessMonitor monitor;
-		public StringBuilderStreamTextMonitor streamGrabber;
-		public IVirtualMachineConfiguration configuration;
-		private IStatus failedStatus;
-		
-		public boolean isAlive() {
-			if (monitor == null)
-				return false;
-			
-			return !monitor.isCompleted();
-		}
-		
-		/**
-		 * Return an status describing the output if the machine died.
-		 * @return IStatus
-		 */
-		public IStatus checkAlive() {
-			if (isAlive())
-				return Status.OK_STATUS;
-
-			String msg;
-			if (launcher != null) {
-				LaunchResults results = new LaunchResults(launcher.getLastCreatedProcess().exitValue(),
-						streamGrabber.stdout.toString(),
-						streamGrabber.stderr.toString());
-				msg = results.reportResults("Virtual machine died unexpectedly");
-				return Activator.createErrorStatus(msg, null);
-			} else {
-				return failedStatus != null ? failedStatus : 
-					Activator.createErrorStatus("The machine was never launched", null);
-			}
-		}
-
-		/**
-		 * @return the failed
-		 */
-		public boolean isFailed() {
-			return failedStatus != null;
-		}
-		
-		/**
-		 * Indicate that this launch failed
-		 * @param status 
-		 */
-		public void setFailed(IStatus status) {
-			if (this.failedStatus == null)
-				this.failedStatus = status;
-		}
-		/**
-		 * @return the failedStatus
-		 */
-		public IStatus getFailedStatus() {
-			return failedStatus;
-		}
-		/**
-		 * 
-		 */
-		public void cancel() {
-			setFailed(CANCEL_STATUS);
-
-			// don't cancel anything else here... we can't distinguish explicit user cancel from 
-			// a nested cancellation (e.g. refresh SDKs launches machine, then the refresh is canceled).
-			// This can result in killing a perfectly fine machine
-		}
-	}
 	/**
 	 * Launch the machine and return an {@link IProcessLauncher} to track it.
 	 * The launcher is not quite ready upon return -- you need to call {@link LaunchedMachineStatus#monitor#runBlocking()}
@@ -217,91 +135,6 @@
 		return status;
 	}
 	
-	/**
-	 * Probe the machine until the connection is established.  Since this
-	 * may be never-ending (since we can't contact the machine if its network
-	 * is misconfigured), in non-unit test mode, we show a dialog where the 
-	 * user can edit the machine settings.
-	 * @param launchInfo info used to track the process, or <code>null</code> if it is not relevant or cannot be tracked
-	 * @param monitor
-	 * @return status of connection: OK or CANCEL
-	 * @throws MachineException
-	 */
-	protected IStatus probeUntilConnect(LaunchedMachineInfo launchInfo,  
-			IProgressMonitor monitor) {
-		final int PROBE_COUNT = 10;
-		
-		long timeout = System.currentTimeMillis() + 300 * 1000;
-		while (true) {
-			IStatus status;
-			
-			// see if the process died
-			if (launchInfo != null) {
-				status = launchInfo.checkAlive();
-				if (!status.isOK()) {
-					return status;
-				}
-			} else {
-				if (!isMachineRunning()) {
-					return Activator.createErrorStatus("Machine is no longer running", null);
-				}
-			}
-			
-			// spend some time
-			for (int cnt = 0; cnt < PROBE_COUNT; cnt++) {
-				monitor.worked(1);
-				if (monitor.isCanceled())
-					return CANCEL_STATUS;
-
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-					return CANCEL_STATUS;
-				}
-				
-				Display display = Display.getCurrent();
-				if (display != null) {
-					while (display.readAndDispatch()) ;
-				}
-			}
-			
-			// test the connection
-			scheduleProbe();
-			status = doProbeMachine(new SubProgressMonitor(monitor, 1));
-			if (status.isOK()) {
-				// XXX: do this more intelligently
-				// sshd starts a few moments before /etc/rc.local is run, 
-				// so kernel parameters like vdso might not be configured yet... 
-				// wait a few seconds more to avoid immediately invoking
-				// scratchbox commands and failing.
-				for (int cnt = 0; cnt < 50; cnt++) {
-					Display display = Display.getCurrent();
-					if (display != null) {
-						while (display.readAndDispatch()) ;
-					}
-					
-					monitor.worked(1);
-					if (monitor.isCanceled())
-						return CANCEL_STATUS;
-
-					try {
-						Thread.sleep(100);
-					} catch (InterruptedException e) {
-						return CANCEL_STATUS;
-					}
-				}
-				break;
-			}
-			
-			if (System.currentTimeMillis() >= timeout) {
-				return Activator.createErrorStatus("Timed out while trying to establish SSH connection to " 
-						+ getName() + "; network settings may be wrong", null);
-			}
-		}
-		
-		return Status.OK_STATUS;
-	}
-	
 	protected MachineException cancelled() {
 		return new MachineException(null, new CoreException(CANCEL_STATUS));
 	}
@@ -450,15 +283,4 @@
 	protected LaunchedMachineInfo getMachineLaunchInfo() {
 		return launchInfo;
 	}
-
-	/**
-	 * Tell if the virtual machine or engine is running.  This either detects
-	 * existing instances of the machine running on the host, or verifies
-	 * that a previously launched instance via {@link #startMachine(IProgressMonitor)} 
-	 * is still valid.
-	 * @return true if it is likely running, false if we either don't know
-	 * or if it is not running.  If unsure, return false.
-	 */
-	abstract public boolean isMachineRunning();
-	
 }

Modified: branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core/BaseVirtualMachineController.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core/BaseVirtualMachineController.java	2009-09-24 19:39:57 UTC (rev 2228)
+++ branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core/BaseVirtualMachineController.java	2009-09-24 20:29:52 UTC (rev 2229)
@@ -80,6 +80,103 @@
 		return machineConfiguration.getSSHConfiguration(); 
 	}
 	
+
+	/**
+	 * Tell if the virtual machine or engine is running.  This either detects
+	 * existing instances of the machine running on the host, or verifies
+	 * that a previously launched instance via {@link #startMachine(IProgressMonitor)} 
+	 * is still valid.
+	 * @return true if it is likely running, false if we either don't know
+	 * or if it is not running.  If unsure, return false.
+	 */
+	abstract public boolean isMachineRunning();
+	
+	/**
+	 * Probe the machine until the connection is established.  Since this
+	 * may be never-ending (since we can't contact the machine if its network
+	 * is misconfigured), in non-unit test mode, we show a dialog where the 
+	 * user can edit the machine settings.
+	 * @param launchInfo info used to track the process, or <code>null</code> if it is not relevant or cannot be tracked
+	 * @param monitor
+	 * @return status of connection: OK or CANCEL
+	 * @throws MachineException
+	 */
+	protected IStatus probeUntilConnect(LaunchedMachineInfo launchInfo,  
+			IProgressMonitor monitor) {
+		final int PROBE_COUNT = 10;
+		
+		long timeout = System.currentTimeMillis() + 300 * 1000;
+		while (true) {
+			IStatus status;
+			
+			// see if the process died
+			if (launchInfo != null) {
+				status = launchInfo.checkAlive();
+				if (!status.isOK()) {
+					return status;
+				}
+			} else {
+				if (!isMachineRunning()) {
+					return Activator.createErrorStatus("Machine is no longer running", null);
+				}
+			}
+			
+			// spend some time
+			for (int cnt = 0; cnt < PROBE_COUNT; cnt++) {
+				monitor.worked(1);
+				if (monitor.isCanceled())
+					return CANCEL_STATUS;
+
+				try {
+					Thread.sleep(100);
+				} catch (InterruptedException e) {
+					return CANCEL_STATUS;
+				}
+				
+				Display display = Display.getCurrent();
+				if (display != null) {
+					while (display.readAndDispatch()) ;
+				}
+			}
+			
+			// test the connection
+			scheduleProbe();
+			status = doProbeMachine(new SubProgressMonitor(monitor, 1));
+			if (status.isOK()) {
+				// XXX: do this more intelligently
+				// sshd starts a few moments before /etc/rc.local is run, 
+				// so kernel parameters like vdso might not be configured yet... 
+				// wait a few seconds more to avoid immediately invoking
+				// scratchbox commands and failing.
+				for (int cnt = 0; cnt < 50; cnt++) {
+					Display display = Display.getCurrent();
+					if (display != null) {
+						while (display.readAndDispatch()) ;
+					}
+					
+					monitor.worked(1);
+					if (monitor.isCanceled())
+						return CANCEL_STATUS;
+
+					try {
+						Thread.sleep(100);
+					} catch (InterruptedException e) {
+						return CANCEL_STATUS;
+					}
+				}
+				break;
+			}
+			
+			if (System.currentTimeMillis() >= timeout) {
+				return Activator.createErrorStatus("Timed out while trying to establish SSH connection to " 
+						+ getName() + "; network settings may be wrong", null);
+			}
+		}
+		
+		return Status.OK_STATUS;
+	}
+	
+
 	@Override
 	protected final IStatus doStartMachine(final IMachine machine, IProgressMonitor monitor_) throws MachineException {
 		if (monitor_ == null)
@@ -155,7 +252,15 @@
 		
 		if (retryLaunch) {
 			scheduleProbe();
-			return doProbeMachine(monitor);
+			status = probeUntilConnect(
+					null,
+					new SubProgressMonitor(monitor, 8));
+			
+			if (monitor.isCanceled() || status.getSeverity() == IStatus.CANCEL) {
+				return CANCEL_STATUS;
+			}
+			
+			return status;
 		}
 		
 		if (!doLaunch)

Added: branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core/LaunchedMachineInfo.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core/LaunchedMachineInfo.java	                        (rev 0)
+++ branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core/LaunchedMachineInfo.java	2009-09-24 20:29:52 UTC (rev 2229)
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Nokia Corporation
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Ed Swartz (Nokia) - initial API and implementation
+ *******************************************************************************/
+
+package org.maemo.esbox.internal.api.vm.core;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.maemo.esbox.internal.vm.Activator;
+import org.maemo.esbox.vm.core.IVirtualMachineConfiguration;
+import org.maemo.mica.common.core.process.IProcessLauncher;
+import org.maemo.mica.common.core.process.IProcessMonitor;
+import org.maemo.mica.common.core.process.StringBuilderStreamTextMonitor;
+import org.maemo.mica.common.core.process.ProcessLauncherUtils.LaunchResults;
+
+public class LaunchedMachineInfo {
+	public LaunchedMachineInfo(
+			IVirtualMachineConfiguration configuration,
+			IProcessLauncher processLauncher) {
+		this.configuration = configuration;
+		this.launcher = processLauncher;
+		this.monitor = processLauncher.createProcessMonitor();
+		this.streamGrabber = new StringBuilderStreamTextMonitor(false);
+		this.monitor.addMonitor(streamGrabber);
+	}
+	public LaunchedMachineInfo(IStatus failedStatus) {
+		this.failedStatus = failedStatus;
+	}
+
+	public IProcessLauncher launcher;
+	public IProcessMonitor monitor;
+	public StringBuilderStreamTextMonitor streamGrabber;
+	public IVirtualMachineConfiguration configuration;
+	private IStatus failedStatus;
+	
+	public boolean isAlive() {
+		if (monitor == null)
+			return false;
+		
+		return !monitor.isCompleted();
+	}
+	
+	/**
+	 * Return an status describing the output if the machine died.
+	 * @return IStatus
+	 */
+	public IStatus checkAlive() {
+		if (isAlive())
+			return Status.OK_STATUS;
+
+		String msg;
+		if (launcher != null) {
+			LaunchResults results = new LaunchResults(launcher.getLastCreatedProcess().exitValue(),
+					streamGrabber.stdout.toString(),
+					streamGrabber.stderr.toString());
+			msg = results.reportResults("Virtual machine died unexpectedly");
+			return Activator.createErrorStatus(msg, null);
+		} else {
+			return failedStatus != null ? failedStatus : 
+				Activator.createErrorStatus("The machine was never launched", null);
+		}
+	}
+
+	/**
+	 * @return the failed
+	 */
+	public boolean isFailed() {
+		return failedStatus != null;
+	}
+	
+	/**
+	 * Indicate that this launch failed
+	 * @param status 
+	 */
+	public void setFailed(IStatus status) {
+		if (this.failedStatus == null)
+			this.failedStatus = status;
+	}
+	/**
+	 * @return the failedStatus
+	 */
+	public IStatus getFailedStatus() {
+		return failedStatus;
+	}
+	/**
+	 * 
+	 */
+	public void cancel() {
+		setFailed(BaseLaunchableVirtualMachineController.CANCEL_STATUS);
+
+		// don't cancel anything else here... we can't distinguish explicit user cancel from 
+		// a nested cancellation (e.g. refresh SDKs launches machine, then the refresh is canceled).
+		// This can result in killing a perfectly fine machine
+	}
+}
\ No newline at end of file

Modified: branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/vm/ManualVirtualMachineController.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/vm/ManualVirtualMachineController.java	2009-09-24 19:39:57 UTC (rev 2228)
+++ branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/vm/ManualVirtualMachineController.java	2009-09-24 20:29:52 UTC (rev 2229)
@@ -53,4 +53,12 @@
 	protected IStatus doStopVirtualMachine(IProgressMonitor monitor) {
 		return Activator.createErrorStatus("The build machine must be manually stopped.", null);
 	}
+	
+	/* (non-Javadoc)
+	 * @see org.maemo.esbox.internal.api.vm.core.BaseVirtualMachineController#isMachineRunning()
+	 */
+	@Override
+	public boolean isMachineRunning() {
+		return false;
+	}
 }

Modified: branches/work_Ed/org.maemo.esbox.vm.qemu/src/org/maemo/esbox/internal/vm/qemu/QemuMachineController.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.qemu/src/org/maemo/esbox/internal/vm/qemu/QemuMachineController.java	2009-09-24 19:39:57 UTC (rev 2228)
+++ branches/work_Ed/org.maemo.esbox.vm.qemu/src/org/maemo/esbox/internal/vm/qemu/QemuMachineController.java	2009-09-24 20:29:52 UTC (rev 2229)
@@ -23,6 +23,7 @@
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.maemo.esbox.internal.api.vm.core.BaseLaunchableVirtualMachineController;
+import org.maemo.esbox.internal.api.vm.core.LaunchedMachineInfo;
 import org.maemo.esbox.vm.core.IVirtualMachine;
 import org.maemo.esbox.vm.qemu.IQemuConfiguration;
 import org.maemo.mica.common.core.MicaException;

Modified: branches/work_Ed/org.maemo.esbox.vm.virtualbox/src/org/maemo/esbox/internal/vm/virtualbox/VirtualBoxMachineController.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.virtualbox/src/org/maemo/esbox/internal/vm/virtualbox/VirtualBoxMachineController.java	2009-09-24 19:39:57 UTC (rev 2228)
+++ branches/work_Ed/org.maemo.esbox.vm.virtualbox/src/org/maemo/esbox/internal/vm/virtualbox/VirtualBoxMachineController.java	2009-09-24 20:29:52 UTC (rev 2229)
@@ -27,6 +27,7 @@
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.maemo.esbox.internal.api.vm.core.BaseLaunchableVirtualMachineController;
+import org.maemo.esbox.internal.api.vm.core.LaunchedMachineInfo;
 import org.maemo.esbox.vm.core.IVirtualMachine;
 import org.maemo.esbox.vm.core.IVirtualMachineConfiguration;
 import org.maemo.esbox.vm.virtualbox.IVirtualBoxConfiguration;

Modified: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareMachineController.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareMachineController.java	2009-09-24 19:39:57 UTC (rev 2228)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareMachineController.java	2009-09-24 20:29:52 UTC (rev 2229)
@@ -22,6 +22,7 @@
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.maemo.esbox.internal.api.vm.core.BaseLaunchableVirtualMachineController;
+import org.maemo.esbox.internal.api.vm.core.LaunchedMachineInfo;
 import org.maemo.esbox.vm.core.IVirtualMachine;
 import org.maemo.esbox.vm.vmware.IVMwareConfiguration;
 import org.maemo.mica.common.core.HostUtils;

Modified: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareSettingsPreferencePage.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareSettingsPreferencePage.java	2009-09-24 19:39:57 UTC (rev 2228)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareSettingsPreferencePage.java	2009-09-24 20:29:52 UTC (rev 2229)
@@ -98,7 +98,7 @@
 		addField(feVMWAREExeName);
 		text = feVMWAREExeName.getTextControl(getFieldEditorParent()); 
 		text.setToolTipText(MessageFormat.format(
-				"Specify the VMware \"vmrun\" executable to launch (for {0}) or the VMware Player executable.",
+				"Specify the VMware executable to launch (for {0}) or the VMware Player executable.",
 				HostUtils.isOSX() ? "Fusion" : "Player, Server, or Workstation"));
 		
 		/*



More information about the Esbox-commits mailing list