mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Kotlin, Maven] Support JPA with All-Open compiler plugins combination
Since Kotlin 2.3.20-Beta2 release, JPA compiler plugin is also automatically applying all-open plugin with newly added "jpa" preset. Added support for it in Maven import, so highlighting and JPS should work properly. ^KTIJ-37092 Verification Pending GitOrigin-RevId: e884d1f2608d06dbafd830ff8372194da923d00e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9b44038438
commit
4008ab1c7e
+15
-1
@@ -3,6 +3,7 @@
|
||||
package org.jetbrains.kotlin.idea.compilerPlugin.allopen.maven
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.util.text.VersionComparatorUtil
|
||||
import org.jetbrains.idea.maven.project.MavenProject
|
||||
import org.jetbrains.kotlin.allopen.AllOpenPluginNames.ANNOTATION_OPTION_NAME
|
||||
import org.jetbrains.kotlin.allopen.AllOpenPluginNames.PLUGIN_ID
|
||||
@@ -11,6 +12,7 @@ import org.jetbrains.kotlin.idea.base.plugin.artifacts.KotlinArtifacts
|
||||
import org.jetbrains.kotlin.idea.compilerPlugin.CompilerPluginSetup.PluginOption
|
||||
import org.jetbrains.kotlin.idea.maven.compilerPlugin.AbstractMavenImportHandler
|
||||
import java.nio.file.Path
|
||||
import org.jetbrains.kotlin.idea.maven.getKotlinPlugin
|
||||
|
||||
class AllOpenMavenProjectImportHandler(project: Project) : AbstractMavenImportHandler(project) {
|
||||
override val compilerPluginId: String = PLUGIN_ID
|
||||
@@ -23,7 +25,10 @@ class AllOpenMavenProjectImportHandler(project: Project) : AbstractMavenImportHa
|
||||
enabledCompilerPlugins: List<String>,
|
||||
compilerPluginOptions: List<String>
|
||||
): List<PluginOption>? {
|
||||
if ("all-open" !in enabledCompilerPlugins && "spring" !in enabledCompilerPlugins) {
|
||||
if ("all-open" !in enabledCompilerPlugins &&
|
||||
"spring" !in enabledCompilerPlugins &&
|
||||
!mavenProject.isJpaWithAllOpenEnabled(enabledCompilerPlugins)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -42,6 +47,15 @@ class AllOpenMavenProjectImportHandler(project: Project) : AbstractMavenImportHa
|
||||
|
||||
return annotations.map { PluginOption(ANNOTATION_OPTION_NAME, it) }
|
||||
}
|
||||
|
||||
private fun MavenProject.isJpaWithAllOpenEnabled(
|
||||
enabledCompilerPlugins: List<String>
|
||||
): Boolean {
|
||||
val kotlinPluginVersion = getKotlinPlugin().version
|
||||
|
||||
return "jpa" in enabledCompilerPlugins &&
|
||||
VersionComparatorUtil.compare(kotlinPluginVersion, "2.3.20-Beta2") >= 0
|
||||
}
|
||||
}
|
||||
|
||||
private const val ANNOTATION_PARAMETER_PREFIX = "all-open:$ANNOTATION_OPTION_NAME="
|
||||
|
||||
+2
-5
@@ -11,10 +11,9 @@ import org.jetbrains.kotlin.idea.compiler.configuration.KotlinPluginLayoutServic
|
||||
import org.jetbrains.kotlin.idea.compilerPlugin.CompilerPluginSetup
|
||||
import org.jetbrains.kotlin.idea.compilerPlugin.CompilerPluginSetup.PluginOption
|
||||
import org.jetbrains.kotlin.idea.compilerPlugin.modifyCompilerArgumentsForPluginWithFacetSettings
|
||||
import org.jetbrains.kotlin.idea.maven.KotlinMavenImporter.Companion.KOTLIN_PLUGIN_ARTIFACT_ID
|
||||
import org.jetbrains.kotlin.idea.maven.KotlinMavenImporter.Companion.KOTLIN_PLUGIN_GROUP_ID
|
||||
import org.jetbrains.kotlin.idea.maven.MavenProjectImportHandler
|
||||
import java.nio.file.Path
|
||||
import org.jetbrains.kotlin.idea.maven.findKotlinPlugin
|
||||
|
||||
abstract class AbstractMavenImportHandler(protected val project: Project) : MavenProjectImportHandler {
|
||||
abstract val compilerPluginId: String
|
||||
@@ -37,9 +36,7 @@ abstract class AbstractMavenImportHandler(protected val project: Project) : Mave
|
||||
): List<PluginOption>?
|
||||
|
||||
private fun getPluginSetup(mavenProject: MavenProject): CompilerPluginSetup? {
|
||||
val kotlinPlugin = mavenProject.plugins.firstOrNull {
|
||||
it.groupId == KOTLIN_PLUGIN_GROUP_ID && it.artifactId == KOTLIN_PLUGIN_ARTIFACT_ID
|
||||
} ?: return null
|
||||
val kotlinPlugin = mavenProject.findKotlinPlugin() ?: return null
|
||||
|
||||
val configuration = kotlinPlugin.configurationElement ?: return null
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ open class KotlinMavenImporter : MavenApplicableConfigurator(KOTLIN_PLUGIN_GROUP
|
||||
detectPlatformByExecutions(mavenProject) ?: detectPlatformByLibraries(mavenProject)
|
||||
|
||||
private fun detectPlatformByExecutions(mavenProject: MavenProject): IdePlatformKind? {
|
||||
return mavenProject.findPlugin(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ARTIFACT_ID)?.executions?.flatMap { it.goals }
|
||||
return mavenProject.findKotlinPlugin()?.executions?.flatMap { it.goals }
|
||||
?.mapNotNull { goal ->
|
||||
when (goal) {
|
||||
PomFile.KotlinGoals.Compile, PomFile.KotlinGoals.TestCompile -> JvmIdePlatformKind
|
||||
@@ -245,6 +245,10 @@ open class KotlinMavenImporter : MavenApplicableConfigurator(KOTLIN_PLUGIN_GROUP
|
||||
}
|
||||
}
|
||||
|
||||
fun MavenProject.findKotlinPlugin() = plugins.firstOrNull { it.isKotlinPlugin() }
|
||||
|
||||
fun MavenProject.getKotlinPlugin() = plugins.single { it.isKotlinPlugin() }
|
||||
|
||||
fun MavenPlugin.isKotlinPlugin(): Boolean =
|
||||
groupId == KotlinMavenImporter.KOTLIN_PLUGIN_GROUP_ID && artifactId == KotlinMavenImporter.KOTLIN_PLUGIN_ARTIFACT_ID
|
||||
|
||||
|
||||
+9
@@ -3921,4 +3921,13 @@ abstract class AbstractKotlinMavenImporterTest(private val createStdProjectFolde
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object TestVersions {
|
||||
object Kotlin {
|
||||
const val KOTLIN_2_3_10 = "2.3.10"
|
||||
const val KOTLIN_2_3_20 = "2.3.20-Beta2"
|
||||
|
||||
const val LATEST_STABLE = "2.3.10"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.kotlin.idea.maven.importer
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.jetbrains.kotlin.idea.base.plugin.artifacts.KotlinArtifacts
|
||||
import org.jetbrains.kotlin.idea.maven.AbstractKotlinMavenImporterTest
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Test
|
||||
|
||||
class AllOpenKotlinMavenImporterTest : AbstractKotlinMavenImporterTest() {
|
||||
|
||||
@Test
|
||||
fun testAllOpenIsNotEnabledViaJpaPluginInOldKotlinVersions() = runBlocking {
|
||||
createProjectSubDirs("src/main/kotlin", "src/test/kotlin")
|
||||
|
||||
importProjectAsync(projectWithJpaPlugin(TestVersions.Kotlin.KOTLIN_2_3_10))
|
||||
|
||||
assertModules("project")
|
||||
|
||||
with(facetSettings) {
|
||||
assertNotNull(compilerArguments?.pluginClasspaths)
|
||||
assertFalse(compilerArguments!!.pluginClasspaths!!.any { it.endsWith(KotlinArtifacts.allopenCompilerPluginPath.fileName.toString()) })
|
||||
assertTrue(compilerArguments!!.pluginClasspaths!!.any { it.endsWith(KotlinArtifacts.noargCompilerPluginPath.fileName.toString()) })
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAllOpenIsEnabledViaJpaPlugin() = runBlocking {
|
||||
createProjectSubDirs("src/main/kotlin", "src/test/kotlin")
|
||||
|
||||
importProjectAsync(projectWithJpaPlugin(TestVersions.Kotlin.KOTLIN_2_3_20))
|
||||
|
||||
assertModules("project")
|
||||
|
||||
with(facetSettings) {
|
||||
assertNotNull(compilerArguments?.pluginClasspaths)
|
||||
assertTrue(compilerArguments!!.pluginClasspaths!!.any { it.endsWith(KotlinArtifacts.allopenCompilerPluginPath.fileName.toString()) })
|
||||
assertTrue(compilerArguments!!.pluginClasspaths!!.any { it.endsWith(KotlinArtifacts.noargCompilerPluginPath.fileName.toString()) })
|
||||
assertArrayEquals(
|
||||
compilerArguments!!.pluginOptions!!,
|
||||
arrayOf(
|
||||
"plugin:org.jetbrains.kotlin.noarg:annotation=javax.persistence.Entity",
|
||||
"plugin:org.jetbrains.kotlin.noarg:annotation=javax.persistence.Embeddable",
|
||||
"plugin:org.jetbrains.kotlin.noarg:annotation=javax.persistence.MappedSuperclass",
|
||||
"plugin:org.jetbrains.kotlin.noarg:annotation=jakarta.persistence.Entity",
|
||||
"plugin:org.jetbrains.kotlin.noarg:annotation=jakarta.persistence.Embeddable",
|
||||
"plugin:org.jetbrains.kotlin.noarg:annotation=jakarta.persistence.MappedSuperclass",
|
||||
"plugin:org.jetbrains.kotlin.allopen:annotation=javax.persistence.Entity",
|
||||
"plugin:org.jetbrains.kotlin.allopen:annotation=javax.persistence.Embeddable",
|
||||
"plugin:org.jetbrains.kotlin.allopen:annotation=javax.persistence.MappedSuperclass",
|
||||
"plugin:org.jetbrains.kotlin.allopen:annotation=jakarta.persistence.Entity",
|
||||
"plugin:org.jetbrains.kotlin.allopen:annotation=jakarta.persistence.Embeddable",
|
||||
"plugin:org.jetbrains.kotlin.allopen:annotation=jakarta.persistence.MappedSuperclass",
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun projectWithJpaPlugin(kotlinVersion: String) =
|
||||
//language=xml
|
||||
"""
|
||||
|<groupId>test</groupId>
|
||||
|<artifactId>project</artifactId>
|
||||
|<version>1.0.0</version>
|
||||
|
|
||||
|<properties>
|
||||
| <kotlin.version>${kotlinVersion}</kotlin.version>
|
||||
|</properties>
|
||||
|
|
||||
|<build>
|
||||
| <sourceDirectory>src/main/kotlin</sourceDirectory>
|
||||
| <testSourceDirectory>src/test/kotlin</testSourceDirectory>
|
||||
| <plugins>
|
||||
| <plugin>
|
||||
| <groupId>org.jetbrains.kotlin</groupId>
|
||||
| <artifactId>kotlin-maven-plugin</artifactId>
|
||||
| <version>${'$'}{kotlin.version}</version>
|
||||
| <configuration>
|
||||
| <compilerPlugins>
|
||||
| <plugin>jpa</plugin>
|
||||
| </compilerPlugins>
|
||||
| </configuration>
|
||||
| <executions>
|
||||
| <execution>
|
||||
| <id>compile</id>
|
||||
| <phase>compile</phase>
|
||||
| <goals>
|
||||
| <goal>compile</goal>
|
||||
| </goals>
|
||||
| </execution>
|
||||
| <execution>
|
||||
| <id>test-compile</id>
|
||||
| <phase>test-compile</phase>
|
||||
| <goals>
|
||||
| <goal>test-compile</goal>
|
||||
| </goals>
|
||||
| </execution>
|
||||
| </executions>
|
||||
| <dependencies>
|
||||
| <dependency>
|
||||
| <groupId>org.jetbrains.kotlin</groupId>
|
||||
| <artifactId>kotlin-maven-noarg</artifactId>
|
||||
| <version>${'$'}{kotlin.version}</version>
|
||||
| </dependency>
|
||||
| </dependencies>
|
||||
| </plugin>
|
||||
| </plugins>
|
||||
|</build>
|
||||
""".trimMargin()
|
||||
}
|
||||
Reference in New Issue
Block a user