You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Emmanouil Batsis <Em...@eurodyn.com> on 2005/06/27 14:17:17 UTC

Help with (regexp?) file mapper

Hi all,

I'm trying to both change the file name (add 'Form' suffix and change 
from .xml to .java) and directory structure (add one more directory) for 
example from

my/package/Foo.xml

to

my/package/web/FooForm.java

Looks like this is a piece of cake using the regexp file mapper but i 
really suck in regular expressions, anyone have a similar example handy?

Thanks,

Manos

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


Re: Help with (regexp?) file mapper

Posted by Stefan Bodewig <bo...@apache.org>.
On Mon, 27 Jun 2005, Emmanouil Batsis <Em...@eurodyn.com>
wrote:

> my/package/Foo.xml
> 
> to
> 
> my/package/web/FooForm.java

untested

from="(.*)/(.*)\.xml" to="\1/web/\2Form.java"

Stefan

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


Re: Help with (regexp?) file mapper

Posted by Ondrej Svetlik <on...@svetlik.info>.

Emmanouil Batsis wrote:
> 
> It didn't work at first but then i remembered my machine at work runs 
> windows; It works fine after changing the from attribute to 
> (.+)\\(.+).xml. I think i saw something regarding the path seperator and 
> how to make it transparent to the task so i'll look for that now. Many 
> thanks for giving me a head start!

Hello,

since ant-1.6.3 regexpmapper has handledirsep attribute, set this to 
"yes" and it will match slashes and backslashes.

Best regards,

Ondrej Svetlik


Re: Help with (regexp?) file mapper

Posted by Peter Reilly <pe...@apache.org>.
Emmanouil Batsis wrote:

> Dominique Devienne wrote:
>
>>> From: Emmanouil Batsis [mailto:Emmanouil.Batsis@eurodyn.com]
>>> It didn't work at first but then i remembered my machine at work runs
>>> windows; It works fine after changing the from attribute to
>>> (.+)\\(.+).xml. I think i saw something regarding the path seperator 
>>> and
>>> how to make it transparent to the task so i'll look for that now. Many
>>> thanks for giving me a head start!
>>>   
>>
>>
>> Yes, you've run into the ugly bit in mappers, namely the fact that the
>> file separator changes on different platforms, compounded by the fact
>> that the Windows separator is a special character in regexp.
>>
>
> ${file.separator} does not work for regexp mapper but that is a minor 
> issue; the real issue, IMHO, is using mappers within other tasks.

This has to be done "by hand" in the code. Most of the tasks have been 
updated to allow
the new "named" mapper elements - but some for example xslt have not 
been updated yet.

> For example, the xslt/style allows a nested mapper type="regexp" but 
> that does not support the  handledirsep attribute. regexpmapper does, 
> but that subtask is not allowed by xslt!

The mapper element does allow a nested mapper which corresponds to the 
same thing.

<mapper>
   <regexpmapper .../>
</mapper>

Peter

>
> Anyway, i just defined a project property to use within mappers and 
> that works well.
>
> Thaniks,
>
> Manos
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
>


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


[solved] Task allows nested mapper but not regexpmapper with handledirsep (was Re: Help with (regexp?) file mapper)

Posted by Emmanouil Batsis <Em...@eurodyn.com>.
Dominique Devienne wrote:

>> i just defined a project property to use within mappers and that
>>works well.
>>    
>>
>
>Do you mind describing your solution in more details, to help those
>who search the mailing list archive?
>
>BTW, did you try \${file.separator}? 
>  
>

That wouldn't work on my linux box right? I switch between a windows 
machine at work and my linux laptop frequently, so i initially added an 
entry in my build properties:

# controls the path seperator to use in regexp mappers,
# use "/" on unixish systems and "\\\\" on wonblows (no quotes)
mapper.dir.seperator=\\\\

and used it like

<mapper type="regexp" from="(.*)${mapper.dir.seperator}(.*).xml"

However, Peter Reilly's way removes the need to maintain a property and 
allows the use of handledirsep by just nesting the mappers:

<task.that.allows.mapper.but.not.regexp.or.other>
   <mapper>
      <regexpmapper handledirsep="true" from="(.*)/(.*).xml" 
to="\1/web/\2Form.java" />
   </mapper>
</task.that.allows.mapper.but.not.regexp.or.other>

Thanks all.

Manos

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


RE: Help with (regexp?) file mapper

Posted by Dominique Devienne <dd...@gmail.com>.
> From: Emmanouil Batsis [mailto:Emmanouil.Batsis@eurodyn.com]
> ${file.separator} does not work for regexp mapper but that is a minor
> issue; the real issue, IMHO, is using mappers within other tasks. For
> example, the xslt/style allows a nested mapper type="regexp" but that
> does not support the  handledirsep attribute. regexpmapper does, but
> that subtask is not allowed by xslt!

