Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing a UNIX Timestamp in an Ant Property?

I'd like to store a UNIX timestamp (i.e. seconds since epoch) in an Ant property for later use in a couple build targets. It appears to be impossible:

<tstamp>
  <format property="build.time" />
</tstamp>`

...generates a formatted timestamp.

<propertyfile file="foo.properties">
    <entry key="build.time" type="date" default="now" />
</propertyfile>

...also generates a formatted timestamp.

I'd hope that this is possible without using <exec> or similar (since we will sometimes run the build on Windows).

like image 819
magneticMonster Avatar asked Apr 14 '11 15:04

magneticMonster


People also ask

How is Unix time stored?

Unix timestamps usually are stored in 32-bit signed integers. A 32-bit signed integer uses the first bit to determine the sign, and the next 31 to encode the number, so it can represent integers from −(231) to 231 − 1.

Are Unix timestamps always UTC?

A few things you should know about Unix timestamps:Unix timestamps are always based on UTC (otherwise known as GMT). It is illogical to think of a Unix timestamp as being in any particular time zone. Unix timestamps do not account for leap seconds.

What does * stands for in * Test Java in ant?

**\*.sql means "in the given directory and inside all of its subdirectories, all the files that end with .sql"

Are Unix timestamps seconds or milliseconds?

Unix is an operating system originally developed in the 1960s. Unix time is a way of representing a timestamp by representing the time as the number of seconds since January 1st, 1970 at 00:00:00 UTC.


1 Answers

A quick google brings up:

http://www.norio.be/blog/2010/08/getting-unix-time-epoch-ant-build-file

<target name="print-epoch">
  <script language="javascript">
  <![CDATA[
    property = project.setProperty("now",Math.floor((new Date()).getTime()/1000));
  ]]>
  </script>
  <echo message="${now}" />
</target>

Other approaches that would be cleaner IMO would be to

  1. create your own custom anttask. It's really not that difficult; http://ant.apache.org/manual/develop.html

  2. Use the Maven exec plugin to execute Java to do this: http://mojo.codehaus.org/exec-maven-plugin/

like image 89
Brian Roach Avatar answered Oct 13 '22 23:10

Brian Roach