geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jche...@apache.org
Subject [geode] 01/01: Add extensions jars to locator/server's classpath
Date Thu, 22 Mar 2018 22:43:46 GMT
This is an automated email from the ASF dual-hosted git repository.

jchen21 pushed a commit to branch add-extensions-to-classpath-155484283
in repository https://gitbox.apache.org/repos/asf/geode.git

commit bcafe0e890d907e32ef4c29cd6ef47abc1d5581d
Author: Orhan Kislal <okislal@apache.org>
AuthorDate: Thu Mar 22 15:42:01 2018 -0700

    Add extensions jars to locator/server's classpath
    
    [GEODE-4923]
    
    Signed-off-by: Jianxia Chen <jchen21@apache.org>
---
 .../internal/cli/commands/StartLocatorCommand.java | 27 ++++++++++++++++++++-
 .../internal/cli/commands/StartMemberUtils.java    | 23 +-----------------
 .../internal/cli/commands/StartServerCommand.java  | 24 ++++++++++++++++++-
 .../cli/commands/StartMemberUtilsTest.java         | 28 ++++++++++++++++++++++
 4 files changed, 78 insertions(+), 24 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java
index 4a82736..8d82238 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartLocatorCommand.java
@@ -18,6 +18,7 @@ package org.apache.geode.management.internal.cli.commands;
 import java.io.File;
 import java.net.InetAddress;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Properties;
 import java.util.concurrent.TimeUnit;
@@ -25,6 +26,7 @@ import java.util.concurrent.TimeUnit;
 import javax.management.MalformedObjectNameException;
 import javax.net.ssl.SSLException;
 
+import org.apache.commons.lang.ArrayUtils;
 import org.springframework.shell.core.annotation.CliCommand;
 import org.springframework.shell.core.annotation.CliOption;
 
@@ -470,7 +472,30 @@ public class StartLocatorCommand extends GfshCommand {
   }
 
   String getLocatorClasspath(final boolean includeSystemClasspath, final String userClasspath)
{
+    List<String> jarFilePathnames = new ArrayList<>();
+    jarFilePathnames.add(StartMemberUtils.CORE_DEPENDENCIES_JAR_PATHNAME);
+    // include all extension dependencies on the CLASSPATH...
+    for (String extensionsJarPathname : getExtensionsJars()) {
+      if (org.apache.commons.lang.StringUtils.isNotBlank(extensionsJarPathname)) {
+        jarFilePathnames.add(extensionsJarPathname);
+      }
+    }
+
     return StartMemberUtils.toClasspath(includeSystemClasspath,
-        new String[] {StartMemberUtils.CORE_DEPENDENCIES_JAR_PATHNAME}, userClasspath);
+        jarFilePathnames.toArray(new String[jarFilePathnames.size()]), userClasspath);
+  }
+
+  private String[] getExtensionsJars() {
+    File extensionsDirectory = new File(StartMemberUtils.EXTENSIONS_PATHNAME);
+    File[] extensionsJars = extensionsDirectory.listFiles();
+
+    if (extensionsJars != null) {
+      // assume `extensions` directory does not contain any subdirectories. It only contains
jars.
+      return Arrays.stream(extensionsJars).filter(file -> file.isFile()).map(
+          file -> IOUtils.appendToPath(StartMemberUtils.GEODE_HOME, "extensions", file.getName()))
+          .toArray(String[]::new);
+    } else {
+      return ArrayUtils.EMPTY_STRING_ARRAY;
+    }
   }
 }
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java
index 184c339..f9e459a 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java
@@ -232,7 +232,7 @@ public class StartMemberUtils {
     jarFilePathnames =
         (jarFilePathnames != null ? jarFilePathnames : ArrayUtils.EMPTY_STRING_ARRAY);
 
-    // Now, include all GemFire dependencies on the CLASSPATH...
+    // And finally, include all GemFire dependencies on the CLASSPATH...
     for (String jarFilePathname : jarFilePathnames) {
       if (StringUtils.isNotBlank(jarFilePathname)) {
         classpath.append((classpath.length() == 0) ? StringUtils.EMPTY : File.pathSeparator);
@@ -240,14 +240,6 @@ public class StartMemberUtils {
       }
     }
 
-    // And finally, include all extension dependencies on the CLASS`PATH...
-    for (String extensionsJarPathname : getExtensionsJars()) {
-      if (StringUtils.isNotBlank(extensionsJarPathname)) {
-        classpath.append((classpath.length() == 0) ? StringUtils.EMPTY : File.pathSeparator);
-        classpath.append(extensionsJarPathname);
-      }
-    }
-
     return classpath.toString();
   }
 
@@ -263,17 +255,4 @@ public class StartMemberUtils {
     return gemfireJarPath;
   }
 
-  private static String[] getExtensionsJars() {
-    File extensionsDirectory = new File(EXTENSIONS_PATHNAME);
-    File[] extensionsJars = extensionsDirectory.listFiles();
-
-    if (extensionsJars != null) {
-      // assume `extensions` directory does not contain any subdirectories. It only contains
jars.
-      return Arrays.stream(extensionsJars).filter(file -> file.isFile())
-          .map(file -> IOUtils.appendToPath(GEODE_HOME, "extensions", file.getName()))
-          .toArray(String[]::new);
-    } else {
-      return ArrayUtils.EMPTY_STRING_ARRAY;
-    }
-  }
 }
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java
index e12ca15..10652b3 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartServerCommand.java
@@ -17,12 +17,14 @@ package org.apache.geode.management.internal.cli.commands;
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Properties;
 import java.util.concurrent.TimeUnit;
 
 import javax.management.MalformedObjectNameException;
 
