Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert generate script to gradle task #8

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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