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

OSGi import/export headers #247

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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
77 changes: 71 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@
<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>
<reactor.version>Dysprosium-SR12</reactor.version>
<spring.version>5.2.6.RELEASE</spring.version>
</properties>

<licenses>
Expand All @@ -62,18 +66,22 @@

<developers>
<developer>
<id>nebhale</id>
<name>Ben Hale</name>
<email>bhale@pivotal.io</email>
</developer>
<developer>
<id>mp911de</id>
<name>Mark Paluch</name>
<email>mpaluch@vmware.com</email>
</developer>
<developer>
<id>mirromutth</id>
<name>Mirro Mutth</name>
<email>mirromutth@gmail.com</email>
</developer>
<developer>
<id>gregturn</id>
<name>Greg Turnquist</name>
<email>gturnquist@pivotal.io</email>
</developer>
Expand Down Expand Up @@ -106,6 +114,68 @@
<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>biz.aQute.bnd</groupId>
<artifactId>bnd-resolver-maven-plugin</artifactId>
<version>${bnd.version}</version>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>resolve</goal>
</goals>
</execution>
</executions>
<configuration>
<bndruns>
<bndrun>verifyOSGi.bndrun</bndrun>
</bndruns>
<failOnChanges>false</failOnChanges>
<reportOptional>false</reportOptional>
<scopes>
<scope>compile</scope>
<scope>test</scope>
</scopes>
<writeOnChanges>false</writeOnChanges>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -129,12 +199,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
62 changes: 51 additions & 11 deletions r2dbc-spi-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,74 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.2.6.RELEASE</version>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.aries.spifly</groupId>
<artifactId>org.apache.aries.spifly.dynamic.framework.extension</artifactId>
<version>1.3.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.spring-beans</artifactId>
<version>${spring.version}_1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.spring-context</artifactId>
<version>${spring.version}_1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.spring-core</artifactId>
<version>${spring.version}_1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.spring-jdbc</artifactId>
<version>${spring.version}_1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.spring-tx</artifactId>
<version>${spring.version}_1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.osgi</artifactId>
<version>3.17.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-resolver-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
8 changes: 8 additions & 0 deletions r2dbc-spi-test/verifyOSGi.bndrun
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-runfw: org.eclipse.osgi
-resolve.effective: resolve, active

-runsystempackages: \
sun.misc

-runsystemcapabilities: \
osgi.serviceloader;osgi.serviceloader=io.r2dbc.spi.ConnectionFactoryProvider
42 changes: 35 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 @@ -59,24 +69,42 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.aries.spifly</groupId>
<artifactId>org.apache.aries.spifly.dynamic.framework.extension</artifactId>
<version>1.3.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.osgi</artifactId>
<version>3.17.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<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>biz.aQute.bnd</groupId>
<artifactId>bnd-resolver-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>
<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
8 changes: 8 additions & 0 deletions r2dbc-spi/verifyOSGi.bndrun
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-runfw: org.eclipse.osgi
-resolve.effective: resolve, active

-runsystempackages: \
sun.misc

-runsystemcapabilities: \
osgi.serviceloader;osgi.serviceloader=io.r2dbc.spi.ConnectionFactoryProvider