Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Build_with_Ant

Philipp Haussleiter edited this page Nov 25, 2015 · 1 revision

Build with Ant

BundleBee is provided with a build system based on popular ant.

The design goals have been:

  • KISS (keep it stupid simple)
  • fully canned
  • fast
  • exact
  • flexible

Projects either create a simple jar for reference or OSGi bundles meant to run within the OSGi framework.

It is KISS bc. every single projects build file is very simple (2 lines in the best case).

It is fast bc. no files are copied around unnecessarily. Everything is build right in place and at its final destination. Libraries and dependencies are fine grained enough to avoid monstrous classpathes.

The build is fully canned in the sense that everything needed is provided by svn or any other kind of deployment. No external resources have to be drawn before the build/run cycle can happen.

Checkout the Sources

You can checkout the latest source from:
https://dev.innoq.com/svn/bundle-bee/trunk

You need to register with

username: bundle-bee password: bundlebee

There is also a tags URL:
https://dev.innoq.com/svn/bundle-bee/tags

The build system is composed of always two components:

  • the infrastructure found in the directory antbuild
  • per project/bundle build files
    • build.xml
    • osgibundle.properties (optional)

available targets

  • build: high-level build, either creates a simple jar or an OSGi bundle; covers jar and bundle
  • run: build the project and run the framework
  • debug: build the project and run the framework, connectable by a debugger
  • test: run the tests
  • clean: well … clean
  • jar: build a jar if the project is a simple jar project
  • bundle: build a OSGi bundle if the project provides osgibundle.properties
  • force_jar: unconditionally creates a jar, even for a OSGi bundle project
  • force_bundle: unconditionally creates a bundle, even for simple jar projects, taking default OSGi properties
  • assembly: create a deliverable binary

antbuild

This directory contains everything that is common to all builds:

  • common.xml: definition of common ant targets
  • libs.properties: definition of common jars like the OSGi framework itself
  • build.properties: version number and such
  • plugins: directory with all jars needed at runtime; target directory for bundle builds
  • devlibs: jars only needed at build/test time

per project files

The build is based on a couple of assumptions that are inherited from the maven build system. These assumptions refer to the directory layout for the sourcecode. Everything is customizable on a per-project basis, but adhering to the defauls makes life easier.

  • src/main/java: basic sources for the jar/bundle
  • src/main/resources: resources to be embodied with the jar/bundle
  • src/test/java: junit test sources
  • build: base directory for build results, created during the build
  • build/classes: raw compiler output
  • build/testclasses: raw compiler output for tests
  • build/testoutput: test reports
  • build/$PROJECTNAME_$VERSION.jar: build jar

build.xml
Build description that is directly passed to ant.

build.xml is as simple as it can be as long as the project layout follows the basic assumptions bc. all the magic is performed from common.xml from the infrastructure. Here is a sample of a build.xml build just a simple jar:

<project name="registry" default="jar" basedir=".">
	<!-- where to find the common ant build directory -->
	<property name="common.dir" value="../antbuild"/>

	<!--import common targets-->
	<import file="${common.dir}/common.xml"/>
</project>

Obviously, nothing has to be done except properly referencing common.xml. With this build.xml, all the targets mentioned above are available.

<project name="carrier" default="bundle" basedir=".">

	<description>Builds, tests, and runs the project ${ant.project.name} ${version}.</description>

	<!-- where to find the common ant build directory -->
	<property name="common.dir" value="../antbuild"/>

	<!--import common targets-->
	<import file="${common.dir}/common.xml"/>

	<!--build dependent projects-->
	<target name="build_dependencies">

		<declare_jar_dependency.macro		prjpath="../Registry"	jar="registry"/>
		<declare_bundle_dependency.macro	prjpath="../Repository" name="repository"/>

		<!--
		Define the projects compile classpath.
		Library paths can be found in antbuild/libs.properties for reference.
		-->
		<path id="project.classpath.refid">
			<pathelement	path="${registry.artifact}"/>
			<pathelement	path="${repository.artifact}"/>
		</path>
	</target>
</project>

This sample declares two dependencies using the declare_jar_dependency.macro and declare_bundle_dependency.macro macros. They make sure that the resp. dependency is build an provide a property holding the resp. classpath element (registry.artifact and repository.artifact in this case). Please note that the jar and name parameters for the macros determine the name of that property.

osgibundle.properties (optional)

Properties describing the OSGi bundle like exported/imported packages and such

top level build

There is a top-level build script antbuild/build.xml which deals with the BundleBee project as a whole. Cleaning and building everything or creating an assembly for binary distribution are the available targets.
Targets to use are:

  • clean
  • build
  • run
  • debug
  • assembly

customisation

The build can be customized be pre-setting ant properties or overloading ant targets. I advise to refer to antbuild/common.xml to see a list of properties that can be predefined in a projects build.xml file. E.g.

<property name="java.src.dir" value="myjavasrc"/>