Remove old js during configuring new one

This commit is contained in:
Nikolay Krasko
2013-03-24 23:20:12 +04:00
parent 9a4ab3546b
commit 14a6cf3c8f
3 changed files with 47 additions and 7 deletions
@@ -47,7 +47,7 @@ public class FrameworksCompatibilityUtils {
for (OrderEntry entry : rootModel.getOrderEntries()) {
if (!(entry instanceof LibraryOrderEntry)) continue;
final Library library = ((LibraryOrderEntry)entry).getLibrary();
Library library = ((LibraryOrderEntry)entry).getLibrary();
if (library == null) continue;
for (LibraryKind kind : kinds) {
@@ -57,15 +57,36 @@ public class FrameworksCompatibilityUtils {
}
}
if (!existingEntries.isEmpty()) {
int result = Messages.showYesNoDialog(
String.format("Current module is already configured with '%s' framework.\nDo you want to remove it?", frameworkType.getPresentableName()),
"Framework Conflict",
Messages.getWarningIcon());
removeWithConfirm(rootModel, existingEntries,
String.format("Current module is already configured with '%s' framework.\nDo you want to remove it?",
frameworkType.getPresentableName()),
"Framework Conflict");
}
public static void suggestRemoveOldJsLibrary(@NotNull ModifiableRootModel rootModel) {
List<OrderEntry> oldJsLibraries = new ArrayList<OrderEntry>();
for (OrderEntry entry : rootModel.getOrderEntries()) {
if (!(entry instanceof LibraryOrderEntry)) continue;
Library library = ((LibraryOrderEntry)entry).getLibrary();
if (library == null) continue;
if (JSLibraryStdPresentationProvider.detectOld(library)) {
oldJsLibraries.add(entry);
}
}
removeWithConfirm(rootModel, oldJsLibraries,
"Current module is configured with old js library.\nDo you want to remove it?",
"Old JS Library");
}
private static void removeWithConfirm(ModifiableRootModel rootModel, List<OrderEntry> orderEntries, String message, String title) {
if (!orderEntries.isEmpty()) {
int result = Messages.showYesNoDialog(message, title, Messages.getWarningIcon());
if (result == 0) {
for (OrderEntry entry : existingEntries) {
for (OrderEntry entry : orderEntries) {
rootModel.removeOrderEntry(entry);
}
}
@@ -68,6 +68,8 @@ public class JSFrameworkSupportProvider extends FrameworkSupportInModuleProvider
rootModel,
new JavaRuntimeLibraryDescription(),
JavaFrameworkType.getInstance());
FrameworksCompatibilityUtils.suggestRemoveOldJsLibrary(rootModel);
}
};
}
@@ -17,7 +17,9 @@
package org.jetbrains.jet.plugin.framework;
import com.intellij.framework.library.LibraryVersionProperties;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.JarVersionDetectionUtil;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryPresentationProvider;
import com.intellij.openapi.vfs.JarFile;
import com.intellij.openapi.vfs.JarFileSystem;
@@ -71,4 +73,19 @@ public class JSLibraryStdPresentationProvider extends LibraryPresentationProvide
return null;
}
/**
* Detect js standard library according to M5.1 rules.
*/
public static boolean detectOld(@NotNull Library library) {
if (library.getFiles(OrderRootType.CLASSES).length == 0) {
for (VirtualFile file : library.getFiles(OrderRootType.SOURCES)) {
if (file.getName().equals(PathUtil.JS_LIB_JAR_NAME)) {
return true;
}
}
}
return false;
}
}