ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luke Lindsay <luke.lind...@gmail.com>
Subject Re: AW: How can I set last modified date in html files using ant?
Date Fri, 11 Feb 2005 07:25:39 GMT


Jan.Materne@rzf.fin-nrw.de wrote:
> Hhmm - not easy ...
> 1) "iterate" over a fileset
> 2) check the date for each time
> 3) modify the files content
> hmm - maybe (pseudo code):
> 
> 01: <for param="file">
> 02:     <fileset .../>
> 03:     <sequential>
> 04:         <script>
> 05:             importClass(Package.java.io.File);
> 06:             f = new File("@{file}");
> 07:             project.setProperty("date", f.lastModDate() );
> 08:         </script>
> 09:         <replaceregexp file="@{file}" match="..." replace="${date}"/>
> 10:     </sequential>
> 11: </for>
> 
> Line 7 is not "Ant-conform" - it overrides an existing property (usually you
> should use
> the setNewProperty() method). But this is a hack :)
> In Line 7 you also have to search for the right method in File :-)
> 
> And ... no garantue :-O
> 
> 
> Jan
>

Thanks for the suggestion, it worked using the code below.

<taskdef resource="net/sf/antcontrib/antlib.xml" />
<for param="file">
	<fileset dir="${doc}/docs">
		<include name="**/*.html" />
		<include name="**/*.htm" />
				
	</fileset>

	<sequential>
		<script language="jython">
			<![CDATA[
from java.io import File
from java.util import Date
from java.text import SimpleDateFormat
					
file = File("@{file}")

if file.lastModified() == 0:
	project.setProperty("date", "unknown" )					
else:
	date = Date(file.lastModified())				
	sdf = SimpleDateFormat("dd MMM yyyy") 				
	project.setProperty("date", sdf.format(date) )					
]]>
		</script>
		<echo>@{file}  ${date}</echo>
				
		<replace file="@{file}" token="@lastModified@" value="${date}"/>
						
	</sequential>

</for>



Luke

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


Mime
View raw message