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
- Export Package - Validates that exported packages follow naming conventions
- Bundle Symbolic Name - Ensures bundle symbolic names follow naming conventions
- DS Component Provided Services - Validates provided service FQCNs in DS components
- HTTP/Servlet Whiteboard - Validates that HTTP servlets/filters registered via HTTP/servlet whiteboard are listening to specific paths only
- Sling Servlet/Filter - Validates Sling servlet paths, resource types, and resource super types as well as Sling filter patterns/resource types
- Sling Authentication Handler - Validates a Sling Authentication Handler is registered to a specific path only
Validates that all exported packages match a specified regular expression pattern.
Ensures Bundle-SymbolicName headers conform to naming conventions, with support for parameter handling (e.g., singleton:=true
).
Validates that Declarative Services components only provide services whose fully qualified class names match specified patterns.
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
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
For DS components implementing javax.servlet.Servlet
or jakarta.servlet.Servlet
, validates:
sling.servlet.paths
- Servlet path patternssling.servlet.resourceTypes
- Resource type patternssling.servlet.resourceSuperType
- Resource super type patterns
For DS components implementing javax.servlet.Filter
or jakarta.servlet.Filter
, validates:
sling.filter.pattern
- Servlet filter patternssling.filter.resourceTypes
- Resource type patterns
For DS components implementing org.apache.sling.auth.core.spi.AuthenticationHandler
validates property path
.
The configuration differs slightly depending on which Maven plugin is being used. In general Bnd's -plugin instruction is being used.
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.
In general you add this artifact as plugin dependency to the Maven plugin. Then you can configure with the options outlined above.
<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>
- 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+ ormaven-bundle-plugin
5.1.4+)
This project is licensed under the Eclipse Public License 2.0 - see the LICENSE for details.
- AEM Content Package Namespace Validators - Content package validation
- Bnd Tools - OSGi development tools
- Apache Sling - Web framework for the JVM