Skip to content

Commit 6085f9d

Browse files
committed
OSGi import/export headers
- <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 r2dbc#242 Signed-off-by: Raymond Augé <[email protected]>
1 parent f55bb5d commit 6085f9d

File tree

5 files changed

+87
-23
lines changed

5 files changed

+87
-23
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ dependency-reduced-pom.xml
99
buildNumber.properties
1010
.mvn/timing.properties
1111

12+
# Eclipse
13+
.project
14+
.classpath
15+
.settings
16+
1217
# IntelliJ
1318
out/
1419
build/

pom.xml

+45-6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
<jsr305.version>3.0.2</jsr305.version>
4242
<junit.version>5.7.0</junit.version>
4343
<assertj.version>3.17.2</assertj.version>
44+
<bnd.version>6.0.0</bnd.version>
45+
<osgi.annotation.version>8.0.0</osgi.annotation.version>
46+
<project.build.outputTimestamp>1</project.build.outputTimestamp>
4447
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4548
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
4649
<reactive-streams.version>1.0.3</reactive-streams.version>
@@ -62,18 +65,22 @@
6265

6366
<developers>
6467
<developer>
68+
<id>nebhale</id>
6569
<name>Ben Hale</name>
6670
<email>[email protected]</email>
6771
</developer>
6872
<developer>
73+
<id>mp911de</id>
6974
<name>Mark Paluch</name>
7075
<email>[email protected]</email>
7176
</developer>
7277
<developer>
78+
<id>mirromutth</id>
7379
<name>Mirro Mutth</name>
7480
<email>[email protected]</email>
7581
</developer>
7682
<developer>
83+
<id>gregturn</id>
7784
<name>Greg Turnquist</name>
7885
<email>[email protected]</email>
7986
</developer>
@@ -106,6 +113,43 @@
106113
<build>
107114
<pluginManagement>
108115
<plugins>
116+
<plugin>
117+
<groupId>biz.aQute.bnd</groupId>
118+
<artifactId>bnd-maven-plugin</artifactId>
119+
<version>${bnd.version}</version>
120+
<executions>
121+
<execution>
122+
<goals>
123+
<goal>bnd-process</goal>
124+
</goals>
125+
</execution>
126+
</executions>
127+
<configuration>
128+
<bnd><![CDATA[
129+
# Vars are ignored from the output
130+
spec.version = ${version;===;${project.version}}
131+
132+
Automatic-Module-Name: ${replacestring;${project.artifactId};-;.}
133+
134+
# Don't import findbugs annotation packages since they are never runtime dependency
135+
Import-Package:\
136+
!javax.annotation.*,\
137+
*
138+
139+
# Automatically export all packages in the resulting jar at spec version
140+
-exportcontents: *;version=${spec.version}
141+
142+
# Add default specification headers
143+
-namesection: io/r2dbc/spi*/;\
144+
Specification-Title="${project.name}";\
145+
Specification-Version="${spec.version}"
146+
147+
# Ensure repeatable builds if desired
148+
-noextraheaders: true
149+
-snapshot: SNAPSHOT
150+
]]></bnd>
151+
</configuration>
152+
</plugin>
109153
<plugin>
110154
<groupId>org.apache.maven.plugins</groupId>
111155
<artifactId>maven-compiler-plugin</artifactId>
@@ -129,12 +173,7 @@
129173
<version>3.2.0</version>
130174
<configuration>
131175
<archive>
132-
<manifest>
133-
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
134-
</manifest>
135-
<manifestEntries>
136-
<R2DBC-Specification-Version>${project.version}</R2DBC-Specification-Version>
137-
</manifestEntries>
176+
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
138177
</archive>
139178
</configuration>
140179
</plugin>

r2dbc-spi-test/pom.xml

+4-10
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,17 @@
7777

