CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-biz-a-qute-bnd--biz-a-qute-bndlib

bndlib: A Swiss Army Knife for OSGi providing comprehensive bundle manipulation and analysis capabilities

Pending
Overview
Eval results
Files

core-osgi-processing.mddocs/

Core OSGi Processing

Core OSGi bundle building and analysis functionality that forms the foundation of all OSGi development workflows in bndlib.

Capabilities

Processor

Base class for all BND processors providing macro processing, reporting, and property handling.

/**
 * Base class for all BND processors providing macro processing, reporting, and property handling
 */
public class Processor extends Domain implements Reporter, Registry, Constants, Closeable {
    // Constructors
    public Processor();
    public Processor(Properties props);
    public Processor(Processor parent);
    public Processor(Properties props, boolean wrap);
    public Processor(Processor parent, Properties props, boolean wrap);
    
    // 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 String getUnexpandedProperty(String key);
    public void setProperties(Properties properties);
    public void addProperties(File file) throws Exception;
    public void mergeProperties(File file, boolean overwrite);
    public Set<String> getPropertyKeys(boolean inherit);
    
    // Reporter Interface Methods
    public SetLocation error(String msg, Object... args);
    public SetLocation warning(String msg, Object... args);
    public void progress(float progress, String format, Object... args);
    public SetLocation exception(Throwable t, String format, Object... args);
    public List<String> getErrors();
    public List<String> getWarnings();
    public boolean isOk();
    public boolean isFailOk();
    public void trace(String msg, Object... parms);
    public boolean isPedantic();
    public Location getLocation(String msg);
    
    // Registry Interface Methods
    public <T> List<T> getPlugins(Class<T> clazz);
    public <T> T getPlugin(Class<T> clazz);
    
    // File and Base Management
    public File getBase();
    public URI getBaseURI();
    public void setBase(File base);
    public File getFile(String file);
    public static File getFile(File base, String file);
    public File getPropertiesFile();
    public void setPropertiesFile(File source);
    public void setProperties(File propertiesFile);
    
    // Configuration and Analysis
    public void begin();
    public boolean refresh();
    public void forceRefresh();
    public boolean exists();
    public void clear();
    public Parameters parseHeader(String value);
    public static Parameters parseHeader(String value, Processor logger);
    
    // Lifecycle Management
    public void close() throws IOException;
    public void addClose(AutoCloseable closeable);
    public void removeClose(AutoCloseable closeable);
    
    // Utility Methods
    public static boolean isTrue(String value);
    public static String join(Collection<?> list);
    public static String join(Collection<?> list, String delimiter);
    public static Collection<String> split(String s);
    public static String merge(String... strings);
    public static String formatArrays(String string, Object... parms);
    public static String cleanupVersion(String version);
}

Usage Examples:

import aQute.bnd.osgi.Processor;

// Basic processor usage
Processor processor = new Processor();
processor.setProperty("Bundle-Version", "1.0.0");
processor.setProperty("Bundle-SymbolicName", "com.example.bundle");

// Check for errors
if (!processor.isOk()) {
    for (String error : processor.getErrors()) {
        System.err.println("Error: " + error);
    }
}

// Clean up
processor.close();

Analyzer

Analyzes JAR files and class files to determine OSGi metadata including imports, exports, and contained packages.

