Created
December 14, 2023 17:07
-
-
Save zeitlinger/8e41eb262f7a1581fd8cba2f40e67ffc to your computer and use it in GitHub Desktop.
script to prune unneeded modules from javaagent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
here's the idea that you want to work on spring-boot-starter