1+ import de.undercouch.gradle.tasks.download.Download
2+
13plugins {
24 id(" otel.java-conventions" )
35
46 id(" otel.animalsniffer-conventions" )
7+
8+ id(" de.undercouch.download" )
59}
610
711dependencies {
@@ -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+ }
0 commit comments