pax_global_header00006660000000000000000000000064146345753170014531gustar00rootroot0000000000000052 comment=628fc4a0f376a6066f8bcb3221f1044764f270e1 rules_java-7.6.5/000077500000000000000000000000001463457531700137035ustar00rootroot00000000000000rules_java-7.6.5/.bazel_checkout/000077500000000000000000000000001463457531700167435ustar00rootroot00000000000000rules_java-7.6.5/.bazel_checkout/__README000066400000000000000000000002601463457531700201170ustar00rootroot00000000000000This directory exists just so we can clone Bazel sources and run tests on presubmit At some point, we should migrate the tests we care about, out of Bazel and into rules_java.rules_java-7.6.5/.bazel_checkout/setup.sh000066400000000000000000000037561463457531700204520ustar00rootroot00000000000000#!/usr/bin/env bash set -e set -x FAKE_BCR_ROOT=$(mktemp -d --tmpdir fake-bcr.XXX) FAKE_RULES_JAVA_ROOT=${FAKE_BCR_ROOT}/modules/rules_java FAKE_MODULE_VERSION=9999 FAKE_MODULE_ROOT=${FAKE_RULES_JAVA_ROOT}/${FAKE_MODULE_VERSION} FAKE_ARCHIVE=${FAKE_MODULE_ROOT}/rules_java.tar.gz mkdir -p ${FAKE_MODULE_ROOT} # relying on the line number is not great, but :shrugs: sed -e "3 c version = \"${FAKE_MODULE_VERSION}\"," ../MODULE.bazel > ${FAKE_MODULE_ROOT}/MODULE.bazel tar zcf ${FAKE_ARCHIVE} ../ RULES_JAVA_INTEGRITY_SHA256=`cat ${FAKE_ARCHIVE} | openssl dgst -sha256 -binary | base64` cat << EOF > ${FAKE_MODULE_ROOT}/source.json { "integrity": "sha256-${RULES_JAVA_INTEGRITY_SHA256}", "strip_prefix": "", "url": "file://${FAKE_ARCHIVE}" } EOF # fetch and setup bazel sources git init git remote add origin https://github.com/bazelbuild/bazel.git git pull origin master sed -i.bak -e 's/^# android_sdk_repository/android_sdk_repository/' \ -e 's/^# android_ndk_repository/android_ndk_repository/' \ WORKSPACE.bzlmod rm -f WORKSPACE.bzlmod.bak rm -rf $HOME/bazeltest mkdir $HOME/bazeltest echo "common --registry=https://bcr.bazel.build" >> .bazelrc echo "common --registry=file://${FAKE_BCR_ROOT}" >> .bazelrc echo "add_to_bazelrc \"common --registry=https://bcr.bazel.build\"" >> src/test/shell/testenv.sh.tmpl echo "add_to_bazelrc \"common --registry=file://${FAKE_BCR_ROOT}\"" >> src/test/shell/testenv.sh.tmpl SED_CMD="s/bazel_dep(name = \"rules_java\".*/bazel_dep(name = \"rules_java\", version = \"${FAKE_MODULE_VERSION}\")/" sed -i "${SED_CMD}" MODULE.bazel sed -i "${SED_CMD}" src/MODULE.tools BAZEL_QUIET_MODE_ARGS="--ui_event_filters=error,fail" bazel run ${BAZEL_QUIET_MODE_ARGS} //src/test/tools/bzlmod:update_default_lock_file -- \ --registry="https://bcr.bazel.build" --registry="file://${FAKE_BCR_ROOT}" ${BAZEL_QUIET_MODE_ARGS} bazel mod deps --lockfile_mode=update # populate repo cache so tests don't need to access network bazel fetch --config=ci-linux --all ${BAZEL_QUIET_MODE_ARGS} rules_java-7.6.5/.bazelci/000077500000000000000000000000001463457531700153725ustar00rootroot00000000000000rules_java-7.6.5/.bazelci/presubmit.yml000066400000000000000000000032421463457531700201300ustar00rootroot00000000000000--- build_targets: &build_targets - "//..." - "@remote_java_tools//java_tools/..." # TODO: Look into broken targets in //toolchains - "-//toolchains/..." - "-//test/repo/..." build_targets_bzlmod: &build_targets_bzlmod - "//..." - "@remote_java_tools//java_tools/..." - "-//toolchains/..." # TODO(pcloudy): pkg_tar doesn't work with Bzlmod due to https://github.com/bazelbuild/bazel/issues/14259 # Enable once the issue is fixed. - "-//distro/..." - "-//test/repo/..." test_targets: &test_targets - "//test/..." buildifier: latest tasks: ubuntu2004: build_targets: *build_targets test_targets: *test_targets ubuntu2004_integration: name: "Integration Tests" platform: ubuntu2004 working_directory: "test/repo" build_targets: - "//..." - "//:bin_deploy.jar" macos: build_targets: *build_targets windows: build_targets: *build_targets ubuntu2004_head: name: "Bazel@HEAD" bazel: last_green platform: ubuntu2004 build_targets: *build_targets macos_head: name: "Bazel@HEAD" bazel: last_green platform: macos build_targets: *build_targets windows_head: name: "Bazel@HEAD" bazel: last_green platform: windows build_targets: *build_targets ubuntu2004_bzlmod: name: "bzlmod" platform: ubuntu2004 build_flags: - "--config=bzlmod" build_targets: *build_targets_bzlmod macos_bzlmod: name: "bzlmod" platform: macos build_flags: - "--config=bzlmod" build_targets: *build_targets_bzlmod windows_bzlmod: name: "bzlmod" platform: windows build_flags: - "--config=bzlmod" build_targets: *build_targets_bzlmodrules_java-7.6.5/.bazelrc000066400000000000000000000001241463457531700153230ustar00rootroot00000000000000build:bzlmod --experimental_enable_bzlmod common --incompatible_disallow_empty_globrules_java-7.6.5/.bazelversion000066400000000000000000000000061463457531700164030ustar00rootroot000000000000007.0.0 rules_java-7.6.5/.bcr/000077500000000000000000000000001463457531700145275ustar00rootroot00000000000000rules_java-7.6.5/.bcr/metadata.template.json000066400000000000000000000004441463457531700210160ustar00rootroot00000000000000{ "homepage": "https://github.com/bazelbuild/rules_java", "maintainers": [ { "email": "hvd@google.com", "github": "hvadehra", "name": "Hemanshu Vadehra" } ], "versions": [], "yanked_versions": {}, "repository": [ "github:bazelbuild/rules_java" ] } rules_java-7.6.5/.bcr/presubmit.yml000066400000000000000000000004121463457531700172610ustar00rootroot00000000000000matrix: platform: - centos7 - debian10 - macos - ubuntu2004 - windows bazel: - 7.x tasks: verify_build_targets: name: "Verify build targets" platform: ${{ platform }} bazel: ${{ bazel }} build_targets: - "@rules_java//java/..." rules_java-7.6.5/.bcr/source.template.json000066400000000000000000000002121463457531700205270ustar00rootroot00000000000000{ "integrity": "", "strip_prefix": "", "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_java-{TAG}.tar.gz" } rules_java-7.6.5/.github/000077500000000000000000000000001463457531700152435ustar00rootroot00000000000000rules_java-7.6.5/.github/ISSUE_TEMPLATE/000077500000000000000000000000001463457531700174265ustar00rootroot00000000000000rules_java-7.6.5/.github/ISSUE_TEMPLATE/release.md000066400000000000000000000006561463457531700213770ustar00rootroot00000000000000--- name: 'Release tracker' about: Use this template to request for a new rules_java release title: 'Release: rules_java X.Y.Z' labels: ['release','P1'] assignees: - iancha1992 - sgowroji --- **Link to relevant issue and/or commit:** **Other details:** cc @bazelbuild/triage rules_java-7.6.5/.gitignore000066400000000000000000000006411463457531700156740ustar00rootroot00000000000000# Ignore backup files. *~ # Ignore Vim swap files. .*.swp # Ignore files generated by IDEs. /.classpath /.factorypath /.idea/ /.ijwb/ /.project /.settings # Ignore all bazel-* symlinks. There is no full list since this can change # based on the name of the directory bazel is cloned into. /bazel-* # Ignore outputs generated during Bazel bootstrapping. /output/ # Ignore jekyll build output. /production /.sass-cache rules_java-7.6.5/AUTHORS000066400000000000000000000004611463457531700147540ustar00rootroot00000000000000# This the official list of Bazel authors for copyright purposes. # This file is distinct from the CONTRIBUTORS files. # See the latter for an explanation. # Names should be added to this file as: # Name or Organization # The email address is not required for organizations. Google Inc. rules_java-7.6.5/BUILD000066400000000000000000000005101463457531700144610ustar00rootroot00000000000000licenses(["notice"]) exports_files([ "LICENSE", "WORKSPACE", ]) filegroup( name = "distribution", srcs = [ "AUTHORS", "BUILD", "LICENSE", "MODULE.bazel", "WORKSPACE", "//java:srcs", "//toolchains:srcs", ], visibility = ["//visibility:public"], ) rules_java-7.6.5/CODEOWNERS000066400000000000000000000013141463457531700152750ustar00rootroot00000000000000# Each line is a file pattern followed by one or more owners. # Order is important; the last matching pattern takes the most precedence. # When someone opens a pull request that only modifies files in directory, only # component owners and not the global owner(s) will be requested for a review. # Syntax: https://help.github.com/articles/about-codeowners/ # Use individual usernames instead of teams (like @bazelbuild/android) for # auto-assignment to work, unless everyone in the team has write permissions to the repository. # See https://github.community/t5/How-to-use-Git-and-GitHub/CODEOWNERS-works-with-users-but-not-teams/td-p/4986 # Component owners # ---------------- * @comius @bazelbuild/java-team rules_java-7.6.5/CONTRIBUTING.md000066400000000000000000000021151463457531700161330ustar00rootroot00000000000000# How to Contribute We'd love to accept your patches and contributions to this project. There are just a few small guidelines you need to follow. ## Contributor License Agreement Contributions to this project must be accompanied by a Contributor License Agreement. You (or your employer) retain the copyright to your contribution; this simply gives us permission to use and redistribute your contributions as part of the project. Head over to to see your current agreements on file or to sign a new one. You generally only need to submit a CLA once, so if you've already submitted one (even if it was for a different project), you probably don't need to do it again. ## Code reviews All submissions, including submissions by project members, require review. We use GitHub pull requests for this purpose. Consult [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more information on using pull requests. ## Community Guidelines This project follows [Google's Open Source Community Guidelines](https://opensource.google.com/conduct/). rules_java-7.6.5/LICENSE000066400000000000000000000261351463457531700147170ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] 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. rules_java-7.6.5/MODULE.bazel000066400000000000000000000053511463457531700157130ustar00rootroot00000000000000module( name = "rules_java", version = "7.6.5", # Requires @bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type. bazel_compatibility = [">=7.0.0"], compatibility_level = 1, ) bazel_dep(name = "platforms", version = "0.0.4") bazel_dep(name = "rules_cc", version = "0.0.2") bazel_dep(name = "bazel_features", version = "1.11.0") bazel_dep(name = "bazel_skylib", version = "1.6.1") # Required by @remote_java_tools, which is loaded via module extension. bazel_dep(name = "rules_proto", version = "4.0.0") bazel_dep(name = "rules_license", version = "0.0.3") register_toolchains("//toolchains:all") toolchains = use_extension("//java:extensions.bzl", "toolchains") # Declare remote java tools repos use_repo(toolchains, "remote_java_tools") use_repo(toolchains, "remote_java_tools_linux") use_repo(toolchains, "remote_java_tools_windows") use_repo(toolchains, "remote_java_tools_darwin_x86_64") use_repo(toolchains, "remote_java_tools_darwin_arm64") # Declare local jdk repo use_repo(toolchains, "local_jdk") register_toolchains( "@local_jdk//:runtime_toolchain_definition", "@local_jdk//:bootstrap_runtime_toolchain_definition", ) # Declare all remote jdk toolchain config repos JDKS = { # Must match JDK repos defined in remote_jdk8_repos() "8": [ "linux", "linux_aarch64", "linux_s390x", "macos", "macos_aarch64", "windows", ], # Must match JDK repos defined in remote_jdk11_repos() "11": [ "linux", "linux_aarch64", "linux_ppc64le", "linux_s390x", "macos", "macos_aarch64", "win", "win_arm64", ], # Must match JDK repos defined in remote_jdk17_repos() "17": [ "linux", "linux_aarch64", "linux_ppc64le", "linux_s390x", "macos", "macos_aarch64", "win", "win_arm64", ], # Must match JDK repos defined in remote_jdk21_repos() "21": [ "linux", "linux_aarch64", "linux_ppc64le", "linux_s390x", "macos", "macos_aarch64", "win", "win_arm64", ], } REMOTE_JDK_REPOS = [(("remote_jdk" if version == "8" else "remotejdk") + version + "_" + platform) for version in JDKS for platform in JDKS[version]] [use_repo( toolchains, repo + "_toolchain_config_repo", ) for repo in REMOTE_JDK_REPOS] [register_toolchains("@" + name + "_toolchain_config_repo//:all") for name in REMOTE_JDK_REPOS] # Dev dependencies bazel_dep(name = "rules_pkg", version = "0.9.1", dev_dependency = True) # Override rules_python version to deal with #161 and https://github.com/bazelbuild/bazel/issues/20458 single_version_override( module_name = "rules_python", version = "0.24.0", ) rules_java-7.6.5/README.md000066400000000000000000000007111463457531700151610ustar00rootroot00000000000000# rules_java * Postsubmit [![Build status](https://badge.buildkite.com/d4f950ef5f481b8ca066624ba06c238fa1446d84a057ddbf89.svg?branch=master)](https://buildkite.com/bazel/rules-java-java) * Postsubmit + Current Bazel Incompatible Flags [![Build status](https://badge.buildkite.com/ef265d270238c02aff65106a0b861abb9265efacdf4af399c3.svg?branch=master)](https://buildkite.com/bazel/rules-java-plus-bazelisk-migrate) Java Rules for Bazel https://bazel.build. rules_java-7.6.5/WORKSPACE000066400000000000000000000017541463457531700151730ustar00rootroot00000000000000workspace(name = "rules_java") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "bazel_skylib", sha256 = "9f38886a40548c6e96c106b752f242130ee11aaa068a56ba7e56f4511f33e4f2", urls = [ "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.6.1/bazel-skylib-1.6.1.tar.gz", "https://github.com/bazelbuild/bazel-skylib/releases/download/1.6.1/bazel-skylib-1.6.1.tar.gz", ], ) load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") bazel_skylib_workspace() http_archive( name = "rules_pkg", sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8", urls = [ "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz", "https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz", ], ) load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") rules_pkg_dependencies() rules_java-7.6.5/WORKSPACE.bzlmod000066400000000000000000000002351463457531700164520ustar00rootroot00000000000000# A completely empty WORKSPACE file to replace the original WORKSPACE content when enabling Bzlmod. # No WORKSPACE prefix or suffix are added for this file. rules_java-7.6.5/distro/000077500000000000000000000000001463457531700152075ustar00rootroot00000000000000rules_java-7.6.5/distro/BUILD.bazel000066400000000000000000000014501463457531700170650ustar00rootroot00000000000000load("@rules_pkg//pkg:tar.bzl", "pkg_tar") load("@rules_pkg//pkg/releasing:defs.bzl", "print_rel_notes") package(default_visibility = ["//visibility:private"]) # Build the artifact to put on the github release page. pkg_tar( name = "rules_java-%s" % module_version(), srcs = ["//:distribution"], extension = "tar.gz", # It is all source code, so make it read-only. mode = "0444", # Make it owned by root so it does not have the uid of the CI robot. owner = "0.0", package_dir = ".", strip_prefix = ".", ) print_rel_notes( name = "relnotes", outs = ["relnotes.txt"], deps_method = "rules_java_dependencies", repo = "rules_java", setup_file = "java:repositories.bzl", toolchains_method = "rules_java_toolchains", version = module_version(), ) rules_java-7.6.5/distro/README.md000066400000000000000000000021451463457531700164700ustar00rootroot00000000000000# Releasing rules_java 1. Update version in [MODULE.bazel](/MODULE.bazel) and merge it 2. Build the release running `bazel build //distro:rules_java-{version}` 3. Prepare release notes running `bazel build //distro:relnotes` 4. Create a new release on GitHub 5. Copy/paste the produced `relnotes.txt` into the notes. Adjust as needed. 6. Upload the produced tar.gz file as an artifact. ------ **Note:** Steps 2-6 have been automated. Trigger a new build of the [rules_java release pipeline](https://buildkite.com/bazel-trusted/rules-java-release/). Set the message to "rules_java [version]" (or anything else), and leave the commit and branch fields as is. A new release will be created [here](https://github.com/bazelbuild/rules_java/releases) -- edit the description as needed. A PR will be submitted against the [bazel-central-registry](https://github.com/bazelbuild/bazel-central-registry) repo. rules_java 6.5.0 example: - Build: https://buildkite.com/bazel-trusted/rules-java-release/builds/1 - Release: https://github.com/bazelbuild/rules_java/releases/tag/6.5.0 - BCR PR: bazelbuild/bazel-central-registry#818 rules_java-7.6.5/examples/000077500000000000000000000000001463457531700155215ustar00rootroot00000000000000rules_java-7.6.5/examples/hello_world/000077500000000000000000000000001463457531700200335ustar00rootroot00000000000000rules_java-7.6.5/examples/hello_world/BUILD000066400000000000000000000002461463457531700206170ustar00rootroot00000000000000load("//java:defs.bzl", "java_binary") java_binary( name = "hello_world", srcs = ["com/google/HelloWorld.java"], main_class = "com.google.HelloWorld", ) rules_java-7.6.5/examples/hello_world/com/000077500000000000000000000000001463457531700206115ustar00rootroot00000000000000rules_java-7.6.5/examples/hello_world/com/google/000077500000000000000000000000001463457531700220655ustar00rootroot00000000000000rules_java-7.6.5/examples/hello_world/com/google/HelloWorld.java000066400000000000000000000014161463457531700250050ustar00rootroot00000000000000// Copyright 2021 The Bazel Authors. All rights reserved. // // 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. package com.google; public class HelloWorld { private HelloWorld() {} public static void main (String[] args) { System.out.println("Hello World!\n"); } } rules_java-7.6.5/java/000077500000000000000000000000001463457531700146245ustar00rootroot00000000000000rules_java-7.6.5/java/BUILD000066400000000000000000000026741463457531700154170ustar00rootroot00000000000000load("@bazel_skylib//:bzl_library.bzl", "bzl_library") package(default_visibility = ["//visibility:public"]) licenses(["notice"]) filegroup( name = "srcs", srcs = glob(["**"]) + [ "//java/common:srcs", "//java/private:srcs", "//java/proto:srcs", "//java/toolchains:srcs", ], visibility = ["//:__pkg__"], ) bzl_library( name = "rules", srcs = ["defs.bzl"], visibility = ["//visibility:public"], deps = [ ":core_rules", "//java/common", "//java/toolchains:toolchain_rules", ], ) bzl_library( name = "core_rules", srcs = [ "java_binary.bzl", "java_import.bzl", "java_library.bzl", "java_plugin.bzl", "java_single_jar.bzl", "java_test.bzl", ], visibility = ["//visibility:public"], deps = [ "//java/common", "//java/private", ], ) bzl_library( name = "utils", srcs = ["java_utils.bzl"], visibility = ["//visibility:public"], ) bzl_library( name = "java_single_jar", srcs = ["java_single_jar.bzl"], visibility = ["//visibility:public"], deps = ["//java/common"], ) filegroup( name = "for_bazel_tests", testonly = 1, srcs = [ "BUILD", ":core_rules", ":java_single_jar", ":rules", "//java/common:for_bazel_tests", "//java/private:for_bazel_tests", ], visibility = ["//visibility:public"], ) rules_java-7.6.5/java/bazel/000077500000000000000000000000001463457531700157215ustar00rootroot00000000000000rules_java-7.6.5/java/bazel/BUILD.bazel000066400000000000000000000040151463457531700175770ustar00rootroot00000000000000# Copyright 2024 The Bazel Authors. All rights reserved. # # 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. load(":repositories_util.bzl", "FLAT_CONFIGS") # run this to generate _REMOTE_JDK_CONFIGS_LIST in repositories.bzl # this downloads all the jdks and computes their sha256 sum, so can take a while # TODO(hvd): make this a sh_binary to update the configs in place genrule( name = "dump_remote_jdk_configs", outs = ["remote_jdks_config.out"], cmd = """ echo > $@ while read -r config; do TMP_FILE=$$(mktemp -q /tmp/remotejdk.XXXXXX) IFS=\\| read -r name version urls strip_prefix target_compatible_with primary_url <<< "$$config" echo "fetching: $$primary_url to $$TMP_FILE" > /dev/stderr curl --silent -o $$TMP_FILE -L "$$primary_url" > /dev/stderr sha256=`sha256sum $$TMP_FILE | cut -d' ' -f1` echo "struct(" echo " name = \\"$$name\\"," echo " target_compatible_with = $$target_compatible_with," echo " sha256 = \\"$$sha256\\"," echo " strip_prefix = \\"$$strip_prefix\\"," echo " urls = $$urls," echo " version = \\"$$version\\"," echo ")," done <<< '{configs}' >> $@ """.format(configs = "\n".join([ "|".join([ config.name, config.version, json.encode(config.urls), config.strip_prefix, json.encode(config.target_compatible_with), config.urls[0], ]) for config in FLAT_CONFIGS ])), tags = [ "local", "manual", ], visibility = ["//visibility:private"], ) rules_java-7.6.5/java/bazel/repositories_util.bzl000066400000000000000000000151351463457531700222230ustar00rootroot00000000000000# Copyright 2024 The Bazel Authors. All rights reserved. # # 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. """Helper functions to register remote jdk repos""" visibility(["//test"]) _RELEASE_CONFIGS = { "8": { "zulu": { "release": "8.78.0.19-ca-jdk8.0.412", "platforms": { "linux": ["aarch64", "x86_64"], "macos": ["aarch64", "x86_64"], "windows": ["x86_64"], }, }, "adoptopenjdk": { "release": "8u292-b10", "platforms": { "linux": ["s390x"], }, }, }, "11": { "zulu": { "release": "11.72.19-ca-jdk11.0.23", "platforms": { "linux": ["aarch64", "x86_64"], "macos": ["aarch64", "x86_64"], "windows": ["x86_64"], }, }, "adoptium": { "release": "11.0.15+10", "platforms": { "linux": ["ppc", "s390x"], }, }, "microsoft": { "release": "11.0.13.8.1", "platforms": { "windows": ["arm64"], }, }, }, "17": { "zulu": { "release": "17.50.19-ca-jdk17.0.11", "platforms": { "linux": ["aarch64", "x86_64"], "macos": ["aarch64", "x86_64"], "windows": ["arm64", "x86_64"], }, }, "adoptium": { "release": "17.0.8.1+1", "platforms": { "linux": ["ppc", "s390x"], }, }, }, "21": { "zulu": { "release": "21.34.19-ca-jdk21.0.3", "platforms": { "linux": ["aarch64", "x86_64"], "macos": ["aarch64", "x86_64"], "windows": ["x86_64"], }, }, "adoptium": { "release": "21.0.2+13", "platforms": { "linux": ["ppc", "s390x"], }, }, "microsoft": { "release": "21.0.0", "platforms": { "windows": ["arm64"], }, }, }, } _STRIP_PREFIX_OVERRIDES = { "remotejdk11_win_arm64": "jdk-11.0.13+8", "remotejdk21_win_arm64": "jdk-21+35", } def _name_for_remote_jdk(version, os, cpu): prefix = "remote_jdk" if version == "8" else "remotejdk" os_part = "win" if (os == "windows" and version != "8") else os if cpu == "x86_64": suffix = "" elif cpu == "ppc": suffix = "_ppc64le" else: suffix = "_" + cpu return prefix + version + "_" + os_part + suffix def _zulu_remote_jdk_repo(os, cpu, release): arch = cpu if cpu == "x86_64": arch = "x64" platform = os ext = ".tar.gz" if os == "macos": platform = "macosx" elif os == "windows": ext = ".zip" platform = "win" arch = "aarch64" if arch == "arm64" else arch archive_name = "zulu" + release + "-" + platform + "_" + arch primary_url = "cdn.azul.com/zulu/bin/" + archive_name + ext urls = [ "https://" + primary_url, "https://mirror.bazel.build/" + primary_url, ] return urls, archive_name def _adoptium_linux_remote_jdk_repo(version, cpu, release): os = "linux" arch = cpu if cpu == "ppc": arch = "ppc64le" archive_name = "OpenJDK" + version + "U-jdk_" + arch + "_" + os + "_hotspot_" + release.replace("+", "_") + ".tar.gz" primary_url = "github.com/adoptium/temurin" + version + "-binaries/releases/download/jdk-" + release + "/" + archive_name urls = [ "https://" + primary_url, "https://mirror.bazel.build/" + primary_url, ] return urls, "jdk-" + release def _microsoft_windows_arm64_remote_jdk_repo(release): primary_url = "aka.ms/download-jdk/microsoft-jdk-" + release + "-windows-aarch64.zip" urls = [ "https://" + primary_url, "https://mirror.bazel.build/" + primary_url, ] return urls, "" def _adoptopenjdk_remote_jdk_repo(version, os, cpu, release): archive = "OpenJDK" + version + "U-jdk_" + cpu + "_" + os + "_hotspot_" + release.replace("-", "") + ".tar.gz" primary_url = "github.com/AdoptOpenJDK/openjdk" + version + "-binaries/releases/download/jdk" + release + "/" + archive urls = [ "https://" + primary_url, "https://mirror.bazel.build/" + primary_url, ] return urls, "jdk" + release def _flatten_configs(): result = [] for version, all_for_version in _RELEASE_CONFIGS.items(): for distrib, distrib_cfg in all_for_version.items(): release = distrib_cfg["release"] for os, cpus in distrib_cfg["platforms"].items(): for cpu in cpus: name = _name_for_remote_jdk(version, os, cpu) if distrib == "zulu": urls, strip_prefix = _zulu_remote_jdk_repo(os, cpu, release) elif distrib == "adoptium": if os != "linux": fail("adoptium jdk configured but not linux") urls, strip_prefix = _adoptium_linux_remote_jdk_repo(version, cpu, release) elif distrib == "microsoft": if os != "windows" or cpu != "arm64": fail("only windows_arm64 config for microsoft is expected") urls, strip_prefix = _microsoft_windows_arm64_remote_jdk_repo(release) elif distrib == "adoptopenjdk": urls, strip_prefix = _adoptopenjdk_remote_jdk_repo(version, os, cpu, release) else: fail("unexpected distribution:", distrib) result.append(struct( name = name, version = version, urls = urls, strip_prefix = _STRIP_PREFIX_OVERRIDES.get(name, strip_prefix), target_compatible_with = ["@platforms//os:" + os, "@platforms//cpu:" + cpu], )) return result FLAT_CONFIGS = _flatten_configs() rules_java-7.6.5/java/common/000077500000000000000000000000001463457531700161145ustar00rootroot00000000000000rules_java-7.6.5/java/common/BUILD000066400000000000000000000010101463457531700166660ustar00rootroot00000000000000load("@bazel_skylib//:bzl_library.bzl", "bzl_library") package(default_visibility = ["//visibility:public"]) licenses(["notice"]) filegroup( name = "srcs", srcs = glob(["**"]), visibility = ["//java:__pkg__"], ) bzl_library( name = "common", srcs = glob(["*.bzl"]), visibility = ["//visibility:public"], deps = ["//java/private"], ) filegroup( name = "for_bazel_tests", testonly = 1, srcs = [ "BUILD", ":common", ], visibility = ["//java:__pkg__"], ) rules_java-7.6.5/java/common/java_common.bzl000066400000000000000000000013161463457531700211170ustar00rootroot00000000000000# Copyright 2023 The Bazel Authors. All rights reserved. # # 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. """java_common module""" load("//java/private:native.bzl", "native_java_common") java_common = native_java_common rules_java-7.6.5/java/common/java_info.bzl000066400000000000000000000013021463457531700205550ustar00rootroot00000000000000# Copyright 2023 The Bazel Authors. All rights reserved. # # 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. """JavaInfo provider""" load("//java/private:native.bzl", "NativeJavaInfo") JavaInfo = NativeJavaInfo rules_java-7.6.5/java/common/java_plugin_info.bzl000066400000000000000000000013321463457531700221360ustar00rootroot00000000000000# Copyright 2023 The Bazel Authors. All rights reserved. # # 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. """JavaPluginInfo provider""" load("//java/private:native.bzl", "NativeJavaPluginInfo") JavaPluginInfo = NativeJavaPluginInfo rules_java-7.6.5/java/defs.bzl000066400000000000000000000037261463457531700162660ustar00rootroot00000000000000# Copyright 2019 The Bazel Authors. All rights reserved. # # 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. """Starlark rules for building Java projects.""" load("//java:java_binary.bzl", _java_binary = "java_binary") load("//java:java_import.bzl", _java_import = "java_import") load("//java:java_library.bzl", _java_library = "java_library") load("//java:java_plugin.bzl", _java_plugin = "java_plugin") load("//java:java_test.bzl", _java_test = "java_test") load("//java/common:java_common.bzl", _java_common = "java_common") load("//java/common:java_info.bzl", _JavaInfo = "JavaInfo") load("//java/common:java_plugin_info.bzl", _JavaPluginInfo = "JavaPluginInfo") load("//java/toolchains:java_package_configuration.bzl", _java_package_configuration = "java_package_configuration") load("//java/toolchains:java_runtime.bzl", _java_runtime = "java_runtime") load("//java/toolchains:java_toolchain.bzl", _java_toolchain = "java_toolchain") # Language rules java_binary = _java_binary java_test = _java_test java_library = _java_library java_plugin = _java_plugin java_import = _java_import # Toolchain rules java_runtime = _java_runtime java_toolchain = _java_toolchain java_package_configuration = _java_package_configuration # Proto rules # Deprecated: don't use java proto libraries from here java_proto_library = native.java_proto_library java_lite_proto_library = native.java_lite_proto_library # Modules and providers JavaInfo = _JavaInfo JavaPluginInfo = _JavaPluginInfo java_common = _java_common rules_java-7.6.5/java/extensions.bzl000066400000000000000000000024051463457531700175350ustar00rootroot00000000000000# Copyright 2021 The Bazel Authors. All rights reserved. # # 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. """Module extensions for rules_java.""" load("@bazel_features//:features.bzl", "bazel_features") load( "//java:repositories.bzl", "java_tools_repos", "local_jdk_repo", "remote_jdk11_repos", "remote_jdk17_repos", "remote_jdk21_repos", "remote_jdk8_repos", ) def _toolchains_impl(module_ctx): java_tools_repos() local_jdk_repo() remote_jdk8_repos() remote_jdk11_repos() remote_jdk17_repos() remote_jdk21_repos() if bazel_features.external_deps.extension_metadata_has_reproducible: return module_ctx.extension_metadata(reproducible = True) else: return None toolchains = module_extension(_toolchains_impl) rules_java-7.6.5/java/java_binary.bzl000066400000000000000000000016671463457531700176340ustar00rootroot00000000000000# Copyright 2023 The Bazel Authors. All rights reserved. # # 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. """java_binary rule""" # Do not touch: This line marks the end of loads; needed for PR importing. def java_binary(**attrs): """Bazel java_binary rule. https://docs.bazel.build/versions/master/be/java.html#java_binary Args: **attrs: Rule attributes """ # buildifier: disable=native-java native.java_binary(**attrs) rules_java-7.6.5/java/java_import.bzl000066400000000000000000000015531463457531700176540ustar00rootroot00000000000000# Copyright 2023 The Bazel Authors. All rights reserved. # # 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. """java_import rule""" def java_import(**attrs): """Bazel java_import rule. https://docs.bazel.build/versions/master/be/java.html#java_import Args: **attrs: Rule attributes """ # buildifier: disable=native-java native.java_import(**attrs) rules_java-7.6.5/java/java_library.bzl000066400000000000000000000016741463457531700200120ustar00rootroot00000000000000# Copyright 2023 The Bazel Authors. All rights reserved. # # 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. """java_library rule""" # Do not touch: This line marks the end of loads; needed for PR importing. def java_library(**attrs): """Bazel java_library rule. https://docs.bazel.build/versions/master/be/java.html#java_library Args: **attrs: Rule attributes """ # buildifier: disable=native-java native.java_library(**attrs) rules_java-7.6.5/java/java_plugin.bzl000066400000000000000000000015531463457531700176400ustar00rootroot00000000000000# Copyright 2023 The Bazel Authors. All rights reserved. # # 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. """java_plugin rule""" def java_plugin(**attrs): """Bazel java_plugin rule. https://docs.bazel.build/versions/master/be/java.html#java_plugin Args: **attrs: Rule attributes """ # buildifier: disable=native-java native.java_plugin(**attrs) rules_java-7.6.5/java/java_single_jar.bzl000066400000000000000000000126671463457531700204670ustar00rootroot00000000000000""" Definition of _java_single_jar. """ load("//java/common:java_common.bzl", "java_common") load("//java/common:java_info.bzl", "JavaInfo") def _java_single_jar(ctx): transitive_inputs = [] for dep in ctx.attr.deps: if JavaInfo in dep: info = dep[JavaInfo] transitive_inputs.append(info.transitive_runtime_jars) if hasattr(info, "compilation_info"): compilation_info = info.compilation_info if hasattr(compilation_info, "runtime_classpath"): transitive_inputs.append(compilation_info.runtime_classpath) else: files = [] for f in dep[DefaultInfo].files.to_list(): if not f.extension == "jar": fail("unexpected file type in java_single_jar.deps: %s" % f.path) files.append(f) transitive_inputs.append(depset(files)) inputs = depset(transitive = transitive_inputs) if hasattr(java_common, "JavaRuntimeClasspathInfo"): deploy_env_jars = depset(transitive = [ dep[java_common.JavaRuntimeClasspathInfo].runtime_classpath for dep in ctx.attr.deploy_env ]) excluded_jars = {jar: None for jar in deploy_env_jars.to_list()} if excluded_jars: inputs = depset([jar for jar in inputs.to_list() if jar not in excluded_jars]) args = ctx.actions.args() args.add_all("--sources", inputs) args.use_param_file("@%s") args.set_param_file_format("multiline") args.add_all("--deploy_manifest_lines", ctx.attr.deploy_manifest_lines) args.add("--output", ctx.outputs.jar) args.add("--normalize") # Deal with limitation of singlejar flags: tool's default behavior is # "no", but you get that behavior only by absence of compression flags. if ctx.attr.compress == "preserve": args.add("--dont_change_compression") elif ctx.attr.compress == "yes": args.add("--compression") elif ctx.attr.compress == "no": pass else: fail("\"compress\" attribute (%s) must be: yes, no, preserve." % ctx.attr.compress) if ctx.attr.exclude_build_data: args.add("--exclude_build_data") if ctx.attr.multi_release: args.add("--multi_release") ctx.actions.run( inputs = inputs, outputs = [ctx.outputs.jar], arguments = [args], progress_message = "Merging into %s" % ctx.outputs.jar.short_path, mnemonic = "JavaSingleJar", executable = ctx.executable._singlejar, ) files = depset([ctx.outputs.jar]) providers = [DefaultInfo( files = files, runfiles = ctx.runfiles(transitive_files = files), )] if hasattr(java_common, "JavaRuntimeClasspathInfo"): providers.append(java_common.JavaRuntimeClasspathInfo(runtime_classpath = inputs)) return providers java_single_jar = rule( attrs = { "deps": attr.label_list( allow_files = True, doc = """ The Java targets (including java_import and java_library) to collect transitive dependencies from. Runtime dependencies are collected via deps, exports, and runtime_deps. Resources are also collected. Native cc_library or java_wrap_cc dependencies are not.""", ), "deploy_manifest_lines": attr.string_list(doc = """ A list of lines to add to the META-INF/manifest.mf file."""), "deploy_env": attr.label_list( providers = [java_common.JavaRuntimeClasspathInfo] if hasattr(java_common, "JavaRuntimeClasspathInfo") else [], allow_files = False, doc = """ A list of `java_binary` or `java_single_jar` targets which represent the deployment environment for this binary. Set this attribute when building a plugin which will be loaded by another `java_binary`. `deploy_env` dependencies are excluded from the jar built by this rule.""", ), "compress": attr.string(default = "preserve", doc = """ Whether to always deflate ("yes"), always store ("no"), or pass through unmodified ("preserve"). The default is "preserve", and is the most efficient option -- no extra work is done to inflate or deflate."""), "exclude_build_data": attr.bool(default = True, doc = """ Whether to omit the build-data.properties file generated by default."""), "multi_release": attr.bool(default = True, doc = """Whether to enable Multi-Release output jars."""), "_singlejar": attr.label( default = Label("//toolchains:singlejar"), cfg = "exec", allow_single_file = True, executable = True, ), }, outputs = { "jar": "%{name}.jar", }, implementation = _java_single_jar, doc = """ Collects Java dependencies and jar files into a single jar `java_single_jar` collects Java dependencies and jar files into a single jar. This is similar to java_binary with everything related to executables disabled, and provides an alternative to the java_binary "deploy jar hack". ## Example ```skylark load("//tools/build_defs/java_single_jar:java_single_jar.bzl", "java_single_jar") java_single_jar( name = "my_single_jar", deps = [ "//java/com/google/foo", "//java/com/google/bar", ], ) ``` Outputs: {name}.jar: A single jar containing all of the inputs. """, ) rules_java-7.6.5/java/java_test.bzl000066400000000000000000000016551463457531700173240ustar00rootroot00000000000000# Copyright 2023 The Bazel Authors. All rights reserved. # # 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. """java_test rule""" # Do not touch: This line marks the end of loads; needed for PR importing. def java_test(**attrs): """Bazel java_test rule. https://docs.bazel.build/versions/master/be/java.html#java_test Args: **attrs: Rule attributes """ # buildifier: disable=native-java native.java_test(**attrs) rules_java-7.6.5/java/java_utils.bzl000066400000000000000000000012731463457531700175010ustar00rootroot00000000000000"""Utility methods for interacting with the java rules""" def _tokenize_javacopts(ctx, opts): """Tokenizes a list or depset of options to a list. Iff opts is a depset, we reverse the flattened list to ensure right-most duplicates are preserved in their correct position. Args: ctx: (RuleContext) the rule context opts: (depset[str]|[str]) the javac options to tokenize Returns: [str] list of tokenized options """ if hasattr(opts, "to_list"): opts = reversed(opts.to_list()) return [ token for opt in opts for token in ctx.tokenize(opt) ] utils = struct( tokenize_javacopts = _tokenize_javacopts, ) rules_java-7.6.5/java/private/000077500000000000000000000000001463457531700162765ustar00rootroot00000000000000rules_java-7.6.5/java/private/BUILD000066400000000000000000000007051463457531700170620ustar00rootroot00000000000000load("@bazel_skylib//:bzl_library.bzl", "bzl_library") licenses(["notice"]) bzl_library( name = "private", srcs = [ "native.bzl", ], visibility = ["//java:__subpackages__"], ) filegroup( name = "srcs", srcs = glob(["**"]), visibility = ["//java:__pkg__"], ) filegroup( name = "for_bazel_tests", testonly = 1, srcs = [ "BUILD", ":private", ], visibility = ["//java:__pkg__"], ) rules_java-7.6.5/java/private/native.bzl000066400000000000000000000023571463457531700203040ustar00rootroot00000000000000# Copyright 2022 The Bazel Authors. All rights reserved. # # 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. # Redefine native symbols with a new name as a workaround for # exporting them in `//third_party/bazel_rules/rules_proto/proto:defs.bzl` with their original name. # # While we cannot force users to load these symbol due to the lack of a # allowlisting mechanism, we can still export them and tell users to # load it to make a future migration to pure Starlark easier. """Lovely workaround to be able to expose native constants pretending to be Starlark.""" # buildifier: disable=native-java native_java_common = java_common # buildifier: disable=native-java NativeJavaInfo = JavaInfo # buildifier: disable=native-java NativeJavaPluginInfo = JavaPluginInfo rules_java-7.6.5/java/proto/000077500000000000000000000000001463457531700157675ustar00rootroot00000000000000rules_java-7.6.5/java/proto/BUILD000066400000000000000000000006351463457531700165550ustar00rootroot00000000000000package(default_visibility = ["//visibility:public"]) # Toolchain type provided by proto_lang_toolchain rule and used by java_proto_library toolchain_type(name = "toolchain_type") # Toolchain type provided by proto_lang_toolchain rule and used by java_lite_proto_library toolchain_type(name = "lite_toolchain_type") filegroup( name = "srcs", srcs = glob(["**"]), visibility = ["//java:__pkg__"], ) rules_java-7.6.5/java/repositories.bzl000066400000000000000000000524001463457531700200650ustar00rootroot00000000000000# Copyright 2019 The Bazel Authors. All rights reserved. # # 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. """Development and production dependencies of rules_java.""" load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load("//toolchains:jdk_build_file.bzl", "JDK_BUILD_TEMPLATE") load("//toolchains:local_java_repository.bzl", "local_java_repository") load("//toolchains:remote_java_repository.bzl", "remote_java_repository") # visible for tests JAVA_TOOLS_CONFIG = { "version": "v13.6.1", "release": "true", "artifacts": { "java_tools_linux": { "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v13.6.1/java_tools_linux-v13.6.1.zip", "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_13.6.1/java_tools_linux-v13.6.1.zip", "sha": "0d3fcae7ae40d0a25f17c3adc30a3674f526953c55871189e2efe3463fce3496", }, "java_tools_windows": { "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v13.6.1/java_tools_windows-v13.6.1.zip", "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_13.6.1/java_tools_windows-v13.6.1.zip", "sha": "5a7d00e42c0b35f08eb5c8577eb115f8f57dd36ef8b6940c2190bd0d0e4ddcf0", }, "java_tools_darwin_x86_64": { "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v13.6.1/java_tools_darwin_x86_64-v13.6.1.zip", "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_13.6.1/java_tools_darwin_x86_64-v13.6.1.zip", "sha": "465dcb1da77a0c83c49f178c11bad29b3d703df1756722ec42fe5afd7c8129f8", }, "java_tools_darwin_arm64": { "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v13.6.1/java_tools_darwin_arm64-v13.6.1.zip", "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_13.6.1/java_tools_darwin_arm64-v13.6.1.zip", "sha": "eb54c4e5fa23d6e9e9fc14c106a682dbefc54659d8e389a2f3c0d61d51cae274", }, "java_tools": { "mirror_url": "https://mirror.bazel.build/bazel_java_tools/releases/java/v13.6.1/java_tools-v13.6.1.zip", "github_url": "https://github.com/bazelbuild/java_tools/releases/download/java_13.6.1/java_tools-v13.6.1.zip", "sha": "74c978eab040ad4ec38ce0d0970ac813cc2c6f4f6f4f121c0414719487edc991", }, }, } def java_tools_repos(): """ Declares the remote java_tools repositories """ for name, config in JAVA_TOOLS_CONFIG["artifacts"].items(): maybe( http_archive, name = "remote_" + name, sha256 = config["sha"], urls = [ config["mirror_url"], config["github_url"], ], ) def local_jdk_repo(): maybe( local_java_repository, name = "local_jdk", build_file_content = JDK_BUILD_TEMPLATE, ) # DO NOT MANUALLY UPDATE! Update java/bazel/repositories_util.bzl instead and # run the java/bazel:dump_remote_jdk_configs target to generate this list _REMOTE_JDK_CONFIGS_LIST = [ struct( name = "remote_jdk8_linux_aarch64", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"], sha256 = "82c46c65d57e187ef68fdd125ef760eaeb52ebfe1be1a6a251cf5b43cbebc78a", strip_prefix = "zulu8.78.0.19-ca-jdk8.0.412-linux_aarch64", urls = ["https://cdn.azul.com/zulu/bin/zulu8.78.0.19-ca-jdk8.0.412-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.78.0.19-ca-jdk8.0.412-linux_aarch64.tar.gz"], version = "8", ), struct( name = "remote_jdk8_linux", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"], sha256 = "9c0ac5ebffa61520fee78ead52add0f4edd3b1b54b01b6a17429b719515caf90", strip_prefix = "zulu8.78.0.19-ca-jdk8.0.412-linux_x64", urls = ["https://cdn.azul.com/zulu/bin/zulu8.78.0.19-ca-jdk8.0.412-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.78.0.19-ca-jdk8.0.412-linux_x64.tar.gz"], version = "8", ), struct( name = "remote_jdk8_macos_aarch64", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"], sha256 = "35bc35808379400e4a70e1f7ee379778881799b93c2cc9fe1ae515c03c2fb057", strip_prefix = "zulu8.78.0.19-ca-jdk8.0.412-macosx_aarch64", urls = ["https://cdn.azul.com/zulu/bin/zulu8.78.0.19-ca-jdk8.0.412-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.78.0.19-ca-jdk8.0.412-macosx_aarch64.tar.gz"], version = "8", ), struct( name = "remote_jdk8_macos", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"], sha256 = "2bfa0506196962bddb21a604eaa2b0b39eaf3383d0bdad08bdbe7f42f25d8928", strip_prefix = "zulu8.78.0.19-ca-jdk8.0.412-macosx_x64", urls = ["https://cdn.azul.com/zulu/bin/zulu8.78.0.19-ca-jdk8.0.412-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.78.0.19-ca-jdk8.0.412-macosx_x64.tar.gz"], version = "8", ), struct( name = "remote_jdk8_windows", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"], sha256 = "ca5499c301d5b42604d8535b8c40a7f928a796247b8c66a600333dd799798ff7", strip_prefix = "zulu8.78.0.19-ca-jdk8.0.412-win_x64", urls = ["https://cdn.azul.com/zulu/bin/zulu8.78.0.19-ca-jdk8.0.412-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu8.78.0.19-ca-jdk8.0.412-win_x64.zip"], version = "8", ), struct( name = "remote_jdk8_linux_s390x", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:s390x"], sha256 = "276a431c79b7e94bc1b1b4fd88523383ae2d635ea67114dfc8a6174267f8fb2c", strip_prefix = "jdk8u292-b10", urls = ["https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u292-b10/OpenJDK8U-jdk_s390x_linux_hotspot_8u292b10.tar.gz", "https://mirror.bazel.build/github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u292-b10/OpenJDK8U-jdk_s390x_linux_hotspot_8u292b10.tar.gz"], version = "8", ), struct( name = "remotejdk11_linux_aarch64", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"], sha256 = "be7d7574253c893eb58f66e985c75adf48558c41885827d1f02f827e109530e0", strip_prefix = "zulu11.72.19-ca-jdk11.0.23-linux_aarch64", urls = ["https://cdn.azul.com/zulu/bin/zulu11.72.19-ca-jdk11.0.23-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.72.19-ca-jdk11.0.23-linux_aarch64.tar.gz"], version = "11", ), struct( name = "remotejdk11_linux", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"], sha256 = "0a4d1bfc7a96a7f9f5329b72b9801b3c53366417b4753f1b658fa240204c7347", strip_prefix = "zulu11.72.19-ca-jdk11.0.23-linux_x64", urls = ["https://cdn.azul.com/zulu/bin/zulu11.72.19-ca-jdk11.0.23-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.72.19-ca-jdk11.0.23-linux_x64.tar.gz"], version = "11", ), struct( name = "remotejdk11_macos_aarch64", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"], sha256 = "40fb1918385e03814b67b7608c908c7f945ccbeddbbf5ed062cdfb2602e21c83", strip_prefix = "zulu11.72.19-ca-jdk11.0.23-macosx_aarch64", urls = ["https://cdn.azul.com/zulu/bin/zulu11.72.19-ca-jdk11.0.23-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.72.19-ca-jdk11.0.23-macosx_aarch64.tar.gz"], version = "11", ), struct( name = "remotejdk11_macos", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"], sha256 = "e5b19b82045826ae09c9d17742691bc9e40312c44be7bd7598ae418a3d4edb1c", strip_prefix = "zulu11.72.19-ca-jdk11.0.23-macosx_x64", urls = ["https://cdn.azul.com/zulu/bin/zulu11.72.19-ca-jdk11.0.23-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.72.19-ca-jdk11.0.23-macosx_x64.tar.gz"], version = "11", ), struct( name = "remotejdk11_win", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"], sha256 = "1295b2affe498018c45f6f15187b58c4456d51dce5eb608ee73ef7665d4566d2", strip_prefix = "zulu11.72.19-ca-jdk11.0.23-win_x64", urls = ["https://cdn.azul.com/zulu/bin/zulu11.72.19-ca-jdk11.0.23-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu11.72.19-ca-jdk11.0.23-win_x64.zip"], version = "11", ), struct( name = "remotejdk11_linux_ppc64le", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:ppc"], sha256 = "a8fba686f6eb8ae1d1a9566821dbd5a85a1108b96ad857fdbac5c1e4649fc56f", strip_prefix = "jdk-11.0.15+10", urls = ["https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.15+10/OpenJDK11U-jdk_ppc64le_linux_hotspot_11.0.15_10.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.15+10/OpenJDK11U-jdk_ppc64le_linux_hotspot_11.0.15_10.tar.gz"], version = "11", ), struct( name = "remotejdk11_linux_s390x", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:s390x"], sha256 = "a58fc0361966af0a5d5a31a2d8a208e3c9bb0f54f345596fd80b99ea9a39788b", strip_prefix = "jdk-11.0.15+10", urls = ["https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.15+10/OpenJDK11U-jdk_s390x_linux_hotspot_11.0.15_10.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.15+10/OpenJDK11U-jdk_s390x_linux_hotspot_11.0.15_10.tar.gz"], version = "11", ), struct( name = "remotejdk11_win_arm64", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:arm64"], sha256 = "b8a28e6e767d90acf793ea6f5bed0bb595ba0ba5ebdf8b99f395266161e53ec2", strip_prefix = "jdk-11.0.13+8", urls = ["https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-windows-aarch64.zip", "https://mirror.bazel.build/aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-windows-aarch64.zip"], version = "11", ), struct( name = "remotejdk17_linux_aarch64", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"], sha256 = "518cc455c0c7b49c0ae7d809c0bb87ab371bb850d46abb8efad5010c6a06faec", strip_prefix = "zulu17.50.19-ca-jdk17.0.11-linux_aarch64", urls = ["https://cdn.azul.com/zulu/bin/zulu17.50.19-ca-jdk17.0.11-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.50.19-ca-jdk17.0.11-linux_aarch64.tar.gz"], version = "17", ), struct( name = "remotejdk17_linux", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"], sha256 = "a1e8ac9ae5804b84dc07cf9d8ebe1b18247d70c92c1e0de97ea10109563f4379", strip_prefix = "zulu17.50.19-ca-jdk17.0.11-linux_x64", urls = ["https://cdn.azul.com/zulu/bin/zulu17.50.19-ca-jdk17.0.11-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.50.19-ca-jdk17.0.11-linux_x64.tar.gz"], version = "17", ), struct( name = "remotejdk17_macos_aarch64", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"], sha256 = "dd1a82d57e80cdefb045066e5c28b5bd41e57eea9c57303ec7e012b57230bb9c", strip_prefix = "zulu17.50.19-ca-jdk17.0.11-macosx_aarch64", urls = ["https://cdn.azul.com/zulu/bin/zulu17.50.19-ca-jdk17.0.11-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.50.19-ca-jdk17.0.11-macosx_aarch64.tar.gz"], version = "17", ), struct( name = "remotejdk17_macos", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"], sha256 = "b384991e93af39abe5229c7f5efbe912a7c5a6480674a6e773f3a9128f96a764", strip_prefix = "zulu17.50.19-ca-jdk17.0.11-macosx_x64", urls = ["https://cdn.azul.com/zulu/bin/zulu17.50.19-ca-jdk17.0.11-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.50.19-ca-jdk17.0.11-macosx_x64.tar.gz"], version = "17", ), struct( name = "remotejdk17_win_arm64", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:arm64"], sha256 = "b8833d272eb31f54f8c881139807a28a74de9deae07d2cc37688ff72043e32c9", strip_prefix = "zulu17.50.19-ca-jdk17.0.11-win_aarch64", urls = ["https://cdn.azul.com/zulu/bin/zulu17.50.19-ca-jdk17.0.11-win_aarch64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.50.19-ca-jdk17.0.11-win_aarch64.zip"], version = "17", ), struct( name = "remotejdk17_win", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"], sha256 = "43f0f1bdecf48ba9763d46ee7784554c95b442ffdd39ebd62dc8b297cc82e116", strip_prefix = "zulu17.50.19-ca-jdk17.0.11-win_x64", urls = ["https://cdn.azul.com/zulu/bin/zulu17.50.19-ca-jdk17.0.11-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu17.50.19-ca-jdk17.0.11-win_x64.zip"], version = "17", ), struct( name = "remotejdk17_linux_ppc64le", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:ppc"], sha256 = "00a4c07603d0218cd678461b5b3b7e25b3253102da4022d31fc35907f21a2efd", strip_prefix = "jdk-17.0.8.1+1", urls = ["https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.8.1+1/OpenJDK17U-jdk_ppc64le_linux_hotspot_17.0.8.1_1.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.8.1+1/OpenJDK17U-jdk_ppc64le_linux_hotspot_17.0.8.1_1.tar.gz"], version = "17", ), struct( name = "remotejdk17_linux_s390x", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:s390x"], sha256 = "ffacba69c6843d7ca70d572489d6cc7ab7ae52c60f0852cedf4cf0d248b6fc37", strip_prefix = "jdk-17.0.8.1+1", urls = ["https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.8.1+1/OpenJDK17U-jdk_s390x_linux_hotspot_17.0.8.1_1.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.8.1+1/OpenJDK17U-jdk_s390x_linux_hotspot_17.0.8.1_1.tar.gz"], version = "17", ), struct( name = "remotejdk21_linux_aarch64", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"], sha256 = "c898d4ce365c8926e22859c06be4a81bafb9fd0126088867e15a528fe99b1599", strip_prefix = "zulu21.34.19-ca-jdk21.0.3-linux_aarch64", urls = ["https://cdn.azul.com/zulu/bin/zulu21.34.19-ca-jdk21.0.3-linux_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.34.19-ca-jdk21.0.3-linux_aarch64.tar.gz"], version = "21", ), struct( name = "remotejdk21_linux", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"], sha256 = "ca763d1308a6bcc768382f160733a08e591d5f595a7dd9e51b60d27d54828dcc", strip_prefix = "zulu21.34.19-ca-jdk21.0.3-linux_x64", urls = ["https://cdn.azul.com/zulu/bin/zulu21.34.19-ca-jdk21.0.3-linux_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.34.19-ca-jdk21.0.3-linux_x64.tar.gz"], version = "21", ), struct( name = "remotejdk21_macos_aarch64", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:aarch64"], sha256 = "4f42a561909d71868a700cf2efa1390e1b9e04863f3fa75ea30c4965e5a702f0", strip_prefix = "zulu21.34.19-ca-jdk21.0.3-macosx_aarch64", urls = ["https://cdn.azul.com/zulu/bin/zulu21.34.19-ca-jdk21.0.3-macosx_aarch64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.34.19-ca-jdk21.0.3-macosx_aarch64.tar.gz"], version = "21", ), struct( name = "remotejdk21_macos", target_compatible_with = ["@platforms//os:macos", "@platforms//cpu:x86_64"], sha256 = "148006a220a18922d7a9c52ac0bad099c5b4e60334a8d02b11f8c945e9ec9a34", strip_prefix = "zulu21.34.19-ca-jdk21.0.3-macosx_x64", urls = ["https://cdn.azul.com/zulu/bin/zulu21.34.19-ca-jdk21.0.3-macosx_x64.tar.gz", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.34.19-ca-jdk21.0.3-macosx_x64.tar.gz"], version = "21", ), struct( name = "remotejdk21_win", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:x86_64"], sha256 = "fb9f0dc6a484b0b169b3b3a3c2425d5f62bebfd15cb06c1597e33f77959c72af", strip_prefix = "zulu21.34.19-ca-jdk21.0.3-win_x64", urls = ["https://cdn.azul.com/zulu/bin/zulu21.34.19-ca-jdk21.0.3-win_x64.zip", "https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu21.34.19-ca-jdk21.0.3-win_x64.zip"], version = "21", ), struct( name = "remotejdk21_linux_ppc64le", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:ppc"], sha256 = "d08de863499d8851811c893e8915828f2cd8eb67ed9e29432a6b4e222d80a12f", strip_prefix = "jdk-21.0.2+13", urls = ["https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.2+13/OpenJDK21U-jdk_ppc64le_linux_hotspot_21.0.2_13.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.2+13/OpenJDK21U-jdk_ppc64le_linux_hotspot_21.0.2_13.tar.gz"], version = "21", ), struct( name = "remotejdk21_linux_s390x", target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:s390x"], sha256 = "0d5676c50821e0d0b951bf3ffd717e7a13be2a89d8848a5c13b4aedc6f982c78", strip_prefix = "jdk-21.0.2+13", urls = ["https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.2+13/OpenJDK21U-jdk_s390x_linux_hotspot_21.0.2_13.tar.gz", "https://mirror.bazel.build/github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.2+13/OpenJDK21U-jdk_s390x_linux_hotspot_21.0.2_13.tar.gz"], version = "21", ), struct( name = "remotejdk21_win_arm64", target_compatible_with = ["@platforms//os:windows", "@platforms//cpu:arm64"], sha256 = "975603e684f2ec5a525b3b5336d6aa0b09b5b7d2d0d9e271bd6a9892ad550181", strip_prefix = "jdk-21+35", urls = ["https://aka.ms/download-jdk/microsoft-jdk-21.0.0-windows-aarch64.zip", "https://mirror.bazel.build/aka.ms/download-jdk/microsoft-jdk-21.0.0-windows-aarch64.zip"], version = "21", ), ] def _make_version_to_remote_jdks(): result = {} for cfg in _REMOTE_JDK_CONFIGS_LIST: result.setdefault(cfg.version, []) result[cfg.version].append(cfg) return result # visible for testing REMOTE_JDK_CONFIGS = _make_version_to_remote_jdks() def _remote_jdk_repos_for_version(version): for item in REMOTE_JDK_CONFIGS[version]: maybe( remote_java_repository, name = item.name, target_compatible_with = item.target_compatible_with, sha256 = item.sha256, strip_prefix = item.strip_prefix, urls = item.urls, version = item.version, ) def remote_jdk8_repos(name = ""): """Imports OpenJDK 8 repositories. Args: name: The name of this macro (not used) """ _remote_jdk_repos_for_version("8") def remote_jdk11_repos(): """Imports OpenJDK 11 repositories.""" _remote_jdk_repos_for_version("11") def remote_jdk17_repos(): """Imports OpenJDK 17 repositories.""" _remote_jdk_repos_for_version("17") def remote_jdk21_repos(): """Imports OpenJDK 21 repositories.""" _remote_jdk_repos_for_version("21") def rules_java_dependencies(): """An utility method to load all dependencies of rules_java. Loads the remote repositories used by default in Bazel. """ local_jdk_repo() remote_jdk8_repos() remote_jdk11_repos() remote_jdk17_repos() remote_jdk21_repos() java_tools_repos() def rules_java_toolchains(name = "toolchains"): """An utility method to load all Java toolchains. Args: name: The name of this macro (not used) """ native.register_toolchains( "//toolchains:all", "@local_jdk//:runtime_toolchain_definition", "@local_jdk//:bootstrap_runtime_toolchain_definition", ) for items in REMOTE_JDK_CONFIGS.values(): for item in items: native.register_toolchains( "@" + item.name + "_toolchain_config_repo//:toolchain", "@" + item.name + "_toolchain_config_repo//:bootstrap_runtime_toolchain", ) rules_java-7.6.5/java/toolchains/000077500000000000000000000000001463457531700167675ustar00rootroot00000000000000rules_java-7.6.5/java/toolchains/BUILD000066400000000000000000000007451463457531700175570ustar00rootroot00000000000000load("@bazel_skylib//:bzl_library.bzl", "bzl_library") package(default_visibility = ["//visibility:public"]) licenses(["notice"]) filegroup( name = "srcs", srcs = glob(["**"]), visibility = ["//java:__pkg__"], ) bzl_library( name = "toolchain_rules", srcs = glob(["*.bzl"]), visibility = ["//visibility:public"], deps = ["//java/private"], ) filegroup( name = "for_bazel_tests", srcs = [ "BUILD", "java_toolchain.bzl", ], ) rules_java-7.6.5/java/toolchains/java_package_configuration.bzl000066400000000000000000000016661463457531700250340ustar00rootroot00000000000000# Copyright 2023 The Bazel Authors. All rights reserved. # # 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. """java_package_configuration rule""" def java_package_configuration(**attrs): """Bazel java_package_configuration rule. https://docs.bazel.build/versions/master/be/java.html#java_package_configuration Args: **attrs: Rule attributes """ # buildifier: disable=native-java native.java_package_configuration(**attrs) rules_java-7.6.5/java/toolchains/java_runtime.bzl000066400000000000000000000015601463457531700221660ustar00rootroot00000000000000# Copyright 2023 The Bazel Authors. All rights reserved. # # 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. """java_runtime rule""" def java_runtime(**attrs): """Bazel java_runtime rule. https://docs.bazel.build/versions/master/be/java.html#java_runtime Args: **attrs: Rule attributes """ # buildifier: disable=native-java native.java_runtime(**attrs) rules_java-7.6.5/java/toolchains/java_toolchain.bzl000066400000000000000000000015721463457531700224660ustar00rootroot00000000000000# Copyright 2023 The Bazel Authors. All rights reserved. # # 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. """java_toolchain rule""" def java_toolchain(**attrs): """Bazel java_toolchain rule. https://docs.bazel.build/versions/master/be/java.html#java_toolchain Args: **attrs: Rule attributes """ # buildifier: disable=native-java native.java_toolchain(**attrs) rules_java-7.6.5/renovate.json000066400000000000000000000000611463457531700164160ustar00rootroot00000000000000{ "extends": [ "config:base" ] } rules_java-7.6.5/test/000077500000000000000000000000001463457531700146625ustar00rootroot00000000000000rules_java-7.6.5/test/BUILD.bazel000066400000000000000000000027441463457531700165470ustar00rootroot00000000000000# Copyright 2024 The Bazel Authors. All rights reserved. # # 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. load("//java:repositories.bzl", "JAVA_TOOLS_CONFIG", "REMOTE_JDK_CONFIGS") load(":check_remotejdk_configs_match.bzl", "validate_configs") sh_test( name = "check_remote_jdk_configs_test", srcs = ["check_remote_jdk_configs.sh"], args = [ ",".join([ config.name, config.urls[0], config.urls[1] if len(config.urls) > 1 else "", config.sha256, config.strip_prefix, ]) for configs in REMOTE_JDK_CONFIGS.values() for config in configs ], ) sh_test( name = "check_remote_java_tools_configs_test", srcs = ["check_remote_java_tools_configs.sh"], args = [ ",".join([ name, config["mirror_url"], config["github_url"], config["sha"], ]) for name, config in JAVA_TOOLS_CONFIG["artifacts"].items() ], ) validate_configs() rules_java-7.6.5/test/check_remote_java_tools_configs.sh000077500000000000000000000024121463457531700236010ustar00rootroot00000000000000#!/usr/bin/env bash # Copyright 2024 The Bazel Authors. All rights reserved. # # 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. echo "Checking hashes for $# configs" function download_and_check_hash() { name=$1 url=$2 hash=$3 TMP_FILE=$(mktemp -q /tmp/remotejavatools.XXXXXX) echo "fetching $name from $url to ${TMP_FILE}" curl --silent -o ${TMP_FILE} -L "$url" actual_hash=`sha256sum ${TMP_FILE} | cut -d' ' -f1` if [ "${hash}" != "${actual_hash}" ]; then echo "ERROR: wrong hash for ${name}! wanted: ${hash}, got: ${actual_hash}" exit 1 fi } for config in "$@"; do IFS=, read -r name mirror_url gh_url hash <<< "${config}" download_and_check_hash ${name} ${mirror_url} ${hash} download_and_check_hash ${name} ${gh_url} ${hash} donerules_java-7.6.5/test/check_remote_jdk_configs.sh000077500000000000000000000036021463457531700222120ustar00rootroot00000000000000#!/usr/bin/env bash # Copyright 2024 The Bazel Authors. All rights reserved. # # 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. echo "Checking hashes and strip_prefix for $# configs" _MISSING_MIRRORS=() for config in "$@"; do TMP_FILE=$(mktemp -q /tmp/remotejdk.XXXXXX) IFS=, read -r name url mirror_url hash strip_prefix <<< "${config}" echo "fetching $name from $url to ${TMP_FILE}" curl --silent -o ${TMP_FILE} -L "$url" actual_hash=`sha256sum ${TMP_FILE} | cut -d' ' -f1` if [ "${hash}" != "${actual_hash}" ]; then echo "ERROR: wrong hash for ${name}! wanted: ${hash}, got: ${actual_hash}" exit 1 fi if [[ -z "${url##*.tar.gz}" ]]; then root_dir=`tar ztf ${TMP_FILE} --exclude='*/*'` elif [[ -z "${url##*.zip}" ]]; then root_dir=`unzip -Z1 ${TMP_FILE} | head -n1` else echo "ERROR: unexpected archive type for ${name}" exit 1 fi if [ "${root_dir}" != "${strip_prefix}/" ]; then echo "ERROR: bad strip_prefix for ${name}, wanted: ${strip_prefix}/, got: ${root_dir}" exit 1 fi if [[ -n "${mirror_url}" ]]; then echo "checking mirror: ${mirror_url}" curl --silent --fail -I -L ${mirror_url} > /dev/null || { _MISSING_MIRRORS+="${mirror_url}"; } fi done if [[ ${#_MISSING_MIRRORS[@]} -gt 0 ]]; then echo "Missing mirror URLs:" for m in "${_MISSING_MIRRORS[@]}"; do echo " ${m}" done exit 1 firules_java-7.6.5/test/check_remotejdk_configs_match.bzl000066400000000000000000000024721463457531700234050ustar00rootroot00000000000000# Copyright 2024 The Bazel Authors. All rights reserved. # # 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. """Checks for keeping repository_util.bzl and repositories.bzl in sync""" load("//java:repositories.bzl", "REMOTE_JDK_CONFIGS") load("//java/bazel:repositories_util.bzl", "FLAT_CONFIGS") def validate_configs(): """Ensures repository_util.bzl and repositories.bzl are in sync""" for expected in FLAT_CONFIGS: actual = [cfg for cfg in REMOTE_JDK_CONFIGS[expected.version] if cfg.name == expected.name] if len(actual) != 1: fail("Expected to find exactly one configuration for:", expected.name, "found: ", actual) actual = actual[0] if expected.urls != actual.urls or expected.strip_prefix != actual.strip_prefix: fail("config mismatch! wanted:", expected, "got:", actual) rules_java-7.6.5/test/repo/000077500000000000000000000000001463457531700156275ustar00rootroot00000000000000rules_java-7.6.5/test/repo/BUILD.bazel000066400000000000000000000004201463457531700175010ustar00rootroot00000000000000load("@rules_java//java:java_binary.bzl", "java_binary") load("@rules_java//java:java_library.bzl", "java_library") java_library( name = "lib", srcs = glob(["src/*.java"]), ) java_binary( name = "bin", main_class = "Main", runtime_deps = [":lib"], ) rules_java-7.6.5/test/repo/MODULE.bazel000066400000000000000000000002461463457531700176350ustar00rootroot00000000000000module(name = "fake_repo_for_testing") bazel_dep(name = "rules_java", version = "7.5.0") local_path_override( module_name = "rules_java", path = "../../", ) rules_java-7.6.5/test/repo/WORKSPACE.bzlmod000066400000000000000000000002231463457531700203730ustar00rootroot00000000000000load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains") rules_java_dependencies() rules_java_toolchains() rules_java-7.6.5/test/repo/src/000077500000000000000000000000001463457531700164165ustar00rootroot00000000000000rules_java-7.6.5/test/repo/src/Main.java000066400000000000000000000000251463457531700201420ustar00rootroot00000000000000public class Main {} rules_java-7.6.5/toolchains/000077500000000000000000000000001463457531700160465ustar00rootroot00000000000000rules_java-7.6.5/toolchains/BUILD000066400000000000000000000261761463457531700166440ustar00rootroot00000000000000load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@rules_cc//cc:defs.bzl", "cc_library") load( ":default_java_toolchain.bzl", "DEFAULT_TOOLCHAIN_CONFIGURATION", "PREBUILT_TOOLCHAIN_CONFIGURATION", "bootclasspath", "default_java_toolchain", "java_runtime_files", ) load( ":java_toolchain_alias.bzl", "java_host_runtime_alias", "java_runtime_alias", "java_runtime_version_alias", "java_toolchain_alias", ) package(default_visibility = ["//visibility:public"]) licenses(["notice"]) filegroup( name = "srcs", srcs = glob(["**"]), ) filegroup( name = "bzl_srcs", srcs = glob(["*.bzl"]), ) # A single binary distribution of a JDK (e.g., OpenJDK 17 for Windows arm64) provides three # different types of toolchains from the perspective of Bazel: # The compilation toolchain, which provides the Java runtime used to execute the Java compiler, as # well as various helper tools and settings. # # Toolchains of this type typically have constraints on the execution platform so that their Java # runtime can run the compiler, but not on the target platform as Java compilation outputs are # platform independent. # # Obtain the associated JavaToolchainInfo via: # ctx.toolchains["@bazel_tools//tools/jdk:toolchain_type"].java # TODO: migrate away from using @bazel_tools//tools/jdk:toolchain_type ? # toolchain_type(name = "toolchain_type") # The Java runtime that executable Java compilation outputs (e.g., java_binary with # create_executable = True) will run on. # # Toolchains of this type typically have constraints on the target platform so that the runtime's # native 'java' binary can be run there, but not on the execution platform as building an executable # Java target only requires copying or symlinking the runtime, which can be done on any platform. # # Obtain the associated JavaRuntimeInfo via: # ctx.toolchains["@bazel_tools//tools/jdk:runtime_toolchain_type"].java_runtime # TODO: migrate away from using @bazel_tools//tools/jdk:runtime_toolchain_type ? # toolchain_type(name = "runtime_toolchain_type") # The Java runtime to extract the bootclasspath from that is then used to compile Java sources. # # As the bootclasspath is platform independent, toolchains of this type may have no constraints. # Purely as an optimization to prevent unnecessary fetches of remote runtimes for other # architectures, toolchains of this type may have constraints on the execution platform that match # those on the corresponding compilation toolchain. # # Toolchains of this type are only consumed internally by the bootclasspath rule and should not be # accessed from Starlark. # TODO: migrate away from using @bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type ? # toolchain_type(name = "bootstrap_runtime_toolchain_type") # Points to toolchain[":runtime_toolchain_type"] (was :legacy_current_java_runtime) java_runtime_alias(name = "current_java_runtime") # Host configuration of ":current_java_runtime" java_host_runtime_alias(name = "current_host_java_runtime") # Points to toolchain[":toolchain_type"] (was :legacy_current_java_toolchain) java_toolchain_alias(name = "current_java_toolchain") # These individual jni_* targets are exposed for legacy reasons. # Most users should depend on :jni. java_runtime_files( name = "jni_header", srcs = ["include/jni.h"], ) java_runtime_files( name = "jni_md_header-darwin", srcs = ["include/darwin/jni_md.h"], ) java_runtime_files( name = "jni_md_header-linux", srcs = ["include/linux/jni_md.h"], ) java_runtime_files( name = "jni_md_header-windows", srcs = ["include/win32/jni_md.h"], ) java_runtime_files( name = "jni_md_header-freebsd", srcs = ["include/freebsd/jni_md.h"], ) java_runtime_files( name = "jni_md_header-openbsd", srcs = ["include/openbsd/jni_md.h"], ) # The Java native interface. Depend on this package if you #include . # # See test_jni in third_party/bazel/src/test/shell/bazel/bazel_java_test.sh for # an example of using Bazel to build a Java program that calls a C function. # # TODO(ilist): use //src:condition:linux when released in Bazel cc_library( name = "jni", hdrs = [":jni_header"] + select({ "@bazel_tools//src/conditions:darwin": [":jni_md_header-darwin"], "@bazel_tools//src/conditions:freebsd": [":jni_md_header-freebsd"], "@bazel_tools//src/conditions:linux_aarch64": [":jni_md_header-linux"], "@bazel_tools//src/conditions:linux_mips64": [":jni_md_header-linux"], "@bazel_tools//src/conditions:linux_ppc64le": [":jni_md_header-linux"], "@bazel_tools//src/conditions:linux_riscv64": [":jni_md_header-linux"], "@bazel_tools//src/conditions:linux_s390x": [":jni_md_header-linux"], "@bazel_tools//src/conditions:linux_x86_64": [":jni_md_header-linux"], "@bazel_tools//src/conditions:openbsd": [":jni_md_header-openbsd"], "@bazel_tools//src/conditions:windows": [":jni_md_header-windows"], "//conditions:default": [], }), includes = ["include"] + select({ "@bazel_tools//src/conditions:darwin": ["include/darwin"], "@bazel_tools//src/conditions:freebsd": ["include/freebsd"], "@bazel_tools//src/conditions:linux_aarch64": ["include/linux"], "@bazel_tools//src/conditions:linux_mips64": [":include/linux"], "@bazel_tools//src/conditions:linux_ppc64le": ["include/linux"], "@bazel_tools//src/conditions:linux_riscv64": [":include/linux"], "@bazel_tools//src/conditions:linux_s390x": ["include/linux"], "@bazel_tools//src/conditions:linux_x86_64": ["include/linux"], "@bazel_tools//src/conditions:openbsd": ["include/openbsd"], "@bazel_tools//src/conditions:windows": ["include/win32"], "//conditions:default": [], }), tags = ["nobuilder"], ) [ ( alias( name = "ijar_prebuilt_binary_%s" % OS, actual = "@remote_java_tools_%s//:ijar_prebuilt_binary" % OS, visibility = ["//visibility:private"], ), alias( name = "prebuilt_singlejar_%s" % OS, actual = "@remote_java_tools_%s//:prebuilt_singlejar" % OS, visibility = ["//visibility:private"], ), alias( name = "turbine_direct_graal_%s" % OS, actual = "@remote_java_tools_%s//:turbine_direct_graal" % OS, ), ) for OS in [ "linux", "darwin_x86_64", "darwin_arm64", "windows", ] ] alias( name = "ijar", actual = ":ijar_prebuilt_binary_or_cc_binary", ) alias( name = "ijar_prebuilt_binary_or_cc_binary", actual = select({ "@bazel_tools//src/conditions:darwin_arm64": ":ijar_prebuilt_binary_darwin_arm64", "@bazel_tools//src/conditions:darwin_x86_64": ":ijar_prebuilt_binary_darwin_x86_64", "@bazel_tools//src/conditions:linux_x86_64": ":ijar_prebuilt_binary_linux", "@bazel_tools//src/conditions:windows": ":ijar_prebuilt_binary_windows", "//conditions:default": "@remote_java_tools//:ijar_cc_binary", }), ) alias( name = "ijar_prebuilt_binary", actual = select({ "@bazel_tools//src/conditions:darwin_arm64": ":ijar_prebuilt_binary_darwin_arm64", "@bazel_tools//src/conditions:darwin_x86_64": ":ijar_prebuilt_binary_darwin_x86_64", "@bazel_tools//src/conditions:linux_x86_64": ":ijar_prebuilt_binary_linux", "@bazel_tools//src/conditions:windows": ":ijar_prebuilt_binary_windows", }), ) alias( name = "singlejar", actual = ":singlejar_prebuilt_or_cc_binary", ) alias( name = "singlejar_prebuilt_or_cc_binary", actual = select({ "@bazel_tools//src/conditions:darwin_arm64": ":prebuilt_singlejar_darwin_arm64", "@bazel_tools//src/conditions:darwin_x86_64": ":prebuilt_singlejar_darwin_x86_64", "@bazel_tools//src/conditions:linux_x86_64": ":prebuilt_singlejar_linux", "@bazel_tools//src/conditions:windows": ":prebuilt_singlejar_windows", "//conditions:default": "@remote_java_tools//:singlejar_cc_bin", }), ) alias( name = "prebuilt_singlejar", actual = select({ "@bazel_tools//src/conditions:darwin_arm64": ":prebuilt_singlejar_darwin_arm64", "@bazel_tools//src/conditions:darwin_x86_64": ":prebuilt_singlejar_darwin_x86_64", "@bazel_tools//src/conditions:linux_x86_64": ":prebuilt_singlejar_linux", "@bazel_tools//src/conditions:windows": ":prebuilt_singlejar_windows", }), ) alias( name = "turbine_direct", actual = ":turbine_direct_graal_or_java", ) alias( name = "turbine_direct_graal_or_java", actual = select({ "@bazel_tools//src/conditions:darwin_arm64": ":turbine_direct_graal_darwin_arm64", "@bazel_tools//src/conditions:darwin_x86_64": ":turbine_direct_graal_darwin_x86_64", "@bazel_tools//src/conditions:linux_x86_64": ":turbine_direct_graal_linux", "@bazel_tools//src/conditions:windows": ":turbine_direct_graal_windows", "//conditions:default": "@remote_java_tools//:TurbineDirect", }), ) alias( name = "turbine_direct_graal", actual = select({ "@bazel_tools//src/conditions:darwin_arm64": ":turbine_direct_graal_darwin_arm64", "@bazel_tools//src/conditions:darwin_x86_64": ":turbine_direct_graal_darwin_x86_64", "@bazel_tools//src/conditions:linux_x86_64": ":turbine_direct_graal_linux", "@bazel_tools//src/conditions:windows": ":turbine_direct_graal_windows", }), ) bootclasspath( name = "platformclasspath", src = "DumpPlatformClassPath.java", java_runtime_alias = ":current_java_runtime", ) default_java_toolchain( name = "toolchain", configuration = DEFAULT_TOOLCHAIN_CONFIGURATION, toolchain_definition = False, ) alias( name = "remote_toolchain", actual = ":toolchain", ) RELEASES = (8, 9, 10, 11, 17, 21) [ default_java_toolchain( name = ("toolchain_java%d" if release <= 11 else "toolchain_jdk_%d") % release, configuration = DEFAULT_TOOLCHAIN_CONFIGURATION, source_version = "%s" % release, target_version = "%s" % release, ) for release in RELEASES ] default_java_toolchain( name = "prebuilt_toolchain", configuration = PREBUILT_TOOLCHAIN_CONFIGURATION, toolchain_definition = False, ) # A JDK 11 for use as a --host_javabase. java_runtime_version_alias( name = "remote_jdk11", runtime_version = "remotejdk_11", visibility = ["//visibility:public"], ) java_runtime_version_alias( name = "remotejdk_15", runtime_version = "remotejdk_15", visibility = ["//visibility:public"], ) java_runtime_version_alias( name = "remotejdk_16", runtime_version = "remotejdk_16", visibility = ["//visibility:public"], ) java_runtime_version_alias( name = "remotejdk_17", runtime_version = "remotejdk_17", visibility = ["//visibility:public"], ) java_runtime_version_alias( name = "remotejdk_21", runtime_version = "remotejdk_21", visibility = ["//visibility:public"], ) java_runtime_version_alias( name = "jdk_8", runtime_version = "8", visibility = ["//visibility:public"], ) bzl_library( name = "toolchain_utils", srcs = ["toolchain_utils.bzl"], visibility = ["//visibility:public"], deps = ["//java/common"], ) rules_java-7.6.5/toolchains/DumpPlatformClassPath.java000066400000000000000000000224401463457531700231300ustar00rootroot00000000000000// Copyright 2017 The Bazel Authors. All rights reserved. // // 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. import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.UncheckedIOException; import java.lang.reflect.Method; import java.net.URI; import java.nio.file.DirectoryStream; import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.GregorianCalendar; import java.util.List; import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.jar.JarOutputStream; import java.util.zip.CRC32; import java.util.zip.ZipEntry; /** * Output a jar file containing all classes on the platform classpath of the given JDK release. * *

