TECHO - ANT ECHO task with timestamp

I often find myself writing ANT script which I need to measure times in it.

I can write ANT task for that and include it in my project (I have such task but it will not be in the scope of that post), but it will require me to add files to the source control, manage the build and deployment of the tasks-jar and more while what I want is a quick solution that will not go beyond the scope of my build.xml script.

The quick solution I have for the above requirements is to add a scriptdef for a script called TECHO that will wrap the ECHO task and will able to add a timestamp signiture to the printed message.

For example, if the following echo instance will display the text as displayed below it:

<echo message="Print this text"/>

output:

[echo] Print this text

The matching techo instance will result as follow:

<techo message="Print this text"/>

output:

[echo] Print this text [25/11/2013 13:26:48]

You can of course use Ant-contrib-stopwatch for the same purpose but this will require you to include the antcontrib jar in your build environment and track the stop-watches, while my suggested solution will only provide timestamps printputs.

All you need is to add the below definition in the build.xml file header:

<scriptdef name="techo" language="javascript">
 <attribute name="message"/>

<![CDATA[
function getTimeStamp() {
    var now = new Date();
    return ((now.getDate()) + '/' +
             (now.getMonth() + 1) + '/' +
             now.getFullYear() + " " +
             now.getHours() + ':' +
             ((now.getMinutes() < 10)
                 ? ("0" + now.getMinutes())
                 : (now.getMinutes())) + ':' +
             ((now.getSeconds() < 10)
                 ? ("0" + now.getSeconds())
                 : (now.getSeconds())));
}
    tstamp = getTimeStamp();
    self.log(attributes.get("message") +" ["+tstamp+"]");
]]>
</scriptdef>

Enjoy!

 

Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com