ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Reilly" <peter.kitt.rei...@gmail.com>
Subject Re: [antunit] antlib best practices
Date Mon, 01 Jan 2007 14:40:56 GMT
On 1/1/07, robert burrell donkin <robertburrelldonkin@blueyonder.co.uk> wrote:
> i'm using ant 1.7.0 and antunit to integration test a antlib task. the
> tests are factored into separate build scripts. these run fine
> individually but i'd like to include them in a comprehensive
> build-and-test target in a master build file.
>
> ATM i'm using exec to call ant so that i can pass a -lib setting on the
> command line since i can't work out how to persuade ant to load
> additional antlib's.
>
> is this possible?
> if so, how?
> if not, what's the best way to include antunit integration tests?

There are a number ways to persuade ant to load antlibs.
One way is to place the antlib jar file in ~/.ant/lib, or $ANT_HOME/lib
In this case ant will automatically pick load the antlib when
resolveing the XML namespace for the task.

This has the disadvantage of making the project depend on
the user or global ant configuration.

I prefer to keep as much in the project as possible, so I normally
have a configuration file for the project which I import into the main
build.xml.

One can use <typedef uri="NAMESPACE of antlib" classpath="ANTLIB.jar"/>
(since Ant 1.7.0 - the resource attribute is not needed for antlibs)
to load in the antlib.

I normally setup a project as follows:
  build.xml
  setup.xml
  lib/
  lib/antlibs/
  lib/antlibs/ant-contrib/
  lib/antlibs/ant-contrib/ant-contrib.jar
  lib/antlibs/antunit/
  lib/antlibs/antunit/antunit-1.0.jar

build.xml
<project name="test"
   xmlns:au="antlib:org.apache.ant.antunit"
   xmlns:ac="antlib:net.sf.antcontrib"
   >
  <import file="setup.xml"/>
  <au:assertTrue>
     <equals arg1="a" arg2="a"/>
  </au:assertTrue>
</project>

setup.xml

<!-- build file to configure ant -->
<project name="setup">
  <dirname property="ant.dir.setup" file="${ant.file.setup}"/>
  <macrodef name="define-antlib">
    <attribute name="ns"/>
    <attribute name="dir"/>
    <sequential>
      <typedef uri="@{ns}">
        <classpath>
          <fileset dir="${ant.dir.setup}/lib/antlibs/@{dir}"
                   includes="**/*.jar"/>
        </classpath>
      </typedef>
    </sequential>
  </macrodef>

  <!-- antunit -->
  <define-antlib ns="antlib:org.apache.ant.antunit" dir="antunit"/>

  <!-- ant-contrib -->
  <define-antlib ns="antlib:net.sf.antcontrib" dir="ant-contrib"/>
</project>

Peter

>
> - robert
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message