/**
 * Analyzes JAR files and class files to determine OSGi metadata
 */
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(Collection<?> jars) throws IOException;
    public void addClasspath(File cp) throws IOException;
    public void setClasspath(Collection<?> classpath) throws IOException;
    public void setClasspath(File[] classpath) throws IOException;
    public void setClasspath(Jar[] classpath);
    public void setClasspath(String[] classpath);
    
    // Package Analysis Results
    public Packages getContained();
    public Packages getExports();
    public Packages getImports();
    public Packages getReferred();
    public Set<PackageRef> getPrivates();
    public Packages getClasspathExports();
    public Set<PackageRef> getUnreachable();
    public Map<PackageRef, List<PackageRef>> getUses();
    public Map<PackageRef, List<PackageRef>> getAPIUses();
    
    // Class and Type Analysis
    public Map<TypeRef, Clazz> getClassspace();
    public Clazz findClass(TypeRef typeRef) throws Exception;
    public Resource findResource(String path);
    public Stream<Resource> findResources(Predicate<String> matches);
    
    // Bundle Information
    public String getBsn();
    public String getVersion();
    public String getBndVersion();
    public long getBndLastModified();
    public boolean isNoBundle();
    public SortedSet<Clazz.JAVA> getEEs();
    public Clazz.JAVA getLowestEE();
    public Clazz.JAVA getHighestEE();
    
    // Type and Package References
    public TypeRef getTypeRef(String binaryClassName);
    public PackageRef getPackageRef(String binaryName);
    public TypeRef getTypeRefFromFQN(String fqn);
    public TypeRef getTypeRefFromPath(String path);
    public void referTo(TypeRef ref);
    public void referToByBinaryName(String binaryClassName);
    
    // Utility Methods
    public String calculateExportsFromContents(Jar bundle);
    public Collection<Clazz> getClasses(String... args) throws Exception;
    public boolean isImported(PackageRef packageRef);
    public boolean assignable(String annoService, String inferredService);
    public void mergeManifest(Manifest manifest) throws IOException;
    
    // Static Utility Methods
    public static Properties getManifest(File dirOrJar) throws Exception;
    public static String cleanupVersion(String version);
}

Usage Examples:

import aQute.bnd.osgi.Analyzer;
import aQute.bnd.osgi.Jar;
import aQute.bnd.osgi.Packages;

// Analyze an existing JAR file
Analyzer analyzer = new Analyzer();
analyzer.setJar(new Jar(new File("example.jar")));
analyzer.analyze();

// Get discovered packages
Packages imports = analyzer.getImports();
Packages exports = analyzer.getExports();

System.out.println("Import packages: " + imports);
System.out.println("Export packages: " + exports);

// Generate manifest
Manifest manifest = analyzer.calcManifest();
analyzer.close();

Builder

Builds OSGi bundles from source files and bnd instructions, extending Analyzer with bundle creation capabilities.

/**
 * Builds OSGi bundles from source files and bnd instructions
 */
