Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:SeleniumHQ Selenium ModuleGenerator

From Leeroopedia
Revision as of 11:51, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/SeleniumHQ_Selenium_ModuleGenerator.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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:

  1. Accepting an input JAR, a module name, and configuration flags (exports, hides, uses, opens-to, module-path).
  2. Running the JDK's jdeps tool with --generate-module-info to produce an initial module-info.java from the input JAR.
  3. Parsing the generated module-info.java using JavaParser to obtain the module declaration AST.
  4. Customizing the module declaration by setting the module name, open status, exported/hidden packages, uses directives (including those detected by scanning for ServiceLoader.load() calls via ASM bytecode analysis), and opens directives.
  5. Compiling the final module descriptor to bytecode using ByteBuddy's ASM ClassWriter and ModuleVisitor.
  6. Writing the resulting module-info.class into 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

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

Inputs (Command-Line Flags)
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
Output
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

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment