From 18f454c532e98227d7d9e6fb5f2e96b04cea2db8 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Mon, 29 Jun 2015 15:05:12 +0300 Subject: [PATCH] Update binary skeletons path on every SDK update and clean up obsolete paths (PY-15499) Sometimes paths to binary skeletons in jdk.table.xml used to become corrupted or invalid. There used to be no way of fixing that since the paths had been added there only once during the SDK set up. Now we restore them every time the SDK gets updated. The paths should be in the jdk.table.xml because they are the part of SDK paths and they are required for indexing. Indexing contributors don't allow to associate paths with modules. --- .../python/sdk/PythonSdkUpdater.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java b/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java index 409f860d71fd..47ab071f2c6b 100644 --- a/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java +++ b/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java @@ -19,6 +19,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.PathManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.module.Module; @@ -34,6 +35,7 @@ import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.startup.StartupActivity; import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.StandardFileSystems; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.PathMappingSettings; import com.jetbrains.python.PyBundle; @@ -193,6 +195,7 @@ public class PythonSdkUpdater implements StartupActivity { boolean changed = addNewSysPathEntries(sdk, modificator, sysPath); changed = removeSourceRoots(sdk, modificator) || changed; changed = removeDuplicateClassRoots(sdk, modificator) || changed; + changed = updateSkeletonsPath(sdk, modificator) || changed; if (changed) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override @@ -257,6 +260,36 @@ public class PythonSdkUpdater implements StartupActivity { return false; } + /** + * Updates binary skeletons path in the Python SDK table. + */ + private static boolean updateSkeletonsPath(@NotNull Sdk sdk, @NotNull SdkModificator modificator) { + boolean changed = false; + final String skeletonsPath = PythonSdkType.getSkeletonsPath(PathManager.getSystemPath(), sdk.getHomePath()); + if (skeletonsPath != null) { + final VirtualFile skeletonsDir = StandardFileSystems.local().refreshAndFindFileByPath(skeletonsPath); + if (skeletonsDir != null) { + LOG.info("Binary skeletons directory for SDK \"" + sdk.getName() + "\" (" + sdk.getHomePath() + "): " + skeletonsDir.getPath()); + final List sourceRoots = Arrays.asList(sdk.getRootProvider().getFiles(OrderRootType.CLASSES)); + boolean skeletonsDirFound = false; + for (VirtualFile root : sourceRoots) { + if (root.equals(skeletonsDir)) { + skeletonsDirFound = true; + } + if (PythonSdkType.isSkeletonsPath(root.getPath()) && !skeletonsDirFound) { + modificator.removeRoot(root, OrderRootType.CLASSES); + changed = true; + } + } + if (!skeletonsDirFound) { + modificator.addRoot(skeletonsDir, OrderRootType.CLASSES); + changed = true; + } + } + } + return changed; + } + private static boolean wasOldRoot(@NotNull String root, @NotNull Collection oldRoots) { final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(root); if (file != null) {