You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Marco Faustinelli <ma...@yahoo.com> on 2010/05/03 14:43:15 UTC

FileNameMapper implementation gets invoked twice inside a

Good day to everybody,

I have written a FileNameMapper that gets invoked during the run of a <copy> task. What puzzles me is that the mapper is invoked TWICE per each file handled by the copy task, whereas I request only ONE invocation.

The details follow here. Thanks in advance to whoever will want to spend some time on my issue.

Have a nice day,
Marco Faustinelli - Italy
------------------------------------------------
DETAILS:

The mapper writes the name of the file currently processed into a property of my chosing. The signature of the class is:

publicclassFilenameInPropertySettingMapper extendsProjectComponent implementsFileNameMapper
 
The mapFileName(String sourceFileName) method is just like the IdentityMapper, plus the instruction getProject().setProperty(property, sourceFileName) along it. I have also added a log call to monitor the activity of the mapper.
 
My build.xml looks contains the following <typedef>:
....... 
Inside the target I have the lines:
<copy todir=".....">
 <fileset ... />
 <mapper>
  <chainedmapper>
   <filenameSetMapper property="currentFile" />
   <globmapper from="*.csv" to="*.xml" casesensitive="no" />
  </chainedmapper>
 </mapper>
 <filterchain ... />
........
</copy>

When I run the script I verify that the property currentFile is set correctly and I can use it in the remainder of the <copy>. But I can see from the log that my mapper is invoked TWICE for each file found in the fileset.
 
Can anybody explain me what is happening? How can I avoid this potentially dangerous double invocation?
 
Thanks in advance
Marco Faustinelli, Italy
 <typedefname="filenameSetMapper"classname="net.faustinelli.ant.mapper.FilenameInPropertySettingMapper"classpath="..."/>........

Re: FileNameMapper implementation gets invoked twice inside a

Posted by Marco Faustinelli <ma...@yahoo.com>.
Stefan,
Thank you for the quick and exhaustive answer. What you recall matches what I see.
I have to be careful.

Have a nice day,
Marco

 

________________________________
From: Stefan Bodewig <bo...@apache.org>
To: user@ant.apache.org
Sent: Mon, May 3, 2010 3:53:42 PM
Subject: Re: FileNameMapper implementation gets invoked twice inside a <chainedmapper>

On 2010-05-03, Marco Faustinelli <ma...@yahoo.com> wrote:

> I have written a FileNameMapper that gets invoked during the run of a
> <copy> task. What puzzles me is that the mapper is invoked TWICE per
> each file handled by the copy task, whereas I request only ONE
> invocation.

I don't think Ant makes any guarantees about how often it may want to
invoke a mapper.

From the top of my head - I'd have to look into the code to be sure -
the mapper is invoked once when Ant determines which files to copy at
all (to provide the target for timestamp comparisons) and once when the
file is actually copied.

Please note that it gets invoked during the "what needs to be copied
anyway" phase even for files that won't be copied later at all.

Stefan

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

Re: FileNameMapper implementation gets invoked twice inside a

Posted by Stefan Bodewig <bo...@apache.org>.
On 2010-05-03, Marco Faustinelli <ma...@yahoo.com> wrote:

> I have written a FileNameMapper that gets invoked during the run of a
> <copy> task. What puzzles me is that the mapper is invoked TWICE per
> each file handled by the copy task, whereas I request only ONE
> invocation.

I don't think Ant makes any guarantees about how often it may want to
invoke a mapper.

>From the top of my head - I'd have to look into the code to be sure -
the mapper is invoked once when Ant determines which files to copy at
all (to provide the target for timestamp comparisons) and once when the
file is actually copied.

Please note that it gets invoked during the "what needs to be copied
anyway" phase even for files that won't be copied later at all.

Stefan

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