Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OSGi manifest headers for jars #87

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add OSGi manifest headers for jars
bdhoine committed Aug 28, 2024
commit 1e4faa6b681797258606150334e66ece80f436fb
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -14,4 +14,5 @@ dependencies {
implementation("me.champeau.gradle:japicmp-gradle-plugin:0.4.2")
// Needed for japicmp but not automatically brought in for some reason.
implementation("com.google.guava:guava:32.1.3-jre")
implementation("biz.aQute.bnd:biz.aQute.bnd.gradle:7.0.0")
}
Original file line number Diff line number Diff line change
@@ -9,4 +9,5 @@ import org.gradle.api.provider.Property

abstract class OtelJavaExtension {
abstract val moduleName: Property<String>
abstract val bundleName: Property<String>
}
14 changes: 12 additions & 2 deletions buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ plugins {
eclipse
idea

id("biz.aQute.bnd.builder")
id("otel.spotless-conventions")
}

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

systemProperty("felix.cache.dir", buildDir)
systemProperty("felix.bundle.path", "$buildDir/libs/${project.base.archivesName.get()}-${project.version}.jar")

testLogging {
exceptionFormat = TestExceptionFormat.FULL
showExceptions = true
@@ -88,11 +92,17 @@ tasks {

manifest {
attributes(
"Automatic-Module-Name" to otelJava.moduleName,
"Automatic-Module-Name" to otelJava.moduleName,
"Built-By" to System.getProperty("user.name"),
"Built-JDK" to System.getProperty("java.version"),
"Implementation-Title" to project.base.archivesName,
"Implementation-Version" to project.version)
"Implementation-Version" to project.version,
// 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
)
}
}

1 change: 1 addition & 0 deletions semconv-incubating/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"))
3 changes: 3 additions & 0 deletions semconv/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -12,9 +12,12 @@ 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")
testImplementation("org.apache.felix:org.apache.felix.framework:7.0.5")
testImplementation("org.osgi:osgi.core:6.0.0")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

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>();
params.put(Constants.FRAMEWORK_STORAGE, System.getProperty("felix.cache.dir"));

Framework framework = new Felix(params);
framework.init();
framework.start();

BundleContext context = framework.getBundleContext();
File bundleFile = new File(System.getProperty("felix.bundle.path"));

Bundle bundle = context.installBundle(bundleFile.toURI().toString());
bundle.start();

assertEquals(Bundle.ACTIVE, bundle.getState());
}
}