Skip to content

Commit

Permalink
OSGi import/export headers
Browse files Browse the repository at this point in the history
- <developers><developer><id> element added to silence a complaint from bnd about well formed entries
- let bnd generate default manifest spec entries, as well as setting all other headers
- added BND SPI annotations to add the necessary parts to make ServiceLoader work in OSGi (passively)

fixes #242

Signed-off-by: Raymond Augé <[email protected]>
  • Loading branch information
rotty3000 committed Oct 5, 2021
1 parent f55bb5d commit 6085f9d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties

# Eclipse
.project
.classpath
.settings

# IntelliJ
out/
build/
Expand Down
51 changes: 45 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<jsr305.version>3.0.2</jsr305.version>
<junit.version>5.7.0</junit.version>
<assertj.version>3.17.2</assertj.version>
<bnd.version>6.0.0</bnd.version>
<osgi.annotation.version>8.0.0</osgi.annotation.version>
<project.build.outputTimestamp>1</project.build.outputTimestamp>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<reactive-streams.version>1.0.3</reactive-streams.version>
Expand All @@ -62,18 +65,22 @@

<developers>
<developer>
<id>nebhale</id>
<name>Ben Hale</name>
<email>[email protected]</email>
</developer>
<developer>
<id>mp911de</id>
<name>Mark Paluch</name>
<email>[email protected]</email>
</developer>
<developer>
<id>mirromutth</id>
<name>Mirro Mutth</name>
<email>[email protected]</email>
</developer>
<developer>
<id>gregturn</id>
<name>Greg Turnquist</name>
<email>[email protected]</email>
</developer>
Expand Down Expand Up @@ -106,6 +113,43 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>${bnd.version}</version>
<executions>
<execution>
<goals>
<goal>bnd-process</goal>
</goals>
</execution>
</executions>
<configuration>
<bnd><![CDATA[
# Vars are ignored from the output
spec.version = ${version;===;${project.version}}
Automatic-Module-Name: ${replacestring;${project.artifactId};-;.}
# Don't import findbugs annotation packages since they are never runtime dependency
Import-Package:\
!javax.annotation.*,\
*
# Automatically export all packages in the resulting jar at spec version
-exportcontents: *;version=${spec.version}
# Add default specification headers
-namesection: io/r2dbc/spi*/;\
Specification-Title="${project.name}";\
Specification-Version="${spec.version}"
# Ensure repeatable builds if desired
-noextraheaders: true
-snapshot: SNAPSHOT
]]></bnd>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -129,12 +173,7 @@
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<R2DBC-Specification-Version>${project.version}</R2DBC-Specification-Version>
</manifestEntries>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
Expand Down
14 changes: 4 additions & 10 deletions r2dbc-spi-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,17 @@

<build>
<plugins>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Automatic-Module-Name>r2dbc.spi.test</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
26 changes: 19 additions & 7 deletions r2dbc-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
<artifactId>reactive-streams</artifactId>
<version>${reactive-streams.version}</version>
</dependency>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bnd.annotation</artifactId>
<version>${bnd.version}</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.annotation</artifactId>
<version>${osgi.annotation.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
Expand All @@ -63,20 +73,22 @@

<build>
<plugins>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<configuration>
<bnd><![CDATA[
R2DBC-Specification-Version: ${project.version}
]]></bnd>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>r2dbc.spi</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@

package io.r2dbc.spi;

import static aQute.bnd.annotation.Cardinality.MULTIPLE;
import static aQute.bnd.annotation.Resolution.OPTIONAL;

import java.util.ServiceLoader;

import aQute.bnd.annotation.spi.ServiceConsumer;

/**
* A Java Service interface for implementations to examine a collection of {@link ConnectionFactoryOptions} and optionally return an implementation of {@link ConnectionFactory}.
* <p>{@link ConnectionFactoryProvider} implementations are typically discovered by {@link ConnectionFactories} from the class path using {@link ServiceLoader}.
Expand All @@ -27,6 +32,15 @@
* @see ConnectionFactories
* @see ServiceLoader
*/

@ServiceConsumer(
// This instance enables resolving a provider at _assembly_ without incurring a strict runtime
// dependency on Service Loader Mediator (SML) impl
cardinality = MULTIPLE, effective = "active", value = ConnectionFactoryProvider.class)
@ServiceConsumer(
// This instance enables SML to instrument ServiceLoader calls _if SML is present_
// (without preventing the bundles from resolving if it is not)
cardinality = MULTIPLE, resolution = OPTIONAL, value = ConnectionFactoryProvider.class)
public interface ConnectionFactoryProvider {

/**
Expand Down

0 comments on commit 6085f9d

Please sign in to comment.