ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "didge" <di...@foundrylogic.com>
Subject RE: Any examples of how we can simplify ant build.xml with templates (?)
Date Wed, 04 Feb 2004 17:43:48 GMT
I recently started experimenting with the new <import> task and wanted to
come up with a basic set of targets that would be reusable across projects
with minimal configuration per project.

I wanted my basic set of targets to include the following targets:
compile
jar
javadoc
build
clean

In addition, I wanted the source, class, output paths, and a number of other
variables to be overridable as needed.

First, an examle project build file that my default targets showing the use
of the <import> task:

<project name="Some Project" basedir="." default="build">

    <property environment="env"/>
    <property name="jar.name" value="some-project"/>
    <import file="targets.xml"/>

</project>

Here is the template:

<project name="targets">

    <path id="javac.extended.classpath" path=""/>
    <path id="javac.sourcepath" path="${basedir}/src"/>

    <target name="debug">
        <property name="javac.debug" value="on"/>
    </target>

    <target name="optimize">
        <property name="javac.optimize" value="on"/>
    </target>

    <target name="nowarn">
        <property name="javac.nowarn" value="on"/>
    </target>

    <target name="deprecation">
        <property name="javac.deprecation" value="on"/>
    </target>


    <target name="init" unless="init.done" >
        <property name="init.done" value="true"/>

        <!--
             The following Ant property ensures that the user's classpath is
             ignored.
        -->
        <property name="build.sysclasspath" value="ignore"/>

        <condition property="javac.debug" value="off">
            <not><isset property="javac.debug"/></not>
        </condition>

        <condition property="javac.optimize" value="off">
            <not><isset property="javac.optimize"/></not>
        </condition>

        <condition property="javac.nowarn" value="off">
            <not><isset property="javac.nowarn"/></not>
        </condition>

        <condition property="javac.deprecation" value="off">
            <not><isset property="javac.deprecation"/></not>
        </condition>

        <condition property="javac.src.dir" value="${basedir}/src">
            <not><isset property="javac.src.dir"/></not>
        </condition>

        <condition property="build.dir" value="${basedir}/build">
            <not><isset property="build.dir"/></not>
        </condition>

        <condition property="javac.dest.dir" value="${build.dir}/classes">
            <not><isset property="javac.dest.dir"/></not>
        </condition>

        <condition property="jar.dest.dir" value="${build.dir}/lib">
            <not><isset property="jar.dest.dir"/></not>
        </condition>

        <condition property="javadoc.fullname" value="${ant.project.name}">
            <not><isset property="javadoc.fullname"/></not>
        </condition>

        <condition property="javadoc.dest.dir" value="${basedir}/build/api">
            <not><isset property="javadoc.dest.dir"/></not>
        </condition>

        <condition property="lib.dir" value="${basedir}/lib">
            <not><isset property="lib.dir"/></not>
        </condition>

        <path id="javac.classpath">
            <path refid="javac.extended.classpath"/>
            <path refid="javac.sourcepath"/>
            <pathelement path="${javac.dest.dir}"/>
            <fileset dir="${lib.dir}" includes="*.jar,*.zip"/>
            <fileset dir="${env.OC4J_HOME}/j2ee/home/lib" includes="*.jar"/>
            <fileset dir="${env.OC4J_HOME}/j2ee/home" includes="*.jar"/>
            <fileset dir="${env.OC4J_HOME}/jdbc/lib" includes="*.jar"/>
            <fileset dir="${env.OC4J_HOME}/lib" includes="*.jar"/>
            <fileset dir="${env.OC4J_HOME}/jlib" includes="*.jar"/>
            <fileset dir="${env.CAP_HOME}/cap/lib/" includes="*.jar,*.zip"/>
        </path>

    </target>

    <target name="compile" depends="init">
        <javac
            includeAntRuntime="false"
            debug="${javac.debug}"
            optimize="${javac.optimize}"
            nowarn="${javac.nowarn}"
            deprecation="${javac.deprecation}"
            destdir="${javac.dest.dir}"
            classpathref="javac.classpath"
        >
            <src refid="javac.sourcepath"/>
        </javac>
    </target>

    <target name="javadoc" depends="init">
        <mkdir dir="${javadoc.dest.dir}"/>

        <javadoc
            destdir="${javadoc.dest.dir}"
            packagenames="*"
            author="true"
            private="true"
            version="true"
            use="true"
            windowtitle="${javadoc.fullname}"
            doctitle="${javadoc.fullname}"
            bottom="Copyright &#169; All Rights Reserved."
            sourcepathref="javac.sourcepath"
            classpathref="javac.classpath"
        />

    </target>

    <target name="jar" depends="init">
        <jar jarfile="${jar.dest.dir}/${jar.name}.jar">
            <fileset dir="${javac.dest.dir}"/>
        </jar>
    </target>

    <target name="build" depends="clean, compile, jar">
    </target>

    <target name="clean" depends="init">
        <delete failonerror="false" includeEmptyDirs="true">
			<fileset dir="${javac.dest.dir}" includes="**/*"/>
			<fileset dir="${jar.dest.dir}" includes="**/*"/>
        </delete>
    </target>

    <target name="createProject">
        <mkdir dir="${basedir}/bin"/>
        <mkdir dir="${basedir}/build/classes"/>
        <mkdir dir="${basedir}/build/lib"/>
        <mkdir dir="${basedir}/build/api"/>
        <mkdir dir="${basedir}/conf"/>
        <mkdir dir="${basedir}/doc"/>
        <mkdir dir="${basedir}/lib"/>
        <mkdir dir="${basedir}/src"/>
    </target>

</project>

didge

> -----Original Message-----
> From: Baz ¤Ñª° [mailto:sky_fox1@yahoo.com]
> Sent: Tuesday, February 03, 2004 11:28 AM
> To: ant-user@jakarta.apache.org
> Subject: Any examples of how we can simplify ant build.xml with
> templates (?)
>
>
> All,
>
> I am sure that there are thousand solutions for this question. But,
> I want to see if anyone can give actual ant build.xml samples for
> simplifying multi layers projects. Meaning parent/build.xml,
> child/build.xml.
>
> How can I simplify them? Using <import> as one suggested and build
> templates.xml with already definied targets in the top of the tree?
> How can I implement it correctly? Other examples or solutions?
>
> Thanks
>
> B.
>
>
> ---------------------------------------------------------------------
> 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