Skip to content

Commit

Permalink
Add initial test for Felix OSGi implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
bdhoine committed Aug 28, 2024
1 parent 1df9980 commit e59f33f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ import org.gradle.api.provider.Property

abstract class OtelJavaExtension {
abstract val moduleName: Property<String>
abstract val bundleName: Property<String>
}
6 changes: 5 additions & 1 deletion buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
Expand Down
1 change: 1 addition & 0 deletions semconv-incubating/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
4 changes: 4 additions & 0 deletions semconv/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
36 changes: 36 additions & 0 deletions semconv/src/test/java/io/opentelemetry/semconv/OSGiBundleTest.java
Original file line number Diff line number Diff line change
@@ -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<String,String> params = new HashMap<String, String>();
// 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());
}
}

0 comments on commit e59f33f

Please sign in to comment.