diff --git a/.gitignore b/.gitignore index b97e729..68f5be2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # Build artifacts +/.intellijPlatform/ [Bb]in/ [Oo]bj/ build diff --git a/build.gradle.kts b/build.gradle.kts index 4a7c812..1928f14 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,41 +1,40 @@ @file:Suppress("HardCodedStringLiteral") +import com.jetbrains.plugin.structure.base.utils.isFile +import com.jetbrains.plugin.structure.base.utils.listFiles import org.jetbrains.changelog.exceptions.MissingVersionException +import org.jetbrains.intellij.platform.gradle.Constants +import org.jetbrains.intellij.platform.gradle.tasks.PrepareSandboxTask import java.util.* import kotlin.collections.* - -buildscript { - repositories { - maven { setUrl("https://cache-redirector.jetbrains.com/maven-central") } - } - - // https://search.maven.org/artifact/com.jetbrains.rd/rd-gen - dependencies { - classpath("com.jetbrains.rd:rd-gen:2024.1.1") - } -} +import kotlin.io.path.absolute +import kotlin.io.path.isDirectory +import kotlin.io.path.name +import kotlin.io.path.readText repositories { + maven("https://cache-redirector.jetbrains.com/intellij-dependencies") + maven("https://cache-redirector.jetbrains.com/intellij-repository/releases") maven("https://cache-redirector.jetbrains.com/intellij-repository/snapshots") maven("https://cache-redirector.jetbrains.com/maven-central") + intellijPlatform { + defaultRepositories() + jetbrainsRuntime() + } } plugins { - id("me.filippov.gradle.jvm.wrapper") version "0.14.0" + id("me.filippov.gradle.jvm.wrapper") // https://plugins.gradle.org/plugin/org.jetbrains.changelog id("org.jetbrains.changelog") version "2.2.0" - // https://plugins.gradle.org/plugin/org.jetbrains.intellij - id("org.jetbrains.intellij") version "1.17.2" + // https://plugins.gradle.org/plugin/org.jetbrains.intellij.platform + id("org.jetbrains.intellij.platform") // https://plugins.gradle.org/plugin/org.jetbrains.kotlin.jvm - id("org.jetbrains.kotlin.jvm") version "1.9.23" + id("org.jetbrains.kotlin.jvm") // https://plugins.gradle.org/plugin/org.jetbrains.grammarkit id("org.jetbrains.grammarkit") version "2022.3.2.2" } -apply { - plugin("com.jetbrains.rdgen") -} - dependencies { testImplementation("org.testng:testng:7.7.0") } @@ -46,12 +45,13 @@ val productVersion: String by project val pluginVersion: String by project val buildConfiguration = ext.properties["buildConfiguration"] ?: "Debug" +intellijPlatform { + buildSearchableOptions = buildConfiguration == "Release" +} + val publishToken: String by project val publishChannel: String by project -val rdLibDirectory: () -> File = { file("${tasks.setupDependencies.get().idea.get().classes}/lib/rd") } -extra["rdLibDirectory"] = rdLibDirectory - val dotNetSrcDir = File(projectDir, "src/dotnet") val nuGetSdkPackagesVersionsFile = File(dotNetSrcDir, "RiderSdk.PackageVersions.Generated.props") @@ -81,35 +81,12 @@ sourceSets { } } -apply(plugin = "com.jetbrains.rdgen") - -configure { - val modelDir = file("$projectDir/protocol/src/main/kotlin/model") - val csOutput = file("$projectDir/src/dotnet/$dotnetPluginId/Rd") - val ktOutput = file("$projectDir/src/rider/main/kotlin/${riderPluginId.replace('.','/').lowercase(Locale.getDefault())}/rd") - - verbose = true - classpath({ - "${rdLibDirectory()}/rider-model.jar" - }) - sources("$modelDir/rider") - hashFolder = "$buildDir" - packages = "model.rider" - - generator { - language = "kotlin" - transform = "asis" - root = "com.jetbrains.rider.model.nova.ide.IdeRoot" - namespace = "me.seclerp.rider.plugins.efcore.model" - directory = "$ktOutput" - } +dependencies { + intellijPlatform { + rider(productVersion) + jetbrainsRuntime() - generator { - language = "csharp" - transform = "reversed" - root = "com.jetbrains.rider.model.nova.ide.IdeRoot" - namespace = "Rider.Plugins.EfCore" - directory = "$csOutput" + instrumentationTools() } } @@ -118,13 +95,21 @@ grammarKit { grammarKitRelease.set("2022.3.1") } -intellij { - type.set("RD") - version.set(productVersion) - downloadSources.set(false) - plugins.set(listOf( -// "com.intellij.database" - )) +val riderModel: Configuration by configurations.creating { + isCanBeConsumed = true + isCanBeResolved = false +} + +artifacts { + add(riderModel.name, provider { + intellijPlatform.platformPath.resolve("lib/rd/rider-model.jar").also { + check(it.isFile) { + "rider-model.jar is not found at $riderModel" + } + } + }) { + builtBy(Constants.Tasks.INITIALIZE_INTELLIJ_PLATFORM_PLUGIN) + } } tasks { @@ -149,8 +134,8 @@ tasks { } val riderSdkPath by lazy { - val path = setupDependencies.get().idea.get().classes.resolve("lib/DotNetSdkForRdPlugins") - if (!path.isDirectory) error("$path does not exist or not a directory") + val path = intellijPlatform.platformPath.resolve("lib/DotNetSdkForRdPlugins").absolute() + if (!path.isDirectory()) error("$path does not exist or not a directory") println("Rider SDK path: $path") return@lazy path @@ -180,13 +165,13 @@ tasks { val packageRefRegex = "PackageReference\\.(.+).Props".toRegex() val versionRegex = "(.+)".toRegex() val packagesWithVersions = sdkPropsFolder.listFiles() - ?.mapNotNull { file -> + .mapNotNull { file -> val packageId = packageRefRegex.matchEntire(file.name)?.groupValues?.get(1) ?: return@mapNotNull null val version = versionRegex.find(file.readText())?.groupValues?.get(1) ?: return@mapNotNull null packageId to version } - ?.filter { (packageId, _) -> !excludedNuGets.contains(packageId) } ?: emptyList() + .filter { (packageId, _) -> !excludedNuGets.contains(packageId) } ?: emptyList() val directoryPackagesFileContents = buildString { appendLine(""" @@ -210,14 +195,12 @@ tasks { } } - val rdgen by existing - register("prepare") { - dependsOn(rdgen, generateLexer, generateParser, generateNuGetConfig, generateSdkPackagesVersionsLock) + dependsOn(":protocol:rdgen", generateLexer, generateParser, generateNuGetConfig, generateSdkPackagesVersionsLock) } val compileDotNet by registering { - dependsOn(rdgen, generateNuGetConfig, generateSdkPackagesVersionsLock) + dependsOn(":protocol:rdgen", generateNuGetConfig, generateSdkPackagesVersionsLock) doLast { exec { workingDir(dotNetSrcDir) @@ -243,7 +226,7 @@ tasks { } withType { - dependsOn(rdgen, generateLexer, generateParser) + dependsOn(":protocol:rdgen", generateLexer, generateParser) kotlinOptions { jvmTarget = "17" freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn" @@ -251,8 +234,8 @@ tasks { } patchPluginXml { - sinceBuild.set("241.0") - untilBuild.set("241.*") + sinceBuild.set("242.0") + untilBuild.set("242.*") val latestChangelog = try { changelog.getUnreleased() } catch (_: MissingVersionException) { @@ -292,7 +275,7 @@ tasks { environment["LOCAL_ENV_RUN"] = "true" } - withType { + withType { dependsOn(compileDotNet) val outputFolder = file("$dotNetSrcDir/$dotnetPluginId/bin/$dotnetPluginId/$buildConfiguration") diff --git a/gradle.properties b/gradle.properties index 682c418..52a2e6e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,6 +6,11 @@ dotnetPluginId=Rider.Plugins.MonoGame riderPluginId=me.seclerp.rider.plugins.monogame pluginVersion=241.0.0-rc1 +rdVersion=2024.1.1 +rdKotlinVersion=1.9.23 +intellijPlatformGradlePluginVersion=2.0.0-beta7 +gradleJvmWrapperVersion=0.14.0 + buildConfiguration=Debug publishToken="_PLACEHOLDER_" @@ -15,11 +20,14 @@ publishChannel=default # Release: 2020.2 # Nightly: 2020.3-SNAPSHOT # EAP: 2020.3-EAP2-SNAPSHOT -productVersion=2024.1-RC1-SNAPSHOT +productVersion=2024.2-SNAPSHOT # Kotlin 1.4 will bundle the stdlib dependency by default, causing problems with the version bundled with the IDE # https://blog.jetbrains.com/kotlin/2020/07/kotlin-1-4-rc-released/#stdlib-default kotlin.stdlib.default.dependency=false # Fix for Kotlin 1.8.20 uses a new incremental compilation approach that can?t handle large JAR files, resulting in an OutOfMemory exception in the compileKotlin task. -kotlin.incremental.useClasspathSnapshot=false \ No newline at end of file +kotlin.incremental.useClasspathSnapshot=false + +# To use IDE builds from Maven repo rather than official installers. +org.jetbrains.intellij.platform.buildFeature.useBinaryReleases=false \ No newline at end of file diff --git a/protocol/build.gradle.kts b/protocol/build.gradle.kts index bf5a911..a35e319 100644 --- a/protocol/build.gradle.kts +++ b/protocol/build.gradle.kts @@ -1,19 +1,63 @@ +import com.jetbrains.rd.generator.gradle.RdGenTask + plugins { - id("java") + id("com.jetbrains.rdgen") id("org.jetbrains.kotlin.jvm") } -val rdLibDirectory: () -> File by rootProject.extra - repositories { - maven { setUrl("https://cache-redirector.jetbrains.com/maven-central") } - flatDir { - dir(rdLibDirectory()) + maven("https://cache-redirector.jetbrains.com/intellij-dependencies") + maven("https://cache-redirector.jetbrains.com/maven-central") +} + +val repoRoot: File = projectDir.parentFile + +sourceSets { + main { + kotlin { + srcDir(repoRoot.resolve("protocol/src/main/kotlin/model")) + } + } +} + +rdgen { + verbose = true + packages = "model" + + generator { + language = "kotlin" + transform = "asis" + root = "com.jetbrains.rider.model.nova.ide.IdeRoot" + namespace = "com.jetbrains.rider.plugins.efcore.model" + directory = file("$projectDir/src/rider/main/kotlin/me/seclerp/rider/plugins/monogame/rd").absolutePath + } + + generator { + language = "csharp" + transform = "reversed" + root = "com.jetbrains.rider.model.nova.ide.IdeRoot" + namespace = "Rider.Plugins.EfCore" + directory = file("$projectDir/src/dotnet/Rider.Plugins.MonoGame/Rd").absolutePath } } +tasks.withType { + dependsOn(sourceSets["main"].runtimeClasspath) + classpath(sourceSets["main"].runtimeClasspath) +} + dependencies { - implementation("org.jetbrains.kotlin:kotlin-stdlib") - implementation(group = "", name = "rd-gen") - implementation(group = "", name = "rider-model") + val rdVersion: String by project + val rdKotlinVersion: String by project + + implementation("com.jetbrains.rd:rd-gen:$rdVersion") + implementation("org.jetbrains.kotlin:kotlin-stdlib:$rdKotlinVersion") + implementation( + project( + mapOf( + "path" to ":", + "configuration" to "riderModel" + ) + ) + ) } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 57b1662..361ce20 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,12 +1,39 @@ +rootProject.name = "rider-monogame" + pluginManagement { + val rdVersion: String by settings + val rdKotlinVersion: String by settings + val intellijPlatformGradlePluginVersion: String by settings + val gradleJvmWrapperVersion: String by settings + repositories { - maven("https://packages.jetbrains.team/maven/p/ij/intellij-dependencies") + maven("https://cache-redirector.jetbrains.com/intellij-dependencies") maven("https://cache-redirector.jetbrains.com/plugins.gradle.org") - maven("https://oss.sonatype.org/content/repositories/snapshots/") - gradlePluginPortal() + maven("https://cache-redirector.jetbrains.com/maven-central") + + if (rdVersion == "SNAPSHOT") { + mavenLocal() + } } -} -rootProject.name = "rider-monogame" + plugins { + id("com.jetbrains.rdgen") version rdVersion + id("org.jetbrains.kotlin.jvm") version rdKotlinVersion + id("org.jetbrains.intellij.platform") version intellijPlatformGradlePluginVersion + id("me.filippov.gradle.jvm.wrapper") version gradleJvmWrapperVersion + } + + resolutionStrategy { + eachPlugin { + when (requested.id.name) { + // This required to correctly rd-gen plugin resolution. + // Maybe we should switch our naming to match Gradle plugin naming convention. + "rdgen" -> { + useModule("com.jetbrains.rd:rd-gen:${rdVersion}") + } + } + } + } +} -include("protocol") \ No newline at end of file +include(":protocol") \ No newline at end of file diff --git a/src/rider/main/kotlin/me/seclerp/rider/plugins/monogame/mgcb/previewer/MgcbEditorWithPreview.kt b/src/rider/main/kotlin/me/seclerp/rider/plugins/monogame/mgcb/previewer/MgcbEditorWithPreview.kt index dd4f282..944ec60 100644 --- a/src/rider/main/kotlin/me/seclerp/rider/plugins/monogame/mgcb/previewer/MgcbEditorWithPreview.kt +++ b/src/rider/main/kotlin/me/seclerp/rider/plugins/monogame/mgcb/previewer/MgcbEditorWithPreview.kt @@ -18,7 +18,7 @@ class MgcbEditorWithPreview( textEditor.editor.document.addDocumentListener(documentListener) } - override fun isShowFloatingToolbar(): Boolean = false + override val isShowFloatingToolbar = false override fun dispose() { textEditor.editor.document.removeDocumentListener(documentListener)