Detect K/N library kind if library is a ZIP file (common part)

Issue #KT-26730
This commit is contained in:
Dmitriy Dolovov
2018-09-11 10:48:19 +03:00
parent 8a79255176
commit 0d0929922a
2 changed files with 8 additions and 4 deletions
@@ -68,10 +68,13 @@ fun getLibraryPlatform(project: Project, library: Library): TargetPlatform {
fun detectLibraryKind(roots: Array<VirtualFile>): PersistentLibraryKind<*>? {
val jarFile = roots.firstOrNull() ?: return null
if (jarFile.fileSystem is JarFileSystem) {
return when (jarFile.getLibraryKindForJar()) {
KnownLibraryKindForIndex.COMMON -> CommonLibraryKind
KnownLibraryKindForIndex.JS -> JSLibraryKind
KnownLibraryKindForIndex.UNKNOWN -> null
// TODO: Detect library kind for Jar file using IdePlatformKindResolution.
when (jarFile.getLibraryKindForJar()) {
KnownLibraryKindForIndex.COMMON -> return CommonLibraryKind
KnownLibraryKindForIndex.JS -> return JSLibraryKind
KnownLibraryKindForIndex.UNKNOWN -> {
/* Continue detection of library kind via IdePlatformKindResolution. */
}
}
}
@@ -25,6 +25,7 @@ private val KOTLIN_LIBRARY_KIND_FILE_ATTRIBUTE: String = "kotlin-library-kind".a
ServiceManager.getService(FileAttributeService::class.java)?.register(this, 1)
}
// TODO: Detect library kind for Jar file using IdePlatformKindResolution.
fun VirtualFile.getLibraryKindForJar(): KnownLibraryKindForIndex {
if (this !is VirtualFileWithId) return detectLibraryKindFromJarContentsForIndex(this)