ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mithun Gonsalvez <mithungonsal...@gmail.com>
Subject Problem Reusing Condition API
Date Tue, 23 Jun 2009 12:55:39 GMT
Hi All,

I have a small problem (hopefully):

I am trying to extend MacroDef to aggregate certain arguments depending upon
conditions.

*Ant-File:*
<?xml version="1.0" encoding="UTF-8"?>
<project name="ExtensionTester" default="default" basedir=".">

    <taskdef name="anotherTezt" classname="myownpackage.TestCheck"/>
    <anotherTezt name="Test">
        <MainArgument>
            <MySingleArgument>
                <equals arg1="MyName"  arg2="MyName"
 casesensitive="false"/>
                <equals arg1="MyName2" arg2="MyName2"
casesensitive="false"/>
            </MySingleArgument>
            <!-- More MySingleArgument's can come here -->
        </MainArgument>
        <!-- More MainArgument's can come here -->
    </anotherTezt>

    <target name="default" >
        <anotherTezt/>
    </target>
</project>


*Extension Code:*
package myownpackage;

import java.util.ArrayList;
import java.util.List;
import org.apache.tools.ant.taskdefs.MacroDef;
import org.apache.tools.ant.taskdefs.condition.Condition;

public class TestCheck extends MacroDef {

    public static class MySingleArgument {

        List<Condition> conditions = new ArrayList<Condition>();

        public void addConfiguredCondition(Condition condition) {
            this.conditions.add(condition);
        }

//        .... More code here to set other values ....
    }

    public static class MainArgument {

        private List<MySingleArgument> singularArguments = new
ArrayList<MySingleArgument>();

        public void addConfiguredMySingleArgument(MySingleArgument
singularArgument) {
            this.singularArguments.add(singularArgument);
        }

//        .... More code here to set other values ....
    }

    private List<MainArgument> allArguments = new ArrayList<MainArgument>();

    @Override
    public void execute() {
        for (MainArgument arg : allArguments) {
            for (MySingleArgument singleArg : arg.singularArguments) {
                for (Condition condition : singleArg.conditions) {
                    if (condition.eval()) {
                        // Do Something here :)
                    }
                }
            }
        }
    }

    public void addConfiguredMainArgument(MainArgument anArgument) {
        this.allArguments.add(anArgument);
    }
}


*After Running:*
BUILD FAILED
My_CustomeBuild.xml:5: MySingleArgument doesn't support the nested "equals"
element.



I wish to achieve what is being mentioned in "execute()" method [Atleast in
a logical way],
  ie. to evaluate each condition and then take an appropriate decision.
I do now wish to set any property value after evaluation of the condition,
hence <condition> tag was omitted.
Any help would be greatly appreciated, to solve this issue.

(Hope this is not a question for the "dev@ant.apache.org")

Thank You,
Mithun Gonsalvez

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