You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Angus McIntyre <an...@pobox.com> on 2003/01/18 22:47:36 UTC

FilenameMapper with multiple mappings?

I've written an Ant task that uses Xalan to do XSLT transformations 
(plus one or two other little things, which is why I didn't just use 
Style or Styler). It works fine, but I've just run up against a 
problem.

The task is based on Copy, which allows a single Mapper. I need to 
specify several mappings, i.e. "*.xml" --> "*.html", "*.php" --> 
"*.php" etc. As far as I can see, there's no way to do this with any 
of the existing Mapper types.

I can think of several approaches that I might take.

One would be to define a new FileNameMapper type, so as to be able to 
do something like:

	<mapper type="multiglob" from="*.xml,*.php" to="*.html,*.php"/>

However, it's not immediately clear to me how easy it would be to 
integrate this, given the way mapper implementations are defined. It 
looks to me as if I'd need to hack Mapper to make this work.

Another approach might be to override 'createMapper()' in my task 
implementation to allow multiple mappers to be defined for a task. 
This would work, but might also require me to override 'buildMap()'.

What would be the best (and quickest) way to be able to do what I 
want? Or am I missing some existing feature that would allow me to do 
this without changing anything?

Thanks,

	Angus
-- 
angus@pobox.com                             http://pobox.com/~angus

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: FilenameMapper with multiple mappings?

Posted by Stefan Bodewig <bo...@apache.org>.
On Mon, 20 Jan 2003, Angus McIntyre <an...@pobox.com> wrote:

> am I correct in thinking that mappers are local to a task ... but
> their IDs are global?

Yes.

> What I've observed is that if I define a mapper with an 'id'
> attribute in one task, then I can use 'refid' to reference it within
> that same task, but if I try to reference it from elsewhere, I get
> errors telling me that I must specify at least type or classname
> (i.e. the mapper isn't identifiable/usable outside the task where it
> was defined).

Ant 1.5.1?  I vaguely remember fixing a bug with just this symptoms.
Do you have a simple example that exposes this bug?

> I think that if mappers become more complex, it would be good to be
> able to define them globally at the project level, and then
> reference them from within tasks.

This should be possible right now.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: FilenameMapper with multiple mappings?

Posted by Angus McIntyre <an...@pobox.com>.
At 8:59 +0100 20.01.2003, Stefan Bodewig wrote:
>On Sat, 18 Jan 2003, Angus McIntyre <an...@pobox.com> wrote:
>>  One would be to define a new FileNameMapper type, so as to be able
>>  to do something like:
>>
>>  	<mapper type="multiglob" from="*.xml,*.php"
>>  	to="*.html,*.php"/>
>
>Yes.  Maybe we should add some support for arbitrary nested elements
>in <mapper> (using DynamicElement?).

It occurred to me that to be able to do something like:

	<mapper type="multiple">
	   <mapper type="glob" from="*.xml" from="*.html"/>
	   <mapper type="glob" from="*.php" to="*.php"/>
	</mapper>

might be handy (possibly not with that exact syntax, but I'm sure you 
get the idea). It may be overkill, but someone would find a use for 
it sooner or later.

Also, am I correct in thinking that mappers are local to a task ... 
but their IDs are global?

What I've observed is that if I define a mapper with an 'id' 
attribute in one task, then I can use 'refid' to reference it within 
that same task, but if I try to reference it from elsewhere, I get 
errors telling me that I must specify at least type or classname 
(i.e. the mapper isn't identifiable/usable outside the task where it 
was defined). This seems reasonable enough, but if I define two 
mappers with the same ID in different tasks, I get warnings about 
non-unique IDs.

I think that if mappers become more complex, it would be good to be 
able to define them globally at the project level, and then reference 
them from within tasks. Unless I'm misunderstanding the way Ant 
works, this is not currently possible.

>>  looks to me as if I'd need to hack Mapper to make this work.
>
>No, just use the classname attribute instead of type.

Yes, I finally worked this out by myself ("Use the Force, Luke - read 
the source"), and hacked up my own mapper that takes comma-separated 
lists of extensions as 'from' and 'to' attributes. This works fine, 
and does just what I needed it to. Ant rocks, as they say.

Thanks

	Angus
-- 
angus@pobox.com                             http://pobox.com/~angus

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: FilenameMapper with multiple mappings?

Posted by Stefan Bodewig <bo...@apache.org>.
On Sat, 18 Jan 2003, Angus McIntyre <an...@pobox.com> wrote:

> One would be to define a new FileNameMapper type, so as to be able
> to do something like:
> 
> 
> 	<mapper type="multiglob" from="*.xml,*.php"
> 	to="*.html,*.php"/>

Yes.  Maybe we should add some support for arbitrary nested elements
in <mapper> (using DynamicElement?).

> However, it's not immediately clear to me how easy it would be to
> integrate this, given the way mapper implementations are defined. It
> looks to me as if I'd need to hack Mapper to make this work.

No, just use the classname attribute instead of type.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>