Vendor the external cookbooks

Knife-Zero doesn't include Berkshelf support, so vendoring everything in
the repo is convenient again
This commit is contained in:
Greg Karékinian
2019-10-13 19:17:42 +02:00
parent f4bfe31ac1
commit a32f34b408
1245 changed files with 100630 additions and 0 deletions

590
cookbooks/java/CHANGELOG.md Normal file
View File

@@ -0,0 +1,590 @@
# Java Cookbook CHANGELOG
This file is used to list changes made in each version of the Java cookbook.
## Unreleased
## 4.3.0 (2019-08-04)
- Upgrade Amazon Corretto to the latest versions: 8.222.10.1 and 11.0.4.11.1
- Upgrade circleci orb to version 2 and add yamllint and markdown lint
## 4.2.0 - (2019-07-15)
- Fix for issue 538
- Added "download_path" node attribute defaulting to file_cache_path
- Replaced all hardcoded instances of file_cache_path with the node attribute
## 4.1.0 - (2019-05-08)
- Added new install flavor "corretto" for Amazon's Corretto distribution of OpenJDK
## 4.0.0 - (2019-04-19)
- Added new install flavor "adoptopenjdk" for AdoptOpenJDK's distribution of Java
- The certificate resource now uses the Java version to determine the default cacerts location
- Updated AdoptOpenJDK links for Java 8
- Updated AdoptOpenJDK links for Java 11 to 11.0.1
- BREAKING CHANGE: Remove support for Java 6 & 7
- Remove platform suport for untested platforms (smartOS, XenServer, zlinux, arch)
- Remove testing of Ubuntu 14.04, support at this point is no longer guaranteed and patches or other changes may not be accepted going further as Ubuntu 14.04 will be shortly EOL
- Fixed oracle download link for JDK 8 (update to 8u202 from 8u201)
- fixed specs for windows
## 3.2.0 - (2019-01-24)
- Add support OpenJDK 11
- Fixed oracle download link again
## 3.1.2 - (2018-12-11)
- Set java home on macosx using /usr/libexec/java_home
- Find command should have ./ for path to search, works for nix and mac
- Make `java_certificate` work with SNI endpoints
## 3.1.1 - (2018-11-09)
- Fix jce installation linux
- Allow overwrite `returns` property of windows_packages
## 3.1.0 - (2018-10-18)
- Add support for JDK 11
## 3.0.0 - (2018-10-18)
- Fix broken JCE with JRE installations
- make cert alias matching case insensitive as `keytool` always returns results downcases
- BREAKING CHANGE: fixed greedy matching by adding a word boundry when checking cert alias this prevents matching `foo_123` as `foo`
- verify artifact after downloading from oracle
- fixed `recipes/openjdk` when `node['java']['jdk_version']` by casting it to a string
- Updated Oracle Java links to 8u191
## 2.2.1 - (2018-09-29)
- Allows for additional Oracle (post 9) jdk download file naming, including '10.0.2'. '18.9', '11'
## 2.2.0 - (2018-07-19)
- Updated Oracle Java links to 8u181
- Fixed incorrect kitchen setup runlists that preventing local testing
- Resolve undefined certout errors
## 2.1.0 - (2018-05-25)
- Added Java 10 JCE attributes to default attrs
- Update oracle recipeM to not perform a switch on java major version and instead use the version provided in attributes. This allows end users to include new Java versions without the cookbook requiring an update each time a major version gets released
- Updated the oracle_install resource to pick up semantic versioning that Oracle has started using for Java 10+
- Updated the default attributes file to include x86_64 endpoint and checksum for Oracle Java 10\. The i586 version is not (yet) available.
- Fix JCE installation on Windows
- Avoid EmptyWindowsCommand error on Windows
## v2.0.1 - (2018-05-02)
- Fix java_certificate and java_oracle_install to work on FIPS enabled systems
## v2.0.0 - (2018-05-02)
- Converted alternatives, ark, and certificate LWRP/HWRPs to custom resources with improved logging and convergence notification.
- Renamed the java_ark resource to java_oracle_install, which better represents what it does. The existing name will continue to function
- Removed the need for the apt cookbook and instead require Chef 12.9+
- Fixed Amazon Linux support on Chef 13+.
- Fixed the alternatives commands on Fedora systems.
- Added initial openSUSE leap support.
- Updated code to use multi-package installs to speed up runs
- Made the 'cert_alias' property in the certificate resource the name_property to allow users to avoid resource cloning and to be able to use friendly resource names
- Moved the warning code for downloading directly from Oracle into the resource to prevent another resource showing as converged
- Updated the metadata to resolve failures to parse chef_version on older chef-client releases.
- Added installation of tar directly to the ark resource when uncompression .tar.gz files. This prevents installation in the recipe that occurred even if tar wasn't needed.
- Deprecated the java::purge recipe which purged old Sun Java packages which were distributed in distro repos before the Oracle acquisition of Sun. Migration away from these packages occurred many years ago and this recipe will be removed in the next major release of this cookbook.
- Updated the metadata license string to an SPDX compliant string to resolve Foodcritic warnings.
- Removed Chef 10 compatibility code in the Windows recipe that resulted in Foodcritic warnings.
- Removed logic to support paths on Debian < 7 and Ubuntu < 12.04 as these are both EOL.
- Removed duplicate logging in the resources.
- Converted integration tests from bats to InSpec.
- Moved template files out of the default directory as
- Corrected deprecation warnings in the ChefSpecs.
- Moved all Kitchen testing logic to the test_java cookbook and eliminated the need for the apt & free_bsd bash cookbooks in testing
- Don't try to create Chef's cache directory in the certificate resource.
- Disabled certificate integration tests since we're not currently running the certificate resource in Test Kitchen.
- Removed testing of Oracle JDK 6/7 since Oracle no longer allows directly downloading these releases.
- Added kitchen-dokken based testing
## v1.50.0 - (05/24/2017)
- Oracle downloads changed again. Only Oracle 8 is able to be downloaded automatically. Please host your own copy internally to avoid issues such as this.
- Add Log warning if download url contains oracle.com
## v1.49.0 - (04/21/2017)
- potential 'curl' resource cloning #415
- Oracle 8u131
- Add ChefSpec matchers for java_certificate resource
- Remove unnecessary apt update
## v1.48.0 - (03/31/2017)
- Update Oracle Java links from 101 to 121
- Remove convergence report
- Remove Fedora 24 testing
- Fix test cookbook license
- Update platforms in the specs
- Remove testing on EOL platforms
## v1.47.0 - (01/30/2017)
- Fix typo in method name (#397)
- Remove useless ruby_block[set-env-java-home]
- Update README: using java::notify
- Add forgotten "do" to README
## v1.46.0 - (01/09/2017)
- fix jce installation on windows #386
## v1.45.0 - (12/27/2016)
- Update to resolve latest rubocop rules
## v1.44.0 - (12/27/2016)
- Unpublished due to newer rubocop rules in travis
- Added zlinux defaults
## v1.43.0 - (12/6/2016)
- Switch recursive chown from executing on the jdk parent directory to executing on the jdk directory itself.
- Added proxy support to curl
- add java_certificate LWRP from java-libraries cookbook - java-libraries now depricated.
- (Windows) support removal of obsolete JREs via optional attribute
- (Windows) Can download from s3 only using an IAM profile
- (Windows) aws session token for windows java download
## v1.42.0 - (8/8/2016)
- Use openjdk ppa for all ubuntu versions to allow for older/newer jdks to be installed. Fixes #368
- update oracle java 8u101 - Use sha256 hash (seems to help with downloading each converge)
- Mac default converge fails since notify is not included by homebrew
- Remove chef 14(!) depreciation warning in tests
- Resolve chef-12 related warning
## v1.41.0 - (7/15/2016)
- Feature: Add new resource for cookbooks to subscribe to, see README
- Use a remote_file resource for JCE download instead of curl in an execute block.
- Since v1.40.4 Travis deploys cookbook to supermarket - expect more frequent, smaller releases.
## v1.40.4 - (7/12/2016)
- Automated deploy, no cookbook changes.
## v1.40.3 - (7/12/2016)
- Attempt to have travis publish this.
- Mac depends on homebrew.
- Fixed typo in platform family spelling for OS X
- fix openjdk version logic for freebsd
- Enable Ark provider to handle URI with get parameters
## v1.40.1 - (7/8/2016)
- Fixed: JAVA_HOME not set on systems with restrictive umask #359
## v1.40 - (6/29/2016)
- Travis build green
- Add Windows JCE support
- Changes to prevent re-execution of resource creating file '/etc/profile.d/jdk.sh'
- Fix JDK checksum
- Update ibm_jdk.installer.properties.erb for IBM JDK 1.8
- Install OpenJDK from distribution if Ubuntu version >= 15.10
- Fixes #342 - Tar is included in macosx and homebrews package is gnutar which causes this to fail
- Add 12.04 to jdk8 test suite
- Add source and issues urls to supermarket
- Distinguishing the Java version for installing on the Mac OS X
- Doc and cruft cleanup
## v1.39 - (1/14/2016)
- Travis debugging only, no code changes.
## v1.38 - (1/13/2016)
- (Win) Fix for Java install failing on Windows (introduced in #315)
- Travis fixes/badge
## v1.37 - (11/9/2015)
- (Win) Attirbute for specifying the install directory for the public jre #315
## v1.36 - (9/3/2015)
- Oracle JDK 1.8.0_65
- Add Ubuntu ppa (allows OpenJDK 8)
- Added ChefSpec matchers #284
- Fix compile error using Chef::Application.fatal #279
- #222 Provide possibility to set ark download timeout
- Openjdk6 does not exist in deb 8.2
- Change to create java home dir even if top level doesn't exist(Eg mkdir_p instead of mkdir)
- Fix berks url and remove apt
- Documentation and dependency updates
## v1.35 - (8/4/2015)
- Use bento boxes and remove EOL distros from testing suite.
- Update to latest JDKs. Note Oracle JDK7 is now EOL.
- Alternatives improvements
- Fixes #155 to allow install of OpenJDK 1.8
- Fixes #257 Changed switches for the jdk 8 exe installer on windows
- Make sure tar package installed for java_ark
- Add support for Mac OS X "mac_os_x" via homebrew.
- Update metadata.rb to contain source and issue information for supermarket and chef-repo convenience
### Known Issues
- Kitchen CI test with 12.04 fails due to hostname unable to be set.
## v1.31 - (2/3/2015)
- Update to latest JDKs for 7 and 8\. JDK7 will be EOL April 2015
- Fix up Travis support.
- Add ability to install JCE policy files for oracle JDK #228
- Change connect timeout to 30 seconds
## v1.29.0 - (11/14/2014)
- **[#216](https://github.com/agileorbit-cookbooks/java/pull/216)** - Ensure dirs, links, and jinfo files are owned correctly
- **[#217](https://github.com/agileorbit-cookbooks/java/pull/217)** - Update to Oracle JDK 8u25
- **[#214](https://github.com/agileorbit-cookbooks/java/pull/214)** - Update to Oracle JDK 7u71-b14
- Adding a connect_timeout option for downloading java.
- Switched to chef-zero provisioner in test suites.
- Adding ISSUES.md for guidance on creating new issues for the Java cookbook.
- Fix IBM unit tests.
## v1.28.0 - (9/6/2014)
- Allow setting of group to extracted java files.
- Add -no-same-owner parameter to tar extract to avoid issues when the chef cache dir is on an NFS mounted drive.
- In the ark provider, it doesn't compare the MD5 sum with the right value which causes Java cookbook always download tarball from oracle server
## v1.27.0 - (8/22/2014)
- Update Oracle JDK8 to version 8u20
## v1.26.0 - (8/16/2014)
- **[#201](https://github.com/agileorbit-cookbooks/java/pull/201)** - Allow pinning of package versions for openjdk
- **[#198](https://github.com/agileorbit-cookbooks/java/pull/198)** - Update Oracle JDK7 to version 7u67
- **[#189](https://github.com/agileorbit-cookbooks/java/pull/184)** - Support specific version and name for Oracle RPM
## v1.25.0 - (8/1/2014)
- **[#189](https://github.com/agileorbit-cookbooks/java/pull/189)** - Resource ark -> attribute bin_cmds default value
- **[#168](https://github.com/agileorbit-cookbooks/java/pull/168)** - Add option to put JAVA_HOME in /etc/environment
- **[#172](https://github.com/agileorbit-cookbooks/java/pull/172)** - Allow ark to pull from http and files ending in .gz.
- Recommendations for inclusion in community cookbooks
- Production Deployment with Oracle Java
- Update testing instructions for chefdk
- Various Readme formatting.
- Use Supermarket endpoint in berksfile
- rspec cleanup
- Adding ubuntu-14.04 to test suite
## v1.24.0 - (7/25/2014)
New Cookbook maintainer! **[Agile Orbit](http://agileorbit.com)**
- **[#192](https://github.com/agileorbit-cookbooks/java/pull/192)** - Bump JDK7 URLs to 7u65
- **[#191](https://github.com/agileorbit-cookbooks/java/pull/192)** - Upgrade Oracle's Java 8 to u11
- **[#188](https://github.com/agileorbit-cookbooks/java/pull/188)** - Allow for alternatives priority to be set from attribute.
- **[#176](https://github.com/agileorbit-cookbooks/java/pull/176)** - Change ownership of extracted files
- **[#169](https://github.com/agileorbit-cookbooks/java/pull/169)** - Add retries and retry_delay parameters to java_ark LWRP
- **[#167](https://github.com/agileorbit-cookbooks/java/pull/167)** - default: don't fail when using java 8 on windows
- **[#165](https://github.com/agileorbit-cookbooks/java/pull/165)** - Support for Server JRE
- **[#158](https://github.com/agileorbit-cookbooks/java/pull/158)** - Updated README for accepting oracle terms
- **[#157](https://github.com/agileorbit-cookbooks/java/pull/157)** -Remove VirtualBox specific box_urls
- List AgileOrbit as the maintainer (AgileOrbit took over from Socrata in July 2014)
## v1.23.0 - (7/25/2014)
- Tagged but never published to community cookbooks. All changes rolled into 1.24.0
## v1.22.0
- **[#148](https://github.com/socrata-cookbooks/java/pull/148)** - Add support for Oracle JDK 1.8.0
- **[#150](https://github.com/socrata-cookbooks/java/pull/150)** - Make use of Chef's cache directory instead of /tmp
- **[#151](https://github.com/socrata-cookbooks/java/pull/151)** - Update Test Kitchen suites
- **[#154](https://github.com/socrata-cookbooks/java/pull/154)** - Add safety check for JDK 8 on non-Oracle
## v1.21.2
- **[#146](https://github.com/socrata-cookbooks/java/pull/146)** - Update Oracle accept-license-terms cookie format
## v1.21.0
- **[#143](https://github.com/socrata-cookbooks/java/pull/143)** - Symlink /usr/lib/jvm/default-java for both OpenJDK and Oracle
- **[#144](https://github.com/socrata-cookbooks/java/pull/144)** - Remove /var/lib/alternatives/#{cmd} before calling alternatives (Hopefully fixes sporadic issues when setting alternatives)
- **[Make default_java_symlink conditional on set_default attribute](https://github.com/socrata-cookbooks/java/commit/e300e235a463382a5022e1dddaac674930b4d138)**
## v1.20.0
- **[#137](https://github.com/socrata-cookbooks/java/pull/137)** - Create /usr/lib/jvm/default-java on Debian
- **[#138](https://github.com/socrata-cookbooks/java/pull/138)** - allow wrapping cookbook without providing templates
- **[#140](https://github.com/socrata-cookbooks/java/pull/140)** - Adds set_default attribute to toggle setting JDK as default
- **[#141](https://github.com/socrata-cookbooks/java/pull/141)** - set java_home correctly for oracle_rpm
## v1.19.2
- **[#129](https://github.com/socrata-cookbooks/java/pull/129)** - Upgrade to ChefSpec 3
- Rewrite unit tests for better coverage and to work with ChefSpec 3 (various commits)
- List Socrata as the maintainer (Socrata took over from Opscode in December 2013)
- **[#133](https://github.com/socrata-cookbooks/java/pull/133)** - Allow jdk_version to be a string or number
- **[#131](https://github.com/socrata-cookbooks/java/pull/131)** - Fix JDK install on Windows
- **[Fix openjdk_packages on Arch Linux](https://github.com/socrata-cookbooks/java/commit/677bee7b9bf08988596d40ac65e75984a86bda99)**
## v1.19.0
Refactor the cookbook to better support wrapper cookbooks and other cookbook authoring patterns.
- **[#123](https://github.com/socrata-cookbooks/java/pull/123)** - Update documentation & add warning for issue 122
- **[#124](https://github.com/socrata-cookbooks/java/pull/124)** - Refactor default recipe to better enable wrapper cookbooks
- **[#125](https://github.com/socrata-cookbooks/java/pull/125)** - Removes the attribute to purge deprecated packages
- **[#127](https://github.com/socrata-cookbooks/java/pull/127)** - Add safety check if attributes are unset
- **[Adds tests for directly using openjdk and oracle recipes](https://github.com/socrata-cookbooks/java/commit/794df596959d65a1a6d5f6c52688bffd8de6bff4)**
- **[Adds recipes to README](https://github.com/socrata-cookbooks/java/commit/76d52114bb9df084174d43fed143123b1cdbae16)**
- **[The Opscode CCLA is no longer required](https://github.com/socrata-cookbooks/java/commit/ce4ac25caa8383f185c25c4e32cafef8c0453376)**
- **[Adds tests for openjdk-7 and oracle-7](https://github.com/socrata-cookbooks/java/commit/9c38af241f68b3198cde4ad6fe2b4cb752062009)**
- **[#119](https://github.com/socrata-cookbooks/java/pull/119)** - Use java_home instead of java_location for update-alternatives
- **[Fix java_home for rhel and fedora](https://github.com/socrata-cookbooks/java/commit/71dadbd1bfe2eab50ff21cdab4ded97877911cc4)**
## v1.18.0
- **[#118](https://github.com/socrata-cookbooks/java/pull/118)** - Upgrade to 7u51
- **[#117](https://github.com/socrata-cookbooks/java/pull/117)** - Suggest windows and aws
## v1.17.6
- Revert **[COOK-4165](https://tickets.opscode.com/browse/COOK-4165)** - The headers option was only added to remote_file in Chef 11.6.0, meaning this change breaks older clients.
## v1.17.4
### Bug
- **[#111](https://github.com/socrata-cookbooks/java/pull/111)** - Fix alternatives for centos
### Improvement
- **[COOK-4165](https://tickets.opscode.com/browse/COOK-4165)** - Replace curl with remote_file with cookie header
- **[#110](https://github.com/socrata-cookbooks/java/pull/110)** - Update openjdk to use the alternatives resource
## v1.17.2
### Bug
- **[COOK-4136](https://tickets.opscode.com/browse/COOK-4136)** - Add md5 parameter to java_ark resource
## v1.17.0
- **[COOK-4114](https://tickets.opscode.com/browse/COOK-4114)** - Test Kitchen no longer works after merging Pull Request #95 for openjdk tests on Debian/Ubuntu
- **[COOK-4124](https://tickets.opscode.com/browse/COOK-4124)** - update-alternatives fails to run
- **[#81](https://github.com/socrata/java/pull/81)** - Ensure local directory hierarchy
- **[#97](https://github.com/socrata/java/pull/97)** - Expose LWRP state attributes
- **[#99](https://github.com/socrata/java/pull/99)** - support for MD5 checksum
- **[#106](https://github.com/socrata/java/pull/106)** - Fixed windows case to prevent bad java_home variable setting
- **[Update checksums to the officially-published ones from Oracle](https://github.com/socrata/java/commit/b9e1df24caeb6e22346d2d415b3b4384f15d4ffd)**
- **[Further test kitchen fixes to use the default recipe](https://github.com/socrata/java/commit/01c0b432705d9cfa6d2dfeaa380983e3f604069f)**
## v1.16.4
### Bug
- **[#103](https://github.com/socrata/java/pull/103)** - set alternatives when using ibm_tar recipe
- **[#104](https://github.com/socrata/java/pull/104)** - Specify windows attributes in attribute files
## v1.16.2
### Improvement
- **[COOK-3488](https://tickets.opscode.com/browse/COOK-3488)** - set alternatives for ibm jdk
- **[COOK-3764](https://tickets.opscode.com/browse/COOK-3764)** - IBM Java installer needs 'rpm' package on Ubuntu
### Bug
- **[COOK-3857](https://tickets.opscode.com/browse/COOK-3857)** - do not unescape the java windows url before parsing it
- **[#95](https://github.com/socrata/java/pull/95)** - fixes update-alternatives for openjdk installs
- **[#100](https://github.com/socrata/java/pull/100)** - Use escaped quotes for Windows INSTALLDIR
## v1.16.0
### Improvement
- **[COOK-3823](https://tickets.opscode.com/browse/COOK-3823)** - Upgrade to JDK 7u45-b18
## v1.15.4
[COOK-4210] - remove unneeded run_command to prevent zombie processes
## v1.15.2
[CHEF-4210] remove unneeded run_command to prevent zombie processes
## v1.15.0
### Bug
- Fixing version number. Accidently released at 0.15.x instead of 1.15.x
## v0.15.2
### FIX
- [COOK-3908] - Fixing JAVA_HOME on Ubuntu 10.04
## v1.14.0
### Bug
- **[COOK-3704](https://tickets.opscode.com/browse/COOK-3704)** - Fix alternatives when the package is already installed
- **[COOK-3668](https://tickets.opscode.com/browse/COOK-3668)** - Fix a condition that would result in an error executing action `run` on resource 'bash[update-java-alternatives]'
- **[COOK-3569](https://tickets.opscode.com/browse/COOK-3569)** - Fix bad checksum length
- **[COOK-3541](https://tickets.opscode.com/browse/COOK-3541)** - Fix an issue where Java cookbook installs both JDK 6 and JDK 7 when JDK 7 is specified
- **[COOK-3518](https://tickets.opscode.com/browse/COOK-3518)** - Allow Windoes recipe to download from signed S3 url
- **[COOK-2996](https://tickets.opscode.com/browse/COOK-2996)** - Fix a failure on Centos 6.4 and Oracle JDK 7
### Improvement
- **[COOK-2793](https://tickets.opscode.com/browse/COOK-2793)** - Improve Windows support
## v1.13.0
### Bug
- **[COOK-3295](https://tickets.opscode.com/browse/COOK-3295)** - Add default `platform_family` option in Java helper
- **[COOK-3277](https://tickets.opscode.com/browse/COOK-3277)** - Fix support for Fedora
### Improvement
- **[COOK-3278](https://tickets.opscode.com/browse/COOK-3278)** - Upgrade to Oracle Java 7u25
- **[COOK-3029](https://tickets.opscode.com/browse/COOK-3029)** - Add Oracle RPM support
- **[COOK-2931](https://tickets.opscode.com/browse/COOK-2931)** - Add support for the platform `xenserver`
- **[COOK-2154](https://tickets.opscode.com/browse/COOK-2154)** - Add SmartOS support
## v1.12.0
### Improvement
- [COOK-2154]: Add SmartOS support to java::openjdk recipe
- [COOK-3278]: upgrade to Oracle Java 7u25
- [COOK-2931]: Adding support for the platform 'xenserver' (for installations of java in DOM0)
- [COOK-3277]: java cookbook fails on Fedora
## v1.11.6
- [COOK-2847]: Java cookbook does not have opensuse support
- [COOK-3142]: Syntax Errors spec/default_spec.rb:4-8
## v1.11.4
- [COOK-2989]: `bash[update-java-alternatives]` resource uses wrong attribute
## v1.11.2
- Use SHA256 checksums for Oracle downloads, not SHA1.
## v1.11.0
This version brings a wealth of tests and (backwards-compatible) refactoring, plus some new features (updated Java, IBM recipe).
- [COOK-2897]: Add ibm recipe to java cookbook
- [COOK-2903]: move java_home resources to their own recipe
- [COOK-2904]: refactor ruby_block "update-java-alternatives"
- [COOK-2905]: use platform_family in java cookbook
- [COOK-2920]: add chefspec to java cookbook
- [COOK-2902]: Refactor java cookbook
- [COOK-2900]: update JDK to JDK 7u21, 6u45
## v1.10.2
- [COOK-2415] - Fixed deprecation warnings in ark provider and openjdk recipe by using Chef::Mixin::ShellOut instead of Chef::ShellOut
## v1.10.0
- [COOK-2400] - Allow java ark :url to be https
- [COOK-2436] - Upgrade needed for oracle jdk in java cookbook
## v1.9.6
- [COOK-2412] - add support for Oracle Linux
## v1.9.4
- [COOK-2083] - Run set-env-java-home in Java cookbook only if necessary
- [COOK-2332] - ark provider does not allow for *.tgz tarballs to be used
- [COOK-2345] - Java cookbook fails on CentOS6 (update-java-alternatives)
## v1.9.2
- [COOK-2306] - FoodCritic fixes for java cookbook
## v1.9.0
- [COOK-2236] - Update the Oracle Java version in the Java cookbook to release 1.7u11
## v1.8.2
- [COOK-2205] - Fix for missing /usr/lib/jvm/default-java on Debian
## v1.8.0
- [COOK-2095] - Add windows support
## v1.7.0
- [COOK-2001] - improvements for Oracle update-alternatives
- When installing an Oracle JDK it is now registered with a higher priority than OpenJDK. (Related to COOK-1131.)
- When running both the oracle and oracle_i386 recipes, alternatives are now created for both JDKs.
- Alternatives are now created for all binaries listed in version specific attributes. (Related to COOK-1563 and COOK-1635.)
- When installing Oracke JDKs on Ubuntu, create .jinfo files for use with update-java-alternatives. Commands to set/install alternatives now only run if needed.
## v1.6.4
- [COOK-1930] - fixed typo in attribute for java 5 on i586
## v1.6.2
- whyrun support in `java_ark` LWRP
- CHEF-1804 compatibility
- [COOK-1786] - install Java 6u37 and Java 7u9
- [COOK-1819] - incorrect warning text about `node['java']['oracle']['accept_oracle_download_terms']`
## v1.6.0
- [COOK-1218] - Install Oracle JDK from Oracle download directly
- [COOK-1631] - set JAVA_HOME in openjdk recipe
- [COOK-1655] - Install correct architecture on Amazon Linux
## v1.5.4
- [COOK-885] - update alternatives called on wrong file
- [COOK-1607] - use shellout instead of execute resource to update alternatives
## v1.5.2
- [COOK-1200] - remove sun-java6-jre on Ubuntu before installing Oracle's Java
- [COOK-1260] - fails on Ubuntu 12.04 64bit with openjdk7
- [COOK-1265] - Oracle Java should symlink the jar command
## v1.5.0
- [COOK-1146] - Oracle now prevents download of JDK via non-browser
- [COOK-1114] - fix File.exists?
## v1.4.2
- [COOK-1051] - fix attributes typo and platform case switch consistency
## v1.4.0
- [COOK-858] - numerous updates: handle jdk6 and 7, switch from sun to oracle, make openjdk default, add `java_ark` LWRP.
- [COOK-942] - FreeBSD support
- [COOK-520] - ArchLinux support

View File

@@ -0,0 +1,21 @@
# Contributing
## Branches
### `master` branch
The master branch is the current committed changes. These changes may not yet be released although we try to release often.
## Tags
All releases are tagged in git. To see the releases available to you see the changelog or the tags directly.
## Pull requests
- <https://github.com/sous-chefs/java/pulls>
## Issues
Need to report an issue? Use the github issues:
- <https://github.com/sous-chefs/java/issues>

466
cookbooks/java/README.md Normal file
View File

@@ -0,0 +1,466 @@
# java cookbook
[![Cookbook Version](https://img.shields.io/cookbook/v/java.svg)](https://supermarket.chef.io/cookbooks/java)
[![Build Status](https://img.shields.io/circleci/project/github/sous-chefs/java/master.svg)](https://circleci.com/gh/sous-chefs/java)
[![OpenCollective](https://opencollective.com/sous-chefs/backers/badge.svg)](#backers)
[![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors)
[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0)
This cookbook installs a Java JDK/JRE. It defaults to installing OpenJDK, but it can also install Oracle, IBM JDKs or AdoptOpenJDK.
## Maintainers
This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If youd like to know more please visit [sous-chefs.org](https://sous-chefs.org/) or come chat with us on the Chef Community Slack in [#sous-chefs](https://chefcommunity.slack.com/messages/C2V7B88SF).
## Production Deployment with Oracle Java
Oracle has been known to change the behavior of its download site frequently. It is recommended you store the archives on an artifact server or s3 bucket. You can then override the attributes in a cookbook, role, or environment:
```ruby
default['java']['jdk_version'] = '8'
default['java']['install_flavor'] = 'oracle'
default['java']['jdk']['7']['x86_64']['url'] = 'http://artifactory.example.com/artifacts/jdk-7u65-linux-x64.tar.gz'
default['java']['jdk']['7']['x86_64']['checksum'] = 'The SHA-256 checksum of the JDK archive'
default['java']['oracle']['accept_oracle_download_terms'] = true
```
## Usage
Include the `java` recipe wherever you would like Java installed, such as a run list (`recipe[java]`) or a cookbook (`include_recipe 'java'`). By default, OpenJDK 6 is installed. The `install_flavor` attribute is used to determine which JDK to install (AdoptOpenJDK, OpenJDK, Oracle, IBM, or Windows), and `jdk_version` specifies which version to install (currently 6 and 7 are supported for all JDK types, 8 and 10 for Oracle and AdoptOpenJDK ).
### Examples
To install Oracle Java 7 (note that when installing Oracle JDK, `accept_oracle_download_terms` attribute must be set -- see below role for an example):
```ruby
name "java"
description "Install Oracle Java"
default_attributes(
"java" => {
"install_flavor" => "oracle",
"jdk_version" => "7",
"oracle" => {
"accept_oracle_download_terms" => true
}
}
)
run_list(
"recipe[java]"
)
```
Example role to install IBM flavored Java:
```ruby
name "java"
description "Install IBM Java on Ubuntu"
default_attributes(
"java" => {
"install_flavor" => "ibm",
"ibm" => {
"accept_ibm_download_terms" => true,
"url" => "http://fileserver.example.com/ibm-java-x86_64-sdk-7.0-4.1.bin",
"checksum" => "The SHA256 checksum of the bin"
}
}
)
run_list(
"recipe[java]"
)
```
## Requirements
Chef 13.4+
### Platforms
- Debian, Ubuntu
- CentOS, RedHat, Fedora, Scientific, Amazon
- ArchLinux
- FreeBSD
- Windows
- macOS
### Cookbooks
- homebrew
## Attributes
See `attributes/default.rb` for default values.
- `node['java']['download_path']` - Location to download and extract the tarball
- `node['java']['install_flavor']` - Flavor of JVM you would like installed (`oracle`, `oracle_rpm`, `openjdk`, `adoptopenjdk`, `ibm`, `windows`), default `openjdk` on Linux/Unix platforms, `windows` on Windows platforms.
- `node['java']['install_type']` - Type of Java installation, defauls to jdk, needed for JCE to find the install path of jar's for JDK/JRE installation.
- `node['java']['jdk_version']` - JDK version to install, defaults to `'6'`.
- `node['java']['java_home']` - Default location of the "`$JAVA_HOME`". To configure this attribute for `ibm`, `ibm_tar`, and `oracle_rpm` install flavors, you must use an attribute precedence of `force_default` or higher in your attribute file.
- `node['java']['set_etc_environment']` - Optionally sets JAVA_HOME in `/etc/environment` for Default `false`.
- `node['java']['openjdk_packages']` - Array of OpenJDK package names to install in the `java::openjdk` recipe. This is set based on the platform.
- `node['java']['jdk']` - Version and architecture specific attributes for setting the URL on Oracle's site for the JDK, and the checksum of the .tar.gz.
- `node['java']['oracle']['accept_oracle_download_terms']` - Indicates that you accept Oracle's EULA
- `node['java']['windows']['url']` - The internal location of your java install for windows
- `node['java']['windows']['package_name']` - The package name used by windows_package to check in the registry to determine if the install has already been run
- `node['java']['windows']['checksum']` - The checksum for the package to download on Windows machines (default is nil, which does not perform checksum validation)
- `node['java']['windows']['remove_obsolete']` - Indicates whether to remove previous versions of the JRE (default is `false`)
- `node['java']['windows']['aws_access_key_id']` - AWS Acess Key ID to use with AWS API calls
- `node['java']['windows']['aws_secret_access_key']` - AWS Secret Access Key to use with AWS API calls
- `node['java']['windows']['aws_session_token']` - AWS Session Token to use with AWS API calls
- `node['java']['windows']['returns']` - The allowed return codes for the package to
be installed on Windows machines (default is 0, you can define an array of valid values.)
- `node['java']['ibm']['url']` - The URL which to download the IBM JDK/SDK. See the `ibm` recipe section below.
- `node['java']['ibm']['accept_ibm_download_terms']` - Indicates that you accept IBM's EULA (for `java::ibm`)
- `node['java']['oracle_rpm']['type']` - Type of java RPM (`jre` or `jdk`), default `jdk`
- `node['java']['oracle_rpm']['package_version']` - optional, can be set to pin a version different from the up-to-date one available in the YUM repo, it might be needed to also override the node['java']['java_home'] attribute to a value consistent with the defined version
- `node['java']['oracle_rpm']['package_name']` - optional, can be set to define a package name different from the RPM published by Oracle.
- `node['java']['accept_license_agreement']` - Indicates that you accept the EULA for openjdk package installation.
- `node['java']['set_default']` - Indicates whether or not you want the JDK installed to be default on the system. Defaults to true.
- `node['java']['oracle']['jce']['enabled']` - Indicates if the JCE Unlimited Strength Jurisdiction Policy Files should be installed for oracle JDKs
- `node['java']['oracle']['jce']['home']` - Where the JCE policy files should be installed to
- `node['java']['oracle']['jce'][java_version]['checksum']` - Checksum of the JCE policy zip. Can be sha256 or md5
- `node['java']['oracle']['jce'][java_version]['url']` - URL which to download the JCE policy zip
- `node['java']['adoptopenjdk']['variant']` - Install the Eclipse Openj9 (default), Eclipse OpenJ9 Large Heap or Hotspot version of AdoptOpenJDK
## Recipes
### default
Include the default recipe in a run list or recipe to get `java`. By default the `openjdk` flavor of Java is installed, but this can be changed by using the `install_flavor` attribute. By default on Windows platform systems, the `install_flavor` is `windows` and on Mac OS X platform systems, the `install_flavor` is `homebrew`.
OpenJDK is the default because of licensing changes made upstream by Oracle. See notes on the `oracle` recipe below.
NOTE: In most cases, including just the default recipe will be sufficient. It's possible to include the install_type recipes directly, as long as the necessary attributes (such as java_home) are set.
### set_attributes_from_version
Sets default attributes based on the JDK version. This is included by `default.rb`. This logic must be in a recipe instead of attributes/default.rb. See [#95](https://github.com/agileorbit-cookbooks/java/pull/95) for details.
### default_java_symlink
Updates /usr/lib/jvm/default-java to point to JAVA_HOME.
### openjdk
This recipe installs the `openjdk` flavor of Java. It also uses the `alternatives` system on RHEL/Debian families to set the default Java.
On platforms such as SmartOS that require the acceptance of a license agreement during package installation, set `node['java']['accept_license_agreement']` to true in order to indicate that you accept the license.
### oracle
This recipe installs the `oracle` flavor of Java. This recipe does not use distribution packages as Oracle changed the licensing terms with JDK 1.6u27 and prohibited the practice for both RHEL and Debian family platforms.
You can not directly download the JDK from Oracle's website without using a special cookie. This cookbook uses that cookie to download the oracle recipe on your behalf, however the `java::oracle` recipe forces you to set either override the `node['java']['oracle']['accept_oracle_download_terms']` to true or set up a private repository accessible by HTTP.
override the `accept_oracle_download_terms` in, e.g., `roles/base.rb`
```ruby
default_attributes(
:java => {
:oracle => {
"accept_oracle_download_terms" => true
}
}
)
```
For both RHEL and Debian families, this recipe pulls the binary distribution from the Oracle website, and installs it in the default `JAVA_HOME` for each distribution. For Debian, this is `/usr/lib/jvm/default-java`. For RHEL, this is `/usr/lib/jvm/java`.
After putting the binaries in place, the `java::oracle` recipe updates `/usr/bin/java` to point to the installed JDK using the `update-alternatives` script. This is all handled in the `java_oracle_install` resource.
### oracle_i386
This recipe installs the 32-bit Java virtual machine without setting it as the default. This can be useful if you have applications on the same machine that require different versions of the JVM.
This recipe operates in a similar manner to `java::oracle`.
### oracle_rpm
This recipe installs the Oracle JRE or JDK provided by a custom YUM repositories. It also uses the `alternatives` system on RHEL families to set the default Java.
While public YUM repos for Oracle Java 7 and prior are available, you need to download the RPMs manually for Java 8 and make your own internal repository. This must be done to use this recipe to install Oracle Java 8 via RPM. You will also likely need to set `node['java']['oracle_rpm']['package_name']` to `jdk1.8.0_40`, replacing `40` with the most current version in your local repo.
### adoptopenjdk
This recipe installs the `AdoptOpenJDK` flavor of Java from [https://adoptopenjdk.net/](https://adoptopenjdk.net/). It also uses the `alternatives` system on the RHEL/Debian families to set the default Java.
### Amazon Corretto
This recipe installs the `Amazon Corretto` flavor of OpenJDK from [https://aws.amazon.com/corretto/](https://aws.amazon.com/corretto/). It also uses the `alternatives` system on RHEL/Debian families to set the default Java.
### windows
Because as of 26 March 2012 you can no longer directly download the JDK msi from Oracle's website without using a special cookie. This recipe requires you to set `node['java']['oracle']['accept_oracle_download_terms']` to true or host it internally on your own http repo or s3 bucket.
**IMPORTANT NOTE**
If you use the `windows` recipe, you'll need to make sure you've uploaded the `aws` and `windows` cookbooks. As of version 1.18.0, this cookbook references them with `suggests` instead of `depends`, as they are only used by the `windows` recipe.
### ibm
The `java::ibm` recipe is used to install the IBM version of Java. Note that IBM requires you to create an account _and_ log in to download the binary installer for your platform. You must accept the license agreement with IBM to use their version of Java. In this cookbook, you indicate this by setting `node['java']['ibm']['accept_ibm_download_terms']` to `true`. You must also host the binary on your own HTTP server to have an automated installation. The `node['java']['ibm']['url']` attribute must be set to a valid https/http URL; the URL is checked for validity in the recipe.
At this time the `java::ibm` recipe does not support multiple SDK installations.
### notify
The `java::notify` recipe contains a log resource whose `:write` action is called when a JDK version changes. This gives cookbook authors a way to subscribe to JDK changes and take actions (say restart a java service):
```ruby
service 'somejavaservice' do
action :restart
subscribes :restart, 'log[jdk-version-changed]', :delayed
end
```
## Resources
### java_oracle_install
This cookbook contains the `java_oracle_install` resource which handles installation of Oracle's distribution of Java..
By default, the extracted directory is extracted to `app_root/extracted_dir_name` and symlinked to `app_root/default`
#### Actions
- `:install`: extracts the tarball and makes necessary symlinks
- `:remove`: removes the tarball and run update-alternatives for all symlinked `bin_cmds`
#### Attribute Parameters
- `url`: path to tarball, .tar.gz, .bin (oracle-specific), and .zip currently supported
- `checksum`: SHA256 checksum, not used for security but avoid redownloading the archive on each chef-client run
- `app_home`: the default for installations of this type of application, for example, `/usr/lib/tomcat/default`. If your application is not set to the default, it will be placed at the same level in the directory hierarchy but the directory name will be `app_root/extracted_directory_name + "_alt"`
- `app_home_mode`: file mode for app_home, is an integer
- `bin_cmds`: array of binary commands that should be symlinked to `/usr/bin`, examples are mvn, java, javac, etc. These cmds must be in the `bin` subdirectory of the extracted folder. Will be ignored if this `java_oracle_install` is not the default
- `owner`: owner of extracted directory, set to "root" by default
- `group`: group of extracted directory, set to `:owner` by default
- `default`: whether this the default installation of this package, boolean true or false
- `reset_alternatives`: whether alternatives is reset boolean true or false
- `use_alt_suffix`: whether `_alt` suffix is used for not default javas boolean true or false
- `proxy`: optional address and port of proxy server, for example, `proxy.example.com:1234`
#### Examples
```ruby
# install jdk6 from Oracle
java_oracle_install "jdk" do
url 'http://download.oracle.com/otn/java/jdk/6u29-b11/jdk-6u29-linux-x64.bin'
checksum 'a8603fa62045ce2164b26f7c04859cd548ffe0e33bfc979d9fa73df42e3b3365'
app_home '/usr/local/java/default'
bin_cmds ["java", "javac"]
action :install
end
```
### adoptopenjdk_install
This cookbook contains the `adoptopenjdk_install` resource which handles the installation of AdopOpenJDK's distribution of Java.
By default, the extracted directory is extracted to `app_root/extracted_dir_name` and symlinked to `app_root/default`
#### Actions
- `:install`: extracts the tarball and makes necessary symlinks
- `:remove`: removes the tarball and run update-alternatives for all symlinked `bin_cmds`
#### Attribute Parameters
- `url`: path to tarball, .tar.gz is currently supported
- `checksum`: SHA256 checksum, not used for security but avoid redownloading the archive on each chef-client run
- `app_home`: the default for installations of this type of application, for example, `/usr/lib/tomcat/default`.
- `app_home_mode`: file mode for app_home, is an integer
- `bin_cmds`: array of binary commands that should be symlinked to `/usr/bin`, examples are mvn, java, javac, etc. These cmds must be in the `bin` subdirectory of the extracted folder. Will be ignored if this `java_oracle_install` is not the default
- `owner`: owner of extracted directory, set to "root" by default
- `group`: group of extracted directory, set to `:owner` by default
- `default`: whether this the default installation of this package, boolean true or false
- `reset_alternatives`: whether alternatives is reset boolean true or false
- `variant`: One of `hotspot`, `openj9`, or `openj9-large-heap`
#### Examples
```ruby
# install Java 10 from AdoptOpenJDK
adoptopenjdk_install "jdk" do
url 'https://github.com/AdoptOpenJDK/openjdk10-openj9-releases/releases/download/jdk-10.0.2%2B13_openj9-0.9.0/OpenJDK10-OPENJ9_x64_Linux_jdk-10.0.2.13_openj9-0.9.0.tar.gz'
checksum '1ef0dab3853b2f3666091854ef8149fcb85970254558d5d62cfa9446831779d1'
app_home '/usr/local/java/default'
bin_cmds ["java", "javac"]
action :install
end
```
### java_alternatives
The `java_alternatives` resource uses `update-alternatives` command to set and unset command alternatives for various Java tools such as java, javac, etc.
#### Actions
- `:set`: set alternatives for Java tools
- `:unset`: unset alternatives for Java tools
#### Attribute Parameters
- `java_location`: Java installation location.
- `bin_cmds`: array of Java tool names to set or unset alternatives on.
- `default`: whether to set the Java tools as system default. Boolean, defaults to `true`.
- `priority`: priority of the alternatives. Integer, defaults to `1061`.
#### Examples
```ruby
# set alternatives for java and javac commands
java_alternatives "set java alternatives" do
java_location '/usr/local/java'
bin_cmds ["java", "javac"]
action :set
end
```
### java_certificate
This cookbook contains the `java_certificate` resource which simplifies adding certificates to a java keystore. It can also populate the keystore with a certificate retrieved from a given SSL end-point. It defaults to the default keystore `<java_home>/jre/lib/security/cacerts` for Java 8 or below and `<java_home>/lib/security/cacerts` for Java 9+ with the default password if a specific keystore is not provided.
### Actions
- `:install`: installs a certificate.
- `:remove`: removes a certificate.
### Attribute Parameters
- `cert_alias`: The alias of the certificate in the keystore. This defaults to the name of the resource.
Optional parameters:
- `java_home`: the java home directory. Defaults to `node['java']['java_home']`.
- `keystore_path`: the keystore path. Defaults to `node['java']['java_home']/jre/lib/security/cacerts` for Java 8 or below and `node['java']['java_home']/lib/security/cacerts` for Java 9+.
- `keystore_passwd`: the keystore password. Defaults to 'changeit' as specified by the Java Documentation.
Only one of the following
- `cert_data`: the certificate data to install
- `cert_file`: path to a certificate file to install
- `ssl_endpoint`: an SSL end-point from which to download the certificate
### Examples
```ruby
java_certificate "Install LDAP server certificate to Java CA keystore for Jenkins" do
cert_alias node['jenkins']['ldap']['url'][/\/\/(.*)/, 1]
ssl_endpoint node['jenkins']['ldap']['url']
action :install
notifies :restart, "runit_service[jenkins]", :delayed
end
```
### java_jce
This cookbook contains the `java_jce` resource, which installs the Java Cryptography Extension (JCE) policy files for a given Java installation. It defaults to installing the JCE files into the Java location defined by cookbook attributes, but it can be customized to install to arbitrary Java locations. Please note that if `node['java']['oracle']['jce']['enabled']` is set to true, this custom resource will be run automatically.
### Actions
- `:install`: Installs the JCE policy files.
### Attribute Parameters
No attributes are required by this resource.
Optional parameters:
- `jdk_version`: The Java version to install into. Defaults to `node['java']['jdk_version']`.
- `jce_url`: The URL for the JCE distribution. Defaults to `node['java']['oracle']['jce'][jdk_version]['url']`.
- `jce_checksum`: The checksum of the JCE distribution. Defaults to `node['java']['oracle']['jce'][jdk_version]['checksum']`.
- `jce_cookie`: Indicates that you accept Oracle's EULA. Defaults to the value of `node['java']['oracle']['accept_oracle_download_terms']`.
- `jce_home`: The location where JCE files will be decompressed for installation. Defaults to `node['java']['oracle']['jce']['home']`.
- `java_home`: The location of the Java installation.. Defaults to `node['java']['java_home']`.
- `principal`: For Windows installations only, this determines the owner of the JCE files. Defaults to `node['java']['windows']['owner']`.
### Examples
``` ruby
# Install the JCE for the default Java installation:
java_jce "Install the JCE files" do
end
# Install the JCE for a Java installation in /opt/tools/jdk8:
java_jce "Install the JCE files" do
java_home "/opt/tools/jdk8"
end
# Install the JCE for a Java 8 installation in /opt/tools/java using a custom download location:
java_jce "Install the JCE files" do
java_home "/opt/tools/java"
jdk_version "8"
jce_url "https://artifacts/path/to/jce/policy.zip"
jce_checksum "deadbeefcafe..."
end
```
## Recommendations for inclusion in community cookbooks
This cookbook is a dependency for many other cookbooks in the Java/Chef sphere. Here are some guidelines for including it into other cookbooks:
### Allow people to not use this cookbook
Many users manage Java on their own or have systems that already have java installed. Give these users an option to skip this cookbook, for example:
```ruby
include_recipe 'java' if node['maven']['install_java']
```
This would allow a users of the maven cookbook to choose if they want the maven cookbook to install java for them or leave that up to the consumer.
Another good example is from the [Jenkins Cookbook Java recipe](https://github.com/opscode-cookbooks/jenkins/commit/ca2a69d982011dc1bec6a6d0ee4da5c1a1599864).
### Pinning to major version of cookbook and Java
This cookbook follows semver. It is recommended to pin at the major version of this cookbook when including it in other cookbooks, eg: `depends 'java', '~> 1.0'`
It is acceptable to set the `node['java']['jdk_version']` to a specific version if required for your software to run, eg software xyz requires Java 8 to run. Refrain from pinning to specific patches of the JDK to allow users to consume security updates.
## Development
This cookbook uses [test-kitchen](https://github.com/test-kitchen/test-kitchen) for integration tests and [ChefSpec/RSpec](https://github.com/sethvargo/chefspec) for unit tests. See [TESTING.md](https://github.com/agileorbit-cookbooks/java/blob/master/TESTING.md) for testing instructions.
At this time due to licensing concerns, the IBM recipe is not set up in test kitchen. If you would like to test this locally, copy .kitchen.yml to .kitchen.local.yml and add the following suite:
```yml
suites:
- name: ibm
run_list: ["recipe[java]"]
attributes:
java:
install_flavor: "ibm"
ibm:
accept_ibm_download_terms: true
url: "http://jenkins/ibm-java-x86_64-sdk-7.0-4.1.bin"
checksum: the-sha256-checksum
```
Log into the IBM DeveloperWorks site to download a copy of the IBM Java SDK you wish to use/test, host it on an internal HTTP server, and calculate the SHA256 checksum to use in the suite.
## Contributors
This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false)
### Backers
Thank you to all our backers!
![https://opencollective.com/sous-chefs#backers](https://opencollective.com/sous-chefs/backers.svg?width=600&avatarHeight=40)
### Sponsors
Support this project by becoming a sponsor. Your logo will show up here with a link to your website.
![https://opencollective.com/sous-chefs/sponsor/0/website](https://opencollective.com/sous-chefs/sponsor/0/avatar.svg?avatarHeight=100)
![https://opencollective.com/sous-chefs/sponsor/1/website](https://opencollective.com/sous-chefs/sponsor/1/avatar.svg?avatarHeight=100)
![https://opencollective.com/sous-chefs/sponsor/2/website](https://opencollective.com/sous-chefs/sponsor/2/avatar.svg?avatarHeight=100)
![https://opencollective.com/sous-chefs/sponsor/3/website](https://opencollective.com/sous-chefs/sponsor/3/avatar.svg?avatarHeight=100)
![https://opencollective.com/sous-chefs/sponsor/4/website](https://opencollective.com/sous-chefs/sponsor/4/avatar.svg?avatarHeight=100)
![https://opencollective.com/sous-chefs/sponsor/5/website](https://opencollective.com/sous-chefs/sponsor/5/avatar.svg?avatarHeight=100)
![https://opencollective.com/sous-chefs/sponsor/6/website](https://opencollective.com/sous-chefs/sponsor/6/avatar.svg?avatarHeight=100)
![https://opencollective.com/sous-chefs/sponsor/7/website](https://opencollective.com/sous-chefs/sponsor/7/avatar.svg?avatarHeight=100)
![https://opencollective.com/sous-chefs/sponsor/8/website](https://opencollective.com/sous-chefs/sponsor/8/avatar.svg?avatarHeight=100)
![https://opencollective.com/sous-chefs/sponsor/9/website](https://opencollective.com/sous-chefs/sponsor/9/avatar.svg?avatarHeight=100)

View File

@@ -0,0 +1,185 @@
#
# Author:: Seth Chisamore (<schisamo@chef.io>)
# Cookbook:: java
# Attributes:: default
#
# Copyright:: 2010-2015, Chef Software, Inc.
#
# 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.
# default jdk attributes
default['java']['download_path'] = Chef::Config[:file_cache_path]
default['java']['jdk_version'] = '8'
default['java']['arch'] = node['kernel']['machine'] =~ /x86_64/ ? 'x86_64' : 'i586'
default['java']['openjdk_packages'] = []
default['java']['openjdk_version'] = nil
default['java']['accept_license_agreement'] = false
default['java']['set_default'] = true
default['java']['alternatives_priority'] = 1062
default['java']['set_etc_environment'] = false
default['java']['use_alt_suffix'] = true
default['java']['reset_alternatives'] = true
# the following retry parameters apply when downloading oracle java
default['java']['ark_retries'] = 0
default['java']['ark_retry_delay'] = 2
default['java']['ark_timeout'] = 600
default['java']['ark_download_timeout'] = 600
case node['platform_family']
when 'windows'
default['java']['install_flavor'] = 'windows'
default['java']['windows']['url'] = nil
default['java']['windows']['checksum'] = nil
default['java']['windows']['package_name'] = 'Java(TM) SE Development Kit 7 (64-bit)'
default['java']['windows']['public_jre_home'] = nil
default['java']['windows']['owner'] = 'administrator'
default['java']['windows']['remove_obsolete'] = false
default['java']['windows']['returns'] = 0
when 'mac_os_x'
default['java']['install_flavor'] = 'homebrew'
else
default['java']['install_flavor'] = 'openjdk'
end
# type of Java installation, can be jdk or jre
default['java']['install_type'] = 'jdk'
# S390(X) - IBM zSeries Architecture - only IBM jre / jdk can be used. Download from https://developer.ibm.com/javasdk/downloads/
if node['kernel']['machine'].start_with?('s390')
default['java']['install_flavor'] = 'ibm'
end
default['java']['ibm']['url'] = nil
default['java']['ibm']['checksum'] = nil
default['java']['ibm']['accept_ibm_download_terms'] = false
default['java']['ibm']['6']['bin_cmds'] = %w(appletviewer apt ControlPanel extcheck HtmlConverter idlj jar jarsigner
java javac javadoc javah javap javaws jconsole jcontrol jdb jdmpview
jrunscript keytool native2ascii policytool rmic rmid rmiregistry
schemagen serialver tnameserv wsgen wsimport xjc)
default['java']['ibm']['7']['bin_cmds'] = node['java']['ibm']['6']['bin_cmds'] + %w(pack200 unpack200)
default['java']['ibm']['8']['bin_cmds'] = node['java']['ibm']['7']['bin_cmds']
# type of java RPM : jdk or jre
default['java']['oracle_rpm']['type'] = 'jdk'
# optional, can be overriden to pin to a version different
# from the up-to-date.
default['java']['oracle_rpm']['package_version'] = nil
# optional, some distros re-package the official Oracle's RPM
# with a different name
default['java']['oracle_rpm']['package_name'] = nil
# if you change this to true, you can download directly from Oracle
default['java']['oracle']['accept_oracle_download_terms'] = false
# direct download paths for oracle, you have been warned!
# jdk8 attributes
default['java']['jdk']['8']['bin_cmds'] = %w(appletviewer apt ControlPanel extcheck idlj jar jarsigner java javac
javadoc javafxpackager javah javap javaws jcmd jconsole jcontrol jdb
jdeps jhat jinfo jjs jmap jmc jps jrunscript jsadebugd jstack
jstat jstatd jvisualvm keytool native2ascii orbd pack200 policytool
rmic rmid rmiregistry schemagen serialver servertool tnameserv
unpack200 wsgen wsimport xjc)
# Official checksums for the latest release can be found at https://www.oracle.com/webfolder/s/digest/8u172checksum.html
# x86_64
default['java']['jdk']['8']['x86_64']['url'] = 'https://download.oracle.com/otn-pub/java/jdk/8u202-b08/1961070e4c9b4e26a04e7f5a083f551e/jdk-8u202-linux-x64.tar.gz'
default['java']['jdk']['8']['x86_64']['checksum'] = '9a5c32411a6a06e22b69c495b7975034409fa1652d03aeb8eb5b6f59fd4594e0'
# i586
default['java']['jdk']['8']['i586']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-i586.tar.gz'
default['java']['jdk']['8']['i586']['checksum'] = '640333e749f24428b78c2b10422f7174f8fbd0b8acde27526c195024fad8b6b6'
# x86_64
default['java']['jdk']['10']['x86_64']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/10.0.1+10/fb4372174a714e6b8c52526dc134031e/jdk-10.0.1_linux-x64_bin.tar.gz'
default['java']['jdk']['10']['x86_64']['checksum'] = 'ae8ed645e6af38432a56a847597ac61d4283b7536688dbab44ab536199d1e5a4'
# i586
default['java']['jdk']['10']['i586']['url'] = 'NOT YET AVAILABLE'
default['java']['jdk']['10']['i586']['checksum'] = 'NOT YET AVAILABLE'
default['java']['jdk']['10']['bin_cmds'] = %w(appletviewer jar javac javapackager jconsole jdeprscan jimage jlink jmod
jshell jstatd orbd rmid serialver unpack200 xjc idlj jarsigner javadoc javaws
jcontrol jdeps jinfo jmap jps jstack jweblauncher pack200 rmiregistry servertool wsgen
jaotc java javap jcmd jdb jhsdb jjs jmc jrunscript jstat keytool rmic schemagen tnameserv
wsimport)
# x86_64
default['java']['jdk']['11']['x86_64']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/11.0.1+13/90cf5d8f270a4347a95050320eef3fb7/jdk-11.0.1_linux-x64_bin.tar.gz'
default['java']['jdk']['11']['x86_64']['checksum'] = 'e7fd856bacad04b6dbf3606094b6a81fa9930d6dbb044bbd787be7ea93abc885'
default['java']['jdk']['11']['bin_cmds'] = %w(jaotc jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan
jdeps jhsdb jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack
jstat jstatd keytool pack200 rmic rmid rmiregistry serialver unpack200
)
default['java']['oracle']['jce']['enabled'] = false
default['java']['oracle']['jce']['10']['url'] = 'https://edelivery.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip'
default['java']['oracle']['jce']['10']['checksum'] = 'f3020a3922efd6626c2fff45695d527f34a8020e938a49292561f18ad1320b59'
default['java']['oracle']['jce']['8']['url'] = 'https://edelivery.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip'
default['java']['oracle']['jce']['8']['checksum'] = 'f3020a3922efd6626c2fff45695d527f34a8020e938a49292561f18ad1320b59'
default['java']['oracle']['jce']['7']['url'] = 'http://ORACLE_HAS_REMOVED_THESE_FILES.SELF_HOST_THEM_INSTEAD'
default['java']['oracle']['jce']['7']['checksum'] = 'CALCULATE_THIS_FROM_YOUR_FILE'
default['java']['oracle']['jce']['6']['url'] = 'http://ORACLE_HAS_REMOVED_THESE_FILES.SELF_HOST_THEM_INSTEAD'
default['java']['oracle']['jce']['6']['checksum'] = 'CALCULATE_THIS_FROM_YOUR_FILE'
default['java']['oracle']['jce']['home'] = '/opt/java_jce'
# AdoptOpenJDK
default['java']['adoptopenjdk']['variant'] = 'openj9'
# AdoptOpenJDK 8
default['java']['adoptopenjdk']['8']['x86_64']['hotspot']['url'] = 'https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u181-b13/OpenJDK8U-jdk_x64_linux_hotspot_8u181b13.tar.gz'
default['java']['adoptopenjdk']['8']['x86_64']['hotspot']['checksum'] = '7cac51df1a976a376e9acd6d053c96ce0fe54db24e5d7079c303d09c416270a2'
default['java']['adoptopenjdk']['8']['x86_64']['openj9']['url'] = 'https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u192-b12/OpenJDK8U-jdk_x64_linux_openj9_8u192b12.tar.gz'
default['java']['adoptopenjdk']['8']['x86_64']['openj9']['checksum'] = '23f7f99c051b45366f0d91a94f8d5465f01bfccdc78f6d62222b1f338e6663eb'
default['java']['adoptopenjdk']['8']['bin_cmds']['default'] = %w(appletviewer extcheck idlj jar jarsigner java javac javadoc javah javap jconsole jdb jdeps jdmpview jextract jjs jrunscript jsadebugd keytool native2ascii orbd pack200 policytool rmic rmid rmiregistry schemagen serialver servertool tnameserv traceformat unpack200 wsgen wsimport xjc)
# AdoptOpenJDK 10
default['java']['adoptopenjdk']['10']['x86_64']['hotspot']['url'] = 'https://github.com/AdoptOpenJDK/openjdk10-releases/releases/download/jdk-10.0.2%2B13/OpenJDK10_x64_Linux_jdk-10.0.2.13.tar.gz'
default['java']['adoptopenjdk']['10']['x86_64']['hotspot']['checksum'] = 'f8caa2e8c28370e3b8e455686e1ddeb74656f068848f8c355d9d8d1c225528f4'
default['java']['adoptopenjdk']['10']['x86_64']['openj9']['url'] = 'https://github.com/AdoptOpenJDK/openjdk10-openj9-releases/releases/download/jdk-10.0.2%2B13_openj9-0.9.0/OpenJDK10-OPENJ9_x64_Linux_jdk-10.0.2.13_openj9-0.9.0.tar.gz'
default['java']['adoptopenjdk']['10']['x86_64']['openj9']['checksum'] = '1ef0dab3853b2f3666091854ef8149fcb85970254558d5d62cfa9446831779d1'
default['java']['adoptopenjdk']['10']['bin_cmds']['default'] = %w(appletviewer idlj jar jarsigner java javac javadoc javap jconsole jdb jdeprscan jdeps jdmpview jextract jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack jstat keytool orbd pack200 rmic rmid rmiregistry schemagen serialver servertool tnameserv traceformat unpack200 wsgen wsimport xjc)
default['java']['adoptopenjdk']['10']['bin_cmds']['hotspot'] = %w(appletviewer idlj jaotc jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jhsdb jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack jstat jstatd keytool orbd pack200 rmic rmid rmiregistry schemagen serialver servertool tnameserv unpack200 wsgen wsimport xjc)
# AdoptOpenJDK 11
default['java']['adoptopenjdk']['11']['x86_64']['hotspot']['url'] = 'https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11%2B28/OpenJDK11-jdk_x64_linux_hotspot_11_28.tar.gz'
default['java']['adoptopenjdk']['11']['x86_64']['hotspot']['checksum'] = 'e1e18fc9ce2917473da3e0acb5a771bc651f600c0195a3cb40ef6f22f21660af'
default['java']['adoptopenjdk']['11']['x86_64']['openj9']['url'] = 'https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.1%2B13/OpenJDK11-jdk_x64_linux_openj9_11.0.1_13.tar.gz'
default['java']['adoptopenjdk']['11']['x86_64']['openj9']['checksum'] = '765947ab9457a29d2aa9d11460a4849611343c1e0ea3b33b9c08409cd4672251'
default['java']['adoptopenjdk']['11']['x86_64']['openj9-large-heap']['url'] = 'https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.1%2B13/OpenJDK11-jdk_x64_linux_openj9_linuxXL_11.0.1_13.tar.gz'
default['java']['adoptopenjdk']['11']['x86_64']['openj9-large-heap']['checksum'] = '0b6050cc670eefd9465370ab19ae70401476430fca329e65f0dd636ca9cce9bd'
default['java']['adoptopenjdk']['11']['bin_cmds']['default'] = %w(jar jarsigner java javac javadoc javap jconsole jdb jdeprscan jdeps jdmpview jextract jimage jjs jlink jrunscript jshell keytool pack200 rmic rmid rmiregistry serialver traceformat unpack200)
default['java']['adoptopenjdk']['11']['bin_cmds']['hotspot'] = %w(jaotc jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jhsdb jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack jstat jstatd keytool pack200 rmic rmid rmiregistry serialver unpack200)
# Placeholders for AdoptOpenJDK 12 when it gets released
default['java']['adoptopenjdk']['12']['x86_64']['hotspot']['url'] = nil
default['java']['adoptopenjdk']['12']['x86_64']['hotspot']['checksum'] = nil
default['java']['adoptopenjdk']['12']['x86_64']['openj9']['url'] = nil
default['java']['adoptopenjdk']['12']['x86_64']['openj9']['checksum'] = nil
default['java']['adoptopenjdk']['12']['x86_64']['openj9-large-heap']['url'] = nil
default['java']['adoptopenjdk']['12']['x86_64']['openj9-large-heap']['checksum'] = nil
# TODO: Update list when released
default['java']['adoptopenjdk']['12']['bin_cmds']['default'] = %w(jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jhsdb jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack jstat jstatd keytool pack200 rmic rmid rmiregistry serialver unpack200)
# Amazon Corretto
default['java']['corretto']['8']['x86_64']['url'] = 'https://d3pxv6yz143wms.cloudfront.net/8.222.10.1/amazon-corretto-8.222.10.1-linux-x64.tar.gz'
default['java']['corretto']['8']['x86_64']['checksum'] = '6599a081ce56dda81ee7ac23802d6e67'
default['java']['corretto']['8']['bin_cmds'] = %w(appletviewer clhsdb extcheck hsdb idlj jar jarsigner java java-rmi.cgi javac javadoc javafxpackager javah javap javapackager jcmd jconsole jdb jdeps jhat jinfo jjs jmap jps jrunscript jsadebugd jstack jstat jstatd keytool native2ascii orbd pack200 policytool rmic rmid rmiregistry schemagen serialver servertool tnameserv unpack200 wsgen wsimport xjc)
default['java']['corretto']['11']['x86_64']['url'] = 'https://d3pxv6yz143wms.cloudfront.net/11.0.4.11.1/amazon-corretto-11.0.4.11.1-linux-x64.tar.gz'
default['java']['corretto']['11']['x86_64']['checksum'] = '4bbcd5e6d721fef56e46b3bfa8631c1c'
default['java']['corretto']['11']['bin_cmds'] = %w(jaotc jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jhsdb jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack jstat jstatd keytool pack200 rmic rmid rmiregistry serialver unpack200)

View File

@@ -0,0 +1,88 @@
#
# Author:: Joshua Timberman <joshua@chef.io>
# Copyright:: Copyright (c) 2013-2015, Chef Software, Inc. <legal@chef.io>
#
# 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.
#
require 'chef/version_constraint'
require 'uri'
require 'pathname'
module ChefCookbook
class OpenJDK
attr_accessor :java_home, :jdk_version
def initialize(node)
@node = node.to_hash
@java_home = @node['java']['java_home'] || '/usr/lib/jvm/default-java'
@jdk_version = @node['java']['jdk_version'].to_s || '6'
end
def java_location
File.join(java_home_parent(@java_home), openjdk_path, 'bin/java')
end
def java_home_parent(java_home)
Pathname.new(java_home).parent.to_s
end
def openjdk_path
case @node['platform_family']
when 'debian'
format('java-%s-openjdk%s/jre', @jdk_version, arch_dir)
when 'rhel', 'fedora', 'amazon'
path = @node['java']['jdk_version'].to_i < 11 ? 'jre-1.%s.0-openjdk%s' : 'java-%s'
format(path, @jdk_version, arch_dir)
else
'jre'
end
end
def arch_dir
@node['kernel']['machine'] == 'x86_64' ? sixty_four : thirty_two
end
def sixty_four
case @node['platform_family']
when 'debian'
'-amd64'
when 'rhel', 'fedora', 'amazon'
'.x86_64'
else
'-x86_64'
end
end
def thirty_two
case @node['platform_family']
when 'debian'
'-i386'
else
''
end
end
end
end
class Chef
class Recipe
def valid_ibm_jdk_uri?(url)
url =~ ::URI::ABS_URI && %w(file http https).include?(::URI.parse(url).scheme)
end
def platform_requires_license_acceptance?
%w(smartos).include?(node['platform'])
end
end
end

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,28 @@
name 'java'
maintainer 'Sous Chefs'
maintainer_email 'help@sous-chefs.org'
license 'Apache-2.0'
description 'Recipes and resources for installing Java and managing certificates'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '4.3.0'
supports 'debian'
supports 'ubuntu'
supports 'centos'
supports 'redhat'
supports 'scientific'
supports 'fedora'
supports 'amazon'
supports 'oracle'
supports 'freebsd'
supports 'windows'
supports 'suse'
supports 'opensuseleap'
supports 'mac_os_x'
depends 'homebrew'
depends 'windows'
source_url 'https://github.com/sous-chefs/java'
issues_url 'https://github.com/sous-chefs/java/issues'
chef_version '>= 13.4'

View File

@@ -0,0 +1,46 @@
# Cookbook:: java
# Recipe:: adoptopenjdk
include_recipe 'java::notify'
unless node.recipe?('java::default')
Chef::Log.warn('Using java::default instead is recommended.')
# Even if this recipe is included by itself, a safety check is nice...
if node['java']['java_home'].nil? || node['java']['java_home'].empty?
include_recipe 'java::set_attributes_from_version'
end
end
include_recipe 'java::set_java_home'
java_home = node['java']['java_home']
arch = node['java']['arch']
version = node['java']['jdk_version'].to_s
variant = node['java']['adoptopenjdk']['variant']
tarball_url = node['java']['adoptopenjdk'][version][arch][variant]['url']
tarball_checksum = node['java']['adoptopenjdk'][version][arch][variant]['checksum']
bin_cmds = if node['java']['adoptopenjdk'][version]['bin_cmds'].key?(variant)
node['java']['adoptopenjdk'][version]['bin_cmds'][variant]
else
node['java']['adoptopenjdk'][version]['bin_cmds']['default']
end
adoptopenjdk_install 'adoptopenjdk' do
url tarball_url
default node['java']['set_default']
checksum tarball_checksum
app_home java_home
bin_cmds bin_cmds
alternatives_priority node['java']['alternatives_priority']
retries node['java']['ark_retries']
retry_delay node['java']['ark_retry_delay']
reset_alternatives node['java']['reset_alternatives']
variant variant
action :install
notifies :write, 'log[jdk-version-changed]', :immediately
end
if node['java']['set_default'] && platform_family?('debian')
include_recipe 'java::default_java_symlink'
end

View File

@@ -0,0 +1,46 @@
# Cookbook:: java
# Recipe:: corretto
# This recipe installs and configures Amazon's Corretto package
# https://aws.amazon.com/corretto/
include_recipe 'java::notify'
unless node.recipe?('java::default')
Chef::Log.warn('Using java::default instead is recommended.')
# Even if this recipe is included by itself, a safety check is nice...
if node['java']['java_home'].nil? || node['java']['java_home'].empty?
include_recipe 'java::set_attributes_from_version'
end
end
java_home = node['java']['java_home']
arch = node['java']['arch']
version = node['java']['jdk_version'].to_s
tarball_url = node['java']['corretto'][version][arch]['url']
tarball_checksum = node['java']['corretto'][version][arch]['checksum']
bin_cmds = node['java']['corretto'][version]['bin_cmds']
include_recipe 'java::set_java_home'
java_oracle_install 'jdk' do
url tarball_url
default node['java']['set_default']
md5 tarball_checksum
app_home java_home
bin_cmds bin_cmds
alternatives_priority node['java']['alternatives_priority']
retries node['java']['ark_retries']
retry_delay node['java']['ark_retry_delay']
connect_timeout node['java']['ark_timeout']
use_alt_suffix node['java']['use_alt_suffix']
reset_alternatives node['java']['reset_alternatives']
download_timeout node['java']['ark_download_timeout']
proxy node['java']['ark_proxy']
action :install
notifies :write, 'log[jdk-version-changed]', :immediately
end
if node['java']['set_default'] && platform_family?('debian')
include_recipe 'java::default_java_symlink'
end

View File

@@ -0,0 +1,22 @@
#
# Author:: Seth Chisamore (<schisamo@chef.io>)
# Cookbook:: java
# Recipe:: default
#
# Copyright:: 2008-2015, Chef Software, Inc.
#
# 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'
include_recipe "java::#{node['java']['install_flavor']}"

View File

@@ -0,0 +1,19 @@
# Cookbook:: java
# Recipe:: default_java_symlink
#
# 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.
link '/usr/lib/jvm/default-java' do
to node['java']['java_home']
not_if { node['java']['java_home'] == '/usr/lib/jvm/default-java' }
end

View File

@@ -0,0 +1,8 @@
include_recipe 'homebrew'
include_recipe 'homebrew::cask'
include_recipe 'java::notify'
homebrew_tap 'caskroom/versions'
homebrew_cask "java#{node['java']['jdk_version']}" do
notifies :write, 'log[jdk-version-changed]', :immediately
end

View File

@@ -0,0 +1,83 @@
# Author:: Joshua Timberman (<joshua@chef.io>)
# Cookbook:: java
# Recipe:: ibm
#
# Copyright:: 2013-2015, Chef Software, Inc.
#
# 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.
require 'uri'
include_recipe 'java::notify'
# If you need to override this in an attribute file you must use
# force_default or higher precedence.
node.default['java']['java_home'] = '/opt/ibm/java'
source_url = node['java']['ibm']['url']
jdk_uri = ::URI.parse(source_url)
jdk_filename = ::File.basename(jdk_uri.path)
unless valid_ibm_jdk_uri?(source_url)
raise "You must set the attribute `node['java']['ibm']['url']` to a valid HTTP URI"
end
# "installable package" installer needs rpm on Ubuntu
package 'rpm' do
action :install
only_if { platform_family?('debian') && jdk_filename !~ /archive/ }
end
template "#{node['java']['download_path']}/installer.properties" do
source 'ibm_jdk.installer.properties.erb'
only_if { node['java']['ibm']['accept_ibm_download_terms'] }
end
remote_file "#{node['java']['download_path']}/#{jdk_filename}" do
source source_url
mode '0755'
if node['java']['ibm']['checksum']
checksum node['java']['ibm']['checksum']
action :create
else
action :create_if_missing
end
notifies :run, 'execute[install-ibm-java]', :immediately
end
java_alternatives 'set-java-alternatives' do
java_location node['java']['java_home']
default node['java']['set_default']
case node['java']['jdk_version'].to_s
when '6'
bin_cmds node['java']['ibm']['6']['bin_cmds']
when '7'
bin_cmds node['java']['ibm']['7']['bin_cmds']
when '8'
bin_cmds node['java']['ibm']['8']['bin_cmds']
end
action :nothing
end
execute 'install-ibm-java' do
cwd node['java']['download_path']
environment('_JAVA_OPTIONS' => '-Dlax.debug.level=3 -Dlax.debug.all=true',
'LAX_DEBUG' => '1')
command "./#{jdk_filename} -f ./installer.properties -i silent"
creates "#{node['java']['java_home']}/jre/bin/java"
notifies :set, 'java_alternatives[set-java-alternatives]', :immediately
notifies :write, 'log[jdk-version-changed]', :immediately
end
include_recipe 'java::set_java_home'

View File

@@ -0,0 +1,79 @@
# Cookbook:: java
# Recipe:: ibm_tar
#
# Copyright:: 2013-2015, Chef Software, Inc.
#
# 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.
require 'uri'
include_recipe 'java::notify'
# If you need to override this in an attribute file you must use
# force_default or higher precedence.
node.default['java']['java_home'] = '/opt/ibm/java'
source_url = node['java']['ibm']['url']
jdk_uri = ::URI.parse(source_url)
jdk_filename = ::File.basename(jdk_uri.path)
unless valid_ibm_jdk_uri?(source_url)
raise "You must set the attribute `node['java']['ibm']['url']` to a valid URI"
end
unless jdk_filename =~ /\.(tar.gz|tgz)$/
raise "The attribute `node['java']['ibm']['url']` must specify a .tar.gz file"
end
remote_file "#{node['java']['download_path']}/#{jdk_filename}" do
source source_url
mode '0755'
if node['java']['ibm']['checksum']
checksum node['java']['ibm']['checksum']
action :create
else
action :create_if_missing
end
notifies :create, 'directory[create-java-home]', :immediately
notifies :run, 'execute[untar-ibm-java]', :immediately
end
directory 'create-java-home' do
path node['java']['java_home']
mode '0755'
recursive true
end
java_alternatives 'set-java-alternatives' do
java_location node['java']['java_home']
default node['java']['set_default']
case node['java']['jdk_version'].to_s
when '6'
bin_cmds node['java']['ibm']['6']['bin_cmds']
when '7'
bin_cmds node['java']['ibm']['7']['bin_cmds']
when '8'
bin_cmds node['java']['ibm']['8']['bin_cmds']
end
action :nothing
end
execute 'untar-ibm-java' do
cwd node['java']['download_path']
command "tar xzf ./#{jdk_filename} -C #{node['java']['java_home']} --strip 1"
notifies :set, 'java_alternatives[set-java-alternatives]', :immediately
notifies :write, 'log[jdk-version-changed]', :immediately
creates "#{node['java']['java_home']}/jre/bin/java"
end
include_recipe 'java::set_java_home'

View File

@@ -0,0 +1,33 @@
#
# Author:: Eric Helgeson (<eric@agileorbit.com>)
# Cookbook:: java
# Recipe:: notify
#
# Copyright:: 2008-2015, Chef Software, Inc.
#
# 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.
#
# This resource is avalible for other recipes to subscribe to so they can be
# notified of a JDK change. For example you want to restart a service to take
# advantage of the new JDK
# eg:
# service 'somejavaservice'
# action :restart
# subscribes :write, 'log[jdk-version-changed]', :delayed
# end
log 'jdk-version-changed' do
message 'A new version of java was installed'
level :info
action :nothing
end

View File

@@ -0,0 +1,72 @@
# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
# Author:: Seth Chisamore (<schisamo@chef.io>)
# Author:: Joshua Timberman (<joshua@chef.io>)
#
# Cookbook:: java
# Recipe:: openjdk
#
# Copyright:: 2010-2015, Chef Software, Inc.
#
# 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::notify'
unless node.recipe?('java::default')
Chef::Log.warn('Using java::default instead is recommended.')
# Even if this recipe is included by itself, a safety check is nice...
[node['java']['openjdk_packages'], node['java']['java_home']].each do |v|
include_recipe 'java::set_attributes_from_version' if v.nil? || v.empty?
end
end
jdk = ChefCookbook::OpenJDK.new(node)
if platform_requires_license_acceptance?
file '/opt/local/.dlj_license_accepted' do
owner 'root'
group 'root'
mode '0400'
action :create
only_if { node['java']['accept_license_agreement'] }
end
end
if node['platform'] == 'ubuntu'
apt_repository 'openjdk-r-ppa' do
uri 'ppa:openjdk-r'
distribution node['lsb']['codename']
end
end
package node['java']['openjdk_packages'] do
version node['java']['openjdk_version'] if node['java']['openjdk_version']
notifies :write, 'log[jdk-version-changed]', :immediately
end
java_alternatives 'set-java-alternatives' do
java_location jdk.java_home
default node['java']['set_default']
priority 1100
bin_cmds node['java']['jdk'][node['java']['jdk_version'].to_s]['bin_cmds']
action :set
only_if { platform_family?('debian', 'rhel', 'fedora', 'amazon') }
end
if node['java']['set_default'] && platform_family?('debian')
include_recipe 'java::default_java_symlink'
end
# We must include this recipe AFTER updating the alternatives or else JAVA_HOME
# will not point to the correct java.
include_recipe 'java::set_java_home'

View File

@@ -0,0 +1,62 @@
#
# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
# Cookbook:: java
# Recipe:: oracle
#
# Copyright:: 2011, Bryan w. Berry
#
# 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::notify'
unless node.recipe?('java::default')
Chef::Log.warn('Using java::default instead is recommended.')
# Even if this recipe is included by itself, a safety check is nice...
if node['java']['java_home'].nil? || node['java']['java_home'].empty?
include_recipe 'java::set_attributes_from_version'
end
end
java_home = node['java']['java_home']
arch = node['java']['arch']
version = node['java']['jdk_version'].to_s
tarball_url = node['java']['jdk'][version][arch]['url']
tarball_checksum = node['java']['jdk'][version][arch]['checksum']
bin_cmds = node['java']['jdk'][version]['bin_cmds']
include_recipe 'java::set_java_home'
java_oracle_install 'jdk' do
url tarball_url
default node['java']['set_default']
checksum tarball_checksum
app_home java_home
bin_cmds bin_cmds
alternatives_priority node['java']['alternatives_priority']
retries node['java']['ark_retries']
retry_delay node['java']['ark_retry_delay']
connect_timeout node['java']['ark_timeout']
use_alt_suffix node['java']['use_alt_suffix']
reset_alternatives node['java']['reset_alternatives']
download_timeout node['java']['ark_download_timeout']
proxy node['java']['ark_proxy']
action :install
notifies :write, 'log[jdk-version-changed]', :immediately
end
if node['java']['set_default'] && platform_family?('debian')
include_recipe 'java::default_java_symlink'
end
include_recipe 'java::oracle_jce' if node['java']['oracle']['jce']['enabled']

View File

@@ -0,0 +1,74 @@
#
# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
# Cookbook:: java
# Recipe:: oracle_i386
#
# Copyright:: 2010-2015, Chef Software, Inc.
#
# 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::notify'
unless node.recipe?('java::default')
Chef::Log.warn('Using java::default instead is recommended.')
# Even if this recipe is included by itself, a safety check is nice...
if node['java']['java_home'].nil? || node['java']['java_home'].empty?
include_recipe 'java::set_attributes_from_version'
end
end
java_home = node['java']['java_home']
case node['java']['jdk_version'].to_s
when '6'
tarball_url = node['java']['jdk']['6']['i586']['url']
tarball_checksum = node['java']['jdk']['6']['i586']['checksum']
bin_cmds = node['java']['jdk']['6']['bin_cmds']
when '7'
tarball_url = node['java']['jdk']['7']['i586']['url']
tarball_checksum = node['java']['jdk']['7']['i586']['checksum']
bin_cmds = node['java']['jdk']['7']['bin_cmds']
when '8'
tarball_url = node['java']['jdk']['8']['i586']['url']
tarball_checksum = node['java']['jdk']['8']['i586']['checksum']
bin_cmds = node['java']['jdk']['8']['bin_cmds']
end
include_recipe 'java::set_java_home'
yum_package 'glibc' do
arch 'i686'
only_if { platform_family?('rhel', 'fedora', 'amazon') }
end
java_oracle_install 'jdk-alt' do
url tarball_url
default node['java']['set_default']
checksum tarball_checksum
app_home java_home
bin_cmds bin_cmds
retries node['java']['ark_retries']
retry_delay node['java']['ark_retries']
use_alt_suffix node['java']['use_alt_suffix']
reset_alternatives node['java']['reset_alternatives']
action :install
default false
notifies :write, 'log[jdk-version-changed]', :immediately
end
if node['java']['set_default'] && platform_family?('debian')
include_recipe 'java::default_java_symlink'
end
include_recipe 'java::oracle_jce' if node['java']['oracle']['jce']['enabled']

View File

@@ -0,0 +1,21 @@
#
# Author:: Kyle McGovern (<spion06@gmail.com>)
# Cookbook:: java
# Recipe:: oracle_jce
#
# Copyright:: 2014, Kyle McGovern
#
# 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.
jdk_version = node['java']['jdk_version'].to_s
java_jce "Install JCE for JDK #{jdk_version}"

View File

@@ -0,0 +1,61 @@
# Author:: Christophe Arguel (<christophe.arguel@free.fr>)
#
# Cookbook:: java
# Recipe:: oracle_rpm
#
# Copyright:: 2013, Christophe Arguel <christophe.arguel@free.fr>
#
# 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.
# If you need to override this in an attribute file you must use
# force_default or higher precedence.
node.default['java']['java_home'] = '/usr/java/latest'
include_recipe 'java::set_java_home'
include_recipe 'java::notify'
slave_cmds = case node['java']['oracle_rpm']['type']
when 'jdk'
%w(appletviewer apt ControlPanel extcheck idlj jar jarsigner javac javadoc javafxpackager javah javap java-rmi.cgi javaws jcmd jconsole jcontrol jdb jhat jinfo jmap jps jrunscript jsadebugd jstack jstat jstatd jvisualvm keytool native2ascii orbd pack200 policytool rmic rmid rmiregistry schemagen serialver servertool tnameserv unpack200 wsgen wsimport xjc)
when 'jre'
%w(ControlPanel java_vm javaws jcontrol keytool orbd pack200 policytool rmid rmiregistry servertool tnameserv unpack200)
else
Chef::Application.fatal!("Unsupported oracle RPM type (#{node['java']['oracle_rpm']['type']})")
end
bash 'update-java-alternatives' do
java_home = node['java']['java_home']
java_location = File.join(java_home, 'bin', 'java')
slave_lines = slave_cmds.inject('') do |slaves, cmd|
slaves << "--slave /usr/bin/#{cmd} #{cmd} #{File.join(java_home, 'bin', cmd)} \\\n"
end
code <<-EOH.gsub(/^\s+/, '')
update-alternatives --install /usr/bin/java java #{java_location} #{node['java']['alternatives_priority']} \
#{slave_lines} && \
update-alternatives --set java #{java_location}
EOH
action :nothing
end
package_name = node['java']['oracle_rpm']['package_name'] || node['java']['oracle_rpm']['type']
package package_name do
action :install
version node['java']['oracle_rpm']['package_version'] if node['java']['oracle_rpm']['package_version']
notifies :run, 'bash[update-java-alternatives]', :immediately if platform_family?('rhel', 'fedora', 'amazon') && node['java']['set_default']
notifies :write, 'log[jdk-version-changed]', :immediately
end
include_recipe 'java::oracle_jce' if node['java']['oracle']['jce']['enabled']

View File

@@ -0,0 +1,76 @@
# Cookbook:: java
# Recipe:: set_attributes_from_version
#
# 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.
# Calculate variables that depend on jdk_version
# If you need to override this in an attribute file you must use
# force_default or higher precedence.
case node['platform_family']
when 'rhel', 'fedora', 'amazon'
node.default['java']['java_home'] = case node['java']['install_flavor']
when 'adoptopenjdk'
"/usr/lib/jvm/java-#{node['java']['jdk_version'].to_i}-#{node['java']['install_flavor']}-#{node['java']['adoptopenjdk']['variant']}"
when 'oracle'
'/usr/lib/jvm/java'
when 'oracle_rpm'
'/usr/java/latest'
else
node['java']['jdk_version'].to_i < 11 ? "/usr/lib/jvm/java-1.#{node['java']['jdk_version']}.0" : "/usr/lib/jvm/java-#{node['java']['jdk_version']}"
end
node.default['java']['openjdk_packages'] = node['java']['jdk_version'].to_i < 11 ? ["java-1.#{node['java']['jdk_version']}.0-openjdk", "java-1.#{node['java']['jdk_version']}.0-openjdk-devel"] : ["java-#{node['java']['jdk_version']}-openjdk", "java-#{node['java']['jdk_version']}-openjdk-devel"]
when 'suse'
node.default['java']['java_home'] = case node['java']['install_flavor']
when 'adoptopenjdk'
"/usr/lib/jvm/java-#{node['java']['jdk_version'].to_i}-#{node['java']['install_flavor']}-#{node['java']['adoptopenjdk']['variant']}"
when 'oracle'
'/usr/lib/jvm/java'
when 'oracle_rpm'
'/usr/java/latest'
else
"/usr/lib#{node['kernel']['machine'] == 'x86_64' ? '64' : nil}/jvm/java-1.#{node['java']['jdk_version']}.0"
end
node.default['java']['openjdk_packages'] = ["java-1_#{node['java']['jdk_version']}_0-openjdk", "java-1_#{node['java']['jdk_version']}_0-openjdk-devel"]
when 'freebsd'
node.default['java']['java_home'] = "/usr/local/openjdk#{node['java']['jdk_version']}"
jdk_version = node['java']['jdk_version']
openjdk_package = jdk_version == '7' ? 'openjdk' : "openjdk#{node['java']['jdk_version']}"
node.default['java']['openjdk_packages'] = [openjdk_package]
when 'arch'
node.default['java']['java_home'] = "/usr/lib/jvm/java-#{node['java']['jdk_version']}-openjdk"
node.default['java']['openjdk_packages'] = ["openjdk#{node['java']['jdk_version']}"]
when 'debian'
node.default['java']['java_home'] = case node['java']['install_flavor']
when 'adoptopenjdk'
"/usr/lib/jvm/java-#{node['java']['jdk_version'].to_i}-#{node['java']['install_flavor']}-#{node['java']['adoptopenjdk']['variant']}"
else
"/usr/lib/jvm/java-#{node['java']['jdk_version']}-#{node['java']['install_flavor']}-#{node['kernel']['machine'] == 'x86_64' ? 'amd64' : 'i386'}"
end
node.default['java']['openjdk_packages'] = ["openjdk-#{node['java']['jdk_version']}-jdk", "openjdk-#{node['java']['jdk_version']}-jre-headless"]
when 'smartos'
node.default['java']['java_home'] = '/opt/local/java/sun6'
node.default['java']['openjdk_packages'] = ["sun-jdk#{node['java']['jdk_version']}", "sun-jre#{node['java']['jdk_version']}"]
when 'windows'
node.default['java']['java_home'] = nil
when 'mac_os_x'
java_home = if node['java']['jdk_version'].to_i >= 10
"$(/usr/libexec/java_home -v #{node['java']['jdk_version']})"
else
"$(/usr/libexec/java_home -v 1.#{node['java']['jdk_version']})"
end
node.default['java']['java_home'] = java_home
else
node.default['java']['java_home'] = '/usr/lib/jvm/default-java'
node.default['java']['openjdk_packages'] = ["openjdk-#{node['java']['jdk_version']}-jdk"]
end

View File

@@ -0,0 +1,37 @@
# Author:: Joshua Timberman (<joshua@chef.io>)
# Cookbook:: java
# Recipe:: set_java_home
#
# Copyright:: 2013-2015, Chef Software, Inc.
#
# 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.
directory '/etc/profile.d' do
mode '0755'
end
template '/etc/profile.d/jdk.sh' do
source 'jdk.sh.erb'
mode '0755'
end
if node['java']['set_etc_environment']
ruby_block 'Set JAVA_HOME in /etc/environment' do
block do
file = Chef::Util::FileEdit.new('/etc/environment')
file.insert_line_if_no_match(/^JAVA_HOME=/, "JAVA_HOME=#{node['java']['java_home']}")
file.search_file_replace_line(/^JAVA_HOME=/, "JAVA_HOME=#{node['java']['java_home']}")
file.write_file
end
end
end

View File

@@ -0,0 +1,109 @@
#
# Author:: Kendrick Martin (<kendrick.martin@webtrends.com>)
# Cookbook:: java
# Recipe:: windows
#
# Copyright:: 2008-2012 Webtrends, Inc.
#
# 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.
#
require 'uri'
include_recipe 'java::notify'
Chef::Log.fatal('No download url set for java installer.') unless node['java'] && node['java']['windows'] && node['java']['windows']['url']
pkg_checksum = node['java']['windows']['checksum']
aws_access_key_id = node['java']['windows']['aws_access_key_id']
aws_secret_access_key = node['java']['windows']['aws_secret_access_key']
aws_session_token = node['java']['windows']['aws_session_token']
s3_bucket = node['java']['windows']['bucket']
s3_remote_path = node['java']['windows']['remote_path']
uri = ::URI.parse(node['java']['windows']['url'])
cache_file_path = File.join(node['java']['download_path'], File.basename(::URI.unescape(uri.path)))
if s3_bucket && s3_remote_path
aws_s3_file cache_file_path do
aws_access_key_id aws_access_key_id
aws_secret_access_key aws_secret_access_key
aws_session_token aws_session_token
checksum pkg_checksum if pkg_checksum
bucket s3_bucket
remote_path s3_remote_path
backup false
action :create
end
else
ruby_block 'Enable Accessing cookies' do
block do
cookie_jar = Chef::HTTP::CookieJar
cookie_jar.instance["#{uri.host}:#{uri.port}"] = 'oraclelicense=accept-securebackup-cookie'
end
only_if { node['java']['oracle']['accept_oracle_download_terms'] }
end
remote_file cache_file_path do
checksum pkg_checksum if pkg_checksum
source node['java']['windows']['url']
backup false
action :create
end
end
if node['java'].attribute?('java_home') && !node['java']['java_home'].nil?
java_home_win = win_friendly_path(node['java']['java_home'])
additional_options = if node['java']['jdk_version'].to_s == '8'
# Seems that the jdk 8 EXE installer does not need anymore the /v /qn flags
"INSTALLDIR=\"#{java_home_win}\""
else
# The jdk 7 EXE installer expects escaped quotes, so we need to double escape
# them here. The final string looks like :
# /v"/qn INSTALLDIR=\"C:\Program Files\Java\""
"/v\"/qn INSTALLDIR=\\\"#{java_home_win}\\\"\""
end
env 'JAVA_HOME' do
value java_home_win
end
# update path
windows_path "#{java_home_win}\\bin" do
action :add
end
end
if node['java']['windows'].attribute?('public_jre_home') && node['java']['windows']['public_jre_home']
java_publicjre_home_win = win_friendly_path(node['java']['windows']['public_jre_home'])
additional_options = "#{additional_options} /INSTALLDIRPUBJRE=\"#{java_publicjre_home_win}\""
end
if node['java']['windows'].attribute?('remove_obsolete') && node['java']['windows']['remove_obsolete']
additional_options = "#{additional_options} REMOVEOUTOFDATEJRES=1"
end
windows_package node['java']['windows']['package_name'] do
source cache_file_path
checksum node['java']['windows']['checksum']
action :install
returns node['java']['windows']['returns']
installer_type :custom
options "/s #{additional_options}"
notifies :write, 'log[jdk-version-changed]', :immediately
end
include_recipe 'java::oracle_jce' if node['java']['oracle']['jce']['enabled']

View File

@@ -0,0 +1,202 @@
#
# Cookbook:: java
# Resource:: adoptopenjdk_install
#
# Based on oracle_install.rb by Bryan W. Berry (<bryan.berry@gmail.com>)
#
resource_name :adoptopenjdk_install
default_action :install
property :url, String
property :checksum, String, regex: /^[0-9a-f]{32}$|^[a-zA-Z0-9]{40,64}$/
property :md5, String, regex: /^[0-9a-f]{32}$|^[a-zA-Z0-9]{40,64}$/
property :app_home, String
property :app_home_mode, Integer, default: 0755
property :bin_cmds, Array, default: []
property :owner, String, default: 'root'
property :group, String, default: lazy { node['root_group'] }
property :default, [true, false], default: true
property :alternatives_priority, Integer, default: 1
property :reset_alternatives, [true, false], default: true
property :variant, ['hotspot', 'openj9', 'openj9-large-heap'], default: 'openj9'
action :install do
raise 'No URL provided to download AdoptOpenJDK\'s tar file!' if new_resource.url.nil? || new_resource.url.empty?
app_dir_name, tarball_name, app_root, app_dir =
parse_dir_names(new_resource.url,
new_resource.app_home,
new_resource.variant)
app_group = new_resource.group
app_home = new_resource.app_home
Chef::Log.debug("processing #{new_resource.variant} variant")
directory app_root do
owner new_resource.owner
group app_group
mode new_resource.app_home_mode
recursive true
action :nothing
end.run_action(:create)
unless ::File.exist?(app_dir)
download_path = "#{node['java']['download_path']}/#{tarball_name}"
if adoptopendjk_downloaded?(download_path, new_resource)
Chef::Log.debug('AdoptOpenJDK tarball already downloaded, not downloading again')
else
Chef::Log.debug("downloading tarball from #{URI.parse(new_resource.url).host}")
remote_file "#{node['java']['download_path']}/#{tarball_name}" do
source new_resource.url
checksum new_resource.checksum
retries new_resource.retries
retry_delay new_resource.retry_delay
mode 0o644
action :nothing
end.run_action(:create_if_missing)
end
converge_by("extract compressed data into Chef file cache path and move extracted data to #{app_dir}") do
package 'tar' do
not_if { platform_family?('mac_os_x', 'windows') }
action :nothing
end.run_action(:install)
cmd = shell_out(%(tar xvzf "#{node['java']['download_path']}/#{tarball_name}" -C "#{node['java']['download_path']}" --no-same-owner)
)
unless cmd.exitstatus == 0
Chef::Application.fatal!("Failed to extract file #{tarball_name}!")
end
cmd = shell_out(
%(mv "#{node['java']['download_path']}/#{app_dir_name}" "#{app_dir}" )
)
unless cmd.exitstatus == 0
Chef::Application.fatal!(%( Command \' mv "#{node['java']['download_path']}/#{app_dir_name}" "#{app_dir}" \' failed ))
end
# change ownership of extracted files
FileUtils.chown_R new_resource.owner, app_group, app_dir
end
end
# set up .jinfo file for update-java-alternatives
java_name, jinfo_file = alternatives_config_file(app_root, app_home)
if platform_family?('debian') && !::File.exist?(jinfo_file)
converge_by("Add #{jinfo_file} for debian") do
template jinfo_file do
cookbook 'java'
source 'adoptopenjdk.jinfo.erb'
owner new_resource.owner
group app_group
variables(
priority: new_resource.alternatives_priority,
bin_cmds: new_resource.bin_cmds,
name: java_name,
app_dir: app_home
)
action :nothing
end.run_action(:create)
end
end
# link app_home to app_dir
Chef::Log.debug "app_home is #{app_home} and app_dir is #{app_dir}"
current_link = ::File.symlink?(app_home) ? ::File.readlink(app_home) : nil
if current_link != app_dir
converge_by("symlink #{app_dir} to #{app_home}") do
FileUtils.rm_f app_home
FileUtils.ln_sf app_dir, app_home
FileUtils.chown new_resource.owner, app_group, app_home
end
end
# update-alternatives
java_alternatives 'set-java-alternatives' do
java_location app_home
bin_cmds new_resource.bin_cmds
priority new_resource.alternatives_priority
default new_resource.default
reset_alternatives new_resource.reset_alternatives
action :set
end
end
action :remove do
raise 'No URL provided for AdoptOpenJDK\'s tar file!' if new_resource.url.nil? || new_resource.url.empty?
_app_dir_name, _tarball_name, _app_root, app_dir =
parse_dir_names(new_resource.url,
new_resource.app_home,
new_resource.variant)
app_home = new_resource.app_home
Chef::Log.debug("processing #{new_resource.variant} variant")
if ::File.exist?(app_dir)
java_alternatives 'unset-java-alternatives' do
java_location app_home
bin_cmds new_resource.bin_cmds
action :unset
end
directory "AdoptOpenJDK removal of #{app_home}" do
path app_home
recursive true
action :delete
end
directory "AdoptOpenJDK removal of #{app_dir}" do
path app_dir
recursive true
action :delete
end
end
end
action_class do
require 'uri'
def parse_app_dir_name(url)
uri = URI.parse(url)
file_name = uri.path.split('/').last
if file_name =~ /jdk\d+u\d+-b\d+/ # OpenJDK8
dir_name_results = file_name.scan(/_(jdk\d+u\d+-b\d+)(?:_openj[-.\d]+)?\.tar\.gz$/)
app_dir_name = dir_name_results[0][0] unless dir_name_results.empty?
elsif file_name =~ /_\d+u\d+b\d+\.tar\.gz$/ # OpenJDK8U
dir_name_results = file_name.scan(/_(\d+u\d+)(b\d+)\.tar\.gz$/)
app_dir_name = "jdk#{dir_name_results[0][0]}-#{dir_name_results[0][1]}" unless dir_name_results.empty?
else
dir_name_results = file_name.scan(/[-_]([.\d]+)[._]([\d]+)(?:_openj[-.\d]+)?\.tar\.gz$/)
app_dir_name = "jdk-#{dir_name_results[0][0]}+#{dir_name_results[0][1]}" unless dir_name_results.empty?
end
Chef::Application.fatal!("Failed to parse #{file_name} for application directory name!") if dir_name_results.empty?
[app_dir_name, file_name]
end
def parse_dir_names(url, app_home, variant)
app_dir_name, tarball_name = parse_app_dir_name(url)
app_root = app_home.split('/')[0..-2].join('/')
app_dir = "#{app_root}/#{app_dir_name}-#{variant}"
[app_dir_name, tarball_name, app_root, app_dir]
end
def alternatives_config_file(app_root, app_home)
java_name = app_home.split('/')[-1]
config_file = "#{app_root}/.#{java_name}.jinfo"
[java_name, config_file]
end
def adoptopendjk_downloaded?(download_path, new_resource)
if ::File.exist? download_path
require 'openssl'
if new_resource.checksum =~ /^[0-9a-f]{32}$/
downloaded_md5 = OpenSSL::Digest::MD5.file(download_path).hexdigest
downloaded_md5 == new_resource.checksum
else
downloaded_sha = OpenSSL::Digest::SHA256.file(download_path).hexdigest
downloaded_sha == new_resource.checksum
end
else
false
end
end
end

View File

@@ -0,0 +1,89 @@
#
# Cookbook:: java
# Provider:: alternatives
#
# 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.
property :java_location, String
property :bin_cmds, Array
property :default, [true, false], default: true
property :priority, Integer, default: 1061
property :reset_alternatives, [true, false], default: true
action :set do
if new_resource.bin_cmds
new_resource.bin_cmds.each do |cmd|
bin_path = "/usr/bin/#{cmd}"
alt_path = "#{new_resource.java_location}/bin/#{cmd}"
priority = new_resource.priority
unless ::File.exist?(alt_path)
Chef::Log.debug "Skipping setting alternative for #{cmd}. Command #{alt_path} does not exist."
next
end
alternative_exists_same_priority = shell_out("#{alternatives_cmd} --display #{cmd} | grep #{alt_path} | grep 'priority #{priority}$'").exitstatus == 0
alternative_exists = shell_out("#{alternatives_cmd} --display #{cmd} | grep #{alt_path}").exitstatus == 0
# remove alternative if priority is changed and install it with new priority
if alternative_exists && !alternative_exists_same_priority
converge_by("Removing alternative for #{cmd} with old priority") do
Chef::Log.debug "Removing alternative for #{cmd} with old priority"
remove_cmd = shell_out("#{alternatives_cmd} --remove #{cmd} #{alt_path}")
alternative_exists = false
unless remove_cmd.exitstatus == 0
Chef::Application.fatal!(%( remove alternative failed ))
end
end
end
# install the alternative if needed
unless alternative_exists
converge_by("Add alternative for #{cmd}") do
Chef::Log.debug "Adding alternative for #{cmd}"
if new_resource.reset_alternatives
shell_out("rm /var/lib/alternatives/#{cmd}")
end
install_cmd = shell_out("#{alternatives_cmd} --install #{bin_path} #{cmd} #{alt_path} #{priority}")
unless install_cmd.exitstatus == 0
Chef::Application.fatal!(%( install alternative failed ))
end
end
end
# set the alternative if default
next unless new_resource.default
alternative_is_set = shell_out("#{alternatives_cmd} --display #{cmd} | grep \"link currently points to #{alt_path}\"").exitstatus == 0
next if alternative_is_set
converge_by("Set alternative for #{cmd}") do
Chef::Log.debug "Setting alternative for #{cmd}"
set_cmd = shell_out("#{alternatives_cmd} --set #{cmd} #{alt_path}")
unless set_cmd.exitstatus == 0
Chef::Application.fatal!(%( set alternative failed ))
end
end
end
end
end
action :unset do
new_resource.bin_cmds.each do |cmd|
converge_by("Remove alternative for #{cmd}") do
shell_out("#{alternatives_cmd} --remove #{cmd} #{new_resource.java_location}/bin/#{cmd}")
end
end
end
action_class do
def alternatives_cmd
platform_family?('rhel', 'fedora', 'amazon') ? 'alternatives' : 'update-alternatives'
end
end

View File

@@ -0,0 +1,144 @@
#
# Author:: Mevan Samaratunga (<mevansam@gmail.com>)
# Author:: Michael Goetz (<mpgoetz@gmail.com>)
# Cookbook:: java
# Resource:: certificate
#
# Copyright:: 2013, Mevan Samaratunga
#
# 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.
property :java_home, String, default: lazy { node['java']['java_home'] }
property :keystore_path, String, default: lazy { node['java']['jdk_version'].to_i < 11 ? "#{node['java']['java_home']}/jre/lib/security/cacerts" : "#{node['java']['java_home']}/lib/security/cacerts" }
property :keystore_passwd, String, default: 'changeit'
property :cert_alias, String, name_property: true
property :cert_data, String
property :cert_file, String
property :ssl_endpoint, String
action :install do
require 'openssl'
java_home = new_resource.java_home
keytool = "#{java_home}/bin/keytool"
truststore = if new_resource.keystore_path.empty?
truststore_default_location
else
new_resource.keystore_path
end
truststore_passwd = new_resource.keystore_passwd
certalias = new_resource.cert_alias
certdata = new_resource.cert_data || fetch_certdata
hash = OpenSSL::Digest::SHA512.hexdigest(certdata)
certfile = "#{node['java']['download_path']}/#{certalias}.cert.#{hash}"
cmd = Mixlib::ShellOut.new("#{keytool} -list -keystore #{truststore} -storepass #{truststore_passwd} -rfc -alias \"#{certalias}\"")
cmd.run_command
keystore_cert = cmd.stdout.match(/^[-]+BEGIN.*END(\s|\w)+[-]+$/m).to_s
keystore_cert_digest = keystore_cert.empty? ? nil : OpenSSL::Digest::SHA512.hexdigest(OpenSSL::X509::Certificate.new(keystore_cert).to_der)
certfile_digest = OpenSSL::Digest::SHA512.hexdigest(OpenSSL::X509::Certificate.new(certdata).to_der)
if keystore_cert_digest == certfile_digest
Chef::Log.debug("Certificate \"#{certalias}\" in keystore \"#{truststore}\" is up-to-date.")
else
cmd = Mixlib::ShellOut.new("#{keytool} -list -keystore #{truststore} -storepass #{truststore_passwd} -v")
cmd.run_command
Chef::Log.debug(cmd.format_for_exception)
Chef::Application.fatal!("Error querying keystore for existing certificate: #{cmd.exitstatus}", cmd.exitstatus) unless cmd.exitstatus == 0
has_key = !cmd.stdout[/Alias name: \b#{certalias}/i].nil?
if has_key
converge_by("delete existing certificate #{certalias} from #{truststore}") do
cmd = Mixlib::ShellOut.new("#{keytool} -delete -alias \"#{certalias}\" -keystore #{truststore} -storepass #{truststore_passwd}")
cmd.run_command
Chef::Log.debug(cmd.format_for_exception)
unless cmd.exitstatus == 0
Chef::Application.fatal!("Error deleting existing certificate \"#{certalias}\" in " \
"keystore so it can be updated: #{cmd.exitstatus}", cmd.exitstatus)
end
end
end
::File.open(certfile, 'w', 0o644) { |f| f.write(certdata) }
converge_by("add certificate #{certalias} to keystore #{truststore}") do
cmd = Mixlib::ShellOut.new("#{keytool} -import -trustcacerts -alias \"#{certalias}\" -file #{certfile} -keystore #{truststore} -storepass #{truststore_passwd} -noprompt")
cmd.run_command
Chef::Log.debug(cmd.format_for_exception)
unless cmd.exitstatus == 0
FileUtils.rm_f(certfile)
Chef::Application.fatal!("Error importing certificate into keystore: #{cmd.exitstatus}", cmd.exitstatus)
end
end
end
end
action :remove do
certalias = new_resource.name
truststore = if new_resource.keystore_path.nil?
truststore_default_location
else
new_resource.keystore_path
end
truststore_passwd = new_resource.keystore_passwd
keytool = "#{node['java']['java_home']}/bin/keytool"
cmd = Mixlib::ShellOut.new("#{keytool} -list -keystore #{truststore} -storepass #{truststore_passwd} -v | grep \"#{certalias}\"")
cmd.run_command
has_key = !cmd.stdout[/Alias name: #{certalias}/].nil?
Chef::Application.fatal!("Error querying keystore for existing certificate: #{cmd.exitstatus}", cmd.exitstatus) unless cmd.exitstatus == 0
if has_key
converge_by("remove certificate #{certalias} from #{truststore}") do
cmd = Mixlib::ShellOut.new("#{keytool} -delete -alias \"#{certalias}\" -keystore #{truststore} -storepass #{truststore_passwd}")
cmd.run_command
unless cmd.exitstatus == 0
Chef::Application.fatal!("Error deleting existing certificate \"#{certalias}\" in " \
"keystore so it can be updated: #{cmd.exitstatus}", cmd.exitstatus)
end
end
end
FileUtils.rm_f("#{node['java']['download_path']}/#{certalias}.cert.*")
end
action_class do
def fetch_certdata
return IO.read(new_resource.cert_file) unless new_resource.cert_file.nil?
certendpoint = new_resource.ssl_endpoint
unless certendpoint.nil?
cmd = Mixlib::ShellOut.new("echo QUIT | openssl s_client -showcerts -servername #{certendpoint.split(':').first} -connect #{certendpoint} 2> /dev/null | openssl x509")
cmd.run_command
Chef::Log.debug(cmd.format_for_exception)
Chef::Application.fatal!("Error returned when attempting to retrieve certificate from remote endpoint #{certendpoint}: #{cmd.exitstatus}", cmd.exitstatus) unless cmd.exitstatus == 0
certout = cmd.stdout
return certout unless certout.empty?
Chef::Application.fatal!("Unable to parse certificate from openssl query of #{certendpoint}.", 999)
end
Chef::Application.fatal!('At least one of cert_data, cert_file or ssl_endpoint attributes must be provided.', 999)
end
def truststore_default_location
if node['java']['jdk_version'].to_i > 8
"#{node['java']['java_home']}/lib/security/cacerts"
else
"#{node['java']['java_home']}/jre/lib/security/cacerts"
end
end
end

View File

@@ -0,0 +1,106 @@
#
# Cookbook:: java
# Provider:: jce
#
# 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.
property :jdk_version, String, default: lazy { node['java']['jdk_version'].to_s }
property :jce_url, String, default: lazy { node['java']['oracle']['jce'][jdk_version]['url'] }
property :jce_checksum, String, default: lazy { node['java']['oracle']['jce'][jdk_version]['checksum'] }
property :java_home, String, default: lazy { node['java']['java_home'] }
property :jce_home, String, default: lazy { node['java']['oracle']['jce']['home'] }
property :jce_cookie, String, default: lazy { node['java']['oracle']['accept_oracle_download_terms'] ? 'oraclelicense=accept-securebackup-cookie' : '' }
property :principal, String, default: lazy { platform_family?('windows') ? node['java']['windows']['owner'] : 'administrator' }
action :install do
jdk_version = new_resource.jdk_version
jce_url = new_resource.jce_url
jce_checksum = new_resource.jce_checksum
java_home = new_resource.java_home
jce_home = new_resource.jce_home
jce_cookie = new_resource.jce_cookie
principal = new_resource.principal
directory ::File.join(jce_home, jdk_version) do
mode '0755'
recursive true
end
r = remote_file "#{node['java']['download_path']}/jce.zip" do
source jce_url
checksum jce_checksum
headers(
'Cookie' => jce_cookie
)
not_if { ::File.exist?(::File.join(jce_home, jdk_version, 'US_export_policy.jar')) }
end
# JRE installation does not have a jre folder
jre_path = node['java']['install_type'] == 'jdk' ? 'jre' : ''
if node['os'] == 'windows'
staging_path = ::File.join(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(java_home, jre_path, '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 r.path
checksum jce_checksum
action :unzip
not_if { ::File.exist? staging_local_policy }
end
remote_file final_local_policy do
rights :full_control, principal
source "file://#{staging_local_policy}"
end
remote_file final_export_policy do
rights :full_control, principal
source "file://#{staging_export_policy}"
end
else
package 'unzip'
package 'curl'
execute 'extract jce' do
command <<-EOF
rm -rf java_jce
mkdir java_jce
cd java_jce
unzip -o ../jce.zip
find ./ -name '*.jar' | xargs -I JCE_JAR mv JCE_JAR #{jce_home}/#{jdk_version}/
chmod -R 0644 #{jce_home}/#{jdk_version}/*.jar
EOF
cwd node['java']['download_path']
creates ::File.join(jce_home, jdk_version, 'US_export_policy.jar')
end
%w(local_policy.jar US_export_policy.jar).each do |jar|
jar_path = ::File.join(java_home, jre_path, 'lib', 'security', jar)
# remove the jars already in the directory
file jar_path do
action :delete
not_if { ::File.symlink? jar_path }
end
link jar_path do
to ::File.join(jce_home, jdk_version, jar)
end
end
end
end

View File

@@ -0,0 +1,285 @@
#
# Author:: Bryan W. Berry (<bryan.berry@gmail.com>)
# Cookbook:: java
# Resource:: oracle_install
#
# Copyright:: 2011, Bryan w. Berry
# Copyright:: 2017-2018, Chef Software, Inc.
#
# 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.
# backwards compatibility with the old name
provides :java_oracle_install
provides :java_ark
property :url, String
property :mirrorlist, Array, default: []
property :checksum, String, regex: /^[0-9a-f]{32}$|^[a-zA-Z0-9]{40,64}$/
property :md5, String, regex: /^[0-9a-f]{32}$|^[a-zA-Z0-9]{40,64}$/
property :app_home, String
property :app_home_mode, Integer, default: 0755
property :bin_cmds, Array, default: []
property :owner, String, default: 'root'
property :group, String, default: lazy { node['root_group'] }
property :default, [true, false], default: true
property :alternatives_priority, Integer, default: 1
property :connect_timeout, Integer, default: 30 # => 30 seconds
property :reset_alternatives, [true, false], default: true
property :use_alt_suffix, [true, false], default: true
property :download_timeout, Integer, default: 600 # => 600 seconds
property :proxy, String
property :accept_oracle_download_terms, [true, false], default: lazy { node['java']['oracle']['accept_oracle_download_terms'] }
action :install do
app_dir_name, tarball_name = parse_app_dir_name(new_resource.url)
app_root = new_resource.app_home.split('/')[0..-2].join('/')
app_dir = app_root + '/' + app_dir_name
app_group = new_resource.group
if !new_resource.default && new_resource.use_alt_suffix
Chef::Log.debug('processing alternate jdk')
app_dir += '_alt'
app_home = new_resource.app_home + '_alt'
else
app_home = new_resource.app_home
end
directory app_root do
owner new_resource.owner
group app_group
mode new_resource.app_home_mode
recursive true
action :nothing
end.run_action(:create)
unless ::File.exist?(app_dir)
if new_resource.url =~ /oracle\.com.*$/
download_path = "#{node['java']['download_path']}/#{tarball_name}"
if oracle_downloaded?(download_path, new_resource)
Chef::Log.debug('oracle tarball already downloaded, not downloading again')
else
Chef::Log.warn('Downloading directly from Oracle is unreliable as artifacts have been removed in the past. Change download url.')
download_direct_from_oracle tarball_name, new_resource
end
else
Chef::Log.debug('downloading tarball from an unofficial repository')
remote_file "#{node['java']['download_path']}/#{tarball_name}" do
source new_resource.url
checksum new_resource.checksum
retries new_resource.retries
retry_delay new_resource.retry_delay
mode '0755'
action :nothing
end.run_action(:create_if_missing)
end
converge_by("extract compressed data into Chef file cache path and move extracted data to #{app_dir}") do
case tarball_name
when /^.*\.bin/
cmd = shell_out(
%(cd "#{node['java']['download_path']}";
bash ./#{tarball_name} -noregister
)
)
unless cmd.exitstatus == 0
Chef::Application.fatal!("Failed to extract file #{tarball_name}!")
end
when /^.*\.zip/
cmd = shell_out(
%(unzip "#{node['java']['download_path']}/#{tarball_name}" -d "#{node['java']['download_path']}" )
)
unless cmd.exitstatus == 0
Chef::Application.fatal!("Failed to extract file #{tarball_name}!")
end
when /^.*\.(tar.gz|tgz)/
package 'tar' do
not_if { platform_family?('mac_os_x', 'windows') }
action :nothing
end.run_action(:install)
cmd = shell_out(
%(tar xvzf "#{node['java']['download_path']}/#{tarball_name}" -C "#{node['java']['download_path']}" --no-same-owner)
)
unless cmd.exitstatus == 0
Chef::Application.fatal!("Failed to extract file #{tarball_name}!")
end
end
cmd = shell_out(
%(mv "#{node['java']['download_path']}/#{app_dir_name}" "#{app_dir}" )
)
unless cmd.exitstatus == 0
Chef::Application.fatal!(%( Command \' mv "#{node['java']['download_path']}/#{app_dir_name}" "#{app_dir}" \' failed ))
end
# change ownership of extracted files
FileUtils.chown_R new_resource.owner, app_group, app_dir
end
end
# set up .jinfo file for update-java-alternatives
java_name = app_home.split('/')[-1]
jinfo_file = "#{app_root}/.#{java_name}.jinfo"
if platform_family?('debian') && !::File.exist?(jinfo_file)
converge_by("Add #{jinfo_file} for debian") do
template jinfo_file do
cookbook 'java'
source 'oracle.jinfo.erb'
owner new_resource.owner
group app_group
variables(
priority: new_resource.alternatives_priority,
bin_cmds: new_resource.bin_cmds,
name: java_name,
app_dir: app_home
)
action :nothing
end.run_action(:create)
end
end
# link app_home to app_dir
Chef::Log.debug "app_home is #{app_home} and app_dir is #{app_dir}"
current_link = ::File.symlink?(app_home) ? ::File.readlink(app_home) : nil
if current_link != app_dir
converge_by("symlink #{app_dir} to #{app_home}") do
FileUtils.rm_f app_home
FileUtils.ln_sf app_dir, app_home
FileUtils.chown new_resource.owner, app_group, app_home
end
end
# update-alternatives
java_alternatives 'set-java-alternatives' do
java_location app_home
bin_cmds new_resource.bin_cmds
priority new_resource.alternatives_priority
default new_resource.default
reset_alternatives new_resource.reset_alternatives
action :set
end
end
action :remove do
app_dir_name, _tarball_name = parse_app_dir_name(new_resource.url)
app_root = new_resource.app_home.split('/')[0..-2].join('/')
app_dir = app_root + '/' + app_dir_name
if new_resource.default
app_home = new_resource.app_home
else
Chef::Log.debug('processing alternate jdk')
app_dir += '_alt'
app_home = new_resource.app_home + '_alt'
end
if ::File.exist?(app_dir)
java_alternatives 'unset-java-alternatives' do
java_location app_home
bin_cmds new_resource.bin_cmds
action :unset
end
converge_by("remove #{new_resource.name} at #{app_dir}") do
Chef::Log.info "Removing #{new_resource.name} at #{app_dir}"
FileUtils.rm_rf app_dir
end
end
end
action_class do
require 'uri'
def parse_app_dir_name(url)
uri = URI.parse(url)
file_name = uri.path.split('/').last
# funky logic to parse oracle's non-standard naming convention
# for jdk1.6 -> 1.9, 10.0.0->10.0.2, 11
if file_name =~ /^(jre|jdk|server-jre).*$/
major_num = file_name.scan(/\d{1,}/)[0]
package_name = file_name =~ /^server-jre.*$/ ? 'jdk' : file_name.scan(/[a-z]+/)[0]
if major_num.to_i >= 10
# Versions 10 and above incorporate semantic versioning and/or single version numbers
version_result = file_name.scan(/.*-([\d\.]+)_.*/)[0][0]
app_dir_name = "#{package_name}-#{version_result}"
else
update_token = file_name.scan(/u(\d+)/)[0]
update_num = update_token ? update_token[0] : '0'
# pad a single digit number with a zero
update_num = '0' + update_num if update_num.length < 2
app_dir_name = if update_num == '00'
"#{package_name}1.#{major_num}.0"
else
"#{package_name}1.#{major_num}.0_#{update_num}"
end
end
else
app_dir_name = file_name.split(/(.tgz|.tar.gz|.zip)/)[0]
app_dir_name = app_dir_name.split('-bin')[0]
end
[app_dir_name, file_name]
end
def oracle_downloaded?(download_path, new_resource)
if ::File.exist? download_path
require 'openssl'
if new_resource.checksum =~ /^[0-9a-f]{32}$/
downloaded_md5 = OpenSSL::Digest::MD5.file(download_path).hexdigest
downloaded_md5 == new_resource.checksum
else
downloaded_sha = OpenSSL::Digest::SHA256.file(download_path).hexdigest
downloaded_sha == new_resource.checksum
end
else
false
end
end
def download_direct_from_oracle(tarball_name, new_resource)
download_path = "#{node['java']['download_path']}/#{tarball_name}"
cookie = 'oraclelicense=accept-securebackup-cookie'
proxy = "-x #{new_resource.proxy}" unless new_resource.proxy.nil?
if new_resource.accept_oracle_download_terms
# install the curl package
package 'curl' do
action :nothing
end.run_action(:install)
converge_by('download oracle tarball straight from the server') do
Chef::Log.debug 'downloading oracle tarball straight from the source'
shell_out!(
%W(
curl
--fail
--create-dirs
-L
--retry #{new_resource.retries}
--retry-delay #{new_resource.retry_delay} --cookie "#{cookie}"
#{new_resource.url}
-o #{download_path}
--connect-timeout #{new_resource.connect_timeout}
#{proxy}
).join(' '),
timeout: new_resource.download_timeout
)
end
# Can't verify anything with HTTP return codes from Oracle. For example, they return 200 for auth failure.
# Do a generic verification of the download
unless oracle_downloaded?(download_path, new_resource)
Chef::Application.fatal!("Checksum verification failure. Possible wrong checksum or download from Oracle failed.\nVerify artifact checksum and/or verify #{download_path} is an archive and not an HTML response from Oracle")
end
else
Chef::Application.fatal!("You must set the resource property 'accept_oracle_download_terms' or set the node attribute node['java']['oracle']['accept_oracle_download_terms'] to true if you want to download directly from the oracle site!")
end
end
end

View File

@@ -0,0 +1,6 @@
name=<%= @name %>
priority=<%= @priority %>
section=main
<% @bin_cmds.each do |cmd| -%>jdk <%= cmd %> <%= @app_dir %>/bin/<%= cmd %>
<% end -%>

View File

@@ -0,0 +1,4 @@
LICENSE_ACCEPTED=<%= node['java']['accept_license_agreement'] %>
INSTALLER_UI=silent
USER_INSTALL_DIR=<%= node['java']['java_home'] %>
-fileOverwrite_<%= node['java']['java_home'] %>_uninstall/uninstall.lax=Yes

View File

@@ -0,0 +1 @@
export JAVA_HOME=<%= node['java']['java_home']%>

View File

@@ -0,0 +1,6 @@
name=<%= @name %>
priority=<%= @priority %>
section=main
<% @bin_cmds.each do |cmd| -%>jdk <%= cmd %> <%= @app_dir %>/bin/<%= cmd %>
<% end -%>