script to select modules to work with (#10090)

This commit is contained in:
Gregor Zeitlinger 2024-01-03 22:19:40 +01:00 committed by GitHub
parent 1c1ca91643
commit a1d5729f26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 93 additions and 0 deletions

View File

@ -31,6 +31,16 @@ on which you are not actively working.
Specifically, unload all modules, and then selectively load the modules on which you need to work.
IntelliJ will prompt you to load additional modules on which the selected modules depend.
If you are working on a specific instrumentation, you can load only the modules for that instrumentation.
For example, to load the modules for the Spring Boot autoconfigure instrumentation, run:
```shell
./docs/contributing/selectModules.kts instrumentation/spring/spring-boot-autoconfigure/
```
Install the [Kotlin executable](https://kotlinlang.org/docs/tutorials/command-line.html)
if you don't have it already.
## Troubleshooting
Occasionally, Intellij gets confused, maybe due to the number of modules in this project,

View File

@ -0,0 +1,83 @@
#!/usr/bin/env kotlin
//install kotlin compiler: https://kotlinlang.org/docs/tutorials/command-line.html
import java.io.File
val includeRegex = Regex("include\\(\"(.*?)\"\\)")
val projectRegex = "project\\(\"([^\"]+)\"(, configuration = \".*\")?\\)".toRegex()
val keepModules = mutableSetOf<Module>()
var root = ""
main(args)
fun main(args: Array<String>) {
if (args.isEmpty()) {
println("Usage: ./docs/contributing/selectModules.kts instrumentation/spring/spring-boot-autoconfigure/ <module to include2> ...")
return
}
(args.map {
moduleOfArg(
File(File(it).absolutePath),
"/" + it.trimStart('.', '/').trimEnd('/')
)
} + listOf(":javaagent"))
.map { Module(it) }
.forEach(Module::addSelfAndChildren)
File("$root/conventions/src/main/kotlin").listFiles()!!
.filter { it.name.endsWith(".kts") }
.forEach {
children(it).forEach(Module::addSelfAndChildren)
}
println("removing modules except:\n${keepModules.map { it.name }.sorted().joinToString("\n")}")
val target = File("$root/settings.gradle.kts")
val text = target.readText().lines().flatMap { line ->
includeRegex.matchEntire(line)?.let { it.groupValues[1] }?.let { module ->
if (Module(module) in keepModules) {
listOf(line)
} else {
emptyList()
}
} ?: listOf(line)
}.joinToString("\n")
target.writeText(text)
}
data class Module(val name: String) {
fun children(): List<Module> {
val file = moduleFile()
return children(file)
}
private fun moduleFile(): File = File("$root/${name.replace(":", "/")}/build.gradle.kts")
fun addSelfAndChildren() {
if (!keepModules.add(this)) {
return
}
children().forEach(Module::addSelfAndChildren)
}
}
fun moduleOfArg(file: File, name: String): String {
val settings = File(file, "settings.gradle.kts")
return if (settings.exists()) {
root = file.absolutePath
name.substringAfter(root).replace("/", ":")
} else {
moduleOfArg(file.parentFile, name)
}
}
fun children(file: File) = file.readText().lines().flatMap { line ->
projectRegex.find(line)?.let { it.groupValues[1] }?.let { module ->
listOf(Module(module))
} ?: emptyList()
}