<commit_before># inspiration from https://github.com/caskroom/homebrew-cask/blob/master/Casks/java.rb

cmd = Mixlib::ShellOut.new("pkgutil --pkgs='com.oracle.jdk#{node['java_se']['jdk_version']}'")
cmd.run_command
unless cmd.exitstatus == 0
  version = node['java_se']['version']

  name = "JDK #{version.split('.')[1]} Update #{version.sub(/^.*?_(\d+)$/, '\1')}"
  execute "hdiutil attach '#{node['java_se']['file_cache_path']}' -quiet"

  avoid_daemon = Gem::Version.new(node['platform_version']) >= Gem::Version.new('10.8')
  execute "sudo installer -pkg '/Volumes/#{name}/#{name}.pkg' -target /" do
    # Prevent cfprefsd from holding up hdiutil detach for certain disk images
    environment('__CFPREFERENCES_AVOID_DAEMON' => '1') if avoid_daemon
  end

  execute "hdiutil detach '/Volumes/#{name}' || hdiutil detach '/Volumes/#{name}' -force"

  #
  # make minor modifications to the JRE to prevent issues with packaged applications,
  # as discussed here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=411361
  #

  %w(BundledApp JNI WebStart Applets).each do |str|<commit_msg>Wrap shellout in ruby_block<commit_after># inspiration from https://github.com/caskroom/homebrew-cask/blob/master/Casks/java.rb

ruby_block 'update-alternatives' do # ~FC014
  block do
    cmd = Mixlib::ShellOut.new("pkgutil --pkgs='com.oracle.jdk#{node['java_se']['jdk_version']}'")
    cmd.run_command
    package_installed = cmd.exitstatus == 0
  end
end

unless package_installed
  version = node['java_se']['version']

  name = "JDK #{version.split('.')[1]} Update #{version.sub(/^.*?_(\d+)$/, '\1')}"
  execute "hdiutil attach '#{node['java_se']['file_cache_path']}' -quiet"

  avoid_daemon = Gem::Version.new(node['platform_version']) >= Gem::Version.new('10.8')
  execute "sudo installer -pkg '/Volumes/#{name}/#{name}.pkg' -target /" do
    # Prevent cfprefsd from holding up hdiutil detach for certain disk images
    environment('__CFPREFERENCES_AVOID_DAEMON' => '1') if avoid_daemon
  end

  execute "hdiutil detach '/Volumes/#{name}' || hdiutil detach '/Volumes/#{name}' -force"

  #
  # make minor modifications to the JRE to prevent issues with packaged applications,
  # as discussed here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=411361
  #

  %w(BundledApp JNI WebStart Applets).each do |str|
{'fraction_non_alphanumeric': 0.17050891692040018, 'fraction_numerical': 0.012614180078294911, 'mean_word_length': 4.808080808080808, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2330269', 'n_tokens_mistral': 835, 'n_tokens_neox': 779, 'n_words': 172}