|
| 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