From e82857996f9805bd53ce7edebe193fea8cd8f80f Mon Sep 17 00:00:00 2001 From: Andrey Zinovyev Date: Tue, 18 May 2021 13:33:30 +0300 Subject: [PATCH] [lombok] Resolve to absolute path when import from maven #KT-46723 Fixed --- .../kotlin/plugin/ide/AbstractMavenImportHandler.kt | 8 +++++++- .../lombok/ide/LombokMavenProjectImportHandler.kt | 13 +++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/plugins/base-compiler-plugins-ide-support/src/org/jetbrains/kotlin/plugin/ide/AbstractMavenImportHandler.kt b/plugins/base-compiler-plugins-ide-support/src/org/jetbrains/kotlin/plugin/ide/AbstractMavenImportHandler.kt index 85eadf7d0b3..7f279eef9a0 100644 --- a/plugins/base-compiler-plugins-ide-support/src/org/jetbrains/kotlin/plugin/ide/AbstractMavenImportHandler.kt +++ b/plugins/base-compiler-plugins-ide-support/src/org/jetbrains/kotlin/plugin/ide/AbstractMavenImportHandler.kt @@ -30,6 +30,12 @@ abstract class AbstractMavenImportHandler : MavenProjectImportHandler { abstract fun getOptions(enabledCompilerPlugins: List, compilerPluginOptions: List): List? + protected open fun getOptions( + mavenProject: MavenProject, + enabledCompilerPlugins: List, + compilerPluginOptions: List + ): List? = getOptions(enabledCompilerPlugins, compilerPluginOptions) + private fun getPluginSetup(mavenProject: MavenProject): CompilerPluginSetup? { val kotlinPlugin = mavenProject.plugins.firstOrNull { it.groupId == KOTLIN_PLUGIN_GROUP_ID && it.artifactId == KOTLIN_PLUGIN_ARTIFACT_ID @@ -51,7 +57,7 @@ abstract class AbstractMavenImportHandler : MavenProjectImportHandler { // We can't use the plugin from Gradle as it may have the incompatible version val classpath = listOf(pluginJarFileFromIdea.absolutePath) - val options = getOptions(enabledCompilerPlugins, compilerPluginOptions) ?: return null + val options = getOptions(mavenProject, enabledCompilerPlugins, compilerPluginOptions) ?: return null return CompilerPluginSetup(options, classpath) } diff --git a/plugins/lombok/lombok-ide-plugin/src/org/jetbrains/kotlin/lombok/ide/LombokMavenProjectImportHandler.kt b/plugins/lombok/lombok-ide-plugin/src/org/jetbrains/kotlin/lombok/ide/LombokMavenProjectImportHandler.kt index 920033c9d0c..9891d2a3898 100644 --- a/plugins/lombok/lombok-ide-plugin/src/org/jetbrains/kotlin/lombok/ide/LombokMavenProjectImportHandler.kt +++ b/plugins/lombok/lombok-ide-plugin/src/org/jetbrains/kotlin/lombok/ide/LombokMavenProjectImportHandler.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.lombok.ide +import org.jetbrains.idea.maven.project.MavenProject import org.jetbrains.kotlin.lombok.LombokCommandLineProcessor import org.jetbrains.kotlin.lombok.LombokCommandLineProcessor.Companion.CONFIG_FILE_OPTION import org.jetbrains.kotlin.plugin.ide.AbstractMavenImportHandler @@ -18,6 +19,7 @@ class LombokMavenProjectImportHandler : AbstractMavenImportHandler() { override val pluginJarFileFromIdea: File = PathUtil.kotlinPathsForIdeaPlugin.lombokPluginJarPath override fun getOptions( + mavenProject: MavenProject, enabledCompilerPlugins: List, compilerPluginOptions: List ): List? { @@ -25,14 +27,21 @@ class LombokMavenProjectImportHandler : AbstractMavenImportHandler() { return compilerPluginOptions.mapNotNull { option -> if (option.startsWith(CONFIG_FILE_PREFIX)) { - val location = option.substring(CONFIG_FILE_PREFIX.length) - PluginOption(CONFIG_FILE_OPTION.optionName, location) + val location = File(option.substring(CONFIG_FILE_PREFIX.length)) + val correctedLocation = + if (!location.isAbsolute) File(mavenProject.directory, location.path) + else location + PluginOption(CONFIG_FILE_OPTION.optionName, correctedLocation.absolutePath) } else { null } } } + override fun getOptions(enabledCompilerPlugins: List, compilerPluginOptions: List): List? { + throw NotImplementedError("Shouldn't be called") + } + companion object { private const val MAVEN_SUBPLUGIN_NAME = "lombok" private val CONFIG_FILE_PREFIX = "$MAVEN_SUBPLUGIN_NAME:${CONFIG_FILE_OPTION.optionName}="