diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 8af810ef5..000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -version: 2.1 -orbs: - kitchen: sous-chefs/kitchen@2 -workflows: - danger: - jobs: - - kitchen/danger: - name: danger - context: Danger-Minimal diff --git a/.delivery/project.toml b/.delivery/project.toml deleted file mode 100644 index 6d5e36173..000000000 --- a/.delivery/project.toml +++ /dev/null @@ -1 +0,0 @@ -remote_file = "https://raw.githubusercontent.com/chef-cookbooks/community_cookbook_tools/master/delivery/project.toml" diff --git a/.editorconfig b/.editorconfig index 1656a6d5d..cc21b0460 100755 --- a/.editorconfig +++ b/.editorconfig @@ -1,11 +1,19 @@ -#https://EditorConfig.org +# https://EditorConfig.org + # top-most EditorConfig file root=true +# Unix-style newlines with a newline ending every file [*] end_of_line = lf insert_final_newline = true + +# 2 space indentation indent_style = space indent_size = 2 + +# Avoid issues parsing cookbook files later charset = utf-8 + +# Avoid cookstyle warnings trim_trailing_whitespace = true diff --git a/.envrc b/.envrc index 6ed589ea8..484ad2666 100644 --- a/.envrc +++ b/.envrc @@ -1 +1,2 @@ use chefworkstation +export KITCHEN_GLOBAL_YAML=kitchen.global.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 3f69af20c..7cc52a972 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @sous-chefs/java +* @sous-chefs/maintainers diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index 651e753af..000000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,20 +0,0 @@ -### Cookbook version -[Version of the cookbook where you are encountering the issue] - -### Chef-client version -[Version of chef-client in your environment] - -### Platform Details -[Operating system distribution and release version. Cloud provider if running in the cloud] - -### Scenario: -[What you are trying to achieve and you can't?] - -### Steps to Reproduce: -[If you are filing an issue what are the things we need to do in order to repro your problem? How are you using this cookbook or any resources it includes?] - -### Expected Result: -[What are you expecting to happen as the consequence of above reproduction steps?] - -### Actual Result: -[What actually happens after the reproduction steps? Include the error output or a link to a gist if possible.] diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 5ae7f3ffe..000000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,13 +0,0 @@ -### Description - -[Describe what this change achieves] - -### Issues Resolved - -[List any existing issues this PR resolves] - -### Check List - -- [ ] All tests pass. See -- [ ] New functionality includes testing. -- [ ] New functionality has been documented in the README if applicable \ No newline at end of file diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 000000000..e10849328 --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,95 @@ +# Copilot Instructions for Sous Chefs Cookbooks + +## Repository Overview + +**Chef cookbook** for managing software installation and configuration. Part of the Sous Chefs cookbook ecosystem. + +**Key Facts:** Ruby-based, Chef >= 16 required, supports various OS platforms (check metadata.rb, kitchen.yml and .github/workflows/ci.yml for which platforms to specifically test) + +## Project Structure + +**Critical Paths:** +- `recipes/` - Chef recipes for cookbook functionality (if this is a recipe-driven cookbook) +- `resources/` - Custom Chef resources with properties and actions (if this is a resource-driven cookbook) +- `spec/` - ChefSpec unit tests +- `test/integration/` - InSpec integration tests (tests all platforms supported) +- `test/cookbooks/` or `test/fixtures/` - Example cookbooks used during testing that show good examples of custom resource usage +- `attributes/` - Configuration for recipe driven cookbooks (not applicable to resource cookbooks) +- `libraries/` - Library helpers to assist with the cookbook. May contain multiple files depending on complexity of the cookbook. +- `templates/` - ERB templates that may be used in the cookbook +- `files/` - files that may be used in the cookbook +- `metadata.rb`, `Berksfile` - Cookbook metadata and dependencies + +## Build and Test System + +### Environment Setup +**MANDATORY:** Install Chef Workstation first - provides chef, berks, cookstyle, kitchen tools. + +### Essential Commands (strict order) +```bash +berks install # Install dependencies (always first) +cookstyle # Ruby/Chef linting +yamllint . # YAML linting +markdownlint-cli2 '**/*.md' # Markdown linting +chef exec rspec # Unit tests (ChefSpec) +# Integration tests will be done via the ci.yml action. Do not run these. Only check the action logs for issues after CI is done running. +``` + +### Critical Testing Details +- **Kitchen Matrix:** Multiple OS platforms × software versions (check kitchen.yml for specific combinations) +- **Docker Required:** Integration tests use Dokken driver +- **CI Environment:** Set `CHEF_LICENSE=accept-no-persist` +- **Full CI Runtime:** 30+ minutes for complete matrix + +### Common Issues and Solutions +- **Always run `berks install` first** - most failures are dependency-related +- **Docker must be running** for kitchen tests +- **Chef Workstation required** - no workarounds, no alternatives +- **Test data bags needed** (optional for some cookbooks) in `test/integration/data_bags/` for convergence + +## Development Workflow + +### Making Changes +1. Edit recipes/resources/attributes/templates/libraries +2. Update corresponding ChefSpec tests in `spec/` +3. Also update any InSpec tests under test/integration +4. Ensure cookstyle and rspec passes at least. You may run `cookstyle -a` to automatically fix issues if needed. +5. Also always update all documentation found in README.md and any files under documentation/* +6. **Always update CHANGELOG.md** (required by Dangerfile) - Make sure this conforms with the Sous Chefs changelog standards. + +### Pull Request Requirements +- **PR description >10 chars** (Danger enforced) +- **CHANGELOG.md entry** for all code changes +- **Version labels** (major/minor/patch) required +- **All linters must pass** (cookstyle, yamllint, markdownlint) +- **Test updates** needed for code changes >5 lines and parameter changes that affect the code logic + +## Chef Cookbook Patterns + +### Resource Development +- Custom resources in `resources/` with properties and actions +- Include comprehensive ChefSpec tests for all actions +- Follow Chef resource DSL patterns + +### Recipe Conventions +- Use `include_recipe` for modularity +- Handle platforms with `platform_family?` conditionals +- Use encrypted data bags for secrets (passwords, SSL certs) +- Leverage attributes for configuration with defaults + +### Testing Approach +- **ChefSpec (Unit):** Mock dependencies, test recipe logic in `spec/` +- **InSpec (Integration):** Verify actual system state in `test/integration/inspec/` - InSpec files should contain proper inspec.yml and controls directories so that it could be used by other suites more easily. +- One test file per recipe, use standard Chef testing patterns + +## Trust These Instructions + +These instructions are validated for Sous Chefs cookbooks. **Do not search for build instructions** unless information here fails. + +**Error Resolution Checklist:** +1. Verify Chef Workstation installation +2. Confirm `berks install` completed successfully +3. Ensure Docker is running for integration tests +4. Check for missing test data dependencies + +The CI system uses these exact commands - following them matches CI behavior precisely. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d951f1b9..08b47e1b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,87 +1,59 @@ --- -name: ci +name: "Test" -'on': +"on": pull_request: push: - branches: - - master + branches: [main] jobs: - delivery: - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@master - - name: Run Chef Delivery - uses: actionshub/chef-delivery@master - env: - CHEF_LICENSE: accept-no-persist + lint-unit: + uses: sous-chefs/.github/.github/workflows/lint-unit.yml@9.0.0 + permissions: + checks: write + pull-requests: write + statuses: write + secrets: inherit - yamllint: - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@master - - name: Run yaml Lint - uses: actionshub/yamllint@master - - mdl: - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@master - - name: Run Markdown Lint - uses: actionshub/markdownlint@master - - dokken: - needs: [mdl, yamllint, delivery] + integration: + needs: "lint-unit" runs-on: ubuntu-latest strategy: matrix: os: - - amazon-linux - - amazonlinux-2 - - debian-9 - - debian-10 - - centos-7 - - centos-8 - - ubuntu-1804 - - ubuntu-2004 + - almalinux-8 + - almalinux-9 + - almalinux-10 + - amazonlinux-2023 + - centos-stream-9 + - centos-stream-10 + - debian-12 + - debian-13 + - fedora-latest + - oraclelinux-8 + - oraclelinux-9 + - rockylinux-8 + - rockylinux-9 + - rockylinux-10 + - ubuntu-2204 + - ubuntu-2404 suite: - openjdk-11 - - openjdk-12 - - openjdk-13 - - openjdk-pkg-8 - - openjdk-pkg-11 - - adoptopenjdk-8-openj9 - - adoptopenjdk-11-hotspot - - adoptopenjdk-11-openj9 - - adoptopenjdk-11-openj9-large-heap - - adoptopenjdk-14-hotspot - - adoptopenjdk-14-openj9 - - adoptopenjdk-14-openj9-large-heap - - adoptopenjdk-removal-11-openj9 - # - corretto-11 - # - corretto-8 - include: - - os: ubuntu-2004 - suite: openjdk-pkg-14 - exclude: - - os: amazon-linux - suite: openjdk-pkg-11 - - os: debian-9 - suite: openjdk-pkg-11 - - os: debian-10 - suite: openjdk-pkg-8 + - openjdk-17 + - temurin-11 + - temurin-17 + - temurin-21 + - temurin-25 + - corretto-11 + - corretto-17 fail-fast: false steps: - name: Check out code - uses: actions/checkout@master + uses: actions/checkout@v7 - name: Install Chef - uses: actionshub/chef-install@master + uses: sous-chefs/.github/.github/actions/install-workstation@9.0.0 - name: Dokken - uses: actionshub/kitchen-dokken@master + uses: actionshub/test-kitchen@main env: CHEF_LICENSE: accept-no-persist KITCHEN_LOCAL_YAML: kitchen.dokken.yml @@ -89,30 +61,8 @@ jobs: suite: ${{ matrix.suite }} os: ${{ matrix.os }} - macos: - needs: [mdl, yamllint, delivery] - runs-on: macos-latest - steps: - - name: Check out code - uses: actions/checkout@master - - name: Install Chef - uses: actionshub/chef-install@master - - name: Run Test Kitchen - env: - CHEF_LICENSE: accept-no-persist - KITCHEN_LOCAL_YAML: kitchen.macos.yml - TERM: xterm-256color - run: | - kitchen converge adoptopenjdk-14-macos - source /etc/profile - echo "sourced profile for JAVA_HOME" - echo "New JAVA home after Chef run is: ${JAVA_HOME}" - kitchen verify adoptopenjdk-14-macos - - final: - needs: [dokken] runs-on: ubuntu-latest + needs: [integration] steps: - - name: Check out code - uses: actions/checkout@master + - run: echo "integration completed" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..bd814d3c9 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,25 @@ +--- +name: release + + +"on": + push: + branches: [main] + +permissions: + contents: write + issues: write + pull-requests: write + packages: write + attestations: write + id-token: write + +jobs: + release: + uses: sous-chefs/.github/.github/workflows/release-cookbook.yml@9.0.0 + secrets: + token: ${{ secrets.PORTER_GITHUB_TOKEN }} + supermarket_user: ${{ secrets.CHEF_SUPERMARKET_USER }} + supermarket_key: ${{ secrets.CHEF_SUPERMARKET_KEY }} + slack_bot_token: ${{ secrets.SLACK_BOT_TOKEN }} + slack_channel_id: ${{ secrets.SLACK_CHANNEL_ID }} diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 000000000..d9e5240b7 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,25 @@ +--- +name: Mark stale issues and pull requests + +"on": + schedule: [cron: "0 0 * * *"] + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v10 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + close-issue-message: > + Closing due to inactivity. + If this is still an issue please reopen or open another issue. + Alternatively drop by the #sous-chefs channel on the [Chef Community Slack](http://community-slack.chef.io/) and we'll be happy to help! + Thanks, Sous-Chefs. + days-before-close: 7 + days-before-stale: 365 + stale-issue-message: > + Marking stale due to inactivity. + Remove stale label or comment or this will be closed in 7 days. + Alternatively drop by the #sous-chefs channel on the [Chef Community Slack](http://community-slack.chef.io/) and we'll be happy to help! + Thanks, Sous-Chefs. diff --git a/.gitignore b/.gitignore index e085291b9..be3b9a8bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,7 @@ *.rbc .config -coverage InstalledFiles -lib/bundler/man pkg -rdoc -spec/reports test/tmp test/version_tmp tmp @@ -14,27 +10,32 @@ _Store *# .#* \#*# -.*.sw[a-z] *.un~ *.tmp *.bk *.bkup -# ruby/bundler files +# editor files +.idea +.*.sw[a-z] + +# ruby/bundler/rspec files .ruby-version .ruby-gemset .rvmrc Gemfile.lock .bundle *.gem +coverage +spec/reports -# YARD artifacts +# YARD / rdoc artifacts .yardoc _yardoc doc/ -.idea +rdoc -# chef stuff +# chef infra stuff Berksfile.lock .kitchen kitchen.local.yml diff --git a/.markdownlint-cli2.yaml b/.markdownlint-cli2.yaml new file mode 100644 index 000000000..e42be9b18 --- /dev/null +++ b/.markdownlint-cli2.yaml @@ -0,0 +1,10 @@ +config: + ul-indent: false # MD007 + line-length: false # MD013 + no-duplicate-heading: false # MD024 + reference-links-images: false # MD052 + no-multiple-blanks: + maximum: 2 +ignores: + - .github/copilot-instructions.md + - .windsurf/** diff --git a/.overcommit.yml b/.overcommit.yml index 1d27ed8d3..0e89a3c11 100644 --- a/.overcommit.yml +++ b/.overcommit.yml @@ -4,17 +4,21 @@ PreCommit: enabled: true YamlLint: enabled: true - Rspec: + required_executable: "yamllint" + ChefSpec: enabled: true - required_executable: 'rspec' + required_executable: "chef" + command: ["chef", "exec", "rspec"] Cookstyle: enabled: true - required_executable: 'cookstyle' + required_executable: "cookstyle" command: ["cookstyle"] - Delivery: - enabled: true - required_executable: 'delivery' - flags: ['local', 'all'] + MarkdownLint: + enabled: false + required_executable: "npx" + command: ["npx", "markdownlint-cli2", "'**/*.md'"] + include: ["**/*.md"] + CommitMsg: HardTabs: enabled: true diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 000000000..b87683f45 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "15.0.0" +} diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 000000000..61883002d --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,2 @@ +require: + - cookstyle diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 000000000..58f0386e1 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +ruby system diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 000000000..cf171a373 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "chef-software.chef", + "Shopify.ruby-lsp", + "editorconfig.editorconfig", + "DavidAnson.vscode-markdownlint" + ] +} diff --git a/.yamllint b/.yamllint index 15e8b6947..0046b2379 100644 --- a/.yamllint +++ b/.yamllint @@ -1,7 +1,15 @@ --- extends: default -ignore: .kitchen/ rules: line-length: - max: 120 + max: 256 level: warning + document-start: disable + braces: + forbid: false + min-spaces-inside: 0 + max-spaces-inside: 1 + min-spaces-inside-empty: -1 + max-spaces-inside-empty: -1 + comments: + min-spaces-from-content: 1 diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 000000000..4013626d6 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,79 @@ +# AGENTS.md + +## Purpose + +This file records maintainer and agent decisions for the Java cookbook. Keep it focused on durable +patterns, support boundaries, and non-obvious implementation choices. Do not use it as a task +changelog. + +## Modernization Scope + +This cookbook is being modernized incrementally. Preserve the existing custom-resource API where it +is still useful, and avoid broad rewrites unless the requested work explicitly calls for a full +migration. + +Prefer resource properties and helper-derived defaults over cookbook node attributes. Do not add +`attributes/` back to provide defaults for resources. + +## Resource Defaults + +Cookbook-owned defaults should live on resources as static defaults, `lazy` helper calls, or helper +methods in `libraries/`. This keeps defaults visible at the resource boundary and testable through +ChefSpec. + +Do not write cookbook state into `node.default`, `node.normal`, `node.override`, or +`node.automatic`. In particular, do not reintroduce `node['java']` as an API surface for +`java_home`, `jdk_version`, `download_path`, install type, JCE values, or similar resource inputs. + +Do not create custom Ohai plugins for cookbook defaults. Ohai automatic attributes should describe +discovered machine facts, not cookbook policy or resource configuration. + +## Platform Support + +Keep `metadata.rb`, Kitchen files, and GitHub Actions matrices aligned. Platform entries should be +current, non-EOL, and backed by either vendor support or explicit cookbook helper behavior. + +OpenJDK package installs use the platform package manager where helper logic supports the requested +Java version. Source installs remain the fallback when a requested version is not available through +the package path. + +## Dependency Management + +Use `Policyfile.rb` for dependency resolution. Keep it local-only unless a real external cookbook +dependency is introduced. Do not add `default_source :supermarket` when every cookbook in the policy +is supplied by a path. + +Avoid external cookbook dependencies for simple file edits in custom resources. Prefer native Chef +resources so unit tests and Kitchen do not need to contact Supermarket during Policyfile setup. + +Do not reintroduce Berkshelf files or ChefSpec Berkshelf loading unless there is an explicit +compatibility reason. + +## Resource Notes + +`java_alternatives` accepts `bin_cmds` as an Array. Its public actions are `:set` and `:unset`. +Keep both actions covered by ChefSpec when changing alternatives behavior. + +Linux install resources that include the shared Linux partial (`openjdk_pkg_install`, +`openjdk_source_install`, `openjdk_install`, `corretto_install`, and `temurin_package_install`) +default `reset_alternatives` to `true` through that partial. + +`java_certificate` should provide sensible resource defaults without reading `node['java']`. +Current defaults are Java 17 and a platform-specific OpenJDK package `java_home` derived from helper +logic. + +`java_jce` documents legacy Oracle JCE policy file installation only. It should not be described as +a general Java vendor installation path. JCE URL, checksum, and Java home are explicit resource +inputs; staging defaults to Chef's file cache path. + +`temurin_package_install` does not have an `air_gap` property. It supports `repository_uri` for +alternate or mirrored package repositories. The resource must not make live Adoptium API calls while +evaluating defaults. + +Amazon Corretto installs are source archive based and support the architecture-specific Corretto +archive naming handled by helper code (`x64` and `aarch64`). Kitchen and CI cover Corretto 11 and 17 +only; do not add Corretto suites for other majors unless `libraries/corretto_helpers.rb`, docs, and +tests are updated with explicit archive metadata. + +`openjdk_source_install` documentation examples should call `openjdk_source_install`, not the +dispatcher resource `openjdk_install`. diff --git a/Berksfile b/Berksfile deleted file mode 100644 index 8275f4f39..000000000 --- a/Berksfile +++ /dev/null @@ -1,8 +0,0 @@ -source 'https://supermarket.chef.io' - -metadata - -group :integration do - cookbook 'homebrew' - cookbook 'test', path: 'test/fixtures/cookbooks/test' -end diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ced09d99..2203cc0d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,666 +4,532 @@ This file is used to list changes made in each version of the Java cookbook. ## Unreleased -## 8.1.2 (2020-04-20) +Standardise files with files in sous-chefs/repo-management -- Add OpenJDK source install resource -- Add documentation for openjdk_source_install -- Default the openjdk_install resource to install using the package manager by default +Standardise files with files in sous-chefs/repo-management -## 8.1.1 (2020-04-19) +## [15.0.0](https://github.com/sous-chefs/java/compare/14.0.1...v15.0.0) (2026-06-22) -- Fix JAVA_HOME for `adoptopenjdk_linux_install` resource -## 8.1.0 (2020-04-19) +### ⚠ BREAKING CHANGES -- Added `openjdk_pkg_install` resource -- Added documentation for openjdk_pkg_install -- Added `adoptopenjdk_linux_install` resource -- Added `adoptopenjdk_macos_install` resource -- Added documentation for `adoptopenjdk_linux_install` -- Added documentation for `adoptopenjdk_macos_install` -- Resolved cookstyle error: resources/alternatives.rb:49:13 refactor: `ChefCorrectness/ChefApplicationFatal` -- Resolved cookstyle error: resources/alternatives.rb:62:13 refactor: `ChefCorrectness/ChefApplicationFatal` -- Resolved cookstyle error: resources/alternatives.rb:75:11 refactor: `ChefCorrectness/ChefApplicationFatal` -- Resolved cookstyle error: resources/jce.rb:51:6 refactor: `ChefStyle/UnnecessaryOSCheck` +* support source archive upgrades ([#762](https://github.com/sous-chefs/java/issues/762)) +* remove legacy Java node attribute API ([#758](https://github.com/sous-chefs/java/issues/758)) -## 8.0.1 (2020-03-30) +### Features -- Added documentation in documentation/resources for `adoptopenjdk_install`, `alternatives`, `certificate`, `corretto_install`, `jce`, `openjdk_install` +* remove legacy Java node attribute API ([#758](https://github.com/sous-chefs/java/issues/758)) ([14e673e](https://github.com/sous-chefs/java/commit/14e673eee215a0fb5faca1111399272b04735e4b)) -## 8.0.0 (2020-03-30) +### Bug Fixes -- Added `openjdk_install` resource & documentation -- Removed openjdk, corretto, default_java_symlink, ibm & ibm_tar, notify & oracle recipes -- Removed support for IBM and Oracle Java -- Temporarily removed support for Windows -- Split out helpers for each provider into their own namespace and file +* add release-please manifest ([#760](https://github.com/sous-chefs/java/issues/760)) ([e6b0014](https://github.com/sous-chefs/java/commit/e6b00140ecc5f1e83a65d2f7a9173dd33f105431)) +* support source archive upgrades ([#762](https://github.com/sous-chefs/java/issues/762)) ([97433ea](https://github.com/sous-chefs/java/commit/97433eab0686fb9b06b9b57fca75e37cd116fbc3)), closes [#745](https://github.com/sous-chefs/java/issues/745) [#708](https://github.com/sous-chefs/java/issues/708) [#649](https://github.com/sous-chefs/java/issues/649) -## 7.0.0 (2020-03-05) +## 14.0.1 - *2025-09-04* -- Refactored and sped up unit tests. +## 14.0.0 - *2025-07-16* -## Added +* Remove Semeru support as there is no clean yum or apt repository for it -- Added `adoptopenjdk_install` resource & documentation -- Added AdoptOpenJDK 13 testing +## 13.2.0 - *2025-07-14* -## Deprecated +* Add `repository_uri` property to `temurin_package_install` and `openjdk_pkg_install` resources to support installation from alternative/internal mirrors ([#728](https://github.com/sous-chefs/java/issues/728)) +* Clarify documentation for `url` property in `openjdk_source_install` resource to note it can be used for internal mirrors +* Standardise files with files in sous-chefs/repo-management + Update the recommended Ruby VSCode extensions +* Fix missing skip_alternatives property in openjdk_pkg_install -- Removed the adoptopenjdk recipe, please use the `adoptopenjdk_install` resource instead. -- Increased the minimum Chef requirement to Chef 15 to use the archive resource. -- Removed AdoptOpenJDK 10 testing +## 13.1.0 - *2025-07-14* -## 6.0.0 (2020-03-02) +* add `skip_alternatives` to resources `corretto_install`, `openjdk_install`, `openjdk_pkg_install`, `openjdk_source_install` for cases when management of alternatives is not desired. (@dschlenk) -## Deprecated +## 13.0.0 - *2025-07-13* -- The resource alias `java_ark` has been deprecated in favour of `java_oracle_install` +* Add new resource `temurin_package_install` +* Add script to check for Java updates +* Update Temurin Java 8 support +* Update Temurin repositories +* Update bin commands for all OpenJDK versions +* Fix Java alternatives to prevent unnecessary removal and re-addition of alternatives +* Move bin_cmds from Java::Cookbook::OpenJdkHelpers to Java::Cookbook::BinCmdHelpers for reuse outside of OpenJDK +* Fix apt_repository failing to install the GPG in the correct location +* Add Temurin 21 to the test matrix +* Remove Semeru from the test matrix -## 5.0.0 (2020-02-21) +## 12.1.1 - *2024-12-05* -### Added +## 12.1.0 - *2024-12-03* -### Changed +* Add support for OpenJDK versions 19, 20, 21 and 22 +* Remove commented out `adoptopenjdk_linux_install` resource +* CI: chore(deps): update sous-chefs/.github action to v3.1.0 +* CI: chore(deps): update actionshub/chef-install action to v3 +* Update platforms +* Replace AdoptOpenJDK with Eclipse Temurin and IBM Semeru -- Fixed java_certificate regex where it checks if cert exists in cacert file. -- Make Homebrew Cask name an attribute to allow for other options (ex: adoptopenjdk) -- Switch homebrew tap to homebrew/cask-versions -- Make builds parallel -- Updates package name and link changes for adoptopenjdk -- Migrated testing to github actions +## 12.0.7 - *2024-11-18* -### Deprecated +* Standardise files with files in sous-chefs/repo-management -### Removed +## 12.0.6 - *2024-07-15* -- Removes openjdk-6 -- Removes openjdk-7 for Ubuntu 16.04 -- Removes openjdk-11 for Ubuntu -- Removes openjdk-direct for Debian 8 -- Removes oracle variants from test configurations +* Standardise files with files in sous-chefs/repo-management -## 4.3.0 (2019-08-04) +## 12.0.2 - *2024-01-16* -- Upgrade Amazon Corretto to the latest versions: 8.222.10.1 and 11.0.4.11.1 -- Upgrade circleci orb to version 2 and add yamllint and markdown lint +* Fix `openjdk_pkg_install` to obey `pkg_version` property for all `pkg_names` -## 4.2.0 - (2019-07-15) +## 11.2.0 - *2023-09-12* -- Fix for issue 538 -- Added "download_path" node attribute defaulting to file_cache_path -- Replaced all hardcoded instances of file_cache_path with the node attribute +* Standardise files with files in sous-chefs/repo-management -## 4.1.0 - (2019-05-08) +## 11.1.0 - *2023-04-17* -- Added new install flavor "corretto" for Amazon's Corretto distribution of OpenJDK +* Standardise files with files in sous-chefs/repo-management -## 4.0.0 - (2019-04-19) +## 11.1.0 - *2022-04-26* -- Added new install flavor "adoptopenjdk" for AdoptOpenJDK's distribution of Java -- The certificate resource now uses the Java version to determine the default cacerts location -- Updated AdoptOpenJDK links for Java 8 -- Updated AdoptOpenJDK links for Java 11 to 11.0.1 -- BREAKING CHANGE: Remove support for Java 6 & 7 -- Remove platform suport for untested platforms (smartOS, XenServer, zlinux, arch) -- Remove testing of Ubuntu 14.04, support at this point is no longer guaranteed and patches or other changes may not be accepted going further as Ubuntu 14.04 will be shortly EOL -- Fixed oracle download link for JDK 8 (update to 8u202 from 8u201) -- fixed specs for windows +* Remove Correto 15 and 16 +* Add Corretto 17 and 18 +* Change the defualt download URL for Corretto to the versioned resources URL, rather than latest. -## 3.2.0 - (2019-01-24) +## 11.0.0 - *2022-02-16* -- Add support OpenJDK 11 -- Fixed oracle download link again +* Require Chef 16 for resource partials +* Add resource partials for: MacOS, Linux, Java Home and Common as these are used in a multiple places -## 3.1.2 - (2018-12-11) +## 10.2.0 - *2022-01-26* -- Set java home on macosx using /usr/libexec/java_home -- Find command should have ./ for path to search, works for nix and mac -- Make `java_certificate` work with SNI endpoints +* Remove tap_full option as this is no longer supported and there is no replacement +* Remove delivery and move to calling RSpec directly via a reusable workflow -## 3.1.1 - (2018-11-09) +## 10.1.0 - *2021-10-06* -- Fix jce installation linux -- Allow overwrite `returns` property of windows_packages +* Revert worklfow split out +* Rename InSpec attribute folders to input +* Add Corretto 16 +* Update the Corretto minor version numbers +* Default the Debian install method to package +* Remove testing for end of life OpenJDK suites +* Primarily support OpenJDK LTS versions 11, 17 +* Drop support for OpenJDK package installs for non-LTS versions +* Direct Amazon users to Amazon Corretto instead of installing OpenJDK +* Drop package install support for Java 8 -## 3.1.0 - (2018-10-18) +## 10.0.0 - *2021-09-02* -- Add support for JDK 11 +* Remove recipes to stop confusing users -## 3.0.0 - (2018-10-18) +## 9.0.0 - *2021-06-04* -- Fix broken JCE with JRE installations -- make cert alias matching case insensitive as `keytool` always returns results downcases -- BREAKING CHANGE: fixed greedy matching by adding a word boundry when checking cert alias this prevents matching `foo_123` as `foo` -- verify artifact after downloading from oracle -- fixed `recipes/openjdk` when `node['java']['jdk_version']` by casting it to a string -- Updated Oracle Java links to 8u191 +* Remove Corretto checksum code defaults as this changes regularly, and is not provided in the SHA256 format via an API +* Set unified_mode to true for Chef 17 support +* Bump the minimum Chef version to 15.3 for unified_mode support -## 2.2.1 - (2018-09-29) +## 8.6.0 - *2021-01-22* -- Allows for additional Oracle (post 9) jdk download file naming, including '10.0.2'. '18.9', '11' +* Added Amazon Corretto 15 support to `corretto_install` +* Added configurable `file_cache_path` property to `java_certificate` +* Added `cacerts` property to `java_certificate` for interacting with java cacerts file (Java 9+) -## 2.2.0 - (2018-07-19) +## 8.5.0 - *2020-12-03* -- Updated Oracle Java links to 8u181 -- Fixed incorrect kitchen setup runlists that preventing local testing -- Resolve undefined certout errors +* If installation issues with `openjdk_install` resource (fixes #645) +* Remove testing of Amazon Linux 1 +* Use fedora-latest -## 2.1.0 - (2018-05-25) +## 8.4.0 - *2020-09-09* -- Added Java 10 JCE attributes to default attrs -- Update oracle recipeM to not perform a switch on java major version and instead use the version provided in attributes. This allows end users to include new Java versions without the cookbook requiring an update each time a major version gets released -- Updated the oracle_install resource to pick up semantic versioning that Oracle has started using for Java 10+ -- Updated the default attributes file to include x86_64 endpoint and checksum for Oracle Java 10\. The i586 version is not (yet) available. -- Fix JCE installation on Windows -- Avoid EmptyWindowsCommand error on Windows +* Add `starttls` property to `java_certificate` resource to allow fetching certificates from non HTTPS endpoints -## v2.0.1 - (2018-05-02) +## 8.3.2 - *2020-08-20* -- Fix java_certificate and java_oracle_install to work on FIPS enabled systems +* Add aarch64 installation candidate for Corretto -## v2.0.0 - (2018-05-02) +## 8.3.1 - *2020-08-06* -- Converted alternatives, ark, and certificate LWRP/HWRPs to custom resources with improved logging and convergence notification. -- Renamed the java_ark resource to java_oracle_install, which better represents what it does. The existing name will continue to function -- Removed the need for the apt cookbook and instead require Chef 12.9+ -- Fixed Amazon Linux support on Chef 13+. -- Fixed the alternatives commands on Fedora systems. -- Added initial openSUSE leap support. -- Updated code to use multi-package installs to speed up runs -- Made the 'cert_alias' property in the certificate resource the name_property to allow users to avoid resource cloning and to be able to use friendly resource names -- Moved the warning code for downloading directly from Oracle into the resource to prevent another resource showing as converged -- Updated the metadata to resolve failures to parse chef_version on older chef-client releases. -- Added installation of tar directly to the ark resource when uncompression .tar.gz files. This prevents installation in the recipe that occurred even if tar wasn't needed. -- Deprecated the java::purge recipe which purged old Sun Java packages which were distributed in distro repos before the Oracle acquisition of Sun. Migration away from these packages occurred many years ago and this recipe will be removed in the next major release of this cookbook. -- Updated the metadata license string to an SPDX compliant string to resolve Foodcritic warnings. -- Removed Chef 10 compatibility code in the Windows recipe that resulted in Foodcritic warnings. -- Removed logic to support paths on Debian < 7 and Ubuntu < 12.04 as these are both EOL. -- Removed duplicate logging in the resources. -- Converted integration tests from bats to InSpec. -- Moved template files out of the default directory as -- Corrected deprecation warnings in the ChefSpecs. -- Moved all Kitchen testing logic to the test_java cookbook and eliminated the need for the apt & free_bsd bash cookbooks in testing -- Don't try to create Chef's cache directory in the certificate resource. -- Disabled certificate integration tests since we're not currently running the certificate resource in Test Kitchen. -- Removed testing of Oracle JDK 6/7 since Oracle no longer allows directly downloading these releases. -- Added kitchen-dokken based testing +* Extract correct JAVA_HOME from custom URLs -## v1.50.0 - (05/24/2017) +## 8.3.0 - *2020-06-18* -- Oracle downloads changed again. Only Oracle 8 is able to be downloaded automatically. Please host your own copy internally to avoid issues such as this. -- Add Log warning if download url contains oracle.com +* Restore compatibility with Chef Infra Client < 16 +* Update Fedora releases in the Kitchen configs -## v1.49.0 - (04/21/2017) +## 8.2.0 - *2020-06-02* -- potential 'curl' resource cloning #415 -- Oracle 8u131 -- Add ChefSpec matchers for java_certificate resource -- Remove unnecessary apt update +* resolved cookstyle error: resources/adoptopenjdk_install.rb:1:1 warning: `ChefDeprecations/ResourceUsesOnlyResourceName` +* Remove testing of Ubuntu 14.04, support at this point is no longer guaranteed -## v1.48.0 - (03/31/2017) +## 8.1.0 - *2020-04-19* -- Update Oracle Java links from 101 to 121 -- Remove convergence report -- Remove Fedora 24 testing -- Fix test cookbook license -- Update platforms in the specs -- Remove testing on EOL platforms +* Added `openjdk_pkg_install` resource +* Added documentation for openjdk_pkg_install +* Added `adoptopenjdk_linux_install` resource +* Added `adoptopenjdk_macos_install` resource +* Added documentation for `adoptopenjdk_linux_install` +* Added documentation for `adoptopenjdk_macos_install` +* Resolved cookstyle error: resources/alternatives.rb:49:13 refactor: `ChefCorrectness/ChefApplicationFatal` +* Resolved cookstyle error: resources/alternatives.rb:62:13 refactor: `ChefCorrectness/ChefApplicationFatal` +* Resolved cookstyle error: resources/alternatives.rb:75:11 refactor: `ChefCorrectness/ChefApplicationFatal` +* Resolved cookstyle error: resources/jce.rb:51:6 refactor: `ChefStyle/UnnecessaryOSCheck` -## v1.47.0 - (01/30/2017) +## 8.0.0 - *2020-03-30* -- Fix typo in method name (#397) -- Remove useless ruby_block[set-env-java-home] -- Update README: using java::notify -- Add forgotten "do" to README +* Added `openjdk_install` resource & documentation +* Removed openjdk, corretto, default_java_symlink, ibm & ibm_tar, notify & oracle recipes +* Removed support for IBM and Oracle Java +* Temporarily removed support for Windows +* Split out helpers for each provider into their own namespace and file -## v1.46.0 - (01/09/2017) +## 7.0.0 - *2020-03-05* -- fix jce installation on windows #386 +* Refactored and sped up unit tests. +* Added `adoptopenjdk_install` resource & documentation +* Added AdoptOpenJDK 13 testing +* Removed the adoptopenjdk recipe, please use the `adoptopenjdk_install` resource instead. +* Increased the minimum Chef requirement to Chef 15 to use the archive resource. +* Removed AdoptOpenJDK 10 testing -## v1.45.0 - (12/27/2016) +## 6.0.0 - *2020-03-02* -- Update to resolve latest rubocop rules +* The resource alias `java_ark` has been deprecated in favour of `java_oracle_install` -## v1.44.0 - (12/27/2016) +## 5.0.0 - *2020-02-21* -- Unpublished due to newer rubocop rules in travis -- Added zlinux defaults +* Fixed java_certificate regex where it checks if cert exists in cacert file. +* Make Homebrew Cask name an attribute to allow for other options (ex: adoptopenjdk) +* Switch homebrew tap to homebrew/cask-versions +* Make builds parallel +* Updates package name and link changes for adoptopenjdk +* Migrated testing to github actions +* Removes openjdk-6 +* Removes openjdk-7 for Ubuntu 16.04 +* Removes openjdk-11 for Ubuntu +* Removes openjdk-direct for Debian 8 +* Removes oracle variants from test configurations -## v1.43.0 - (12/6/2016) +## 4.3.0 - *2019-08-04* -- Switch recursive chown from executing on the jdk parent directory to executing on the jdk directory itself. -- Added proxy support to curl -- add java_certificate LWRP from java-libraries cookbook - java-libraries now depricated. -- (Windows) support removal of obsolete JREs via optional attribute -- (Windows) Can download from s3 only using an IAM profile -- (Windows) aws session token for windows java download +* Upgrade Amazon Corretto to the latest versions: 8.222.10.1 and 11.0.4.11.1 +* Upgrade circleci orb to version 2 and add yamllint and markdown lint -## v1.42.0 - (8/8/2016) +## 4.2.0 - *2019-07-15* -- Use openjdk ppa for all ubuntu versions to allow for older/newer jdks to be installed. Fixes #368 -- update oracle java 8u101 - Use sha256 hash (seems to help with downloading each converge) -- Mac default converge fails since notify is not included by homebrew -- Remove chef 14(!) depreciation warning in tests -- Resolve chef-12 related warning +* Fix for issue 538 +* Added "download_path" node attribute defaulting to file_cache_path +* Replaced all hardcoded instances of file_cache_path with the node attribute -## v1.41.0 - (7/15/2016) +## 4.1.0 - *2019-05-08* -- Feature: Add new resource for cookbooks to subscribe to, see README -- Use a remote_file resource for JCE download instead of curl in an execute block. -- Since v1.40.4 Travis deploys cookbook to supermarket - expect more frequent, smaller releases. +* Added new install flavor "corretto" for Amazon's Corretto distribution of OpenJDK -## v1.40.4 - (7/12/2016) +## 4.0.0 - *2019-04-19* -- Automated deploy, no cookbook changes. +* Added new install flavor "adoptopenjdk" for AdoptOpenJDK's distribution of Java +* The certificate resource now uses the Java version to determine the default cacerts location +* Updated AdoptOpenJDK links for Java 8 +* Updated AdoptOpenJDK links for Java 11 to 11.0.1 +* BREAKING CHANGE: Remove support for Java 6 & 7 +* Remove platform suport for untested platforms (smartOS, XenServer, zlinux, arch) +* Remove testing of Ubuntu 14.04, support at this point is no longer guaranteed and patches or other changes may not be accepted going further as Ubuntu 14.04 will be shortly EOL +* Fixed oracle download link for JDK 8 (update to 8u202 from 8u201) +* fixed specs for windows -## v1.40.3 - (7/12/2016) +## 3.2.0 - *2019-01-24* -- Attempt to have travis publish this. -- Mac depends on homebrew. -- Fixed typo in platform family spelling for OS X -- fix openjdk version logic for freebsd -- Enable Ark provider to handle URI with get parameters +* Add support OpenJDK 11 +* Fixed oracle download link again -## v1.40.1 - (7/8/2016) +## 3.1.2 - *2018-12-11* -- Fixed: JAVA_HOME not set on systems with restrictive umask #359 +* Set java home on macosx using /usr/libexec/java_home +* Find command should have ./ for path to search, works for nix and mac +* Make `java_certificate` work with SNI endpoints -## v1.40 - (6/29/2016) +## 3.1.1 - *2018-11-09* -- Travis build green -- Add Windows JCE support -- Changes to prevent re-execution of resource creating file '/etc/profile.d/jdk.sh' -- Fix JDK checksum -- Update ibm_jdk.installer.properties.erb for IBM JDK 1.8 -- Install OpenJDK from distribution if Ubuntu version >= 15.10 -- Fixes #342 - Tar is included in macosx and homebrews package is gnutar which causes this to fail -- Add 12.04 to jdk8 test suite -- Add source and issues urls to supermarket -- Distinguishing the Java version for installing on the Mac OS X -- Doc and cruft cleanup +* Fix jce installation linux +* Allow overwrite `returns` property of windows_packages -## v1.39 - (1/14/2016) +## 3.1.0 - *2018-10-18* -- Travis debugging only, no code changes. +* Add support for JDK 11 -## v1.38 - (1/13/2016) +## 3.0.0 - *2018-10-18* -- (Win) Fix for Java install failing on Windows (introduced in #315) -- Travis fixes/badge +* Fix broken JCE with JRE installations +* make cert alias matching case insensitive as `keytool` always returns results downcases +* BREAKING CHANGE: fixed greedy matching by adding a word boundry when checking cert alias this prevents matching `foo_123` as `foo` +* verify artifact after downloading from oracle +* fixed `recipes/openjdk` when `node['java']['jdk_version']` by casting it to a string +* Updated Oracle Java links to 8u191 -## v1.37 - (11/9/2015) +## 2.2.1 - *2018-09-29* -- (Win) Attirbute for specifying the install directory for the public jre #315 +* Allows for additional Oracle (post 9) jdk download file naming, including '10.0.2'. '18.9', '11' -## v1.36 - (9/3/2015) +## 2.2.0 - *2018-07-19* -- Oracle JDK 1.8.0_65 -- Add Ubuntu ppa (allows OpenJDK 8) -- Added ChefSpec matchers #284 -- Fix compile error using Chef::Application.fatal #279 -- #222 Provide possibility to set ark download timeout -- Openjdk6 does not exist in deb 8.2 -- Change to create java home dir even if top level doesn't exist(Eg mkdir_p instead of mkdir) -- Fix berks url and remove apt -- Documentation and dependency updates +* Updated Oracle Java links to 8u181 +* Fixed incorrect kitchen setup runlists that preventing local testing +* Resolve undefined certout errors -## v1.35 - (8/4/2015) +## 2.1.0 - *2018-05-25* -- Use bento boxes and remove EOL distros from testing suite. -- Update to latest JDKs. Note Oracle JDK7 is now EOL. -- Alternatives improvements -- Fixes #155 to allow install of OpenJDK 1.8 -- Fixes #257 Changed switches for the jdk 8 exe installer on windows -- Make sure tar package installed for java_ark -- Add support for Mac OS X "mac_os_x" via homebrew. -- Update metadata.rb to contain source and issue information for supermarket and chef-repo convenience +* Added Java 10 JCE attributes to default attrs +* Update oracle recipeM to not perform a switch on java major version and instead use the version provided in attributes. This allows end users to include new Java versions without the cookbook requiring an update each time a major version gets released +* Updated the oracle_install resource to pick up semantic versioning that Oracle has started using for Java 10+ +* Updated the default attributes file to include x86_64 endpoint and checksum for Oracle Java 10\. The i586 version is not (yet) available. +* Fix JCE installation on Windows +* Avoid EmptyWindowsCommand error on Windows + +## v2.0.1 - *2018-05-02* + +* Fix java_certificate and java_oracle_install to work on FIPS enabled systems + +## v2.0.0 - *2018-05-02* + +* Converted alternatives, ark, and certificate LWRP/HWRPs to custom resources with improved logging and convergence notification. +* Renamed the java_ark resource to java_oracle_install, which better represents what it does. The existing name will continue to function +* Removed the need for the apt cookbook and instead require Chef 12.9+ +* Fixed Amazon Linux support on Chef 13+. +* Fixed the alternatives commands on Fedora systems. +* Added initial openSUSE leap support. +* Updated code to use multi-package installs to speed up runs +* Made the 'cert_alias' property in the certificate resource the name_property to allow users to avoid resource cloning and to be able to use friendly resource names +* Moved the warning code for downloading directly from Oracle into the resource to prevent another resource showing as converged +* Updated the metadata to resolve failures to parse chef_version on older chef-client releases. +* Added installation of tar directly to the ark resource when uncompression .tar.gz files. This prevents installation in the recipe that occurred even if tar wasn't needed. +* Add support for Mac OS X "mac_os_x" via homebrew. +* Update metadata.rb to contain source and issue information for supermarket and chef-repo convenience ### Known Issues -- Kitchen CI test with 12.04 fails due to hostname unable to be set. +* Kitchen CI test with 12.04 fails due to hostname unable to be set. -## v1.31 - (2/3/2015) +## v1.31 - *2/3/2015* -- Update to latest JDKs for 7 and 8\. JDK7 will be EOL April 2015 -- Fix up Travis support. -- Add ability to install JCE policy files for oracle JDK #228 -- Change connect timeout to 30 seconds +* Update to latest JDKs for 7 and 8\. JDK7 will be EOL April 2015 +* Fix up Travis support. +* Add ability to install JCE policy files for oracle JDK #228 +* Change connect timeout to 30 seconds -## v1.29.0 - (11/14/2014) +## v1.29.0 - *11/14/2014* -- **[#216](https://github.com/agileorbit-cookbooks/java/pull/216)** - Ensure dirs, links, and jinfo files are owned correctly -- **[#217](https://github.com/agileorbit-cookbooks/java/pull/217)** - Update to Oracle JDK 8u25 -- **[#214](https://github.com/agileorbit-cookbooks/java/pull/214)** - Update to Oracle JDK 7u71-b14 -- Adding a connect_timeout option for downloading java. -- Switched to chef-zero provisioner in test suites. -- Adding ISSUES.md for guidance on creating new issues for the Java cookbook. -- Fix IBM unit tests. +* Ensure dirs, links, and jinfo files are owned correctly +* Update to Oracle JDK 8u25 +* Update to Oracle JDK 7u71-b14 +* Adding a connect_timeout option for downloading java. +* Switched to chef-zero provisioner in test suites. +* Adding ISSUES.md for guidance on creating new issues for the Java cookbook. +* Fix IBM unit tests. -## v1.28.0 - (9/6/2014) +## v1.28.0 - *9/6/2014* -- Allow setting of group to extracted java files. -- Add -no-same-owner parameter to tar extract to avoid issues when the chef cache dir is on an NFS mounted drive. -- In the ark provider, it doesn't compare the MD5 sum with the right value which causes Java cookbook always download tarball from oracle server +* Allow setting of group to extracted java files. +* Add -no-same-owner parameter to tar extract to avoid issues when the chef cache dir is on an NFS mounted drive. +* In the ark provider, it doesn't compare the MD5 sum with the right value which causes Java cookbook always download tarball from oracle server -## v1.27.0 - (8/22/2014) +## v1.27.0 - *8/22/2014* -- Update Oracle JDK8 to version 8u20 +* Update Oracle JDK8 to version 8u20 -## v1.26.0 - (8/16/2014) +## v1.26.0 - *8/16/2014* -- **[#201](https://github.com/agileorbit-cookbooks/java/pull/201)** - Allow pinning of package versions for openjdk -- **[#198](https://github.com/agileorbit-cookbooks/java/pull/198)** - Update Oracle JDK7 to version 7u67 -- **[#189](https://github.com/agileorbit-cookbooks/java/pull/184)** - Support specific version and name for Oracle RPM +* Allow pinning of package versions for openjdk +* Update Oracle JDK7 to version 7u67 +* Support specific version and name for Oracle RPM -## v1.25.0 - (8/1/2014) +## v1.25.0 - *8/1/2014* -- **[#189](https://github.com/agileorbit-cookbooks/java/pull/189)** - Resource ark -> attribute bin_cmds default value -- **[#168](https://github.com/agileorbit-cookbooks/java/pull/168)** - Add option to put JAVA_HOME in /etc/environment -- **[#172](https://github.com/agileorbit-cookbooks/java/pull/172)** - Allow ark to pull from http and files ending in .gz. -- Recommendations for inclusion in community cookbooks -- Production Deployment with Oracle Java -- Update testing instructions for chefdk -- Various Readme formatting. -- Use Supermarket endpoint in berksfile -- rspec cleanup -- Adding ubuntu-14.04 to test suite +* Resource ark -> attribute bin_cmds default value +* Add option to put JAVA_HOME in /etc/environment +* Allow ark to pull from http and files ending in .gz. +* Recommendations for inclusion in community cookbooks +* Production Deployment with Oracle Java +* Update testing instructions for chefdk +* Various Readme formatting. +* Use Supermarket endpoint in berksfile +* rspec cleanup +* Adding ubuntu-14.04 to test suite -## v1.24.0 - (7/25/2014) +## v1.24.0 - *7/25/2014* New Cookbook maintainer! **[Agile Orbit](http://agileorbit.com)** -- **[#192](https://github.com/agileorbit-cookbooks/java/pull/192)** - Bump JDK7 URLs to 7u65 -- **[#191](https://github.com/agileorbit-cookbooks/java/pull/192)** - Upgrade Oracle's Java 8 to u11 -- **[#188](https://github.com/agileorbit-cookbooks/java/pull/188)** - Allow for alternatives priority to be set from attribute. -- **[#176](https://github.com/agileorbit-cookbooks/java/pull/176)** - Change ownership of extracted files -- **[#169](https://github.com/agileorbit-cookbooks/java/pull/169)** - Add retries and retry_delay parameters to java_ark LWRP -- **[#167](https://github.com/agileorbit-cookbooks/java/pull/167)** - default: don't fail when using java 8 on windows -- **[#165](https://github.com/agileorbit-cookbooks/java/pull/165)** - Support for Server JRE -- **[#158](https://github.com/agileorbit-cookbooks/java/pull/158)** - Updated README for accepting oracle terms -- **[#157](https://github.com/agileorbit-cookbooks/java/pull/157)** -Remove VirtualBox specific box_urls -- List AgileOrbit as the maintainer (AgileOrbit took over from Socrata in July 2014) +* Bump JDK7 URLs to 7u65 +* Upgrade Oracle's Java 8 to u11 +* Allow for alternatives priority to be set from attribute. +* Change ownership of extracted files +* Add retries and retry_delay parameters to java_ark LWRP +* default: don't fail when using java 8 on windows +* Support for Server JRE +* Updated README for accepting oracle terms +* Remove VirtualBox specific box_urls +* List AgileOrbit as the maintainer (AgileOrbit took over from Socrata in July 2014) -## v1.23.0 - (7/25/2014) +## v1.23.0 - *7/25/2014* -- Tagged but never published to community cookbooks. All changes rolled into 1.24.0 +* Tagged but never published to community cookbooks. All changes rolled into 1.24.0 ## v1.22.0 -- **[#148](https://github.com/socrata-cookbooks/java/pull/148)** - Add support for Oracle JDK 1.8.0 -- **[#150](https://github.com/socrata-cookbooks/java/pull/150)** - Make use of Chef's cache directory instead of /tmp -- **[#151](https://github.com/socrata-cookbooks/java/pull/151)** - Update Test Kitchen suites -- **[#154](https://github.com/socrata-cookbooks/java/pull/154)** - Add safety check for JDK 8 on non-Oracle +* Add support for Oracle JDK 1.8.0 +* Make use of Chef's cache directory instead of /tmp +* Update Test Kitchen suites +* Add safety check for JDK 8 on non-Oracle ## v1.21.2 -- **[#146](https://github.com/socrata-cookbooks/java/pull/146)** - Update Oracle accept-license-terms cookie format +[COOK-4210] - remove unneeded run_command to prevent zombie processes ## v1.21.0 -- **[#143](https://github.com/socrata-cookbooks/java/pull/143)** - Symlink /usr/lib/jvm/default-java for both OpenJDK and Oracle -- **[#144](https://github.com/socrata-cookbooks/java/pull/144)** - Remove /var/lib/alternatives/#{cmd} before calling alternatives (Hopefully fixes sporadic issues when setting alternatives) -- **[Make default_java_symlink conditional on set_default attribute](https://github.com/socrata-cookbooks/java/commit/e300e235a463382a5022e1dddaac674930b4d138)** +* Update Oracle accept-license-terms cookie format ## v1.20.0 -- **[#137](https://github.com/socrata-cookbooks/java/pull/137)** - Create /usr/lib/jvm/default-java on Debian -- **[#138](https://github.com/socrata-cookbooks/java/pull/138)** - allow wrapping cookbook without providing templates -- **[#140](https://github.com/socrata-cookbooks/java/pull/140)** - Adds set_default attribute to toggle setting JDK as default -- **[#141](https://github.com/socrata-cookbooks/java/pull/141)** - set java_home correctly for oracle_rpm - -## v1.19.2 - -- **[#129](https://github.com/socrata-cookbooks/java/pull/129)** - Upgrade to ChefSpec 3 -- Rewrite unit tests for better coverage and to work with ChefSpec 3 (various commits) -- List Socrata as the maintainer (Socrata took over from Opscode in December 2013) -- **[#133](https://github.com/socrata-cookbooks/java/pull/133)** - Allow jdk_version to be a string or number -- **[#131](https://github.com/socrata-cookbooks/java/pull/131)** - Fix JDK install on Windows -- **[Fix openjdk_packages on Arch Linux](https://github.com/socrata-cookbooks/java/commit/677bee7b9bf08988596d40ac65e75984a86bda99)** - -## v1.19.0 - -Refactor the cookbook to better support wrapper cookbooks and other cookbook authoring patterns. - -- **[#123](https://github.com/socrata-cookbooks/java/pull/123)** - Update documentation & add warning for issue 122 -- **[#124](https://github.com/socrata-cookbooks/java/pull/124)** - Refactor default recipe to better enable wrapper cookbooks -- **[#125](https://github.com/socrata-cookbooks/java/pull/125)** - Removes the attribute to purge deprecated packages -- **[#127](https://github.com/socrata-cookbooks/java/pull/127)** - Add safety check if attributes are unset -- **[Adds tests for directly using openjdk and oracle recipes](https://github.com/socrata-cookbooks/java/commit/794df596959d65a1a6d5f6c52688bffd8de6bff4)** -- **[Adds recipes to README](https://github.com/socrata-cookbooks/java/commit/76d52114bb9df084174d43fed143123b1cdbae16)** -- **[The Opscode CCLA is no longer required](https://github.com/socrata-cookbooks/java/commit/ce4ac25caa8383f185c25c4e32cafef8c0453376)** -- **[Adds tests for openjdk-7 and oracle-7](https://github.com/socrata-cookbooks/java/commit/9c38af241f68b3198cde4ad6fe2b4cb752062009)** -- **[#119](https://github.com/socrata-cookbooks/java/pull/119)** - Use java_home instead of java_location for update-alternatives -- **[Fix java_home for rhel and fedora](https://github.com/socrata-cookbooks/java/commit/71dadbd1bfe2eab50ff21cdab4ded97877911cc4)** - -## v1.18.0 - -- **[#118](https://github.com/socrata-cookbooks/java/pull/118)** - Upgrade to 7u51 -- **[#117](https://github.com/socrata-cookbooks/java/pull/117)** - Suggest windows and aws - -## v1.17.6 - -- Revert **[COOK-4165](https://tickets.opscode.com/browse/COOK-4165)** - The headers option was only added to remote_file in Chef 11.6.0, meaning this change breaks older clients. - -## v1.17.4 - -### Bug - -- **[#111](https://github.com/socrata-cookbooks/java/pull/111)** - Fix alternatives for centos - -### Improvement - -- **[COOK-4165](https://tickets.opscode.com/browse/COOK-4165)** - Replace curl with remote_file with cookie header -- **[#110](https://github.com/socrata-cookbooks/java/pull/110)** - Update openjdk to use the alternatives resource - -## v1.17.2 - -### Bug - -- **[COOK-4136](https://tickets.opscode.com/browse/COOK-4136)** - Add md5 parameter to java_ark resource - -## v1.17.0 - -- **[COOK-4114](https://tickets.opscode.com/browse/COOK-4114)** - Test Kitchen no longer works after merging Pull Request #95 for openjdk tests on Debian/Ubuntu -- **[COOK-4124](https://tickets.opscode.com/browse/COOK-4124)** - update-alternatives fails to run -- **[#81](https://github.com/socrata/java/pull/81)** - Ensure local directory hierarchy -- **[#97](https://github.com/socrata/java/pull/97)** - Expose LWRP state attributes -- **[#99](https://github.com/socrata/java/pull/99)** - support for MD5 checksum -- **[#106](https://github.com/socrata/java/pull/106)** - Fixed windows case to prevent bad java_home variable setting -- **[Update checksums to the officially-published ones from Oracle](https://github.com/socrata/java/commit/b9e1df24caeb6e22346d2d415b3b4384f15d4ffd)** -- **[Further test kitchen fixes to use the default recipe](https://github.com/socrata/java/commit/01c0b432705d9cfa6d2dfeaa380983e3f604069f)** - -## v1.16.4 - -### Bug - -- **[#103](https://github.com/socrata/java/pull/103)** - set alternatives when using ibm_tar recipe -- **[#104](https://github.com/socrata/java/pull/104)** - Specify windows attributes in attribute files - -## v1.16.2 - -### Improvement - -- **[COOK-3488](https://tickets.opscode.com/browse/COOK-3488)** - set alternatives for ibm jdk -- **[COOK-3764](https://tickets.opscode.com/browse/COOK-3764)** - IBM Java installer needs 'rpm' package on Ubuntu - -### Bug - -- **[COOK-3857](https://tickets.opscode.com/browse/COOK-3857)** - do not unescape the java windows url before parsing it -- **[#95](https://github.com/socrata/java/pull/95)** - fixes update-alternatives for openjdk installs -- **[#100](https://github.com/socrata/java/pull/100)** - Use escaped quotes for Windows INSTALLDIR - -## v1.16.0 - -### Improvement - -- **[COOK-3823](https://tickets.opscode.com/browse/COOK-3823)** - Upgrade to JDK 7u45-b18 - -## v1.15.4 - -[COOK-4210] - remove unneeded run_command to prevent zombie processes - -## v1.15.2 - -[CHEF-4210] remove unneeded run_command to prevent zombie processes - -## v1.15.0 - -### Bug - -- Fixing version number. Accidently released at 0.15.x instead of 1.15.x +* Fixing version number. Accidently released at 0.15.x instead of 1.15.x ## v0.15.2 ### FIX -- [COOK-3908] - Fixing JAVA_HOME on Ubuntu 10.04 +* Fixing JAVA_HOME on Ubuntu 10.04 ## v1.14.0 -### Bug - -- **[COOK-3704](https://tickets.opscode.com/browse/COOK-3704)** - Fix alternatives when the package is already installed -- **[COOK-3668](https://tickets.opscode.com/browse/COOK-3668)** - Fix a condition that would result in an error executing action `run` on resource 'bash[update-java-alternatives]' -- **[COOK-3569](https://tickets.opscode.com/browse/COOK-3569)** - Fix bad checksum length -- **[COOK-3541](https://tickets.opscode.com/browse/COOK-3541)** - Fix an issue where Java cookbook installs both JDK 6 and JDK 7 when JDK 7 is specified -- **[COOK-3518](https://tickets.opscode.com/browse/COOK-3518)** - Allow Windoes recipe to download from signed S3 url -- **[COOK-2996](https://tickets.opscode.com/browse/COOK-2996)** - Fix a failure on Centos 6.4 and Oracle JDK 7 - -### Improvement - -- **[COOK-2793](https://tickets.opscode.com/browse/COOK-2793)** - Improve Windows support +* Fix alternatives when the package is already installed +* Fix a condition that would result in an error executing action `run` on resource 'bash[update-java-alternatives]' +* Fix bad checksum length +* Fix an issue where Java cookbook installs both JDK 6 and JDK 7 when JDK 7 is specified +* Allow Windoes recipe to download from signed S3 url +* Fix a failure on Centos 6.4 and Oracle JDK 7 +* Improve Windows support ## v1.13.0 -### Bug - -- **[COOK-3295](https://tickets.opscode.com/browse/COOK-3295)** - Add default `platform_family` option in Java helper -- **[COOK-3277](https://tickets.opscode.com/browse/COOK-3277)** - Fix support for Fedora - -### Improvement - -- **[COOK-3278](https://tickets.opscode.com/browse/COOK-3278)** - Upgrade to Oracle Java 7u25 -- **[COOK-3029](https://tickets.opscode.com/browse/COOK-3029)** - Add Oracle RPM support -- **[COOK-2931](https://tickets.opscode.com/browse/COOK-2931)** - Add support for the platform `xenserver` -- **[COOK-2154](https://tickets.opscode.com/browse/COOK-2154)** - Add SmartOS support +* Add default `platform_family` option in Java helper +* Fix support for Fedora +* Upgrade to Oracle Java 7u25 +* Add Oracle RPM support +* Add support for the platform `xenserver` +* Add SmartOS support ## v1.12.0 -### Improvement - -- [COOK-2154]: Add SmartOS support to java::openjdk recipe -- [COOK-3278]: upgrade to Oracle Java 7u25 -- [COOK-2931]: Adding support for the platform 'xenserver' (for installations of java in DOM0) -- [COOK-3277]: java cookbook fails on Fedora +* Add SmartOS support to java::openjdk recipe +* upgrade to Oracle Java 7u25 +* Adding support for the platform 'xenserver' (for installations of java in DOM0) +* java cookbook fails on Fedora ## v1.11.6 -- [COOK-2847]: Java cookbook does not have opensuse support -- [COOK-3142]: Syntax Errors spec/default_spec.rb:4-8 +* Java cookbook does not have opensuse support +* Syntax Errors spec/default_spec.rb:4-8 ## v1.11.4 -- [COOK-2989]: `bash[update-java-alternatives]` resource uses wrong attribute +* `bash[update-java-alternatives]` resource uses wrong attribute ## v1.11.2 -- Use SHA256 checksums for Oracle downloads, not SHA1. +* Use SHA256 checksums for Oracle downloads, not SHA1. ## v1.11.0 This version brings a wealth of tests and (backwards-compatible) refactoring, plus some new features (updated Java, IBM recipe). -- [COOK-2897]: Add ibm recipe to java cookbook -- [COOK-2903]: move java_home resources to their own recipe -- [COOK-2904]: refactor ruby_block "update-java-alternatives" -- [COOK-2905]: use platform_family in java cookbook -- [COOK-2920]: add chefspec to java cookbook -- [COOK-2902]: Refactor java cookbook -- [COOK-2900]: update JDK to JDK 7u21, 6u45 +* Add ibm recipe to java cookbook +* move java_home resources to their own recipe +* refactor ruby_block "update-java-alternatives" +* use platform_family in java cookbook +* add chefspec to java cookbook +* Refactor java cookbook +* update JDK to JDK 7u21, 6u45 ## v1.10.2 -- [COOK-2415] - Fixed deprecation warnings in ark provider and openjdk recipe by using Chef::Mixin::ShellOut instead of Chef::ShellOut +* [2415] - Fixed deprecation warnings in ark provider and openjdk recipe by using Chef::Mixin::ShellOut instead of Chef::ShellOut ## v1.10.0 -- [COOK-2400] - Allow java ark :url to be https -- [COOK-2436] - Upgrade needed for oracle jdk in java cookbook +* Allow java ark :url to be https +* Upgrade needed for oracle jdk in java cookbook ## v1.9.6 -- [COOK-2412] - add support for Oracle Linux +* add support for Oracle Linux ## v1.9.4 -- [COOK-2083] - Run set-env-java-home in Java cookbook only if necessary -- [COOK-2332] - ark provider does not allow for *.tgz tarballs to be used -- [COOK-2345] - Java cookbook fails on CentOS6 (update-java-alternatives) +* Run set-env-java-home in Java cookbook only if necessary +* ark provider does not allow for *.tgz tarballs to be used +* Java cookbook fails on CentOS6 (update-java-alternatives) ## v1.9.2 -- [COOK-2306] - FoodCritic fixes for java cookbook +* FoodCritic fixes for java cookbook ## v1.9.0 -- [COOK-2236] - Update the Oracle Java version in the Java cookbook to release 1.7u11 +* Update the Oracle Java version in the Java cookbook to release 1.7u11 ## v1.8.2 -- [COOK-2205] - Fix for missing /usr/lib/jvm/default-java on Debian +* Fix for missing /usr/lib/jvm/default-java on Debian ## v1.8.0 -- [COOK-2095] - Add windows support +* Add windows support ## v1.7.0 -- [COOK-2001] - improvements for Oracle update-alternatives - - When installing an Oracle JDK it is now registered with a higher priority than OpenJDK. (Related to COOK-1131.) - - When running both the oracle and oracle_i386 recipes, alternatives are now created for both JDKs. - - Alternatives are now created for all binaries listed in version specific attributes. (Related to COOK-1563 and COOK-1635.) - - When installing Oracke JDKs on Ubuntu, create .jinfo files for use with update-java-alternatives. Commands to set/install alternatives now only run if needed. +* improvements for Oracle update-alternatives +* When installing an Oracle JDK it is now registered with a higher priority than OpenJDK. (Related to COOK-1131.) +* When running both the oracle and oracle_i386 recipes, alternatives are now created for both JDKs. +* Alternatives are now created for all binaries listed in version specific attributes. (Related to COOK-1563 and COOK-1635.) +* When installing Oracke JDKs on Ubuntu, create .jinfo files for use with update-java-alternatives. Commands to set/install alternatives now only run if needed. ## v1.6.4 -- [COOK-1930] - fixed typo in attribute for java 5 on i586 +* fixed typo in attribute for java 5 on i586 ## v1.6.2 -- whyrun support in `java_ark` LWRP -- CHEF-1804 compatibility -- [COOK-1786] - install Java 6u37 and Java 7u9 -- [COOK-1819] - incorrect warning text about `node['java']['oracle']['accept_oracle_download_terms']` +* whyrun support in `java_ark` LWRP +* CHEF-1804 compatibility +* install Java 6u37 and Java 7u9 +* incorrect warning text about `node['java']['oracle']['accept_oracle_download_terms']` ## v1.6.0 -- [COOK-1218] - Install Oracle JDK from Oracle download directly -- [COOK-1631] - set JAVA_HOME in openjdk recipe -- [COOK-1655] - Install correct architecture on Amazon Linux +* Install Oracle JDK from Oracle download directly +* set JAVA_HOME in openjdk recipe +* Install correct architecture on Amazon Linux ## v1.5.4 -- [COOK-885] update alternatives called on wrong file -- [COOK-1607] use shellout instead of execute resource to update alternatives +update alternatives called on wrong file +use shellout instead of execute resource to update alternatives ## v1.5.2 -- [COOK-1200] - remove sun-java6-jre on Ubuntu before installing Oracle's Java -- [COOK-1260] - fails on Ubuntu 12.04 64bit with openjdk7 -- [COOK-1265] - Oracle Java should symlink the jar command +* remove sun-java6-jre on Ubuntu before installing Oracle's Java +* fails on Ubuntu 12.04 64bit with openjdk7 +* Oracle Java should symlink the jar command ## v1.5.0 -- [COOK-1146] - Oracle now prevents download of JDK via non-browser -- [COOK-1114] - fix File.exists? +* Oracle now prevents download of JDK via non-browser +* fix File.exists? ## v1.4.2 -- [COOK-1051] - fix attributes typo and platform case switch consistency +* fix attributes typo and platform case switch consistency ## v1.4.0 -- [COOK-858] - numerous updates: handle jdk6 and 7, switch from sun to oracle, make openjdk default, add `java_ark` LWRP. -- [COOK-942] - FreeBSD support -- [COOK-520] - ArchLinux support +* numerous updates: handle jdk6 and 7, switch from sun to oracle, make openjdk default, add `java_ark` LWRP. +* [42] - FreeBSD support +* ArchLinux support diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a946aea14..c76e180fc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ # Contributing Please refer to -[https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) +[https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/CONTRIBUTING.MD](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/CONTRIBUTING.MD) diff --git a/Dangerfile b/Dangerfile index 140c4da2c..bc08b7aeb 100644 --- a/Dangerfile +++ b/Dangerfile @@ -18,7 +18,7 @@ def code_changes? end def test_changes? - tests = %w(spec test .kitchen.yml .kitchen.dokken.yml) + tests = %w(spec test kitchen.yml kitchen.dokken.yml) tests.each do |location| return true unless git.modified_files.grep(/#{location}/).empty? end @@ -36,6 +36,11 @@ if !git.modified_files.include?('CHANGELOG.md') && code_changes? failure 'Please include a CHANGELOG entry.' end +# Require Major Minor Patch version labels +unless github.pr_labels.grep /minor|major|patch/i + warn 'Please add a release label to this pull request' +end + # A sanity check for tests. if git.lines_of_code > 5 && code_changes? && !test_changes? warn 'This Pull Request is probably missing tests.' diff --git a/Policyfile.rb b/Policyfile.rb new file mode 100644 index 000000000..9fea7a53d --- /dev/null +++ b/Policyfile.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +name 'java' + +cookbook 'java', path: '.' +cookbook 'test', path: 'test/fixtures/cookbooks/test' + +run_list 'test::base' + +named_run_list :base, 'test::base' +named_run_list :openjdk, 'test::openjdk' +named_run_list :openjdk_pkg, 'test::openjdk_pkg' +named_run_list :temurin_pkg, 'test::temurin_pkg' +named_run_list :corretto, 'test::corretto' +named_run_list :java_cert, 'test::java_cert' diff --git a/README.md b/README.md index 9f4489bfa..656647478 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors) [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) -This cookbook installs a Java JDK/JRE. It defaults to installing OpenJDK, but it can also install Oracle, IBM JDKs or AdoptOpenJDK. +This cookbook installs a Java JDK/JRE. It defaults to installing [OpenJDK](https://openjdk.java.net/), but it can also install [Eclipse Temurin](https://adoptium.net/temurin/) and [Amazon Corretto](https://corretto.aws/). ## Maintainers @@ -16,7 +16,7 @@ This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of ## Requirements -Chef 15+ +Chef 15.3+ ### Platforms @@ -25,15 +25,14 @@ Chef 15+ ## Resources -- [adoptopenjdk_install](https://github.com/sous-chefs/java/blob/master/documentation/resources/adoptopenjdk_install.md) -- [adoptopenjdk_linux_install](https://github.com/sous-chefs/java/blob/master/documentation/resources/adoptopenjdk_linux_install.md) -- [adoptopenjdk_macos_install](https://github.com/sous-chefs/java/blob/master/documentation/resources/adoptopenjdk_macos_install.md) - [alternatives](https://github.com/sous-chefs/java/blob/master/documentation/resources/alternatives.md) - [certificate](https://github.com/sous-chefs/java/blob/master/documentation/resources/certificate.md) - [corretto_install](https://github.com/sous-chefs/java/blob/master/documentation/resources/corretto_install.md) - [jce](https://github.com/sous-chefs/java/blob/master/documentation/resources/jce.md) - [openjdk_install](https://github.com/sous-chefs/java/blob/master/documentation/resources/openjdk_install.md) - [openjdk_pkg_install](https://github.com/sous-chefs/java/blob/master/documentation/resources/openjdk_pkg_install.md) +- [openjdk_source_install](https://github.com/sous-chefs/java/blob/master/documentation/resources/openjdk_source_install.md) +- [temurin_package_install](https://github.com/sous-chefs/java/blob/master/documentation/resources/temurin_package_install.md) ## Contributors diff --git a/TESTING.md b/TESTING.md index 920e381f9..5a7d00191 100644 --- a/TESTING.md +++ b/TESTING.md @@ -1,3 +1,3 @@ # Testing -Please refer to [the community cookbook documentation on testing](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/TESTING.MD). +Please refer to [the community cookbook documentation on testing](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/TESTING.MD). diff --git a/bin/check_java_versions.rb b/bin/check_java_versions.rb new file mode 100755 index 000000000..d2a778eae --- /dev/null +++ b/bin/check_java_versions.rb @@ -0,0 +1,91 @@ +#!/usr/bin/env ruby + +require 'net/http' +require 'json' +require 'uri' + +TEMURIN_REPOS = { + '11' => 'adoptium/temurin11-binaries', + '17' => 'adoptium/temurin17-binaries', +}.freeze + +CORRETTO_REPOS = { + '11' => 'corretto-11', + '17' => 'corretto-17', +}.freeze + +def get_latest_release(repo) + uri = URI("https://api.github.com/repos/#{repo}/releases/latest") + response = Net::HTTP.get_response(uri) + + if response.is_a?(Net::HTTPSuccess) + JSON.parse(response.body) + else + puts "Failed to fetch release info for #{repo}: #{response.code} #{response.message}" + nil + end +end + +def verify_url(url) + uri = URI(url) + response = Net::HTTP.get_response(uri) + + case response + when Net::HTTPRedirection + location = response['location'] + puts " ✓ URL redirects successfully to: #{location}" + true + when Net::HTTPSuccess + puts ' ✓ URL is directly accessible' + true + else + puts " ✗ URL is not accessible: #{response.code} #{response.message}" + false + end +end + +def find_linux_x64_jdk(assets) + assets.find { |asset| asset['name'] =~ /OpenJDK\d+U-jdk_x64_linux_hotspot.*\.tar\.gz$/ } +end + +def check_versions + puts 'Checking Temurin versions...' + puts '-' * 50 + + TEMURIN_REPOS.each do |version, repo| + puts "\nChecking Java #{version}..." + release = get_latest_release(repo) + next unless release + + tag = release['tag_name'] + puts "Latest release: #{tag}" + + asset = find_linux_x64_jdk(release['assets']) + if asset + url = asset['browser_download_url'] + puts "Download URL: #{url}" + if verify_url(url) + puts 'Current version in cookbook needs updating!' if url != current_url_in_cookbook(version) + end + else + puts ' ✗ No Linux x64 JDK found in release assets' + end + end +end + +def current_url_in_cookbook(version) + # Read the current URLs from openjdk_helpers.rb + helpers_file = File.join(File.dirname(__FILE__), '..', 'libraries', 'openjdk_helpers.rb') + content = File.read(helpers_file) + + case version + when '11' + content.match(/temurin.*when '11'\s+'(.+?)'/m)&.[](1) + when '17' + content.match(/temurin.*when '17'\s+'(.+?)'/m)&.[](1) + end +end + +if __FILE__ == $PROGRAM_NAME + check_versions +end diff --git a/bin/check_temurin_versions.sh b/bin/check_temurin_versions.sh new file mode 100755 index 000000000..3532a21fd --- /dev/null +++ b/bin/check_temurin_versions.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# # Fetch latest Temurin versions from endoflife.date API +# curl --request GET \ +# --url https://endoflife.date/api/eclipse-temurin.json \ +# --header 'Accept: application/json' | jq '.' + +# Filter for LTS versions only +echo "LTS Versions:" +curl -s --request GET \ + --url https://endoflife.date/api/eclipse-temurin.json \ + --header 'Accept: application/json' | \ + jq -r '.[] | select(.lts == true) | "Java \(.cycle) (LTS) - Latest: \(.latest), EOL: \(.eol)"' diff --git a/chefignore b/chefignore index 7cc74609e..a27b0b258 100644 --- a/chefignore +++ b/chefignore @@ -9,10 +9,7 @@ ehthumbs.db Icon? nohup.out Thumbs.db - -# SASS # -######## -.sass-cache +.envrc # EDITORS # ########### @@ -26,10 +23,11 @@ Thumbs.db *.tmproj *~ \#* -mkmf.log REVISION TAGS* tmtags +.vscode +.editorconfig ## COMPILED ## ############## @@ -42,22 +40,29 @@ tmtags *.so */rdoc/ a.out +mkmf.log # Testing # ########### .circleci/* .codeclimate.yml +.delivery/* .foodcritic .kitchen* +.mdlrc +.overcommit.yml .rspec .rubocop.yml .travis.yml .watchr +.yamllint azure-pipelines.yml +Dangerfile examples/* features/* Guardfile -kitchen.yml* +kitchen*.yml +mlc_config.json Procfile Rakefile spec/* @@ -70,6 +75,7 @@ test/* .gitconfig .github/* .gitignore +.gitkeep .gitmodules .svn */.bzr/* @@ -95,12 +101,13 @@ Gemfile.lock Policyfile.rb Policyfile.lock.json -# Cookbooks # +# Documentation # ############# -CHANGELOG* +CODE_OF_CONDUCT* CONTRIBUTING* +documentation/* TESTING* -CODE_OF_CONDUCT* +UPGRADING* # Vagrant # ########### diff --git a/documentation/.gitkeep b/documentation/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/documentation/resources/adoptopenjdk_install.md b/documentation/resources/adoptopenjdk_install.md deleted file mode 100644 index 88ff04a88..000000000 --- a/documentation/resources/adoptopenjdk_install.md +++ /dev/null @@ -1,49 +0,0 @@ -[back to resource list](https://github.com/sous-chefs/java#resources) - -# adoptopenjdk_install - -Introduced: v7.0.0 - -## Actions - -- `:install` -- `:remove` - -## Properties - -| Name | Type | Default | Description | -| --------------------- | ----------------- | ------- | -------------------------------------------------------------- | -| version | String | | Java version to install | -| variant | String | | Install flavour', default: 'openj9 | -| url | String | | The URL to download from | -| checksum | String | | The checksum for the downloaded file | -| java_home | String | | Set to override the java_home | -| java_home_mode | String | | The permission for the Java home directory | -| java_home_owner | String | | Owner of the Java Home | -| java_home_group | String | | Group for the Java Home | -| default | [true, false] | | Whether to set this as the defalut Java | -| bin_cmds | Array | | A list of bin_cmds based on the version and variant | -| alternatives_priority | Integer | | Alternatives priority to set for this Java | -| reset_alternatives | [true, false] | | Whether to reset alternatives before setting | -| tap_full | [true, false] | `true` | Perform a full clone on the tap, as opposed to a shallow clone | -| tap_url | String, | | The URL of the tap | -| cask_options | String, | | Options to pass to the brew command during installation | -| homebrew_path | String, | | The path to the homebrew binary | -| owner | [String, Integer] | | The owner of the Homebrew installation | - -## Examples - -To install Hotspot AdoptOpenJDK 11 and set it as the default Java - -```ruby -adoptopenjdk_install '11' -``` - -To install hotspot AdoptOpenJDK 11 and set it as second highest priority - -```ruby -adoptopenjdk_install '10' do - variant 'hotspot' - alternatives_priority 2 -end -``` diff --git a/documentation/resources/adoptopenjdk_linux_install.md b/documentation/resources/adoptopenjdk_linux_install.md deleted file mode 100644 index 9b8e9f5dd..000000000 --- a/documentation/resources/adoptopenjdk_linux_install.md +++ /dev/null @@ -1,42 +0,0 @@ -[back to resource list](https://github.com/sous-chefs/java#resources) - -# adoptopenjdk_linux_install - -Introduced: v8.1.0 - -## Actions - -- `:install` -- `:remove` - -## Properties - -| Name | Type | Default | Description | -| --------------------- | ------------- | ---------------------------------------------------------------------- | ----------------------------------------------------- | -| variant | String | `openj9` | Install flavour | -| url | String | `default_adopt_openjdk_url(version)[variant]` | The URL to download from | -| checksum | String | `default_adopt_openjdk_checksum(version)[variant]` | The checksum for the downloaded file | -| java_home | String | `/usr/lib/jvm/java-#{version}-adoptopenjdk-#{variant}/#{sub_dir(url)}` | Set to override the java_home | -| java_home_mode | String | | Owner of the Java Home | -| java_home_group | String | `node['root_group']` | Group for the Java Home | -| default | [true, false] | `true` | Whether to set this as the defalut Java | -| bin_cmds | Array | `default_adopt_openjdk_bin_cmds(version)[variant]` | A list of `bin_cmds` based on the version and variant | -| alternatives_priority | Integer | `1` | Alternatives priority to set for this Java | -| reset_alternatives | [true, false] | `true` | Whether to reset alternatives before setting | - -## Examples - -To install Hotspot AdoptOpenJDK 11 and set it as the default Java - -```ruby -adoptopenjdk_linux_install1 '11' -``` - -To install hotspot AdoptOpenJDK 11 and set it as second highest priority - -```ruby -adoptopenjdk_linux_install1 '10' do - variant 'hotspot' - alternatives_priority 2 -end -``` diff --git a/documentation/resources/adoptopenjdk_macos_install.md b/documentation/resources/adoptopenjdk_macos_install.md deleted file mode 100644 index a8b718510..000000000 --- a/documentation/resources/adoptopenjdk_macos_install.md +++ /dev/null @@ -1,65 +0,0 @@ -[back to resource list](https://github.com/sous-chefs/java#resources) - -# adoptopenjdk_macos_install - -Introduced: v8.1.0 - -## Actions - -- `:install` -- `:remove` - -## Properties - -| Name | Type | Default | Description | Allowed Values | -| ------------- | ----------------- | -------------------------- | -------------------------------------------------------------- | -| tap_full | [true, false] | `true` | Perform a full clone on the tap, as opposed to a shallow clone | -| tap_url | String | | The URL of the tap | -| cask_options | String | | Options to pass to the brew command during installation | -| homebrew_path | String | | The path to the homebrew binary | -| owner | [String, Integer] | | The owner of the Homebrew installation | -| java_home | String | `macos_java_home(version)` | MacOS specific JAVA_HOME | -| version | String | `adoptopenjdk14` | | See list below | - -## Allowed Install Versions - -- adoptopenjdk8 -- adoptopenjdk8-openj9 -- adoptopenjdk8-openj9-large -- adoptopenjdk8-jre -- adoptopenjdk8-openj9-jre -- adoptopenjdk8-jre-large -- adoptopenjdk9 -- adoptopenjdk10 -- adoptopenjdk11 -- adoptopenjdk11-openj9 -- adoptopenjdk11-openj9-large -- adoptopenjdk11-jre -- adoptopenjdk11-openj9-jre -- adoptopenjdk11-openj9-jre-large -- adoptopenjdk12 -- adoptopenjdk12-openj9 -- adoptopenjdk12-openj9-large -- adoptopenjdk12-jre -- adoptopenjdk12-openj9-jre -- adoptopenjdk12-openj9-jre-large -- adoptopenjdk13 -- adoptopenjdk13-openj9 -- adoptopenjdk13-openj9-large -- adoptopenjdk13-jre -- adoptopenjdk13-openj9-jre -- adoptopenjdk13-openj9-jre-large -- adoptopenjdk14 -- adoptopenjdk14-openj9 -- adoptopenjdk14-openj9-large -- adoptopenjdk14-jre -- adoptopenjdk14-openj9-jre -- adoptopenjdk14-openj9-jre-large - -## Examples - -To install Hotspot AdoptOpenJDK 11 and set it as the default Java - -```ruby -adoptopenjdk_macos_install 'adoptopenjdk14-jre' -``` diff --git a/documentation/resources/alternatives.md b/documentation/resources/alternatives.md index fabc67e7e..cb599c9d1 100644 --- a/documentation/resources/alternatives.md +++ b/documentation/resources/alternatives.md @@ -1,7 +1,8 @@ -[back to resource list](https://github.com/sous-chefs/java#resources) # java_alternatives +[back to resource list](https://github.com/sous-chefs/java#resources) + The `java_alternatives` resource uses `update-alternatives` command to set and unset command alternatives for various Java tools such as java, javac, etc. ## Actions @@ -14,10 +15,10 @@ The `java_alternatives` resource uses `update-alternatives` command to set and u | Name | Type | Default | Description | | -------------------- | ------------- | ------- | ---------------------------------------------------------------------------- | | `java_location` | `String` | | Java installation location | -| `bin_cmds` | `String` | | Array of Java tool names to set or unset alternatives on | +| `bin_cmds` | `Array` | | Array of Java tool names to set or unset alternatives on | | `default` | `true, false` | `true` | Whether to set the Java tools as system default. Boolean, defaults to `true` | | `priority` | `Integer` | `1061` | Priority of the alternatives. Integer, defaults to `1061` | -| `reset_alternatives` | `true, false` | `true` | Whether to reset alternatives before setting them | +| `reset_alternatives` | `true, false` | `false` | Whether to reset alternatives before setting them | - `java_location`: Java installation location. - `bin_cmds`: . @@ -28,7 +29,7 @@ The `java_alternatives` resource uses `update-alternatives` command to set and u ```ruby java_alternatives "set java alternatives" do - java_location '/usr/local/java' - bin_cmds ["java", "javac"] + java_location '/usr/local/java' + bin_cmds ["java", "javac"] end ``` diff --git a/documentation/resources/certificate.md b/documentation/resources/certificate.md index 681e44495..864c0c873 100644 --- a/documentation/resources/certificate.md +++ b/documentation/resources/certificate.md @@ -1,7 +1,8 @@ -[back to resource list](https://github.com/sous-chefs/java#resources) # java_certificate +[back to resource list](https://github.com/sous-chefs/java#resources) + Java certificate simplifies adding certificates to a java keystore. It can also populate the keystore with a certificate retrieved from a given SSL end-point. @@ -12,16 +13,17 @@ It can also populate the keystore with a certificate retrieved from a given SSL ## Properties -| Name | Type | Default | Description | -| ----------------- | ------ | --------------------------- | --------------------------------------------------------------------------------------- | -| `java_home` | | node['java']['java_home'] | The java home directory | -| `java_version` | | node['java']['jdk_version'] | The java version | -| `keystore_path` | String | | Path to the keystore | -| `keystore_passwd` | String | `changeit` | Password to the keystore | -| `cert_alias` | String | | The alias of the certificate in the keystore. This defaults to the name of the resource | -| `cert_data` | String | | The certificate data to install | -| `cert_file` | String | | Path to a certificate file to install | -| `ssl_endpoint` | String | | An SSL end-point from which to download the certificate | +| Name | Type | Default | Description | +| --- | --- | --- | --- | +| `java_home` | String | Platform-specific path for `java_version` | The java home directory | +| `java_version` | String | `17` | The java version | +| `keystore_path` | String | | Path to the keystore | +| `keystore_passwd` | String | `changeit` | Password to the keystore | +| `cert_alias` | String | | The alias of the certificate in the keystore. This defaults to the name of the resource | +| `cert_data` | String | | The certificate data to install | +| `cert_file` | String | | Path to a certificate file to install | +| `ssl_endpoint` | String | | An SSL end-point from which to download the certificate | +| `starttls` | String | | Control the TLS protocol handler when fetching a remote certificate from `ssl_endpoint` | ## Examples diff --git a/documentation/resources/corretto_install.md b/documentation/resources/corretto_install.md index 48132fb25..58e9fddf9 100644 --- a/documentation/resources/corretto_install.md +++ b/documentation/resources/corretto_install.md @@ -1,7 +1,10 @@ -[back to resource list](https://github.com/sous-chefs/java#resources) # corretto_install +[back to resource list](https://github.com/sous-chefs/java#resources) + +Installs Amazon Corretto Java distribution. This resource handles downloading, extracting and configuring Amazon's Corretto distribution of OpenJDK, including setting up Java home directories and configuring system alternatives. + Introduced: v8.0.0 ## Actions @@ -11,33 +14,38 @@ Introduced: v8.0.0 ## Properties -| Name | Type | Default | Description | -| --------------------- | --------------- | ------------------------------------ | ----------------------------------------------------------------------------------------------------------------- | -| version | String | | Java version to install | -| full_version | String | | Used to configure the package directory, change this is the version installed by the package is no longer correct | -| url | String | `default_corretto_url(version)` | The URL to download from | -| checksum | String | `default_corretto_checksum(version)` | The checksum for the downloaded file | -| java_home | String | Based on the version | Set to override the java_home | -| java_home_mode | Integer, String | `0755` | The permission for the Java home directory | -| java_home_owner | String | `root` | Owner of the Java Home | -| java_home_group | String | `node['root_group']` | Group for the Java Home | -| default | Boolean | `true` | Whether to set this as the defalut Java | -| bin_cmds | Array | `default_corretto_bin_cmds(version)` | A list of bin_cmds based on the version and variant | -| alternatives_priority | Integer | `1` | Alternatives priority to set for this Java | -| reset_alternatives | Boolean | `true` | Whether to reset alternatives before setting | +| Name | Type | Default | Description | +| --- | --- | --- | --- | +| version | String | | Java version to install | +| full_version | String | | Used to configure the package directory, change this is the version installed by the package is no longer correct | +| url | String | `default_corretto_url(version)` | The URL to download from | +| checksum | String | | The checksum for the downloaded file | +| java_home | String | Based on the version | Set to override the java_home | +| java_home_mode | Integer, String | `0755` | The permission for the Java home directory | +| java_home_owner | String | `root` | Owner of the Java Home | +| java_home_group | String | `node['root_group']` | Group for the Java Home | +| default | Boolean | `true` | Whether to set this as the default Java | +| bin_cmds | Array | `default_corretto_bin_cmds(version)` | A list of bin_cmds based on the version and variant | +| alternatives_priority | Integer | `1` | Alternatives priority to set for this Java | +| reset_alternatives | Boolean | `true` | Whether to reset alternatives before setting | +| skip_alternatives | Boolean | `false` | Skip alternatives installation completely | ## Examples -To install Corretto 11 and set it as the default Java +To install Corretto 11 and set it as the default Java: ```ruby corretto_install '11' ``` -To install Corretto 11 and set it as second highest priority +To install Corretto 11 and set it as second highest priority: ```ruby corretto_install '8' do alternatives_priority 2 end ``` + +## Architecture Support + +This resource supports installation on both x86_64 and ARM64 architectures. Amazon Corretto provides architecture-specific builds and the resource automatically handles the correct paths and downloads for the target platform. diff --git a/documentation/resources/jce.md b/documentation/resources/jce.md index 2c73db8a4..3a154fa1c 100644 --- a/documentation/resources/jce.md +++ b/documentation/resources/jce.md @@ -1,24 +1,28 @@ -[back to resource list](https://github.com/sous-chefs/java#resources) # java_jce +[back to resource list](https://github.com/sous-chefs/java#resources) + `java_jce` installs the Java Cryptography Extension (JCE) policy files for a given Java installation. ## Actions - `:install`: Installs the JCE policy files. +- `:remove`: Removes the staged JCE policy files, archive, and managed policy symlinks. ## Properties -| Name | Type | Default | Description | -| -------------- | ------ | -------------------------------------------------------- | -------------------------------------------------------------------------- | -| `jdk_version` | String | `node['java']['jdk_version']` | The Java version to install into | -| `jce_url` | String | `node['java']['oracle']['jce'][jdk_version]['url']` | The URL for the JCE distribution | -| `jce_checksum` | String | `node['java']['oracle']['jce'][jdk_version]['checksum']` | The checksum of the JCE distribution | -| `jce_cookie` | String | `node['java']['oracle']['accept_oracle_download_terms']` | Indicates that you accept Oracle's EULA | -| `jce_home` | String | `node['java']['oracle']['jce']['home']` | The location where JCE files will be decompressed for installation | -| `java_home` | String | `node['java']['java_home']` | The location of the Java installation | -| `principal` | String | `node['java']['windows']['owner']` | For Windows installations only, this determines the owner of the JCE files | +| Name | Type | Default | Description | +| --------------- | ------ | -------------------------------------------------------- | -------------------------------------------------------------------------- | +| `jdk_version` | String | Resource name | The Java version to install into | +| `jce_url` | String | Required | The URL for the JCE distribution | +| `jce_checksum` | String | Required | The checksum of the JCE distribution | +| `jce_cookie` | String | `''` | Indicates that you accept Oracle's EULA | +| `jce_home` | String | `/usr/lib/jvm/jce` | The location where JCE files will be decompressed for installation | +| `java_home` | String | Required | The location of the Java installation | +| `principal` | String | `administrator` | For Windows installations only, this determines the owner of the JCE files | +| `download_path` | String | Chef file cache path | Path used to stage the JCE archive | +| `install_type` | String | `jdk` | Whether the Java install is a jdk or jre layout | ## Examples diff --git a/documentation/resources/openjdk_install.md b/documentation/resources/openjdk_install.md index 0db6fdf5f..a9ad46d78 100644 --- a/documentation/resources/openjdk_install.md +++ b/documentation/resources/openjdk_install.md @@ -1,7 +1,10 @@ -[back to resource list](https://github.com/sous-chefs/java#resources) # openjdk_install +[back to resource list](https://github.com/sous-chefs/java#resources) + +Installs OpenJDK Java via source or package manager. This resource selects the appropriate installation method based on the `install_type` property and handles cross-platform Java installation including alternatives configuration. + Introduced: v8.0.0 ## Actions @@ -13,33 +16,49 @@ Introduced: v8.0.0 | Name | Type | Default | Description | Allowed values | | --------------------- | --------------- | ------- | --------------------------------------------------- | ------------------ | -| version | String | | Java version to install | -| url | String | | The URL to download from | -| checksum | String | | The checksum for the downloaded file | -| java_home | String | | Set to override the java_home | -| java_home_mode | Integer, String | | The permission for the Java home directory | -| java_home_owner | String | | Owner of the Java Home | -| java_home_group | String | | Group for the Java Home | -| default | Boolean | | Whether to set this as the defalut Java | -| bin_cmds | Array | | A list of bin_cmds based on the version and variant | -| alternatives_priority | Integer | | Alternatives priority to set for this Java | -| reset_alternatives | Boolean | | Whether to reset alternatives before setting | -| pkg_names | Array | | List of packages to install | -| pkg_version | String | | Package version to install | +| version | String | | Java version to install | | +| url | String | | The URL to download from | | +| checksum | String | | The checksum for the downloaded file | | +| java_home | String | | Set to override the java_home | | +| java_home_mode | Integer, String | | The permission for the Java home directory | | +| java_home_owner | String | | Owner of the Java Home | | +| java_home_group | String | | Group for the Java Home | | +| default | Boolean | | Whether to set this as the default Java | | +| bin_cmds | Array | | A list of bin_cmds based on the version and variant | | +| alternatives_priority | Integer | | Alternatives priority to set for this Java | | +| reset_alternatives | Boolean | | Whether to reset alternatives before setting | | +| skip_alternatives | Boolean | `false` | Skip alternatives installation completely | | +| pkg_names | Array | | List of packages to install | | +| pkg_version | String | | Package version to install | | | install_type | String | | Installation type | `package` `source` | +| source_install_dir | String | | Source install directory | | ## Examples -To install OpenJDK 11 and set it as the default Java +To install OpenJDK 11 and set it as the default Java: ```ruby openjdk_install '11' ``` -To install OpenJDK 11 and set it as second highest priority +To install OpenJDK 11 and set it as second highest priority: ```ruby openjdk_install '11' do alternatives_priority 2 end ``` + +To install a source archive from an internal mirror: + +```ruby +openjdk_install '17' do + install_type 'source' + url 'https://artifacts.example.com/java/OpenJDK17U-jdk_x64_linux_hotspot_17.0.9_9.tar.gz' + checksum 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' +end +``` + +For source installs, custom URLs install into a directory derived from the archive name unless +`java_home` or `source_install_dir` is set. Source archives must contain a single top-level +directory because the source installer strips one leading path component during extraction. diff --git a/documentation/resources/openjdk_pkg_install.md b/documentation/resources/openjdk_pkg_install.md index 60d801e74..885d5bb15 100644 --- a/documentation/resources/openjdk_pkg_install.md +++ b/documentation/resources/openjdk_pkg_install.md @@ -1,7 +1,10 @@ -[back to resource list](https://github.com/sous-chefs/java#resources) # openjdk_pkg_install +[back to resource list](https://github.com/sous-chefs/java#resources) + +Installs OpenJDK Java packages from the system's package manager. This resource handles platform-specific package installation for OpenJDK across different Linux distributions and versions, and configures the alternatives system appropriately. + Introduced: v8.1.0 ## Actions @@ -11,29 +14,35 @@ Introduced: v8.1.0 ## Properties -| Name | Type | Default | Description | -| --------------------- | ------- | ------------------------------------ | --------------------------------------------------- | -| version | String | | Java major version to install | -| pkg_names | Array | `default_openjdk_pkg_names(version)` | List of packages to install | -| pkg_version | String | `nil` | Package version to install | -| java_home | String | Based on the version | Set to override the java_home | -| default | Boolean | `true` | Whether to set this as the defalut Java | -| bin_cmds | Array | `default_openjdk_bin_cmds(version)` | A list of bin_cmds based on the version and variant | -| alternatives_priority | Integer | `1062` | Alternatives priority to set for this Java | -| reset_alternatives | Boolean | `true` | Whether to reset alternatives before setting | +| Name | Type | Default | Description | +| --- | --- | --- | --- | +| version | String | | Java major version to install | +| pkg_names | Array | `default_openjdk_pkg_names(version)` | List of packages to install | +| pkg_version | String | `nil` | Package version to install | +| java_home | String | Based on the version | Set to override the java_home | +| default | Boolean | `true` | Whether to set this as the default Java | +| bin_cmds | Array | `default_bin_cmds(version)` | A list of bin_cmds based on the version and variant | +| alternatives_priority | Integer | `1062` | Alternatives priority to set for this Java | +| reset_alternatives | Boolean | `true` | Whether to reset alternatives before setting | +| skip_alternatives | Boolean | `false` | Skip alternatives installation completely | +| repository_uri | String | `nil` | URI for the repository mirror to use instead of default repository URLs | ## Examples -To install OpenJDK 11 and set it as the default Java +To install OpenJDK 11 and set it as the default Java: ```ruby openjdk_pkg_install '11' ``` -To install OpenJDK 11 and set it as second highest priority +To install OpenJDK 11 and set it as second highest priority: ```ruby openjdk_pkg_install '11' do alternatives_priority 2 end ``` + +## Architecture Support + +This resource supports installation on both x86_64 and ARM64 architectures. On ARM64 platforms (like ARM Macs or ARM-based cloud instances), package paths may include architecture-specific suffixes in paths (e.g., `-arm64` or `-aarch64`). diff --git a/documentation/resources/openjdk_source_install.md b/documentation/resources/openjdk_source_install.md index cd08d4c88..e8dcb9d8c 100644 --- a/documentation/resources/openjdk_source_install.md +++ b/documentation/resources/openjdk_source_install.md @@ -1,6 +1,9 @@ + +# openjdk_source_install + [back to resource list](https://github.com/sous-chefs/java#resources) -# openjdk_install +Installs OpenJDK Java from source archives. This resource handles downloading, extracting, and configuring OpenJDK from source tarballs, including setting up the Java home directory and alternatives system entries. Introduced: v8.0.0 @@ -17,26 +20,53 @@ Introduced: v8.0.0 | url | String | `default_openjdk_url(version)` | The URL to download from | | checksum | String | `default_openjdk_checksum(version)` | The checksum for the downloaded file | | java_home | String | Based on the version | Set to override the java_home | +| source_install_dir | String | Based on the archive name | Source install directory | | java_home_mode | Integer, String | `0755` | The permission for the Java home directory | | java_home_owner | String | `root` | Owner of the Java Home | | java_home_group | String | `node['root_group']` | Group for the Java Home | -| default | Boolean | `true` | Whether to set this as the defalut Java | -| bin_cmds | Array | `default_openjdk_bin_cmds(version)` | A list of bin_cmds based on the version and variant | +| default | Boolean | `true` | Whether to set this as the default Java | +| bin_cmds | Array | `default_bin_cmds(version)` | A list of bin_cmds based on the version and variant | | alternatives_priority | Integer | `1` | Alternatives priority to set for this Java | | reset_alternatives | Boolean | `true` | Whether to reset alternatives before setting | +| skip_alternatives | Boolean | `false` | Skip alternatives installation completely | ## Examples -To install OpenJDK 11 and set it as the default Java +To install OpenJDK 11 and set it as the default Java: ```ruby -openjdk_install '11' +openjdk_source_install '11' ``` -To install OpenJDK 11 and set it as second highest priority +To install OpenJDK 11 and set it as second highest priority: ```ruby -openjdk_install '11' do +openjdk_source_install '11' do alternatives_priority 2 end ``` + +To install a custom OpenJDK archive from an internal mirror: + +```ruby +openjdk_source_install '17' do + url 'https://artifacts.example.com/java/OpenJDK17U-jdk_x64_linux_hotspot_17.0.9_9.tar.gz' + checksum 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' +end +``` + +This installs to `/usr/lib/jvm/java-17-openjdk/OpenJDK17U-jdk_x64_linux_hotspot_17.0.9_9` +and configures alternatives from that Java home. + +To choose a stable install directory for a custom archive: + +```ruby +openjdk_source_install '17' do + url 'https://artifacts.example.com/java/OpenJDK17U-jdk_x64_linux_hotspot_17.0.9_9.tar.gz' + checksum 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + source_install_dir 'jdk-17.0.9+9' +end +``` + +Source archives must contain a single top-level directory. The resource extracts archives with +one leading path component stripped so the archive contents land directly in `java_home`. diff --git a/documentation/resources/temurin_package_install.md b/documentation/resources/temurin_package_install.md new file mode 100644 index 000000000..a1965f8a0 --- /dev/null +++ b/documentation/resources/temurin_package_install.md @@ -0,0 +1,83 @@ +# temurin_package_install + +[back to resource list](https://github.com/sous-chefs/java#resources) + +Installs Eclipse Temurin packages provided by Adoptium. This resource handles the repository setup and package installation for Temurin JDK packages across various platforms. + +Introduced: v12.0.0 + +## Actions + +- `:install` - Installs Temurin JDK packages +- `:remove` - Removes Temurin JDK packages + +## Properties + +| Property | Type | Default | Description | +| --- | --- | --- | --- | +| `version` | String | Name Property | Java version to install (e.g. '8', '11', '17') | +| `pkg_name` | String | `temurin-#{version}-jdk` | Package name to install | +| `pkg_version` | String | `nil` | Package version to install | +| `java_home` | String | Platform-specific JAVA_HOME | Path to set as JAVA_HOME | +| `bin_cmds` | Array | Version-specific binary commands | Commands for alternatives | +| `alternatives_priority` | Integer | `1062` | Priority for alternatives system | +| `reset_alternatives` | Boolean | `true` | Whether to reset alternatives before setting | +| `default` | Boolean | `true` | Whether to set this as the default Java | +| `skip_alternatives` | Boolean | `false` | Skip alternatives installation completely | +| `repository_uri` | String | `nil` | URI for the repository mirror to use instead of default repository URLs | + +## Platform Support + +- Debian/Ubuntu: Uses apt_repository with `signed_by false` and `trusted true` options to bypass GPG signature verification issues +- Amazon Linux/CentOS/RHEL: Uses yum_repository with standard configuration +- SUSE: Uses zypper_repository with standard configuration + +## Architecture Support + +This resource supports installation on both x86_64 and ARM64 architectures. On ARM64 platforms (like ARM Macs or ARM-based cloud instances), the package paths may include architecture-specific suffixes (e.g., `/usr/lib/jvm/temurin-8-jdk-arm64/bin/java`). + +## Notes + +- Due to a bug in Chef's apt_repository resource ([PR #15043](https://github.com/chef/chef/pull/15043)), GPG key verification is disabled by default on Debian-family systems to ensure the repository can be used successfully + +## Examples + +### Install Temurin JDK 11 + +```ruby +temurin_package_install '11' +``` + +### Install Temurin JDK 17 with custom alternatives priority + +```ruby +temurin_package_install '17' do + alternatives_priority 1100 +end +``` + +### Install specific version with custom package name + +```ruby +temurin_package_install '11' do + pkg_name 'temurin-11-jdk' +end +``` + +## Supported Platforms + +This resource supports the following platforms: + +- Debian +- Ubuntu +- RHEL/CentOS/Rocky Linux +- Fedora +- Amazon Linux +- OpenSUSE/SLES + +Each platform will have the appropriate Adoptium repository configured automatically. + +## Additional Information + +- For most use cases, you can simply specify the major version number. +- `repository_uri` can point package repository setup at an internal mirror. diff --git a/kitchen.dokken.yml b/kitchen.dokken.yml index af2daed53..e898fcd03 100644 --- a/kitchen.dokken.yml +++ b/kitchen.dokken.yml @@ -1,55 +1,50 @@ ---- driver: name: dokken - privileged: true # because Docker and SystemD/Upstart + privileged: true + chef_version: <%= ENV['CHEF_VERSION'] || 'current' %> -transport: - name: dokken - -provisioner: - name: dokken - -verifier: - name: inspec +transport: { name: dokken } +provisioner: { name: dokken } platforms: - - name: amazon-linux + - name: almalinux-8 driver: - image: dokken/amazonlinux - pid_one_command: /sbin/init + image: dokken/almalinux-8 + pid_one_command: /usr/lib/systemd/systemd - - name: amazonlinux-2 + - name: almalinux-9 driver: - image: dokken/amazonlinux-2 + image: dokken/almalinux-9 pid_one_command: /usr/lib/systemd/systemd - - name: debian-9 + - name: almalinux-10 driver: - image: dokken/debian-9 - pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update + image: dokken/almalinux-10 + pid_one_command: /usr/lib/systemd/systemd - - name: debian-10 + - name: amazonlinux-2023 driver: - image: dokken/debian-10 - pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update + image: dokken/amazonlinux-2023 + pid_one_command: /usr/lib/systemd/systemd - - name: centos-7 + - name: centos-stream-9 driver: - image: dokken/centos-7 + image: dokken/centos-stream-9 pid_one_command: /usr/lib/systemd/systemd - - name: centos-8 + - name: centos-stream-10 driver: - image: dokken/centos-8 + image: dokken/centos-stream-10 pid_one_command: /usr/lib/systemd/systemd - - name: fedora-30 + - name: debian-12 + driver: + image: dokken/debian-12 + pid_one_command: /bin/systemd + + - name: debian-13 driver: - image: dokken/fedora-31 + image: dokken/debian-13 pid_one_command: /usr/lib/systemd/systemd - name: fedora-latest @@ -57,21 +52,37 @@ platforms: image: dokken/fedora-latest pid_one_command: /usr/lib/systemd/systemd - - name: ubuntu-18.04 + - name: oraclelinux-8 driver: - image: dokken/ubuntu-18.04 - pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update + image: dokken/oraclelinux-8 + pid_one_command: /usr/lib/systemd/systemd + + - name: oraclelinux-9 + driver: + image: dokken/oraclelinux-9 + pid_one_command: /usr/lib/systemd/systemd + + - name: rockylinux-8 + driver: + image: dokken/rockylinux-8 + pid_one_command: /usr/lib/systemd/systemd + + - name: rockylinux-9 + driver: + image: dokken/rockylinux-9 + pid_one_command: /usr/lib/systemd/systemd + + - name: rockylinux-10 + driver: + image: dokken/rockylinux-10 + pid_one_command: /usr/lib/systemd/systemd - - name: ubuntu-20.04 + - name: ubuntu-22.04 driver: - image: dokken/ubuntu-20.04 + image: dokken/ubuntu-22.04 pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update - - name: opensuse-leap-15 + - name: ubuntu-24.04 driver: - image: dokken/opensuse-leap-15 + image: dokken/ubuntu-24.04 pid_one_command: /bin/systemd diff --git a/kitchen.exec.yml b/kitchen.exec.yml new file mode 100644 index 000000000..ba7b2a962 --- /dev/null +++ b/kitchen.exec.yml @@ -0,0 +1,7 @@ +--- +driver: { name: exec } +transport: { name: exec } + +platforms: + - name: macos-latest + - name: windows-latest diff --git a/kitchen.global.yml b/kitchen.global.yml new file mode 100644 index 000000000..ad83b6239 --- /dev/null +++ b/kitchen.global.yml @@ -0,0 +1,33 @@ +--- +provisioner: + name: chef_infra + product_name: chef + product_version: <%= ENV['CHEF_VERSION'] || 'latest' %> + channel: stable + install_strategy: once + chef_license: accept + enforce_idempotency: <%= ENV['ENFORCE_IDEMPOTENCY'] || true %> + multiple_converge: <%= ENV['MULTIPLE_CONVERGE'] || 2 %> + deprecations_as_errors: true + log_level: <%= ENV['CHEF_LOG_LEVEL'] || 'auto' %> + +verifier: + name: inspec + +platforms: + - name: almalinux-8 + - name: almalinux-9 + - name: almalinux-10 + - name: amazonlinux-2023 + - name: centos-stream-9 + - name: centos-stream-10 + - name: debian-12 + - name: debian-13 + - name: fedora-latest + - name: oraclelinux-8 + - name: oraclelinux-9 + - name: rockylinux-8 + - name: rockylinux-9 + - name: rockylinux-10 + - name: ubuntu-22.04 + - name: ubuntu-24.04 diff --git a/kitchen.macos.local.yml b/kitchen.macos.local.yml index f1aa62194..071b95cd3 100644 --- a/kitchen.macos.local.yml +++ b/kitchen.macos.local.yml @@ -13,10 +13,13 @@ platforms: gui: false suites: - - name: adoptopenjdk-14 + - name: default run_list: - recipe[homebrew] - - recipe[test::adoptopenjdk-14-openj9] + - recipe[test::openjdk] + attributes: + version: 14 + variant: openj9 verifier: - inspec_tests: [test/integration/adoptopenjdk] - input_files: [test/integration/adoptopenjdk/attributes/adoptopenjdk-14-macos.yml] + inspec_tests: [test/integration/openjdk] + input_files: [test/integration/openjdk/inputs/openjdk-14-macos.yml] diff --git a/kitchen.macos.yml b/kitchen.macos.yml index 3756e6586..0b6a70528 100644 --- a/kitchen.macos.yml +++ b/kitchen.macos.yml @@ -20,10 +20,11 @@ platforms: gui: false suites: - - name: adoptopenjdk-14 + - name: default run_list: - - recipe[homebrew] - - recipe[test::adoptopenjdk-14-openj9] + - recipe[test::openjdk] + attributes: + version: 17 verifier: - inspec_tests: [test/integration/adoptopenjdk] - input_files: [test/integration/adoptopenjdk/attributes/adoptopenjdk-14-macos.yml] + inspec_tests: [test/integration/openjdk] + inputs: { java_version: "17" } diff --git a/kitchen.windows.yml b/kitchen.windows.yml index c3aa95f3b..a27961663 100644 --- a/kitchen.windows.yml +++ b/kitchen.windows.yml @@ -14,7 +14,7 @@ # suites: # - name: adoptopenjdk-13-openj9 # run_list: -# - recipe[test::adoptopenjdk-13-openj9] +# - recipe[test::adoptopenjdk] # platforms: # - name: windows_2019 diff --git a/kitchen.yml b/kitchen.yml index b97d0b0c8..cdb91a2c8 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -11,172 +11,110 @@ verifier: name: inspec platforms: - - name: amazonlinux-2 - - name: centos-7 - - name: centos-8 - - name: debian-9 - - name: debian-10 - - name: freebsd-11 - - name: freebsd-12 - - name: fedora-30 - - name: fedora-31 - - name: opensuse-leap-15 - - name: ubuntu-18.04 - - name: ubuntu-20.04 + - name: almalinux-8 + - name: almalinux-9 + - name: almalinux-10 + - name: amazonlinux-2023 + - name: centos-stream-9 + - name: centos-stream-10 + - name: debian-12 + - name: debian-13 + - name: fedora-latest + - name: oraclelinux-8 + - name: oraclelinux-9 + - name: rockylinux-8 + - name: rockylinux-9 + - name: rockylinux-10 + - name: ubuntu-22.04 + - name: ubuntu-24.04 suites: # OpenJDK - - name: openjdk-10 - run_list: - - recipe[test::openjdk] - attributes: {version: '10'} - verifier: - inspec_tests: [test/integration/openjdk] - inputs: {java_version: '10'} - - name: openjdk-11 + provisioner: + named_run_list: openjdk run_list: - recipe[test::openjdk] - attributes: {version: '11'} - verifier: - inspec_tests: [test/integration/openjdk] - inputs: {java_version: '11'} - - - name: openjdk-12 - run_list: - - recipe[test::openjdk] - attributes: {version: '12'} + attributes: { version: "11" } verifier: inspec_tests: [test/integration/openjdk] - inputs: {java_version: '12'} + inputs: { java_version: "11" } - - name: openjdk-13 + - name: openjdk-17 + provisioner: + named_run_list: openjdk run_list: - recipe[test::openjdk] - attributes: {version: '13'} + attributes: { version: "17" } verifier: inspec_tests: [test/integration/openjdk] - inputs: {java_version: '13'} + inputs: { java_version: "17" } - # OpenJDK_PKG - - name: openjdk-pkg-7 + # Temurin + - name: temurin-11 + provisioner: + named_run_list: temurin_pkg run_list: - - recipe[test::openjdk_pkg] - attributes: {version: '7'} + - recipe[test::temurin_pkg] + attributes: + version: 11 verifier: - inspec_tests: [test/integration/openjdk_pkg] - inputs: {java_version: '7'} - includes: ["amazon-linux", "amazonlinux-2", "centos-7"] + inspec_tests: [test/integration/temurin] + inputs: { java_version: "11" } - - name: openjdk-pkg-8 + - name: temurin-17 + provisioner: + named_run_list: temurin_pkg run_list: - - recipe[test::openjdk_pkg] - attributes: {version: '8'} + - recipe[test::temurin_pkg] + attributes: + version: 17 verifier: - inspec_tests: [test/integration/openjdk_pkg] - inputs: {java_version: '8'} - excludes: ["debian-10"] - - - name: openjdk-pkg-11 - run_list: - - recipe[test::openjdk_pkg] - attributes: {version: '11'} - verifier: - inspec_tests: [test/integration/openjdk_pkg] - inputs: {java_version: '11'} - excludes: ["amazon-linux", "debian-9"] - - - name: openjdk-pkg-14 - run_list: - - recipe[test::openjdk_pkg] - attributes: {version: '14'} - verifier: - inspec_tests: [test/integration/openjdk_pkg] - inputs: {java_version: '14'} - includes: [ubuntu-20.04] - - # AdoptOpenJDK - # Version 8 - - name: adoptopenjdk-8-hotspot - run_list: - - recipe[test::adoptopenjdk-8-hotspot] - verifier: - inspec_tests: [test/integration/adoptopenjdk] - input_files: [test/integration/adoptopenjdk/attributes/adoptopenjdk-8-hotspot.yml] - - name: adoptopenjdk-8-openj9 - run_list: - - recipe[test::adoptopenjdk-8-openj9] - verifier: - inspec_tests: [test/integration/adoptopenjdk] - input_files: [test/integration/adoptopenjdk/attributes/adoptopenjdk-8-openj9.yml] - - name: adoptopenjdk-8-openj9-large-heap - run_list: - - recipe[test::adoptopenjdk-8-openj9-large-heap] - verifier: - inspec_tests: [test/integration/adoptopenjdk] - input_files: [test/integration/adoptopenjdk/attributes/adoptopenjdk-8-openj9-large-heap.yml] - - # Version 11 - - name: adoptopenjdk-11-hotspot - run_list: - - recipe[test::adoptopenjdk-11-hotspot] - verifier: - inspec_tests: [test/integration/adoptopenjdk] - input_files: [test/integration/adoptopenjdk/attributes/adoptopenjdk-11-hotspot.yml] - - name: adoptopenjdk-11-openj9 - run_list: - - recipe[test::adoptopenjdk-11-openj9] - verifier: - inspec_tests: [test/integration/adoptopenjdk] - input_files: [test/integration/adoptopenjdk/attributes/adoptopenjdk-11-openj9.yml] - - name: adoptopenjdk-11-openj9-large-heap - run_list: - - recipe[test::adoptopenjdk-11-openj9-large-heap] - verifier: - inspec_tests: [test/integration/adoptopenjdk] - input_files: [test/integration/adoptopenjdk/attributes/adoptopenjdk-11-openj9-large-heap.yml] + inspec_tests: + - test/integration/temurin + inputs: { java_version: "17" } - # Version 14 - - name: adoptopenjdk-14-openj9-large-heap - run_list: - - recipe[test::adoptopenjdk-14-openj9-large-heap] - verifier: - inspec_tests: [test/integration/adoptopenjdk] - input_files: [test/integration/adoptopenjdk/attributes/adoptopenjdk-14-openj9-large-heap.yml] - - name: adoptopenjdk-14-openj9 + - name: temurin-21 + provisioner: + named_run_list: temurin_pkg run_list: - - recipe[test::adoptopenjdk-14-openj9] + - recipe[test::temurin_pkg] + attributes: + version: 21 verifier: inspec_tests: - - test/integration/adoptopenjdk - input_files: [test/integration/adoptopenjdk/attributes/adoptopenjdk-14-openj9.yml] - - name: adoptopenjdk-14-hotspot - run_list: - - recipe[test::adoptopenjdk-14-hotspot] - verifier: - inspec_tests: [test/integration/adoptopenjdk] - input_files: [test/integration/adoptopenjdk/attributes/adoptopenjdk-14-hotspot.yml] + - test/integration/temurin + inputs: { java_version: "21" } - # 11 Removal - - name: adoptopenjdk-removal-11-openj9 + - name: temurin-25 + provisioner: + named_run_list: temurin_pkg run_list: - - recipe[test::remove-adoptopenjdk-11-openj9] + - recipe[test::temurin_pkg] + attributes: + version: 25 verifier: - inspec_tests: [test/integration/remove-adoptopenjdk] - input_files: [test/integration/adoptopenjdk/attributes/adoptopenjdk-11-openj9.yml] + inspec_tests: + - test/integration/temurin + inputs: { java_version: "25" } # Corretto - - name: corretto-8 + - name: corretto-11 + provisioner: + named_run_list: corretto run_list: - recipe[test::corretto] - attributes: {version: '8'} + attributes: { version: "11" } verifier: inspec_tests: [test/integration/corretto] - inputs: {java_version: '8'} - - name: corretto-11 + inputs: { java_version: "11" } + + - name: corretto-17 + provisioner: + named_run_list: corretto run_list: - recipe[test::corretto] - attributes: {version: '11'} + attributes: { version: "17" } verifier: inspec_tests: [test/integration/corretto] - inputs: {java_version: '11'} + inputs: { java_version: "17" } diff --git a/lefthook.yml b/lefthook.yml new file mode 100644 index 000000000..bf255f836 --- /dev/null +++ b/lefthook.yml @@ -0,0 +1,8 @@ +pre-commit: + commands: + rubocop: + glob: "*.rb" + run: chef exec rubocop {staged_files} + skip: + - merge + - rebase diff --git a/libraries/adopt_openjdk_helpers.rb b/libraries/adopt_openjdk_helpers.rb deleted file mode 100644 index c70c620c2..000000000 --- a/libraries/adopt_openjdk_helpers.rb +++ /dev/null @@ -1,99 +0,0 @@ -module Java - module Cookbook - module AdoptOpenJdkHelpers - def sub_dir(url) - uri = URI.parse(url) - f = uri.path.split('/')[-2] - - case f - when /jdk8/ - result = f.split('_').first - when /jdk-14/ - result = f.split('_').first.gsub('%2B', '+') - result = result.slice(0..(result.index('.') - 1)) if result.include? '.' - result - else - result = f.split('_').first.gsub('%2B', '+') - end - - raise("Failed to parse #{f} for directory name!") if result.empty? - - result - end - - def default_adopt_openjdk_url(version) - case version - when '8' - { 'hotspot' => 'https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u242-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u242b08.tar.gz', - 'openj9' => 'https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u242-b08_openj9-0.18.1/OpenJDK8U-jdk_x64_linux_openj9_8u242b08_openj9-0.18.1.tar.gz', - 'openj9-large-heap' => 'https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u242-b08_openj9-0.18.1/OpenJDK8U-jdk_x64_linux_openj9_linuxXL_8u242b08_openj9-0.18.1.tar.gz', - } - when '11' - { 'hotspot' => 'https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.6%2B10/OpenJDK11U-jdk_x64_linux_hotspot_11.0.6_10.tar.gz', - 'openj9' => 'https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.6%2B10_openj9-0.18.1/OpenJDK11U-jdk_x64_linux_openj9_11.0.6_10_openj9-0.18.1.tar.gz', - 'openj9-large-heap' => 'https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.6%2B10_openj9-0.18.1/OpenJDK11U-jdk_x64_linux_openj9_linuxXL_11.0.6_10_openj9-0.18.1.tar.gz', - } - when '13' - { 'hotspot' => 'https://github.com/AdoptOpenJDK/openjdk13-binaries/releases/download/jdk-13.0.2%2B8/OpenJDK13U-jdk_x64_linux_hotspot_13.0.2_8.tar.gz', - 'openj9' => 'https://github.com/AdoptOpenJDK/openjdk13-binaries/releases/download/jdk-13.0.2%2B8_openj9-0.18.0/OpenJDK13U-jdk_x64_linux_openj9_13.0.2_8_openj9-0.18.0.tar.gz', - 'openj9-large-heap' => 'https://github.com/AdoptOpenJDK/openjdk13-binaries/releases/download/jdk-13.0.2%2B8_openj9-0.18.0/OpenJDK13U-jdk_x64_linux_openj9_linuxXL_13.0.2_8_openj9-0.18.0.tar.gz', - } - when '14' - { - 'hotspot' => 'https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14%2B36/OpenJDK14U-jdk_x64_linux_hotspot_14_36.tar.gz', - 'openj9' => 'https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14%2B36.1_openj9-0.19.0/OpenJDK14U-jdk_x64_linux_openj9_14_36_openj9-0.19.0.tar.gz', - 'openj9-large-heap' => 'https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14%2B36.1_openj9-0.19.0/OpenJDK14U-jdk_x64_linux_openj9_linuxXL_14_36_openj9-0.19.0.tar.gz', - } - else - Chef::Log.fatal('Version specified does not have a URL value set') - end - end - - def default_adopt_openjdk_checksum(version) - case version - when '8' - { 'hotspot' => 'f39b523c724d0e0047d238eb2bb17a9565a60574cf651206c867ee5fc000ab43', - 'openj9' => 'ca785af638b24f9d4df896f5a9f557cc9f1e5fa5e2b1174d6b906e3fd5474c2e', - 'openj9-large-heap' => '6ee788d57f15cc8c326bb3468390d5e353cc1aac1925efa3f2992a93e2520d97', - } - when '11' - { 'hotspot' => '330d19a2eaa07ed02757d7a785a77bab49f5ee710ea03b4ee2fa220ddd0feffc', - 'openj9' => '1530172ee98edd129954fcdca1bf725f7b30c8bfc3cdc381c88de96b7d19e690', - 'openj9-large-heap' => '6524d85d2ce334c955a4347015567326067ef15fe5f6a805714b25cace256f40', - } - when '13' - { 'hotspot' => '9ccc063569f19899fd08e41466f8c4cd4e05058abdb5178fa374cb365dcf5998', - 'openj9' => 'aeecf6d30d0c847db81d07793cf97e5dc44890c29366d7d9f8f9f397f6c52590', - 'openj9-large-heap' => '16751b3951b808c4cb0b77d4df1a16f9bfff5b2dbc59919773e6386114e6d8d5', - } - when '14' - { 'hotspot' => '6c06853332585ab58834d9e8a02774b388e6e062ef6c4084b4f058c67f2e81b5', - 'openj9' => '106b72d565be98834ead5fea9555bd646d488a86fc4ae4dd294a38e97bf77509', - 'openj9-large-heap' => '4ee13d0689ab7a38d6abb7dee974c3b189e36f1911a0cb61c882a38e61cc8b98', - } - else - Chef::Log.fatal('Version specified does not have a checksum value set') - end - end - - def default_adopt_openjdk_bin_cmds(version) - case version - when '8' - { 'hotspot' => ['appletviewer', 'clhsdb', 'extcheck', 'hsdb', 'idlj', 'jar', 'jarsigner', 'java', 'java-rmi.cgi', 'javac', 'javadoc', 'javah', 'javap', 'jcmd', 'jconsole', 'jdb', 'jdeps', 'jhat', 'jinfo', 'jjs', 'jmap', 'jps', 'jrunscript', 'jsadebugd', 'jstack', 'jstat', 'jstatd', 'keytool', 'native2ascii', 'orbd', 'pack200', 'policytool', 'rmic', 'rmid', 'rmiregistry', 'schemagen', 'serialver', 'servertool', 'tnameserv', 'unpack200', 'wsgen', 'wsimport', 'xjc'], - 'openj9' => ['appletviewer', 'extcheck', 'idlj', 'jar', 'jarsigner', 'java', 'java-rmi.cgi', 'javac', 'javadoc', 'javah', 'javap', 'jcmd', 'jconsole', 'jdb', 'jdeps', 'jdmpview', 'jitserver', 'jjs', 'jmap', 'jps', 'jrunscript', 'jsadebugd', 'jstack', 'jstat', 'keytool', 'native2ascii', 'orbd', 'pack200', 'policytool', 'rmic', 'rmid', 'rmiregistry', 'schemagen', 'serialver', 'servertool', 'tnameserv', 'traceformat', 'unpack200', 'wsgen', 'wsimport', 'xjc'], - 'openj9-large-heap' => ['appletviewer', 'extcheck', 'idlj', 'jar', 'jarsigner', 'java', 'java-rmi.cgi', 'javac', 'javadoc', 'javah', 'javap', 'jcmd', 'jconsole', 'jdb', 'jdeps', 'jdmpview', 'jitserver', 'jjs', 'jmap', 'jps', 'jrunscript', 'jsadebugd', 'jstack', 'jstat', 'keytool', 'native2ascii', 'orbd', 'pack200', 'policytool', 'rmic', 'rmid', 'rmiregistry', 'schemagen', 'serialver', 'servertool', 'tnameserv', 'traceformat', 'unpack200', 'wsgen', 'wsimport', 'xjc'] } - when '11' - { 'hotspot' => %w(jaotc jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jfr jhsdb jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack jstat jstatd keytool pack200 rmic rmid rmiregistry serialver unpack200), - 'openj9' => %w(jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jdmpview jextract jimage jitserver jjs jlink jmap jmod jps jrunscript jshell jstack jstat keytool pack200 rmic rmid rmiregistry serialver traceformat unpack200), - 'openj9-large-heap' => %w(jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jdmpview jextract jimage jitserver jjs jlink jmap jmod jps jrunscript jshell jstack jstat keytool pack200 rmic rmid rmiregistry serialver traceformat unpack200) } - when '13', '14' - { 'hotspot' => %w(jaotc jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jfr jhsdb jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack jstat jstatd keytool pack200 rmic rmid rmiregistry serialver unpack200), - 'openj9' => %w(jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jdmpview jextract jimage jjs jlink jmap jmod jps jrunscript jshell jstack jstat keytool pack200 rmic rmid rmiregistry serialver traceformat unpack200), - 'openj9-large-heap' => %w(jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jdmpview jextract jimage jjs jlink jmap jmod jps jrunscript jshell jstack jstat keytool pack200 rmic rmid rmiregistry serialver traceformat unpack200) } - else - Chef::Log.fatal('Version specified does not have a default set of bin_cmds') - end - end - end - end -end diff --git a/libraries/adopt_openjdk_macos_helpers.rb b/libraries/adopt_openjdk_macos_helpers.rb deleted file mode 100644 index 3680c9ce7..000000000 --- a/libraries/adopt_openjdk_macos_helpers.rb +++ /dev/null @@ -1,19 +0,0 @@ -module Java - module Cookbook - module AdoptOpenJdkMacOsHelpers - def macos_java_home(version) - if version.include? 'jre' - ending = '.jre' - version.gsub!('-jre', '') - else - ending = '.jdk' - end - - version.gsub!('jdk', 'jdk-') - version.slice!('-large') - - "/Library/Java/JavaVirtualMachines/#{version}#{ending}/Contents/Home" - end - end - end -end diff --git a/libraries/bin_cmd_helpers.rb b/libraries/bin_cmd_helpers.rb new file mode 100644 index 000000000..ac8de87b5 --- /dev/null +++ b/libraries/bin_cmd_helpers.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module Java + module Cookbook + module BinCmdHelpers + def default_bin_cmds(version) + case version + when '8' + %w(appletviewer extcheck idlj jar jarsigner java javac javadoc javah javap jcmd jconsole jdb jdeps jhat jinfo jjs jmap jps jrunscript jsadebugd jstack jstat jstatd keytool native2ascii orbd pack200 policytool rmic rmid rmiregistry schemagen serialver servertool tnameserv unpack200 wsgen wsimport xjc) + when '9' + %w(appletviewer idlj jaotc jar jarsigner java javac javadoc javah javap jcmd jconsole jdb jdeprscan jdeps jhsdb jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack jstat jstatd keytool orbd pack200 policytool rmic rmid rmiregistry schemagen serialver servertool tnameserv unpack200 wsgen wsimport xjc) + when '10' + %w(appletviewer idlj jaotc jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jhsdb jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack jstat jstatd keytool orbd pack200 rmic rmid rmiregistry schemagen serialver servertool tnameserv unpack200 wsgen wsimport xjc) + when '11' + %w(jaotc jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jhsdb jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack jstat jstatd keytool pack200 rmic rmid rmiregistry serialver unpack200) + when '12', '13', '14', '15', '16' + %w(jaotc jarsigner javac javap jconsole jdeprscan jfr jimage jjs jmap jps jshell jstat keytool rmic rmiregistry unpack200 jar java javadoc jcmd jdb jdeps jhsdb jinfo jlink jmod jrunscript jstack jstatd pack200 rmid serialver) + when '17' + %w(jarsigner javac javap jconsole jdeprscan jfr jimage jjs jmap jps jshell jstat keytool rmic rmiregistry unpack200 jar java javadoc jcmd jdb jdeps jhsdb jinfo jlink jmod jrunscript jstack jstatd pack200 rmid serialver) + when '18', '19', '20', '21', '22', '23', '24', '25', 'latest' + %w(jarsigner javac javap jconsole jdeprscan jfr jimage jjs jmap jps jshell jstat keytool rmic rmiregistry unpack200 jar java javadoc jcmd jdb jdeps jhsdb jinfo jlink jmod jrunscript jstack jstatd pack200 rmid serialver jwebserver) + else + Chef::Log.fatal('Version specified does not have a default set of bin_cmds') + end + end + end + end +end diff --git a/libraries/certificate_helpers.rb b/libraries/certificate_helpers.rb new file mode 100644 index 000000000..e24914867 --- /dev/null +++ b/libraries/certificate_helpers.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Java + module Cookbook + module CertificateHelpers + def default_truststore_path(version, java_home) + if version.to_i > 8 + "#{java_home}/lib/security/cacerts" + else + Chef::Log.fatal('Java 8 is no longer supported') + raise 'Java 8 is no longer supported' + end + end + + def keystore_argument(cacerts, truststore_path) + cacerts ? ['-cacerts'] : ['-keystore', truststore_path] + end + end + end +end diff --git a/libraries/corretto_helpers.rb b/libraries/corretto_helpers.rb index f9a2982c8..0e53c7cd0 100644 --- a/libraries/corretto_helpers.rb +++ b/libraries/corretto_helpers.rb @@ -1,38 +1,45 @@ +# frozen_string_literal: true + module Java module Cookbook module CorrettoHelpers - def default_corretto_url(version) - if version.to_s == '8' - 'https://corretto.aws/downloads/latest/amazon-corretto-8-x64-linux-jdk.tar.gz' - else - 'https://corretto.aws/downloads/latest/amazon-corretto-11-x64-linux-jdk.tar.gz' - end + def corretto_arch + node['kernel']['machine'].match?('aarch64') ? 'aarch64' : 'x64' end - def default_corretto_checksum(version) - if version.to_s == '8' - '7f08bc6097a14424bf09eb693304d48812099f29edb1d7326c6372a85b86b1df' + def default_corretto_bin_cmds(version) + case version.to_s + when '11' + %w(jaotc jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jfr jhsdb jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack jstat jstatd keytool pack200 rmic rmid rmiregistry serialver unpack200) + when '15', '17', '18' + %w(jaotc jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jfr jhsdb jimage jinfo jlink jmap jmod jpackage jps jrunscript jshell jstack jstat jstatd keytool rmid rmiregistry serialver) else - '24a487d594d10df540383c4c642444f969a00e616331d3dc3bdc4815ada71c0e' + raise 'Corretto version not recognised' end end - def default_corretto_bin_cmds(version) - if version.to_s == '8' - ['appletviewer', 'clhsdb', 'extcheck', 'hsdb', 'idlj', 'jar', 'jarsigner', 'java', 'java-rmi.cgi', 'javac', 'javadoc', 'javafxpackager', 'javah', 'javap', 'javapackager', 'jcmd', 'jconsole', 'jdb', 'jdeps', 'jhat', 'jinfo', 'jjs', 'jmap', 'jps', 'jrunscript', 'jsadebugd', 'jstack', 'jstat', 'jstatd', 'keytool', 'native2ascii', 'orbd', 'pack200', 'policytool', 'rmic', 'rmid', 'rmiregistry', 'schemagen', 'serialver', 'servertool', 'tnameserv', 'unpack200', 'wsgen', 'wsimport', 'xjc'] + def default_corretto_minor(version) + case version + when '11' + '11.0.15.9.1' + when '17' + '17.0.3.6.1' + when '18' + '18.0.1.10.1' else - %w(jaotc jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jhsdb jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack jstat jstatd keytool pack200 rmic rmid rmiregistry serialver unpack200) + raise 'Corretto version not recognised' end end def corretto_sub_dir(version, full_version = nil) - ver = if version == '8' - full_version || '8.242.08.1' - else - full_version || '11.0.6.10.1' - end + ver = full_version.nil? ? default_corretto_minor(version) : full_version + "amazon-corretto-#{ver}-linux-#{corretto_arch}" + end + + def default_corretto_url(version) + ver = version.include?('.') ? version : default_corretto_minor(version) - "amazon-corretto-#{ver}-linux-x64" + "https://corretto.aws/downloads/resources/#{ver}/amazon-corretto-#{ver}-linux-#{corretto_arch}.tar.gz" end end end diff --git a/libraries/openjdk_helpers.rb b/libraries/openjdk_helpers.rb index 2487de5a5..30114df14 100644 --- a/libraries/openjdk_helpers.rb +++ b/libraries/openjdk_helpers.rb @@ -1,21 +1,97 @@ +# frozen_string_literal: true + module Java module Cookbook module OpenJdkHelpers - def default_openjdk_url(version) - case version - when '9' - 'https://download.java.net/java/GA/jdk9/9/binaries/openjdk-9_linux-x64_bin.tar.gz' - when '10' - 'https://download.java.net/java/GA/jdk10/10/binaries/openjdk-10_linux-x64_bin.tar.gz' - when '11' - 'https://download.java.net/java/ga/jdk11/openjdk-11_linux-x64_bin.tar.gz' - when '12' - 'https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_linux-x64_bin.tar.gz' - when '13' - 'https://download.java.net/java/GA/jdk13/5b8a42f3905b406298b72d750b6919f6/33/GPL/openjdk-13_linux-x64_bin.tar.gz' + def lts + %w(11 17) + end + + # This method relies on the GitHub release artefact URL + # e.g. https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.3%2B7/OpenJDK17U-jdk_aarch64_linux_hotspot_17.0.3_7.tar.gz + def sub_dir(url) + URI.parse(url) + url.split('/')[7].split('_').first.gsub('%2', '-').downcase + end + + def default_openjdk_install_method(version) + case node['platform_family'] + when 'amazon' + 'source' + when 'rhel' + supported = node['platform_version'].to_i >= 10 ? [] : lts + supported.include?(version) ? 'package' : 'source' + when 'fedora' + 'source' + when 'debian' + if node['platform'] == 'debian' + case node['platform_version'].to_i + when 9 + %w(8).include?(version) ? 'package' : 'source' + when 10 + supported = lts - ['17'] + supported.include?(version) ? 'package' : 'source' + when 11 + lts.include?(version) ? 'package' : 'source' + when 12 + %w(17).include?(version) ? 'package' : 'source' + else + 'source' + end + else + case node['platform_version'] + when '10', '18.04' + supported = lts - ['17'] + supported.include?(version) ? 'package' : 'source' + when '9' + %w(8).include?(version) ? 'package' : 'source' + else + lts.include?(version) ? 'package' : 'source' + end + end else - Chef::Log.fatal('Version specified does not have a URL value set') - raise 'No checksum value' + lts.include?(version) ? 'package' : 'source' + end + end + + def default_openjdk_url(version, variant = 'openjdk') + case variant.downcase + when 'temurin' + case version + when '11' + 'https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.25%2B9/OpenJDK11U-jdk_x64_linux_hotspot_11.0.25_9.tar.gz' + when '17' + 'https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.13%2B11/OpenJDK17U-jdk_x64_linux_hotspot_17.0.13_11.tar.gz' + else + Chef::Log.fatal('Version specified does not have a URL value set') + raise 'Version supplied does not have a download URL set' + end + else + case version + when '9' + 'https://download.java.net/java/GA/jdk9/9/binaries/openjdk-9_linux-x64_bin.tar.gz' + when '10' + 'https://download.java.net/java/GA/jdk10/10/binaries/openjdk-10_linux-x64_bin.tar.gz' + when '11' + 'https://download.java.net/java/ga/jdk11/openjdk-11_linux-x64_bin.tar.gz' + when '12' + 'https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_linux-x64_bin.tar.gz' + when '13' + 'https://download.java.net/java/GA/jdk13/5b8a42f3905b406298b72d750b6919f6/33/GPL/openjdk-13_linux-x64_bin.tar.gz' + when '14' + 'https://download.java.net/java/GA/jdk14/076bab302c7b4508975440c56f6cc26a/36/GPL/openjdk-14_linux-x64_bin.tar.gz' + when '15' + 'https://download.java.net/java/GA/jdk15/779bf45e88a44cbd9ea6621d33e33db1/36/GPL/openjdk-15_linux-x64_bin.tar.gz' + when '16' + 'https://download.java.net/java/GA/jdk16/7863447f0ab643c585b9bdebf67c69db/36/GPL/openjdk-16_linux-x64_bin.tar.gz' + when '17' + 'https://download.java.net/java/GA/jdk17/0d483333a00540d886896bac774ff48b/35/GPL/openjdk-17_linux-x64_bin.tar.gz' + when '18' + 'https://download.java.net/java/GA/jdk18.0.1/3f48cabb83014f9fab465e280ccf630b/10/GPL/openjdk-18.0.1_linux-x64_bin.tar.gz' + else + Chef::Log.fatal('Version specified does not have a URL value set') + raise 'Version supplied does not have a download URL set' + end end end @@ -31,37 +107,26 @@ def default_openjdk_checksum(version) 'b43bc15f4934f6d321170419f2c24451486bc848a2179af5e49d10721438dd56' when '13' '5f547b8f0ffa7da517223f6f929a5055d749776b1878ccedbd6cc1334f4d6f4d' + when '14' + 'c7006154dfb8b66328c6475447a396feb0042608ee07a96956547f574a911c09' + when '15' + 'bb67cadee687d7b486583d03c9850342afea4593be4f436044d785fba9508fb7' + when '16' + 'e952958f16797ad7dc7cd8b724edd69ec7e0e0434537d80d6b5165193e33b931' + when '17' + 'aef49cc7aa606de2044302e757fa94c8e144818e93487081c4fd319ca858134b' else - Chef::Log.fatal('Version specified does not have a c value set') + Chef::Log.fatal('Version specified does not have a checksum value set') raise 'No checksum value' end end - def default_openjdk_bin_cmds(version) - case version - when '7' - %w(appletviewer apt ControlPanel extcheck idlj jar jarsigner java javac javadoc javafxpackager javah javap javaws jcmd jconsole jcontrol jdb jdeps jhat jinfo jjs jmap jmc jps jrunscript jsadebugd jstack jstat jstatd jvisualvm keytool native2ascii orbd pack200 policytool rmic rmid rmiregistry schemagen serialver servertool tnameserv unpack200 wsgen wsimport xjc) - when '8' - %w(appletviewer apt ControlPanel extcheck idlj jar jarsigner java javac javadoc javafxpackager javah javap javaws jcmd jconsole jcontrol jdb jdeps jhat jinfo jjs jmap jmc jps jrunscript jsadebugd jstack jstat jstatd jvisualvm keytool native2ascii orbd pack200 policytool rmic rmid rmiregistry schemagen serialver servertool tnameserv unpack200 wsgen wsimport xjc) - when '9' - %w(appletviewer idlj jaotc jar jarsigner java javac javadoc javah javap jcmd jconsole jdb jdeprscan jdeps jhsdb jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack jstat jstatd keytool orbd pack200 policytool rmic rmid rmiregistry schemagen serialver servertool tnameserv unpack200 wsgen wsimport xjc) - when '10' - %w(appletviewer idlj jaotc jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jhsdb jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack jstat jstatd keytool orbd pack200 rmic rmid rmiregistry schemagen serialver servertool tnameserv unpack200 wsgen wsimport xjc) - when '11' - %w(jaotc jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jhsdb jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack jstat jstatd keytool pack200 rmic rmid rmiregistry serialver unpack200) - when '12', '13', '14', '15', 'latest' - %w(jaotc jarsigner javac javap jconsole jdeprscan jfr jimage jjs jmap jps jshell jstat keytool rmic rmiregistry unpack200 jar java javadoc jcmd jdb jdeps jhsdb jinfo jlink jmod jrunscript jstack jstatd pack200 rmid serialver) - else - Chef::Log.fatal('Version specified does not have a default set of bin_cmds') - end - end - def default_openjdk_pkg_names(version) value_for_platform_family( - amazon: version.to_i < 11 ? ["java-1.#{version}.0-openjdk", "java-1.#{version}.0-openjdk-devel"] : "java-#{version}-amazon-corretto", + amazon: ["java-1.#{version}.0-openjdk", "java-1.#{version}.0-openjdk-devel"], %w(rhel fedora) => version.to_i < 11 ? ["java-1.#{version}.0-openjdk", "java-1.#{version}.0-openjdk-devel"] : ["java-#{version}-openjdk", "java-#{version}-openjdk-devel"], - suse: ["java-1_#{version}_0-openjdk", "java-1_#{version}_0-openjdk-devel"], - freebsd: version.to_i.eql?(7) ? 'openjdk' : "openjdk#{version}", + suse: version.to_i == 8 ? ["java-1_#{version}_0-openjdk", "java-1_#{version}_0-openjdk-devel"] : ["java-#{version}-openjdk", "java-#{version}-openjdk-devel"], + freebsd: "openjdk#{version}", arch: "openjdk#{version}", debian: ["openjdk-#{version}-jdk", "openjdk-#{version}-jre-headless"], default: ["openjdk-#{version}-jdk"] @@ -69,12 +134,30 @@ def default_openjdk_pkg_names(version) end def default_openjdk_pkg_java_home(version) + # For both standard OpenJDK and Temurin variants, use the standard OpenJDK paths + # Temurin variant is installed using package managers with standard paths + + # Map architecture to the correct suffix used in Java paths + arch = case node['kernel']['machine'] + when 'x86_64' + 'amd64' + when 'aarch64', 'arm64' + 'arm64' + when 'i386', 'i686' + 'i386' + else + node['kernel']['machine'] + end + + # For Debian-based systems, Temurin variant uses the same path structure + # with architecture-specific suffixes value_for_platform_family( - %w(rhel fedora amazon) => version.to_i < 11 ? "/usr/lib/jvm/java-1.#{version}.0" : "/usr/lib/jvm/java-#{version}", - suse: "/usr/lib#{node['kernel']['machine'] == 'x86_64' ? '64' : nil}/jvm/java-1.#{version}.0", + %w(rhel fedora) => version.to_i < 11 ? "/usr/lib/jvm/java-1.#{version}.0" : "/usr/lib/jvm/java-#{version}", + amazon: version.to_i < 11 ? "/usr/lib/jvm/java-1.#{version}.0" : "/usr/lib/jvm/jre-#{version}", + suse: "/usr/lib#{node['kernel']['machine'] == 'x86_64' ? '64' : nil}/jvm/java-#{version.to_i == 8 ? "1.#{version}.0" : version}", freebsd: "/usr/local/openjdk#{version}", arch: "/usr/lib/jvm/java-#{version}-openjdk", - debian: "/usr/lib/jvm/java-#{version}-openjdk-#{node['kernel']['machine'] == 'x86_64' ? 'amd64' : 'i386'}", + debian: "/usr/lib/jvm/java-#{version}-openjdk-#{arch}", default: '/usr/lib/jvm/default-java' ) end diff --git a/libraries/temurin_helpers.rb b/libraries/temurin_helpers.rb new file mode 100644 index 000000000..58285b7d2 --- /dev/null +++ b/libraries/temurin_helpers.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +module Java + module Cookbook + module TemurinHelpers + # Fetch available Temurin releases from Adoptium API + def available_temurin_releases + require 'net/http' + require 'json' + require 'uri' + + uri = URI('https://api.adoptium.net/v3/info/available_releases') + response = Net::HTTP.get_response(uri) + + if response.is_a?(Net::HTTPSuccess) + releases = JSON.parse(response.body) + Chef::Log.info("Available Temurin releases: #{releases}") + releases + else + Chef::Log.warn("Failed to fetch Temurin releases: #{response.code} #{response.message}") + {} + end + rescue => e + Chef::Log.warn("Error fetching Temurin releases: #{e.message}") + {} + end + + # Get available LTS versions + def temurin_lts_versions + releases = available_temurin_releases + return [] unless releases.is_a?(Hash) && releases.key?('available_lts_releases') + + releases['available_lts_releases'] + end + + # Get latest LTS version + def temurin_latest_lts + lts = temurin_lts_versions + lts.empty? ? '17' : lts.max.to_s + end + + # Helper to determine if a version is available as LTS + def temurin_version_available?(version) + version = version.to_s + lts = temurin_lts_versions + + return true if lts.include?(version.to_i) + false + end + end + end +end diff --git a/metadata.rb b/metadata.rb index 054e984df..602ca56d9 100644 --- a/metadata.rb +++ b/metadata.rb @@ -3,22 +3,17 @@ maintainer_email 'help@sous-chefs.org' license 'Apache-2.0' description 'Recipes and resources for installing Java and managing certificates' -version '8.1.2' +source_url 'https://github.com/sous-chefs/java' +issues_url 'https://github.com/sous-chefs/java/issues' +chef_version '>= 17.5' +version '15.0.0' -supports 'debian' -supports 'ubuntu' -supports 'centos' -supports 'redhat' -supports 'scientific' +supports 'almalinux', '>= 8.0' +supports 'amazon', '>= 2023.0' +supports 'centos_stream', '>= 9.0' +supports 'debian', '>= 12.0' supports 'fedora' -supports 'amazon' -supports 'oracle' -supports 'freebsd' -supports 'suse' -supports 'opensuseleap' - -source_url 'https://github.com/sous-chefs/java' -issues_url 'https://github.com/sous-chefs/java/issues' -chef_version '>= 15.0' - -depends 'line' +supports 'oracle', '>= 8.0' +supports 'redhat', '>= 8.0' +supports 'rocky', '>= 8.0' +supports 'ubuntu', '>= 22.04' diff --git a/recipes/adoptopenjdk.rb b/recipes/adoptopenjdk.rb deleted file mode 100644 index 680306686..000000000 --- a/recipes/adoptopenjdk.rb +++ /dev/null @@ -1,10 +0,0 @@ - -Chef::Log.fatal(" - -Adopt OpenJDK recipe is now deprecated -Using the adoptopenjdk_install resource is now recommended -See: https://github.com/sous-chefs/java/blob/master/documentation/resources/adoptopenjdk_.md for help - -") - -raise 'Recipe used instead of custom resource' diff --git a/recipes/corretto.rb b/recipes/corretto.rb deleted file mode 100644 index a4f7e56b5..000000000 --- a/recipes/corretto.rb +++ /dev/null @@ -1,10 +0,0 @@ - -Chef::Log.fatal(" - -java::corretto recipe is now deprecated -Using the corrett_install resource is now recommended -See: https://github.com/sous-chefs/java/blob/master/documentation/resources/corretto_install.md for help - -") - -raise 'Recipe used instead of custom resource' diff --git a/recipes/default.rb b/recipes/default.rb deleted file mode 100644 index 685057e01..000000000 --- a/recipes/default.rb +++ /dev/null @@ -1,10 +0,0 @@ - -Chef::Log.fatal(" - -Default install recipe is now deprecated -Use one of the documented install resources -See the documentation folder for a list of resources - -") - -raise 'Recipe used instead of custom resource' diff --git a/recipes/homebrew.rb b/recipes/homebrew.rb deleted file mode 100644 index 58cbfd5e2..000000000 --- a/recipes/homebrew.rb +++ /dev/null @@ -1,9 +0,0 @@ -Chef::Log.fatal(" - -The java::homebrew recipe is now deprecated -Use the homebrew cookbook and resources in your wrapper cookbook -See the documentation folder for a list of resources - -") - -raise 'Recipe used instead of custom resource' diff --git a/recipes/ibm.rb b/recipes/ibm.rb deleted file mode 100644 index 88c487b58..000000000 --- a/recipes/ibm.rb +++ /dev/null @@ -1,10 +0,0 @@ - -Chef::Log.fatal(" - -java::ibm recipe is now removed -Use one of the documented install resources -See the documentation folder for a list of resources - -") - -raise 'Recipe used instead of custom resource' diff --git a/recipes/ibm_tar.rb b/recipes/ibm_tar.rb deleted file mode 100644 index 5bfc5ac89..000000000 --- a/recipes/ibm_tar.rb +++ /dev/null @@ -1,10 +0,0 @@ - -Chef::Log.fatal(" - -java::ibm_tar recipe is now deprecated -Using one of the documented install resources -See the documentation folder for a list of resources - -") - -raise 'Recipe used instead of custom resource' diff --git a/recipes/notify.rb b/recipes/notify.rb deleted file mode 100644 index fa4eeae16..000000000 --- a/recipes/notify.rb +++ /dev/null @@ -1,10 +0,0 @@ - -Chef::Log.fatal(" - -java::notify recipe is now deprecated -Use one of the documented install resources -See the documentation folder for a list of resources - -") - -raise 'Recipe used instead of custom resource' diff --git a/recipes/openjdk.rb b/recipes/openjdk.rb deleted file mode 100644 index 8061b3bc1..000000000 --- a/recipes/openjdk.rb +++ /dev/null @@ -1,10 +0,0 @@ - -Chef::Log.fatal(" - -java::openjdk recipe is now deprecated -Using the adoptopenjdk_install resource is now recommended -See: https://github.com/sous-chefs/java/blob/master/documentation/resources/openjdk_install.md for help - -") - -raise 'Recipe used instead of custom resource' diff --git a/recipes/set_java_home.rb b/recipes/set_java_home.rb deleted file mode 100644 index 63531ca6e..000000000 --- a/recipes/set_java_home.rb +++ /dev/null @@ -1,10 +0,0 @@ - -Chef::Log.fatal(" - -java::set_java_home recipe is now deprecated -Use one of the documented install resources -See the documentation folder for a list of resources - -") - -raise 'Recipe used instead of custom resource' diff --git a/recipes/windows.rb b/recipes/windows.rb deleted file mode 100644 index 2a33e7459..000000000 --- a/recipes/windows.rb +++ /dev/null @@ -1,10 +0,0 @@ - -Chef::Log.fatal(" - -The java::windows recipe is now deprecated -Use one of the documented install resources -See the documentation folder for a list of resources - -") - -raise 'Recipe used instead of custom resource' diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 000000000..36027f41f --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,12 @@ +{ + "packages": { + ".": { + "package-name": "java", + "changelog-path": "CHANGELOG.md", + "release-type": "ruby", + "include-component-in-tag": false, + "version-file": "metadata.rb" + } + }, + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json" +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 000000000..a0b29c85c --- /dev/null +++ b/renovate.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": ["config:base"], + "packageRules": [ + { + "groupName": "Actions", + "matchUpdateTypes": ["minor", "patch", "pin"], + "automerge": true, + "addLabels": ["Release: Patch", "Skip: Announcements"] + }, + { + "groupName": "Actions", + "matchUpdateTypes": ["major"], + "automerge": false, + "addLabels": ["Release: Patch", "Skip: Announcements"] + } + ] +} diff --git a/resources/adoptopenjdk_install.rb b/resources/adoptopenjdk_install.rb deleted file mode 100644 index 0153ac308..000000000 --- a/resources/adoptopenjdk_install.rb +++ /dev/null @@ -1,80 +0,0 @@ -resource_name :adoptopenjdk_install -default_action :install - -# Common options -property :version, String, name_property: true, description: 'Java version to install' - -# Linux options -property :variant, String, description: 'Install flavour', default: 'openj9' -property :url, String, description: 'The URL to download from' -property :checksum, String, description: 'The checksum for the downloaded file' -property :java_home, String, description: 'Set to override the java_home' -property :java_home_mode, String, description: 'The permission for the Java home directory' -property :java_home_owner, String, description: 'Owner of the Java Home' -property :java_home_group, String, description: 'Group for the Java Home' -property :default, [true, false], description: ' Whether to set this as the defalut Java' -property :bin_cmds, Array, description: 'A list of bin_cmds based on the version and variant' -property :alternatives_priority, Integer, description: 'Alternatives priority to set for this Java' -property :reset_alternatives, [true, false], description: 'Whether to reset alternatives before setting' - -# MacOS options -property :tap_full, [true, false], default: true, description: 'Perform a full clone on the tap, as opposed to a shallow clone' -property :tap_url, String, description: 'The URL of the tap' -property :cask_options, String, description: 'Options to pass to the brew command during installation' -property :homebrew_path, String, description: 'The path to the homebrew binary' -property :owner, [String, Integer], description: 'The owner of the Homebrew installation' - -action :install do - case node['platform_family'] - when 'mac_os_x' - variant = if new_resource.variant.include? 'openj9' - '' - else - "-#{new_resource.variant}" - end - - adoptopenjdk_macos_install 'homebrew' do - tap_full new_resource.tap_full - tap_url new_resource.tap_url - cask_options new_resource.cask_options - homebrew_path new_resource.homebrew_path - owner new_resource.owner - version "adoptopenjdk#{new_resource.version}#{variant}" - end - when 'windows' - log 'not yet implemented' - else - adoptopenjdk_linux_install new_resource.version do - variant new_resource.variant - url new_resource.url - checksum new_resource.checksum - java_home new_resource.java_home - java_home_mode new_resource.java_home_mode - java_home_group new_resource.java_home_group - end - end -end - -action :remove do - case node['platform_family'] - when 'mac_os_x' - adoptopenjdk_macos_install 'homebrew' do - tap_full new_resource.tap_full - tap_url new_resource.tap_url - cask_options new_resource.cask_options - homebrew_path new_resource.homebrew_path - owner new_resource.owner - action :remove - end - when 'windows' - log 'not yet implemented' - else - adoptopenjdk_linux_install 'linux' do - version new_resource.version unless new_resource.version.nil? - variant new_resource.variant unless new_resource.variant.nil? - java_home new_resource.java_home unless new_resource.java_home.nil? - bin_cmds new_resource.bin_cmds unless new_resource.bin_cmds.nil? - action :remove - end - end -end diff --git a/resources/adoptopenjdk_linux_install.rb b/resources/adoptopenjdk_linux_install.rb deleted file mode 100644 index 8e48a7a4c..000000000 --- a/resources/adoptopenjdk_linux_install.rb +++ /dev/null @@ -1,121 +0,0 @@ -resource_name :adoptopenjdk_linux_install -include Java::Cookbook::AdoptOpenJdkHelpers -property :version, String, name_property: true, description: 'Java version to install' - -property :variant, String, - equal_to: %w(hotspot openj9 openj9-large-heap), - default: 'openj9', - description: 'Install flavour' - -property :url, String, - default: lazy { default_adopt_openjdk_url(version)[variant] }, - description: 'The URL to download from' - -property :checksum, String, - regex: /^[0-9a-f]{32}$|^[a-zA-Z0-9]{40,64}$/, - default: lazy { default_adopt_openjdk_checksum(version)[variant] }, - description: 'The checksum for the downloaded file' - -property :java_home, String, - default: lazy { "/usr/lib/jvm/java-#{version}-adoptopenjdk-#{variant}/#{sub_dir(url)}" }, - description: 'Set to override the java_home' - -property :java_home_mode, String, - description: 'The permission for the Java home directory' - -property :java_home_owner, String, - default: 'root', - description: 'Owner of the Java Home' - -property :java_home_group, String, - default: lazy { node['root_group'] }, - description: 'Group for the Java Home' - -property :default, [true, false], - default: true, - description: ' Whether to set this as the defalut Java' - -property :bin_cmds, Array, - default: lazy { default_adopt_openjdk_bin_cmds(version)[variant] }, - description: 'A list of bin_cmds based on the version and variant' - -property :alternatives_priority, Integer, - default: 1, - description: 'Alternatives priority to set for this Java' - -property :reset_alternatives, [true, false], - default: true, - description: 'Whether to reset alternatives before setting' - -action :install do - extract_dir = new_resource.java_home.split('/')[0..-2].join('/') - parent_dir = new_resource.java_home.split('/')[0..-3].join('/') - tarball_name = new_resource.url.split('/').last - - directory parent_dir do - owner new_resource.java_home_owner - group new_resource.java_home_group - mode new_resource.java_home_mode - recursive true - end - - remote_file "#{Chef::Config[:file_cache_path]}/#{tarball_name}" do - source new_resource.url - checksum new_resource.checksum - retries new_resource.retries - retry_delay new_resource.retry_delay - mode '644' - end - - archive_file "#{Chef::Config[:file_cache_path]}/#{tarball_name}" do - destination extract_dir - end - - template "/usr/lib/jvm/.java-#{new_resource.version}-adoptopenjdk-#{new_resource.variant}.jinfo" do - cookbook 'java' - source 'jinfo.erb' - owner new_resource.java_home_owner - group new_resource.java_home_group - variables( - priority: new_resource.alternatives_priority, - bin_cmds: new_resource.bin_cmds, - name: extract_dir.split('/').last, - app_dir: new_resource.java_home - ) - only_if { platform_family?('debian') } - end - - java_alternatives 'set-java-alternatives' do - java_location new_resource.java_home - bin_cmds new_resource.bin_cmds - priority new_resource.alternatives_priority - default new_resource.default - reset_alternatives new_resource.reset_alternatives - action :set - end - - node.default['java']['java_home'] = new_resource.java_home - - append_if_no_line 'Java Home' do - path '/etc/profile.d/java.sh' - line "export JAVA_HOME=#{new_resource.java_home}" - end -end - -action :remove do - extract_dir = new_resource.java_home.split('/')[0..-2].join('/') - - java_alternatives 'unset-java-alternatives' do - java_location new_resource.java_home - bin_cmds new_resource.bin_cmds - only_if { ::File.exist?(extract_dir) } - action :unset - end - - directory "AdoptOpenJDK removal of #{extract_dir}" do - path extract_dir - recursive true - only_if { ::File.exist?(extract_dir) } - action :delete - end -end diff --git a/resources/adoptopenjdk_macos_install.rb b/resources/adoptopenjdk_macos_install.rb deleted file mode 100644 index 4a219b07b..000000000 --- a/resources/adoptopenjdk_macos_install.rb +++ /dev/null @@ -1,85 +0,0 @@ -resource_name :adoptopenjdk_macos_install -include Java::Cookbook::AdoptOpenJdkMacOsHelpers - -property :tap_full, [true, false], - default: true, - description: 'Perform a full clone on the tap, as opposed to a shallow clone' - -property :tap_url, String, - description: 'The URL of the tap' - -property :cask_options, String, - description: 'Options to pass to the brew command during installation' - -property :homebrew_path, String, - description: 'The path to the homebrew binary' - -property :owner, [String, Integer], - description: 'The owner of the Homebrew installation' - -property :java_home, String, - default: lazy { macos_java_home(version) }, - description: 'MacOS specific JAVA_HOME' - -property :version, String, - default: 'adoptopenjdk14', - equal_to: %w( - adoptopenjdk8 adoptopenjdk8-openj9 adoptopenjdk8-openj9-large - adoptopenjdk8-jre adoptopenjdk8-openj9-jre adoptopenjdk8-jre-large - adoptopenjdk9 adoptopenjdk10 - adoptopenjdk11 adoptopenjdk11-openj9 adoptopenjdk11-openj9-large - adoptopenjdk11-jre adoptopenjdk11-openj9-jre adoptopenjdk11-openj9-jre-large - adoptopenjdk12 adoptopenjdk12-openj9 adoptopenjdk12-openj9-large - adoptopenjdk12-jre adoptopenjdk12-openj9-jre adoptopenjdk12-openj9-jre-large - adoptopenjdk13 adoptopenjdk13-openj9 adoptopenjdk13-openj9-large - adoptopenjdk13-jre adoptopenjdk13-openj9-jre adoptopenjdk13-openj9-jre-large - adoptopenjdk14 adoptopenjdk14-openj9 adoptopenjdk14-openj9-large - adoptopenjdk14-jre adoptopenjdk14-openj9-jre adoptopenjdk14-openj9-jre-large - ) - -action :install do - homebrew_tap 'AdoptOpenJDK/openjdk' do - full new_resource.tap_full - homebrew_path new_resource.homebrew_path - owner new_resource.owner - url new_resource.tap_url - action :tap - end - - homebrew_cask "AdoptOpenJDK/openjdk/#{new_resource.version}" do - homebrew_path new_resource.homebrew_path - install_cask true - options new_resource.cask_options - owner new_resource.owner - action :install - end - - # Bash system wide environment variables - append_if_no_line 'Java Home' do - path '/etc/profile' - line "export JAVA_HOME=#{new_resource.java_home}" - end - - # Zsh system wide environment variables - append_if_no_line 'Java Home' do - path '/etc/zshrc' - line "export JAVA_HOME=#{new_resource.java_home}" - end - - node.default['java']['java_home'] = new_resource.java_home -end - -action :remove do - homebrew_tap 'AdoptOpenJDK/openjdk' do - homebrew_path new_resource.homebrew_path - owner new_resource.owner - action :untap - end - - homebrew_cask "adoptopenjdk#{new_resource.version}" do - homebrew_path new_resource.homebrew_path - options new_resource.cask_options - owner new_resource.owner - action :remove - end -end diff --git a/resources/alternatives.rb b/resources/alternatives.rb index 792744f33..2def88b32 100644 --- a/resources/alternatives.rb +++ b/resources/alternatives.rb @@ -1,39 +1,73 @@ -# -# Cookbook:: java -# Provider:: alternatives -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -property :java_location, String, - description: 'Java installation location' - -property :bin_cmds, Array, - description: 'Array of Java tool names to set or unset alternatives on' - -property :default, [true, false], - default: true, - description: 'Whether to set the Java tools as system default. Boolean, defaults to `true`' - -property :priority, Integer, - default: 1061, - description: ' Priority of the alternatives. Integer, defaults to `1061`' - -property :reset_alternatives, [true, false], - default: true, - description: 'Whether to reset alternatives before setting them' +# frozen_string_literal: true + +provides :java_alternatives +unified_mode true + +property :java_location, + String, + description: 'Java installation location' + +property :bin_cmds, + Array, + callbacks: { + 'must contain only command names' => lambda { |cmds| + cmds.all? { |cmd| cmd.match?(/\A[A-Za-z0-9_.+-]+\z/) } + }, + }, + description: 'Array of Java tool names to set or unset alternatives on' + +property :default, + [true, false], + default: true, + description: 'Whether to set the Java tools as system default. Boolean, defaults to `true`' + +property :priority, + Integer, + default: 1061, + description: ' Priority of the alternatives. Integer, defaults to `1061`' + +property :reset_alternatives, + [true, false], + default: false, + description: 'Whether to reset alternatives before setting them' action :set do - if new_resource.bin_cmds + bin_cmds_to_setup = parse_java_alternatives + set_alternatives(bin_cmds_to_setup) do |cmd, alt_path| + alternative_exists = ::File.exist?(alternative_file_path(cmd)) && + alternatives_display(cmd).stdout.include?(alt_path) + Chef::Log.debug("Alternative for #{cmd} exists with correct path? #{alternative_exists}") + alternative_exists + end +end + +action :unset do + new_resource.bin_cmds.each do |cmd| + converge_by("Remove alternative for #{cmd}") do + shell_out!(alternatives_cmd, '--remove', cmd, "#{new_resource.java_location}/bin/#{cmd}") + end + end +end + +action_class do + def alternatives_cmd + platform_family?('rhel', 'fedora', 'amazon') ? 'alternatives' : 'update-alternatives' + end + + def alternatives_display(cmd) + shell_out(alternatives_cmd, '--display', cmd) + end + + def alternative_file_path(cmd) + if platform_family?('debian') + "/var/lib/dpkg/alternatives/#{cmd}" + else + "/var/lib/alternatives/#{cmd}" + end + end + + def parse_java_alternatives + bin_cmds_to_setup = [] new_resource.bin_cmds.each do |cmd| bin_path = "/usr/bin/#{cmd}" alt_path = "#{new_resource.java_location}/bin/#{cmd}" @@ -44,58 +78,55 @@ next end - alternative_exists_same_priority = shell_out("#{alternatives_cmd} --display #{cmd} | grep #{alt_path} | grep 'priority #{priority}$'").exitstatus == 0 - alternative_exists = shell_out("#{alternatives_cmd} --display #{cmd} | grep #{alt_path}").exitstatus == 0 - # remove alternative if priority is changed and install it with new priority - if alternative_exists && !alternative_exists_same_priority - converge_by("Removing alternative for #{cmd} with old priority") do - Chef::Log.debug "Removing alternative for #{cmd} with old priority" - remove_cmd = shell_out("#{alternatives_cmd} --remove #{cmd} #{alt_path}") - alternative_exists = false - unless remove_cmd.exitstatus == 0 - raise(%( remove alternative failed )) - end + bin_cmds_to_setup << [cmd, bin_path, alt_path, priority] + end + bin_cmds_to_setup + end + + def set_alternatives(bin_cmds) + bin_cmds.each do |cmd, bin_path, alt_path, priority| + if block_given? && yield(cmd, alt_path) + Chef::Log.debug "Skipping alternative for #{cmd} as it already exists with correct path" + next + end + + display_result = alternatives_display(cmd) + cmd_output = display_result.stdout + + alternative_system_exists = display_result.exitstatus == 0 && !cmd_output.empty? + our_alternative_exists = alternative_system_exists && cmd_output.include?(alt_path) + + existing_priority = nil + if our_alternative_exists + if cmd_output =~ /#{Regexp.escape(alt_path)}.*priority\s+(\d+)/ + existing_priority = Regexp.last_match(1).to_i end end - # install the alternative if needed - unless alternative_exists + + if our_alternative_exists && existing_priority && existing_priority != priority + converge_by("Removing alternative for #{cmd} with old priority #{existing_priority}") do + shell_out!(alternatives_cmd, '--remove', cmd, alt_path) + end + end + + alternative_file_exists = ::File.exist?(alternative_file_path(cmd)) + + if !our_alternative_exists || !alternative_file_exists converge_by("Add alternative for #{cmd}") do - Chef::Log.debug "Adding alternative for #{cmd}" - if new_resource.reset_alternatives - shell_out("rm /var/lib/alternatives/#{cmd}") - end - install_cmd = shell_out("#{alternatives_cmd} --install #{bin_path} #{cmd} #{alt_path} #{priority}") - unless install_cmd.exitstatus == 0 - raise(%( install alternative failed )) + if new_resource.reset_alternatives && alternative_file_exists + ::FileUtils.rm_f(alternative_file_path(cmd)) end + shell_out!(alternatives_cmd, '--install', bin_path, cmd, alt_path, priority.to_s) end end - # set the alternative if default next unless new_resource.default - alternative_is_set = shell_out("#{alternatives_cmd} --display #{cmd} | grep \"link currently points to #{alt_path}\"").exitstatus == 0 + alternative_is_set = alternatives_display(cmd).stdout.include?("link currently points to #{alt_path}") next if alternative_is_set converge_by("Set alternative for #{cmd}") do Chef::Log.debug "Setting alternative for #{cmd}" - set_cmd = shell_out("#{alternatives_cmd} --set #{cmd} #{alt_path}") - unless set_cmd.exitstatus == 0 - raise(%( set alternative failed )) - end + shell_out!(alternatives_cmd, '--set', cmd, alt_path) end end end end - -action :unset do - new_resource.bin_cmds.each do |cmd| - converge_by("Remove alternative for #{cmd}") do - shell_out("#{alternatives_cmd} --remove #{cmd} #{new_resource.java_location}/bin/#{cmd}") - end - end -end - -action_class do - def alternatives_cmd - platform_family?('rhel', 'fedora', 'amazon') ? 'alternatives' : 'update-alternatives' - end -end diff --git a/resources/certificate.rb b/resources/certificate.rb index 5d64941cc..c39e40162 100644 --- a/resources/certificate.rb +++ b/resources/certificate.rb @@ -1,99 +1,111 @@ -# -# Author:: Mevan Samaratunga () -# Author:: Michael Goetz () -# Cookbook:: java -# Resource:: certificate -# -# Copyright:: 2013, Mevan Samaratunga -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -property :cert_alias, String, - name_property: true, - description: 'The alias of the certificate in the keystore. This defaults to the name of the resource' - -property :java_home, String, - default: lazy { node['java']['java_home'] }, - description: 'The java home directory' - -property :java_version, String, - default: lazy { node['java']['jdk_version'] }, - description: ' The java version' - -property :keystore_path, String, - description: 'Path to the keystore' - -property :keystore_passwd, String, - default: 'changeit', - description: 'Password to the keystore' - -property :cert_data, String, - description: 'The certificate data to install' - -property :cert_file, String, - description: 'Path to a certificate file to install' - -property :ssl_endpoint, String, - description: 'An SSL end-point from which to download the certificate' +# frozen_string_literal: true + +provides :java_certificate +unified_mode true +include Java::Cookbook::CertificateHelpers +include Java::Cookbook::OpenJdkHelpers + +property :cert_alias, + String, + regex: /\A[A-Za-z0-9_.-]+\z/, + name_property: true, + description: 'The alias of the certificate in the keystore. This defaults to the name of the resource' + +property :java_version, + String, + default: '17', + description: 'The major java version' + +property :java_home, + String, + default: lazy { default_openjdk_pkg_java_home(java_version) }, + description: 'The java home directory' + +property :cacerts, + [true, false], + default: true, + description: 'Specify true for interacting with the Java installation cacerts file. (Java 9+)' + +property :keystore_path, + String, + default: lazy { default_truststore_path(java_version, java_home) }, + description: 'Path to the keystore' + +property :keystore_passwd, + String, + default: 'changeit', + description: 'Password to the keystore' + +property :cert_data, + String, + description: 'The certificate data to install' + +property :cert_file, + String, + description: 'Path to a certificate file to install' + +property :ssl_endpoint, + String, + callbacks: { + 'must be a host:port endpoint' => lambda { |endpoint| + endpoint.match?(/\A[A-Za-z0-9.-]+:\d+\z/) + }, + }, + description: 'An SSL end-point from which to download the certificate' + +property :starttls, + String, + equal_to: %w(smtp pop3 imap ftp xmpp xmpp-server irc postgres mysql lmtp nntp sieve ldap), + description: 'A protocol specific STARTTLS argument to use when fetching from an ssl_endpoint' + +property :file_cache_path, + String, + default: Chef::Config[:file_cache_path], + description: 'Location to store certificate files' action :install do require 'openssl' - java_home = new_resource.java_home - Chef::Log.info java_home - keytool = "#{java_home}/bin/keytool" - truststore = if new_resource.keystore_path.nil? - truststore_default_location - else - new_resource.keystore_path - end - truststore_passwd = new_resource.keystore_passwd - certalias = new_resource.cert_alias + keystore_arguments = keystore_argument(new_resource.cacerts, new_resource.keystore_path) + certdata = new_resource.cert_data || fetch_certdata hash = OpenSSL::Digest::SHA512.hexdigest(certdata) - certfile = "#{Chef::Config[:file_cache_path]}/#{certalias}.cert.#{hash}" - cmd = Mixlib::ShellOut.new("#{keytool} -list -keystore #{truststore} -storepass #{truststore_passwd} -rfc -alias \"#{certalias}\"") + certfile = ::File.join(new_resource.file_cache_path, "#{new_resource.cert_alias}.cert.#{hash}") + + cmd = keytool('-list', *keystore_arguments, '-storepass', new_resource.keystore_passwd, '-rfc', '-alias', new_resource.cert_alias) cmd.run_command keystore_cert = cmd.stdout.match(/^[-]+BEGIN.*END(\s|\w)+[-]+$/m).to_s keystore_cert_digest = keystore_cert.empty? ? nil : OpenSSL::Digest::SHA512.hexdigest(OpenSSL::X509::Certificate.new(keystore_cert).to_der) certfile_digest = OpenSSL::Digest::SHA512.hexdigest(OpenSSL::X509::Certificate.new(certdata).to_der) if keystore_cert_digest == certfile_digest - Chef::Log.debug("Certificate \"#{certalias}\" in keystore \"#{truststore}\" is up-to-date.") + Chef::Log.debug("Certificate \"#{new_resource.cert_alias}\" in keystore \"#{new_resource.keystore_path}\" is up-to-date.") else - cmd = Mixlib::ShellOut.new("#{keytool} -list -keystore #{truststore} -storepass #{truststore_passwd} -v") + cmd = keytool('-list', *keystore_arguments, '-storepass', new_resource.keystore_passwd, '-v') cmd.run_command - Chef::Log.info(cmd.format_for_exception) + Chef::Log.debug(cmd.format_for_exception) Chef::Application.fatal!("Error querying keystore for existing certificate: #{cmd.exitstatus}", cmd.exitstatus) unless cmd.exitstatus == 0 - has_key = !cmd.stdout[/Alias name: \b#{certalias}\s*$/i].nil? + has_key = !cmd.stdout[/Alias name: \b#{Regexp.escape(new_resource.cert_alias)}\s*$/i].nil? if has_key - converge_by("delete existing certificate #{certalias} from #{truststore}") do - cmd = Mixlib::ShellOut.new("#{keytool} -delete -alias \"#{certalias}\" -keystore #{truststore} -storepass #{truststore_passwd}") + converge_by("delete existing certificate #{new_resource.cert_alias} from #{new_resource.keystore_path}") do + cmd = keytool('-delete', '-alias', new_resource.cert_alias, *keystore_arguments, '-storepass', new_resource.keystore_passwd) cmd.run_command Chef::Log.debug(cmd.format_for_exception) unless cmd.exitstatus == 0 - Chef::Application.fatal!("Error deleting existing certificate \"#{certalias}\" in " \ + Chef::Application.fatal!("Error deleting existing certificate \"#{new_resource.cert_alias}\" in " \ "keystore so it can be updated: #{cmd.exitstatus}", cmd.exitstatus) end end end + ::FileUtils.mkdir_p(new_resource.file_cache_path) ::File.open(certfile, 'w', 0o644) { |f| f.write(certdata) } - converge_by("add certificate #{certalias} to keystore #{truststore}") do - cmd = Mixlib::ShellOut.new("#{keytool} -import -trustcacerts -alias \"#{certalias}\" -file #{certfile} -keystore #{truststore} -storepass #{truststore_passwd} -noprompt") + converge_by("add certificate #{new_resource.cert_alias} to keystore #{new_resource.keystore_path}") do + cmd = keytool('-import', '-trustcacerts', '-alias', new_resource.cert_alias, '-file', certfile, *keystore_arguments, '-storepass', new_resource.keystore_passwd, '-noprompt') cmd.run_command Chef::Log.debug(cmd.format_for_exception) @@ -106,59 +118,51 @@ end action :remove do - certalias = new_resource.name - truststore = if new_resource.keystore_path.nil? - truststore_default_location - else - new_resource.keystore_path - end - truststore_passwd = new_resource.keystore_passwd - keytool = "#{new_resource.java_home}/bin/keytool" - - cmd = Mixlib::ShellOut.new("#{keytool} -list -keystore #{truststore} -storepass #{truststore_passwd} -v | grep \"#{certalias}\"") + keystore_arguments = keystore_argument(new_resource.cacerts, new_resource.keystore_path) + + cmd = keytool('-list', *keystore_arguments, '-storepass', new_resource.keystore_passwd, '-v') cmd.run_command - has_key = !cmd.stdout[/Alias name: #{certalias}/].nil? - Chef::Application.fatal!("Error querying keystore for existing certificate: #{cmd.exitstatus}", cmd.exitstatus) unless cmd.exitstatus == 0 + has_key = !cmd.stdout[/Alias name: #{Regexp.escape(new_resource.cert_alias)}/].nil? + does_not_exist = cmd.stdout[/Alias <#{Regexp.escape(new_resource.cert_alias)}> does not exist/] + Chef::Application.fatal!("Error querying keystore for existing certificate: #{cmd.exitstatus}", cmd.exitstatus) unless (cmd.exitstatus == 0) || does_not_exist if has_key - converge_by("remove certificate #{certalias} from #{truststore}") do - cmd = Mixlib::ShellOut.new("#{keytool} -delete -alias \"#{certalias}\" -keystore #{truststore} -storepass #{truststore_passwd}") + converge_by("remove certificate #{new_resource.cert_alias} from #{new_resource.keystore_path}") do + cmd = keytool('-delete', '-alias', new_resource.cert_alias, *keystore_arguments, '-storepass', new_resource.keystore_passwd) cmd.run_command unless cmd.exitstatus == 0 - Chef::Application.fatal!("Error deleting existing certificate \"#{certalias}\" in " \ + Chef::Application.fatal!("Error deleting existing certificate \"#{new_resource.cert_alias}\" in " \ "keystore so it can be updated: #{cmd.exitstatus}", cmd.exitstatus) end end end - FileUtils.rm_f("#{new_reource.download_path}/#{certalias}.cert.*") + FileUtils.rm_f(::Dir.glob(::File.join(new_resource.file_cache_path, "#{new_resource.cert_alias}.cert.*"))) end action_class do + def keytool(*args) + Mixlib::ShellOut.new(::File.join(new_resource.java_home, 'bin', 'keytool'), *args) + end + def fetch_certdata return IO.read(new_resource.cert_file) unless new_resource.cert_file.nil? certendpoint = new_resource.ssl_endpoint unless certendpoint.nil? - cmd = Mixlib::ShellOut.new("echo QUIT | openssl s_client -showcerts -servername #{certendpoint.split(':').first} -connect #{certendpoint} 2> /dev/null | openssl x509") + host = certendpoint.split(':').first + starttls = new_resource.starttls.nil? ? [] : ['-starttls', new_resource.starttls] + cmd = Mixlib::ShellOut.new('openssl', 's_client', '-showcerts', '-servername', host, '-connect', certendpoint, *starttls, input: "QUIT\n", timeout: 30) cmd.run_command Chef::Log.debug(cmd.format_for_exception) Chef::Application.fatal!("Error returned when attempting to retrieve certificate from remote endpoint #{certendpoint}: #{cmd.exitstatus}", cmd.exitstatus) unless cmd.exitstatus == 0 - certout = cmd.stdout + certout = cmd.stdout[/-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----/m].to_s return certout unless certout.empty? Chef::Application.fatal!("Unable to parse certificate from openssl query of #{certendpoint}.", 999) end Chef::Application.fatal!('At least one of cert_data, cert_file or ssl_endpoint attributes must be provided.', 999) end - - def truststore_default_location - if new_resource.java_version.to_i > 8 - "#{new_resource.java_home}/lib/security/cacerts" - else - "#{new_resource.java_home}/jre/lib/security/cacerts" - end - end end diff --git a/resources/corretto_install.rb b/resources/corretto_install.rb index 1a8e5b58d..0a5a53ac3 100644 --- a/resources/corretto_install.rb +++ b/resources/corretto_install.rb @@ -1,50 +1,31 @@ -resource_name :corretto_install +# frozen_string_literal: true + +provides :corretto_install +unified_mode true include Java::Cookbook::CorrettoHelpers -property :version, String, name_property: true, description: 'Java version to install' property :full_version, String, - description: 'Used to configure the package directory, change this is the version installed by the package is no longer correct' + description: 'Used to configure the package directory, change this is the version installed by the package is no longer correct' property :url, String, - default: lazy { default_corretto_url(version) }, - description: 'The URL to download from' + default: lazy { default_corretto_url(version) }, + description: 'The URL to download from' property :checksum, String, - regex: /^[0-9a-f]{32}$|^[a-zA-Z0-9]{40,64}$/, - default: lazy { default_corretto_checksum(version) }, - description: 'The checksum for the downloaded file' + regex: /^[0-9a-f]{32}$|^[a-zA-Z0-9]{40,64}$/, + description: 'The checksum for the downloaded file' property :java_home, String, - default: lazy { "/usr/lib/jvm/java-#{version}-corretto/#{corretto_sub_dir(version, full_version)}" }, - description: 'Set to override the java_home' - -property :java_home_mode, String, - default: '0755', - description: 'The permission for the Java home directory' - -property :java_home_owner, String, - default: 'root', - description: 'Owner of the Java Home' - -property :java_home_group, String, - default: lazy { node['root_group'] }, - description: 'Group for the Java Home' - -property :default, [true, false], - default: true, - description: ' Whether to set this as the defalut Java' + default: lazy { "/usr/lib/jvm/java-#{version}-corretto/#{corretto_sub_dir(version, full_version)}" }, + description: 'Set to override the java_home' property :bin_cmds, Array, - default: lazy { default_corretto_bin_cmds(version) }, - description: 'A list of bin_cmds based on the version and variant' - -property :alternatives_priority, Integer, - default: 1, - description: 'Alternatives priority to set for this Java' + default: lazy { default_corretto_bin_cmds(version) }, + description: 'A list of bin_cmds based on the version and variant' -property :reset_alternatives, [true, false], - default: true, - description: 'Whether to reset alternatives before setting' +use 'partial/_common' +use 'partial/_linux' +use 'partial/_java_home' action :install do extract_dir = new_resource.java_home.split('/')[0..-2].join('/') @@ -60,7 +41,7 @@ remote_file "#{Chef::Config[:file_cache_path]}/#{tarball_name}" do source new_resource.url - checksum new_resource.checksum + checksum new_resource.checksum if new_resource.checksum retries new_resource.retries retry_delay new_resource.retry_delay mode '644' @@ -70,8 +51,6 @@ destination extract_dir end - node.default['java']['java_home'] = new_resource.java_home - # Set up .jinfo file for update-java-alternatives template "/usr/lib/jvm/.java-#{new_resource.version}-corretto.jinfo" do cookbook 'java' @@ -93,7 +72,7 @@ priority new_resource.alternatives_priority default new_resource.default reset_alternatives new_resource.reset_alternatives - action :set + not_if { new_resource.skip_alternatives } end end @@ -113,4 +92,9 @@ only_if { ::File.exist?(extract_dir) } action :delete end + + file "/usr/lib/jvm/.java-#{new_resource.version}-corretto.jinfo" do + only_if { platform_family?('debian') } + action :delete + end end diff --git a/resources/jce.rb b/resources/jce.rb index e01c23d6e..af69473e3 100644 --- a/resources/jce.rb +++ b/resources/jce.rb @@ -1,26 +1,44 @@ -# -# Cookbook:: java -# Provider:: jce -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -property :jdk_version, String, default: lazy { node['java']['jdk_version'].to_s }, description: 'The Java version to install into' -property :jce_url, String, default: lazy { node['java']['oracle']['jce'][jdk_version]['url'] }, description: 'The URL for the JCE distribution' -property :jce_checksum, String, default: lazy { node['java']['oracle']['jce'][jdk_version]['checksum'] }, description: 'The checksum of the JCE distribution' -property :java_home, String, default: lazy { node['java']['java_home'] }, description: 'The location of the Java installation' -property :jce_home, String, default: lazy { node['java']['oracle']['jce']['home'] }, description: 'The location where JCE files will be decompressed for installation' -property :jce_cookie, String, default: lazy { node['java']['oracle']['accept_oracle_download_terms'] ? 'oraclelicense=accept-securebackup-cookie' : '' }, description: 'Indicates that you accept Oracles EULA' -property :principal, String, default: lazy { platform_family?('windows') ? node['java']['windows']['owner'] : 'administrator' }, description: 'For Windows installations only, this determines the owner of the JCE files' +# frozen_string_literal: true + +provides :java_jce +unified_mode true + +property :jdk_version, + String, + name_property: true, description: 'The Java version to install into' + +property :jce_url, + String, + required: true, description: 'The URL for the JCE distribution' + +property :jce_checksum, + String, + required: true, description: 'The checksum of the JCE distribution' + +property :java_home, + String, + required: true, description: 'The location of the Java installation' + +property :jce_home, + String, + default: '/usr/lib/jvm/jce', description: 'The location where JCE files will be decompressed for installation' + +property :jce_cookie, + String, + default: '', description: 'Indicates that you accept Oracles EULA' + +property :principal, + String, + default: 'administrator', description: 'For Windows installations only, this determines the owner of the JCE files' + +property :download_path, + String, + default: Chef::Config[:file_cache_path], description: 'Path used to stage the JCE archive' + +property :install_type, + String, + equal_to: %w(jdk jre), + default: 'jdk', description: 'Whether the Java install is a jdk or jre layout' action :install do jdk_version = new_resource.jdk_version @@ -30,13 +48,20 @@ jce_home = new_resource.jce_home jce_cookie = new_resource.jce_cookie principal = new_resource.principal + download_path = new_resource.download_path + install_type = new_resource.install_type directory ::File.join(jce_home, jdk_version) do mode '0755' recursive true end - r = remote_file "#{node['java']['download_path']}/jce.zip" do + directory download_path do + mode '0755' + recursive true + end + + r = remote_file ::File.join(download_path, 'jce.zip') do source jce_url checksum jce_checksum headers( @@ -46,7 +71,7 @@ end # JRE installation does not have a jre folder - jre_path = node['java']['install_type'] == 'jdk' ? 'jre' : '' + jre_path = install_type == 'jdk' ? 'jre' : '' if platform_family?('windows') @@ -76,19 +101,23 @@ else package 'unzip' - package 'curl' - - execute 'extract jce' do - command <<-EOF - rm -rf java_jce - mkdir java_jce - cd java_jce - unzip -o ../jce.zip - find ./ -name '*.jar' | xargs -I JCE_JAR mv JCE_JAR #{jce_home}/#{jdk_version}/ - chmod -R 0644 #{jce_home}/#{jdk_version}/*.jar - EOF - cwd node['java']['download_path'] - creates ::File.join(jce_home, jdk_version, 'US_export_policy.jar') + + archive_file 'extract jce' do + path r.path + destination ::File.join(download_path, 'java_jce') + overwrite true + not_if { ::File.exist?(::File.join(jce_home, jdk_version, 'US_export_policy.jar')) } + end + + ruby_block 'stage jce policy jars' do + block do + ::Dir.glob(::File.join(download_path, 'java_jce', '**', '*.jar')).each do |jar| + destination = ::File.join(jce_home, jdk_version, ::File.basename(jar)) + ::FileUtils.mv(jar, destination) + ::FileUtils.chmod(0o644, destination) + end + end + not_if { ::File.exist?(::File.join(jce_home, jdk_version, 'US_export_policy.jar')) } end %w(local_policy.jar US_export_policy.jar).each do |jar| @@ -104,3 +133,32 @@ end end end + +action :remove do + jdk_version = new_resource.jdk_version + java_home = new_resource.java_home + jce_home = new_resource.jce_home + download_path = new_resource.download_path + jre_path = new_resource.install_type == 'jdk' ? 'jre' : '' + + %w(local_policy.jar US_export_policy.jar).each do |jar| + file ::File.join(java_home, jre_path, 'lib', 'security', jar) do + action :delete + only_if { ::File.symlink?(path) } + end + end + + directory ::File.join(jce_home, jdk_version) do + recursive true + action :delete + end + + directory ::File.join(download_path, 'java_jce') do + recursive true + action :delete + end + + file ::File.join(download_path, 'jce.zip') do + action :delete + end +end diff --git a/resources/openjdk_install.rb b/resources/openjdk_install.rb index 84673e697..e119b7178 100644 --- a/resources/openjdk_install.rb +++ b/resources/openjdk_install.rb @@ -1,30 +1,60 @@ -resource_name :openjdk_install +# frozen_string_literal: true + +provides :openjdk_install +unified_mode true include Java::Cookbook::OpenJdkHelpers -default_action :install +include Java::Cookbook::BinCmdHelpers + +property :install_type, + String, + equal_to: %w( package source ), + description: 'Installation type' + +property :pkg_names, + [String, Array], + description: 'List of packages to install' + +property :pkg_version, + String, + description: 'Package version to install' + +property :java_home, + String, + description: 'Set to override the java_home' + +property :source_install_dir, + String, + description: 'Directory under the versioned parent path where the source archive is installed' -property :version, String, name_property: true, description: 'Java major version to install' -property :install_type, String, default: 'package', equal_to: %w( package source ), description: 'Installation type' -property :pkg_names, [String, Array], description: 'List of packages to install' -property :pkg_version, String, description: 'Package version to install' -property :java_home, String, description: 'Set to override the java_home' -property :default, [true, false], description: ' Whether to set this as the defalut Java' -property :bin_cmds, Array, description: 'A list of bin_cmds based on the version and variant' -property :alternatives_priority, Integer, description: 'Alternatives priority to set for this Java' -property :reset_alternatives, [true, false], description: 'Whether to reset alternatives before setting' -property :url, String, description: 'The URL to download from' -property :checksum, String, description: 'The checksum for the downloaded file' -property :java_home_mode, String, description: 'The permission for the Java home directory' -property :java_home_owner, String, description: 'Owner of the Java Home' -property :java_home_group, String, description: 'Group for the Java Home' +property :bin_cmds, + Array, + description: 'A list of bin_cmds based on the version and variant' + +property :url, + String, + description: 'The URL to download from' + +property :checksum, + String, + description: 'The checksum for the downloaded file' + +use 'partial/_common' +use 'partial/_linux' +use 'partial/_java_home' +use 'partial/_openjdk' action :install do + install_type = new_resource.install_type || default_openjdk_install_method(new_resource.version) + bin_cmds = new_resource.bin_cmds || default_bin_cmds(new_resource.version) + if install_type == 'package' openjdk_pkg_install new_resource.version do pkg_names new_resource.pkg_names pkg_version new_resource.pkg_version java_home new_resource.java_home default new_resource.default - bin_cmds new_resource.bin_cmds + bin_cmds bin_cmds + skip_alternatives new_resource.skip_alternatives alternatives_priority new_resource.alternatives_priority reset_alternatives new_resource.reset_alternatives end @@ -33,10 +63,13 @@ url new_resource.url checksum new_resource.checksum java_home new_resource.java_home + source_install_dir new_resource.source_install_dir java_home_mode new_resource.java_home_mode + java_home_owner new_resource.java_home_owner java_home_group new_resource.java_home_group default new_resource.default - bin_cmds new_resource.bin_cmds + bin_cmds bin_cmds + skip_alternatives new_resource.skip_alternatives alternatives_priority new_resource.alternatives_priority reset_alternatives new_resource.reset_alternatives end @@ -46,13 +79,17 @@ end action :remove do + install_type = new_resource.install_type || default_openjdk_install_method(new_resource.version) + bin_cmds = new_resource.bin_cmds || default_bin_cmds(new_resource.version) + if install_type == 'package' openjdk_pkg_install new_resource.version do pkg_names new_resource.pkg_names pkg_version new_resource.pkg_version java_home new_resource.java_home default new_resource.default - bin_cmds new_resource.bin_cmds + bin_cmds bin_cmds + skip_alternatives new_resource.skip_alternatives alternatives_priority new_resource.alternatives_priority reset_alternatives new_resource.reset_alternatives action :remove @@ -62,10 +99,13 @@ url new_resource.url checksum new_resource.checksum java_home new_resource.java_home + source_install_dir new_resource.source_install_dir java_home_mode new_resource.java_home_mode + java_home_owner new_resource.java_home_owner java_home_group new_resource.java_home_group default new_resource.default - bin_cmds new_resource.bin_cmds + bin_cmds bin_cmds + skip_alternatives new_resource.skip_alternatives alternatives_priority new_resource.alternatives_priority reset_alternatives new_resource.reset_alternatives action :remove diff --git a/resources/openjdk_pkg_install.rb b/resources/openjdk_pkg_install.rb index 394fb71a3..783df2b83 100644 --- a/resources/openjdk_pkg_install.rb +++ b/resources/openjdk_pkg_install.rb @@ -1,70 +1,79 @@ -resource_name :openjdk_pkg_install +# frozen_string_literal: true + +provides :openjdk_pkg_install +unified_mode true include Java::Cookbook::OpenJdkHelpers -default_action :install +include Java::Cookbook::BinCmdHelpers -property :version, String, - name_property: true, - description: 'Java major version to install' +use 'partial/_common' +use 'partial/_linux' +use 'partial/_openjdk' property :pkg_names, [String, Array], - default: lazy { default_openjdk_pkg_names(version) }, - description: 'List of packages to install' + description: 'List of packages to install' property :pkg_version, String, - description: 'Package version to install' + description: 'Package version to install' property :java_home, String, - default: lazy { default_openjdk_pkg_java_home(version) }, - description: 'Set to override the java_home' - -property :default, [true, false], - default: true, - description: ' Whether to set this as the defalut Java' + description: 'Set to override the java_home' property :bin_cmds, Array, - default: lazy { default_openjdk_bin_cmds(version) }, - description: 'A list of bin_cmds based on the version and variant' + description: 'A list of bin_cmds based on the version and variant' property :alternatives_priority, Integer, - default: 1062, - description: 'Alternatives priority to set for this Java' + default: 1062, + description: 'Alternatives priority to set for this Java' -property :reset_alternatives, [true, false], - default: true, - description: 'Whether to reset alternatives before setting' +property :repository_uri, String, + description: 'URI for the repository mirror (e.g., "https://custom-mirror.example.com/openjdk/ubuntu")' action :install do + pkg_names = new_resource.pkg_names || default_openjdk_pkg_names(new_resource.version) + java_home = new_resource.java_home || default_openjdk_pkg_java_home(new_resource.version) + bin_cmds = new_resource.bin_cmds || default_bin_cmds(new_resource.version) + if platform?('ubuntu') apt_repository 'openjdk-r-ppa' do - uri 'ppa:openjdk-r' + uri new_resource.repository_uri || 'ppa:openjdk-r' end end - package new_resource.pkg_names do - version new_resource.pkg_version if new_resource.pkg_version - end + pkg_version = + if new_resource.pkg_version && pkg_names.is_a?(String) + new_resource.pkg_version + elsif new_resource.pkg_version && pkg_names.is_a?(Array) + Array.new(pkg_names.size, new_resource.pkg_version) + end - node.default['java']['java_home'] = new_resource.java_home + package pkg_names do + version pkg_version if pkg_version + end java_alternatives 'set-java-alternatives' do - java_location new_resource.java_home - bin_cmds new_resource.bin_cmds + java_location java_home + bin_cmds bin_cmds priority new_resource.alternatives_priority default new_resource.default reset_alternatives new_resource.reset_alternatives - action :set + not_if { new_resource.skip_alternatives } end end action :remove do + pkg_names = new_resource.pkg_names || default_openjdk_pkg_names(new_resource.version) + java_home = new_resource.java_home || default_openjdk_pkg_java_home(new_resource.version) + bin_cmds = new_resource.bin_cmds || default_bin_cmds(new_resource.version) + java_alternatives 'unset-java-alternatives' do - java_location new_resource.java_home - bin_cmds new_resource.bin_cmds - only_if { ::File.exist?(new_resource.java_home) } + java_location java_home + bin_cmds bin_cmds + only_if { ::File.exist?(java_home) } + not_if { new_resource.skip_alternatives } action :unset end - package new_resource.pkg_names do + package pkg_names do action :remove end diff --git a/resources/openjdk_source_install.rb b/resources/openjdk_source_install.rb index bc906fda6..0b07ecb73 100644 --- a/resources/openjdk_source_install.rb +++ b/resources/openjdk_source_install.rb @@ -1,58 +1,43 @@ -resource_name :openjdk_install +# frozen_string_literal: true + +provides :openjdk_source_install +unified_mode true include Java::Cookbook::OpenJdkHelpers -default_action :install +include Java::Cookbook::BinCmdHelpers property :version, String, - name_property: true, - description: 'Java version to install' + name_property: true, + description: 'Java version to install' property :url, String, - default: lazy { default_openjdk_url(version) }, - description: 'The URL to download from' + description: 'The URL to download from. Can be an internal mirror URL (e.g., "https://internal-mirror.example.com/java/openjdk/").' property :checksum, String, - regex: /^[0-9a-f]{32}$|^[a-zA-Z0-9]{40,64}$/, - default: lazy { default_openjdk_checksum(version) }, - description: 'The checksum for the downloaded file' + regex: /^[0-9a-f]{32}$|^[a-zA-Z0-9]{40,64}$/, + description: 'The checksum for the downloaded file' property :java_home, String, - default: lazy { "/usr/lib/jvm/java-#{version}-openjdk/jdk-#{version}" }, - description: 'Set to override the java_home' - -property :java_home_mode, String, - default: '0755', - description: 'The permission for the Java home directory' - -property :java_home_owner, String, - default: 'root', - description: 'Owner of the Java Home' + description: 'Set to override the java_home' -property :java_home_group, String, - default: lazy { node['root_group'] }, - description: 'Group for the Java Home' - -property :default, [true, false], - default: true, - description: ' Whether to set this as the defalut Java' +property :source_install_dir, String, + description: 'Directory under the versioned parent path where the source archive is installed' property :bin_cmds, Array, - default: lazy { default_openjdk_bin_cmds(version) }, - description: 'A list of bin_cmds based on the version and variant' - -property :alternatives_priority, Integer, - default: 1, - description: 'Alternatives priority to set for this Java' + description: 'A list of bin_cmds based on the version and variant' -property :reset_alternatives, [true, false], - default: true, - description: 'Whether to reset alternatives before setting' +use 'partial/_common' +use 'partial/_linux' +use 'partial/_java_home' +use 'partial/_openjdk' action :install do - extract_dir = new_resource.java_home.split('/')[0..-2].join('/') - parent_dir = new_resource.java_home.split('/')[0..-3].join('/') - tarball_name = new_resource.url.split('/').last + url = new_resource.url || default_openjdk_url(new_resource.version, new_resource.variant) + checksum = new_resource.checksum || default_openjdk_checksum(new_resource.version) + java_home = resolved_java_home(url) + bin_cmds = new_resource.bin_cmds || default_bin_cmds(new_resource.version) + tarball_name = url.split('/').last - directory parent_dir do + directory java_home do owner new_resource.java_home_owner group new_resource.java_home_group mode new_resource.java_home_mode @@ -60,43 +45,84 @@ end remote_file "#{Chef::Config[:file_cache_path]}/#{tarball_name}" do - source new_resource.url - checksum new_resource.checksum + source url + checksum checksum retries new_resource.retries retry_delay new_resource.retry_delay mode '644' end archive_file "#{Chef::Config[:file_cache_path]}/#{tarball_name}" do - destination extract_dir + destination java_home + strip_components 1 + overwrite true + owner new_resource.java_home_owner + group new_resource.java_home_group + mode new_resource.java_home_mode + not_if { ::File.exist?(::File.join(java_home, 'bin', 'java')) } end - node.default['java']['java_home'] = new_resource.java_home - java_alternatives 'set-java-alternatives' do - java_location new_resource.java_home - bin_cmds new_resource.bin_cmds + java_location java_home + bin_cmds bin_cmds priority new_resource.alternatives_priority default new_resource.default reset_alternatives new_resource.reset_alternatives + not_if { new_resource.skip_alternatives } action :set end + + file '/etc/profile.d/java.sh' do + content "export JAVA_HOME=#{java_home}\n" + owner 'root' + group 'root' + mode '0644' + end end action :remove do - extract_dir = new_resource.java_home.split('/')[0..-2].join('/') + url = new_resource.url || default_openjdk_url(new_resource.version, new_resource.variant) + java_home = resolved_java_home(url) + bin_cmds = new_resource.bin_cmds || default_bin_cmds(new_resource.version) java_alternatives 'unset-java-alternatives' do - java_location new_resource.java_home - bin_cmds new_resource.bin_cmds - only_if { ::File.exist?(extract_dir) } + java_location java_home + bin_cmds bin_cmds + only_if { ::File.exist?(java_home) } + not_if { new_resource.skip_alternatives } action :unset end - directory "Removing #{extract_dir}" do - path extract_dir + directory "Removing #{java_home}" do + path java_home recursive true - only_if { ::File.exist?(extract_dir) } + only_if { ::File.exist?(java_home) } action :delete end + + file '/etc/profile.d/java.sh' do + action :delete + end +end + +action_class do + def resolved_java_home(url) + return new_resource.java_home if new_resource.java_home + + install_dir = + if new_resource.source_install_dir + new_resource.source_install_dir + elsif new_resource.url + source_install_dir_from_url(url) + else + "jdk-#{new_resource.version}" + end + + "/usr/lib/jvm/java-#{new_resource.version}-openjdk/#{install_dir}" + end + + def source_install_dir_from_url(url) + ::File.basename(::URI.parse(url).path) + .sub(/\.(?:tar\.(?:gz|bz2|xz)|tgz|tbz2|zip)\z/i, '') + end end diff --git a/resources/partial/_common.rb b/resources/partial/_common.rb new file mode 100644 index 000000000..c95d9b88e --- /dev/null +++ b/resources/partial/_common.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +property :version, String, + name_property: true, + description: 'Java version to install' + +property :skip_alternatives, [true, false], + default: false, + description: 'Skip alternatives installation' diff --git a/resources/partial/_java_home.rb b/resources/partial/_java_home.rb new file mode 100644 index 000000000..a99ae72ae --- /dev/null +++ b/resources/partial/_java_home.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +property :java_home_mode, String, + default: '0755', + description: 'The permission for the Java home directory' + +property :java_home_owner, String, + default: 'root', + description: 'Owner of the Java Home' + +property :java_home_group, String, + default: lazy { node['root_group'] }, + description: 'Group for the Java Home' diff --git a/resources/partial/_linux.rb b/resources/partial/_linux.rb new file mode 100644 index 000000000..d18532d32 --- /dev/null +++ b/resources/partial/_linux.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +property :alternatives_priority, Integer, + default: 1, + description: 'Alternatives priority to set for this Java' + +property :reset_alternatives, [true, false], + default: true, + description: 'Whether to reset alternatives before setting' + +property :default, [true, false], + default: true, + description: ' Whether to set this as the default Java' diff --git a/resources/partial/_macos.rb b/resources/partial/_macos.rb new file mode 100644 index 000000000..0c2402fde --- /dev/null +++ b/resources/partial/_macos.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +property :tap_url, + String, + description: 'The URL of the tap' + +property :cask_options, + String, + description: 'Options to pass to the brew command during installation' + +property :homebrew_path, + String, + description: 'The path to the homebrew binary' + +property :owner, + [String, Integer], + description: 'The owner of the Homebrew installation' diff --git a/resources/partial/_openjdk.rb b/resources/partial/_openjdk.rb new file mode 100644 index 000000000..ec7a07211 --- /dev/null +++ b/resources/partial/_openjdk.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +property :variant, String, + equal_to: %w(openjdk temurin), + default: 'openjdk', + description: 'Install flavour' diff --git a/resources/temurin_package_install.rb b/resources/temurin_package_install.rb new file mode 100644 index 000000000..b7308da30 --- /dev/null +++ b/resources/temurin_package_install.rb @@ -0,0 +1,131 @@ +# frozen_string_literal: true + +provides :temurin_package_install +unified_mode true +include Java::Cookbook::OpenJdkHelpers +include Java::Cookbook::BinCmdHelpers + +use 'partial/_common' +use 'partial/_linux' + +def default_temurin_pkg_name(version) + "temurin-#{version}-jdk" +end + +def default_temurin_rpm_baseurl + return 'https://packages.adoptium.net/artifactory/rpm/amazonlinux/2/$basearch' if platform?('amazon') + + repository_platform = value_for_platform( + %w(almalinux oracle redhat rocky) => { 'default' => 'rhel' }, + 'centos' => { 'default' => 'centos' }, + 'fedora' => { 'default' => 'fedora' }, + 'default' => node['platform'] + ) + + "https://packages.adoptium.net/artifactory/rpm/#{repository_platform}/$releasever/$basearch" +end + +property :pkg_name, String, + description: 'Package name to install' + +property :pkg_version, String, + description: 'Package version to install' + +property :java_home, String, + description: 'Set to override the java_home' + +property :bin_cmds, Array, + description: 'A list of bin_cmds based on the version' + +property :repository_uri, String, + description: 'URI for the repository mirror (e.g., "https://custom-mirror.example.com/artifactory/deb")' + +action :install do + keyring_path = '/usr/share/keyrings/adoptium.asc' + pkg_name = new_resource.pkg_name || default_temurin_pkg_name(new_resource.version) + java_home = new_resource.java_home || "/usr/lib/jvm/temurin-#{new_resource.version}-jdk" + bin_cmds = new_resource.bin_cmds || default_bin_cmds(new_resource.version) + + remote_file keyring_path do + source 'https://packages.adoptium.net/artifactory/api/gpg/key/public' + mode '0644' + only_if { platform_family?('debian') } + end + + apt_repository 'adoptium' do + uri new_resource.repository_uri || 'https://packages.adoptium.net/artifactory/deb' + components ['main'] + distribution lazy { node['lsb']['codename'] || node['debian']['distribution_codename'] } + signed_by keyring_path + only_if { platform_family?('debian') } + end + + yum_repository 'adoptium' do + description 'Eclipse Adoptium' + baseurl new_resource.repository_uri || default_temurin_rpm_baseurl + enabled true + gpgcheck true + gpgkey 'https://packages.adoptium.net/artifactory/api/gpg/key/public' + only_if { platform_family?('rhel', 'fedora', 'amazon', 'rocky', 'suse', 'oraclelinux') } + end + + zypper_repository 'adoptium' do + description 'Eclipse Adoptium' + baseurl new_resource.repository_uri || 'https://packages.adoptium.net/artifactory/rpm/opensuse/$releasever/$basearch' + gpgcheck true + gpgkey 'https://packages.adoptium.net/artifactory/api/gpg/key/public' + action :create + only_if { platform_family?('suse') } + end + + package pkg_name do + version new_resource.pkg_version if new_resource.pkg_version + end + + java_alternatives 'set-java-alternatives' do + java_location java_home + bin_cmds bin_cmds + priority new_resource.alternatives_priority + default new_resource.default + reset_alternatives new_resource.reset_alternatives + not_if { new_resource.skip_alternatives } + end +end + +action :remove do + pkg_name = new_resource.pkg_name || default_temurin_pkg_name(new_resource.version) + java_home = new_resource.java_home || "/usr/lib/jvm/temurin-#{new_resource.version}-jdk" + bin_cmds = new_resource.bin_cmds || default_bin_cmds(new_resource.version) + + java_alternatives 'unset-java-alternatives' do + java_location java_home + bin_cmds bin_cmds + only_if { ::File.exist?(java_home) } + action :unset + not_if { new_resource.skip_alternatives } + end + + package pkg_name do + action :remove + end + + apt_repository 'adoptium' do + action :remove + only_if { platform_family?('debian') } + end + + file '/usr/share/keyrings/adoptium.asc' do + action :delete + only_if { platform_family?('debian') } + end + + yum_repository 'adoptium' do + action :remove + only_if { platform_family?('rhel', 'fedora', 'amazon', 'rocky', 'suse', 'oraclelinux') } + end + + zypper_repository 'adoptium' do + action :remove + only_if { platform_family?('suse') } + end +end diff --git a/spec/libraries/adopt_openjdk_helpers_spec.rb b/spec/libraries/adopt_openjdk_helpers_spec.rb deleted file mode 100644 index 6eb05071c..000000000 --- a/spec/libraries/adopt_openjdk_helpers_spec.rb +++ /dev/null @@ -1,103 +0,0 @@ -require 'spec_helper' - -RSpec.describe Java::Cookbook::AdoptOpenJdkHelpers do - class DummyClass < Chef::Node - include Java::Cookbook::AdoptOpenJdkHelpers - end - - subject { DummyClass.new } - - describe '#sub_dir' do - before do - allow(subject).to receive(:[]).with('url').and_return(url) - end - - context 'AdoptOpenJDK 8 Hotspot' do - let(:url) { 'https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u242-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u242b08.tar.gz' } - - it 'returns the correct folder name' do - expect(subject.sub_dir(url)).to eq 'jdk8u242-b08' - end - end - - context 'OpenJDK 8 OpenJ9' do - let(:url) { 'https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u242-b08_openj9-0.18.1/OpenJDK8U-jdk_x64_linux_openj9_8u242b08_openj9-0.18.1.tar.gz' } - - it 'returns the correct folder name' do - expect(subject.sub_dir(url)).to eq 'jdk8u242-b08' - end - end - - context 'OpenJKDK 8 Large Heap' do - let(:url) { 'https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u242-b08_openj9-0.18.1/OpenJDK8U-jdk_x64_linux_openj9_linuxXL_8u242b08_openj9-0.18.1.tar.gz' } - - it 'returns the correct folder name' do - expect(subject.sub_dir(url)).to eq 'jdk8u242-b08' - end - end - - context 'AdoptOpenJDK 11 Hotspot' do - let(:url) { 'https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.6%2B10/OpenJDK11U-jdk_x64_linux_hotspot_11.0.6_10.tar.gz' } - - it 'returns the correct folder name' do - expect(subject.sub_dir(url)).to eq 'jdk-11.0.6+10' - end - end - - context 'AdoptOpenJDK 11 OpenJ9' do - let(:url) { 'https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.6%2B10_openj9-0.18.1/OpenJDK11U-jdk_x64_linux_openj9_11.0.6_10_openj9-0.18.1.tar.gz' } - - it 'returns the correct folder name' do - expect(subject.sub_dir(url)).to eq 'jdk-11.0.6+10' - end - end - - context 'AdoptOpenJDK 11 LargeHeap' do - let(:url) { 'https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.6%2B10_openj9-0.18.1/OpenJDK11U-jdk_x64_linux_openj9_linuxXL_11.0.6_10_openj9-0.18.1.tar.gz' } - - it 'returns the correct folder name' do - expect(subject.sub_dir(url)).to eq 'jdk-11.0.6+10' - end - end - - context 'AdoptOpenJDK 14 Hotspot' do - let(:url) { 'https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14%2B36/OpenJDK14U-jdk_x64_linux_hotspot_14_36.tar.gz' } - - it 'returns the correct folder name' do - expect(subject.sub_dir(url)).to eq 'jdk-14+36' - end - end - - context 'AdoptOpenJDK 14 LargeHeap' do - let(:url) { 'https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14%2B36.1_openj9-0.19.0/OpenJDK14U-jdk_x64_linux_openj9_linuxXL_14_36_openj9-0.19.0.tar.gz' } - - it 'returns the correct folder name' do - expect(subject.sub_dir(url)).to eq 'jdk-14+36' - end - end - end - - describe '#default_adopt_openjdk_url' do - before do - allow(subject).to receive(:[]).with('version').and_return(version) - end - - context 'AdoptOpenJDK 11 LargeHeap' do - let(:version) { '11' } - let(:variant) { 'openj9-large-heap' } - - it 'returns the correct folder name' do - expect(subject.default_adopt_openjdk_url(version)[variant]).to eq 'https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.6%2B10_openj9-0.18.1/OpenJDK11U-jdk_x64_linux_openj9_linuxXL_11.0.6_10_openj9-0.18.1.tar.gz' - end - end - - context 'AdoptOpenJDK 11 OpenJ9' do - let(:version) { '11' } - let(:variant) { 'openj9' } - - it 'returns the correct folder name' do - expect(subject.default_adopt_openjdk_url(version)[variant]).to eq 'https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.6%2B10_openj9-0.18.1/OpenJDK11U-jdk_x64_linux_openj9_11.0.6_10_openj9-0.18.1.tar.gz' - end - end - end -end diff --git a/spec/libraries/adopt_openjdk_macos_helpers_spec.rb b/spec/libraries/adopt_openjdk_macos_helpers_spec.rb deleted file mode 100644 index 6f98ecd5c..000000000 --- a/spec/libraries/adopt_openjdk_macos_helpers_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'spec_helper' - -RSpec.describe Java::Cookbook::AdoptOpenJdkMacOsHelpers do - class DummyClass < Chef::Node - include Java::Cookbook::AdoptOpenJdkMacOsHelpers - end - - subject { DummyClass.new } - - describe '#macos_java_home' do - before do - allow(subject).to receive(:[]).with('version').and_return(version) - end - - context 'adoptopenjdk14' do - let(:version) { 'adoptopenjdk14' } - - it 'returns the correct folder' do - expect(subject.macos_java_home(version)).to eq '/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home' - end - end - - context 'adoptopenjdk14-openj9-jre' do - let(:version) { 'adoptopenjdk14-openj9-jre' } - - it 'returns the correct folder' do - expect(subject.macos_java_home(version)).to eq '/Library/Java/JavaVirtualMachines/adoptopenjdk-14-openj9.jre/Contents/Home' - end - end - - context 'adoptopenjdk14-openj9-jre-large' do - let(:version) { 'adoptopenjdk14-openj9-jre-large' } - - it 'returns the correct folder' do - expect(subject.macos_java_home(version)).to eq '/Library/Java/JavaVirtualMachines/adoptopenjdk-14-openj9.jre/Contents/Home' - end - end - - context 'adoptopenjdk14-openj9-large' do - let(:version) { 'adoptopenjdk14-openj9-large' } - - it 'returns the correct folder' do - expect(subject.macos_java_home(version)).to eq '/Library/Java/JavaVirtualMachines/adoptopenjdk-14-openj9.jdk/Contents/Home' - end - end - end -end diff --git a/spec/libraries/bin_cmd_helpers_spec.rb b/spec/libraries/bin_cmd_helpers_spec.rb new file mode 100644 index 000000000..2217ca20b --- /dev/null +++ b/spec/libraries/bin_cmd_helpers_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Java::Cookbook::BinCmdHelpers do + subject(:helper) do + Class.new do + include Java::Cookbook::BinCmdHelpers + end.new + end + + describe '#default_bin_cmds' do + it 'returns Java command alternatives for Temurin 25' do + expect(helper.default_bin_cmds('25')).to include('java', 'javac', 'keytool', 'jwebserver') + end + + it 'logs a fatal error for unsupported versions' do + allow(Chef::Log).to receive(:fatal) + + helper.default_bin_cmds('26') + + expect(Chef::Log).to have_received(:fatal).with('Version specified does not have a default set of bin_cmds') + end + end +end diff --git a/spec/libraries/certificate_helpers_spec.rb b/spec/libraries/certificate_helpers_spec.rb new file mode 100644 index 000000000..0f60f40b3 --- /dev/null +++ b/spec/libraries/certificate_helpers_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +RSpec.describe Java::Cookbook::CertificateHelpers do + class DummyClass < Chef::Node + include Java::Cookbook::CertificateHelpers + end + + subject { DummyClass.new } + + describe '#default_truststore_path' do + context 'Java 9' do + let(:version) { '9' } + let(:java_home) { '/usr/lib/jvm/corretto-9' } + + it 'returns the correct path' do + expect(subject.default_truststore_path(version, java_home)).to eq('/usr/lib/jvm/corretto-9/lib/security/cacerts') + end + end + end + + describe '#keystore_argument' do + context 'cacerts set ' do + let(:cacerts) { true } + let(:truststore_path) { '/usr/lib/jvm/corretto-9/jre/lib/security/cacerts' } + + it 'returns the correct argument' do + expect(subject.keystore_argument(cacerts, truststore_path)).to eq(['-cacerts']) + end + end + + context 'no cacerts' do + let(:cacerts) { false } + let(:truststore_path) { '/mycertstore.jks' } + + it 'returns the correct argument' do + expect(subject.keystore_argument(cacerts, truststore_path)).to eq(['-keystore', '/mycertstore.jks']) + end + end + end +end diff --git a/spec/libraries/corretto_helpers_spec.rb b/spec/libraries/corretto_helpers_spec.rb index a6580ea96..152f7077d 100644 --- a/spec/libraries/corretto_helpers_spec.rb +++ b/spec/libraries/corretto_helpers_spec.rb @@ -10,23 +10,62 @@ class DummyClass < Chef::Node describe '#default_corretto_url' do before do allow(subject).to receive(:[]).with('version').and_return(version) + allow(subject).to receive(:[]).with('kernel').and_return('machine' => machine) end - context 'Corretto 8' do - let(:version) { '8' } + context 'Corretto 11 x64' do + let(:version) { '11' } + let(:machine) { 'x86_64' } it 'returns the correct URL' do - expect(subject.default_corretto_url(version)).to match /corretto-8.+\.tar.gz/ + expect(subject.default_corretto_url(version)).to match /corretto-11.+\.tar.gz/ end end - context 'Corretto 11' do + context 'Corretto 17 x64' do + let(:version) { '17' } + let(:machine) { 'x86_64' } + + it 'returns the correct URL' do + expect(subject.default_corretto_url(version)).to match /corretto-17.+\.tar.gz/ + end + end + + context 'Corretto 18 x64' do + let(:version) { '18' } + let(:machine) { 'x86_64' } + + it 'returns the correct URL' do + expect(subject.default_corretto_url(version)).to match /corretto-18.+\.tar.gz/ + end + end + + context 'Corretto 11 aarch64' do let(:version) { '11' } + let(:machine) { 'aarch64' } it 'returns the correct URL' do expect(subject.default_corretto_url(version)).to match /corretto-11.+\.tar.gz/ end end + + context 'Corretto 17 aarch64' do + let(:version) { '17' } + let(:machine) { 'aarch64' } + + it 'returns the correct URL' do + expect(subject.default_corretto_url(version)).to match /corretto-17.+\.tar.gz/ + end + end + + context 'Corretto 18 aarch64' do + let(:version) { '18' } + let(:machine) { 'aarch64' } + + it 'returns the correct URL' do + expect(subject.default_corretto_url(version)).to match /corretto-18.+\.tar.gz/ + end + end end describe '#default_bin_cmds' do @@ -34,52 +73,91 @@ class DummyClass < Chef::Node allow(subject).to receive(:[]).with('version').and_return(version) end - context 'Corretto 8' do - let(:version) { '8' } + context 'Corretto 11' do + let(:version) { '11' } it 'returns the correct bin command array' do - expect(subject.default_corretto_bin_cmds(version)).to include 'appletviewer' - expect(subject.default_corretto_bin_cmds(version)).to_not include 'jaotc' + expect(subject.default_corretto_bin_cmds(version)).to_not include 'appletviewer' + expect(subject.default_corretto_bin_cmds(version)).to include 'jaotc' end end - context 'Corretto 11' do - let(:version) { '11' } + context 'Corretto 17' do + let(:version) { '17' } it 'returns the correct bin command array' do - expect(subject.default_corretto_bin_cmds(version)).to_not include 'appletviewer' + expect(subject.default_corretto_bin_cmds(version)).to_not include 'jjs' expect(subject.default_corretto_bin_cmds(version)).to include 'jaotc' end end - end - describe '#corretto_sub_dir' do - before do - allow(subject).to receive(:[]).with('version', 'full_version').and_return(version) + context 'Corretto 18' do + let(:version) { '18' } + + it 'returns the correct bin command array' do + expect(subject.default_corretto_bin_cmds(version)).to_not include 'jjs' + expect(subject.default_corretto_bin_cmds(version)).to include 'jaotc' + end end - context 'No full_version passed for Corretto 8' do - let(:version) { '8' } + describe '#corretto_sub_dir' do + before do + allow(subject).to receive(:[]).with('version', 'full_version').and_return(version) + allow(subject).to receive(:[]).with('kernel').and_return('machine' => machine) + end + + context 'No full_version passed for Corretto 11 x64' do + let(:version) { '11' } + let(:machine) { 'x86_64' } - it 'returns the default directory value for Corrretto 8' do - expect(subject.corretto_sub_dir(version)).to include '242' + it 'returns the default directory value for Corrretto 11 x64' do + expect(subject.corretto_sub_dir(version)).to include '11.0.15.9.1' + end end - end - context 'No full_version passed for Corretto 11' do - let(:version) { '11' } + context 'No full_version passed for Corretto 11 aarch64' do + let(:version) { '11' } + let(:machine) { 'aarch64' } - it 'returns the default directory value for Corrretto 8' do - expect(subject.corretto_sub_dir(version)).to include '0.6.10.1' + it 'returns the default directory value for Corrretto 11 aarch64' do + expect(subject.corretto_sub_dir(version)).to include '11.0.15.9.1' + end + end + + context 'No full_version passed for Corretto 17 x64' do + let(:version) { '17' } + let(:machine) { 'x86_64' } + + it 'returns the default directory value for Corrretto 17 x64' do + expect(subject.corretto_sub_dir(version)).to include '17.0.3.6.1' + end + end + + context 'No full_version passed for Corretto 17 aarch64' do + let(:version) { '17' } + let(:machine) { 'aarch64' } + + it 'returns the default directory value for Corrretto 17 aarch64' do + expect(subject.corretto_sub_dir(version)).to include '17.0.3.6.1' + end + end + + context 'No full_version passed for Corretto 18 x64' do + let(:version) { '18' } + let(:machine) { 'x86_64' } + + it 'returns the default directory value for Corrretto 18 x64' do + expect(subject.corretto_sub_dir(version)).to include '18.0.1.10.1' + end end - end - context 'A full version passed for for Corretto 8' do - let(:version) { '8' } - let(:full_version) { '8.123.45.6' } + context 'No full_version passed for Corretto 18 aarch64' do + let(:version) { '18' } + let(:machine) { 'aarch64' } - it 'returns the default directory value for Corrretto 8' do - expect(subject.corretto_sub_dir(version, full_version)).to include '8.123.45.6' + it 'returns the default directory value for Corrretto 18 aarch64' do + expect(subject.corretto_sub_dir(version)).to include '18.0.1.10.1' + end end end end diff --git a/spec/libraries/openjdk_helpers_spec.rb b/spec/libraries/openjdk_helpers_spec.rb new file mode 100644 index 000000000..b9950f9b0 --- /dev/null +++ b/spec/libraries/openjdk_helpers_spec.rb @@ -0,0 +1,293 @@ +require 'spec_helper' + +RSpec.describe Java::Cookbook::OpenJdkHelpers do + class DummyClass < Chef::Node + include Java::Cookbook::OpenJdkHelpers + end + + subject { DummyClass.new } + + describe '#lts' do + it 'returns the currently supported OpenJDK versions minus version 8' do + expect(subject.lts).to include('11', '17') + end + end + + describe '#default_openjdk_url' do + before do + allow(subject).to receive(:[]).with(version).and_return(version) + end + + context 'OpenJDK 17' do + let(:version) { '17' } + + it 'returns the correct download URL' do + expect(subject.default_openjdk_url(version)).to eq 'https://download.java.net/java/GA/jdk17/0d483333a00540d886896bac774ff48b/35/GPL/openjdk-17_linux-x64_bin.tar.gz' + end + end + + context 'Invalid OpenJDK version' do + let(:version) { '18.2' } + + it 'should raise an error' do + expect { subject.default_openjdk_url(version) } + .to raise_error('Version supplied does not have a download URL set') + end + end + + context 'Temurin' do + let(:version) { '17' } + + it 'returns the correct download URL for Temurin' do + expect(subject.default_openjdk_url(version, 'temurin')) + .to eq 'https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.13%2B11/OpenJDK17U-jdk_x64_linux_hotspot_17.0.13_11.tar.gz' + end + + it 'returns the correct download URL for Temurin 11' do + expect(subject.default_openjdk_url('11', 'temurin')) + .to eq 'https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.25%2B9/OpenJDK11U-jdk_x64_linux_hotspot_11.0.25_9.tar.gz' + end + end + end + + describe '#default_openjdk_install_method' do + before do + allow(subject).to receive(:[]).with(version).and_return(version) + allow(subject).to receive(:[]).with('platform_family').and_return(platform_family) + allow(subject).to receive(:[]).with('platform').and_return(platform) + allow(subject).to receive(:[]).with('platform_version').and_return(platform_version) + end + + context 'Amazon' do + let(:platform_family) { 'amazon' } + let(:platform) { 'amazon' } + let(:platform_version) { '2' } + let(:version) { '17' } + it 'should default to a source install' do + expect(subject.default_openjdk_install_method(version)).to eq 'source' + end + end + + context 'RHEL 9' do + let(:platform_family) { 'rhel' } + let(:platform) { 'almalinux' } + let(:platform_version) { '9.6' } + + context 'OpenJDK 11' do + let(:version) { '11' } + + it 'should default to a package install' do + expect(subject.default_openjdk_install_method(version)).to eq 'package' + end + end + + context 'OpenJDK 17' do + let(:version) { '17' } + + it 'should default to a package install' do + expect(subject.default_openjdk_install_method(version)).to eq 'package' + end + end + end + + context 'RHEL 10' do + let(:platform_family) { 'rhel' } + let(:platform) { 'almalinux' } + let(:platform_version) { '10.2' } + + context 'OpenJDK 11' do + let(:version) { '11' } + + it 'should default to a source install' do + expect(subject.default_openjdk_install_method(version)).to eq 'source' + end + end + + context 'OpenJDK 17' do + let(:version) { '17' } + + it 'should default to a source install' do + expect(subject.default_openjdk_install_method(version)).to eq 'source' + end + end + end + + context 'Fedora' do + let(:platform_family) { 'fedora' } + let(:platform) { 'fedora' } + let(:platform_version) { '44' } + + context 'OpenJDK 11' do + let(:version) { '11' } + + it 'should default to a source install' do + expect(subject.default_openjdk_install_method(version)).to eq 'source' + end + end + + context 'OpenJDK 17' do + let(:version) { '17' } + + it 'should default to a source install' do + expect(subject.default_openjdk_install_method(version)).to eq 'source' + end + end + end + + context 'Debian' do + let(:platform_family) { 'debian' } + let(:platform) { 'debian' } + + context '9' do + let(:platform_version) { '9' } + + context 'OpenJDK 8' do + let(:version) { '8' } + + it 'should default to a package install' do + expect(subject.default_openjdk_install_method(version)).to eq 'package' + end + end + + context 'OpenJDK 11' do + let(:version) { '11' } + + it 'should default to a source install' do + expect(subject.default_openjdk_install_method(version)).to eq 'source' + end + end + + context 'OpenJDK 17' do + let(:version) { '17' } + + it 'should default to a source install' do + expect(subject.default_openjdk_install_method(version)).to eq 'source' + end + end + end + + context '10' do + let(:platform_version) { '10' } + + context 'OpenJDK 17' do + let(:version) { '17' } + + it 'should default to a source install' do + expect(subject.default_openjdk_install_method(version)).to eq 'source' + end + end + + context 'OpenJDK 11' do + let(:version) { '11' } + + it 'should default to a package install' do + expect(subject.default_openjdk_install_method(version)).to eq 'package' + end + end + end + + context '11' do + let(:platform_version) { '11' } + + context 'OpenJDK 17' do + let(:version) { '17' } + + it 'should default to a package install' do + expect(subject.default_openjdk_install_method(version)).to eq 'package' + end + end + + context 'OpenJDK 11' do + let(:version) { '11' } + + it 'should default to a package install' do + expect(subject.default_openjdk_install_method(version)).to eq 'package' + end + end + end + + context '12' do + let(:platform_version) { '12' } + + context 'OpenJDK 11' do + let(:version) { '11' } + + it 'should default to a source install' do + expect(subject.default_openjdk_install_method(version)).to eq 'source' + end + end + + context 'OpenJDK 17' do + let(:version) { '17' } + + it 'should default to a package install' do + expect(subject.default_openjdk_install_method(version)).to eq 'package' + end + end + end + + context '13' do + let(:platform_version) { '13' } + + context 'OpenJDK 17' do + let(:version) { '17' } + + it 'should default to a source install' do + expect(subject.default_openjdk_install_method(version)).to eq 'source' + end + end + end + + context 'Ubuntu 18.04' do + let(:platform) { 'ubuntu' } + let(:platform_version) { '18.04' } + + context 'OpenJDK 17' do + let(:version) { '17' } + + it 'should default to a source install' do + expect(subject.default_openjdk_install_method(version)).to eq 'source' + end + end + + context 'OpenJDK 11' do + let(:version) { '11' } + + it 'should default to a package install' do + expect(subject.default_openjdk_install_method(version)).to eq 'package' + end + end + end + + context 'Ubuntu 20.04' do + let(:platform) { 'ubuntu' } + let(:platform_version) { '20.04' } + + context 'OpenJDK 17' do + let(:version) { '17' } + + it 'should default to a package install' do + expect(subject.default_openjdk_install_method(version)).to eq 'package' + end + end + + context 'OpenJDK 11' do + let(:version) { '11' } + + it 'should default to a package install' do + expect(subject.default_openjdk_install_method(version)).to eq 'package' + end + end + end + end + + # context 'Debian 11' do + # let(:platform_family) { 'debian' } + # let(:platform_version) { '10' } + # let(:version) { '17' } + # it 'should default to a package install' do + # expect(subject.default_openjdk_install_method(version)).to eq 'package' + # end + # end + end +end diff --git a/spec/resources/alternatives_spec.rb b/spec/resources/alternatives_spec.rb new file mode 100644 index 000000000..3d4953d8e --- /dev/null +++ b/spec/resources/alternatives_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'java_alternatives' do + let(:runner) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '24.04', step_into: ['java_alternatives']) } + + it 'converges with an empty command list without shelling out' do + expect { runner.converge('test::alternatives_spec') }.not_to raise_error + end + + it 'supports unsetting command alternatives' do + stubs_for_provider('java_alternatives[test-unset-alternatives]') do |provider| + allow(provider).to receive_shell_out('update-alternatives', '--remove', 'java', '/opt/java/bin/java') + end + + expect { runner.converge('test::alternatives_unset_spec') }.not_to raise_error + end + + it 'does not reinstall an existing Debian alternative' do + allow(::File).to receive(:exist?).and_call_original + allow(::File).to receive(:exist?).with('/opt/java/bin/java').and_return(true) + allow(::File).to receive(:exist?).with('/var/lib/dpkg/alternatives/java').and_return(true) + allow(::File).to receive(:exist?).with('/var/lib/alternatives/java').and_return(false) + + stubs_for_provider('java_alternatives[test-existing-alternatives]') do |provider| + display = <<~OUTPUT + java - auto mode + link best version is /opt/java/bin/java + link currently points to /opt/java/bin/java + link java is /usr/bin/java + /opt/java/bin/java - priority 1062 + OUTPUT + + allow(provider).to receive(:shell_out) + .with('update-alternatives', '--display', 'java') + .and_return(instance_double(Mixlib::ShellOut, stdout: display, exitstatus: 0)) + allow(provider).to receive(:shell_out!) do |*args| + raise "unexpected shell_out!: #{args.join(' ')}" + end + end + + expect { runner.converge('test::alternatives_existing_spec') }.not_to raise_error + end +end diff --git a/spec/resources/certificate_spec.rb b/spec/resources/certificate_spec.rb new file mode 100644 index 000000000..f71fd487c --- /dev/null +++ b/spec/resources/certificate_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'java_certificate' do + let(:shellout) do + instance_double(Mixlib::ShellOut, run_command: nil, stdout: '', exitstatus: 0, format_for_exception: '') + end + + before do + allow(Mixlib::ShellOut).to receive(:new).and_return(shellout) + end + + let(:runner) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '24.04', step_into: ['java_certificate']) } + + it 'steps into certificate install without invoking host keytool' do + expect { runner.converge('test::certificate_spec') }.not_to raise_error + end +end diff --git a/spec/resources/corretto_install_spec.rb b/spec/resources/corretto_install_spec.rb new file mode 100644 index 000000000..c42aaf13b --- /dev/null +++ b/spec/resources/corretto_install_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'corretto_install' do + let(:runner) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '24.04', step_into: ['corretto_install']) } + let(:converge) { runner.converge('test::corretto_spec') } + + it 'downloads the Corretto archive' do + expect(converge).to create_remote_file(::File.join(Chef::Config[:file_cache_path], 'corretto.tar.gz')) + end + + it 'creates a Debian jinfo file' do + expect(converge).to create_template('/usr/lib/jvm/.java-17-corretto.jinfo') + end +end diff --git a/spec/resources/jce_spec.rb b/spec/resources/jce_spec.rb new file mode 100644 index 000000000..1524c614c --- /dev/null +++ b/spec/resources/jce_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'java_jce' do + context 'install' do + let(:runner) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '24.04', step_into: ['java_jce']) } + let(:converge) { runner.converge('test::jce_spec') } + + it 'downloads the JCE archive to the explicit download path' do + expect(converge).to create_remote_file('/tmp/java/jce.zip') + end + + it 'extracts the archive without a shell execute resource' do + expect(converge).to extract_archive_file('extract jce') + expect(converge).to_not run_execute('extract jce') + end + end + + context 'remove' do + let(:runner) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '24.04', step_into: ['java_jce']) } + let(:converge) { runner.converge('test::jce_remove_spec') } + + it 'removes staged JCE artifacts' do + expect(converge).to delete_directory('/usr/lib/jvm/jce/17') + expect(converge).to delete_file('/tmp/java/jce.zip') + end + end +end diff --git a/spec/resources/openjdk_install_spec.rb b/spec/resources/openjdk_install_spec.rb new file mode 100644 index 000000000..8bb387fe2 --- /dev/null +++ b/spec/resources/openjdk_install_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'openjdk_install' do + context 'package install' do + let(:runner) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '24.04', step_into: ['openjdk_install']) } + + let(:converge) do + runner.converge('test::openjdk_package_spec') + end + + it 'delegates to openjdk_pkg_install' do + expect(converge).to install_openjdk_pkg_install('17').with( + pkg_names: %w(openjdk-17-jdk openjdk-17-jre-headless), + java_home: '/usr/lib/jvm/java-17-openjdk-amd64', + bin_cmds: %w(java javac), + skip_alternatives: true + ) + end + end + + context 'source install' do + let(:runner) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '24.04', step_into: ['openjdk_install']) } + + let(:converge) do + runner.converge('test::openjdk_source_spec') + end + + it 'delegates to openjdk_source_install' do + expect(converge).to install_openjdk_source_install('17').with( + url: 'https://example.test/openjdk.tar.gz', + checksum: 'a' * 64, + java_home: '/usr/lib/jvm/java-17-openjdk/jdk-17', + source_install_dir: 'jdk-17.0.9+9', + java_home_owner: 'javauser', + bin_cmds: %w(java javac), + skip_alternatives: true + ) + end + end +end diff --git a/spec/resources/openjdk_pkg_install_spec.rb b/spec/resources/openjdk_pkg_install_spec.rb new file mode 100644 index 000000000..e1ddb0c86 --- /dev/null +++ b/spec/resources/openjdk_pkg_install_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'openjdk_pkg_install' do + let(:runner) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '24.04', step_into: ['openjdk_pkg_install']) } + + let(:converge) do + runner.converge('test::openjdk_pkg_spec') + end + + it 'installs the requested OpenJDK packages' do + expect(converge).to install_package(%w(openjdk-17-jdk openjdk-17-jre-headless)) + end + + it 'does not write node java_home state' do + expect(converge.node.default_attrs).not_to have_key('java') + expect(converge.node.normal_attrs).not_to have_key('java') + expect(converge.node.override_attrs).not_to have_key('java') + end +end diff --git a/spec/resources/openjdk_source_install_spec.rb b/spec/resources/openjdk_source_install_spec.rb new file mode 100644 index 000000000..efcef1af9 --- /dev/null +++ b/spec/resources/openjdk_source_install_spec.rb @@ -0,0 +1,100 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'openjdk_source_install' do + let(:cache_path) { Chef::Config[:file_cache_path] } + + context 'install' do + let(:runner) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '24.04', step_into: ['openjdk_source_install']) } + let(:converge) { runner.converge('test::openjdk_source_direct_spec') } + + it 'downloads the source archive' do + expect(converge).to create_remote_file(::File.join(Chef::Config[:file_cache_path], 'openjdk.tar.gz')) + end + + it 'sets JAVA_HOME in the profile file' do + resource = converge.resource_collection.to_a.find do |candidate| + candidate.resource_name == :file && candidate.name == '/etc/profile.d/java.sh' + end + + expect(resource.content).to eq("export JAVA_HOME=/usr/lib/jvm/java-17-openjdk/jdk-17\n") + expect(resource.mode).to eq('0644') + end + + it 'extracts the archive into the final java_home' do + archive = converge.resource_collection.find(archive_file: ::File.join(cache_path, 'openjdk.tar.gz')) + + expect(archive.destination).to eq('/usr/lib/jvm/java-17-openjdk/jdk-17') + expect(archive.strip_components).to eq(1) + expect(archive.overwrite).to be true + expect(archive.not_if).not_to be_empty + end + end + + context 'custom source URL' do + let(:runner) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '24.04', step_into: ['openjdk_source_install']) } + let(:converge) { runner.converge('test::openjdk_source_custom_url_spec') } + let(:java_home) { '/usr/lib/jvm/java-17-openjdk/OpenJDK17U-jdk_x64_linux_hotspot_17.0.9_9' } + + it 'derives java_home from the archive file name' do + resource = converge.resource_collection.find(file: '/etc/profile.d/java.sh') + + expect(resource.content).to eq("export JAVA_HOME=#{java_home}\n") + end + + it 'sets alternatives to the derived java_home' do + expect(converge).to set_java_alternatives('set-java-alternatives').with( + java_location: java_home, + bin_cmds: %w(java javac) + ) + end + + it 'extracts the archive into the derived java_home' do + archive = converge.resource_collection.find(archive_file: ::File.join(cache_path, 'OpenJDK17U-jdk_x64_linux_hotspot_17.0.9_9.tar.gz')) + + expect(archive.destination).to eq(java_home) + expect(archive.strip_components).to eq(1) + expect(archive.overwrite).to be true + expect(archive.owner).to eq('root') + expect(archive.group).to eq('root') + expect(archive.mode).to eq('0755') + expect(archive.not_if).not_to be_empty + end + end + + context 'custom source URL with explicit java_home' do + let(:runner) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '24.04', step_into: ['openjdk_source_install']) } + let(:converge) { runner.converge('test::openjdk_source_explicit_java_home_spec') } + + it 'uses the explicit java_home' do + resource = converge.resource_collection.find(file: '/etc/profile.d/java.sh') + + expect(resource.content).to eq("export JAVA_HOME=/opt/java/custom-openjdk\n") + end + end + + context 'custom source URL with source_install_dir' do + let(:runner) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '24.04', step_into: ['openjdk_source_install']) } + let(:converge) { runner.converge('test::openjdk_source_install_dir_spec') } + + it 'uses source_install_dir under the versioned parent directory' do + resource = converge.resource_collection.find(file: '/etc/profile.d/java.sh') + + expect(resource.content).to eq("export JAVA_HOME=/usr/lib/jvm/java-17-openjdk/jdk-17.0.9+9\n") + end + end + + context 'remove' do + let(:runner) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '24.04', step_into: ['openjdk_source_install']) } + let(:converge) { runner.converge('test::openjdk_source_remove_spec') } + + it 'removes the managed JAVA_HOME line' do + resource = converge.resource_collection.to_a.find do |candidate| + candidate.resource_name == :file && candidate.name == '/etc/profile.d/java.sh' + end + + expect(resource.action).to eq([:delete]) + end + end +end diff --git a/spec/resources/temurin_package_install_spec.rb b/spec/resources/temurin_package_install_spec.rb new file mode 100644 index 000000000..4cb660fec --- /dev/null +++ b/spec/resources/temurin_package_install_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'temurin_package_install' do + let(:runner) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '24.04', step_into: ['temurin_package_install']) } + + let(:converge) do + runner.converge('test::temurin_package_spec') + end + + it 'installs the Adoptium apt keyring' do + expect(converge).to create_remote_file('/usr/share/keyrings/adoptium.asc').with( + source: 'https://packages.adoptium.net/artifactory/api/gpg/key/public', + mode: '0644' + ) + end + + it 'configures the apt repository with signed_by instead of trusted mode' do + expect(converge).to add_apt_repository('adoptium').with( + signed_by: '/usr/share/keyrings/adoptium.asc' + ) + end + + it 'installs the Temurin package' do + expect(converge).to install_package('temurin-17-jdk') + end + + context 'on AlmaLinux' do + let(:runner) { ChefSpec::SoloRunner.new(platform: 'almalinux', version: '8', step_into: ['temurin_package_install']) } + + it 'uses the RHEL-compatible Adoptium RPM repository' do + expect(converge).to create_yum_repository('adoptium').with( + baseurl: 'https://packages.adoptium.net/artifactory/rpm/rhel/$releasever/$basearch' + ) + end + end + + context 'on Amazon Linux' do + let(:runner) { ChefSpec::SoloRunner.new(platform: 'amazon', version: '2', step_into: ['temurin_package_install']) } + + it 'uses the Adoptium Amazon Linux 2 RPM repository' do + expect(converge).to create_yum_repository('adoptium').with( + baseurl: 'https://packages.adoptium.net/artifactory/rpm/amazonlinux/2/$basearch' + ) + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e19e1f46c..b9669727e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,10 +1,24 @@ require 'chefspec' -require 'chefspec/berkshelf' +require 'chefspec/policyfile' -require_relative '../libraries/adopt_openjdk_helpers.rb' -require_relative '../libraries/adopt_openjdk_macos_helpers.rb' -require_relative '../libraries/corretto_helpers.rb' -require_relative '../libraries/openjdk_helpers.rb' +require_relative '../libraries/certificate_helpers' +require_relative '../libraries/bin_cmd_helpers' +require_relative '../libraries/corretto_helpers' +require_relative '../libraries/openjdk_helpers' + +module PolicyfileCookbookPath + def initialize(options = {}) + if Array(options[:cookbook_path]).include?('spec/fixtures/cookbooks') + options = options.merge( + cookbook_path: Array(RSpec.configuration.cookbook_path) + [File.expand_path('fixtures/cookbooks', __dir__)] + ) + end + + super(options) + end +end + +ChefSpec::SoloRunner.prepend(PolicyfileCookbookPath) RSpec.configure do |config| config.file_cache_path = File.join(Dir.tmpdir, 'chefspec') if config.respond_to?(:file_cache_path) diff --git a/templates/jdk.sh.erb b/templates/jdk.sh.erb deleted file mode 100644 index 39486d3ce..000000000 --- a/templates/jdk.sh.erb +++ /dev/null @@ -1 +0,0 @@ -export JAVA_HOME=<%= node['java']['java_home']%> diff --git a/test/fixtures/cookbooks/test/recipes/adoptopenjdk-11-hotspot.rb b/test/fixtures/cookbooks/test/recipes/adoptopenjdk-11-hotspot.rb deleted file mode 100644 index b4afe5a60..000000000 --- a/test/fixtures/cookbooks/test/recipes/adoptopenjdk-11-hotspot.rb +++ /dev/null @@ -1,26 +0,0 @@ -apt_update - -version = '11' -variant = 'hotspot' - -adoptopenjdk_install version do - variant variant -end - -cookbook_file '/tmp/java_certificate_test.pem' do - source 'java_certificate_test.pem' -end - -java_certificate 'java_certificate_test' do - cert_file '/tmp/java_certificate_test.pem' - java_version version -end - -java_certificate 'java_certificate_ssl_endpoint' do - ssl_endpoint 'google.com:443' - java_version version -end - -cookbook_file '/tmp/UnlimitedSupportJCETest.jar' do - source 'UnlimitedSupportJCETest.jar' -end diff --git a/test/fixtures/cookbooks/test/recipes/adoptopenjdk-11-openj9-large-heap.rb b/test/fixtures/cookbooks/test/recipes/adoptopenjdk-11-openj9-large-heap.rb deleted file mode 100644 index ee8c32832..000000000 --- a/test/fixtures/cookbooks/test/recipes/adoptopenjdk-11-openj9-large-heap.rb +++ /dev/null @@ -1,26 +0,0 @@ -apt_update - -version = '11' -variant = 'openj9-large-heap' - -adoptopenjdk_install version do - variant variant -end - -cookbook_file '/tmp/java_certificate_test.pem' do - source 'java_certificate_test.pem' -end - -java_certificate 'java_certificate_test' do - cert_file '/tmp/java_certificate_test.pem' - java_version version -end - -java_certificate 'java_certificate_ssl_endpoint' do - ssl_endpoint 'google.com:443' - java_version version -end - -cookbook_file '/tmp/UnlimitedSupportJCETest.jar' do - source 'UnlimitedSupportJCETest.jar' -end diff --git a/test/fixtures/cookbooks/test/recipes/adoptopenjdk-11-openj9.rb b/test/fixtures/cookbooks/test/recipes/adoptopenjdk-11-openj9.rb deleted file mode 100644 index dab6de801..000000000 --- a/test/fixtures/cookbooks/test/recipes/adoptopenjdk-11-openj9.rb +++ /dev/null @@ -1,26 +0,0 @@ -apt_update - -version = '11' -variant = 'openj9' - -adoptopenjdk_install version do - variant variant -end - -cookbook_file '/tmp/java_certificate_test.pem' do - source 'java_certificate_test.pem' -end - -java_certificate 'java_certificate_test' do - cert_file '/tmp/java_certificate_test.pem' - java_version version -end - -java_certificate 'java_certificate_ssl_endpoint' do - ssl_endpoint 'google.com:443' - java_version version -end - -cookbook_file '/tmp/UnlimitedSupportJCETest.jar' do - source 'UnlimitedSupportJCETest.jar' -end diff --git a/test/fixtures/cookbooks/test/recipes/adoptopenjdk-14-hotspot.rb b/test/fixtures/cookbooks/test/recipes/adoptopenjdk-14-hotspot.rb deleted file mode 100644 index 4d5d1f22d..000000000 --- a/test/fixtures/cookbooks/test/recipes/adoptopenjdk-14-hotspot.rb +++ /dev/null @@ -1,26 +0,0 @@ -apt_update - -version = '14' -variant = 'hotspot' - -adoptopenjdk_install version do - variant variant -end - -cookbook_file '/tmp/java_certificate_test.pem' do - source 'java_certificate_test.pem' -end - -java_certificate 'java_certificate_test' do - cert_file '/tmp/java_certificate_test.pem' - java_version version -end - -java_certificate 'java_certificate_ssl_endpoint' do - ssl_endpoint 'google.com:443' - java_version version -end - -cookbook_file '/tmp/UnlimitedSupportJCETest.jar' do - source 'UnlimitedSupportJCETest.jar' -end diff --git a/test/fixtures/cookbooks/test/recipes/adoptopenjdk-14-openj9-large-heap.rb b/test/fixtures/cookbooks/test/recipes/adoptopenjdk-14-openj9-large-heap.rb deleted file mode 100644 index 841899eb7..000000000 --- a/test/fixtures/cookbooks/test/recipes/adoptopenjdk-14-openj9-large-heap.rb +++ /dev/null @@ -1,26 +0,0 @@ -apt_update - -version = '14' -variant = 'openj9-large-heap' - -adoptopenjdk_install version do - variant variant -end - -cookbook_file '/tmp/java_certificate_test.pem' do - source 'java_certificate_test.pem' -end - -java_certificate 'java_certificate_test' do - cert_file '/tmp/java_certificate_test.pem' - java_version version -end - -java_certificate 'java_certificate_ssl_endpoint' do - ssl_endpoint 'google.com:443' - java_version version -end - -cookbook_file '/tmp/UnlimitedSupportJCETest.jar' do - source 'UnlimitedSupportJCETest.jar' -end diff --git a/test/fixtures/cookbooks/test/recipes/adoptopenjdk-14-openj9.rb b/test/fixtures/cookbooks/test/recipes/adoptopenjdk-14-openj9.rb deleted file mode 100644 index 7251ff504..000000000 --- a/test/fixtures/cookbooks/test/recipes/adoptopenjdk-14-openj9.rb +++ /dev/null @@ -1,23 +0,0 @@ -apt_update - -version = '14' - -adoptopenjdk_install version - -cookbook_file '/tmp/java_certificate_test.pem' do - source 'java_certificate_test.pem' -end - -java_certificate 'java_certificate_test' do - cert_file '/tmp/java_certificate_test.pem' - java_version version -end - -java_certificate 'java_certificate_ssl_endpoint' do - ssl_endpoint 'google.com:443' - java_version version -end - -cookbook_file '/tmp/UnlimitedSupportJCETest.jar' do - source 'UnlimitedSupportJCETest.jar' -end diff --git a/test/fixtures/cookbooks/test/recipes/adoptopenjdk-8-hotspot.rb b/test/fixtures/cookbooks/test/recipes/adoptopenjdk-8-hotspot.rb deleted file mode 100644 index 0665310ce..000000000 --- a/test/fixtures/cookbooks/test/recipes/adoptopenjdk-8-hotspot.rb +++ /dev/null @@ -1,26 +0,0 @@ -apt_update - -version = '8' -variant = 'hotspot' - -adoptopenjdk_install version do - variant variant -end - -cookbook_file '/tmp/java_certificate_test.pem' do - source 'java_certificate_test.pem' -end - -java_certificate 'java_certificate_test' do - cert_file '/tmp/java_certificate_test.pem' - java_version version -end - -java_certificate 'java_certificate_ssl_endpoint' do - ssl_endpoint 'google.com:443' - java_version version -end - -cookbook_file '/tmp/UnlimitedSupportJCETest.jar' do - source 'UnlimitedSupportJCETest.jar' -end diff --git a/test/fixtures/cookbooks/test/recipes/adoptopenjdk-8-openj9-large-heap.rb b/test/fixtures/cookbooks/test/recipes/adoptopenjdk-8-openj9-large-heap.rb deleted file mode 100644 index ba8804c48..000000000 --- a/test/fixtures/cookbooks/test/recipes/adoptopenjdk-8-openj9-large-heap.rb +++ /dev/null @@ -1,26 +0,0 @@ -apt_update - -version = '8' -variant = 'openj9-large-heap' - -adoptopenjdk_install version do - variant variant -end - -cookbook_file '/tmp/java_certificate_test.pem' do - source 'java_certificate_test.pem' -end - -java_certificate 'java_certificate_test' do - cert_file '/tmp/java_certificate_test.pem' - java_version version -end - -java_certificate 'java_certificate_ssl_endpoint' do - ssl_endpoint 'google.com:443' - java_version version -end - -cookbook_file '/tmp/UnlimitedSupportJCETest.jar' do - source 'UnlimitedSupportJCETest.jar' -end diff --git a/test/fixtures/cookbooks/test/recipes/adoptopenjdk-8-openj9.rb b/test/fixtures/cookbooks/test/recipes/adoptopenjdk-8-openj9.rb deleted file mode 100644 index 40c4f3d6c..000000000 --- a/test/fixtures/cookbooks/test/recipes/adoptopenjdk-8-openj9.rb +++ /dev/null @@ -1,26 +0,0 @@ -apt_update - -version = '8' -variant = 'openj9' - -adoptopenjdk_install version do - variant variant -end - -cookbook_file '/tmp/java_certificate_test.pem' do - source 'java_certificate_test.pem' -end - -java_certificate 'java_certificate_test' do - cert_file '/tmp/java_certificate_test.pem' - java_version version -end - -java_certificate 'java_certificate_ssl_endpoint' do - ssl_endpoint 'google.com:443' - java_version version -end - -cookbook_file '/tmp/UnlimitedSupportJCETest.jar' do - source 'UnlimitedSupportJCETest.jar' -end diff --git a/test/fixtures/cookbooks/test/recipes/alternatives_existing_spec.rb b/test/fixtures/cookbooks/test/recipes/alternatives_existing_spec.rb new file mode 100644 index 000000000..b714fd5eb --- /dev/null +++ b/test/fixtures/cookbooks/test/recipes/alternatives_existing_spec.rb @@ -0,0 +1,5 @@ +java_alternatives 'test-existing-alternatives' do + java_location '/opt/java' + bin_cmds ['java'] + priority 1062 +end diff --git a/test/fixtures/cookbooks/test/recipes/alternatives_spec.rb b/test/fixtures/cookbooks/test/recipes/alternatives_spec.rb new file mode 100644 index 000000000..f4167760d --- /dev/null +++ b/test/fixtures/cookbooks/test/recipes/alternatives_spec.rb @@ -0,0 +1,4 @@ +java_alternatives 'test-alternatives' do + java_location '/opt/java' + bin_cmds [] +end diff --git a/test/fixtures/cookbooks/test/recipes/alternatives_unset_spec.rb b/test/fixtures/cookbooks/test/recipes/alternatives_unset_spec.rb new file mode 100644 index 000000000..ef7469a8d --- /dev/null +++ b/test/fixtures/cookbooks/test/recipes/alternatives_unset_spec.rb @@ -0,0 +1,5 @@ +java_alternatives 'test-unset-alternatives' do + java_location '/opt/java' + bin_cmds ['java'] + action :unset +end diff --git a/test/fixtures/cookbooks/test/recipes/certificate_spec.rb b/test/fixtures/cookbooks/test/recipes/certificate_spec.rb new file mode 100644 index 000000000..f467a8867 --- /dev/null +++ b/test/fixtures/cookbooks/test/recipes/certificate_spec.rb @@ -0,0 +1,20 @@ +java_certificate 'java_certificate_test' do + cert_data <<~CERT + -----BEGIN CERTIFICATE----- + MIICjzCCAfigAwIBAgIJAOXrhcX4ZaGtMA0GCSqGSIb3DQEBBQUAMDoxCzAJBgNV + BAYTAlVTMQ0wCwYDVQQIEwRUZXN0MQ0wCwYDVQQKEwRUZXN0MQ0wCwYDVQQDEwR0 + ZXN0MB4XDTE2MTAxMzAxMTkzOVoXDTM2MTAwODAxMTkzOVowOjELMAkGA1UEBhMC + VVMxDTALBgNVBAgTBFRlc3QxDTALBgNVBAoTBFRlc3QxDTALBgNVBAMTBHRlc3Qw + gZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALu8/ylmItn9wUOB4qvlONEiFQpJ + DCK5bt/OkjT02Knm+aAEZS1EDTVEiZWkumM884fd2+WgaMREk02Gy6u5CraOTtEz + VjLeHdr7V9CBZpR6l5gmUY5Ujk1coHZImiqRs3STLVlWHJGjzLXMkRx10CIU8SHC + zgTr57kNG/FT+e25AgMBAAGjgZwwgZkwHQYDVR0OBBYEFP3Ox0pHbZ0u6z746Hp0 + Yk1EBTacMGoGA1UdIwRjMGGAFP3Ox0pHbZ0u6z746Hp0Yk1EBTacoT6kPDA6MQsw + CQYDVQQGEwJVUzENMAsGA1UECBMEVGVzdDENMAsGA1UEChMEVGVzdDENMAsGA1UE + AxMEdGVzdIIJAOXrhcX4ZaGtMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQAD + gYEAG4idDXusAZ9OrzqdWdFQ+rhQYRovZnfSgPSdF7hugWL5i/qGGlsFjZld2Kyj + X0msGzk61iW7C6kv6OfPGaGNzdNtsH8jUvIYP1IrKpf1NKTKetIWiP08ZI1XNF4H + bXmOxdtxzlHW4qukka+HkK0RBrwX35C8HYqePmInI51JnqY= + -----END CERTIFICATE----- + CERT +end diff --git a/test/fixtures/cookbooks/test/recipes/corretto.rb b/test/fixtures/cookbooks/test/recipes/corretto.rb index 216a4463c..338e87fef 100644 --- a/test/fixtures/cookbooks/test/recipes/corretto.rb +++ b/test/fixtures/cookbooks/test/recipes/corretto.rb @@ -1 +1,12 @@ -corretto_install node['version'] +extend Java::Cookbook::CorrettoHelpers + +version = node['version'].to_s +java_home = "/usr/lib/jvm/java-#{version}-corretto/#{corretto_sub_dir(version)}" + +corretto_install version do + java_home java_home +end + +node.run_state['java_certificate_java_home'] = java_home + +include_recipe 'test::java_cert' diff --git a/test/fixtures/cookbooks/test/recipes/corretto_spec.rb b/test/fixtures/cookbooks/test/recipes/corretto_spec.rb new file mode 100644 index 000000000..9664c1eb4 --- /dev/null +++ b/test/fixtures/cookbooks/test/recipes/corretto_spec.rb @@ -0,0 +1,7 @@ +declare_resource(:corretto_install, '17') do + url 'https://example.test/corretto.tar.gz' + checksum 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + java_home '/usr/lib/jvm/java-17-corretto/amazon-corretto-17' + bin_cmds %w(java javac) + skip_alternatives true +end diff --git a/test/fixtures/cookbooks/test/recipes/java_cert.rb b/test/fixtures/cookbooks/test/recipes/java_cert.rb index efa6ad98e..7931ce01b 100644 --- a/test/fixtures/cookbooks/test/recipes/java_cert.rb +++ b/test/fixtures/cookbooks/test/recipes/java_cert.rb @@ -1,11 +1,37 @@ +version = node['version'].to_s +certificate_java_home = node.run_state['java_certificate_java_home'] + cookbook_file '/tmp/java_certificate_test.pem' do source 'java_certificate_test.pem' end java_certificate 'java_certificate_test' do cert_file '/tmp/java_certificate_test.pem' + java_version version + java_home certificate_java_home if certificate_java_home end java_certificate 'java_certificate_ssl_endpoint' do ssl_endpoint 'google.com:443' + java_version version + java_home certificate_java_home if certificate_java_home +end + +java_certificate 'java_certificate_ssl_endpoint' do + java_version version + java_home certificate_java_home if certificate_java_home + action :remove +end + +java_certificate 'java_certificate_ssl_endpoint_starttls_smtp' do + ssl_endpoint 'smtp.gmail.com:587' + starttls 'smtp' + java_version version + java_home certificate_java_home if certificate_java_home +end + +java_certificate 'java_certificate_ssl_endpoint_starttls_smtp' do + java_version version + java_home certificate_java_home if certificate_java_home + action :remove end diff --git a/test/fixtures/cookbooks/test/recipes/jce_remove_spec.rb b/test/fixtures/cookbooks/test/recipes/jce_remove_spec.rb new file mode 100644 index 000000000..7e5d05e6d --- /dev/null +++ b/test/fixtures/cookbooks/test/recipes/jce_remove_spec.rb @@ -0,0 +1,9 @@ +declare_resource(:java_jce, '17') do + jce_url 'https://example.test/jce.zip' + jce_checksum 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + java_home '/usr/lib/jvm/java-17-openjdk-amd64' + jce_home '/usr/lib/jvm/jce' + download_path '/tmp/java' + install_type 'jdk' + action :remove +end diff --git a/test/fixtures/cookbooks/test/recipes/jce_spec.rb b/test/fixtures/cookbooks/test/recipes/jce_spec.rb new file mode 100644 index 000000000..51ac74273 --- /dev/null +++ b/test/fixtures/cookbooks/test/recipes/jce_spec.rb @@ -0,0 +1,8 @@ +declare_resource(:java_jce, '17') do + jce_url 'https://example.test/jce.zip' + jce_checksum 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + java_home '/usr/lib/jvm/java-17-openjdk-amd64' + jce_home '/usr/lib/jvm/jce' + download_path '/tmp/java' + install_type 'jdk' +end diff --git a/test/fixtures/cookbooks/test/recipes/openjdk.rb b/test/fixtures/cookbooks/test/recipes/openjdk.rb index f78349f52..7da436538 100644 --- a/test/fixtures/cookbooks/test/recipes/openjdk.rb +++ b/test/fixtures/cookbooks/test/recipes/openjdk.rb @@ -1 +1,6 @@ -openjdk_install node['version'] +# Test recipe for verifying installation paths +# This focuses only on path verification, avoiding non-idempotent operations + +openjdk_install node['version'].to_s do + variant node['variant'] if node['variant'] +end diff --git a/test/fixtures/cookbooks/test/recipes/openjdk_package_spec.rb b/test/fixtures/cookbooks/test/recipes/openjdk_package_spec.rb new file mode 100644 index 000000000..4f4138665 --- /dev/null +++ b/test/fixtures/cookbooks/test/recipes/openjdk_package_spec.rb @@ -0,0 +1,7 @@ +declare_resource(:openjdk_install, '17') do + install_type 'package' + pkg_names %w(openjdk-17-jdk openjdk-17-jre-headless) + java_home '/usr/lib/jvm/java-17-openjdk-amd64' + bin_cmds %w(java javac) + skip_alternatives true +end diff --git a/test/fixtures/cookbooks/test/recipes/openjdk_pkg.rb b/test/fixtures/cookbooks/test/recipes/openjdk_pkg.rb index 4201abdcb..328f9b3c9 100644 --- a/test/fixtures/cookbooks/test/recipes/openjdk_pkg.rb +++ b/test/fixtures/cookbooks/test/recipes/openjdk_pkg.rb @@ -1 +1,5 @@ -openjdk_pkg_install node['version'] +openjdk_install node['version'] do + install_type 'package' +end + +include_recipe 'test::java_cert' diff --git a/test/fixtures/cookbooks/test/recipes/openjdk_pkg_spec.rb b/test/fixtures/cookbooks/test/recipes/openjdk_pkg_spec.rb new file mode 100644 index 000000000..5bb3e045f --- /dev/null +++ b/test/fixtures/cookbooks/test/recipes/openjdk_pkg_spec.rb @@ -0,0 +1,6 @@ +declare_resource(:openjdk_pkg_install, '17') do + pkg_names %w(openjdk-17-jdk openjdk-17-jre-headless) + java_home '/usr/lib/jvm/java-17-openjdk-amd64' + bin_cmds %w(java javac) + skip_alternatives true +end diff --git a/test/fixtures/cookbooks/test/recipes/openjdk_source_custom_url_spec.rb b/test/fixtures/cookbooks/test/recipes/openjdk_source_custom_url_spec.rb new file mode 100644 index 000000000..8ac6fcf73 --- /dev/null +++ b/test/fixtures/cookbooks/test/recipes/openjdk_source_custom_url_spec.rb @@ -0,0 +1,5 @@ +declare_resource(:openjdk_source_install, '17') do + url 'https://artifacts.example.test/java/OpenJDK17U-jdk_x64_linux_hotspot_17.0.9_9.tar.gz' + checksum 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + bin_cmds %w(java javac) +end diff --git a/test/fixtures/cookbooks/test/recipes/openjdk_source_direct_spec.rb b/test/fixtures/cookbooks/test/recipes/openjdk_source_direct_spec.rb new file mode 100644 index 000000000..9a2207bb8 --- /dev/null +++ b/test/fixtures/cookbooks/test/recipes/openjdk_source_direct_spec.rb @@ -0,0 +1,7 @@ +declare_resource(:openjdk_source_install, '17') do + url 'https://example.test/openjdk.tar.gz' + checksum 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + java_home '/usr/lib/jvm/java-17-openjdk/jdk-17' + bin_cmds %w(java javac) + skip_alternatives true +end diff --git a/test/fixtures/cookbooks/test/recipes/openjdk_source_explicit_java_home_spec.rb b/test/fixtures/cookbooks/test/recipes/openjdk_source_explicit_java_home_spec.rb new file mode 100644 index 000000000..4fc8a5216 --- /dev/null +++ b/test/fixtures/cookbooks/test/recipes/openjdk_source_explicit_java_home_spec.rb @@ -0,0 +1,6 @@ +declare_resource(:openjdk_source_install, '17') do + url 'https://artifacts.example.test/java/OpenJDK17U-jdk_x64_linux_hotspot_17.0.9_9.tar.gz' + checksum 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + java_home '/opt/java/custom-openjdk' + bin_cmds %w(java javac) +end diff --git a/test/fixtures/cookbooks/test/recipes/openjdk_source_install_dir_spec.rb b/test/fixtures/cookbooks/test/recipes/openjdk_source_install_dir_spec.rb new file mode 100644 index 000000000..dab3492da --- /dev/null +++ b/test/fixtures/cookbooks/test/recipes/openjdk_source_install_dir_spec.rb @@ -0,0 +1,6 @@ +declare_resource(:openjdk_source_install, '17') do + url 'https://artifacts.example.test/java/OpenJDK17U-jdk_x64_linux_hotspot_17.0.9_9.tar.gz' + checksum 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + source_install_dir 'jdk-17.0.9+9' + bin_cmds %w(java javac) +end diff --git a/test/fixtures/cookbooks/test/recipes/openjdk_source_remove_spec.rb b/test/fixtures/cookbooks/test/recipes/openjdk_source_remove_spec.rb new file mode 100644 index 000000000..c822322c0 --- /dev/null +++ b/test/fixtures/cookbooks/test/recipes/openjdk_source_remove_spec.rb @@ -0,0 +1,8 @@ +declare_resource(:openjdk_source_install, '17') do + url 'https://example.test/openjdk.tar.gz' + checksum 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + java_home '/usr/lib/jvm/java-17-openjdk/jdk-17' + bin_cmds %w(java javac) + skip_alternatives true + action :remove +end diff --git a/test/fixtures/cookbooks/test/recipes/openjdk_source_spec.rb b/test/fixtures/cookbooks/test/recipes/openjdk_source_spec.rb new file mode 100644 index 000000000..80b2f26e6 --- /dev/null +++ b/test/fixtures/cookbooks/test/recipes/openjdk_source_spec.rb @@ -0,0 +1,10 @@ +declare_resource(:openjdk_install, '17') do + install_type 'source' + url 'https://example.test/openjdk.tar.gz' + checksum 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + java_home '/usr/lib/jvm/java-17-openjdk/jdk-17' + source_install_dir 'jdk-17.0.9+9' + java_home_owner 'javauser' + bin_cmds %w(java javac) + skip_alternatives true +end diff --git a/test/fixtures/cookbooks/test/recipes/remove-adoptopenjdk-11-openj9.rb b/test/fixtures/cookbooks/test/recipes/remove-adoptopenjdk-11-openj9.rb deleted file mode 100644 index 606df0e15..000000000 --- a/test/fixtures/cookbooks/test/recipes/remove-adoptopenjdk-11-openj9.rb +++ /dev/null @@ -1,8 +0,0 @@ -apt_update - -include_recipe 'test::adoptopenjdk-11-openj9' - -adoptopenjdk_install '11' do - variant 'openj9' - action :remove -end diff --git a/test/fixtures/cookbooks/test/recipes/temurin_package_spec.rb b/test/fixtures/cookbooks/test/recipes/temurin_package_spec.rb new file mode 100644 index 000000000..bc3b4eec7 --- /dev/null +++ b/test/fixtures/cookbooks/test/recipes/temurin_package_spec.rb @@ -0,0 +1,4 @@ +declare_resource(:temurin_package_install, '17') do + bin_cmds %w(java javac) + skip_alternatives true +end diff --git a/test/fixtures/cookbooks/test/recipes/temurin_pkg.rb b/test/fixtures/cookbooks/test/recipes/temurin_pkg.rb new file mode 100644 index 000000000..a502a7522 --- /dev/null +++ b/test/fixtures/cookbooks/test/recipes/temurin_pkg.rb @@ -0,0 +1,4 @@ +# This recipe tests the temurin_package_install resource +# It should install temurin java packages based on the version specified + +temurin_package_install node['version'] diff --git a/test/integration/adoptopenjdk/attributes/adoptopenjdk-11-hotspot.yml b/test/integration/adoptopenjdk/attributes/adoptopenjdk-11-hotspot.yml deleted file mode 100644 index aca4299ea..000000000 --- a/test/integration/adoptopenjdk/attributes/adoptopenjdk-11-hotspot.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -java_version: 11.0.6 -variant: "hotspot" -keystore_location: '/usr/lib/jvm/java-11-adoptopenjdk-hotspot/jdk-11.0.6+10/lib/security/cacerts' diff --git a/test/integration/adoptopenjdk/attributes/adoptopenjdk-11-openj9-large-heap.yml b/test/integration/adoptopenjdk/attributes/adoptopenjdk-11-openj9-large-heap.yml deleted file mode 100644 index ceb92c0bb..000000000 --- a/test/integration/adoptopenjdk/attributes/adoptopenjdk-11-openj9-large-heap.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -java_version: 11.0.6 -variant: "openj9-large-heap" -keystore_location: '/usr/lib/jvm/java-11-adoptopenjdk-openj9-large-heap/jdk-11.0.6+10/lib/security/cacerts' diff --git a/test/integration/adoptopenjdk/attributes/adoptopenjdk-11-openj9.yml b/test/integration/adoptopenjdk/attributes/adoptopenjdk-11-openj9.yml deleted file mode 100644 index 51f0e8878..000000000 --- a/test/integration/adoptopenjdk/attributes/adoptopenjdk-11-openj9.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -java_version: 11.0.6 -variant: "openj9" -keystore_location: '/usr/lib/jvm/java-11-adoptopenjdk-openj9/jdk-11.0.6+10/lib/security/cacerts' diff --git a/test/integration/adoptopenjdk/attributes/adoptopenjdk-14-hotspot.yml b/test/integration/adoptopenjdk/attributes/adoptopenjdk-14-hotspot.yml deleted file mode 100644 index 7be7f985b..000000000 --- a/test/integration/adoptopenjdk/attributes/adoptopenjdk-14-hotspot.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -java_version: 14 -variant: "hotspot" -keystore_location: '/usr/lib/jvm/java-14-adoptopenjdk-hotspot/jdk-14+36/lib/security/cacerts' diff --git a/test/integration/adoptopenjdk/attributes/adoptopenjdk-14-macos.yml b/test/integration/adoptopenjdk/attributes/adoptopenjdk-14-macos.yml deleted file mode 100644 index 315dca348..000000000 --- a/test/integration/adoptopenjdk/attributes/adoptopenjdk-14-macos.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -java_version: '14' -variant: "openj9" -keystore_location: '/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home/lib/security/cacerts' diff --git a/test/integration/adoptopenjdk/attributes/adoptopenjdk-14-openj9-large-heap.yml b/test/integration/adoptopenjdk/attributes/adoptopenjdk-14-openj9-large-heap.yml deleted file mode 100644 index 3cc4019bf..000000000 --- a/test/integration/adoptopenjdk/attributes/adoptopenjdk-14-openj9-large-heap.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -java_version: 14 -variant: "openj9-large-heap" -keystore_location: '/usr/lib/jvm/java-14-adoptopenjdk-openj9-large-heap/jdk-14+36/lib/security/cacerts' diff --git a/test/integration/adoptopenjdk/attributes/adoptopenjdk-14-openj9.yml b/test/integration/adoptopenjdk/attributes/adoptopenjdk-14-openj9.yml deleted file mode 100644 index 06f74fe26..000000000 --- a/test/integration/adoptopenjdk/attributes/adoptopenjdk-14-openj9.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -java_version: 14 -variant: "openj9" -keystore_location: '/usr/lib/jvm/java-14-adoptopenjdk-openj9/jdk-14+36/lib/security/cacerts' diff --git a/test/integration/adoptopenjdk/attributes/adoptopenjdk-8-hotspot.yml b/test/integration/adoptopenjdk/attributes/adoptopenjdk-8-hotspot.yml deleted file mode 100644 index ed5cfa28b..000000000 --- a/test/integration/adoptopenjdk/attributes/adoptopenjdk-8-hotspot.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -java_version: 1.8.0 -variant: "hotspot" -keystore_location: '/usr/lib/jvm/java-8-adoptopenjdk-hotspot/jdk8u242-b08/jre/lib/security/cacerts' diff --git a/test/integration/adoptopenjdk/attributes/adoptopenjdk-8-openj9-large-heap.yml b/test/integration/adoptopenjdk/attributes/adoptopenjdk-8-openj9-large-heap.yml deleted file mode 100644 index e6ebc7c70..000000000 --- a/test/integration/adoptopenjdk/attributes/adoptopenjdk-8-openj9-large-heap.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -java_version: 1.8.0 -variant: "openj9-large-heap" -keystore_location: '/usr/lib/jvm/java-8-adoptopenjdk-openj9-large-heap/jdk8u242-b08/jre/lib/security/cacerts' diff --git a/test/integration/adoptopenjdk/attributes/adoptopenjdk-8-openj9.yml b/test/integration/adoptopenjdk/attributes/adoptopenjdk-8-openj9.yml deleted file mode 100644 index f7c4ccf6c..000000000 --- a/test/integration/adoptopenjdk/attributes/adoptopenjdk-8-openj9.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -java_version: 1.8.0 -variant: "openj9" -keystore_location: '/usr/lib/jvm/java-8-adoptopenjdk-openj9/jdk8u242-b08/jre/lib/security/cacerts' diff --git a/test/integration/adoptopenjdk/controls/verify_adoptopenjdk.rb b/test/integration/adoptopenjdk/controls/verify_adoptopenjdk.rb deleted file mode 100644 index 2d9d881e8..000000000 --- a/test/integration/adoptopenjdk/controls/verify_adoptopenjdk.rb +++ /dev/null @@ -1,79 +0,0 @@ -variant = attribute('variant', description: 'Variant being used: openj9, openj9-large-heap, or hotspot') -java_version = attribute('java_version', description: 'Which version of java should be installed') -certificate_sha256_checksum = attribute('certificate_sha256_checksum', - value: '64:F3:3B:A7:EF:C3:5C:6B:2D:ED:95:0B:CB:4E:96:3B:12:97:B8:62:BA:1A:8E:30:13:B0:B0:59:77:12:31:EA', - description: 'The SHA256 checksum of the certificate' - ) -parent_install_dir = attribute('parent_install_dir', - value: "java-#{java_version.to_i > 8 ? java_version.to_i : java_version.split('.')[1]}-adoptopenjdk-#{variant}", - description: 'The parent of the Java home') -keystore_location = attribute('keystore_location', - value: nil, - description: 'Where the java keystore is located' - ) -keystore_password = attribute('keystore_password', - value: 'changeit', - description: 'Password to the Java keystore') - -control 'check-java-version' do - impact 1.0 - title 'Verify java version' - desc 'Verify the correct version of java is installed' - - match_java_version = "^openjdk version \"#{Regexp.escape(java_version.to_s)}[-_\"]" - describe command('java -version 2>&1') do - its('stdout') { should match /AdoptOpenJDK/ } unless java_version.to_i == 1 - its('stdout') { should match match_java_version } - end -end - -if os.linux? - control 'check-java-alternatives' do - impact 1.0 - title 'Verify alternatives for java' - desc 'Verify alternatives for java are set to the correct version' - - %w(jar jarsigner java javac).each do |cmd| - describe command("update-alternatives --display #{cmd}") do - its('stdout') { should match parent_install_dir.to_s } - end - end - end -end - -control 'check-jce' do - impact 1.0 - title 'Verify JCE is Unlimitied' - desc 'Verify JCE unlimited support and string' - - describe command('java -jar /tmp/UnlimitedSupportJCETest.jar') do - its('stdout') { should match /isUnlimitedSupported=TRUE/ } - its('stdout') { should match /strength: 2147483647/ } - end -end - -control 'check-certificate' do - impact 1.0 - title 'Verify Java keystore contains the certificate' - desc 'Verify Java keystore exists and contains the certificate' - - unless certificate_sha256_checksum.nil? || certificate_sha256_checksum.empty? - cmd = "keytool -list -v -keystore #{keystore_location}" - cmd.concat(" -storepass #{keystore_password}") unless keystore_password.nil? - describe command("#{cmd} | grep SHA256:") do - its('stdout') { should match certificate_sha256_checksum } - end - end -end - -if os.darwin? - control 'JAVA_HOME' do - impact 0.1 - title 'Verify the JAVA_HOME is set correctly' - desc 'Verify that JAVA_HOME is set correctly and to the correct version in the bash profile' - - describe file('/etc/profile') do - its('content') { should match /JAVA_HOME/ } - end - end -end diff --git a/test/integration/adoptopenjdk/inspec.yml b/test/integration/adoptopenjdk/inspec.yml deleted file mode 100644 index 69dff34a8..000000000 --- a/test/integration/adoptopenjdk/inspec.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -name: adoptopenjdk -title: AdoptOpenJDK tests -license: Public domain -copyright: None -summary: Verify installation of AdoptOpenJDK -version: 0.0.1 diff --git a/test/integration/custom-package/controls/verify_home.rb b/test/integration/custom-package/controls/verify_home.rb new file mode 100644 index 000000000..9b63691d1 --- /dev/null +++ b/test/integration/custom-package/controls/verify_home.rb @@ -0,0 +1,31 @@ +variant = input('variant', description: 'Variant being used: openj9, openj9-large-heap, or hotspot') +java_version = input('java_version', description: 'Which version of java should be installed') +parent_install_dir = input('parent_install_dir', + value: "java-#{java_version.to_i > 8 ? java_version.to_i : java_version.split('.')[1]}-adoptopenjdk-#{variant}", + description: 'The parent of the Java home') +java_home_dir = input('java_home_dir', description: 'Name of the JAVA_HOME directory') + +control 'check-java-version' do + impact 1.0 + title 'Verify java version' + desc 'Verify the correct version of java is installed' + + describe command('java -version 2>&1') do + its('stdout') { should match(/OpenJDK|Temurin|Corretto/) } unless java_version.to_i == 1 + its('stdout') { should match Regexp.new(java_version.to_s) } + end +end + +control 'check-java-home' do + impact 1.0 + title 'Check JAVA_HOME is set' + desc 'Check that custom URL install sets JAVA_HOME properly' + + describe directory("/usr/lib/jvm/#{parent_install_dir}/#{java_home_dir}") do + it { should exist } + end + + describe file('/etc/profile.d/java.sh') do + its('content') { should eq "export JAVA_HOME=/usr/lib/jvm/#{parent_install_dir}/#{java_home_dir}\n" } + end +end diff --git a/test/integration/custom-package/inputs/hotspot-11.yml b/test/integration/custom-package/inputs/hotspot-11.yml new file mode 100644 index 000000000..b3ec265ef --- /dev/null +++ b/test/integration/custom-package/inputs/hotspot-11.yml @@ -0,0 +1,4 @@ +--- +variant: hotspot +java_version: 11.0.6 +java_home_dir: jdk-11.0.6+10 diff --git a/test/integration/custom-package/inputs/hotspot-8.yml b/test/integration/custom-package/inputs/hotspot-8.yml new file mode 100644 index 000000000..e848987d6 --- /dev/null +++ b/test/integration/custom-package/inputs/hotspot-8.yml @@ -0,0 +1,4 @@ +--- +variant: hotspot +java_version: 1.8.0_232 +java_home_dir: jdk8u232-b09 diff --git a/test/integration/custom-package/inputs/openj9-11.yml b/test/integration/custom-package/inputs/openj9-11.yml new file mode 100644 index 000000000..cfefb59be --- /dev/null +++ b/test/integration/custom-package/inputs/openj9-11.yml @@ -0,0 +1,4 @@ +--- +variant: openj9 +java_version: 11.0.6 +java_home_dir: jdk-11.0.6+10 diff --git a/test/integration/custom-package/inputs/openj9-large-heap-11.yml b/test/integration/custom-package/inputs/openj9-large-heap-11.yml new file mode 100644 index 000000000..6bf147e5b --- /dev/null +++ b/test/integration/custom-package/inputs/openj9-large-heap-11.yml @@ -0,0 +1,4 @@ +--- +variant: openj9-large-heap +java_version: 11.0.6 +java_home_dir: jdk-11.0.6+10 diff --git a/test/integration/custom-package/inspec.yml b/test/integration/custom-package/inspec.yml new file mode 100644 index 000000000..e8b042ff2 --- /dev/null +++ b/test/integration/custom-package/inspec.yml @@ -0,0 +1,7 @@ +--- +name: custom-package +title: Custom package from URL testing +license: Public domain +copyright: None +summary: Verify installation from a custom URL +version: 0.0.1 diff --git a/test/integration/openjdk/controls/verify_openjdk.rb b/test/integration/openjdk/controls/verify_openjdk.rb index e966199fc..cd5a75f0f 100644 --- a/test/integration/openjdk/controls/verify_openjdk.rb +++ b/test/integration/openjdk/controls/verify_openjdk.rb @@ -7,8 +7,26 @@ describe command('java -version 2>&1') do its('stdout') { should match java_version.to_s } end +end + +control 'Java path is correct' do + impact 1.0 + title 'Path Verification' + desc 'Verifies that keytool and other binaries are accessible in the correct paths using update-alternatives' describe command('update-alternatives --display jar') do - its('stdout') { should match %r{\/usr\/lib\/jvm\/java} } + its('stdout') { should match %r{/usr/lib/jvm/java} } + end + + expected_java_home = %r{/usr/lib/jvm/java-#{java_version}[^\s]*/} + + describe command('update-alternatives --display java') do + its('stdout') { should match %r{#{expected_java_home}bin/java} } + end + + describe command('update-alternatives --display keytool') do + its('stdout') { should match %r{#{expected_java_home}bin/keytool} } + its('stdout') { should match %r{link (keytool )?(is )?/usr/bin/keytool|keytool - status} } + its('stdout') { should match /priority 1/ } end end diff --git a/test/integration/openjdk_pkg/controls/verify_openjdk.rb b/test/integration/openjdk_pkg/controls/verify_openjdk.rb index 3cfd0bd48..b00d26479 100644 --- a/test/integration/openjdk_pkg/controls/verify_openjdk.rb +++ b/test/integration/openjdk_pkg/controls/verify_openjdk.rb @@ -9,6 +9,6 @@ end describe command('update-alternatives --display java') do - its('stdout') { should match %r{\/usr\/lib\/jvm\/java} } + its('stdout') { should match %r{/usr/lib/jvm/java} } end end diff --git a/test/integration/remove-adoptopenjdk/controls/verify_adoptopenjdk-removal.rb b/test/integration/remove-adoptopenjdk/controls/verify_adoptopenjdk-removal.rb deleted file mode 100644 index 60d0f6430..000000000 --- a/test/integration/remove-adoptopenjdk/controls/verify_adoptopenjdk-removal.rb +++ /dev/null @@ -1,35 +0,0 @@ -variant = attribute('variant', value: 'openj9', description: 'Variant being used: openj9, openj9-large-heap, or hotspot') -alternative_bin_cmds = attribute('alternative_bin_cmds', - value: %w(jar java keytool), - description: 'List of bin commands that should be included in alternatives') -java_version = attribute('java_version', - value: '1.8.0', - description: 'Which version of java should be installed') -java_home = attribute('java_home', - value: "/usr/lib/jvm/java-#{java_version.to_i > 8 ? java_version.to_i : java_version.split('.')[1]}-adoptopenjdk-#{variant}", - description: 'Path to the Java home directory') - -control 'check-removal-java-directory' do - impact 1.0 - title 'Verify java directory has been removed' - desc 'Verify java directory has been removed' - - describe directory(java_home) do - it { should_not exist } - end -end - -control 'check-java-alternatives-removal' do - impact 1.0 - title 'Verify alternatives for java are removed' - desc 'Verify alternatives for java are removed' - - # NOTE: platform_family?('rhel') is not working for amazon-linux - if os.family == 'redhat' - alternative_bin_cmds.each do |cmd| - describe command("update-alternatives --display #{cmd}") do - its('stdout') { should_not match "#{java_home}/bin/#{cmd}" } - end - end - end -end diff --git a/test/integration/remove-adoptopenjdk/inspec.yml b/test/integration/remove-adoptopenjdk/inspec.yml deleted file mode 100644 index 22d8d373c..000000000 --- a/test/integration/remove-adoptopenjdk/inspec.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -name: remove-adoptopenjdk -title: AdoptOpenJDK removal tests -license: Public domain -copyright: None -summary: Verify removal of AdoptOpenJDK -version: 0.0.1 diff --git a/test/integration/temurin/controls/verify_temurin.rb b/test/integration/temurin/controls/verify_temurin.rb new file mode 100644 index 000000000..64850472c --- /dev/null +++ b/test/integration/temurin/controls/verify_temurin.rb @@ -0,0 +1,57 @@ +java_version = input('java_version', description: 'Which version of java should be installed') + +control 'Temurin Java is installed & linked correctly' do + impact 1.0 + title 'Installed' + desc 'Temurin Java is installed & linked correctly' + + describe command('java -version 2>&1') do + its('stdout') { should match(java_version.to_s) } + its('stdout') { should match(/Temurin/) } + end +end + +control 'Temurin Java path is correct' do + impact 1.0 + title 'Path Verification' + desc 'Verifies that keytool and other binaries are accessible in the correct paths using update-alternatives' + + # Handle architecture-specific paths + describe command('update-alternatives --display jar') do + its('stdout') { should match %r{/usr/lib/jvm/temurin-#{java_version}-jdk(-[a-z0-9]+)?/bin/jar} } + end + + describe command('update-alternatives --display java') do + its('stdout') { should match %r{/usr/lib/jvm/temurin-#{java_version}-jdk(-[a-z0-9]+)?/bin/java} } + end + + describe command('update-alternatives --display keytool') do + # Check for architecture-specific paths with regex that allows for optional architecture suffix + its('stdout') { should match %r{/usr/lib/jvm/temurin-#{java_version}-jdk(-[a-z0-9]+)?/bin/keytool} } + its('stdout') { should match(/priority/) } + end +end + +control 'Adoptium repository is properly configured' do + impact 1.0 + title 'Repository Configuration' + desc 'Verifies that the Adoptium repository is properly configured' + + # Handle platform detection more robustly + if os.family == 'debian' + describe file('/etc/apt/sources.list.d/adoptium.list') do + it { should exist } + its('content') { should match(/packages.adoptium.net/) } + end + elsif os.family == 'redhat' || os.family == 'fedora' || os.name == 'amazon' + describe file('/etc/yum.repos.d/adoptium.repo') do + it { should exist } + its('content') { should match(/packages.adoptium.net/) } + end + elsif os.family == 'suse' + describe file('/etc/zypp/repos.d/adoptium.repo') do + it { should exist } + its('content') { should match(/packages.adoptium.net/) } + end + end +end diff --git a/test/integration/temurin/inspec.yml b/test/integration/temurin/inspec.yml new file mode 100644 index 000000000..7b558efab --- /dev/null +++ b/test/integration/temurin/inspec.yml @@ -0,0 +1,6 @@ +name: temurin +title: Temurin Java Installation +maintainer: Sous Chefs +copyright: Sous Chefs +license: Apache-2.0 +version: 1.0.0 diff --git a/test/integration/temurin_mirror/inspec.yml b/test/integration/temurin_mirror/inspec.yml new file mode 100644 index 000000000..e69de29bb