AllOpen, NoArg: Use the bundled plugins in Maven projects
Use the bundled compiler plugins for Maven projects (as we do for Gradle projects already) because the plugin provided as a dependency in the POM file may have an incompatible version.
This commit is contained in:
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.allopen.ide
|
||||
|
||||
import org.jetbrains.kotlin.allopen.AllOpenCommandLineProcessor
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AbstractMavenImportHandler
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
|
||||
class AllOpenMavenProjectImportHandler : AbstractMavenImportHandler() {
|
||||
private companion object {
|
||||
@@ -28,6 +29,7 @@ class AllOpenMavenProjectImportHandler : AbstractMavenImportHandler() {
|
||||
override val pluginName = "allopen"
|
||||
override val annotationOptionName = AllOpenCommandLineProcessor.ANNOTATION_OPTION.name
|
||||
override val mavenPluginArtifactName = "kotlin-maven-allopen"
|
||||
override val pluginJarFileFromIdea = PathUtil.getKotlinPathsForIdeaPlugin().allOpenPluginJarPath
|
||||
|
||||
override fun getAnnotations(enabledCompilerPlugins: List<String>, compilerPluginOptions: List<String>): List<String>? {
|
||||
if ("all-open" !in enabledCompilerPlugins && "spring" !in enabledCompilerPlugins) {
|
||||
|
||||
+2
-1
@@ -65,7 +65,8 @@ abstract class AbstractGradleImportHandler : GradleProjectImportHandler {
|
||||
|
||||
val annotationFqNames = annotationFqNamesList.split(',')
|
||||
|
||||
// For now we can't use plugins from Gradle cause they're shaded. So we use ones from the IDEA plugin
|
||||
// For now we can't use plugins from Gradle cause they're shaded and may have an incompatible version.
|
||||
// So we use ones from the IDEA plugin.
|
||||
val classpath = listOf(pluginJarFileFromIdea.absolutePath)
|
||||
|
||||
return AnnotationBasedCompilerPluginSetup(annotationFqNames, classpath)
|
||||
|
||||
+5
-10
@@ -30,6 +30,7 @@ abstract class AbstractMavenImportHandler : MavenProjectImportHandler {
|
||||
abstract val pluginName: String
|
||||
abstract val annotationOptionName: String
|
||||
abstract val mavenPluginArtifactName: String
|
||||
abstract val pluginJarFileFromIdea: File
|
||||
|
||||
override fun invoke(facet: KotlinFacet, mavenProject: MavenProject) {
|
||||
modifyCompilerArgumentsForPlugin(facet, getPluginSetup(mavenProject),
|
||||
@@ -45,15 +46,6 @@ abstract class AbstractMavenImportHandler : MavenProjectImportHandler {
|
||||
it.groupId == KOTLIN_PLUGIN_GROUP_ID && it.artifactId == KOTLIN_PLUGIN_ARTIFACT_ID
|
||||
} ?: return null
|
||||
|
||||
val runtimeJarFile = mavenProject.dependencies
|
||||
.firstOrNull { it.groupId == KOTLIN_PLUGIN_GROUP_ID &&
|
||||
(it.artifactId == "kotlin-runtime" || it.artifactId == "kotlin-stdlib") }
|
||||
?.file ?: return null
|
||||
val runtimeVersion = runtimeJarFile.parentFile.name
|
||||
|
||||
val mavenCompilerPluginJar = File(runtimeJarFile.parentFile.parentFile.parentFile,
|
||||
"$mavenPluginArtifactName/$runtimeVersion/$mavenPluginArtifactName-$runtimeVersion.jar")
|
||||
|
||||
val configuration = kotlinPlugin.configurationElement ?: return null
|
||||
|
||||
val enabledCompilerPlugins = configuration.getElement("compilerPlugins")
|
||||
@@ -67,8 +59,11 @@ abstract class AbstractMavenImportHandler : MavenProjectImportHandler {
|
||||
?.mapTo(mutableListOf()) { (it as Text).text }
|
||||
?: mutableListOf<String>()
|
||||
|
||||
// We can't use the plugin from Gradle as it may have the incompatible version
|
||||
val classpath = listOf(pluginJarFileFromIdea.absolutePath)
|
||||
|
||||
val annotationFqNames = getAnnotations(enabledCompilerPlugins, compilerPluginOptions) ?: return null
|
||||
return AnnotationBasedCompilerPluginSetup(annotationFqNames, listOf(mavenCompilerPluginJar.absolutePath))
|
||||
return AnnotationBasedCompilerPluginSetup(annotationFqNames, classpath)
|
||||
}
|
||||
|
||||
private fun Element.getElement(name: String) = content.firstOrNull { it is Element && it.name == name } as? Element
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.noarg.ide
|
||||
|
||||
import org.jetbrains.kotlin.noarg.NoArgCommandLineProcessor
|
||||
import org.jetbrains.kotlin.annotation.plugin.ide.AbstractMavenImportHandler
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
|
||||
class NoArgMavenProjectImportHandler : AbstractMavenImportHandler() {
|
||||
private companion object {
|
||||
@@ -28,6 +29,7 @@ class NoArgMavenProjectImportHandler : AbstractMavenImportHandler() {
|
||||
override val pluginName = "noarg"
|
||||
override val annotationOptionName = NoArgCommandLineProcessor.ANNOTATION_OPTION.name
|
||||
override val mavenPluginArtifactName = "kotlin-maven-noarg"
|
||||
override val pluginJarFileFromIdea = PathUtil.getKotlinPathsForIdeaPlugin().noArgPluginJarPath
|
||||
|
||||
override fun getAnnotations(enabledCompilerPlugins: List<String>, compilerPluginOptions: List<String>): List<String>? {
|
||||
if ("no-arg" !in enabledCompilerPlugins && "jpa" !in enabledCompilerPlugins) {
|
||||
|
||||
Reference in New Issue
Block a user