Knopflerfish OSGi 5.2.0

org.knopflerfish.ant.taskdefs.bundle
Class BundleManifestTask

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by org.knopflerfish.ant.taskdefs.bundle.BundleManifestTask
All Implemented Interfaces:
java.lang.Cloneable

public class BundleManifestTask
extends org.apache.tools.ant.Task

Extension of the standard Manifest task.

This task builds a manifest file from three different sources:

  1. A template manifest file.
  2. Project properties with given prefix.
  3. Nested attribute and section data.
It may also be used to create properties (with a given prefix) for each main section attribute in the template manifest file.

Parameters

Attribute Description Required
file the manifest-file to create. Yes if "attributePropertyPrefix" is empty, otherwise No.
encoding The encoding used to read the existing manifest when updating. No, defaults to UTF-8 encoding.
mode One of "update", "replace", "template" and "templateOnly" default is "replace".

The "mode" determines which sources to use when creating the resulting manifest:

replace
Use properties and nested data.
update
Use template, properties and nested data.
template
Use template and nested data.
templateOnly
Use template.
No.
templateFile the template manifest file to load. No.
attributePropertyPrefix If set and a template file is given but no file to write to export all attributes from the main section of the template file as properties.

If set and mode is one of "update", "replace" then create main section attributes for all project properties that starts with the prefix.

If set and "file" is given then export all attributes written to the main section as properties.

The name of property that maps to a main section attribute is the value of "attributePropertyPrefix" followed by the attribute name. The value is the attribute value.

No.
kind The kind of bundle that the manifest is for.

If given this string will be appended to the following manifest attributes of the main section:

  • Bundle-Name
  • Bundle-SymbolicName
  • Bundle-UUID
  • Bundle-Description
  • Bundle-Category (only for kind="api").
All main section manifest attribute starting with "kind-" will be replaced with a main section attribute without the prefix. E.g., if kind="api" and there is an attribute named "api-Export-Package" then it will be renamed to "Export-Package", overriding any previous definition of "Export-Package".
No.
allKinds A comma separated list specifying all kinds.

If given all main section attributes starting with any of the kinds in allKinds will be removed after the specified kind has been used to override attributes. E.g., if kind="all" and allKinds="api,all" and there is an attribute named "api-Export-Package" then that attribute will be removed from the resulting manifest.

No.
mainAttributesToSkip Comma separated list with names of main section attributes to weed out when writing the manifest file. No.
replaceEEmin Replace the filter part of any osgi.ee requirement for the OSGi/Minimum EE with the given value. E.g., replaceEEmin="(&(osgi.ee=JavaSE)(version>=1.7))" will replace any filter matching 'OSGi/Minimum' in the osgi.ee name space with the given filter expression. No.
verbose If set to "true" then log the name of the bundle activator together with the imported and exported packages No.

Nested elements

attribute

One attribute for the manifest file. Those attributes that are not nested into a section will be added to the "Main" section.

Attribute Description Required
name the name of the attribute. Yes
value the value of the attribute. Yes

section

A manifest section - you can nest attribute elements into sections.

Attribute Description Required
name the name of the section. No, if omitted it will be assumed to be the main section.

Examples

Build bundle manifest for the impl jar

  <bundlemanifest mode="template"
                  kind="impl"
                  mainAttributesToSkip="Export-Package"
                  attributePropertyPrefix="bmfa."
                  templateFile="bundle.manifest"
                  verbose="true"
                  file="${outdir}/impl.mf">
     <attribute name="Build-Date"       value="${bundle.date}"/>
     <attribute name="Built-From"       value="${proj.dir}"/>
   </bundlemanifest>
 

Create properties for main section attributes in the template manifest file

   <bundlemanifest mode="template"
                   attributePropertyPrefix = "bmfa."
                   templateFile="bundle.manifest">
   </bundlemanifest>
 


Nested Class Summary
static class BundleManifestTask.Mode
          Helper class for bundle manifest's mode attribute.
 
Field Summary
protected static java.lang.String BUNDLE_EMPTY_STRING
          Special value used to indicate that a Manifest.Attribute with this value shall be weeded out.
 
Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
 
Constructor Summary
BundleManifestTask()
          Default constructor.
 
Method Summary
 void addConfiguredAttribute(org.apache.tools.ant.taskdefs.Manifest.Attribute attribute)
          Add an attribute to the main section of the manifest.
 void addConfiguredSection(org.apache.tools.ant.taskdefs.Manifest.Section section)
          Add a section to the manifest.
 void execute()
          Create or update the Manifest when used as a task.
