Implementation:SeleniumHQ Selenium ModuleGenerator
| Knowledge Sources | |
|---|---|
| Domains | WebDriver, Build_Tooling |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
ModuleGenerator is a Bazel build tool that generates Java Platform Module System (JPMS) module-info.class descriptors for Selenium JAR artifacts.
Description
The ModuleGenerator class automates the creation of Java module descriptors (module-info.class) for Selenium's modular JAR files. It works by:
- Accepting an input JAR, a module name, and configuration flags (exports, hides, uses, opens-to, module-path).
- Running the JDK's
jdepstool with--generate-module-infoto produce an initialmodule-info.javafrom the input JAR. - Parsing the generated
module-info.javausing JavaParser to obtain the module declaration AST. - Customizing the module declaration by setting the module name, open status, exported/hidden packages,
usesdirectives (including those detected by scanning forServiceLoader.load()calls via ASM bytecode analysis), andopensdirectives. - Compiling the final module descriptor to bytecode using ByteBuddy's ASM
ClassWriterandModuleVisitor. - Writing the resulting
module-info.classinto an output JAR.
The tool also handles automatic module name normalization (stripping processed_ prefixes added by Bazel), marks non-Selenium/non-JDK modules as static (so users can optionally exclude transitive dependencies), and infers packages from class entries in the input JAR (including multi-release JAR support).
Usage
This tool is invoked as part of the Bazel build pipeline for Selenium's Java bindings. It is not intended for direct end-user invocation. It is called with command-line flags to produce a module-info JAR that is merged with the main artifact JAR during the build process.
Code Reference
Source Location
- Repository: SeleniumHQ_Selenium
- File: java/src/dev/selenium/tools/modules/ModuleGenerator.java
Signature
public class ModuleGenerator {
public static void main(String[] args) throws IOException
private static Collection<String> readServicesFromClasses(Path inJar)
private static Set<String> inferPackages(Path inJar)
private static class MyModuleVisitor extends VoidVisitorAdapter<Void> {
MyModuleVisitor(ClassLoader classLoader, Set<String> packages,
Set<String> excluded, ModuleVisitor byteBuddyVisitor)
public void visit(ModuleRequiresDirective n, Void arg)
public void visit(ModuleExportsDirective n, Void arg)
public void visit(ModuleProvidesDirective n, Void arg)
public void visit(ModuleUsesDirective n, Void arg)
public void visit(ModuleOpensDirective n, Void arg)
}
}
Import
import dev.selenium.tools.modules.ModuleGenerator;
I/O Contract
| Flag | Type | Required | Description |
|---|---|---|---|
--in |
Path | Yes | Path to the input JAR to analyze |
--output |
Path | Yes | Path for the output JAR containing module-info.class |
--module-name |
String | Yes | The Java module name to assign (e.g., org.seleniumhq.selenium.api)
|
--module-path |
Path | No (repeatable) | JARs to include on the module path for jdeps analysis |
--exports |
String | No (repeatable) | Package names to export; if omitted, all packages except hidden ones are exported |
--hides |
String | No (repeatable) | Package names to hide (not export) |
--uses |
String | No (repeatable) | Fully-qualified service interface names for uses directives
|
--is-open |
Boolean | No | Whether the module is an open module |
--open-to |
String | No (repeatable) | Module names to open all exported packages to |
--opens-to |
String String | No (repeatable) | Package and target module for specific opens directives |
| Artifact | Description |
|---|---|
| Output JAR | A JAR containing a single module-info.class with the generated JPMS module descriptor
|
Usage Examples
# Typical invocation via Bazel (conceptual, not run directly):
java -cp <classpath> dev.selenium.tools.modules.ModuleGenerator \
--in bazel-bin/java/src/org/openqa/selenium/libapi.jar \
--output bazel-bin/java/src/org/openqa/selenium/module-info.jar \
--module-name org.seleniumhq.selenium.api \
--module-path third_party/guava.jar \
--exports org.openqa.selenium \
--exports org.openqa.selenium.logging \
--hides org.openqa.selenium.internal \
--uses org.openqa.selenium.remote.locator.CustomLocator
Related Pages
- SeleniumHQ_Selenium_Bazel_Build_And_Go_Wrapper - Bazel build and Go wrapper tooling
- SeleniumHQ_Selenium_CdpClientGenerator - Another Java code generation build tool
- SeleniumHQ_Selenium_Architecture - Overall Selenium architecture