Merge pull request #3352 from JCount/legacy-java-cask-requirement-support

java_requirement: support prompting users to install legacy Java casks
This commit is contained in:
JCount 2017-10-26 11:26:00 -04:00 committed by GitHub
commit badbb00b08

View File

@ -1,13 +1,30 @@
class JavaRequirement < Requirement
cask "java"
env do
env_java_common
env_oracle_jdk || env_apple
end
# A strict Java 8 requirement (1.8) should prompt the user to install
# the legacy java8 cask because the current version, Java 9, is not
# completely backwards compatible, and contains breaking changes such as
# strong encapsulation of JDK-internal APIs and a modified version scheme
# (9.0 not 1.9).
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
private
JAVA_CASK_MAP = {
"1.8" => "caskroom/versions/java8",
"9.0" => "java",
}.freeze
def possible_javas
javas = []
javas << Pathname.new(ENV["JAVA_HOME"])/"bin/java" if ENV["JAVA_HOME"]