├── .devcontainer ├── Dockerfile ├── README.md └── devcontainer.json ├── .fixtures.yml ├── .gitattributes ├── .github ├── pull_request_template.md └── workflows │ ├── ci.yml │ ├── mend.yml │ ├── nightly.yml │ ├── release.yml │ └── release_prep.yml ├── .gitignore ├── .gitpod.Dockerfile ├── .gitpod.yml ├── .pdkignore ├── .puppet-lint.rc ├── .rspec ├── .rubocop.yml ├── .rubocop_todo.yml ├── .sync.yml ├── .vscode └── extensions.json ├── .yardopts ├── CHANGELOG.md ├── CODEOWNERS ├── CONTRIBUTING.md ├── Gemfile ├── HISTORY.md ├── LICENSE ├── NOTICE ├── README.md ├── REFERENCE.md ├── Rakefile ├── data └── common.yaml ├── examples ├── alternative.pp ├── init.pp └── oracle.pp ├── hiera.yaml ├── lib └── facter │ ├── java_default_home.rb │ ├── java_libjvm_path.rb │ ├── java_major_version.rb │ ├── java_patch_level.rb │ └── java_version.rb ├── manifests ├── adopt.pp ├── adoptium.pp ├── config.pp ├── download.pp ├── init.pp ├── params.pp └── sap.pp ├── metadata.json ├── pdk.yaml ├── provision.yaml └── spec ├── acceptance └── install_spec.rb ├── classes └── java_spec.rb ├── default_facts.yml ├── defines ├── adopt_spec.rb ├── adoptium_spec.rb ├── download_spec.rb └── sap_spec.rb ├── spec_helper.rb ├── spec_helper_acceptance.rb ├── spec_helper_acceptance_local.rb ├── spec_helper_local.rb └── unit └── facter ├── java_default_home_spec.rb ├── java_libjvm_path_spec.rb ├── java_major_version_spec.rb ├── java_patch_level_spec.rb └── java_version_spec.rb /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM puppet/pdk:latest 2 | 3 | # [Optional] Uncomment this section to install additional packages. 4 | # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ 5 | # && apt-get -y install --no-install-recommends 6 | 7 | -------------------------------------------------------------------------------- /.devcontainer/README.md: -------------------------------------------------------------------------------- 1 | # devcontainer 2 | 3 | 4 | For format details, see https://aka.ms/devcontainer.json. 5 | 6 | For config options, see the README at: 7 | https://github.com/microsoft/vscode-dev-containers/tree/v0.140.1/containers/puppet 8 | 9 | ``` json 10 | { 11 | "name": "Puppet Development Kit (Community)", 12 | "dockerFile": "Dockerfile", 13 | 14 | // Set *default* container specific settings.json values on container create. 15 | "settings": { 16 | "terminal.integrated.profiles.linux": { 17 | "bash": { 18 | "path": "bash", 19 | } 20 | } 21 | }, 22 | 23 | // Add the IDs of extensions you want installed when the container is created. 24 | "extensions": [ 25 | "puppet.puppet-vscode", 26 | "rebornix.Ruby" 27 | ], 28 | 29 | // Use 'forwardPorts' to make a list of ports inside the container available locally. 30 | "forwardPorts": [], 31 | 32 | // Use 'postCreateCommand' to run commands after the container is created. 33 | "postCreateCommand": "pdk --version", 34 | } 35 | ``` 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Puppet Development Kit (Community)", 3 | "dockerFile": "Dockerfile", 4 | 5 | "settings": { 6 | "terminal.integrated.profiles.linux": { 7 | "bash": { 8 | "path": "bash" 9 | } 10 | } 11 | }, 12 | 13 | "extensions": [ 14 | "puppet.puppet-vscode", 15 | "rebornix.Ruby" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /.fixtures.yml: -------------------------------------------------------------------------------- 1 | fixtures: 2 | repositories: 3 | archive: "https://github.com/voxpupuli/puppet-archive.git" 4 | facts: 'https://github.com/puppetlabs/puppetlabs-facts.git' 5 | stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git" 6 | puppet_agent: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' 7 | provision: 'https://github.com/puppetlabs/provision.git' 8 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.rb eol=lf 2 | *.erb eol=lf 3 | *.pp eol=lf 4 | *.sh eol=lf 5 | *.epp eol=lf 6 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## Summary 2 | Provide a detailed description of all the changes present in this pull request. 3 | 4 | ## Additional Context 5 | Add any additional context about the problem here. 6 | - [ ] Root cause and the steps to reproduce. (If applicable) 7 | - [ ] Thought process behind the implementation. 8 | 9 | ## Related Issues (if any) 10 | Mention any related issues or pull requests. 11 | 12 | ## Checklist 13 | - [ ] 🟢 Spec tests. 14 | - [ ] 🟢 Acceptance tests. 15 | - [ ] Manually verified. (For example `puppet apply`) -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: "ci" 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - "main" 7 | workflow_dispatch: 8 | 9 | jobs: 10 | Spec: 11 | uses: "puppetlabs/cat-github-actions/.github/workflows/module_ci.yml@main" 12 | secrets: "inherit" 13 | 14 | Acceptance: 15 | needs: Spec 16 | uses: "puppetlabs/cat-github-actions/.github/workflows/module_acceptance.yml@main" 17 | secrets: "inherit" 18 | with: 19 | runs_on: "ubuntu-24.04" 20 | flags: "--exclude-platforms '[\"Ubuntu-24.04-arm\", \"Ubuntu-22.04-arm\", \"RedHat-9-arm\", \"Debian-12-arm\"]'" 21 | -------------------------------------------------------------------------------- /.github/workflows/mend.yml: -------------------------------------------------------------------------------- 1 | name: "mend" 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - "main" 7 | schedule: 8 | - cron: "0 0 * * *" 9 | workflow_dispatch: 10 | 11 | jobs: 12 | 13 | mend: 14 | uses: "puppetlabs/cat-github-actions/.github/workflows/mend_ruby.yml@main" 15 | secrets: "inherit" 16 | -------------------------------------------------------------------------------- /.github/workflows/nightly.yml: -------------------------------------------------------------------------------- 1 | name: "nightly" 2 | 3 | on: 4 | schedule: 5 | - cron: "0 0 * * *" 6 | workflow_dispatch: 7 | 8 | jobs: 9 | Spec: 10 | uses: "puppetlabs/cat-github-actions/.github/workflows/module_ci.yml@main" 11 | secrets: "inherit" 12 | 13 | Acceptance: 14 | needs: Spec 15 | uses: "puppetlabs/cat-github-actions/.github/workflows/module_acceptance.yml@main" 16 | secrets: "inherit" 17 | with: 18 | runs_on: "ubuntu-24.04" 19 | flags: "--exclude-platforms '[\"Ubuntu-24.04-arm\", \"Ubuntu-22.04-arm\", \"RedHat-9-arm\", \"Debian-12-arm\"]'" 20 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: "Publish module" 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | release: 8 | uses: "puppetlabs/cat-github-actions/.github/workflows/module_release.yml@main" 9 | secrets: "inherit" 10 | -------------------------------------------------------------------------------- /.github/workflows/release_prep.yml: -------------------------------------------------------------------------------- 1 | name: "Release Prep" 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | version: 7 | description: "Module version to be released. Must be a valid semver string. (1.2.3)" 8 | required: true 9 | 10 | jobs: 11 | release_prep: 12 | uses: "puppetlabs/cat-github-actions/.github/workflows/module_release_prep.yml@main" 13 | with: 14 | version: "${{ github.event.inputs.version }}" 15 | secrets: "inherit" 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .git/ 2 | .*.sw[op] 3 | .metadata 4 | .yardoc 5 | .yardwarns 6 | *.iml 7 | /.bundle/ 8 | /.idea/ 9 | /.vagrant/ 10 | /coverage/ 11 | /bin/ 12 | /doc/ 13 | /Gemfile.local 14 | /Gemfile.lock 15 | /junit/ 16 | /log/ 17 | /pkg/ 18 | /spec/fixtures/manifests/ 19 | /spec/fixtures/modules/* 20 | /tmp/ 21 | /vendor/ 22 | /.vendor/ 23 | /convert_report.txt 24 | /update_report.txt 25 | .DS_Store 26 | .project 27 | .envrc 28 | /inventory.yaml 29 | /spec/fixtures/litmus_inventory.yaml 30 | .resource_types 31 | .modules 32 | .task_cache.json 33 | .plan_cache.json 34 | .rerun.json 35 | bolt-debug.log 36 | -------------------------------------------------------------------------------- /.gitpod.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM gitpod/workspace-full 2 | RUN sudo wget https://apt.puppet.com/puppet-tools-release-bionic.deb && \ 3 | wget https://apt.puppetlabs.com/puppet6-release-bionic.deb && \ 4 | sudo dpkg -i puppet6-release-bionic.deb && \ 5 | sudo dpkg -i puppet-tools-release-bionic.deb && \ 6 | sudo apt-get update && \ 7 | sudo apt-get install -y pdk zsh puppet-agent && \ 8 | sudo apt-get clean && \ 9 | sudo rm -rf /var/lib/apt/lists/* 10 | RUN sudo usermod -s $(which zsh) gitpod && \ 11 | sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" && \ 12 | echo "plugins=(git gitignore github gem pip bundler python ruby docker docker-compose)" >> /home/gitpod/.zshrc && \ 13 | echo 'PATH="$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/puppetlabs/bin:/opt/puppetlabs/puppet/bin"' >> /home/gitpod/.zshrc && \ 14 | sudo /opt/puppetlabs/puppet/bin/gem install puppet-debugger hub -N && \ 15 | mkdir -p /home/gitpod/.config/puppet && \ 16 | /opt/puppetlabs/puppet/bin/ruby -r yaml -e "puts ({'disabled' => true}).to_yaml" > /home/gitpod/.config/puppet/analytics.yml 17 | RUN rm -f puppet6-release-bionic.deb puppet-tools-release-bionic.deb 18 | ENTRYPOINT /usr/bin/zsh 19 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | image: 2 | file: .gitpod.Dockerfile 3 | 4 | tasks: 5 | - init: pdk bundle install 6 | 7 | vscode: 8 | extensions: 9 | - puppet.puppet-vscode@1.2.0:f5iEPbmOj6FoFTOV6q8LTg== 10 | -------------------------------------------------------------------------------- /.pdkignore: -------------------------------------------------------------------------------- 1 | .git/ 2 | .*.sw[op] 3 | .metadata 4 | .yardoc 5 | .yardwarns 6 | *.iml 7 | /.bundle/ 8 | /.idea/ 9 | /.vagrant/ 10 | /coverage/ 11 | /bin/ 12 | /doc/ 13 | /Gemfile.local 14 | /Gemfile.lock 15 | /junit/ 16 | /log/ 17 | /pkg/ 18 | /spec/fixtures/manifests/ 19 | /spec/fixtures/modules/* 20 | /tmp/ 21 | /vendor/ 22 | /.vendor/ 23 | /convert_report.txt 24 | /update_report.txt 25 | .DS_Store 26 | .project 27 | .envrc 28 | /inventory.yaml 29 | /spec/fixtures/litmus_inventory.yaml 30 | .resource_types 31 | .modules 32 | .task_cache.json 33 | .plan_cache.json 34 | .rerun.json 35 | bolt-debug.log 36 | /.fixtures.yml 37 | /Gemfile 38 | /.gitattributes 39 | /.github/ 40 | /.gitignore 41 | /.pdkignore 42 | /.puppet-lint.rc 43 | /Rakefile 44 | /rakelib/ 45 | /.rspec 46 | /..yml 47 | /.yardopts 48 | /spec/ 49 | /.vscode/ 50 | /.sync.yml 51 | /.devcontainer/ 52 | -------------------------------------------------------------------------------- /.puppet-lint.rc: -------------------------------------------------------------------------------- 1 | --relative 2 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --format documentation 3 | -------------------------------------------------------------------------------- /.rubocop_todo.yml: -------------------------------------------------------------------------------- 1 | # This configuration was generated by 2 | # `rubocop --auto-gen-config` 3 | # on 2023-11-28 05:16:01 UTC using RuboCop version 1.48.1. 4 | # The point is for the user to remove these configuration records 5 | # one by one as the offenses are removed from the code base. 6 | # Note that changes in the inspected code, or installation of new 7 | # versions of RuboCop, may require this file to be generated again. 8 | 9 | # Offense count: 2 10 | # Configuration parameters: EnforcedStyle, IgnoreSharedExamples. 11 | # SupportedStyles: always, named_only 12 | RSpec/NamedSubject: 13 | Exclude: 14 | - 'spec/defines/download_spec.rb' 15 | -------------------------------------------------------------------------------- /.sync.yml: -------------------------------------------------------------------------------- 1 | --- 2 | ".gitlab-ci.yml": 3 | delete: true 4 | appveyor.yml: 5 | delete: true 6 | .rubocop.yml: 7 | include_todos: true 8 | spec/spec_helper.rb: 9 | mock_with: ":rspec" 10 | coverage_report: true 11 | .gitpod.Dockerfile: 12 | unmanaged: false 13 | .gitpod.yml: 14 | unmanaged: false 15 | .github/workflows/auto_release.yml: 16 | unmanaged: false 17 | .github/workflows/ci.yml: 18 | unmanaged: false 19 | .github/workflows/nightly.yml: 20 | unmanaged: false 21 | .github/workflows/release.yml: 22 | unmanaged: false 23 | .travis.yml: 24 | delete: true 25 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "puppet.puppet-vscode", 4 | "Shopify.ruby-lsp" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /.yardopts: -------------------------------------------------------------------------------- 1 | --markup markdown 2 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Setting ownership to the modules team 2 | # include Trusted Contributors 3 | * @puppetlabs/modules @bastelfreak 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Puppet modules 2 | 3 | Check out our [Contributing to Supported Modules Blog Post](https://puppetlabs.github.io/iac/docs/contributing_to_a_module.html) to find all the information that you will need. 4 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source ENV['GEM_SOURCE'] || 'https://rubygems.org' 2 | 3 | def location_for(place_or_version, fake_version = nil) 4 | git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} 5 | file_url_regex = %r{\Afile:\/\/(?.*)} 6 | 7 | if place_or_version && (git_url = place_or_version.match(git_url_regex)) 8 | [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact 9 | elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) 10 | ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] 11 | else 12 | [place_or_version, { require: false }] 13 | end 14 | end 15 | 16 | group :development do 17 | gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) 18 | gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) 19 | gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) 20 | gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) 21 | gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) 22 | gem "racc", '~> 1.4.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) 23 | gem "deep_merge", '~> 1.2.2', require: false 24 | gem "voxpupuli-puppet-lint-plugins", '~> 5.0', require: false 25 | gem "facterdb", '~> 2.1', require: false 26 | gem "metadata-json-lint", '~> 4.0', require: false 27 | gem "rspec-puppet-facts", '~> 4.0', require: false 28 | gem "dependency_checker", '~> 1.0.0', require: false 29 | gem "parallel_tests", '= 3.12.1', require: false 30 | gem "pry", '~> 0.10', require: false 31 | gem "simplecov-console", '~> 0.9', require: false 32 | gem "puppet-debugger", '~> 1.0', require: false 33 | gem "rubocop", '~> 1.50.0', require: false 34 | gem "rubocop-performance", '= 1.16.0', require: false 35 | gem "rubocop-rspec", '= 2.19.0', require: false 36 | gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] 37 | gem "rexml", '>= 3.3.9', require: false 38 | end 39 | group :development, :release_prep do 40 | gem "puppet-strings", '~> 4.0', require: false 41 | gem "puppetlabs_spec_helper", '~> 7.0', require: false 42 | end 43 | group :system_tests do 44 | gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw] 45 | gem "CFPropertyList", '< 3.0.7', require: false, platforms: [:mswin, :mingw, :x64_mingw] 46 | gem "serverspec", '~> 2.41', require: false 47 | end 48 | 49 | puppet_version = ENV['PUPPET_GEM_VERSION'] 50 | facter_version = ENV['FACTER_GEM_VERSION'] 51 | hiera_version = ENV['HIERA_GEM_VERSION'] 52 | 53 | gems = {} 54 | 55 | gems['puppet'] = location_for(puppet_version) 56 | 57 | # If facter or hiera versions have been specified via the environment 58 | # variables 59 | 60 | gems['facter'] = location_for(facter_version) if facter_version 61 | gems['hiera'] = location_for(hiera_version) if hiera_version 62 | 63 | gems.each do |gem_name, gem_params| 64 | gem gem_name, *gem_params 65 | end 66 | 67 | # Evaluate Gemfile.local and ~/.gemfile if they exist 68 | extra_gemfiles = [ 69 | "#{__FILE__}.local", 70 | File.join(Dir.home, '.gemfile'), 71 | ] 72 | 73 | extra_gemfiles.each do |gemfile| 74 | if File.file?(gemfile) && File.readable?(gemfile) 75 | eval(File.read(gemfile), binding) 76 | end 77 | end 78 | # vim: syntax=ruby 79 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | ## 2.4.0 2 | ### Summary 3 | This release uses the PDK convert functionality which in return makes the module PDK compliant. Also includes a clean up from Rubocop. 4 | 5 | #### Changed 6 | - 1.3.2 PDK convert has been applied [MODULES-6456](https://tickets.puppetlabs.com/browse/MODULES-6456) 7 | - The modules has undergone a Rubocop cleanup. 8 | 9 | #### Fixed 10 | - $java_home for SLES 11.4 has been updated to the correct location. 11 | 12 | ## Supported Release [2.3.0] 13 | ### Summary 14 | This release is in order to implement Rubocop changes into the module. 15 | 16 | #### Added 17 | - Several Modulesync changes have been made. 18 | - Rubocop has been implemented in the module. 19 | - CentOS 7 is now supported. 20 | - Red Hat Enterprise Linux (RHEL) 7 is now supported. 21 | - Ubuntu artful 1710 now supported. 22 | - Bionic 1804 now supported. 23 | 24 | ## Supported Release [2.2.0] 25 | ### Summary 26 | This release is a maintenance release that includes a roll up of minor changes. 27 | 28 | #### Added 29 | - Addition of Ubuntu for Oracle Java. 30 | - Addition of Debian 9 in supported versions. 31 | - Addition of OpenBSD case and use `realpath` rather than `readlink` in Java Default Home Facter fact. 32 | 33 | #### Removed 34 | - Removal of OpenBSD as a special case and deprecated `with_env` in Java Version Facter Facter fact. 35 | 36 | ## Supported Release 2.1.1 37 | ### Summary 38 | This release is a maintenance release that includes a roll up of minor changes. 39 | 40 | #### Added 41 | - Basic Arch Linux, Cloud Linux and Ubuntu 17.04 compatibility. 42 | - Metadata bump for Puppet 5. 43 | - Search for matching line with java version. 44 | - ([MODULES-4069](https://tickets.puppet.com/browse/MODULES-4069)) Fail when required params are not available in params. 45 | - A test for java version when java not installed. 46 | - Allow latest archive version as dependency. 47 | 48 | #### Changed 49 | - CONTRIBUTING.md document includes updates. 50 | - Removal of Ubuntu 10.04 ad 12.04, Debian 6 in supported versions. 51 | 52 | ## Supported Release 2.1.0 53 | ### Summary 54 | This release adds fixes to restore the ability to install Oracle Java. It also fixes the paths for the latest RHEL 7 1.7.0 and 1.8.0 OpenJDKs. 55 | 56 | ### Added 57 | - java::oracle parameter `url` 58 | - java::oracle parameter `url_hash` 59 | 60 | ### Fixed 61 | - Let `java_default_home` fact work when /usr/bin/java does not exist 62 | - Add puppet 4 parameter types 63 | - Use `/usr/lib/jvm/java-1.x.0` symlinks for `java_home` defaults. 64 | 65 | ## Supported Release 2.0.0 66 | ### Summary 67 | 68 | This is a major release including some bug fixes, new parameters, and general module updates. 69 | 70 | **This release drops Puppet 3 support** 71 | 72 | #### Added 73 | - Debian Stretch, Yakkety Yak, Amazon Linux, Oracle Linux, Scientific Linux CERN compatibility 74 | - `version_major` and `version_minor` parameters for specifying Java SE version to install 75 | - `$JAVA_HOME` now set by the module on compatible systems. The `java_home` parameter is also provided for manual setting. [MODULES-2971](https://tickets.puppetlabs.com/browse/MODULES-2971) 76 | - `proxy_server` and `proxy_type` for choosing a proxy server to get Java from 77 | 78 | #### Changed 79 | - Moved lower Puppet version requirement to 4.7.0 80 | 81 | #### Fixed 82 | - Module no longer downloads the Java archive on Puppet runs if Java is already installed. 83 | - java_default_home fact is not always correct on oracle packages [MODULES-4050](https://tickets.puppetlabs.com/browse/MODULES-4050) 84 | - Order of operations for archives [MODULES-4751](https://tickets.puppetlabs.com/browse/https://tickets.puppetlabs.com/browse/MODULES-4751) 85 | - Increase Xmx setting for `java_version` fact [MODULES-4736](https://tickets.puppetlabs.com/browse/MODULES-4736) 86 | 87 | ## Supported Release 1.6.0 88 | ### Summary 89 | 90 | Addition of a new supported OS, along with several other features and bugfixes. 91 | 92 | #### Features 93 | - Ubuntu 16.04 support. 94 | - Addition example for installing Java 8. 95 | - Update to newest modulesync_configs. 96 | - Addition of RedHat for Oracle Java. 97 | 98 | #### Bugfixes 99 | - Custom archive type now given extract_path. 100 | - Fix for rspec deprectation warnings. 101 | - Typo fixes for readme. 102 | - Fixed tests to run under strict variables. 103 | - Updated Java package for SLES 11.4. 104 | 105 | ## Supported Release 1.5.0 106 | ### Summary 107 | 108 | A release which has several support additions for different OSes. Also a couple of additional features and a few bug fixes. 109 | 110 | #### Features 111 | - Added Ubuntu 15.10 compatibility. 112 | - Addition of two facts: java_libjvm_path and java_default_home. 113 | - Added support for oracle-j2re1.8 and oracle-j2sdk1.8. 114 | - Adds FreeBSD Support. 115 | - Exposed the Puppet package resources install_options parameter via a new class parameter named package_options. 116 | - Debian 8 support. 117 | - Add support for official Oracle Java SE jdk and jre packages for CentOS. 118 | - Use java 8 as the default on RHEL > 7.0. 119 | 120 | #### Bugfixes 121 | - Updated fixtures.yml to use git instead of http for stdlib. 122 | - Updates to current msync configs. 123 | - Small README updates and syntax error fixes. 124 | 125 | ## Supported Release 1.4.3 126 | ### Summary 127 | 128 | Small release for support of newer PE versions. This increments the version of PE in the metadata.json file. 129 | 130 | ## 2015-10-07 - Supported Release 1.4.2 131 | ### Summary 132 | This release fixes the fact to not trigger java every time on OS X when it is not available. 133 | 134 | #### Bugfixes 135 | - Causes java\_version fact to not run `java` when java is not installed on OS X 136 | 137 | ## 2015-07-16 - Supported Release 1.4.1 138 | ### Summary 139 | This release updates the metadata for the upcoming release of PE and update params for OEL to match metadata 140 | 141 | #### Bugfixes: 142 | - Add missing OEL to params 143 | 144 | ## 2015-07-07 - Supported Release 1.4.0 145 | ### Summary 146 | This release adds several new features, bugfixes, documentation updates, and test improvements. 147 | 148 | #### Features: 149 | - Puppet 4 support and testing 150 | - Adds support for several Operating Systems 151 | - Ubuntu 15.04 152 | - OpenBSD 5.6, 5.7 153 | - Fedora 20, 21, 22 154 | 155 | #### Bugfixes: 156 | - Fixes java_version fact to work on large systems. (MODULES-1749) 157 | - Improves maintainability of java_version fact. 158 | - Fixes java package names on Fedora 21+. 159 | - Fixes java install problems on Puppet 3.7.5 - 3.8.1 (PUP-4520) 160 | - Fixes create-java-alternatives commands on RedHat distros. 161 | - Fixes bug with Debian systems missing java-common package. 162 | 163 | ## 2015-01-20 - Supported Release 1.3.0 164 | ### Summary 165 | This release adds 3 new facts for determining Java version, adds RHEL alternatives support, adds utopic support, and fixes the flag for `update-java-alternatives` when installed from a headless pacakge. 166 | 167 | #### Features 168 | - Added RHEL support for alternatives 169 | - New facts 170 | - java_major_version 171 | - java_patch_level 172 | - java_version 173 | - Add support for utopic 174 | 175 | #### Bugfixes 176 | - Use `--jre-headless` in the `update-java-alternatives` command when installed from a `headless` package 177 | 178 | ## 2014-11-11 - Supported Version 1.2.0 179 | 180 | ### Summary: 181 | This release adds SLES 12 support and is tested for Future Parser Support 182 | 183 | #### Bugfixes: 184 | - Several readme updates 185 | - Testcase flexability increased 186 | 187 | #### Features: 188 | - Add SLES 12 support 189 | - Future Parser tested 190 | - Validated against PE 3.7 191 | 192 | ## 2014-08-25 - Supported Version 1.1.2 193 | 194 | ### Summary: 195 | This release begins the support coverage of the puppetlabs-java module. 196 | 197 | ### Bugfixes: 198 | - Update java alternative values from deprecated names 199 | - Readme updated 200 | - Testing updated 201 | 202 | ## 2014-05-02 - Version 1.1.1 203 | 204 | ### Summary: 205 | 206 | Add support for new versions of Debian and Ubuntu! 207 | 208 | #### Features: 209 | - Add support for Ubuntu Trusty (14.04) 210 | - Add support for Debian Jessie (8.x) 211 | 212 | ## 2014-01-06 - Version 1.1.0 213 | 214 | ### Summary: 215 | 216 | Primarily a release for Ubuntu users! 217 | 218 | #### Features: 219 | - Add support for Ubuntu Saucy (13.10) 220 | - Add `java_home` parameter for centralized setting of JAVA_HOME. 221 | - Add Scientific Linux 222 | 223 | #### Bugfixes: 224 | - Plus signs are valid in debian/ubuntu package names. 225 | 226 | ## 2013-08-01 - Version 1.0.1 227 | 228 | Matthaus Owens 229 | * Update java packages for Fedora systems 230 | 231 | ## 2013-07-29 - Version 1.0.0 232 | 233 | #### Detailed Changes 234 | 235 | Krzysztof Suszyński 236 | * Adding support for Oracle Enterprise Linux 237 | 238 | Peter Drake 239 | * Add support for natty 240 | 241 | Robert Munteanu 242 | * Add support for OpenSUSE 243 | 244 | Martin Jackson 245 | * Added support Amazon Linux using facter >= 1.7.x 246 | 247 | Gareth Rushgrove 248 | Brett Porter 249 | * Fixes for older versions of CentOS 250 | * Improvements to module build and tests 251 | 252 | Nathan R Valentine 253 | * Add support for Ubuntu quantal and raring 254 | 255 | Sharif Nassar 256 | * Add support for Debian alternatives, and more than one JDK/JRE per platform. 257 | 258 | ## 2013-04-04 - Version 0.3.0 259 | Reid Vandewiele - 260 | * Refactor, introduce params pattern 261 | 262 | ## 2012-11-15 - Version 0.2.0 263 | Scott Schneider 264 | * Add Solaris support 265 | 266 | ## 2011-06-16 - Version 0.1.5 267 | Jeff McCune 268 | * Add Debian based distro (Lucid) support 269 | 270 | ## 2011-06-02 - Version 0.1.4 271 | Jeff McCune 272 | * Fix class composition ordering problems 273 | 274 | ## 2011-05-28 - Version 0.1.3 275 | Jeff McCune 276 | * Remove stages 277 | 278 | ## 2011-05-26 - Version 0.1.2 279 | Jeff McCune 280 | * Changes JRE/JDK selection class parameter to $distribution 281 | 282 | ## 2011-05-25 - Version 0.1.1 283 | Jeff McCune 284 | * Re-did versioning to follow semantic versioning 285 | * Add validation of class parameters 286 | 287 | ## 2011-05-24 - Version 0.1.0 288 | Jeff McCune 289 | * Default to JDK version 6u25 290 | 291 | ## 2011-05-24 - Version 0.0.1 292 | Jeff McCune 293 | * Initial release 294 | 295 | [2.3.0]:https://github.com/puppetlabs/puppetlabs-java/compare/2.2.0...2.3.0 296 | [2.2.0]:https://github.com/puppetlabs/puppetlabs-java/compare/2.1.1...2.2.0 297 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Puppet Module - puppetlabs-java 2 | 3 | Copyright 2018 Puppet, Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # java 2 | 3 | #### Table of Contents 4 | 5 | 1. [Overview](#overview) 6 | 2. [Module Description - What the module does and why it is useful](#module-description) 7 | 3. [Setup - The basics of getting started with the java module](#setup) 8 | * [Beginning with the java module](#beginning-with-the-java-module) 9 | 4. [Usage - Configuration options and additional functionality](#usage) 10 | 5. [Reference - An under-the-hood peek at what the module is doing and how](#reference) 11 | 6. [Limitations - OS compatibility, etc.](#limitations) 12 | 7. [License](#license) 13 | 8. [Development - Guide for contributing to the module](#development) 14 | 15 | ## Overview 16 | 17 | Installs the correct Java package on various platforms. 18 | 19 | ## Module Description 20 | 21 | The java module can automatically install Java jdk or jre on a wide variety of systems. Java is a base component for many software platforms, but Java system packages don't always follow packaging conventions. The java module simplifies the Java installation process. 22 | 23 | ## Setup 24 | 25 | ### Beginning with the java module 26 | 27 | To install the correct Java package on your system, include the `java` class: `include java`. 28 | 29 | ## Usage 30 | 31 | The java module installs the correct jdk or jre package on a wide variety of systems. By default, the module installs the jdk package, but you can set different installation parameters as needed. For example, to install jre instead of jdk, you would set the distribution parameter: 32 | 33 | ```puppet 34 | class { 'java': 35 | distribution => 'jre', 36 | } 37 | ``` 38 | 39 | To install the latest patch version of Java 8 on CentOS 40 | 41 | ```puppet 42 | class { 'java' : 43 | package => 'java-1.8.0-openjdk-devel', 44 | } 45 | ``` 46 | 47 | The defined type `java::download` installs one or more versions of Java SE from a remote url. `java::download` depends on [puppet/archive](https://github.com/voxpupuli/puppet-archive). 48 | 49 | To install Java to a non-default basedir (defaults: /usr/lib/jvm for Debian; /usr/java for RedHat): 50 | ```puppet 51 | java::download { 'jdk8' : 52 | ensure => 'present', 53 | java_se => 'jdk', 54 | url => 'http://myjava.repository/java.tgz", 55 | basedir => '/custom/java', 56 | } 57 | ``` 58 | 59 | ## AdoptOpenJDK 60 | 61 | The defined type `java::adopt` installs one or more versions of AdoptOpenJDK Java. `java::adopt` depends on [puppet/archive](https://github.com/voxpupuli/puppet-archive). 62 | 63 | ```puppet 64 | java::adopt { 'jdk8' : 65 | ensure => 'present', 66 | version => '8', 67 | java => 'jdk', 68 | } 69 | 70 | java::adopt { 'jdk11' : 71 | ensure => 'present', 72 | version => '11', 73 | java => 'jdk', 74 | } 75 | ``` 76 | 77 | To install a specific release of a AdoptOpenJDK Java version, e.g. 8u202-b08, provide both parameters `version_major` and `version_minor` as follows: 78 | 79 | ```puppet 80 | java::adopt { 'jdk8' : 81 | ensure => 'present', 82 | version_major => '8u202', 83 | version_minor => 'b08', 84 | java => 'jdk', 85 | } 86 | ``` 87 | 88 | To install AdoptOpenJDK Java to a non-default basedir (defaults: /usr/lib/jvm for Debian; /usr/java for RedHat): 89 | ```puppet 90 | java::adopt { 'jdk8' : 91 | ensure => 'present', 92 | version_major => '8u202', 93 | version_minor => 'b08', 94 | java => 'jdk', 95 | basedir => '/custom/java', 96 | } 97 | ``` 98 | 99 | To ensure that a custom basedir is a directory before AdoptOpenJDK Java is installed (note: manage separately for custom ownership or perms): 100 | ```puppet 101 | java::adopt { 'jdk8' : 102 | ensure => 'present', 103 | version_major => '8u202', 104 | version_minor => 'b08', 105 | java => 'jdk', 106 | manage_basedir => true, 107 | basedir => '/custom/java', 108 | } 109 | ``` 110 | 111 | ## Adoptium Temurin 112 | 113 | Adoptium Temurin is the successor of AdoptOpenJDK and is supported using the defined type `java::adoptium`. It depends on [puppet/archive](https://github.com/voxpupuli/puppet-archive). 114 | 115 | The `java::adoptium` defined type expects a major, minor, patch and build version to download the specific release. It doesn't support jre downloads as the other distributions. 116 | 117 | ```puppet 118 | java::adoptium { 'jdk16' : 119 | ensure => 'present', 120 | version_major => '16', 121 | version_minor => '0', 122 | version_patch => '2', 123 | version_build => '7', 124 | } 125 | java::adoptium { 'jdk17' : 126 | ensure => 'present', 127 | version_major => '17', 128 | version_minor => '0', 129 | version_patch => '1', 130 | version_build => '12', 131 | } 132 | ``` 133 | 134 | To install Adoptium to a non-default basedir (defaults: /usr/lib/jvm for Debian; /usr/java for RedHat): 135 | 136 | ```puppet 137 | java::adoptium { 'jdk7' : 138 | ensure => 'present', 139 | version_major => '17', 140 | version_minor => '0', 141 | version_patch => '1', 142 | version_build => '12', 143 | basedir => '/custom/java', 144 | } 145 | ``` 146 | 147 | To ensure that a custom basedir is a directory before Adoptium is installed (note: manage separately for custom ownership or perms): 148 | 149 | ```puppet 150 | java::adoptium { 'jdk8' : 151 | ensure => 'present', 152 | version_major => '17', 153 | version_minor => '0', 154 | version_patch => '1', 155 | version_build => '12', 156 | manage_basedir => true, 157 | basedir => '/custom/java', 158 | } 159 | ``` 160 | 161 | ## SAP Java (sapjvm / sapmachine) 162 | 163 | SAP also offers JVM distributions. They are mostly required for their SAP products. In earlier versions it is called "sapjvm", in newer versions they call it "sapmachine". 164 | 165 | The defined type `java::sap` installs one or more versions of sapjvm (if version 7 or 8) or sapmachine (if version > 8) Java. `java::sap` depends on [puppet/archive](https://github.com/voxpupuli/puppet-archive). 166 | By using this defined type with versions 7 or 8 you agree with the EULA presented at https://tools.hana.ondemand.com/developer-license-3_1.txt! 167 | 168 | ```puppet 169 | java::sap { 'sapjvm8' : 170 | ensure => 'present', 171 | version => '8', 172 | java => 'jdk', 173 | } 174 | 175 | java::sap { 'sapmachine11' : 176 | ensure => 'present', 177 | version => '11', 178 | java => 'jdk', 179 | } 180 | ``` 181 | 182 | To install a specific release of a SAP Java version, e.g. sapjvm 8.1.063, provide parameter `version_full`: 183 | 184 | ```puppet 185 | java::sap { 'jdk8' : 186 | ensure => 'present', 187 | version_full => '8.1.063', 188 | java => 'jdk', 189 | } 190 | ``` 191 | 192 | To install SAP Java to a non-default basedir (defaults: /usr/lib/jvm for Debian; /usr/java for RedHat): 193 | ```puppet 194 | java::adopt { 'sapjvm8' : 195 | ensure => 'present', 196 | version_full => '8.1.063', 197 | java => 'jdk', 198 | basedir => '/custom/java', 199 | } 200 | ``` 201 | 202 | To ensure that a custom basedir is a directory before SAP Java is installed (note: manage separately for custom ownership or perms): 203 | ```puppet 204 | java::adopt { 'sapjvm8' : 205 | ensure => 'present', 206 | version_full => '8.1.063', 207 | java => 'jdk', 208 | manage_basedir => true, 209 | basedir => '/custom/java', 210 | } 211 | ``` 212 | 213 | ## Reference 214 | 215 | For information on the classes and types, see the [REFERENCE.md](https://github.com/puppetlabs/puppetlabs-java/blob/main/REFERENCE.md). For information on the facts, see below. 216 | 217 | ### Facts 218 | 219 | The java module includes a few facts to describe the version of Java installed on the system: 220 | 221 | * `java_major_version`: The major version of Java. 222 | * `java_patch_level`: The patch level of Java. 223 | * `java_version`: The full Java version string. 224 | * `java_default_home`: The absolute path to the java system home directory (only available on Linux). For instance, the `java` executable's path would be `${::java_default_home}/jre/bin/java`. This is slightly different from the "standard" JAVA_HOME environment variable. 225 | * `java_libjvm_path`: The absolute path to the directory containing the shared library `libjvm.so` (only available on Linux). Useful for setting `LD_LIBRARY_PATH` or configuring the dynamic linker. 226 | 227 | **Note:** The facts return `nil` if Java is not installed on the system. 228 | 229 | ## Limitations 230 | 231 | For an extensive list of supported operating systems, see [metadata.json](https://github.com/puppetlabs/puppetlabs-java/blob/main/metadata.json) 232 | 233 | This module cannot guarantee installation of Java versions that are not available on platform repositories. 234 | 235 | This module only manages a singular installation of Java, meaning it is not possible to manage e.g. OpenJDK 7, Oracle Java 7 and Oracle Java 8 in parallel on the same system. 236 | 237 | Oracle Java packages are not included in Debian 7 and Ubuntu 12.04/14.04 repositories. To install Java on those systems, you'll need to package Oracle JDK/JRE, and then the module can install the package. For more information on how to package Oracle JDK/JRE, see the [Debian wiki](http://wiki.debian.org/JavaPackage). 238 | 239 | This module is officially [supported](https://forge.puppetlabs.com/supported) for the following Java versions and platforms: 240 | 241 | OpenJDK is supported on: 242 | 243 | * Red Hat Enterprise Linux (RHEL) 7, 8, 9 244 | * CentOS 7, 8 245 | * Oracle Linux 7 246 | * Debian 10, 11 247 | * Ubuntu 18.04, 20.04, 22.04 248 | * Solaris 11 249 | * SLES 12, 15 250 | 251 | Oracle Java is supported on: 252 | 253 | * CentOS 7 254 | * CentOS 8 255 | * Red Hat Enterprise Linux (RHEL) 7 256 | 257 | AdoptOpenJDK Java is supported on: 258 | 259 | * CentOS 260 | * Red Hat Enterprise Linux (RHEL) 261 | * Amazon Linux 262 | * Debian 263 | 264 | Adoptium Temurin Java is supported on: 265 | 266 | * CentOS 267 | * Red Hat Enterprise Linux (RHEL) 268 | * Amazon Linux 269 | * Debian 270 | 271 | SAP Java 7 and 8 (=sapjvm) are supported (by SAP) on: 272 | 273 | * SLES 12, 15 274 | * Oracle Linux 7, 8 275 | * Red Hat Enterprise Linux (RHEL) 7, 8 276 | 277 | (however installations on other distributions mostly also work well) 278 | 279 | For SAP Java > 8 (=sapmachine) please refer to the OpenJDK list as it is based on OpenJDK and has no special requirements. 280 | 281 | ### Known issues 282 | 283 | Where Oracle change the format of the URLs to different installer packages, the curl to fetch the package may fail with a HTTP/404 error. In this case, passing a full known good URL using the `url` parameter will allow the module to still be able to install specific versions of the JRE/JDK. Note the `version_major` and `version_minor` parameters must be passed and must match the version downloaded using the known URL in the `url` parameter. 284 | 285 | #### OpenBSD 286 | 287 | OpenBSD packages install Java JRE/JDK in a unique directory structure, not linking 288 | the binaries to a standard directory. Because of that, the path to this location 289 | is hardcoded in the `java_version` fact. Whenever you upgrade Java to a newer 290 | version, you have to update the path in this fact. 291 | 292 | ## License 293 | 294 | This codebase is licensed under the Apache2.0 licensing, however due to the nature of the codebase the open source dependencies may also use a combination of [AGPL](https://opensource.org/license/agpl-v3/), [BSD-2](https://opensource.org/license/bsd-2-clause/), [BSD-3](https://opensource.org/license/bsd-3-clause/), [GPL2.0](https://opensource.org/license/gpl-2-0/), [LGPL](https://opensource.org/license/lgpl-3-0/), [MIT](https://opensource.org/license/mit/) and [MPL](https://opensource.org/license/mpl-2-0/) Licensing. 295 | 296 | ## Development 297 | 298 | Puppet modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. To contribute to Puppet projects, see our [module contribution guide.](https://docs.puppetlabs.com/forge/contributing.html) 299 | 300 | ## Contributors 301 | 302 | The list of contributors can be found at [https://github.com/puppetlabs/puppetlabs-java/graphs/contributors](https://github.com/puppetlabs/puppetlabs-java/graphs/contributors). 303 | -------------------------------------------------------------------------------- /REFERENCE.md: -------------------------------------------------------------------------------- 1 | # Reference 2 | 3 | 4 | 5 | ## Table of Contents 6 | 7 | ### Classes 8 | 9 | #### Public Classes 10 | 11 | * [`java`](#java): This module manages the Java runtime package 12 | 13 | #### Private Classes 14 | 15 | * `java::config` 16 | * `java::params`: This class builds a hash of JDK/JRE packages and (for Debian) 17 | alternatives. For wheezy/precise, we provide Oracle JDK/JRE 18 | options, even though those are not in the package repositories. 19 | 20 | ### Defined types 21 | 22 | * [`java::adopt`](#java--adopt): Install one or more versions of AdoptOpenJDK Java. 23 | * [`java::adoptium`](#java--adoptium): Install one or more versions of Adoptium Temurin OpenJDK (former AdoptOpenJDK). 24 | * [`java::download`](#java--download): Installs Java from a url location. 25 | * [`java::sap`](#java--sap): Install one or more versions of SAPJVM or Sapmachine 26 | 27 | ## Classes 28 | 29 | ### `java` 30 | 31 | This module manages the Java runtime package 32 | 33 | #### Parameters 34 | 35 | The following parameters are available in the `java` class: 36 | 37 | * [`distribution`](#-java--distribution) 38 | * [`version`](#-java--version) 39 | * [`package`](#-java--package) 40 | * [`package_options`](#-java--package_options) 41 | * [`java_alternative`](#-java--java_alternative) 42 | * [`java_alternative_path`](#-java--java_alternative_path) 43 | * [`java_home`](#-java--java_home) 44 | 45 | ##### `distribution` 46 | 47 | Data type: `String` 48 | 49 | The java distribution to install. Can be one of "jdk" or "jre", 50 | or other platform-specific options where there are multiple 51 | implementations available (eg: OpenJDK vs Oracle JDK). 52 | 53 | Default value: `'jdk'` 54 | 55 | ##### `version` 56 | 57 | Data type: `Pattern[/present|installed|latest|^[.+_0-9a-zA-Z:~-]+$/]` 58 | 59 | The version of java to install. By default, this module simply ensures 60 | that java is present, and does not require a specific version. 61 | 62 | Default value: `'present'` 63 | 64 | ##### `package` 65 | 66 | Data type: `Optional[String]` 67 | 68 | The name of the java package. This is configurable in case a non-standard 69 | java package is desired. 70 | 71 | Default value: `undef` 72 | 73 | ##### `package_options` 74 | 75 | Data type: `Optional[Array]` 76 | 77 | Array of strings to pass installation options to the 'package' Puppet resource. 78 | Options available depend on the 'package' provider for the target OS. 79 | 80 | Default value: `undef` 81 | 82 | ##### `java_alternative` 83 | 84 | Data type: `Optional[String]` 85 | 86 | The name of the java alternative to use on Debian systems. 87 | "update-java-alternatives -l" will show which choices are available. 88 | If you specify a particular package, you will almost always also 89 | want to specify which java_alternative to choose. If you set 90 | this, you also need to set the path below. 91 | 92 | Default value: `undef` 93 | 94 | ##### `java_alternative_path` 95 | 96 | Data type: `Optional[String]` 97 | 98 | The path to the "java" command on Debian systems. Since the 99 | alternatives system makes it difficult to verify which 100 | alternative is actually enabled, this is required to ensure the 101 | correct JVM is enabled. 102 | 103 | Default value: `undef` 104 | 105 | ##### `java_home` 106 | 107 | Data type: `Optional[String]` 108 | 109 | The path to where the JRE is installed. This will be set as an 110 | environment variable. 111 | 112 | Default value: `undef` 113 | 114 | ## Defined types 115 | 116 | ### `java::adopt` 117 | 118 | Defined Type java::adopt 119 | 120 | #### Parameters 121 | 122 | The following parameters are available in the `java::adopt` defined type: 123 | 124 | * [`ensure`](#-java--adopt--ensure) 125 | * [`version`](#-java--adopt--version) 126 | * [`version_major`](#-java--adopt--version_major) 127 | * [`version_minor`](#-java--adopt--version_minor) 128 | * [`java`](#-java--adopt--java) 129 | * [`proxy_server`](#-java--adopt--proxy_server) 130 | * [`proxy_type`](#-java--adopt--proxy_type) 131 | * [`url`](#-java--adopt--url) 132 | * [`basedir`](#-java--adopt--basedir) 133 | * [`manage_basedir`](#-java--adopt--manage_basedir) 134 | * [`package_type`](#-java--adopt--package_type) 135 | * [`manage_symlink`](#-java--adopt--manage_symlink) 136 | * [`symlink_name`](#-java--adopt--symlink_name) 137 | 138 | ##### `ensure` 139 | 140 | Data type: `Enum['present']` 141 | 142 | Install or remove the package. 143 | 144 | Default value: `'present'` 145 | 146 | ##### `version` 147 | 148 | Data type: `String[1]` 149 | 150 | Version of Java to install, e.g. '8' or '9'. Default values for major and minor versions will be used. 151 | 152 | Default value: `'8'` 153 | 154 | ##### `version_major` 155 | 156 | Data type: `Optional[String]` 157 | 158 | Major version which should be installed, e.g. '8u101' or '9.0.4'. Must be used together with version_minor. 159 | 160 | Default value: `undef` 161 | 162 | ##### `version_minor` 163 | 164 | Data type: `Optional[String]` 165 | 166 | Minor version which should be installed, e.g. 'b12' (for version = '8') or '11' (for version != '8'). 167 | Must be used together with version_major. 168 | 169 | Default value: `undef` 170 | 171 | ##### `java` 172 | 173 | Data type: `String[1]` 174 | 175 | Type of Java Standard Edition to install, jdk or jre. 176 | 177 | Default value: `'jdk'` 178 | 179 | ##### `proxy_server` 180 | 181 | Data type: `Optional[String]` 182 | 183 | Specify a proxy server, with port number if needed. ie: https://example.com:8080. (passed to archive) 184 | 185 | Default value: `undef` 186 | 187 | ##### `proxy_type` 188 | 189 | Data type: `Optional[String]` 190 | 191 | Proxy server type (none|http|https|ftp). (passed to archive) 192 | 193 | Default value: `undef` 194 | 195 | ##### `url` 196 | 197 | Data type: `Optional[String]` 198 | 199 | Full URL 200 | 201 | Default value: `undef` 202 | 203 | ##### `basedir` 204 | 205 | Data type: `Optional[String]` 206 | 207 | Directory under which the installation will occur. If not set, defaults to 208 | /usr/lib/jvm for Debian and /usr/java for RedHat. 209 | 210 | Default value: `undef` 211 | 212 | ##### `manage_basedir` 213 | 214 | Data type: `Boolean` 215 | 216 | Whether to manage the basedir directory. 217 | Note: /usr/lib/jvm is managed for Debian by default, separate from this parameter. 218 | 219 | Default value: `true` 220 | 221 | ##### `package_type` 222 | 223 | Data type: `Optional[String]` 224 | 225 | Type of installation package for specified version of java_se. java_se 6 comes 226 | in a few installation package flavors and we need to account for them. 227 | Optional forced package types: rpm, rpmbin, tar.gz 228 | 229 | Default value: `undef` 230 | 231 | ##### `manage_symlink` 232 | 233 | Data type: `Boolean` 234 | 235 | Whether to manage a symlink that points to the installation directory. Defaults to false. 236 | 237 | Default value: `false` 238 | 239 | ##### `symlink_name` 240 | 241 | Data type: `Optional[String]` 242 | 243 | The name for the optional symlink in the installation directory. 244 | 245 | Default value: `undef` 246 | 247 | ### `java::adoptium` 248 | 249 | Defined Type java::adoptium 250 | 251 | #### Parameters 252 | 253 | The following parameters are available in the `java::adoptium` defined type: 254 | 255 | * [`ensure`](#-java--adoptium--ensure) 256 | * [`version_major`](#-java--adoptium--version_major) 257 | * [`version_minor`](#-java--adoptium--version_minor) 258 | * [`version_patch`](#-java--adoptium--version_patch) 259 | * [`version_build`](#-java--adoptium--version_build) 260 | * [`proxy_server`](#-java--adoptium--proxy_server) 261 | * [`proxy_type`](#-java--adoptium--proxy_type) 262 | * [`url`](#-java--adoptium--url) 263 | * [`basedir`](#-java--adoptium--basedir) 264 | * [`manage_basedir`](#-java--adoptium--manage_basedir) 265 | * [`manage_symlink`](#-java--adoptium--manage_symlink) 266 | * [`symlink_name`](#-java--adoptium--symlink_name) 267 | 268 | ##### `ensure` 269 | 270 | Data type: `Enum['present']` 271 | 272 | Install or remove the package. 273 | 274 | Default value: `'present'` 275 | 276 | ##### `version_major` 277 | 278 | Data type: `Optional[String]` 279 | 280 | Major version which should be installed, e.g. '16' or '17' 281 | 282 | Default value: `undef` 283 | 284 | ##### `version_minor` 285 | 286 | Data type: `Optional[String]` 287 | 288 | Minor version which should be installed, e.g. '0' 289 | 290 | Default value: `undef` 291 | 292 | ##### `version_patch` 293 | 294 | Data type: `Optional[String]` 295 | 296 | Minor version which should be installed, e.g. '2' 297 | 298 | Default value: `undef` 299 | 300 | ##### `version_build` 301 | 302 | Data type: `Optional[String]` 303 | 304 | Build version which should be installed, e.g. '07' 305 | 306 | Default value: `undef` 307 | 308 | ##### `proxy_server` 309 | 310 | Data type: `Optional[String]` 311 | 312 | Specify a proxy server, with port number if needed. ie: https://example.com:8080. (passed to archive) 313 | 314 | Default value: `undef` 315 | 316 | ##### `proxy_type` 317 | 318 | Data type: `Optional[Enum['none', 'http', 'https', 'ftp']]` 319 | 320 | Proxy server type (none|http|https|ftp). (passed to archive) 321 | 322 | Default value: `undef` 323 | 324 | ##### `url` 325 | 326 | Data type: `Optional[String]` 327 | 328 | Full URL 329 | 330 | Default value: `undef` 331 | 332 | ##### `basedir` 333 | 334 | Data type: `Optional[String]` 335 | 336 | Directory under which the installation will occur. If not set, defaults to 337 | /usr/lib/jvm for Debian and /usr/java for RedHat. 338 | 339 | Default value: `undef` 340 | 341 | ##### `manage_basedir` 342 | 343 | Data type: `Boolean` 344 | 345 | Whether to manage the basedir directory. Defaults to false. 346 | Note: /usr/lib/jvm is managed for Debian by default, separate from this parameter. 347 | 348 | Default value: `true` 349 | 350 | ##### `manage_symlink` 351 | 352 | Data type: `Boolean` 353 | 354 | Whether to manage a symlink that points to the installation directory. Defaults to false. 355 | 356 | Default value: `false` 357 | 358 | ##### `symlink_name` 359 | 360 | Data type: `Optional[String]` 361 | 362 | The name for the optional symlink in the installation directory. 363 | 364 | Default value: `undef` 365 | 366 | ### `java::download` 367 | 368 | Defined Type java::download 369 | 370 | #### Parameters 371 | 372 | The following parameters are available in the `java::download` defined type: 373 | 374 | * [`ensure`](#-java--download--ensure) 375 | * [`version`](#-java--download--version) 376 | * [`version_major`](#-java--download--version_major) 377 | * [`version_minor`](#-java--download--version_minor) 378 | * [`java_se`](#-java--download--java_se) 379 | * [`proxy_server`](#-java--download--proxy_server) 380 | * [`proxy_type`](#-java--download--proxy_type) 381 | * [`url`](#-java--download--url) 382 | * [`jce`](#-java--download--jce) 383 | * [`jce_url`](#-java--download--jce_url) 384 | * [`basedir`](#-java--download--basedir) 385 | * [`manage_basedir`](#-java--download--manage_basedir) 386 | * [`package_type`](#-java--download--package_type) 387 | * [`manage_symlink`](#-java--download--manage_symlink) 388 | * [`symlink_name`](#-java--download--symlink_name) 389 | 390 | ##### `ensure` 391 | 392 | Data type: `Enum['present']` 393 | 394 | Install or remove the package. 395 | 396 | Default value: `'present'` 397 | 398 | ##### `version` 399 | 400 | Data type: `String[1]` 401 | 402 | Version of Java to install, e.g. '7' or '8'. Default values for major and minor versions will be used. 403 | 404 | Default value: `'8'` 405 | 406 | ##### `version_major` 407 | 408 | Data type: `Optional[String]` 409 | 410 | Major version which should be installed, e.g. '8u101'. Must be used together with version_minor. 411 | 412 | Default value: `undef` 413 | 414 | ##### `version_minor` 415 | 416 | Data type: `Optional[String]` 417 | 418 | Minor version which should be installed, e.g. 'b12'. Must be used together with version_major. 419 | 420 | Default value: `undef` 421 | 422 | ##### `java_se` 423 | 424 | Data type: `String[1]` 425 | 426 | Type of Java Standard Edition to install, jdk or jre. 427 | 428 | Default value: `'jdk'` 429 | 430 | ##### `proxy_server` 431 | 432 | Data type: `Optional[String]` 433 | 434 | Specify a proxy server, with port number if needed. ie: https://example.com:8080. (passed to archive) 435 | 436 | Default value: `undef` 437 | 438 | ##### `proxy_type` 439 | 440 | Data type: `Optional[Enum['none', 'http', 'https', 'ftp']]` 441 | 442 | Proxy server type (none|http|https|ftp). (passed to archive) 443 | 444 | Default value: `undef` 445 | 446 | ##### `url` 447 | 448 | Data type: `Optional[String]` 449 | 450 | Full URL 451 | 452 | Default value: `undef` 453 | 454 | ##### `jce` 455 | 456 | Data type: `Boolean` 457 | 458 | Install Oracles Java Cryptographic Extensions into the JRE or JDK 459 | 460 | Default value: `false` 461 | 462 | ##### `jce_url` 463 | 464 | Data type: `Optional[String]` 465 | 466 | Full URL to the jce zip file 467 | 468 | Default value: `undef` 469 | 470 | ##### `basedir` 471 | 472 | Data type: `Optional[String]` 473 | 474 | Directory under which the installation will occur. If not set, defaults to 475 | /usr/lib/jvm for Debian and /usr/java for RedHat. 476 | 477 | Default value: `undef` 478 | 479 | ##### `manage_basedir` 480 | 481 | Data type: `Boolean` 482 | 483 | Whether to manage the basedir directory. Defaults to false. 484 | Note: /usr/lib/jvm is managed for Debian by default, separate from this parameter. 485 | 486 | Default value: `false` 487 | 488 | ##### `package_type` 489 | 490 | Data type: `Optional[String]` 491 | 492 | Type of installation package for specified version of java_se. java_se 6 comes 493 | in a few installation package flavors and we need to account for them. 494 | Optional forced package types: rpm, rpmbin, tar.gz 495 | 496 | Default value: `undef` 497 | 498 | ##### `manage_symlink` 499 | 500 | Data type: `Boolean` 501 | 502 | Whether to manage a symlink that points to the installation directory. Defaults to false. 503 | 504 | Default value: `false` 505 | 506 | ##### `symlink_name` 507 | 508 | Data type: `Optional[String]` 509 | 510 | The name for the optional symlink in the installation directory. 511 | 512 | Default value: `undef` 513 | 514 | ### `java::sap` 515 | 516 | Defined Type java::sap 517 | 518 | #### Parameters 519 | 520 | The following parameters are available in the `java::sap` defined type: 521 | 522 | * [`ensure`](#-java--sap--ensure) 523 | * [`version`](#-java--sap--version) 524 | * [`version_full`](#-java--sap--version_full) 525 | * [`java`](#-java--sap--java) 526 | * [`proxy_server`](#-java--sap--proxy_server) 527 | * [`proxy_type`](#-java--sap--proxy_type) 528 | * [`basedir`](#-java--sap--basedir) 529 | * [`manage_basedir`](#-java--sap--manage_basedir) 530 | * [`manage_symlink`](#-java--sap--manage_symlink) 531 | * [`symlink_name`](#-java--sap--symlink_name) 532 | 533 | ##### `ensure` 534 | 535 | Data type: `Enum['present']` 536 | 537 | Install or remove the package. 538 | 539 | Default value: `'present'` 540 | 541 | ##### `version` 542 | 543 | Data type: `String[1]` 544 | 545 | Version of Java to install, e.g. '8' or '9'. Default values for full versions will be used. 546 | 547 | Default value: `'8'` 548 | 549 | ##### `version_full` 550 | 551 | Data type: `Optional[String]` 552 | 553 | Major version which should be installed, e.g. '8.1.063' or '11.0.7'. If used, "version" parameter is ignored. 554 | 555 | Default value: `undef` 556 | 557 | ##### `java` 558 | 559 | Data type: `String[1]` 560 | 561 | Type of Java Edition to install, jdk or jre. 562 | 563 | Default value: `'jdk'` 564 | 565 | ##### `proxy_server` 566 | 567 | Data type: `Optional[String]` 568 | 569 | Specify a proxy server, with port number if needed. ie: https://example.com:8080. (passed to archive) 570 | 571 | Default value: `undef` 572 | 573 | ##### `proxy_type` 574 | 575 | Data type: `Optional[Enum['none', 'http', 'https', 'ftp']]` 576 | 577 | Proxy server type (none|http|https|ftp). (passed to archive) 578 | 579 | Default value: `undef` 580 | 581 | ##### `basedir` 582 | 583 | Data type: `Optional[String]` 584 | 585 | Directory under which the installation will occur. If not set, defaults to 586 | /usr/lib/jvm for Debian and /usr/java for RedHat. 587 | 588 | Default value: `undef` 589 | 590 | ##### `manage_basedir` 591 | 592 | Data type: `Boolean` 593 | 594 | Whether to manage the basedir directory. 595 | Note: /usr/lib/jvm is managed for Debian by default, separate from this parameter. 596 | 597 | Default value: `true` 598 | 599 | ##### `manage_symlink` 600 | 601 | Data type: `Boolean` 602 | 603 | Whether to manage a symlink that points to the installation directory. Defaults to false. 604 | 605 | Default value: `false` 606 | 607 | ##### `symlink_name` 608 | 609 | Data type: `Optional[String]` 610 | 611 | The name for the optional symlink in the installation directory. 612 | 613 | Default value: `undef` 614 | 615 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'bundler' 4 | require 'puppet_litmus/rake_tasks' if Gem.loaded_specs.key? 'puppet_litmus' 5 | require 'puppetlabs_spec_helper/rake_tasks' 6 | require 'puppet-syntax/tasks/puppet-syntax' 7 | require 'puppet-strings/tasks' if Gem.loaded_specs.key? 'puppet-strings' 8 | 9 | PuppetLint.configuration.send('disable_relative') 10 | -------------------------------------------------------------------------------- /data/common.yaml: -------------------------------------------------------------------------------- 1 | --- {} 2 | -------------------------------------------------------------------------------- /examples/alternative.pp: -------------------------------------------------------------------------------- 1 | class { 'java': 2 | package => 'jdk-8u25-linux-x64', 3 | java_alternative => 'jdk1.8.0_25', 4 | java_alternative_path => '/usr/java/jdk1.8.0_25/jre/bin/java', 5 | } 6 | -------------------------------------------------------------------------------- /examples/init.pp: -------------------------------------------------------------------------------- 1 | class { 'java': 2 | distribution => 'jdk', 3 | version => 'latest', 4 | } 5 | -------------------------------------------------------------------------------- /examples/oracle.pp: -------------------------------------------------------------------------------- 1 | java::oracle { 'jdk6' : 2 | ensure => 'present', 3 | version => '6', 4 | java_se => 'jdk', 5 | } 6 | -------------------------------------------------------------------------------- /hiera.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 5 3 | 4 | defaults: # Used for any hierarchy level that omits these keys. 5 | datadir: data # This path is relative to hiera.yaml's directory. 6 | data_hash: yaml_data # Use the built-in YAML backend. 7 | 8 | hierarchy: 9 | - name: "osfamily/major release" 10 | paths: 11 | # Used to distinguish between Debian and Ubuntu 12 | - "os/%{facts.os.name}/%{facts.os.release.major}.yaml" 13 | - "os/%{facts.os.family}/%{facts.os.release.major}.yaml" 14 | # Used for Solaris 15 | - "os/%{facts.os.family}/%{facts.kernelrelease}.yaml" 16 | - name: "osfamily" 17 | paths: 18 | - "os/%{facts.os.name}.yaml" 19 | - "os/%{facts.os.family}.yaml" 20 | - name: 'common' 21 | path: 'common.yaml' 22 | -------------------------------------------------------------------------------- /lib/facter/java_default_home.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Fact: java_default_home 4 | # 5 | # Purpose: get absolute path of java system home 6 | # 7 | # Resolution: 8 | # Find the real java binary, and return the subsubdir 9 | # 10 | # Caveats: 11 | # java binary has to be found in $PATH 12 | # 13 | # Notes: 14 | # None 15 | Facter.add(:java_default_home) do 16 | confine kernel: ['Linux', 'OpenBSD'] 17 | java_default_home = nil 18 | setcode do 19 | java_bin = Facter::Core::Execution.which('java').to_s.strip 20 | if java_bin.empty? 21 | nil 22 | else 23 | java_path = File.realpath(java_bin) 24 | java_default_home = if java_path.include?('/jre/') 25 | File.dirname(File.dirname(File.dirname(java_path))) 26 | else 27 | File.dirname(File.dirname(java_path)) 28 | end 29 | end 30 | end 31 | java_default_home 32 | end 33 | -------------------------------------------------------------------------------- /lib/facter/java_libjvm_path.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Fact: java_libjvm_path 4 | # 5 | # Purpose: get path to libjvm.so 6 | # 7 | # Resolution: 8 | # Lists file in java default home and searches for the file 9 | # 10 | # Caveats: 11 | # Needs to list files recursively. Returns the first match 12 | # Needs working java_major_version fact 13 | # 14 | # Notes: 15 | # None 16 | Facter.add(:java_libjvm_path) do 17 | confine kernel: ['Linux', 'OpenBSD'] 18 | setcode do 19 | java_default_home = Facter.value(:java_default_home) 20 | java_major_version = Facter.value(:java_major_version) 21 | unless java_major_version.nil? 22 | java_libjvm_file = if java_major_version.to_i >= 11 23 | Dir.glob("#{java_default_home}/lib/**/libjvm.so") 24 | else 25 | Dir.glob("#{java_default_home}/jre/lib/**/libjvm.so") 26 | end 27 | if java_libjvm_file.nil? || java_libjvm_file.empty? 28 | nil 29 | else 30 | File.dirname(java_libjvm_file[0]) 31 | end 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/facter/java_major_version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Fact: java_major_version 4 | # 5 | # Purpose: get Java's major version 6 | # 7 | # Resolution: 8 | # Tests for presence of java, returns nil if not present 9 | # returns output of "java -version" and splits on \n + '"' 10 | # eg. 11 | # 12 | # Caveats: 13 | # none 14 | # 15 | # Notes: 16 | # None 17 | Facter.add(:java_major_version) do 18 | java_major_version = nil 19 | setcode do 20 | java_version = Facter.value(:java_version) 21 | unless java_version.nil? 22 | java_major_version = if java_version.strip[0..1] == '1.' 23 | java_version.strip.split('_')[0].split('.')[1] 24 | else 25 | java_version.strip.split('.')[0] 26 | end 27 | end 28 | end 29 | java_major_version 30 | end 31 | -------------------------------------------------------------------------------- /lib/facter/java_patch_level.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Fact: java_patch_level 4 | # 5 | # Purpose: get Java's patch level 6 | # 7 | # Resolution: 8 | # Uses java_version fact splits on the patch number (after _ for 1.x and patch number for semver'ed javas) 9 | # 10 | # Caveats: 11 | # none 12 | # 13 | # Notes: 14 | # None 15 | Facter.add(:java_patch_level) do 16 | java_patch_level = nil 17 | setcode do 18 | java_version = Facter.value(:java_version) 19 | unless java_version.nil? 20 | if java_version.strip[0..1] == '1.' 21 | java_patch_level = java_version.strip.split('_')[1] unless java_version.nil? 22 | else 23 | java_patch_level = java_version.strip.split('.')[2] unless java_version.nil? 24 | end 25 | end 26 | end 27 | java_patch_level 28 | end 29 | -------------------------------------------------------------------------------- /lib/facter/java_version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Fact: java_version 4 | # 5 | # Purpose: get full java version string 6 | # 7 | # Resolution: 8 | # Tests for presence of java, returns nil if not present 9 | # returns output of "java -version" and splits on '"' 10 | # 11 | # Caveats: 12 | # none 13 | # 14 | # Notes: 15 | # None 16 | Facter.add(:java_version) do 17 | setcode do 18 | if ['darwin'].include? Facter.value(:kernel).downcase 19 | if Facter::Core::Execution.execute('/usr/libexec/java_home --failfast', { on_fail: false }) 20 | version = Facter::Core::Execution.execute('java -Xmx12m -version 2>&1').lines.find { |line| line.include?('version') } 21 | end 22 | elsif Facter::Core::Execution.which('java') 23 | version = Facter::Core::Execution.execute('java -Xmx12m -version 2>&1').lines.find { |line| line.include?('version') } 24 | end 25 | version[%r{"(.*?)"}, 1] if version 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /manifests/adopt.pp: -------------------------------------------------------------------------------- 1 | # Defined Type java::adopt 2 | # 3 | # @summary 4 | # Install one or more versions of AdoptOpenJDK Java. 5 | # 6 | # @param ensure 7 | # Install or remove the package. 8 | # 9 | # @param version 10 | # Version of Java to install, e.g. '8' or '9'. Default values for major and minor versions will be used. 11 | # 12 | # @param version_major 13 | # Major version which should be installed, e.g. '8u101' or '9.0.4'. Must be used together with version_minor. 14 | # 15 | # @param version_minor 16 | # Minor version which should be installed, e.g. 'b12' (for version = '8') or '11' (for version != '8'). 17 | # Must be used together with version_major. 18 | # 19 | # @param java 20 | # Type of Java Standard Edition to install, jdk or jre. 21 | # 22 | # @param proxy_server 23 | # Specify a proxy server, with port number if needed. ie: https://example.com:8080. (passed to archive) 24 | # 25 | # @param proxy_type 26 | # Proxy server type (none|http|https|ftp). (passed to archive) 27 | # 28 | # @param url 29 | # Full URL 30 | # 31 | # @param basedir 32 | # Directory under which the installation will occur. If not set, defaults to 33 | # /usr/lib/jvm for Debian and /usr/java for RedHat. 34 | # 35 | # @param manage_basedir 36 | # Whether to manage the basedir directory. 37 | # Note: /usr/lib/jvm is managed for Debian by default, separate from this parameter. 38 | # 39 | # @param package_type 40 | # Type of installation package for specified version of java_se. java_se 6 comes 41 | # in a few installation package flavors and we need to account for them. 42 | # Optional forced package types: rpm, rpmbin, tar.gz 43 | # 44 | # @param manage_symlink 45 | # Whether to manage a symlink that points to the installation directory. Defaults to false. 46 | # 47 | # @param symlink_name 48 | # The name for the optional symlink in the installation directory. 49 | # 50 | define java::adopt ( 51 | Enum['present'] $ensure = 'present', 52 | String[1] $version = '8', 53 | Optional[String] $version_major = undef, 54 | Optional[String] $version_minor = undef, 55 | String[1] $java = 'jdk', 56 | Optional[String] $proxy_server = undef, 57 | Optional[String] $proxy_type = undef, 58 | Optional[String] $url = undef, 59 | Optional[String] $basedir = undef, 60 | Boolean $manage_basedir = true, 61 | Optional[String] $package_type = undef, 62 | Boolean $manage_symlink = false, 63 | Optional[String] $symlink_name = undef, 64 | ) { 65 | # archive module is used to download the java package 66 | include archive 67 | 68 | # validate java Standard Edition to download 69 | if $java !~ /(jre|jdk)/ { 70 | fail('java must be either jre or jdk.') 71 | } 72 | 73 | # determine AdoptOpenJDK Java major and minor version, and installation path 74 | if $version_major and $version_minor { 75 | $release_major = $version_major 76 | $release_minor = $version_minor 77 | 78 | if ( $version_major[0] == '8' or $version_major[0] == '9' ) { 79 | $_version = $version_major[0] 80 | } else { 81 | $_version = $version_major[0,2] 82 | } 83 | 84 | $_version_int = Numeric($_version) 85 | 86 | if ( $java == 'jre' ) { 87 | $_append_jre = '-jre' 88 | } else { 89 | $_append_jre = '' 90 | } 91 | 92 | # extracted folders look like this: 93 | # jdk8u202-b08 94 | # jdk-9.0.4+11 95 | # jdk-10.0.2+13 96 | # jdk-11.0.2+9 97 | # jdk-12.0.1+12 98 | # jdk8u202-b08-jre 99 | # jdk-9.0.4+11-jre 100 | # hence we need to check for the major version and build the install path according to it 101 | if ( $_version_int == 8 ) { 102 | $install_path = "jdk${release_major}-${release_minor}${_append_jre}" 103 | } elsif ( $_version_int > 8 ) { 104 | $install_path = "jdk-${release_major}+${release_minor}${_append_jre}" 105 | } else { 106 | fail ("unsupported version ${_version}") 107 | } 108 | } else { 109 | $_version = $version 110 | $_version_int = Numeric($_version) 111 | # use default versions if no specific major and minor version parameters are provided 112 | case $version { 113 | '8' : { 114 | $release_major = '8u202' 115 | $release_minor = 'b08' 116 | $install_path = "${java}8u202-b08" 117 | } 118 | '9' : { 119 | $release_major = '9.0.4' 120 | $release_minor = '11' 121 | $install_path = "${java}-9.0.4+11" 122 | } 123 | # minor release is given with +, however package etc. works with underscore, so we use underscore here 124 | '10' : { 125 | $release_major = '10.0.2' 126 | $release_minor = '13' 127 | $install_path = "${java}-10.0.2+13" 128 | } 129 | '11' : { 130 | $release_major = '11.0.2' 131 | $release_minor = '9' 132 | $install_path = "${java}-11.0.2+9" 133 | } 134 | # minor release is given with +, however package etc. works with underscore, so we use underscore here 135 | '12' : { 136 | $release_major = '12.0.1' 137 | $release_minor = '12' 138 | $install_path = "${java}-12.0.1+12" 139 | } 140 | default : { 141 | $release_major = '8u202' 142 | $release_minor = 'b08' 143 | $install_path = "${java}8u202-b08" 144 | } 145 | } 146 | } 147 | 148 | # determine package type (exe/tar/rpm), destination directory based on OS 149 | case $facts['kernel'] { 150 | 'Linux' : { 151 | case $facts['os']['family'] { 152 | 'RedHat', 'Amazon' : { 153 | if $package_type { 154 | $_package_type = $package_type 155 | } else { 156 | $_package_type = 'tar.gz' 157 | } 158 | if $basedir { 159 | $_basedir = $basedir 160 | } else { 161 | $_basedir = '/usr/java' 162 | } 163 | } 164 | 'Debian' : { 165 | if $package_type { 166 | $_package_type = $package_type 167 | } else { 168 | $_package_type = 'tar.gz' 169 | } 170 | if $basedir { 171 | $_basedir = $basedir 172 | } else { 173 | $_basedir = '/usr/lib/jvm' 174 | } 175 | } 176 | default : { 177 | fail ("unsupported platform ${$facts['os']['name']}") 178 | } 179 | } 180 | 181 | $creates_path = "${_basedir}/${install_path}" 182 | $os = 'linux' 183 | $destination_dir = '/tmp/' 184 | } 185 | default : { 186 | fail ( "unsupported platform ${$facts['kernel']}" ) 187 | } 188 | } 189 | 190 | # set java architecture nomenclature 191 | $os_architecture = $facts['os']['architecture'] ? { 192 | default => $facts['os']['architecture'] 193 | } 194 | 195 | case $os_architecture { 196 | 'i386' : { $arch = 'x86-32' } 197 | 'x86_64' : { $arch = 'x64' } 198 | 'amd64' : { $arch = 'x64' } 199 | default : { 200 | fail ("unsupported platform ${$os_architecture}") 201 | } 202 | } 203 | 204 | # package name and path for download from github 205 | # 206 | # following are build based on this real life example full URLs: 207 | # 208 | # https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u202-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz 209 | # https://github.com/AdoptOpenJDK/openjdk9-binaries/releases/download/jdk-9.0.4%2B11/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz 210 | # https://github.com/AdoptOpenJDK/openjdk10-binaries/releases/download/jdk-10.0.2%2B13/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz 211 | # https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.2%2B9/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz 212 | # https://github.com/AdoptOpenJDK/openjdk12-binaries/releases/download/jdk-12.0.1%2B12/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz 213 | # jre just replaces jdk with jre in the archive name, but not in the path name! 214 | # https://github.com/AdoptOpenJDK/openjdk9-binaries/releases/download/jdk-9.0.4%2B11/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz 215 | 216 | if ( $_version_int == 8 ) { 217 | $_release_minor_package_name = $release_minor 218 | } else { 219 | $_release_minor_package_name = "_${release_minor}" 220 | } 221 | 222 | case $_package_type { 223 | 'tar.gz': { 224 | $package_name = "OpenJDK${_version}U-${java}_${arch}_${os}_hotspot_${release_major}${_release_minor_package_name}.tar.gz" 225 | } 226 | default: { 227 | $package_name = "OpenJDK${_version}U-${java}_${arch}_${os}_hotspot_${release_major}${_release_minor_package_name}.tar.gz" 228 | } 229 | } 230 | 231 | # naming convention changed after major version 8, setting variables to consider that 232 | # download_folder_prefix always begins with "jdk", even for jre! see comments for package_name above 233 | if ( $_version_int == 8 ) { 234 | $spacer = '-' 235 | $download_folder_prefix = 'jdk' 236 | } else { 237 | $spacer = '%2B' 238 | $download_folder_prefix = 'jdk-' 239 | } 240 | 241 | # if complete URL is provided, use this value for source in archive resource 242 | if $url { 243 | $source = $url 244 | } 245 | else { 246 | $source = "https://github.com/AdoptOpenJDK/openjdk${_version}-binaries/releases/download/${download_folder_prefix}${release_major}${spacer}${release_minor}/${package_name}" 247 | notice ("Default source url : ${source}") 248 | } 249 | 250 | # full path to the installer 251 | $destination = "${destination_dir}${package_name}" 252 | notice ("Destination is ${destination}") 253 | 254 | $install_command = ['tar', '-zxf', $destination, '-C', $_basedir] 255 | 256 | case $ensure { 257 | 'present' : { 258 | archive { $destination : 259 | ensure => present, 260 | source => $source, 261 | extract_path => '/tmp', 262 | cleanup => false, 263 | creates => $creates_path, 264 | proxy_server => $proxy_server, 265 | proxy_type => $proxy_type, 266 | } 267 | case $facts['kernel'] { 268 | 'Linux' : { 269 | case $facts['os']['family'] { 270 | 'Debian' : { 271 | ensure_resource('file', $_basedir, { 272 | ensure => directory, 273 | } 274 | ) 275 | $install_requires = [Archive[$destination], File[$_basedir]] 276 | } 277 | default : { 278 | $install_requires = [Archive[$destination]] 279 | } 280 | } 281 | 282 | if $manage_basedir { 283 | if (!defined(File[$_basedir])) { 284 | file { $_basedir: 285 | ensure => 'directory', 286 | before => Exec["Install AdoptOpenJDK java ${java} ${_version} ${release_major} ${release_minor}"], 287 | } 288 | } 289 | } 290 | 291 | exec { "Install AdoptOpenJDK java ${java} ${_version} ${release_major} ${release_minor}" : 292 | path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin', 293 | command => $install_command, 294 | creates => $creates_path, 295 | require => $install_requires, 296 | } 297 | 298 | if ($manage_symlink and $symlink_name) { 299 | file { "${_basedir}/${symlink_name}": 300 | ensure => link, 301 | target => $creates_path, 302 | require => Exec["Install AdoptOpenJDK java ${java} ${_version} ${release_major} ${release_minor}"], 303 | } 304 | } 305 | } 306 | default : { 307 | fail ("unsupported platform ${$facts['kernel']}") 308 | } 309 | } 310 | } 311 | default : { 312 | notice ("Action ${ensure} not supported.") 313 | } 314 | } 315 | } 316 | -------------------------------------------------------------------------------- /manifests/adoptium.pp: -------------------------------------------------------------------------------- 1 | # Defined Type java::adoptium 2 | # 3 | # @summary 4 | # Install one or more versions of Adoptium Temurin OpenJDK (former AdoptOpenJDK). 5 | # 6 | # @param ensure 7 | # Install or remove the package. 8 | # 9 | # @param version_major 10 | # Major version which should be installed, e.g. '16' or '17' 11 | # 12 | # @param version_minor 13 | # Minor version which should be installed, e.g. '0' 14 | # 15 | # @param version_patch 16 | # Minor version which should be installed, e.g. '2' 17 | # 18 | # @param version_build 19 | # Build version which should be installed, e.g. '07' 20 | # 21 | # @param proxy_server 22 | # Specify a proxy server, with port number if needed. ie: https://example.com:8080. (passed to archive) 23 | # 24 | # @param proxy_type 25 | # Proxy server type (none|http|https|ftp). (passed to archive) 26 | # 27 | # @param url 28 | # Full URL 29 | # 30 | # @param basedir 31 | # Directory under which the installation will occur. If not set, defaults to 32 | # /usr/lib/jvm for Debian and /usr/java for RedHat. 33 | # 34 | # @param manage_basedir 35 | # Whether to manage the basedir directory. Defaults to false. 36 | # Note: /usr/lib/jvm is managed for Debian by default, separate from this parameter. 37 | # 38 | # @param manage_symlink 39 | # Whether to manage a symlink that points to the installation directory. Defaults to false. 40 | # 41 | # @param symlink_name 42 | # The name for the optional symlink in the installation directory. 43 | # 44 | define java::adoptium ( 45 | Enum['present'] $ensure = 'present', 46 | Optional[String] $version_major = undef, 47 | Optional[String] $version_minor = undef, 48 | Optional[String] $version_patch = undef, 49 | Optional[String] $version_build = undef, 50 | Optional[String] $proxy_server = undef, 51 | Optional[Enum['none', 'http', 'https', 'ftp']] $proxy_type = undef, 52 | Optional[String] $url = undef, 53 | Optional[String] $basedir = undef, 54 | Boolean $manage_basedir = true, 55 | Boolean $manage_symlink = false, 56 | Optional[String] $symlink_name = undef, 57 | ) { 58 | # archive module is used to download the java package 59 | include archive 60 | 61 | $install_path = "jdk-${version_major}.${version_minor}.${version_patch}+${version_build}" 62 | 63 | # determine package type (exe/tar/rpm), destination directory based on OS 64 | case $facts['kernel'] { 65 | 'Linux' : { 66 | case $facts['os']['family'] { 67 | 'RedHat', 'Amazon' : { 68 | if $basedir { 69 | $_basedir = $basedir 70 | } else { 71 | $_basedir = '/usr/java' 72 | } 73 | } 74 | 'Debian' : { 75 | if $basedir { 76 | $_basedir = $basedir 77 | } else { 78 | $_basedir = '/usr/lib/jvm' 79 | } 80 | } 81 | default : { 82 | fail ("unsupported platform ${$facts['os']['name']}") 83 | } 84 | } 85 | 86 | $creates_path = "${_basedir}/${install_path}" 87 | $os = 'linux_hotspot' 88 | } 89 | default : { 90 | fail ( "unsupported platform ${$facts['kernel']}" ) 91 | } 92 | } 93 | 94 | # set java architecture nomenclature 95 | $os_architecture = $facts['os']['architecture'] ? { 96 | default => $facts['os']['architecture'] 97 | } 98 | 99 | case $os_architecture { 100 | 'i386' : { $arch = 'x86-32' } 101 | 'x86_64' : { $arch = 'x64' } 102 | 'amd64' : { $arch = 'x64' } 103 | default : { 104 | fail ("unsupported platform ${$os_architecture}") 105 | } 106 | } 107 | 108 | # package name and path for download from github 109 | # 110 | # following are build based on this real life example full URLs: 111 | # 112 | # https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.1%2B12/OpenJDK17U-jdk_x64_linux_hotspot_17.0.1_12.tar.gz 113 | # https://github.com/adoptium/temurin16-binaries/releases/download/jdk-16.0.2%2B7/OpenJDK16U-jdk_x64_alpine-linux_hotspot_16.0.2_7.tar.gz 114 | 115 | $package_name = "OpenJDK${version_major}U-jdk_${arch}_${os}_${version_major}.${version_minor}.${version_patch}_${version_build}.tar.gz" 116 | 117 | # if complete URL is provided, use this value for source in archive resource 118 | if $url { 119 | $source = $url 120 | } 121 | else { 122 | $source = "https://github.com/adoptium/temurin${version_major}-binaries/releases/download/jdk-${version_major}.${version_minor}.${version_patch}%2B${version_build}/${package_name}" 123 | notice ("Default source url : ${source}") 124 | } 125 | 126 | # full path to the installer 127 | $destination = "/tmp/${package_name}" 128 | notice ("Destination is ${destination}") 129 | 130 | case $ensure { 131 | 'present' : { 132 | archive { $destination : 133 | ensure => present, 134 | source => $source, 135 | extract_path => '/tmp', 136 | cleanup => false, 137 | creates => $creates_path, 138 | proxy_server => $proxy_server, 139 | proxy_type => $proxy_type, 140 | } 141 | case $facts['kernel'] { 142 | 'Linux' : { 143 | case $facts['os']['family'] { 144 | 'Debian' : { 145 | ensure_resource('file', $_basedir, { 146 | ensure => directory, 147 | } 148 | ) 149 | $install_requires = [Archive[$destination], File[$_basedir]] 150 | } 151 | default : { 152 | $install_requires = [Archive[$destination]] 153 | } 154 | } 155 | 156 | if $manage_basedir { 157 | if (!defined(File[$_basedir])) { 158 | file { $_basedir: 159 | ensure => 'directory', 160 | before => Exec["Install Adoptium Temurin java ${version_major} ${version_minor} ${version_patch} ${version_build}"], 161 | } 162 | } 163 | } 164 | 165 | $install_adoptium = ['tar', '-zxf', $destination, '-C', $_basedir] 166 | 167 | exec { "Install Adoptium Temurin java ${version_major} ${version_minor} ${version_patch} ${version_build}" : 168 | path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin', 169 | command => $install_adoptium, 170 | creates => $creates_path, 171 | require => $install_requires, 172 | } 173 | 174 | if ($manage_symlink and $symlink_name) { 175 | file { "${_basedir}/${symlink_name}": 176 | ensure => link, 177 | target => $creates_path, 178 | require => Exec["Install Adoptium Temurin java ${version_major} ${version_minor} ${version_patch} ${version_build}"], 179 | } 180 | } 181 | } 182 | default : { 183 | fail ("unsupported platform ${$facts['kernel']}") 184 | } 185 | } 186 | } 187 | default : { 188 | notice ("Action ${ensure} not supported.") 189 | } 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /manifests/config.pp: -------------------------------------------------------------------------------- 1 | # @api private 2 | class java::config ( ) { 3 | case $facts['os']['family'] { 4 | 'Debian': { 5 | if $java::use_java_alternative != undef and $java::use_java_alternative_path != undef { 6 | $command_debian = ['update-java-alternatives', '--set', $java::use_java_alternative, $java::jre_flag] 7 | $unless_debian = [['test', '/etc/alternatives/java', '-ef', $java::use_java_alternative_path]] 8 | 9 | exec { 'update-java-alternatives': 10 | path => '/usr/bin:/usr/sbin:/bin:/sbin', 11 | command => $command_debian, 12 | unless => $unless_debian, 13 | } 14 | } 15 | if $java::use_java_home != undef { 16 | file_line { 'java-home-environment': 17 | path => '/etc/environment', 18 | line => "JAVA_HOME=${$java::use_java_home}", 19 | match => 'JAVA_HOME=', 20 | } 21 | } 22 | } 23 | 'RedHat': { 24 | if $java::use_java_alternative != undef and $java::use_java_alternative_path != undef { 25 | # The standard packages install alternatives, custom packages do not 26 | # For the stanard packages java::params needs these added. 27 | if $java::use_java_package_name != $java::default_package_name { 28 | $command_redhat = ['alternatives', '--install', '/usr/bin/java', 'java', $java::use_java_alternative_path, '20000'] 29 | $unless_redhat = "alternatives --display java | grep -q ${shell_escape($java::use_java_alternative_path)}" 30 | 31 | exec { 'create-java-alternatives': 32 | path => '/usr/bin:/usr/sbin:/bin:/sbin', 33 | command => $command_redhat, 34 | unless => $unless_redhat, 35 | before => Exec['update-java-alternatives'], 36 | } 37 | } 38 | $command_default = ['alternatives', '--set', 'java', $java::use_java_alternative_path] 39 | $unless_default = [['test', '/etc/alternatives/java', '-ef', $java::use_java_alternative_path]] 40 | 41 | exec { 'update-java-alternatives': 42 | path => '/usr/bin:/usr/sbin', 43 | command => $command_default, 44 | unless => $unless_default, 45 | } 46 | } 47 | if $java::use_java_home != undef { 48 | file_line { 'java-home-environment': 49 | path => '/etc/environment', 50 | line => "JAVA_HOME=${$java::use_java_home}", 51 | match => 'JAVA_HOME=', 52 | } 53 | } 54 | } 55 | 'Suse': { 56 | if $java::use_java_home != undef { 57 | file_line { 'java-home-environment': 58 | path => '/etc/environment', 59 | line => "JAVA_HOME=${$java::use_java_home}", 60 | match => 'JAVA_HOME=', 61 | } 62 | } 63 | } 64 | 'FreeBSD': { 65 | if $java::use_java_home != undef { 66 | file_line { 'java-home-environment-profile': 67 | path => '/etc/profile', 68 | line => "JAVA_HOME=${$java::use_java_home}; export JAVA_HOME", 69 | match => 'JAVA_HOME=', 70 | } 71 | file_line { 'java-home-environment-cshrc': 72 | path => '/etc/csh.login', 73 | line => "setenv JAVA_HOME ${$java::use_java_home}", 74 | match => 'setenv JAVA_HOME', 75 | } 76 | } 77 | } 78 | 'Solaris': { 79 | if $java::use_java_home != undef { 80 | file_line { 'java-home-environment': 81 | path => '/etc/profile', 82 | line => "JAVA_HOME=${$java::use_java_home}", 83 | match => 'JAVA_HOME=', 84 | } 85 | } 86 | } 87 | 'Archlinux': { 88 | if $java::use_java_home != undef { 89 | file_line { 'java-home-environment': 90 | path => '/etc/profile', 91 | line => "JAVA_HOME=${$java::use_java_home}", 92 | match => 'JAVA_HOME=', 93 | } 94 | } 95 | } 96 | default: { 97 | # Do nothing. 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /manifests/download.pp: -------------------------------------------------------------------------------- 1 | # Defined Type java::download 2 | # 3 | # @summary 4 | # Installs Java from a url location. 5 | # 6 | # 7 | # @param ensure 8 | # Install or remove the package. 9 | # 10 | # @param version 11 | # Version of Java to install, e.g. '7' or '8'. Default values for major and minor versions will be used. 12 | # 13 | # @param version_major 14 | # Major version which should be installed, e.g. '8u101'. Must be used together with version_minor. 15 | # 16 | # @param version_minor 17 | # Minor version which should be installed, e.g. 'b12'. Must be used together with version_major. 18 | # 19 | # @param java_se 20 | # Type of Java Standard Edition to install, jdk or jre. 21 | # 22 | # @param proxy_server 23 | # Specify a proxy server, with port number if needed. ie: https://example.com:8080. (passed to archive) 24 | # 25 | # @param proxy_type 26 | # Proxy server type (none|http|https|ftp). (passed to archive) 27 | # 28 | # @param url 29 | # Full URL 30 | # 31 | # @param jce 32 | # Install Oracles Java Cryptographic Extensions into the JRE or JDK 33 | # 34 | # @param jce_url 35 | # Full URL to the jce zip file 36 | # 37 | # @param basedir 38 | # Directory under which the installation will occur. If not set, defaults to 39 | # /usr/lib/jvm for Debian and /usr/java for RedHat. 40 | # 41 | # @param manage_basedir 42 | # Whether to manage the basedir directory. Defaults to false. 43 | # Note: /usr/lib/jvm is managed for Debian by default, separate from this parameter. 44 | # 45 | # @param package_type 46 | # Type of installation package for specified version of java_se. java_se 6 comes 47 | # in a few installation package flavors and we need to account for them. 48 | # Optional forced package types: rpm, rpmbin, tar.gz 49 | # 50 | # @param manage_symlink 51 | # Whether to manage a symlink that points to the installation directory. Defaults to false. 52 | # 53 | # @param symlink_name 54 | # The name for the optional symlink in the installation directory. 55 | # 56 | define java::download ( 57 | Enum['present'] $ensure = 'present', 58 | String[1] $version = '8', 59 | Optional[String] $version_major = undef, 60 | Optional[String] $version_minor = undef, 61 | String[1] $java_se = 'jdk', 62 | Optional[String] $proxy_server = undef, 63 | Optional[Enum['none', 'http', 'https', 'ftp']] $proxy_type = undef, 64 | Optional[String] $url = undef, 65 | Boolean $jce = false, 66 | Optional[String] $jce_url = undef, 67 | Optional[String] $basedir = undef, 68 | Boolean $manage_basedir = false, 69 | Optional[String] $package_type = undef, 70 | Boolean $manage_symlink = false, 71 | Optional[String] $symlink_name = undef, 72 | ) { 73 | # archive module is used to download the java package 74 | include archive 75 | 76 | # validate java Standard Edition to download 77 | if $java_se !~ /(jre|jdk)/ { 78 | fail('Java SE must be either jre or jdk.') 79 | } 80 | 81 | if $jce { 82 | if $jce_url { 83 | $jce_download = $jce_url 84 | } else { 85 | fail('JCE URL must be specified') 86 | } 87 | } 88 | 89 | # determine Java major and minor version, and installation path 90 | if $version_major and $version_minor { 91 | $label = $version_major 92 | $release_major = $version_major 93 | $release_minor = $version_minor 94 | 95 | if $release_major =~ /(\d+)u(\d+)/ { 96 | # Required for CentOS systems where Java8 update number is >= 171 to ensure 97 | # the package is visible to Puppet. This is only true for installations that 98 | # don't use the tar.gz package type. 99 | if $facts['os']['family'] == 'RedHat' and Numeric($2) >= 171 and $package_type != 'tar.gz' { 100 | $install_path = "${java_se}1.${1}.0_${2}-amd64" 101 | } else { 102 | $install_path = "${java_se}1.${1}.0_${2}" 103 | } 104 | } else { 105 | $install_path = "${java_se}${release_major}${release_minor}" 106 | } 107 | } else { 108 | # use default versions if no specific major and minor version parameters are provided 109 | $label = $version 110 | case $version { 111 | '6' : { 112 | $release_major = '6u45' 113 | $release_minor = 'b06' 114 | $install_path = "${java_se}1.6.0_45" 115 | } 116 | '7' : { 117 | $release_major = '7u80' 118 | $release_minor = 'b15' 119 | $install_path = "${java_se}1.7.0_80" 120 | } 121 | '8' : { 122 | $release_major = '8u201' 123 | $release_minor = 'b09' 124 | $install_path = "${java_se}1.8.0_201" 125 | } 126 | default : { 127 | $release_major = '8u201' 128 | $release_minor = 'b09' 129 | $install_path = "${java_se}1.8.0_201" 130 | } 131 | } 132 | } 133 | 134 | # determine package type (exe/tar/rpm), destination directory based on OS 135 | case $facts['kernel'] { 136 | 'Linux' : { 137 | case $facts['os']['family'] { 138 | 'RedHat', 'Amazon' : { 139 | # Oracle Java 6 comes in a special rpmbin format 140 | if $package_type { 141 | $_package_type = $package_type 142 | } elsif $version == '6' { 143 | $_package_type = 'rpmbin' 144 | } else { 145 | $_package_type = 'rpm' 146 | } 147 | if $basedir { 148 | $_basedir = $basedir 149 | } else { 150 | $_basedir = '/usr/java' 151 | } 152 | } 153 | 'Debian' : { 154 | if $package_type { 155 | $_package_type = $package_type 156 | } else { 157 | $_package_type = 'tar.gz' 158 | } 159 | if $basedir { 160 | $_basedir = $basedir 161 | } else { 162 | $_basedir = '/usr/lib/jvm' 163 | } 164 | } 165 | default : { 166 | fail ("unsupported platform ${$facts['os']['name']}") 167 | } 168 | } 169 | 170 | $creates_path = "${_basedir}/${install_path}" 171 | $os = 'linux' 172 | $destination_dir = '/tmp/' 173 | } 174 | default : { 175 | fail ( "unsupported platform ${$facts['kernel']}" ) 176 | } 177 | } 178 | 179 | # Install required unzip packages for jce 180 | if $jce { 181 | ensure_resource('package', 'unzip', { 'ensure' => 'present' }) 182 | } 183 | 184 | # set java architecture nomenclature 185 | $os_architecture = $facts['os']['architecture'] ? { 186 | undef => $facts['os']['architecture'], 187 | default => $facts['os']['architecture'] 188 | } 189 | 190 | case $os_architecture { 191 | 'i386' : { $arch = 'i586' } 192 | 'x86_64' : { $arch = 'x64' } 193 | 'amd64' : { $arch = 'x64' } 194 | 'aarch64' : { $arch = 'aarch64' } 195 | 'arm64' : { $arch = 'aarch64' } 196 | default : { 197 | fail ("unsupported platform ${$os_architecture}") 198 | } 199 | } 200 | 201 | # following are based on this example: 202 | # http://download.oracle.com/otn-pub/java/jdk/7u80-b15/jre-7u80-linux-i586.rpm 203 | # 204 | # JaveSE 6 distributed in .bin format 205 | # http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586-rpm.bin 206 | # http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin 207 | # package name to use in destination directory for the installer 208 | case $_package_type { 209 | 'bin' : { 210 | $package_name = "${java_se}-${version}-${release_major}-${release_minor}-${os}-${arch}.bin" 211 | } 212 | 'rpmbin' : { 213 | $package_name = "${java_se}-${version}-${release_major}-${release_minor}-${os}-${arch}-rpm.bin" 214 | } 215 | 'rpm' : { 216 | $package_name = "${java_se}-${version}-${release_major}-${release_minor}-${os}-${arch}.rpm" 217 | } 218 | 'tar.gz' : { 219 | $package_name = "${java_se}-${version}-${release_major}-${release_minor}-${os}-${arch}.tar.gz" 220 | } 221 | default : { 222 | $package_name = "${java_se}-${version}-${release_major}-${release_minor}-${os}-${arch}.rpm" 223 | } 224 | } 225 | 226 | # if complete URL is provided, use this value for source in archive resource 227 | if $url { 228 | $source = $url 229 | } 230 | else { 231 | fail('Url must be specified') 232 | } 233 | 234 | # full path to the installer 235 | $destination = "${destination_dir}${package_name}" 236 | notice ("Destination is ${destination}") 237 | 238 | case $_package_type { 239 | 'bin' : { 240 | $install_command = ['sh', $destination] 241 | } 242 | 'rpmbin' : { 243 | $install_command = ['sh', $destination, '-x;', 'rpm', '--force', '-iv', 'sun*.rpm;', 'rpm', '--force', '-iv', "${java_se}*.rpm"] 244 | } 245 | 'rpm' : { 246 | $install_command = ['rpm', '--force', '-iv', $destination] 247 | } 248 | 'tar.gz' : { 249 | $install_command = ['tar', '-zxf', $destination, '-C', $_basedir] 250 | } 251 | default : { 252 | $install_command = ['rpm', '-iv', $destination] 253 | } 254 | } 255 | 256 | case $ensure { 257 | 'present' : { 258 | archive { $destination : 259 | ensure => present, 260 | source => $source, 261 | extract_path => '/tmp', 262 | cleanup => false, 263 | creates => $creates_path, 264 | proxy_server => $proxy_server, 265 | proxy_type => $proxy_type, 266 | } 267 | case $facts['kernel'] { 268 | 'Linux' : { 269 | case $facts['os']['family'] { 270 | 'Debian' : { 271 | ensure_resource('file', $_basedir, { 272 | ensure => directory, 273 | } 274 | ) 275 | $install_requires = [Archive[$destination], File[$_basedir]] 276 | } 277 | default : { 278 | $install_requires = [Archive[$destination]] 279 | } 280 | } 281 | 282 | if $manage_basedir { 283 | ensure_resource('file', $_basedir, { 'ensure' => 'directory', 'before' => Exec["Install Oracle java_se ${java_se} ${version} ${release_major} ${release_minor}"] }) 284 | } 285 | 286 | exec { "Install Oracle java_se ${java_se} ${version} ${release_major} ${release_minor}" : 287 | path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin', 288 | command => $install_command, 289 | creates => $creates_path, 290 | require => $install_requires, 291 | } 292 | 293 | if ($manage_symlink and $symlink_name) { 294 | file { "${_basedir}/${symlink_name}": 295 | ensure => link, 296 | target => $creates_path, 297 | require => Exec["Install Oracle java_se ${java_se} ${version} ${release_major} ${release_minor}"], 298 | } 299 | } 300 | 301 | if ($jce and $jce_download != undef) { 302 | $jce_path = $java_se ? { 303 | 'jre' => "${creates_path}/lib/security", 304 | 'jdk' => "${creates_path}/jre/lib/security" 305 | } 306 | archive { "/tmp/jce-${version}.zip": 307 | source => $jce_download, 308 | extract => true, 309 | extract_path => $jce_path, 310 | extract_flags => '-oj', 311 | creates => "${jce_path}/US_export_policy.jar", 312 | cleanup => false, 313 | proxy_server => $proxy_server, 314 | proxy_type => $proxy_type, 315 | require => [ 316 | Package['unzip'], 317 | Exec["Install Oracle java_se ${java_se} ${version} ${release_major} ${release_minor}"] 318 | ], 319 | } 320 | } 321 | } 322 | default : { 323 | fail ("unsupported platform ${$facts['kernel']}") 324 | } 325 | } 326 | } 327 | default : { 328 | notice ("Action ${ensure} not supported.") 329 | } 330 | } 331 | } 332 | -------------------------------------------------------------------------------- /manifests/init.pp: -------------------------------------------------------------------------------- 1 | # @summary 2 | # This module manages the Java runtime package 3 | # 4 | # @param distribution 5 | # The java distribution to install. Can be one of "jdk" or "jre", 6 | # or other platform-specific options where there are multiple 7 | # implementations available (eg: OpenJDK vs Oracle JDK). 8 | # 9 | # @param version 10 | # The version of java to install. By default, this module simply ensures 11 | # that java is present, and does not require a specific version. 12 | # 13 | # @param package 14 | # The name of the java package. This is configurable in case a non-standard 15 | # java package is desired. 16 | # 17 | # @param package_options 18 | # Array of strings to pass installation options to the 'package' Puppet resource. 19 | # Options available depend on the 'package' provider for the target OS. 20 | # 21 | # @param java_alternative 22 | # The name of the java alternative to use on Debian systems. 23 | # "update-java-alternatives -l" will show which choices are available. 24 | # If you specify a particular package, you will almost always also 25 | # want to specify which java_alternative to choose. If you set 26 | # this, you also need to set the path below. 27 | # 28 | # @param java_alternative_path 29 | # The path to the "java" command on Debian systems. Since the 30 | # alternatives system makes it difficult to verify which 31 | # alternative is actually enabled, this is required to ensure the 32 | # correct JVM is enabled. 33 | # 34 | # @param java_home 35 | # The path to where the JRE is installed. This will be set as an 36 | # environment variable. 37 | # 38 | class java ( 39 | String $distribution = 'jdk', 40 | Pattern[/present|installed|latest|^[.+_0-9a-zA-Z:~-]+$/] $version = 'present', 41 | Optional[String] $package = undef, 42 | Optional[Array] $package_options = undef, 43 | Optional[String] $java_alternative = undef, 44 | Optional[String] $java_alternative_path = undef, 45 | Optional[String] $java_home = undef 46 | ) { 47 | contain java::params 48 | 49 | $default_package_name = $distribution in $java::params::java ? { 50 | false => undef, 51 | default => $java::params::java[$distribution]['package'], 52 | } 53 | 54 | $use_java_package_name = $package ? { 55 | undef => $default_package_name, 56 | default => $package, 57 | } 58 | 59 | ## Weird logic........ 60 | ## If $java_alternative is set, use that. 61 | ## Elsif the DEFAULT package is being used, then use $default_alternative. 62 | ## Else undef 63 | $use_java_alternative = $java_alternative ? { 64 | undef => $use_java_package_name ? { 65 | $default_package_name => $distribution in $java::params::java ? { 66 | default => $java::params::java[$distribution]['alternative'], 67 | false => undef, 68 | }, 69 | default => undef, 70 | }, 71 | default => $java_alternative, 72 | } 73 | 74 | ## Same logic as $java_alternative above. 75 | $use_java_alternative_path = $java_alternative_path ? { 76 | undef => $use_java_package_name ? { 77 | $default_package_name => $distribution in $java::params::java ? { 78 | default => $java::params::java[$distribution]['alternative_path'], 79 | false => undef, 80 | }, 81 | default => undef, 82 | }, 83 | default => $java_alternative_path, 84 | } 85 | 86 | $use_java_home = $java_home ? { 87 | undef => $use_java_package_name ? { 88 | $default_package_name => $distribution in $java::params::java ? { 89 | default => $java::params::java[$distribution]['java_home'], 90 | false => undef, 91 | }, 92 | default => undef, 93 | }, 94 | default => $java_home, 95 | } 96 | 97 | ## This should only be required if we did not override all the information we need. 98 | # One of the defaults is missing and its not intentional: 99 | if (( 100 | $use_java_package_name == undef or $use_java_alternative == undef or 101 | $use_java_alternative_path == undef or $use_java_home == undef 102 | ) and ( 103 | !($distribution in $java::params::java) 104 | )) { 105 | fail("Java distribution ${distribution} is not supported. Missing default values.") 106 | } 107 | 108 | $jre_flag = $use_java_package_name ? { 109 | /headless/ => '--jre-headless', 110 | default => '--jre' 111 | } 112 | 113 | # If the OS is SLES >= 15.3, enable the legacy repo to install net-tools-deprecated package 114 | if ($facts['os']['family'] in ['SLES', 'SUSE']) and (versioncmp($facts['os']['release']['full'], '15.3') >= 0) { 115 | exec { 'Enable legacy repos': 116 | path => '/bin:/usr/bin/:/sbin:/usr/sbin', 117 | command => "SUSEConnect --product sle-module-legacy/${facts['os']['release']['full']}/x86_64", 118 | unless => "SUSEConnect --status-text | grep sle-module-legacy/${facts['os']['release']['full']}/x86_64", 119 | } 120 | } 121 | 122 | if $facts['os']['family'] == 'Debian' { 123 | # Needed for update-java-alternatives 124 | package { 'java-common': 125 | ensure => present, 126 | before => Class['java::config'], 127 | } 128 | } 129 | 130 | package { 'java': 131 | ensure => $version, 132 | install_options => $package_options, 133 | name => $use_java_package_name, 134 | } 135 | -> class { 'java::config': } 136 | } 137 | -------------------------------------------------------------------------------- /manifests/params.pp: -------------------------------------------------------------------------------- 1 | # @summary 2 | # This class builds a hash of JDK/JRE packages and (for Debian) 3 | # alternatives. For wheezy/precise, we provide Oracle JDK/JRE 4 | # options, even though those are not in the package repositories. 5 | # 6 | # @api private 7 | class java::params { 8 | case $facts['os']['family'] { 9 | 'RedHat': { 10 | case $facts['os']['name'] { 11 | 'AlmaLinux', 'Rocky', 'RedHat', 'CentOS', 'OracleLinux', 'Scientific', 'OEL', 'SLC', 'CloudLinux': { 12 | # See PR#160 / c8e46b5 for why >= 6.3 < 7.1 13 | if (versioncmp($facts['os']['release']['full'], '7.1') < 0) { 14 | $openjdk = '1.7.0' 15 | } else { 16 | $openjdk = '1.8.0' 17 | } 18 | $jdk_package = "java-${openjdk}-openjdk-devel" 19 | $jre_package = "java-${openjdk}-openjdk" 20 | $java_home = "/usr/lib/jvm/java-${openjdk}/" 21 | } 22 | 'Fedora': { 23 | if (versioncmp($facts['os']['release']['full'], '21') < 0) { 24 | $openjdk = '1.7.0' 25 | } else { 26 | $openjdk = '1.8.0' 27 | } 28 | $jdk_package = "java-${openjdk}-openjdk-devel" 29 | $jre_package = "java-${openjdk}-openjdk" 30 | $java_home = "/usr/lib/jvm/java-${openjdk}-openjdk-${facts['os']['architecture']}/" 31 | } 32 | 'Amazon': { 33 | $jdk_package = 'java-1.7.0-openjdk-devel' 34 | $jre_package = 'java-1.7.0-openjdk' 35 | $java_home = "/usr/lib/jvm/java-1.7.0-openjdk-${facts['os']['architecture']}/" 36 | } 37 | default: { fail("unsupported os ${facts['os']['name']}") } 38 | } 39 | $java = { 40 | 'jdk' => { 41 | 'package' => $jdk_package, 42 | 'java_home' => $java_home, 43 | }, 44 | 'jre' => { 45 | 'package' => $jre_package, 46 | 'java_home' => $java_home, 47 | }, 48 | } 49 | } 50 | 'Debian': { 51 | $oracle_architecture = $facts['os']['architecture'] ? { 52 | 'amd64' => 'x64', 53 | default => $facts['os']['architecture'] 54 | } 55 | $openjdk_architecture = $facts['os']['architecture'] ? { 56 | 'aarch64' => 'arm64', 57 | 'armv7l' => 'armhf', 58 | default => $facts['os']['architecture'] 59 | } 60 | case $facts['os']['release']['major'] { 61 | '12', '24.04': { 62 | $openjdk = 17 63 | } 64 | '10', '11', '18.04', '18.10', '19.04', '19.10', '20.04', '22.04': { 65 | $openjdk = 11 66 | } 67 | default: { fail("unsupported release ${facts['os']['release']['major']}") } 68 | } 69 | $java = { 70 | 'jdk' => { 71 | 'package' => "openjdk-${openjdk}-jdk", 72 | 'alternative' => "java-1.${openjdk}.0-openjdk-${openjdk_architecture}", 73 | 'alternative_path' => "/usr/lib/jvm/java-1.${openjdk}.0-openjdk-${openjdk_architecture}/bin/java", 74 | 'java_home' => "/usr/lib/jvm/java-1.${openjdk}.0-openjdk-${openjdk_architecture}/", 75 | }, 76 | 'jre' => { 77 | 'package' => "openjdk-${openjdk}-jre-headless", 78 | 'alternative' => "java-1.${openjdk}.0-openjdk-${openjdk_architecture}", 79 | 'alternative_path' => "/usr/lib/jvm/java-1.${openjdk}.0-openjdk-${openjdk_architecture}/bin/java", 80 | 'java_home' => "/usr/lib/jvm/java-1.${openjdk}.0-openjdk-${openjdk_architecture}/", 81 | }, 82 | } 83 | } 84 | 'OpenBSD': { 85 | $java = { 86 | 'jdk' => { 87 | 'package' => 'jdk', 88 | 'java_home' => '/usr/local/jdk/', 89 | }, 90 | 'jre' => { 91 | 'package' => 'jre', 92 | 'java_home' => '/usr/local/jdk/', 93 | }, 94 | } 95 | } 96 | 'FreeBSD': { 97 | $java = { 98 | 'jdk' => { 99 | 'package' => 'openjdk', 100 | 'java_home' => '/usr/local/openjdk7/', 101 | }, 102 | 'jre' => { 103 | 'package' => 'openjdk-jre', 104 | 'java_home' => '/usr/local/openjdk7/', 105 | }, 106 | } 107 | } 108 | 'Solaris': { 109 | $java = { 110 | 'jdk' => { 111 | 'package' => 'developer/java/jdk-7', 112 | 'java_home' => '/usr/jdk/instances/jdk1.7.0/', 113 | }, 114 | 'jre' => { 115 | 'package' => 'runtime/java/jre-7', 116 | 'java_home' => '/usr/jdk/instances/jdk1.7.0/', 117 | }, 118 | } 119 | } 120 | 'Suse': { 121 | case $facts['os']['name'] { 122 | 'SLES': { 123 | if (versioncmp($facts['os']['release']['full'], '12.1') >= 0) { 124 | $jdk_package = 'java-1_8_0-openjdk-devel' 125 | $jre_package = 'java-1_8_0-openjdk' 126 | $java_home = '/usr/lib64/jvm/java-1.8.0-openjdk-1.8.0/' 127 | } elsif (versioncmp($facts['os']['release']['full'], '12') >= 0) { 128 | $jdk_package = 'java-1_7_0-openjdk-devel' 129 | $jre_package = 'java-1_7_0-openjdk' 130 | $java_home = '/usr/lib64/jvm/java-1.7.0-openjdk-1.7.0/' 131 | } elsif (versioncmp($facts['os']['release']['full'], '11.4') >= 0) { 132 | $jdk_package = 'java-1_7_1-ibm-devel' 133 | $jre_package = 'java-1_7_1-ibm' 134 | $java_home = '/usr/lib64/jvm/java-1.7.1-ibm-1.7.1/' 135 | } else { 136 | $jdk_package = 'java-1_6_0-ibm-devel' 137 | $jre_package = 'java-1_6_0-ibm' 138 | $java_home = '/usr/lib64/jvm/java-1.6.0-ibm-1.6.0/' 139 | } 140 | } 141 | 'OpenSuSE': { 142 | $jdk_package = 'java-1_7_0-openjdk-devel' 143 | $jre_package = 'java-1_7_0-openjdk' 144 | $java_home = '/usr/lib64/jvm/java-1.7.0-openjdk-1.7.0/' 145 | } 146 | default: { 147 | $jdk_package = 'java-1_6_0-ibm-devel' 148 | $jre_package = 'java-1_6_0-ibm' 149 | $java_home = '/usr/lib64/jvm/java-1.6.0-ibd-1.6.0/' 150 | } 151 | } 152 | $java = { 153 | 'jdk' => { 154 | 'package' => $jdk_package, 155 | 'java_home' => $java_home, 156 | }, 157 | 'jre' => { 158 | 'package' => $jre_package, 159 | 'java_home' => $java_home, 160 | }, 161 | } 162 | } 163 | 'Archlinux': { 164 | $jdk_package = 'jdk8-openjdk' 165 | $jre_package = 'jre8-openjdk' 166 | $java_home = '/usr/lib/jvm/java-8-openjdk/jre/' 167 | $java = { 168 | 'jdk' => { 169 | 'package' => $jdk_package, 170 | 'java_home' => $java_home, 171 | }, 172 | 'jre' => { 173 | 'package' => $jre_package, 174 | 'java_home' => $java_home, 175 | }, 176 | } 177 | } 178 | default: { fail("unsupported platform ${facts['os']['family']}") } 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /manifests/sap.pp: -------------------------------------------------------------------------------- 1 | # Defined Type java::sap 2 | # 3 | # @summary 4 | # Install one or more versions of SAPJVM or Sapmachine 5 | # 6 | # @param ensure 7 | # Install or remove the package. 8 | # 9 | # @param version 10 | # Version of Java to install, e.g. '8' or '9'. Default values for full versions will be used. 11 | # 12 | # @param version_full 13 | # Major version which should be installed, e.g. '8.1.063' or '11.0.7'. If used, "version" parameter is ignored. 14 | # 15 | # @param java 16 | # Type of Java Edition to install, jdk or jre. 17 | # 18 | # @param proxy_server 19 | # Specify a proxy server, with port number if needed. ie: https://example.com:8080. (passed to archive) 20 | # 21 | # @param proxy_type 22 | # Proxy server type (none|http|https|ftp). (passed to archive) 23 | # 24 | # @param basedir 25 | # Directory under which the installation will occur. If not set, defaults to 26 | # /usr/lib/jvm for Debian and /usr/java for RedHat. 27 | # 28 | # @param manage_basedir 29 | # Whether to manage the basedir directory. 30 | # Note: /usr/lib/jvm is managed for Debian by default, separate from this parameter. 31 | # 32 | # @param manage_symlink 33 | # Whether to manage a symlink that points to the installation directory. Defaults to false. 34 | # 35 | # @param symlink_name 36 | # The name for the optional symlink in the installation directory. 37 | # 38 | define java::sap ( 39 | Enum['present'] $ensure = 'present', 40 | String[1] $version = '8', 41 | Optional[String] $version_full = undef, 42 | String[1] $java = 'jdk', 43 | Optional[String] $proxy_server = undef, 44 | Optional[Enum['none', 'http', 'https', 'ftp']] $proxy_type = undef, 45 | Optional[String] $basedir = undef, 46 | Boolean $manage_basedir = true, 47 | Boolean $manage_symlink = false, 48 | Optional[String] $symlink_name = undef, 49 | ) { 50 | # archive module is used to download the java package 51 | include archive 52 | 53 | # validate java edition to download 54 | if $java !~ /(jre|jdk)/ { 55 | fail('java must be either jre or jdk.') 56 | } 57 | 58 | # determine version and installation path 59 | if $version_full { 60 | $_version_array = $version_full.scanf('%i') 61 | $_version_int = $_version_array[0] 62 | $_version_full = $version_full 63 | } else { 64 | $_version = $version 65 | $_version_int = Numeric($_version) 66 | # use default versions if full version parameter is not provided 67 | case $version { 68 | '7' : { 69 | $_version_full = '7.1.072' 70 | if ($java != 'jdk') { 71 | fail('java parameter is not jdk. jre is not supported on version 7') 72 | } 73 | } 74 | '8' : { 75 | $_version_full = '8.1.065' 76 | if ($java != 'jdk') { 77 | fail('java parameter is not jdk. jre is not supported on version 8') 78 | } 79 | } 80 | '11' : { 81 | $_version_full = '11.0.7' 82 | } 83 | '14' : { 84 | $_version_full = '14.0.1' 85 | } 86 | default : { 87 | fail("${version} not yet supported by module") 88 | } 89 | } 90 | } 91 | 92 | # extracted folders look like this: 93 | # sapjvm_8 94 | # sapmachine-jdk-11.0.7 95 | if ($_version_int == 7 or $_version_int == 8) { 96 | $_creates_folder = "sapjvm_${_version_int}" 97 | } else { 98 | $_creates_folder = "sapmachine-${java}-${_version_full}" 99 | } 100 | 101 | # determine destination directory based on OS 102 | case $facts['kernel'] { 103 | 'Linux' : { 104 | case $facts['os']['family'] { 105 | 'RedHat', 'Amazon' : { 106 | if $basedir { 107 | $_basedir = $basedir 108 | } else { 109 | $_basedir = '/usr/java' 110 | } 111 | } 112 | 'Debian' : { 113 | if $basedir { 114 | $_basedir = $basedir 115 | } else { 116 | $_basedir = '/usr/lib/jvm' 117 | } 118 | } 119 | default : { 120 | fail ("unsupported os family ${$facts['os']['name']}") 121 | } 122 | } 123 | $creates_path = "${_basedir}/${_creates_folder}" 124 | } 125 | default : { 126 | fail ( "unsupported platform ${$facts['kernel']}" ) 127 | } 128 | } 129 | 130 | $_os_architecture = $facts['os']['architecture'] ? { 131 | default => $facts['os']['architecture'] 132 | } 133 | 134 | if ($_os_architecture != 'x86_64' and $_os_architecture != 'amd64') { 135 | fail ("unsupported platform ${_os_architecture}") 136 | } 137 | 138 | # download links look like this (examples): 139 | # https://tools.hana.ondemand.com/additional/sapjvm-8.1.065-linux-x64.zip 140 | # https://github.com/SAP/SapMachine/releases/download/sapmachine-11.0.7/sapmachine-jre-11.0.7_linux-x64_bin.tar.gz 141 | # https://github.com/SAP/SapMachine/releases/download/sapmachine-11.0.7/sapmachine-jdk-11.0.7_linux-x64_bin.tar.gz 142 | # https://github.com/SAP/SapMachine/releases/download/sapmachine-14.0.1/sapmachine-jdk-14.0.1_linux-x64_bin.tar.gz 143 | 144 | # cookie is currently at version 3.1, but may be changed one day. It is only required for download at SAP. 145 | # by using this module you agree with the EULA presented at tools.hana.ondemand.com download page! 146 | # Github does not require it 147 | 148 | if ( $_version_int == 7 or $_version_int == 8 ) { 149 | # sapjvm download 150 | $archive_filename = "sapjvm-${_version_full}-linux-x64.zip" 151 | $source = "https://tools.hana.ondemand.com/additional/${archive_filename}" 152 | $cookie = 'eula_3_1_agreed=tools.hana.ondemand.com/developer-license-3_1.txt' 153 | 154 | if (!defined(Package['unzip'])) { 155 | package { 'unzip': 156 | ensure => 'present', 157 | before => Archive["/tmp/${archive_filename}"], 158 | } 159 | } 160 | } else { 161 | $archive_filename = "sapmachine-${java}-${_version_full}_linux-x64_bin.tar.gz" 162 | $source = "https://github.com/SAP/SapMachine/releases/download/sapmachine-${_version_full}/${archive_filename}" 163 | $cookie = undef 164 | 165 | if (!defined(Package['tar'])) { 166 | package { 'tar': 167 | ensure => 'present', 168 | before => Archive["/tmp/${archive_filename}"], 169 | } 170 | } 171 | if (!defined(Package['gzip'])) { 172 | package { 'gzip': 173 | ensure => 'present', 174 | before => Archive["/tmp/${archive_filename}"], 175 | } 176 | } 177 | } 178 | 179 | case $ensure { 180 | 'present' : { 181 | case $facts['kernel'] { 182 | 'Linux' : { 183 | if ($manage_basedir or $facts['os']['family'] == 'Debian') { 184 | if (!defined(File[$_basedir])) { 185 | file { $_basedir: 186 | ensure => 'directory', 187 | before => Archive["/tmp/${archive_filename}"], 188 | } 189 | } 190 | } 191 | 192 | archive { "/tmp/${archive_filename}" : 193 | ensure => present, 194 | source => $source, 195 | extract => true, 196 | extract_path => $_basedir, 197 | cleanup => false, 198 | creates => $creates_path, 199 | cookie => $cookie, 200 | proxy_server => $proxy_server, 201 | proxy_type => $proxy_type, 202 | } 203 | 204 | if ($manage_symlink and $symlink_name) { 205 | file { "${_basedir}/${symlink_name}": 206 | ensure => link, 207 | target => $creates_path, 208 | require => Archive["/tmp/${archive_filename}"], 209 | } 210 | } 211 | } 212 | default : { 213 | fail ("unsupported platform ${$facts['kernel']}") 214 | } 215 | } 216 | } 217 | default : { 218 | notice ("Action ${ensure} not supported.") 219 | } 220 | } 221 | } 222 | -------------------------------------------------------------------------------- /metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "puppetlabs-java", 3 | "version": "11.1.0", 4 | "author": "puppetlabs", 5 | "summary": "Installs the correct Java package on various platforms.", 6 | "license": "Apache-2.0", 7 | "source": "git://github.com/puppetlabs/puppetlabs-java", 8 | "project_page": "https://github.com/puppetlabs/puppetlabs-java", 9 | "issues_url": "https://github.com/puppetlabs/puppetlabs-java/issues", 10 | "dependencies": [ 11 | { 12 | "name": "puppetlabs/stdlib", 13 | "version_requirement": ">= 4.13.1 < 10.0.0" 14 | }, 15 | { 16 | "name": "puppet/archive", 17 | "version_requirement": ">= 1.1.0 < 8.0.0" 18 | } 19 | ], 20 | "operatingsystem_support": [ 21 | { 22 | "operatingsystem": "RedHat", 23 | "operatingsystemrelease": [ 24 | "7", 25 | "8", 26 | "9" 27 | ] 28 | }, 29 | { 30 | "operatingsystem": "CentOS", 31 | "operatingsystemrelease": [ 32 | "7", 33 | "8" 34 | ] 35 | }, 36 | { 37 | "operatingsystem": "OracleLinux", 38 | "operatingsystemrelease": [ 39 | "7" 40 | ] 41 | }, 42 | { 43 | "operatingsystem": "Debian", 44 | "operatingsystemrelease": [ 45 | "10", 46 | "11", 47 | "12" 48 | ] 49 | }, 50 | { 51 | "operatingsystem": "Ubuntu", 52 | "operatingsystemrelease": [ 53 | "18.04", 54 | "20.04", 55 | "22.04", 56 | "24.04" 57 | ] 58 | }, 59 | { 60 | "operatingsystem": "SLES", 61 | "operatingsystemrelease": [ 62 | "12", 63 | "15" 64 | ] 65 | }, 66 | { 67 | "operatingsystem": "Rocky", 68 | "operatingsystemrelease": [ 69 | "8" 70 | ] 71 | }, 72 | { 73 | "operatingsystem": "AlmaLinux", 74 | "operatingsystemrelease": [ 75 | "8" 76 | ] 77 | } 78 | ], 79 | "requirements": [ 80 | { 81 | "name": "puppet", 82 | "version_requirement": ">= 7.0.0 < 9.0.0" 83 | } 84 | ], 85 | "template-url": "https://github.com/puppetlabs/pdk-templates.git#main", 86 | "template-ref": "tags/3.2.0.4-0-g5d17ec1", 87 | "pdk-version": "3.2.0" 88 | } 89 | -------------------------------------------------------------------------------- /pdk.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | ignore: [] 3 | -------------------------------------------------------------------------------- /provision.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | default: 3 | provisioner: docker 4 | images: 5 | - litmusimage/debian:8 6 | vagrant: 7 | provisioner: vagrant 8 | images: 9 | - centos/7 10 | - generic/ubuntu1804 11 | docker_deb: 12 | provisioner: docker 13 | images: 14 | - litmusimage/debian:9 15 | - litmusimage/debian:10 16 | docker_ub_6: 17 | provisioner: docker 18 | images: 19 | - litmusimage/ubuntu:18.04 20 | - litmusimage/ubuntu:20.04 21 | docker_el7: 22 | provisioner: docker 23 | images: 24 | - litmusimage/centos:7 25 | - litmusimage/oraclelinux:7 26 | - litmusimage/scientificlinux:7 27 | docker_el8: 28 | provisioner: docker 29 | images: 30 | - litmusimage/centos:8 31 | release_checks_6: 32 | provisioner: abs 33 | images: 34 | - redhat-6-x86_64 35 | - redhat-7-x86_64 36 | - redhat-8-x86_64 37 | - centos-6-x86_64 38 | - centos-7-x86_64 39 | - centos-8-x86_64 40 | - oracle-6-x86_64 41 | - oracle-7-x86_64 42 | - scientific-6-x86_64 43 | - scientific-7-x86_64 44 | - debian-9-x86_64 45 | - debian-10-x86_64 46 | - ubuntu-1804-x86_64 47 | - ubuntu-2004-x86_64 48 | - sles-12-x86_64 49 | - sles-15-x86_64 50 | release_checks_7: 51 | provisioner: abs 52 | images: 53 | - redhat-7-x86_64 54 | - redhat-8-x86_64 55 | - centos-7-x86_64 56 | - centos-8-x86_64 57 | - oracle-7-x86_64 58 | - debian-9-x86_64 59 | - debian-10-x86_64 60 | - ubuntu-1804-x86_64 61 | - ubuntu-2004-x86_64 62 | - sles-12-x86_64 63 | - sles-15-x86_64 64 | -------------------------------------------------------------------------------- /spec/acceptance/install_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper_acceptance' 4 | require 'pry' 5 | 6 | java_class_jre = "class { 'java':\n " \ 7 | "distribution => 'jre',\n" \ 8 | '}' 9 | 10 | java_class = "class { 'java': }" 11 | 12 | _sources = "file_line { 'non-free source':\n " \ 13 | "path => '/etc/apt/sources.list',\n " \ 14 | "match => \"deb http://osmirror.delivery.puppetlabs.net/debian/ ${::lsbdistcodename} main\",\n " \ 15 | "line => \"deb http://osmirror.delivery.puppetlabs.net/debian/ ${::lsbdistcodename} main non-free\",\n" \ 16 | '}' 17 | 18 | _sun_jre = "class { 'java':\n " \ 19 | "distribution => 'sun-jre',\n" \ 20 | '}' 21 | 22 | _sun_jdk = "class { 'java':\n " \ 23 | "distribution => 'sun-jdk',\n" \ 24 | '}' 25 | 26 | blank_version = "class { 'java':\n " \ 27 | "version => '',\n" \ 28 | '}' 29 | 30 | incorrect_distro = "class { 'java':\n " \ 31 | "distribution => 'xyz',\n" \ 32 | '}' 33 | 34 | blank_distro = "class { 'java':\n " \ 35 | "distribution => '',\n" \ 36 | '}' 37 | 38 | incorrect_package = "class { 'java':\n " \ 39 | "package => 'xyz',\n" \ 40 | '}' 41 | 42 | bogus_alternative = "class { 'java':\n " \ 43 | "java_alternative => 'whatever',\n " \ 44 | "java_alternative_path => '/whatever',\n" \ 45 | '}' 46 | 47 | # Oracle installs are disabled by default, because the links to valid oracle installations 48 | # change often. Look the parameters up from the Oracle download URLs at https://java.oracle.com and 49 | # enable the tests: 50 | 51 | oracle_enabled = false 52 | oracle_version_major = '8' 53 | oracle_version_minor = '201' 54 | oracle_version_build = '09' 55 | oracle_hash = '42970487e3af4f5aa5bca3f542482c60' 56 | 57 | install_oracle_jdk_jre = < '#{oracle_version_major}', 61 | version_major => '#{oracle_version_major}u#{oracle_version_minor}', 62 | version_minor => 'b#{oracle_version_build}', 63 | url_hash => '#{oracle_hash}', 64 | java_se => 'jre', 65 | } 66 | java::oracle { 67 | 'test_oracle_jdk': 68 | version => '#{oracle_version_major}', 69 | version_major => '#{oracle_version_major}u#{oracle_version_minor}', 70 | version_minor => 'b#{oracle_version_build}', 71 | url_hash => '#{oracle_hash}', 72 | java_se => 'jdk', 73 | } 74 | MANIFEST 75 | 76 | install_oracle_jre_jce = < '#{oracle_version_major}', 80 | version_major => '#{oracle_version_major}u#{oracle_version_minor}', 81 | version_minor => 'b#{oracle_version_build}', 82 | url_hash => '#{oracle_hash}', 83 | java_se => 'jre', 84 | jce => true, 85 | } 86 | 87 | MANIFEST 88 | 89 | install_oracle_jdk_jce = < '#{oracle_version_major}', 93 | version_major => '#{oracle_version_major}u#{oracle_version_minor}', 94 | version_minor => 'b#{oracle_version_build}', 95 | url_hash => '#{oracle_hash}', 96 | java_se => 'jdk', 97 | jce => true, 98 | } 99 | MANIFEST 100 | 101 | # AdoptOpenJDK URLs are quite generic, so tests are enabled by default 102 | # We need to test version 8 and >8 (here we use 9), because namings are different after version 8 103 | 104 | adopt_enabled = true unless os[:family].casecmp('SLES').zero? 105 | adopt_version8_major = '8' 106 | adopt_version8_minor = '202' 107 | adopt_version8_build = '08' 108 | adopt_version9_major = '9' 109 | adopt_version9_full = '9.0.4' 110 | adopt_version9_build = '11' 111 | 112 | install_adopt_jdk_jre = < '#{adopt_version8_major}', 116 | version_major => '#{adopt_version8_major}u#{adopt_version8_minor}', 117 | version_minor => 'b#{adopt_version8_build}', 118 | java => 'jre', 119 | } 120 | java::adopt { 121 | 'test_adopt_jdk_version8': 122 | version => '#{adopt_version8_major}', 123 | version_major => '#{adopt_version8_major}u#{adopt_version8_minor}', 124 | version_minor => 'b#{adopt_version8_build}', 125 | java => 'jdk', 126 | } 127 | java::adopt { 128 | 'test_adopt_jre_version9': 129 | version => '#{adopt_version9_major}', 130 | version_major => '#{adopt_version9_full}', 131 | version_minor => '#{adopt_version9_build}', 132 | java => 'jre', 133 | } 134 | java::adopt { 135 | 'test_adopt_jdk_version9': 136 | version => '#{adopt_version9_major}', 137 | version_major => '#{adopt_version9_full}', 138 | version_minor => '#{adopt_version9_build}', 139 | java => 'jdk', 140 | } 141 | MANIFEST 142 | 143 | # Adoptium 144 | 145 | adoptium_enabled = true unless os[:family].casecmp('SLES').zero? 146 | 147 | install_adoptium_jdk = < '16', 151 | version_minor => '0', 152 | version_patch => '2', 153 | version_build => '7', 154 | } 155 | java::adoptium { 156 | 'test_adoptium_jdk_version17': 157 | version_major => '17', 158 | version_minor => '0', 159 | version_patch => '1', 160 | version_build => '12', 161 | } 162 | MANIFEST 163 | 164 | sap_enabled = true 165 | sap_version7 = '7' 166 | sap_version7_full = '7.1.072' 167 | sap_version8 = '8' 168 | sap_version8_full = '8.1.065' 169 | sap_version11 = '11' 170 | sap_version11_full = '11.0.7' 171 | sap_version14 = '14' 172 | sap_version14_full = '14.0.1' 173 | 174 | install_sap_jdk_jre = < '#{sap_version7}', 178 | version_full => '#{sap_version7_full}', 179 | java => 'jdk', 180 | } 181 | java::sap { 182 | 'test_sap_jdk_version8': 183 | version => '#{sap_version8}', 184 | version_full => '#{sap_version8_full}', 185 | java => 'jdk', 186 | } 187 | java::sap { 188 | 'test_sap_jre_version11': 189 | version => '#{sap_version11}', 190 | version_full => '#{sap_version11_full}', 191 | java => 'jre', 192 | } 193 | java::sap { 194 | 'test_sap_jdk_version11': 195 | version => '#{sap_version11}', 196 | version_full => '#{sap_version11_full}', 197 | java => 'jdk', 198 | } 199 | java::sap { 200 | 'test_sap_jre_version14': 201 | version => '#{sap_version14}', 202 | version_full => '#{sap_version14_full}', 203 | java => 'jre', 204 | } 205 | java::sap { 206 | 'test_sap_jdk_version14': 207 | version => '#{sap_version14}', 208 | version_full => '#{sap_version14_full}', 209 | java => 'jdk', 210 | } 211 | MANIFEST 212 | 213 | describe 'installing' do 214 | context 'when installing java jre' do 215 | it 'installs jre' do 216 | idempotent_apply(java_class_jre) 217 | end 218 | end 219 | 220 | context 'when installing java jdk' do 221 | it 'installs jdk' do 222 | idempotent_apply(java_class) 223 | end 224 | end 225 | 226 | context 'when with failure cases' do 227 | it 'fails to install java with a blank version' do 228 | apply_manifest(blank_version, expect_failures: true) 229 | end 230 | 231 | it 'fails to install java with an incorrect distribution' do 232 | apply_manifest(incorrect_distro, expect_failures: true) 233 | end 234 | 235 | it 'fails to install java with a blank distribution' do 236 | apply_manifest(blank_distro, expect_failures: true) 237 | end 238 | 239 | it 'fails to install java with an incorrect package' do 240 | apply_manifest(incorrect_package, expect_failures: true) 241 | end 242 | 243 | it 'fails on debian or RHEL when passed fake java_alternative and path' do 244 | if os[:family] == 'sles' 245 | apply_manifest(bogus_alternative, catch_failures: true) 246 | else 247 | apply_manifest(bogus_alternative, expect_failures: true) 248 | end 249 | end 250 | end 251 | 252 | context 'when java::oracle', if: oracle_enabled, unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do 253 | let(:install_path) do 254 | (os[:family] == 'redhat') ? '/usr/java' : '/usr/lib/jvm' 255 | end 256 | 257 | let(:version_suffix) do 258 | (os[:family] == 'redhat') ? '-amd64' : '' 259 | end 260 | 261 | it 'installs oracle jdk and jre' do 262 | idempotent_apply(install_oracle_jdk_jre) 263 | jdk_result = shell("test ! -e #{install_path}/jdk1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/jre/lib/security/local_policy.jar") 264 | jre_result = shell("test ! -e #{install_path}/jre1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/lib/security/local_policy.jar") 265 | expect(jdk_result.exit_code).to eq(0) 266 | expect(jre_result.exit_code).to eq(0) 267 | end 268 | 269 | it 'installs oracle jdk with jce' do 270 | idempotent_apply(install_oracle_jdk_jce) 271 | result = shell("test -e #{install_path}/jdk1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/jre/lib/security/local_policy.jar") 272 | expect(result.exit_code).to eq(0) 273 | end 274 | 275 | it 'installs oracle jre with jce' do 276 | idempotent_apply(install_oracle_jre_jce) 277 | result = shell("test -e #{install_path}/jre1.#{oracle_version_major}.0_#{oracle_version_minor}#{version_suffix}/lib/security/local_policy.jar") 278 | expect(result.exit_code).to eq(0) 279 | end 280 | end 281 | 282 | context 'when java::adopt', if: adopt_enabled, unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do 283 | let(:install_path) do 284 | (os[:family] == 'redhat') ? '/usr/java' : '/usr/lib/jvm' 285 | end 286 | 287 | let(:version_suffix) do 288 | (os[:family] == 'redhat') ? '-amd64' : '' 289 | end 290 | 291 | it 'installs adopt jdk and jre' do 292 | idempotent_apply(install_adopt_jdk_jre) 293 | end 294 | end 295 | 296 | context 'when java::adoptium', if: adoptium_enabled, unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do 297 | let(:install_path) do 298 | (os[:family] == 'redhat') ? '/usr/java' : '/usr/lib/jvm' 299 | end 300 | 301 | let(:version_suffix) do 302 | (os[:family] == 'redhat') ? '-amd64' : '' 303 | end 304 | 305 | it 'installs adopt jdk and jre' do 306 | idempotent_apply(install_adoptium_jdk) 307 | end 308 | end 309 | 310 | context 'when java::sap', if: sap_enabled && ['Sles'].include?(os[:family]), unless: UNSUPPORTED_PLATFORMS.include?(os[:family]) do 311 | let(:install_path) do 312 | (os[:family] == 'redhat') ? '/usr/java' : '/usr/lib/jvm' 313 | end 314 | 315 | it 'installs adopt jdk and jre' do 316 | idempotent_apply(install_sap_jdk_jre) 317 | end 318 | end 319 | end 320 | -------------------------------------------------------------------------------- /spec/classes/java_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | describe 'java', type: :class do 6 | context 'when selecting openjdk for CentOS 7.1.1503' do 7 | let(:facts) { { os: { family: 'RedHat', name: 'CentOS', release: { full: '7.1.1503' }, architecture: 'x86_64' } } } 8 | 9 | it { is_expected.to contain_package('java').with_name('java-1.8.0-openjdk-devel') } 10 | it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.8.0/') } 11 | end 12 | 13 | context 'on Debian Buster (10.0)' do 14 | let(:facts) { { os: { family: 'Debian', name: 'Debian', lsb: { distcodename: 'buster' }, release: { major: '10' }, architecture: 'amd64' } } } 15 | 16 | context 'when selecting jdk' do 17 | let(:params) { { 'distribution' => 'jdk' } } 18 | 19 | it { is_expected.to contain_package('java').with_name('openjdk-11-jdk') } 20 | it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64/') } 21 | end 22 | 23 | context 'when selecting jre' do 24 | let(:params) { { 'distribution' => 'jre' } } 25 | 26 | it { is_expected.to contain_package('java').with_name('openjdk-11-jre-headless') } 27 | it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64/') } 28 | end 29 | end 30 | 31 | context 'on Debian Bookworm (12)' do 32 | let(:facts) { { os: { family: 'Debian', name: 'Debian', lsb: { distcodename: 'bookworm' }, release: { major: '12' }, architecture: 'amd64' } } } 33 | 34 | context 'when selecting jdk' do 35 | let(:params) { { 'distribution' => 'jdk' } } 36 | 37 | it { is_expected.to contain_package('java').with_name('openjdk-17-jdk') } 38 | it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.17.0-openjdk-amd64/') } 39 | end 40 | 41 | context 'when selecting jre' do 42 | let(:params) { { 'distribution' => 'jre' } } 43 | 44 | it { is_expected.to contain_package('java').with_name('openjdk-17-jre-headless') } 45 | it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.17.0-openjdk-amd64/') } 46 | end 47 | end 48 | 49 | context 'on Ubuntu Bionic (18.04)' do 50 | let(:facts) { { os: { family: 'Debian', name: 'Ubuntu', lsb: { distcodename: 'bionic' }, release: { major: '18.04' }, architecture: 'amd64' } } } 51 | 52 | context 'when selecting jdk' do 53 | let(:params) { { 'distribution' => 'jdk' } } 54 | 55 | it { is_expected.to contain_package('java').with_name('openjdk-11-jdk') } 56 | it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64/') } 57 | end 58 | 59 | context 'when selecting jre' do 60 | let(:params) { { 'distribution' => 'jre' } } 61 | 62 | it { is_expected.to contain_package('java').with_name('openjdk-11-jre-headless') } 63 | it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64/') } 64 | end 65 | end 66 | 67 | context 'on Oracle Linux 7.0' do 68 | let(:facts) { { os: { family: 'RedHat', name: 'OracleLinux', release: { full: '7.0' }, architecture: 'x86_64' } } } 69 | 70 | context 'when selecting openjdk' do 71 | it { is_expected.to contain_package('java').with_name('java-1.7.0-openjdk-devel') } 72 | end 73 | 74 | context 'when selecting passed value for Oracle Linux' do 75 | let(:params) { { 'distribution' => 'jre' } } 76 | 77 | it { is_expected.to contain_package('java').with_name('java-1.7.0-openjdk') } 78 | end 79 | end 80 | 81 | context 'when selecting passed value for Scientific Linux' do 82 | let(:facts) { { os: { family: 'RedHat', name: 'Scientific', release: { full: '7.0' }, architecture: 'x86_64' } } } 83 | let(:params) { { 'distribution' => 'jre' } } 84 | 85 | it { is_expected.to contain_package('java').with_name('java-1.7.0-openjdk') } 86 | it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.7.0/') } 87 | end 88 | 89 | context 'when selecting passed value for Scientific Linux CERN (SLC)' do 90 | let(:facts) { { os: { family: 'RedHat', name: 'SLC', release: { full: '7.0' }, architecture: 'x86_64' } } } 91 | let(:params) { { 'distribution' => 'jre' } } 92 | 93 | it { is_expected.to contain_package('java').with_name('java-1.7.0-openjdk') } 94 | it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib/jvm/java-1.7.0/') } 95 | end 96 | 97 | context 'when selecting default for OpenSUSE 12.3' do 98 | let(:facts) { { os: { family: 'Suse', name: 'OpenSUSE', release: { full: '12.3', major: '12', minor: '3' }, architecture: 'x86_64' } } } 99 | 100 | it { is_expected.to contain_package('java').with_name('java-1_7_0-openjdk-devel') } 101 | it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib64/jvm/java-1.7.0-openjdk-1.7.0/') } 102 | end 103 | 104 | context 'when selecting default for SLES 11.3' do 105 | let(:facts) { { os: { family: 'Suse', name: 'SLES', release: { full: '11.3', major: '11', minor: '3' }, architecture: 'x86_64' } } } 106 | 107 | it { is_expected.to contain_package('java').with_name('java-1_6_0-ibm-devel') } 108 | it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib64/jvm/java-1.6.0-ibm-1.6.0/') } 109 | end 110 | 111 | context 'when selecting default for SLES 11.4' do 112 | let(:facts) { { os: { family: 'Suse', name: 'SLES', release: { full: '11.4', major: '11', minor: '4' }, architecture: 'x86_64' } } } 113 | 114 | it { is_expected.to contain_package('java').with_name('java-1_7_1-ibm-devel') } 115 | it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib64/jvm/java-1.7.1-ibm-1.7.1/') } 116 | end 117 | 118 | context 'when selecting default for SLES 12.0' do 119 | let(:facts) { { os: { family: 'Suse', name: 'SLES', release: { full: '12.0', major: '12' }, architecture: 'x86_64' } } } 120 | 121 | it { is_expected.to contain_package('java').with_name('java-1_7_0-openjdk-devel') } 122 | it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib64/jvm/java-1.7.0-openjdk-1.7.0/') } 123 | end 124 | 125 | context 'when selecting default for SLES 12.1' do 126 | let(:facts) { { os: { family: 'Suse', name: 'SLES', release: { full: '12.1', major: '12' }, architecture: 'x86_64' } } } 127 | 128 | it { is_expected.to contain_package('java').with_name('java-1_8_0-openjdk-devel') } 129 | it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/usr/lib64/jvm/java-1.8.0-openjdk-1.8.0/') } 130 | end 131 | 132 | describe 'custom java package' do 133 | let(:facts) { { os: { family: 'Debian', name: 'Debian', lsb: { distcodename: 'bullseye' }, release: { major: '11' }, architecture: 'amd64' } } } 134 | 135 | context 'when all params provided' do 136 | let(:params) do 137 | { 138 | 'distribution' => 'custom', 139 | 'package' => 'custom_jdk', 140 | 'java_alternative' => 'java-custom_jdk', 141 | 'java_alternative_path' => '/opt/custom_jdk/bin/java', 142 | 'java_home' => '/opt/custom_jdk' 143 | } 144 | end 145 | 146 | it { is_expected.to contain_package('java').with_name('custom_jdk') } 147 | it { is_expected.to contain_file_line('java-home-environment').with_line('JAVA_HOME=/opt/custom_jdk') } 148 | it { is_expected.to contain_exec('update-java-alternatives').with_command(['update-java-alternatives', '--set', 'java-custom_jdk', '--jre']) } 149 | end 150 | 151 | context 'with missing parameters' do 152 | let(:params) do 153 | { 154 | 'distribution' => 'custom', 155 | 'package' => 'custom_jdk' 156 | } 157 | end 158 | 159 | it do 160 | expect { catalogue }.to raise_error Puppet::Error, %r{is not supported. Missing default values} 161 | end 162 | end 163 | end 164 | 165 | describe 'incompatible OSs' do 166 | [ 167 | { 168 | os: { 169 | family: 'windows', 170 | name: 'windows', 171 | release: { full: '8.1' } 172 | } 173 | }, 174 | { 175 | os: { 176 | family: 'Darwin', 177 | name: 'Darwin', 178 | release: { full: '13.3.0' } 179 | } 180 | }, 181 | { 182 | os: { 183 | family: 'AIX', 184 | name: 'AIX', 185 | release: { full: '7100-02-00-000' } 186 | } 187 | }, 188 | { 189 | os: { 190 | family: 'AIX', 191 | name: 'AIX', 192 | release: { full: '6100-07-04-1216' } 193 | } 194 | }, 195 | { 196 | os: { 197 | family: 'AIX', 198 | name: 'AIX', 199 | release: { full: '5300-12-01-1016' } 200 | } 201 | }, 202 | ].each do |facts| 203 | let(:facts) { facts } 204 | 205 | it "is_expected.to fail on #{facts[:os][:name]} #{facts[:os][:release][:full]}" do 206 | expect { catalogue }.to raise_error Puppet::Error, %r{unsupported platform} 207 | end 208 | end 209 | end 210 | end 211 | -------------------------------------------------------------------------------- /spec/default_facts.yml: -------------------------------------------------------------------------------- 1 | # Use default_module_facts.yml for module specific facts. 2 | # 3 | # Facts specified here will override the values provided by rspec-puppet-facts. 4 | --- 5 | networking: 6 | ip: "172.16.254.254" 7 | ip6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA" 8 | mac: "AA:AA:AA:AA:AA:AA" 9 | is_pe: false 10 | -------------------------------------------------------------------------------- /spec/defines/adopt_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | describe 'java::adopt', type: :define do 6 | context 'with CentOS 64-bit' do 7 | let(:facts) { { kernel: 'Linux', os: { family: 'RedHat', architecture: 'x86_64', name: 'CentOS', release: { full: '7.0' } } } } 8 | 9 | context 'when manage_symlink is set to true' do 10 | let(:params) do 11 | { 12 | ensure: 'present', 13 | version: '11', 14 | java: 'jdk', 15 | basedir: '/usr/java', 16 | manage_symlink: true, 17 | symlink_name: 'java_home' 18 | } 19 | end 20 | let(:title) { 'jdk11_symlink' } 21 | 22 | it { is_expected.to contain_file('/usr/java/java_home') } 23 | end 24 | 25 | context 'when manage_symlink is not set' do 26 | let(:params) { { ensure: 'present', version: '11', java: 'jdk' } } 27 | let(:title) { 'jdk11_nosymlink' } 28 | 29 | it { is_expected.not_to contain_file('/usr/java/java_home') } 30 | end 31 | 32 | context 'when AdoptOpenJDK Java 8 JDK' do 33 | let(:params) { { ensure: 'present', version: '8', java: 'jdk' } } 34 | let(:title) { 'jdk8' } 35 | 36 | it { is_expected.to contain_archive('/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz') } 37 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 8 8u202 b08').with_command(['tar', '-zxf', '/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz', '-C', '/usr/java']) } 38 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 8 8u202 b08').that_requires('Archive[/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz]') } 39 | end 40 | 41 | context 'when AdoptOpenJDK Java 9 JDK' do 42 | let(:params) { { ensure: 'present', version: '9', java: 'jdk' } } 43 | let(:title) { 'jdk9' } 44 | 45 | it { is_expected.to contain_archive('/tmp/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz') } 46 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 9 9.0.4 11').with_command(['tar', '-zxf', '/tmp/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz', '-C', '/usr/java']) } 47 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 9 9.0.4 11').that_requires('Archive[/tmp/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz]') } 48 | end 49 | 50 | context 'when AdoptOpenJDK Java 10 JDK' do 51 | let(:params) { { ensure: 'present', version: '10', java: 'jdk' } } 52 | let(:title) { 'jdk10' } 53 | 54 | it { is_expected.to contain_archive('/tmp/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz') } 55 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 10 10.0.2 13').with_command(['tar', '-zxf', '/tmp/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz', '-C', '/usr/java']) } 56 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 10 10.0.2 13').that_requires('Archive[/tmp/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz]') } 57 | end 58 | 59 | context 'when AdoptOpenJDK Java 11 JDK' do 60 | let(:params) { { ensure: 'present', version: '11', java: 'jdk' } } 61 | let(:title) { 'jdk11' } 62 | 63 | it { is_expected.to contain_archive('/tmp/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz') } 64 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 11 11.0.2 9').with_command(['tar', '-zxf', '/tmp/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz', '-C', '/usr/java']) } 65 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 11 11.0.2 9').that_requires('Archive[/tmp/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz]') } 66 | end 67 | 68 | context 'when AdoptOpenJDK Java 12 JDK' do 69 | let(:params) { { ensure: 'present', version: '12', java: 'jdk' } } 70 | let(:title) { 'jdk12' } 71 | 72 | it { is_expected.to contain_archive('/tmp/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz') } 73 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 12 12.0.1 12').with_command(['tar', '-zxf', '/tmp/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz', '-C', '/usr/java']) } 74 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 12 12.0.1 12').that_requires('Archive[/tmp/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz]') } 75 | end 76 | 77 | context 'when AdoptOpenJDK Java 8 JRE' do 78 | let(:params) { { ensure: 'present', version: '8', java: 'jre' } } 79 | let(:title) { 'jre8' } 80 | 81 | it { is_expected.to contain_archive('/tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz') } 82 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 8 8u202 b08').with_command(['tar', '-zxf', '/tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz', '-C', '/usr/java']) } 83 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 8 8u202 b08').that_requires('Archive[/tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz]') } 84 | end 85 | 86 | context 'when AdoptOpenJDK Java 9 JRE' do 87 | let(:params) { { ensure: 'present', version: '9', java: 'jre' } } 88 | let(:title) { 'jre9' } 89 | 90 | it { is_expected.to contain_archive('/tmp/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz') } 91 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 9 9.0.4 11').with_command(['tar', '-zxf', '/tmp/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz', '-C', '/usr/java']) } 92 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 9 9.0.4 11').that_requires('Archive[/tmp/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz]') } 93 | end 94 | 95 | context 'when AdoptOpenJDK Java 10 JRE' do 96 | let(:params) { { ensure: 'present', version: '10', java: 'jre' } } 97 | let(:title) { 'jre11' } 98 | 99 | it { is_expected.to contain_archive('/tmp/OpenJDK10U-jre_x64_linux_hotspot_10.0.2_13.tar.gz') } 100 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 10 10.0.2 13').with_command(['tar', '-zxf', '/tmp/OpenJDK10U-jre_x64_linux_hotspot_10.0.2_13.tar.gz', '-C', '/usr/java']) } 101 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 10 10.0.2 13').that_requires('Archive[/tmp/OpenJDK10U-jre_x64_linux_hotspot_10.0.2_13.tar.gz]') } 102 | end 103 | 104 | context 'when AdoptOpenJDK Java 11 JRE' do 105 | let(:params) { { ensure: 'present', version: '11', java: 'jre' } } 106 | let(:title) { 'jre11' } 107 | 108 | it { is_expected.to contain_archive('/tmp/OpenJDK11U-jre_x64_linux_hotspot_11.0.2_9.tar.gz') } 109 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 11 11.0.2 9').with_command(['tar', '-zxf', '/tmp/OpenJDK11U-jre_x64_linux_hotspot_11.0.2_9.tar.gz', '-C', '/usr/java']) } 110 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 11 11.0.2 9').that_requires('Archive[/tmp/OpenJDK11U-jre_x64_linux_hotspot_11.0.2_9.tar.gz]') } 111 | end 112 | 113 | context 'when AdoptOpenJDK Java 12 JRE' do 114 | let(:params) { { ensure: 'present', version: '12', java: 'jre' } } 115 | let(:title) { 'jre12' } 116 | 117 | it { is_expected.to contain_archive('/tmp/OpenJDK12U-jre_x64_linux_hotspot_12.0.1_12.tar.gz') } 118 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 12 12.0.1 12').with_command(['tar', '-zxf', '/tmp/OpenJDK12U-jre_x64_linux_hotspot_12.0.1_12.tar.gz', '-C', '/usr/java']) } 119 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 12 12.0.1 12').that_requires('Archive[/tmp/OpenJDK12U-jre_x64_linux_hotspot_12.0.1_12.tar.gz]') } 120 | end 121 | 122 | context 'when installing multiple versions' do 123 | let(:params) do 124 | { 125 | ensure: 'present', 126 | version_major: '8u202', 127 | version_minor: 'b08', 128 | java: 'jdk' 129 | } 130 | end 131 | let(:title) { 'jdk8' } 132 | 133 | let(:pre_condition) do 134 | <<-MANIFEST 135 | java::adopt { 136 | 'jdk8172': 137 | ensure => 'present', 138 | version_major => '8u172', 139 | version_minor => 'b11', 140 | java => 'jdk', 141 | } 142 | MANIFEST 143 | end 144 | 145 | it { is_expected.to compile } 146 | end 147 | 148 | context 'when specifying package_type tar.gz and basedir' do 149 | let(:params) do 150 | { 151 | ensure: 'present', 152 | version: '8', 153 | java: 'jdk', 154 | basedir: '/usr/java', 155 | package_type: 'tar.gz' 156 | } 157 | end 158 | let(:title) { 'jdk8' } 159 | 160 | it { is_expected.to contain_archive('/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz') } 161 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 8 8u202 b08').with_command(['tar', '-zxf', '/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz', '-C', '/usr/java']) } 162 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 8 8u202 b08').that_requires('Archive[/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz]') } 163 | end 164 | 165 | context 'when manage_basedir is set to true' do 166 | let(:params) do 167 | { 168 | ensure: 'present', 169 | version: '8', 170 | java: 'jdk', 171 | basedir: '/usr/java', 172 | manage_basedir: true 173 | } 174 | end 175 | let(:title) { 'jdk8' } 176 | 177 | it { is_expected.to contain_file('/usr/java') } 178 | end 179 | end 180 | 181 | context 'with Ubuntu 64-bit' do 182 | let(:facts) { { kernel: 'Linux', os: { family: 'Debian', architecture: 'amd64', name: 'Ubuntu', release: { full: '18.04' } } } } 183 | 184 | context 'when AdoptOpenJDK Java 8 JDK' do 185 | let(:params) { { ensure: 'present', version: '8', java: 'jdk' } } 186 | let(:title) { 'jdk8' } 187 | 188 | it { is_expected.to contain_archive('/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz') } 189 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 8 8u202 b08').with_command(['tar', '-zxf', '/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz', '-C', '/usr/lib/jvm']) } 190 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 8 8u202 b08').that_requires('Archive[/tmp/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz]') } 191 | end 192 | 193 | context 'when AdoptOpenJDK Java 9 JDK' do 194 | let(:params) { { ensure: 'present', version: '9', java: 'jdk' } } 195 | let(:title) { 'jdk9' } 196 | 197 | it { is_expected.to contain_archive('/tmp/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz') } 198 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 9 9.0.4 11').with_command(['tar', '-zxf', '/tmp/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz', '-C', '/usr/lib/jvm']) } 199 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 9 9.0.4 11').that_requires('Archive[/tmp/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz]') } 200 | end 201 | 202 | context 'when AdoptOpenJDK Java 10 JDK' do 203 | let(:params) { { ensure: 'present', version: '10', java: 'jdk' } } 204 | let(:title) { 'jdk10' } 205 | 206 | it { is_expected.to contain_archive('/tmp/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz') } 207 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 10 10.0.2 13').with_command(['tar', '-zxf', '/tmp/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz', '-C', '/usr/lib/jvm']) } 208 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 10 10.0.2 13').that_requires('Archive[/tmp/OpenJDK10U-jdk_x64_linux_hotspot_10.0.2_13.tar.gz]') } 209 | end 210 | 211 | context 'when AdoptOpenJDK Java 11 JDK' do 212 | let(:params) { { ensure: 'present', version: '11', java: 'jdk' } } 213 | let(:title) { 'jdk11' } 214 | 215 | it { is_expected.to contain_archive('/tmp/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz') } 216 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 11 11.0.2 9').with_command(['tar', '-zxf', '/tmp/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz', '-C', '/usr/lib/jvm']) } 217 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 11 11.0.2 9').that_requires('Archive[/tmp/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_9.tar.gz]') } 218 | end 219 | 220 | context 'when AdoptOpenJDK Java 12 JDK' do 221 | let(:params) { { ensure: 'present', version: '12', java: 'jdk' } } 222 | let(:title) { 'jdk12' } 223 | 224 | it { is_expected.to contain_archive('/tmp/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz') } 225 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 12 12.0.1 12').with_command(['tar', '-zxf', '/tmp/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz', '-C', '/usr/lib/jvm']) } 226 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jdk 12 12.0.1 12').that_requires('Archive[/tmp/OpenJDK12U-jdk_x64_linux_hotspot_12.0.1_12.tar.gz]') } 227 | end 228 | 229 | context 'when AdoptOpenJDK Java 8 JRE' do 230 | let(:params) { { ensure: 'present', version: '8', java: 'jre' } } 231 | let(:title) { 'jre8' } 232 | 233 | it { is_expected.to contain_archive('/tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz') } 234 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 8 8u202 b08').with_command(['tar', '-zxf', '/tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz', '-C', '/usr/lib/jvm']) } 235 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 8 8u202 b08').that_requires('Archive[/tmp/OpenJDK8U-jre_x64_linux_hotspot_8u202b08.tar.gz]') } 236 | end 237 | 238 | context 'when AdoptOpenJDK Java 9 JRE' do 239 | let(:params) { { ensure: 'present', version: '9', java: 'jre' } } 240 | let(:title) { 'jre9' } 241 | 242 | it { is_expected.to contain_archive('/tmp/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz') } 243 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 9 9.0.4 11').with_command(['tar', '-zxf', '/tmp/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz', '-C', '/usr/lib/jvm']) } 244 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 9 9.0.4 11').that_requires('Archive[/tmp/OpenJDK9U-jre_x64_linux_hotspot_9.0.4_11.tar.gz]') } 245 | end 246 | 247 | context 'when AdoptOpenJDK Java 10 JRE' do 248 | let(:params) { { ensure: 'present', version: '10', java: 'jre' } } 249 | let(:title) { 'jre11' } 250 | 251 | it { is_expected.to contain_archive('/tmp/OpenJDK10U-jre_x64_linux_hotspot_10.0.2_13.tar.gz') } 252 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 10 10.0.2 13').with_command(['tar', '-zxf', '/tmp/OpenJDK10U-jre_x64_linux_hotspot_10.0.2_13.tar.gz', '-C', '/usr/lib/jvm']) } 253 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 10 10.0.2 13').that_requires('Archive[/tmp/OpenJDK10U-jre_x64_linux_hotspot_10.0.2_13.tar.gz]') } 254 | end 255 | 256 | context 'when AdoptOpenJDK Java 11 JRE' do 257 | let(:params) { { ensure: 'present', version: '11', java: 'jre' } } 258 | let(:title) { 'jre11' } 259 | 260 | it { is_expected.to contain_archive('/tmp/OpenJDK11U-jre_x64_linux_hotspot_11.0.2_9.tar.gz') } 261 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 11 11.0.2 9').with_command(['tar', '-zxf', '/tmp/OpenJDK11U-jre_x64_linux_hotspot_11.0.2_9.tar.gz', '-C', '/usr/lib/jvm']) } 262 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 11 11.0.2 9').that_requires('Archive[/tmp/OpenJDK11U-jre_x64_linux_hotspot_11.0.2_9.tar.gz]') } 263 | end 264 | 265 | context 'when AdoptOpenJDK Java 12 JRE' do 266 | let(:params) { { ensure: 'present', version: '12', java: 'jre' } } 267 | let(:title) { 'jre12' } 268 | 269 | it { is_expected.to contain_archive('/tmp/OpenJDK12U-jre_x64_linux_hotspot_12.0.1_12.tar.gz') } 270 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 12 12.0.1 12').with_command(['tar', '-zxf', '/tmp/OpenJDK12U-jre_x64_linux_hotspot_12.0.1_12.tar.gz', '-C', '/usr/lib/jvm']) } 271 | it { is_expected.to contain_exec('Install AdoptOpenJDK java jre 12 12.0.1 12').that_requires('Archive[/tmp/OpenJDK12U-jre_x64_linux_hotspot_12.0.1_12.tar.gz]') } 272 | end 273 | 274 | context 'when installing multiple versions' do 275 | let(:params) do 276 | { 277 | ensure: 'present', 278 | version_major: '8u202', 279 | version_minor: 'b08', 280 | java: 'jdk' 281 | } 282 | end 283 | let(:title) { 'jdk8' } 284 | 285 | let(:pre_condition) do 286 | <<-MANIFEST 287 | java::adopt { 288 | 'jdk8172': 289 | ensure => 'present', 290 | version_major => '8u172', 291 | version_minor => 'b11', 292 | java => 'jdk', 293 | } 294 | MANIFEST 295 | end 296 | 297 | it { is_expected.to compile } 298 | end 299 | end 300 | 301 | describe 'incompatible OSes' do 302 | [ 303 | { 304 | kernel: 'Windows', 305 | os: { 306 | family: 'Windows', 307 | name: 'Windows', 308 | release: { 309 | full: '8.1' 310 | } 311 | } 312 | }, 313 | { 314 | kernel: 'Darwin', 315 | os: { 316 | family: 'Darwin', 317 | name: 'Darwin', 318 | release: { 319 | full: '13.3.0' 320 | } 321 | } 322 | }, 323 | { 324 | kernel: 'AIX', 325 | os: { 326 | family: 'AIX', 327 | name: 'AIX', 328 | release: { 329 | full: '7100-02-00-000' 330 | } 331 | } 332 | }, 333 | { 334 | kernel: 'AIX', 335 | os: { 336 | family: 'AIX', 337 | name: 'AIX', 338 | release: { 339 | full: '6100-07-04-1216' 340 | } 341 | } 342 | }, 343 | { 344 | kernel: 'AIX', 345 | os: { 346 | family: 'AIX', 347 | name: 'AIX', 348 | release: { 349 | full: '5300-12-01-1016' 350 | } 351 | } 352 | }, 353 | ].each do |facts| 354 | let(:facts) { facts } 355 | let(:title) { 'jdk' } 356 | 357 | it "is_expected.to fail on #{facts[:os][:name]} #{facts[:os][:release][:full]}" do 358 | expect { catalogue }.to raise_error Puppet::Error, %r{unsupported platform} 359 | end 360 | end 361 | end 362 | end 363 | -------------------------------------------------------------------------------- /spec/defines/adoptium_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | describe 'java::adoptium', type: :define do 6 | context 'with CentOS 64-bit' do 7 | let(:facts) { { kernel: 'Linux', os: { family: 'RedHat', architecture: 'x86_64', name: 'CentOS', release: { full: '7.0' } } } } 8 | 9 | context 'when manage_symlink is set to true' do 10 | let(:params) do 11 | { 12 | ensure: 'present', 13 | version_major: '16', 14 | version_minor: '0', 15 | version_patch: '2', 16 | version_build: '7', 17 | basedir: '/usr/java', 18 | manage_symlink: true, 19 | symlink_name: 'java_home' 20 | } 21 | end 22 | let(:title) { 'jdk16_symlink' } 23 | 24 | it { is_expected.to contain_file('/usr/java/java_home') } 25 | end 26 | 27 | context 'when manage_symlink is not set' do 28 | let(:params) do 29 | { 30 | ensure: 'present', 31 | version_major: '16', 32 | version_minor: '0', 33 | version_patch: '2', 34 | version_build: '7', 35 | basedir: '/usr/java', 36 | symlink_name: 'java_home' 37 | } 38 | end 39 | let(:title) { 'jdk16_nosymlink' } 40 | 41 | it { is_expected.not_to contain_file('/usr/java/java_home') } 42 | end 43 | 44 | context 'when Adoptium Temurin Java 16 JDK' do 45 | let(:params) do 46 | { 47 | ensure: 'present', 48 | version_major: '16', 49 | version_minor: '0', 50 | version_patch: '2', 51 | version_build: '7', 52 | basedir: '/usr/java', 53 | symlink_name: 'java_home' 54 | } 55 | end 56 | let(:title) { 'jdk16' } 57 | 58 | it { is_expected.to contain_archive('/tmp/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz') } 59 | it { is_expected.to contain_exec('Install Adoptium Temurin java 16 0 2 7').with_command(['tar', '-zxf', '/tmp/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz', '-C', '/usr/java']) } 60 | it { is_expected.to contain_exec('Install Adoptium Temurin java 16 0 2 7').that_requires('Archive[/tmp/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz]') } 61 | end 62 | 63 | context 'when Adoptium Temurin Java 17 JDK' do 64 | let(:params) do 65 | { 66 | ensure: 'present', 67 | version_major: '17', 68 | version_minor: '0', 69 | version_patch: '1', 70 | version_build: '12', 71 | basedir: '/usr/java', 72 | symlink_name: 'java_home' 73 | } 74 | end 75 | let(:title) { 'jdk17' } 76 | 77 | it { is_expected.to contain_archive('/tmp/OpenJDK17U-jdk_x64_linux_hotspot_17.0.1_12.tar.gz') } 78 | it { is_expected.to contain_exec('Install Adoptium Temurin java 17 0 1 12').with_command(['tar', '-zxf', '/tmp/OpenJDK17U-jdk_x64_linux_hotspot_17.0.1_12.tar.gz', '-C', '/usr/java']) } 79 | it { is_expected.to contain_exec('Install Adoptium Temurin java 17 0 1 12').that_requires('Archive[/tmp/OpenJDK17U-jdk_x64_linux_hotspot_17.0.1_12.tar.gz]') } 80 | end 81 | 82 | context 'when installing multiple versions' do 83 | let(:params) do 84 | { 85 | ensure: 'present', 86 | version_major: '16', 87 | version_minor: '0', 88 | version_patch: '2', 89 | version_build: '7' 90 | } 91 | end 92 | let(:title) { 'jdk16' } 93 | 94 | let(:pre_condition) do 95 | <<-MANIFEST 96 | java::adoptium { 97 | 'jdk17': 98 | ensure => 'present', 99 | version_major => '17', 100 | version_minor => '0', 101 | version_patch => '1', 102 | version_build => '12', 103 | } 104 | MANIFEST 105 | end 106 | 107 | it { is_expected.to compile } 108 | end 109 | 110 | context 'when specifying package_type tar.gz and basedir' do 111 | let(:params) do 112 | { 113 | ensure: 'present', 114 | version_major: '16', 115 | version_minor: '0', 116 | version_patch: '2', 117 | version_build: '7', 118 | basedir: '/usr/java' 119 | } 120 | end 121 | let(:title) { 'jdk16' } 122 | 123 | it { is_expected.to contain_archive('/tmp/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz') } 124 | it { is_expected.to contain_exec('Install Adoptium Temurin java 16 0 2 7').with_command(['tar', '-zxf', '/tmp/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz', '-C', '/usr/java']) } 125 | it { is_expected.to contain_exec('Install Adoptium Temurin java 16 0 2 7').that_requires('Archive[/tmp/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz]') } 126 | end 127 | 128 | context 'when manage_basedir is set to true' do 129 | let(:params) do 130 | { 131 | ensure: 'present', 132 | version_major: '16', 133 | version_minor: '0', 134 | version_patch: '2', 135 | version_build: '7', 136 | basedir: '/usr/java', 137 | manage_basedir: true 138 | } 139 | end 140 | let(:title) { 'jdk16' } 141 | 142 | it { is_expected.to contain_file('/usr/java') } 143 | end 144 | end 145 | 146 | context 'with Ubuntu 64-bit' do 147 | let(:facts) { { kernel: 'Linux', os: { family: 'Debian', architecture: 'amd64', name: 'Ubuntu', release: { full: '18.04' } } } } 148 | 149 | context 'when Adoptium Temurin Java 16 JDK' do 150 | let(:params) do 151 | { 152 | ensure: 'present', 153 | version_major: '16', 154 | version_minor: '0', 155 | version_patch: '2', 156 | version_build: '7', 157 | symlink_name: 'java_home' 158 | } 159 | end 160 | let(:title) { 'jdk16' } 161 | 162 | it { is_expected.to contain_archive('/tmp/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz') } 163 | it { is_expected.to contain_exec('Install Adoptium Temurin java 16 0 2 7').with_command(['tar', '-zxf', '/tmp/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz', '-C', '/usr/lib/jvm']) } 164 | it { is_expected.to contain_exec('Install Adoptium Temurin java 16 0 2 7').that_requires('Archive[/tmp/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz]') } 165 | end 166 | 167 | context 'when Adoptium Temurin Java 17 JDK' do 168 | let(:params) do 169 | { 170 | ensure: 'present', 171 | version_major: '17', 172 | version_minor: '0', 173 | version_patch: '1', 174 | version_build: '12', 175 | symlink_name: 'java_home' 176 | } 177 | end 178 | let(:title) { 'jdk17' } 179 | 180 | it { is_expected.to contain_archive('/tmp/OpenJDK17U-jdk_x64_linux_hotspot_17.0.1_12.tar.gz') } 181 | it { is_expected.to contain_exec('Install Adoptium Temurin java 17 0 1 12').with_command(['tar', '-zxf', '/tmp/OpenJDK17U-jdk_x64_linux_hotspot_17.0.1_12.tar.gz', '-C', '/usr/lib/jvm']) } 182 | it { is_expected.to contain_exec('Install Adoptium Temurin java 17 0 1 12').that_requires('Archive[/tmp/OpenJDK17U-jdk_x64_linux_hotspot_17.0.1_12.tar.gz]') } 183 | end 184 | 185 | context 'when installing multiple versions' do 186 | let(:params) do 187 | { 188 | ensure: 'present', 189 | version_major: '16', 190 | version_minor: '0', 191 | version_patch: '2', 192 | version_build: '7' 193 | } 194 | end 195 | let(:title) { 'jdk16' } 196 | 197 | let(:pre_condition) do 198 | <<-MANIFEST 199 | java::adoptium { 200 | 'jdk17': 201 | ensure => 'present', 202 | version_major => '17', 203 | version_minor => '0', 204 | version_patch => '1', 205 | version_build => '12', 206 | } 207 | MANIFEST 208 | end 209 | 210 | it { is_expected.to compile } 211 | end 212 | 213 | context 'when specifying package_type tar.gz and basedir' do 214 | let(:params) do 215 | { 216 | ensure: 'present', 217 | version_major: '16', 218 | version_minor: '0', 219 | version_patch: '2', 220 | version_build: '7', 221 | basedir: '/usr/lib/jvm' 222 | } 223 | end 224 | let(:title) { 'jdk16' } 225 | 226 | it { is_expected.to contain_archive('/tmp/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz') } 227 | it { is_expected.to contain_exec('Install Adoptium Temurin java 16 0 2 7').with_command(['tar', '-zxf', '/tmp/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz', '-C', '/usr/lib/jvm']) } 228 | it { is_expected.to contain_exec('Install Adoptium Temurin java 16 0 2 7').that_requires('Archive[/tmp/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz]') } 229 | end 230 | 231 | context 'when manage_basedir is set to true' do 232 | let(:params) do 233 | { 234 | ensure: 'present', 235 | version_major: '16', 236 | version_minor: '0', 237 | version_patch: '2', 238 | version_build: '7', 239 | basedir: '/usr/lib/jvm', 240 | manage_basedir: true 241 | } 242 | end 243 | let(:title) { 'jdk16' } 244 | 245 | it { is_expected.to contain_file('/usr/lib/jvm') } 246 | end 247 | end 248 | 249 | describe 'incompatible OSes' do 250 | [ 251 | { 252 | kernel: 'Windows', 253 | os: { 254 | family: 'Windows', 255 | name: 'Windows', 256 | release: { 257 | full: '8.1' 258 | } 259 | } 260 | }, 261 | { 262 | kernel: 'Darwin', 263 | os: { 264 | family: 'Darwin', 265 | name: 'Darwin', 266 | release: { 267 | full: '13.3.0' 268 | } 269 | } 270 | }, 271 | { 272 | kernel: 'AIX', 273 | os: { 274 | family: 'AIX', 275 | name: 'AIX', 276 | release: { 277 | full: '7100-02-00-000' 278 | } 279 | } 280 | }, 281 | { 282 | kernel: 'AIX', 283 | os: { 284 | family: 'AIX', 285 | name: 'AIX', 286 | release: { 287 | full: '6100-07-04-1216' 288 | } 289 | } 290 | }, 291 | { 292 | kernel: 'AIX', 293 | os: { 294 | family: 'AIX', 295 | name: 'AIX', 296 | release: { 297 | full: '5300-12-01-1016' 298 | } 299 | } 300 | }, 301 | ].each do |facts| 302 | let(:facts) { facts } 303 | let(:title) { 'jdk' } 304 | 305 | it "is_expected.to fail on #{facts[:os][:name]} #{facts[:os][:release][:full]}" do 306 | expect { catalogue }.to raise_error Puppet::Error, %r{unsupported platform} 307 | end 308 | end 309 | end 310 | end 311 | -------------------------------------------------------------------------------- /spec/defines/download_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | describe 'java::download', type: :define do 6 | let(:url) { 'http://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz' } 7 | 8 | context 'with CentOS 64-bit' do 9 | let(:facts) { { kernel: 'Linux', os: { family: 'RedHat', architecture: 'x86_64', name: 'CentOS', release: { full: '7.0' } } } } 10 | 11 | context 'when passing URL to url parameter' do 12 | let(:params) do 13 | { 14 | ensure: 'present', 15 | version_major: '8u201', 16 | version_minor: 'b09', 17 | java_se: 'jdk', 18 | url: url 19 | } 20 | end 21 | let(:title) { 'jdk8' } 22 | 23 | it { 24 | expect(subject).to contain_archive('/tmp/jdk-8-8u201-b09-linux-x64.rpm') 25 | } 26 | end 27 | 28 | context 'when no url provided' do 29 | let(:params) do 30 | { 31 | ensure: 'present', 32 | version_major: '8u201', 33 | version_minor: 'b09', 34 | java_se: 'jdk' 35 | } 36 | end 37 | let(:title) { 'jdk8' } 38 | 39 | it { 40 | expect(subject).to raise_error Puppet::Error 41 | } 42 | end 43 | 44 | context 'when manage_symlink is set to true' do 45 | let(:params) do 46 | { 47 | ensure: 'present', 48 | version: '6', 49 | java_se: 'jdk', 50 | basedir: '/usr/java', 51 | manage_symlink: true, 52 | symlink_name: 'java_home', 53 | url: url 54 | } 55 | end 56 | let(:title) { 'jdk6' } 57 | 58 | it { is_expected.to contain_file('/usr/java/java_home') } 59 | end 60 | 61 | context 'when manage_symlink is not set' do 62 | let(:params) do 63 | { 64 | ensure: 'present', 65 | version: '6', 66 | java_se: 'jdk', 67 | basedir: '/usr/java', 68 | url: url 69 | } 70 | end 71 | let(:title) { 'jdk6_nosymlink' } 72 | 73 | it { is_expected.not_to contain_file('/usr/java/java_home') } 74 | end 75 | end 76 | 77 | context 'with Ubuntu 64-bit' do 78 | let(:facts) { { kernel: 'Linux', os: { family: 'Debian', architecture: 'amd64', name: 'Ubuntu', release: { full: '18.04' } } } } 79 | 80 | context 'when passing URL to url parameter' do 81 | let(:params) { { ensure: 'present', version_major: '8u201', version_minor: 'b09', java_se: 'jdk', url: url } } 82 | let(:title) { 'jdk8' } 83 | 84 | it { is_expected.to contain_archive('/tmp/jdk-8-8u201-b09-linux-x64.tar.gz') } 85 | end 86 | end 87 | 88 | context 'with Debian 64-bit' do 89 | let(:facts) { { kernel: 'Linux', os: { family: 'Debian', architecture: 'amd64', name: 'Debian', release: { full: '10.0' } } } } 90 | 91 | context 'when passing URL to url parameter' do 92 | let(:params) { { ensure: 'present', version_major: '8u201', version_minor: 'b09', java_se: 'jdk', url: url } } 93 | let(:title) { 'jdk8' } 94 | 95 | it { is_expected.to contain_archive('/tmp/jdk-8-8u201-b09-linux-x64.tar.gz') } 96 | end 97 | end 98 | 99 | describe 'incompatible OSes' do 100 | [ 101 | { 102 | kernel: 'Windows', 103 | os: { 104 | family: 'Windows', 105 | name: 'Windows', 106 | release: { 107 | full: '8.1' 108 | } 109 | } 110 | }, 111 | { 112 | kernel: 'Darwin', 113 | os: { 114 | family: 'Darwin', 115 | name: 'Darwin', 116 | release: { 117 | full: '13.3.0' 118 | } 119 | } 120 | }, 121 | { 122 | kernel: 'AIX', 123 | os: { 124 | family: 'AIX', 125 | name: 'AIX', 126 | release: { 127 | full: '7100-02-00-000' 128 | } 129 | } 130 | }, 131 | { 132 | kernel: 'AIX', 133 | os: { 134 | family: 'AIX', 135 | name: 'AIX', 136 | release: { 137 | full: '6100-07-04-1216' 138 | } 139 | } 140 | }, 141 | { 142 | kernel: 'AIX', 143 | os: { 144 | family: 'AIX', 145 | name: 'AIX', 146 | release: { 147 | full: '5300-12-01-1016' 148 | } 149 | } 150 | }, 151 | ].each do |facts| 152 | let(:facts) { facts } 153 | let(:title) { 'jdk' } 154 | 155 | it "is_expected.to fail on #{facts[:os][:name]} #{facts[:os][:release][:full]}" do 156 | expect { catalogue }.to raise_error Puppet::Error, %r{unsupported platform} 157 | end 158 | end 159 | end 160 | end 161 | -------------------------------------------------------------------------------- /spec/defines/sap_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | describe 'java::sap', type: :define do 6 | context 'with CentOS 64-bit' do 7 | let(:facts) { { kernel: 'Linux', os: { family: 'RedHat', architecture: 'x86_64', name: 'CentOS', release: { full: '7.0' } } } } 8 | 9 | context 'when manage_symlink is set to true' do 10 | let(:params) do 11 | { 12 | ensure: 'present', 13 | version: '11', 14 | java: 'jdk', 15 | basedir: '/usr/java', 16 | manage_symlink: true, 17 | symlink_name: 'java_home' 18 | } 19 | end 20 | let(:title) { 'jdk11_symlink' } 21 | 22 | it { is_expected.to contain_file('/usr/java/java_home') } 23 | end 24 | 25 | context 'when manage_symlink is not set' do 26 | let(:params) { { ensure: 'present', version: '11', java: 'jdk' } } 27 | let(:title) { 'jdk11_nosymlink' } 28 | 29 | it { is_expected.not_to contain_file('/usr/java/java_home') } 30 | end 31 | 32 | context 'when sapjvm 7' do 33 | let(:params) { { ensure: 'present', version: '7', java: 'jdk' } } 34 | let(:title) { 'jdk7' } 35 | 36 | it { is_expected.to contain_archive('/tmp/sapjvm-7.1.072-linux-x64.zip') } 37 | end 38 | 39 | context 'when sapjvm 8' do 40 | let(:params) { { ensure: 'present', version: '8', java: 'jdk' } } 41 | let(:title) { 'jdk8' } 42 | 43 | it { is_expected.to contain_archive('/tmp/sapjvm-8.1.065-linux-x64.zip') } 44 | end 45 | 46 | context 'when sapmachine 11 jdk' do 47 | let(:params) { { ensure: 'present', version: '11', java: 'jdk' } } 48 | let(:title) { 'jdk11' } 49 | 50 | it { is_expected.to contain_archive('/tmp/sapmachine-jdk-11.0.7_linux-x64_bin.tar.gz') } 51 | end 52 | 53 | context 'when sapmachine 11 jre' do 54 | let(:params) { { ensure: 'present', version: '11', java: 'jre' } } 55 | let(:title) { 'jre11' } 56 | 57 | it { is_expected.to contain_archive('/tmp/sapmachine-jre-11.0.7_linux-x64_bin.tar.gz') } 58 | end 59 | 60 | context 'when sapmachine 14 jdk' do 61 | let(:params) { { ensure: 'present', version: '14', java: 'jdk' } } 62 | let(:title) { 'jdk14' } 63 | 64 | it { is_expected.to contain_archive('/tmp/sapmachine-jdk-14.0.1_linux-x64_bin.tar.gz') } 65 | end 66 | 67 | context 'when sapmachine 14 jre' do 68 | let(:params) { { ensure: 'present', version: '14', java: 'jre' } } 69 | let(:title) { 'jre14' } 70 | 71 | it { is_expected.to contain_archive('/tmp/sapmachine-jre-14.0.1_linux-x64_bin.tar.gz') } 72 | end 73 | 74 | context 'when installing multiple versions' do 75 | let(:params) do 76 | { 77 | ensure: 'present', 78 | version_full: '11.0.7', 79 | java: 'jdk' 80 | } 81 | end 82 | let(:title) { 'jdk1107' } 83 | 84 | let(:pre_condition) do 85 | <<-MANIFEST 86 | java::sap { 87 | 'jdk1106': 88 | ensure => 'present', 89 | version_full => '11.0.6', 90 | java => 'jdk', 91 | } 92 | MANIFEST 93 | end 94 | 95 | it { is_expected.to compile } 96 | end 97 | 98 | context 'when specifying basedir' do 99 | let(:params) do 100 | { 101 | ensure: 'present', 102 | version: '8', 103 | java: 'jdk', 104 | basedir: '/usr/java' 105 | } 106 | end 107 | let(:title) { 'jdk8' } 108 | 109 | it { is_expected.to contain_archive('/tmp/sapjvm-8.1.065-linux-x64.zip') } 110 | end 111 | 112 | context 'when manage_basedir is set to true' do 113 | let(:params) do 114 | { 115 | ensure: 'present', 116 | version: '8', 117 | java: 'jdk', 118 | basedir: '/usr/java', 119 | manage_basedir: true 120 | } 121 | end 122 | let(:title) { 'jdk8' } 123 | 124 | it { is_expected.to contain_file('/usr/java') } 125 | end 126 | end 127 | 128 | context 'with Ubuntu 64-bit' do 129 | let(:facts) { { kernel: 'Linux', os: { family: 'Debian', architecture: 'amd64', name: 'Ubuntu', release: { full: '18.04' } } } } 130 | 131 | context 'when sapjvm 7' do 132 | let(:params) { { ensure: 'present', version: '7', java: 'jdk' } } 133 | let(:title) { 'jdk7' } 134 | 135 | it { is_expected.to contain_archive('/tmp/sapjvm-7.1.072-linux-x64.zip') } 136 | end 137 | 138 | context 'when sapjvm 8' do 139 | let(:params) { { ensure: 'present', version: '8', java: 'jdk' } } 140 | let(:title) { 'jdk8' } 141 | 142 | it { is_expected.to contain_archive('/tmp/sapjvm-8.1.065-linux-x64.zip') } 143 | end 144 | 145 | context 'when sapmachine 11 jdk' do 146 | let(:params) { { ensure: 'present', version: '11', java: 'jdk' } } 147 | let(:title) { 'jdk11' } 148 | 149 | it { is_expected.to contain_archive('/tmp/sapmachine-jdk-11.0.7_linux-x64_bin.tar.gz') } 150 | end 151 | 152 | context 'when sapmachine 11 jre' do 153 | let(:params) { { ensure: 'present', version: '11', java: 'jre' } } 154 | let(:title) { 'jre11' } 155 | 156 | it { is_expected.to contain_archive('/tmp/sapmachine-jre-11.0.7_linux-x64_bin.tar.gz') } 157 | end 158 | 159 | context 'when sapmachine 14 jdk' do 160 | let(:params) { { ensure: 'present', version: '14', java: 'jdk' } } 161 | let(:title) { 'jdk14' } 162 | 163 | it { is_expected.to contain_archive('/tmp/sapmachine-jdk-14.0.1_linux-x64_bin.tar.gz') } 164 | end 165 | 166 | context 'when sapmachine 14 jre' do 167 | let(:params) { { ensure: 'present', version: '14', java: 'jre' } } 168 | let(:title) { 'jre14' } 169 | 170 | it { is_expected.to contain_archive('/tmp/sapmachine-jre-14.0.1_linux-x64_bin.tar.gz') } 171 | end 172 | 173 | context 'when installing multiple versions' do 174 | let(:params) do 175 | { 176 | ensure: 'present', 177 | version_full: '11.0.7', 178 | java: 'jdk' 179 | } 180 | end 181 | let(:title) { 'jdk1107' } 182 | 183 | let(:pre_condition) do 184 | <<-MANIFEST 185 | java::sap { 186 | 'jdk1106': 187 | ensure => 'present', 188 | version_full => '11.0.6', 189 | java => 'jdk', 190 | } 191 | MANIFEST 192 | end 193 | 194 | it { is_expected.to compile } 195 | end 196 | end 197 | 198 | describe 'incompatible OSes' do 199 | [ 200 | { 201 | kernel: 'Windows', 202 | os: { 203 | family: 'Windows', 204 | name: 'Windows', 205 | release: { 206 | full: '8.1' 207 | } 208 | } 209 | }, 210 | { 211 | kernel: 'Darwin', 212 | os: { 213 | family: 'Darwin', 214 | name: 'Darwin', 215 | release: { 216 | full: '13.3.0' 217 | } 218 | } 219 | }, 220 | { 221 | kernel: 'AIX', 222 | os: { 223 | family: 'AIX', 224 | name: 'AIX', 225 | release: { 226 | full: '7100-02-00-000' 227 | } 228 | } 229 | }, 230 | { 231 | kernel: 'AIX', 232 | os: { 233 | family: 'AIX', 234 | name: 'AIX', 235 | release: { 236 | full: '6100-07-04-1216' 237 | } 238 | } 239 | }, 240 | { 241 | kernel: 'AIX', 242 | os: { 243 | family: 'AIX', 244 | name: 'AIX', 245 | release: { 246 | full: '5300-12-01-1016' 247 | } 248 | } 249 | }, 250 | ].each do |facts| 251 | let(:facts) { facts } 252 | let(:title) { 'jdk' } 253 | 254 | it "is_expected.to fail on #{facts[:os][:name]} #{facts[:os][:release][:full]}" do 255 | expect { catalogue }.to raise_error Puppet::Error, %r{unsupported platform} 256 | end 257 | end 258 | end 259 | end 260 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.configure do |c| 4 | c.mock_with :rspec 5 | end 6 | 7 | require 'puppetlabs_spec_helper/module_spec_helper' 8 | require 'rspec-puppet-facts' 9 | 10 | require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) 11 | 12 | include RspecPuppetFacts 13 | 14 | default_facts = { 15 | puppetversion: Puppet.version, 16 | facterversion: Facter.version, 17 | } 18 | 19 | default_fact_files = [ 20 | File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), 21 | File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), 22 | ] 23 | 24 | default_fact_files.each do |f| 25 | next unless File.exist?(f) && File.readable?(f) && File.size?(f) 26 | 27 | begin 28 | require 'deep_merge' 29 | default_facts.deep_merge!(YAML.safe_load(File.read(f), permitted_classes: [], permitted_symbols: [], aliases: true)) 30 | rescue StandardError => e 31 | RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" 32 | end 33 | end 34 | 35 | # read default_facts and merge them over what is provided by facterdb 36 | default_facts.each do |fact, value| 37 | add_custom_fact fact, value, merge_facts: true 38 | end 39 | 40 | RSpec.configure do |c| 41 | c.default_facts = default_facts 42 | c.before :each do 43 | # set to strictest setting for testing 44 | # by default Puppet runs at warning level 45 | Puppet.settings[:strict] = :warning 46 | Puppet.settings[:strict_variables] = true 47 | end 48 | c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] 49 | c.after(:suite) do 50 | RSpec::Puppet::Coverage.report!(0) 51 | end 52 | 53 | # Filter backtrace noise 54 | backtrace_exclusion_patterns = [ 55 | %r{spec_helper}, 56 | %r{gems}, 57 | ] 58 | 59 | if c.respond_to?(:backtrace_exclusion_patterns) 60 | c.backtrace_exclusion_patterns = backtrace_exclusion_patterns 61 | elsif c.respond_to?(:backtrace_clean_patterns) 62 | c.backtrace_clean_patterns = backtrace_exclusion_patterns 63 | end 64 | end 65 | 66 | # Ensures that a module is defined 67 | # @param module_name Name of the module 68 | def ensure_module_defined(module_name) 69 | module_name.split('::').reduce(Object) do |last_module, next_module| 70 | last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) 71 | last_module.const_get(next_module, false) 72 | end 73 | end 74 | 75 | # 'spec_overrides' from sync.yml will appear below this line 76 | -------------------------------------------------------------------------------- /spec/spec_helper_acceptance.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'puppet_litmus' 4 | require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb')) 5 | 6 | PuppetLitmus.configure! 7 | -------------------------------------------------------------------------------- /spec/spec_helper_acceptance_local.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | UNSUPPORTED_PLATFORMS = ['darwin', 'windows'].freeze 4 | -------------------------------------------------------------------------------- /spec/spec_helper_local.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | if ENV['COVERAGE'] == 'yes' 4 | require 'simplecov' 5 | require 'simplecov-console' 6 | require 'codecov' 7 | 8 | SimpleCov.formatters = [ 9 | SimpleCov::Formatter::HTMLFormatter, 10 | SimpleCov::Formatter::Console, 11 | SimpleCov::Formatter::Codecov, 12 | ] 13 | SimpleCov.start do 14 | track_files 'lib/**/*.rb' 15 | 16 | add_filter '/spec' 17 | 18 | # do not track vendored files 19 | add_filter '/vendor' 20 | add_filter '/.vendor' 21 | 22 | # do not track gitignored files 23 | # this adds about 4 seconds to the coverage check 24 | # this could definitely be optimized 25 | add_filter do |f| 26 | # system returns true if exit status is 0, which with git-check-ignore means file is ignored 27 | system("git check-ignore --quiet #{f.filename}") 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /spec/unit/facter/java_default_home_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | java_7_path = '/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java' 6 | java_7_home = '/usr/lib/jvm/java-7-openjdk-amd64' 7 | java_8_path = '/usr/lib/jvm/oracle-java8-jre-amd64/bin/java' 8 | java_8_home = '/usr/lib/jvm/oracle-java8-jre-amd64' 9 | 10 | def unlink_and_delete(filename) 11 | File.unlink(filename) if File.symlink?(filename) 12 | return unless File.exist?(filename) 13 | 14 | File.delete(filename) 15 | end 16 | 17 | def symlink_and_test(symlink_path, java_home) 18 | File.symlink(symlink_path, './java_test') 19 | allow(Facter::Core::Execution).to receive(:which).with('java').and_return('./java_test') 20 | allow(File).to receive(:realpath).with('./java_test').and_return(symlink_path) 21 | expect(Facter.value(:java_default_home)).to eql java_home 22 | end 23 | 24 | describe 'java_default_home' do 25 | before(:each) do 26 | Facter.clear 27 | allow(Facter.fact(:kernel)).to receive(:value).once.and_return('Linux') 28 | end 29 | 30 | context 'when java found in PATH' do 31 | context 'when java is in /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java' do 32 | it do 33 | unlink_and_delete('./java_test') 34 | symlink_and_test(java_7_path, java_7_home) 35 | unlink_and_delete('./java_test') 36 | end 37 | end 38 | 39 | context 'when java is in /usr/lib/jvm/oracle-java8-jre-amd64/bin/java' do 40 | it do 41 | unlink_and_delete('./java_test') 42 | symlink_and_test(java_8_path, java_8_home) 43 | unlink_and_delete('./java_test') 44 | end 45 | end 46 | end 47 | 48 | context 'when java not present, return nil' do 49 | it do 50 | allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls 51 | expect(Facter::Core::Execution).to receive(:which).with('java').at_least(1).and_return(nil) 52 | expect(Facter.value(:java_default_home)).to be_nil 53 | end 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /spec/unit/facter/java_libjvm_path_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | describe 'java_libjvm_path' do 6 | let(:java_default_home) { '/usr/lib/jvm/java-8-openjdk-amd64' } 7 | 8 | before(:each) do 9 | Facter.clear 10 | allow(Facter.fact(:kernel)).to receive(:value).and_return('Linux') 11 | allow(Facter.fact(:java_default_home)).to receive(:value).and_return(java_default_home) 12 | end 13 | 14 | context 'when libjvm exists' do 15 | it do 16 | allow(Facter.fact(:java_major_version)).to receive(:value).and_return(8) 17 | allow(Dir).to receive(:glob).with("#{java_default_home}/jre/lib/**/libjvm.so").and_return(['/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so']) 18 | expect(Facter.value(:java_libjvm_path)).to eql '/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server' 19 | end 20 | end 21 | 22 | context 'when libjvm does not exist' do 23 | it do 24 | allow(Dir).to receive(:glob).with("#{java_default_home}/lib/**/libjvm.so").and_return([]) 25 | expect(Facter.value(:java_libjvm_path)).to be_nil 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /spec/unit/facter/java_major_version_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | describe 'java_major_version' do 6 | before(:each) do 7 | Facter.clear 8 | end 9 | 10 | context 'when java_version fact present, returns major version' do 11 | before :each do 12 | allow(Facter.fact(:java_version)).to receive(:value).and_return('1.7.0_71') 13 | end 14 | 15 | it do 16 | expect(Facter.fact(:java_major_version).value).to eq('7') 17 | end 18 | end 19 | 20 | context 'when java not present, returns nil' do 21 | before :each do 22 | allow(Facter.fact(:java_version)).to receive(:value).and_return(nil) 23 | end 24 | 25 | it do 26 | expect(Facter.fact(:java_major_version).value).to be_nil 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /spec/unit/facter/java_patch_level_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | describe 'java_patch_level' do 6 | before(:each) do 7 | Facter.clear 8 | end 9 | 10 | context 'when java is installed returns java patch version extracted from java_version fact' do 11 | before :each do 12 | allow(Facter.fact(:java_version)).to receive(:value).and_return('1.7.0_71') 13 | end 14 | 15 | it do 16 | expect(Facter.fact(:java_patch_level).value).to eq('71') 17 | end 18 | end 19 | 20 | context 'when java is not installed returns nil' do 21 | before :each do 22 | allow(Facter.fact(:java_version)).to receive(:value).and_return('nil') 23 | end 24 | 25 | it do 26 | expect(Facter.fact(:java_patch_level).value).to be_nil 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /spec/unit/facter/java_version_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | openjdk_7_output = "Picked up JAVA_TOOL_OPTIONS: -Djava.net.preferIPv4Stack=true\n" \ 6 | "openjdk version \"1.7.0_71\"\n" \ 7 | "OpenJDK Runtime Environment (build 1.7.0_71-b14)\n" \ 8 | "OpenJDK 64-Bit Server VM (build 24.71-b01, mixed mode)\n" 9 | 10 | jdk_7_hotspot_output = "Picked up JAVA_TOOL_OPTIONS: -Djava.net.preferIPv4Stack=true\n" \ 11 | "java version \"1.7.0_71\"\n" \ 12 | "Java(TM) SE Runtime Environment (build 1.7.0_71-b14)\n" \ 13 | "Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)\n" 14 | 15 | describe 'java_version' do 16 | before(:each) do 17 | Facter.clear 18 | end 19 | 20 | context 'when java present, returns java version' do 21 | context 'when on OpenBSD', with_env: true do 22 | before(:each) do 23 | allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('OpenBSD') 24 | allow(Facter.fact(:kernel)).to receive(:value).and_return('Linux') 25 | end 26 | 27 | let(:facts) { { operatingsystem: 'OpenBSD' } } 28 | 29 | it do 30 | allow(Facter::Core::Execution).to receive(:which).with('java').and_return('/usr/local/jdk-1.7.0/jre/bin/java') 31 | allow(Facter::Core::Execution).to receive(:execute).with('java -Xmx12m -version 2>&1').and_return(openjdk_7_output) 32 | expect(Facter.value(:java_version)).to eq('1.7.0_71') 33 | end 34 | end 35 | 36 | context 'when on Darwin' do 37 | before(:each) do 38 | allow(Facter.fact(:kernel)).to receive(:value).and_return('Darwin') 39 | end 40 | 41 | let(:facts) { { kernel: 'Darwin' } } 42 | 43 | it do 44 | allow(Facter::Core::Execution).to receive(:execute).with('/usr/libexec/java_home --failfast', { on_fail: false }).and_return('/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home') 45 | allow(Facter::Core::Execution).to receive(:execute).with('java -Xmx12m -version 2>&1').and_return(jdk_7_hotspot_output) 46 | expect(Facter.value(:java_version)).to eq('1.7.0_71') 47 | end 48 | end 49 | 50 | context 'when on other systems' do 51 | before(:each) do 52 | allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('MyOS') 53 | allow(Facter.fact(:kernel)).to receive(:value).and_return('Linux') 54 | end 55 | 56 | let(:facts) { { operatingsystem: 'MyOS' } } 57 | 58 | it do 59 | allow(Facter::Core::Execution).to receive(:which).with('java').and_return('/path/to/java') 60 | allow(Facter::Core::Execution).to receive(:execute).with('java -Xmx12m -version 2>&1').and_return(jdk_7_hotspot_output) 61 | expect(Facter.value(:java_version)).to eq('1.7.0_71') 62 | end 63 | end 64 | end 65 | 66 | context 'when java not present, returns nil' do 67 | context 'when on OpenBSD', with_env: true do 68 | before(:each) do 69 | allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('OpenBSD') 70 | allow(Facter.fact(:kernel)).to receive(:value).and_return('Linux') 71 | end 72 | 73 | let(:facts) { { operatingsystem: 'OpenBSD' } } 74 | 75 | it do 76 | allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls 77 | allow(Facter::Core::Execution).to receive(:which).and_return(nil) 78 | expect(Facter.value(:java_version)).to be_nil 79 | end 80 | end 81 | 82 | context 'when on Darwin' do 83 | before(:each) do 84 | allow(Facter.fact(:kernel)).to receive(:value).and_return('Darwin') 85 | end 86 | 87 | let(:facts) { { kernel: 'Darwin' } } 88 | 89 | it do 90 | expect(Facter::Core::Execution).to receive(:execute).with('/usr/libexec/java_home --failfast', { on_fail: false }).at_least(1).and_return(false) 91 | expect(Facter.value(:java_version)).to be_nil 92 | end 93 | end 94 | 95 | context 'when on other systems' do 96 | before(:each) do 97 | allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('MyOS') 98 | allow(Facter.fact(:kernel)).to receive(:value).and_return('Linux') 99 | end 100 | 101 | let(:facts) { { operatingsystem: 'MyOS' } } 102 | 103 | it do 104 | expect(Facter::Core::Execution).to receive(:which).at_least(1).with('java').and_return(false) 105 | expect(Facter.value(:java_version)).to be_nil 106 | end 107 | end 108 | end 109 | end 110 | --------------------------------------------------------------------------------