FWIW, you can define an external <mapper> with an ID that contains the
<rexexpmapper> (using the attribute), and refid this one inside <xslt>

Not tested, but a quick look at the code seems to indicate it's possible,
at least on the HEAD>

> Anyway, i just defined a project property to use within mappers and that
> works well.

Do you mind describing your solution in more details, to help those
who search the mailing list archive?

BTW, did you try \${file.separator}? --DD


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


Re: Help with (regexp?) file mapper

Posted by Emmanouil Batsis <Em...@eurodyn.com>.
Dominique Devienne wrote:

>>From: Emmanouil Batsis [mailto:Emmanouil.Batsis@eurodyn.com]
>>It didn't work at first but then i remembered my machine at work runs
>>windows; It works fine after changing the from attribute to
>>(.+)\\(.+).xml. I think i saw something regarding the path seperator and
>>how to make it transparent to the task so i'll look for that now. Many
>>thanks for giving me a head start!
>>    
>>
>
>Yes, you've run into the ugly bit in mappers, namely the fact that the
>file separator changes on different platforms, compounded by the fact
>that the Windows separator is a special character in regexp.
>

${file.separator} does not work for regexp mapper but that is a minor 
issue; the real issue, IMHO, is using mappers within other tasks. For 
example, the xslt/style allows a nested mapper type="regexp" but that 
does not support the  handledirsep attribute. regexpmapper does, but 
that subtask is not allowed by xslt!

Anyway, i just defined a project property to use within mappers and that 
works well.

Thaniks,

Manos

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


RE: Help with (regexp?) file mapper

Posted by Dominique Devienne <dd...@gmail.com>.
> From: Emmanouil Batsis [mailto:Emmanouil.Batsis@eurodyn.com]
> It didn't work at first but then i remembered my machine at work runs
> windows; It works fine after changing the from attribute to
> (.+)\\(.+).xml. I think i saw something regarding the path seperator and
> how to make it transparent to the task so i'll look for that now. Many
> thanks for giving me a head start!

Yes, you've run into the ugly bit in mappers, namely the fact that the
file separator changes on different platforms, compounded by the fact
that the Windows separator is a special character in regexp.

Just using ${file.separator} is not enough, because it yields just
\ and not the escaped form. (maybe using \${file.separator} would
be cross-platform).

I think I remember a fix was introduced to 'normalize' filenames to
forward slashes prior to mapping them. I don't recall the new attribute
name though (if it indeed exists). --DD


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


Re: Help with (regexp?) file mapper

Posted by Emmanouil Batsis <Em...@eurodyn.com>.
Jeffrey E Care wrote:

>In the future you tell us what you have already tried: it would be helpful 
>in debugging the problem. Asking the question in the manner that you have 
>might make one think that you haven't tried this at all & are just looking 
>for someone to figure it out for you. 
>  
>

My intention was to be sincere, not rude. I really am clueless when it 
comes to regexp and have little time to actually get into regular 
expression tutorials right now.

>In any case, this is untested, but it should be close; you may have to 
>play around with the greediness qualifiers.
>  
>

>From: (.+)/(.+).xml
>To:   \1/web/\2Form.java
>  
>

It didn't work at first but then i remembered my machine at work runs 
windows; It works fine after changing the from attribute to 
(.+)\\(.+).xml. I think i saw something regarding the path seperator and 
how to make it transparent to the task so i'll look for that now. Many 
thanks for giving me a head start!

Manos


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


Re: Help with (regexp?) file mapper

Posted by Jeffrey E Care <ca...@us.ibm.com>.
In the future you tell us what you have already tried: it would be helpful 
in debugging the problem. Asking the question in the manner that you have 
might make one think that you haven't tried this at all & are just looking 
for someone to figure it out for you. 

In any case, this is untested, but it should be close; you may have to 
play around with the greediness qualifiers.

From: (.+)/(.+).xml
To:   \1/web/\2Form.java

-- 
Jeffrey E. Care (carej@us.ibm.com)
WebSphere Build SWAT Team Lead
WebSphere Build Tooling Lead (Project Mantis)
https://w3.opensource.ibm.com/projects/mantis


Emmanouil Batsis <Em...@eurodyn.com> wrote on 06/27/2005 
08:17:17 AM:

> 
> Hi all,
> 
> I'm trying to both change the file name (add 'Form' suffix and change 
> from .xml to .java) and directory structure (add one more directory) for 

> example from
> 
> my/package/Foo.xml
> 
> to
> 
> my/package/web/FooForm.java
> 
> Looks like this is a piece of cake using the regexp file mapper but i 
> really suck in regular expressions, anyone have a similar example handy?
> 
> Thanks,
> 
> Manos
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>