ANT - Tips & Tricks - TemplateMethod pattern for build files.

0 views
Skip to first unread message

Muthu Ramadoss

unread,
Jan 22, 2006, 10:07:53 PM1/22/06
to End 2 End Enterprise Technology
In typical development scenario, a 'build-common.xml' file is shared
across multiple projects.

Here's how to provide custom hooks, the ability for the sub projects to
override previous definitions.

1. Include 'custom-build.xml' as the last import and make it optional.

ex:

<!-- import custom build files.. used for project specific
overriding-->
<import file="custom-build.xml" optional="true"/>

Now the sub projects are free to do whatever they like in
custom-build.xml including other property files and overriding previous
property defintions. This would be really handy for having project
specific property settings.

2. Define common targets and do some default behaviour. The sub
projects if required can override the common targets and provide
project specific behavior.

ex:

<target name="_dummy"/>

A target named '_dummy' which does nothing is being included here. The
sub projects can override this to provide custom behavior.

In essence, the 'TemplateMethod' pattern can be applied with build
files to control the way a build sequence would work.

Here's a 'build-common.xml' file that we use in a large project. Of
course this is just one artifact in what we have 10's of build files
for each functionality.

===================

<?xml version="1.0"?>
<!--
$Id: build-common.xml 417 2006-01-21 05:44:12Z Muthu $
-->

<!--
################################################################################
AUTO-GENERATED - DO NOT EDIT!
################################################################################
-->

<project
name="CLIQUE-METRICS_Build_Common"
basedir="."
default="_dummy"
>

<description>
Clique Metrics Common build to be reused across
Applications/Components
</description>

<!--The basedir - would be set to the dir where this file is
included from -->
<!--NOTE: 'cm.basedir' property would be reused in other build
files -->
<dirname
property="cm.basedir"
file="${ant.file.CLIQUE-METRICS_Build_Common}"
/>

<basename property="component.name" file="${cm.basedir}"/>

<property file="build.properties"/>
<property file="build-component.properties"/>

<!-- import custom build files.. used for project specific
overriding-->
<import file="custom-build.xml" optional="true"/>

<!--PROPERTY DEFINITIONS - READ FROM 'build-component.properties'
file -->
<property name="p_src" value="${SRC_DIR}"/>
<property name="p_web" value="${WEB_DIR}"/>
<property name="p_lib" value="${LIB_DIR}"/>
<property name="p_test" value="${TEST_DIR}"/>
<property name="p_dist" value="${DIST_DIR}"/>
<property name="p_setup" value="${SETUP_DIR}"/>
<property name="p_java" value="${JAVA_DIR}"/>
<property name="p_conf" value="${CONF_DIR}"/>
<property name="p_build" value="${BUILD_DIR}"/>
<property name="p_classes" value="${CLASSES_DIR}"/>
<property name="p_exploded" value="${EXPLODED_DIR}"/>
<property name="p_test_classes" value="${TEST_CLASSES_DIR}"/>
<property name="p_test_output" value="${TEST_OUTPUT_DIR}"/>

<property name="src" value="${cm.basedir}/${p_src}"/>
<property name="lib" value="${cm.basedir}/${p_lib}"/>
<property name="web" value="${cm.basedir}/${p_web}"/>
<property name="test" value="${cm.basedir}/${p_test}"/>
<property name="dist" value="${cm.basedir}/${p_dist}"/>
<property name="setup" value="${cm.basedir}/${p_setup}"/>
<property name="conf" value="${cm.basedir}/${p_conf}"/>
<property name="build" value="${cm.basedir}/${p_build}"/>

<property name="src-java" value="${src}/${p_java}"/>
<property name="test-java" value="${test}/${p_java}"/>
<property name="src-conf" value="${src}/${p_conf}"/>
<property name="test-conf" value="${test}/${p_conf}"/>
<property name="test-setup" value="${test}/${p_setup}"/>
<property name="build-classes" value="${build}/${p_classes}"/>
<property name="build-test-classes"
value="${build}/${p_test_classes}"/>
<property name="build-test-output"
value="${build}/${p_test_output}"/>
<property name="build-exploded" value="${build}/${p_exploded}"/>

<property name="web-inf" value="${build-exploded}/WEB-INF"/>
<property name="web-xml" value="${web-inf}/web.xml"/>
<property name="web-classes" value="${web-inf}/${p_classes}"/>
<property name="web-lib" value="${web-inf}/${p_lib}"/>


<!--NOTE: Subsystem can override this and add additional library
paths-->
<path id="lib_path">
<fileset dir="${p_lib}" includes="**/*.jar"/>
</path>

<path id="class_path">
<path location="${p_build}/${p_test_classes}"/>
<!-- HBM files are located in classes, Include them here -->
<path location="${p_build}/${p_classes}"/>
</path>

<path id="lib_class_path">
<path refid="lib_path"/>
<path refid="class_path"/>
</path>

<target name="_dummy"/>

</project>

Reply all
Reply to author
Forward
0 new messages