ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
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 GMT
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.



Mime
View raw message