ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject RE: Any examples of how we can simplify ant build.xml with templa tes (?)
Date Thu, 05 Feb 2004 06:31:17 GMT
> Maybe the solution is just to check if the hook'd targets 
> have dependencies
> and fail if they do. That's what I'll do if I ever use your 
> trick ;-) --DD


Something like that?

Jan



<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="test" basedir="." default="main">

    <property name="failOnDep" value="true"/>

    <scriptdef name="hook" language="javascript">
        <attribute name="target"/>
        <attribute name="failondep"/>
        <![CDATA[
            failOnDep = attributes.get("failondep");
            if (project.getTargets().containsKey(attributes.get("target")))
{
                target = project.getTargets().get(attributes.get("target"));
                if (target.getDependencies().hasMoreElements()) {
                    java.lang.System.out.println("has dependencies");
                    // target has dependencies ...
                    if ("true".equals(failOnDep)) {
                        // ... so fail
                        fail = project.createTask("fail");
                        fail.setMessage("Target " + target.getName() + " has
dependencies");
                        fail.perform();
                    } else {
                        // ... but doesn´t matter
                        java.lang.System.out.println("Target " +
target.getName() + " has dependencies");
                        target.performTasks();
                    }
                } else {
                    // no dependencies
                    java.lang.System.out.println("has no dependencies");
                    target.performTasks();
                }
            }
        ]]>
    </scriptdef>


    <target name="init">
        <echo>INIT</echo>
    </target>

    <target name="main-pre" depends="init">
        <echo>PRE</echo>
    </target>

    <target name="main-post">
        <echo>POST</echo>
    </target>


    <target name="main">
        <hook target="main-pre" failondep="${failOnDep}"/>
        <echo>MAIN</echo>
        <hook target="main-post"/>
    </target>

</project>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message