in dubbo-error-code-inspector/src/main/java/org/apache/dubbo/errorcode/Main.java [60:146]
public static void main(String[] args) {
directoryToInspect = args[0];
System.out.println("Directory to inspect: " + directoryToInspect);
// Step 1
System.out.println("Scanning error codes and detecting invalid logger invocation...");
long millis1 = System.currentTimeMillis();
List<Path> targetFolders = FileUtils.getAllClassFilePaths(args[0]);
Map<Path, List<String>> fileBasedCodes = new HashMap<>(1024);
List<String> codes = Collections.synchronizedList(new ArrayList<>(30));
Map<String, List<MethodDefinition>> illegalLoggerMethodInvocations = new ConcurrentHashMap<>(256);
CountDownLatch countDownLatch = new CountDownLatch(targetFolders.size());
for (Path folder : targetFolders) {
EXECUTOR.submit(() -> handleSinglePackageFolder(
fileBasedCodes,
codes,
illegalLoggerMethodInvocations,
countDownLatch,
folder));
}
try {
countDownLatch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
long millis2 = System.currentTimeMillis();
System.out.println("Milliseconds elapsed: " + (millis2 - millis1));
// Step 2
System.out.println("Locating illegal logger method invocations...");
millis1 = System.currentTimeMillis();
Map<String, List<MethodDefinition>> illegalInvocationClassesAndLoggerMethods = illegalLoggerMethodInvocations.entrySet()
.stream()
.filter(e -> !e.getValue().isEmpty())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
Map<String, List<LoggerMethodInvocation>> invalidLoggerMethodInvocationLocations = new HashMap<>();
Set<String> illegalInvocationClasses = illegalInvocationClassesAndLoggerMethods.keySet();
illegalInvocationClasses.forEach(x ->
invalidLoggerMethodInvocationLocations.put(
x, INVALID_LOGGER_INVOCATION_LOCATOR.locateInvalidLoggerInvocation(x)
)
);
millis2 = System.currentTimeMillis();
System.out.println("Milliseconds elapsed: " + (millis2 - millis1));
// Step 3
System.out.println("Finding error codes that document links are not reachable...");
millis1 = System.currentTimeMillis();
List<String> linksNotReachable = LinkTestingForkJoinTask.findDocumentMissingErrorCodes(codes);
millis2 = System.currentTimeMillis();
System.out.println("Milliseconds elapsed: " + (millis2 - millis1));
System.out.println();
InspectionResult inspectionResult = getInspectionResult(
codes,
illegalInvocationClassesAndLoggerMethods,
invalidLoggerMethodInvocationLocations,
linksNotReachable);
ErrorCodeInspectorConfig.REPORTERS.forEach(x -> x.report(inspectionResult));
cleanUp();
if (ErrorCodeInspectorConfig.REPORT_AS_ERROR) {
if (!inspectionResult.getIllegalInvocations().isEmpty() ||
!inspectionResult.getLinkNotReachableErrorCodes().isEmpty()) {
throw new IllegalStateException("Invalid situation occurred, check console or log for details;");
}
} else {
System.out.println("Tolerance mode enabled, will not throw exception.");
}
}