ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Jan.Mate...@rzf.fin-nrw.de>
Subject AW: extract file date in a given format
Date Fri, 05 Jan 2007 07:37:38 GMT
><!-- usage : <filedate file="xxx.jar" property="date"/> --> 
><scriptdef name="filedate" language="javascript">
>     <attribute name="file"/>
>     <attribute name="property"/>
>     <![CDATA[
>         fileName = attributes.get("file");
>         propName = attributes.get("property");
>         file = new java.io.File(fileName);
>         last = file.lastModified();
>         project.setNewProperty(propName, last);
>     ]]>
></scriptdef>



>I also need the date in a human readable format.
>
>I tried to write a second script but am getting an 
>IllegalArgumentException on "new Date(millis)":
>
><!-- usage : <formatdate millis="${millis}" format="yyMMddHHmm" 
>property="formatted"/> -->
><scriptdef name="filedate" language="javascript">
>     <attribute name="millis"/>
>     <attribute name="format"/>
>     <attribute name="property"/>
>     <![CDATA[
>         millis = attributes.get("millis");
>         format = attributes.get("format");
>         propName = attributes.get("property");
>         d = new java.util.Date(millis);
>         f = new java.text.SimpleDateFormat(format);
>	y = f.format(d);
>         project.setNewProperty(propName, y);
>     ]]>
></scriptdef>



Project: public String getProperty(String propertyName)
You have to convert the String into a long.


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


You dont return a property - you store a value in project's
property-hashtable.
And of course you can save muliple values.


Jan

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


Mime
View raw message