Skip to content

Commit e59f33f

Browse files
committed
Add initial test for Felix OSGi implementation
1 parent 1df9980 commit e59f33f

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelJavaExtension.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ import org.gradle.api.provider.Property
99

1010
abstract class OtelJavaExtension {
1111
abstract val moduleName: Property<String>
12+
abstract val bundleName: Property<String>
1213
}

buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ tasks {
9494
"Built-JDK" to System.getProperty("java.version"),
9595
"Implementation-Title" to project.base.archivesName,
9696
"Implementation-Version" to project.version,
97-
"-exportcontents" to "${otelJava.moduleName.get()}.*"
97+
// Add OSGi manifest headers with bnd
98+
"-exportcontents" to "${otelJava.moduleName.get()}.*",
99+
"Bundle-Name" to otelJava.bundleName,
100+
"Bundle-SymbolicName" to "${otelJava.moduleName.get()}.${project.base.archivesName.get()}",
101+
"Import-Package" to "io.opentelemetry.api.*;resolution:=optional" // FIXME: should not be optional, dependency should be provided
98102
)
99103
}
100104
}

semconv-incubating/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ base {
1010
archivesName.set("opentelemetry-semconv-incubating")
1111
}
1212
otelJava.moduleName.set("io.opentelemetry.semconv.incubating")
13+
otelJava.bundleName.set("OpenTelemetry - Semantic Conventions Incubating")
1314

1415
dependencies {
1516
api(project(":semconv"))

semconv/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ base {
1212
archivesName.set("opentelemetry-semconv")
1313
}
1414
otelJava.moduleName.set("io.opentelemetry.semconv")
15+
otelJava.bundleName.set("OpenTelemetry - Semantic Conventions")
1516

1617
dependencies {
1718
compileOnly("io.opentelemetry:opentelemetry-api")
1819

1920
testImplementation("io.opentelemetry:opentelemetry-api")
21+
// FIXME: dependency and version should not be managed here
22+
testImplementation("org.apache.felix:org.apache.felix.framework:7.0.5")
23+
testImplementation("org.osgi:osgi.core:6.0.0")
2024
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.opentelemetry.semconv;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.io.File;
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
import org.apache.felix.framework.Felix;
9+
import org.junit.jupiter.api.Test;
10+
import org.osgi.framework.Bundle;
11+
import org.osgi.framework.BundleContext;
12+
import org.osgi.framework.BundleException;
13+
import org.osgi.framework.Constants;
14+
import org.osgi.framework.launch.Framework;
15+
16+
class OSGiBundleTest {
17+
@Test
18+
void bundleIsActive() throws BundleException {
19+
Map<String,String> params = new HashMap<String, String>();
20+
// FIXME: do not use hardcoded build path
21+
params.put(Constants.FRAMEWORK_STORAGE, "build");
22+
23+
Framework framework = new Felix(params);
24+
framework.init();
25+
framework.start();
26+
27+
BundleContext context = framework.getBundleContext();
28+
// FIXME: do not use hardcoded bundle path
29+
File bundleFile = new File("build/libs/opentelemetry-semconv-1.27.0-alpha-SNAPSHOT.jar");
30+
31+
Bundle bundle = context.installBundle(bundleFile.toURI().toString());
32+
bundle.start();
33+
34+
assertEquals(Bundle.ACTIVE, bundle.getState());
35+
}
36+
}

0 commit comments

Comments
 (0)