Skip to content

Commit b3f3d02

Browse files
authored
Convert generate script to gradle task (#8)
1 parent 2433eee commit b3f3d02

File tree

6 files changed

+90
-53
lines changed

6 files changed

+90
-53
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,16 @@
33
# OpenTelemetry Semantic Conventions for Java
44

55
Java code-generation for the [OpenTelemetry Semantic Conventions](https://github.com/open-telemetry/semantic-conventions).
6+
7+
## Generating semantic conventions
8+
9+
Prerequisites:
10+
- Docker
11+
- JDK 17+
12+
13+
In a shell, execute the following gradle tasks:
14+
15+
```shell
16+
./gradlew generateSemanticConventions --console=plain
17+
./gradlew spotlessApply
18+
```

build.gradle.kts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import de.undercouch.gradle.tasks.download.Download
2+
13
plugins {
24
id("otel.java-conventions")
35

46
id("otel.animalsniffer-conventions")
7+
8+
id("de.undercouch.download")
59
}
610

711
dependencies {
@@ -15,3 +19,75 @@ dependencies {
1519
testImplementation(platform("org.assertj:assertj-bom:3.24.2"))
1620
testImplementation("org.assertj:assertj-core")
1721
}
22+
23+
val specificationVersion = "1.20.0"
24+
var generatorVersion = "0.18.0"
25+
26+
val specificationRepoZip = "https://github.com/open-telemetry/opentelemetry-specification/archive/v$specificationVersion.zip"
27+
val schemaUrl = "https://opentelemetry.io/schemas/$specificationVersion"
28+
29+
val downloadSpecification by tasks.registering(Download::class) {
30+
src(specificationRepoZip)
31+
dest("$buildDir/opentelemetry-specification/opentelemetry-specification.zip")
32+
overwrite(false)
33+
}
34+
35+
val unzipConfigurationSchema by tasks.registering(Copy::class) {
36+
dependsOn(downloadSpecification)
37+
38+
from(zipTree(downloadSpecification.get().dest))
39+
eachFile(closureOf<FileCopyDetails> {
40+
// Remove the top level folder "/opentelemetry-specification-$semanticConventionsVersion"
41+
val pathParts = path.split("/")
42+
path = pathParts.subList(1, pathParts.size).joinToString("/")
43+
})
44+
into("$buildDir/opentelemetry-specification/")
45+
}
46+
47+
val generateSemanticAttributes by tasks.registering(Exec::class) {
48+
dependsOn(unzipConfigurationSchema)
49+
50+
standardOutput = System.out
51+
executable = "docker"
52+
setArgs(listOf(
53+
"run",
54+
"--rm",
55+
"-v", "$buildDir/opentelemetry-specification/semantic_conventions:/source",
56+
"-v", "$projectDir/buildscripts/templates:/templates",
57+
"-v", "$projectDir/src/main/java/io/opentelemetry/semconv/trace/attributes/:/output",
58+
"otel/semconvgen:$generatorVersion",
59+
"--only", "span,event,attribute_group,scope",
60+
"-f", "/source", "code",
61+
"--template", "/templates/SemanticAttributes.java.j2",
62+
"--output", "/output/SemanticAttributes.java",
63+
"-Dsemconv=trace",
64+
"-Dclass=SemanticAttributes",
65+
"-DschemaUrl=$schemaUrl",
66+
"-Dpkg=io.opentelemetry.semconv.trace.attributes"))
67+
}
68+
69+
val generateResourceAttributes by tasks.registering(Exec::class) {
70+
dependsOn(unzipConfigurationSchema)
71+
72+
standardOutput = System.out
73+
executable = "docker"
74+
setArgs(listOf(
75+
"run",
76+
"--rm",
77+
"-v", "$buildDir/opentelemetry-specification/semantic_conventions:/source",
78+
"-v", "$projectDir/buildscripts/templates:/templates",
79+
"-v", "$projectDir/src/main/java/io/opentelemetry/semconv/resource/attributes/:/output",
80+
"otel/semconvgen:$generatorVersion",
81+
"--only", "resource",
82+
"-f", "/source", "code",
83+
"--template", "/templates/SemanticAttributes.java.j2",
84+
"--output", "/output/ResourceAttributes.java",
85+
"-Dclass=ResourceAttributes",
86+
"-DschemaUrl=$schemaUrl",
87+
"-Dpkg=io.opentelemetry.semconv.resource.attributes"))
88+
}
89+
90+
val generateSemanticConventions by tasks.registering {
91+
dependsOn(generateSemanticAttributes)
92+
dependsOn(generateResourceAttributes)
93+
}

buildscripts/semantic-convention/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

buildscripts/semantic-convention/generate.sh

Lines changed: 0 additions & 52 deletions
This file was deleted.

buildscripts/semantic-convention/templates/SemanticAttributes.java.j2 renamed to buildscripts/templates/SemanticAttributes.java.j2

File renamed without changes.

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pluginManagement {
22
plugins {
33
id("com.gradle.enterprise") version "3.14.1"
4+
id("de.undercouch.download") version "5.4.0"
45
}
56
}
67

0 commit comments

Comments
 (0)