Class ClassIndexWriter
java.lang.Object
cloud.opencode.base.classloader.index.ClassIndexWriter
Class Index Writer - Generates a pre-built class index at build time
类索引写入器 - 在构建时生成预构建的类索引
Scans specified packages using ClassScanner and MetadataReader,
then writes a JSON index file to the output directory.
使用 ClassScanner 和 MetadataReader 扫描指定包,
然后将 JSON 索引文件写入输出目录。
Usage Examples | 使用示例:
ClassIndexWriter.builder()
.addPackage("com.example")
.outputDir(Path.of("target/classes"))
.generate();
Security | 安全性:
- Thread-safe: No (builder pattern, single-use) - 线程安全: 否 (构建器模式,一次性使用)
- Since:
- JDK 25, opencode-base-classloader V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaddPackage(String packageName) Add a package to scan 添加要扫描的包static ClassIndexWriterbuilder()Create a new builder 创建新的构建器classLoader(ClassLoader classLoader) Set the class loader for scanning 设置用于扫描的类加载器static StringCompute a SHA-256 hash of the current classpath for staleness detection 计算当前 classpath 的 SHA-256 哈希值用于陈旧检测static StringescapeJson(String value) Escape a string for JSON output 为 JSON 输出转义字符串generate()Generate the class index and write it to the output directory 生成类索引并写入输出目录Set the output directory for the index file 设置索引文件的输出目录
-
Method Details
-
builder
Create a new builder 创建新的构建器- Returns:
- new builder instance | 新的构建器实例
-
addPackage
Add a package to scan 添加要扫描的包- Parameters:
packageName- package name to scan | 要扫描的包名- Returns:
- this builder | 此构建器
-
classLoader
Set the class loader for scanning 设置用于扫描的类加载器- Parameters:
classLoader- class loader to use | 要使用的类加载器- Returns:
- this builder | 此构建器
-
outputDir
Set the output directory for the index file 设置索引文件的输出目录- Parameters:
outputDir- output directory path (e.g. target/classes) | 输出目录路径- Returns:
- this builder | 此构建器
-
generate
Generate the class index and write it to the output directory 生成类索引并写入输出目录- Returns:
- the generated class index | 生成的类索引
- Throws:
IOException- if writing fails | 写入失败时抛出
-
computeClasspathHash
Compute a SHA-256 hash of the current classpath for staleness detection 计算当前 classpath 的 SHA-256 哈希值用于陈旧检测- Returns:
- hex-encoded SHA-256 hash | 十六进制编码的 SHA-256 哈希值
-
escapeJson
Escape a string for JSON output 为 JSON 输出转义字符串Shared utility used across the classloader module to avoid code duplication.
跨 classloader 模块共享的工具方法,避免代码重复。
- Parameters:
value- input string | 输入字符串- Returns:
- escaped JSON string, or empty string if null | 转义后的 JSON 字符串,null 时返回空字符串
-