Skip to content

Commit 3966f36

Browse files
committed
Reindex files with manual virtual file and index refresh
1 parent d2b948d commit 3966f36

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

idea/src/META-INF/plugin.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
<component>
4444
<implementation-class>org.jetbrains.jet.plugin.PluginBundledRegistrar</implementation-class>
4545
</component>
46+
47+
<component>
48+
<implementation-class>org.jetbrains.jet.plugin.versions.KotlinUpdatePluginComponent</implementation-class>
49+
</component>
4650
</application-components>
4751

4852
<module-components>

idea/src/org/jetbrains/jet/plugin/references/BuiltInsReferenceResolver.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
import com.intellij.openapi.components.AbstractProjectComponent;
2222
import com.intellij.openapi.project.Project;
2323
import com.intellij.openapi.startup.StartupManager;
24-
import com.intellij.openapi.vfs.VfsUtil;
25-
import com.intellij.openapi.vfs.VirtualFile;
24+
import com.intellij.openapi.vfs.*;
2625
import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
2726
import com.intellij.psi.PsiDirectory;
2827
import com.intellij.psi.PsiElement;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2010-2013 JetBrains s.r.o.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.jetbrains.jet.plugin.versions
18+
19+
import com.intellij.openapi.components.ApplicationComponent
20+
import org.jetbrains.jet.utils.PathUtil
21+
import com.intellij.openapi.vfs.JarFileSystem
22+
import com.intellij.ide.util.PropertiesComponent
23+
import org.jetbrains.jet.plugin.JetPluginUtil
24+
import com.intellij.util.indexing.FileBasedIndex
25+
import com.intellij.openapi.vfs.LocalFileSystem
26+
import java.io.File
27+
import com.intellij.openapi.vfs.VfsUtil
28+
import com.intellij.openapi.vfs.VirtualFileVisitor
29+
import com.intellij.openapi.vfs.newvfs.NewVirtualFile
30+
import com.intellij.openapi.vfs.VfsUtilCore
31+
import org.jetbrains.jet.plugin.vfilefinder.KotlinClassFileIndex
32+
33+
private val INSTALLED_KOTLIN_VERSION = "installed.kotlin.plugin.version"
34+
35+
class KotlinUpdatePluginComponent : ApplicationComponent {
36+
override fun initComponent() {
37+
val installedKotlinVersion = PropertiesComponent.getInstance()?.getValue(INSTALLED_KOTLIN_VERSION)
38+
39+
if (installedKotlinVersion == null || JetPluginUtil.getPluginVersion() != installedKotlinVersion) {
40+
val ideaPluginPaths = PathUtil.getKotlinPathsForIdeaPlugin()
41+
42+
// Force refresh jar handlers
43+
requestFullJarUpdate(ideaPluginPaths.getRuntimePath())
44+
requestFullJarUpdate(ideaPluginPaths.getRuntimeSourcesPath())
45+
46+
requestFullJarUpdate(ideaPluginPaths.getJsLibJarPath())
47+
48+
requestFullJarUpdate(ideaPluginPaths.getJdkAnnotationsPath())
49+
requestFullJarUpdate(ideaPluginPaths.getAndroidSdkAnnotationsPath())
50+
51+
// Force update indices for files under config directory
52+
val fileBasedIndex = FileBasedIndex.getInstance()!!
53+
fileBasedIndex.requestRebuild(KotlinAbiVersionIndex.INSTANCE.getName())
54+
fileBasedIndex.requestRebuild(KotlinClassFileIndex.KEY)
55+
56+
PropertiesComponent.getInstance()?.setValue(INSTALLED_KOTLIN_VERSION, JetPluginUtil.getPluginVersion())
57+
}
58+
}
59+
60+
override fun getComponentName(): String {
61+
return "ReindexBundledRuntimeComponent"
62+
}
63+
64+
override fun disposeComponent() {
65+
}
66+
67+
private fun requestFullJarUpdate(jarFilePath: File) {
68+
val localVirtualFile = LocalFileSystem.getInstance()!!.refreshAndFindFileByIoFile(jarFilePath)
69+
70+
// Build and update JarHandler
71+
val jarFile = JarFileSystem.getInstance()!!.getJarRootForLocalFile(localVirtualFile!!)
72+
VfsUtilCore.visitChildrenRecursively(jarFile!!, object : VirtualFileVisitor<Any?>() {})
73+
((jarFile as NewVirtualFile)).markDirtyRecursively()
74+
75+
jarFile.refresh(false, true)
76+
VfsUtil.markDirtyAndRefresh(false, false, true, localVirtualFile)
77+
}
78+
}

0 commit comments

Comments
 (0)