Class JPMSModule

java.lang.Object
aQute.bnd.osgi.JPMSModule

public class JPMSModule extends Object
Multi Release jars are another error magnet extension to Java. Instead of having the flat class space of Java and Javac, it allows developers to put multiple versions of a class in versioned directory.

  • Field Details

  • Constructor Details

    • JPMSModule

      public JPMSModule(Jar jar)
      Cosntructor
      Parameters:
      jar - the base for this module
  • Method Details

    • getJar

      public Jar getJar()
      Get the underlying JAR
    • getVersionedPath

      public static String getVersionedPath(int release, String path)
      Get the path to a resource in a version directory
      Parameters:
      release - the release version of the VM
      path - the path in the version directory
      Returns:
      a path
    • getVersions

      public SortedSet<Integer> getVersions()
      Return the available releases in this modules. This does not include the base, we do not know what version that is

      Returns:
      a map with the release number -> a JAR.
    • getReleaseOnly

      public Jar getReleaseOnly(int release)
      Return a Jar that contains only the resources for a specific release version.
      Parameters:
      release - the release number
      Returns:
      the Jar will only the release classes invalid input: '&' resources
    • putResource

      public boolean putResource(int release, String path, Resource resource)
      Put a resource in a Jar in the META-INF/versions/ subtree for Multi Release Jars.
      Parameters:
      release - the release number (> 8)
      path - the relative path of the resource
      resource - the resource
      Returns:
      true if this modified the set of resources
    • getResource

      public Resource getResource(int release, String path)
      Get a resource from a Jar that is in the versioned area.
      Parameters:
      release - the release number we're looking for
      path - the path
      Returns:
      the resource or null if not existent
    • findResource

      public Optional<Resource> findResource(String path, int release)
      Find a resource from a Jar. Start in the normal space than look in the increasing versioned areas.
      Parameters:
      path - the path
      release - the release to start. If invalid input: '<' 0, start from default and go up in releases. If invalid input: '<'9, use default. Otherwise start there and go down, ending in default
      Returns:
      the resource or null if not existent
    • isMultiRelease

      public boolean isMultiRelease()
      Checks if this JAR has version directories. This does not look at the manifest header.
      Returns:
      if this is a multi release JAR (has versions)
    • getModuleName

      public Optional<String> getModuleName() throws Exception
      Returns the name of the module, either from the module descriptor or automatically generated from the JAR file manifest.
      Returns:
      An optional string containing the module name, or an empty optional if the module name cannot be determined.
      Throws:
      Exception - If an error occurs while parsing the module descriptor or manifest.
    • getModuleVersion

      public Optional<String> getModuleVersion() throws Exception
      Returns the version of the module, if present in the module descriptor.
      Returns:
      An optional string containing the module version, or an empty optional if the module version cannot be determined.
      Throws:
      Exception - If an error occurs while parsing the module descriptor.
    • getManifest

      public Manifest getManifest(int release)
      Return a manifest for OSGi.

      The Framework must first look in the versioned directory for the major version of the current Java platform and then prior versioned directories in descending order. The first supplemental manifest file found must be used and the Framework must replace the values of the following manifest headers in the manifest with the values of these headers, if present, in the supplemental manifest file.

          Import-Package
          Require-Capability
      
      Any other headers in the supplemental manifest file must be ignored.
      Parameters:
      release - the version of the VM
      Returns:
      a Manifest
    • copy

      public static Manifest copy(Manifest result, Manifest r, String... headers)
      Copies specified headers from one manifest to another.
      Parameters:
      result - The manifest to copy the headers to. If null, a new manifest will be created.
      r - The manifest to copy the headers from. If null, no headers will be copied.
      headers - The headers to copy.
      Returns:
      The manifest with the copied headers.
    • getRelease

      public Jar getRelease(int release)
      Gets a new JAR file that includes all the files from this JAR file and all previous versions up to and including the specified release.
      Parameters:
      release - The release number to include in the new JAR file.
      Returns:
      A new JAR file containing all the files from this JAR file and all previous versions up to and including the specified release.
    • getNextRelease

      public int getNextRelease(int release)
      Gets the release number of the next version after the specified release.
      Parameters:
      release - The release number.
      Returns:
      The release number of the next version after the specified release, or Integer.MAX_VALUE if there are no more versions.
    • cleanupName

      public static String cleanupName(String bsn)
      Cleanup a bsn so that it matches a JPMS module name
      Parameters:
      bsn - a symbolic name or null
      Returns:
      a name that matches the JPMS specification for a module name or null if the input was null