8000 Fix Java shared library path for darwin by viren-nadkarni · Pull Request #11792 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

Fix Java shared library path for darwin #11792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions localstack-core/localstack/packages/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def get_java_home(self) -> str | None:
"""
return java_package.get_installer().get_java_home()

def get_java_lib_path(self) -> str | None:
"""
Returns the path to the Java shared library.
"""
if java_home := self.get_java_home():
if is_mac_os():
return os.path.join(java_home, "Contents", "Home", "lib", "jli", "libjli.dylib")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: any particular reason why we use pathlib (e.g., Path and get_*_path) and os.path interchangeably ?
(/-separated pathlib.Path look a little more readable to me than ,-separated os.path)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the old code uses os.path, including the packaging library. I think it's nice to maintain the consistency but I don't see any issues with migrating everything to pathlib together.

return os.path.join(java_home, "lib", "server", "libjvm.so")

def get_java_env_vars(self, path: str = None, ld_library_path: str = None) -> dict[str, str]:
"""
Returns environment variables pointing to the Java installation. This is useful to build the environment where
Expand Down Expand Up @@ -74,6 +83,8 @@ def __init__(self, version: str):
super().__init__("java", version, extract_single_directory=True)

def _get_install_marker_path(self, install_dir: str) -> str:
if is_mac_os():
return os.path.join(install_dir, "Contents", "Home", "bin", "java")
return os.path.join(install_dir, "bin", "java")

def _get_download_url(self) -> str:
Expand Down
13 changes: 5 additions & 8 deletions localstack-core/localstack/services/events/event_ruler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,23 @@ def start_jvm() -> None:

if not jpype.isJVMStarted():
jvm_lib, event_ruler_libs_path = get_jpype_lib_paths()
event_ruler_libs_pattern = event_ruler_libs_path.joinpath("*")
event_ruler_libs_pattern = Path(event_ruler_libs_path).joinpath("*")

jpype.startJVM(str(jvm_lib), classpath=[event_ruler_libs_pattern])
jpype.startJVM(jvm_lib, classpath=[event_ruler_libs_pattern])


@cache
def get_jpype_lib_paths() -> Tuple[Path, Path]:
def get_jpype_lib_paths() -> Tuple[str, str]:
"""
Downloads Event Ruler, its dependencies and returns a tuple of:
- Path to libjvm.so to be used by JPype as jvmpath. JPype requires this to start the JVM.
- Path to libjvm.so/libjli.dylib to be used by JPype as jvmpath. JPype requires this to start the JVM.
See https://jpype.readthedocs.io/en/latest/userguide.html#path-to-the-jvm
- Path to Event Ruler libraries to be used by JPype as classpath
"""
installer = event_ruler_package.get_installer()
installer.install()

java_home = installer.get_java_home()
jvm_lib = Path(java_home) / "lib" / "server" / "libjvm.so"

return jvm_lib, Path(installer.get_installed_dir())
return installer.get_java_lib_path(), installer.get_installed_dir()


def matches_rule(event: str, rule: str) -> bool:
Expand Down
Loading
0