You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Bailey, Darragh" <db...@hp.com> on 2010/07/23 15:50:56 UTC

Problem with Ant pathconvert and paths with spaces

I've been trying to run my ant builds within eclipse and I've been running into a slight problem with the path generated by the pathconvert task.

After some testing, it seems that it's a problem in general with spaces appear in paths.

The project that I have needs to pick up a library from another project in my tree, until such time that I have everything converted to publish and retrive artifacts from ivy, I've been using whichresource & pathconvert to assist in locating the library from another project in my tree.



Here's a snippet of the ant tasks I'm using:
<whichresource property="extra.lib.url" class="${extralib.classname}">
  <classpath>
    <fileset dir="${extra.lib.dir}" >
      <include name="**/*.jar" />
    </fileset>
  </classpath>
</whichresource>
<fail unless="extra.lib.url" message="Extra library required not found" />
<pathconvert property="extra.lib">
  <path location="${extra.lib.url}" />
  <regexpmapper to="\1" from="file:([^\!]*)" />
</pathconvert>

<echo message="Using extra lib from ${extra.lib}" />
<path id="classpath.extra.lib.id">
  <fileset file="${extra.lib}" />
</path>

I reference classpath.extra.lib.id in the classpath that I construct for the javac task.

When running the Ant build on linux, I normally don't have spaces in the directory names, so everything worked fine until I tried to enable Ant builds within eclipse. My workspace directory resides under "C:\Documents and Settings\<my username>\My Documents\workspace".

So when I build I get the following error:
"C:\Documents and Settings\<my username>\My Documents\workspace\<some project>\build.xml:201: C:\Documents%20and%20Settings\<my username>\My%20Documents\workspace\extralib\build not found."


Some testing on the linux, by moving extralib to extralib\ test and setting the property extra.lib.dir on the command line as following, resulted in a similar error message:
-Dextra.lib.dir=/build/extralib\ test/trunk

"/build/<some project>/trunk/build.xml:209: /build/extralib%20test/trunk/build does not exist."

The echo line in the ant code above prints the following output:
"Using common lib from /build/extralib%20test/trunk/build/extralib-0.1.0.jar"
So I know that the whichresource part is locating the file, and the pathconvert is striping the "jar:file:" from the start and the 
"!${extralib.classname}" text from the end.

The problems seems to be due to the space getting converted to "%20" by whichresource, and I don't seem to be able to match it to change it back.

Besides changing the workspace directory to c:\workspace\ and asking all the other developers that are working on the project to do the same, is there anything I can do to change how I'm using pathconvert to avoid this problem?


Searching the mail archives it seems someone else ran into the same issue back in Feb 2008:
http://mail-archives.apache.org/mod_mbox/ant-user/200802.mbox/%3C003001c86d27$3ef33ee0$0a01a8c0@WORKSTATION%3E

But the only solution suggested was to effectively require the property being set, to be set to the exact path required in the first place and thus not use whichresource at all. Is that the only alternative? (besides writing an extension)


--
Regards,
Darragh Bailey

Systems Software Engineer
Hewlett Packard Galway Ltd.

Postal Address:    Hewlett Packard Galway Limited, Ballybrit Business Park, Galway
Registered Office: Hewlett Packard Galway Limited, 63-74 Sir John Rogerson's Quay Dublin 2
Registered Number: 361933 

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


RE: Problem with Ant pathconvert and paths with spaces

Posted by Jonathan Rosenberg <jr...@tabbysplace.org>.
How about <propertyregex />?

--
Jonathan Rosenberg
Founder & Executive Director, Tabby's Place
http://www.tabbysplace.org/




-----Original Message-----
From: Bailey, Darragh [mailto:dbailey@hp.com] 
Sent: Friday, July 23, 2010 11:01 AM
To: Ant Users List
Subject: RE: Problem with Ant pathconvert and paths with spaces


 

> -----Original Message-----
> From: Jonathan Rosenberg [mailto:jr@tabbysplace.org] 
> Sent: 23 July 2010 15:43
> To: 'Ant Users List'
> Subject: RE: Problem with Ant pathconvert and paths with spaces
> 
> What happens if you run the build outside of Eclipse?

I did, guess I wasn't particularly clear. When I was making the following
comments, I should have stated that I was doing this by running ant via the
command line on a linux box.

> Some testing on the linux, by moving extralib to extralib\ 
> test and setting
> the property extra.lib.dir on the command line as following, 
> resulted in a
> similar error message:
> -Dextra.lib.dir=/build/extralib\ test/trunk
> 
> "/build/<some project>/trunk/build.xml:209:
> /build/extralib%20test/trunk/build does not exist."

Renaming the folder from "extralib test" to "extralib" allows the build to
work correctly once again.

So it's not a problem with eclipse, but rather that I was running eclipse on
Windows and my workspace folder in under a directory path that contains
multiple spaces. On the linux system that I generally write the ant scripts,
I use a heirarchy that doesn't have spaces in any directory name.


