cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject git commit: Fix loading of external script so they will be loaded from the webapp classloader.
Date Fri, 26 Oct 2012 13:32:37 GMT
Updated Branches:
  refs/heads/master e59726ad9 -> 6a9c588d3


Fix loading of external script so they will be loaded from the webapp classloader.

This change will allow the Script class to look for resources in the classpath of the webapp.
This makes it possible to distribute the management server as a single prepackaged war. An
added benefit is easier integration with IDE's that have the option to start webapps internally.

Also fixes a bug/feature in the URL handling were some components of the script path were
translated to urlencoding. This  change means that files are more often found in the first
two steps of the findScript method which saves some filesystem calls.


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

Branch: refs/heads/master
Commit: 6a9c588d33e481e3ed6b3b5045e97b1431c02117
Parents: e59726a
Author: Hugo Trippaers <htrippaers@schubergphilis.com>
Authored: Fri Oct 5 16:35:40 2012 +0200
Committer: Hugo Trippaers <htrippaers@schubergphilis.com>
Committed: Fri Oct 26 15:32:00 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/6a9c588d/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