mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
eclipse: warn about unknown nature (IDEA-94025)
This commit is contained in:
@@ -23,6 +23,7 @@ package org.jetbrains.idea.eclipse;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
@@ -32,6 +33,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class EclipseProjectFinder implements EclipseXml {
|
||||
public static void findModuleRoots(final List<String> paths, final String rootPath, @Nullable Processor<String> progressUpdater) {
|
||||
@@ -111,6 +113,25 @@ public class EclipseProjectFinder implements EclipseXml {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void collectUnknownNatures(String path, Set<String> naturesNames) {
|
||||
final File projectfile = new File(path, DOT_PROJECT_EXT);
|
||||
try {
|
||||
final Element natures = JDOMUtil.loadDocument(projectfile).getRootElement().getChild("natures");
|
||||
if (natures != null) {
|
||||
final List naturesList = natures.getChildren("nature");
|
||||
for (Object nature : naturesList) {
|
||||
final String natureName = ((Element)nature).getText();
|
||||
if (!StringUtil.isEmptyOrSpaces(natureName)) {
|
||||
naturesNames.add(natureName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
}
|
||||
naturesNames.remove("org.eclipse.jdt.core.javanature");
|
||||
}
|
||||
|
||||
public static class LinkedResource {
|
||||
private String myURI;
|
||||
private String myLocation;
|
||||
|
||||
@@ -15,7 +15,11 @@
|
||||
*/
|
||||
package org.jetbrains.idea.eclipse.importWizard;
|
||||
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationType;
|
||||
import com.intellij.notification.Notifications;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.application.ex.ApplicationInfoEx;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileChooser.FileChooser;
|
||||
@@ -166,6 +170,7 @@ public class EclipseImportBuilder extends ProjectImportBuilder<String> implement
|
||||
public boolean validate(final Project currentProject, final Project dstProject) {
|
||||
final Ref<Exception> refEx = new Ref<Exception>();
|
||||
final HashSet<String> variables = new HashSet<String>();
|
||||
final Set<String> naturesNames = new HashSet<String>();
|
||||
ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
@@ -175,6 +180,7 @@ public class EclipseImportBuilder extends ProjectImportBuilder<String> implement
|
||||
final Element classpathElement = JDOMUtil.loadDocument(classpathfile).getRootElement();
|
||||
EclipseClasspathReader.collectVariables(variables, classpathElement, path);
|
||||
}
|
||||
EclipseProjectFinder.collectUnknownNatures(path, naturesNames);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
@@ -195,6 +201,17 @@ public class EclipseImportBuilder extends ProjectImportBuilder<String> implement
|
||||
return false;
|
||||
}
|
||||
|
||||
final Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
if (!naturesNames.isEmpty()) {
|
||||
final String title = "Unknown Natures Detected";
|
||||
Notifications.Bus.notify(new Notification(title, title, "Imported projects contain unknown natures:<br>" + StringUtil.join(naturesNames, "<br>")+ "<br>" +
|
||||
"Some settings may be lost after import.", NotificationType.WARNING));
|
||||
}
|
||||
}
|
||||
};
|
||||
ApplicationManager.getApplication().invokeLater(runnable, ModalityState.NON_MODAL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user