Skip to content

Netcentric/bundle-namespace-validators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bundle Namespace Validators Bnd Plugin

Build Status License Maven Central SonarCloud Quality Gate Status SonarCloud Coverage

Overview

A Bnd plugin that validates OSGi bundle metadata compliance with configurable namespacing rules. This plugin helps ensure consistent naming conventions and organizational standards across OSGi bundles in enterprise projects. It validates the following aspects of an OSGi bundle

Features

Export Package

Validates that all exported packages match a specified regular expression pattern.

Bundle Symbolic Name

Ensures Bundle-SymbolicName headers conform to naming conventions, with support for parameter handling (e.g., singleton:=true).

DS Component Provided Services

Validates that Declarative Services components only provide services whose fully qualified class names match specified patterns.

Implicitly Allowed Services

In addition to explicitly configured patterns, the following services are always allowed by default because they are known to support multi-tenancy or are unlikely to cause namespace clashes:

  • javax.servlet.Servlet
  • jakarta.servlet.Servlet
  • javax.servlet.Filter
  • jakarta.servlet.Filter
  • org.apache.sling.api.adapter.AdapterFactory
  • org.apache.sling.rewriter.TransformerFactory
  • com.adobe.granite.workflow.exec.WorkflowProcess
  • com.day.cq.workflow.exec.WorkflowProcess
  • org.apache.sling.auth.core.spi.AuthenticationHandler

HTTP/Servlet Whiteboard

For DS components implementing javax.servlet.Servlet or jakarta.servlet.Servlet, validates

  • osgi.http.whiteboard.servlet.pattern - Servlet pattern

For DS components implementing javax.servlet.Filter or jakarta.servlet.Filter, validates

  • osgi.http.whiteboard.filter.pattern - Servlet filter pattern

Sling Servlet/Filter

For DS components implementing javax.servlet.Servlet or jakarta.servlet.Servlet, validates:

  • sling.servlet.paths - Servlet path patterns
  • sling.servlet.resourceTypes - Resource type patterns
  • sling.servlet.resourceSuperType - Resource super type patterns

For DS components implementing javax.servlet.Filter or jakarta.servlet.Filter, validates:

  • sling.filter.pattern - Servlet filter patterns
  • sling.filter.resourceTypes - Resource type patterns

Sling Authentication Handler

For DS components implementing org.apache.sling.auth.core.spi.AuthenticationHandler validates property path.

Configuration

The configuration differs slightly depending on which Maven plugin is being used. In general Bnd's -plugin instruction is being used.

Configuration Parameters

Parameter Type Description
allowedExportPackagePatterns Pattern[] Regular expression(s) for validating exported package names
allowedBundleSymbolicNamePatterns Pattern[] Regular expression(s) for validating Bundle-SymbolicName header
allowedServiceClassPatterns Pattern[] Regular expression(s) for validating provided service FQCNs of DS components
allowedHttpWhiteboardServletPatterns Pattern[] Regular expression(s) for validating HTTP Whiteboard servlet patterns (osgi.http.whiteboard.servlet.pattern)
allowedHttpWhiteboardFilterPatterns Pattern[] Regular expression(s) for validating HTTP Whiteboard filter patterns (osgi.http.whiteboard.filter.pattern)
allowedSlingServletPathsPatterns Pattern[] Regular expression(s) for validating Sling servlet paths (sling.servlet.paths)
allowedSlingServletResourceTypesPatterns Pattern[] Regular expression(s) for validating Sling servlet resource types (sling.servlet.resourceTypes)
allowedSlingServletResourceSuperTypePatterns Pattern[] Regular expression(s) for validating Sling servlet resource super types (sling.servlet.resourceSuperType)
allowedSlingFilterPatterns Pattern[] Regular expression(s) for validating Sling filter patterns (sling.filter.pattern)
allowedSlingFilterResourceTypesPatterns Pattern[] Regular expression(s) for validating Sling filter resource types (sling.filter.resourceTypes)
allowedSlingAuthenticationHandlerPathPatterns Pattern[] Regular expression(s) for validating Sling Authentication Handler's path property (path)

Each parameter may take multiple regular expression patterns separated by comma. That makes the comma itself unusable within the regular expression pattern itself, however this shouldn't be necessary there. All parameters are optional. If not set the according property/name/header is not validated.

Usage

In general you add this artifact as plugin dependency to the Maven plugin. Then you can configure with the options outlined above.

Example with bnd-maven-plugin Configuration Example (in POM)

<plugin>
    <groupId>biz.aQute.bnd</groupId>
    <artifactId>bnd-maven-plugin</artifactId>
    <version>7.1.0</version>
    <extensions>true</extensions>
    <configuration>
        <bnd><![CDATA[
            Bundle-Name: My OSGi Bundle
            Bundle-SymbolicName: com.mycompany.bundles.mybundle
            
            Export-Package: \
                com.mycompany.api.*,\
                com.mycompany.services.*
            
            -plugin.namespace: biz.netcentric.osgi.bnd.NamespaceValidatorsPlugin; \
                allowedExportPackagePattern="com\\.mycompany\\..*"; \
                allowedBundleSymbolicNamePatterns="com\\.mycompany\\.bundles\\..*"; \
                allowedServiceClassPatterns="com\\.mycompany\\..*"; \
                allowedSlingServletPathsPattern="/apps/myproject/.*"; \
                allowedSlingServletResourceTypesPatterns="/apps/myproject/.*"; \
                allowedSlingServletResourceSuperTypePattern="/apps/myproject/.*";
        ]]></bnd>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>biz.netcentric.osgi.bnd</groupId>
            <artifactId>bundle-namespace-validators</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>
</plugin>

Requirements

  • Java 8 or higher (builds with Java 21, targets Java 8)
  • Maven 3.9.0 or higher
  • Bnd 6.0.0 or higher (i.e. bnd-maven-plugin 6.0.0+ or maven-bundle-plugin 5.1.4+)

License

This project is licensed under the Eclipse Public License 2.0 - see the LICENSE for details.

Related Projects

About

Bnd plugin validating that the OSGi metadata complies with certain namespacing rules

Resources

Stars

Watchers

Forks

Packages

No packages published