SLING-12181 Evaluate provider type from annotations

Only in case META-INF/api-info.json is not available in the class path
(no apis-jar) and if enabled via attribute
6 files changed
tree: cd6d568a6ccc7352baa241130cbaae107e70b8fe
  1. src/
  2. .asf.yaml
  3. .gitignore
  4. CODE_OF_CONDUCT.md
  5. CONTRIBUTING.md
  6. Jenkinsfile
  7. LICENSE
  8. pom.xml
  9. readme.md
readme.md

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>
    <extensions>true</extensions>
    <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 there within this plugin. Only as fallback and on demand this plugin evaluates the annotations from the classpath directly.