bndlib: A Swiss Army Knife for OSGi providing comprehensive bundle manipulation and analysis capabilities
npx @tessl/cli install tessl/maven-biz-a-qute-bnd--biz-a-qute-bndlib@7.1.0bndlib is a comprehensive Java library that provides essential functionality for OSGi bundle development, analysis, and management. It serves as the foundational component for the entire bnd ecosystem, offering powerful APIs for building OSGi bundles, analyzing dependencies, managing repositories, and performing semantic versioning analysis.
implementation 'biz.aQute.bnd:biz.aQute.bndlib:7.1.0' (Gradle) or <dependency><groupId>biz.aQute.bnd</groupId><artifactId>biz.aQute.bndlib</artifactId><version>7.1.0</version></dependency> (Maven)import aQute.bnd.osgi.Processor;
import aQute.bnd.osgi.Analyzer;
import aQute.bnd.osgi.Builder;
import aQute.bnd.osgi.Jar;
import aQute.bnd.build.Workspace;
import aQute.bnd.build.Project;
import aQute.bnd.version.Version;import aQute.bnd.osgi.Builder;
import aQute.bnd.osgi.Jar;
import aQute.bnd.build.Workspace;
import aQute.bnd.build.Project;
// Build an OSGi bundle
Builder builder = new Builder();
builder.setProperty("Bundle-SymbolicName", "com.example.mybundle");
builder.setProperty("Bundle-Version", "1.0.0");
builder.setProperty("Export-Package", "com.example.api");
builder.addSourcepath(new File("src"));
Jar jar = builder.build();
jar.write(new File("mybundle.jar"));
// Work with workspace and projects
Workspace workspace = Workspace.getWorkspace(new File("."));
Project project = workspace.getProject("my.bundle");
if (project != null) {
Collection<Container> dependencies = project.getDependencies();
// Process dependencies...
}bndlib is organized around several key architectural components:
Processor, Analyzer, and Builder classes that handle bundle creation and analysisWorkspace and Project classes for managing multi-project buildsJar and Resource abstractions for manipulating bundle contentsAnalyzerPlugin and RepositoryPluginEssential OSGi bundle building and analysis functionality. The foundation for all OSGi development workflows.
public class Processor extends Domain implements Reporter, Registry, Constants, Closeable {
// Constructors
public Processor();
public Processor(Properties props);
public Processor(Processor parent);
// Property Management
public Properties getProperties();
public String getProperty(String key);
public String getProperty(String key, String deflt);
public void setProperty(String key, String value);
public void unsetProperty(String key);
public void setProperties(Properties properties);
// Reporter Interface
public SetLocation error(String msg, Object... args);
public SetLocation warning(String msg, Object... args);
public List<String> getErrors();
public List<String> getWarnings();
public boolean isOk();
// Registry Interface
public <T> List<T> getPlugins(Class<T> clazz);
public <T> T getPlugin(Class<T> clazz);
// File Management
public File getBase();
public void setBase(File base);
public File getFile(String file);
// Configuration and Lifecycle
public void begin();
public boolean refresh();
public Parameters parseHeader(String value);
public void close() throws IOException;
}
public class Analyzer extends Processor {
// Constructors
public Analyzer();
public Analyzer(Jar jar) throws Exception;
public Analyzer(Processor parent);
// Core Analysis
public void analyze() throws Exception;
public Manifest calcManifest() throws Exception;
public void reset();
// Jar and Classpath Management
public Jar getJar();
public Jar setJar(File file) throws IOException;
public Jar setJar(Jar jar);
public List<Jar> getClasspath();
public void addClasspath(Jar jar);
public void addClasspath(File cp) throws IOException;
public void setClasspath(Collection<?> classpath) throws IOException;
public void setClasspath(File[] classpath) throws IOException;
// Package Analysis Results
public Packages getContained();
public Packages getExports();
public Packages getImports();
public Packages getReferred();
public Set<PackageRef> getPrivates();
public Map<PackageRef, List<PackageRef>> getUses();
// Bundle Information
public String getBsn();
public String getVersion();
public boolean isNoBundle();
// Type and Package References
public TypeRef getTypeRef(String binaryClassName);
public PackageRef getPackageRef(String binaryName);
public void referTo(TypeRef ref);
}
public class Builder extends Analyzer {
// Constructors
public Builder();
public Builder(Processor parent);
// Build Operations
public Jar build() throws Exception;
public Jar[] builds() throws Exception;
public void init() throws Exception;
// Sub-builder Management
public List<Builder> getSubBuilders() throws Exception;
public Builder getSubBuilder() throws Exception;
// Source Path Management
public Collection<File> getSourcePath();
public void setSourcepath(File[] files);
public void addSourcepath(File cp);
public void addSourcepath(Collection<File> sourcepath);
// Bundle Configuration
public boolean hasSources();
public void setDefaults(String bsn, Version version);
public File getOutputFile(String output);
public boolean save(File output, boolean force) throws Exception;
}Multi-project workspace management for organizing and building OSGi bundles in enterprise environments.
public class Workspace extends Processor {
// Constructors and Factory Methods
public Workspace(File workspaceDir) throws Exception;
public static Workspace getWorkspace(File workspaceDir) throws Exception;
public static Workspace findWorkspace(File base) throws Exception;
public static Workspace createWorkspace(File wsdir) throws Exception;
// Project Management
public Project getProject(String bsn);
public Collection<Project> getAllProjects();
public Collection<Project> getCurrentProjects();
public Collection<Project> getBuildOrder() throws Exception;
public Project createProject(String name) throws Exception;
// Repository Management
public List<RepositoryPlugin> getRepositories();
public RepositoryPlugin getRepository(String repo) throws Exception;
public WorkspaceRepository getWorkspaceRepository();
// Configuration and State
public boolean refresh();
public boolean isValid();
public boolean isOffline();
public WorkspaceLayout getLayout();
// Thread Safety
public <T> T readLocked(Callable<T> callable) throws Exception;
public <T> T writeLocked(Callable<T> callable) throws Exception;
}
public class Project extends Processor {
// Constructors
public Project(Workspace workspace, File buildDir);
// Project State and Identity
public String getName();
public boolean isValid();
public Workspace getWorkspace();
public boolean refresh();
// Builder Management
public ProjectBuilder getBuilder(ProjectBuilder parent) throws Exception;
public Builder getSubBuilder(File bndFile) throws Exception;
// Bundle and Container Management
public List<Container> getBundles(Strategy strategyx, String spec, String source) throws Exception;
public Container getBundle(String bsn, String range, Strategy strategy, Map<String, String> attrs) throws Exception;
public Collection<Container> getDeliverables() throws Exception;
// Path Management
public Collection<Container> getBuildpath() throws Exception;
public Collection<Container> getTestpath() throws Exception;
public Collection<Container> getRunpath() throws Exception;
public Collection<File> getSourcePath() throws Exception;
// Build Operations
public void prepare() throws Exception;
public File[] build() throws Exception;
public File[] build(boolean underTest) throws Exception;
public boolean isStale() throws Exception;
public void clean() throws Exception;
// Dependencies
public Collection<Project> getDependson() throws Exception;
public Set<Project> getBuildDependencies() throws Exception;
public Set<Project> getTestDependencies() throws Exception;
// Release and Testing
public void release() throws Exception;
public void test() throws Exception;
public void run() throws Exception;
}Workspace and Project Management
Low-level JAR file manipulation and resource handling for OSGi bundles.
public class Jar implements Closeable {
public void putResource(String path, Resource resource);
public Resource getResource(String path);
public void write(File file) throws Exception;
public Manifest getManifest() throws Exception;
}
public interface Resource extends Closeable {
public InputStream openInputStream() throws IOException;
public void write(OutputStream out) throws Exception;
public long lastModified();
public void setExtra(String extra);
}OSGi-compliant version handling and semantic versioning for dependency resolution.
public class Version implements Comparable<Version> {
public Version(int major, int minor, int micro, String qualifier);
public int getMajor();
public int getMinor();
public int getMicro();
public String getQualifier();
}
public class VersionRange {
public boolean includes(Version version);
public static VersionRange parseVersionRange(String range);
}Pluggable repository architecture for artifact storage and dependency resolution.
public interface RepositoryPlugin extends Plugin {
public File get(String bsn, Version version, Map<String,String> properties) throws Exception;
public List<String> list(String regex) throws Exception;
public SortedSet<Version> versions(String bsn) throws Exception;
}
public class ResourcesRepository implements Repository {
public void add(Resource resource);
public Collection<Capability> findProviders(Requirement requirement);
}OSGi manifest header parsing and manipulation utilities.
public class Parameters implements Map<String, Attrs> {
public Parameters(String header);
public Attrs get(String key);
public Attrs put(String key, Attrs value);
}
public class Attrs extends LinkedHashMap<String, String> {
public Version getVersion();
public <T> T getTyped(String key);
}Semantic versioning analysis based on API changes between bundle versions.
public class DiffImpl implements Diff {
public Diff diff(Jar newer, Jar older) throws Exception;
public Tree tree(Jar jar) throws Exception;
}
public class Baseline {
public Set<Info> baseline(Jar jar, Jar baseline, Instructions instructions) throws Exception;
}Extensible plugin system for customizing build processes and analysis.
public interface Plugin {
public void setProperties(Map<String,String> map);
public void setReporter(Reporter processor);
}
public interface AnalyzerPlugin extends Plugin {
public boolean analyzeJar(Analyzer analyzer) throws Exception;
}public interface Constants {
String BUNDLE_SYMBOLICNAME = "Bundle-SymbolicName";
String BUNDLE_VERSION = "Bundle-Version";
String EXPORT_PACKAGE = "Export-Package";
String IMPORT_PACKAGE = "Import-Package";
// ... extensive constants for OSGi headers
}
public interface Reporter {
void error(String msg, Object... args);
void warning(String msg, Object... args);
void progress(float progress, String msg, Object... args);
}
public class Container {
public File getFile();
public String getBundleSymbolicName();
public Version getVersion();
public String getError();
}