Kotlin JPS plugin: drop intellij-core dependency

Drop dependency because
https://youtrack.jetbrains.com/issue/IDEA-292483/UnsupportedClassVersionError-when-trying-to-run-JUnit5-unit-test#focus=Comments-27-6034750.0-0

IDEA plans to drop `PathUtil` from JPS classpath, we should prepare to
that

`KotlinFacetSettingsProvider` isn't used in jps so it was moved into
intellij repo. It was moved to
`community/plugins/kotlin/idea/src/org/jetbrains/kotlin/config/KotlinFacetSettingsProvider.kt`
path (so you can find it git history)

Review: KT-MR-6195
This commit is contained in:
Nikita Bobko
2022-04-25 19:08:30 +02:00
parent 1fc7fbed79
commit c1f2d66ed8
9 changed files with 33 additions and 46 deletions
@@ -11,6 +11,7 @@ val Project.intellijVersion
get() = rootProject.extra["versions.intellijSdk"] get() = rootProject.extra["versions.intellijSdk"]
fun Project.intellijCore() = dependencies.project(":dependencies:intellij-core") fun Project.intellijCore() = dependencies.project(":dependencies:intellij-core")
fun Project.intellijUtilRt() = "com.jetbrains.intellij.platform:util-rt:$intellijVersion"
fun Project.jpsModel() = "com.jetbrains.intellij.platform:jps-model:$intellijVersion" fun Project.jpsModel() = "com.jetbrains.intellij.platform:jps-model:$intellijVersion"
fun Project.jpsModelSerialization() = "com.jetbrains.intellij.platform:jps-model-serialization:$intellijVersion" fun Project.jpsModelSerialization() = "com.jetbrains.intellij.platform:jps-model-serialization:$intellijVersion"
+2 -1
View File
@@ -13,7 +13,8 @@ dependencies {
api(project(":compiler:frontend.java")) api(project(":compiler:frontend.java"))
api(project(":js:js.frontend")) api(project(":js:js.frontend"))
api(project(":native:frontend.native")) api(project(":native:frontend.native"))
compileOnly(intellijCore()) compileOnly(intellijUtilRt())
compileOnly(intellijPlatformUtil())
compileOnly(jpsModel()) compileOnly(jpsModel())
compileOnly(jpsModelImpl()) compileOnly(jpsModelImpl())
compileOnly(jpsModelSerialization()) compileOnly(jpsModelSerialization())
@@ -5,9 +5,7 @@
package org.jetbrains.kotlin.config package org.jetbrains.kotlin.config
import com.intellij.openapi.application.ApplicationManager const val APPLICATION_MANAGER_CLASS_NAME = "com.intellij.openapi.application.ApplicationManager"
private const val APPLICATION_MANAGER_CLASS_NAME = "com.intellij.openapi.application.ApplicationManager"
val isJps: Boolean by lazy { val isJps: Boolean by lazy {
/* /*
@@ -16,7 +14,7 @@ val isJps: Boolean by lazy {
Though Application is not properly initialized inside JPS so we can use it as a check. Though Application is not properly initialized inside JPS so we can use it as a check.
*/ */
return@lazy if (doesClassExist(APPLICATION_MANAGER_CLASS_NAME)) { return@lazy if (doesClassExist(APPLICATION_MANAGER_CLASS_NAME)) {
ApplicationManager.getApplication() == null Class.forName(APPLICATION_MANAGER_CLASS_NAME).getMethod("getApplication").invoke(null) == null
} else { } else {
true true
} }
@@ -5,8 +5,6 @@
package org.jetbrains.kotlin.config package org.jetbrains.kotlin.config
import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.cli.common.arguments.* import org.jetbrains.kotlin.cli.common.arguments.*
import org.jetbrains.kotlin.platform.IdePlatformKind import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.platform.TargetPlatform import org.jetbrains.kotlin.platform.TargetPlatform
@@ -276,13 +274,3 @@ class KotlinFacetSettings {
var pureKotlinSourceFolders: List<String> = emptyList() var pureKotlinSourceFolders: List<String> = emptyList()
} }
interface KotlinFacetSettingsProvider {
fun getSettings(module: Module): KotlinFacetSettings?
fun getInitializedSettings(module: Module): KotlinFacetSettings
companion object {
fun getInstance(project: Project): KotlinFacetSettingsProvider? = project.takeUnless(Project::isDisposed)
?.getService(KotlinFacetSettingsProvider::class.java)
}
}
@@ -5,7 +5,7 @@
package org.jetbrains.kotlin.config package org.jetbrains.kotlin.config
import com.intellij.util.PathUtil import com.intellij.openapi.util.io.FileUtilRt
import com.intellij.util.xmlb.SerializationFilter import com.intellij.util.xmlb.SerializationFilter
import com.intellij.util.xmlb.SkipDefaultsSerializationFilter import com.intellij.util.xmlb.SkipDefaultsSerializationFilter
import com.intellij.util.xmlb.XmlSerializer import com.intellij.util.xmlb.XmlSerializer
@@ -179,10 +179,10 @@ private fun readV2AndLaterConfig(
compilerArguments!!.detectVersionAutoAdvance() compilerArguments!!.detectVersionAutoAdvance()
} }
productionOutputPath = element.getChild("productionOutputPath")?.let { productionOutputPath = element.getChild("productionOutputPath")?.let {
PathUtil.toSystemDependentName((it.content.firstOrNull() as? Text)?.textTrim) (it.content.firstOrNull() as? Text)?.textTrim?.let(FileUtilRt::toSystemDependentName)
} ?: (compilerArguments as? K2JSCompilerArguments)?.outputFile } ?: (compilerArguments as? K2JSCompilerArguments)?.outputFile
testOutputPath = element.getChild("testOutputPath")?.let { testOutputPath = element.getChild("testOutputPath")?.let {
PathUtil.toSystemDependentName((it.content.firstOrNull() as? Text)?.textTrim) (it.content.firstOrNull() as? Text)?.textTrim?.let(FileUtilRt::toSystemDependentName)
} ?: (compilerArguments as? K2JSCompilerArguments)?.outputFile } ?: (compilerArguments as? K2JSCompilerArguments)?.outputFile
} }
} }
@@ -222,33 +222,33 @@ fun deserializeFacetSettings(element: Element): KotlinFacetSettings {
} }
fun CommonCompilerArguments.convertPathsToSystemIndependent() { fun CommonCompilerArguments.convertPathsToSystemIndependent() {
pluginClasspaths?.forEachIndexed { index, s -> pluginClasspaths!![index] = PathUtil.toSystemIndependentName(s) } pluginClasspaths?.forEachIndexed { index, s -> pluginClasspaths!![index] = FileUtilRt.toSystemIndependentName(s) }
when (this) { when (this) {
is K2JVMCompilerArguments -> { is K2JVMCompilerArguments -> {
destination = PathUtil.toSystemIndependentName(destination) destination = destination?.let(FileUtilRt::toSystemIndependentName)
classpath = PathUtil.toSystemIndependentName(classpath) classpath = classpath?.let(FileUtilRt::toSystemIndependentName)
jdkHome = PathUtil.toSystemIndependentName(jdkHome) jdkHome = jdkHome?.let(FileUtilRt::toSystemIndependentName)
kotlinHome = PathUtil.toSystemIndependentName(kotlinHome) kotlinHome = kotlinHome?.let(FileUtilRt::toSystemIndependentName)
friendPaths?.forEachIndexed { index, s -> friendPaths!![index] = PathUtil.toSystemIndependentName(s) } friendPaths?.forEachIndexed { index, s -> friendPaths!![index] = FileUtilRt.toSystemIndependentName(s) }
declarationsOutputPath = PathUtil.toSystemIndependentName(declarationsOutputPath) declarationsOutputPath = declarationsOutputPath?.let(FileUtilRt::toSystemIndependentName)
} }
is K2JSCompilerArguments -> { is K2JSCompilerArguments -> {
outputFile = PathUtil.toSystemIndependentName(outputFile) outputFile = outputFile?.let(FileUtilRt::toSystemIndependentName)
libraries = PathUtil.toSystemIndependentName(libraries) libraries = libraries?.let(FileUtilRt::toSystemIndependentName)
} }
is K2MetadataCompilerArguments -> { is K2MetadataCompilerArguments -> {
destination = PathUtil.toSystemIndependentName(destination) destination = destination?.let(FileUtilRt::toSystemIndependentName)
classpath = PathUtil.toSystemIndependentName(classpath) classpath = classpath?.let(FileUtilRt::toSystemIndependentName)
} }
} }
} }
fun CompilerSettings.convertPathsToSystemIndependent() { fun CompilerSettings.convertPathsToSystemIndependent() {
scriptTemplatesClasspath = PathUtil.toSystemIndependentName(scriptTemplatesClasspath) scriptTemplatesClasspath = FileUtilRt.toSystemIndependentName(scriptTemplatesClasspath)
outputDirectoryForJsLibraryFiles = PathUtil.toSystemIndependentName(outputDirectoryForJsLibraryFiles) outputDirectoryForJsLibraryFiles = FileUtilRt.toSystemIndependentName(outputDirectoryForJsLibraryFiles)
} }
private fun KClass<*>.superClass() = superclasses.firstOrNull { !it.java.isInterface } private fun KClass<*>.superClass() = superclasses.firstOrNull { !it.java.isInterface }
@@ -351,12 +351,12 @@ private fun KotlinFacetSettings.writeConfig(element: Element) {
} }
productionOutputPath?.let { productionOutputPath?.let {
if (it != (compilerArguments as? K2JSCompilerArguments)?.outputFile) { if (it != (compilerArguments as? K2JSCompilerArguments)?.outputFile) {
element.addContent(Element("productionOutputPath").apply { addContent(PathUtil.toSystemIndependentName(it)) }) element.addContent(Element("productionOutputPath").apply { addContent(FileUtilRt.toSystemIndependentName(it)) })
} }
} }
testOutputPath?.let { testOutputPath?.let {
if (it != (compilerArguments as? K2JSCompilerArguments)?.outputFile) { if (it != (compilerArguments as? K2JSCompilerArguments)?.outputFile) {
element.addContent(Element("testOutputPath").apply { addContent(PathUtil.toSystemIndependentName(it)) }) element.addContent(Element("testOutputPath").apply { addContent(FileUtilRt.toSystemIndependentName(it)) })
} }
} }
compilerSettings?.let { copyBean(it) }?.let { compilerSettings?.let { copyBean(it) }?.let {
@@ -5,7 +5,7 @@
package org.jetbrains.kotlin.platform package org.jetbrains.kotlin.platform
import com.intellij.openapi.application.ApplicationManager import org.jetbrains.kotlin.config.APPLICATION_MANAGER_CLASS_NAME
import org.jetbrains.kotlin.config.isJps import org.jetbrains.kotlin.config.isJps
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
@@ -20,7 +20,10 @@ interface DefaultIdeTargetPlatformKindProvider {
return JvmPlatforms.defaultJvmPlatform return JvmPlatforms.defaultJvmPlatform
} }
return ApplicationManager.getApplication().getService(DefaultIdeTargetPlatformKindProvider::class.java).defaultPlatform val application = Class.forName(APPLICATION_MANAGER_CLASS_NAME).getMethod("getApplication").invoke(null)
val service = application::class.java.getMethod("getService", Class::class.java)
.invoke(application, DefaultIdeTargetPlatformKindProvider::class.java) as DefaultIdeTargetPlatformKindProvider
return service.defaultPlatform
} }
} }
} }
-3
View File
@@ -31,7 +31,6 @@ dependencies {
api(project(":kotlin-preloader")) api(project(":kotlin-preloader"))
api(project(":jps:jps-common")) api(project(":jps:jps-common"))
compileOnly(commonDependency("org.jetbrains.intellij.deps.fastutil:intellij-deps-fastutil")) compileOnly(commonDependency("org.jetbrains.intellij.deps.fastutil:intellij-deps-fastutil"))
compileOnly(intellijCore())
compileOnly(jpsModel()) compileOnly(jpsModel())
compileOnly(jpsModelImpl()) compileOnly(jpsModelImpl())
compileOnly(jpsBuild()) compileOnly(jpsBuild())
@@ -68,8 +67,6 @@ dependencies {
testCompileOnly(jpsBuild()) testCompileOnly(jpsBuild())
testApi(devKitJps()) testApi(devKitJps())
testApi(intellijCore())
testApi(jpsBuildTest()) testApi(jpsBuildTest())
compilerModules.forEach { compilerModules.forEach {
testRuntimeOnly(project(it)) testRuntimeOnly(project(it))
@@ -16,7 +16,7 @@
package org.jetbrains.kotlin.jps.build package org.jetbrains.kotlin.jps.build
import com.intellij.util.PathUtil import com.intellij.util.PathUtilRt
import org.jetbrains.jps.model.java.JpsJavaExtensionService import org.jetbrains.jps.model.java.JpsJavaExtensionService
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner
@@ -46,7 +46,7 @@ class SimpleKotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
K bar(); K bar();
} }
""") """)
val a = addModule("m1", PathUtil.getParentPath(aFile)) val a = addModule("m1", PathUtilRt.getParentPath(aFile))
val bFile = createFile("m2/m2.kt", val bFile = createFile("m2/m2.kt",
""" """
@@ -57,7 +57,7 @@ class SimpleKotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
override fun bar(): K override fun bar(): K
} }
""") """)
val b = addModule("b", PathUtil.getParentPath(bFile)) val b = addModule("b", PathUtilRt.getParentPath(bFile))
JpsJavaExtensionService.getInstance().getOrCreateDependencyExtension( JpsJavaExtensionService.getInstance().getOrCreateDependencyExtension(
b.dependenciesList.addModuleDependency(a) b.dependenciesList.addModuleDependency(a)
).isExported = false ).isExported = false
@@ -6,7 +6,6 @@ package org.jetbrains.kotlin.jps.targets
import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vfs.StandardFileSystems
import com.intellij.util.containers.FileCollectionFactory import com.intellij.util.containers.FileCollectionFactory
import com.intellij.util.io.URLUtil import com.intellij.util.io.URLUtil
import org.jetbrains.jps.ModuleChunk import org.jetbrains.jps.ModuleChunk
@@ -321,9 +320,9 @@ class KotlinJvmModuleBuildTarget(kotlinContext: KotlinCompileContext, jpsModuleB
.satisfying { dependency -> dependency is JpsSdkDependency } .satisfying { dependency -> dependency is JpsSdkDependency }
.classes().urls .classes().urls
val url = urls.firstOrNull { it.startsWith(StandardFileSystems.JRT_PROTOCOL_PREFIX) } ?: return null val url = urls.firstOrNull { it.startsWith(URLUtil.JRT_PROTOCOL + URLUtil.SCHEME_SEPARATOR) } ?: return null
return File(url.substringAfter(StandardFileSystems.JRT_PROTOCOL_PREFIX).substringBeforeLast(URLUtil.JAR_SEPARATOR)) return File(url.substringAfter(URLUtil.JRT_PROTOCOL + URLUtil.SCHEME_SEPARATOR).substringBeforeLast(URLUtil.JAR_SEPARATOR))
} }
private fun findSourceRoots(context: CompileContext): List<JvmSourceRoot> { private fun findSourceRoots(context: CompileContext): List<JvmSourceRoot> {