usage: {@code DumpPlatformClassPath } */ public class DumpPlatformClassPath { public static void main(String[] args) throws Exception { if (args.length != 2) { System.err.println("usage: DumpPlatformClassPath "); System.exit(1); } Path output = Paths.get(args[0]); Path targetJavabase = Paths.get(args[1]); int hostMajorVersion = hostMajorVersion(); boolean ok; if (hostMajorVersion == 8) { ok = dumpJDK8BootClassPath(output, targetJavabase); } else { ok = dumpJDK9AndNewerBootClassPath(hostMajorVersion, output, targetJavabase); } System.exit(ok ? 0 : 1); } // JDK 8 bootclasspath handling. // * JDK 8 represents a bootclasspath as a search path of jars (rt.jar, etc.). // * It does not support --release or --system. static boolean dumpJDK8BootClassPath(Path output, Path targetJavabase) throws IOException { List bootClassPathJars = getBootClassPathJars(targetJavabase); writeClassPathJars(output, bootClassPathJars); return true; } // JDK > 8 --host_javabase bootclasspath handling. // (The default --host_javabase is currently JDK 9.) static boolean dumpJDK9AndNewerBootClassPath( int hostMajorVersion, Path output, Path targetJavabase) throws IOException { // JDK 9 and newer support cross-compiling to older platform versions using the --system // and --release flags. // * --system takes the path to a JDK root for JDK 9 and up, and causes the compilation // to target the APIs from that JDK. // * --release takes a language level (e.g. '9') and uses the API information baked in to // the host JDK (in lib/ct.sym). // Since --system only supports JDK >= 9, first check if the target JDK defines a JDK 8 // bootclasspath. List bootClassPathJars = getBootClassPathJars(targetJavabase); if (!bootClassPathJars.isEmpty()) { writeClassPathJars(output, bootClassPathJars); return true; } // Read the bootclasspath data using the JRT filesystem Map entries = new TreeMap<>(); Map env = new TreeMap<>(); env.put("java.home", String.valueOf(targetJavabase)); try (FileSystem fileSystem = FileSystems.newFileSystem(URI.create("jrt:/"), env)) { Path modules = fileSystem.getPath("/modules"); try (DirectoryStream ms = Files.newDirectoryStream(modules)) { for (Path m : ms) { Files.walkFileTree( m, new SimpleFileVisitor() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (file.getFileName().toString().endsWith(".class")) { entries.put(m.relativize(file).toString(), Files.readAllBytes(file)); } return super.visitFile(file, attrs); } }); } } writeEntries(output, entries); } return true; } /** Writes the given entry names and data to a jar archive at the given path. */ private static void writeEntries(Path output, Map entries) throws IOException { if (!entries.containsKey("java/lang/Object.class")) { throw new AssertionError( "\nCould not find java.lang.Object on bootclasspath; something has gone terribly wrong.\n" + "Please file a bug: https://github.com/bazelbuild/bazel/issues"); } try (OutputStream os = Files.newOutputStream(output); BufferedOutputStream bos = new BufferedOutputStream(os, 65536); JarOutputStream jos = new JarOutputStream(bos)) { entries.entrySet().stream() .forEachOrdered( entry -> { try { addEntry(jos, entry.getKey(), entry.getValue()); } catch (IOException e) { throw new UncheckedIOException(e); } }); } } /** Collects the entries of the given jar files into a map from jar entry names to their data. */ private static void writeClassPathJars(Path output, Collection paths) throws IOException { List jars = new ArrayList<>(); for (Path path : paths) { jars.add(new JarFile(path.toFile())); } SortedMap entries = new TreeMap<>(); for (JarFile jar : jars) { jar.stream() .filter(p -> p.getName().endsWith(".class")) .forEachOrdered( entry -> { try { entries.put(entry.getName(), toByteArray(jar.getInputStream(entry))); } catch (IOException e) { throw new UncheckedIOException(e); } }); } writeEntries(output, entries); for (JarFile jar : jars) { jar.close(); } } /** Returns paths to the entries of a JDK 8-style bootclasspath. */ private static List getBootClassPathJars(Path javaHome) throws IOException { List jars = new ArrayList<>(); Path extDir = javaHome.resolve("jre/lib/ext"); if (Files.exists(extDir)) { for (Path extJar : Files.newDirectoryStream(extDir, "*.jar")) { jars.add(extJar); } } for (String jar : Arrays.asList("rt.jar", "resources.jar", "jsse.jar", "jce.jar", "charsets.jar")) { Path path = javaHome.resolve("jre/lib").resolve(jar); if (Files.exists(path)) { jars.add(path); } } Path toolsJar = javaHome.resolve("lib/tools.jar"); if (Files.exists(toolsJar)) { jars.add(toolsJar); } return jars; } // Use a fixed timestamp for deterministic jar output. private static final long FIXED_TIMESTAMP = new GregorianCalendar(2010, 0, 1, 0, 0, 0).getTimeInMillis(); /** * Add a jar entry to the given {@link JarOutputStream}, normalizing the entry timestamps to * ensure deterministic build output. */ private static void addEntry(JarOutputStream jos, String name, byte[] bytes) throws IOException { JarEntry je = new JarEntry(name); je.setTime(FIXED_TIMESTAMP); je.setMethod(ZipEntry.STORED); // When targeting JDK >= 10, patch the major version so it will be accepted by javac 9 // TODO(cushon): remove this after updating javac if (bytes[7] > 53) { bytes[7] = 53; } je.setSize(bytes.length); CRC32 crc = new CRC32(); crc.update(bytes); je.setCrc(crc.getValue()); jos.putNextEntry(je); jos.write(bytes); } private static byte[] toByteArray(InputStream is) throws IOException { byte[] buffer = new byte[8192]; ByteArrayOutputStream boas = new ByteArrayOutputStream(); while (true) { int r = is.read(buffer); if (r == -1) { break; } boas.write(buffer, 0, r); } return boas.toByteArray(); } /** * Returns the major version of the host Java runtime (e.g. '8' for JDK 8), using {@link * Runtime#version} if it is available, and otherwise falling back to the {@code * java.class.version} system. property. */ static int hostMajorVersion() { try { Method versionMethod = Runtime.class.getMethod("version"); Object version = versionMethod.invoke(null); return (int) version.getClass().getMethod("major").invoke(version); } catch (ReflectiveOperationException e) { // Runtime.version() isn't available on JDK 8; continue below } int version = (int) Double.parseDouble(System.getProperty("java.class.version")); if (49 <= version && version <= 52) { return version - (49 - 5); } throw new IllegalStateException( "Unknown Java version: " + System.getProperty("java.specification.version")); } }rules_java-7.6.5/toolchains/default_java_toolchain.bzl000066400000000000000000000270611463457531700232520ustar00rootroot00000000000000# Copyright 2022 The Bazel Authors. All rights reserved. # # 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. """Rules for defining default_java_toolchain""" load("//java:defs.bzl", "java_toolchain") load("//java/common:java_common.bzl", "java_common") # JVM options, without patching java.compiler and jdk.compiler modules. BASE_JDK9_JVM_OPTS = [ # Allow JavaBuilder to access internal javac APIs. "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", "--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", "--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", "--add-exports=jdk.compiler/com.sun.tools.javac.resources=ALL-UNNAMED", "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", "--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", "--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", # quiet warnings from com.google.protobuf.UnsafeUtil, # see: https://github.com/google/protobuf/issues/3781 # and: https://github.com/bazelbuild/bazel/issues/5599 "--add-opens=java.base/java.nio=ALL-UNNAMED", "--add-opens=java.base/java.lang=ALL-UNNAMED", # TODO(b/64485048): Disable this option in persistent worker mode only. # Disable symlinks resolution cache since symlinks in exec root change "-Dsun.io.useCanonCaches=false", # Compact strings make JavaBuilder slightly slower. "-XX:-CompactStrings", # Since https://bugs.openjdk.org/browse/JDK-8153723, JVM logging goes to stdout. This # makes it go to stderr instead. "-Xlog:disable", "-Xlog:all=warning:stderr:uptime,level,tags", ] JDK9_JVM_OPTS = BASE_JDK9_JVM_OPTS DEFAULT_JAVACOPTS = [ "-XDskipDuplicateBridges=true", "-XDcompilePolicy=simple", "-g", "-parameters", # https://github.com/bazelbuild/bazel/issues/15219 "-Xep:ReturnValueIgnored:OFF", # https://github.com/bazelbuild/bazel/issues/16996 "-Xep:IgnoredPureGetter:OFF", "-Xep:EmptyTopLevelDeclaration:OFF", "-Xep:LenientFormatStringValidation:OFF", "-Xep:ReturnMissingNullable:OFF", "-Xep:UseCorrectAssertInTests:OFF", ] # Default java_toolchain parameters _BASE_TOOLCHAIN_CONFIGURATION = dict( forcibly_disable_header_compilation = False, genclass = [Label("@remote_java_tools//:GenClass")], header_compiler = [Label("@remote_java_tools//:TurbineDirect")], header_compiler_direct = [Label("//toolchains:turbine_direct")], ijar = [Label("//toolchains:ijar")], javabuilder = [Label("@remote_java_tools//:JavaBuilder")], javac_supports_workers = True, jacocorunner = Label("@remote_java_tools//:jacoco_coverage_runner_filegroup"), jvm_opts = BASE_JDK9_JVM_OPTS, turbine_jvm_opts = [ # Turbine is not a worker and parallel GC is faster for short-lived programs. "-XX:+UseParallelGC", ], misc = DEFAULT_JAVACOPTS, singlejar = [Label("//toolchains:singlejar")], # Code to enumerate target JVM boot classpath uses host JVM. Because # java_runtime-s are involved, its implementation is in @bazel_tools. bootclasspath = [Label("//toolchains:platformclasspath")], source_version = "8", target_version = "8", reduced_classpath_incompatible_processors = [ "dagger.hilt.processor.internal.root.RootProcessor", # see b/21307381 ], java_runtime = Label("//toolchains:remotejdk_21"), ) DEFAULT_TOOLCHAIN_CONFIGURATION = _BASE_TOOLCHAIN_CONFIGURATION # The 'vanilla' toolchain is an unsupported alternative to the default. # # It does not provide any of the following features: # * Error Prone # * Strict Java Deps # * Reduced Classpath Optimization # # It uses the version of internal javac from the `--host_javabase` JDK instead # of providing a javac. Internal javac may not be source- or bug-compatible with # the javac that is provided with other toolchains. # # However it does allow using a wider range of `--host_javabase`s, including # versions newer than the current JDK. VANILLA_TOOLCHAIN_CONFIGURATION = dict( javabuilder = [Label("@remote_java_tools//:VanillaJavaBuilder")], jvm_opts = [], java_runtime = None, ) # The new toolchain is using all the pre-built tools, including # singlejar and ijar, even on remote execution. This toolchain # should be used only when host and execution platform are the # same, otherwise the binaries will not work on the execution # platform. PREBUILT_TOOLCHAIN_CONFIGURATION = dict( ijar = [Label("//toolchains:ijar_prebuilt_binary")], singlejar = [Label("//toolchains:prebuilt_singlejar")], ) # The new toolchain is using all the tools from sources. NONPREBUILT_TOOLCHAIN_CONFIGURATION = dict( ijar = [Label("@remote_java_tools//:ijar_cc_binary")], singlejar = [Label("@remote_java_tools//:singlejar_cc_bin")], header_compiler_direct = [Label("@remote_java_tools//:TurbineDirect")], ) # If this is changed, the docs for "{,tool_}java_language_version" also # need to be updated in the Bazel user manual _DEFAULT_SOURCE_VERSION = "8" def default_java_toolchain(name, configuration = DEFAULT_TOOLCHAIN_CONFIGURATION, toolchain_definition = True, exec_compatible_with = [], target_compatible_with = [], **kwargs): """Defines a remote java_toolchain with appropriate defaults for Bazel. Args: name: The name of the toolchain configuration: Toolchain configuration toolchain_definition: Whether to define toolchain target and its config setting exec_compatible_with: A list of constraint values that must be satisifed for the exec platform. target_compatible_with: A list of constraint values that must be satisifed for the target platform. **kwargs: More arguments for the java_toolchain target """ toolchain_args = dict(_BASE_TOOLCHAIN_CONFIGURATION) toolchain_args.update(configuration) toolchain_args.update(kwargs) java_toolchain( name = name, **toolchain_args ) if toolchain_definition: source_version = toolchain_args["source_version"] if source_version == _DEFAULT_SOURCE_VERSION: native.config_setting( name = name + "_default_version_setting", values = {"java_language_version": ""}, visibility = ["//visibility:private"], ) native.toolchain( name = name + "_default_definition", toolchain_type = Label("@bazel_tools//tools/jdk:toolchain_type"), target_settings = [name + "_default_version_setting"], toolchain = name, exec_compatible_with = exec_compatible_with, target_compatible_with = target_compatible_with, ) native.config_setting( name = name + "_version_setting", values = {"java_language_version": source_version}, visibility = ["//visibility:private"], ) native.toolchain( name = name + "_definition", toolchain_type = Label("@bazel_tools//tools/jdk:toolchain_type"), target_settings = [name + "_version_setting"], toolchain = name, exec_compatible_with = exec_compatible_with, target_compatible_with = target_compatible_with, ) def java_runtime_files(name, srcs): """Copies the given sources out of the current Java runtime.""" native.filegroup( name = name, srcs = srcs, tags = ["manual"], ) for src in srcs: native.genrule( name = "gen_%s" % src, srcs = [Label("//toolchains:current_java_runtime")], toolchains = [Label("//toolchains:current_java_runtime")], cmd = "cp $(JAVABASE)/%s $@" % src, outs = [src], tags = ["manual"], ) _JAVA_BOOTSTRAP_RUNTIME_TOOLCHAIN_TYPE = Label("@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type") # Opt the Java bootstrap actions into path mapping: # https://github.com/bazelbuild/bazel/commit/a239ea84832f18ee8706682145e9595e71b39680 _SUPPORTS_PATH_MAPPING = {"supports-path-mapping": "1"} def _bootclasspath_impl(ctx): exec_javabase = ctx.attr.java_runtime_alias[java_common.JavaRuntimeInfo] class_dir = ctx.actions.declare_directory("%s_classes" % ctx.label.name) args = ctx.actions.args() args.add("-source") args.add("8") args.add("-target") args.add("8") args.add("-Xlint:-options") args.add("-J-XX:-UsePerfData") args.add("-d") args.add_all([class_dir], expand_directories = False) args.add(ctx.file.src) ctx.actions.run( executable = "%s/bin/javac" % exec_javabase.java_home, mnemonic = "JavaToolchainCompileClasses", inputs = [ctx.file.src] + ctx.files.java_runtime_alias, outputs = [class_dir], arguments = [args], execution_requirements = _SUPPORTS_PATH_MAPPING, ) bootclasspath = ctx.outputs.output_jar args = ctx.actions.args() args.add("-XX:+IgnoreUnrecognizedVMOptions") args.add("-XX:-UsePerfData") args.add("--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED") args.add("--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED") args.add("--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED") args.add_all("-cp", [class_dir], expand_directories = False) args.add("DumpPlatformClassPath") args.add(bootclasspath) any_javabase = ctx.toolchains[_JAVA_BOOTSTRAP_RUNTIME_TOOLCHAIN_TYPE].java_runtime args.add(any_javabase.java_home) system_files = ("release", "modules", "jrt-fs.jar") system = [f for f in any_javabase.files.to_list() if f.basename in system_files] if len(system) != len(system_files): system = None inputs = depset([class_dir] + ctx.files.java_runtime_alias, transitive = [any_javabase.files]) ctx.actions.run( executable = str(exec_javabase.java_executable_exec_path), mnemonic = "JavaToolchainCompileBootClasspath", inputs = inputs, outputs = [bootclasspath], arguments = [args], execution_requirements = _SUPPORTS_PATH_MAPPING, ) return [ DefaultInfo(files = depset([bootclasspath])), java_common.BootClassPathInfo( bootclasspath = [bootclasspath], system = system, ), OutputGroupInfo(jar = [bootclasspath]), ] _bootclasspath = rule( implementation = _bootclasspath_impl, attrs = { "java_runtime_alias": attr.label( cfg = "exec", providers = [java_common.JavaRuntimeInfo], ), "output_jar": attr.output(mandatory = True), "src": attr.label( cfg = "exec", allow_single_file = True, ), }, toolchains = [_JAVA_BOOTSTRAP_RUNTIME_TOOLCHAIN_TYPE], ) def bootclasspath(name, **kwargs): _bootclasspath( name = name, output_jar = name + ".jar", **kwargs ) rules_java-7.6.5/toolchains/fail_rule.bzl000066400000000000000000000021441463457531700205220ustar00rootroot00000000000000# Copyright 2020 The Bazel Authors. All rights reserved. # # 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. """A rule than fails during analysis.""" def _fail_rule_impl(ctx): if ctx.attr.header: fail("%s %s" % (ctx.attr.header, ctx.attr.message)) else: fail(ctx.attr.message) fail_rule = rule( doc = "A rule that fails during analysis.", implementation = _fail_rule_impl, attrs = { "header": attr.string( doc = "Header of the message.", ), "message": attr.string( mandatory = True, doc = "Message to display.", ), }, ) rules_java-7.6.5/toolchains/java_toolchain_alias.bzl000066400000000000000000000070661463457531700227220ustar00rootroot00000000000000# Copyright 2019 The Bazel Authors. All rights reserved. # # 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. """Experimental re-implementations of Java toolchain aliases using toolchain resolution.""" load("//java/common:java_common.bzl", "java_common") def _java_runtime_alias(ctx): """An experimental implementation of java_runtime_alias using toolchain resolution.""" toolchain_info = ctx.toolchains["@bazel_tools//tools/jdk:runtime_toolchain_type"] toolchain = toolchain_info.java_runtime return [ toolchain_info, toolchain, platform_common.TemplateVariableInfo({ "JAVA": str(toolchain.java_executable_exec_path), "JAVABASE": str(toolchain.java_home), }), # See b/65239471 for related discussion of handling toolchain runfiles/data. DefaultInfo( runfiles = ctx.runfiles(transitive_files = toolchain.files), files = toolchain.files, ), ] java_runtime_alias = rule( implementation = _java_runtime_alias, toolchains = ["@bazel_tools//tools/jdk:runtime_toolchain_type"], ) def _java_host_runtime_alias(ctx): """An experimental implementation of java_host_runtime_alias using toolchain resolution.""" runtime = ctx.attr._runtime java_runtime = runtime[java_common.JavaRuntimeInfo] template_variable_info = runtime[platform_common.TemplateVariableInfo] toolchain_info = platform_common.ToolchainInfo(java_runtime = java_runtime) return [ java_runtime, template_variable_info, toolchain_info, runtime[DefaultInfo], ] java_host_runtime_alias = rule( implementation = _java_host_runtime_alias, attrs = { "_runtime": attr.label( default = Label("//toolchains:current_java_runtime"), providers = [ java_common.JavaRuntimeInfo, platform_common.TemplateVariableInfo, ], cfg = "exec", ), }, provides = [ java_common.JavaRuntimeInfo, platform_common.TemplateVariableInfo, platform_common.ToolchainInfo, ], ) def _java_runtime_transition_impl(_settings, attr): return {"//command_line_option:java_runtime_version": attr.runtime_version} _java_runtime_transition = transition( implementation = _java_runtime_transition_impl, inputs = [], outputs = ["//command_line_option:java_runtime_version"], ) java_runtime_version_alias = rule( implementation = _java_runtime_alias, toolchains = ["@bazel_tools//tools/jdk:runtime_toolchain_type"], attrs = { "runtime_version": attr.string(mandatory = True), }, cfg = _java_runtime_transition, ) def _java_toolchain_alias(ctx): """An experimental implementation of java_toolchain_alias using toolchain resolution.""" toolchain_info = ctx.toolchains["@bazel_tools//tools/jdk:toolchain_type"] toolchain = toolchain_info.java return [ toolchain_info, toolchain, ] java_toolchain_alias = rule( implementation = _java_toolchain_alias, toolchains = ["@bazel_tools//tools/jdk:toolchain_type"], ) rules_java-7.6.5/toolchains/jdk_build_file.bzl000066400000000000000000000057441463457531700215170ustar00rootroot00000000000000# Copyright 2023 The Bazel Authors. All rights reserved. # # 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. """A templated BUILD file for Java repositories.""" JDK_BUILD_TEMPLATE = """load("@rules_java//java:defs.bzl", "java_runtime") package(default_visibility = ["//visibility:public"]) exports_files(["WORKSPACE", "BUILD.bazel"]) filegroup( name = "jre", srcs = glob( [ "jre/bin/**", "jre/lib/**", ], allow_empty = True, # In some configurations, Java browser plugin is considered harmful and # common antivirus software blocks access to npjp2.dll interfering with Bazel, # so do not include it in JRE on Windows. exclude = ["jre/bin/plugin2/**"], ), ) filegroup( name = "jdk-bin", srcs = glob( ["bin/**"], # The JDK on Windows sometimes contains a directory called # "%systemroot%", which is not a valid label. exclude = ["**/*%*/**"], ), ) # This folder holds security policies. filegroup( name = "jdk-conf", srcs = glob( ["conf/**"], allow_empty = True, ), ) filegroup( name = "jdk-include", srcs = glob( ["include/**"], allow_empty = True, ), ) filegroup( name = "jdk-lib", srcs = glob( ["lib/**", "release"], allow_empty = True, exclude = [ "lib/missioncontrol/**", "lib/visualvm/**", ], ), ) java_runtime( name = "jdk", srcs = [ ":jdk-bin", ":jdk-conf", ":jdk-include", ":jdk-lib", ":jre", ], # Provide the 'java` binary explicitly so that the correct path is used by # Bazel even when the host platform differs from the execution platform. # Exactly one of the two globs will be empty depending on the host platform. # When --incompatible_disallow_empty_glob is enabled, each individual empty # glob will fail without allow_empty = True, even if the overall result is # non-empty. java = glob(["bin/java.exe", "bin/java"], allow_empty = True)[0], version = {RUNTIME_VERSION}, ) filegroup( name = "jdk-jmods", srcs = glob( ["jmods/**"], allow_empty = True, ), ) java_runtime( name = "jdk-with-jmods", srcs = [ ":jdk-bin", ":jdk-conf", ":jdk-include", ":jdk-lib", ":jdk-jmods", ":jre", ], java = glob(["bin/java.exe", "bin/java"], allow_empty = True)[0], version = {RUNTIME_VERSION}, ) """ rules_java-7.6.5/toolchains/local_java_repository.bzl000066400000000000000000000323161463457531700231560ustar00rootroot00000000000000# Copyright 2021 The Bazel Authors. All rights reserved. # # 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. """Rules for importing a local JDK.""" load("//java:defs.bzl", "java_runtime") load(":default_java_toolchain.bzl", "default_java_toolchain") def _detect_java_version(repository_ctx, java_bin): properties_out = repository_ctx.execute([java_bin, "-XshowSettings:properties"]).stderr # This returns an indented list of properties separated with newlines: # " java.vendor.url.bug = ... \n" # " java.version = 11.0.8\n" # " java.version.date = 2020-11-05\" strip_properties = [property.strip() for property in properties_out.splitlines()] version_property = [property for property in strip_properties if property.startswith("java.version = ")] if len(version_property) != 1: return None version_value = version_property[0][len("java.version = "):] parts = version_value.split(".") major = parts[0] if len(parts) == 1: return major elif major == "1": # handles versions below 1.8 minor = parts[1] return minor return major def local_java_runtime(name, java_home, version, runtime_name = None, visibility = ["//visibility:public"], exec_compatible_with = [], target_compatible_with = []): """Defines a java_runtime target together with Java runtime and compile toolchain definitions. Java runtime toolchain is constrained by flag --java_runtime_version having value set to either name or version argument. Java compile toolchains are created for --java_language_version flags values between 8 and version (inclusive). Java compile toolchains use the same (local) JDK for compilation. This requires a different configuration for JDK8 than the newer versions. Args: name: name of the target. java_home: Path to the JDK. version: Version of the JDK. runtime_name: name of java_runtime target if it already exists. visibility: Visibility that will be applied to the java runtime target exec_compatible_with: A list of constraint values that must be satisfied by the exec platform for the Java compile toolchain to be selected. They must be satisfied by the target platform for the Java runtime toolchain to be selected. target_compatible_with: A list of constraint values that must be satisfied by the target platform for the Java compile toolchain to be selected. """ if runtime_name == None: runtime_name = name java_runtime( name = runtime_name, java_home = java_home, visibility = visibility, version = int(version) if version.isdigit() else 0, ) native.config_setting( name = name + "_name_setting", values = {"java_runtime_version": name}, visibility = ["//visibility:private"], ) native.config_setting( name = name + "_version_setting", values = {"java_runtime_version": version}, visibility = ["//visibility:private"], ) native.config_setting( name = name + "_name_version_setting", values = {"java_runtime_version": name + "_" + version}, visibility = ["//visibility:private"], ) native.alias( name = name + "_settings_alias", actual = select({ name + "_name_setting": name + "_name_setting", name + "_version_setting": name + "_version_setting", "//conditions:default": name + "_name_version_setting", }), visibility = ["//visibility:private"], ) native.toolchain( name = "runtime_toolchain_definition", # A JDK can be used as a runtime *for* the platforms it can be used to compile *on*. target_compatible_with = exec_compatible_with, target_settings = [":%s_settings_alias" % name], toolchain_type = Label("@bazel_tools//tools/jdk:runtime_toolchain_type"), toolchain = runtime_name, ) native.toolchain( name = "bootstrap_runtime_toolchain_definition", target_settings = [":%s_settings_alias" % name], toolchain_type = Label("@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type"), toolchain = runtime_name, ) if type(version) == type("") and version.isdigit() and int(version) > 8: for version in range(8, int(version) + 1): default_java_toolchain( name = name + "_toolchain_java" + str(version), source_version = str(version), target_version = str(version), java_runtime = runtime_name, exec_compatible_with = exec_compatible_with, target_compatible_with = target_compatible_with, ) # else version is not recognized and no compilation toolchains are predefined def _is_macos(repository_ctx): return repository_ctx.os.name.lower().find("mac os x") != -1 def _is_windows(repository_ctx): return repository_ctx.os.name.lower().find("windows") != -1 def _with_os_extension(repository_ctx, binary): return binary + (".exe" if _is_windows(repository_ctx) else "") def _determine_java_home(repository_ctx): """Determine the java home path. If the `java_home` attribute is specified, then use the given path, otherwise, try to detect the java home path on the system. Args: repository_ctx: repository context """ java_home = repository_ctx.attr.java_home if java_home: java_home_path = repository_ctx.path(java_home) if not java_home_path.exists: fail('The path indicated by the "java_home" attribute "%s" (absolute: "%s") does not exist.' % (java_home, str(java_home_path))) return java_home_path if "JAVA_HOME" in repository_ctx.os.environ: return repository_ctx.path(repository_ctx.os.environ["JAVA_HOME"]) if _is_macos(repository_ctx): # Replicate GetSystemJavabase() in src/main/cpp/blaze_util_darwin.cc result = repository_ctx.execute(["/usr/libexec/java_home", "-v", "1.11+"]) if result.return_code == 0: return repository_ctx.path(result.stdout.strip()) else: # Calculate java home by locating the javac binary # javac should exists at ${JAVA_HOME}/bin/javac # Replicate GetSystemJavabase() in src/main/cpp/blaze_util_linux.cc # This logic should also work on Windows. javac_path = repository_ctx.which(_with_os_extension(repository_ctx, "javac")) if javac_path: return javac_path.realpath.dirname.dirname return repository_ctx.path("./nosystemjdk") def _local_java_repository_impl(repository_ctx): """Repository rule local_java_repository implementation. Args: repository_ctx: repository context """ java_home = _determine_java_home(repository_ctx) # When Bzlmod is enabled, the Java runtime name should be the last segment of the repository name. local_java_runtime_name = repository_ctx.name.split("~")[-1] repository_ctx.file( "WORKSPACE", "# DO NOT EDIT: automatically generated WORKSPACE file for local_java_repository\n" + "workspace(name = \"{name}\")\n".format(name = local_java_runtime_name), ) java_bin = java_home.get_child("bin").get_child(_with_os_extension(repository_ctx, "java")) if not java_bin.exists: # Java binary does not exist _create_auto_config_error_build_file( repository_ctx, local_java_runtime_name = local_java_runtime_name, java_home = java_home, message = "Cannot find Java binary {java_binary} in {java_home}; " + "either correct your JAVA_HOME, PATH or specify Java from " + "remote repository (e.g. --java_runtime_version=remotejdk_11)", ) return # Detect version version = repository_ctx.attr.version if repository_ctx.attr.version != "" else _detect_java_version(repository_ctx, java_bin) if version == None: # Java version could not be detected _create_auto_config_error_build_file( repository_ctx, local_java_runtime_name = local_java_runtime_name, java_home = java_home, message = "Cannot detect Java version of {java_binary} in {java_home}; " + "make sure it points to a valid Java executable", ) return # Prepare BUILD file using "local_java_runtime" macro if repository_ctx.attr.build_file_content and repository_ctx.attr.build_file: fail("build_file and build_file_content are exclusive") if repository_ctx.attr.build_file_content: build_file = repository_ctx.attr.build_file_content elif repository_ctx.attr.build_file: build_file = repository_ctx.read(repository_ctx.path(repository_ctx.attr.build_file)) else: build_file = "" build_file = build_file.format(RUNTIME_VERSION = version if version.isdigit() else "0") runtime_name = '"jdk"' if build_file else None local_java_runtime_macro = """ local_java_runtime( name = "%s", runtime_name = %s, java_home = "%s", version = "%s", exec_compatible_with = HOST_CONSTRAINTS, ) """ % (local_java_runtime_name, runtime_name, java_home, version) repository_ctx.file( "BUILD.bazel", 'load("@rules_java//toolchains:local_java_repository.bzl", "local_java_runtime")\n' + 'load("@local_config_platform//:constraints.bzl", "HOST_CONSTRAINTS")\n' + build_file + local_java_runtime_macro, ) # Symlink all files for file in repository_ctx.path(java_home).readdir(): repository_ctx.symlink(file, file.basename) # Build file template, when JDK could not be detected _AUTO_CONFIG_ERROR_BUILD_TPL = '''load("@rules_java//toolchains:fail_rule.bzl", "fail_rule") fail_rule( name = "jdk", header = "Auto-Configuration Error:", message = {message}, ) config_setting( name = "localjdk_setting", values = {{"java_runtime_version": "{local_jdk}"}}, visibility = ["//visibility:private"], ) toolchain( name = "runtime_toolchain_definition", target_settings = [":localjdk_setting"], toolchain_type = "@bazel_tools//tools/jdk:runtime_toolchain_type", toolchain = ":jdk", ) toolchain( name = "bootstrap_runtime_toolchain_definition", target_settings = [":localjdk_setting"], toolchain_type = "@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type", toolchain = ":jdk", ) ''' def _create_auto_config_error_build_file(repository_ctx, *, local_java_runtime_name, java_home, message): repository_ctx.file( "BUILD.bazel", _AUTO_CONFIG_ERROR_BUILD_TPL.format( local_jdk = local_java_runtime_name, message = repr(message.format( java_binary = _with_os_extension(repository_ctx, "bin/java"), java_home = java_home, )), ), False, ) _local_java_repository_rule = repository_rule( implementation = _local_java_repository_impl, local = True, configure = True, environ = ["JAVA_HOME"], attrs = { "build_file": attr.label(), "build_file_content": attr.string(), "java_home": attr.string(), "version": attr.string(), }, ) def local_java_repository(name, java_home = "", version = "", build_file = None, build_file_content = None, **kwargs): """Defines runtime and compile toolchains for a local JDK. Register the toolchains defined by this macro as follows (where `` is the value of the `name` parameter): * Runtime toolchains only (recommended) ``` register_toolchains("@//:runtime_toolchain_definition") register_toolchains("@//:bootstrap_runtime_toolchain_definition") ``` * Runtime and compilation toolchains: ``` register_toolchains("@//:all") ``` Toolchain resolution is constrained with --java_runtime_version flag having value of the "name" or "version" parameter. Java compile toolchains are created for --java_language_version flags values between 8 and version (inclusive). Java compile toolchains use the same (local) JDK for compilation. If there is no JDK "virtual" targets are created, which fail only when actually needed. Args: name: A unique name for this rule. java_home: Location of the JDK imported. build_file: optionally BUILD file template build_file_content: optional BUILD file template as a string version: optionally java version **kwargs: additional arguments for repository rule """ _local_java_repository_rule(name = name, java_home = java_home, version = version, build_file = build_file, build_file_content = build_file_content, **kwargs) rules_java-7.6.5/toolchains/remote_java_repository.bzl000066400000000000000000000075211463457531700233570ustar00rootroot00000000000000# Copyright 2020 The Bazel Authors. All rights reserved. # # 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. """Rules for importing JDKs from http archive. Rule remote_java_repository imports a JDK and creates toolchain definitions for it. """ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("//toolchains:jdk_build_file.bzl", "JDK_BUILD_TEMPLATE") def _toolchain_config_impl(ctx): ctx.file("WORKSPACE", "workspace(name = \"{name}\")\n".format(name = ctx.name)) ctx.file("BUILD.bazel", ctx.attr.build_file) _toolchain_config = repository_rule( local = True, implementation = _toolchain_config_impl, attrs = { "build_file": attr.string(), }, ) def remote_java_repository(name, version, target_compatible_with = None, prefix = "remotejdk", **kwargs): """Imports a JDK from a http archive and creates runtime toolchain definitions for it. Register the toolchains defined by this macro via `register_toolchains("@//:all")`, where `` is the value of the `name` parameter. Toolchain resolution is determined with target_compatible_with parameter and constrained with --java_runtime_version flag either having value of "version" or "{prefix}_{version}" parameters. Args: name: A unique name for this rule. version: Version of the JDK imported. target_compatible_with: Target platform constraints (CPU and OS) for this JDK. prefix: Optional alternative prefix for configuration flag value used to determine this JDK. **kwargs: Refer to http_archive documentation """ http_archive( name = name, build_file_content = JDK_BUILD_TEMPLATE.format(RUNTIME_VERSION = version), **kwargs ) _toolchain_config( name = name + "_toolchain_config_repo", build_file = """ config_setting( name = "prefix_version_setting", values = {{"java_runtime_version": "{prefix}_{version}"}}, visibility = ["//visibility:private"], ) config_setting( name = "version_setting", values = {{"java_runtime_version": "{version}"}}, visibility = ["//visibility:private"], ) alias( name = "version_or_prefix_version_setting", actual = select({{ ":version_setting": ":version_setting", "//conditions:default": ":prefix_version_setting", }}), visibility = ["//visibility:private"], ) toolchain( name = "toolchain", target_compatible_with = {target_compatible_with}, target_settings = [":version_or_prefix_version_setting"], toolchain_type = "@bazel_tools//tools/jdk:runtime_toolchain_type", toolchain = "{toolchain}", ) toolchain( name = "bootstrap_runtime_toolchain", # These constraints are not required for correctness, but prevent fetches of remote JDK for # different architectures. As every Java compilation toolchain depends on a bootstrap runtime in # the same configuration, this constraint will not result in toolchain resolution failures. exec_compatible_with = {target_compatible_with}, target_settings = [":version_or_prefix_version_setting"], toolchain_type = "@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type", toolchain = "{toolchain}", ) """.format( prefix = prefix, version = version, target_compatible_with = target_compatible_with, toolchain = "@{repo}//:jdk".format(repo = name), ), ) rules_java-7.6.5/toolchains/toolchain_utils.bzl000066400000000000000000000034351463457531700217640ustar00rootroot00000000000000# Copyright 2019 The Bazel Authors. All rights reserved. # # 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. """ Finds the Java toolchain. Returns the toolchain if enabled, and falls back to a toolchain constructed from legacy toolchain selection. """ load("//java/common:java_common.bzl", "java_common") def find_java_toolchain(ctx, target): """ Finds the Java toolchain. If the Java toolchain is in use, returns it. Otherwise, returns a Java toolchain derived from legacy toolchain selection. Args: ctx: The rule context for which to find a toolchain. target: A java_toolchain target (for legacy toolchain resolution). Returns: A JavaToolchainInfo. """ _ignore = [ctx] # buildifier: disable=unused-variable return target[java_common.JavaToolchainInfo] def find_java_runtime_toolchain(ctx, target): """ Finds the Java runtime. If the Java toolchain is in use, returns it. Otherwise, returns a Java runtime derived from legacy toolchain selection. Args: ctx: The rule context for which to find a toolchain. target: A java_runtime target (for legacy toolchain resolution). Returns: A JavaRuntimeInfo. """ _ignore = [ctx] # buildifier: disable=unused-variable return target[java_common.JavaRuntimeInfo]