| 374 | |
| 375 | |
| 376 | class ThreadRunner(object): |
| 377 | # 多线程执行checkstyle 类 |
| 378 | def __init__(self, scan_cmd, source_dir, params): |
| 379 | self.scan_cmd = scan_cmd |
| 380 | self.source_dir = source_dir |
| 381 | self.issues = [] |
| 382 | self.params = params |
| 383 | self.mutex = threading.Lock() # 线程锁 |
| 384 | |
| 385 | def __scan_file_callback_(self, file_path): |
| 386 | file_result = CheckStyleRunner().run_checkstyle_on_file(file_path, self.scan_cmd, self.source_dir, self.params) |
| 387 | self.mutex.acquire() # 上锁 |
| 388 | self.issues.extend(file_result) |
| 389 | self.mutex.release() # 解锁 |
| 390 | |
| 391 | def run(self, toscans): |
| 392 | # 多线程执行类 |
| 393 | callback_queue = CallbackQueue(min_threads=20, max_threads=1000) |
| 394 | LogPrinter.info("toscans : %s" % toscans) |
| 395 | for path in toscans: |
| 396 | LogPrinter.info("path: %s" % path) |
| 397 | callback_queue.append(self.__scan_file_callback_, path) |
| 398 | callback_queue.wait_for_all_callbacks_to_be_execute_and_destroy() |
| 399 | return self.issues |
| 400 | |
| 401 | |
| 402 | tool = CheckStyle |