Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 21670 invoked from network); 17 May 2007 16:26:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 17 May 2007 16:26:07 -0000 Received: (qmail 88571 invoked by uid 500); 17 May 2007 16:26:13 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 88542 invoked by uid 500); 17 May 2007 16:26:13 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 88531 invoked by uid 500); 17 May 2007 16:26:12 -0000 Received: (qmail 88528 invoked by uid 99); 17 May 2007 16:26:12 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 May 2007 09:26:12 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 May 2007 09:26:05 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id CF6FF1A9844; Thu, 17 May 2007 09:25:45 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r539002 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/launch/Locator.java src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java Date: Thu, 17 May 2007 16:25:45 -0000 To: ant-cvs@apache.org From: stevel@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070517162545.CF6FF1A9844@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: stevel Date: Thu May 17 09:25:44 2007 New Revision: 539002 URL: http://svn.apache.org/viewvc?view=rev&rev=539002 Log: bug 42275...handle failure of File.toURI() by printing the message (too noisy?) and falling back to our own code. Modified: ant/core/trunk/WHATSNEW ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java ant/core/trunk/src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java Modified: ant/core/trunk/WHATSNEW URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=539002&r1=539001&r2=539002 ============================================================================== --- ant/core/trunk/WHATSNEW (original) +++ ant/core/trunk/WHATSNEW Thu May 17 09:25:44 2007 @@ -19,6 +19,10 @@ * Regression: Locator fails with URI encoding problem when spaces in path Bugzilla report 42222 +* Regression in Locator: running Ant off a network share does not work: + message "URI has authority component" appears + Bugzilla report 42275 + * Improvements in AntClassLoader Speed. Bugzilla report 42259 @@ -76,13 +80,14 @@ * -autoproxy turns Java1.5+ automatic proxy support on. Bugzilla 41904 -* handle null result of system getProperty(). Bugzilla 42334. +* Handle null result of system getProperty(). Bugzilla 42334. * Regression: concat fixlastline="true" should not have applied to nested text, but did in Ant 1.7.0. Bugzilla 42369. * Regression: ant.version was not passed down in . - This worked in Ant1.6.5, but not in 1.7.0. Bugzilla bug 42263 + This worked in Ant1.6.5, but not in 1.7.0. Bugzilla bug 42263 + Other changes: -------------- Modified: ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java?view=diff&rev=539002&r1=539001&r2=539002 ============================================================================== --- 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 Thu May 17 09:25:44 2007 @@ -32,6 +32,16 @@ * The Locator is a utility class which is used to find certain items * in the environment. * + * It is used at boot time in the launcher, and cannot make use of any of Ant's other classes. + * + * This is a surprisingly brittle piece of code, and has had lots of bugs filed against it. + * {@link running ant off a network share can cause Ant to fail} + * {@link use File.toURI().toURL().toExternalForm()} + * {@link Locator implementation not encoding URI strings properly: spaces in paths} + * It also breaks Eclipse 3.3 Betas + * {@link Exception if installation path has spaces} + * + * Be very careful when making changes to this class, as a break will upset a lot of people. * @since Ant 1.6 */ public final class Locator { @@ -151,12 +161,28 @@ * @since Ant 1.6 */ public static String fromURI(String uri) { - // #8031: first try Java 1.4. + // #buzilla8031: first try Java 1.4. + String result = null; + //result = fromUriJava14(uri); + if (result == null) { + result = fromURIJava13(uri); + } + return result; + } + + + /** + * Java1.4+ code to extract the path from the URI. + * @param uri + * @return null if a conversion was not possible + */ + private static String fromUriJava14(String uri) { Class uriClazz = null; try { uriClazz = Class.forName("java.net.URI"); } catch (ClassNotFoundException cnfe) { // Fine, Java 1.3 or earlier, do it by hand. + return null; } // Also check for properly formed URIs. Ant formerly recommended using // nonsense URIs such as "file:./foo.xml" in XML includes. You shouldn't @@ -165,18 +191,22 @@ if (uriClazz != null && uri.startsWith("file:/")) { try { java.lang.reflect.Method createMethod - = uriClazz.getMethod("create", new Class[] {String.class}); - Object uriObj = createMethod.invoke(null, new Object[] {encodeURI(uri)}); + = uriClazz.getMethod("create", new Class[]{String.class}); + Object uriObj = createMethod.invoke(null, new Object[]{encodeURI(uri)}); java.lang.reflect.Constructor fileConst - = File.class.getConstructor(new Class[] {uriClazz}); - File f = (File) fileConst.newInstance(new Object[] {uriObj}); + = File.class.getConstructor(new Class[]{uriClazz}); + File f = (File) fileConst.newInstance(new Object[]{uriObj}); //bug #42227 forgot to decode before returning return decodeUri(f.getAbsolutePath()); } catch (java.lang.reflect.InvocationTargetException e) { Throwable e2 = e.getTargetException(); if (e2 instanceof IllegalArgumentException) { // Bad URI, pass this on. - throw new IllegalArgumentException("Bad URI "+uri+ ":"+e2.getMessage(),e2); + // no, this is downgraded to a warning after various JRE bugs surfaced. Hand off + // to our built in code on a failure + //throw new IllegalArgumentException("Bad URI " + uri + ":" + e2.getMessage(), e2); + e2.printStackTrace(); + } else { // Unexpected target exception? Should not happen. e2.printStackTrace(); @@ -186,13 +216,14 @@ e.printStackTrace(); } } - return fromURIJava13(uri); + return null; } /** * This is only public for testing purposes, so its use is strongly discouraged. * @param uri uri to expand * @return the decoded URI + * @since Ant1.7.1 */ public static String fromURIJava13(String uri) { // Fallback method for Java 1.3 or earlier. Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java?view=diff&rev=539002&r1=539001&r2=539002 ============================================================================== --- ant/core/trunk/src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java (original) +++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java Thu May 17 09:25:44 2007 @@ -20,6 +20,9 @@ import junit.framework.TestCase; +import java.net.URISyntaxException; +import java.io.File; + /** Test the locator in the ant-launch JAR */ public class LocatorTest extends TestCase { @@ -40,19 +43,43 @@ private String resolve(String uri) { String j14= Locator.fromURI(uri); String j13 = Locator.fromURIJava13(uri); - assertEquals(uri,j14,j13); + assertEquals("Different fromURI conversion.\nJava1.4="+j14+"\nJava1.3="+j13+"\n", + j14, j13); return j14; } private void resolveTo(String uri,String expectedResult) { String result = resolve(uri); - assertEquals(uri,expectedResult,result); + assertResolved(uri, expectedResult, result); + } + + private void assertResolved(String uri, String expectedResult, String result) { + assertEquals("Expected "+uri+" to resolve to \n"+expectedResult+"\n but got\n"+result+"\n", + expectedResult,result); + } + + /** + * This asserts that we can round trip the path to a URI and back again + * @param path + */ + private void assertResolves(String path) throws Exception { + String asuri = new File(path).toURI().toASCIIString(); + logURI(path +" => "+asuri); + resolveTo(asuri,path); } private void resolveTo13(String uri, String expectedResult) { String result = Locator.fromURIJava13(uri); - assertEquals(uri, expectedResult, result); + assertResolved(uri, expectedResult, result); } + + private void logURI(String path) throws URISyntaxException{ + + String s = new File(path).toURI().toASCIIString(); + System.out.println(path+" => "+s); + + } + /** * this isnt really a valid URI, except maybe in IE * @throws Exception @@ -61,7 +88,7 @@ resolveTo("file:\\\\PC03\\jclasses\\lib\\ant-1.7.0.jar","\\\\PC03\\jclasses\\lib\\ant-1.7.0.jar"); } - public void testTripleForwardSlashNetworkURI_BugID_42275() throws Exception { + public void testTripleForwardSlashNetworkURI() throws Exception { resolveTo("file:///PC03/jclasses/lib/ant-1.7.0.jar", "///PC03/jclasses/lib/ant-1.7.0.jar"); } @@ -93,7 +120,13 @@ } + public void testInternationalURI() throws Exception { + assertResolves("/L\\u00f6wenbrau/aus/M\\u00fcnchen"); + } + public void testOddLowAsciiURI() throws Exception { + assertResolves("/hash#/ and /percent%"); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org