Skip to content

Instantly share code, notes, and snippets.

@zeitlinger
Created December 14, 2023 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeitlinger/8e41eb262f7a1581fd8cba2f40e67ffc to your computer and use it in GitHub Desktop.
Save zeitlinger/8e41eb262f7a1581fd8cba2f40e67ffc to your computer and use it in GitHub Desktop.
script to prune unneeded modules from javaagent
import java.io.File
val depFiles = listOf(
File("/home/gregor/source/opentelemetry-java-instrumentation/instrumentation/spring/starters/spring-boot-starter/dep.txt"),
File("/home/gregor/source/opentelemetry-java-instrumentation/javaagent/dep.txt"), // gradle dependencies --configuration baseJavaagentLibs > dep.txt
)
val target = File("/home/gregor/source/opentelemetry-java-instrumentation/settings.gradle.kts")
val includeRegex = Regex("include\\(\"(.*?)\"\\)")
val projectRegex = listOf(Regex("project ([^ ]+)"), Regex("Project '([^']+)'"))
val special = listOf("external-annotations","instrumentation:executors")
fun main() {
//include(":instrumentation:netty:netty-4.1:testing")
val lines = depFiles.flatMap {it.readText().lines() }
val want = lines.flatMap { line ->
val project = projectRegex.mapNotNull {it.find(line)?.let { it.groupValues[1] } }.firstOrNull()
if (project != null) {
listOf(project)
} else {
emptyList()
}
}
val text = target.readText().lines().flatMap { line ->
includeRegex.matchEntire(line)?.let { it.groupValues[1] }?.let { module ->
val dep = want.any { it.contains(module) }
if (dep || !module.startsWith(":instrumentation:") || module.contains(":internal:") || special.any { module.contains(it) }){
listOf(line)
} else {
emptyList()
}
} ?: listOf(line)
}.joinToString("\n")
println(text)
target.writeText(text)
}
@zeitlinger
Copy link
Author

here's the idea that you want to work on spring-boot-starter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment