Fix Klib file check.

#KT-37876
This commit is contained in:
Konstantin Tskhovrebov
2020-04-03 15:01:24 +03:00
committed by Ilya Matveev
parent f7f7d237e0
commit 2726f7f5ed
@@ -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