Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2014-04-19 08:15:15 -0400
committerIgor Fedorenko2014-04-20 19:04:43 -0400
commit29cf3f60e55941e95d97eaf8627877d9ff734130 (patch)
treed4dc44b757ab28eaaeb02cc0e070f6ba7e23f080
parentf68db7860dd0d0c7b03349e0dc550733a01844fa (diff)
downloadm2e-core-29cf3f60e55941e95d97eaf8627877d9ff734130.tar.gz
m2e-core-29cf3f60e55941e95d97eaf8627877d9ff734130.tar.xz
m2e-core-29cf3f60e55941e95d97eaf8627877d9ff734130.zip
432436 enforce unique maven installation names
Change-Id: I1485d036414869e5d907e47c3e73bb711cd2a07f Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizard.java13
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizardPage.java11
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationsPreferencePage.java50
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntimeManager.java20
4 files changed, 73 insertions, 21 deletions
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizard.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizard.java
index f772b8b3..82b030ce 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizard.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizard.java
@@ -11,6 +11,8 @@
package org.eclipse.m2e.core.ui.internal.preferences.launch;
+import java.util.Set;
+
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.m2e.core.embedder.MavenRuntime;
@@ -22,18 +24,15 @@ public class MavenInstallationWizard extends Wizard {
private final MavenInstallationWizardPage runtimePage;
- private MavenRuntime original;
-
private MavenRuntime result;
- public MavenInstallationWizard() {
- this.runtimePage = new MavenInstallationWizardPage(null);
+ public MavenInstallationWizard(Set<String> names) {
+ this.runtimePage = new MavenInstallationWizardPage(null, names);
setWindowTitle("New Maven Runtime");
}
- public MavenInstallationWizard(MavenRuntime runtime) {
- this.original = runtime;
- this.runtimePage = new MavenInstallationWizardPage((AbstractMavenRuntime) original);
+ public MavenInstallationWizard(MavenRuntime original, Set<String> names) {
+ this.runtimePage = new MavenInstallationWizardPage((AbstractMavenRuntime) original, names);
setWindowTitle("Edit Maven Runtime");
}
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizardPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizardPage.java
index 2cfcd5de..f38bc928 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizardPage.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizardPage.java
@@ -16,6 +16,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Set;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.viewers.ArrayContentProvider;
@@ -84,6 +85,8 @@ public class MavenInstallationWizardPage extends WizardPage {
private Button btnDirectory;
+ private Set<String> usedNames;
+
class TreeContentProvider implements ITreeContentProvider {
public void dispose() {
@@ -137,9 +140,10 @@ public class MavenInstallationWizardPage extends WizardPage {
}
}
- public MavenInstallationWizardPage(AbstractMavenRuntime original) {
+ public MavenInstallationWizardPage(AbstractMavenRuntime original, Set<String> usedNames) {
super(Messages.ExternalInstallPage_pageName);
this.original = original;
+ this.usedNames = usedNames;
setDescription(Messages.ExternalInstallPage_description);
this.extensions = original != null && original.getExtensions() != null ? original.getExtensions()
@@ -404,7 +408,10 @@ public class MavenInstallationWizardPage extends WizardPage {
return;
}
- // TODO name is unique
+ if(usedNames.contains(name.getText().trim())) {
+ setErrorMessage("The Maven installation name is already in use");
+ return;
+ }
setMessage(null);
setPageComplete(true);
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationsPreferencePage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationsPreferencePage.java
index 9a52aeb9..99f005ec 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationsPreferencePage.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationsPreferencePage.java
@@ -11,7 +11,9 @@
package org.eclipse.m2e.core.ui.internal.preferences.launch;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
@@ -41,8 +43,10 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.IMaven;
@@ -88,7 +92,7 @@ public class MavenInstallationsPreferencePage extends PreferencePage implements
protected void performDefaults() {
runtimeManager.reset();
defaultRuntime = runtimeManager.getDefaultRuntime().getName();
- runtimes = runtimeManager.getMavenRuntimes();
+ runtimes = runtimeManager.getMavenRuntimes(false);
runtimesViewer.setInput(runtimes);
refreshRuntimesViewer();
@@ -121,7 +125,7 @@ public class MavenInstallationsPreferencePage extends PreferencePage implements
new Label(composite, SWT.NONE);
defaultRuntime = runtimeManager.getDefaultRuntime().getName();
- runtimes = runtimeManager.getMavenRuntimes();
+ runtimes = runtimeManager.getMavenRuntimes(false);
runtimesViewer.setInput(runtimes);
refreshRuntimesViewer();
@@ -207,7 +211,7 @@ public class MavenInstallationsPreferencePage extends PreferencePage implements
addButton.setText(Messages.MavenInstallationsPreferencePage_btnAdd);
addButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
- MavenInstallationWizard wizard = new MavenInstallationWizard();
+ MavenInstallationWizard wizard = new MavenInstallationWizard(getForbiddenNames(null));
WizardDialog dialog = new WizardDialog(getShell(), wizard);
if(dialog.open() == Window.OK) {
runtimes.add(wizard.getResult());
@@ -223,7 +227,7 @@ public class MavenInstallationsPreferencePage extends PreferencePage implements
editButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
MavenRuntime runtime = getSelectedMavenRuntime();
- MavenInstallationWizard wizard = new MavenInstallationWizard(runtime);
+ MavenInstallationWizard wizard = new MavenInstallationWizard(runtime, getForbiddenNames(runtime));
WizardDialog dialog = new WizardDialog(getShell(), wizard);
if(dialog.open() == Window.OK) {
MavenRuntime updatedRuntime = wizard.getResult();
@@ -263,9 +267,7 @@ public class MavenInstallationsPreferencePage extends PreferencePage implements
runtimesViewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
- if(event.getElement() != null && event.getChecked()) {
- setCheckedRuntime((MavenRuntime) event.getElement());
- }
+ setCheckedRuntime((MavenRuntime) event.getElement());
}
});
Label noteLabel = new Label(composite, SWT.WRAP);
@@ -276,23 +278,48 @@ public class MavenInstallationsPreferencePage extends PreferencePage implements
noteLabel.setText(Messages.MavenInstallationsPreferencePage_lblNote);
}
+ protected Set<String> getForbiddenNames(MavenRuntime runtime) {
+ Set<String> names = new HashSet<String>();
+ for(MavenRuntime other : runtimes) {
+ if(other != runtime) {
+ names.add(other.getName());
+ }
+ }
+ return names;
+ }
+
protected void setCheckedRuntime(MavenRuntime runtime) {
runtimesViewer.setAllChecked(false);
+ if(runtime == null || !runtime.isAvailable()) {
+ runtime = getDefaultRuntime();
+ } else {
+ defaultRuntime = runtime.getName();
+ }
runtimesViewer.setChecked(runtime, true);
- defaultRuntime = runtime.getName();
}
static class RuntimesLabelProvider implements ITableLabelProvider, IColorProvider {
public String getColumnText(Object element, int columnIndex) {
AbstractMavenRuntime runtime = (AbstractMavenRuntime) element;
- if(columnIndex == 0) {
- return !runtime.isLegacy() ? runtime.getName() : null;
+ switch(columnIndex) {
+ case 0:
+ return !runtime.isLegacy() ? runtime.getName() : null;
+ case 1:
+ StringBuilder sb = new StringBuilder();
+ if(!runtime.isAvailable()) {
+ sb.append("NOT AVAILABLE ");
+ }
+ sb.append(runtime.toString());
+ return sb.toString();
}
- return runtime.toString();
+ return null;
}
public Image getColumnImage(Object element, int columnIndex) {
+ if(columnIndex == 1 && !((AbstractMavenRuntime) element).isAvailable()) {
+ return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK);
+ }
return null;
}
@@ -320,7 +347,6 @@ public class MavenInstallationsPreferencePage extends PreferencePage implements
public void removeListener(ILabelProviderListener listener) {
}
-
}
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntimeManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntimeManager.java
index 6fa3dead..98c17da8 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntimeManager.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntimeManager.java
@@ -12,9 +12,11 @@
package org.eclipse.m2e.core.embedder;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
@@ -116,6 +118,20 @@ public class MavenRuntimeManager {
return mavenRuntimes;
}
+ /**
+ * @param available is {@code true} only available runtimes are returned, all runtimes are returned if {@code false}
+ * @since 1.5
+ */
+ public List<MavenRuntime> getMavenRuntimes(boolean available) {
+ List<MavenRuntime> mavenRuntimes = new ArrayList<MavenRuntime>();
+ for(MavenRuntime mavenRuntime : getRuntimes().values()) {
+ if(!available || mavenRuntime.isAvailable()) {
+ mavenRuntimes.add(mavenRuntime);
+ }
+ }
+ return mavenRuntimes;
+ }
+
public void reset() {
preferencesLookup[0].remove(MavenPreferenceConstants.P_RUNTIMES);
preferencesLookup[0].remove(MavenPreferenceConstants.P_DEFAULT_RUNTIME);
@@ -142,8 +158,12 @@ public class MavenRuntimeManager {
public void setRuntimes(List<MavenRuntime> runtimes) {
removeRuntimePreferences();
+ Set<String> names = new HashSet<String>();
StringBuilder sb = new StringBuilder();
for(MavenRuntime runtime : runtimes) {
+ if(!names.add(runtime.getName())) {
+ throw new IllegalArgumentException();
+ }
if(runtime.isEditable()) {
AbstractMavenRuntime impl = (AbstractMavenRuntime) runtime;
if(sb.length() > 0) {

Back to the top