protected static boolean isPropertyValueEmpty(java.lang.String pval)
          Check if a property value is empty or not.
 void setAllKinds(java.lang.String s)
          Comma separated list of known bundle kinds.
 void setAttributePropertyPrefix(java.lang.String s)
          Set the prefix of project properties to add main section attributes for.
 void setEncoding(java.lang.String encoding)
          The encoding to use for reading in the manifest template file.
 void setFile(java.io.File f)
          The name of the manifest file to create.
 void setKind(java.lang.String s)
          Bundle kind, will be appended to some of the bundle specific attributes in the main section.
 void setMainAttributesToSkip(java.lang.String s)
          Comma separated list of attributes to skip from the main section.
 void setMode(BundleManifestTask.Mode m)
          Which sources to use when creating the resulting manifest.
 void setReplaceEEmin(java.lang.String s)
          Sets the replacement filter expression for required capabilities in the osgi.ee name-space that requires the OSGi/Minimum EE.
 void setTemplateFile(java.io.File f)
          The name of the template manifest file.
 void setVerbose(boolean b)
          Set the verbosity of this task.
 
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUNDLE_EMPTY_STRING

protected static final java.lang.String BUNDLE_EMPTY_STRING
Special value used to indicate that a Manifest.Attribute with this value shall be weeded out. I.e., not added to the manifest. This value is used as the default value for properties that maps to bundle manifest attributes via the attributePropertyPrefix.

See Also:
Constant Field Values
Constructor Detail

BundleManifestTask

public BundleManifestTask()
Default constructor.

Method Detail

setEncoding

public void setEncoding(java.lang.String encoding)
The encoding to use for reading in the manifest template file. Default encoding is UTF-8.

Parameters:
encoding - the manifest template file encoding.

setTemplateFile

public void setTemplateFile(java.io.File f)
The name of the template manifest file.

Parameters:
f - the template manifest file to load.

setFile

public void setFile(java.io.File f)
The name of the manifest file to create.

Parameters:
f - the manifest file to write.

setMode

public void setMode(BundleManifestTask.Mode m)
Which sources to use when creating the resulting manifest.
replace
Use properties and nested data.
update
Use template, properties and nested data.
template
Use template and nested data.
templateOnly
Use template.

Parameters:
m - the mode value one of - update, replace, template and templateOnly.

setMainAttributesToSkip

public void setMainAttributesToSkip(java.lang.String s)
Comma separated list of attributes to skip from the main section.

Parameters:
s - main section attributes to skip from out put.

setKind

public void setKind(java.lang.String s)
Bundle kind, will be appended to some of the bundle specific attributes in the main section.

Parameters:
s - the kind of bundle that we are writing a manifest file for.

setAllKinds

public void setAllKinds(java.lang.String s)
Comma separated list of known bundle kinds. Any main section attribute starting with one of the known kind values will be removed from the resulting manifest after processing of kind specific overrides.

Parameters:
s - Comma separated list of bundle kinds.

setReplaceEEmin

public void setReplaceEEmin(java.lang.String s)
Sets the replacement filter expression for required capabilities in the osgi.ee name-space that requires the OSGi/Minimum EE.

Parameters:
s -

setVerbose

public void setVerbose(boolean b)
Set the verbosity of this task. If set to true the bundle activator, export package and import package list in the written manifest will be printed on the console.

Parameters:
b - verbose or not.

setAttributePropertyPrefix

public void setAttributePropertyPrefix(java.lang.String s)
Set the prefix of project properties to add main section attributes for. For each property in the project with a name that starts with this prefix a manifest attribute in the main section will be created. The attribute name will be the property name without the prefix and the attribute value will be the property value.

Parameters:
s - the property names prefix to check for.

addConfiguredSection

public void addConfiguredSection(org.apache.tools.ant.taskdefs.Manifest.Section section)
                          throws org.apache.tools.ant.taskdefs.ManifestException
Add a section to the manifest.

Parameters:
section - the manifest section to be added.
Throws:
org.apache.tools.ant.taskdefs.ManifestException - if the section is not valid.

isPropertyValueEmpty

protected static boolean isPropertyValueEmpty(java.lang.String pval)
Check if a property value is empty or not. The value is empty if it is null, the empty string or the special value BundleManifestTask.BUNDLE_EMPTY_STRING.

Parameters:
pval - The property value to check.
Returns:
true if the value is empty.

addConfiguredAttribute

public void addConfiguredAttribute(org.apache.tools.ant.taskdefs.Manifest.Attribute attribute)
                            throws org.apache.tools.ant.taskdefs.ManifestException
Add an attribute to the main section of the manifest. Attributes with the value BUNDLE_EMPTY_STRING are not added.

Parameters:
attribute - the attribute to be added.
Throws:
org.apache.tools.ant.taskdefs.ManifestException - if the attribute is not valid.

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Create or update the Manifest when used as a task.

Overrides:
execute in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException - if the manifest cannot be written.

Knopflerfish OSGi 5.2.0