The Inoyu OSGi Utilities Maven Plugin is a collection of utilities designed to help developers work with OSGi bundles in Maven projects. This plugin provides several goals to analyze, validate, and manage OSGi-related aspects of your project.
- Package Analysis: Locate packages within project dependencies and analyze package usage in OSGi bundles
- Manifest Management: View and validate OSGi bundle manifests with enhanced formatting
- Blueprint to DS Conversion: Automatically convert OSGi Blueprint XML files to Declarative Services annotations
- Blueprint Validation: Validate Blueprint XML files for syntax and semantic correctness
- Theme Support: Dark and light theme support for better readability
- Maven 3.8.5 or later
- Java 8 or later
This plugin can be used directly from the command line. Some goals require a Maven project context, while others can be used both within a project and independently.
This goal must be run within a Maven project context:
mvn dev.inoyu:osgi-utils-maven-plugin:1.3:locate-package -Dpackage=com.example.package1This goal scans your project's dependencies and reports where the specified package is found.
Sample Output:
📦 Package found in Project classes
Dependency trail:
├─ dev.inoyu:osgi-tools:1.1
com/example/package1/Class1.class
com/example/package1/Class2.class
This goal must also be run within a Maven project context:
mvn dev.inoyu:osgi-utils-maven-plugin:1.3:find-package-usages -Dpackage=com.example.packageThis goal examines your project and its dependencies to find where the specified packages are used.
Sample Output:
Searching for usages of package: com.example.package
📦 Usage found in Dependency: org.example:example-artifact:1.0: com/example/usage/Class1 uses com.example.package.Class2
Dependency trail:
├─ org.example:example-artifact:1.0
This goal can be used both within a Maven project context and independently:
-
Within a Maven project:
mvn dev.inoyu:osgi-utils-maven-plugin:1.3:view-manifest
This will display the manifest of the project's main artifact.
-
For arbitrary JAR files (can be used anywhere):
mvn dev.inoyu:osgi-utils-maven-plugin:1.3:view-manifest -Djars=path/to/your/jar1.jar,path/to/your/jar2.jar
This goal displays the contents of the OSGi bundle manifest, including all headers and their values with enhanced formatting.
Sample Output:
Analyzing manifest of: path/to/your/jar1.jar
================================================================================
Bundle-Name: Example Bundle
Bundle-SymbolicName: com.example.bundle
Bundle-Version: 1.0.0
Export-Package: com.example.package;version="1.0.0"
Import-Package: org.osgi.framework;version="[1.3,2)"
================================================================================
This goal validates Blueprint XML files for syntax and semantic correctness:
mvn dev.inoyu:osgi-utils-maven-plugin:1.3:validate-blueprintConfiguration Options:
| Parameter | Default | Description |
|---|---|---|
blueprint.sourceDir |
${project.build.sourceDirectory} |
Source directory containing Java classes |
blueprint.resourcesDir |
${project.build.resources[0].directory} |
Resources directory containing Blueprint XML files |
blueprint.failOnError |
true |
Whether to fail the build on validation errors |
Sample Output:
🔍 Validating Blueprint XML files...
âś… Blueprint validation completed successfully
📊 Validation Summary:
- Files processed: 3
- Errors: 0
- Warnings: 2
The convert-blueprint-to-ds goal automatically converts OSGi Blueprint XML files to Declarative Services annotations in Java code.
- Converts Blueprint XML to DS annotations
- Handles all OSGi Blueprint features:
- Services and references
- Property placeholders and configurations
- Reference lists and dynamic references
- Karaf shell commands
- Service properties and metadata
- Init/destroy methods
- Bundle context injection
- Recursive processing of multi-module projects
- Selective module inclusion/exclusion
- Add the plugin to your project's
pom.xml:
<build>
<plugins>
<plugin>
<groupId>dev.inoyu</groupId>
<artifactId>osgi-utils-maven-plugin</artifactId>
<version>1.3</version>
</plugin>
</plugins>
</build>- Add required dependencies for DS annotations:
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<version>1.5.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.metatype.annotations</artifactId>
<version>1.4.1</version>
<scope>provided</scope>
</dependency>
</dependencies>- Run the conversion:
mvn osgi-utils:convert-blueprint-to-ds| Parameter | Default | Description |
|---|---|---|
keepBlueprintFiles |
false |
Whether to keep the original Blueprint XML files after conversion |
recursive |
false |
Whether to process sub-modules recursively |
includeModules |
null |
Array of module name patterns to include (regex) |
excludeModules |
null |
Array of module name patterns to exclude (regex) |
Process only specific modules:
mvn osgi-utils:convert-blueprint-to-ds -DincludeModules="core.*,api.*"Exclude test modules:
mvn osgi-utils:convert-blueprint-to-ds -DexcludeModules=".*test.*,.*demo.*"Keep original files and process recursively:
mvn osgi-utils:convert-blueprint-to-ds -DkeepBlueprintFiles=true -Drecursive=trueTo convert Apache Unomi from Blueprint to DS:
- Clone the Apache Unomi repository:
git clone https://github.com/apache/unomi.git
cd unomi- Add the plugin to the parent
pom.xml:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>dev.inoyu</groupId>
<artifactId>osgi-utils-maven-plugin</artifactId>
<version>1.3</version>
</plugin>
</plugins>
</pluginManagement>
</build>- Add the plugin to each module that uses Blueprint:
<build>
<plugins>
<plugin>
<groupId>dev.inoyu</groupId>
<artifactId>osgi-utils-maven-plugin</artifactId>
</plugin>
</plugins>
</build>- Run the conversion on all modules:
mvn osgi-utils:convert-blueprint-to-ds -Drecursive=trueThe plugin performs the following conversions:
-
Services
<service interface="com.example.Service"> <service-properties> <entry key="property" value="value"/> </service-properties> </service>
becomes:
@Component( service = Service.class, property = {"property=value"} )
-
References
<reference interface="com.example.Service" availability="optional" policy="dynamic"> <reference-listener bind-method="bind" unbind-method="unbind"/> </reference>
becomes:
@Reference( service = Service.class, cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC, bind = "bind", unbind = "unbind" )
-
Property Placeholders
<cm:property-placeholder persistent-id="com.example"> <cm:default-properties> <cm:property name="prop" value="value"/> </cm:default-properties> </cm:property-placeholder>
becomes:
@Component @Designate(ocd = Config.class) public class MyService { // ... } @ObjectClassDefinition public @interface Config { @AttributeDefinition String prop() default "value"; }
-
Karaf Commands
<shell:command-bundle> <shell:command name="example:cmd"> <shell:action class="com.example.Command"/> </shell:command> </shell:command-bundle>
becomes:
@Service @Command(scope = "example", name = "cmd") public class Command implements Action { // ... }
The plugin supports both dark and light themes for better readability. You can set the theme using the theme system property:
# Use dark theme (default)
mvn osgi-utils:view-manifest -Dtheme=dark
# Use light theme
mvn osgi-utils:view-manifest -Dtheme=lightThe plugin supports the following parameters:
package: The package name to search for or analyze (forlocate-packageandfind-package-usagesgoals).jars: A comma-separated list of paths to JAR files to analyze (optional forview-manifestgoal when used outside a project context).theme: Theme to use for output formatting (darkorlight, default:dark).
-
Locate a package in a Maven project:
mvn dev.inoyu:osgi-utils-maven-plugin:1.3:locate-package -Dpackage=org.osgi.framework
-
Analyze package usage in a Maven project:
mvn dev.inoyu:osgi-utils-maven-plugin:1.3:find-package-usages -Dpackage=com.example.api
-
View manifest of the current Maven project:
mvn dev.inoyu:osgi-utils-maven-plugin:1.3:view-manifest
-
View manifests of multiple JARs (can be used anywhere):
mvn dev.inoyu:osgi-utils-maven-plugin:1.3:view-manifest -Djars=/path/to/bundle1.jar,/path/to/bundle2.jar
-
Validate Blueprint XML files:
mvn dev.inoyu:osgi-utils-maven-plugin:1.3:validate-blueprint
-
Convert Blueprint to DS with custom configuration:
mvn dev.inoyu:osgi-utils-maven-plugin:1.3:convert-blueprint-to-ds -Drecursive=true -DkeepBlueprintFiles=true
- Use
locate-packageto understand where packages are coming from - Use
find-package-usagesto identify dependencies on specific packages - Use
view-manifestto inspect bundle metadata and dependencies
-
Before Conversion
- Backup your codebase
- Run all tests to establish baseline
- Document current Blueprint configurations
- Validate Blueprint files using the validation goal
-
During Conversion
- Convert one module at a time
- Verify each module after conversion
- Run tests after each module conversion
- Use
keepBlueprintFiles=trueinitially for safety
-
After Conversion
- Verify all services are properly registered
- Check service properties and metadata
- Validate configuration handling
- Run full test suite
- Remove Blueprint dependencies
- Run validation as part of your CI/CD pipeline
- Use
failOnError=falseduring development for warnings only - Address validation warnings to improve code quality
-
Package Not Found
- Verify the package name is correct
- Check if the package is in a different artifact
- Use
locate-packageto find where the package is located
-
Manifest Issues
- Use
view-manifestto inspect the actual manifest content - Check for malformed headers or missing information
- Use
-
Missing Service Registration
- Verify
@Componentannotation includesserviceattribute - Check service interface is correctly specified
- Verify
-
Configuration Issues
- Ensure
@Designateannotation points to correct Config class - Verify property names match in Config interface
- Ensure
-
Reference Binding
- Check cardinality matches Blueprint configuration
- Verify bind/unbind methods are correctly specified
-
Karaf Commands
- Ensure command scope and name match original Blueprint
- Verify all command properties are preserved
-
XML Syntax Errors
- Check for malformed XML
- Verify namespace declarations
- Ensure proper element nesting
-
Bean Property Errors
- Verify Java classes exist and are accessible
- Check property names match Java class fields
- Ensure proper type compatibility
-
Reference Errors
- Verify referenced services exist
- Check interface compatibility
- Ensure proper cardinality settings
For more complex issues, please file a bug report with:
- Original Blueprint XML (if applicable)
- Generated DS annotations (if applicable)
- Error messages or unexpected behavior
- Steps to reproduce
- Maven and Java versions
Contributions to the Inoyu OSGi Utilities Maven Plugin are welcome! Please submit pull requests or open issues on our GitHub repository.
This project is licensed under the Apache License 2.0.