brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [10/21] git commit: Add comments explaining the reason for the code changes.
Date Thu, 26 Jun 2014 11:42:16 GMT
Add comments explaining the reason for the code changes.


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/0232e220
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/0232e220
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/0232e220

Branch: refs/heads/master
Commit: 0232e2201b779dd1191a474a980e8df284a2ac79
Parents: f67d7c4
Author: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Authored: Mon Jun 23 12:29:25 2014 +0300
Committer: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Committed: Wed Jun 25 18:28:54 2014 +0300

----------------------------------------------------------------------
 core/src/main/java/brooklyn/util/ResourceUtils.java | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0232e220/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 412b781..347e0a2 100644
--- a/core/src/main/java/brooklyn/util/ResourceUtils.java
+++ b/core/src/main/java/brooklyn/util/ResourceUtils.java
@@ -378,21 +378,31 @@ public class ResourceUtils {
         Class<?> cc = contextObject instanceof Class ? (Class<?>)contextObject
: contextObject.getClass();
         return getClassLoaderDir(cc.getCanonicalName().replace('.', '/')+".class");
     }
+    
     public String getClassLoaderDir(String resourceInThatDir) {
         resourceInThatDir = Strings.removeFromStart(resourceInThatDir, "/");
         URL url = getLoader().getResource(resourceInThatDir);
         if (url==null) throw new NoSuchElementException("Resource ("+resourceInThatDir+")
not found");
 
+        //Switching from manual parsing of jar: and file: URLs to java provided functionality.
+        //The old code was breaking on any Windows path and instead of fixing it, using
+        //the provided Java APIs seemed like the better option since they are already tested
+        //on multiple platforms.
         boolean isJar = "jar".equals(url.getProtocol());
         if(isJar) {
             try {
-                //let java handle the parsing of jar url, no network connection is established.
+                //let java handle the parsing of jar URL, no network connection is established.
+                //Strips the jar protocol:
+                //  jar:file:/<path to jar>!<resourceInThatDir>
+                //  becomes
+                //  file:/<path to jar>
                 JarURLConnection connection = (JarURLConnection) url.openConnection();
                 url = connection.getJarFileURL();
             } catch (IOException e) {
                 throw new IllegalStateException(e);
             }
         } else {
+            //Remove the trailing resouceInThatDir path from the URL, thus getting the parent
folder.
             String path = url.toString();
             int i = path.indexOf(resourceInThatDir);
             if (i==-1) throw new IllegalStateException("Resource path ("+resourceInThatDir+")
not in url substring ("+url+")");
@@ -406,6 +416,7 @@ public class ResourceUtils {
         
         if (!"file".equals(url.getProtocol())) throw new IllegalStateException("Resource
("+resourceInThatDir+") not on file system (at "+url+")");
 
+        //convert from file: URL to File
         File file;
         try {
             file = new File(url.toURI());


Mime
View raw message