Skip to content

Commit 3b117e1

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

12 files changed

Lines changed: 43 additions & 10 deletions

File tree

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

Lines changed: 9 additions & 8 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

0 commit comments

Comments
 (0)