JS: add notification for incompatible abi version for Kotlin/JavaScript libraries

This commit is contained in:
Michael Nedzelsky
2015-06-09 16:37:15 +03:00
parent 1dd101f362
commit dac10944e0
3 changed files with 54 additions and 31 deletions
@@ -36,6 +36,7 @@ import com.intellij.psi.search.ProjectScope;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.indexing.FileBasedIndex;
import com.intellij.util.indexing.ID;
import com.intellij.util.indexing.ScalarIndexExtension;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.idea.JetPluginUtil;
@@ -62,33 +63,15 @@ public class KotlinRuntimeLibraryUtil {
@NotNull
public static Collection<VirtualFile> getLibraryRootsWithAbiIncompatibleKotlinClasses(@NotNull Project project) {
ID<Integer, Void> id = KotlinAbiVersionIndex.INSTANCE.getName();
Collection<Integer> abiVersions = FileBasedIndex.getInstance().getAllKeys(id, project);
Set<Integer> badAbiVersions = Sets.newHashSet(Collections2.filter(abiVersions, new Predicate<Integer>() {
@Override
public boolean apply(Integer abiVersion) {
return !AbiVersionUtil.isAbiVersionCompatible(abiVersion);
}
}));
Set<VirtualFile> badRoots = Sets.newHashSet();
ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(project);
for (Integer version : badAbiVersions) {
Collection<VirtualFile> indexedFiles = FileBasedIndex.getInstance().getContainingFiles(
id, version, ProjectScope.getLibrariesScope(project));
for (VirtualFile indexedFile : indexedFiles) {
VirtualFile libraryRoot = fileIndex.getClassRootForFile(indexedFile);
assert libraryRoot != null : "Only library roots were requested, " +
"and only class files should be indexed with KotlinAbiVersionIndex key. " +
"File: " + indexedFile.getPath();
badRoots.add(getLocalFile(libraryRoot));
}
}
return badRoots;
return getLibraryRootsWithAbiIncompatibleVersion(project, KotlinAbiVersionIndex.INSTANCE$);
}
@NotNull
public static Collection<VirtualFile> getLibraryRootsWithAbiIncompatibleForKotlinJs(@NotNull Project project) {
return getLibraryRootsWithAbiIncompatibleVersion(project, KotlinJavaScriptAbiVersionIndex.INSTANCE$);
}
public static void addJdkAnnotations(@NotNull Sdk sdk) {
addAnnotations(sdk, PathUtil.getKotlinPathsForIdeaPlugin().getJdkAnnotationsPath());
}
@@ -300,4 +283,36 @@ public class KotlinRuntimeLibraryUtil {
throw new AssertionError(e);
}
}
@NotNull
private static Collection<VirtualFile> getLibraryRootsWithAbiIncompatibleVersion(
@NotNull Project project,
@NotNull ScalarIndexExtension<Integer> index
) {
ID<Integer, Void> id = index.getName();
Collection<Integer> abiVersions = FileBasedIndex.getInstance().getAllKeys(id, project);
Set<Integer> badAbiVersions = Sets.newHashSet(Collections2.filter(abiVersions, new Predicate<Integer>() {
@Override
public boolean apply(Integer abiVersion) {
return !AbiVersionUtil.isAbiVersionCompatible(abiVersion);
}
}));
Set<VirtualFile> badRoots = Sets.newHashSet();
ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(project);
for (Integer version : badAbiVersions) {
Collection<VirtualFile> indexedFiles = FileBasedIndex.getInstance().getContainingFiles(
id, version, ProjectScope.getLibrariesScope(project));
for (VirtualFile indexedFile : indexedFiles) {
VirtualFile libraryRoot = fileIndex.getClassRootForFile(indexedFile);
assert libraryRoot != null : "Only library roots were requested, " +
"and only class files should be indexed with KotlinAbiVersionIndex key. " +
"File: " + indexedFile.getPath();
badRoots.add(getLocalFile(libraryRoot));
}
}
return badRoots;
}
}
@@ -61,7 +61,8 @@ class KotlinUpdatePluginComponent : ApplicationComponent {
// Force update indices for files under config directory
val fileBasedIndex = FileBasedIndex.getInstance()
fileBasedIndex.requestRebuild(KotlinAbiVersionIndex.INSTANCE.getName())
fileBasedIndex.requestRebuild(KotlinAbiVersionIndex.getName())
fileBasedIndex.requestRebuild(KotlinJavaScriptAbiVersionIndex.getName())
fileBasedIndex.requestRebuild(KotlinClassFileIndex.KEY)
fileBasedIndex.requestRebuild(KotlinJavaScriptMetaFileIndex.KEY)
@@ -51,6 +51,7 @@ import org.jetbrains.kotlin.idea.JetFileType;
import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinInProjectUtils;
import org.jetbrains.kotlin.idea.configuration.KotlinJavaModuleConfigurator;
import org.jetbrains.kotlin.idea.configuration.KotlinProjectConfigurator;
import org.jetbrains.kotlin.idea.framework.JSLibraryStdPresentationProvider;
import org.jetbrains.kotlin.idea.framework.JavaRuntimePresentationProvider;
import javax.swing.*;
@@ -85,7 +86,7 @@ public class UnsupportedAbiVersionNotificationPanelProvider extends EditorNotifi
@Nullable
public static EditorNotificationPanel checkAndCreate(@NotNull Project project) {
Collection<VirtualFile> badRoots = KotlinRuntimeLibraryUtil.getLibraryRootsWithAbiIncompatibleKotlinClasses(project);
Collection<VirtualFile> badRoots = collectBadRoots(project);
if (!badRoots.isEmpty()) {
return new UnsupportedAbiVersionNotificationPanelProvider(project).doCreate(badRoots);
}
@@ -101,8 +102,9 @@ public class UnsupportedAbiVersionNotificationPanelProvider extends EditorNotifi
@Override
public boolean apply(@Nullable Library library) {
assert library != null : "library should be non null";
VirtualFile runtimeJar = JavaRuntimePresentationProvider.getRuntimeJar(library);
return badRoots.contains(KotlinRuntimeLibraryUtil.getLocalJar(runtimeJar));
VirtualFile runtimeJar = KotlinRuntimeLibraryUtil.getLocalJar(JavaRuntimePresentationProvider.getRuntimeJar(library));
VirtualFile jsLibJar = KotlinRuntimeLibraryUtil.getLocalJar(JSLibraryStdPresentationProvider.getJsStdLibJar(library));
return badRoots.contains(runtimeJar) || badRoots.contains(jsLibJar);
}
});
@@ -161,8 +163,7 @@ public class UnsupportedAbiVersionNotificationPanelProvider extends EditorNotifi
DumbService.getInstance(project).tryRunReadActionInSmartMode(new Computable<Object>() {
@Override
public Object compute() {
Collection<VirtualFile> badRoots =
KotlinRuntimeLibraryUtil.getLibraryRootsWithAbiIncompatibleKotlinClasses(project);
Collection<VirtualFile> badRoots = collectBadRoots(project);
assert !badRoots.isEmpty() : "This action should only be called when bad roots are present";
LibraryRootsPopupModel listPopupModel = new LibraryRootsPopupModel("Unsupported format", project, badRoots);
@@ -272,4 +273,10 @@ public class UnsupportedAbiVersionNotificationPanelProvider extends EditorNotifi
});
}
@NotNull
private static Collection<VirtualFile> collectBadRoots(@NotNull Project project) {
Collection<VirtualFile> badRoots = KotlinRuntimeLibraryUtil.getLibraryRootsWithAbiIncompatibleKotlinClasses(project);
badRoots.addAll(KotlinRuntimeLibraryUtil.getLibraryRootsWithAbiIncompatibleForKotlinJs(project));
return badRoots;
}
}