Correctly detect multiplatform modules in run code
LanguageVersionSettings doesn't mean that the module is actually multiplatform; it only means that it _could_ be one. Use platform and information from facet instead. Also fix detection of common stdlib version and add tests for common run config.
This commit is contained in:
@@ -14,36 +14,22 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.framework
|
||||
|
||||
import com.intellij.openapi.roots.OrderRootType
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx
|
||||
import com.intellij.openapi.roots.libraries.DummyLibraryProperties
|
||||
import com.intellij.openapi.roots.libraries.Library
|
||||
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
|
||||
import com.intellij.openapi.vfs.JarFileSystem
|
||||
import com.intellij.openapi.vfs.VfsUtil
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.vfs.VirtualFileVisitor
|
||||
import com.intellij.openapi.util.io.JarUtil
|
||||
import com.intellij.openapi.vfs.*
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import org.jetbrains.kotlin.serialization.deserialization.MetadataPackageFragment
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
import java.util.jar.Attributes
|
||||
import java.util.regex.Pattern
|
||||
|
||||
object JSLibraryKind : PersistentLibraryKind<DummyLibraryProperties>("kotlin.js") {
|
||||
override fun createDefaultProperties() = DummyLibraryProperties.INSTANCE!!
|
||||
@@ -99,3 +85,15 @@ private fun detectLibraryKindFromJarContents(jarRoot: VirtualFile): PersistentLi
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
fun getLibraryJarVersion(library: Library, jarPattern: Pattern): String? {
|
||||
for (file in library.getFiles(OrderRootType.CLASSES)) {
|
||||
if (jarPattern.matcher(file.name).matches()) {
|
||||
return JarUtil.getJarAttribute(VfsUtilCore.virtualToIoFile(file), Attributes.Name.IMPLEMENTATION_VERSION)
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun getCommonRuntimeLibraryVersion(library: Library) =
|
||||
getLibraryJarVersion(library, PathUtil.KOTLIN_STDLIB_COMMON_JAR_PATTERN)
|
||||
|
||||
Reference in New Issue
Block a user