Package com.atlassian.plugin.osgi.util
Class OsgiHeaderUtil
java.lang.Object
com.atlassian.plugin.osgi.util.OsgiHeaderUtil
Utilities to help create OSGi headers
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbuildHeader(String key, Map<String, String> attrs) Builds the header string from a mapstatic StringBuilds the header string from a mapstatic PluginInformationextractOsgiPluginInformation(Manifest manifest, boolean requireVersion) Extract a PluginInformation from the Manifest of a jar containing an OSGi bundle.findReferredPackageNames(Collection<Class<?>> classes) Finds all referred packages for the specified set of classes/interfaces by scanning their bytecode.findReferredPackageVersions(List<HostComponentRegistration> registrations, Map<String, String> packageVersions) Finds all referred packages for host component registrations by scanning their declared interfaces' bytecode.static StringgeneratePackageVersionString(Map<String, String> packages) Generate package version string such as "com.abc;version=1.2,com.atlassian".static StringgetAttributeWithoutValidation(Manifest manifest, String key) Extract the attribute from manifest(no-validations)static ManifestgetManifest(PluginArtifact pluginArtifact) Extract the manifest of a PluginArtifact.static StringgetNonEmptyAttribute(Manifest manifest, String key) Extract the attribute from manifest and validate if it's not emptystatic StringgetPluginKey(File file) Obtain the plugin key for a bundle in the given File.static StringgetPluginKey(Manifest mf) Gets the plugin key from the jar manifeststatic StringgetPluginKey(org.osgi.framework.Bundle bundle) Gets the plugin key from the bundle WARNING: shamelessly copied atPluginBundleUtils, which can't use this class due to creating a cyclic build dependency.static StringgetValidatedAttribute(Manifest manifest, String key) Extract the attribute from manifest and validate it's not null and not emptyReorder any Import-Package or Export-Package or Private-Package value passed, so that packages containing a star-value i.e.parseHeader(String header) Parses an OSGi header line into a map structureRemove any duplicate Import-Package or Export-Package or Private-Package value passed.
-
Constructor Details
-
OsgiHeaderUtil
public OsgiHeaderUtil()
-
-
Method Details
-
findReferredPackageNames
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 IOExceptionFinds 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
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
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
Builds the header string from a map- Parameters:
key- The header valueattrs- The map of attributes- Returns:
- A string, suitable for inclusion into an OSGI header string
- Since:
- 2.2.0
-
getPluginKey
Gets the plugin key from the bundle WARNING: shamelessly copied atPluginBundleUtils, 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 thePluginRetrievalService.- Parameters:
bundle- The plugin bundle- Returns:
- The plugin key, cannot be null
- Since:
- 2.2.0
-
getPluginKey
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
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
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
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 nullIllegalArgumentException- if attribute is empty
-
getNonEmptyAttribute
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
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
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, moveStarPackageToEndString>> (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 namepluginKey- only used for debug logging- Returns:
- copy of packages with star packages at the end
-
stripDuplicatePackages
public static Map<String,Map<String, stripDuplicatePackagesString>> (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 namepluginKey- only used for debug loggingaction- only used for debug logging - "import", "export" etc.- Returns:
- de-duplicated copy of packages
-