incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject [2/2] git commit: Fix loading of external script so they will be loaded from the webapp classloader.
Date Fri, 05 Oct 2012 14:45:42 GMT
Fix loading of external script so they will be loaded from the webapp classloader.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/5c46e955
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/5c46e955
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/5c46e955

Branch: refs/heads/maven-to-rpm
Commit: 5c46e9552de9e48ce02ceeda684acd6b4bb28012
Parents: df1b066
Author: Hugo Trippaers <htrippaers@schubergphilis.com>
Authored: Fri Oct 5 16:35:40 2012 +0200
Committer: Hugo Trippaers <htrippaers@schubergphilis.com>
Committed: Fri Oct 5 16:35:40 2012 +0200

----------------------------------------------------------------------
 utils/src/com/cloud/utils/script/Script.java |   27 ++++++++++++++------
 1 files changed, 19 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5c46e955/utils/src/com/cloud/utils/script/Script.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/script/Script.java b/utils/src/com/cloud/utils/script/Script.java
index feed764..a0f9e8e 100755
--- a/utils/src/com/cloud/utils/script/Script.java
+++ b/utils/src/com/cloud/utils/script/Script.java
@@ -23,6 +23,8 @@ import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
@@ -344,14 +346,23 @@ public class Script implements Callable<String> {
             return file.getAbsolutePath();
         }
 
-/*        url = Script.class.getClassLoader().getResource(path);
- *        s_logger.debug("Classpath resource: " + url);
- *        if (url != null) {
- *            file = new File(url.getFile());
- *            s_logger.debug("Absolute path =  " + file.getAbsolutePath());
- *            return file.getAbsolutePath();
- *        }
- */        
+        /**
+         * Look in WEB-INF/classes of the webapp
+         * URI workaround the URL encoding of url.getFile
+         */
+        url = Script.class.getClassLoader().getResource(path + script);
+        s_logger.debug("Classpath resource: " + url);
+        if (url != null) {
+       	    try {
+                file = new File(new URI(url.toString()).getPath());
+                s_logger.debug("Absolute path =  " + file.getAbsolutePath());
+                return file.getAbsolutePath();
+            }
+            catch (URISyntaxException e) {
+                s_logger.warn("Unable to convert " + url.toString() + " to a URI");
+            }
+        }       
+
         if (path.endsWith(File.separator)) {
             path = path.substring(0, path.lastIndexOf(File.separator));
         }


Mime
View raw message