[lombok] Resolve to absolute path when import from maven

#KT-46723 Fixed
This commit is contained in:
Andrey Zinovyev
2021-05-18 13:33:30 +03:00
committed by teamcityserver
parent 2680111125
commit e82857996f
2 changed files with 18 additions and 3 deletions
@@ -30,6 +30,12 @@ abstract class AbstractMavenImportHandler : MavenProjectImportHandler {
abstract fun getOptions(enabledCompilerPlugins: List<String>, compilerPluginOptions: List<String>): List<PluginOption>?
protected open fun getOptions(
mavenProject: MavenProject,
enabledCompilerPlugins: List<String>,
compilerPluginOptions: List<String>
): List<PluginOption>? = 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)
}
@@ -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<String>,
compilerPluginOptions: List<String>
): List<PluginOption>? {
@@ -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<String>, compilerPluginOptions: List<String>): List<PluginOption>? {
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}="