Apache Sling Provider Type Checker Bnd Plugin

Clone this repo:
  1. b1b1f4b Update readme.md by Konrad Windszus · 8 months ago master
  2. 426190e Update readme.md by Konrad Windszus · 8 months ago
  3. 83648b9 Add remarks to README by Konrad Windszus · 12 months ago
  4. 490b515 SLING-12181 Evaluate provider type from annotations by Konrad Windszus · 1 year ago
  5. ca551e0 Update readme.md by Konrad Windszus · 12 months ago

Apache Sling

Build Status Test Status Coverage Sonarcloud Status JavaDoc Maven Central License

Apache Sling Provider Type Checker Bnd Plugin

This module contains a Bnd plugin enforcing that no class of the current bundle extends or implements a provider type. Note that using a provider type (i.e. calling its methods without implementing or extending it) is still allowed (even for consumers).

That ensures that the import-package version ranges are not narrow but broad and the risk that the bundle is incompatible with newer versions of its dependent bundles is less likely.

Usage

For usage with Maven the Bnd plugin has to be added to the plugin dependencies of bnd-maven-plugin (or maven-bundle-plugin) like this:

<plugin>
    <groupId>biz.aQute.bnd</groupId>
    <artifactId>bnd-maven-plugin</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.providertype.bnd-plugin</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>
</plugin>

In addition the bnd.bnd file needs to register the Bnd plugin with the plugin instruction

-plugin.providertype:org.apache.sling.providertype.bndplugin.ProviderTypeScanner

Configuration

To explicitly ignore certain provider types (i.e. don't fail when these are extended/implemented) one can use the attribute ignored with one or multiple comma-separated fully qualified provider type names. For example

-plugin.providertype:org.apache.sling.providertype.bndplugin.ProviderTypeScanner;ignored=org.apache.jackrabbit.api.security.user.User

In case the provider types are not provided in a classpath resource named META-INF/api-info.json the plugin can optionally evaluate the classpath for the relevant annotations directly. Since this is time consuming it needs to be explicitly enabled via attribute evaluateAnnotations with value true.

-plugin.providertype:org.apache.sling.providertype.bndplugin.ProviderTypeScanner;evaluateAnnotations=true

Multiple attributes must be separated with ; according to OSGi Common Header Syntax.

Prerequisites

  • Bnd 6.0 or newer (integrated in bnd-maven-plugin version 6.0.0+ or maven-bundle-plugin version 5.1.5+)
  • Java 11 or newer

Provider Type Information

The information whether a type (i.e. a class or interface) is designed to be extended/implemented only by providers or also by consumers is determined originally from the the annotations @org.osgi.annotation.versioning.ProviderType or @org.osgi.annotation.versioning.ConsumerType. In order to speed up the check the annotation is evaluated and extracted into a dedicated JSON file named META-INF/api-info.json when generating the apis jar and being looked up from this resource in the Bnd classpath within this plugin. Only as fallback and on demand this plugin evaluates the annotations from the classpath directly.

Remarks

All provider type annotations are not inherited, i.e. only the direct super class and directly implemented interfaces are ever evaluated (OSGi issue #634). Bnd does not correctly calculate the proper import-package version policy for provider type classes being extended (Bnd issue #5925).