diff --git a/buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelJavaExtension.kt b/buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelJavaExtension.kt index bf584e7..2ad241f 100644 --- a/buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelJavaExtension.kt +++ b/buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelJavaExtension.kt @@ -9,4 +9,5 @@ import org.gradle.api.provider.Property abstract class OtelJavaExtension { abstract val moduleName: Property + abstract val bundleName: Property } diff --git a/buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts b/buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts index 2a9ff0b..6099a10 100644 --- a/buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts @@ -94,7 +94,11 @@ tasks { "Built-JDK" to System.getProperty("java.version"), "Implementation-Title" to project.base.archivesName, "Implementation-Version" to project.version, - "-exportcontents" to "${otelJava.moduleName.get()}.*" + // Add OSGi manifest headers with bnd + "-exportcontents" to "${otelJava.moduleName.get()}.*", + "Bundle-Name" to otelJava.bundleName, + "Bundle-SymbolicName" to "${otelJava.moduleName.get()}.${project.base.archivesName.get()}", + "Import-Package" to "io.opentelemetry.api.*;resolution:=optional" // FIXME: should not be optional, dependency should be provided ) } } diff --git a/semconv-incubating/build.gradle.kts b/semconv-incubating/build.gradle.kts index 3a5eee4..e8f814b 100644 --- a/semconv-incubating/build.gradle.kts +++ b/semconv-incubating/build.gradle.kts @@ -10,6 +10,7 @@ base { archivesName.set("opentelemetry-semconv-incubating") } otelJava.moduleName.set("io.opentelemetry.semconv.incubating") +otelJava.bundleName.set("OpenTelemetry - Semantic Conventions Incubating") dependencies { api(project(":semconv")) diff --git a/semconv/build.gradle.kts b/semconv/build.gradle.kts index 890c43f..eacebad 100644 --- a/semconv/build.gradle.kts +++ b/semconv/build.gradle.kts @@ -12,9 +12,13 @@ base { archivesName.set("opentelemetry-semconv") } otelJava.moduleName.set("io.opentelemetry.semconv") +otelJava.bundleName.set("OpenTelemetry - Semantic Conventions") dependencies { compileOnly("io.opentelemetry:opentelemetry-api") testImplementation("io.opentelemetry:opentelemetry-api") + // FIXME: dependency and version should not be managed here + testImplementation("org.apache.felix:org.apache.felix.framework:7.0.5") + testImplementation("org.osgi:osgi.core:6.0.0") } diff --git a/semconv/src/test/java/io/opentelemetry/semconv/OSGiBundleTest.java b/semconv/src/test/java/io/opentelemetry/semconv/OSGiBundleTest.java new file mode 100644 index 0000000..cd5b86b --- /dev/null +++ b/semconv/src/test/java/io/opentelemetry/semconv/OSGiBundleTest.java @@ -0,0 +1,36 @@ +package io.opentelemetry.semconv; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; +import org.apache.felix.framework.Felix; +import org.junit.jupiter.api.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; +import org.osgi.framework.Constants; +import org.osgi.framework.launch.Framework; + +class OSGiBundleTest { + @Test + void bundleIsActive() throws BundleException { + Map params = new HashMap(); + // FIXME: do not use hardcoded build path + params.put(Constants.FRAMEWORK_STORAGE, "build"); + + Framework framework = new Felix(params); + framework.init(); + framework.start(); + + BundleContext context = framework.getBundleContext(); + // FIXME: do not use hardcoded bundle path + File bundleFile = new File("build/libs/opentelemetry-semconv-1.27.0-alpha-SNAPSHOT.jar"); + + Bundle bundle = context.installBundle(bundleFile.toURI().toString()); + bundle.start(); + + assertEquals(Bundle.ACTIVE, bundle.getState()); + } +}