-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.gradle.kts
220 lines (189 loc) · 6.5 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
import com.jetbrains.plugin.structure.base.utils.isFile
import groovy.ant.FileNameFinder
import org.apache.tools.ant.taskdefs.condition.Os
import org.jetbrains.intellij.platform.gradle.Constants
import java.io.ByteArrayOutputStream
plugins {
id("java")
alias(libs.plugins.kotlinJvm)
id("org.jetbrains.intellij.platform") version "2.0.0-beta5" // See https://github.com/JetBrains/intellij-platform-gradle-plugin/releases
id("me.filippov.gradle.jvm.wrapper") version "0.14.0"
}
val isWindows = Os.isFamily(Os.FAMILY_WINDOWS)
extra["isWindows"] = isWindows
val DotnetSolution: String by project
val BuildConfiguration: String by project
val ProductVersion: String by project
val DotnetPluginId: String by project
val RiderPluginId: String by project
val PublishToken: String by project
allprojects {
repositories {
maven { setUrl("https://cache-redirector.jetbrains.com/maven-central") }
}
}
repositories {
intellijPlatform {
defaultRepositories()
jetbrainsRuntime()
}
}
tasks.wrapper {
gradleVersion = "8.8"
distributionType = Wrapper.DistributionType.ALL
distributionUrl = "https://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"
}
version = extra["PluginVersion"] as String
tasks.processResources {
from("dependencies.json") { into("META-INF") }
}
sourceSets {
main {
java.srcDir("src/rider/main/java")
kotlin.srcDir("src/rider/main/kotlin")
resources.srcDir("src/rider/main/resources")
}
}
tasks.compileKotlin {
kotlinOptions { jvmTarget = "17" }
}
val setBuildTool by tasks.registering {
doLast {
extra["executable"] = "dotnet"
var args = mutableListOf("msbuild")
if (isWindows) {
val stdout = ByteArrayOutputStream()
exec {
executable("${rootDir}\\tools\\vswhere.exe")
args("-latest", "-property", "installationPath", "-products", "*")
standardOutput = stdout
workingDir(rootDir)
}
val directory = stdout.toString().trim()
if (directory.isNotEmpty()) {
val files = FileNameFinder().getFileNames("${directory}\\MSBuild", "**/MSBuild.exe")
extra["executable"] = files.get(0)
args = mutableListOf("/v:minimal")
}
}
args.add("${DotnetSolution}")
args.add("/p:Configuration=${BuildConfiguration}")
args.add("/p:HostFullIdentifier=")
extra["args"] = args
}
}
val compileDotNet by tasks.registering {
dependsOn(setBuildTool)
doLast {
val executable: String by setBuildTool.get().extra
val arguments = (setBuildTool.get().extra["args"] as List<String>).toMutableList()
arguments.add("/t:Restore;Rebuild")
exec {
executable(executable)
args(arguments)
workingDir(rootDir)
}
}
}
val testDotNet by tasks.registering {
doLast {
exec {
executable("dotnet")
args("test","${DotnetSolution}","--logger","GitHubActions")
workingDir(rootDir)
}
}
}
tasks.buildPlugin {
doLast {
copy {
from("${buildDir}/distributions/${rootProject.name}-${version}.zip")
into("${rootDir}/output")
}
// TODO: See also org.jetbrains.changelog: https://github.com/JetBrains/gradle-changelog-plugin
val changelogText = file("${rootDir}/CHANGELOG.md").readText()
val changelogMatches = Regex("(?s)(-.+?)(?=##|$)").findAll(changelogText)
val changeNotes = changelogMatches.map {
it.groups[1]!!.value.replace("(?s)- ".toRegex(), "\u2022 ").replace("`", "").replace(",", "%2C").replace(";", "%3B")
}.take(1).joinToString()
val executable: String by setBuildTool.get().extra
val arguments = (setBuildTool.get().extra["args"] as List<String>).toMutableList()
arguments.add("/t:Pack")
arguments.add("/p:PackageOutputPath=${rootDir}/output")
arguments.add("/p:PackageReleaseNotes=${changeNotes}")
arguments.add("/p:PackageVersion=${version}")
exec {
executable(executable)
args(arguments)
workingDir(rootDir)
}
}
}
dependencies {
intellijPlatform {
rider(ProductVersion)
jetbrainsRuntime()
instrumentationTools()
}
}
tasks.runIde {
// Match Rider's default heap size of 1.5Gb (default for runIde is 512Mb)
maxHeapSize = "1500m"
}
tasks.patchPluginXml {
// TODO: See also org.jetbrains.changelog: https://github.com/JetBrains/gradle-changelog-plugin
val changelogText = file("${rootDir}/CHANGELOG.md").readText()
val changelogMatches = Regex("(?s)(-.+?)(?=##|\$)").findAll(changelogText)
changeNotes.set(changelogMatches.map {
it.groups[1]!!.value.replace("(?s)\r?\n".toRegex(), "<br />\n")
}.take(1).joinToString())
}
tasks.prepareSandbox {
dependsOn(compileDotNet)
val outputFolder = "${rootDir}/src/dotnet/${DotnetPluginId}/bin/${DotnetPluginId}.Rider/${BuildConfiguration}"
val dllFiles = listOf(
"$outputFolder/${DotnetPluginId}.dll",
"$outputFolder/${DotnetPluginId}.pdb",
"$outputFolder/DiffEngine.dll",
"$outputFolder/EmptyFiles.dll",
"$outputFolder/Verify.ExceptionParsing.dll",
// TODO: add additional assemblies
)
dllFiles.forEach({ f ->
val file = file(f)
from(file, { into("${rootProject.name}/dotnet") })
})
doLast {
dllFiles.forEach({ f ->
val file = file(f)
if (!file.exists()) throw RuntimeException("File ${file} does not exist")
})
}
}
tasks.publishPlugin {
// dependsOn testDotNet
dependsOn(tasks.buildPlugin)
token.set("${PublishToken}")
doLast {
exec {
executable("dotnet")
args("nuget","push","output/${DotnetPluginId}.${version}.nupkg","--api-key","${PublishToken}","--source","https://plugins.jetbrains.com")
workingDir(rootDir)
}
}
}
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)
}
}