2015-02-26 22:36:04 +08:00
|
|
|
require "language/java"
|
|
|
|
|
2015-06-15 09:56:04 +01:00
|
|
|
class JavaRequirement < Requirement
|
2015-02-26 22:36:04 +08:00
|
|
|
fatal true
|
2017-03-11 11:35:19 +01:00
|
|
|
download "https://www.oracle.com/technetwork/java/javase/downloads/index.html"
|
2015-02-26 22:36:04 +08:00
|
|
|
|
2018-04-18 09:55:44 +01:00
|
|
|
# A strict Java 8 requirement (1.8) should prompt the user to install
|
|
|
|
# the legacy java8 cask because versions newer than Java 8 are not
|
|
|
|
# completely backwards compatible, and contain breaking changes such as
|
|
|
|
# strong encapsulation of JDK-internal APIs and a modified version scheme
|
|
|
|
# (*.0 not 1.*).
|
|
|
|
def cask
|
|
|
|
if @version.nil? || @version.to_s.end_with?("+") ||
|
|
|
|
@version.to_f >= JAVA_CASK_MAP.keys.max.to_f
|
|
|
|
JAVA_CASK_MAP.fetch(JAVA_CASK_MAP.keys.max)
|
|
|
|
else
|
|
|
|
JAVA_CASK_MAP.fetch("1.8")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-17 15:32:44 +01:00
|
|
|
satisfy build_env: false do
|
2016-12-04 18:43:46 -08:00
|
|
|
setup_java
|
|
|
|
next false unless @java
|
|
|
|
next true
|
2015-02-26 22:36:04 +08:00
|
|
|
end
|
|
|
|
|
2017-12-30 18:58:30 +00:00
|
|
|
def initialize(tags = [])
|
2017-10-18 02:25:34 +01:00
|
|
|
@version = tags.shift if /(\d+\.)+\d/ =~ tags.first
|
2015-02-26 22:36:04 +08:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def message
|
|
|
|
version_string = " #{@version}" if @version
|
|
|
|
|
2017-04-02 14:38:43 -07:00
|
|
|
s = "Java#{version_string} is required to install this formula.\n"
|
2015-02-26 22:36:04 +08:00
|
|
|
s += super
|
|
|
|
s
|
|
|
|
end
|
|
|
|
|
|
|
|
def inspect
|
|
|
|
"#<#{self.class.name}: #{name.inspect} #{tags.inspect} version=#{@version.inspect}>"
|
|
|
|
end
|
2016-09-18 00:37:02 -04:00
|
|
|
|
|
|
|
def display_s
|
|
|
|
if @version
|
2016-12-04 18:43:46 -08:00
|
|
|
if exact_version?
|
2016-09-18 00:37:02 -04:00
|
|
|
op = "="
|
2016-12-04 18:43:46 -08:00
|
|
|
else
|
|
|
|
op = ">="
|
2016-09-18 00:37:02 -04:00
|
|
|
end
|
2016-12-04 18:43:46 -08:00
|
|
|
"#{name} #{op} #{version_without_plus}"
|
2016-09-18 00:37:02 -04:00
|
|
|
else
|
|
|
|
name
|
|
|
|
end
|
|
|
|
end
|
2016-12-04 18:43:46 -08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-04-18 09:55:44 +01:00
|
|
|
JAVA_CASK_MAP = {
|
2018-05-25 18:03:16 +02:00
|
|
|
"1.8" => "homebrew/cask-versions/java8",
|
2018-04-18 09:55:44 +01:00
|
|
|
"10.0" => "java",
|
|
|
|
}.freeze
|
|
|
|
|
2016-12-04 18:43:46 -08:00
|
|
|
def version_without_plus
|
|
|
|
if exact_version?
|
|
|
|
@version
|
|
|
|
else
|
2017-06-01 16:06:51 +02:00
|
|
|
@version[0, @version.length - 1]
|
2016-12-04 18:43:46 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def exact_version?
|
|
|
|
@version && @version.to_s.chars.last != "+"
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup_java
|
|
|
|
java = preferred_java
|
|
|
|
return unless java
|
|
|
|
@java = java
|
|
|
|
@java_home = java.parent.parent
|
|
|
|
end
|
|
|
|
|
|
|
|
def possible_javas
|
|
|
|
javas = []
|
|
|
|
javas << Pathname.new(ENV["JAVA_HOME"])/"bin/java" if ENV["JAVA_HOME"]
|
|
|
|
jdk = begin
|
|
|
|
Formula["jdk"]
|
|
|
|
rescue FormulaUnavailableError
|
|
|
|
nil
|
|
|
|
end
|
2017-09-24 19:24:46 +01:00
|
|
|
javas << jdk.bin/"java" if jdk&.installed?
|
2016-12-04 18:43:46 -08:00
|
|
|
javas << which("java")
|
|
|
|
javas
|
|
|
|
end
|
|
|
|
|
|
|
|
def preferred_java
|
|
|
|
possible_javas.detect do |java|
|
2017-09-24 19:24:46 +01:00
|
|
|
next false unless java&.executable?
|
2016-12-04 18:43:46 -08:00
|
|
|
next true unless @version
|
|
|
|
next true if satisfies_version(java)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def env_java_common
|
2017-02-15 21:47:08 -08:00
|
|
|
return unless @java_home
|
2016-12-04 18:43:46 -08:00
|
|
|
java_home = Pathname.new(@java_home)
|
|
|
|
ENV["JAVA_HOME"] = java_home
|
|
|
|
ENV.prepend_path "PATH", java_home/"bin"
|
|
|
|
end
|
|
|
|
|
|
|
|
def env_oracle_jdk
|
2017-02-15 21:47:08 -08:00
|
|
|
return unless @java_home
|
2016-12-04 18:43:46 -08:00
|
|
|
java_home = Pathname.new(@java_home)
|
2017-02-15 21:47:08 -08:00
|
|
|
return unless (java_home/"include").exist?
|
2016-12-04 18:43:46 -08:00
|
|
|
ENV.append_to_cflags "-I#{java_home}/include"
|
|
|
|
ENV.append_to_cflags "-I#{java_home}/include/#{oracle_java_os}"
|
2017-02-15 21:47:08 -08:00
|
|
|
true
|
2016-12-04 18:43:46 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def oracle_java_os
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def satisfies_version(java)
|
2017-12-14 15:07:01 +00:00
|
|
|
java_version_s = Utils.popen_read(java, "-version", err: :out)[/\d+.\d/]
|
2016-12-04 18:43:46 -08:00
|
|
|
return false unless java_version_s
|
|
|
|
java_version = Version.create(java_version_s)
|
|
|
|
needed_version = Version.create(version_without_plus)
|
|
|
|
if exact_version?
|
|
|
|
java_version == needed_version
|
|
|
|
else
|
|
|
|
java_version >= needed_version
|
|
|
|
end
|
|
|
|
end
|
2015-02-26 22:36:04 +08:00
|
|
|
end
|
2016-12-04 18:43:46 -08:00
|
|
|
|
|
|
|
require "extend/os/requirements/java_requirement"
|