Skip to content

Commit d580fde

Browse files
Clayton Walkercopybara-github
authored andcommitted
Add Automatic-Module-Name (#14562)
Adds Automatic-Module-Name after it was lost during the maven-bazel migration (and subsequent re-addition of osgi bundle support). Updates OsgiWrapper to support adding the Automatic-Module-Name header to the list of properties supported by the `osgi_java_library` rule. Fixes #12639 Closes #14562 COPYBARA_INTEGRATE_REVIEW=#14562 from Sineaggi:add-automatic-module-name a27b3e6 PiperOrigin-RevId: 579748655
1 parent 0a2fe57 commit d580fde

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

build_defs/java_opts.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def protobuf_java_library(**kwargs):
2727
)
2828

2929
def protobuf_versioned_java_library(
30+
automatic_module_name,
3031
bundle_description,
3132
bundle_name,
3233
bundle_symbolic_name,
@@ -44,6 +45,9 @@ def protobuf_versioned_java_library(
4445
Args:
4546
bundle_description: (required) The Bundle-Description header defines a short
4647
description of this bundle.
48+
automatic_module_name: (required) The Automatic-Module-Name header that represents
49+
the name of the module when this bundle is used as an automatic
50+
module.
4751
bundle_name: (required) The Bundle-Name header defines a readable name for this
4852
bundle. This should be a short, human-readable name that can
4953
contain spaces.
@@ -65,6 +69,7 @@ def protobuf_versioned_java_library(
6569
"""
6670
osgi_java_library(
6771
javacopts = JAVA_OPTS,
72+
automatic_module_name = automatic_module_name,
6873
bundle_doc_url = BUNDLE_DOC_URL,
6974
bundle_license = BUNDLE_LICENSE,
7075
bundle_version = PROTOBUF_JAVA_VERSION,

java/core/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ protobuf_versioned_java_library(
136136
srcs = LITE_SRCS + [
137137
":gen_well_known_protos_javalite",
138138
],
139+
automatic_module_name = "com.google.protobuf",
139140
bundle_description = "Lite version of Protocol Buffers library. This " +
140141
"version is optimized for code size, but does not " +
141142
"guarantee API/ABI stability.",
@@ -217,6 +218,7 @@ protobuf_versioned_java_library(
217218
) + [
218219
":gen_well_known_protos_java",
219220
],
221+
automatic_module_name = "com.google.protobuf",
220222
bundle_description = "Core Protocol Buffers library. Protocol Buffers " +
221223
"are a way of encoding structured data in an " +
222224
"efficient yet extensible format.",

java/osgi/OsgiWrapper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public final class OsgiWrapper implements Callable<Integer> {
5555
description = "The classpath that contains dependencies of the input jar, separated with :")
5656
private String classpath;
5757

58+
@Option(
59+
names = {"--automatic_module_name"},
60+
description = "The automatic module name of the bundle")
61+
private String automaticModuleName;
62+
5863
@Option(
5964
names = {"--bundle_copyright"},
6065
description = "Copyright string for the bundle")
@@ -106,6 +111,7 @@ public Integer call() throws Exception {
106111

107112
Analyzer analyzer = new Analyzer();
108113
analyzer.setJar(bin);
114+
analyzer.setProperty(Analyzer.AUTOMATIC_MODULE_NAME, automaticModuleName);
109115
analyzer.setProperty(Analyzer.BUNDLE_NAME, bundleName);
110116
analyzer.setProperty(Analyzer.BUNDLE_SYMBOLICNAME, bundleSymbolicName);
111117
analyzer.setProperty(Analyzer.BUNDLE_VERSION, bundleVersion);

java/osgi/osgi.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ load("@rules_java//java:defs.bzl", "java_library")
2323
# which is probably sub-optimal.
2424
def osgi_java_library(
2525
name,
26+
automatic_module_name,
2627
bundle_description,
2728
bundle_doc_url,
2829
bundle_license,
@@ -119,6 +120,7 @@ def osgi_java_library(
119120
# Repackage the jar with an OSGI manifest
120121
_osgi_jar(
121122
name = name,
123+
automatic_module_name = automatic_module_name,
122124
bundle_description = bundle_description,
123125
bundle_doc_url = bundle_doc_url,
124126
bundle_license = bundle_license,
@@ -141,6 +143,7 @@ def _run_osgi_wrapper(ctx, input_jar, classpath_jars, output_jar):
141143
args.add_joined("--classpath", classpath_jars, join_with = ":")
142144
args.add("--input_jar", input_jar.path)
143145
args.add("--output_jar", output_jar.path)
146+
args.add("--automatic_module_name", ctx.attr.automatic_module_name)
144147
args.add("--bundle_copyright", ctx.attr.bundle_copyright)
145148
args.add("--bundle_description", ctx.attr.bundle_description)
146149
args.add("--bundle_doc_url", ctx.attr.bundle_doc_url)
@@ -215,6 +218,7 @@ _osgi_jar = rule(
215218
"output_jar": "lib%{name}.jar",
216219
},
217220
attrs = {
221+
"automatic_module_name": attr.string(),
218222
"bundle_copyright": attr.string(),
219223
"bundle_description": attr.string(),
220224
"bundle_doc_url": attr.string(),

java/util/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ protobuf_versioned_java_library(
2626
srcs = glob([
2727
"src/main/java/com/google/protobuf/util/*.java",
2828
]),
29+
automatic_module_name = "com.google.protobuf.util",
2930
bundle_description = "Utilities for Protocol Buffers",
3031
bundle_name = "Protocol Buffers [Util]",
3132
bundle_symbolic_name = "com.google.protobuf.util",

0 commit comments

Comments
 (0)