4.2 Apache ANT Usage

The ANT task allows you to run Bundlor from inside any ANT based build system

4.2.1 ANT Setup

The following procedure shows how to set up Bundlor inside of an existing ANT build file

  1. Define a bundlor namespace

    <project name="bundlor-sample-ant"
        xmlns:bundlor="antlib:org.eclipse.virgo.bundlor.ant">
  2. Import the bundlor task into your build

    <target name="bundlor.init">
      <ivy:cachepath resolveId="bundlor.classpath" pathid="bundlor.classpath" organisation="org.eclipse.virgo.bundlor"
                     module="org.eclipse.virgo.bundlor.ant" revision="1.1.2.RELEASE" conf="ant" inline="true"
                     type="jar" log="download-only"/>
      <taskdef resource="org/eclipse/virgo/bundlor/ant/antlib.xml" uri="antlib:org.eclipse.virgo.bundlor.ant"
               classpathref="bundlor.classpath"/>
    </target>

    This example uses a very simplistic method for building the bundlor task classpath. It is possible to use a dependency manager such as Ivy to better manage the classpath of Bundlor.

  3. Use the bundlor task, as shown in the following example. See Section 4.2.2, “ANT Task Reference” for details about the parameters of the task.

    <bundlor:bundlor
        inputPath="${basedir}/target/classes"
        outputPath="${basedir}/target/classes"
        bundleVersion="1.0.2.BUILD-${timestamp}"
        manifestTemplatePath="${basedir}/template.mf" >
      <property name="name" value="${ant.project.name}" />
    </bundlor:bundlor>

4.2.2 ANT Task Reference

4.2.2.1 Task Attributes

The following table lists all the attributes that you can specify for the bundlor ANT task.

Table 4.2. Attributes

AttributeDescriptionRequired
bundleSymbolicNameThe OSGi Bundle-SymbolicName for the resulting manifestNo
bundleVersionThe OSGi Bundle-Version for the resulting manifestNo
enabledWhether Bundlor should create a manifestNo - defaults to true
failOnWarnings Whether Bundlor should cause a build failure when there are warnings about the resulting manifest No - defaults to false
inputPath The path to the input to create a manifest for. This can either be a directory or a JAR file. Yes
manifestTemplatePath The path to the manifest template. See Chapter 5, Manifest Templates for details. No
OSGiProfilePath The path to the OSGi profile. See Chapter 6, OSGi Profiles and Bundlor for details. No
outputPath

The path to write the manifest to. This can either be a directory, a JAR file, or not specified.

If a directory is specified, the manifest will be written to ${directory}/META-INF/MANIFEST.MF.

If a JAR file is specified, the manifest will be written as the manifest for that JAR file.

If nothing is specified, the manifest will be written to System.out.

No - defaults to System.out
propertiesPath The path to a properties file used for substitution. See Section 5.3, “Specifying property placeholders” for details. No

4.2.2.2 Inline Manifest Template

Manifest templates can be optionally specified inline instead of as an external file using the <manifestTemplate/> element.

<bundlor:bundlor>
  <manifestTemplate>
Bundle-ManifestVersion: 2
Bundle-Name: Bundlor Core
Bundle-SymbolicName: org.eclipse.virgo.bundlor
Bundle-Version: 0
  </manifestTemplate>
</bundlor:bundlor>

See Chapter 5, Manifest Templates for details.

4.2.2.3 Inline OSGi Profile

OSGi profiles can be optionally specified inline instead of as an external file using the <OSGiProfile/> element.

<bundlor:bundlor>
  <OSGiProfile>
org.OSGi.framework.system.packages = \
 org.eclipse.virgo.osgi.extensions.equinox.hooks,\
 javax.accessibility,\
 javax.activation,\
 javax.activation;version="1.1.1",\
 javax.activity,\
 javax.annotation,\
...

org.OSGi.framework.bootdelegation = \
 org.eclipse.virgo.kernel.authentication,\
 com.sun.*,\
 javax.xml.*,\
...
  </OSGiProfile>
</bundlor:bundlor>

See Chapter 6, OSGi Profiles and Bundlor for details.

4.2.2.4 Inline Property Values

Property substitution values can be optionally specified inline instead of as an external file using the <property/> and <propertySet/> elements.

<bundlor:bundlor>
  <property name="bundle.name" value="Kernel test bundle"/>
  <property name="bundle.version" value="1.0.2.BUILD-${timestamp}"/>
  <propertyset>
    <propertyref builtin="all"/>
  </propertyset>
</bundlor:bundlor>

See Section 5.3, “Specifying property placeholders” for details.

4.2.3 ANT Task Examples

4.2.3.1 Creating a manifest

<bundlor:bundlor
   inputPath="${basedir}/target/classes"
   outputPath="${basedir}/target/classes"
   bundleVersion="1.0.2.BUILD-${timestamp}"
   manifestTemplatePath="${basedir}/template.mf"/>

4.2.3.2 Creating a manifest with placeholder replacement

<bundlor:bundlor
    inputPath="${basedir}/target/classes"
    outputPath="${basedir}/target/target/classes"
    bundleVersion="1.0.2.BUILD-${timestamp}"
    manifestTemplatePath="${basedir}/template.mf">
  <property name="bundle.name" value="Kernel test bundle"/>
  <property name="bundle.version" value="1.0.2.BUILD-${timestamp}"/>
</bundlor:bundlor>