|
| 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 | +} |
0 commit comments