You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by pe...@apache.org on 2006/04/19 12:50:07 UTC

svn commit: r395206 - /ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java

Author: peterreilly
Date: Wed Apr 19 03:50:02 2006
New Revision: 395206

URL: http://svn.apache.org/viewcvs?rev=395206&view=rev
Log:
escape none URL characters

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java?rev=395206&r1=395205&r2=395206&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java Wed Apr 19 03:50:02 2006
@@ -401,7 +401,20 @@
             String path = location.getPath();
             for (int i = 0; i < extensions.length; ++i) {
                 if (path.toLowerCase().endsWith(extensions[i])) {
-                    urls[0] = location.toURL();
+                    try {
+                        /**
+                         * File.toURL() does not encode characters like #.
+                         * File.toURI() has been introduced in java 1.4, so
+                         * ANT cannot use it (except by reflection)
+                         * FileUtils.toURI() cannot be used by Locator.java
+                         * Implemented this way.
+                         * File.toURL() adds file: and changes '\' to '/' for dos OSes
+                         * encodeUri converts characters like ' ' and '#' to %DD
+                         */
+                        urls[0] = new URL(encodeUri(location.toURL().toString()));
+                    } catch (UnsupportedEncodingException ex) {
+                        throw new MalformedURLException(ex.toString());
+                    }
                     break;
                 }
             }
@@ -420,7 +433,12 @@
             });
         urls = new URL[matches.length];
         for (int i = 0; i < matches.length; ++i) {
-            urls[i] = matches[i].toURL();
+            try {
+                // See comments above.
+                urls[i] = new URL(encodeUri(matches[i].toURL().toString()));
+            } catch (UnsupportedEncodingException ex) {
+                throw new MalformedURLException(ex.toString());
+            }
         }
         return urls;
     }



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


Re: svn commit: r395206 - /ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java

Posted by Antoine Levy-Lambert <an...@gmx.de>.
Peter Reilly wrote:
> Hi Antoine,
> Thanks for checking.
> I had made a mistake!
> I had forgot to commit the other file that I changed - Launcher.java
> (assuming that it only had changes with printf statements!).
> Can you test now?
>
>   
Hello Peter,

I have tweaked docs.xml to work with a classpath set with the -lib 
option (by removing classpath setup).

This works now. :-)

$ $ANT_HOME/bin/ant -f docs.test.xml -lib 
c:/opt/velocity-1.4/velocity\#dep-1.4.jar -lib 
c:/opt/velocity-1.4/build/li\#b/jdom-b9.jar
Buildfile: docs.test.xml

anakia:

   [anakia] Transforming into: C:\dev\asf\ant-core\docs


fixcrlf:


docs:



BUILD SUCCESSFUL

Total time: 7 seconds

Thanks for developing, ;-)

Antonie

> I have tested by moving ant-contib.jar into ~/# and running
> with ant --execdebug -f x.xml -lib ~/#
> where x.xml was:
> <project name="x" default="p" xmlns:ac="antlib:net.sf.antcontrib">
>   <target name="p">
>     <ac:if>
>       <equals arg1="a" arg2="a"/>
>       <then>
>         <echo>Hello world</echo>
>       </then>
>     </ac:if>
>   </target>
> </project>
>
> Peter
>   



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


Re: svn commit: r395206 - /ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java

Posted by Peter Reilly <pe...@gmail.com>.
Hi Antoine,
Thanks for checking.
I had made a mistake!
I had forgot to commit the other file that I changed - Launcher.java
(assuming that it only had changes with printf statements!).
Can you test now?

I have tested by moving ant-contib.jar into ~/# and running
with ant --execdebug -f x.xml -lib ~/#
where x.xml was:
<project name="x" default="p" xmlns:ac="antlib:net.sf.antcontrib">
  <target name="p">
    <ac:if>
      <equals arg1="a" arg2="a"/>
      <then>
        <echo>Hello world</echo>
      </then>
    </ac:if>
  </target>
