Elffuss BraidHub

kikocis/java-driver public

Add support for overriding PATH and JAVA_HOME used by ccm.

At times it is necessary to use a separate java install for CCM then
what is being used for running tests.  For example, if you want to run
tests with JDK 6 but against Cassandra 2.0, which requires JDK 7.

Added 2 new system properties 'ccm.path' which if provided will prepend
the value to PATH and 'ccm.java.home' which will set JAVA_HOME to the
value provided.
Changeset224ae57a24ac8b5ac26d3732f6d4938ad9b41bfa384e4928aff346506d3e8d30
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-04-03 14:47 -05:00
CommitterAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-04-07 08:13 -05:00
Parentsf3391d2c849a

Browse the files at this changeset

1 file changed

modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +32 −1
@@ -28,6 +28,7 @@
2828
2929 import com.google.common.base.Joiner;
3030 import com.google.common.collect.ImmutableMap;
31+import com.google.common.collect.Maps;
3132 import com.google.common.io.ByteStreams;
3233 import com.google.common.io.Closer;
3334 import com.google.common.io.Files;
@@ -72,6 +73,36 @@
7273
7374 private static final File DEFAULT_SERVER_KEYSTORE_FILE = createTempStore(DEFAULT_SERVER_KEYSTORE_PATH);
7475
76+ /**
77+ * The environment variables to use when invoking CCM. Inherits the current processes environment, but will also
78+ * prepend to the PATH variable the value of the 'ccm.path' property and set JAVA_HOME variable to the
79+ * 'ccm.java.home' variable.
80+ *
81+ * At times it is necessary to use a separate java install for CCM then what is being used for running tests.
82+ * For example, if you want to run tests with JDK 6 but against Cassandra 2.0, which requires JDK 7.
83+ */
84+ private static final Map<String,String> ENVIRONMENT_MAP;
85+
86+ static {
87+ // Inherit the current environment.
88+ Map<String,String> envMap = Maps.newHashMap(new ProcessBuilder().environment());
89+ // If ccm.path is set, override the PATH variable with it.
90+ String ccmPath = System.getProperty("ccm.path");
91+ if(ccmPath != null) {
92+ String existingPath = envMap.get("PATH");
93+ if(existingPath == null) {
94+ existingPath = "";
95+ }
96+ envMap.put("PATH", ccmPath + ":" + existingPath);
97+ }
98+ // If ccm.java.home is set, override the JAVA_HOME variable with it.
99+ String ccmJavaHome = System.getProperty("ccm.java.home");
100+ if(ccmJavaHome != null) {
101+ envMap.put("JAVA_HOME", ccmJavaHome);
102+ }
103+ ENVIRONMENT_MAP = ImmutableMap.copyOf(envMap);
104+ }
105+
75106 static final File CASSANDRA_DIR;
76107 static final String CASSANDRA_VERSION;
77108
@@ -290,7 +321,7 @@
290321 ExecuteStreamHandler streamHandler = new PumpStreamHandler(outStream, errStream);
291322 executor.setStreamHandler(streamHandler);
292323
293- int retValue = executor.execute(cli);
324+ int retValue = executor.execute(cli, ENVIRONMENT_MAP);
294325 if (retValue != 0) {
295326 logger.error("Non-zero exit code ({}) returned from executing ccm command: {}", retValue, fullCommand);
296327 throw new RuntimeException();