1# Copyright 2020 Google LLC 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""" Definition of gen_maven_jar_rules. """ 16 17load("//tools:jar_jar.bzl", "jar_jar") 18load("//tools:java_single_jar.bzl", "java_single_jar") 19load("//tools:javadoc.bzl", "javadoc_library") 20 21_EXTERNAL_JAVADOC_LINKS = [ 22 "https://docs.oracle.com/javase/8/docs/api/", 23 "https://developer.android.com/reference/", 24] 25 26_TINK_PACKAGES = [ 27 "com.google.crypto.tink", 28] 29 30def gen_maven_jar_rules( 31 name, 32 deps = [], 33 resources = [], 34 root_packages = _TINK_PACKAGES, 35 shaded_packages = [], 36 shading_rules = "", 37 exclude_packages = [], 38 doctitle = "", 39 android_api_level = 23, 40 bottom_text = "", 41 external_javadoc_links = _EXTERNAL_JAVADOC_LINKS, 42 manifest_lines = []): 43 """ 44 Generates rules that generate Maven jars for a given package. 45 46 Args: 47 name: Given a name, this function generates 3 rules: a compiled package 48 name.jar, a source package name-src.jar and a Javadoc package 49 name-javadoc.jar. 50 deps: A combination of the deps of java_single_jar and javadoc_library 51 resources: A list of resource files. Files must be stored in 52 src/main/resources. Mapping rules: src/main/resources/a/b/c.txt will be 53 copied to a/b/c.txt in the output jar. 54 root_packages: See javadoc_library 55 shaded_packages: These packages will be shaded, according to the rules 56 specified in shading_rules. 57 shading_rules: The shading rules, must specified when shaded_packages is present. 58 Rules file format can be found at https://github.com/bazelbuild/bazel/blob/master/third_party/jarjar/java/com/tonicsystems/jarjar/help.txt. 59 exclude_packages: See javadoc_library 60 doctitle: See javadoc_library 61 android_api_level: See javadoc_library 62 bottom_text: See javadoc_library 63 external_javadoc_links: See javadoc_library 64 manifest_lines: lines to put in the output manifest file (manifest 65 files in the input jars are ignored) 66 """ 67 68 if shaded_packages: 69 unshaded_jar = name + "-unshaded" 70 java_single_jar( 71 name = unshaded_jar, 72 deps = deps, 73 resources = resources, 74 root_packages = root_packages + shaded_packages, 75 manifest_lines = manifest_lines, 76 ) 77 jar_jar( 78 name = name, 79 input_jar = unshaded_jar, 80 rules = shading_rules, 81 ) 82 else: 83 java_single_jar( 84 name = name, 85 deps = deps, 86 resources = resources, 87 root_packages = root_packages, 88 manifest_lines = manifest_lines, 89 ) 90 91 source_jar_name = name + "-src" 92 java_single_jar( 93 name = source_jar_name, 94 deps = deps, 95 root_packages = root_packages, 96 source_jar = True, 97 ) 98 99 javadoc_name = name + "-javadoc" 100 javadoc_library( 101 name = javadoc_name, 102 deps = deps, 103 root_packages = root_packages, 104 srcs = [":%s" % source_jar_name], 105 doctitle = doctitle, 106 exclude_packages = exclude_packages, 107 android_api_level = android_api_level, 108 bottom_text = bottom_text, 109 external_javadoc_links = external_javadoc_links, 110 ) 111