</project>

Peter

On 4/19/06, Antoine Levy-Lambert <an...@gmx.de> wrote:
>
>
>
> Antoine Levy-Lambert wrote:
> > results :
> >
> > ant -f docs.xml -lib c:/opt/velocity\#1.4/velocity-dep-1.4.jar -lib
> > c:/opt/velocity\#1.4/build/lib/jdom-b9.jar
> >
> > I wonder whether the lines 146 to 181 in Locator.java which I copied
> > from a bug report of Jesse are good.
> >
> >
> If I remove the lines 146 to 181 in Locator.java,
> (meaning if Locator#fromURI(String uri) is implemented without
> reflection, using ant's own code)
> there is no exception, but the Anakia task is not found. :-(
>
> It sounds like we need to setup special testcases concerning locating
> directories or files containing the # sign.
>
> Peter : were you able to test something like that under UNIX ? Or is it
> impossible ?
>
> I would also try simply running a java program with java -cp something
> someclass with a classpath containing hash signs
> to see whether this works.
>
> Regards,
>
> Antoine
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>

Re: svn commit: r395206 - /ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java

Posted by Antoine Levy-Lambert <an...@gmx.de>.

Antoine Levy-Lambert wrote:
> results :
>
> ant -f docs.xml -lib c:/opt/velocity\#1.4/velocity-dep-1.4.jar -lib
> c:/opt/velocity\#1.4/build/lib/jdom-b9.jar
>
> I wonder whether the lines 146 to 181 in Locator.java which I copied
> from a bug report of Jesse are good.
>
>   
If I remove the lines 146 to 181 in Locator.java,
(meaning if Locator#fromURI(String uri) is implemented without
reflection, using ant's own code)
there is no exception, but the Anakia task is not found. :-(

It sounds like we need to setup special testcases concerning locating
directories or files containing the # sign.

Peter : were you able to test something like that under UNIX ? Or is it
impossible ?

I would also try simply running a java program with java -cp something
someclass with a classpath containing hash signs
to see whether this works.

Regards,

Antoine


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


Re: svn commit: r395206 - /ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java

Posted by Antoine Levy-Lambert <an...@gmx.de>.
Hello Peter,

First of all your code change is very clean and looks like a
simplification. :-)



I have tried on Windows2000 with JDK 1.5

results :

ant -f docs.xml -lib c:/opt/velocity\#1.4/velocity-dep-1.4.jar -lib
c:/opt/velocity\#1.4/build/lib/jdom-b9.jar
java.lang.IllegalArgumentException: URI has a fragment component

    at java.io.File.<init>(File.java:342)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

    at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

    at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

    at java.lang.reflect.Constructor.newInstance(Constructor.java:494)

    at org.apache.tools.ant.launch.Locator.fromURI(Locator.java:162)

    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:267)

    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:99)

I wonder whether the lines 146 to 181 in Locator.java which I copied
from a bug report of Jesse are good.





Antoine


Peter Reilly wrote:
> Hi,
> Can someone on a windows system check that this works there?
>
> i.e. the -lib option to ant
>
> Peter
>
>
> On 4/19/06, peterreilly@apache.org <pe...@apache.org> wrote:
>   
>> Author: peterreilly
>> Date: Wed Apr 19 03:50:02 2006
>> New Revision: 395206
>>
>> URL: http://svn.apache.org/viewcvs?rev=395206&view=rev
>> Log:
>> escape none URL characters
>>
>> Modified:
>>     ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java
>>
>> Modified: ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java
>> URL:
>> http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java?rev=395206&r1=395205&r2=395206&view=diff
>>
>> ==============================================================================
>> --- ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java
>> (original)
>> +++ ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java Wed
>> Apr 19 03:50:02 2006
>> @@ -401,7 +401,20 @@
>>              String path = location.getPath();
>>              for (int i = 0; i < extensions.length; ++i) {
>>                  if (path.toLowerCase().endsWith(extensions[i])) {
>> -                    urls[0] = location.toURL();
>> +                    try {
>> +                        /**
>> +                         * File.toURL() does not encode characters like
>> #.
>> +                         * File.toURI() has been introduced in java 1.4,
>> so
>> +                         * ANT cannot use it (except by reflection)
>> +                         * FileUtils.toURI() cannot be used by
>> Locator.java
>> +                         * Implemented this way.
>> +                         * File.toURL() adds file: and changes '\' to '/'
>> for dos OSes
>> +                         * encodeUri converts characters like ' ' and '#'
>> to %DD
>> +                         */
>> +                        urls[0] = new URL(encodeUri(location.toURL
>> ().toString()));
>> +                    } catch (UnsupportedEncodingException ex) {
>> +                        throw new MalformedURLException(ex.toString());
>> +                    }
>>                      break;
>>                  }
>>              }
>> @@ -420,7 +433,12 @@
>>              });
>>          urls = new URL[matches.length];
>>          for (int i = 0; i < matches.length; ++i) {
>> -            urls[i] = matches[i].toURL();
>> +            try {
>> +                // See comments above.
>> +                urls[i] = new
>> URL(encodeUri(matches[i].toURL().toString()));
>> +            } catch (UnsupportedEncodingException ex) {
>> +                throw new MalformedURLException(ex.toString());
>> +            }
>>          }
>>          return urls;
>>      }
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>> For additional commands, e-mail: dev-help@ant.apache.org
>>
>>
>>     
>
>   


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


