Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Commit cf08e71

Browse files
authored
Make Java optional in CLI and check JAVA_BIN (#3521)
1 parent c7a5ab4 commit cf08e71

File tree

4 files changed

+13
-23
lines changed

4 files changed

+13
-23
lines changed

heron/tools/admin/src/python/main.py

-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ def check_environment():
121121
Check whether the environment variables are set
122122
:return:
123123
'''
124-
if not config.check_java_home_set():
125-
sys.exit(1)
126124

127125
if not config.check_release_file_exists():
128126
sys.exit(1)

heron/tools/cli/src/python/execute.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,15 @@ def heron_class(class_name, lib_jars, extra_jars=None, args=None, java_defines=N
5959
# the class locally.
6060
java_opts = ['-D' + opt for opt in java_defines]
6161

62+
java_path = config.get_java_path()
63+
if java_path is None:
64+
err_context = "Neither JAVA_BIN or JAVA_HOME are set"
65+
return SimpleResult(Status.InvocationError, err_context)
66+
6267
# Construct the command line for the sub process to run
6368
# Because of the way Python execute works,
6469
# the java opts must be passed as part of the list
65-
all_args = [config.get_java_path(), "-client", "-Xmx1g"] + \
70+
all_args = [java_path, "-client", "-Xmx1g"] + \
6671
java_opts + \
6772
["-cp", config.get_classpath(extra_jars + lib_jars)]
6873

heron/tools/cli/src/python/main.py

-3
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ def check_environment():
149149
Check whether the environment variables are set
150150
:return:
151151
'''
152-
if not config.check_java_home_set():
153-
sys.exit(1)
154-
155152
if not config.check_release_file_exists():
156153
sys.exit(1)
157154

heron/tools/common/src/python/utils/config.py

+7-17
Original file line numberDiff line numberDiff line change
@@ -424,24 +424,14 @@ def parse_override_config(namespace):
424424

425425
def get_java_path():
426426
"""Get the path of java executable"""
427+
java_bin = os.environ.get("JAVA_BIN")
428+
if java_bin:
429+
return java_bin
427430
java_home = os.environ.get("JAVA_HOME")
428-
return os.path.join(java_home, BIN_DIR, "java")
429-
430-
431-
def check_java_home_set():
432-
"""Check if the java home set"""
433-
# check if environ variable is set
434-
if "JAVA_HOME" not in os.environ:
435-
Log.error("JAVA_HOME not set")
436-
return False
437-
438-
# check if the value set is correct
439-
java_path = get_java_path()
440-
if os.path.isfile(java_path) and os.access(java_path, os.X_OK):
441-
return True
442-
443-
Log.error("JAVA_HOME/bin/java either does not exist or not an executable")
444-
return False
431+
if java_home:
432+
return os.path.join(java_home, BIN_DIR, "java")
433+
# this could use shutil.which("java") when python2 support is dropped
434+
return None
445435

446436

447437
def check_release_file_exists():

0 commit comments

Comments
 (0)