[Esbox-commits] r2191 - branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware
eswartz at garage.maemo.org
eswartz at garage.maemo.org
Thu Sep 17 19:38:48 EEST 2009
Author: eswartz
Date: 2009-09-17 19:38:47 +0300 (Thu, 17 Sep 2009)
New Revision: 2191
Modified:
branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareMachineController.java
Log:
Make running VMware detection smarter on OS X, where a separate process holds onto the *.vmx file.
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-16 21:06:07 UTC (rev 2190)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareMachineController.java 2009-09-17 16:38:47 UTC (rev 2191)
@@ -12,6 +12,7 @@
import java.io.File;
+import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.IPath;
@@ -26,7 +27,9 @@
import org.maemo.mica.common.core.HostUtils;
import org.maemo.mica.common.core.MicaException;
import org.maemo.mica.common.core.machine.IProcess;
+import org.maemo.mica.common.core.machine.IProcessLister;
import org.maemo.mica.common.core.machine.MachineException;
+import org.maemo.mica.common.core.machine.MachineRegistry;
import org.maemo.mica.common.core.process.CommandLineArguments;
import org.maemo.mica.common.core.process.ProcessLauncherParameters;
import org.maemo.mica.common.core.process.ShellTemplateSubstitutor;
@@ -45,6 +48,46 @@
super("VMware", configuration);
}
+ /**
+ * Try to detect VMware running with the given vmx.
+ * @param program
+ * @param vmx
+ * @return list of possible matches
+ */
+ protected IProcess[] getRunningVMwareVMXInstances(File program, File vmx) {
+ IProcessLister processLister = MachineRegistry.getInstance().getLocalMachine().getProcessLister();
+ List<IProcess> allProcesses = processLister.getProcesses(null);
+
+ List<IProcess> matches = new ArrayList<IProcess>();
+
+ // First, see if we find the vmx referenced.
+ // (On OS X, a separate process handles the VMX itself, so it
+ // won't necessarily be the program we expect)
+ for (IProcess process : allProcesses) {
+ if (process.getCommandLine().contains(vmx.getName())) {
+ if (process.getName().contains(program.getName())
+ || process.getName().contains("vmware-vmx")) {
+ matches.add(process);
+ }
+ }
+ }
+
+ if (!matches.isEmpty())
+ return (IProcess[]) matches.toArray(new IProcess[matches.size()]);
+
+ // If on Windows, we'll never find the match, since command
+ // lines are empty. Be looser.
+ if (HostUtils.isWindows()) {
+ for (IProcess process : allProcesses) {
+ if (process.getName().contains(program.getName())) {
+ matches.add(process);
+ }
+ }
+ }
+
+ return (IProcess[]) matches.toArray(new IProcess[matches.size()]);
+ }
+
/* (non-Javadoc)
* @see org.maemo.esbox.internal.api.vm.core.IVirtualMachineController#isMachineRunning()
*/
@@ -55,28 +98,14 @@
return true;
}
- try {
- // TODO: check the product and use vmrun if possible (or not... that utility
- // is not available widely enough to be of any use)
- IVMwareConfiguration config = (IVMwareConfiguration) machineConfiguration;
-
- File exe = new File(config.getExecutable());
- IProcess[] runningVMwares = getRunningProcesses(exe, null);
- if (runningVMwares.length == 0)
- return false;
-
- if (!HostUtils.isWindows()) {
- // we can't tell anything on Windows
- File vmx = new File(config.getVmxPath());
- IProcess[] runningExactInstances = getRunningProcesses(exe, vmx);
- return runningExactInstances.length > 0;
- } else {
- return true;
- }
- } catch (MicaException e) {
- Activator.getErrorLogger().logError("Can't check running VMWare processes", e);
- return false;
- }
+ // TODO: check the product and use vmrun if possible (or not... that utility
+ // is not available widely enough to be of any use)
+ IVMwareConfiguration config = (IVMwareConfiguration) machineConfiguration;
+
+ File exe = new File(config.getExecutable());
+ File vmx = new File(config.getVmxPath());
+ IProcess[] runningVMwares = getRunningVMwareVMXInstances(exe, vmx);
+ return (runningVMwares.length > 0);
}
/* (non-Javadoc)
@@ -109,7 +138,10 @@
monitor.beginTask("Starting VMware...", 10);
monitor.subTask("Checking existing VMware instances...");
- // first, see if we recognize any other VMware instances
+ // First, see if we recognize any other VMware instances at all.
+ // We don't care about our vmx itself, but for the fact that
+ // the new process exits immediately if the executable is
+ // already running
IVMwareConfiguration config = (IVMwareConfiguration) machineConfiguration;
File exe = new File(config.getExecutable());
IProcess[] runningEngines;
More information about the Esbox-commits
mailing list