-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle.kts
726 lines (627 loc) · 24.9 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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
import groovy.xml.XmlParser
import org.gradle.api.JavaVersion.VERSION_17
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import org.jetbrains.intellij.platform.gradle.Constants.Configurations
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.intellij.platform.gradle.tasks.*
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jsoup.Jsoup
import java.io.Writer
import kotlin.concurrent.thread
// The same as `--stacktrace` param
gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS
val isCI = System.getenv("CI") != null
val isTeamcity = System.getenv("TEAMCITY_VERSION") != null
val channel = prop("publishChannel")
val platformVersion = prop("platformVersion").toInt()
val baseIDE = prop("baseIDE")
val ideToRun = prop("ideToRun").ifEmpty { baseIDE }
val ideaVersion = prop("ideaVersion")
val baseVersion = versionForIde(baseIDE)
val baseVersionForRun = versionForIde(ideToRun)
val tomlPlugin: String by project
val graziePlugin: String by project
val psiViewerPlugin: String by project
val copyrightPlugin = "com.intellij.copyright"
val javaPlugin = "com.intellij.java"
val javaIdePlugin = "com.intellij.java.ide"
val javaScriptPlugin = "JavaScript"
val mlCompletionPlugin = "com.intellij.completion.ml.ranking"
val compileNativeCodeTaskName = "compileNativeCode"
val grammarKitFakePsiDeps = "grammar-kit-fake-psi-deps"
val basePluginArchiveName = "intellij-rust"
plugins {
idea
kotlin("jvm") version "2.1.0"
id("org.jetbrains.intellij.platform") version "2.0.1"
id("org.jetbrains.grammarkit") version "2022.3.2.2"
id("net.saliman.properties") version "1.5.2"
id("org.gradle.test-retry") version "1.5.10"
}
idea {
module {
// https://github.com/gradle/kotlin-dsl/issues/537/
excludeDirs = excludeDirs + file("testData") + file("deps") + file("bin") +
file("$grammarKitFakePsiDeps/src/main/kotlin")
}
}
allprojects {
apply {
plugin("idea")
plugin("kotlin")
plugin("org.jetbrains.grammarkit")
plugin("org.jetbrains.intellij.platform")
plugin("org.gradle.test-retry")
}
repositories {
mavenCentral()
intellijPlatform {
defaultRepositories()
}
}
idea {
module {
generatedSourceDirs.add(file("src/gen"))
}
}
intellijPlatform {
sandboxContainer.set(layout.buildDirectory.dir("$ideToRun-sandbox-$platformVersion"))
pluginConfiguration {
ideaVersion {
sinceBuild.set(prop("sinceBuild"))
untilBuild.set(prop("untilBuild"))
}
}
pluginVerification {
ides {
recommended()
}
}
}
configure<JavaPluginExtension> {
sourceCompatibility = VERSION_17
targetCompatibility = VERSION_17
}
tasks {
withType<KotlinCompile> {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
languageVersion.set(KotlinVersion.DEFAULT)
// see https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#kotlin-standard-library
apiVersion.set(KotlinVersion.KOTLIN_1_8)
freeCompilerArgs.set(listOf("-Xjvm-default=all"))
}
}
// All these tasks don't make sense for non-root subprojects
// Root project (i.e. `:plugin`) enables them itself if needed
runIde { enabled = false }
prepareSandbox { enabled = false }
buildSearchableOptions { enabled = false }
test {
systemProperty("java.awt.headless", "true")
testLogging {
showStandardStreams = prop("showStandardStreams").toBoolean()
afterSuite(
KotlinClosure2<TestDescriptor, TestResult, Unit>({ desc, result ->
if (desc.parent == null) { // will match the outermost suite
val output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped)"
println(output)
}
})
)
}
if (isCI) {
retry {
maxRetries.set(3)
maxFailures.set(5)
}
}
}
// It makes sense to copy native binaries only for root ("intellij-rust") and "plugin" projects because:
// - `intellij-rust` is supposed to provide all necessary functionality related to procedural macro expander.
// So the binaries are required for the corresponding tests.
// - `plugin` is root project to build plugin artifact and exactly its sandbox is included into the plugin artifact
if (project.name in listOf("intellij-rust", "plugin")) {
task<Exec>(compileNativeCodeTaskName) {
workingDir = rootDir.resolve("native-helper")
executable = "cargo"
// Hack to use unstable `--out-dir` option work for stable toolchain
// https://doc.rust-lang.org/cargo/commands/cargo-build.html#output-options
environment("RUSTC_BOOTSTRAP", "1")
val hostPlatform = DefaultNativePlatform.host()
val archName = when (val archName = hostPlatform.architecture.name) {
"arm-v8", "aarch64" -> "arm64"
else -> archName
}
val outDir = "${rootDir}/bin/${hostPlatform.operatingSystem.toFamilyName()}/$archName"
args("build", "--release", "-Z", "unstable-options", "--out-dir", outDir)
// It may be useful to disable compilation of native code.
// For example, CI builds native code for each platform in separate tasks and puts it into `bin` dir manually
// so there is no need to do it again.
enabled = prop("compileNativeCode").toBoolean()
}
}
}
sourceSets {
main {
java.srcDirs("src/gen")
resources.srcDirs("src/$platformVersion/main/resources")
}
test {
resources.srcDirs("src/$platformVersion/test/resources")
}
}
kotlin {
sourceSets {
main {
kotlin.srcDirs("src/$platformVersion/main/kotlin")
}
test {
kotlin.srcDirs("src/$platformVersion/test/kotlin")
}
}
}
val testOutput = configurations.create("testOutput")
dependencies {
intellijPlatform {
create(baseIDE, baseVersion)
pluginVerifier()
instrumentationTools()
// used in MacroExpansionManager.kt and ResolveCommonThreadPool.kt
testFramework(TestFrameworkType.Platform, configurationName = Configurations.INTELLIJ_PLATFORM_DEPENDENCIES)
}
compileOnly(kotlin("stdlib-jdk8"))
implementation("junit:junit:4.13.2") // used in kotlin/org/rust/openapiext/Testmark.kt
// https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-faq.html#missing-opentest4j-dependency-in-test-framework
testImplementation("org.opentest4j:opentest4j:1.3.0")
testOutput(sourceSets.getByName("test").output.classesDirs)
}
afterEvaluate {
tasks.withType<AbstractTestTask> {
testLogging {
if (hasProp("showTestStatus") && prop("showTestStatus").toBoolean()) {
events = setOf(TestLogEvent.STARTED, TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
}
exceptionFormat = TestExceptionFormat.FULL
}
}
tasks.withType<Test>().configureEach {
jvmArgs = listOf("-Xmx3g", "-XX:-OmitStackTraceInFastThrow")
// 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.
systemProperty("jna.nosys", "true")
// The factory should be set up automatically in `IdeaForkJoinWorkerThreadFactory.setupForkJoinCommonPool`,
// but when tests are launched by Gradle this may not happen because Gradle can use the pool earlier.
// Setting this factory is critical for `ReadMostlyRWLock` performance, so ensure it is properly set
systemProperty(
"java.util.concurrent.ForkJoinPool.common.threadFactory",
"com.intellij.concurrency.IdeaForkJoinWorkerThreadFactory"
)
if (isTeamcity) {
// Make teamcity builds green if only muted tests fail
// https://youtrack.jetbrains.com/issue/TW-16784
ignoreFailures = true
}
if (hasProp("excludeTests")) {
exclude(prop("excludeTests"))
}
}
}
}
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
}
val pluginProjects: List<Project>
get() = rootProject.allprojects.filter { it.name != grammarKitFakePsiDeps }
// Special module with run, build, and publish tasks
project(":plugin") {
val pluginVersion = System.getenv("BUILD_NUMBER") ?: "${platformVersion}.${prop("buildNumber")}"
version = if (pluginVersion.contains(".")) {
val split = pluginVersion.split(".").toMutableList()
split[0] = platformVersion.toString()
// From 232 branch, plugin version `232.9921` and `233.9921` were published
// These versions were based on IJ platform `232.9921` build
//
// From 233 branch, plugin versions are `233.8264` and `232.8264`, which are based on IJ platform `233.8264` build
// Since we publish versions for 2 platform versions from a single branch, plugin versions has to be hacked this way,
// Otherwise newly published `233.8264` version would be considered lower than `233.9921` published earlier
//
// TODO: For `241`, come up with new plugin versioning to avoid this problem
split[1] = (split[1].toIntOrNull()?.plus(10000))?.toString() ?: split[1]
split.joinToString(".")
} else {
pluginVersion
}
intellijPlatform {
pluginConfiguration {
name.set("intellij-rust")
description.set(provider { file("description.html").readText() })
}
}
dependencies {
intellijPlatform {
val pluginList = mutableListOf(
tomlPlugin,
graziePlugin,
psiViewerPlugin,
)
val bundledPluginList = mutableListOf(
javaScriptPlugin,
mlCompletionPlugin
)
if (ideToRun in setOf("IU", "IC")) {
bundledPluginList += listOf(
copyrightPlugin,
javaPlugin,
)
}
create(baseIDE, baseVersionForRun)
plugins(pluginList)
bundledPlugins(bundledPluginList)
pluginModule(implementation(project(":idea")))
pluginModule(implementation(project(":copyright")))
pluginModule(implementation(project(":coverage")))
pluginModule(implementation(project(":duplicates")))
pluginModule(implementation(project(":grazie")))
pluginModule(implementation(project(":js")))
pluginModule(implementation(project(":ml-completion")))
}
implementation(project(":"))
}
// Add plugin sources to the plugin ZIP.
// gradle-intellij-plugin will use it as a plugin sources if the plugin is used as a dependency
val createSourceJar = task<Jar>("createSourceJar") {
dependsOn(":generateLexer")
dependsOn(":generateParser")
for (prj in pluginProjects) {
from(prj.kotlin.sourceSets.main.get().kotlin) {
include("**/*.java")
include("**/*.kt")
}
}
destinationDirectory.set(layout.buildDirectory.dir("libs"))
archiveBaseName.set(basePluginArchiveName)
archiveClassifier.set("src")
}
tasks {
buildPlugin {
dependsOn(createSourceJar)
from(createSourceJar) { into("lib/src") }
// Set proper name for final plugin zip.
// Otherwise, base name is the same as gradle module name
archiveBaseName.set(basePluginArchiveName)
}
runIde { enabled = true }
prepareSandbox {
enabled = true
}
verifyPlugin {
}
buildSearchableOptions {
enabled = prop("enableBuildSearchableOptions").toBoolean()
}
withType<PrepareSandboxTask> {
dependsOn(named(compileNativeCodeTaskName))
// Copy native binaries
from("${rootDir}/bin") {
into("${intellijPlatform.projectName.get()}/bin")
include("**")
}
}
withType<RunIdeTask> {
// Default args for IDEA installation
jvmArgs("-Xmx768m", "-XX:+UseG1GC", "-XX:SoftRefLRUPolicyMSPerMB=50")
// Disable plugin auto reloading. See `com.intellij.ide.plugins.DynamicPluginVfsListener`
jvmArgs("-Didea.auto.reload.plugins=false")
// Don't show "Tip of the Day" at startup
jvmArgs("-Dide.show.tips.on.startup.default.value=false")
// uncomment if `unexpected exception ProcessCanceledException` prevents you from debugging a running IDE
// jvmArgs("-Didea.ProcessCanceledException=disabled")
// Uncomment to enable FUS testing mode
// jvmArgs("-Dfus.internal.test.mode=true")
// Uncomment to enable localization testing mode
// jvmArgs("-Didea.l10n=true")
}
withType<PublishPluginTask> {
token.set(prop("publishToken"))
channels.set(listOf(channel))
}
}
// Generates event scheme for Rust plugin FUS events to `plugin/build/eventScheme.json`
task<RunIdeTask>("buildEventsScheme") {
dependsOn(tasks.prepareSandbox)
args("buildEventsScheme", "--outputFile=${buildDir.resolve("eventScheme.json").absolutePath}", "--pluginId=org.rust.lang")
// BACKCOMPAT: 2024.1. Update value to 242 and this comment
// `IDEA_BUILD_NUMBER` variable is used by `buildEventsScheme` task to write `buildNumber` to output json.
// It will be used by TeamCity automation to set minimal IDE version for new events
environment("IDEA_BUILD_NUMBER", "241")
}
}
project(":$grammarKitFakePsiDeps")
project(":") {
sourceSets {
main {
if (channel == "nightly" || channel == "dev") {
resources.srcDirs("src/main/resources-nightly")
resources.srcDirs("src/$platformVersion/main/resources-nightly")
} else {
resources.srcDirs("src/main/resources-stable")
resources.srcDirs("src/$platformVersion/main/resources-stable")
}
}
}
dependencies {
intellijPlatform {
plugins(listOf(tomlPlugin))
}
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-toml:2.18.2") {
exclude(module = "jackson-core")
exclude(module = "jackson-databind")
exclude(module = "jackson-annotations")
}
api("io.github.z4kn4fein:semver:2.0.0") {
excludeKotlinDeps()
}
implementation("org.eclipse.jgit:org.eclipse.jgit:7.1.0.202411261347-r") {
exclude("org.slf4j")
}
testImplementation("com.squareup.okhttp3:mockwebserver:4.12.0")
}
tasks {
generateLexer {
sourceFile.set(file("src/main/grammars/RustLexer.flex"))
targetOutputDir.set(file("src/gen/org/rust/lang/core/lexer"))
purgeOldFiles.set(true)
}
generateParser {
sourceFile.set(file("src/main/grammars/RustParser.bnf"))
targetRootOutputDir.set(file("src/gen"))
pathToParser.set("org/rust/lang/core/parser/RustParser.java")
pathToPsiRoot.set("org/rust/lang/core/psi")
purgeOldFiles.set(true)
classpath(project(":$grammarKitFakePsiDeps").sourceSets.main.get().runtimeClasspath)
}
withType<KotlinCompile> {
dependsOn(generateLexer, generateParser)
}
// In tests `resources` directory is used instead of `sandbox`
processTestResources {
dependsOn(named(compileNativeCodeTaskName))
from("${rootDir}/bin") {
into("bin")
include("**")
}
}
}
task("resolveDependencies") {
doLast {
rootProject.allprojects
.map { it.configurations }
.flatMap { it.filter { c -> c.isCanBeResolved } }
.forEach { it.resolve() }
}
}
}
project(":idea") {
dependencies {
intellijPlatform {
create(baseIDE, baseVersion)
bundledPlugins(listOf(
javaPlugin,
// this plugin registers `com.intellij.ide.projectView.impl.ProjectViewPane` for IDEA that we use in tests
javaIdePlugin
))
}
implementation(project(":"))
testImplementation(project(":", "testOutput"))
}
}
project(":copyright") {
dependencies {
intellijPlatform {
create(baseIDE, baseVersion)
bundledPlugins(listOf(copyrightPlugin))
}
implementation(project(":"))
testImplementation(project(":", "testOutput"))
}
tasks {
composedJar {
archiveBaseName.set("copyright-rust")
}
}
}
project(":duplicates") {
dependencies {
implementation(project(":"))
testImplementation(project(":", "testOutput"))
}
}
project(":coverage") {
dependencies {
implementation(project(":"))
testImplementation(project(":", "testOutput"))
}
}
project(":grazie") {
dependencies {
intellijPlatform {
plugins(listOf(graziePlugin))
}
implementation(project(":"))
testImplementation(project(":", "testOutput"))
}
tasks {
composedJar {
archiveBaseName.set("grazie-rust")
}
}
}
project(":js") {
dependencies {
intellijPlatform {
bundledPlugins(listOf(javaScriptPlugin))
}
implementation(project(":"))
testImplementation(project(":", "testOutput"))
}
}
project(":ml-completion") {
dependencies {
intellijPlatform {
bundledPlugins(listOf(mlCompletionPlugin))
}
implementation("org.jetbrains.intellij.deps.completion:completion-ranking-rust:0.4.1")
implementation(project(":"))
testImplementation(project(":", "testOutput"))
}
}
task("updateCargoOptions") {
doLast {
val file = File("src/main/kotlin/org/rust/cargo/util/CargoOptions.kt")
file.bufferedWriter().use {
it.writeln("""
/*
* Use of this source code is governed by the MIT license that can be
* found in the LICENSE file.
*/
package org.rust.cargo.util
data class CargoOption(val name: String, val description: String) {
val longName: String get() = "--${'$'}name"
}
""".trimIndent())
it.writeCargoOptions("https://doc.rust-lang.org/cargo/commands")
}
}
}
tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}
fun Writer.writeCargoOptions(baseUrl: String) {
data class CargoOption(
val name: String,
val description: String
)
data class CargoCommand(
val name: String,
val description: String,
val options: List<CargoOption>
)
fun fetchCommand(commandUrl: String): CargoCommand {
val document = Jsoup.connect("$baseUrl/$commandUrl").get()
val fullCommandDesc = document.select("div[class=sectionbody] > p").text()
val parts = fullCommandDesc.split(" - ", limit = 2)
check(parts.size == 2) { "Invalid page format: $baseUrl/$commandUrl$" }
val commandName = parts.first().removePrefix("cargo-")
val commandDesc = parts.last()
val options = document
.select("dt > strong:matches(^--)")
.map { option ->
val optionName = option.text().removePrefix("--")
val nextSiblings = generateSequence(option.parent()) { it.nextElementSibling() }
val descElement = nextSiblings.first { it.tagName() == "dd" }
val fullOptionDesc = descElement.select("p").text()
val optionDesc = fullOptionDesc.substringBefore(". ").removeSuffix(".")
CargoOption(optionName, optionDesc)
}
return CargoCommand(commandName, commandDesc, options)
}
fun fetchCommands(): List<CargoCommand> {
val document = Jsoup.connect("$baseUrl/cargo.html").get()
val urls = document.select("dt > a[href]").map { it.attr("href") }
return urls.map { fetchCommand(it) }
}
fun writeEnumVariant(command: CargoCommand, isLast: Boolean) {
val variantName = command.name.toUpperCase().replace('-', '_')
val renderedOptions = command.options.joinToString(
separator = ",\n ",
prefix = "\n ",
postfix = "\n "
) { "CargoOption(\"${it.name}\", \"\"\"${it.description}\"\"\")" }
writeln("""
| $variantName(
| description = "${command.description}",
| options = ${if (command.options.isEmpty()) "emptyList()" else "listOf($renderedOptions)"}
| )${if (isLast) ";" else ","}
""".trimMargin())
writeln()
}
val commands = fetchCommands()
writeln("enum class CargoCommands(val description: String, val options: List<CargoOption>) {")
for ((index, command) in commands.withIndex()) {
writeEnumVariant(command, isLast = index == commands.size - 1)
}
writeln(" val presentableName: String get() = name.toLowerCase().replace('_', '-')")
writeln("}")
}
fun Writer.writeln(str: String = "") {
write(str)
write("\n")
}
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 versionForIde(ideName: String): String = when (ideName) {
"IU", "IC" -> ideaVersion
else -> error("Unexpected IDE name: `$baseIDE`")
}
inline operator fun <T : Task> T.invoke(a: T.() -> Unit): T = apply(a)
fun String.execute(wd: String? = null, ignoreExitCode: Boolean = false, print: Boolean = true): String =
split(" ").execute(wd, ignoreExitCode, print)
fun List<String>.execute(wd: String? = null, ignoreExitCode: Boolean = false, print: Boolean = true): String {
val process = ProcessBuilder(this)
.also { pb -> wd?.let { pb.directory(File(it)) } }
.start()
var result = ""
val errReader = thread { process.errorStream.bufferedReader().forEachLine { println(it) } }
val outReader = thread {
process.inputStream.bufferedReader().forEachLine { line ->
if (print) {
println(line)
}
result += line
}
}
process.waitFor()
outReader.join()
errReader.join()
if (process.exitValue() != 0 && !ignoreExitCode) error("Non-zero exit status for `$this`")
return result
}
fun File.isPluginJar(): Boolean {
if (!isFile) return false
if (extension != "jar") return false
return zipTree(this).files.any { it.isManifestFile() }
}
fun File.isManifestFile(): Boolean {
if (extension != "xml") return false
val rootNode = try {
val parser = XmlParser()
parser.parse(this)
} catch (e: Exception) {
logger.error("Failed to parse $path", e)
return false
}
return rootNode.name() == "idea-plugin"
}
fun <T : ModuleDependency> T.excludeKotlinDeps() {
exclude(module = "kotlin-reflect")
exclude(module = "kotlin-runtime")
exclude(module = "kotlin-stdlib")
exclude(module = "kotlin-stdlib-common")
exclude(module = "kotlin-stdlib-jdk8")
exclude(module = "kotlinx-serialization-core")
}