ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Allwicher, Klaus" <Klaus.Allwic...@nuance.com>
Subject Copy question
Date Tue, 15 Aug 2006 09:49:58 GMT
Hello,

I have a stylistic question to the copy task and the mappers.

I have the following situation: I have four directories, one
reference/source directory, one reference/compiled directory, one
current/source directory and a current/compiled directory:

+- reference
|  +- source
|  +- compiled
|
+- current
   +- source
   +- compiled


The task is to copy all the files from the reference/compiled directory to
the current/compiled directory, for which the source files does not differ.

e.g:
reference/source
* equal.ref  
* diff.ref
* only_ref.ref

reference/compiled
* same as above with .bin suffix

current/source
* equal.ref (equal to reference/source)
* diff.ref (different content)

current/compiled
<<empty>>

In the situation above the task should only copy
'reference/compiled/equal.bin' to the 'current/compiled' directory.

Currently I implemented this with a <for> loop over a fileset, which
includes the equal files of the both source directories. In the loop, I
change the filename/path of the reference/source folder to the reference
compiled folder.
This works, but does not look very nice. 
Is there an easier solutions (The compilation has nothing to do with
Java/C++, so that dedicated tasks for this cannot be used).

And finally here the code snippet, how it is currently implemented:

<property name="current.source"     value="current\source" />
<property name="current.compiled"   value="current\compiled" />
<property name="reference.source"   value="reference\source" />
<property name="reference.compiled" value="reference\compiled" />

<!-- replace backslashes with slashes, so that the path can be used in 
	regular expressions -->
<propertyregex property="normalized.current.source" override="true" 
	input="${current.source}" regexp="\\" replace="/" />
<propertyregex property="normalized.reference.compiled"  override="true" 
	input="${reference.compiled}"  regexp="\\" replace="/" />

<!-- Iterate over the files, which are equal in both source directories -->
<for param="filename" >
	<fileset dir="${current.source}" includes="**/*.ref" >
		<not>
			<different targetdir="${reference.source}" 
				ignoreFileTimes="true" 
				ignoreContents="false" />
		</not>
	</fileset>
<sequential>
	<propertyregex property="normalized.filename" override="true" 
		input="@{filename}" regexp="\\" replace="/" />
	<!-- replace the path to the source with the path to the compiled
reference -->
	<propertyregex property="normalized.filename" override="true" 
		input="${normalized.filename}" 
		regexp="(.*)${normalized.current.source}/([^/]*)\.([^/\.]*)"

		select="\1${normalized.reference.compiled}/\2.bin" />
	<copy file="${normalized.filename}" todir="${current.compiled}" />
</sequential>
</for>

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


Mime
View raw message