Skip to content

Commit

Permalink
Convert generate script to gradle task (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg authored Aug 15, 2023
1 parent 2433eee commit b3f3d02
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 53 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,16 @@
# OpenTelemetry Semantic Conventions for Java

Java code-generation for the [OpenTelemetry Semantic Conventions](https://github.com/open-telemetry/semantic-conventions).

## Generating semantic conventions

Prerequisites:
- Docker
- JDK 17+

In a shell, execute the following gradle tasks:

```shell
./gradlew generateSemanticConventions --console=plain
./gradlew spotlessApply
```
76 changes: 76 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import de.undercouch.gradle.tasks.download.Download

plugins {
id("otel.java-conventions")

id("otel.animalsniffer-conventions")

id("de.undercouch.download")
}

dependencies {
Expand All @@ -15,3 +19,75 @@ dependencies {
testImplementation(platform("org.assertj:assertj-bom:3.24.2"))
testImplementation("org.assertj:assertj-core")
}

val specificationVersion = "1.20.0"
var generatorVersion = "0.18.0"

val specificationRepoZip = "https://github.com/open-telemetry/opentelemetry-specification/archive/v$specificationVersion.zip"
val schemaUrl = "https://opentelemetry.io/schemas/$specificationVersion"

val downloadSpecification by tasks.registering(Download::class) {
src(specificationRepoZip)
dest("$buildDir/opentelemetry-specification/opentelemetry-specification.zip")
overwrite(false)
}

val unzipConfigurationSchema by tasks.registering(Copy::class) {
dependsOn(downloadSpecification)

from(zipTree(downloadSpecification.get().dest))
eachFile(closureOf<FileCopyDetails> {
// Remove the top level folder "/opentelemetry-specification-$semanticConventionsVersion"
val pathParts = path.split("/")
path = pathParts.subList(1, pathParts.size).joinToString("/")
})
into("$buildDir/opentelemetry-specification/")
}

val generateSemanticAttributes by tasks.registering(Exec::class) {
dependsOn(unzipConfigurationSchema)

standardOutput = System.out
executable = "docker"
setArgs(listOf(
"run",
"--rm",
"-v", "$buildDir/opentelemetry-specification/semantic_conventions:/source",
"-v", "$projectDir/buildscripts/templates:/templates",
"-v", "$projectDir/src/main/java/io/opentelemetry/semconv/trace/attributes/:/output",
"otel/semconvgen:$generatorVersion",
"--only", "span,event,attribute_group,scope",
"-f", "/source", "code",
"--template", "/templates/SemanticAttributes.java.j2",
"--output", "/output/SemanticAttributes.java",
"-Dsemconv=trace",
"-Dclass=SemanticAttributes",
"-DschemaUrl=$schemaUrl",
"-Dpkg=io.opentelemetry.semconv.trace.attributes"))
}

val generateResourceAttributes by tasks.registering(Exec::class) {
dependsOn(unzipConfigurationSchema)

standardOutput = System.out
executable = "docker"
setArgs(listOf(
"run",
"--rm",
"-v", "$buildDir/opentelemetry-specification/semantic_conventions:/source",
"-v", "$projectDir/buildscripts/templates:/templates",
"-v", "$projectDir/src/main/java/io/opentelemetry/semconv/resource/attributes/:/output",
"otel/semconvgen:$generatorVersion",
"--only", "resource",
"-f", "/source", "code",
"--template", "/templates/SemanticAttributes.java.j2",
"--output", "/output/ResourceAttributes.java",
"-Dclass=ResourceAttributes",
"-DschemaUrl=$schemaUrl",
"-Dpkg=io.opentelemetry.semconv.resource.attributes"))
}

val generateSemanticConventions by tasks.registering {
dependsOn(generateSemanticAttributes)
dependsOn(generateResourceAttributes)
}
1 change: 0 additions & 1 deletion buildscripts/semantic-convention/.gitignore

This file was deleted.

52 changes: 0 additions & 52 deletions buildscripts/semantic-convention/generate.sh

This file was deleted.

1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pluginManagement {
plugins {
id("com.gradle.enterprise") version "3.14.1"
id("de.undercouch.download") version "5.4.0"
}
}

Expand Down

0 comments on commit b3f3d02

Please sign in to comment.