Skip to content

Commit 1a87892

Browse files
committed
Add OSGi manifest headers for jars
1 parent 05cc138 commit 1a87892

File tree

6 files changed

+57
-2
lines changed

6 files changed

+57
-2
lines changed

buildSrc/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ dependencies {
1414
implementation("me.champeau.gradle:japicmp-gradle-plugin:0.4.2")
1515
// Needed for japicmp but not automatically brought in for some reason.
1616
implementation("com.google.guava:guava:32.1.3-jre")
17+
implementation("biz.aQute.bnd:biz.aQute.bnd.gradle:7.0.0")
1718
}

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

+1
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

+12-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ plugins {
88
eclipse
99
idea
1010

11+
id("biz.aQute.bnd.builder")
1112
id("otel.spotless-conventions")
1213
}
1314

@@ -59,6 +60,9 @@ tasks {
5960
)
6061
}
6162

63+
systemProperty("felix.cache.dir", buildDir)
64+
systemProperty("felix.bundle.path", "$buildDir/libs/${project.base.archivesName.get()}-${project.version}.jar")
65+
6266
testLogging {
6367
exceptionFormat = TestExceptionFormat.FULL
6468
showExceptions = true
@@ -88,11 +92,17 @@ tasks {
8892

8993
manifest {
9094
attributes(
91-
"Automatic-Module-Name" to otelJava.moduleName,
95+
"Automatic-Module-Name" to otelJava.moduleName,
9296
"Built-By" to System.getProperty("user.name"),
9397
"Built-JDK" to System.getProperty("java.version"),
9498
"Implementation-Title" to project.base.archivesName,
95-
"Implementation-Version" to project.version)
99+
"Implementation-Version" to project.version,
100+
// Add OSGi manifest headers with bnd
101+
"-exportcontents" to "${otelJava.moduleName.get()}.*",
102+
"Bundle-Name" to otelJava.bundleName,
103+
"Bundle-SymbolicName" to "${otelJava.moduleName.get()}.${project.base.archivesName.get()}",
104+
"Import-Package" to "io.opentelemetry.api.*;resolution:=optional" // FIXME: should not be optional, dependency should be provided
105+
)
96106
}
97107
}
98108

semconv-incubating/build.gradle.kts

+1
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

+3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ 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+
testImplementation("org.apache.felix:org.apache.felix.framework:7.0.5")
22+
testImplementation("org.osgi:osgi.core:6.0.0")
2023
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.semconv;
7+
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
import java.io.File;
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
import org.apache.felix.framework.Felix;
14+
import org.junit.jupiter.api.Test;
15+
import org.osgi.framework.Bundle;
16+
import org.osgi.framework.BundleContext;
17+
import org.osgi.framework.BundleException;
18+
import org.osgi.framework.Constants;
19+
import org.osgi.framework.launch.Framework;
20+
21+
class OSGiBundleTest {
22+
@Test
23+
void bundleIsActive() throws BundleException {
24+
Map<String, String> params = new HashMap<String, String>();
25+
params.put(Constants.FRAMEWORK_STORAGE, System.getProperty("felix.cache.dir"));
26+
27+
Framework framework = new Felix(params);
28+
framework.init();
29+
framework.start();
30+
31+
BundleContext context = framework.getBundleContext();
32+
File bundleFile = new File(System.getProperty("felix.bundle.path"));
33+
34+
Bundle bundle = context.installBundle(bundleFile.toURI().toString());
35+
bundle.start();
36+
37+
assertEquals(Bundle.ACTIVE, bundle.getState());
38+
}
39+
}

0 commit comments

Comments
 (0)