[Esbox-commits] r2227 - 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/api/vm/ui org.maemo.esbox.vm.vmware org.maemo.esbox.vm.vmware/conf org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware org.maemo.esbox.vm.vmware/src/org/maemo/esbox/vm/vmware
eswartz at garage.maemo.org
eswartz at garage.maemo.org
Thu Sep 24 21:41:59 EEST 2009
Author: eswartz
Date: 2009-09-24 21:41:53 +0300 (Thu, 24 Sep 2009)
New Revision: 2227
Modified:
branches/work_Ed/org.maemo.esbox.vm.vmware/conf/vmware_prefs.xml
branches/work_Ed/org.maemo.esbox.vm.vmware/plugin.xml
branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareConfiguration.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/VMwarePreferenceConstants.java
branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwarePreferenceMigrator.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.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareUtils.java
branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/vm/vmware/IVMwareConfiguration.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/api/vm/ui/LaunchVirtualMachineDialog.java
Log:
-- Add an "I launched it" button to the Launch VM Dialog (so "Launch" and "Cancel" aren't the only choices)
-- Make VMware use "vmrun" if possible (for ESbox #4595)
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 18:33:57 UTC (rev 2226)
+++ branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core/BaseVirtualMachineController.java 2009-09-24 18:41:53 UTC (rev 2227)
@@ -23,6 +23,7 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
@@ -90,6 +91,7 @@
IStatus status;
boolean doLaunch;
+ boolean retryLaunch = false;
if (WorkbenchUtils.isJUnitRunning()) {
doLaunch = true;
@@ -118,28 +120,44 @@
ProductUtils.getProductName(),
name);
- final boolean launchRet[] = { false };
+ final boolean launchRet[] = { false, false };
Display.getDefault().syncExec(new Runnable() {
public void run() {
LaunchVirtualMachineDialog dialog = new LaunchVirtualMachineDialog(
- null, "Virtual Machine Needed",
+ null, "Virtual Machine Needed", null,
message,
+ MessageDialog.QUESTION,
"If the machine has already booted, you may need to synchronize the network settings or look for other problems.",
new ILookHereProvider[] {
getLookAtBuildMachinePrefs(),
getLookAtNetworkPrefs(),
getLookAtMaemoVMWare()
- });
+ },
+ new String[] {
+ "Launch now",
+ "I launched it",
+ IDialogConstants.CANCEL_LABEL
+ },
+ 0
+ );
if (likelyNetworkIssue) {
dialog.setHelpExpanded(true);
}
- launchRet[0] = dialog.open() == IDialogConstants.OK_ID;
+ int ret = dialog.open();
+ launchRet[0] = ret == 0;
+ launchRet[1] = ret == 1;
}
});
doLaunch = launchRet[0];
+ retryLaunch = launchRet[1];
}
+ if (retryLaunch) {
+ scheduleProbe();
+ return doProbeMachine(monitor);
+ }
+
if (!doLaunch)
return Status.CANCEL_STATUS;
Modified: branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/ui/LaunchVirtualMachineDialog.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/ui/LaunchVirtualMachineDialog.java 2009-09-24 18:33:57 UTC (rev 2226)
+++ branches/work_Ed/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/ui/LaunchVirtualMachineDialog.java 2009-09-24 18:41:53 UTC (rev 2227)
@@ -11,8 +11,6 @@
package org.maemo.esbox.internal.api.vm.ui;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;
import org.maemo.esbox.internal.vm.Activator;
@@ -28,17 +26,27 @@
*/
public class LaunchVirtualMachineDialog extends AbstractExpandableLookHereDialog {
- public LaunchVirtualMachineDialog(Shell parent,
- String title,
- String mainMessage,
- String helpMessage,
- ILookHereProvider[] providers) {
- super(parent, title, null, mainMessage, MessageDialog.QUESTION,
- helpMessage,
- providers,
- new String[] { "Launch", IDialogConstants.CANCEL_LABEL }, 0);
+
+ /**
+ * @param parentShell
+ * @param dialogTitle
+ * @param dialogTitleImage
+ * @param dialogMessage
+ * @param dialogImageType
+ * @param helpMessage
+ * @param providers
+ * @param dialogButtonLabels
+ * @param defaultIndex
+ */
+ public LaunchVirtualMachineDialog(Shell parentShell, String dialogTitle,
+ Image dialogTitleImage, String dialogMessage, int dialogImageType,
+ String helpMessage, ILookHereProvider[] providers,
+ String[] dialogButtonLabels, int defaultIndex) {
+ super(parentShell, dialogTitle, dialogTitleImage, dialogMessage,
+ dialogImageType, helpMessage, providers, dialogButtonLabels,
+ defaultIndex);
}
-
+
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IconAndMessageDialog#getImage()
*/
Modified: branches/work_Ed/org.maemo.esbox.vm.vmware/conf/vmware_prefs.xml
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.vmware/conf/vmware_prefs.xml 2009-09-24 18:33:57 UTC (rev 2226)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/conf/vmware_prefs.xml 2009-09-24 18:41:53 UTC (rev 2227)
@@ -10,7 +10,8 @@
See the org.maemo.mica.common.core.preference_set_provider extension.
</comment>
-
+
+ <!-- these are only used when not running vmrun -->
<entry key="VMWARE_LAUNCH_PATTERN_WIN32">"${VMWARE}" -x "${VMX_PATH}"</entry>
<entry key="VMWARE_LAUNCH_PATTERN_UNIX">"${VMWARE}" -x "${VMX_PATH}"</entry>
<entry key="VMWARE_LAUNCH_PATTERN_OSX">"${VMWARE}" "${VMX_PATH}"</entry>
Modified: branches/work_Ed/org.maemo.esbox.vm.vmware/plugin.xml
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.vmware/plugin.xml 2009-09-24 18:33:57 UTC (rev 2226)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/plugin.xml 2009-09-24 18:41:53 UTC (rev 2227)
@@ -15,7 +15,7 @@
preferenceConstantsClass="org.maemo.esbox.internal.vm.vmware.VMwarePreferenceConstants"
preferenceMigratorClass="org.maemo.esbox.internal.vm.vmware.VMwarePreferenceMigrator"
preferenceStoreBundle="org.maemo.esbox.vm.vmware"
- version="1">
+ version="2">
</preferenceSetProvider>
</extension>
<extension
Modified: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareConfiguration.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareConfiguration.java 2009-09-24 18:33:57 UTC (rev 2226)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareConfiguration.java 2009-09-24 18:41:53 UTC (rev 2227)
@@ -72,6 +72,7 @@
private static final String VMX_PATH = "vmxPath";
private static final String COMMAND_LAUNCH_PATTERN = "commandLaunchPattern";
private static final String EXECUTABLE = "executable";
+ private static final String PRODUCT = "product";
/* (non-Javadoc)
* @see org.maemo.esbox.internal.api.vm.core.BaseVirtualMachineURIQueryDecoder#decode(java.lang.String, java.lang.String)
@@ -87,6 +88,8 @@
getSettings().put(VMwarePreferenceConstants.VMWARE_LAUNCH_PATTERN, value);
} else if (key.equals(EXECUTABLE)) {
getSettings().put(VMwarePreferenceConstants.VMWARE_EXE_NAME, value);
+ } else if (key.equals(PRODUCT)) {
+ getSettings().put(VMwarePreferenceConstants.VMWARE_PRODUCT, value);
} else {
return false;
}
@@ -102,6 +105,12 @@
public void setVmxPath(String vmx) {
setPreference(VMwarePreferenceConstants.VMWARE_VMX_PATH, vmx);
}
+ public String getProduct() {
+ return getPreference(VMwarePreferenceConstants.VMWARE_PRODUCT);
+ }
+ public void setProduct(String product) {
+ setPreference(VMwarePreferenceConstants.VMWARE_PRODUCT, product);
+ }
public String getExecutable() {
return getPreference(VMwarePreferenceConstants.VMWARE_EXE_NAME);
}
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 18:33:57 UTC (rev 2226)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareMachineController.java 2009-09-24 18:41:53 UTC (rev 2227)
@@ -30,9 +30,8 @@
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;
+import org.maemo.mica.common.core.process.ProcessLauncherUtils.LaunchResults;
/**
* This is the basic implementation of a QEMU machine
@@ -61,11 +60,13 @@
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)
+ // 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().toLowerCase().contains("vmware")
|| process.getName().contains("vmware-vmx")) {
matches.add(process);
}
@@ -92,20 +93,40 @@
* @see org.maemo.esbox.internal.api.vm.core.IVirtualMachineController#isMachineRunning()
*/
public boolean isMachineRunning() {
- // we can't tell if the machine stopped running just based on the process stopping
- // (VMware may have used another instance to host the machine)
+ // We can't tell if the machine stopped running just based on the process stopping
+ // (VMware may have used another instance to host the machine, or, vmrun has exited
+ // right away)
if (launchInfo != null && launchInfo.isAlive()) {
return true;
}
- // TODO: check the product and use vmrun if possible (or not... that utility
- // is not available widely enough to be of any use)
+ // vmrun is VERY VERY SLOW on Windows, so do something quick first
+
IVMwareConfiguration config = (IVMwareConfiguration) machineConfiguration;
+ File vmx = new File(config.getVmxPath());
+ File exe = new File(config.getExecutable());
- File exe = new File(config.getExecutable());
- File vmx = new File(config.getVmxPath());
- IProcess[] runningVMwares = getRunningVMwareVMXInstances(exe, vmx);
- return (runningVMwares.length > 0);
+ if (HostUtils.isWindows()) {
+ IProcess[] runningVMwares = getRunningVMwareVMXInstances(exe, vmx);
+ if (runningVMwares.length == 0) {
+ return false;
+ }
+ }
+
+ IPath[] vmxPaths = VMwareUtils.getRunningVMXs(config);
+ if (vmxPaths != null) {
+ for (IPath vmxPath : vmxPaths) {
+ if (vmx.equals(vmxPath.toFile())) {
+ return true;
+ }
+ }
+ }
+
+ if (HostUtils.isWindows()) {
+ // we tested above that it's running; assume it is
+ return true;
+ }
+ return false;
}
/* (non-Javadoc)
@@ -115,16 +136,22 @@
protected ProcessLauncherParameters constructLaunchParameters() {
IVMwareConfiguration vmwareConfiguration = (IVMwareConfiguration) machineConfiguration;
- String launchPattern = vmwareConfiguration.getCommandLaunchPattern();
- ShellTemplateSubstitutor substitutor = new ShellTemplateSubstitutor();
+ List<String> cmdLine = VMwareUtils.createVmrunCmdLine(vmwareConfiguration,
+ "start", vmwareConfiguration.getVmxPath());
- IPath launchPath = new Path(vmwareConfiguration.getExecutable());
- substitutor.define("VMWARE", launchPath.toOSString());
- substitutor.define("VMX_PATH", new Path(vmwareConfiguration.getVmxPath()).toOSString());
-
- launchPattern = substitutor.substitute(launchPattern);
- List<String> cmdLine = CommandLineArguments.createFromHostCommandLine(launchPattern);
-
+ // if not vmrun, generate directly
+ if (cmdLine == null) {
+ cmdLine = new ArrayList<String>();
+
+ IPath launchPath = new Path(vmwareConfiguration.getExecutable());
+
+ cmdLine.add(launchPath.toOSString());
+ if (!HostUtils.isOSX()) {
+ cmdLine.add("-x");
+ }
+ cmdLine.add(new Path(vmwareConfiguration.getVmxPath()).toOSString());
+ }
+
return ProcessLauncherParameters.create(cmdLine);
}
@@ -136,19 +163,26 @@
throws MachineException {
monitor.beginTask("Starting VMware...", 10);
+
+ IVMwareConfiguration config = (IVMwareConfiguration) machineConfiguration;
+ File exe = new File(config.getExecutable());
+
+ boolean usingVMrun = VMwareUtils.findVmrunExecutable(exe.getAbsolutePath()) != null;
+
monitor.subTask("Checking existing 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;
- try {
- runningEngines = getRunningProcesses(exe, null);
- } catch (MicaException e) {
- runningEngines = new IProcess[0];
+ IProcess[] runningEngines = new IProcess[0];
+
+ if (!usingVMrun) {
+ // 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
+ try {
+ runningEngines = getRunningProcesses(exe, null);
+ } catch (MicaException e) {
+ runningEngines = new IProcess[0];
+ }
}
monitor.worked(1);
@@ -161,12 +195,39 @@
launchInfo.monitor.runNonBlocking();
- // depending on whether others were running, it's either important or not
- // if the subsequent launch succeeds
LaunchedMachineInfo watchStatus = null;
- if (runningEngines.length == 0)
- watchStatus = launchInfo;
+ if (usingVMrun) {
+ // wait for this to finish
+ launchInfo.monitor.waitForCompletion(null);
+
+ // we need a little delay between that exit
+ // and the actual launch, since it takes some time
+ // before the machine appears in the runningvms list.
+ int timeout = 5000;
+ while (timeout > 0) {
+ if (isMachineRunning())
+ break;
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ break;
+ }
+ monitor.worked(500);
+ if (monitor.isCanceled()) {
+ cancelled();
+ }
+ timeout -= 500;
+ }
+
+ } else {
+ // depending on whether others were running, it's either important or not
+ // if the subsequent launch succeeds
+
+ if (runningEngines.length == 0)
+ watchStatus = launchInfo;
+ }
+
status = probeUntilConnect(
watchStatus,
new SubProgressMonitor(monitor, 8));
@@ -199,13 +260,19 @@
if (monitor.isCanceled())
return Status.CANCEL_STATUS;
- // then be mean if we launched it ourselves
- if (launchInfo != null) {
-
- Process process = launchInfo.launcher.getLastCreatedProcess();
- if (process != null)
- process.destroy();
- launchInfo = null;
+
+ IVMwareConfiguration config = (IVMwareConfiguration) machineConfiguration;
+ File vmx = new File(config.getVmxPath());
+ LaunchResults results = VMwareUtils.launchAndRunVmrun(config, 30, "stop", vmx.getAbsolutePath());
+ if (results == null) {
+ // no vmrun; be mean if we launched it ourselves
+ if (launchInfo != null) {
+
+ Process process = launchInfo.launcher.getLastCreatedProcess();
+ if (process != null)
+ process.destroy();
+ launchInfo = null;
+ }
}
return Status.OK_STATUS;
}
Modified: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwarePreferenceConstants.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwarePreferenceConstants.java 2009-09-24 18:33:57 UTC (rev 2226)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwarePreferenceConstants.java 2009-09-24 18:41:53 UTC (rev 2227)
@@ -27,8 +27,11 @@
public static final int VERSION_MAJOR = 1;
public static final int VERSION_MINOR = 1;
- public static final String VMWARE_EXE_NAME = "VMWARE_EXE_NAME";
+ public static final String VMWARE_EXE_NAME = "VMWARE_EXE_NAME";
+ // only used when not running vmrun
public static final String VMWARE_LAUNCH_PATTERN = "VMWARE_LAUNCH_PATTERN";
+
+ public static final String VMWARE_VMRUN_NAME = "VMWARE_EXE_PATH";
public static final String VMWARE_VMX_PATH = "VMWARE_VMX_PATH";
/** product type, see VMwareUtils */
Modified: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwarePreferenceMigrator.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwarePreferenceMigrator.java 2009-09-24 18:33:57 UTC (rev 2226)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwarePreferenceMigrator.java 2009-09-24 18:41:53 UTC (rev 2227)
@@ -12,11 +12,19 @@
package org.maemo.esbox.internal.vm.vmware;
import org.eclipse.cdt.utils.WindowsRegistry;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.maemo.esbox.vm.vmware.IVMwareConfiguration;
+import org.maemo.mica.common.core.HostUtils;
+import org.maemo.mica.common.core.machine.MachineRegistry;
+import org.maemo.mica.common.core.machine.MachineUtils;
import org.maemo.mica.common.core.preferences.CorePreferenceManager;
import org.maemo.mica.common.core.preferences.PreferenceMigratorAdapter;
import java.io.File;
+import java.util.Map;
import java.util.Properties;
/**
@@ -31,11 +39,14 @@
public void adjustDefaultSettings(Properties newPropertyDefaults) {
// adjust any environment-dependent defaults
CorePreferenceManager.selectDefaultForOS(newPropertyDefaults,
- VMwarePreferenceConstants.VMWARE_LAUNCH_PATTERN);
- CorePreferenceManager.selectDefaultForOS(newPropertyDefaults,
VMwarePreferenceConstants.VMWARE_EXE_NAME);
CorePreferenceManager.selectDefaultForOS(newPropertyDefaults,
VMwarePreferenceConstants.VMWARE_VMX_PATH);
+ CorePreferenceManager.selectDefaultForOS(newPropertyDefaults,
+ VMwarePreferenceConstants.VMWARE_LAUNCH_PATTERN);
+
+ String product = HostUtils.isOSX() ? IVMwareConfiguration.PRODUCT_FUSION : IVMwareConfiguration.PRODUCT_WORKSTATION;
+ newPropertyDefaults.setProperty(VMwarePreferenceConstants.VMWARE_PRODUCT, product);
}
/* (non-Javadoc)
@@ -45,29 +56,59 @@
int oldMajor, Properties existingSettings,
Properties newPropertyDefaults) {
+ if (HostUtils.isWindows())
+ guessWindowsVMwareInfo(existingSettings, newPropertyDefaults);
+ else if (HostUtils.isOSX())
+ guessOSXVMwareInfo(existingSettings, newPropertyDefaults);
+ else
+ guessUnixVMwareInfo(existingSettings, newPropertyDefaults);
+
+ // fallback
+ String product = newPropertyDefaults.getProperty(VMwarePreferenceConstants.VMWARE_PRODUCT);
+ if (product == null)
+ product = existingSettings.getProperty(VMwarePreferenceConstants.VMWARE_PRODUCT);
+ if (product == null || product.equals(IVMwareConfiguration.PRODUCT_UNKNOWN)) {
+ product = HostUtils.isOSX() ? IVMwareConfiguration.PRODUCT_FUSION : IVMwareConfiguration.PRODUCT_WORKSTATION;
+ newPropertyDefaults.setProperty(VMwarePreferenceConstants.VMWARE_PRODUCT, product);
+ }
+ }
+
+ /**
+ * @param existingSettings
+ * @param newPropertyDefaults
+ */
+ private void guessWindowsVMwareInfo(Properties existingSettings,
+ Properties newPropertyDefaults) {
+ String product = null;
+
// this isn't strictly a conversion from an older version,
// but a change that reflects changes in any current installation
if (!existingSettings.containsKey(VMwarePreferenceConstants.VMWARE_EXE_NAME)) {
WindowsRegistry registry = WindowsRegistry.getRegistry();
if (registry != null) {
- // look for some, on Windows, where it's a hassle
- String progFiles = registry.getLocalMachineValue("SOFTWARE\\Microsoft\\Windows\\CurrentVersion", "ProgramFilesDir");
- if (progFiles == null)
- progFiles = "C:\\Program Files";
- String prefix = progFiles + "\\VMWare\\";
- String[] candidates = {
- "VMware Workstation",
- "VMware Server",
- "VMware Player"
- };
+ String installPath;
+
+ product = IVMwareConfiguration.PRODUCT_WORKSTATION;
+ installPath = registry.getLocalMachineValue("SOFTWARE\\VMware, Inc.\\VMware Workstation", "InstallPath");
+ if (installPath == null) {
+ product = IVMwareConfiguration.PRODUCT_SERVER;
+ installPath = registry.getLocalMachineValue("SOFTWARE\\VMware, Inc.\\VMware Server", "InstallPath");
+ }
+ if (installPath == null) {
+ product = IVMwareConfiguration.PRODUCT_PLAYER;
+ installPath = registry.getLocalMachineValue("SOFTWARE\\VMware, Inc.\\VMware Player", "InstallPath");
+ }
+
String[] progs = {
+ "vmrun.exe",
"vmware.exe",
"vmplayer.exe",
};
+
String exePath = null;
- for (String candidate : candidates) {
- if (exePath != null) break;
- File dir = new File(prefix + candidate);
+ if (installPath != null) {
+ // look here
+ File dir = new File(installPath);
if (dir.exists()) {
for (String prog : progs) {
File exe = new File(dir, prog);
@@ -77,19 +118,144 @@
}
}
}
+ } else {
+ // look for some, on Windows, where it's a hassle
+
+ product = null;
+
+ String progFiles = registry.getLocalMachineValue("SOFTWARE\\Microsoft\\Windows\\CurrentVersion", "ProgramFilesDir");
+ if (progFiles == null)
+ progFiles = "C:\\Program Files";
+
+ String prefix = progFiles + "\\VMWare\\";
+ String[] candidates = {
+ "VMware Workstation",
+ "VMware Server",
+ "VMware Player"
+ };
+ for (String candidate : candidates) {
+ if (exePath != null) break;
+ File dir = new File(prefix + candidate);
+ if (dir.exists()) {
+ for (String prog : progs) {
+ File exe = new File(dir, prog);
+ if (exe.exists()) {
+ exePath = exe.getAbsolutePath();
+ break;
+ }
+ }
+ }
+ }
}
+
if (exePath != null) {
newPropertyDefaults.put(VMwarePreferenceConstants.VMWARE_EXE_NAME,
exePath);
}
}
if (!existingSettings.containsKey(VMwarePreferenceConstants.VMWARE_PRODUCT)) {
- // guess from path
- String exePath = existingSettings.getProperty(VMwarePreferenceConstants.VMWARE_EXE_NAME);
+ if (product == null) {
+ // guess from path
+ String exePath = newPropertyDefaults.getProperty(VMwarePreferenceConstants.VMWARE_EXE_NAME);
+ if (exePath == null)
+ exePath = existingSettings.getProperty(VMwarePreferenceConstants.VMWARE_EXE_NAME);
+ product = VMwareUtils.guessProductFromPath(exePath);
+ }
+
newPropertyDefaults.put(VMwarePreferenceConstants.VMWARE_PRODUCT,
- VMwareUtils.guessProductFromPath(exePath));
+ product);
}
}
}
+ /**
+ * @param existingSettings
+ * @param newPropertyDefaults
+ */
+ private void guessOSXVMwareInfo(Properties existingSettings,
+ Properties newPropertyDefaults) {
+
+ if (!existingSettings.containsKey(VMwarePreferenceConstants.VMWARE_EXE_NAME)) {
+
+ String product = IVMwareConfiguration.PRODUCT_FUSION;
+
+ File exePath;
+
+ exePath = new File("/Library/Application Support/VMware Fusion/vmrun");
+ if (!exePath.exists()) {
+ exePath = new File("/Applications/VMware Fusion.app/Contents/MacOS/vmware");
+ if (!exePath.exists()) {
+ exePath = null;
+ }
+ }
+
+ if (exePath != null) {
+ newPropertyDefaults.put(VMwarePreferenceConstants.VMWARE_EXE_NAME,
+ exePath.getAbsolutePath());
+ }
+
+ if (!existingSettings.containsKey(VMwarePreferenceConstants.VMWARE_PRODUCT)) {
+ newPropertyDefaults.put(VMwarePreferenceConstants.VMWARE_PRODUCT,
+ product);
+ }
+ }
+ }
+
+ /**
+ * @param existingSettings
+ * @param newPropertyDefaults
+ */
+ private void guessUnixVMwareInfo(Properties existingSettings,
+ Properties newPropertyDefaults) {
+
+ if (!existingSettings.containsKey(VMwarePreferenceConstants.VMWARE_EXE_NAME)) {
+
+ String product = IVMwareConfiguration.PRODUCT_UNKNOWN;
+ IPath exePath = null;
+
+ try {
+ Map<String, String> confKeys = VMwareUtils.readKeyValueFile("/etc/vmware/config");
+ String installPath = confKeys.get("bindir");
+ exePath = new Path(installPath).append("vmrun");
+ if (!exePath.toFile().exists()) {
+ exePath = null;
+
+ String exe = confKeys.get("vmware.fullpath");
+ if (exe != null) {
+ exePath = new Path(exe);
+ if (!exePath.toFile().exists())
+ exePath = null;
+ }
+ }
+
+ String productName = confKeys.get("product.name");
+ if (productName != null) {
+ if (productName.toLowerCase().contains("workstation"))
+ product = IVMwareConfiguration.PRODUCT_WORKSTATION;
+ else if (productName.toLowerCase().contains("server"))
+ product = IVMwareConfiguration.PRODUCT_SERVER;
+ else if (productName.toLowerCase().contains("player"))
+ product = IVMwareConfiguration.PRODUCT_PLAYER;
+ }
+ } catch (CoreException e) {
+ product = IVMwareConfiguration.PRODUCT_WORKSTATION;
+
+ exePath = MachineUtils.findProgramOnPath(MachineRegistry.getInstance().getLocalMachine(),
+ "vmrun");
+ if (exePath == null)
+ exePath = MachineUtils.findProgramOnPath(MachineRegistry.getInstance().getLocalMachine(),
+ "vmware");
+ }
+
+ if (exePath != null) {
+ newPropertyDefaults.put(VMwarePreferenceConstants.VMWARE_EXE_NAME,
+ exePath.toOSString());
+ }
+
+ if (!existingSettings.containsKey(VMwarePreferenceConstants.VMWARE_PRODUCT)) {
+ newPropertyDefaults.put(VMwarePreferenceConstants.VMWARE_PRODUCT,
+ product);
+ }
+ }
+ }
}
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 18:33:57 UTC (rev 2226)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareSettingsPreferencePage.java 2009-09-24 18:41:53 UTC (rev 2227)
@@ -11,11 +11,14 @@
package org.maemo.esbox.internal.vm.vmware;
+import java.lang.reflect.Field;
import java.text.MessageFormat;
import org.eclipse.jface.preference.FileFieldEditor;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.maemo.esbox.internal.api.maemosdk.ui.preferences.BaseMachinePreferencePage;
import org.maemo.esbox.internal.api.vm.ui.preferences.IVirtualMachineSettingsPreferencePage;
@@ -35,8 +38,9 @@
private FileFieldEditor feVmxPath;
private StringFieldEditor feVMWAREExeName;
- private StringFieldEditor feVMWARELaunchPattern;
+ //private StringFieldEditor feVMWARELaunchPattern;
/*private*/ final BaseMachinePreferencePage vmPrefPage;
+ private RadioGroupFieldEditor feVMwareProductType;
/**
* @param preferenceStore
@@ -66,15 +70,38 @@
"Specify the full path to a VMware installation.");
*/
+ String[][] namesAndValues;
+ if (HostUtils.isOSX()) {
+ namesAndValues = new String[][] {
+ { "Fusion", IVMwareConfiguration.PRODUCT_FUSION }
+ };
+ } else {
+ namesAndValues = new String[][] {
+ { "Player", IVMwareConfiguration.PRODUCT_PLAYER },
+ { "Workstation", IVMwareConfiguration.PRODUCT_WORKSTATION },
+ { "Server", IVMwareConfiguration.PRODUCT_SERVER },
+ };
+ }
+ feVMwareProductType = new RadioGroupFieldEditor(
+ VMwarePreferenceConstants.VMWARE_PRODUCT,
+ "Product Type:",
+ 3, namesAndValues,
+ getFieldEditorParent());
+
+ Composite radioBoxControl = feVMwareProductType.getRadioBoxControl(getFieldEditorParent());
+ radioBoxControl.setToolTipText("Set the VMware product type to use.");
+ addField(feVMwareProductType);
+
feVMWAREExeName = new FileFieldEditor(
VMwarePreferenceConstants.VMWARE_EXE_NAME,
"Executable:", getFieldEditorParent());
addField(feVMWAREExeName);
text = feVMWAREExeName.getTextControl(getFieldEditorParent());
text.setToolTipText(MessageFormat.format(
- "Specify the VMware executable to launch{0}.\n\nIf the program lives in the installation directory or on the PATH, provide a bare filename.\n\nOtherwise, provide a full path to the executable.",
- HostUtils.isOSX() ? "" : " (Player, Server, or Workstation)"));
+ "Specify the VMware \"vmrun\" executable to launch (for {0}) or the VMware Player executable.",
+ HostUtils.isOSX() ? "Fusion" : "Player, Server, or Workstation"));
+ /*
feVMWARELaunchPattern = new StringFieldEditor(
VMwarePreferenceConstants.VMWARE_LAUNCH_PATTERN,
"Command pattern:",
@@ -83,8 +110,9 @@
addField(feVMWARELaunchPattern);
text = feVMWARELaunchPattern.getTextControl(getFieldEditorParent());
text.setToolTipText(
- "Specify the specific command pattern to use to launch the virtual machine.");
-
+ "Override the specific command pattern to use to launch the virtual machine.");
+ */
+
feVmxPath = new NonValidatingFileFieldEditor(
VMwarePreferenceConstants.VMWARE_VMX_PATH,
"VMX path:", getFieldEditorParent());
@@ -120,8 +148,26 @@
* @see org.maemo.esbox.internal.api.vm.ui.preferences.IVirtualMachineSettingsPreferencePage#saveTo(org.maemo.esbox.vm.core.IVirtualMachineConfiguration)
*/
public void saveTo(IVirtualMachineConfiguration config) {
- config.setCommandLaunchPattern(feVMWARELaunchPattern.getStringValue());
+ //config.setCommandLaunchPattern(feVMWARELaunchPattern.getStringValue());
config.setExecutable(feVMWAREExeName.getStringValue());
((IVMwareConfiguration) config).setVmxPath(feVmxPath.getStringValue());
+ String product = getCurrentProductName();
+ ((IVMwareConfiguration) config).setProduct(product);
}
+
+ /**
+ * @return
+ */
+ private String getCurrentProductName() {
+ // horrible horrible private fields
+ Field field;
+ try {
+ field = RadioGroupFieldEditor.class.getDeclaredField("value");
+ field.setAccessible(true);
+
+ return (String) field.get(feVMwareProductType);
+ } catch (Exception e) {
+ return null;
+ }
+ }
}
Modified: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareUtils.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareUtils.java 2009-09-24 18:33:57 UTC (rev 2226)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/internal/vm/vmware/VMwareUtils.java 2009-09-24 18:41:53 UTC (rev 2227)
@@ -18,15 +18,31 @@
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.cdt.utils.WindowsRegistry;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.maemo.esbox.vm.vmware.IVMwareConfiguration;
+import org.maemo.mica.common.core.HostUtils;
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.TimeoutProgressMonitor;
+import org.maemo.mica.common.core.machine.MachineRegistry;
+import org.maemo.mica.common.core.process.CommandLineArguments;
+import org.maemo.mica.common.core.process.IProcessLauncher;
+import org.maemo.mica.common.core.process.ProcessLauncherParameters;
+import org.maemo.mica.common.core.process.ProcessLauncherUtils;
+import org.maemo.mica.common.core.process.ShellTemplateSubstitutor;
+import org.maemo.mica.common.core.process.ProcessLauncherUtils.LaunchResults;
import com.nokia.cpp.internal.api.utils.core.FileUtils;
@@ -36,17 +52,6 @@
*
*/
public class VMwareUtils {
- /** unknown product */
- public static String PRODUCT_UNKNOWN = "unknown";
- /** VMware Player */
- public static String PRODUCT_PLAYER = "player";
- /** VMware Fusion */
- public static String PRODUCT_FUSION = "fusion";
- /** VMware Workstation (note: value is special) */
- public static String PRODUCT_WORKSTATION = "ws";
- /** VMware Server (note: value is special) */
- public static String PRODUCT_SERVER = "server";
-
public static String NETWORK_CONFIG_HOSTONLY = "hostonly";
public static String NETWORK_CONFIG_NAT = "nat";
public static String NETWORK_CONFIG_BRIDGED = "bridged";
@@ -101,16 +106,14 @@
return addresses;
}
- private static final Pattern VMX_VARIABLE = Pattern.compile("\\s*(\\S+)\\s*=\\s*\"(.*)\"");
- public static Map<String, String> readVMXFile(String vmx) throws CoreException {
- if (!vmx.toLowerCase().endsWith(".vmx"))
- throw new CoreException(Activator.createErrorStatus("This does not look like a VMX file: " + vmx, null));
-
- String text = new String(FileUtils.readFileContents(new File(vmx), null));
+ private static final Pattern KEY_VALUE_PATTERN = Pattern.compile("\\s*(\\S+)\\s*=\\s*\"(.*)\"");
+
+ public static Map<String, String> readKeyValueFile(String file) throws CoreException {
+ String text = new String(FileUtils.readFileContents(new File(file), null));
String[] lines = text.split("(\r\n|\r|\n)");
Map<String, String> settings = new LinkedHashMap<String, String>();
for (String line : lines) {
- Matcher matcher = VMX_VARIABLE.matcher(line);
+ Matcher matcher = KEY_VALUE_PATTERN.matcher(line);
if (matcher.matches()) {
settings.put(matcher.group(1), matcher.group(2));
}
@@ -118,6 +121,13 @@
return settings;
}
+ public static Map<String, String> readVMXFile(String vmx) throws CoreException {
+ if (!vmx.toLowerCase().endsWith(".vmx"))
+ throw new CoreException(Activator.createErrorStatus("This does not look like a VMX file: " + vmx, null));
+
+ return readKeyValueFile(vmx);
+ }
+
/**
* Get the first network configuration
* @param vmxSettings
@@ -211,16 +221,136 @@
*/
public static String guessProductFromPath(String exePath) {
if (exePath == null)
- return PRODUCT_UNKNOWN;
+ return IVMwareConfiguration.PRODUCT_UNKNOWN;
String lower = exePath.toLowerCase();
if (lower.contains("player"))
- return PRODUCT_PLAYER;
+ return IVMwareConfiguration.PRODUCT_PLAYER;
if (lower.contains("server"))
- return PRODUCT_SERVER;
+ return IVMwareConfiguration.PRODUCT_SERVER;
if (lower.contains("workstation"))
- return PRODUCT_WORKSTATION;
+ return IVMwareConfiguration.PRODUCT_WORKSTATION;
if (lower.contains("fusion"))
- return PRODUCT_FUSION;
- return PRODUCT_UNKNOWN;
+ return IVMwareConfiguration.PRODUCT_FUSION;
+ return IVMwareConfiguration.PRODUCT_UNKNOWN;
}
+
+ /**
+ * Get the path to vmrun from the path either to vmware or vmrun itself.
+ * @param path the full path to an executable
+ * @return updated path to vmrun, or <code>null</code> if we can't find it.
+ */
+ public static File findVmrunExecutable(String executablePath) {
+ File exefile = new File(executablePath);
+ if (HostUtils.isOSX()) {
+ // vmrun is jammed in a different location
+ if (exefile.getName().equals("vmrun") && exefile.exists()) {
+ return exefile;
+ }
+
+ for (String productName : executablePath.split("/")) {
+ if (productName.toLowerCase().contains("vmware")
+ && productName.endsWith(".app")) {
+ productName = productName.substring(0, productName.length() - 4);
+ File runFile = new File("/Library/Application Support/" + productName + "/vmrun");
+ if (runFile.exists()) {
+ return runFile;
+ }
+ }
+ }
+ }
+
+ // fall through in case OS X ever follows other OS patterns
+ if (exefile.exists()) {
+ if (exefile.getName().contains("vmrun")) {
+ return exefile;
+ }
+
+ File runFile = new File(exefile.getParentFile(), "vmrun");
+ if (HostUtils.isWindows()) {
+ runFile = new File(runFile.getAbsolutePath() + ".exe");
+ }
+
+ if (runFile.exists()) {
+ return runFile;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Create a command line that launches vmrun.
+ * @return command line
+ */
+ public static List<String> createVmrunCmdLine(IVMwareConfiguration configuration,
+ String command, String... arguments) {
+ String launchPattern = "\"${VMWARE_EXECUTABLE}\" -T ${VMWARE_PRODUCT} ${COMMAND} ${ARGUMENTS}";
+ ShellTemplateSubstitutor substitutor = new ShellTemplateSubstitutor();
+
+ File vmrun = VMwareUtils.findVmrunExecutable(configuration.getExecutable());
+ if (vmrun == null)
+ return null;
+
+ substitutor.define("VMWARE_EXECUTABLE", vmrun.getAbsolutePath());
+ substitutor.define("VMWARE_PRODUCT", configuration.getProduct());
+ substitutor.define("COMMAND", command);
+ substitutor.define("ARGUMENTS", CommandLineArguments.toCommandLine(Arrays.asList(arguments)));
+
+ launchPattern = substitutor.substitute(launchPattern);
+ List<String> cmdLine = CommandLineArguments.createFromHostCommandLine(launchPattern);
+ return cmdLine;
+ }
+
+
+ /**
+ * Run vmrun for the given command and arguments, packaging results.
+ * @param command
+ * @param arguments
+ * @param timeout in seconds
+ * @return Results if ran, else <code>null</code> if no vmrun known or failed to launch (error logged)
+ */
+ public static LaunchResults launchAndRunVmrun(IVMwareConfiguration configuration, int timeout,
+ String command, String... arguments) {
+ List<String> cmdLine = createVmrunCmdLine(configuration, command, arguments);
+ if (cmdLine == null) {
+ return null;
+ }
+ LaunchResults results = null;
+ try {
+ IProcessLauncher processLauncher = MachineRegistry.getInstance().getLocalMachine().getProcessLauncherFactory().createProcessLauncher(
+ ProcessLauncherParameters.create(cmdLine));
+ results = ProcessLauncherUtils.launchAndReadStandardStreams(
+ processLauncher, new TimeoutProgressMonitor(timeout * 1000));
+ } catch (MicaException e) {
+ Activator.getErrorLogger().logError("Failed to run vmrun tool", e);
+ }
+ return results;
+ }
+
+ /**
+ * Get the list of running machines.
+ * @return array of running VMXs, or <code>null</code> if vmrun can
+ */
+ public static IPath[] getRunningVMXs(IVMwareConfiguration config) {
+ LaunchResults results = launchAndRunVmrun(config, 60, "list");
+ if (results == null)
+ return null;
+
+ if (results.exitCode != 0) {
+ Activator.getErrorLogger().logError(
+ results.reportResults("Failed to list running virtual machines"),
+ null);
+ }
+
+ List<IPath> vmxPaths = new ArrayList<IPath>();
+ for (String line : results.getStdoutLines()) {
+ IPath vmxPath = new Path(line);
+ if (vmxPath.toFile().exists()) {
+ vmxPaths.add(vmxPath);
+ }
+ }
+ return (IPath[]) vmxPaths.toArray(new IPath[vmxPaths.size()]);
+ }
+
+
}
Modified: branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/vm/vmware/IVMwareConfiguration.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/vm/vmware/IVMwareConfiguration.java 2009-09-24 18:33:57 UTC (rev 2226)
+++ branches/work_Ed/org.maemo.esbox.vm.vmware/src/org/maemo/esbox/vm/vmware/IVMwareConfiguration.java 2009-09-24 18:41:53 UTC (rev 2227)
@@ -24,6 +24,17 @@
*/
public interface IVMwareConfiguration extends IVirtualMachineConfiguration {
+ /** unknown product */
+ public static String PRODUCT_UNKNOWN = "unknown";
+ /** VMware Player */
+ public static String PRODUCT_PLAYER = "player";
+ /** VMware Fusion */
+ public static String PRODUCT_FUSION = "fusion";
+ /** VMware Workstation (note: value is special) */
+ public static String PRODUCT_WORKSTATION = "ws";
+ /** VMware Server (note: value is special) */
+ public static String PRODUCT_SERVER = "server";
+
/** Get the VMX path
* @return full path to *.vmx file
*/
@@ -35,4 +46,26 @@
*/
void setVmxPath(String path);
+ /**
+ * Get the VMware product type
+ * @return String
+ * @value {@value #PRODUCT_FUSION}
+ * @value {@value #PRODUCT_PLAYER}
+ * @value {@value #PRODUCT_SERVER}
+ * @value {@value #PRODUCT_WORKSTATION}
+ * @value {@value #PRODUCT_UNKNOWN}
+ */
+ String getProduct();
+
+ /**
+ * Set the VMware product type
+ * @param type String
+ * @value {@value #PRODUCT_FUSION}
+ * @value {@value #PRODUCT_PLAYER}
+ * @value {@value #PRODUCT_SERVER}
+ * @value {@value #PRODUCT_WORKSTATION}
+ * @value {@value #PRODUCT_UNKNOWN}
+ */
+ void setProduct(String product);
+
}
More information about the Esbox-commits
mailing list