Class BndAnalyzer

All Implemented Interfaces:
Generator, Renamable, ResourceProvider

public class BndAnalyzer extends AbstractBndGenerator

A Generator that computes OSGi metadata in response to requests for ManifestAttributes.

This implementation uses the bndlib library from the bnd project to analyze bundle contents and compute manifest attributes.

When invoked, the analyzer first obtains resources of type ClassTree supplied to the project (typically by a JavaCompiler). These class trees are treated as the content of the bundle.

It then obtains resources of type LibraryJarFile from the project's dependencies with intents Consume, Reveal and Expose (the same intents as used by the JavaCompiler when assembling the compilation classpath). These library resources are registered as bundle dependencies.

The collected class tree and library resources are analyzed by bndlib to produce the manifest attributes requested.

Contrary to most ResourceProviders, the BndAnalyzer needs project specific informations (supplied as instructions). This can be handled in multiple ways. One approach is to add the BndAnalyzer with the instructions in the project’s constructor rather than in RootProject.prepareProject(Project). Alternatively, put project-specific instructions in a bnd.bnd file in the project's directory, then register the analyzer in RootProject.prepareProject(Project) and add the instructions via instructions(Path), where Path refers to the bnd.bnd file.