Re: svn commit: r395206 - /ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java

Posted by Peter Reilly <pe...@gmail.com>.
Hi,
Can someone on a windows system check that this works there?

i.e. the -lib option to ant

Peter


On 4/19/06, peterreilly@apache.org <pe...@apache.org> wrote:
>
> Author: peterreilly
> Date: Wed Apr 19 03:50:02 2006
> New Revision: 395206
>
> URL: http://svn.apache.org/viewcvs?rev=395206&view=rev
> Log:
> escape none URL characters
>
> Modified:
>     ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java
>
> Modified: ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java
> URL:
> http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java?rev=395206&r1=395205&r2=395206&view=diff
>
> ==============================================================================
> --- ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java
> (original)
> +++ ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java Wed
> Apr 19 03:50:02 2006
> @@ -401,7 +401,20 @@
>              String path = location.getPath();
>              for (int i = 0; i < extensions.length; ++i) {
>                  if (path.toLowerCase().endsWith(extensions[i])) {
> -                    urls[0] = location.toURL();
> +                    try {
> +                        /**
> +                         * File.toURL() does not encode characters like
> #.
> +                         * File.toURI() has been introduced in java 1.4,
> so
> +                         * ANT cannot use it (except by reflection)
> +                         * FileUtils.toURI() cannot be used by
> Locator.java
> +                         * Implemented this way.
> +                         * File.toURL() adds file: and changes '\' to '/'
> for dos OSes
> +                         * encodeUri converts characters like ' ' and '#'
> to %DD
> +                         */
> +                        urls[0] = new URL(encodeUri(location.toURL
> ().toString()));
> +                    } catch (UnsupportedEncodingException ex) {
> +                        throw new MalformedURLException(ex.toString());
> +                    }
>                      break;
>                  }
>              }
> @@ -420,7 +433,12 @@
>              });
>          urls = new URL[matches.length];
>          for (int i = 0; i < matches.length; ++i) {
> -            urls[i] = matches[i].toURL();
> +            try {
> +                // See comments above.
> +                urls[i] = new
> URL(encodeUri(matches[i].toURL().toString()));
> +            } catch (UnsupportedEncodingException ex) {
> +                throw new MalformedURLException(ex.toString());
> +            }
>          }
>          return urls;
>      }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>