>> using condition in target
Ok, I found the topic you're talking about :
http://marc.info/?l=ant-dev&m=124052209931008&w=2Append <condition> task as the first element of <target> task would be
really nice.
Do you know if it's implemented ? or planned to be implemented ?
>> using return task
By going in this way, I think that using a <return> task would be more
flexible :
- may be used wherever in the <target> task
- may be implemented in other tasks (<macrodef>)
For example :
/<target name="test-return"> /
/ <echo message="test-return : begin" /> /
/ <return message="return from target"> /
/ <condition> /
/ <equals arg1="Y" arg2="Y" /> /
/ </condition> /
/ </return> /
/ <echo message="test-return : end" /> /
/</target> /
> ant -f test.xml test-return
Buildfile: test.xml
test-return:
[echo] test-return : begin
[return] return from target
BUILD SUCCESSFUL
Total time: 0 seconds
To implement this example :
- I create a /Return/ class from the /Exit/ one, it's quiet the same
I just /throw new ReturnException(this.message)/ at the end
- I catch the Exception in the /Target/ class
/[...]
} catch (ReturnException e) { /
/ Echo echo = new Echo(); /
/ echo.setProject(getProject()); /
/ echo.setTaskName("return"); /
/ echo.setMessage(e.getMessage().substring("ReturnException:
".length(),e.getMessage().length()).trim()); /
/ echo.execute(); /
/} finally { /
/ localProperties.exitScope(); /
/}/
I can work on this task (implementation, unit tests, doc...), if this
idea is approved.
Regards,
Benjamin
Jeffrey E Care a écrit :
>
> We've already discussed various schemes for expanding the conditional
> execution of targets, most recently by allowing conditions as
> top-level children of targets. Check the archives.
> ____________________________________________________________________________________________
>
> Jeffrey E. (Jeff) Care
>
_carej@... <mailto:
carej@...>
> IBM WebSphere Application Server
> WAS Release Engineering
>
>
> WebSphere Mosiac
> WebSphere Brandmark
>
>
>
>
> Benjamin de Dardel <
benjamin.dedardel@...> wrote on 06/22/2009
> 05:54:32 PM:
>
> > [image removed]
> >
> > discussion about conditional structures
> >
> > Benjamin de Dardel
> >
> > to:
> >
> > Ant Developers List
> >
> > 06/22/2009 05:55 PM
> >
> > Please respond to "Ant Developers List"
> >
> > Hi all,
> >
> > I suppose that there have been a lot of discussion about conditional
> > structures, but I would like to open another one.
> > For now, I notice two solutions :
> >
> > >> solution 1 : ant approach, using if and unless parameters.
> > <target name="todo" depends="ok,ko"/>
> > <target name="ok" if="my-property-is-set"/>
> > <target name="ko" unless="my-property-is-NOT-set"/>
> > Disadvantages :
> > - not as simple as it should be
> > - property evaluation is not possible (or I don't know how to do this)
> >
> > >> solution 2 : ant-contrib
> > <if>
> > <equals arg1="..." arg2="..."/>
> > </if>
> > Disadvantages :
> > - verbose solution
> > - project still maintain ?
> > - solution not integrated in the ant project
> >
> > >> solution 3
> > I would like to discuss about another solution, based upon <antcall>
> > et <condition> tasks.
> > <antcall target="todo">
> > <condition>
> > <equals arg1="${val1}" arg2="${val2}"/>
> > </condition>
> > </antcall>
> > Target would be executed if condition succeeded.
> >
> > Advantages :
> > + use an existing task : <antcall> by adding a nested element
> > => quiet easy to implement (see attached file)
> > + use all <condition> possibilities
> >
> > What do you think about this idea ?
> >
> > Best regards,
> > Benjaminpackage net.sourceforge.ant4hg.contrib;
> >
> > import org.apache.tools.ant.BuildException;
> > import org.apache.tools.ant.taskdefs.CallTarget;
> > import org.apache.tools.ant.taskdefs.condition.Condition;
> > import org.apache.tools.ant.taskdefs.condition.ConditionBase;
> >
> > public class CallTarget2 extends CallTarget {
> >
> > // //////////////////////////////////////////////
> > // INNER CLASS
> > // //////////////////////////////////////////////
> > /**
> > * @see org.apache.tools.ant.taskdefs.Exit
> > */
> > private static class NestedCondition extends ConditionBase
> > implements Condition {
> > public boolean eval() {
> > if (countConditions() != 1) {
> > throw new BuildException("A single nested condition
> > is required.");
> > }
> > return ((Condition) (getConditions().nextElement())).eval();
> > }
> > }
> >
> > // //////////////////////////////////////////////
> > // ATTRIBUTES
> > // //////////////////////////////////////////////
> > /**
> > * @see org.apache.tools.ant.taskdefs.Exit
> > */
> > private NestedCondition nestedCondition;
> >
> > /**
> > * @see org.apache.tools.ant.taskdefs.Exit
> > */
> > public ConditionBase createCondition() {
> > if (nestedCondition != null) {
> > throw new BuildException("Only one nested condition is
> allowed.");
> > }
> > nestedCondition = new NestedCondition();
> > return nestedCondition;
> > }
> >
> > // //////////////////////////////////////////////
> > // CONSTRUCTORS
> > // //////////////////////////////////////////////
> > public CallTarget2() {
> > super();
> > setTaskName("antcall");
> > }
> >
> > // //////////////////////////////////////////////
> > // OVERRIDEN METHODS
> > // //////////////////////////////////////////////
> > public void execute() throws BuildException {
> > if (!nestedCondition.eval()) {
> > return;
> > }
> > super.execute();
> > }
> >
> > }
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
dev-unsubscribe@...
> > For additional commands, e-mail:
dev-help@...