Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilos Kleint2011-03-21 13:41:55 +0000
committerMilos Kleint2011-03-21 13:41:55 +0000
commitce3aa6e1f8eac14f89f7b3096426501c061e4060 (patch)
tree5f815c92ff8d8b059bc86232608b8edd6dd1f198
parent11d77c64ab8b97b6d4c664f067c5cd4004986f39 (diff)
downloadm2e-core-ce3aa6e1f8eac14f89f7b3096426501c061e4060.tar.gz
m2e-core-ce3aa6e1f8eac14f89f7b3096426501c061e4060.tar.xz
m2e-core-ce3aa6e1f8eac14f89f7b3096426501c061e4060.zip
338799 when a project at given location is already imported, don't allow reimporting it and provide better error message
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java2
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties1
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java38
3 files changed, 40 insertions, 1 deletions
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java
index 65bfd60d..7104c4c8 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java
@@ -170,6 +170,8 @@ public class Messages extends NLS {
public static String MavenImportWizardPage_title;
+ public static String wizardImportValidatorProjectImported;
+
public static String MavenInstallationsPreferencePage_btnAdd;
public static String MavenInstallationsPreferencePage_btnEdit;
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties
index 0b5e8bfa..26fc07ae 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties
@@ -72,6 +72,7 @@ MavenImportWizard_title=Import Maven projects
MavenImportWizardPage_desc=Select Maven projects
MavenImportWizardPage_inherited=[inherited]
MavenImportWizardPage_title=Maven Projects
+wizardImportValidatorProjectImported=Project {0} is already imported into workspace
MavenInstallationsPreferencePage_btnAdd=&Add...
MavenInstallationsPreferencePage_btnEdit=&Edit...
MavenInstallationsPreferencePage_btnGlobalBrowse=&Browse...
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java
index 6d04085b..5cf721b4 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java
@@ -13,6 +13,8 @@ package org.eclipse.m2e.core.ui.internal.wizards;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -101,7 +103,7 @@ public class MavenImportWizardPage extends AbstractMavenWizardPage {
private String loadingErrorMessage;
protected MavenImportWizardPage(ProjectImportConfiguration importConfiguration, List<IWorkingSet> workingSets) {
- super("MavenProjectImportWizardPage", importConfiguration);
+ super("MavenProjectImportWizardPage", importConfiguration); //$NON-NLS-1$
this.workingSets = workingSets;
setTitle(org.eclipse.m2e.core.ui.internal.Messages.MavenImportWizardPage_title);
setDescription(org.eclipse.m2e.core.ui.internal.Messages.MavenImportWizardPage_desc);
@@ -464,6 +466,37 @@ public class MavenImportWizardPage extends AbstractMavenWizardPage {
}
return false;
}
+
+ /**
+ * this will iterate all existing projects and return true
+ * if the absolute location URI of the old (imported) and new (to-be-imported) projects match
+ * @param info
+ * @return
+ */
+ boolean isAlreadyImported(MavenProjectInfo info) {
+ if(info!=null) {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ for (IProject project : workspace.getRoot().getProjects()) {
+ URI mavenuri = info.getPomFile().getParentFile().toURI();
+ //mkleint: this is sort of heuristic blah blah code. unfortunately for some reason the
+ // URI returned by the eclipse code in project.getLocationURI() differs by the ending / character from the
+ // java.io.File code. That results in failing match of the URIs. I've blah it by removing the ending slash.
+ // please tell me there is a more sane solution!
+ if (mavenuri.toString().endsWith("/")) { //$NON-NLS-1$
+ try {
+ mavenuri = new URI(mavenuri.toString().substring(0, mavenuri.toString().length() - 1));
+ } catch(URISyntaxException ex) {
+ log.error(ex.getMessage(), ex);
+ }
+ }
+ boolean ok = project.exists() && project.getLocationURI().equals(mavenuri);
+ if (ok) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
protected AbstractProjectScanner<MavenProjectInfo> getProjectScanner() {
File root = workspaceRoot.getLocation().toFile();
@@ -513,6 +546,9 @@ public class MavenImportWizardPage extends AbstractMavenWizardPage {
if(isWorkspaceFolder(info)) {
String projectName = getImportConfiguration().getProjectName(info.getModel());
return NLS.bind(Messages.wizardImportValidatorWorkspaceFolder, projectName);
+ } else if(isAlreadyImported(info)) {
+ String projectName = getImportConfiguration().getProjectName(info.getModel());
+ return NLS.bind(Messages.wizardImportValidatorProjectImported, projectName);
} else if(isAlreadyExists(info)) {
String projectName = getImportConfiguration().getProjectName(info.getModel());
return NLS.bind(Messages.wizardImportValidatorProjectExists, projectName);

Back to the top