Author: bodewig
Date: Sat Mar 15 07:16:36 2014
New Revision: 1577796
URL: http://svn.apache.org/r1577796
Log:
URLResource#isExists returns true for non-existent http and ftp URLs, based on
patch by Anthony Wat, PR 51110
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java
Modified: ant/core/trunk/WHATSNEW
URL:
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1577796&r1=1577795&r2=1577796&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Sat Mar 15 07:16:36 2014
@@ -94,6 +94,9 @@ Fixed bugs:
implementations that encode big numbers by not adding a trailing
NUL.
+ * the isExists() method of URLResource returned false positives for
+ HTTP and FTP URLs.
+
Other changes:
--------------
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java?rev=1577796&r1=1577795&r2=1577796&view=diff
==============================================================================
---
ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java
(original)
+++
ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java
Sat Mar 15 07:16:36 2014
@@ -22,6 +22,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.MalformedURLException;
@@ -227,6 +228,19 @@ public class URLResource extends Resourc
}
try {
connect(Project.MSG_VERBOSE);
+ if (conn instanceof HttpURLConnection) {
+ int sc = ((HttpURLConnection) conn).getResponseCode();
+ // treating inaccessible resources as non-existent
+ return sc < 400;
+ } else if (url.getProtocol().startsWith("ftp")) {
+ closeConnection = true;
+ InputStream in = null;
+ try {
+ in = conn.getInputStream();
+ } finally {
+ FileUtils.close(in);
+ }
+ }
return true;
} catch (IOException e) {
return false;