-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
101 lines (78 loc) · 2.6 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
// SPDX-FileCopyrightText: © 2024 JetBrains s.r.o.
// SPDX-License-Identifier: Apache-2.0
import org.gradle.api.tasks.PathSensitivity.NONE
import org.gradle.kotlin.dsl.support.serviceOf
plugins {
id("datalyzer.base")
kotlin("jvm") version embeddedKotlinVersion
kotlin("plugin.serialization") version embeddedKotlinVersion
application
id("dev.jacomet.logging-capabilities") version "0.11.0"
}
group = "org.jetbrains.experimental.gradle.datalyzer"
project.version = object {
private val gitVersion = project.gitVersion
override fun toString(): String = gitVersion.get()
}
dependencies {
implementation("org.gradle:gradle-tooling-api:8.6")
implementation("org.slf4j:slf4j-simple:2.0.12")
implementation("org.slf4j:slf4j-api:2.0.12")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
implementation("com.github.ajalt.clikt:clikt:4.2.2")
testImplementation(kotlin("test"))
}
loggingCapabilities {
enforceSlf4JSimple()
}
application {
applicationName = "datalyzer"
mainClass = "org.jetbrains.experimental.gradle.datalyzer.MainKt"
}
kotlin {
jvmToolchain(8)
compilerOptions {
optIn.addAll("kotlin.io.path.ExperimentalPathApi")
}
}
tasks.distZip {
archiveVersion.set("")
}
tasks.distTar {
archiveVersion.set("")
}
val updateReadMeUsage by tasks.registering {
group = project.name
val readme = file("README.md")
outputs.file(readme).withPropertyName("readme")
dependsOn(tasks.installDist)
val datalyzer = tasks.installDist.map { it.destinationDir.resolve("bin/datalyzer") }
inputs.file(datalyzer).withPropertyName("datalyzer").withPathSensitivity(NONE)
onlyIf { "win" !in System.getProperty("os.name").lowercase() }
val providers = serviceOf<ProviderFactory>()
val optionsBlockStartTag = "```shell datalyzer-options"
doLast {
@Suppress("UnstableApiUsage")
val datalyzerHelp = providers.exec {
executable(datalyzer.get())
args("--help")
}.standardOutput.asText
val readmeText = readme.readText()
val startIndex = readmeText.indexOf(optionsBlockStartTag)
.takeIf { it > 0 } ?: error("README is missing datalyzer-options block")
val endIndex = readmeText.indexOf("```", startIndex = startIndex + optionsBlockStartTag.length)
.takeIf { it > 0 } ?: error("could not find end of datalyzer-options block")
val updatedReadme = readmeText.replaceRange(
startIndex = startIndex,
endIndex = endIndex,
replacement = """
|$optionsBlockStartTag
|${datalyzerHelp.get()}
""".trimMargin(),
)
readme.writeText(updatedReadme)
}
}
tasks.assemble {
dependsOn(updateReadMeUsage)
}