diff --git a/java/.gitignore b/java/.gitignore index 317d7cc..a90cbbb 100644 --- a/java/.gitignore +++ b/java/.gitignore @@ -1,9 +1,21 @@ -.bundle -.cache -.kitchen -bin -#*# *~ -.#*# -.kitchen/ +*# +.#* +\#*# +.*.sw[a-z] +*.un~ +*.tmp +*.bk +*.bkup .kitchen.local.yml +Berksfile.lock +Gemfile.lock + +.bundle/ +.cache/ +.kitchen/ +.vagrant/ +.vagrant.d/ +bin/ +tmp/ +vendor/ diff --git a/java/.kitchen.yml b/java/.kitchen.yml index c6ddc15..de52196 100644 --- a/java/.kitchen.yml +++ b/java/.kitchen.yml @@ -1,67 +1,130 @@ --- -driver_plugin: vagrant -driver_config: +driver: + name: vagrant require_chef_omnibus: true + customize: + memory: 1024 -platforms: -- name: ubuntu-12.04 - driver_config: - box: opscode-ubuntu-12.04 - box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box - run_list: ["recipe[apt]"] - -- name: ubuntu-10.04 - driver_config: - box: opscode-ubuntu-10.04 - box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-10.04_provisionerless.box - require_chef_omnibus: true - run_list: ["recipe[apt]"] - -- name: debian-6 - driver_config: - box: opscode-debian-6 - box_url: http://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_debian-6.0.7_provisionerless.box - run_list: ["recipe[apt]"] - -- name: centos-6.4 - driver_config: - box: opscode-centos-6.4 - box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_centos-6.4_provisionerless.box - -- name: centos-5.9 - driver_config: - box: opscode-centos-5.9 - box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_centos-5.9_provisionerless.box - -- name: fedora-18 - driver_config: - box: opscode-fedora-18 - box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode-fedora-18_provisionerless.box - -suites: -- name: openjdk - excludes: ["fedora-18"] - run_list: ["recipe[minitest-handler]", "recipe[java::openjdk]"] - attributes: {} -- name: openjdk-7 - excludes: ["ubuntu-10.04", "debian-6"] - run_list: ["recipe[minitest-handler]", "recipe[java::openjdk]"] +provisioner: + name: chef_zero attributes: java: - jdk_version: "7" + ark_retries: 2 + ark_retry_delay: 10 -- name: oracle - run_list: ["recipe[minitest-handler]", "recipe[java::oracle]"] - attributes: - java: - oracle: - accept_oracle_download_terms: true - install_flavor: "oracle" -- name: oracle-7 - run_list: ["recipe[minitest-handler]", "recipe[java::oracle]"] - attributes: - java: - jdk_version: "7" - oracle: - accept_oracle_download_terms: true - install_flavor: "oracle" +platforms: + - name: ubuntu-14.04 + run_list: + - recipe[apt] + driver: + box: opscode-ubuntu-14.04 + - name: ubuntu-13.10 + driver: + box: opscode-ubuntu-13.10 + run_list: + - recipe[apt] + - name: ubuntu-12.04 + driver: + box: opscode-ubuntu-12.04 + run_list: + - recipe[apt] + - name: ubuntu-10.04 + driver: + box: opscode-ubuntu-10.04 + run_list: + - recipe[apt] + - name: debian-6.0.8 + driver: + box: opscode-debian-6.0.8 + run_list: + - recipe[apt] + - name: debian-7.6 + driver: + box: opscode-debian-7.6 + run_list: + - recipe[apt] + - name: debian-7.4 + driver: + box: opscode-debian-7.4 + run_list: + - recipe[apt] + - name: centos-7.0 + driver: + box: opscode-centos-7.0 + - name: centos-6.5 + driver: + box: opscode-centos-6.5 + - name: centos-5.10 + driver: + box: opscode-centos-5.10 + - name: fedora-19 + driver: + box: opscode-fedora-19 + - name: fedora-20 + driver: + box: opscode-fedora-20 + +suites: + - name: openjdk + excludes: + - fedora-19 + - fedora-20 + run_list: + - recipe[java::default] + - name: openjdk-7 + excludes: + - ubuntu-10.04 + - debian-6.0.8 + run_list: + - recipe[java::default] + attributes: + java: + jdk_version: "7" + - name: oracle + run_list: + - recipe[java::default] + attributes: + java: + oracle: + accept_oracle_download_terms: true + install_flavor: oracle + - name: oracle-7 + run_list: + - recipe[java::default] + attributes: + java: + jdk_version: "7" + oracle: + accept_oracle_download_terms: true + install_flavor: oracle + - name: oracle-8 + run_list: + - recipe[java::default] + attributes: + java: + jdk_version: "8" + oracle: + accept_oracle_download_terms: true + install_flavor: oracle + - name: oracle-direct + run_list: + - recipe[java::oracle] + attributes: + java: + oracle: + accept_oracle_download_terms: true + - name: openjdk-direct + run_list: + - recipe[java::openjdk] + excludes: + - fedora-19 + - fedora-20 + - name: oracle-rpm + run_list: + - recipe[java] + attributes: + java: + install_flavor: oracle_rpm + jdk_version: 7 + oracle: + accept_oracle_download_terms: true diff --git a/java/Berksfile b/java/Berksfile index 4e41c34..7898a3d 100644 --- a/java/Berksfile +++ b/java/Berksfile @@ -1,7 +1,8 @@ -site :opscode +source "https://supermarket.getchef.com" metadata group :integration do - cookbook "apt" - cookbook "minitest-handler" + cookbook 'apt', '~> 2.0' + cookbook 'yum', '~> 3.3' + cookbook 'windows', '~> 1.12' end diff --git a/java/CHANGELOG.md b/java/CHANGELOG.md index 13cc397..c5be2c9 100644 --- a/java/CHANGELOG.md +++ b/java/CHANGELOG.md @@ -1,150 +1,377 @@ -## v1.12.0: +Java Cookbook CHANGELOG +======================= +This file is used to list changes made in each version of the Java cookbook. + +v1.29.0 - 11/6/2014 +------- +### Bug +- **[#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 ### Improvement +- Adding a connect_timeout option for downloading java. -- [COOK-2154]: Add SmartOS support to java::openjdk recipe -- [COOK-3278]: upgrade to Oracle Java 7u25 +### Misc +- 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 +------- +### Improvement +- Allow setting of group to extracted java files. ### Bug +- 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 -- [COOK-2931]: Adding support for the platform 'xenserver' (for - installations of java in DOM0) -- [COOK-3277]: java cookbook fails on Fedora +v1.27.0 - 8/22/2014 +------- +- Update Oracle JDK8 to version 8u20 -## v1.11.6: +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 -### Bug +v1.25.0 - 8/1/2014 +------- +### Improvement +- **[#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. -- [COOK-2847]: Java cookbook does not have opensuse support -- [COOK-3142]: Syntax Errors spec/default_spec.rb:4-8 +### Documentation +- Recommendations for inclusion in community cookbooks +- Production Deployment with Oracle Java +- Update testing instructions for chefdk +- Various Readme formatting. -## v1.11.4: +### Misc +- 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)** + +### Improvement +- **[#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 +------- +### Improvement +- **[#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 +------- ### Bug +- **[#146](https://github.com/socrata-cookbooks/java/pull/146)** - Update Oracle accept-license-terms cookie format -- [COOK-2989]: `bash[update-java-alternatives]` resource uses wrong attribute +v1.21.0 +------- +### Improvement +- **[#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.11.2: +v1.20.0 +------- +### Improvement +- **[#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 ### Bug +- **[#141](https://github.com/socrata-cookbooks/java/pull/141)** - set java_home correctly for oracle_rpm -- Use SHA256 checksums for Oracle downloads, not SHA1. +v1.19.2 +------- +### Improvement +- **[#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) + +### Bug +- **[#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.11.0: +v1.19.0 +------- +Refactor the cookbook to better support wrapper cookbooks and other cookbook authoring patterns. +### Improvement +- **[#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)** -This version brings a wealth of tests and (backwards-compatible) -refactoring, plus some new features (updated Java, IBM recipe). -### Sub-task +### Bug +- **[#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)** -- [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 +v1.18.0 +------- +### Improvement +- **[#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 -### Task +v1.17.6 +------- +### Bug +- 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. -- [COOK-2902]: Refactor java cookbook +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 -- [COOK-2900]: update JDK to JDK 7u21, 6u45 +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.10.2: +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 -* [COOK-2415] - Fixed deprecation warnings in ark provider and openjdk - recipe by using Chef::Mixin::ShellOut instead of Chef::ShellOut -## v1.10.0: +v1.16.0 +------- +### Improvement +- **[COOK-3823](https://tickets.opscode.com/browse/COOK-3823)** - Upgrade to JDK 7u45-b18 -* [COOK-2400] - Allow java ark :url to be https -* [COOK-2436] - Upgrade needed for oracle jdk in java cookbook +v1.15.4 +------- +[COOK-4210] - remove unneeded run_command to prevent zombie processes -## v1.9.6: -* [COOK-2412] - add support for Oracle Linux +v1.15.2 +------- +[CHEF-4210] remove unneeded run_command to prevent zombie processes -## 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.15.0 +------- +### Bug +- Fixing version number. Accidently released at 0.15.x instead of 1.15.x + -## v1.9.2: +v0.15.2 +------- +### FIX +- [COOK-3908] - Fixing JAVA_HOME on Ubuntu 10.04 -* [COOK-2306] - FoodCritic fixes for java cookbook -## v1.9.0: +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 -* [COOK-2236] - Update the Oracle Java version in the Java cookbook to - release 1.7u11 +### Improvement +- **[COOK-2793](https://tickets.opscode.com/browse/COOK-2793)** - Improve Windows support -## v1.8.2: -* [COOK-2205] - Fix for missing /usr/lib/jvm/default-java on Debian +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 -## v1.8.0: +### 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 -* [COOK-2095] - Add windows support +v1.12.0 +------- +### Improvement +- [COOK-2154]: Add SmartOS support to java::openjdk recipe +- [COOK-3278]: upgrade to Oracle Java 7u25 -## v1.7.0: +### Bug +- [COOK-2931]: Adding support for the platform 'xenserver' (for installations of java in DOM0) +- [COOK-3277]: java cookbook fails on Fedora -* [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.11.6 +------- +### Bug +- [COOK-2847]: Java cookbook does not have opensuse support +- [COOK-3142]: Syntax Errors spec/default_spec.rb:4-8 -## v1.6.4: +v1.11.4 +------- +### Bug +- [COOK-2989]: `bash[update-java-alternatives]` resource uses wrong attribute -* [COOK-1930] - fixed typo in attribute for java 5 on i586 +v1.11.2 +------- +### Bug +- Use SHA256 checksums for Oracle downloads, not SHA1. -## v1.6.2: +v1.11.0 +------- +This version brings a wealth of tests and (backwards-compatible) refactoring, plus some new features (updated Java, IBM recipe). -* 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']` +### Sub-task +- [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 -## v1.6.0: +### Task +- [COOK-2902]: Refactor java cookbook -* [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 +### Improvement +- [COOK-2900]: update JDK to JDK 7u21, 6u45 -## v1.5.4: +v1.10.2 +------- +- [COOK-2415] - Fixed deprecation warnings in ark provider and openjdk recipe by using Chef::Mixin::ShellOut instead of Chef::ShellOut -* [COOK-885] - update alternatives called on wrong file -* [COOK-1607] - use shellout instead of execute resource to update - alternatives +v1.10.0 +------- +- [COOK-2400] - Allow java ark :url to be https +- [COOK-2436] - Upgrade needed for oracle jdk in java cookbook -## v1.5.2: +v1.9.6 +------ +- [COOK-2412] - add support for Oracle Linux -* [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.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.5.0: +v1.9.2 +------ +- [COOK-2306] - FoodCritic fixes for java cookbook -* [COOK-1146] - Oracle now prevents download of JDK via non-browser -* [COOK-1114] - fix File.exists? +v1.9.0 +------ +- [COOK-2236] - Update the Oracle Java version in the Java cookbook to release 1.7u11 -## v1.4.2: +v1.8.2 +------ +- [COOK-2205] - Fix for missing /usr/lib/jvm/default-java on Debian -* [COOK-1051] - fix attributes typo and platform case switch - consistency +v1.8.0 +------ +- [COOK-2095] - Add windows support -## v1.4.0: +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. -* [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 +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 diff --git a/java/CONTRIBUTING.md b/java/CONTRIBUTING.md index 3a99897..ca6b264 100644 --- a/java/CONTRIBUTING.md +++ b/java/CONTRIBUTING.md @@ -1,257 +1,12 @@ -# Contributing to Opscode Cookbooks - -We are glad you want to contribute to Opscode Cookbooks! The first -step is the desire to improve the project. - -You can find the answers to additional frequently asked questions -[on the wiki](http://wiki.opscode.com/display/chef/How+to+Contribute). - -You can find additional information about -[contributing to cookbooks](http://wiki.opscode.com/display/chef/How+to+Contribute+to+Opscode+Cookbooks) -on the wiki as well. - -## Quick-contribute - -* Create an account on our [bug tracker](http://tickets.opscode.com) -* Sign our contributor agreement (CLA) -[ online](https://secure.echosign.com/public/hostedForm?formid=PJIF5694K6L) -(keep reading if you're contributing on behalf of your employer) -* Create a ticket for your change on the - [bug tracker](http://tickets.opscode.com) -* Link to your patch as a rebased git branch or pull request from the - ticket -* Resolve the ticket as fixed - -We regularly review contributions and will get back to you if we have -any suggestions or concerns. - -## The Apache License and the CLA/CCLA - -Licensing is very important to open source projects, it helps ensure -the software continues to be available under the terms that the author -desired. Chef uses the Apache 2.0 license to strike a balance between -open contribution and allowing you to use the software however you -would like to. - -The license tells you what rights you have that are provided by the -copyright holder. It is important that the contributor fully -understands what rights they are licensing and agrees to them. -Sometimes the copyright holder isn't the contributor, most often when -the contributor is doing work for a company. - -To make a good faith effort to ensure these criteria are met, Opscode -requires a Contributor License Agreement (CLA) or a Corporate -Contributor License Agreement (CCLA) for all contributions. This is -without exception due to some matters not being related to copyright -and to avoid having to continually check with our lawyers about small -patches. - -It only takes a few minutes to complete a CLA, and you retain the -copyright to your contribution. - -You can complete our contributor agreement (CLA) -[ online](https://secure.echosign.com/public/hostedForm?formid=PJIF5694K6L). -If you're contributing on behalf of your employer, have your employer -fill out our -[Corporate CLA](https://secure.echosign.com/public/hostedForm?formid=PIE6C7AX856) -instead. - -## Ticket Tracker (JIRA) - -The [ticket tracker](http://tickets.opscode.com) is the most important -documentation for the code base. It provides significant historical -information, such as: - -* Which release a bug fix is included in -* Discussion regarding the design and merits of features -* Error output to aid in finding similar bugs - -Each ticket should aim to fix one bug or add one feature. - -## Using git - -You can get a quick copy of the repository for this cookbook by -running `git clone -git://github.com/opscode-coobkooks/COOKBOOKNAME.git`. - -For collaboration purposes, it is best if you create a Github account -and fork the repository to your own account. Once you do this you will -be able to push your changes to your Github repository for others to -see and use. - -If you have another repository in your GitHub account named the same -as the cookbook, we suggest you suffix the repository with -cookbook. - -### Branches and Commits - -You should submit your patch as a git branch named after the ticket, -such as COOK-1337. This is called a _topic branch_ and allows users to -associate a branch of code with the ticket. - -It is a best practice to have your commit message have a _summary -line_ that includes the ticket number, followed by an empty line and -then a brief description of the commit. This also helps other -contributors understand the purpose of changes to the code. - - [COOK-1757] - platform_family and style - - * use platform_family for platform checking - * update notifies syntax to "resource_type[resource_name]" instead of - resources() lookup - * COOK-692 - delete config files dropped off by packages in conf.d - * dropped debian 4 support because all other platforms have the same - values, and it is older than "old stable" debian release - -Remember that not all users use Chef in the same way or on the same -operating systems as you, so it is helpful to be clear about your use -case and change so they can understand it even when it doesn't apply -to them. - -### Github and Pull Requests - -All of Opscode's open source cookbook projects are available on -[Github](http://www.github.com/opscode-cookbooks). - -We don't require you to use Github, and we will even take patch diffs -attached to tickets on the tracker. However Github has a lot of -convenient features, such as being able to see a diff of changes -between a pull request and the main repository quickly without -downloading the branch. - -If you do choose to use a pull request, please provide a link to the -pull request from the ticket __and__ a link to the ticket from the -pull request. Because pull requests only have two states, open and -closed, we can't easily filter pull requests that are waiting for a -reply from the author for various reasons. - -### More information - -Additional help with git is available on the -[Working with Git](http://wiki.opscode.com/display/chef/Working+with+Git) -wiki page. - -## Functional and Unit Tests - -This cookbook is set up to run tests under -[Opscode's test-kitchen](https://github.com/opscode/test-kitchen). It -uses minitest-chef to run integration tests after the node has been -converged to verify that the state of the node. - -Test kitchen should run completely without exception using the default -[baseboxes provided by Opscode](https://github.com/opscode/bento). -Because Test Kitchen creates VirtualBox machines and runs through -every configuration in the Kitchenfile, it may take some time for -these tests to complete. - -If your changes are only for a specific recipe, run only its -configuration with Test Kitchen. If you are adding a new recipe, or -other functionality such as a LWRP or definition, please add -appropriate tests and ensure they run with Test Kitchen. - -If any don't pass, investigate them before submitting your patch. - -Any new feature should have unit tests included with the patch with -good code coverage to help protect it from future changes. Similarly, -patches that fix a bug or regression should have a _regression test_. -Simply put, this is a test that would fail without your patch but -passes with it. The goal is to ensure this bug doesn't regress in the -future. Consider a regular expression that doesn't match a certain -pattern that it should, so you provide a patch and a test to ensure -that the part of the code that uses this regular expression works as -expected. Later another contributor may modify this regular expression -in a way that breaks your use cases. The test you wrote will fail, -signalling to them to research your ticket and use case and accounting -for it. - -If you need help writing tests, please ask on the Chef Developer's -mailing list, or the #chef-hacking IRC channel. - -## Code Review - -Opscode regularly reviews code contributions and provides suggestions -for improvement in the code itself or the implementation. - -We find contributions by searching the ticket tracker for _resolved_ -tickets with a status of _fixed_. If we have feedback we will reopen -the ticket and you should resolve it again when you've made the -changes or have a response to our feedback. When we believe the patch -is ready to be merged, we will tag the _Code Reviewed_ field with -_Reviewed_. - -Depending on the project, these tickets are then merged within a week -or two, depending on the current release cycle. - -## Release Cycle - -The versioning for Opscode Cookbook projects is X.Y.Z. - -* X is a major release, which may not be fully compatible with prior - major releases -* Y is a minor release, which adds both new features and bug fixes -* Z is a patch release, which adds just bug fixes - -A released version of a cookbook will end in an even number, e.g. -"1.2.4" or "0.8.0". When development for the next version of the -cookbook begins, the "Z" patch number is incremented to the next odd -number, however the next release of the cookbook may be a major or -minor incrementing version. - -Releases of Opscode's cookbooks are usually announced on the Chef user -mailing list. Releases of several cookbooks may be batched together -and announced on the [Opscode Blog](http://www.opscode.com/blog). - -## Working with the community - -These resources will help you learn more about Chef and connect to -other members of the Chef community: - -* [chef](http://lists.opscode.com/sympa/info/chef) and - [chef-dev](http://lists.opscode.com/sympa/info/chef-dev) mailing - lists -* #chef and #chef-hacking IRC channels on irc.freenode.net -* [Community Cookbook site](http://community.opscode.com) -* [Chef wiki](http://wiki.opscode.com/display/chef) -* Opscode Chef [product page](http://www.opscode.com/chef) - - -## Cookbook Contribution Do's and Don't's - -Please do include tests for your contribution. If you need help, ask -on the -[chef-dev mailing list](http://lists.opscode.com/sympa/info/chef-dev) -or the -[#chef-hacking IRC channel](http://community.opscode.com/chat/chef-hacking). -Not all platforms that a cookbook supports may be supported by Test -Kitchen. Please provide evidence of testing your contribution if it -isn't trivial so we don't have to duplicate effort in testing. Chef -10.14+ "doc" formatted output is sufficient. - -Please do indicate new platform (families) or platform versions in the -commit message, and update the relevant ticket. - -If a contribution adds new platforms or platform versions, indicate -such in the body of the commit message(s), and update the relevant -COOK ticket. When writing commit messages, it is helpful for others if -you indicate the COOK ticket. For example: - - git commit -m '[COOK-1041] - Updated pool resource to correctly - delete.' - -Please do use [foodcritic](http://acrmp.github.com/foodcritic) to -lint-check the cookbook. Except FC007, it should pass all correctness -rules. FC007 is okay as long as the dependent cookbooks are *required* -for the default behavior of the cookbook, such as to support an -uncommon platform, secondary recipe, etc. - -Please do ensure that your changes do not break or modify behavior for -other platforms supported by the cookbook. For example if your changes -are for Debian, make sure that they do not break on CentOS. - -Please do not modify the version number in the metadata.rb, Opscode -will select the appropriate version based on the release cycle -information above. - -Please do not update the CHANGELOG.md for a new version. Not all -changes to a cookbook may be merged and released in the same versions. -Opscode will update the CHANGELOG.md when releasing a new version of -the cookbook. +Contributing +============ +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. [**Add tests!**](https://github.com/agileorbit-cookbooks/java/blob/master/TESTING.md) +5. Push to the branch (`git push origin my-new-feature`) +6. Create new Pull Request + +As this cookbook is no longer maintained by Chef, you **do not** need to sign any sort of contributor agreement. Simply make your change and open a pull request. + +Contributions will only be accepted if they are fully tested as specified in [TESTING.md](https://github.com/agileorbit-cookbooks/java/blob/master/TESTING.md) diff --git a/java/Gemfile b/java/Gemfile index 2b41ef5..c874ab2 100644 --- a/java/Gemfile +++ b/java/Gemfile @@ -1,17 +1,11 @@ -source "https://rubygems.org" +source 'https://rubygems.org' -gem "berkshelf" +gem 'berkshelf', '~> 2.0' +gem 'chefspec', '~> 3.1' +gem 'foodcritic', '~> 3.0' +gem 'rubocop', '~> 0.12' -group :test do - gem "chefspec" - gem "foodcritic" - gem "guard" - gem "guard-rspec" - gem "guard-kitchen" - gem "rb-inotify", :require => false - gem "rb-fsevent", :require => false - gem "rb-fchange", :require => false +group :integration do + gem 'test-kitchen', '~> 1.2.1' + gem 'kitchen-vagrant', '~> 0.14.0' end - -gem "test-kitchen", "1.0.0.alpha.6" -gem "kitchen-vagrant", "0.10.0" diff --git a/java/Guardfile b/java/Guardfile deleted file mode 100644 index 3183950..0000000 --- a/java/Guardfile +++ /dev/null @@ -1,25 +0,0 @@ -# A sample Guardfile -# More info at https://github.com/guard/guard#readme - -guard 'rspec' do - watch(%r{^spec/.+_spec\.rb$}) - watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } - watch('spec/spec_helper.rb') { "spec" } - - watch(%r{^recipes/(.+)\.rb$}) { |m| "spec/unit/recipes/#{m[1]}_spec.rb" } - watch(%r{^attributes/(.+)\.rb$}) - watch(%r{^files/(.+)}) - watch(%r{^templates/(.+)}) - watch(%r{^providers/(.+)\.rb}) { |m| "spec/unit/providers/#{m[1]}_spec.rb" } - watch(%r{^resources/(.+)\.rb}) { |m| "spec/unit/resources/#{m[1]}_spec.rb" } -end - -guard 'kitchen' do - watch(%r{test/.+}) - watch(%r{^recipes/(.+)\.rb$}) - watch(%r{^attributes/(.+)\.rb$}) - watch(%r{^files/(.+)}) - watch(%r{^templates/(.+)}) - watch(%r{^providers/(.+)\.rb}) - watch(%r{^resources/(.+)\.rb}) -end diff --git a/java/ISSUES.md b/java/ISSUES.md new file mode 100644 index 0000000..0d030d1 --- /dev/null +++ b/java/ISSUES.md @@ -0,0 +1,43 @@ +Java Cookbook Issues +======================= +This file documents the steps necessary to report and issue with the Java cookbook. Following these guidelines will help ensure your issue is resolved in a timely manner. + +Reporting +--------- +When you report an issue, please include the following information: + +- A high-level overview of what you are trying to accomplish +- An [SSCCE](http://sscce.org/) _Short, Self Contained, Correct (Compilable), Example_ +- The command you ran +- What you expected to happen +- What actually happened +- The exception backtrace(s), if any +- What operating system and version +- Everything output by running `env` +- What version of the cookbook are you using? +- What version of Ruby you are using (run `ruby -v`) +- What version of Rubygems you are using (run `gem -v`) +- What version of Chef you are using (run `knife -v`) + +Here's a snippet you can copy-paste into the issue and fill out: + +```text +(What is the issue? What are you trying to do? What happened?) + +- Command: `...` +- OS: +- Cookbook Version: +- Ruby Version: +- Rubygems Version: +- Chef Version: +- env: + ```text + # Paste your env here + ``` +- Backtrace: + ```text + # Paste backtrace here + ``` +``` + +[Create a ticket](https://github.com/agileorbit-cookbooks/java/issues/new) describing your problem and include the information above. diff --git a/java/README.md b/java/README.md index 122d600..2e851f6 100644 --- a/java/README.md +++ b/java/README.md @@ -1,36 +1,59 @@ -Description -=========== +java +===== This cookbook installs a Java JDK/JRE. It defaults to installing OpenJDK, but it can also install Oracle and IBM JDKs. -**IMPORTANT NOTE** - -As of 26 March 2012 you can no longer 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. - -### Example - -override the `accept_oracle_download_terms` in, e.g., `roles/base.rb` - - default_attributes( - :java => { - :oracle => { - "accept_oracle_download_terms" => true - } - } - ) +Usage +----- + +Simply 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 (OpenJDK, Oracle, IBM, or Windows), and `jdk_version` specifies which version to install (currently 6 and 7 are supported for all JDK types, 8 for Oracle only). + +### 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 0.10.10+ and Ohai 6.10+ for `platform_family` use. -## Platform +### Platform * Debian, Ubuntu * CentOS, Red Hat, Fedora, Scientific, Amazon, XenServer @@ -39,23 +62,20 @@ Chef 0.10.10+ and Ohai 6.10+ for `platform_family` use. * SmartOS * Windows -This cookbook includes cross-platform testing support via -`test-kitchen`, see `TESTING.md`. - Attributes -========== +----- See `attributes/default.rb` for default values. -* `node['java']['remove_deprecated_packages']` - Removes the now -deprecated Ubuntu JDK packages from the system, default `false` * `node['java']['install_flavor']` - Flavor of JVM you would like -installed (`oracle`, `openjdk`, `ibm`, `windows`), default `openjdk` +installed (`oracle`, `oracle_rpm`, `openjdk`, `ibm`, `windows`), default `openjdk` on Linux/Unix platforms, `windows` on Windows platforms. * `node['java']['jdk_version']` - JDK version to install, defaults to `'6'`. * `node['java']['java_home']` - Default location of the "`$JAVA_HOME`". +* `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. @@ -74,19 +94,31 @@ the .tar.gz. * `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']['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. Recipes -======= +----- -## default +### default -Include the default recipe in a run list, to get `java`. By 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`. @@ -94,7 +126,25 @@ systems, the `install_flavor` is `windows`. OpenJDK is the default because of licensing changes made upstream by Oracle. See notes on the `oracle` recipe below. -## openjdk +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. + +### purge_packages + +Purges deprecated Sun Java packages. + +### openjdk This recipe installs the `openjdk` flavor of Java. It also uses the `alternatives` system on RHEL/Debian families to set the default Java. @@ -104,13 +154,31 @@ agreement during package installation, set `node['java']['accept_license_agreement']` to true in order to indicate that you accept the license. -## oracle +### 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. +As of 26 March 2012 you can no longer 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 @@ -121,7 +189,7 @@ After putting the binaries in place, the `java::oracle` recipe updates `update-alternatives` script. This is all handled in the `java_ark` LWRP. -## oracle_i386 +### 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 @@ -129,12 +197,26 @@ same machine that require different versions of the JVM. This recipe operates in a similar manner to `java::oracle`. -## windows +### 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. + +### windows Because there is no easy way to pull the java msi off oracle's site, this recipe requires you to host it internally on your own http repo. -## ibm +**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 @@ -150,7 +232,9 @@ At this time the `java::ibm` recipe does not support multiple SDK installations. Resources/Providers -=================== +----- + +### java_ark This cookbook contains the `java_ark` LWRP. Generally speaking this LWRP is deprecated in favor of `ark` from the @@ -160,13 +244,13 @@ still used in this cookbook for handling the Oracle JDK installation. By default, the extracted directory is extracted to `app_root/extracted_dir_name` and symlinked to `app_root/default` -## Actions +#### Actions - `:install`: extracts the tarball and makes necessary symlinks - `:remove`: removes the tarball and run update-alternatives for all symlinked `bin_cmds` -## Attribute Parameters +#### Attribute Parameters - `url`: path to tarball, .tar.gz, .bin (oracle-specific), and .zip currently supported @@ -183,94 +267,118 @@ By default, the extracted directory is extracted to the `bin` subdirectory of the extracted folder. Will be ignored if this `java_ark` 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 -## Examples +#### Examples +```ruby +# install jdk6 from Oracle +java_ark "jdk" do + url 'http://download.oracle.com/otn-pub/java/jdk/6u29-b11/jdk-6u29-linux-x64.bin' + checksum 'a8603fa62045ce2164b26f7c04859cd548ffe0e33bfc979d9fa73df42e3b3365' + app_home '/usr/local/java/default' + bin_cmds ["java", "javac"] + action :install +end +``` +### java_alternatives - # install jdk6 from Oracle - java_ark "jdk" do - url 'http://download.oracle.com/otn-pub/java/jdk/6u29-b11/jdk-6u29-linux-x64.bin' - checksum 'a8603fa62045ce2164b26f7c04859cd548ffe0e33bfc979d9fa73df42e3b3365' - app_home '/usr/local/java/default' - bin_cmds ["java", "javac"] - action :install - end +The `java_alternatives` LWRP uses `update-alternatives` command +to set and unset command alternatives for various Java tools +such as java, javac, etc. -Usage -===== +#### Actions -Simply include the `java` recipe where ever you would like Java installed. +- `:set`: set alternatives for Java tools +- `:unset`: unset alternatives for Java tools -To install Oracle flavored Java override the `node['java']['install_flavor']` attribute with in role: +#### Attribute Parameters - name "java" - description "Install Oracle Java on Ubuntu" - default_attributes( - "java" => { - "install_flavor" => "oracle" - } - ) - run_list( - "recipe[java]" - ) +- `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`. -To install IBM flavored Java, set the required attributes: +#### 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 +``` - 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]" - ) +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'] = '7' +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']['oracle']['accept_oracle_download_terms'] = true +``` + +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/opscode/test-kitchen) for integration tests and -[ChefSpec/RSpec](https://github.com/acrmp/chefspec) for unit tests. -Pull requests should pass existing tests in -`files/default/tests/minitest-handler`. +[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: - - 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 +```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. License and Author -================== +----- * Author: Seth Chisamore () * Author: Bryan W. Berry () * Author: Joshua Timberman () +* Author: Eric Helgeson () -Copyright: 2008-2013, Opscode, Inc +Copyright: 2014, Agile Orbit, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/java/TESTING.md b/java/TESTING.md index e29ff7c..4663616 100644 --- a/java/TESTING.md +++ b/java/TESTING.md @@ -1,25 +1,41 @@ -This cookbook includes support for running tests via Test Kitchen (1.0). This has some requirements. +Testing the java cookbook +===== -1. You must be using the Git repository, rather than the downloaded cookbook from the Chef Community Site. -2. You must have Vagrant 1.1 installed. -3. You must have a "sane" Ruby 1.9.3 environment. +This cookbook includes both unit tests via [ChefSpec](https://github.com/sethvargo/chefspec) and integration tests via [Test Kitchen](https://github.com/test-kitchen/test-kitchen). Contributions to this cookbook will only be accepted if all tests pass successfully: -Once the above requirements are met, install the additional requirements: +```bash +kitchen test +chef exec rspec +``` -Install the berkshelf plugin for vagrant, and berkshelf to your local Ruby environment. +Setting up the test environment +----- - vagrant plugin install vagrant-berkshelf - gem install berkshelf +Install the latest version of [Vagrant](http://www.vagrantup.com/downloads.html) and [VirtualBox](https://www.virtualbox.org/wiki/Downloads) (free) or [VMWare Fusion](http://www.vmware.com/products/fusion) (paid). -Install Test Kitchen 1.0 (unreleased yet, use the alpha / prerelease version). +The Chef tooling (chefspec/test kitchen/etc) is managed by the [Chef Development Kit](http://downloads.getchef.com/chef-dk/) - Version 0.2.0-2. - gem install test-kitchen --pre +Clone the latest version of the cookbook from the repository. -Install the Vagrant driver for Test Kitchen. +```bash +git clone git@github.com:agileorbit-cookbooks/java.git +cd java +``` - gem install kitchen-vagrant +Running ChefSpec +----- -Once the above are installed, you should be able to run Test Kitchen: +ChefSpec unit tests are located in `spec`. Each recipe has a `recipename_spec.rb` file that contains unit tests for that recipe. Your new functionality or bug fix should have corresponding test coverage - if it's a change, make sure it doesn't introduce a regression (existing tests should pass). If it's a change or introduction of new functionality, add new tests as appropriate. - kitchen list - kitchen test +To run ChefSpec for the whole cookbook: + +`chef exec rspec` + +To run ChefSpec for a specific recipe: + +`chef exec rspec spec/set_java_home_spec.rb` + +Running Test Kitchen +----- + +Test Kitchen test suites are defined in [.kitchen.yml](https://github.com/agileorbit-cookbooks/java/blob/master/.kitchen.yml). Running `kitchen test` will cause Test Kitchen to spin up each platform VM in turn, running the `java::default` recipe with differing parameters in order to test all possible combinations of platform, install_flavor, and JDK version. If the Chef run completes successfully, corresponding tests in `test/integration` are executed. These must also pass. diff --git a/java/attributes/default.rb b/java/attributes/default.rb index 20ed6bb..0571c34 100644 --- a/java/attributes/default.rb +++ b/java/attributes/default.rb @@ -17,46 +17,58 @@ # See the License for the specific language governing permissions and # limitations under the License. -# remove the deprecated Ubuntu jdk packages -default['java']['remove_deprecated_packages'] = false - # default jdk attributes -default['java']['install_flavor'] = "openjdk" default['java']['jdk_version'] = '6' default['java']['arch'] = 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 + +# the following retry parameters apply when downloading oracle java +default['java']['ark_retries'] = 0 +default['java']['ark_retry_delay'] = 2 case node['platform_family'] -when "rhel", "fedora" - default['java']['java_home'] = "/usr/lib/jvm/java" - default['java']['openjdk_packages'] = ["java-1.#{node['java']['jdk_version']}.0-openjdk", "java-1.#{node['java']['jdk_version']}.0-openjdk-devel"] -when "freebsd" - default['java']['java_home'] = "/usr/local/openjdk#{node['java']['jdk_version']}" - default['java']['openjdk_packages'] = ["openjdk#{node['java']['jdk_version']}"] -when "arch" - default['java']['java_home'] = "/usr/lib/jvm/java-#{node['java']['jdk_version']}-openjdk" - default['java']['openjdk_packages'] = ["openjdk#{node['java']['jdk_version']}}"] 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)" -when "debian" - default['java']['java_home'] = "/usr/lib/jvm/default-java" - default['java']['openjdk_packages'] = ["openjdk-#{node['java']['jdk_version']}-jdk", "default-jre-headless"] -when "smartos" - default['java']['java_home'] = "/opt/local/java/sun6" - default['java']['openjdk_packages'] = ["sun-jdk#{node['java']['jdk_version']}", "sun-jre#{node['java']['jdk_version']}"] else - default['java']['java_home'] = "/usr/lib/jvm/default-java" - default['java']['openjdk_packages'] = ["openjdk-#{node['java']['jdk_version']}-jdk"] + default['java']['install_flavor'] = "openjdk" end -if node['java']['install_flavor'] == 'ibm' +case node['java']['install_flavor'] +when 'ibm', 'ibm_tar' default['java']['ibm']['url'] = nil default['java']['ibm']['checksum'] = nil default['java']['ibm']['accept_ibm_download_terms'] = false default['java']['java_home'] = "/opt/ibm/java" + + default['java']['ibm']['6']['bin_cmds'] = [ "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'] + [ "pack200", "unpack200" ] +when 'oracle_rpm' + # 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 + + # set the JAVA_HOME path, it may be overriden + # when a package version is provided. + default['java']['java_home'] = "/usr/java/latest" end # if you change this to true, you can download directly from Oracle @@ -69,7 +81,7 @@ "java", "javac", "javadoc", "javah", "javap", "javaws", "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" ] + "schemagen", "serialver", "servertool", "tnameserv", "unpack200", "wsgen", "wsimport", "xjc"] # x86_64 default['java']['jdk']['6']['x86_64']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-x64.bin' @@ -85,12 +97,35 @@ "javadoc", "javafxpackager", "javah", "javap", "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" ] + "schemagen", "serialver", "servertool", "tnameserv", "unpack200", "wsgen", "wsimport", "xjc"] + +# Oracle doesn't seem to publish SHA256 checksums for Java releases, so we use MD5 instead. +# Official checksums for the latest release can be found at http://www.oracle.com/technetwork/java/javase/downloads/java-se-binaries-checksum-1956892.html + +# x86_64 +default['java']['jdk']['7']['x86_64']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/7u71-b14/jdk-7u71-linux-x64.tar.gz' +default['java']['jdk']['7']['x86_64']['checksum'] = '22761b214b1505f1a9671b124b0f44f4' + +# i586 +default['java']['jdk']['7']['i586']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/7u71-b14/jdk-7u71-linux-i586.tar.gz' +default['java']['jdk']['7']['i586']['checksum'] = '54899d0733d9a8697da59de79a02cc8f' + +# jdk8 attributes + +default['java']['jdk']['8']['bin_cmds'] = [ "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"] + +# Oracle doesn't seem to publish SHA256 checksums for Java releases, so we use MD5 instead. +# Official checksums for the latest release can be found at https://www.oracle.com/webfolder/s/digest/8u25checksum.html # x86_64 -default['java']['jdk']['7']['x86_64']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/7u25-b15/jdk-7u25-linux-x64.tar.gz' -default['java']['jdk']['7']['x86_64']['checksum'] = 'f80dff0e19ca8d038cf7fe3aaa89538496b80950f4d10ff5f457988ae159b2a6' +default['java']['jdk']['8']['x86_64']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-x64.tar.gz' +default['java']['jdk']['8']['x86_64']['checksum'] = 'e145c03a7edc845215092786bcfba77e' # i586 -default['java']['jdk']['7']['i586']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/7u25-b15/jdk-7u25-linux-i586.tar.gz' -default['java']['jdk']['7']['i586']['checksum'] = 'dd89b20afa939992bb7fdc44837fa64f0a98d7ee1e5706fe8a2d9e2247ba6de7' +default['java']['jdk']['8']['i586']['url'] = 'http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-i586.tar.gz' +default['java']['jdk']['8']['i586']['checksum'] = 'b5b16247f66643727d9b6d4bc7c5efda' diff --git a/java/files/default/tests/minitest/openjdk_test.rb b/java/files/default/tests/minitest/openjdk_test.rb deleted file mode 100644 index 353f159..0000000 --- a/java/files/default/tests/minitest/openjdk_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'minitest/spec' -require File.expand_path('../support/helpers', __FILE__) - -describe_recipe 'java::openjdk' do - include Helpers::Java - - it "installs the correct version of the jdk" do - java_version = shell_out("java -version") - version_line = java_version.stderr - jdk_version = version_line.scan(/\.([678])\./)[0][0] - assert_equal node['java']['jdk_version'], jdk_version - end - - it "properly sets JAVA_HOME environment variable" do - env_java_home = shell_out("echo $JAVA_HOME") - java_home = env_java_home.stdout.chomp - assert_equal node['java']['java_home'], java_home - end - -end diff --git a/java/files/default/tests/minitest/oracle_test.rb b/java/files/default/tests/minitest/oracle_test.rb deleted file mode 100644 index 24fed9d..0000000 --- a/java/files/default/tests/minitest/oracle_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'minitest/spec' -require File.expand_path('../support/helpers', __FILE__) - -describe_recipe 'java::oracle' do - include Helpers::Java - - it "installs the correct version of the jdk" do - java_version = shell_out("java -version") - version_line = java_version.stderr - jdk_version = version_line.scan(/\.([678])\./)[0][0] - assert_equal node['java']['jdk_version'], jdk_version - end - - it "properly sets JAVA_HOME environment variable" do - env_java_home = shell_out("echo $JAVA_HOME") - java_home = env_java_home.stdout.chomp - assert_equal node['java']['java_home'], java_home - end - -end diff --git a/java/libraries/helpers.rb b/java/libraries/helpers.rb index e102498..761cc35 100644 --- a/java/libraries/helpers.rb +++ b/java/libraries/helpers.rb @@ -27,13 +27,32 @@ class OpenJDK def initialize(node) @node = node.to_hash @java_home = @node['java']['java_home'] || '/usr/lib/jvm/default-java' - @jdk_version = @node['java']['jdk_version'] || '6' + @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 alternatives_priority + if @jdk_version == '6' + # 'accepted' default for java 6 + 1061 + elsif @jdk_version == '7' + # i just made this number up + 1100 + elsif @jdk_version.to_i > 7 + # just a guard against the incoming java 8 + # so this cookbook will actually work for.. new versions of java + 1110 + else + # it's not 6, it's not 7, it's not newer than + # 7, but we probably want to install it, so + # override 6's priority. arbitrary number. + 1062 + end + end + def java_home_parent(java_home) Pathname.new(java_home).parent.to_s end @@ -46,6 +65,8 @@ def openjdk_path 'jre-1.%s.0-openjdk%s' % [@jdk_version, arch_dir] when 'smartos' 'jre' + else + 'jre' end end @@ -89,7 +110,7 @@ def old_version? class Chef class Recipe def valid_ibm_jdk_uri?(url) - url =~ ::URI::ABS_URI && %w[http https].include?(::URI.parse(url).scheme) + url =~ ::URI::ABS_URI && %w[file http https].include?(::URI.parse(url).scheme) end def platform_requires_license_acceptance? diff --git a/java/libraries/matchers.rb b/java/libraries/matchers.rb new file mode 100644 index 0000000..32a89aa --- /dev/null +++ b/java/libraries/matchers.rb @@ -0,0 +1,5 @@ +if defined?(ChefSpec) + def set_java_alternatives(resource_name) + ChefSpec::Matchers::ResourceMatcher.new(:java_alternatives, :set, resource_name) + end +end \ No newline at end of file diff --git a/java/metadata.rb b/java/metadata.rb index f9db2a1..a14a05a 100644 --- a/java/metadata.rb +++ b/java/metadata.rb @@ -1,16 +1,23 @@ name "java" -maintainer "Opscode, Inc." -maintainer_email "cookbooks@opscode.com" +maintainer "Agile Orbit" +maintainer_email "info@agileorbit.com" license "Apache 2.0" description "Installs Java runtime." long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "1.12.1" +version "1.29.0" -recipe "java", "Installs Java runtime" +recipe "java::default", "Installs Java runtime" +recipe "java::default_java_symlink", "Updates /usr/lib/jvm/default-java" +recipe "java::ibm", "Installs the JDK for IBM" +recipe "java::ibm_tar", "Installs the JDK for IBM from a tarball" recipe "java::openjdk", "Installs the OpenJDK flavor of Java" recipe "java::oracle", "Installs the Oracle flavor of Java" recipe "java::oracle_i386", "Installs the 32-bit jvm without setting it as the default" - +recipe "java::oracle_rpm", "Installs the Oracle RPM flavor of Java" +recipe "java::purge_packages", "Purges old Sun JDK packages" +recipe "java::set_attributes_from_version", "Sets various attributes that depend on jdk_version" +recipe "java::set_java_home", "Sets the JAVA_HOME environment variable" +recipe "java::windows", "Installs the JDK on Windows" %w{ debian @@ -23,9 +30,13 @@ arch oracle freebsd + windows suse xenserver smartos }.each do |os| supports os end + +suggests "windows" +suggests "aws" diff --git a/java/providers/alternatives.rb b/java/providers/alternatives.rb new file mode 100644 index 0000000..08076a7 --- /dev/null +++ b/java/providers/alternatives.rb @@ -0,0 +1,79 @@ +# +# Cookbook Name:: 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. + +require 'chef/mixin/shell_out' +include Chef::Mixin::ShellOut + +action :set do + if new_resource.bin_cmds + # I couldn't find a way to cleanly avoid repeating this variable declaration in both :set and :unset + alternatives_cmd = node['platform_family'] == 'rhel' ? 'alternatives' : 'update-alternatives' + new_resource.bin_cmds.each do |cmd| + + bin_path = "/usr/bin/#{cmd}" + alt_path = "#{new_resource.java_location}/bin/#{cmd}" + priority = new_resource.priority + + if !::File.exist?(alt_path) + Chef::Log.debug "Skipping setting alternative for #{cmd}. Command #{alt_path} does not exist." + next + end + + # install the alternative if needed + alternative_exists = shell_out("#{alternatives_cmd} --display #{cmd} | grep #{alt_path}").exitstatus == 0 + unless alternative_exists + description = "Add alternative for #{cmd}" + converge_by(description) do + Chef::Log.debug "Adding alternative for #{cmd}" + shell_out("rm /var/lib/alternatives/#{cmd}") + install_cmd = shell_out("#{alternatives_cmd} --install #{bin_path} #{cmd} #{alt_path} #{priority}") + unless install_cmd.exitstatus == 0 + Chef::Application.fatal!(%Q[ set alternative failed ]) + end + end + new_resource.updated_by_last_action(true) + end + + # set the alternative if default + if new_resource.default + alternative_is_set = shell_out("#{alternatives_cmd} --display #{cmd} | grep \"link currently points to #{alt_path}\"").exitstatus == 0 + unless alternative_is_set + description = "Set alternative for #{cmd}" + converge_by(description) 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!(%Q[ set alternative failed ]) + end + end + new_resource.updated_by_last_action(true) + end + end + end + end +end + +action :unset do + # I couldn't find a way to cleanly avoid repeating this variable declaration in both :set and :unset + alternatives_cmd = node['platform_family'] == 'rhel' ? 'alternatives' : 'update-alternatives' + new_resource.bin_cmds.each do |cmd| + alt_path = "#{new_resource.java_location}/bin/#{cmd}" + cmd = shell_out("#{alternatives_cmd} --remove #{cmd} #{alt_path}") + if cmd.exitstatus == 0 + new_resource.updated_by_last_action(true) + end + end +end diff --git a/java/providers/ark.rb b/java/providers/ark.rb index e77056c..38f64e9 100644 --- a/java/providers/ark.rb +++ b/java/providers/ark.rb @@ -28,15 +28,20 @@ def parse_app_dir_name url file_name = url.split('/')[-1] # funky logic to parse oracle's non-standard naming convention # for jdk1.6 - if file_name =~ /^(jre|jdk).*$/ + if file_name =~ /^(jre|jdk|server-jre).*$/ major_num = file_name.scan(/\d/)[0] - update_num = file_name.scan(/\d+/)[1] + update_token = file_name.scan(/u(\d+)/)[0] + update_num = update_token ? update_token[0] : "0" # pad a single digit number with a zero if update_num.length < 2 update_num = "0" + update_num end - package_name = file_name.scan(/[a-z]+/)[0] - app_dir_name = "#{package_name}1.#{major_num}.0_#{update_num}" + package_name = (file_name =~ /^server-jre.*$/) ? "jdk" : file_name.scan(/[a-z]+/)[0] + if update_num == "00" + app_dir_name = "#{package_name}1.#{major_num}.0" + else + app_dir_name = "#{package_name}1.#{major_num}.0_#{update_num}" + end else app_dir_name = file_name.split(/(.tgz|.tar.gz|.zip)/)[0] app_dir_name = app_dir_name.split("-bin")[0] @@ -47,8 +52,13 @@ def parse_app_dir_name url def oracle_downloaded?(download_path, new_resource) if ::File.exists? download_path require 'digest' - downloaded_sha = Digest::SHA256.file(download_path).hexdigest - downloaded_sha == new_resource.checksum + if new_resource.checksum =~ /^[0-9a-f]{32}$/ + downloaded_md5 = Digest::MD5.file(download_path).hexdigest + downloaded_md5 == new_resource.checksum + else + downloaded_sha = Digest::SHA256.file(download_path).hexdigest + downloaded_sha == new_resource.checksum + end else return false end @@ -56,8 +66,7 @@ def oracle_downloaded?(download_path, new_resource) def download_direct_from_oracle(tarball_name, new_resource) download_path = "#{Chef::Config[:file_cache_path]}/#{tarball_name}" - jdk_id = new_resource.url.scan(/\/([6789]u[0-9][0-9]?-b[0-9][0-9])\//)[0][0] - cookie = "oraclelicensejdk-#{jdk_id}-oth-JPR=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com" + cookie = "oraclelicense=accept-securebackup-cookie" if node['java']['oracle']['accept_oracle_download_terms'] # install the curl package p = package "curl" do @@ -68,11 +77,9 @@ def download_direct_from_oracle(tarball_name, new_resource) description = "download oracle tarball straight from the server" converge_by(description) do Chef::Log.debug "downloading oracle tarball straight from the source" - cmd = shell_out( - %Q[ curl -L --cookie "#{cookie}" #{new_resource.url} -o #{download_path} ] + cmd = shell_out!( + %Q[ curl --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} ] ) - cmd.run_command - cmd.error! end else Chef::Application.fatal!("You must set the attribute node['java']['oracle']['accept_oracle_download_terms'] to true if you want to download directly from the oracle site!") @@ -83,6 +90,11 @@ def download_direct_from_oracle(tarball_name, new_resource) 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.group + app_group = new_resource.group + else + app_group = new_resource.owner + end unless new_resource.default Chef::Log.debug("processing alternate jdk") @@ -97,10 +109,10 @@ def download_direct_from_oracle(tarball_name, new_resource) require 'fileutils' unless ::File.exists?(app_root) - description = "create dir #{app_root} and change owner to #{new_resource.owner}" + description = "create dir #{app_root} and change owner to #{new_resource.owner}:#{app_group}" converge_by(description) do FileUtils.mkdir app_root, :mode => new_resource.app_home_mode - FileUtils.chown new_resource.owner, new_resource.owner, app_root + FileUtils.chown new_resource.owner, app_group, app_root end end @@ -116,6 +128,8 @@ def download_direct_from_oracle(tarball_name, new_resource) r = remote_file "#{Chef::Config[:file_cache_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 @@ -123,45 +137,43 @@ def download_direct_from_oracle(tarball_name, new_resource) r.run_action(:create_if_missing) end - require 'tmpdir' - - description = "create tmpdir, extract compressed data into tmpdir, - move extracted data to #{app_dir} and delete tmpdir" + description = "extract compressed data into Chef file cache path and + move extracted data to #{app_dir}" converge_by(description) do - tmpdir = Dir.mktmpdir case tarball_name when /^.*\.bin/ cmd = shell_out( - %Q[ cd "#{tmpdir}"; - cp "#{Chef::Config[:file_cache_path]}/#{tarball_name}" . ; + %Q[ cd "#{Chef::Config[:file_cache_path]}"; bash ./#{tarball_name} -noregister - ] ).run_command + ] ) unless cmd.exitstatus == 0 Chef::Application.fatal!("Failed to extract file #{tarball_name}!") end when /^.*\.zip/ cmd = shell_out( - %Q[ unzip "#{Chef::Config[:file_cache_path]}/#{tarball_name}" -d "#{tmpdir}" ] - ).run_command + %Q[ unzip "#{Chef::Config[:file_cache_path]}/#{tarball_name}" -d "#{Chef::Config[:file_cache_path]}" ] + ) unless cmd.exitstatus == 0 Chef::Application.fatal!("Failed to extract file #{tarball_name}!") end when /^.*\.(tar.gz|tgz)/ cmd = shell_out( - %Q[ tar xvzf "#{Chef::Config[:file_cache_path]}/#{tarball_name}" -C "#{tmpdir}" ] - ).run_command + %Q[ tar xvzf "#{Chef::Config[:file_cache_path]}/#{tarball_name}" -C "#{Chef::Config[:file_cache_path]}" --no-same-owner] + ) unless cmd.exitstatus == 0 Chef::Application.fatal!("Failed to extract file #{tarball_name}!") end end cmd = shell_out( - %Q[ mv "#{tmpdir}/#{app_dir_name}" "#{app_dir}" ] - ).run_command + %Q[ mv "#{Chef::Config[:file_cache_path]}/#{app_dir_name}" "#{app_dir}" ] + ) unless cmd.exitstatus == 0 - Chef::Application.fatal!(%Q[ Command \' mv "#{tmpdir}/#{app_dir_name}" "#{app_dir}" \' failed ]) + Chef::Application.fatal!(%Q[ Command \' mv "#{Chef::Config[:file_cache_path]}/#{app_dir_name}" "#{app_dir}" \' failed ]) end - FileUtils.rm_r tmpdir + + # change ownership of extracted files + FileUtils.chown_R new_resource.owner, app_group, app_root end new_resource.updated_by_last_action(true) end @@ -174,7 +186,10 @@ def download_direct_from_oracle(tarball_name, new_resource) converge_by(description) do Chef::Log.debug "Adding #{jinfo_file} for debian" 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, @@ -196,47 +211,17 @@ def download_direct_from_oracle(tarball_name, new_resource) Chef::Log.debug "Symlinking #{app_dir} to #{app_home}" 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 - if new_resource.bin_cmds - new_resource.bin_cmds.each do |cmd| - - bin_path = "/usr/bin/#{cmd}" - alt_path = "#{app_home}/bin/#{cmd}" - priority = new_resource.alternatives_priority - - # install the alternative if needed - alternative_exists = shell_out("update-alternatives --display #{cmd} | grep #{alt_path}").run_command.exitstatus == 0 - unless alternative_exists - description = "Add alternative for #{cmd}" - converge_by(description) do - Chef::Log.debug "Adding alternative for #{cmd}" - install_cmd = shell_out("update-alternatives --install #{bin_path} #{cmd} #{alt_path} #{priority}").run_command - unless install_cmd.exitstatus == 0 - Chef::Application.fatal!(%Q[ set alternative failed ]) - end - end - new_resource.updated_by_last_action(true) - end - - # set the alternative if default - if new_resource.default - alternative_is_set = shell_out("update-alternatives --display #{cmd} | grep \"link currently points to #{alt_path}\"").run_command.exitstatus == 0 - unless alternative_is_set - description = "Set alternative for #{cmd}" - converge_by(description) do - Chef::Log.debug "Setting alternative for #{cmd}" - set_cmd = shell_out("update-alternatives --set #{cmd} #{alt_path}").run_command - unless set_cmd.exitstatus == 0 - Chef::Application.fatal!(%Q[ set alternative failed ]) - end - end - new_resource.updated_by_last_action(true) - end - end - end + 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 + action :set end end @@ -245,15 +230,19 @@ def download_direct_from_oracle(tarball_name, new_resource) app_root = new_resource.app_home.split('/')[0..-2].join('/') app_dir = app_root + '/' + app_dir_name + unless new_resource.default + Chef::Log.debug("processing alternate jdk") + app_dir = app_dir + "_alt" + app_home = new_resource.app_home + "_alt" + else + app_home = new_resource.app_home + end + if ::File.exists?(app_dir) - new_resource.bin_cmds.each do |cmd| - cmd = execute "update_alternatives" do - command "update-alternatives --remove #{cmd} #{app_dir} " - returns [0,2] - action :nothing - end - # the execute resource will take care of of the run_action(:run) - cmd.run_action(:run) + java_alternatives 'unset-java-alternatives' do + java_location app_home + bin_cmds new_resource.bin_cmds + action :unset end description = "remove #{new_resource.name} at #{app_dir}" converge_by(description) do diff --git a/java/recipes/default.rb b/java/recipes/default.rb index 574aecd..2c1b287 100644 --- a/java/recipes/default.rb +++ b/java/recipes/default.rb @@ -18,12 +18,11 @@ # limitations under the License. # -include_recipe "java::#{node['java']['install_flavor']}" - -# Purge the deprecated Sun Java packages if remove_deprecated_packages is true -%w[sun-java6-jdk sun-java6-bin sun-java6-jre].each do |pkg| - package pkg do - action :purge - only_if { node['java']['remove_deprecated_packages'] } +if node['java']['install_flavor'] != 'windows' + if node['java']['jdk_version'].to_i == 8 and node['java']['install_flavor'] != 'oracle' + Chef::Application.fatal!("JDK 8 is currently only provided with the Oracle JDK") end end + +include_recipe "java::set_attributes_from_version" +include_recipe "java::#{node['java']['install_flavor']}" diff --git a/java/recipes/default_java_symlink.rb b/java/recipes/default_java_symlink.rb new file mode 100644 index 0000000..2fbd650 --- /dev/null +++ b/java/recipes/default_java_symlink.rb @@ -0,0 +1,19 @@ +# Cookbook Name:: 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 diff --git a/java/recipes/ibm.rb b/java/recipes/ibm.rb index ea1b271..65cfd7f 100644 --- a/java/recipes/ibm.rb +++ b/java/recipes/ibm.rb @@ -17,6 +17,7 @@ # limitations under the License. require 'uri' + source_url = node['java']['ibm']['url'] jdk_uri = ::URI.parse(source_url) jdk_filename = ::File.basename(jdk_uri.path) @@ -25,6 +26,13 @@ raise "You must set the attribute `node['java']['ibm']['url']` to a valid HTTP URI" end +# "installable package" installer needs rpm on Ubuntu +if platform_family?('debian') && jdk_filename !~ /archive/ + package "rpm" do + action :install + end +end + template "#{Chef::Config[:file_cache_path]}/installer.properties" do source "ibm_jdk.installer.properties.erb" only_if { node['java']['ibm']['accept_ibm_download_terms'] } @@ -42,6 +50,18 @@ 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'] + end + action :nothing +end + execute "install-ibm-java" do cwd Chef::Config[:file_cache_path] environment({ @@ -49,6 +69,7 @@ "LAX_DEBUG" => "1" }) command "./#{jdk_filename} -f ./installer.properties -i silent" + notifies :set, 'java_alternatives[set-java-alternatives]', :immediately creates "#{node['java']['java_home']}/jre/bin/java" end diff --git a/java/recipes/ibm_tar.rb b/java/recipes/ibm_tar.rb new file mode 100644 index 0000000..5968491 --- /dev/null +++ b/java/recipes/ibm_tar.rb @@ -0,0 +1,70 @@ +# Cookbook Name:: java +# Recipe:: ibm_tar +# +# Copyright 2013, Opscode, 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' + +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 "#{Chef::Config[:file_cache_path]}/#{jdk_filename}" do + source source_url + mode 00755 + 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 00755 + 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'] + end + action :nothing +end + +execute "untar-ibm-java" do + cwd Chef::Config[:file_cache_path] + command "tar xzf ./#{jdk_filename} -C #{node['java']['java_home']} --strip 1" + notifies :set, 'java_alternatives[set-java-alternatives]', :immediately + creates "#{node['java']['java_home']}/jre/bin/java" +end + +include_recipe "java::set_java_home" diff --git a/java/recipes/openjdk.rb b/java/recipes/openjdk.rb index 439331b..e634381 100644 --- a/java/recipes/openjdk.rb +++ b/java/recipes/openjdk.rb @@ -19,22 +19,19 @@ # See the License for the specific language governing permissions and # limitations under the License. -java_location = Opscode::OpenJDK.new(node).java_location +unless node.recipe?('java::default') + Chef::Log.warn("Using java::default instead is recommended.") -include_recipe 'java::set_java_home' - -if platform_family?('debian', 'rhel', 'fedora') - - bash 'update-java-alternatives' do - code <<-EOH.gsub(/^\s+/, '') - update-alternatives --install /usr/bin/java java #{java_location} 1061 && \ - update-alternatives --set java #{java_location} - EOH - action :nothing + # Even if this recipe is included by itself, a safety check is nice... + [ node['java']['openjdk_packages'], node['java']['java_home'] ].each do |v| + if v.nil? or v.empty? + include_recipe "java::set_attributes_from_version" + end end - end +jdk = Opscode::OpenJDK.new(node) + if platform_requires_license_acceptance? file "/opt/local/.dlj_license_accepted" do owner "root" @@ -47,7 +44,29 @@ node['java']['openjdk_packages'].each do |pkg| package pkg do - action :install - notifies :run, 'bash[update-java-alternatives]', :immediately if platform_family?('debian', 'rhel', 'fedora') + version node['java']['openjdk_version'] if node['java']['openjdk_version'] + end +end + +if platform_family?('debian', 'rhel', 'fedora') + java_alternatives 'set-java-alternatives' do + java_location jdk.java_home + default node['java']['set_default'] + priority jdk.alternatives_priority + case node['java']['jdk_version'].to_s + when "6" + bin_cmds node['java']['jdk']['6']['bin_cmds'] + when "7" + bin_cmds node['java']['jdk']['7']['bin_cmds'] + end + action :set end end + +if node['java']['set_default'] and 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' diff --git a/java/recipes/oracle.rb b/java/recipes/oracle.rb index 3e19992..12acdd0 100644 --- a/java/recipes/oracle.rb +++ b/java/recipes/oracle.rb @@ -17,17 +17,19 @@ # See the License for the specific language governing permissions and # limitations under the License. +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? or node['java']['java_home'].empty? + include_recipe "java::set_attributes_from_version" + end +end java_home = node['java']["java_home"] arch = node['java']['arch'] -jdk_version = node['java']['jdk_version'] -#convert version number to a string if it isn't already -if jdk_version.instance_of? Fixnum - jdk_version = jdk_version.to_s -end - -case jdk_version +case node['java']['jdk_version'].to_s when "6" tarball_url = node['java']['jdk']['6'][arch]['url'] tarball_checksum = node['java']['jdk']['6'][arch]['checksum'] @@ -36,6 +38,10 @@ tarball_url = node['java']['jdk']['7'][arch]['url'] tarball_checksum = node['java']['jdk']['7'][arch]['checksum'] bin_cmds = node['java']['jdk']['7']['bin_cmds'] +when "8" + tarball_url = node['java']['jdk']['8'][arch]['url'] + tarball_checksum = node['java']['jdk']['8'][arch]['checksum'] + bin_cmds = node['java']['jdk']['8']['bin_cmds'] end if tarball_url =~ /example.com/ @@ -46,10 +52,16 @@ java_ark "jdk" do url tarball_url + default node['java']['set_default'] checksum tarball_checksum app_home java_home bin_cmds bin_cmds - alternatives_priority 1062 + alternatives_priority node['java']['alternatives_priority'] + retries node['java']['ark_retries'] + retry_delay node['java']['ark_retry_delay'] action :install end +if node['java']['set_default'] and platform_family?('debian') + include_recipe 'java::default_java_symlink' +end diff --git a/java/recipes/oracle_i386.rb b/java/recipes/oracle_i386.rb index 7472572..c3319b9 100644 --- a/java/recipes/oracle_i386.rb +++ b/java/recipes/oracle_i386.rb @@ -17,9 +17,18 @@ # See the License for the specific language governing permissions and # limitations under the License. +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? or 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'] +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'] @@ -28,6 +37,10 @@ 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" @@ -39,9 +52,16 @@ java_ark "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'] action :install default false end + +if node['java']['set_default'] and platform_family?('debian') + include_recipe 'java::default_java_symlink' +end diff --git a/java/recipes/oracle_rpm.rb b/java/recipes/oracle_rpm.rb new file mode 100644 index 0000000..200399d --- /dev/null +++ b/java/recipes/oracle_rpm.rb @@ -0,0 +1,58 @@ +# Author:: Christophe Arguel () +# +# Cookbook Name:: java +# Recipe:: oracle_rpm +# +# Copyright 2013, Christophe Arguel +# +# 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_java_home' + + +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 + +if platform_family?('rhel', 'fedora') and node['java']['set_default'] + + 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} 1061 \ + #{slave_lines} && \ + update-alternatives --set java #{java_location} + EOH + action :nothing + end + +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') and node['java']['set_default'] +end diff --git a/java/files/default/tests/minitest/support/helpers.rb b/java/recipes/purge_packages.rb similarity index 55% rename from java/files/default/tests/minitest/support/helpers.rb rename to java/recipes/purge_packages.rb index 9813832..d596445 100644 --- a/java/files/default/tests/minitest/support/helpers.rb +++ b/java/recipes/purge_packages.rb @@ -1,29 +1,20 @@ -# -# Cookbook:: java -# -# Author:: Joshua Timberman -# Copyright:: Copyright (c) 2013, Opscode, Inc. +# Cookbook Name:: java +# Recipe:: purge_packages # # 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 +# 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. -# - -module Helpers - module Java - require 'chef/mixin/shell_out' - include Chef::Mixin::ShellOut - include MiniTest::Chef::Assertions - include MiniTest::Chef::Context - include MiniTest::Chef::Resources +%w[sun-java6-jdk sun-java6-bin sun-java6-jre].each do |pkg| + package pkg do + action :purge end -end \ No newline at end of file +end diff --git a/java/recipes/set_attributes_from_version.rb b/java/recipes/set_attributes_from_version.rb new file mode 100644 index 0000000..0a52e98 --- /dev/null +++ b/java/recipes/set_attributes_from_version.rb @@ -0,0 +1,53 @@ +# Cookbook Name:: 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" + case node['java']['install_flavor'] + when "oracle" + node.default['java']['java_home'] = "/usr/lib/jvm/java" + when "oracle_rpm" + node.default['java']['java_home'] = "/usr/java/latest" + else + node.default['java']['java_home'] = "/usr/lib/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']}" + node.default['java']['openjdk_packages'] = ["openjdk#{node['java']['jdk_version']}"] +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'] = "/usr/lib/jvm/java-#{node['java']['jdk_version']}-#{node['java']['install_flavor']}" + # Newer Debian & Ubuntu adds the architecture to the path + if node['platform'] == 'debian' && Chef::VersionConstraint.new(">= 7.0").include?(node['platform_version']) || + node['platform'] == 'ubuntu' && Chef::VersionConstraint.new(">= 12.04").include?(node['platform_version']) + node.default['java']['java_home'] = "#{node['java']['java_home']}-#{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" + # Do nothing otherwise we will fall through to the else and set java_home to an invalid path, causing the installer to popup a dialog +else + node.default['java']['java_home'] = "/usr/lib/jvm/default-java" + node.default['java']['openjdk_packages'] = ["openjdk-#{node['java']['jdk_version']}-jdk"] +end diff --git a/java/recipes/set_java_home.rb b/java/recipes/set_java_home.rb index f695d5a..a09ea0b 100644 --- a/java/recipes/set_java_home.rb +++ b/java/recipes/set_java_home.rb @@ -31,3 +31,14 @@ content "export JAVA_HOME=#{node['java']['java_home']}" mode 00755 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 diff --git a/java/recipes/windows.rb b/java/recipes/windows.rb index 8480edc..7ca8d7a 100644 --- a/java/recipes/windows.rb +++ b/java/recipes/windows.rb @@ -18,11 +18,60 @@ # limitations under the License. # -Chef::Log.warn("No download url set for java installer.") unless node['java']['windows']['url'] +require 'uri' + +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'] + +uri = ::URI.parse(node['java']['windows']['url']) +cache_file_path = File.join(Chef::Config[:file_cache_path], File.basename(::URI.unescape(uri.path))) + +if aws_access_key_id && aws_secret_access_key + include_recipe 'aws::default' # install right_aws gem for aws_s3_file + + aws_s3_file cache_file_path do + aws_access_key_id aws_access_key_id + aws_secret_access_key aws_secret_access_key + checksum pkg_checksum if pkg_checksum + bucket node['java']['windows']['bucket'] + remote_path node['java']['windows']['remote_path'] + backup false + action :create + end +else + 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") + java_home_win = win_friendly_path(node['java']['java_home']) + # The 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\"" + additional_options = "/v\"/qn INSTALLDIR=\\\"#{java_home_win}\\\"\"" + + env "JAVA_HOME" do + value java_home_win + end + + # update path + windows_path "#{java_home_win}\\bin" do + action :add + end +end + windows_package node['java']['windows']['package_name'] do - source node['java']['windows']['url'] + source cache_file_path + checksum node['java']['windows']['checksum'] action :install installer_type :custom - options "/s" -end \ No newline at end of file + options "/s #{additional_options}" +end diff --git a/java/resources/alternatives.rb b/java/resources/alternatives.rb new file mode 100644 index 0000000..a99e370 --- /dev/null +++ b/java/resources/alternatives.rb @@ -0,0 +1,29 @@ +# +# Cookbook Name:: 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. + +actions :set, :unset + +attribute :java_location, :kind_of => String, :default => nil +attribute :bin_cmds, :kind_of => Array, :default => nil +attribute :default, :equal_to => [true, false], :default => true +attribute :priority, :kind_of => Integer, :default => 1061 + +# we have to set default for the supports attribute +# in initializer since it is a 'reserved' attribute name +def initialize(*args) + super + @action = :set +end diff --git a/java/resources/ark.rb b/java/resources/ark.rb index d96042c..3c04607 100644 --- a/java/resources/ark.rb +++ b/java/resources/ark.rb @@ -19,15 +19,33 @@ actions :install, :remove -attribute :url, :regex => /^https?:\/\/.*(tar.gz|tgz|bin|zip)$/, :default => nil +state_attrs :alternatives_priority, + :app_home, + :app_home_mode, + :bin_cmds, + :checksum, + :md5, + :default, + :mirrorlist, + :owner, + :group, + :url + +attribute :url, :regex => /^(file|http|https?):\/\/.*(gz|tar.gz|tgz|bin|zip)$/, :default => nil attribute :mirrorlist, :kind_of => Array, :default => nil -attribute :checksum, :regex => /^[a-zA-Z0-9]{64}$/, :default => nil +attribute :checksum, :regex => /^[0-9a-f]{32}$|^[a-zA-Z0-9]{40,64}$/, :default => nil +attribute :md5, :regex => /^[0-9a-f]{32}$|^[a-zA-Z0-9]{40,64}$/, :default => nil attribute :app_home, :kind_of => String, :default => nil attribute :app_home_mode, :kind_of => Integer, :default => 0755 -attribute :bin_cmds, :kind_of => Array, :default => nil -attribute :owner, :default => "root" +attribute :bin_cmds, :kind_of => Array, :default => [] +attribute :owner, :default => 'root' +# Will default to :owner if :group is not passed +attribute :group, :default => nil attribute :default, :equal_to => [true, false], :default => true attribute :alternatives_priority, :kind_of => Integer, :default => 1 +attribute :retries, :kind_of => Integer, :default => 0 +attribute :retry_delay, :kind_of => Integer, :default => 2 +attribute :connect_timeout, :kind_of => Integer, :default => 600 # => 10 minutes # we have to set default for the supports attribute # in initializer since it is a 'reserved' attribute name diff --git a/java/spec/default_java_symlink_spec.rb b/java/spec/default_java_symlink_spec.rb new file mode 100644 index 0000000..1b82f6c --- /dev/null +++ b/java/spec/default_java_symlink_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe 'java::default_java_symlink' do + let(:chef_run) do + ChefSpec::Runner.new.converge(described_recipe) + end + + it 'symlinks /usr/lib/jvm/default-java' do + link = chef_run.link('/usr/lib/jvm/default-java') + expect(link).to link_to(chef_run.node['java']['java_home']) + end +end diff --git a/java/spec/default_spec.rb b/java/spec/default_spec.rb index 83fb9f5..899e844 100644 --- a/java/spec/default_spec.rb +++ b/java/spec/default_spec.rb @@ -2,37 +2,42 @@ describe 'java::default' do let(:chef_run) do - runner = ChefSpec::ChefRunner.new( + runner = ChefSpec::Runner.new( :platform => 'debian', :version => '7.0' ) - runner.converge('java::default') + runner.converge(described_recipe) end it 'should include the openjdk recipe by default' do expect(chef_run).to include_recipe('java::openjdk') end + it 'includes set_attributes_from_version' do + expect(chef_run).to include_recipe('java::set_attributes_from_version') + end context 'windows' do let(:chef_run) do - runner = ChefSpec::ChefRunner.new( - 'platform' => 'windows', - 'version' => '2008R2' + runner = ChefSpec::Runner.new( + :platform => 'windows', + :version => '2008R2' ) - runner.node.set['java']['install_flavor'] = 'windows' runner.node.set['java']['windows']['url'] = 'http://example.com/windows-java.msi' - runner.converge('java::default') + runner.node.set['java']['java_home'] = 'C:/java' + runner.converge('windows::default',described_recipe) end - it 'should include the windows recipe' do - expect(chef_run).to include_recipe('java::windows') + # Running the tests on non-Windows platforms will error in the Windows library, + # but this means the recipe was included. There has to be a better way to handle this... + it 'should error on windows recipe' do + expect { chef_run }.to raise_error(TypeError) end end context 'oracle' do let(:chef_run) do - runner = ChefSpec::ChefRunner.new + runner = ChefSpec::Runner.new runner.node.set['java']['install_flavor'] = 'oracle' - runner.converge('java::default') + runner.converge(described_recipe) end it 'should include the oracle recipe' do @@ -42,9 +47,9 @@ context 'oracle_i386' do let(:chef_run) do - runner = ChefSpec::ChefRunner.new + runner = ChefSpec::Runner.new runner.node.set['java']['install_flavor'] = 'oracle_i386' - runner.converge('java::default') + runner.converge(described_recipe) end it 'should include the oracle_i386 recipe' do @@ -54,10 +59,10 @@ context 'ibm' do let(:chef_run) do - runner = ChefSpec::ChefRunner.new + runner = ChefSpec::Runner.new runner.node.set['java']['install_flavor'] = 'ibm' runner.node.set['java']['ibm']['url'] = 'http://example.com/ibm-java.bin' - runner.converge('java::default') + runner.converge(described_recipe) end it 'should include the ibm recipe' do @@ -65,4 +70,42 @@ end end + context 'ibm_tar' do + let(:chef_run) do + runner = ChefSpec::Runner.new + runner.node.set['java']['install_flavor'] = 'ibm_tar' + runner.node.set['java']['ibm']['url'] = 'http://example.com/ibm-java.tar.gz' + runner.converge(described_recipe) + end + + it 'should include the ibm_tar recipe' do + expect(chef_run).to include_recipe('java::ibm_tar') + end + end + + context 'Oracle JDK 8' do + let(:chef_run) do + runner = ChefSpec::Runner.new + runner.node.set['java']['install_flavor'] = 'oracle' + runner.node.set['java']['jdk_version'] = '8' + runner.converge(described_recipe) + end + + it 'should not error' do + expect{chef_run}.to_not raise_error + end + end + + context 'OpenJDK 8' do + let(:chef_run) do + runner = ChefSpec::Runner.new + runner.node.set['java']['install_flavor'] = 'openjdk' + runner.node.set['java']['jdk_version'] = '8' + runner.converge(described_recipe) + end + + it 'should error' do + expect{chef_run}.to raise_error + end + end end diff --git a/java/spec/ibm_spec.rb b/java/spec/ibm_spec.rb index aa3ae04..51f263f 100644 --- a/java/spec/ibm_spec.rb +++ b/java/spec/ibm_spec.rb @@ -1,28 +1,83 @@ require 'spec_helper' describe 'java::ibm' do + before do + Chef::Config[:file_cache_path] = '/var/chef/cache' + end + let(:chef_run) do - runner = ChefSpec::ChefRunner.new + runner = ChefSpec::Runner.new runner.node.set['java']['install_flavor'] = 'ibm' runner.node.set['java']['ibm']['url'] = 'http://example.com/ibm-java.bin' runner.node.set['java']['ibm']['checksum'] = 'deadbeef' runner.node.set['java']['ibm']['accept_ibm_download_terms'] = true - runner.converge('java::ibm') + runner.converge(described_recipe) end it 'creates an installer.properties file' do - expect(chef_run).to create_file('/var/chef/cache/installer.properties') + expect(chef_run).to create_template(Chef::Config[:file_cache_path] + '/installer.properties') end it 'downloads the remote jdk file' do - expect(chef_run).to create_remote_file('/var/chef/cache/ibm-java.bin') + expect(chef_run).to create_remote_file(Chef::Config[:file_cache_path] + '/ibm-java.bin') end it 'runs the installer' do - expect(chef_run).to execute_command('./ibm-java.bin -f ./installer.properties -i silent') + expect(chef_run).to run_execute('install-ibm-java').with( + :command => './ibm-java.bin -f ./installer.properties -i silent', + :creates => '/opt/ibm/java/jre/bin/java' + ) + + install_command = chef_run.execute('install-ibm-java') + expect(install_command).to notify('java_alternatives[set-java-alternatives]') end it 'includes the set_java_home recipe' do expect(chef_run).to include_recipe('java::set_java_home') end + + context 'install on ubuntu' do + let(:chef_run) do + runner = ChefSpec::Runner.new(:platform => 'ubuntu', :version => '12.04') + runner.node.set['java']['install_flavor'] = 'ibm' + runner.node.set['java']['ibm']['checksum'] = 'deadbeef' + runner.node.set['java']['ibm']['accept_ibm_download_terms'] = true + runner + end + + it 'install rpm for installable package' do + chef_run.node.set['java']['ibm']['url'] = 'http://example.com/ibm-java.bin' + chef_run.converge('java::ibm') + expect(chef_run).to install_package('rpm') + end + + it 'no need to install rpm for tgz package' do + chef_run.node.set['java']['ibm']['url'] = 'http://example.com/ibm-java-archive.bin' + chef_run.converge('java::ibm') + expect(chef_run).not_to install_package('rpm') + end + end + + context 'install on centos' do + let(:chef_run) do + runner = ChefSpec::Runner.new(:platform => 'centos', :version => '5.8') + runner.node.set['java']['install_flavor'] = 'ibm' + runner.node.set['java']['ibm']['checksum'] = 'deadbeef' + runner.node.set['java']['ibm']['accept_ibm_download_terms'] = true + runner + end + + it 'no need to install rpm for installable package' do + chef_run.node.set['java']['ibm']['url'] = 'http://example.com/ibm-java.bin' + chef_run.converge('java::ibm') + expect(chef_run).not_to install_package('rpm') + end + + it 'no need to install rpm for tgz package' do + chef_run.node.set['java']['ibm']['url'] = 'http://example.com/ibm-java-archive.bin' + chef_run.converge('java::ibm') + expect(chef_run).not_to install_package('rpm') + end + end + end diff --git a/java/spec/ibm_tar_spec.rb b/java/spec/ibm_tar_spec.rb new file mode 100644 index 0000000..8094fdd --- /dev/null +++ b/java/spec/ibm_tar_spec.rb @@ -0,0 +1,34 @@ +require 'spec_helper' + +describe 'java::ibm_tar' do + let(:chef_run) do + runner = ChefSpec::Runner.new + runner.node.set['java']['java_home'] = '/home/java' + runner.node.set['java']['install_flavor'] = 'ibm' + runner.node.set['java']['ibm']['url'] = 'http://example.com/ibm-java.tar.gz' + runner.node.set['java']['ibm']['checksum'] = 'deadbeef' + runner.converge(described_recipe) + end + + it 'downloads the remote jdk file' do + expect(chef_run).to create_remote_file(Chef::Config[:file_cache_path] + '/ibm-java.tar.gz') + end + + it 'create java_home directory' do + expect(chef_run).to create_directory('/home/java') + end + + it 'untar the jdk file' do + expect(chef_run).to run_execute('untar-ibm-java').with( + :command => 'tar xzf ./ibm-java.tar.gz -C /home/java --strip 1', + :creates => '/home/java/jre/bin/java' + ) + + untar_command = chef_run.execute('untar-ibm-java') + expect(untar_command).to notify('java_alternatives[set-java-alternatives]') + end + + it 'includes the set_java_home recipe' do + expect(chef_run).to include_recipe('java::set_java_home') + end +end diff --git a/java/spec/libraries/helpers_spec.rb b/java/spec/libraries/helpers_spec.rb index 0eb821c..f146018 100644 --- a/java/spec/libraries/helpers_spec.rb +++ b/java/spec/libraries/helpers_spec.rb @@ -23,7 +23,7 @@ { 'java' => { 'java_home' => '/usr/lib/jvm/default-java', - 'jdk_version' => 6 + 'jdk_version' => '6' }, 'kernel' => { 'machine' => 'x86_64' diff --git a/java/spec/openjdk_spec.rb b/java/spec/openjdk_spec.rb index 726de97..be8c168 100644 --- a/java/spec/openjdk_spec.rb +++ b/java/spec/openjdk_spec.rb @@ -2,57 +2,83 @@ describe 'java::openjdk' do platforms = { - 'ubuntu' => { - 'packages' => ['openjdk-6-jdk', 'default-jre-headless'], - 'versions' => ['10.04', '12.04'], + 'ubuntu-10.04' => { + 'packages' => ['openjdk-6-jdk', 'openjdk-6-jre-headless'], 'update_alts' => true }, - 'centos' => { + 'ubuntu-12.04' => { + 'packages' => ['openjdk-6-jdk', 'openjdk-6-jre-headless'], + 'update_alts' => true + }, + 'debian-6.0.5' => { + 'packages' => ['openjdk-6-jdk', 'openjdk-6-jre-headless'], + 'update_alts' => true + }, + 'debian-7.0' => { + 'packages' => ['openjdk-6-jdk', 'openjdk-6-jre-headless'], + 'update_alts' => true + }, + 'centos-6.4' => { 'packages' => ['java-1.6.0-openjdk', 'java-1.6.0-openjdk-devel'], - 'versions' => ['5.8', '6.3'], 'update_alts' => true }, - 'smartos' => { + 'smartos-joyent_20130111T180733Z' => { 'packages' => ['sun-jdk6', 'sun-jre6'], - 'versions' => ['joyent_20130111T180733Z'], 'update_alts' => false } } - # Regression test for COOK-2989 - context 'update-java-alternatives' do - let(:chef_run) do - ChefSpec::ChefRunner.new(:platform => 'ubuntu', :version => '12.04').converge('java::openjdk') - end + platforms.each do |platform, data| + parts = platform.split('-') + os = parts[0] + version = parts[1] + context "On #{os} #{version}" do + let(:chef_run) { ChefSpec::Runner.new(:platform => os, :version => version).converge(described_recipe) } + + data['packages'].each do |pkg| + it "installs package #{pkg}" do + expect(chef_run).to install_package(pkg) + end + end - it 'executes update-java-alternatives with the right commands' do - # We can't use a regexp in the matcher's #with attributes, so - # let's reproduce the code block with the heredoc + gsub: - code_string = <<-EOH.gsub(/^\s+/, '') - update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 && \ - update-alternatives --set java /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java - EOH - expect(chef_run).to execute_bash_script('update-java-alternatives').with(:code => code_string) + it 'sends notification to update-java-alternatives' do + if data['update_alts'] + expect(chef_run).to set_java_alternatives('set-java-alternatives') + else + expect(chef_run).to_not set_java_alternatives('set-java-alternatives') + end + end end end - platforms.each do |platform, data| - data['versions'].each do |version| - context "On #{platform} #{version}" do - let(:chef_run) do - ChefSpec::ChefRunner.new(:platform => platform, :version => version).converge('java::openjdk') - end + describe 'conditionally includes set attributes' do + context 'when java_home and openjdk_packages are set' do + let(:chef_run) do + runner = ChefSpec::Runner.new( + :platform => 'ubuntu', + :version => '12.04' + ) + runner.node.set['java']['java_home'] = "/some/path" + runner.node.set['java']['openjdk_packages'] = ['dummy','stump'] + runner.converge(described_recipe) + end - data['packages'].each do |pkg| - it "installs package #{pkg}" do - expect(chef_run).to install_package(pkg) - end + it 'does not include set_attributes_from_version' do + expect(chef_run).to_not include_recipe('java::set_attributes_from_version') + end + end - it 'sends notification to update-java-alternatives' do - expectation = data['update_alts'] ? :to : :not_to - expect(chef_run.package(pkg)).send(expectation, notify("bash[update-java-alternatives]", :run)) - end - end + context 'when java_home and openjdk_packages are not set' do + let(:chef_run) do + runner = ChefSpec::Runner.new( + :platform => 'ubuntu', + :version => '12.04' + ) + runner.converge(described_recipe) + end + + it 'does not include set_attributes_from_version' do + expect(chef_run).to include_recipe('java::set_attributes_from_version') end end end @@ -61,7 +87,7 @@ {'centos' => '6.3','ubuntu' => '12.04'}.each_pair do |platform, version| context platform do let(:chef_run) do - ChefSpec::ChefRunner.new(:platform => platform, :version => version).converge('java::openjdk') + ChefSpec::Runner.new(:platform => platform, :version => version).converge('java::openjdk') end it 'does not write out license file' do @@ -72,23 +98,50 @@ context 'smartos' do let(:chef_run) do - ChefSpec::ChefRunner.new(:platform => 'smartos', :version => 'joyent_20130111T180733Z', :evaluate_guards => true) + ChefSpec::Runner.new(:platform => 'smartos', :version => 'joyent_20130111T180733Z', :evaluate_guards => true) end context 'when auto_accept_license is true' do it 'writes out a license acceptance file' do chef_run.node.set['java']['accept_license_agreement'] = true - expect(chef_run.converge('java::openjdk')).to create_file("/opt/local/.dlj_license_accepted") + expect(chef_run.converge(described_recipe)).to create_file("/opt/local/.dlj_license_accepted") end end context 'when auto_accept_license is false' do it 'does not write license file' do chef_run.node.set['java']['accept_license_agreement'] = false - expect(chef_run.converge('java::openjdk')).not_to create_file("/opt/local/.dlj_license_accepted") + expect(chef_run.converge(described_recipe)).not_to create_file("/opt/local/.dlj_license_accepted") end end end + end + + describe 'default-java' do + context 'ubuntu' do + let(:chef_run) do + ChefSpec::Runner.new( + :platform => 'ubuntu', + :version => '12.04' + ).converge(described_recipe) + end + + it 'includes default_java_symlink' do + expect(chef_run).to include_recipe('java::default_java_symlink') + end + end + context 'centos' do + let(:chef_run) do + ChefSpec::Runner.new( + :platform => 'centos', + :version => '6.4' + ).converge(described_recipe) + end + + it 'does not include default_java_symlink' do + expect(chef_run).to_not include_recipe('java::default_java_symlink') + end + end end end diff --git a/java/spec/oracle_i386_spec.rb b/java/spec/oracle_i386_spec.rb index 3668646..d5a5241 100644 --- a/java/spec/oracle_i386_spec.rb +++ b/java/spec/oracle_i386_spec.rb @@ -2,8 +2,8 @@ describe 'java::oracle_i386' do let(:chef_run) do - runner = ChefSpec::ChefRunner.new - runner.converge('java::oracle_i386') + runner = ChefSpec::Runner.new + runner.converge(described_recipe) end it 'should include the set_java_home recipe' do @@ -12,5 +12,65 @@ it 'should configure a java_ark[jdk] resource' do pending "Testing LWRP use is not required at this time, this is tested post-converge." + this_should_not_get_executed + end + + describe 'conditionally includes set attributes' do + context 'when java_home is set' do + let(:chef_run) do + runner = ChefSpec::Runner.new( + :platform => 'ubuntu', + :version => '12.04' + ) + runner.node.set['java']['java_home'] = "/some/path" + runner.converge(described_recipe) + end + + it 'does not include set_attributes_from_version' do + expect(chef_run).to_not include_recipe('java::set_attributes_from_version') + end + end + + context 'when java_home is not set' do + let(:chef_run) do + runner = ChefSpec::Runner.new( + :platform => 'ubuntu', + :version => '12.04' + ) + runner.converge(described_recipe) + end + + it 'does not include set_attributes_from_version' do + expect(chef_run).to include_recipe('java::set_attributes_from_version') + end + end + end + + describe 'default-java' do + context 'ubuntu' do + let(:chef_run) do + ChefSpec::Runner.new( + :platform => 'ubuntu', + :version => '12.04' + ).converge(described_recipe) + end + + it 'includes default_java_symlink' do + expect(chef_run).to include_recipe('java::default_java_symlink') + end + end + + context 'centos' do + let(:chef_run) do + ChefSpec::Runner.new( + :platform => 'centos', + :version => '6.4' + ).converge(described_recipe) + end + + it 'does not include default_java_symlink' do + expect(chef_run).to_not include_recipe('java::default_java_symlink') + end + end end end diff --git a/java/spec/oracle_rpm_spec.rb b/java/spec/oracle_rpm_spec.rb new file mode 100644 index 0000000..8c8198b --- /dev/null +++ b/java/spec/oracle_rpm_spec.rb @@ -0,0 +1,154 @@ +require 'spec_helper' + +describe 'java::oracle_rpm' do + let(:chef_run) do + ChefSpec::Runner.new(platform: 'redhat', version: '6.5') do |node| + node.automatic['java']['install_flavor'] = 'oracle_rpm' + end.converge(described_recipe) + end + + it 'includes the set_java_home recipe' do + expect(chef_run).to include_recipe('java::set_java_home') + end + + describe 'update-java-alternatives' do + let(:chef_run) do + ChefSpec::Runner.new(platform: platform, version: version) do |node| + node.automatic['java']['install_flavor'] = 'oracle_rpm' + node.set['java']['set_default'] = true + end.converge(described_recipe) + end + + describe 'for RHEL' do + let(:platform) { 'redhat' } + let(:version) { '6.5' } + + it 'does not run bash command' do + expect(chef_run).not_to run_bash('update-java-alternatives') + end + end + end + + describe 'package_name attribute' do + describe 'using default value' do + let(:chef_run) do + ChefSpec::Runner.new do |node| + node.automatic['java']['install_flavor'] = 'oracle_rpm' + end.converge(described_recipe) + end + + it 'does not install package_name' do + expect(chef_run).not_to install_package('') + end + end + + context 'when package_name is set' do + let(:chef_run) do + ChefSpec::Runner.new do |node| + node.automatic['java']['install_flavor'] = 'oracle_rpm' + node.set['java']['oracle_rpm']['package_name'] = 'prime-caffeine' + end.converge(described_recipe) + end + + it 'installs package_name' do + expect(chef_run).to install_package('prime-caffeine') + end + end + + context 'when package_name and package_version is set' do + let(:chef_run) do + ChefSpec::Runner.new do |node| + node.automatic['java']['install_flavor'] = 'oracle_rpm' + node.set['java']['oracle_rpm']['package_name'] = 'prime-caffeine' + node.set['java']['oracle_rpm']['package_version'] = '8.7.6-goldmaster' + end.converge(described_recipe) + end + + it 'installs package_name with specific version' do + expect(chef_run).to install_package('prime-caffeine').with( + version: '8.7.6-goldmaster' + ) + end + end + + context 'when type is set' do + let(:chef_run) do + ChefSpec::Runner.new do |node| + node.automatic['java']['install_flavor'] = 'oracle_rpm' + node.set['java']['oracle_rpm']['type'] = 'jdk' + end.converge(described_recipe) + end + + it 'installs type' do + expect(chef_run).to install_package('jdk') + end + end + + context 'when package_name and type are set' do + let(:chef_run) do + ChefSpec::Runner.new do |node| + node.automatic['java']['install_flavor'] = 'oracle_rpm' + node.set['java']['oracle_rpm']['package_name'] = 'top-shelf-beans' + node.set['java']['oracle_rpm']['type'] = 'jdk' + end.converge(described_recipe) + end + + it 'installs package_name instead of type' do + expect(chef_run).to install_package('top-shelf-beans') + end + end + end + + describe 'type attribute' do + let(:chef_run) do + ChefSpec::Runner.new do |node| + node.automatic['java']['install_flavor'] = 'oracle_rpm' + node.set['java']['oracle_rpm']['type'] = type + end.converge(described_recipe) + end + + describe 'using default value' do + let(:chef_run) do + ChefSpec::Runner.new do |node| + node.automatic['java']['install_flavor'] = 'oracle_rpm' + end.converge(described_recipe) + end + + it 'installs jdk package' do + expect(chef_run).to install_package('jdk') + end + end + + describe 'for valid values' do + shared_examples 'expected java packages are installed' do + it "installs package" do + expect(chef_run).to install_package(type) + end + + it 'does not raise an error' do + expect { chef_run }.not_to raise_error + end + end + + context 'for jdk' do + let(:type) { 'jdk' } + + it_behaves_like 'expected java packages are installed' + end + + context 'for jre' do + let(:type) { 'jre' } + + it_behaves_like 'expected java packages are installed' + end + end + + describe 'for invalid values' do + let(:type) { 'banana' } + + it 'raises an error' do + expect { chef_run }.to raise_error + end + end + end +end diff --git a/java/spec/oracle_spec.rb b/java/spec/oracle_spec.rb index 78514ae..077e552 100644 --- a/java/spec/oracle_spec.rb +++ b/java/spec/oracle_spec.rb @@ -2,8 +2,8 @@ describe 'java::oracle' do let(:chef_run) do - runner = ChefSpec::ChefRunner.new - runner.converge('java::oracle') + runner = ChefSpec::Runner.new + runner.converge(described_recipe) end it 'should include the set_java_home recipe' do @@ -12,5 +12,65 @@ it 'should configure a java_ark[jdk] resource' do pending "Testing LWRP use is not required at this time, this is tested post-converge." + this_should_not_get_executed + end + + describe 'conditionally includes set attributes' do + context 'when java_home is set' do + let(:chef_run) do + runner = ChefSpec::Runner.new( + :platform => 'ubuntu', + :version => '12.04' + ) + runner.node.set['java']['java_home'] = "/some/path" + runner.converge(described_recipe) + end + + it 'does not include set_attributes_from_version' do + expect(chef_run).to_not include_recipe('java::set_attributes_from_version') + end + end + + context 'when java_home is not set' do + let(:chef_run) do + runner = ChefSpec::Runner.new( + :platform => 'ubuntu', + :version => '12.04' + ) + runner.converge(described_recipe) + end + + it 'does not include set_attributes_from_version' do + expect(chef_run).to include_recipe('java::set_attributes_from_version') + end + end + end + + describe 'default-java' do + context 'ubuntu' do + let(:chef_run) do + ChefSpec::Runner.new( + :platform => 'ubuntu', + :version => '12.04' + ).converge(described_recipe) + end + + it 'includes default_java_symlink' do + expect(chef_run).to include_recipe('java::default_java_symlink') + end + end + + context 'centos' do + let(:chef_run) do + ChefSpec::Runner.new( + :platform => 'centos', + :version => '6.4' + ).converge(described_recipe) + end + + it 'does not include default_java_symlink' do + expect(chef_run).to_not include_recipe('java::default_java_symlink') + end + end end end diff --git a/java/spec/set_attributes_from_version_spec.rb b/java/spec/set_attributes_from_version_spec.rb new file mode 100644 index 0000000..943c73c --- /dev/null +++ b/java/spec/set_attributes_from_version_spec.rb @@ -0,0 +1,59 @@ +require 'spec_helper' + +describe 'java::set_attributes_from_version' do + platforms = { + 'centos-6.4' => { + 'java_home' => '/usr/lib/jvm/java-1.6.0', + 'packages' => ['java-1.6.0-openjdk', 'java-1.6.0-openjdk-devel'] + }, + 'redhat-6.3' => { + 'java_home' => '/usr/lib/jvm/java-1.6.0', + 'packages' => ['java-1.6.0-openjdk', 'java-1.6.0-openjdk-devel'] + }, + 'freebsd-9.1' => { + 'java_home' => "/usr/local/openjdk6", + 'packages' => ["openjdk6"] + }, + 'debian-7.0' => { + 'java_home' => '/usr/lib/jvm/java-6-openjdk-amd64', + 'packages' => ['openjdk-6-jdk', 'openjdk-6-jre-headless'] + }, + 'ubuntu-12.04' => { + 'java_home' => '/usr/lib/jvm/java-6-openjdk-amd64', + 'packages' => ['openjdk-6-jdk', 'openjdk-6-jre-headless'] + }, + 'debian-6.0.5' => { + 'java_home' => '/usr/lib/jvm/java-6-openjdk', + 'packages' => ['openjdk-6-jdk', 'openjdk-6-jre-headless'] + }, + 'ubuntu-10.04' => { + 'java_home' => '/usr/lib/jvm/java-6-openjdk', + 'packages' => ['openjdk-6-jdk', 'openjdk-6-jre-headless'] + }, + 'smartos-joyent_20130111T180733Z' => { + 'java_home' => '/opt/local/java/sun6', + 'packages' => ['sun-jdk6', 'sun-jre6'] + }, + 'windows-2008R2' => { + 'java_home' => nil, + 'packages' => [] + } + } + + platforms.each do |platform, params| + parts = platform.split('-') + os = parts[0] + version = parts[1] + context "On #{os} #{version}" do + let(:chef_run) { ChefSpec::Runner.new(:version => version, :platform => os).converge(described_recipe) } + + it 'has the correct java_home' do + expect(chef_run.node['java']['java_home']).to eq(params['java_home']) + end + + it 'has the correct openjdk_packages' do + expect(chef_run.node['java']['openjdk_packages']).to eq(params['packages']) + end + end + end +end diff --git a/java/spec/set_java_home_spec.rb b/java/spec/set_java_home_spec.rb index 54c2267..db640da 100644 --- a/java/spec/set_java_home_spec.rb +++ b/java/spec/set_java_home_spec.rb @@ -1,24 +1,43 @@ require 'spec_helper' describe 'java::set_java_home' do - let(:chef_run) do - runner = ChefSpec::ChefRunner.new - runner.node.set['java']['java_home'] = '/opt/java' - runner.converge('java::set_java_home') - end - it 'it should set the java home environment variable' do - expect(chef_run).to execute_ruby_block('set-env-java-home') - end + context 'set_java_home'do + let(:chef_run) do + runner = ChefSpec::Runner.new + runner.node.set['java']['java_home'] = '/opt/java' + runner.converge(described_recipe) + end + it 'it should set the java home environment variable' do + expect(chef_run).to run_ruby_block('set-env-java-home') + expect(chef_run).to_not run_ruby_block('Set JAVA_HOME in /etc/environment') + end - it 'should create the profile.d directory' do - expect(chef_run).to create_directory('/etc/profile.d') - end + it 'should create the profile.d directory' do + expect(chef_run).to create_directory('/etc/profile.d') + end - it 'should create jdk.sh with the java home environment variable' do - expect(chef_run).to create_file_with_content( - '/etc/profile.d/jdk.sh', - 'export JAVA_HOME=/opt/java' - ) + it 'should create jdk.sh with the java home environment variable' do + expect(chef_run).to render_file('/etc/profile.d/jdk.sh').with_content('export JAVA_HOME=/opt/java') + end end + context 'set_java_home_environment' do + let(:chef_run) do + runner = ChefSpec::Runner.new + runner.node.set['java']['java_home'] = '/opt/java' + runner.node.set['java']['set_etc_environment'] = true + runner.converge(described_recipe) + end + it 'it should set the java home environment variable' do + expect(chef_run).to run_ruby_block('set-env-java-home') + end + + it 'should create the profile.d directory' do + expect(chef_run).to create_directory('/etc/profile.d') + end + + it 'should create /etc/environment with the java home variable' do + expect(chef_run).to run_ruby_block('Set JAVA_HOME in /etc/environment') + end + end end diff --git a/java/spec/spec_helper.rb b/java/spec/spec_helper.rb index 803b1b1..58f9849 100644 --- a/java/spec/spec_helper.rb +++ b/java/spec/spec_helper.rb @@ -1,12 +1,12 @@ $:.unshift(File.join(File.dirname(__FILE__), '..', 'libraries')) require 'helpers' require 'chefspec' +require 'chefspec/berkshelf' RSpec.configure do |config| - config.color_enabled = true + config.color = true config.tty = true config.formatter = :documentation - config.treat_symbols_as_metadata_keys_with_true_values = true config.filter_run :focus => true config.run_all_when_everything_filtered = true config.expect_with :rspec do |c| diff --git a/java/spec/windows_spec.rb b/java/spec/windows_spec.rb index a93423d..94fbe68 100644 --- a/java/spec/windows_spec.rb +++ b/java/spec/windows_spec.rb @@ -1,8 +1,17 @@ require 'chefspec' describe 'java::windows' do - let(:chef_run) { ChefSpec::ChefRunner.new.converge 'java::windows' } + let(:chef_run) do + runner = ChefSpec::Runner.new( + :platform => 'windows', + :version => '2008R2' + ) + runner.node.set['java']['windows']['url'] = 'http://example.com/windows-java.msi' + runner.node.set['java']['java_home'] = 'C:/java' + runner.converge('windows::default',described_recipe) + end it 'should do something' do pending 'Your recipe examples go here.' + this_should_not_get_executed end end diff --git a/java/test/integration/openjdk-7/bats/verify_openjdk-7.bats b/java/test/integration/openjdk-7/bats/verify_openjdk-7.bats new file mode 100644 index 0000000..dcba2d1 --- /dev/null +++ b/java/test/integration/openjdk-7/bats/verify_openjdk-7.bats @@ -0,0 +1,14 @@ +@test "installs the correct version of the jdk" { + java -version 2>&1 | grep 1.7 +} + +@test "properly sets JAVA_HOME environment variable" { + source /etc/profile.d/jdk.sh + run test -d $JAVA_HOME + [ "$status" -eq 0 ] +} + +@test "properly links jar" { + run test -L /usr/bin/jar + [ "$status" -eq 0 ] +} diff --git a/java/test/integration/openjdk/bats/verify_openjdk.bats b/java/test/integration/openjdk/bats/verify_openjdk.bats new file mode 100644 index 0000000..a617a03 --- /dev/null +++ b/java/test/integration/openjdk/bats/verify_openjdk.bats @@ -0,0 +1,14 @@ +@test "installs the correct version of the jdk" { + java -version 2>&1 | grep 1.6 +} + +@test "properly sets JAVA_HOME environment variable" { + source /etc/profile.d/jdk.sh + run test -d $JAVA_HOME + [ "$status" -eq 0 ] +} + +@test "properly links jar" { + run test -L /usr/bin/jar + [ "$status" -eq 0 ] +} diff --git a/java/test/integration/oracle-7/bats/verify_oracle-7.bats b/java/test/integration/oracle-7/bats/verify_oracle-7.bats new file mode 100644 index 0000000..dcba2d1 --- /dev/null +++ b/java/test/integration/oracle-7/bats/verify_oracle-7.bats @@ -0,0 +1,14 @@ +@test "installs the correct version of the jdk" { + java -version 2>&1 | grep 1.7 +} + +@test "properly sets JAVA_HOME environment variable" { + source /etc/profile.d/jdk.sh + run test -d $JAVA_HOME + [ "$status" -eq 0 ] +} + +@test "properly links jar" { + run test -L /usr/bin/jar + [ "$status" -eq 0 ] +} diff --git a/java/test/integration/oracle-8/bats/verify_oracle-8.bats b/java/test/integration/oracle-8/bats/verify_oracle-8.bats new file mode 100644 index 0000000..a9f0ba9 --- /dev/null +++ b/java/test/integration/oracle-8/bats/verify_oracle-8.bats @@ -0,0 +1,14 @@ +@test "installs the correct version of the jdk" { + java -version 2>&1 | grep 1.8 +} + +@test "properly sets JAVA_HOME environment variable" { + source /etc/profile.d/jdk.sh + run test -d $JAVA_HOME + [ "$status" -eq 0 ] +} + +@test "properly links jar" { + run test -L /usr/bin/jar + [ "$status" -eq 0 ] +} diff --git a/java/test/integration/oracle/bats/verify_oracle.bats b/java/test/integration/oracle/bats/verify_oracle.bats new file mode 100644 index 0000000..a617a03 --- /dev/null +++ b/java/test/integration/oracle/bats/verify_oracle.bats @@ -0,0 +1,14 @@ +@test "installs the correct version of the jdk" { + java -version 2>&1 | grep 1.6 +} + +@test "properly sets JAVA_HOME environment variable" { + source /etc/profile.d/jdk.sh + run test -d $JAVA_HOME + [ "$status" -eq 0 ] +} + +@test "properly links jar" { + run test -L /usr/bin/jar + [ "$status" -eq 0 ] +}