| 1 |
"""Java options and protobuf-specific java build rules with those options.""" |
| 2 |
|
| 3 |
load("@rules_java//java:defs.bzl", "java_library") |
| 4 |
load("@rules_jvm_external//:defs.bzl", "java_export") |
| 5 |
load("//java/osgi:osgi.bzl", "osgi_java_library") |
| 6 |
load("//:protobuf_version.bzl", "PROTOBUF_JAVA_VERSION") |
| 7 |
|
| 8 |
JAVA_OPTS = [ |
| 9 |
"-source 8", |
| 10 |
"-target 8", |
| 11 |
"-Xep:Java8ApiChecker:ERROR", |
| 12 |
] |
| 13 |
|
| 14 |
BUNDLE_DOC_URL = "https://developers.google.com/protocol-buffers/" |
| 15 |
BUNDLE_LICENSE = "https://opensource.org/licenses/BSD-3-Clause" |
| 16 |
|
| 17 |
def protobuf_java_export(**kwargs): |
| 18 |
java_export( |
| 19 |
javacopts = JAVA_OPTS, |
| 20 |
**kwargs |
| 21 |
) |
| 22 |
|
| 23 |
def protobuf_java_library(**kwargs): |
| 24 |
java_library( |
| 25 |
javacopts = JAVA_OPTS, |
| 26 |
**kwargs |
| 27 |
) |
| 28 |
|
| 29 |
def protobuf_versioned_java_library( |
| 30 |
bundle_description, |
| 31 |
bundle_name, |
| 32 |
bundle_symbolic_name, |
| 33 |
bundle_additional_imports = [], |
| 34 |
bundle_additional_exports = [], |
| 35 |
**kwargs): |
| 36 |
"""Extends `java_library` to add OSGi headers to the MANIFEST.MF using bndlib |
| 37 |
|
| 38 |
This macro should be usable as a drop-in replacement for java_library. |
| 39 |
|
| 40 |
The additional arguments are given the bndlib tool to generate an OSGi-compliant manifest file. |
| 41 |
See [bnd documentation](https://bnd.bndtools.org/chapters/110-introduction.html) |
| 42 |
|
| 43 |
Takes all the args that are standard for a java_library target plus the following. |
| 44 |
Args: |
| 45 |
bundle_description: (required) The Bundle-Description header defines a short |
| 46 |
description of this bundle. |
| 47 |
bundle_name: (required) The Bundle-Name header defines a readable name for this |
| 48 |
bundle. This should be a short, human-readable name that can |
| 49 |
contain spaces. |
| 50 |
bundle_symbolic_name: (required) The Bundle-SymbolicName header specifies a |
| 51 |
non-localizable name for this bundle. The bundle symbolic name |
| 52 |
together with a version must identify a unique bundle though it can |
| 53 |
be installed multiple times in a framework. The bundle symbolic |
| 54 |
name should be based on the reverse domain name convention. |
| 55 |
bundle_additional_exports: The Export-Package header contains a |
| 56 |
declaration of exported packages. These are additional export |
| 57 |
package statements to be added before the default wildcard export |
| 58 |
"*;version={$Bundle-Version}". |
| 59 |
bundle_additional_imports: The Import-Package header declares the |
| 60 |
imported packages for this bundle. These are additional import |
| 61 |
package statements to be added before the default wildcard import |
| 62 |
"*". |
| 63 |
**kwargs: Additional key-word arguments that are passed to the internal |
| 64 |
java_library target. |
| 65 |
""" |
| 66 |
osgi_java_library( |
| 67 |
javacopts = JAVA_OPTS, |
| 68 |
bundle_doc_url = BUNDLE_DOC_URL, |
| 69 |
bundle_license = BUNDLE_LICENSE, |
| 70 |
bundle_version = PROTOBUF_JAVA_VERSION, |
| 71 |
bundle_description = bundle_description, |
| 72 |
bundle_name = bundle_name, |
| 73 |
bundle_symbolic_name = bundle_symbolic_name, |
| 74 |
bundle_additional_exports = bundle_additional_exports, |
| 75 |
bundle_additional_imports = bundle_additional_imports + ["sun.misc;resolution:=optional"], |
| 76 |
**kwargs |
| 77 |
) |