diff options
| author | Bob W. Hogg | 2016-12-04 18:43:46 -0800 |
|---|---|---|
| committer | Bob W. Hogg | 2017-02-15 21:35:26 -0800 |
| commit | 5a214de68d52eef0bbf99f740dc22c721dd02233 (patch) | |
| tree | 6f52771110b75e6c4dbb1bf61cc65b8bf6dfc032 /Library/Homebrew/extend/os/mac/requirements/java_requirement.rb | |
| parent | 5a2a0638028ee49991e404c1bd6397c10659474b (diff) | |
| download | brew-5a214de68d52eef0bbf99f740dc22c721dd02233.tar.bz2 | |
java_requirement: port to Linux and refactor
Split the core requirement class into generic, Linux-specific,
and macOS-specific parts.
Additionally, the Linux version is now able to detect Java versions
(the previous Linuxbrew implementation was only able to detect
if Java was present at all.)
Diffstat (limited to 'Library/Homebrew/extend/os/mac/requirements/java_requirement.rb')
| -rw-r--r-- | Library/Homebrew/extend/os/mac/requirements/java_requirement.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Library/Homebrew/extend/os/mac/requirements/java_requirement.rb b/Library/Homebrew/extend/os/mac/requirements/java_requirement.rb new file mode 100644 index 000000000..9c60aff95 --- /dev/null +++ b/Library/Homebrew/extend/os/mac/requirements/java_requirement.rb @@ -0,0 +1,40 @@ +class JavaRequirement + cask "java" + + env do + env_java_common + java_home = Pathname.new(@java_home) + if (java_home/"include").exist? # Oracle JVM + env_oracle_jdk + else # Apple JVM + env_apple + end + end + + private + + def possible_javas + javas = [] + javas << Pathname.new(ENV["JAVA_HOME"])/"bin/java" if ENV["JAVA_HOME"] + javas << java_home_cmd + javas << which("java") + javas + end + + def java_home_cmd + return nil unless File.executable?("/usr/libexec/java_home") + args = %w[--failfast] + args << "--version" << @version.to_s if @version + java_home = Utils.popen_read("/usr/libexec/java_home", *args).chomp + return nil unless $?.success? + Pathname.new(java_home)/"bin/java" + end + + def env_apple + ENV.append_to_cflags "-I/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers/" + end + + def oracle_java_os + :darwin + end +end |
