Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Grunberg2016-03-04 15:31:29 +0000
committerRoland Grunberg2016-03-17 01:48:22 +0000
commit35b3c523f2aa6c9ea72880fd163b65af57eecd19 (patch)
tree8d0a1fe18c22901b6960fdf3e59f7bd70e84a0b6
parentce5441e3665db7d44422c07bab2a5562d0d1c378 (diff)
downloadorg.eclipse.linuxtools-35b3c523f2aa6c9ea72880fd163b65af57eecd19.tar.gz
org.eclipse.linuxtools-35b3c523f2aa6c9ea72880fd163b65af57eecd19.tar.xz
org.eclipse.linuxtools-35b3c523f2aa6c9ea72880fd163b65af57eecd19.zip
Minor bug fixes to certain Vagrant workflows.
- Permit the use of dashes in virtual machine names - Inform user when VM name already exists and cancel VM creation - Remove previously existing Eclipse-controlled Vagrant project if the corresponding VM does not exist - State of the VM should not be used to uniquely identify it - Add missing toString() method to VagrantVM to enable proper search - Fix file dialog logic for the CreateVMPage Change-Id: I9434794559c5276d14f41b86fc8fcfaa18b36ae2 Reviewed-on: https://git.eclipse.org/r/67836 Tested-by: Hudson CI Reviewed-by: Roland Grunberg <rgrunber@redhat.com> Reviewed-on: https://git.eclipse.org/r/68579
-rw-r--r--vagrant/org.eclipse.linuxtools.vagrant.core/src/org/eclipse/linuxtools/internal/vagrant/core/VagrantVM.java9
-rw-r--r--vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/CreateVmCommandHandler.java30
-rw-r--r--vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/wizards/CreateVMPage.java27
-rw-r--r--vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/wizards/WizardMessages.properties2
4 files changed, 52 insertions, 16 deletions
diff --git a/vagrant/org.eclipse.linuxtools.vagrant.core/src/org/eclipse/linuxtools/internal/vagrant/core/VagrantVM.java b/vagrant/org.eclipse.linuxtools.vagrant.core/src/org/eclipse/linuxtools/internal/vagrant/core/VagrantVM.java
index dfd308f864..ef9029f32b 100644
--- a/vagrant/org.eclipse.linuxtools.vagrant.core/src/org/eclipse/linuxtools/internal/vagrant/core/VagrantVM.java
+++ b/vagrant/org.eclipse.linuxtools.vagrant.core/src/org/eclipse/linuxtools/internal/vagrant/core/VagrantVM.java
@@ -94,14 +94,19 @@ public class VagrantVM implements IVagrantVM {
}
@Override
+ public String toString() {
+ return "Name: " + this.name //$NON-NLS-1$
+ + "Provider : " + this.provider //$NON-NLS-1$
+ + "State : " + this.state; //$NON-NLS-1$
+ }
+
+ @Override
public boolean equals(Object o) {
if (o instanceof VagrantVM) {
VagrantVM other = (VagrantVM) o;
return id.equals(other.id())
&& name.equals(other.name())
&& provider.equals(other.provider())
- && state.equals(other.state())
- && state_desc.equals(other.state_desc())
&& directory.equals(other.directory());
}
return false;
diff --git a/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/CreateVmCommandHandler.java b/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/CreateVmCommandHandler.java
index d4bd73157f..2be7ace57a 100644
--- a/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/CreateVmCommandHandler.java
+++ b/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/commands/CreateVmCommandHandler.java
@@ -36,6 +36,7 @@ import org.eclipse.linuxtools.internal.vagrant.ui.wizards.CreateVMWizard;
import org.eclipse.linuxtools.internal.vagrant.ui.wizards.WizardMessages;
import org.eclipse.linuxtools.vagrant.core.IVagrantBox;
import org.eclipse.linuxtools.vagrant.core.IVagrantConnection;
+import org.eclipse.linuxtools.vagrant.core.IVagrantVM;
import org.eclipse.linuxtools.vagrant.core.VagrantException;
import org.eclipse.linuxtools.vagrant.core.VagrantService;
import org.eclipse.swt.widgets.Display;
@@ -82,6 +83,15 @@ public class CreateVmCommandHandler extends AbstractHandler {
monitor.beginTask(DVMessages.getFormattedString(CRATE_VM_TITLE, vmName),
IProgressMonitor.UNKNOWN);
IVagrantConnection connection = VagrantService.getInstance();
+ if (findVM(connection, vmName) != null) {
+ Display.getDefault()
+ .syncExec(() -> MessageDialog.openError(Display.getCurrent()
+ .getActiveShell(),
+ WizardMessages.getString("CreateVmCommandHandler.VMExists.title"), //$NON-NLS-1$
+ WizardMessages.getString("CreateVmCommandHandler.VMExists.msg"))); //$NON-NLS-1$
+ return Status.CANCEL_STATUS;
+ }
+
IVagrantBox box = null;
File vagrantDir;
String boxName = boxRef;
@@ -150,6 +160,17 @@ public class CreateVmCommandHandler extends AbstractHandler {
return box;
}
+ private IVagrantVM findVM(IVagrantConnection connection, String vmName) {
+ IVagrantVM vm = null;
+ for (IVagrantVM v : connection.getVMs()) {
+ if (v.name().equals(vmName)) {
+ vm = v;
+ break;
+ }
+ }
+ return vm;
+ }
+
/*
* init the folder in this bundle's state location, and ensure the
* Vagrantfile has the proper vm name and box name
@@ -159,7 +180,12 @@ public class CreateVmCommandHandler extends AbstractHandler {
String stateLoc = Activator.getDefault().getStateLocation()
.toOSString();
File vagrantDir = Paths.get(stateLoc, vmName).toFile();
- vagrantDir.mkdir();
+ // Project folder exists (but VM cannot exist here)
+ // Safe to remove the stale Vagrant project entry
+ if (!vagrantDir.mkdir()) {
+ CommandUtils.delete(vagrantDir);
+ vagrantDir.mkdir();
+ }
connection.init(vagrantDir);
Path vagrantFilePath = Paths.get(stateLoc, vmName, "Vagrantfile"); //$NON-NLS-1$
@@ -171,7 +197,7 @@ public class CreateVmCommandHandler extends AbstractHandler {
for (String line : defaultContent.split("\n")) { //$NON-NLS-1$
if (line.contains("config.vm.box")) { //$NON-NLS-1$
String defLine = line.replaceAll("config.vm.box = \".*\"", //$NON-NLS-1$
- "config.vm.define :" + vmName); //$NON-NLS-1$
+ "config.vm.define :\"" + vmName + "\""); //$NON-NLS-1$ //$NON-NLS-2$
String boxLine = line.replaceAll("config.vm.box = \".*\"", //$NON-NLS-1$
"config.vm.box = \"" + boxName + "\""); //$NON-NLS-1$ //$NON-NLS-2$
bcontent.append(defLine + '\n');
diff --git a/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/wizards/CreateVMPage.java b/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/wizards/CreateVMPage.java
index 2c3c55e751..0531bd787a 100644
--- a/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/wizards/CreateVMPage.java
+++ b/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/wizards/CreateVMPage.java
@@ -186,7 +186,7 @@ public class CreateVMPage extends WizardPage {
vgFilesearchButton.setEnabled(false);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
.grab(false, false).applyTo(vgFilesearchButton);
- vgFilesearchButton.addSelectionListener(onSearchImage());
+ vgFilesearchButton.addSelectionListener(onSearchVMFile());
customVMFileButton.addSelectionListener(
onCheckCustomVMFile(vmNameText, boxRefText, boxLocText, vgFilesearchButton, boxSearchButton));
@@ -233,25 +233,28 @@ public class CreateVMPage extends WizardPage {
};
}
- /**
- * Opens the {@link ImageSearch} dialog with current image name pre-filled.
- *
- * @return
- */
private SelectionListener onSearchImage() {
return new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent e) {
+ FileDialog fd = new FileDialog(getShell());
+ String location = fd.open();
+ if (location != null && !location.isEmpty()) {
+ model.setBoxRef(location);
+ }
+ }
+ };
+ }
+ private SelectionListener onSearchVMFile() {
+ return new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
FileDialog fd = new FileDialog(getShell());
String location = fd.open();
if (location != null && !location.isEmpty()) {
- if (location.endsWith("box")) { //$NON-NLS-1$
- model.setBoxRef(location);
- } else {
- model.setVMFile(location);
- vmFileChanged(location);
- }
+ model.setVMFile(location);
+ vmFileChanged(location);
}
}
};
diff --git a/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/wizards/WizardMessages.properties b/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/wizards/WizardMessages.properties
index 0431c0f3ca..8df038d763 100644
--- a/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/wizards/WizardMessages.properties
+++ b/vagrant/org.eclipse.linuxtools.vagrant.ui/src/org/eclipse/linuxtools/internal/vagrant/ui/wizards/WizardMessages.properties
@@ -39,6 +39,8 @@ CreateVMAdvancedComposite.DefaultKey=New Environment Variable
CreateVMAdvancedComposite.DefaultValue=Default Environment Variable Value
CreateVMAdvancedComposite.Key=Key
CreateVMAdvancedComposite.Value=Value
+CreateVmCommandHandler.VMExists.msg=A virtual machine with the same name already exists.
+CreateVmCommandHandler.VMExists.title=Virtual machine name exists
SSHVMCommandHandler.invalidCredentials=The SSH credentials for this VM are not properly defined. Please ensure that the VM has an SSH Service running.
SSHVMCommandHandler.sshError=Unable to SSH into Virtual Machine

Back to the top