I reviewed the code with a colleague today and we're pretty sure that
the second solution I came up with is viable.
Normally, the rule is that TaskHandler will only be used at the top
level of the buildfile (that is, in ProjectHandler) or in targets
(TargetHandler).
As soon as a Task has been set up in the target, everything below it is
handled by NestedElementHandler (see TaskHandler, about line 221). That
also applies to tags like <property>: Property is a Task on its own, but
when used like
<phing phingfile="..." ...>
<property name="..." value="...">
</phing>
it is set up as a nested element (in the Phing task).
In order to execute "real" tasks -- that is those directly below
<target> that really "do some work" --, all the Tasks they contain need
to be executed (and especially runtime-configured) before. From what
we've seen, these nested Tasks always seem to be "declarative" in nature
(like fileset, property etc). Additionally, the set of NestedElements
allowed depends on the Task and is limited.
Now comes the exception from the rule: The handler used for setting up
the Tasks can switch back to a TaskHandler *only* when the element at
hand is an instanceof TaskContainer (see startElement() in
NestedElementHandler and TaskHandler). In this case, the tasks contained
are again treated like "main" tasks (directly below target).
Only Target and SequentialTaskContainer implement TaskContainer. Target
is obvious; SequentialTaskContainer is only used by the if/then/else
construct. In other words, currently only if/then/else should allow for
an arbitrary set of elements below it, like <target> does.
This makes us pretty sure that TaskHandler is the only place where
unrelated "main" tasks start (and it only starts this kind of tasks).
Thus, we suggest removing lines 167-170 from TaskHandler.php, which is
where these unrelated and new tasks hook up with their parent's runtime
configurable wrapper. The tasks will still call maybeConfigure
themselves when they start. That will defer the configuration until the
task really needs it.
Best regards,
Matthias