You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2016/02/01 18:48:34 UTC
[04/50] brooklyn-server git commit: treat c:/path as a file path,
not a url (url requires two letters in the protocol spec)
treat c:/path as a file path, not a url (url requires two letters in the protocol spec)
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/568af2f0
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/568af2f0
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/568af2f0
Branch: refs/heads/0.4.0
Commit: 568af2f07c83984b22ad342757ae5b19e96ce815
Parents: 9d829c0
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Wed Sep 26 00:38:16 2012 -0400
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Wed Sep 26 00:48:23 2012 -0400
----------------------------------------------------------------------
core/src/main/java/brooklyn/util/ResourceUtils.java | 12 ++++++++++--
core/src/test/java/brooklyn/util/ResourceUtilsTest.java | 4 +++-
2 files changed, 13 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/568af2f0/core/src/main/java/brooklyn/util/ResourceUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/ResourceUtils.java b/core/src/main/java/brooklyn/util/ResourceUtils.java
index e23937b..857e176 100644
--- a/core/src/main/java/brooklyn/util/ResourceUtils.java
+++ b/core/src/main/java/brooklyn/util/ResourceUtils.java
@@ -75,8 +75,16 @@ public class ResourceUtils {
throw new IOException("Error accessing "+orig+": "+e, e);
}
}
- if (url.matches("[A-Za-z]+:.*")) {
- //looks like a URL
+ if (url.matches("[A-Za-z][A-Za-z]+:.*")) {
+ //looks like a URL - require two letters so we don't think e.g. c:/path/ is a url
+ if (url.matches("file://[A-Za-z]:[/\\\\].*")) {
+ // file://c:/path/to/x is sometimes mistakenly supplied
+ // where file:///c:/path/to/x is the correct syntax.
+ // treat the former as the latter since the former doesn't have any other interpretation
+ if (log.isDebugEnabled())
+ log.debug("silently changing "+url+" to file:/// prefix");
+ url = "file:///"+url.substring(7);
+ }
return new URL(url).openStream();
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/568af2f0/core/src/test/java/brooklyn/util/ResourceUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/util/ResourceUtilsTest.java b/core/src/test/java/brooklyn/util/ResourceUtilsTest.java
index d452f17..dd14820 100644
--- a/core/src/test/java/brooklyn/util/ResourceUtilsTest.java
+++ b/core/src/test/java/brooklyn/util/ResourceUtilsTest.java
@@ -39,9 +39,11 @@ public class ResourceUtilsTest {
InputStream stream = utils.getResourceFromUrl("/brooklyn/config/sample.properties");
assertNotNull(stream);
}
-
+
@Test
public void testGetResourceViaFileWithPrefix() throws Exception {
+ // on windows the correct syntax is file:///c:/path (note the extra /);
+ // however our routines also accept file://c:/path so the following is portable
InputStream stream = utils.getResourceFromUrl("file://"+tempFile.getAbsolutePath());
assertEquals(ResourceUtils.readFullyString(stream), tempFileContents);
}