Class OsgiHeaderUtil

java.lang.Object
com.atlassian.plugin.osgi.util.OsgiHeaderUtil

public class OsgiHeaderUtil extends Object
Utilities to help create OSGi headers
  • Constructor Details

    • OsgiHeaderUtil

      public OsgiHeaderUtil()
  • Method Details

    • findReferredPackageNames

      public static Set<String> findReferredPackageNames(Collection<Class<?>> classes) throws IOException
      Finds all referred packages for the specified set of classes/interfaces by scanning their bytecode. Packages starting with "java." are ignored.
      Parameters:
      classes - The set of classes/interfaces to scan
      Returns:
      The set of referred packages
      Throws:
      IOException - If there are any problems scanning bytecode
      Since:
      5.0.0
    • findReferredPackageVersions

      public static Map<String,String> findReferredPackageVersions(List<HostComponentRegistration> registrations, Map<String,String> packageVersions) throws IOException
      Finds all referred packages for host component registrations by scanning their declared interfaces' bytecode.
      Parameters:
      registrations - A list of host component registrations
      Returns:
      The referred package map ( package-> version ).
      Throws:
      IOException - If there are any problems scanning bytecode
      Since:
      2.7.0
    • parseHeader

      public static Map<String,Map<String,String>> parseHeader(String header)
      Parses an OSGi header line into a map structure
      Parameters:
      header - The header line
      Returns:
      A map with the key the entry value and the value a map of attributes
      Since:
      2.2.0
    • buildHeader

      public static String buildHeader(Map<String,Map<String,String>> values)
      Builds the header string from a map
      Parameters:
      values - The header values
      Returns:
      A string, suitable for inclusion into an OSGI header string
      Since:
      2.6
    • buildHeader

      public static String buildHeader(String key, Map<String,String> attrs)
      Builds the header string from a map
      Parameters:
      key - The header value
      attrs - The map of attributes
      Returns:
      A string, suitable for inclusion into an OSGI header string
      Since:
      2.2.0
    • getPluginKey

      public static String getPluginKey(org.osgi.framework.Bundle bundle)
      Gets the plugin key from the bundle WARNING: shamelessly copied at PluginBundleUtils, which can't use this class due to creating a cyclic build dependency. Ensure these two implementations are in sync. This method shouldn't be used directly. Instead consider consuming the PluginRetrievalService.
      Parameters:
      bundle - The plugin bundle
      Returns:
      The plugin key, cannot be null
      Since:
      2.2.0
    • getPluginKey

      public static String getPluginKey(File file)
      Obtain the plugin key for a bundle in the given File.
      Parameters:
      file - the file containing the bundle.
      Returns:
      the pluginKey, or null if the bundle is malformed.
    • getPluginKey

      public static String getPluginKey(Manifest mf)
      Gets the plugin key from the jar manifest
      Parameters:
      mf - The plugin jar manifest
      Returns:
      The plugin key, cannot be null
      Since:
      2.2.0
    • generatePackageVersionString

      public static String generatePackageVersionString(Map<String,String> packages)
      Generate package version string such as "com.abc;version=1.2,com.atlassian". The output can be used for import or export.
      Parameters:
      packages - map of packagename -> version.
    • getValidatedAttribute

      public static String getValidatedAttribute(Manifest manifest, String key)
      Extract the attribute from manifest and validate it's not null and not empty
      Returns:
      value for the matching attribute key or will raise an Exception in case constraints are not met
      Throws:
      NullPointerException - if attribute value is null
      IllegalArgumentException - if attribute is empty
    • getNonEmptyAttribute

      public static String getNonEmptyAttribute(Manifest manifest, String key)
      Extract the attribute from manifest and validate if it's not empty
      Returns:
      value for the matching attribute key
      Throws:
      IllegalArgumentException - if attribute value is empty
    • getAttributeWithoutValidation

      public static String getAttributeWithoutValidation(Manifest manifest, String key)
      Extract the attribute from manifest(no-validations)
      Returns:
      value for the matching attribute key
    • extractOsgiPluginInformation

      @Internal public static PluginInformation extractOsgiPluginInformation(Manifest manifest, boolean requireVersion)
      Extract a PluginInformation from the Manifest of a jar containing an OSGi bundle.
      Parameters:
      manifest - the manifest to parse.
      Returns:
      the parsed PluginInformation.
    • getManifest

      public static Manifest getManifest(PluginArtifact pluginArtifact)
      Extract the manifest of a PluginArtifact.
      Parameters:
      pluginArtifact - the plugin artifact who manifest is required.
      Returns:
      the manifest from pluginArtifact, or null if the manifest is missing, cannot be read, or is corrupted.
    • moveStarPackageToEnd

      public static Map<String,Map<String,String>> moveStarPackageToEnd(Map<String,Map<String,String>> packages, String pluginKey)
      Reorder any Import-Package or Export-Package or Private-Package value passed, so that packages containing a star-value i.e. '*' to the end, preserving their current order.

      Note that any reordered packages will be logged at debug level.

      Parameters:
      packages - map of package declarations, keyed by package name
      pluginKey - only used for debug logging
      Returns:
      copy of packages with star packages at the end
    • stripDuplicatePackages

      public static Map<String,Map<String,String>> stripDuplicatePackages(Map<String,Map<String,String>> packages, String pluginKey, String action)
      Remove any duplicate Import-Package or Export-Package or Private-Package value passed. Duplicates are packages that end with a ~. Order is preserved.

      Note that any removed packages will be logged at warning level.

      Parameters:
      packages - map of package declarations, keyed by package name
      pluginKey - only used for debug logging
      action - only used for debug logging - "import", "export" etc.
      Returns:
      de-duplicated copy of packages