cask "zulu11" do
  version "11.2.3,11.0.1"
  sha256 "5e2364ae8e1f4d81b2253de3d52dee5701f8f7c31160fac2d23b4f1c371cff2b"

  url "https://cdn.azul.com/zulu/bin/zulu#{version.csv.first}-jdk#{version.csv.second}-macosx_x64.dmg",
      referer: "https://www.azul.com/downloads/zulu/zulu-mac/"
  name "Azul Zulu Java Standard Edition Development Kit"
  desc "OpenJDK distribution from Azul"
  homepage "https://www.azul.com/downloads/zulu/zulu-mac/"

  pkg "Double-Click to Install Zulu #{version.major}.pkg"

  postflight do
    system_command "/bin/mv",
                   args: ["-f", "--", "/Library/Java/JavaVirtualMachines/zulu-#{version.major}.jdk", "/Library/Java/JavaVirtualMachines/zulu-#{version.before_comma}.jdk"],
                   sudo: true
    system_command "/bin/ln",
                   args: ["-nsf", "--", "/Library/Java/JavaVirtualMachines/zulu-#{version.before_comma}.jdk", "/Library/Java/JavaVirtualMachines/zulu-#{version.major}.jdk"],
                   sudo: true
    system_command "/bin/ln",
                   args: ["-nsf", "--", "/Library/Java/JavaVirtualMachines/zulu-#{version.major}.jdk/Contents/Home", "/Library/Java/Home"],
                   sudo: true
    system_command "/usr/libexec/PlistBuddy",
                   args: ["-c", "Add :JavaVM:JVMCapabilities: string JNI", "/Library/Java/JavaVirtualMachines/zulu-#{version.major}.jdk/Contents/Info.plist"],
                   sudo: true
  end

  uninstall pkgutil: "com.azulsystems.zulu.#{version.major}",
            delete:  [
              "/Library/Java/JavaVirtualMachines/zulu-#{version.before_comma}.jdk",
              "/Library/Java/JavaVirtualMachines/zulu-#{version.major}.jdk",
              "/Library/Java/Home",
            ]
end