I've also done some additional testing and have found that the following
will eliminate the problem for a single space.

      <chainedmapper>
        <regexpmapper to="\1" from="file:([^\!]*)" />
        <regexpmapper from="(.*)%20(.*)" to="\1 \2" />
      </chainedmapper>

That's not particularly scalable as I can't just duplicate the second
regexpmapper to handle subsequent matches, as it results in an empty
property when I do. 
So I'm currently looking at the following options:
1) whether there is a regex substitution in ant that can replace all
occurances of a string
2) whether to modify my libraries to be locatable by jarlib-resolve and
extension
3) Use scriptmapper


--
Regards,
Darragh Bailey

Systems Software Engineer
Hewlett Packard Galway Ltd.

Postal Address:    Hewlett Packard Galway Limited, Ballybrit Business Park,
Galway
Registered Office: Hewlett Packard Galway Limited, 63-74 Sir John Rogerson's
Quay Dublin 2
Registered Number: 361933 



---------------------------------------------------------------------
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


RE: Problem with Ant pathconvert and paths with spaces [Solved]

Posted by "Bailey, Darragh" <db...@hp.com>.
> -----Original Message-----
> From: David Weintraub [mailto:qazwart@gmail.com] 
> Sent: 23 July 2010 16:43
> To: Ant Users List
> Subject: Re: Problem with Ant pathconvert and paths with spaces
> 
> On Fri, Jul 23, 2010 at 11:00 AM, Bailey, Darragh 
> <db...@hp.com> wrote:
> > I've also done some additional testing and have found that 
> the following will eliminate the problem for a single space.
> >
> >      <chainedmapper>
> >        <regexpmapper to="\1" from="file:([^\!]*)" />
> >        <regexpmapper from="(.*)%20(.*)" to="\1 \2" />
> >      </chainedmapper>
> 
> Take a look at this:
> http://ant.apache.org/manual/Types/mapper.html#filter-mapper
> 
> This might work:
> 
> <filtermapper>
>   <replacestring from="%20" to=" "/>
> </filtermapper>

Perfect, thanks that did the trick. 

Final result:
    <whichresource property="extra.lib.url" class="${extra.lib.classname}">
      <classpath>
        <fileset dir="${extra.lib.dir}" >
          <include name="**/*.jar" />
        </fileset>
      </classpath>
    </whichresource>
    <fail unless="extra.lib.url" message="extralib classes not found" />
    <pathconvert property="extra.lib">
      <path location="${extra.lib.url}" />
      <chainedmapper>
        <regexpmapper to="\1" from="file:([^\!]*)" />
        <!-- convert the url encoded spaces back to spaces -->
        <filtermapper>
          <replacestring from="%20" to=" " />
        </filtermapper>
      </chainedmapper>
    </pathconvert>

    <echo message="Using extra classes from ${extra.lib}" />
    <path id="classpath.extra.lib.id">
      <fileset file="${extra.lib}" />
    </path>

--
Regards,
Darragh Bailey

Systems Software Engineer
Hewlett Packard Galway Ltd.

Postal Address:    Hewlett Packard Galway Limited, Ballybrit Business Park, Galway
Registered Office: Hewlett Packard Galway Limited, 63-74 Sir John Rogerson's Quay Dublin 2
Registered Number: 361933 


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


Re: Problem with Ant pathconvert and paths with spaces

Posted by David Weintraub <qa...@gmail.com>.
On Fri, Jul 23, 2010 at 11:00 AM, Bailey, Darragh <db...@hp.com> wrote:
> I've also done some additional testing and have found that the following will eliminate the problem for a single space.
>
>      <chainedmapper>
>        <regexpmapper to="\1" from="file:([^\!]*)" />
>        <regexpmapper from="(.*)%20(.*)" to="\1 \2" />
>      </chainedmapper>

Take a look at this:
http://ant.apache.org/manual/Types/mapper.html#filter-mapper

This might work:

<filtermapper>
  <replacestring from="%20" to=" "/>
</filtermapper>

-- 
David Weintraub
qazwart@gmail.com

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


RE: Problem with Ant pathconvert and paths with spaces

Posted by "Bailey, Darragh" <db...@hp.com>.
 

> -----Original Message-----
> From: Jonathan Rosenberg [mailto:jr@tabbysplace.org] 
> Sent: 23 July 2010 15:43
> To: 'Ant Users List'
> Subject: RE: Problem with Ant pathconvert and paths with spaces
> 
> What happens if you run the build outside of Eclipse?

I did, guess I wasn't particularly clear. When I was making the following comments, I should have stated that I was doing this by running ant via the command line on a linux box.

> Some testing on the linux, by moving extralib to extralib\ 
> test and setting
> the property extra.lib.dir on the command line as following, 
> resulted in a
> similar error message:
> -Dextra.lib.dir=/build/extralib\ test/trunk
> 
> "/build/<some project>/trunk/build.xml:209:
> /build/extralib%20test/trunk/build does not exist."

Renaming the folder from "extralib test" to "extralib" allows the build to work correctly once again.

