feat: 项目整体命名修改cache-schema-checker
All checks were successful
缓存序列化结构检查 / cache-schema-check (push) Has been skipped

This commit is contained in:
2026-07-14 11:03:34 +08:00
parent 114b053733
commit 110beb79c0
42 changed files with 197 additions and 199 deletions

View File

@@ -0,0 +1,66 @@
package com.codechecker.cache.analyze;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
/**
* 扫描工作树中受包含/排除模块限制的 {@code src/main/java} 下的所有 Java 源文件。
*/
public class FileScanner {
private final Path repoRoot;
private final List<String> includeModules;
private final List<String> excludeModules;
public FileScanner(Path repoRoot, List<String> includeModules, List<String> excludeModules) {
this.repoRoot = repoRoot;
this.includeModules = includeModules;
this.excludeModules = excludeModules;
}
/**
* @return 相对仓库根(/ 分隔)-> 文件内容
*/
public Map<String, String> scan() {
Map<String, String> result = new LinkedHashMap<>();
try (Stream<Path> stream = Files.walk(repoRoot)) {
stream.filter(Files::isRegularFile)
.filter(p -> p.toString().endsWith(".java"))
.forEach(p -> {
String rel = repoRoot.relativize(p).toString().replace('\\', '/');
if (!rel.contains("/src/main/java/")) {
return;
}
if (!moduleAllowed(rel)) {
return;
}
try {
result.put(rel, new String(Files.readAllBytes(p), StandardCharsets.UTF_8));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return result;
}
boolean moduleAllowed(String relPath) {
String topModule = relPath.contains("/") ? relPath.substring(0, relPath.indexOf('/')) : relPath;
if (excludeModules != null && excludeModules.contains(topModule)) {
return false;
}
if (includeModules == null || includeModules.isEmpty()) {
return true;
}
return includeModules.contains(topModule);
}
}