Return-Path: Delivered-To: apmail-ant-notifications-archive@locus.apache.org Received: (qmail 59828 invoked from network); 6 Nov 2008 10:34:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Nov 2008 10:34:43 -0000 Received: (qmail 78949 invoked by uid 500); 6 Nov 2008 10:34:50 -0000 Delivered-To: apmail-ant-notifications-archive@ant.apache.org Received: (qmail 78928 invoked by uid 500); 6 Nov 2008 10:34:50 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 78919 invoked by uid 99); 6 Nov 2008 10:34:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Nov 2008 02:34:50 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Nov 2008 10:33:40 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0FA9C2388875; Thu, 6 Nov 2008 02:34:23 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r711835 - in /ant/core/trunk/src/main/org/apache/tools/ant: types/resources/Union.java util/FileUtils.java Date: Thu, 06 Nov 2008 10:34:17 -0000 To: notifications@ant.apache.org From: bodewig@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081106103423.0FA9C2388875@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bodewig Date: Thu Nov 6 02:34:11 2008 New Revision: 711835 URL: http://svn.apache.org/viewvc?rev=711835&view=rev Log: Take advantage of Java 1.4 Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java?rev=711835&r1=711834&r2=711835&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java Thu Nov 6 02:34:11 2008 @@ -17,13 +17,11 @@ */ package org.apache.tools.ant.types.resources; -import java.util.List; -import java.util.Iterator; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; -import java.util.Set; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.List; import org.apache.tools.ant.types.Resource; import org.apache.tools.ant.types.ResourceCollection; @@ -101,23 +99,17 @@ if (rc.isEmpty()) { return Collections.EMPTY_LIST; } - //preserve order-encountered using a list; enforce set logic manually: - // (LinkedHashSet better, but JDK 1.4+) - ArrayList union = new ArrayList(rc.size() * 2); - // Use a set as list.contains() can be expensive for lots of resources - Set set = new HashSet(rc.size() * 2); + LinkedHashSet set = new LinkedHashSet(rc.size() * 2); for (Iterator rcIter = rc.iterator(); rcIter.hasNext();) { for (Iterator r = nextRC(rcIter).iterator(); r.hasNext();) { Object o = r.next(); if (asString) { o = o.toString(); } - if (set.add(o)) { - union.add(o); - } + set.add(o); } } - return union; + return set; } private static ResourceCollection nextRC(Iterator i) { Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java?rev=711835&r1=711834&r2=711835&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java Thu Nov 6 02:34:11 2008 @@ -28,6 +28,7 @@ import java.io.Writer; import java.net.MalformedURLException; import java.net.URL; +import java.nio.channels.Channel; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; @@ -1116,46 +1117,7 @@ * @since Ant 1.6 */ public String toURI(String path) { - // #8031: first try Java 1.4. - Class uriClazz = null; - try { - uriClazz = Class.forName("java.net.URI"); - } catch (ClassNotFoundException e) { - // OK, Java 1.3. - } - if (uriClazz != null) { - try { - File f = new File(path).getAbsoluteFile(); - java.lang.reflect.Method toURIMethod = File.class.getMethod("toURI", new Class[0]); - Object uriObj = toURIMethod.invoke(f, new Object[] {}); - java.lang.reflect.Method toASCIIStringMethod - = uriClazz.getMethod("toASCIIString", new Class[0]); - return (String) toASCIIStringMethod.invoke(uriObj, new Object[] {}); - } catch (Exception e) { - // Reflection problems? Should not happen, debug. - e.printStackTrace(); - } - } - boolean isDir = new File(path).isDirectory(); - - StringBuffer sb = new StringBuffer("file:"); - - path = resolveFile(null, path).getPath(); - sb.append("//"); - // add an extra slash for filesystems with drive-specifiers - if (!path.startsWith(File.separator)) { - sb.append("/"); - } - path = path.replace('\\', '/'); - try { - sb.append(Locator.encodeURI(path)); - } catch (UnsupportedEncodingException exc) { - throw new BuildException(exc); - } - if (isDir && !path.endsWith("/")) { - sb.append('/'); - } - return sb.toString(); + return new File(path).getAbsoluteFile().toURI().toASCIIString(); } /** @@ -1429,6 +1391,23 @@ } /** + * Close a Channel without throwing any exception if something went wrong. + * Do not attempt to close it if the argument is null. + * + * @param device channel, can be null. + * @since Ant 1.8.0 + */ + public static void close(Channel device) { + if (null != device) { + try { + device.close(); + } catch (IOException e) { + //ignore + } + } + } + + /** * Delete the file with {@link File#delete()} if the argument is not null. * Do nothing on a null argument. * @param file file to delete.