com.atlassian.plugin.osgi.util
Class OsgiHeaderUtil

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

public class OsgiHeaderUtil
extends java.lang.Object

Utilities to help create OSGi headers


Constructor Summary
OsgiHeaderUtil()
           
 
Method Summary
static java.lang.String buildHeader(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> values)
          Builds the header string from a map
static java.lang.String buildHeader(java.lang.String key, java.util.Map<java.lang.String,java.lang.String> attrs)
          Builds the header string from a map
static java.util.Set<java.lang.String> findReferredPackageNames(java.util.List<HostComponentRegistration> registrations)
          Finds all referred packages for host component registrations by scanning their declared interfaces' bytecode.
static java.lang.String findReferredPackages(java.util.List<HostComponentRegistration> registrations)
          Deprecated. Since 2.7.0, use findReferredPackageNames(java.util.List) instead.
static java.lang.String findReferredPackages(java.util.List<HostComponentRegistration> registrations, java.util.Map<java.lang.String,java.lang.String> packageVersions)
          Deprecated. Since 2.7.0, use findReferredPackageVersions(java.util.List, java.util.Map) instead.
static java.util.Map<java.lang.String,java.lang.String> findReferredPackageVersions(java.util.List<HostComponentRegistration> registrations, java.util.Map<java.lang.String,java.lang.String> packageVersions)
          Finds all referred packages for host component registrations by scanning their declared interfaces' bytecode.
static java.lang.String generatePackageVersionString(java.util.Map<java.lang.String,java.lang.String> packages)
          Generate package version string such as "com.abc;version=1.2,com.atlassian".
static java.lang.String getAttributeWithoutValidation(java.util.jar.Manifest manifest, java.lang.String key)
          Extract the attribute from manifest(no-validations)
static java.lang.String getNonEmptyAttribute(java.util.jar.Manifest manifest, java.lang.String key)
          Extract the attribute from manifest and validate if it's not empty
static java.lang.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.
static java.lang.String getPluginKey(java.util.jar.Manifest mf)
          Gets the plugin key from the jar manifest
static java.lang.String getValidatedAttribute(java.util.jar.Manifest manifest, java.lang.String key)
          Extract the attribute from manifest and validate it's not null and not empty
static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> parseHeader(java.lang.String header)
          Parses an OSGi header line into a map structure
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OsgiHeaderUtil

public OsgiHeaderUtil()
Method Detail

findReferredPackageNames

public static java.util.Set<java.lang.String> findReferredPackageNames(java.util.List<HostComponentRegistration> registrations)
                                                                throws java.io.IOException
Finds all referred packages for host component registrations by scanning their declared interfaces' bytecode. Packages starting with "java." are ignored.

Parameters:
registrations - A list of host component registrations
Returns:
The set of referred packages..
Throws:
java.io.IOException - If there are any problems scanning bytecode
Since:
2.7.0

findReferredPackageVersions

public static java.util.Map<java.lang.String,java.lang.String> findReferredPackageVersions(java.util.List<HostComponentRegistration> registrations,
                                                                                           java.util.Map<java.lang.String,java.lang.String> packageVersions)
                                                                                    throws java.io.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:
java.io.IOException - If there are any problems scanning bytecode
Since:
2.7.0

findReferredPackages

@Deprecated
public static java.lang.String findReferredPackages(java.util.List<HostComponentRegistration> registrations)
                                             throws java.io.IOException
Deprecated. Since 2.7.0, use findReferredPackageNames(java.util.List) instead.

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 packages in a format compatible with an OSGi header
Throws:
java.io.IOException - If there are any problems scanning bytecode
Since:
2.4.0

findReferredPackages

@Deprecated
public static java.lang.String findReferredPackages(java.util.List<HostComponentRegistration> registrations,
                                                               java.util.Map<java.lang.String,java.lang.String> packageVersions)
                                             throws java.io.IOException
Deprecated. Since 2.7.0, use findReferredPackageVersions(java.util.List, java.util.Map) instead.

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 packages in a format compatible with an OSGi header
Throws:
java.io.IOException - If there are any problems scanning bytecode

parseHeader

public static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> parseHeader(java.lang.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 java.lang.String buildHeader(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.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 java.lang.String buildHeader(java.lang.String key,
                                           java.util.Map<java.lang.String,java.lang.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 java.lang.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 java.lang.String getPluginKey(java.util.jar.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 java.lang.String generatePackageVersionString(java.util.Map<java.lang.String,java.lang.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 java.lang.String getValidatedAttribute(java.util.jar.Manifest manifest,
                                                     java.lang.String key)
Extract the attribute from manifest and validate it's not null and not empty

Parameters:
manifest -
key -
Returns:
value for the matching attribute key or will raise an Exception in case constraints are not met
Throws:
java.lang.NullPointerException - if attribute value is null
java.lang.IllegalArgumentException - if attribute is empty

getNonEmptyAttribute

public static java.lang.String getNonEmptyAttribute(java.util.jar.Manifest manifest,
                                                    java.lang.String key)
Extract the attribute from manifest and validate if it's not empty

Parameters:
manifest -
key -
Returns:
value for the matching attribute key
Throws:
java.lang.IllegalArgumentException - if attribute value is empty

getAttributeWithoutValidation

public static java.lang.String getAttributeWithoutValidation(java.util.jar.Manifest manifest,
                                                             java.lang.String key)
Extract the attribute from manifest(no-validations)

Parameters:
manifest -
key -
Returns:
value for the matching attribute key


Copyright © 2012 Atlassian. All Rights Reserved.