@@ -2,12 +2,6 @@ import de.undercouch.gradle.tasks.download.Download
22import java.time.Duration
33
44plugins {
5- id(" otel.java-conventions" )
6- id(" otel.publish-conventions" )
7- id(" otel.japicmp-conventions" )
8-
9- id(" otel.animalsniffer-conventions" )
10-
115 id(" de.undercouch.download" )
126 id(" io.github.gradle-nexus.publish-plugin" )
137}
@@ -18,6 +12,7 @@ val snapshot = true
1812
1913// The release version of https://github.com/open-telemetry/semantic-conventions used to generate classes
2014var semanticConventionsVersion = " 1.23.1"
15+ val schemaUrlVersions = listOf (semanticConventionsVersion, " 1.22.0" )
2116
2217// Compute the artifact version, which includes the "-alpha" suffix and includes "-SNAPSHOT" suffix if not releasing
2318// Release example: version=1.21.0-alpha
@@ -27,10 +22,8 @@ if (snapshot) {
2722 releaseVersion + = " -SNAPSHOT"
2823}
2924
30- base {
25+ allprojects {
3126 version = releaseVersion
32- description = " OpenTelemetry Semantic Conventions generated classes for Java"
33- archivesName.set(" opentelemetry-semconv" )
3427}
3528
3629nexusPublishing {
@@ -54,22 +47,6 @@ nexusPublishing {
5447 }
5548}
5649
57- val opentelemetryJavaVersion = " 1.31.0"
58-
59- dependencies {
60- compileOnly(" io.opentelemetry:opentelemetry-api:$opentelemetryJavaVersion " )
61-
62- testImplementation(" io.opentelemetry:opentelemetry-api:$opentelemetryJavaVersion " )
63-
64- testImplementation(platform(" org.junit:junit-bom:5.10.0" ))
65- testImplementation(" org.junit.jupiter:junit-jupiter-api" )
66- testImplementation(" org.junit.jupiter:junit-jupiter-params" )
67- testImplementation(" org.junit.jupiter:junit-jupiter-engine" )
68-
69- testImplementation(platform(" org.assertj:assertj-bom:3.24.2" ))
70- testImplementation(" org.assertj:assertj-core" )
71- }
72-
7350// start - define tasks to download, unzip, and generate from opentelemetry/semantic-conventions
7451var generatorVersion = " 0.23.0"
7552val semanticConventionsRepoZip = " https://github.com/open-telemetry/semantic-conventions/archive/v$semanticConventionsVersion .zip"
@@ -93,50 +70,66 @@ val unzipConfigurationSchema by tasks.registering(Copy::class) {
9370 into(" $buildDir /semantic-conventions/" )
9471}
9572
96- val generateSemanticAttributes by tasks.registering(Exec ::class ) {
97- dependsOn(unzipConfigurationSchema)
98-
99- standardOutput = System .out
100- executable = " docker"
101- setArgs(listOf (
102- " run" ,
103- " --rm" ,
104- " -v" , " $buildDir /semantic-conventions/model:/source" ,
105- " -v" , " $projectDir /buildscripts/templates:/templates" ,
106- " -v" , " $projectDir /src/main/java/io/opentelemetry/semconv/:/output" ,
107- " otel/semconvgen:$generatorVersion " ,
108- " --only" , " span,event,attribute_group,scope,metric" ,
109- " --yaml-root" , " /source" , " code" ,
110- " --template" , " /templates/SemanticAttributes.java.j2" ,
111- " --output" , " /output/SemanticAttributes.java" ,
112- " -Dclass=SemanticAttributes" ,
113- " -DschemaUrl=$schemaUrl " ,
114- " -Dpkg=io.opentelemetry.semconv" ))
73+ fun generateTask (taskName : String , resource : Boolean , incubating : Boolean ) {
74+ tasks.register(taskName, Exec ::class ) {
75+ dependsOn(unzipConfigurationSchema)
76+
77+ standardOutput = System .out
78+ executable = " docker"
79+
80+ val onlyArg = if (resource) " resource" else " span,event,attribute_group,scope,metric"
81+ val classNamePrefix = if (incubating) " Incubating" else " "
82+ var className = if (resource) " ${classNamePrefix} ResourceAttributes" else " ${classNamePrefix} SemanticAttributes"
83+ val outputDir = if (incubating) " semconv-incubating/src/main/java/io/opentelemetry/semconv/incubating/" else " semconv/src/main/java/io/opentelemetry/semconv/"
84+ val stability = if (incubating) " StabilityLevel.EXPERIMENTAL" else " StabilityLevel.STABLE"
85+ val packageNameArg = if (incubating) " io.opentelemetry.semconv.incubating" else " io.opentelemetry.semconv"
86+
87+ setArgs(listOf (
88+ " run" ,
89+ " --rm" ,
90+ " -v" , " $buildDir /semantic-conventions/model:/source" ,
91+ " -v" , " $projectDir /buildscripts/templates:/templates" ,
92+ " -v" , " $projectDir /$outputDir :/output" ,
93+ " otel/semconvgen:$generatorVersion " ,
94+ " --only" , onlyArg,
95+ " --yaml-root" , " /source" , " code" ,
96+ " --template" , " /templates/SemanticAttributes.java.j2" ,
97+ " --output" , " /output/$className .java" ,
98+ " -Dclass=$className " ,
99+ " -Dstability=${stability} " ,
100+ " -Dpkg=$packageNameArg " ))
101+ }
115102}
116103
117- val generateResourceAttributes by tasks.registering(Exec ::class ) {
118- dependsOn(unzipConfigurationSchema)
119-
120- standardOutput = System .out
121- executable = " docker"
122- setArgs(listOf (
123- " run" ,
124- " --rm" ,
125- " -v" , " $buildDir /semantic-conventions/model:/source" ,
126- " -v" , " $projectDir /buildscripts/templates:/templates" ,
127- " -v" , " $projectDir /src/main/java/io/opentelemetry/semconv/:/output" ,
128- " otel/semconvgen:$generatorVersion " ,
129- " --only" , " resource" ,
130- " --yaml-root" , " /source" , " code" ,
131- " --template" , " /templates/SemanticAttributes.java.j2" ,
132- " --output" , " /output/ResourceAttributes.java" ,
133- " -Dclass=ResourceAttributes" ,
134- " -DschemaUrl=$schemaUrl " ,
135- " -Dpkg=io.opentelemetry.semconv" ))
104+ generateTask(" generateStableSemanticAttributes" , false , false )
105+ generateTask(" generateIncubatingSemanticAttributes" , false , true )
106+ generateTask(" generateStableResourceAttributes" , true , false )
107+ generateTask(" generateIncubatingResourceAttributes" , true , true )
108+
109+ tasks.register(" checkSchemaUrls" ) {
110+ val schemaUrlsClass = File (" $projectDir /semconv/src/main/java/io/opentelemetry/semconv/SchemaUrls.java" )
111+ if (! schemaUrlsClass.exists()) {
112+ throw GradleException (" SchemaUrls file does not exist" )
113+ }
114+
115+ for (schemaUrlVersion: String in schemaUrlVersions) {
116+ val expectedLine = " public static final String V" + schemaUrlVersion.replace(" ." , " _" ) + " = \" https://opentelemetry.io/schemas/" + schemaUrlVersion + " \" ;"
117+ if (! schemaUrlsClass.readLines().any { it.contains(expectedLine) }) {
118+ throw GradleException (" SchemaUrls file does not contain: $expectedLine " )
119+ }
120+ }
136121}
137122
138123val generateSemanticConventions by tasks.registering {
139- dependsOn(generateSemanticAttributes)
140- dependsOn(generateResourceAttributes)
124+ dependsOn(tasks.getByName(" generateStableSemanticAttributes" ))
125+ dependsOn(tasks.getByName(" generateIncubatingSemanticAttributes" ))
126+ dependsOn(tasks.getByName(" generateStableResourceAttributes" ))
127+ dependsOn(tasks.getByName(" generateIncubatingResourceAttributes" ))
128+ dependsOn(tasks.getByName(" checkSchemaUrls" ))
129+ }
130+
131+ tasks.register(" build" ) {
132+ dependsOn(tasks.getByName(" checkSchemaUrls" ))
141133}
134+
142135// end
0 commit comments