| 22 | |
| 23 | |
| 24 | class ASTParser(object): |
| 25 | def __init__(self, source_dir, db_dir=None): |
| 26 | self.project_root = source_dir |
| 27 | if db_dir and os.path.exists(db_dir): |
| 28 | if os.path.isdir(db_dir): |
| 29 | self.ast_db = os.path.join(db_dir, "codedog_ast.db") |
| 30 | else: |
| 31 | self.ast_db = db_dir |
| 32 | else: |
| 33 | self.ast_db = os.path.join(source_dir, "codedog_ast.db") |
| 34 | self.want_suffix = (".java", ".jar") |
| 35 | |
| 36 | def get_tool(self): |
| 37 | tool_home = os.environ["LOONG_HOME"] |
| 38 | tool_path = os.path.join(tool_home, "bin", settings.PLATFORMS[sys.platform], "JAP") |
| 39 | if settings.PLATFORMS[sys.platform] == "windows": |
| 40 | tool_path = f"{tool_path}.exe" |
| 41 | return tool_path |
| 42 | |
| 43 | def parser(self): |
| 44 | tool_path = self.get_tool() |
| 45 | args = [ |
| 46 | "path=%s" % self.project_root, |
| 47 | "thread=%s" % cpu_count(), |
| 48 | "data=%s" % self.ast_db, |
| 49 | ] |
| 50 | astparser_cmd = __lu__().format_cmd(tool_path, args) |
| 51 | SubProcController(astparser_cmd, stdout_line_callback=subprocc_log, stderr_line_callback=subprocc_log).wait() |
| 52 | |
| 53 | |
| 54 | if __name__ == "__main__": |