7878
<build>
7979
<plugins>
80+
<plugin>
81+
<groupId>biz.aQute.bnd</groupId>
82+
<artifactId>bnd-maven-plugin</artifactId>
83+
</plugin>
8084
<plugin>
8185
<groupId>org.apache.maven.plugins</groupId>
8286
<artifactId>maven-compiler-plugin</artifactId>
8387
</plugin>
8488
<plugin>
8589
<groupId>org.apache.maven.plugins</groupId>
8690
<artifactId>maven-jar-plugin</artifactId>
87-
<configuration>
88-
<archive>
89-
<manifest>
90-
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
91-
</manifest>
92-
<manifestEntries>
93-
<Automatic-Module-Name>r2dbc.spi.test</Automatic-Module-Name>
94-
</manifestEntries>
95-
</archive>
96-
</configuration>
9791
</plugin>
9892
<plugin>
9993
<groupId>org.apache.maven.plugins</groupId>

r2dbc-spi/pom.xml

+19-7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@
3939
<artifactId>reactive-streams</artifactId>
4040
<version>${reactive-streams.version}</version>
4141
</dependency>
42+
<dependency>
43+
<groupId>biz.aQute.bnd</groupId>
44+
<artifactId>biz.aQute.bnd.annotation</artifactId>
45+
<version>${bnd.version}</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.osgi</groupId>
49+
<artifactId>osgi.annotation</artifactId>
50+
<version>${osgi.annotation.version}</version>
51+
</dependency>
4252
<dependency>
4353
<groupId>com.google.code.findbugs</groupId>
4454
<artifactId>jsr305</artifactId>
@@ -63,20 +73,22 @@
6373

6474
<build>
6575
<plugins>
76+
<plugin>
77+
<groupId>biz.aQute.bnd</groupId>
78+
<artifactId>bnd-maven-plugin</artifactId>
79+
<configuration>
80+
<bnd><![CDATA[
81+
R2DBC-Specification-Version: ${project.version}
82+
]]></bnd>
83+
</configuration>
84+
</plugin>
6685
<plugin>
6786
<groupId>org.apache.maven.plugins</groupId>
6887
<artifactId>maven-compiler-plugin</artifactId>
6988
</plugin>
7089
<plugin>
7190
<groupId>org.apache.maven.plugins</groupId>
7291
<artifactId>maven-jar-plugin</artifactId>
73-
<configuration>
74-
<archive>
75-
<manifestEntries>
76-
<Automatic-Module-Name>r2dbc.spi</Automatic-Module-Name>
77-
</manifestEntries>
78-
</archive>
79-
</configuration>
8092
</plugin>
8193
<plugin>
8294
<groupId>org.apache.maven.plugins</groupId>

r2dbc-spi/src/main/java/io/r2dbc/spi/ConnectionFactoryProvider.java

+14
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@
1616

1717
package io.r2dbc.spi;
1818

19+
import static aQute.bnd.annotation.Cardinality.MULTIPLE;
20+
import static aQute.bnd.annotation.Resolution.OPTIONAL;
21+
1922
import java.util.ServiceLoader;
2023

24+
import aQute.bnd.annotation.spi.ServiceConsumer;
25+
2126
/**
2227
* A Java Service interface for implementations to examine a collection of {@link ConnectionFactoryOptions} and optionally return an implementation of {@link ConnectionFactory}.
2328
* <p>{@link ConnectionFactoryProvider} implementations are typically discovered by {@link ConnectionFactories} from the class path using {@link ServiceLoader}.
@@ -27,6 +32,15 @@
2732
* @see ConnectionFactories
2833
* @see ServiceLoader
2934
*/
35+
36+
@ServiceConsumer(
37+
// This instance enables resolving a provider at _assembly_ without incurring a strict runtime
38+
// dependency on Service Loader Mediator (SML) impl
39+
cardinality = MULTIPLE, effective = "active", value = ConnectionFactoryProvider.class)
40+
@ServiceConsumer(
41+
// This instance enables SML to instrument ServiceLoader calls _if SML is present_
42+
// (without preventing the bundles from resolving if it is not)
43+
cardinality = MULTIPLE, resolution = OPTIONAL, value = ConnectionFactoryProvider.class)
3044
public interface ConnectionFactoryProvider {
3145

3246
/**

0 commit comments

Comments
 (0)