public class Builder extends Analyzer {
    // Constructors
    public Builder();
    public Builder(Processor parent);
    public Builder(Builder 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;
    public Builder getSubBuilder(File file) 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 void removeBundleSpecificHeaders();
    public File getOutputFile(String output);
    public boolean save(File output, boolean force) throws Exception;
    
    // Utility and Analysis Methods
    public void cleanupVersion(Packages packages, String defaultVersion);
    public boolean addAll(Jar to, Jar sub, Instruction filter);
    public boolean addAll(Jar to, Jar sub, Instruction filter, String destination);
    public boolean isInScope(Collection<File> resources) throws Exception;
    public String getClasspathEntrySuffix(File resource) throws Exception;
    public boolean doNotCopy(String v);
    public boolean doNotCopy(File from);
    public Pattern getDoNotCopy();
    
    // Builder Specification
    public Builder from(BuilderSpecification spec) throws IOException;
    
    // Macro Methods  
    public String _maven_version(String args[]);
    public String _permissions(String args[]);
    public String _githead(String[] args) throws IOException;
}

Usage Examples:

import aQute.bnd.osgi.Builder;
import aQute.bnd.osgi.Jar;

// Build a bundle from source
Builder builder = new Builder();
builder.setBase(new File("."));
builder.setProperty("Bundle-SymbolicName", "com.example.mybundle");
builder.setProperty("Bundle-Version", "1.0.0");
builder.setProperty("Export-Package", "com.example.api");
builder.setProperty("Private-Package", "com.example.impl");

// Set source and class paths
builder.addSourcepath(new File("src"));
builder.addClasspath(new File("lib/dependency.jar"));

// Build the bundle
Jar jar = builder.build();
if (builder.isOk()) {
    jar.write(new File("mybundle.jar"));
    System.out.println("Bundle created successfully");
} else {
    System.err.println("Build failed: " + builder.getErrors());
}

builder.close();

OSGi Constants

Essential OSGi and BND constants used throughout the processing pipeline.

/**
 * OSGi and BND constants
 */
public interface Constants {
    // OSGi Manifest Headers
    String BUNDLE_SYMBOLICNAME = "Bundle-SymbolicName";
    String BUNDLE_VERSION = "Bundle-Version";
    String BUNDLE_NAME = "Bundle-Name";
    String BUNDLE_DESCRIPTION = "Bundle-Description";
    String BUNDLE_VENDOR = "Bundle-Vendor";
    String BUNDLE_COPYRIGHT = "Bundle-Copyright";
    String BUNDLE_CATEGORY = "Bundle-Category";
    String BUNDLE_CLASSPATH = "Bundle-ClassPath";
    String BUNDLE_ACTIVATOR = "Bundle-Activator";
    String BUNDLE_REQUIREDEXECUTIONENVIRONMENT = "Bundle-RequiredExecutionEnvironment";
    String BUNDLE_NATIVECODE = "Bundle-NativeCode";
    String EXPORT_PACKAGE = "Export-Package";
    String IMPORT_PACKAGE = "Import-Package";
    String DYNAMICIMPORT_PACKAGE = "DynamicImport-Package";
    String REQUIRE_BUNDLE = "Require-Bundle";
    String FRAGMENT_HOST = "Fragment-Host";
    String BUNDLE_LOCALIZATION = "Bundle-Localization";
    String BUNDLE_MANIFESTVERSION = "Bundle-ManifestVersion";
    
    // BND Instructions
    String PRIVATE_PACKAGE = "Private-Package";
    String EXPORT_CONTENTS = "Export-Contents";
    String INCLUDE_RESOURCE = "Include-Resource";
    String CONDITIONAL_PACKAGE = "Conditional-Package";
    String BND_LASTMODIFIED = "Bnd-LastModified";
    String CREATED_BY = "Created-By";
    String TOOL = "Tool";
    
    // Version Attributes
    String VERSION_ATTRIBUTE = "version";
    String SPECIFICATION_VERSION = "specification-version";
    String BUNDLE_VERSION_ATTRIBUTE = "bundle-version";
    
    // Resolution Directives
    String RESOLUTION_DIRECTIVE = "resolution";
    String RESOLUTION_MANDATORY = "mandatory";
    String RESOLUTION_OPTIONAL = "optional";
    
    // Uses Directive
    String USES_DIRECTIVE = "uses";
}

Package Information

Core classes for managing package information and dependencies.

/**
 * Represents a collection of packages with their attributes
 */
public class Packages implements Map<PackageRef, Attrs> {
    /** Get package reference by name */
    public PackageRef getByFQN(String packageName);
    
    /** Add package with attributes */
    public Attrs put(PackageRef packageRef, Attrs attrs);
    
    /** Check if package exists */
    public boolean containsKey(PackageRef packageRef);
    
    /** Get all package references */
    public Set<PackageRef> keySet();
    
    /** Merge with another Packages collection */
    public void merge(Packages other);
}

/**
 * Reference to a Java package
 */
public class PackageRef implements Comparable<PackageRef> {
    /** Get the fully qualified package name */
    public String getFQN();
    
    /** Get binary name (with slashes) */
    public String getBinary();
    
    /** Check if this is the default package */
    public boolean isDefaultPackage();
    
    /** Create package reference from string */
    public static PackageRef packageRef(String binaryName);
}

Install with Tessl CLI

npx tessl i tessl/maven-biz-a-qute-bnd--biz-a-qute-bndlib

docs

api-comparison-diffing.md

core-osgi-processing.md

header-processing.md

index.md

jar-resource-management.md

plugin-architecture.md

repository-system.md

version-management.md

workspace-project-management.md

tile.json