mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 08:51:02 +07:00
[Kotlin][Gradle] Support import for unbundled compiler plugins
Update import to support separately published Kotlin compiler plugins that are not embedded into related Gradle/Maven plugins. ^KT-52811 GitOrigin-RevId: 5111708cd7bb6f363a34bafd7fafef5a95e2111a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d0fae888a0
commit
2fbe3f960a
@@ -40,7 +40,7 @@ class KaptGradleProjectImportHandler : GradleProjectImportHandler {
|
||||
|
||||
private fun isKaptCompilerPluginPath(path: String): Boolean {
|
||||
val lastIndexOfFile = path.lastIndexOfAny(charArrayOf('/', File.separatorChar)).takeIf { it >= 0 } ?: return false
|
||||
val fileName = path.drop(lastIndexOfFile + 1).toLowerCase(Locale.US)
|
||||
return fileName.matches("kotlin\\-annotation\\-processing(\\-gradle)?\\-[0-9].*\\.jar".toRegex())
|
||||
val fileName = path.drop(lastIndexOfFile + 1).lowercase(Locale.US)
|
||||
return fileName.matches("kotlin\\-annotation\\-processing(\\-gradle|\\-embeddable)?\\-[0-9].*\\.jar".toRegex())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,17 +18,22 @@ object KotlinSerializationImportHandler {
|
||||
return path.endsWith(KotlinArtifactNames.KOTLINX_SERIALIZATION_COMPILER_PLUGIN)
|
||||
}
|
||||
|
||||
fun modifyCompilerArguments(facet: KotlinFacet, buildSystemPluginJar: String) {
|
||||
fun modifyCompilerArguments(
|
||||
facet: KotlinFacet,
|
||||
pluginJarsRegex: List<Regex>
|
||||
) {
|
||||
val facetSettings = facet.configuration.settings
|
||||
val commonArguments = facetSettings.compilerArguments ?: CommonCompilerArguments.DummyImpl()
|
||||
|
||||
var pluginWasEnabled = false
|
||||
val oldPluginClasspaths = (commonArguments.pluginClasspaths ?: emptyArray()).filterTo(mutableListOf()) {
|
||||
val lastIndexOfFile = it.lastIndexOfAny(charArrayOf('/', File.separatorChar))
|
||||
val oldPluginClasspaths = (commonArguments.pluginClasspaths ?: emptyArray()).filterTo(mutableListOf()) { jarPath ->
|
||||
val lastIndexOfFile = jarPath.lastIndexOfAny(charArrayOf('/', File.separatorChar))
|
||||
if (lastIndexOfFile < 0) {
|
||||
return@filterTo true
|
||||
}
|
||||
val match = it.drop(lastIndexOfFile + 1).matches("$buildSystemPluginJar-.*\\.jar".toRegex())
|
||||
|
||||
val jarFileName = jarPath.drop(lastIndexOfFile + 1)
|
||||
val match = pluginJarsRegex.any { jarFileName.matches(it) }
|
||||
if (match) pluginWasEnabled = true
|
||||
!match
|
||||
}
|
||||
|
||||
@@ -11,12 +11,22 @@ import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
|
||||
|
||||
class KotlinSerializationGradleImportHandler : GradleProjectImportHandler {
|
||||
override fun importBySourceSet(facet: KotlinFacet, sourceSetNode: DataNode<GradleSourceSetData>) {
|
||||
KotlinSerializationImportHandler.modifyCompilerArguments(facet, PLUGIN_GRADLE_JAR)
|
||||
KotlinSerializationImportHandler.modifyCompilerArguments(facet, pluginJarRegex)
|
||||
}
|
||||
|
||||
override fun importByModule(facet: KotlinFacet, moduleNode: DataNode<ModuleData>) {
|
||||
KotlinSerializationImportHandler.modifyCompilerArguments(facet, PLUGIN_GRADLE_JAR)
|
||||
KotlinSerializationImportHandler.modifyCompilerArguments(facet, pluginJarRegex)
|
||||
}
|
||||
|
||||
private val PLUGIN_GRADLE_JAR = "kotlin-serialization"
|
||||
private val pluginJarRegex = listOf(
|
||||
"$PLUGIN_COMPILER_EMBEDDABLE_JAR_NAME-.*\\.jar".toRegex(),
|
||||
"$PLUGIN_COMPILER_JAR_NAME-.*\\.jar".toRegex(),
|
||||
"$PLUGIN_GRADLE_JAR_NAME-.*\\.jar".toRegex()
|
||||
)
|
||||
|
||||
companion object {
|
||||
private const val PLUGIN_GRADLE_JAR_NAME = "kotlin-serialization"
|
||||
private const val PLUGIN_COMPILER_EMBEDDABLE_JAR_NAME = "kotlinx-serialization-compiler-plugin-embeddable"
|
||||
private const val PLUGIN_COMPILER_JAR_NAME = "kotlinx-serialization-compiler-plugin"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user