User: rednesto Date: 05 Jul 24 10:10 Revision: 01f85cf6c72e9edb6a2f5375248471b3935ce89b Summary: Update EAP build and restore Kotlin support TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=9356&personal=false Index: build.gradle.kts =================================================================== --- build.gradle.kts (revision d4b39e68278aebd29f9cc7286a9419450a9c2a32) +++ build.gradle.kts (revision 01f85cf6c72e9edb6a2f5375248471b3935ce89b) @@ -34,11 +34,13 @@ mcdev groovy idea - id("org.jetbrains.intellij.platform") version "2.0.0-beta6" + id("org.jetbrains.intellij.platform") version "2.0.0-beta8" id("org.cadixdev.licenser") id("org.jlleitschuh.gradle.ktlint") version "10.3.0" } +val ideaVersion: String by project +val ideaVersionNoEapSnapshot = ideaVersion.removeSuffix("-EAP-SNAPSHOT") val ideaVersionName: String by project val coreVersion: String by project @@ -93,6 +95,17 @@ } } +configurations.all { + resolutionStrategy.eachDependency { + // For some reason dependency versions do not include the EAP-SNAPSHOT suffix anymore since beta7 + // This works around the issue for now + // TODO remove when no longer needed + if (requested.version == ideaVersionNoEapSnapshot) { + useVersion(ideaVersion) + } + } +} + dependencies { // Add tools.jar for the JDI API implementation(files(Jvm.current().toolsJar)) @@ -126,7 +139,7 @@ bundledPlugin("com.intellij.gradle") bundledPlugin("org.intellij.groovy") // For some reason the Kotlin plugin can't be resolved... -// bundledPlugin("org.jetbrains.kotlin") + bundledPlugin("org.jetbrains.kotlin") bundledPlugin("ByteCodeViewer") bundledPlugin("com.intellij.properties") bundledPlugin("org.toml.lang") @@ -136,7 +149,7 @@ instrumentationTools() - testFramework(TestFrameworkType.Platform.JUnit5) + testFramework(TestFrameworkType.JUnit5) testFramework(TestFrameworkType.Plugin.Java) pluginVerifier() Index: gradle.properties =================================================================== --- gradle.properties (revision d4b39e68278aebd29f9cc7286a9419450a9c2a32) +++ gradle.properties (revision 01f85cf6c72e9edb6a2f5375248471b3935ce89b) @@ -21,7 +21,7 @@ # suppress inspection "UnusedProperty" for whole file kotlin.code.style=official -ideaVersion = 242.16677.21-EAP-SNAPSHOT +ideaVersion = 242.19890.14-EAP-SNAPSHOT ideaVersionName = 2024.2 coreVersion = 1.7.6 Index: gradle/libs.versions.toml =================================================================== --- gradle/libs.versions.toml (revision d4b39e68278aebd29f9cc7286a9419450a9c2a32) +++ gradle/libs.versions.toml (revision 01f85cf6c72e9edb6a2f5375248471b3935ce89b) @@ -18,7 +18,7 @@ grammarKit = "org.jetbrains.idea:grammar-kit:1.5.1" # Gradle Tooling -gradleToolingExtension = "com.jetbrains.intellij.gradle:gradle-tooling-extension:242.16677.21-EAP-SNAPSHOT" +gradleToolingExtension = "com.jetbrains.intellij.gradle:gradle-tooling-extension:242.19890.14-EAP-SNAPSHOT" annotations = "org.jetbrains:annotations:24.0.0" groovy = "org.codehaus.groovy:groovy:3.0.19" Index: src/main/kotlin/creator/buildsystem/GradleFile.kt =================================================================== --- src/main/kotlin/creator/buildsystem/GradleFile.kt (revision d4b39e68278aebd29f9cc7286a9419450a9c2a32) +++ src/main/kotlin/creator/buildsystem/GradleFile.kt (revision 01f85cf6c72e9edb6a2f5375248471b3935ce89b) @@ -20,20 +20,20 @@ package com.demonwav.mcdev.creator.buildsystem -// import com.demonwav.mcdev.util.childrenOfType +import com.demonwav.mcdev.util.childrenOfType import com.demonwav.mcdev.util.mapFirstNotNull import com.intellij.openapi.extensions.ExtensionPointName import com.intellij.openapi.project.Project import com.intellij.openapi.util.text.StringUtil import com.intellij.psi.PsiFile import org.jetbrains.annotations.ApiStatus.Internal -// import org.jetbrains.kotlin.psi.KtBinaryExpression -// import org.jetbrains.kotlin.psi.KtBlockExpression -// import org.jetbrains.kotlin.psi.KtCallExpression -// import org.jetbrains.kotlin.psi.KtFile -// import org.jetbrains.kotlin.psi.KtNameReferenceExpression -// import org.jetbrains.kotlin.psi.KtPsiFactory -// import org.jetbrains.kotlin.psi.KtScriptInitializer +import org.jetbrains.kotlin.psi.KtBinaryExpression +import org.jetbrains.kotlin.psi.KtBlockExpression +import org.jetbrains.kotlin.psi.KtCallExpression +import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.psi.KtNameReferenceExpression +import org.jetbrains.kotlin.psi.KtPsiFactory +import org.jetbrains.kotlin.psi.KtScriptInitializer import org.jetbrains.plugins.groovy.lang.psi.GroovyFile import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock @@ -136,89 +136,89 @@ } } -// class KotlinGradleFile(override val psi: KtFile) : GradleFile { -// override fun addRepositories(project: Project, repositories: List) { -// val script = psi.script?.blockExpression ?: return -// val reposBlock = findOrCreateKotlinBlock(project, script, "repositories") -// val elementFactory = KtPsiFactory(project) -// for (repo in repositories) { -// if (BuildSystemType.GRADLE !in repo.buildSystems) { -// continue -// } -// val mavenBlock = elementFactory.createExpression("maven {\n}") as KtCallExpression -// val mavenLambda = mavenBlock.lambdaArguments[0].getLambdaExpression()!!.bodyExpression!! -// if (repo.id.isNotBlank()) { -// val idStatement = elementFactory.createAssignment("name = ${makeStringLiteral(repo.id)}") -// mavenLambda.addBefore(idStatement, mavenLambda.rBrace) -// } -// val urlStatement = elementFactory.createAssignment("url = uri(${makeStringLiteral(repo.url)})") -// mavenLambda.addBefore(urlStatement, mavenLambda.rBrace) -// reposBlock.addBefore(mavenBlock, reposBlock.rBrace) -// } -// } -// -// override fun addDependencies(project: Project, dependencies: List) { -// val script = psi.script?.blockExpression ?: return -// val depsBlock = findOrCreateKotlinBlock(project, script, "dependencies") -// val elementFactory = KtPsiFactory(project) -// for (dep in dependencies) { -// val gradleConfig = dep.gradleConfiguration ?: continue -// val stmt = elementFactory.createExpression( -// "$gradleConfig(\"${escapeGString(dep.groupId)}:${ -// escapeGString(dep.artifactId) -// }:${escapeGString(dep.version)}\")", -// ) -// depsBlock.addBefore(stmt, depsBlock.rBrace) -// } -// } -// -// override fun addPlugins(project: Project, plugins: List) { -// val script = psi.script?.blockExpression ?: return -// val pluginsBlock = findOrCreateKotlinBlock(project, script, "plugins", first = true) -// val elementFactory = KtPsiFactory(project) -// for (plugin in plugins) { -// val stmt = elementFactory.createExpression(makePluginStatement(plugin, true)) -// pluginsBlock.addBefore(stmt, pluginsBlock.rBrace) -// } -// } -// -// private fun findKotlinBlock(element: KtBlockExpression, name: String): KtBlockExpression? { -// return element.childrenOfType() -// .flatMap { it.childrenOfType() } -// .mapFirstNotNull { call -> -// if ((call.calleeExpression as? KtNameReferenceExpression)?.getReferencedName() == name) { -// call.lambdaArguments.firstOrNull()?.getLambdaExpression()?.bodyExpression -// } else { -// null -// } -// } -// } -// -// private fun findOrCreateKotlinBlock( -// project: Project, -// element: KtBlockExpression, -// name: String, -// first: Boolean = false, -// ): KtBlockExpression { -// findKotlinBlock(element, name)?.let { return it } -// val block = KtPsiFactory(project).createExpression("$name {\n}") -// val addedBlock = if (first) { -// element.addAfter(block, element.lBrace) -// } else { -// element.addBefore(block, element.rBrace) -// } -// return (addedBlock as KtCallExpression).lambdaArguments.first().getLambdaExpression()!!.bodyExpression!! -// } -// -// private fun KtPsiFactory.createAssignment(text: String): KtBinaryExpression { -// return this.createBlock(text).firstStatement as KtBinaryExpression -// } -// -// class Type : GradleFile.Type { -// override fun createGradleFile(psiFile: PsiFile) = (psiFile as? KtFile)?.let(::KotlinGradleFile) -// } -// } +class KotlinGradleFile(override val psi: KtFile) : GradleFile { + override fun addRepositories(project: Project, repositories: List) { + val script = psi.script?.blockExpression ?: return + val reposBlock = findOrCreateKotlinBlock(project, script, "repositories") + val elementFactory = KtPsiFactory(project) + for (repo in repositories) { + if (BuildSystemType.GRADLE !in repo.buildSystems) { + continue + } + val mavenBlock = elementFactory.createExpression("maven {\n}") as KtCallExpression + val mavenLambda = mavenBlock.lambdaArguments[0].getLambdaExpression()!!.bodyExpression!! + if (repo.id.isNotBlank()) { + val idStatement = elementFactory.createAssignment("name = ${makeStringLiteral(repo.id)}") + mavenLambda.addBefore(idStatement, mavenLambda.rBrace) + } + val urlStatement = elementFactory.createAssignment("url = uri(${makeStringLiteral(repo.url)})") + mavenLambda.addBefore(urlStatement, mavenLambda.rBrace) + reposBlock.addBefore(mavenBlock, reposBlock.rBrace) + } + } + override fun addDependencies(project: Project, dependencies: List) { + val script = psi.script?.blockExpression ?: return + val depsBlock = findOrCreateKotlinBlock(project, script, "dependencies") + val elementFactory = KtPsiFactory(project) + for (dep in dependencies) { + val gradleConfig = dep.gradleConfiguration ?: continue + val stmt = elementFactory.createExpression( + "$gradleConfig(\"${escapeGString(dep.groupId)}:${ + escapeGString(dep.artifactId) + }:${escapeGString(dep.version)}\")", + ) + depsBlock.addBefore(stmt, depsBlock.rBrace) + } + } + + override fun addPlugins(project: Project, plugins: List) { + val script = psi.script?.blockExpression ?: return + val pluginsBlock = findOrCreateKotlinBlock(project, script, "plugins", first = true) + val elementFactory = KtPsiFactory(project) + for (plugin in plugins) { + val stmt = elementFactory.createExpression(makePluginStatement(plugin, true)) + pluginsBlock.addBefore(stmt, pluginsBlock.rBrace) + } + } + + private fun findKotlinBlock(element: KtBlockExpression, name: String): KtBlockExpression? { + return element.childrenOfType() + .flatMap { it.childrenOfType() } + .mapFirstNotNull { call -> + if ((call.calleeExpression as? KtNameReferenceExpression)?.getReferencedName() == name) { + call.lambdaArguments.firstOrNull()?.getLambdaExpression()?.bodyExpression + } else { + null + } + } + } + + private fun findOrCreateKotlinBlock( + project: Project, + element: KtBlockExpression, + name: String, + first: Boolean = false, + ): KtBlockExpression { + findKotlinBlock(element, name)?.let { return it } + val block = KtPsiFactory(project).createExpression("$name {\n}") + val addedBlock = if (first) { + element.addAfter(block, element.lBrace) + } else { + element.addBefore(block, element.rBrace) + } + return (addedBlock as KtCallExpression).lambdaArguments.first().getLambdaExpression()!!.bodyExpression!! + } + + private fun KtPsiFactory.createAssignment(text: String): KtBinaryExpression { + return this.createBlock(text).firstStatement as KtBinaryExpression + } + + class Type : GradleFile.Type { + override fun createGradleFile(psiFile: PsiFile) = (psiFile as? KtFile)?.let(::KotlinGradleFile) + } +} + private fun makeStringLiteral(str: String): String { return "\"${escapeGString(str)}\"" } Index: src/main/resources/META-INF/mcdev-kotlin.xml =================================================================== --- src/main/resources/META-INF/mcdev-kotlin.xml (revision d4b39e68278aebd29f9cc7286a9419450a9c2a32) +++ src/main/resources/META-INF/mcdev-kotlin.xml (revision 01f85cf6c72e9edb6a2f5375248471b3935ce89b) @@ -20,6 +20,6 @@ - +