Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[monogame]: Migrate to IJ Platform Plugin 2.0, also migrate RD #22

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Build artifacts
/.intellijPlatform/
[Bb]in/
[Oo]bj/
build
Expand Down
121 changes: 52 additions & 69 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}
Expand All @@ -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")
Expand Down Expand Up @@ -81,35 +81,12 @@ sourceSets {
}
}

apply(plugin = "com.jetbrains.rdgen")

configure<com.jetbrains.rd.generator.gradle.RdGenExtension> {
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()
}
}

Expand All @@ -118,13 +95,21 @@ grammarKit {
grammarKitRelease.set("2022.3.1")
}

intellij {
type.set("RD")
version.set(productVersion)
downloadSources.set(false)
plugins.set(listOf<String>(
// "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 {
Expand All @@ -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
Expand Down Expand Up @@ -180,13 +165,13 @@ tasks {
val packageRefRegex = "PackageReference\\.(.+).Props".toRegex()
val versionRegex = "<Version>(.+)</Version>".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("""
Expand All @@ -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)
Expand All @@ -243,16 +226,16 @@ tasks {
}

withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
dependsOn(rdgen, generateLexer, generateParser)
dependsOn(":protocol:rdgen", generateLexer, generateParser)
kotlinOptions {
jvmTarget = "17"
freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn"
}
}

patchPluginXml {
sinceBuild.set("241.0")
untilBuild.set("241.*")
sinceBuild.set("242.0")
untilBuild.set("242.*")
val latestChangelog = try {
changelog.getUnreleased()
} catch (_: MissingVersionException) {
Expand Down Expand Up @@ -292,7 +275,7 @@ tasks {
environment["LOCAL_ENV_RUN"] = "true"
}

withType<org.jetbrains.intellij.tasks.PrepareSandboxTask> {
withType<PrepareSandboxTask> {
dependsOn(compileDotNet)

val outputFolder = file("$dotNetSrcDir/$dotnetPluginId/bin/$dotnetPluginId/$buildConfiguration")
Expand Down
12 changes: 10 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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_"
Expand All @@ -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
kotlin.incremental.useClasspathSnapshot=false

# To use IDE builds from Maven repo rather than official installers.
org.jetbrains.intellij.platform.buildFeature.useBinaryReleases=false
62 changes: 53 additions & 9 deletions protocol/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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("$repoRoot/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("$repoRoot/src/dotnet/Rider.Plugins.MonoGame/Rd").absolutePath
}
}

tasks.withType<RdGenTask> {
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"
)
)
)
}
39 changes: 33 additions & 6 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
include(":protocol")
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading