-
Notifications
You must be signed in to change notification settings - Fork 14
/
build.gradle.kts
280 lines (235 loc) · 8.13 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
@file:Suppress("HardCodedStringLiteral")
import com.jetbrains.plugin.structure.base.utils.isFile
import org.jetbrains.changelog.exceptions.MissingVersionException
import org.jetbrains.intellij.platform.gradle.Constants
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.intellij.platform.gradle.tasks.PrepareSandboxTask
import kotlin.collections.*
import kotlin.io.path.absolute
import kotlin.io.path.isDirectory
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")
id("org.jetbrains.changelog") version "2.2.0"
id("org.jetbrains.intellij.platform")
id("org.jetbrains.kotlin.jvm")
}
val dotnetPluginId: String by project
val productVersion: String by project
val pluginVersion: String by project
val buildConfiguration = ext.properties["buildConfiguration"] ?: "Debug"
val sinceProductVersion = run {
val yearWithMajor = productVersion.substringBefore("-")
val year = yearWithMajor.substringBefore(".")
val major = yearWithMajor.substringAfter(".")
"${year.substring(2)}$major.0".also {
logger.info("Using since build version: $it")
}
}
intellijPlatform {
buildSearchableOptions = buildConfiguration == "Release"
}
val publishToken: String by project
val publishChannel: String by project
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/generated/kotlin")
kotlin.srcDir("src/rider/main/kotlin")
resources.srcDir("src/rider/main/resources")
}
}
dependencies {
intellijPlatform {
rider(productVersion)
jetbrainsRuntime()
instrumentationTools()
bundledPlugin("com.intellij.database")
bundledPlugin("org.jetbrains.plugins.terminal")
testFramework(TestFrameworkType.Bundled)
}
}
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 {
wrapper {
gradleVersion = "8.7"
distributionUrl = "https://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"
}
val riderSdkPath by lazy {
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
}
val prepareRiderBuildProps by registering {
val generatedFile = layout.buildDirectory.file("DotNetSdkPath.generated.props")
inputs.property("dotNetSdkFile", { riderSdkPath.toString() })
outputs.file(generatedFile)
doLast {
project.file(generatedFile).writeText(
"""<Project>
| <PropertyGroup>
| <DotNetSdkPath>$riderSdkPath</DotNetSdkPath>
| </PropertyGroup>
|</Project>""".trimMargin()
)
}
}
val generateNuGetConfig by registering {
doLast {
nuGetConfigFile.writeTextIfChanged("""
<?xml version="1.0" encoding="utf-8"?>
<!-- Auto-generated from 'generateNuGetConfig' task of old.build_gradle.kts -->
<!-- Run `gradlew :prepare` to regenerate -->
<configuration>
<packageSources>
<add key="rider-sdk" value="$riderSdkPath" />
</packageSources>
</configuration>
""".trimIndent())
}
}
register("prepare") {
dependsOn(":protocol:rdgen", generateNuGetConfig, prepareRiderBuildProps)
}
val compileDotNet by registering {
dependsOn(":protocol:rdgen", generateNuGetConfig, prepareRiderBuildProps)
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<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
dependsOn(":protocol:rdgen")
kotlinOptions {
jvmTarget = "17"
freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn"
}
}
patchPluginXml {
sinceBuild.set(sinceProductVersion)
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)
copy {
from(layout.buildDirectory.file("distributions/${rootProject.name}-${version}.zip"))
into("${rootDir}/output")
}
}
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<PrepareSandboxTask> {
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")
}
}
}
publishPlugin {
token.set(publishToken)
channels.set(listOf(publishChannel))
}
wrapper {
gradleVersion = "8.7"
distributionUrl = "https://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-${gradleVersion}-bin.zip"
}
}
fun getProductMonorepoRoot(): File? {
var currentDir = projectDir
while (currentDir.parent != null) {
if (currentDir.resolve(".ultimate.root.marker").exists()) {
return currentDir
}
currentDir = currentDir.parentFile
}
return null
}