#
# Cookbook Name:: workspace
# Recipe:: attributes_overrides
#

java_version = <%= version %>

case java_version
when 7
  java_minor_version = 7
  java_patch_version = 79
  java_osx_checksum = '910ad1aa48cccdce6cac012ab7107e0707b2edbb'
  java_windows_checksum = '8cb35ac640e28535b977057a941d74bfafeab764'
when 8
  java_minor_version = 8
  java_patch_version = 172
  java_osx_checksum = '7266528f188e4a6c11be340f9bc69cdbd7f5afe7'
  java_windows_checksum = '5578168c1516bb0c5a22230044712dc26a708938'
else
  Chef::Application.fatal!("this JDK version is not supported in #{node['platform']}, please contact DevOps to add it.")
end

case node['platform']
when 'redhat', 'centos', 'fedora', 'amazon'
  node.override[:java].deep_merge!({
    install_flavor: 'oracle_rpm',
    java_home: "/usr/java/jdk1.#{java_minor_version}.0_#{java_patch_version}",
    oracle_rpm: {
      type: 'jdk',
      package_version: "1.#{java_minor_version}.0_#{java_patch_version}-fcs",
      package_name: 'jdk.x86_64'
    }
  })
when 'mac_os_x'
  node.override[:java].deep_merge!({
    osx_dmg: {
      app_name:       "JDK #{java_minor_version} Update #{java_patch_version}",
      volumes_dir:    "JDK #{java_minor_version} Update #{java_patch_version}",
      package_id:     "JDK #{java_minor_version} Update #{java_patch_version}.pkg",
      url:            "https://nexus.internal.microstrategy.com:8443/repositories/filerepo/com/oracle/java/jdk/macosx/#{java_minor_version}u#{java_patch_version}/macosx-#{java_minor_version}u#{java_patch_version}-x64.dmg",
      dmg_name:       "jdk-#{java_minor_version}u#{java_patch_version}-macosx-x64",
      checksum:       java_osx_checksum,
      java_home:      "/Library/Java/JavaVirtualMachines/jdk1.#{java_minor_version}.0_#{java_patch_version}.jdk/Contents/Home"
    }
  })
when 'windows'
  node.override[:java].deep_merge!({
    windows: {
      java_home: "C:\\Java\\jdk1.#{java_minor_version}.0_#{java_patch_version}",
      checksum: java_windows_checksum,
      url: "https://nexus.internal.microstrategy.com/service/local/repositories/filerepo/content/com/oracle/java/jdk/windows/#{java_minor_version}u#{java_patch_version}/windows-#{java_minor_version}u#{java_patch_version}-x64.exe"
    }
  })
else
  Chef::Application.fatal!("this OS is not supported: #{node['platform']}")
end
