DependencyCollector: Add java_dep_if_needed [Linux]

Use the openjdk formula if it's installed.
Use the host's Java if it's sufficient.
Otherwise install the openjdk formula.
This commit is contained in:
Shaun Jackman 2018-11-11 10:15:48 -08:00
parent a8aed381ca
commit d2dba5fc4a
4 changed files with 24 additions and 3 deletions

View File

@ -79,6 +79,10 @@ class DependencyCollector
Dependency.new("bzip2", tags) unless which("bzip2") Dependency.new("bzip2", tags) unless which("bzip2")
end end
def java_dep_if_needed(tags)
JavaRequirement.new(tags)
end
def ld64_dep_if_needed(*); end def ld64_dep_if_needed(*); end
def self.tar_needs_xz_dependency? def self.tar_needs_xz_dependency?
@ -118,7 +122,7 @@ class DependencyCollector
case spec case spec
when :arch then ArchRequirement.new(tags) when :arch then ArchRequirement.new(tags)
when :codesign then CodesignRequirement.new(tags) when :codesign then CodesignRequirement.new(tags)
when :java then JavaRequirement.new(tags) when :java then java_dep_if_needed(tags)
when :linux then LinuxRequirement.new(tags) when :linux then LinuxRequirement.new(tags)
when :macos then MacOSRequirement.new(tags) when :macos then MacOSRequirement.new(tags)
when :maximum_macos then MaximumMacOSRequirement.new(tags) when :maximum_macos then MaximumMacOSRequirement.new(tags)

View File

@ -1 +1,5 @@
require "extend/os/mac/dependency_collector" if OS.mac? if OS.mac?
require "extend/os/mac/dependency_collector"
elsif OS.linux?
require "extend/os/linux/dependency_collector"
end

View File

@ -0,0 +1,13 @@
class DependencyCollector
def java_dep_if_needed(tags)
req = JavaRequirement.new(tags)
begin
dep = Dependency.new("openjdk", tags)
return dep if dep.installed?
return req if req.satisfied?
dep
rescue FormulaUnavailableError
req
end
end
end

View File

@ -86,7 +86,7 @@ class JavaRequirement < Requirement
javas = [] javas = []
javas << Pathname.new(ENV["JAVA_HOME"])/"bin/java" if ENV["JAVA_HOME"] javas << Pathname.new(ENV["JAVA_HOME"])/"bin/java" if ENV["JAVA_HOME"]
jdk = begin jdk = begin
Formula["jdk"] Formula["openjdk"]
rescue FormulaUnavailableError rescue FormulaUnavailableError
nil nil
end end