java_requirement: support prompting users to install legacy Java casks

This enhances the Java requirement to support prompting the user
to install the correct legacy Java version via Cask for formulae
that don't yet work with the latest version of Java. Previously,
even if the formula had a strict requirement that a specific,
older version of Java be used, the messaging would tell the user to
`brew cask install java` (i.e. to install the latest version of Java),
which wouldn't actually satisfy the requirement.
This commit is contained in:
JCount 2017-10-21 22:28:16 -04:00
parent feb3e35e3c
commit 224864b149

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"]