felixcheung commented on a change in pull request #3372: [ZEPPELIN-3623] Create 
interpreter process in the cluster mode
URL: https://github.com/apache/zeppelin/pull/3372#discussion_r287620990
 
 

 ##########
 File path: 
zeppelin-interpreter/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java
 ##########
 @@ -144,6 +162,73 @@ public static synchronized ZeppelinConfiguration create() 
{
     return conf;
   }
 
+  private static String getClassPath(Class cls) {
+    // Check if the parameters passed in by the user are empty
+    if (cls == null) {
+      throw new java.lang.IllegalArgumentException("The parameter cannot be 
empty!");
+    }
+
+    ClassLoader loader = cls.getClassLoader();
+    // Get the full name of the class, including the package name
+    String clsName = cls.getName() + ".class";
+    // Get the package where the incoming parameters are located
+    Package pack = cls.getPackage();
+    String path = "";
+    // If not an anonymous package, convert the package name to a path
+    if (pack != null) {
+      String packName = pack.getName();
+      // Here is a simple decision to determine whether it is a Java base 
class library,
+      // preventing users from passing in the JDK built-in class library.
+      if (packName.startsWith("java.") || packName.startsWith("javax.")) {
+        throw new java.lang.IllegalArgumentException("Do not transfer system 
classes!");
+      }
+
+      // In the name of the class, remove the part of the package name
+      // and get the file name of the class.
+      clsName = clsName.substring(packName.length() + 1);
+      // Determine whether the package name is a simple package name, and if 
so,
+      // directly convert the package name to a path.
+      if (packName.indexOf(".") < 0) {
+        path = packName + "/";
+      } else {
+        // Otherwise, the package name is converted to a path according
+        // to the component part of the package name.
+        int start = 0, end = 0;
+        end = packName.indexOf(".");
+        while (end != -1) {
+          path = path + packName.substring(start, end) + "/";
+          start = end + 1;
+          end = packName.indexOf(".", start);
+        }
+        path = path + packName.substring(start) + "/";
+      }
+    }
+    // Call the classReloader's getResource method, passing in the
+    // class file name containing the path information.
+    java.net.URL url = loader.getResource(path + clsName);
+    // Get path information from the URL object
+    String realPath = url.getPath();
+    // Remove the protocol name "file:" in the path information.
+    int pos = realPath.indexOf("file:");
+    if (pos > -1) {
+      realPath = realPath.substring(pos + 5);
+    }
+    // Remove the path information and the part that contains the class file 
information,
+    // and get the path where the class is located.
+    pos = realPath.indexOf(path + clsName);
+    realPath = realPath.substring(0, pos - 1);
+    // If the class file is packaged into a JAR file, etc.,
+    // remove the corresponding JAR and other package file names.
+    if (realPath.endsWith("!")) {
+      realPath = realPath.substring(0, realPath.lastIndexOf("/"));
+    }
+    try {
+      realPath = java.net.URLDecoder.decode(realPath, "utf-8");
+    } catch (Exception e) {
+      throw new RuntimeException(e);
 
 Review comment:
   why wrap this exception?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to