-
Notifications
You must be signed in to change notification settings - Fork 12
/
build.gradle.kts
347 lines (300 loc) · 11.3 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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
import com.google.protobuf.gradle.*
import groovy.util.Node
import groovy.util.XmlNodePrinter
import org.gradle.api.JavaVersion.VERSION_11
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.gradle.internal.os.OperatingSystem
import org.jetbrains.intellij.tasks.PatchPluginXmlTask
import org.jetbrains.intellij.tasks.PrepareSandboxTask
import org.jetbrains.intellij.tasks.PublishTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.BufferedOutputStream
import java.io.FileOutputStream
import java.io.OutputStreamWriter
import java.io.PrintWriter
import java.nio.charset.StandardCharsets
val grpcVersion = "1.57.2"
val protobufVersion = "3.24.4"
val isTeamCity = System.getenv("RPLUGIN_CI") == "TeamCity"
val channel = prop("publishChannel")
val excludedJars = listOf(
"java-api.jar",
"java-impl.jar"
)
buildscript {
repositories {
maven ("https://cache-redirector.jetbrains.com/repo1.maven.org/maven2" )
maven ("https://oss.sonatype.org/content/repositories/snapshots/" )
}
dependencies {
// classpath ("org.jetbrains.intellij.plugins:gradle-intellij-plugin:0.5.0-SNAPSHOT")
}
}
dependencies {
testCompile("org.mockito:mockito-all:1.10.19")
compile("com.google.protobuf:protobuf-java:$protobufVersion")
compile("io.grpc:grpc-stub:$grpcVersion")
compile("io.grpc:grpc-protobuf:$grpcVersion")
compile("org.assertj:assertj-core:3.18.1")
runtimeOnly("io.grpc:grpc-netty-shaded:$grpcVersion")
protobuf(files("protos/", "grammars/"))
}
protobuf {
generatedFilesBaseDir = "$projectDir/gen-grpc"
protoc {
artifact = "com.google.protobuf:protoc:$protobufVersion"
}
plugins {
id("grpc") {
artifact = "io.grpc:protoc-gen-grpc-java:$grpcVersion"
}
}
generateProtoTasks {
ofSourceSet("main").forEach {
it.plugins {
id("grpc")
}
}
}
}
plugins {
idea
kotlin("jvm") version "1.4.10"
id("org.jetbrains.intellij") version "0.4.10"
id("org.jetbrains.grammarkit") version "2019.2.1"
id("de.undercouch.download") version "3.4.3"
id("net.saliman.properties") version "1.4.6"
id("com.google.protobuf") version "0.8.10"
}
idea {
module {
// https://github.com/gradle/kotlin-dsl/issues/537/
excludeDirs = excludeDirs + file("testData") + file("deps")
}
}
allprojects {
apply {
plugin("org.jetbrains.intellij")
plugin("idea")
plugin("kotlin")
plugin("org.jetbrains.grammarkit")
plugin("org.jetbrains.intellij")
}
repositories {
mavenCentral()
}
intellij {
version = ideName()
updateSinceUntilBuild = true
instrumentCode = false
ideaDependencyCachePath = dependencyCachePath
if (useInlayVisualisationFromPlugin()) {
localPath = guessLocalIdePath() ?: error("Pre-built IDE with visualisation plugin should be unpacked into './local-ide/'")
downloadSources = false
}
else {
downloadSources = !isTeamCity
}
tasks.withType<PatchPluginXmlTask> {
fun writePatchedPluginXml(pluginXml: Node, outputFile: File) {
BufferedOutputStream(FileOutputStream(outputFile)).use { binaryOutputStream ->
val writer = PrintWriter(OutputStreamWriter(binaryOutputStream, StandardCharsets.UTF_8))
val printer = XmlNodePrinter(writer)
printer.isPreserveWhitespace = true
printer.print(pluginXml)
}
}
sinceBuild("${ideMajorVersion()}.${ideMinorVersion()}")
untilBuild("${ideMajorVersion()}.*")
}
}
tasks.withType<PublishTask> {
username(prop("publishUsername"))
password(prop("publishPassword"))
channels(channel)
}
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "11"
languageVersion = "1.4"
apiVersion = "1.4"
freeCompilerArgs = listOf("-Xjvm-default=enable")
}
}
ideaPlatformPrefix()?.let { prefix ->
tasks.withType<org.jetbrains.intellij.tasks.RunIdeBase> {
systemProperty("idea.platform.prefix", prefix)
}
}
configure<JavaPluginConvention> {
sourceCompatibility = VERSION_11
targetCompatibility = VERSION_11
}
afterEvaluate {
val mainSourceSet = sourceSets.getByName("main")
val mainClassPath = mainSourceSet.compileClasspath
val exclusion = mainClassPath.filter { it.name in excludedJars }
mainSourceSet.compileClasspath = mainClassPath - exclusion
tasks.withType<AbstractTestTask> {
testLogging {
if (hasProp("showTestStatus") && prop("showTestStatus").toBoolean()) {
events = setOf(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
exceptionFormat = TestExceptionFormat.FULL
}
}
}
// We need to prevent the platform-specific shared JNA library to loading from the system library paths,
// because otherwise it can lead to compatibility issues.
// Also note that IDEA does the same thing at startup, and not only for tests.
tasks.withType<Test>().configureEach {
systemProperty("jna.nosys", "true")
}
// Some plugins (for example, grammar-kit) may use jitpack.io. It is unstable sometimes, so we use a redirector.
if (repositories.removeIf { it is MavenArtifactRepository && it.url.toString() == "https://jitpack.io" }) {
repositories.add(repositories.maven("https://cache-redirector.jetbrains.com/jitpack.io"))
}
}
}
project(":") {
version = "${ideMajorVersion()}.${ideMinorVersion()}.${prop("buildNumber")}"
intellij {
val plugins = arrayOf("markdown", "yaml") +
(if (isPyCharm()) arrayOf("python-ce") else emptyArray()) +
arrayOf("platform-images", "IntelliLang", "git4idea", "terminal")
pluginName = "rplugin"
setPlugins(*plugins)
}
idea {
module {
generatedSourceDirs.add(file("gen"))
}
}
sourceSets {
main {
val srcDirs = mutableListOf("src", "gen")
srcDirs += "visualisation/src"
if (isPyCharm()) srcDirs += "src-python"
java.srcDirs(*srcDirs.toTypedArray())
val resourcesSrcDirs = mutableListOf("resources", "resources-gradle")
resourcesSrcDirs.add("visualisation/resources")
resources.srcDirs(*resourcesSrcDirs.toTypedArray())
}
test {
val testDirs = if (isPyCharm()) arrayOf("test", "test-python", "visualisation/test") else arrayOf("test", "visualisation/test")
java.srcDirs(*testDirs)
resources.srcDirs( "testData")
}
}
tasks.processResources {
outputs.upToDateWhen { false }
}
tasks.prepareSandbox {
prepareSandbox(this, this@project)
}
tasks.prepareTestingSandbox {
prepareSandbox(this, this@project, isTestingSandbox = true)
}
tasks.runIde {
doFirst {
val prepareSandboxTask = tasks.prepareSandbox.get()
val name = prepareSandboxTask.pluginName
delete(prepareSandboxTask.destinationDir.toString() + "/" + name + "/" + name.toLowerCase() + ".jar")
}
jvmArgs = listOf("-Dsun.java2d.uiScale.enabled=false", "-Xmx1024M")
jbrVersion("11_0_8b1098.2")
}
tasks.buildPlugin {
from("r-helpers")
}
}
tasks {
val listRepos by registering(DefaultTask::class)
listRepos {
doLast {
project.repositories.forEach {
println(it.name)
if (it is MavenArtifactRepository) {
println(it.url)
}
if (it is IvyArtifactRepository) {
println(it.url)
}
}
}
}
}
fun hasProp(name: String): Boolean = extra.has(name)
fun prop(name: String): String =
extra.properties[name] as? String
?: error("Property `$name` is not defined in gradle.properties")
fun prepareSandbox(prepareSandboxTask: PrepareSandboxTask, project: Project, isTestingSandbox: Boolean = false) {
buildRWrapper(project)
doCopyRWrapperTask(prepareSandboxTask, project)
}
fun buildRWrapper(project: Project) {
if (!rwrapperBuilt && !isTeamCity && OperatingSystem.current()?.isUnix == true) {
rwrapperBuilt = true
val workingDir = "${project.rootDir}/rwrapper"
File("$workingDir/build_rwrapper.sh").takeIf { it.exists() }?.let { script ->
project.exec {
commandLine(script)
workingDir(workingDir)
}
}
}
}
fun doCopyRWrapperTask(prepareSandboxTask: PrepareSandboxTask, project: Project) {
prepareSandboxTask.inputs.files(*(File("rwrapper").takeIf { it.exists() && it.isDirectory }?.list { _, name ->
name.startsWith("rwrapper") || name.startsWith("R-") || name == "R" || name.startsWith("fsnotifier-")
}?.map { "rwrapper/$it" }?.toTypedArray() ?: emptyArray<String>()))
prepareSandboxTask.doLast {
project.copy {
from("rwrapper/R")
into(prepareSandboxTask.destinationDir.toString() + "/" + prepareSandboxTask.pluginName + "/R")
}
project.copy {
from("rwrapper")
include("crashpad_handler*")
into(prepareSandboxTask.destinationDir.toString() + "/" + prepareSandboxTask.pluginName)
}
project.copy {
from("rwrapper")
include("R-*/*")
into(prepareSandboxTask.destinationDir.toString() + "/" + prepareSandboxTask.pluginName)
}
project.copy {
from("rwrapper")
include("rwrapper*")
into(prepareSandboxTask.destinationDir.toString() + "/" + prepareSandboxTask.pluginName)
}
project.copy {
from("rwrapper")
include("fsnotifier-*")
into(prepareSandboxTask.destinationDir.toString() + "/" + prepareSandboxTask.pluginName)
}
}
}
val Project.dependencyCachePath get(): String {
val cachePath = file("${rootProject.projectDir}/deps")
// If cache path doesn't exist, we need to create it manually
// because otherwise gradle-intellij-plugin will ignore it
if (!cachePath.exists()) {
cachePath.mkdirs()
}
return cachePath.absolutePath
}
fun Build_gradle.ideMinorVersion() = prop("ideMinor")
fun Build_gradle.ideMajorVersion() = prop("ideMajor")
fun Build_gradle.ideName() = prop("ideName")
fun Build_gradle.isPyCharm() = ideName().contains("PY") || ideName().contains("PC") || ideaPlatformPrefix()?.contains("PyCharm") == true
fun Build_gradle.guessLocalIdePath(): String? =
file("local-ide")
.takeIf { it.resolve("build.txt").exists() }
?.absolutePath
fun Build_gradle.useInlayVisualisationFromPlugin(): Boolean =
extra.properties["useInlayVisualisationFromPlugin"] == "true"
fun Build_gradle.ideaPlatformPrefix(): String? =
(extra.properties["ideaPlatformPrefix"] as? String)?.takeIf { it.isNotBlank() }
@kotlin.jvm.Volatile
private var rwrapperBuilt = false