discover different java versions from common paths
@@ -104,7 +104,7 @@ class UltimateTool(benchexec.tools.template.BaseTool):
cmds = [
# 2
[
- "java",
+ self.get_java(),
"-Xss4m",
"-jar",
launcher_jar,
@@ -115,7 +115,7 @@ class UltimateTool(benchexec.tools.template.BaseTool):
"--version",
],
# 1
- ["java", "-Xss4m", "-jar", launcher_jar, "-data", data_dir, "--version"],
+ [self.get_java(), "-Xss4m", "-jar", launcher_jar, "-data", data_dir, "--version"],
]
self.api = len(cmds)
@@ -245,7 +245,7 @@ class UltimateTool(benchexec.tools.template.BaseTool):
if "-tc" in options or "--toolchain" in options:
# ignore executable (old executable is just around for backwards compatibility)
mem_bytes = rlimits.get(MEMLIMIT, None)
- cmdline = ["java"]
+ cmdline = [self.get_java()]
# -ea has to be given directly to java
if "-ea" in options:
@@ -448,3 +448,45 @@ class UltimateTool(benchexec.tools.template.BaseTool):
start_position = line.find("=") + 1
return line[start_position:].strip()
return None
+
+ @functools.lru_cache(maxsize=1)
+ def get_java(self):
+ candidates = [
+ 'java',
+ '/usr/bin/java',
+ '/opt/oracle-jdk-bin-1.8.0.202/bin/java',
+ '/usr/lib/jvm/java-8-openjdk-amd64/bin/java'
+ ]
+ for c in candidates:
+ candidate = self.which(c)
+ if not candidate:
+ continue
+ try:
+ process = subprocess.Popen(
+ [candidate,'-version'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
+ )
+ (stdout, stderr) = process.communicate()
+ except OSError as e:
+ continue
+
+ stdout = util.decode_to_string(stdout).strip()
+ if not stdout:
+ continue
+ if "1.8" in stdout:
+ return candidate
+ raise BenchExecException("Could not find a suitable Java version: Need Java 1.8")
+
+ def which(self, program):
+ def is_exe(fpath):
+ return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
+
+ fpath, fname = os.path.split(program)
+ if fpath:
+ if is_exe(program):
+ return program
+ else:
+ for path in os.environ["PATH"].split(os.pathsep):
+ exe_file = os.path.join(path, program)
+ if is_exe(exe_file):
+ return exe_file
+ return None
