Skip to content

Commit

Permalink
[java] make external modules static (#12294)
Browse files Browse the repository at this point in the history
Co-authored-by: Diego Molina <diemol@users.noreply.github.com>
  • Loading branch information
joerg1985 and diemol authored Jul 31, 2023
1 parent 3926580 commit f2d8427
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions java/src/dev/selenium/tools/modules/ModuleGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static net.bytebuddy.jar.asm.Opcodes.ACC_MANDATED;
import static net.bytebuddy.jar.asm.Opcodes.ACC_MODULE;
import static net.bytebuddy.jar.asm.Opcodes.ACC_OPEN;
import static net.bytebuddy.jar.asm.Opcodes.ACC_STATIC_PHASE;
import static net.bytebuddy.jar.asm.Opcodes.ACC_TRANSITIVE;
import static net.bytebuddy.jar.asm.Opcodes.ASM9;

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

@Override
Expand Down Expand Up @@ -530,8 +537,11 @@ private int getByteBuddyModifier(NodeList<Modifier> modifiers) {
return modifiers.stream()
.mapToInt(
mod -> {
if (mod.getKeyword() == Modifier.Keyword.TRANSITIVE) {
return ACC_TRANSITIVE;
switch (mod.getKeyword()) {
case STATIC:
return ACC_STATIC_PHASE;
case TRANSITIVE:
return ACC_TRANSITIVE;
}
throw new RuntimeException("Unknown modifier: " + mod);
})
Expand Down

0 comments on commit f2d8427

Please sign in to comment.