Skip to content

Commit f2d8427

Browse files
joerg1985diemol
andauthored
[java] make external modules static (#12294)
Co-authored-by: Diego Molina <[email protected]>
1 parent 3926580 commit f2d8427

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static net.bytebuddy.jar.asm.Opcodes.ACC_MANDATED;
2222
import static net.bytebuddy.jar.asm.Opcodes.ACC_MODULE;
2323
import static net.bytebuddy.jar.asm.Opcodes.ACC_OPEN;
24+
import static net.bytebuddy.jar.asm.Opcodes.ACC_STATIC_PHASE;
2425
import static net.bytebuddy.jar.asm.Opcodes.ACC_TRANSITIVE;
2526
import static net.bytebuddy.jar.asm.Opcodes.ASM9;
2627

@@ -491,7 +492,13 @@ public void visit(ModuleRequiresDirective n, Void arg) {
491492
// name. Therefore, the 'processed.' prefix added by bazel must be removed to get the name.
492493
name = name.substring(10);
493494
}
494-
byteBuddyVisitor.visitRequire(name, getByteBuddyModifier(n.getModifiers()), null);
495+
int modifiers = getByteBuddyModifier(n.getModifiers());
496+
if (!name.startsWith("org.seleniumhq.selenium.") && !name.startsWith("java.")) {
497+
// Some people like to exclude jars from the classpath. To allow this we need to make these modules static,
498+
// otherwise a 'module not found' error while compiling their code would be the consequence.
499+
modifiers |= ACC_STATIC_PHASE;
500+
}
501+
byteBuddyVisitor.visitRequire(name, modifiers, null);
495502
}
496503

497504
@Override
@@ -530,8 +537,11 @@ private int getByteBuddyModifier(NodeList<Modifier> modifiers) {
530537
return modifiers.stream()
531538
.mapToInt(
532539
mod -> {
533-
if (mod.getKeyword() == Modifier.Keyword.TRANSITIVE) {
534-
return ACC_TRANSITIVE;
540+
switch (mod.getKeyword()) {
541+
case STATIC:
542+
return ACC_STATIC_PHASE;
543+
case TRANSITIVE:
544+
return ACC_TRANSITIVE;
535545
}
536546
throw new RuntimeException("Unknown modifier: " + mod);
537547
})

0 commit comments

Comments
 (0)