<commit_before>#
# Author:: <NAME> (<<EMAIL>>)
# Cookbook Name:: java
# Recipe:: oracle_jce
#
# Copyright 2014, <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include_recipe 'java::set_attributes_from_version'

jdk_version = node['java']['jdk_version'].to_s
jce_url = node['java']['oracle']['jce'][jdk_version]['url']
jce_checksum = node['java']['oracle']['jce'][jdk_version]['checksum']
jce_cookie = node['java']['oracle']['accept_oracle_download_terms'] ? 'oraclelicense=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com' : ''

checksum_bin = if jce_checksum =~ /^[0-9a-f]{32}$/
                 'md5sum'
               else
                 'sha256sum'
               end

directory ::File.join(node['java']['oracle']['jce']['home'], jdk_version) do
  mode '0755'
  recursive true
  action :create
end

if node['os'] == 'windows'
  include_recipe 'windows'

  url = node['java']['oracle']['jce'][jdk_version]['url']
  zip_checksum = node['java']['oracle']['jce'][jdk_version]['checksum']
  staging_path = ::File.join(node['java']['oracle']['jce']['home'], jdk_version)
  staging_local_policy = ::File.join(staging_path, "UnlimitedJCEPolicyJDK#{jdk_version}", 'local_policy.jar')
  staging_export_policy = ::File.join(staging_path, "UnlimitedJCEPolicyJDK#{jdk_version}", 'US_export_policy.jar')
  jre_final_path = ::File.join(node['java']['java_home'], 'jre', 'lib', 'security')
  final_local_policy = ::File.join(jre_final_path, 'local_policy.jar')
  final_export_policy = ::File.join(jre_final_path, 'US_export_policy.jar')

  windows_zipfile staging_path do
    source url
    checksum zip_checksum
    action :unzip
    not_if {::File.exists? staging_local_policy}
    notifies :create, "file[#{final_local_policy}]"
    notifies :create, "file[#{final_export_policy}]"
  end

  file final_local_policy do
    rights :full_control, node['java']['windows']['owner']
    content lazy { ::File.read(staging_local_policy) }
    action :nothing
  end

  file final_export_policy do
    rights :full_control, node['java']['windows']['owner']
    content lazy { ::File.read(staging_export_policy) }
    action :nothing
  end


else
  package 'unzip'
  package 'curl'

  execute 'download jce' do
    command <<-EOF
      rm -rf #{Chef::Config[:file_cache_path]}/java_jce
      mkdir -p #{Chef::Config[:file_cache_path]}/java_jce
      cd #{Chef::Config[:file_cache_path]}/java_jce<commit_msg>Rubocop fixes<commit_after>#
# Author:: <NAME> (<<EMAIL>>)
# Cookbook Name:: java
# Recipe:: oracle_jce
#
# Copyright 2014, <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include_recipe 'java::set_attributes_from_version'

jdk_version = node['java']['jdk_version'].to_s
jce_url = node['java']['oracle']['jce'][jdk_version]['url']
jce_checksum = node['java']['oracle']['jce'][jdk_version]['checksum']
jce_cookie = node['java']['oracle']['accept_oracle_download_terms'] ? 'oraclelicense=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com' : ''

checksum_bin = if jce_checksum =~ /^[0-9a-f]{32}$/
                 'md5sum'
               else
                 'sha256sum'
               end

directory ::File.join(node['java']['oracle']['jce']['home'], jdk_version) do
  mode '0755'
  recursive true
  action :create
end

if node['os'] == 'windows'
  include_recipe 'windows'

  url = node['java']['oracle']['jce'][jdk_version]['url']
  zip_checksum = node['java']['oracle']['jce'][jdk_version]['checksum']
  staging_path = ::File.join(node['java']['oracle']['jce']['home'], jdk_version)
  staging_local_policy = ::File.join(staging_path, "UnlimitedJCEPolicyJDK#{jdk_version}", 'local_policy.jar')
  staging_export_policy = ::File.join(staging_path, "UnlimitedJCEPolicyJDK#{jdk_version}", 'US_export_policy.jar')
  jre_final_path = ::File.join(node['java']['java_home'], 'jre', 'lib', 'security')
  final_local_policy = ::File.join(jre_final_path, 'local_policy.jar')
  final_export_policy = ::File.join(jre_final_path, 'US_export_policy.jar')

  windows_zipfile staging_path do
    source url
    checksum zip_checksum
    action :unzip
    not_if { ::File.exist? staging_local_policy }
    notifies :create, "file[#{final_local_policy}]"
    notifies :create, "file[#{final_export_policy}]"
  end

  file final_local_policy do
    rights :full_control, node['java']['windows']['owner']
    content lazy { ::File.read(staging_local_policy) }
    action :nothing
  end

  file final_export_policy do
    rights :full_control, node['java']['windows']['owner']
    content lazy { ::File.read(staging_export_policy) }
    action :nothing
  end

else
  package 'unzip'
  package 'curl'

  execute 'download jce' do
    command <<-EOF
      rm -rf #{Chef::Config[:file_cache_path]}/java_jce
      mkdir -p #{Chef::Config[:file_cache_path]}/java_jce
      cd #{Chef::Config[:file_cache_path]}/java_jce
{'fraction_non_alphanumeric': 0.15067079463364294, 'fraction_numerical': 0.007567939456484348, 'mean_word_length': 5.013443640124095, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5178199', 'n_tokens_mistral': 1969, 'n_tokens_neox': 1907, 'n_words': 426}