From 688c51ef75bc6c231c90e50f8fa107799bd2092f Mon Sep 17 00:00:00 2001 From: Andrii Rublov Date: Fri, 31 Mar 2023 21:19:49 +0200 Subject: [PATCH] Introduce Kotlin Script instead of Grrovy, migrate to Central Package Management for .NET part --- .idea/runConfigurations/Build_plugin.xml | 3 +- build.gradle | 188 ------------ build.gradle.kts | 277 ++++++++++++++++++ gradle.properties | 19 +- protocol/build.gradle | 17 -- protocol/build.gradle.kts | 19 ++ src/dotnet/.gitignore | 5 +- src/dotnet/Directory.Build.props | 16 +- src/dotnet/Directory.Packages.props | 18 ++ src/dotnet/Plugin.props | 4 +- .../Rider.Plugins.EfCore.Tests.csproj | 4 +- src/dotnet/Rider.Plugins.EfCore.sln | 4 + .../Rider.Plugins.EfCore.csproj | 8 +- 13 files changed, 348 insertions(+), 234 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts delete mode 100644 protocol/build.gradle create mode 100644 protocol/build.gradle.kts create mode 100644 src/dotnet/Directory.Packages.props diff --git a/.idea/runConfigurations/Build_plugin.xml b/.idea/runConfigurations/Build_plugin.xml index a0b994fe..dc1b61c4 100644 --- a/.idea/runConfigurations/Build_plugin.xml +++ b/.idea/runConfigurations/Build_plugin.xml @@ -4,7 +4,7 @@ @@ -18,6 +18,7 @@ true true false + false \ No newline at end of file diff --git a/build.gradle b/build.gradle deleted file mode 100644 index d3c55cdd..00000000 --- a/build.gradle +++ /dev/null @@ -1,188 +0,0 @@ -// Reference https://www.jetbrains.org/intellij/sdk/docs/tutorials/build_system/gradle_guide.html -import org.apache.tools.ant.taskdefs.condition.Os - -import java.text.SimpleDateFormat - -plugins { - id 'java' - id 'org.jetbrains.kotlin.jvm' version '1.7.20' - id 'org.jetbrains.intellij' version '1.13.2' // https://github.com/JetBrains/gradle-intellij-plugin/releases - id 'com.jetbrains.rdgen' version '2023.1.2' // https://github.com/JetBrains/rd/releases - id 'org.jetbrains.changelog' version '2.0.0' -} - -ext { - isWindows = Os.isFamily(Os.FAMILY_WINDOWS) - rdLibDirectory = { - new File(setupDependencies.idea.get().classes, "lib/rd") - } -} - -repositories { - maven { url 'https://cache-redirector.jetbrains.com/intellij-repository/snapshots' } - maven { url 'https://cache-redirector.jetbrains.com/maven-central' } -} - -wrapper { - gradleVersion = '7.4.2' - distributionType = Wrapper.DistributionType.ALL - distributionUrl = "https://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-${gradleVersion}-all.zip" -} - -version = ext.PluginVersion - -sourceSets { - main { - java.srcDir 'src/rider/main/java' - kotlin.srcDir 'src/rider/main/kotlin' - resources.srcDir 'src/rider/main/resources' - } -} - -sourceCompatibility = javaVersion -targetCompatibility = javaVersion - -compileKotlin { - kotlinOptions { jvmTarget = javaVersion } -} - -task setBuildTool { - doLast { - ext.args = [] - ByteArrayOutputStream stdout = new ByteArrayOutputStream() - ext.executable = "dotnet" - ext.args << "msbuild" - ext.args << "${DotnetSolution}" - ext.args << "/p:Configuration=${BuildConfiguration}" - ext.args << "/p:HostFullIdentifier=" - ext.args << "/p:SdkVersion=${RiderSdkVersion}" - } -} - -task compileDotNet { - dependsOn setBuildTool - doLast { - def arguments = setBuildTool.args.clone() - arguments << "/t:Restore;Rebuild" - exec { - executable setBuildTool.executable - args arguments - workingDir "${rootDir}/src/dotnet" - } - } -} - -buildPlugin { - doLast { - copy { - from "${buildDir}/distributions/${rootProject.name}-${version}.zip" - into "${rootDir}/output" - } - - def arguments = setBuildTool.args.clone() - arguments << "/t:Pack" - arguments << "/p:PackageOutputPath=${rootDir}/output" - arguments << "/p:PackageVersion=${version}" - exec { - executable setBuildTool.executable - args arguments - workingDir "${rootDir}/src/dotnet" - } - } -} - -apply plugin: 'org.jetbrains.changelog' - -intellij { - type = 'RD' - version = "${ProductVersion}" - downloadSources = false - instrumentCode = false - plugins = ["com.intellij.database"] - - patchPluginXml { - changeNotes = changelog.get(PluginVersion).toHTML() - } -} - -changelog { - version = "${PluginVersion}" - path = "${project.projectDir}/CHANGELOG.md" - header = "[${-> version.get()}] - ${new SimpleDateFormat("yyyy-MM-dd").format(new Date())}" - itemPrefix = "-" - keepUnreleasedSection = true - unreleasedTerm = "[Unreleased]" - groups = ["Added", "Changed", "Deprecated", "Removed", "Fixed", "Security"] -} - -runIde { - // Match Rider's default heap size of 1.5Gb (default for runIde is 512Mb) - maxHeapSize = "1500m" - - // Rider's backend doesn't support dynamic plugins. It might be possible to work with auto-reload of the frontend - // part of a plugin, but there are dangers about keeping plugins in sync - autoReloadPlugins = false - - // gradle-intellij-plugin will download the default version of the JBR for the snapshot. Update if required - // jbrVersion = "jbr_jcef-11_0_6b765.40" // https://confluence.jetbrains.com/display/JBR/Release+notes -} - -rdgen { - def modelDir = new File(rootDir, "protocol/src/main/kotlin/model") - def csOutput = new File(rootDir, "src/dotnet/${DotnetPluginId}/Rd") - def ktOutput = new File(rootDir, "src/rider/main/kotlin/${RiderPluginId.replace('.','/').toLowerCase()}/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" - } - - generator { - language = "csharp" - transform = "reversed" - root = "com.jetbrains.rider.model.nova.ide.IdeRoot" - namespace = "Rider.Plugins.EfCore" - directory = "$csOutput" - } -} - -prepareSandbox { - dependsOn compileDotNet - - def outputFolder = "${rootDir}/src/dotnet/${DotnetPluginId}/bin/${DotnetPluginId}/${BuildConfiguration}" - def dllFiles = [ - "$outputFolder/${DotnetPluginId}.dll", - "$outputFolder/${DotnetPluginId}.pdb", - - // TODO: add additional assemblies - ] - - dllFiles.forEach({ f -> - def file = file(f) - from(file, { into "${rootProject.name}/dotnet" }) - }) - - doLast { - dllFiles.forEach({ f -> - def file = file(f) - if (!file.exists()) throw new RuntimeException("File ${file} does not exist") - }) - } -} - -publishPlugin { - dependsOn buildPlugin - token = "${PublishToken}" - channels = [ "${PublishChannel}" ] -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..c40e5602 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,277 @@ +@file:Suppress("HardCodedStringLiteral") + +import org.jetbrains.changelog.exceptions.MissingVersionException +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:2023.2.0") + } +} + +plugins { + id("me.filippov.gradle.jvm.wrapper") version "0.14.0" + id("org.jetbrains.changelog") version "2.0.0" + id("org.jetbrains.intellij") version "1.13.2" + id("org.jetbrains.kotlin.jvm") version "1.7.20" +} + +apply { + plugin("com.jetbrains.rdgen") +} + +dependencies { + testImplementation("org.testng:testng:7.7.0") +} + +val riderPluginId: String by project +val dotnetPluginId: String by project +val productVersion: String by project +val pluginVersion: String by project +val buildConfiguration = ext.properties["buildConfiguration"] ?: "Debug" + +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") +val nuGetConfigFile = File(dotNetSrcDir, "nuget.config") + +version = pluginVersion + +fun File.writeTextIfChanged(content: String) { + val bytes = content.toByteArray() + + if (!exists() || !readBytes().contentEquals(bytes)) { + println("Writing $path") + parentFile.mkdirs() + writeBytes(bytes) + } +} + +repositories { + maven { setUrl("https://cache-redirector.jetbrains.com/maven-central") } +} + +sourceSets { + main { + kotlin.srcDir("src/rider/main/kotlin") + resources.srcDir("src/rider/main/resources") + } +} + +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('.','/').toLowerCase()}/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" + } + + generator { + language = "csharp" + transform = "reversed" + root = "com.jetbrains.rider.model.nova.ide.IdeRoot" + namespace = "Rider.Plugins.EfCore" + directory = "$csOutput" + } +} + +intellij { + type.set("RD") + version.set(productVersion) + downloadSources.set(false) + plugins.set(listOf( + "com.intellij.database" + )) +} + +tasks { + wrapper { + gradleVersion = "7.5.1" + distributionType = Wrapper.DistributionType.ALL + distributionUrl = "https://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-${gradleVersion}-all.zip" + } + + 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") + + println("Rider SDK path: $path") + return@lazy path + } + + val generateNuGetConfig by registering { + doLast { + nuGetConfigFile.writeTextIfChanged(""" + + + + + + + + + """.trimIndent()) + } + } + + val generateSdkPackagesVersionsLock by registering { + doLast { + val excludedNuGets = setOf( + "NETStandard.Library" + ) + val sdkPropsFolder = riderSdkPath.resolve("Build") + val packageRefRegex = "PackageReference\\.(.+).Props".toRegex() + val versionRegex = "(.+)".toRegex() + val packagesWithVersions = sdkPropsFolder.listFiles() + ?.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() + + val directoryPackagesFileContents = buildString { + appendLine(""" + + + + + """.trimIndent()) + for ((packageId, version) in packagesWithVersions) { + appendLine( + " " + ) + } + appendLine(""" + + + """.trimIndent()) + } + + nuGetSdkPackagesVersionsFile.writeTextIfChanged(directoryPackagesFileContents) + } + } + + val rdgen by existing + + register("prepare") { + dependsOn(rdgen, generateNuGetConfig, generateSdkPackagesVersionsLock) + } + + val compileDotNet by registering { + dependsOn(rdgen, generateNuGetConfig, generateSdkPackagesVersionsLock) + doLast { + exec { + workingDir(dotNetSrcDir) + executable("dotnet") + args("build", "-c", buildConfiguration) + } + } + } + + register("testDotNet") { + dependsOn(compileDotNet) + doLast { + val testsDir = dotNetSrcDir.resolve("Tests") + testsDir.list { entry, name -> entry.isDirectory && name != ".DS_Store" } + ?.forEach { + exec { + workingDir(testsDir.absolutePath) + executable("dotnet") + args("test", "-c", buildConfiguration, it) + } + } + } + } + + withType { + dependsOn(rdgen) + kotlinOptions { + jvmTarget = "17" + freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn" + } + } + + patchPluginXml { + untilBuild.set("232.*") + val latestChangelog = try { + changelog.getUnreleased() + } catch (_: MissingVersionException) { + changelog.getLatest() + } + changeNotes.set(provider { + changelog.renderItem( + latestChangelog + .withHeader(false) + .withEmptySections(false), + org.jetbrains.changelog.Changelog.OutputType.HTML + ) + }) + } + + buildPlugin { + dependsOn(compileDotNet) + } + + runIde { + // For statistics: + // jvmArgs("-Xmx1500m", "-Didea.is.internal=true", "-Dfus.internal.test.mode=true") + jvmArgs("-Xmx1500m") + } + + test { + useTestNG() + testLogging { + showStandardStreams = true + exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL + } + environment["LOCAL_ENV_RUN"] = "true" + } + + withType { + dependsOn(compileDotNet) + + val outputFolder = file("$dotNetSrcDir/$dotnetPluginId/bin/$dotnetPluginId/$buildConfiguration") + val backendFiles = listOf( + "$outputFolder/$dotnetPluginId.dll", + "$outputFolder/$dotnetPluginId.pdb" + + // TODO: add additional assemblies + ) + + for (f in backendFiles) { + from(f) { into("${rootProject.name}/dotnet") } + } + + doLast { + for (f in backendFiles) { + val file = file(f) + if (!file.exists()) throw RuntimeException("File \"$file\" does not exist") + } + } + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 69d4c81c..4757149a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,25 +2,20 @@ # -P= javaVersion=17 -DotnetPluginId=Rider.Plugins.EfCore -DotnetSolution=Rider.Plugins.EfCore.sln -RiderPluginId=me.seclerp.rider.plugins.efcore -PluginVersion=231.0.2-eap04 +dotnetPluginId=Rider.Plugins.EfCore +riderPluginId=me.seclerp.rider.plugins.efcore +pluginVersion=231.1.0-eap10 -BuildConfiguration=Debug +buildConfiguration=Debug -PublishToken="_PLACEHOLDER_" -PublishChannel=default +publishToken="_PLACEHOLDER_" +publishChannel=default -# Possible values: -# Release: 2021.2.0 -# EAP: 2022.2.0-eap04 -RiderSdkVersion=2023.1.0-eap08 # Possible values (minor is omitted): # Release: 2020.2 # Nightly: 2020.3-SNAPSHOT # EAP: 2020.3-EAP2-SNAPSHOT -ProductVersion=2023.1-EAP8-SNAPSHOT +productVersion=2023.1-EAP10-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 diff --git a/protocol/build.gradle b/protocol/build.gradle deleted file mode 100644 index 70177866..00000000 --- a/protocol/build.gradle +++ /dev/null @@ -1,17 +0,0 @@ -plugins { - id 'java' - id 'org.jetbrains.kotlin.jvm' -} - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib" - implementation name: "rd-gen" - implementation name: "rider-model" -} - -repositories { - mavenCentral() - flatDir { - dirs rdLibDirectory().absolutePath - } -} \ No newline at end of file diff --git a/protocol/build.gradle.kts b/protocol/build.gradle.kts new file mode 100644 index 00000000..bf5a9113 --- /dev/null +++ b/protocol/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("java") + id("org.jetbrains.kotlin.jvm") +} + +val rdLibDirectory: () -> File by rootProject.extra + +repositories { + maven { setUrl("https://cache-redirector.jetbrains.com/maven-central") } + flatDir { + dir(rdLibDirectory()) + } +} + +dependencies { + implementation("org.jetbrains.kotlin:kotlin-stdlib") + implementation(group = "", name = "rd-gen") + implementation(group = "", name = "rider-model") +} \ No newline at end of file diff --git a/src/dotnet/.gitignore b/src/dotnet/.gitignore index 782ea74a..23311f80 100644 --- a/src/dotnet/.gitignore +++ b/src/dotnet/.gitignore @@ -350,4 +350,7 @@ MigrationBackup/ .ionide/ # User specific -**/.idea/ \ No newline at end of file +**/.idea/ + +*.Generated.props +nuget.config diff --git a/src/dotnet/Directory.Build.props b/src/dotnet/Directory.Build.props index a4f44fae..80e84ea1 100644 --- a/src/dotnet/Directory.Build.props +++ b/src/dotnet/Directory.Build.props @@ -1,6 +1,8 @@ + Latest + MSB3277 true false None @@ -8,6 +10,13 @@ obj\$(MSBuildProjectName)\ $(DefaultItemExcludes);obj\** bin\$(MSBuildProjectName)\$(Configuration)\ + false + + + + + true + true @@ -16,15 +25,8 @@ - - $(SdkVersion.Substring(2,2))$(SdkVersion.Substring(5,1)) - $(WaveVersionBase).0.0$(SdkVersion.Substring(8)) - $(WaveVersionBase).9999.0 - - - diff --git a/src/dotnet/Directory.Packages.props b/src/dotnet/Directory.Packages.props new file mode 100644 index 00000000..cc5c234e --- /dev/null +++ b/src/dotnet/Directory.Packages.props @@ -0,0 +1,18 @@ + + + true + + + + + + + + + + + + + + + diff --git a/src/dotnet/Plugin.props b/src/dotnet/Plugin.props index bae323ba..f2f4bc3d 100644 --- a/src/dotnet/Plugin.props +++ b/src/dotnet/Plugin.props @@ -1,12 +1,10 @@  - 2023.1.0-eap08 - Entity Framework Core JetBrains Rider plugin for Entity Framework Core - Andrew Rublyov + Andrii Rublov Copyright $([System.DateTime]::Now.Year) Andrii Rublov resharper plugin diff --git a/src/dotnet/Rider.Plugins.EfCore.Tests/Rider.Plugins.EfCore.Tests.csproj b/src/dotnet/Rider.Plugins.EfCore.Tests/Rider.Plugins.EfCore.Tests.csproj index ff568405..547c10c3 100644 --- a/src/dotnet/Rider.Plugins.EfCore.Tests/Rider.Plugins.EfCore.Tests.csproj +++ b/src/dotnet/Rider.Plugins.EfCore.Tests/Rider.Plugins.EfCore.Tests.csproj @@ -6,7 +6,7 @@ - + @@ -18,4 +18,4 @@ - \ No newline at end of file + diff --git a/src/dotnet/Rider.Plugins.EfCore.sln b/src/dotnet/Rider.Plugins.EfCore.sln index f399c059..66fa4b01 100644 --- a/src/dotnet/Rider.Plugins.EfCore.sln +++ b/src/dotnet/Rider.Plugins.EfCore.sln @@ -11,6 +11,10 @@ ProjectSection(SolutionItems) = preProject ..\..\CHANGELOG.md = ..\..\CHANGELOG.md ..\rider\main\resources\META-INF\plugin.xml = ..\rider\main\resources\META-INF\plugin.xml ..\..\gradle.properties = ..\..\gradle.properties + Directory.Build.props = Directory.Build.props + Directory.Packages.props = Directory.Packages.props + RiderSdk.PackageVersions.Generated.props = RiderSdk.PackageVersions.Generated.props + nuget.config = nuget.config EndProjectSection EndProject Global diff --git a/src/dotnet/Rider.Plugins.EfCore/Rider.Plugins.EfCore.csproj b/src/dotnet/Rider.Plugins.EfCore/Rider.Plugins.EfCore.csproj index 3fe076e5..6b68ea41 100644 --- a/src/dotnet/Rider.Plugins.EfCore/Rider.Plugins.EfCore.csproj +++ b/src/dotnet/Rider.Plugins.EfCore/Rider.Plugins.EfCore.csproj @@ -2,7 +2,6 @@ $(MSBuildToolsPath)\Microsoft.CSharp.targets - 8 @@ -16,9 +15,12 @@ - + + + + - \ No newline at end of file +