Phing - Do something at start and at end of build, regardless of task

127 Views Asked by At

For my Phing build I want to record the start and end time in a local file . This time will be used during the build as a reference to determine which of my source files were modified after the last build. I'd like this to work regardless of that task called.

Some problems I've had so far:

I retrieve the start time from the file before I record the new time. But when I use a foreach loop the build properties are redefined, and the new start time is recorded in the property. Maybe I can remedy this by defining the property in a task which is depended on, but I don't want to set up this dependency for every task...

And I have no idea how to make something run last, independent of the task the user chose to run.

Any thoughts?

1

There are 1 best solutions below

0
On

Editing entire answer as I re-read your question - the part wherein you need it to run independent of task.

<target name="taskwrapper">
   <phingcall target="runfirst" />
   <phingcall target"${target} />
   <phingcall target="runlast" />
</target>

<target name="runfirst">
  //Do stuff first
</target>

<target name="runlast">
  //Do stuff last
</target>

Then in the command line you just need to pass the intended task as an arguement.

phing taskwrapper -Dtarget=desired_task

Haven't actually tested this, but seems like it should work fine.