Skip to content

Commit

Permalink
Auto detect JAVA_HOME on Linux (#546)
Browse files Browse the repository at this point in the history
* Auto detect JAVA_HOME for linux

* Fix is_linux and import subprocess

* Revert "Fix is_linux and import subprocess"

This reverts commit 3ff9f89.

* Revert "Auto detect JAVA_HOME for linux"

This reverts commit 1b31fd8.

* Restore original source and update JAVA_PATH on linux

* Add makefile

* Pythonic way to set JAVA_HOME on Linux

* Ignore the Makefile
  • Loading branch information
hahn80 authored Aug 3, 2024
1 parent 35380cf commit c43f3a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion commands/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
import traceback
import sys
import logging
from pathlib import Path

from commands.util import configure_error
from commands.util import is_osx
from commands.util import is_osx, is_linux
from commands.util import shell
from commands.util import CommandFailed
from commands.util import warning
Expand Down Expand Up @@ -48,6 +49,12 @@ def get_java_home():
except CommandFailed:
traceback.print_exc()

if is_linux():
javac_path = shutil.which('javac')
if javac_path is not None:
_java_home = Path(javac_path).resolve().parent.parent.as_posix()
return _java_home

configure_error(
'Please set the environment variable JAVA_HOME to a path containing the JDK.')

Expand Down
4 changes: 4 additions & 0 deletions commands/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def is_bsd():
return 'bsd' in get_platform()


def is_linux():
return "linux" in get_platform()


class CommandFailed(Exception):
"""
The command failed to run for any reason
Expand Down

0 comments on commit c43f3a9

Please sign in to comment.