Skip to content

Commit 3b117e1

Browse files
committed
[bazel] Allow packages to be opened in modules
1 parent 3c96350 commit 3b117e1

File tree

12 files changed

+43
-10
lines changed

12 files changed

+43
-10
lines changed

java/buildtools/src/dev/selenium/tools/modules/ModuleGenerator.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@
7777
import java.util.zip.ZipOutputStream;
7878

7979
import static com.github.javaparser.ParseStart.COMPILATION_UNIT;
80-
import static net.bytebuddy.jar.asm.Opcodes.ACC_MANDATED;
81-
import static net.bytebuddy.jar.asm.Opcodes.ACC_MODULE;
82-
import static net.bytebuddy.jar.asm.Opcodes.ACC_OPEN;
83-
import static net.bytebuddy.jar.asm.Opcodes.ACC_TRANSITIVE;
80+
import static net.bytebuddy.jar.asm.Opcodes.*;
8481

8582
public class ModuleGenerator {
8683

@@ -277,7 +274,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
277274
ModuleVisitor moduleVisitor = classWriter.visitModule(moduleName, isOpen ? ACC_OPEN : 0, null);
278275
moduleVisitor.visitRequire("java.base", ACC_MANDATED, null);
279276

280-
moduleDeclaration.accept(new MyModuleVisitor(classLoader, hides, moduleVisitor), null);
277+
moduleDeclaration.accept(new MyModuleVisitor(classLoader, exportedPackages, hides, moduleVisitor), null);
281278

282279
moduleVisitor.visitEnd();
283280

@@ -360,13 +357,16 @@ private static Set<String> inferPackages(Path inJar) {
360357
private static class MyModuleVisitor extends VoidVisitorAdapter<Void> {
361358

362359
private final ClassLoader classLoader;
363-
private Set<String> seenExports;
360+
private final Set<String> seenExports;
361+
private final Set<String> packages;
364362
private final ModuleVisitor byteBuddyVisitor;
365363

366-
MyModuleVisitor(ClassLoader classLoader, Set<String> excluded, ModuleVisitor byteBuddyVisitor) {
364+
MyModuleVisitor(ClassLoader classLoader, Set<String> packages, Set<String> excluded, ModuleVisitor byteBuddyVisitor) {
367365
this.classLoader = classLoader;
368366
this.byteBuddyVisitor = byteBuddyVisitor;
367+
369368
// Set is modifiable
369+
this.packages = new HashSet<>(packages);
370370
this.seenExports = new HashSet<>(excluded);
371371
}
372372

@@ -408,7 +408,8 @@ public void visit(ModuleUsesDirective n, Void arg) {
408408

409409
@Override
410410
public void visit(ModuleOpensDirective n, Void arg) {
411-
throw new UnsupportedOperationException(n.toString());
411+
// packages.forEach(pkg -> byteBuddyVisitor.visitOpen(pkg, ACC_MANDATED | ACC_SYNTHETIC, n.getNameAsString()));
412+
packages.forEach(pkg -> byteBuddyVisitor.visitOpen(pkg.replace('.', '/'), 0, n.getNameAsString()));
412413
}
413414

414415
private int getByteBuddyModifier(NodeList<Modifier> modifiers) {

java/client/src/org/openqa/selenium/BUILD.bazel

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ java_export(
3131
"org.openqa.selenium.interactions.internal",
3232
"org.openqa.selenium.internal",
3333
],
34+
opens_to = [
35+
"org.openqa.selenium.json",
36+
],
3437
maven_coordinates = "org.seleniumhq.selenium:selenium-api:%s" % SE_VERSION,
3538
pom_template = ":template-pom",
3639
visibility = ["//visibility:public"],

java/client/src/org/openqa/selenium/devtools/BUILD.bazel

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ java_export(
5555
exports = [
5656
":devtools-prototypes",
5757
],
58+
opens_to = [
59+
"org.openqa.selenium.json",
60+
],
5861
deps = [
5962
":devtools-prototypes",
6063
"//java:auto-service",

java/client/src/org/openqa/selenium/devtools/v86/BUILD.bazel

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ java_export(
1414
exports = [
1515
":cdp",
1616
],
17+
opens_to = [
18+
"org.openqa.selenium.json",
19+
],
1720
deps = [
1821
":cdp",
1922
"//java:auto-service",

java/client/src/org/openqa/selenium/devtools/v87/BUILD.bazel

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ java_export(
1616
exports = [
1717
":cdp",
1818
],
19+
opens_to = [
20+
"org.openqa.selenium.json",
21+
],
1922
deps = [
2023
":cdp",
2124
"//java:auto-service",

java/client/src/org/openqa/selenium/devtools/v88/BUILD.bazel

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ java_export(
1616
exports = [
1717
":cdp",
1818
],
19+
opens_to = [
20+
"org.openqa.selenium.json",
21+
],
1922
deps = [
2023
":cdp",
2124
"//java:auto-service",

java/client/src/org/openqa/selenium/devtools/v89/BUILD.bazel

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ java_export(
1616
exports = [
1717
":cdp",
1818
],
19+
opens_to = [
20+
"org.openqa.selenium.json",
21+
],
1922
deps = [
2023
":cdp",
2124
"//java:auto-service",

java/client/src/org/openqa/selenium/remote/BUILD.bazel

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ java_export(
1515
":get-attribute",
1616
":is-displayed",
1717
],
18+
opens_to = [
19+
"org.openqa.selenium.json",
20+
],
1821
uses = [
1922
"org.openqa.selenium.remote.AugmenterProvider",
2023
"org.openqa.selenium.remote.session.CapabilitiesFilter",

java/client/src/org/openqa/selenium/support/BUILD.bazel

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ java_export(
2222
"//java/client/src/org/openqa/selenium/support/ui:elements",
2323
"//java/client/src/org/openqa/selenium/support/ui:wait",
2424
],
25+
opens_to = [
26+
"org.openqa.selenium.json",
27+
],
2528
deps = [
2629
":page-factory",
2730
"//java/client/src/org/openqa/selenium:core",

java/private/export.bzl

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def java_export(
1313
pom_template = None,
1414
hides = [],
1515
uses = [],
16+
opens_to = [],
1617
exports = [],
1718
tags = [],
1819
visibility = None,
@@ -56,6 +57,7 @@ def java_export(
5657
target = "%s-project" % name,
5758
deps = kwargs.get("deps", []) + kwargs.get("runtime_deps", []),
5859
exports = exports,
60+
opens_to = opens_to,
5961
tags = tags,
6062
)
6163

java/private/module.bzl

+5-2
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,16 @@ def _java_module_impl(ctx):
105105
module_info_jar = ctx.actions.declare_file("%s-module-info.jar" % ctx.attr.name)
106106
args = ctx.actions.args()
107107
args.add_all(["--module-name", name])
108-
# args.add_all(["--in", raw_merged_jar])
109108
args.add_all(["--in", ctx.file.target])
110109
args.add_all(["--output", module_info_jar])
111110
args.add_all(ctx.attr.hides, before_each = "--hides")
112111
args.add_all(ctx.attr.uses, before_each = "--uses")
113112
args.add_all(module_path_jars, before_each = "--module-path")
113+
args.add_all(ctx.attr.opens_to, before_each = "--open-to")
114114

115115
ctx.actions.run(
116116
executable = ctx.executable._module_generator,
117117
outputs = [module_info_jar],
118-
# inputs = depset([raw_merged_jar], transitive = [info.module_path for info in all_infos]),
119118
inputs = depset([ctx.file.target], transitive = [info.module_path for info in all_infos]),
120119
arguments = [args],
121120
)
@@ -211,6 +210,10 @@ java_module = rule(
211210
doc = "List of package names to hide",
212211
default = [],
213212
),
213+
"opens_to": attr.string_list(
214+
doc = "List of modules this module is open to",
215+
default = [],
216+
),
214217
"uses": attr.string_list(
215218
doc = "List of classnames that the module uses",
216219
default = [],

java/server/src/org/openqa/selenium/grid/BUILD.bazel

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ java_export(
6060
"org.openqa.selenium.remote.locators.CustomLocator",
6161
"org.openqa.selenium.remote.service.DriverService$Builder",
6262
],
63+
opens_to = [
64+
"org.openqa.selenium.json",
65+
],
6366
visibility = [
6467
"//visibility:public",
6568
],

0 commit comments

Comments
 (0)