├── .allstar └── binary_artifacts.yaml ├── .bazelversion ├── .bcr ├── config.yml ├── metadata.template.json ├── presubmit.yml └── source.template.json ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── BUILD ├── CONTRIBUTING.md ├── LICENSE ├── MODULE.bazel ├── MODULE.bazel.lock ├── README.md ├── maven_install.json ├── testing ├── BUILD └── test_defs.bzl ├── third_party └── java │ ├── apache_bcel │ └── BUILD │ ├── asm │ └── BUILD │ ├── auto │ └── BUILD │ ├── byte_buddy │ └── BUILD │ ├── byte_buddy_agent │ └── BUILD │ ├── checker_framework │ └── BUILD │ ├── checker_framework_annotations │ └── BUILD │ ├── compile_testing │ └── BUILD │ ├── dagger │ └── BUILD │ ├── diffutils │ └── BUILD │ ├── error_prone │ └── BUILD │ ├── google_java_format │ └── BUILD │ ├── grpc │ └── BUILD │ ├── guava │ └── BUILD │ ├── hamcrest │ └── BUILD │ ├── incap │ └── BUILD │ ├── inject_common │ └── BUILD │ ├── javapoet │ └── BUILD │ ├── jspecify_annotations │ └── BUILD │ ├── jsr250_annotations │ └── BUILD │ ├── jsr305_annotations │ └── BUILD │ ├── jsr330_inject │ └── BUILD │ ├── junit │ └── BUILD │ ├── log4j │ └── BUILD │ ├── log4j2 │ └── BUILD │ ├── mockito │ └── BUILD │ ├── objenesis │ └── BUILD │ ├── protobuf │ └── BUILD │ ├── slf4j_api │ └── BUILD │ └── truth │ ├── BUILD │ └── extensions │ └── BUILD └── tools ├── jarjar ├── BUILD ├── expected_libs.dep ├── jarjar.bzl ├── jarjar_runner.sh ├── jarjar_validator.sh ├── test-library1.jar └── test-library2.jar ├── javadoc ├── BUILD └── javadoc.bzl └── maven ├── BUILD └── pom_file.bzl /.allstar/binary_artifacts.yaml: -------------------------------------------------------------------------------- 1 | # Exemption reason: This repo uses binary artifacts for unit tests. 2 | # Exemption timeframe: permanent 3 | optConfig: 4 | optOut: true -------------------------------------------------------------------------------- /.bazelversion: -------------------------------------------------------------------------------- 1 | 8.2.1 2 | -------------------------------------------------------------------------------- /.bcr/ config.yml: -------------------------------------------------------------------------------- 1 | # See https://github.com/bazel-contrib/publish-to-bcr#a-note-on-release-automation 2 | fixedReleaser: 3 | login: mollyibot 4 | email: mollyibot@google.com -------------------------------------------------------------------------------- /.bcr/metadata.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "homepage": "https://github.com/google/bazel-common", 3 | "maintainers": [ 4 | { 5 | "name": "Chris Povirk", 6 | "email": "cpovirk@google.com", 7 | "github": "cpovirk" 8 | } 9 | ], 10 | "repository": [ 11 | "github:google/bazel-common" 12 | ], 13 | "versions": [], 14 | "yanked_versions": {} 15 | } 16 | -------------------------------------------------------------------------------- /.bcr/presubmit.yml: -------------------------------------------------------------------------------- 1 | matrix: 2 | platform: ["debian10", "macos", "ubuntu2004"] 3 | bazel: [7.x, 8.x] 4 | tasks: 5 | run_tests: 6 | name: "Run tests" 7 | platform: ${{ platform }} 8 | bazel: ${{ bazel }} 9 | test_flags: 10 | - "--keep_going" 11 | test_targets: 12 | - "@google_bazel_common//..." 13 | -------------------------------------------------------------------------------- /.bcr/source.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "integrity": "", 3 | "strip_prefix": "{REPO}-{VERSION}", 4 | "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/bazel-common-{TAG}.tar.gz" 5 | } 6 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | test: 13 | name: "Test" 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: 'Check out repository' 17 | uses: actions/checkout@v4.2.2 18 | - name: 'Cache Bazel dependencies' 19 | uses: actions/cache@v4.2.2 20 | with: 21 | path: ~/.cache/bazel/*/*/external 22 | key: bazel-${{ hashFiles('MODULE.bazel') }} 23 | restore-keys: | 24 | bazel- 25 | - name: 'Test' 26 | shell: bash 27 | run: bazelisk test --lockfile_mode=error --test_output=errors //... 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated bazel symlinks. 2 | /bazel-* 3 | -------------------------------------------------------------------------------- /BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Common configuration and dependencies for Google's open-source libraries that are built with 16 | # Bazel. 17 | 18 | exports_files(["LICENSE"]) 19 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement. You (or your employer) retain the copyright to your contribution; 10 | this simply gives us permission to use and redistribute your contributions as 11 | part of the project. Head over to to see 12 | your current agreements on file or to sign a new one. 13 | 14 | You generally only need to submit a CLA once, so if you've already submitted one 15 | (even if it was for a different project), you probably don't need to do it 16 | again. 17 | 18 | ## Code reviews 19 | 20 | All submissions, including submissions by project members, require review. We 21 | use GitHub pull requests for this purpose. Consult 22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 23 | information on using pull requests. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /MODULE.bazel: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2024 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module(name = "google_bazel_common") 16 | 17 | bazel_dep(name = "bazel_skylib", version = "1.7.1") 18 | bazel_dep(name = "rules_java", version = "8.6.1") 19 | bazel_dep(name = "rules_jvm_external", version = "6.6") 20 | 21 | GUAVA_VERSION = "33.4.8-jre" 22 | 23 | AUTO_SERVICE_VERSION = "1.1.1" 24 | 25 | AUTO_VALUE_VERSION = "1.10.4" 26 | 27 | DAGGER_VERSION = "2.43.2" 28 | 29 | ERROR_PRONE_VERSION = "2.22.0" 30 | 31 | BYTE_BUDDY_VERSION = "1.14.9" 32 | 33 | TRUTH_VERSION = "1.4.4" 34 | 35 | GRPC_VERSION = "1.66.0" 36 | 37 | CHECKER_FRAMEWORK_VERSION = "2.5.3" 38 | 39 | ASM_VERSION = "9.6" 40 | 41 | LOG4J2_VERSION = "2.17.2" 42 | 43 | INCAP_VERSION = "0.2" 44 | 45 | maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") 46 | maven.install( 47 | name = "google_bazel_common_maven", 48 | artifacts = [ 49 | "javax.annotation:jsr250-api:1.0", 50 | "com.google.code.findbugs:jsr305:3.0.1", 51 | "javax.inject:javax.inject:1", 52 | "javax.inject:javax.inject-tck:1", 53 | "com.google.guava:guava:" + GUAVA_VERSION, 54 | "com.google.guava:guava-testlib:" + GUAVA_VERSION, 55 | "com.google.guava:failureaccess:1.0.3", 56 | "com.google.guava:guava-beta-checker:1.0", 57 | "com.google.errorprone:javac-shaded:9-dev-r4023-3", 58 | "com.google.googlejavaformat:google-java-format:1.18.1", 59 | "com.google.auto:auto-common:1.2.2", 60 | "com.google.auto.factory:auto-factory:1.0.1", 61 | "com.google.auto.service:auto-service:" + AUTO_SERVICE_VERSION, 62 | "com.google.auto.service:auto-service-annotations:" + AUTO_SERVICE_VERSION, 63 | "com.google.auto.value:auto-value:" + AUTO_VALUE_VERSION, 64 | "com.google.auto.value:auto-value-annotations:" + AUTO_VALUE_VERSION, 65 | "com.google.dagger:dagger:" + DAGGER_VERSION, 66 | "com.google.dagger:dagger-compiler:" + DAGGER_VERSION, 67 | "com.google.errorprone:error_prone_annotation:" + ERROR_PRONE_VERSION, 68 | "com.google.errorprone:error_prone_annotations:" + ERROR_PRONE_VERSION, 69 | "com.google.errorprone:error_prone_check_api:" + ERROR_PRONE_VERSION, 70 | "junit:junit:4.13.2", 71 | "com.google.testing.compile:compile-testing:0.21.0", 72 | "net.bytebuddy:byte-buddy:" + BYTE_BUDDY_VERSION, 73 | "net.bytebuddy:byte-buddy-agent:" + BYTE_BUDDY_VERSION, 74 | "org.mockito:mockito-core:5.4.0", 75 | "org.hamcrest:hamcrest-core:1.3", 76 | "org.objenesis:objenesis:1.0", 77 | "com.google.truth:truth:" + TRUTH_VERSION, 78 | # TODO: b/113905249 - Remove this: All its contents have moved into `truth`. 79 | "com.google.truth.extensions:truth-java8-extension:" + TRUTH_VERSION, 80 | "com.google.truth.extensions:truth-proto-extension:" + TRUTH_VERSION, 81 | "com.squareup:javapoet:1.13.0", 82 | "io.grpc:grpc-api:" + GRPC_VERSION, 83 | "io.grpc:grpc-core:" + GRPC_VERSION, 84 | "io.grpc:grpc-netty:" + GRPC_VERSION, 85 | "io.grpc:grpc-context:" + GRPC_VERSION, 86 | "io.grpc:grpc-protobuf:" + GRPC_VERSION, 87 | "io.grpc:grpc-stub:" + GRPC_VERSION, 88 | "io.grpc:grpc-all:" + GRPC_VERSION, 89 | "com.google.protobuf:protobuf-java:3.24.4", 90 | "org.checkerframework:checker-compat-qual:" + CHECKER_FRAMEWORK_VERSION, 91 | "org.checkerframework:checker-qual:" + CHECKER_FRAMEWORK_VERSION, 92 | "org.checkerframework:javacutil:" + CHECKER_FRAMEWORK_VERSION, 93 | "org.checkerframework:dataflow:" + CHECKER_FRAMEWORK_VERSION, 94 | "org.jspecify:jspecify:1.0.0", 95 | "org.ow2.asm:asm:" + ASM_VERSION, 96 | "org.ow2.asm:asm-tree:" + ASM_VERSION, 97 | "org.ow2.asm:asm-commons:" + ASM_VERSION, 98 | "org.codehaus.plexus:plexus-utils:3.0.20", 99 | "org.codehaus.plexus:plexus-classworlds:2.5.2", 100 | "org.codehaus.plexus:plexus-component-annotations:1.5.5", 101 | "org.eclipse.sisu:org.eclipse.sisu.plexus:0.3.0", 102 | "org.eclipse.sisu:org.eclipse.sisu.inject:0.3.0", 103 | "org.apache.maven:maven-artifact:3.3.3", 104 | "org.apache.maven:maven-model:3.3.3", 105 | "org.apache.maven:maven-plugin-api:3.3.3", 106 | "javax.enterprise:cdi-api:1.0", 107 | "org.pantsbuild:jarjar:1.7.2", 108 | "org.apache.ant:ant:1.9.6", 109 | "org.apache.ant:ant-launcher:1.9.6", 110 | "log4j:log4j:1.2.15", 111 | "org.apache.logging.log4j:log4j-api:" + LOG4J2_VERSION, 112 | "org.apache.logging.log4j:log4j-core:" + LOG4J2_VERSION, 113 | "org.apache.bcel:bcel:6.7.0", 114 | "com.googlecode.java-diff-utils:diffutils:1.3.0", 115 | "org.slf4j:slf4j-api:1.7.14", 116 | "net.ltgt.gradle.incap:incap:" + INCAP_VERSION, 117 | "net.ltgt.gradle.incap:incap-processor:" + INCAP_VERSION, 118 | "com.google.common.inject:inject-common:1.0", 119 | ], 120 | fail_if_repin_required = True, 121 | lock_file = "//:maven_install.json", 122 | repositories = [ 123 | "https://bazel-mirror.storage.googleapis.com/repo1.maven.org/maven2/", 124 | "https://repo1.maven.org/maven2/", 125 | "http://maven.ibiblio.org/maven2/", # link seems to be dead? 126 | ], 127 | strict_visibility = True, 128 | ) 129 | use_repo(maven, "google_bazel_common_maven") 130 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bazel Common Libraries 2 | 3 | This repository contains assorted common functionality for Google's open-source 4 | libraries that are built with [`bazel`]. It is an experimental project and none 5 | of the APIs/target names are fixed/guaranteed to remain. You are welcome to use 6 | it and offer feedback at your own risk. 7 | 8 | This is not an official Google product. 9 | 10 | [`bazel`]: https://bazel.build 11 | 12 | ## Using Bazel Common 13 | 14 | 1. Choose the commit hash you want to use. 15 | 16 | 2. Add the following to your `MODULE.bazel` file. The version can be found 17 | [here](https://registry.bazel.build/modules/google_bazel_common) 18 | 19 | ```bzl 20 | bazel_dep( 21 | name = "google_bazel_common", 22 | version = "0.0.1", 23 | ) 24 | ``` 25 | 26 | To update the version of Bazel Common, choose a new commit and update your 27 | `MODULE.bazel` file. 28 | 29 | ## Incrementing the version of an exported library 30 | 31 | 1. Open `MODULE.bazel` 32 | 33 | 2. Find the maven coordinate of the library export that you want to increment 34 | 35 | 3. Update the version number in the maven coordinate 36 | 37 | 4. Update the `maven_install.json` file by running: 38 | 39 | ```shell 40 | REPIN=1 bazelisk run @google_bazel_common_maven//:pin 41 | ``` 42 | 43 | 5. Send the change for review. 44 | 45 | 6. Once submitted, remember to update your own dep on `bazel_common` to the 46 | version containing your change. 47 | -------------------------------------------------------------------------------- /testing/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # A collection of starlark macros and rules for testing 16 | -------------------------------------------------------------------------------- /testing/test_defs.bzl: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Skylark macros to simplify declaring tests.""" 15 | 16 | load("@rules_java//java:defs.bzl", "java_library", "java_test") 17 | 18 | def gen_java_tests( 19 | name, 20 | srcs, 21 | deps, 22 | prefix_path = None, 23 | lib_deps = None, 24 | test_deps = None, 25 | plugins = None, 26 | lib_plugins = None, 27 | test_plugins = None, 28 | javacopts = None, 29 | lib_javacopts = None, 30 | test_javacopts = None, 31 | jvm_flags = None, # Applied to tests only 32 | **kwargs): 33 | """Generates `java_test` rules for each file in `srcs` ending in "Test.java". 34 | 35 | All other files will be compiled in a supporting `java_library` that is passed 36 | as a dep to each of the generated `java_test` rules. 37 | 38 | The arguments to this macro match those of the `java_library` and `java_test` 39 | rules. The arguments prefixed with `lib_` will be passed to the generated 40 | supporting `java_library` and not the tests, and vice versa for arguments 41 | prefixed with `test_`. For example, passing `deps = [:a], lib_deps = [:b], 42 | test_deps = [:c]` will result in a `java_library` that has `deps = [:a, :b]` 43 | and `java_test`s that have `deps = [:a, :c]`. 44 | 45 | Args: 46 | prefix_path: (string) The prefix between the current package path and the source 47 | file paths, which will be eliminated when determining test class names. 48 | """ 49 | _gen_java_tests( 50 | java_library, 51 | java_test, 52 | name, 53 | srcs, 54 | deps, 55 | prefix_path = prefix_path, 56 | javacopts = javacopts, 57 | lib_deps = lib_deps, 58 | lib_javacopts = lib_javacopts, 59 | lib_plugins = lib_plugins, 60 | plugins = plugins, 61 | test_deps = test_deps, 62 | test_javacopts = test_javacopts, 63 | jvm_flags = jvm_flags, 64 | test_plugins = test_plugins, 65 | **kwargs 66 | ) 67 | 68 | def gen_android_local_tests( 69 | name, 70 | srcs, 71 | deps, 72 | prefix_path = None, 73 | lib_deps = None, 74 | test_deps = None, 75 | plugins = None, 76 | lib_plugins = None, 77 | test_plugins = None, 78 | javacopts = None, 79 | lib_javacopts = None, 80 | test_javacopts = None, # Applied to tests only 81 | jvm_flags = None, 82 | **kwargs): 83 | """Generates `android_local_test` rules for each file in `srcs` ending in "Test.java". 84 | 85 | All other files will be compiled in a supporting `android_library` that is 86 | passed as a dep to each of the generated test rules. 87 | 88 | The arguments to this macro match those of the `android_library` and 89 | `android_local_test` rules. The arguments prefixed with `lib_` will be 90 | passed to the generated supporting `android_library` and not the tests, and 91 | vice versa for arguments prefixed with `test_`. For example, passing `deps = 92 | [:a], lib_deps = [:b], test_deps = [:c]` will result in a `android_library` 93 | that has `deps = [:a, :b]` and `android_local_test`s that have `deps = 94 | [:a, :c]`. 95 | 96 | Args: 97 | prefix_path: (string) The prefix between the current package path and the source 98 | file paths, which will be eliminated when determining test class names. 99 | """ 100 | 101 | _gen_java_tests( 102 | native.android_library, 103 | native.android_local_test, 104 | name, 105 | srcs, 106 | deps, 107 | prefix_path = prefix_path, 108 | javacopts = javacopts, 109 | lib_deps = lib_deps, 110 | lib_javacopts = lib_javacopts, 111 | lib_plugins = lib_plugins, 112 | plugins = plugins, 113 | test_deps = test_deps, 114 | test_javacopts = test_javacopts, 115 | jvm_flags = jvm_flags, 116 | test_plugins = test_plugins, 117 | **kwargs 118 | ) 119 | 120 | def _concat(*lists): 121 | """Concatenates the items in `lists`, ignoring `None` arguments.""" 122 | concatenated = [] 123 | for list in lists: 124 | if list: 125 | concatenated += list 126 | return concatenated 127 | 128 | def _gen_java_tests( 129 | library_rule_type, 130 | test_rule_type, 131 | name, 132 | srcs, 133 | deps, 134 | prefix_path = None, 135 | lib_deps = None, 136 | test_deps = None, 137 | plugins = None, 138 | lib_plugins = None, 139 | test_plugins = None, 140 | javacopts = None, 141 | lib_javacopts = None, 142 | test_javacopts = None, 143 | jvm_flags = None, 144 | runtime_deps = None, 145 | tags = None): 146 | test_files = [] 147 | supporting_lib_files = [] 148 | 149 | for src in srcs: 150 | if src.endswith("Test.java"): 151 | test_files.append(src) 152 | else: 153 | supporting_lib_files.append(src) 154 | 155 | test_deps = _concat(deps, test_deps) 156 | if supporting_lib_files: 157 | supporting_lib_files_name = name + "_lib" 158 | test_deps.append(":" + supporting_lib_files_name) 159 | library_rule_type( 160 | name = supporting_lib_files_name, 161 | testonly = 1, 162 | srcs = supporting_lib_files, 163 | javacopts = _concat(javacopts, lib_javacopts), 164 | plugins = _concat(plugins, lib_plugins), 165 | tags = tags, 166 | deps = _concat(deps, lib_deps), 167 | ) 168 | 169 | package_name = native.package_name() 170 | 171 | if prefix_path: 172 | pass 173 | elif package_name.find("javatests/") != -1: 174 | prefix_path = "javatests/" 175 | else: 176 | prefix_path = "src/test/java/" 177 | 178 | test_names = [] 179 | for test_file in test_files: 180 | test_name = test_file.replace(".java", "") 181 | test_names.append(test_name) 182 | 183 | test_class = (package_name + "/" + test_name).rpartition(prefix_path)[2].replace("/", ".") 184 | test_rule_type( 185 | name = test_name, 186 | srcs = [test_file], 187 | javacopts = _concat(javacopts, test_javacopts), 188 | jvm_flags = jvm_flags, 189 | plugins = _concat(plugins, test_plugins), 190 | tags = _concat(["gen_java_tests"], tags), 191 | test_class = test_class, 192 | deps = test_deps, 193 | runtime_deps = runtime_deps, 194 | ) 195 | 196 | native.test_suite( 197 | name = name, 198 | tests = test_names, 199 | ) 200 | -------------------------------------------------------------------------------- /third_party/java/apache_bcel/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://commons.apache.org/proper/commons-bcel/ 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "apache_bcel", 23 | exports = ["@google_bazel_common_maven//:org_apache_bcel_bcel"], 24 | ) 25 | -------------------------------------------------------------------------------- /third_party/java/asm/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for http://asm.ow2.org/ 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "asm", 23 | exports = ["@google_bazel_common_maven//:org_ow2_asm_asm"], 24 | ) 25 | 26 | java_library( 27 | name = "asm-tree", 28 | exports = ["@google_bazel_common_maven//:org_ow2_asm_asm_tree"], 29 | ) 30 | 31 | java_library( 32 | name = "asm-commons", 33 | exports = ["@google_bazel_common_maven//:org_ow2_asm_asm_commons"], 34 | ) 35 | -------------------------------------------------------------------------------- /third_party/java/auto/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://github.com/google/auto 16 | 17 | load("@rules_java//java:defs.bzl", "java_library", "java_plugin") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "common", 23 | exports = ["@google_bazel_common_maven//:com_google_auto_auto_common"], 24 | ) 25 | 26 | java_plugin( 27 | name = "auto_value_processor", 28 | processor_class = "com.google.auto.value.processor.AutoValueProcessor", 29 | visibility = ["//visibility:private"], 30 | deps = [ 31 | ":common", 32 | ":service", 33 | "//third_party/java/guava", 34 | "@google_bazel_common_maven//:com_google_auto_value_auto_value", 35 | ], 36 | ) 37 | 38 | java_plugin( 39 | name = "auto_annotation_processor", 40 | processor_class = "com.google.auto.value.processor.AutoAnnotationProcessor", 41 | visibility = ["//visibility:private"], 42 | deps = [ 43 | ":common", 44 | ":service", 45 | "//third_party/java/guava", 46 | "@google_bazel_common_maven//:com_google_auto_value_auto_value", 47 | ], 48 | ) 49 | 50 | java_plugin( 51 | name = "auto_oneof_processor", 52 | processor_class = "com.google.auto.value.processor.AutoOneOfProcessor", 53 | visibility = ["//visibility:private"], 54 | deps = [ 55 | ":common", 56 | ":service", 57 | "//third_party/java/guava", 58 | "@google_bazel_common_maven//:com_google_auto_value_auto_value", 59 | ], 60 | ) 61 | 62 | java_plugin( 63 | name = "auto_builder_processor", 64 | processor_class = "com.google.auto.value.processor.AutoBuilderProcessor", 65 | visibility = ["//visibility:private"], 66 | deps = [ 67 | ":common", 68 | ":service", 69 | "//third_party/java/guava", 70 | "@google_bazel_common_maven//:com_google_auto_value_auto_value", 71 | ], 72 | ) 73 | 74 | java_library( 75 | name = "value", 76 | exported_plugins = [ 77 | ":auto_annotation_processor", 78 | ":auto_oneof_processor", 79 | ":auto_value_processor", 80 | ":auto_builder_processor", 81 | ], 82 | tags = ["maven:compile_only"], 83 | exports = [ 84 | "//third_party/java/jsr250_annotations", # TODO(ronshapiro) Can this be removed? 85 | "@google_bazel_common_maven//:com_google_auto_value_auto_value_annotations", 86 | ], 87 | ) 88 | 89 | java_plugin( 90 | name = "auto_factory_processor", 91 | generates_api = True, 92 | processor_class = "com.google.auto.factory.processor.AutoFactoryProcessor", 93 | visibility = ["//visibility:private"], 94 | deps = [ 95 | ":common", 96 | ":service", 97 | "//third_party/java/google_java_format", 98 | "//third_party/java/guava", 99 | "//third_party/java/javapoet", 100 | "@google_bazel_common_maven//:com_google_auto_factory_auto_factory", 101 | ], 102 | ) 103 | 104 | java_library( 105 | name = "factory", 106 | exported_plugins = [":auto_factory_processor"], 107 | exports = ["@google_bazel_common_maven//:com_google_auto_factory_auto_factory"], 108 | ) 109 | 110 | java_plugin( 111 | name = "auto_service_processor", 112 | processor_class = "com.google.auto.service.processor.AutoServiceProcessor", 113 | visibility = ["//visibility:private"], 114 | deps = [ 115 | ":common", 116 | "//third_party/java/guava", 117 | "@google_bazel_common_maven//:com_google_auto_service_auto_service", 118 | "@google_bazel_common_maven//:com_google_auto_service_auto_service_annotations", 119 | ], 120 | ) 121 | 122 | java_library( 123 | name = "service", 124 | exported_plugins = [":auto_service_processor"], 125 | tags = ["maven:compile_only"], 126 | exports = ["@google_bazel_common_maven//:com_google_auto_service_auto_service_annotations"], 127 | ) 128 | -------------------------------------------------------------------------------- /third_party/java/byte_buddy/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://bytebuddy.net/ 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "byte_buddy", 23 | testonly = True, 24 | exports = ["@google_bazel_common_maven//:net_bytebuddy_byte_buddy"], 25 | ) 26 | -------------------------------------------------------------------------------- /third_party/java/byte_buddy_agent/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://bytebuddy.net/ 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "byte_buddy_agent", 23 | testonly = True, 24 | exports = ["@google_bazel_common_maven//:net_bytebuddy_byte_buddy_agent"], 25 | ) 26 | -------------------------------------------------------------------------------- /third_party/java/checker_framework/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://checkerframework.org/ 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "dataflow", 23 | exports = ["@google_bazel_common_maven//:org_checkerframework_dataflow"], 24 | runtime_deps = [ 25 | "@google_bazel_common_maven//:org_checkerframework_checker_qual", 26 | "@google_bazel_common_maven//:org_checkerframework_javacutil", 27 | ], 28 | ) 29 | -------------------------------------------------------------------------------- /third_party/java/checker_framework_annotations/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://checkerframework.org/ 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "checker_framework_annotations", 23 | exports = ["@google_bazel_common_maven//:org_checkerframework_checker_qual"], 24 | ) 25 | -------------------------------------------------------------------------------- /third_party/java/compile_testing/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://github.com/google/compile-testing 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "compile_testing", 23 | testonly = True, 24 | add_exports = [ 25 | "jdk.compiler/com.sun.tools.javac.api", 26 | "jdk.compiler/com.sun.tools.javac.main", 27 | "jdk.compiler/com.sun.tools.javac.util", 28 | ], 29 | exports = ["@google_bazel_common_maven//:com_google_testing_compile_compile_testing"], 30 | runtime_deps = [ 31 | "//third_party/java/auto:value", 32 | "//third_party/java/error_prone:annotations", 33 | "//third_party/java/guava", 34 | "//third_party/java/jsr305_annotations", 35 | "//third_party/java/junit", 36 | "//third_party/java/truth", 37 | ], 38 | ) 39 | -------------------------------------------------------------------------------- /third_party/java/dagger/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2025 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://github.com/google/dagger 16 | 17 | load("@rules_java//java:defs.bzl", "java_library", "java_plugin") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "dagger", 23 | exported_plugins = [":dagger_plugin"], 24 | exports = [ 25 | "@google_bazel_common_maven//:com_google_dagger_dagger", 26 | ], 27 | ) 28 | 29 | java_plugin( 30 | name = "dagger_plugin", 31 | generates_api = 1, 32 | processor_class = "dagger.internal.codegen.ComponentProcessor", 33 | visibility = ["//visibility:private"], 34 | deps = [ 35 | "@google_bazel_common_maven//:com_google_dagger_dagger_compiler", 36 | ], 37 | ) 38 | -------------------------------------------------------------------------------- /third_party/java/diffutils/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://code.google.com/archive/p/java-diff-utils/ 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "diffutils", 23 | exports = ["@google_bazel_common_maven//:com_googlecode_java_diff_utils_diffutils"], 24 | ) 25 | -------------------------------------------------------------------------------- /third_party/java/error_prone/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://github.com/google/error-prone. Note that Bazel already 16 | # applies the Error Prone compiler to all java compilations - this package exports 17 | # dependencies for Error Prone's libraries 18 | 19 | load("@rules_java//java:defs.bzl", "java_library") 20 | 21 | package(default_visibility = ["//visibility:public"]) 22 | 23 | java_library( 24 | name = "annotations", 25 | tags = ["maven:compile_only"], 26 | exports = ["@google_bazel_common_maven//:com_google_errorprone_error_prone_annotations"], 27 | ) 28 | 29 | java_library( 30 | name = "error_prone_javac", 31 | exports = ["@google_bazel_common_maven//:com_google_errorprone_javac_shaded"], 32 | ) 33 | 34 | java_library( 35 | name = "check_api", 36 | exports = [ 37 | "@google_bazel_common_maven//:com_google_errorprone_error_prone_annotation", 38 | "@google_bazel_common_maven//:com_google_errorprone_error_prone_check_api", 39 | ], 40 | runtime_deps = [ 41 | ":annotations", 42 | ":error_prone_javac", 43 | "//third_party/java/checker_framework:dataflow", 44 | "//third_party/java/diffutils", 45 | "//third_party/java/jsr305_annotations", 46 | ], 47 | ) 48 | -------------------------------------------------------------------------------- /third_party/java/google_java_format/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://github.com/google/google-java-format 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "google_java_format", 23 | add_exports = [ 24 | "jdk.compiler/com.sun.tools.javac.api", 25 | "jdk.compiler/com.sun.tools.javac.code", 26 | "jdk.compiler/com.sun.tools.javac.file", 27 | "jdk.compiler/com.sun.tools.javac.main", 28 | "jdk.compiler/com.sun.tools.javac.parser", 29 | "jdk.compiler/com.sun.tools.javac.tree", 30 | "jdk.compiler/com.sun.tools.javac.util", 31 | ], 32 | exports = ["@google_bazel_common_maven//:com_google_googlejavaformat_google_java_format"], 33 | runtime_deps = [ 34 | "//third_party/java/error_prone:error_prone_javac", 35 | "//third_party/java/guava", 36 | ], 37 | ) 38 | -------------------------------------------------------------------------------- /third_party/java/grpc/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://github.com/grpc/grpc-java 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "grpc", 23 | exports = ["@google_bazel_common_maven//:io_grpc_grpc_all"], 24 | ) 25 | 26 | java_library( 27 | name = "api", 28 | exports = ["@google_bazel_common_maven//:io_grpc_grpc_api"], 29 | ) 30 | 31 | java_library( 32 | name = "core", 33 | exports = ["@google_bazel_common_maven//:io_grpc_grpc_core"], 34 | ) 35 | 36 | java_library( 37 | name = "netty", 38 | exports = ["@google_bazel_common_maven//:io_grpc_grpc_netty"], 39 | ) 40 | 41 | java_library( 42 | name = "context", 43 | exports = [":api"], # why not @google_bazel_common_maven//:io_grpc_grpc_context? 44 | ) 45 | 46 | java_library( 47 | name = "protobuf", 48 | exports = ["@google_bazel_common_maven//:io_grpc_grpc_protobuf"], 49 | ) 50 | 51 | java_library( 52 | name = "stub", 53 | exports = ["@google_bazel_common_maven//:io_grpc_grpc_stub"], 54 | ) 55 | -------------------------------------------------------------------------------- /third_party/java/guava/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://github.com/google/guava 16 | 17 | load("@rules_java//java:defs.bzl", "java_library", "java_plugin") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "guava", 23 | exported_plugins = [":beta-checker"], 24 | exports = [ 25 | "@google_bazel_common_maven//:com_google_guava_failureaccess", 26 | "@google_bazel_common_maven//:com_google_guava_guava", 27 | ], 28 | ) 29 | 30 | java_library( 31 | name = "testlib", 32 | testonly = True, 33 | exports = ["@google_bazel_common_maven//:com_google_guava_guava_testlib"], 34 | runtime_deps = [":guava"], 35 | ) 36 | 37 | java_plugin( 38 | name = "beta-checker", 39 | visibility = ["//visibility:private"], 40 | deps = ["@google_bazel_common_maven//:com_google_guava_guava_beta_checker"], 41 | ) 42 | -------------------------------------------------------------------------------- /third_party/java/hamcrest/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://github.com/hamcrest/JavaHamcrest 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "hamcrest", 23 | testonly = True, 24 | exports = ["@google_bazel_common_maven//:org_hamcrest_hamcrest_core"], 25 | ) 26 | -------------------------------------------------------------------------------- /third_party/java/incap/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://github.com/tbroyer/gradle-incap-helper 16 | 17 | load("@rules_java//java:defs.bzl", "java_library", "java_plugin") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "incap", 23 | exported_plugins = [":processor"], 24 | exports = ["@google_bazel_common_maven//:net_ltgt_gradle_incap_incap"], 25 | ) 26 | 27 | java_plugin( 28 | name = "processor", 29 | processor_class = "net.ltgt.gradle.incap.processor.IncrementalAnnotationProcessorProcessor", 30 | visibility = ["//visibility:private"], 31 | deps = [ 32 | "@google_bazel_common_maven//:net_ltgt_gradle_incap_incap", 33 | "@google_bazel_common_maven//:net_ltgt_gradle_incap_incap_processor", 34 | ], 35 | ) 36 | -------------------------------------------------------------------------------- /third_party/java/inject_common/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://github.com/google/inject-common 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "inject_common", 23 | exports = ["@google_bazel_common_maven//:com_google_common_inject_inject_common"], 24 | runtime_deps = [ 25 | "//third_party/java/jsr305_annotations", 26 | "//third_party/java/jsr330_inject", 27 | ], 28 | ) 29 | -------------------------------------------------------------------------------- /third_party/java/javapoet/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://github.com/square/javapoet 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "javapoet", 23 | exports = ["@google_bazel_common_maven//:com_squareup_javapoet"], 24 | ) 25 | -------------------------------------------------------------------------------- /third_party/java/jspecify_annotations/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2024 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://jspecify.dev/ 16 | 17 | package(default_visibility = ["//visibility:public"]) 18 | 19 | alias( 20 | name = "jspecify_annotations", 21 | actual = "@google_bazel_common_maven//:org_jspecify_jspecify", 22 | ) 23 | -------------------------------------------------------------------------------- /third_party/java/jsr250_annotations/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://en.wikipedia.org/wiki/JSR_250 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "jsr250_annotations", 23 | exports = ["@google_bazel_common_maven//:javax_annotation_jsr250_api"], 24 | ) 25 | -------------------------------------------------------------------------------- /third_party/java/jsr305_annotations/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://jcp.org/en/jsr/detail?id=305 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "jsr305_annotations", 23 | exports = ["@google_bazel_common_maven//:com_google_code_findbugs_jsr305"], 24 | ) 25 | -------------------------------------------------------------------------------- /third_party/java/jsr330_inject/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for javax.inject (https://www.jcp.org/en/jsr/detail?id=330) 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "jsr330_inject", 23 | exports = ["@google_bazel_common_maven//:javax_inject_javax_inject"], 24 | ) 25 | 26 | java_library( 27 | name = "tck", 28 | exports = ["@google_bazel_common_maven//:javax_inject_javax_inject_tck"], 29 | ) 30 | -------------------------------------------------------------------------------- /third_party/java/junit/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://github.com/junit-team 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "junit", 23 | testonly = True, 24 | exports = ["@google_bazel_common_maven//:junit_junit"], 25 | runtime_deps = ["//third_party/java/hamcrest"], 26 | ) 27 | -------------------------------------------------------------------------------- /third_party/java/log4j/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://logging.apache.org/log4j/1.x/ 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "log4j", 23 | exports = ["@google_bazel_common_maven//:log4j_log4j"], 24 | ) 25 | -------------------------------------------------------------------------------- /third_party/java/log4j2/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://logging.apache.org/log4j/2.x/ 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "log4j2", 23 | exports = [ 24 | "@google_bazel_common_maven//:org_apache_logging_log4j_log4j_api", 25 | "@google_bazel_common_maven//:org_apache_logging_log4j_log4j_core", 26 | ], 27 | ) 28 | -------------------------------------------------------------------------------- /third_party/java/mockito/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://github.com/mockito/mockito 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "mockito", 23 | testonly = True, 24 | exports = ["@google_bazel_common_maven//:org_mockito_mockito_core"], 25 | runtime_deps = [ 26 | "//third_party/java/byte_buddy", 27 | "//third_party/java/byte_buddy_agent", 28 | "//third_party/java/hamcrest", 29 | "//third_party/java/objenesis", 30 | ], 31 | ) 32 | -------------------------------------------------------------------------------- /third_party/java/objenesis/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://objenesis.org/ 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "objenesis", 23 | testonly = True, 24 | exports = ["@google_bazel_common_maven//:org_objenesis_objenesis"], 25 | ) 26 | -------------------------------------------------------------------------------- /third_party/java/protobuf/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://github.com/google/protobuf/tree/master/java 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "protobuf", 23 | exports = ["@google_bazel_common_maven//:com_google_protobuf_protobuf_java"], 24 | ) 25 | -------------------------------------------------------------------------------- /third_party/java/slf4j_api/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://www.slf4j.org/ 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "slf4j_api", 23 | exports = ["@google_bazel_common_maven//:org_slf4j_slf4j_api"], 24 | ) 25 | -------------------------------------------------------------------------------- /third_party/java/truth/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for https://github.com/google/truth 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "truth", 23 | testonly = True, 24 | exports = [ 25 | "@google_bazel_common_maven//:com_google_truth_extensions_truth_java8_extension", 26 | "@google_bazel_common_maven//:com_google_truth_truth", 27 | ], 28 | # TODO(cpovirk): This would make more sense in deps, but Bazel won't allow 29 | # that unless we add dummy srcs. 30 | runtime_deps = [ 31 | "//third_party/java/asm", 32 | ], 33 | ) 34 | -------------------------------------------------------------------------------- /third_party/java/truth/extensions/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2025 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # BUILD rules for extensions in https://github.com/google/truth 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | package(default_visibility = ["//visibility:public"]) 20 | 21 | java_library( 22 | name = "proto", 23 | testonly = 1, 24 | exports = [ 25 | "@google_bazel_common_maven//:com_google_truth_extensions_truth_proto_extension", 26 | ], 27 | ) 28 | -------------------------------------------------------------------------------- /tools/jarjar/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Skylark rules for using jarjar 16 | 17 | load("@rules_java//java:defs.bzl", "java_binary") 18 | load(":jarjar.bzl", "jarjar_library") 19 | 20 | java_binary( 21 | name = "jarjar", 22 | main_class = "org.pantsbuild.jarjar.Main", 23 | visibility = ["//visibility:public"], 24 | runtime_deps = [ 25 | "//third_party/java/asm", 26 | "//third_party/java/asm:asm-commons", 27 | "//third_party/java/asm:asm-tree", 28 | "//third_party/java/jsr250_annotations", 29 | "//third_party/java/jsr330_inject", 30 | "@google_bazel_common_maven//:javax_enterprise_cdi_api", 31 | "@google_bazel_common_maven//:org_apache_ant_ant", 32 | "@google_bazel_common_maven//:org_apache_ant_ant_launcher", 33 | "@google_bazel_common_maven//:org_apache_maven_maven_artifact", 34 | "@google_bazel_common_maven//:org_apache_maven_maven_model", 35 | "@google_bazel_common_maven//:org_apache_maven_maven_plugin_api", 36 | "@google_bazel_common_maven//:org_codehaus_plexus_plexus_classworlds", 37 | "@google_bazel_common_maven//:org_codehaus_plexus_plexus_component_annotations", 38 | "@google_bazel_common_maven//:org_codehaus_plexus_plexus_utils", 39 | "@google_bazel_common_maven//:org_eclipse_sisu_org_eclipse_sisu_inject", 40 | "@google_bazel_common_maven//:org_eclipse_sisu_org_eclipse_sisu_plexus", 41 | "@google_bazel_common_maven//:org_pantsbuild_jarjar", 42 | ], 43 | ) 44 | 45 | sh_binary( 46 | name = "jarjar_runner", 47 | srcs = ["jarjar_runner.sh"], 48 | visibility = ["//visibility:public"], 49 | ) 50 | 51 | # Test target used for validating rule. 52 | jarjar_library( 53 | name = "test_target", 54 | testonly = 1, 55 | jars = [ 56 | ":test-library1.jar", 57 | ":test-library2.jar", 58 | ], 59 | merge_meta_inf_files = ["utilities/libs.dep"], 60 | ) 61 | 62 | # Test that validates jarjar with merged META-INF files. 63 | sh_test( 64 | name = "validate_test_target", 65 | srcs = [":jarjar_validator.sh"], 66 | args = [ 67 | "$(location :test_target.jar)", 68 | "utilities/libs.dep", 69 | "$(location :expected_libs.dep)", 70 | ], 71 | data = [ 72 | ":expected_libs.dep", 73 | ":test_target.jar", 74 | ], 75 | ) 76 | -------------------------------------------------------------------------------- /tools/jarjar/expected_libs.dep: -------------------------------------------------------------------------------- 1 | Library2 2 | Library1 3 | -------------------------------------------------------------------------------- /tools/jarjar/jarjar.bzl: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Skylark rules for jarjar. See https://github.com/pantsbuild/jarjar 15 | """ 16 | 17 | load("@rules_java//java:defs.bzl", "java_common") 18 | 19 | def _jarjar_library(ctx): 20 | ctx.actions.write( 21 | output = ctx.outputs._rules_file, 22 | content = "\n".join(ctx.attr.rules), 23 | ) 24 | 25 | jar_files = depset(transitive = [jar.files for jar in ctx.attr.jars]).to_list() 26 | 27 | command = """ 28 | export JAVA_HOME="{java_home}" 29 | export MERGE_META_INF_FILES="{merge_meta_inf_files}" 30 | export JARJAR="{jarjar}" 31 | export RULES_FILE="{rules_file}" 32 | export OUTFILE="{outfile}" 33 | "{jarjar_runner}" {jars} 34 | """.format( 35 | java_home = str(ctx.attr._jdk[java_common.JavaRuntimeInfo].java_home), 36 | merge_meta_inf_files = " ".join(ctx.attr.merge_meta_inf_files), 37 | jarjar = ctx.executable._jarjar.path, 38 | rules_file = ctx.outputs._rules_file.path, 39 | outfile = ctx.outputs.jar.path, 40 | jarjar_runner = ctx.executable._jarjar_runner.path, 41 | jars = " ".join([jar.path for jar in jar_files]), 42 | ) 43 | 44 | ctx.actions.run_shell( 45 | command = command, 46 | inputs = [ctx.outputs._rules_file] + jar_files + ctx.files._jdk, 47 | outputs = [ctx.outputs.jar], 48 | tools = [ctx.executable._jarjar, ctx.executable._jarjar_runner], 49 | ) 50 | 51 | _jarjar_library_attrs = { 52 | "rules": attr.string_list(), 53 | "jars": attr.label_list( 54 | allow_files = [".jar"], 55 | ), 56 | "merge_meta_inf_files": attr.string_list( 57 | allow_empty = True, 58 | default = [], 59 | mandatory = False, 60 | doc = """A list of regular expressions that match files relative to the 61 | META-INF directory that will be merged into the output jar, in addition 62 | to files in META-INF/services. To add all files in META-INF/foo, for 63 | example, use "foo/.*".""", 64 | ), 65 | } 66 | 67 | _jarjar_library_attrs.update({ 68 | "_jarjar": attr.label( 69 | default = Label("//tools/jarjar"), 70 | executable = True, 71 | cfg = "exec", 72 | ), 73 | "_jarjar_runner": attr.label( 74 | default = Label("//tools/jarjar:jarjar_runner"), 75 | executable = True, 76 | cfg = "exec", 77 | ), 78 | "_jdk": attr.label( 79 | default = Label("@bazel_tools//tools/jdk:current_java_runtime"), 80 | providers = [java_common.JavaRuntimeInfo], 81 | ), 82 | }) 83 | 84 | jarjar_library = rule( 85 | attrs = _jarjar_library_attrs, 86 | outputs = { 87 | "jar": "%{name}.jar", 88 | "_rules_file": "%{name}.jarjar_rules", 89 | }, 90 | implementation = _jarjar_library, 91 | ) 92 | -------------------------------------------------------------------------------- /tools/jarjar/jarjar_runner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (C) 2018 The Bazel Common Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | JAVA_HOME="$(cd "${JAVA_HOME}" && pwd)" # this is used outside of the root 17 | 18 | TMPDIR="$(mktemp -d)" 19 | for jar in "$@"; do 20 | unzip -qq -B "${jar}" -d "${TMPDIR}" 21 | done 22 | 23 | pushd "${TMPDIR}" &>/dev/null 24 | 25 | find=(find) 26 | if [[ "$(uname -s)" == "Darwin" ]]; then 27 | # Mac uses BSD find, which requires extra args for regex matching. 28 | find+=(-E) 29 | suffix='(~[0-9]*)?' 30 | else 31 | # Default to GNU find, which must escape parentheses. 32 | suffix='\(~[0-9]*\)?' 33 | fi 34 | 35 | # Concatenate similar files in META-INF that allow it. 36 | for meta_inf_pattern in services/.* ${MERGE_META_INF_FILES}; do 37 | regex="META-INF/${meta_inf_pattern}${suffix}" 38 | for file in $("${find[@]}" META-INF -regex "${regex}"); do 39 | original="$(sed s/"~[0-9]*$"// <<< "${file}")" 40 | if [[ "${file}" != "${original}" ]]; then 41 | cat "${file}" >> "${original}" 42 | rm "${file}" 43 | fi 44 | done 45 | done 46 | 47 | # build-data.properties is emitted by Bazel with target information that can 48 | # cause conflicts. Delete it since it doesn't make sense to keep in the merged 49 | # jar anyway. 50 | rm build-data.properties* 51 | rm META-INF/MANIFEST.MF* 52 | rm -rf META-INF/maven/ 53 | duplicate_files="$(find * -type f -regex '.*~[0-9]*$')" 54 | if [[ -n "${duplicate_files}" ]]; then 55 | echo "Error: duplicate files in merged jar: ${duplicate_files}" 56 | exit 1 57 | fi 58 | "${JAVA_HOME}/bin/jar" cf combined.jar * 59 | 60 | popd &>/dev/null 61 | 62 | "${JARJAR}" process "${RULES_FILE}" "${TMPDIR}/combined.jar" "${OUTFILE}" 63 | 64 | rm -rf "${TMPDIR}" 65 | -------------------------------------------------------------------------------- /tools/jarjar/jarjar_validator.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if diff <(unzip -p "$1" "META-INF/$2") "$3"; then 3 | echo Passed 4 | exit 0 5 | else 6 | echo Failed 7 | exit 1 8 | fi 9 | -------------------------------------------------------------------------------- /tools/jarjar/test-library1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/bazel-common/2cab52929507935aa43d460a3976d3bedc814d3a/tools/jarjar/test-library1.jar -------------------------------------------------------------------------------- /tools/jarjar/test-library2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/bazel-common/2cab52929507935aa43d460a3976d3bedc814d3a/tools/jarjar/test-library2.jar -------------------------------------------------------------------------------- /tools/javadoc/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Starlark rules for generating Javadoc 16 | -------------------------------------------------------------------------------- /tools/javadoc/javadoc.bzl: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 The Dagger Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """See javadoc_library.""" 16 | 17 | load("@rules_java//java:defs.bzl", "JavaInfo", "java_common") 18 | load("@bazel_skylib//lib:collections.bzl", "collections") 19 | 20 | def _android_jar(android_api_level): 21 | if android_api_level == -1: 22 | return None 23 | 24 | return Label("@androidsdk//:platforms/android-%s/android.jar" % android_api_level) 25 | 26 | def _get_root_directories(root_packages, srcs): 27 | """ 28 | Returns the list of root directories for the given root packages. 29 | 30 | To accomplish this we get all the directories of the srcs and look for the root package paths in 31 | those directory paths. If there's a match we add the parent directory of that match. For 32 | example, if the root package is "com.google.foo" and the srcs are "java/com/google/foo/Bar.java" 33 | and "java/com/google/foo/Bar.java", we would return "java/". 34 | 35 | Args: 36 | root_packages: The list of root packages to look for (ex. "com.google.foo"). 37 | srcs: The list of sources to look for the root packages in. 38 | 39 | Returns: 40 | The list of root directories that contain the root packages. 41 | """ 42 | 43 | # Get the parent directories of all the java files and any tree artifact directories. 44 | java_files = [f for f in srcs if f.extension == "java"] 45 | directories = collections.uniq( 46 | [f.dirname + "/" for f in java_files] + [f.path + "/" for f in srcs if f.is_directory], 47 | ) 48 | root_package_subpaths = [package.replace(".", "/") + "/" for package in root_packages] 49 | 50 | root_directories = [] 51 | for d in directories: 52 | for package_subpath in root_package_subpaths: 53 | # Find the right-most subpath that contains the root package subpath. We'll use its 54 | # parent directory as a root. 55 | idx = d.rfind(package_subpath) 56 | if idx >= 0: 57 | root_directories.append(d[:idx]) 58 | 59 | return collections.uniq(root_directories) 60 | 61 | def _javadoc_library(ctx): 62 | transitive_deps = [] 63 | for dep in ctx.attr.deps: 64 | if JavaInfo in dep: 65 | transitive_deps.append(dep[JavaInfo].transitive_compile_time_jars) 66 | 67 | if ctx.attr._android_jar: 68 | transitive_deps.append(ctx.attr._android_jar.files) 69 | 70 | classpath = depset([], transitive = transitive_deps).to_list() 71 | 72 | java_home = str(ctx.attr._jdk[java_common.JavaRuntimeInfo].java_home) 73 | 74 | output_dir = ctx.actions.declare_directory("%s_javadoc" % ctx.attr.name) 75 | 76 | javadoc_arguments = ctx.actions.args() 77 | javadoc_arguments.use_param_file("@%s", use_always = True) 78 | javadoc_arguments.set_param_file_format("multiline") 79 | 80 | javadoc_command = java_home + "/bin/javadoc" 81 | 82 | javadoc_arguments.add("-use") 83 | javadoc_arguments.add("-encoding", "UTF8") 84 | javadoc_arguments.add_joined("-classpath", classpath, join_with = ":") 85 | javadoc_arguments.add("-notimestamp") 86 | javadoc_arguments.add("-d", output_dir.path) 87 | javadoc_arguments.add("-Xdoclint:-missing") 88 | javadoc_arguments.add("-quiet") 89 | 90 | # Documentation for the javadoc command 91 | # https://docs.oracle.com/javase/9/javadoc/javadoc-command.htm 92 | if ctx.attr.root_packages: 93 | javadoc_arguments.add_joined( 94 | "-sourcepath", 95 | _get_root_directories(ctx.attr.root_packages, ctx.files.srcs), 96 | join_with = ":", 97 | ) 98 | javadoc_arguments.add_all(ctx.attr.root_packages) 99 | javadoc_arguments.add_joined("-subpackages", ctx.attr.root_packages, join_with = ":") 100 | else: 101 | # Document exactly the code in the specified source files. 102 | javadoc_arguments.add_all(ctx.files.srcs) 103 | 104 | if ctx.attr.doctitle: 105 | javadoc_arguments.add("-doctitle", ctx.attr.doctitle, format = '"%s"') 106 | 107 | if ctx.attr.groups: 108 | groups = [] 109 | for k, v in ctx.attr.groups.items(): 110 | groups.append("-group \"%s\" \"%s\"" % (k, ":".join(v))) 111 | javadoc_arguments.add_all(groups) 112 | 113 | javadoc_arguments.add_joined("-exclude", ctx.attr.exclude_packages, join_with = ":") 114 | 115 | javadoc_arguments.add_all( 116 | ctx.attr.external_javadoc_links, 117 | map_each = _format_linkoffline_value, 118 | ) 119 | 120 | if ctx.attr.bottom_text: 121 | javadoc_arguments.add("-bottom", ctx.attr.bottom_text, format = '"%s"') 122 | 123 | # TODO(ronshapiro): Should we be using a different tool that doesn't include 124 | # timestamp info? 125 | jar_command = "%s/bin/jar cf %s -C %s ." % (java_home, ctx.outputs.jar.path, output_dir.path) 126 | 127 | srcs = depset(transitive = [src.files for src in ctx.attr.srcs]).to_list() 128 | ctx.actions.run_shell( 129 | inputs = srcs + classpath + ctx.files._jdk, 130 | command = "%s $@ && %s" % (javadoc_command, jar_command), 131 | arguments = [javadoc_arguments], 132 | outputs = [output_dir, ctx.outputs.jar], 133 | ) 134 | 135 | def _format_linkoffline_value(link): 136 | return "-linkoffline {0} {0}".format(link) 137 | 138 | javadoc_library = rule( 139 | attrs = { 140 | "srcs": attr.label_list( 141 | allow_empty = False, 142 | allow_files = True, 143 | doc = "Source files to generate Javadoc for.", 144 | ), 145 | "deps": attr.label_list( 146 | doc = """ 147 | Targets that contain references to other types referenced in Javadoc. These can 148 | be the java_library/android_library target(s) for the same sources. 149 | """, 150 | ), 151 | "doctitle": attr.string( 152 | default = "", 153 | doc = "Title for generated index.html. See javadoc -doctitle.", 154 | ), 155 | "groups": attr.string_list_dict( 156 | doc = "Groups specified packages together in overview page. See javadoc -groups.", 157 | ), 158 | "root_packages": attr.string_list( 159 | doc = """ 160 | Java packages to include in generated Javadoc. Any subpackages not listed in 161 | exclude_packages will be included as well. If none are provided, each file in 162 | `srcs` is processed. 163 | """, 164 | ), 165 | "exclude_packages": attr.string_list( 166 | doc = "Java packages to exclude from generated Javadoc.", 167 | ), 168 | "android_api_level": attr.int( 169 | default = -1, 170 | doc = """ 171 | If Android APIs are used, the API level to compile against to generate Javadoc. 172 | """, 173 | ), 174 | "bottom_text": attr.string( 175 | default = "", 176 | doc = "Text passed to Javadoc's `-bottom` flag.", 177 | ), 178 | "external_javadoc_links": attr.string_list( 179 | doc = "URLs passed to Javadoc's `-linkoffline` flag.", 180 | ), 181 | "_android_jar": attr.label( 182 | default = _android_jar, 183 | allow_single_file = True, 184 | ), 185 | "_jdk": attr.label( 186 | default = Label("@bazel_tools//tools/jdk:current_java_runtime"), 187 | providers = [java_common.JavaRuntimeInfo], 188 | ), 189 | }, 190 | outputs = {"jar": "%{name}.jar"}, 191 | doc = "Generates a Javadoc jar path/to/target/.jar.", 192 | implementation = _javadoc_library, 193 | ) 194 | -------------------------------------------------------------------------------- /tools/maven/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Skylark rules for generating Maven pom files 16 | 17 | load(":pom_file.bzl", "pom_file_tests") 18 | 19 | # TODO(ronshapiro): Set up a travis build 20 | pom_file_tests() 21 | -------------------------------------------------------------------------------- /tools/maven/pom_file.bzl: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2018 The Google Bazel Common Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Skylark rules to make publishing Maven artifacts simpler. 15 | """ 16 | 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") 19 | 20 | MavenInfo = provider( 21 | fields = { 22 | "maven_artifacts": """ 23 | The Maven coordinates for the artifacts that are exported by this target: i.e. the target 24 | itself and its transitively exported targets. 25 | """, 26 | "maven_dependencies": """ 27 | The Maven coordinates of the direct dependencies, and the transitively exported targets, of 28 | this target. 29 | """, 30 | }, 31 | ) 32 | 33 | _EMPTY_MAVEN_INFO = MavenInfo( 34 | maven_artifacts = depset(), 35 | maven_dependencies = depset(), 36 | ) 37 | 38 | _MAVEN_COORDINATES_PREFIX = "maven_coordinates=" 39 | 40 | def _maven_artifacts(targets): 41 | return [target[MavenInfo].maven_artifacts for target in targets if MavenInfo in target] 42 | 43 | def _collect_maven_info_impl(_target, ctx): 44 | tags = getattr(ctx.rule.attr, "tags", []) 45 | deps = getattr(ctx.rule.attr, "deps", []) 46 | exports = getattr(ctx.rule.attr, "exports", []) 47 | runtime_deps = getattr(ctx.rule.attr, "runtime_deps", []) 48 | 49 | maven_artifacts = [] 50 | for tag in tags: 51 | if tag in ("maven:compile_only", "maven:shaded"): 52 | return [_EMPTY_MAVEN_INFO] 53 | if tag.startswith(_MAVEN_COORDINATES_PREFIX): 54 | maven_artifacts.append(tag[len(_MAVEN_COORDINATES_PREFIX):]) 55 | 56 | return [MavenInfo( 57 | maven_artifacts = depset(maven_artifacts, transitive = _maven_artifacts(exports)), 58 | maven_dependencies = depset( 59 | [], 60 | transitive = _maven_artifacts(deps + exports + runtime_deps), 61 | ), 62 | )] 63 | 64 | _collect_maven_info = aspect( 65 | attr_aspects = [ 66 | "deps", 67 | "exports", 68 | "runtime_deps", 69 | ], 70 | doc = """ 71 | Collects the Maven information for targets, their dependencies, and their transitive exports. 72 | """, 73 | implementation = _collect_maven_info_impl, 74 | ) 75 | 76 | def _prefix_index_of(item, prefixes): 77 | """Returns the index of the first value in `prefixes` that is a prefix of `item`. 78 | 79 | If none of the prefixes match, return the size of `prefixes`. 80 | 81 | Args: 82 | item: the item to match 83 | prefixes: prefixes to match against 84 | 85 | Returns: 86 | an integer representing the index of the match described above. 87 | """ 88 | for index, prefix in enumerate(prefixes): 89 | if item.startswith(prefix): 90 | return index 91 | return len(prefixes) 92 | 93 | def _sort_artifacts(artifacts, prefixes): 94 | """Sorts `artifacts`, preferring group ids that appear earlier in `prefixes`. 95 | 96 | Values in `prefixes` do not need to be complete group ids. For example, passing `prefixes = 97 | ['io.bazel']` will match `io.bazel.rules:rules-artifact:1.0`. If multiple prefixes match an 98 | artifact, the first one in `prefixes` will be used. 99 | 100 | _Implementation note_: Skylark does not support passing a comparator function to the `sorted()` 101 | builtin, so this constructs a list of tuples with elements: 102 | - `[0]` = an integer corresponding to the index in `prefixes` that matches the artifact (see 103 | `_prefix_index_of`) 104 | - `[1]` = parts of the complete artifact, split on `:`. This is used as a tiebreaker when 105 | multilple artifacts have the same index referenced in `[0]`. The individual parts are used so 106 | that individual artifacts in the same group are sorted correctly - if just the string is used, 107 | the colon that separates the artifact name from the version will sort lower than a longer 108 | name. For example: 109 | - `com.example.project:base:1 110 | - `com.example.project:extension:1 111 | "base" sorts lower than "exension". 112 | - `[2]` = the complete artifact. this is a convenience so that after sorting, the artifact can 113 | be returned. 114 | 115 | The `sorted` builtin will first compare the index element and if it needs a tiebreaker, will 116 | recursively compare the contents of the second element. 117 | 118 | Args: 119 | artifacts: artifacts to be sorted 120 | prefixes: the preferred group ids used to sort `artifacts` 121 | 122 | Returns: 123 | A new, sorted list containing the contents of `artifacts`. 124 | """ 125 | indexed = [] 126 | for artifact in artifacts: 127 | parts = artifact.split(":") 128 | indexed.append((_prefix_index_of(parts[0], prefixes), parts, artifact)) 129 | 130 | return [x[-1] for x in sorted(indexed)] 131 | 132 | DEP_BLOCK = """ 133 | 134 | {0} 135 | {1} 136 | {2} 137 | 138 | """.strip() 139 | 140 | CLASSIFIER_DEP_BLOCK = """ 141 | 142 | {0} 143 | {1} 144 | {2} 145 | {3} 146 | {4} 147 | 148 | """.strip() 149 | 150 | DEP_PKG_BLOCK = """ 151 | 152 | {0} 153 | {1} 154 | {2} 155 | {3} 156 | 157 | """.strip() 158 | 159 | def _pom_file(ctx): 160 | mvn_deps = depset( 161 | [], 162 | transitive = [target[MavenInfo].maven_dependencies for target in ctx.attr.targets], 163 | ) 164 | 165 | formatted_deps = [] 166 | for dep in _sort_artifacts(mvn_deps.to_list(), ctx.attr.preferred_group_ids): 167 | parts = dep.split(":") 168 | if ":".join(parts[0:2]) in ctx.attr.excluded_artifacts: 169 | continue 170 | if len(parts) == 3: 171 | template = DEP_BLOCK 172 | elif len(parts) == 4: 173 | template = DEP_PKG_BLOCK 174 | elif len(parts) == 5: 175 | template = CLASSIFIER_DEP_BLOCK 176 | else: 177 | fail("Unknown dependency format: %s" % dep) 178 | 179 | formatted_deps.append(template.format(*parts)) 180 | 181 | substitutions = {} 182 | substitutions.update(ctx.attr.substitutions) 183 | substitutions.update({ 184 | "{generated_bzl_deps}": "\n".join(formatted_deps), 185 | "{pom_version}": ctx.var.get("pom_version", "LOCAL-SNAPSHOT"), 186 | }) 187 | 188 | ctx.actions.expand_template( 189 | template = ctx.file.template_file, 190 | output = ctx.outputs.pom_file, 191 | substitutions = substitutions, 192 | ) 193 | 194 | pom_file = rule( 195 | attrs = { 196 | "template_file": attr.label( 197 | allow_single_file = True, 198 | ), 199 | "substitutions": attr.string_dict( 200 | allow_empty = True, 201 | mandatory = False, 202 | ), 203 | "targets": attr.label_list( 204 | mandatory = True, 205 | aspects = [_collect_maven_info], 206 | ), 207 | "preferred_group_ids": attr.string_list(), 208 | "excluded_artifacts": attr.string_list(), 209 | }, 210 | doc = """ 211 | Creates a Maven POM file for `targets`. 212 | 213 | This rule scans the deps, runtime_deps, and exports of `targets` and their transitive exports, 214 | checking each for tags of the form `maven_coordinates=`. These tags are used to build 215 | the list of Maven dependencies for the generated POM. 216 | 217 | Users should call this rule with a `template_file` that contains a `{generated_bzl_deps}` 218 | placeholder. The rule will replace this with the appropriate XML for all dependencies. 219 | Additional placeholders to replace can be passed via the `substitutions` argument. 220 | 221 | The dependencies included will be sorted alphabetically by groupId, then by artifactId. The 222 | `preferred_group_ids` can be used to specify groupIds (or groupId-prefixes) that should be 223 | sorted ahead of other artifacts. Artifacts in the same group will be sorted alphabetically. 224 | 225 | Args: 226 | name: the name of target. The generated POM file will use this name, with `.xml` appended 227 | targets: a list of build target(s) that represent this POM file 228 | template_file: a pom.xml file that will be used as a template for the generated POM 229 | substitutions: an optional mapping of placeholders to replacement values that will be applied 230 | to the `template_file` (e.g. `{'GROUP_ID': 'com.example.group'}`). `{pom_version}` is 231 | implicitly included in this mapping and can be configured by passing `bazel build 232 | --define=pom_version=`. 233 | preferred_group_ids: an optional list of maven groupIds that will be used to sort the 234 | generated deps. 235 | excluded_artifacts: an optional list of maven artifacts in the format "groupId:artifactId" 236 | that should be excluded from the generated pom file. 237 | """, 238 | outputs = {"pom_file": "%{name}.xml"}, 239 | implementation = _pom_file, 240 | ) 241 | 242 | def _fake_java_library(name, deps = None, exports = None, runtime_deps = None): 243 | src_file = ["%s.java" % name] 244 | native.genrule( 245 | name = "%s_source_file" % name, 246 | outs = src_file, 247 | cmd = "echo 'class %s {}' > $@" % name, 248 | ) 249 | java_library( 250 | name = name, 251 | srcs = src_file, 252 | tags = ["maven_coordinates=%s:_:_" % name], 253 | javacopts = ["-Xep:DefaultPackage:OFF"], 254 | deps = deps or [], 255 | exports = exports or [], 256 | runtime_deps = runtime_deps or [], 257 | ) 258 | 259 | def _maven_info_test_impl(ctx): 260 | env = unittest.begin(ctx) 261 | asserts.equals( 262 | env, 263 | expected = sorted(ctx.attr.maven_artifacts), 264 | actual = sorted(ctx.attr.target[MavenInfo].maven_artifacts.to_list()), 265 | msg = "MavenInfo.maven_artifacts", 266 | ) 267 | asserts.equals( 268 | env, 269 | expected = sorted(ctx.attr.maven_dependencies), 270 | actual = sorted(ctx.attr.target[MavenInfo].maven_dependencies.to_list()), 271 | msg = "MavenInfo.maven_dependencies", 272 | ) 273 | return unittest.end(env) 274 | 275 | _maven_info_test = unittest.make( 276 | _maven_info_test_impl, 277 | attrs = { 278 | "target": attr.label(aspects = [_collect_maven_info]), 279 | "maven_artifacts": attr.string_list(), 280 | "maven_dependencies": attr.string_list(), 281 | }, 282 | ) 283 | 284 | def pom_file_tests(): 285 | """Tests for `pom_file` and `MavenInfo`. 286 | """ 287 | _fake_java_library(name = "A") 288 | _fake_java_library( 289 | name = "DepOnA", 290 | deps = [":A"], 291 | ) 292 | 293 | _maven_info_test( 294 | name = "a_test", 295 | target = ":A", 296 | maven_artifacts = ["A:_:_"], 297 | maven_dependencies = [], 298 | ) 299 | 300 | _maven_info_test( 301 | name = "dependencies_test", 302 | target = ":DepOnA", 303 | maven_artifacts = ["DepOnA:_:_"], 304 | maven_dependencies = ["A:_:_"], 305 | ) 306 | 307 | _fake_java_library( 308 | name = "RuntimeDepOnA", 309 | runtime_deps = [":A"], 310 | ) 311 | 312 | _maven_info_test( 313 | name = "runtime_dependencies_test", 314 | target = ":RuntimeDepOnA", 315 | maven_artifacts = ["RuntimeDepOnA:_:_"], 316 | maven_dependencies = ["A:_:_"], 317 | ) 318 | 319 | _fake_java_library( 320 | name = "ExportsA", 321 | exports = [":A"], 322 | ) 323 | 324 | _maven_info_test( 325 | name = "exports_test", 326 | target = ":ExportsA", 327 | maven_artifacts = [ 328 | "ExportsA:_:_", 329 | "A:_:_", 330 | ], 331 | maven_dependencies = ["A:_:_"], 332 | ) 333 | 334 | _fake_java_library( 335 | name = "TransitiveExports", 336 | exports = [":ExportsA"], 337 | ) 338 | 339 | _maven_info_test( 340 | name = "transitive_exports_test", 341 | target = ":TransitiveExports", 342 | maven_artifacts = [ 343 | "TransitiveExports:_:_", 344 | "ExportsA:_:_", 345 | "A:_:_", 346 | ], 347 | maven_dependencies = [ 348 | "ExportsA:_:_", 349 | "A:_:_", 350 | ], 351 | ) 352 | 353 | _fake_java_library( 354 | name = "TransitiveDeps", 355 | deps = [":ExportsA"], 356 | ) 357 | 358 | _maven_info_test( 359 | name = "transitive_deps_test", 360 | target = ":TransitiveDeps", 361 | maven_artifacts = ["TransitiveDeps:_:_"], 362 | maven_dependencies = [ 363 | "ExportsA:_:_", 364 | "A:_:_", 365 | ], 366 | ) 367 | --------------------------------------------------------------------------------