Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Commit

Permalink
Merge pull request apache#1669 from apache/add-extensions-to-classpat…
Browse files Browse the repository at this point in the history
…h-155484283

GEODE-4923: Add extensions to classpath 155484283
  • Loading branch information
jchen21 authored Mar 27, 2018
2 parents 6bccecf + f79c8d9 commit 679b095
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 5 deletions.
2 changes: 1 addition & 1 deletion geode-assembly/src/main/dist/bin/gfsh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ GEODE_JARS=$GEODE_HOME/lib/gfsh-dependencies.jar
if [ "x$CLASSPATH" != "x" ]; then
GEODE_JARS=$GEODE_JARS:$CLASSPATH
fi
CLASSPATH=$GEODE_JARS
CLASSPATH=$GEODE_JARS:$GEODE_HOME/extensions/*

#
# Copy default .gfshrc to the home directory. Uncomment if needed.
Expand Down
4 changes: 2 additions & 2 deletions geode-assembly/src/main/dist/bin/gfsh.bat
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ set GEODE_HOME=%gf%
set GFSH_JARS=%GEODE_HOME%\lib\gfsh-dependencies.jar
REM if a system level classpath is set, append it to the classes gfsh will need
if defined CLASSPATH (
set DEPENDENCIES=%GFSH_JARS%;%CLASSPATH%
set DEPENDENCIES=%GFSH_JARS%;%CLASSPATH%;%GEODE_HOME%\extensions\*
) else (
set DEPENDENCIES=%GFSH_JARS%
set DEPENDENCIES=%GFSH_JARS%;%GEODE_HOME%\extensions\*
)

if not defined GF_JAVA (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
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;

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;

Expand Down Expand Up @@ -470,7 +472,30 @@ String[] createStartLocatorCommandLine(final LocatorLauncher launcher,
}

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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class StartMemberUtils {
static final int CMS_INITIAL_OCCUPANCY_FRACTION = 60;
private static final ThreePhraseGenerator nameGenerator = new ThreePhraseGenerator();

static final String EXTENSIONS_PATHNAME = IOUtils.appendToPath(GEODE_HOME, "extensions");
static final String CORE_DEPENDENCIES_JAR_PATHNAME =
IOUtils.appendToPath(GEODE_HOME, "lib", "geode-dependencies.jar");
static final String GEODE_JAR_PATHNAME =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

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;

Expand Down Expand Up @@ -529,11 +531,31 @@ String getServerClasspath(final boolean includeSystemClasspath, final String use
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,
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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -105,6 +104,22 @@ public void testGeodeOnClasspathIsFirst() {
assertThat(gemfireClasspath).startsWith(customGeodeCore);
}

@Test
public void testExtensionsJars() throws IOException {

// when there is no `extensions` directory
String gemfireClasspath = StartMemberUtils.toClasspath(true, new String[0]);
assertThat(gemfireClasspath).doesNotContain("extensions");

// when there is a `test.jar` in `extensions` directory
File folder = temporaryFolder.newFolder("extensions");
File jarFile = new File(folder, "test.jar");
jarFile.createNewFile();
gemfireClasspath = StartMemberUtils.toClasspath(true, new String[] {jarFile.getAbsolutePath()});
assertThat(gemfireClasspath).contains(jarFile.getName());

}

@Test
public void testAddMaxHeap() {
List<String> baseCommandLine = new ArrayList<>();
Expand Down

0 comments on commit 679b095

Please sign in to comment.