Class ResourceBuilder

java.lang.Object
aQute.bnd.osgi.resource.ResourceBuilder
Direct Known Subclasses:
SyntheticBuilder

@ProviderType public class ResourceBuilder extends Object
The ResourceBuilder class provides a fluent API for constructing resources.
  • Field Details

  • Constructor Details

    • ResourceBuilder

      public ResourceBuilder()
      Constructs a new `ResourceBuilder`.
    • ResourceBuilder

      public ResourceBuilder(SupportingResource parent)
      Constructs a new `ResourceBuilder`.
    • ResourceBuilder

      @Deprecated public ResourceBuilder(org.osgi.resource.Resource source)
      Deprecated.
      Constructs a new `ResourceBuilder` with the given source resource.
      Parameters:
      source - the source resource to add to this builder
  • Method Details

    • addResource

      public ResourceBuilder addResource(org.osgi.resource.Resource source)
      Adds a resource to this builder. If the resource is a `SupportingResource`, it is added as a composite resource, otherwise its capabilities and requirements are added to this builder.
      Parameters:
      source - the resource to add
      Returns:
      this builder
    • addResource

      public ResourceBuilder addResource(SupportingResource source)
      Adds a composite resource to this builder. The capabilities, requirements, and supporting resources of the composite resource are added to this builder.
      Parameters:
      source - the composite resource to add
      Returns:
      this builder
    • addSupportingResource

      public void addSupportingResource(org.osgi.resource.Resource resource)
      Adds a supporting resource to this builder.
      Parameters:
      resource - the supporting resource to add
    • addCapability

      public ResourceBuilder addCapability(org.osgi.resource.Capability capability)
      Adds a capability to this builder.
      Parameters:
      capability - the capability to add
      Returns:
      this builder
    • addCapability

      public ResourceBuilder addCapability(CapReqBuilder builder)
      Adds a capability to this builder using the given `CapReqBuilder`.
      Parameters:
      builder - the `CapReqBuilder` to use for building the capability
      Returns:
      this builder
    • buildCapability

      protected CapabilityImpl buildCapability(CapReqBuilder builder)
      Builds a capability using the given `CapReqBuilder`.
      Parameters:
      builder - the `CapReqBuilder` to use for building the capability
      Returns:
      the built capability
    • addRequirement

      public ResourceBuilder addRequirement(org.osgi.resource.Requirement requirement)
      Adds a requirement to this builder.
      Parameters:
      requirement - the requirement to add
      Returns:
      this builder
    • addRequirement

      public ResourceBuilder addRequirement(CapReqBuilder builder)
      Adds a requirement to this ResourceBuilder.
      Parameters:
      builder - the CapReqBuilder representing the requirement to add
      Returns:
      this ResourceBuilder instance
      Throws:
      IllegalStateException - if the Resource has already been built
    • buildRequirement

      protected RequirementImpl buildRequirement(CapReqBuilder builder)
      Builds a new RequirementImpl object using the provided CapReqBuilder.
      Parameters:
      builder - the CapReqBuilder to use to build the RequirementImpl
      Returns:
      the newly created RequirementImpl object
    • build

      public SupportingResource build()
      Builds and returns a new SupportingResource object using the data stored in this ResourceBuilder.
      Returns:
      the newly created SupportingResource object
      Throws:
      IllegalStateException - if the Resource has already been built
    • getCapabilities

      public List<org.osgi.resource.Capability> getCapabilities()
      Returns a flattened list of all the Capability objects stored in this ResourceBuilder.
      Returns:
      a List of Capability objects
    • getRequirements

      public List<org.osgi.resource.Requirement> getRequirements()
      Returns a flattened list of all the Requirement objects stored in this ResourceBuilder.
      Returns:
      a List of Requirement objects
    • addManifest

      public boolean addManifest(Domain manifest)
      Parse the manifest and turn them into requirements invalid input: '&' capabilities
      Parameters:
      manifest - The manifest to parse
    • addExportServices

      public void addExportServices(Parameters exportServices)
      Adds CapabilityBuilder objects to this Processor's capabilities list, one for each service listed in the exportServices Parameters object.
      Parameters:
      exportServices - the Parameters object containing the service names and attributes to export
    • addImportServices

      public void addImportServices(Parameters importServices)
      Adds RequirementBuilder objects to this Processor's requirements list, one for each service listed in the importServices Parameters object.
      Parameters:
      importServices - the Parameters object containing the service names and attributes to import
    • getNativeCode

      public RequirementBuilder getNativeCode(String header)
      Calculate the requirement from a native code header
      Parameters:
      header - the Bundle-NativeCode header or null
      Returns:
      a Requirement Builder set to the requirements according tot he core spec
    • addRequireBundles

      public void addRequireBundles(Parameters requireBundle)
      Add the Require-Bundle header
    • addRequireBundle

      public void addRequireBundle(String bsn, VersionRange range)
      Adds a new Require-Bundle requirement to this Processor's requirements list, specifying the bundle symbolic name and version range.
      Parameters:
      bsn - the bundle symbolic name to require
      range - the version range to require for the specified bundle
    • addRequireBundle

      public void addRequireBundle(String bsn, Attrs attrs)
      Adds a new Require-Bundle requirement to this Processor's requirements list, specifying the bundle symbolic name and any additional attributes.
      Parameters:
      bsn - the bundle symbolic name to require
      attrs - the additional attributes for the requirement
    • addFragmentHost

      public void addFragmentHost(String bsn, Attrs attrs)
      Adds a new Fragment-Host requirement to this Processor's requirements list, specifying the host bundle symbolic name and any additional attributes.
      Parameters:
      bsn - the host bundle symbolic name to require
      attrs - the additional attributes for the requirement
    • addRequireCapabilities

      public void addRequireCapabilities(Parameters required)
      Adds one or more Require-Capability requirements to this Processor's requirements list, using the specified Parameters object to define the required capabilities.
      Parameters:
      required - the Parameters object containing the required capabilities and their attributes
    • addRequireCapability

      public void addRequireCapability(String namespace, String name, Attrs attrs)
      Adds a new Require-Capability requirement to this Processor's requirements list, using the specified namespace, name, and attributes.
      Parameters:
      namespace - the namespace of the required capability
      name - the name of the required capability, or null if not applicable
      attrs - the additional attributes for the requirement
    • addRequireCapability

      public void addRequireCapability(String namespace, String name, String versionRange, Attrs attrs)
      Adds a new Require-Capability requirement to this Processor's requirements list, using the specified namespace, name, version range, and attributes.
      Parameters:
      namespace - the namespace of the required capability
      name - the name of the required capability, or null if not applicable
      versionRange - the version range to require for the specified capability, or null if not applicable
      attrs - the additional attributes for the requirement
    • addProvideCapabilities

      public List<org.osgi.resource.Capability> addProvideCapabilities(Parameters capabilities)
      Adds one or more CapabilityBuilder objects to this Processor's capabilities list, using the specified Parameters object to define the provided capabilities.
      Parameters:
      capabilities - the Parameters object containing the provided capabilities and their attributes
      Returns:
      a List of Capability objects that were added to the Processor's capabilities list
    • addProvideCapabilities

      public List<org.osgi.resource.Capability> addProvideCapabilities(String clauses)
    • addProvideCapability

      public org.osgi.resource.Capability addProvideCapability(String namespace, Attrs attrs)
      Adds a new CapabilityBuilder object to this Processor's capabilities list, representing a provided capability with the specified namespace and attributes.
      Parameters:
      namespace - the namespace of the provided capability
      attrs - the attributes for the provided capability
      Returns:
      the Capability object that was added to the Processor's capabilities list
    • addExportPackages

      public void addExportPackages(Parameters exports)
      Adds one or more Export-Package requirements to this Processor's requirements list, using the specified Parameters object to define the exported packages and their attributes.
      Parameters:
      exports - the Parameters object containing the exported packages and their attributes
    • addExportPackages

      public void addExportPackages(Parameters exports, String bundle_symbolic_name, org.osgi.framework.Version bundle_version)
      Adds one or more Export-Package requirements to this Processor's requirements list, using the specified Parameters object to define the exported packages and their attributes, as well as the bundle symbolic name and version for the exporting bundle.
      Parameters:
      exports - the Parameters object containing the exported packages and their attributes
      bundle_symbolic_name - the symbolic name of the exporting bundle
      bundle_version - the version of the exporting bundle
    • addEE

      public void addEE(EE ee)
      Adds the Execution Environment information to this Processor's capabilities list and exported packages list.
      Parameters:
      ee - the EE object containing the Execution Environment information
    • addExportPackage

      public void addExportPackage(String name, Attrs attrs, String bundle_symbolic_name, org.osgi.framework.Version bundle_version)
      Adds a new Export-Package requirement to this Processor's requirements list, representing an exported package with the specified name and attributes, and exporting by the specified bundle.
      Parameters:
      name - the name of the exported package
      attrs - the attributes for the exported package
      bundle_symbolic_name - the symbolic name of the exporting bundle
      bundle_version - the version of the exporting bundle
    • addExportPackage

      public void addExportPackage(String name, Attrs attrs)
      Adds a new Export-Package requirement to this Processor's requirements list, representing an exported package with the specified name and attributes, and exporting by the current bundle.
      Parameters:
      name - the name of the exported package
      attrs - the attributes for the exported package
    • addImportPackages

      public void addImportPackages(Parameters imports)
      Add imported packages
    • addImportPackage

      public org.osgi.resource.Requirement addImportPackage(String name, Attrs attrs)
    • addExecutionEnvironment

      @Deprecated public void addExecutionEnvironment(EE ee)
      Deprecated.
    • addAllExecutionEnvironments

      @Deprecated public void addAllExecutionEnvironments(EE ee)
      Deprecated.
    • copyCapabilities

      public void copyCapabilities(Set<String> ignoreNamespaces, org.osgi.resource.Resource r)
    • addCapabilities

      public void addCapabilities(List<org.osgi.resource.Capability> capabilities)
    • addRequirement

      public void addRequirement(List<org.osgi.resource.Requirement> requirements)
    • addRequirements

      public void addRequirements(List<org.osgi.resource.Requirement> requires)
    • findCapabilities

      public List<org.osgi.resource.Capability> findCapabilities(String ns, String filter)
    • from

      public Map<org.osgi.resource.Capability, org.osgi.resource.Capability> from(org.osgi.resource.Resource bundle)
    • getReporter

      public aQute.service.reporter.Reporter getReporter()
    • addContentCapability

      public void addContentCapability(URI uri, String sha256, long length, String mime)
    • addFile

      public boolean addFile(File file, URI uri) throws Exception
      Throws:
      Exception
    • addFile

      public boolean addFile(File f) throws Exception
      Throws:
      Exception
    • parse

      public static SupportingResource parse(File file, URI uri)
    • addJar

      public boolean addJar(Jar jar)
    • addManifest

      public boolean addManifest(Manifest m)
    • addHashes

      public void addHashes(File file)
    • addHashes

      public void addHashes(Jar jar)
    • safeResourceBuilder

      public ResourceBuilder safeResourceBuilder()
    • addWorkspaceNamespace

      public void addWorkspaceNamespace(String name)
      A repository that implements the WorkspaceRepositoryMarker in the resolver must add a WORKSPACE_NAMESPACE capability to make its clear the resources are from the workspace. Ideally this would not be necessary but we're having two workspace repositories. One for Bndtools where the repository is interactive, the other is for resolving in Gradle, etc.
      Parameters:
      name - the project name
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • memoize

      public static Supplier<org.osgi.resource.Resource> memoize(Jar jar, URI uri, String projectName) throws Exception
      Create a deferred resource builder so that any expensive actions are deferred until the supplier is called to get the resource.
      Parameters:
      jar - a Jar, preferably with checksum calculated, or null
      uri - the uri to use or null (will use file uri as default)
      projectName - if in a workspace, the project name or otherwise null
      Returns:
      a memo for creating the corresponding resource
      Throws:
      Exception