accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mwa...@apache.org
Subject [accumulo] branch master updated: Simplify how classpath is built for MiniAccumuloCluster (#945)
Date Sat, 09 Feb 2019 16:02:06 GMT
This is an automated email from the ASF dual-hosted git repository.

mwalch pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/master by this push:
     new 90d3b31  Simplify how classpath is built for MiniAccumuloCluster (#945)
90d3b31 is described below

commit 90d3b31bfde26df89608193bf6d54797c5dd6a5e
Author: Mike Walch <mwalch@apache.org>
AuthorDate: Sat Feb 9 11:02:01 2019 -0500

    Simplify how classpath is built for MiniAccumuloCluster (#945)
---
 minicluster/pom.xml                                |   4 -
 .../miniclusterImpl/MiniAccumuloClusterImpl.java   | 102 ++++-----------------
 2 files changed, 16 insertions(+), 90 deletions(-)

diff --git a/minicluster/pom.xml b/minicluster/pom.xml
index bf73807..a75010c 100644
--- a/minicluster/pom.xml
+++ b/minicluster/pom.xml
@@ -88,10 +88,6 @@
       <artifactId>accumulo-tserver</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-vfs2</artifactId>
-    </dependency>
-    <dependency>
       <groupId>org.apache.hadoop</groupId>
       <artifactId>hadoop-client-api</artifactId>
     </dependency>
diff --git a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java
b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java
index e7bda12..339eeda 100644
--- a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java
+++ b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java
@@ -28,9 +28,6 @@ import java.io.UncheckedIOException;
 import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLClassLoader;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.util.ArrayList;
@@ -90,8 +87,6 @@ import org.apache.accumulo.server.zookeeper.ZooReaderWriterFactory;
 import org.apache.accumulo.start.Main;
 import org.apache.accumulo.start.classloader.vfs.MiniDFSUtil;
 import org.apache.commons.io.IOUtils;
-import org.apache.commons.vfs2.FileObject;
-import org.apache.commons.vfs2.impl.VFSClassLoader;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.apache.hadoop.fs.FileSystem;
@@ -156,91 +151,26 @@ public class MiniAccumuloClusterImpl implements AccumuloCluster {
     return _exec(clazz, jvmArgs2, args);
   }
 
-  private boolean containsConfigFile(File f) {
-    if (!f.isDirectory()) {
-      return false;
-    } else {
-      File[] files = f.listFiles(pathname -> pathname.getName().endsWith("site.xml")
-          || pathname.getName().equals("accumulo.properties"));
-      return files != null && files.length > 0;
-    }
-  }
-
-  @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN",
-      justification = "mini runs in the same security context as user providing the url")
-  private void append(StringBuilder classpathBuilder, URL url) throws URISyntaxException
{
-    File file = new File(url.toURI());
-    // do not include dirs containing hadoop or accumulo config files
-    if (!containsConfigFile(file))
-      classpathBuilder.append(File.pathSeparator).append(file.getAbsolutePath());
-  }
-
-  private String getClasspath() throws IOException {
-
-    try {
-      ArrayList<ClassLoader> classloaders = new ArrayList<>();
-
-      ClassLoader cl = this.getClass().getClassLoader();
-
-      while (cl != null) {
-        classloaders.add(cl);
-        cl = cl.getParent();
-      }
-
-      Collections.reverse(classloaders);
-
-      StringBuilder classpathBuilder = new StringBuilder();
-      classpathBuilder.append(config.getConfDir().getAbsolutePath());
-
-      if (config.getHadoopConfDir() != null)
-        classpathBuilder.append(File.pathSeparator)
-            .append(config.getHadoopConfDir().getAbsolutePath());
-
-      if (config.getClasspathItems() == null) {
+  private String getClasspath() {
+    StringBuilder classpathBuilder = new StringBuilder();
+    classpathBuilder.append(config.getConfDir().getAbsolutePath());
 
-        // assume 0 is the system classloader and skip it
-        for (int i = 1; i < classloaders.size(); i++) {
-          ClassLoader classLoader = classloaders.get(i);
-
-          if (classLoader instanceof URLClassLoader) {
-
-            for (URL u : ((URLClassLoader) classLoader).getURLs()) {
-              append(classpathBuilder, u);
-            }
-
-          } else if (classLoader instanceof VFSClassLoader) {
+    if (config.getHadoopConfDir() != null)
+      classpathBuilder.append(File.pathSeparator)
+          .append(config.getHadoopConfDir().getAbsolutePath());
 
-            VFSClassLoader vcl = (VFSClassLoader) classLoader;
-            for (FileObject f : vcl.getFileObjects()) {
-              append(classpathBuilder, f.getURL());
-            }
-          } else {
-            if (classLoader.getClass().getName()
-                .equals("jdk.internal.loader.ClassLoaders$AppClassLoader")) {
-              log.debug("Detected Java 11 classloader: {}", classLoader.getClass().getName());
-            } else {
-              log.debug("Detected unknown classloader: {}", classLoader.getClass().getName());
-            }
-            String javaClassPath = System.getProperty("java.class.path");
-            if (javaClassPath == null) {
-              throw new IllegalStateException("java.class.path is not set");
-            } else {
-              log.debug("Using classpath set by java.class.path system property: {}",
-                  javaClassPath);
-            }
-            classpathBuilder.append(File.pathSeparator).append(javaClassPath);
-          }
-        }
-      } else {
-        for (String s : config.getClasspathItems())
-          classpathBuilder.append(File.pathSeparator).append(s);
+    if (config.getClasspathItems() == null) {
+      String javaClassPath = System.getProperty("java.class.path");
+      if (javaClassPath == null) {
+        throw new IllegalStateException("java.class.path is not set");
       }
-
-      return classpathBuilder.toString();
-
-    } catch (URISyntaxException e) {
-      throw new IOException(e);
+      classpathBuilder.append(File.pathSeparator).append(javaClassPath);
+    } else {
+      for (String s : config.getClasspathItems())
+        classpathBuilder.append(File.pathSeparator).append(s);
     }
+
+    return classpathBuilder.toString();
   }
 
   public static class ProcessInfo {


Mime
View raw message