From 2726f7f5edab2e3cbb52cf3b09b771b6a1058fca Mon Sep 17 00:00:00 2001 From: Konstantin Tskhovrebov Date: Fri, 3 Apr 2020 15:01:24 +0300 Subject: [PATCH] Fix Klib file check. #KT-37876 --- .../src/org/jetbrains/kotlin/idea/klib/utils.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/klib/utils.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/klib/utils.kt index fa9351d1cf8..bcd1faecab0 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/klib/utils.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/klib/utils.kt @@ -5,6 +5,8 @@ package org.jetbrains.kotlin.idea.klib +import com.intellij.ide.highlighter.ArchiveFileType +import com.intellij.openapi.fileTypes.UnknownFileType import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.PsiFileFactory @@ -32,11 +34,7 @@ import java.io.IOException import java.util.* fun VirtualFile.isKlibLibraryRootForPlatform(targetPlatform: TargetPlatform): Boolean { - // The virtual file for a library packed in a ZIP file will have path like "/some/path/to/the/file.klib!/", - // and therefore will be recognized by VFS as a directory (isDirectory == true). - // So, first, let's check the extension. - val extension = extension - if (!extension.isNullOrEmpty() && extension != KLIB_FILE_EXTENSION) return false + if (!isAllowableFile()) return false // run check for library root too // this is necessary to recognize old style KLIBs that do not have components, and report tem to user appropriately @@ -49,6 +47,12 @@ fun VirtualFile.isKlibLibraryRootForPlatform(targetPlatform: TargetPlatform): Bo return children?.any { checkKlibComponent(it, requestedBuiltInsPlatform) } == true } +private fun VirtualFile.isAllowableFile(): Boolean = when { + fileType == ArchiveFileType.INSTANCE -> extension == KLIB_FILE_EXTENSION + isDirectory -> true + else -> false +} + private fun checkKlibComponent(componentFile: VirtualFile, requestedBuiltInsPlatform: BuiltInsPlatform): Boolean { val manifestFile = componentFile.findChild(KLIB_MANIFEST_FILE_NAME)?.takeIf { !it.isDirectory } ?: return false