So it's not a problem with eclipse, but rather that I was running eclipse on Windows and my workspace folder in under a directory path that contains multiple spaces. On the linux system that I generally write the ant scripts, I use a heirarchy that doesn't have spaces in any directory name.


I've also done some additional testing and have found that the following will eliminate the problem for a single space.

      <chainedmapper>
        <regexpmapper to="\1" from="file:([^\!]*)" />
        <regexpmapper from="(.*)%20(.*)" to="\1 \2" />
      </chainedmapper>

That's not particularly scalable as I can't just duplicate the second regexpmapper to handle subsequent matches, as it results in an empty property when I do. 
So I'm currently looking at the following options:
1) whether there is a regex substitution in ant that can replace all occurances of a string
2) whether to modify my libraries to be locatable by jarlib-resolve and extension
3) Use scriptmapper


--
Regards,
Darragh Bailey

Systems Software Engineer
Hewlett Packard Galway Ltd.

Postal Address:    Hewlett Packard Galway Limited, Ballybrit Business Park, Galway
Registered Office: Hewlett Packard Galway Limited, 63-74 Sir John Rogerson's Quay Dublin 2
Registered Number: 361933 



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


RE: Problem with Ant pathconvert and paths with spaces

Posted by Jonathan Rosenberg <jr...@tabbysplace.org>.
What happens if you run the build outside of Eclipse?

--
Jonathan Rosenberg
Founder & Executive Director, Tabby's Place
http://www.tabbysplace.org/



-----Original Message-----
From: Bailey, Darragh [mailto:dbailey@hp.com] 
Sent: Friday, July 23, 2010 9:51 AM
To: Ant Users List
Subject: Problem with Ant pathconvert and paths with spaces


I've been trying to run my ant builds within eclipse and I've been running
into a slight problem with the path generated by the pathconvert task.

After some testing, it seems that it's a problem in general with spaces
appear in paths.

The project that I have needs to pick up a library from another project in
my tree, until such time that I have everything converted to publish and
retrive artifacts from ivy, I've been using whichresource & pathconvert to
assist in locating the library from another project in my tree.



Here's a snippet of the ant tasks I'm using:
<whichresource property="extra.lib.url" class="${extralib.classname}">
  <classpath>
    <fileset dir="${extra.lib.dir}" >
      <include name="**/*.jar" />
    </fileset>
  </classpath>
</whichresource>
<fail unless="extra.lib.url" message="Extra library required not found" />
<pathconvert property="extra.lib">
  <path location="${extra.lib.url}" />
  <regexpmapper to="\1" from="file:([^\!]*)" />
</pathconvert>

<echo message="Using extra lib from ${extra.lib}" />
<path id="classpath.extra.lib.id">
  <fileset file="${extra.lib}" />
</path>

I reference classpath.extra.lib.id in the classpath that I construct for the
javac task.

When running the Ant build on linux, I normally don't have spaces in the
directory names, so everything worked fine until I tried to enable Ant
builds within eclipse. My workspace directory resides under "C:\Documents
and Settings\<my username>\My Documents\workspace".

So when I build I get the following error:
"C:\Documents and Settings\<my username>\My Documents\workspace\<some
project>\build.xml:201: C:\Documents%20and%20Settings\<my
username>\My%20Documents\workspace\extralib\build not found."


Some testing on the linux, by moving extralib to extralib\ test and setting
the property extra.lib.dir on the command line as following, resulted in a
similar error message:
-Dextra.lib.dir=/build/extralib\ test/trunk

"/build/<some project>/trunk/build.xml:209:
/build/extralib%20test/trunk/build does not exist."

The echo line in the ant code above prints the following output:
"Using common lib from
/build/extralib%20test/trunk/build/extralib-0.1.0.jar"
So I know that the whichresource part is locating the file, and the
pathconvert is striping the "jar:file:" from the start and the 
"!${extralib.classname}" text from the end.

The problems seems to be due to the space getting converted to "%20" by
whichresource, and I don't seem to be able to match it to change it back.

Besides changing the workspace directory to c:\workspace\ and asking all the
other developers that are working on the project to do the same, is there
anything I can do to change how I'm using pathconvert to avoid this problem?


Searching the mail archives it seems someone else ran into the same issue
back in Feb 2008:
http://mail-archives.apache.org/mod_mbox/ant-user/200802.mbox/%3C003001c86d2
7$3ef33ee0$0a01a8c0@WORKSTATION%3E

But the only solution suggested was to effectively require the property
being set, to be set to the exact path required in the first place and thus
not use whichresource at all. Is that the only alternative? (besides writing
an extension)


--
Regards,
Darragh Bailey

Systems Software Engineer
Hewlett Packard Galway Ltd.

Postal Address:    Hewlett Packard Galway Limited, Ballybrit Business Park,
Galway
Registered Office: Hewlett Packard Galway Limited, 63-74 Sir John Rogerson's
Quay Dublin 2
Registered Number: 361933 

---------------------------------------------------------------------
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