Skip to content

Commit

Permalink
apply service loader mediator (via bnd annotations), osgi.cdi (via os…
Browse files Browse the repository at this point in the history
…gi bundle annotations) & osgi contracts in a passive way

Signed-off-by: Raymond Augé <raymond.auge@liferay.com>
  • Loading branch information
rotty3000 committed Mar 30, 2020
1 parent e6e7cc3 commit 1c96fd9
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 13 deletions.
26 changes: 22 additions & 4 deletions api/bnd.bnd
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
-exportcontents: \
org.eclipse.microprofile.*

Import-Package: \
javax.enterprise.util;version="[1.1,3)", \
*

Bundle-SymbolicName: org.eclipse.microprofile.config

# For reproducible builds
-noextraheaders: true
-snapshot: SNAPSHOT

# Apply OSGi Portable Java Contracts [1] with "active" effectiveness so that
# they are not strict runtime requirements. This removes the need to import
# packages with versions.
-contract: *;effective:=active

# Two contracts are used in this API; JavaCDI, JavaInject. Simulate them since
# the compile dependencies used do not provide them.
-define-contract: \
osgi.contract;\
osgi.contract=JavaCDI;\
version:List<Version>='2.0,1.1';\
uses:='\
javax.decorator,\
javax.enterprise.context,\
javax.enterprise.context.spi,\
javax.enterprise.event,\
javax.enterprise.inject,\
javax.enterprise.inject.spi,\
javax.enterprise.util'

# [1] https://www.osgi.org/portable-java-contract-definitions/
15 changes: 9 additions & 6 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,28 @@
<version>2.0-SNAPSHOT</version>
</parent>

<properties>
<bnd.version>5.0.0</bnd.version>
</properties>
<groupId>org.eclipse.microprofile.config</groupId>
<artifactId>microprofile-config-api</artifactId>
<name>MicroProfile Config API</name>
<description>MicroProfile Config :: API</description>
<url>https://microprofile.io/project/eclipse/microprofile-config</url>
<dependencies>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bnd.annotation</artifactId>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation.versioning</artifactId>
<version>1.1.0</version>
<scope>provided</scope>
<artifactId>org.osgi.service.cdi</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.annotation</artifactId>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.osgi.annotation.bundle.Requirement.Resolution.OPTIONAL;
import static org.osgi.service.cdi.CDIConstants.CDI_EXTENSION_PROPERTY;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.enterprise.util.Nonbinding;
import javax.inject.Qualifier;

import org.osgi.annotation.bundle.Requirement;

/**
* <p>
* Binds the injection point with a configured value.
Expand Down Expand Up @@ -100,6 +104,15 @@
@Qualifier
@Retention(RUNTIME)
@Target({METHOD, FIELD, PARAMETER, TYPE})
/*
* Two @Requirement annotations are defined so that the result is a _weak requirement_.
* One requirement is resolution:=optional which means that at runtime, if satisfied,
* it will be wired, otherwise it is simply ignored. Another requirement is
* effective:=active which means it is not visible at runtime, but applicable during
* assembly where an effectviness of _active_ is specified.
*/
@Requirement(namespace = CDI_EXTENSION_PROPERTY, name = "org.eclipse.microprofile.config", effective = "active")
@Requirement(namespace = CDI_EXTENSION_PROPERTY, name = "org.eclipse.microprofile.config", resolution = OPTIONAL)
public @interface ConfigProperty {
String UNCONFIGURED_VALUE="org.eclipse.microprofile.config.configproperty.unconfigureddvalue";
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
*
* @author <a href="mailto:struberg@apache.org">Mark Struberg</a>
* @author <a href="mailto:emijiang@uk.ibm.com">Emily Jiang</a>
*
*
*/
@org.osgi.annotation.versioning.Version("1.0")
@org.osgi.annotation.versioning.Version("1.0.1")
package org.eclipse.microprofile.config.inject;

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

import org.eclipse.microprofile.config.Config;

import aQute.bnd.annotation.spi.ServiceConsumer;

/**
* The service provider for implementations of the MicroProfile Configuration specification.
* <p>
Expand All @@ -36,6 +38,16 @@
* @author <a href="mailto:rmannibucau@apache.org">Romain Manni-Bucau</a>
* @author <a href="mailto:emijiang@uk.ibm.com">Emily Jiang</a>
*/

/*
* The @ServiceConsumer annotation adds support for Service Loader Mediator in
* order to support wiring of Service Loader providers to consumers in OSGi.
* However, the requirements generated are specified as effective:=active to
* prevent this from being a strict requirement. As such the API is usable in
* runtimes without a Service Loader Mediator implementation while allowing for
* such to be enabled when using the resolver during assembly.
*/
@ServiceConsumer(value = ConfigProviderResolver.class, effective = "active")
public abstract class ConfigProviderResolver {
/**
* Construct a new instance.
Expand Down
20 changes: 19 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

<links>https://osgi.org/javadoc/osgi.annotation/7.0.0/</links>

<bnd.version>5.0.1</bnd.version>
<checkstyle.version>2.17</checkstyle.version>
<checkstyle.methodNameFormat>^_?[a-z][a-zA-Z0-9]*$</checkstyle.methodNameFormat>
</properties>
Expand Down Expand Up @@ -102,9 +103,14 @@
<module>tck</module>
<module>spec</module>
</modules>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bnd.annotation</artifactId>
<version>${bnd.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
Expand All @@ -123,6 +129,18 @@
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.cdi</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.annotation</artifactId>
<version>7.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down

0 comments on commit 1c96fd9

Please sign in to comment.