+import org.apache.commons.lang.ArrayUtils;
 import org.springframework.shell.core.annotation.CliCommand;
 import org.springframework.shell.core.annotation.CliOption;
 
@@ -529,11 +531,31 @@ public class StartServerCommand extends GfshCommand {
     List<String> jarFilePathnames = new ArrayList<>();
 
     jarFilePathnames.add(StartMemberUtils.CORE_DEPENDENCIES_JAR_PATHNAME);
+    // include all extension dependencies on the CLASSPATH...
+    for (String extensionsJarPathname : getExtensionsJars()) {
+      if (org.apache.commons.lang.StringUtils.isNotBlank(extensionsJarPathname)) {
+        jarFilePathnames.add(extensionsJarPathname);
+      }
+    }
 
-    return StartMemberUtils.toClasspath(includeSystemClasspath,
+        return StartMemberUtils.toClasspath(includeSystemClasspath,
         jarFilePathnames.toArray(new String[jarFilePathnames.size()]), userClasspath);
   }
 
+  private String[] getExtensionsJars() {
+    File extensionsDirectory = new File(StartMemberUtils.EXTENSIONS_PATHNAME);
+    File[] extensionsJars = extensionsDirectory.listFiles();
+
+    if (extensionsJars != null) {
+      // assume `extensions` directory does not contain any subdirectories. It only contains
jars.
+      return Arrays.stream(extensionsJars).filter(file -> file.isFile()).map(
+          file -> IOUtils.appendToPath(StartMemberUtils.GEODE_HOME, "extensions", file.getName()))
+          .toArray(String[]::new);
+    } else {
+      return ArrayUtils.EMPTY_STRING_ARRAY;
+    }
+  }
+
   private void addJvmOptionsForOutOfMemoryErrors(final List<String> commandLine) {
     if (SystemUtils.isHotSpotVM()) {
       if (SystemUtils.isWindows()) {
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartMemberUtilsTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartMemberUtilsTest.java
index e0b327d..6eaa4ca 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartMemberUtilsTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartMemberUtilsTest.java
@@ -15,6 +15,7 @@
 
 package org.apache.geode.management.internal.cli.commands;
 
+import static org.apache.geode.management.internal.cli.commands.StartMemberUtils.GEODE_HOME;
 import static org.assertj.core.api.Java6Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
@@ -22,6 +23,7 @@ import static org.junit.Assert.assertTrue;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
@@ -37,6 +39,7 @@ import org.junit.experimental.categories.Category;
 import org.junit.rules.TemporaryFolder;
 
 import org.apache.geode.internal.GemFireVersion;
+import org.apache.geode.internal.util.ArrayUtils;
 import org.apache.geode.internal.util.IOUtils;
 import org.apache.geode.test.junit.categories.IntegrationTest;
 
@@ -106,6 +109,31 @@ public class StartMemberUtilsTest {
   }
 
   @Test
+  public void testExtensionsJars() throws IOException {
+
+    // when there is no `extensions` directory
+    String gemfireClasspath = StartMemberUtils.toClasspath(true, new String[0]);
+    assertThat(gemfireClasspath).doesNotContain("extensions");
+
+    if (File.separatorChar == '/') {
+      File extensionsDirectory = new File("/tmp/extensions");
+      try {
+
+        boolean result = extensionsDirectory.mkdir();
+        assertThat(result).isTrue();
+        File jarFile = new File("/tmp/extensions/test.jar");
+        result = jarFile.createNewFile();
+        assertThat(result).isTrue();
+        gemfireClasspath =
+            StartMemberUtils.toClasspath(true, new String[]{jarFile.getAbsolutePath()});
+        assertThat(gemfireClasspath).contains(jarFile.getName());
+      } finally {
+        FileUtils.deleteDirectory(extensionsDirectory);
+      }
+    }
+  }
+
+  @Test
   public void testAddMaxHeap() {
     List<String> baseCommandLine = new ArrayList<>();
 

-- 
To stop receiving notification emails like this one, please contact
jchen21@apache.org.

Mime
View raw message