ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rebhan, Gilbert" <Gilbert.Reb...@huk-coburg.de>
Subject RE: extract file date in a given format
Date Fri, 05 Jan 2007 07:38:44 GMT
 
Hi,

-----Original Message-----
From: T E Schmitz [mailto:mailreg@numerixtechnology.de] 
Sent: Thursday, January 04, 2007 11:32 PM
To: user@ant.apache.org
Subject: extract file date in a given format

/*
Also: could I combine the two scripts and return 2 properties if format 
is specified?
*/

i also used javascript a lot, but lately i switched over to (j)ruby


quick hack, something like =

<scriptdef name="filedate" language="ruby">
        <attribute name="file"/>
        <attribute name="property1"/>
        <attribute name="property2"/> 
        <![CDATA[
            stat=File.stat($attributes.get('file'))
 
$project.setProperty($attributes.get('property1'),stat.mtime.strftime('%
d.%m.%Y'))
 
$project.setProperty($attributes.get('property2'),stat.mtime.strftime('%
c'))
         ]]>
    </scriptdef>
     
     <filedate file="C:/ruby/LICENSE.txt" property1="mydate"
property2="localdate"/>   
     
     <echo>
     $${mydate} == ${mydate}
     $${localdate} == ${localdate}
     </echo>


gives =
     [echo] ${mydate} == 03.05.2006
     [echo] ${localdate} == Wed May 03 04:29:10 2006

you may change the format of the output via strftime and several
parameter,
f.e %c means preferred local date/time representation
see =

http://www.ruby.ch/ProgrammingRuby/htmlC/ref_c_time.html#strftime


you need bsf.jar (i think you're already have this when using
javascript)
and jruby.jar in ant's classpath for that <scriptdef>, just put
these jar's in %ANT_HOME%/lib and you're done


Regards, Gilbert

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message