----- Original Message -----
From: "Gary Feldman" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, July 27, 2006 1:31 AM
Subject: Re: [NAnt-users] Evaluation of if and unless
> Gert Driesen wrote:
>> From: "Bonio Lopez" <[EMAIL PROTECTED]>
>> Sent: Tuesday, July 25, 2006 6:37 PM
>> ...
>>
>> Another solution for your problem would be to skip initializing
>> tasks/elements if the value of the "unless" attribute evaulates to true
>> (or
>> the value of the "if" attribute evaluates to false), but we'll need to
>> discuss this further.
>>
> What's the issue with this? This problem comes up often enough. The
> intuitive sense of the if and unless attributes is that they should
> always be evaluated first, and if the result is to skip the task, then
> absolutely nothing else should happen - no other property evaluations,
> no validity checks on other attribute values, etc.
It's a big more complicated than that. Also, it's not just a problem of
tasks, but of elements, and more importantly, global types too.
One of the problems is that the IfDefined and UnlessDefined properties are
only defined on NAnt.Core.Task, not on NAnt.Core.Element. So we could indeed
implement this for tasks, but we'd still run into problems for child elemens
and global types.
We could ofcourse move these properties to NAnt.Core.Element, but we'd risk
breaking existing custom tasks/elements. And even then we'd need to consider
how to deal with elements that should not be initialized.
Should we ignore them altogether and not even add them to their parent
task/element ? If we chose not to ignore them, then we must trust on each
individual task/container to check whether a given element should be taken
into account. If we ignore them, then what about child elements of global
types: between the initialization of the global type and the actual usage of
it, the value of the property that was used to evaluate the if/unless
attribute could have changed.
Consider this following (incomplete) build fragment:
<project default="build">
<property name="include.text" value="false" />
<fileset id="files">
<include name="*.txt" if="${incliude.text}">
</fileset>
<target name="build">
<property name="include.text" value="true" />
<copy ....>
<fileset refid="files" />
</copy>
</target>
</project>
If we chose to ignore elements based on the if/unless attribute during
initialization, then the <include> element of the fileset will not be
initialized. NAnt will first initialize global types/tasks, and at that
moment "include.text" is false.
Later, when the global fileset is referenced by the <copy> task, the
"include.text" property is true. However, if the <include> element was
ignored during the initialization of the global type, then the fileset would
not know about it when referenced by the <copy> task.
Hope that explains it a little. Gotta run now (meeting).
> In an ideal world,
> I'd go as far as saying it shouldn't even fail if there's a missing
> required attribute or subelement, but those are usually done at the XML
> level, meaning they're reported before NAnt even looks at the build file
> contents.
Nope, only if we'd be using XML validation, but we're not. Missing required
elements or attributes are reported by NAnt.
Gert
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NAnt-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nant-users