Skip to content

Commit

Permalink
Added Automatic-Module-Name header to MANIFEST.MF in instrumentation …
Browse files Browse the repository at this point in the history
…libraries (#9140)

Co-authored-by: Lauri Tulmin <ltulmin@splunk.com>
  • Loading branch information
rjbaucells and laurit authored Oct 11, 2023
1 parent 0de1dcf commit 57e6be4
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion conventions/src/main/kotlin/otel.java-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,41 @@ testing {
}
}

var path = project.path
if (path.startsWith(":instrumentation:")) {
// remove segments that are a prefix of the next segment
// for example :instrumentation:log4j:log4j-context-data:log4j-context-data-2.17 is transformed to log4j-context-data-2.17
var tmpPath = path
val suffix = tmpPath.substringAfterLast(':')
var prefix = ":instrumentation:"
if (suffix == "library") {
// strip ":library" suffix
tmpPath = tmpPath.substringBeforeLast(':')
} else if (suffix == "library-autoconfigure") {
// replace ":library-autoconfigure" with "-autoconfigure"
tmpPath = tmpPath.substringBeforeLast(':') + "-autoconfigure"
} else if (suffix == "javaagent") {
// strip ":javaagent" suffix and add it to prefix
prefix += "javaagent:"
tmpPath = tmpPath.substringBeforeLast(':')
}
val segments = tmpPath.substring(":instrumentation:".length).split(':')
var newPath = ""
var done = false
for (s in segments) {
if (!done && (newPath.isEmpty() || s.startsWith(newPath))) {
newPath = s
} else {
newPath += ":$s"
done = true
}
}
if (newPath.isNotEmpty()) {
path = prefix + newPath
}
}
var javaModuleName = "io.opentelemetry" + path.replace(".", "_").replace("-", "_").replace(":", ".")

tasks {
named<Jar>("jar") {
// By default Gradle Jar task can put multiple files with the same name
Expand All @@ -210,7 +245,8 @@ tasks {
"Implementation-Title" to project.name,
"Implementation-Version" to project.version,
"Implementation-Vendor" to "OpenTelemetry",
"Implementation-URL" to "https://github.com/open-telemetry/opentelemetry-java-instrumentation"
"Implementation-URL" to "https://github.com/open-telemetry/opentelemetry-java-instrumentation",
"Automatic-Module-Name" to javaModuleName
)
}
}
Expand Down

0 comments on commit 57e6be4

Please sign in to comment.