Module: Language::Java
- Defined in:
- language/java.rb,
extend/os/mac/language/java.rb
Overview
Helper functions for Java formulae.
Class Method Summary collapse
-
.java_home(version = nil) ⇒ Pathname?
Returns the directory of the newest matching OpenJDK installation or
nil
if none is available. -
.java_home_env(version = nil) ⇒ Hash
Returns a
JAVA_HOME
environment variable to use a specific OpenJDK. -
.overridable_java_home_env(version = nil) ⇒ Hash
Returns a
JAVA_HOME
environment variable to use a default OpenJDK.
Class Method Details
.java_home(version = nil) ⇒ Pathname?
Returns the directory of the newest matching OpenJDK installation or
nil
if none is available. When used in a Formula, there should be
a dependency and corresponding version
for reproducible output.
6 7 8 9 10 11 |
# File 'extend/os/mac/language/java.rb', line 6 def self.java_home(version = nil) openjdk = find_openjdk_formula(version) return unless openjdk openjdk.opt_libexec/"openjdk.jdk/Contents/Home" end |
.java_home_env(version = nil) ⇒ Hash
Returns a JAVA_HOME
environment variable to use a specific OpenJDK.
Usually combined with either Pathname#write_env_script or
Pathname#env_script_all_files.
Example
Use openjdk@21
for all commands:
bin.env_script_all_files libexec/"bin", Language::Java.java_home_env("21")
63 64 65 |
# File 'language/java.rb', line 63 def self.java_home_env(version = nil) { JAVA_HOME: java_home_shell(version) } end |
.overridable_java_home_env(version = nil) ⇒ Hash
Returns a JAVA_HOME
environment variable to use a default OpenJDK.
Unlike java_home_env the OpenJDK can be overridden at runtime.
Example
Use latest openjdk
as default:
bin.env_script_all_files libexec/"bin", Language::Java.overridable_java_home_env
80 81 82 |
# File 'language/java.rb', line 80 def self.overridable_java_home_env(version = nil) { JAVA_HOME: "${JAVA_HOME:-#{java_home_shell(version)}}" } end |