Skip to content

Commit 2c8821c

Browse files
committed
Use correct java home for causal cluster
1 parent 9ab5692 commit 2c8821c

File tree

3 files changed

+68
-8
lines changed

3 files changed

+68
-8
lines changed

driver/src/test/java/org/neo4j/driver/v1/util/Neo4jRunner.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,7 @@ public void restartNeo4j(Neo4jSettings neo4jSettings) throws IOException
159159
private int runCommand( String... cmd ) throws IOException
160160
{
161161
ProcessBuilder pb = new ProcessBuilder().inheritIO();
162-
Map<String,String> env = System.getenv();
163-
pb.environment().put( "JAVA_HOME",
164-
// This driver is built to work with multiple java versions.
165-
// Neo4j, however, works with a specific version of Java. This allows
166-
// specifying which Java version to use for Neo4j separately from which
167-
// version to use for the driver tests.
168-
env.containsKey( "NEO4J_JAVA" ) ? env.get( "NEO4J_JAVA" ) :
169-
System.getProperties().getProperty( "java.home" ) );
162+
ProcessEnvConfigurator.configure( pb );
170163
if( NEORUN_START_ARGS != null )
171164
{
172165
// overwrite the env var in the sub process if the system property is specified
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2002-2016 "Neo Technology,"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.neo4j.driver.v1.util;
20+
21+
import java.util.Map;
22+
23+
public final class ProcessEnvConfigurator
24+
{
25+
/**
26+
* Name of environment variable used by the Neo4j database.
27+
*/
28+
private static final String JAVA_HOME = "JAVA_HOME";
29+
/**
30+
* Name of environment variable to be used for the Neo4j database, defined by the build system.
31+
*/
32+
private static final String NEO4J_JAVA = "NEO4J_JAVA";
33+
34+
private ProcessEnvConfigurator()
35+
{
36+
}
37+
38+
public static void configure( ProcessBuilder processBuilder )
39+
{
40+
processBuilder.environment().put( JAVA_HOME, determineJavaHome() );
41+
}
42+
43+
/**
44+
* This driver is built to work with multiple java versions. Neo4j, however, works with a specific version of
45+
* Java. This allows specifying which Java version to use for Neo4j separately from which version to use for
46+
* the driver tests.
47+
* <p>
48+
* This method determines which java home to use based on present environment variables.
49+
*
50+
* @return path to the java home.
51+
*/
52+
private static String determineJavaHome()
53+
{
54+
Map<String,String> environment = System.getenv();
55+
56+
String definedJava = environment.get( NEO4J_JAVA );
57+
if ( definedJava != null )
58+
{
59+
return definedJava;
60+
}
61+
62+
return System.getProperties().getProperty( "java.home" );
63+
}
64+
}

driver/src/test/java/org/neo4j/driver/v1/util/cc/ClusterControl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.nio.file.Path;
2626
import java.util.Arrays;
2727

28+
import org.neo4j.driver.v1.util.ProcessEnvConfigurator;
29+
2830
import static java.lang.System.lineSeparator;
2931

3032
final class ClusterControl
@@ -75,6 +77,7 @@ private static String executeCommand( String... command )
7577
try
7678
{
7779
ProcessBuilder processBuilder = new ProcessBuilder().command( command );
80+
ProcessEnvConfigurator.configure( processBuilder );
7881
return executeAndGetStdOut( processBuilder );
7982
}
8083
catch ( IOException e )

0 commit comments

Comments
 (0)