dart_code_metrics工具扫描的封装方法 :param params: :param report_type: :param report_path: :param options: :param source_dir: :return: None或者结果文件绝对路径
(self, params, dart_home, report_type, report_path, options=None, source_dir=None)
| 50 | return issues |
| 51 | |
| 52 | def scan(self, params, dart_home, report_type, report_path, options=None, source_dir=None): |
| 53 | """ |
| 54 | dart_code_metrics工具扫描的封装方法 |
| 55 | :param params: |
| 56 | :param report_type: |
| 57 | :param report_path: |
| 58 | :param options: |
| 59 | :param source_dir: |
| 60 | :return: None或者结果文件绝对路径 |
| 61 | """ |
| 62 | source_dir = source_dir if source_dir else params.source_dir |
| 63 | path_exclude = params.path_filters.get("wildcard_exclusion", []) |
| 64 | |
| 65 | scan_cmd = [ |
| 66 | "dart", |
| 67 | os.path.join(dart_home, "bin", "metrics.dart"), |
| 68 | source_dir, |
| 69 | "--root-folder=%s" % (source_dir), |
| 70 | "--reporter=%s" % (report_type), |
| 71 | ] |
| 72 | |
| 73 | # options=["--cyclomatic-complexity=5"] |
| 74 | if options: |
| 75 | scan_cmd.extend(options) |
| 76 | |
| 77 | # 设置路径过滤 |
| 78 | if path_exclude: |
| 79 | scan_cmd.append( |
| 80 | '--ignore-files="{/**.g.dart,%s}"' % (",".join([path.replace("*", "**") for path in path_exclude])) |
| 81 | ) |
| 82 | |
| 83 | # scan_cmd = PathMgr().format_cmd_arg_list(scan_cmd) |
| 84 | self.print_log("scan cmd: %s" % " ".join(scan_cmd)) |
| 85 | subProC = SubProcController( |
| 86 | scan_cmd, |
| 87 | cwd=source_dir, |
| 88 | # stdout_line_callback=subprocc_log, |
| 89 | # stderr_line_callback=self.__collect_result_callback__ |
| 90 | stdout_line_callback=self.__collect_result_callback__ |
| 91 | ) |
| 92 | subProC.wait() |
| 93 | |
| 94 | # 异常处理 |
| 95 | rt = subProC.returncode |
| 96 | if rt != 0: |
| 97 | LogPrinter.error("工具分析异常,返回码为%d" % rt) |
| 98 | |
| 99 | # 结果存入report_path |
| 100 | with open(report_path, 'w') as f: |
| 101 | json.dump(self.cmd_output, f) |
| 102 | |
| 103 | def __collect_result_callback__(self, line): |
| 104 | """单行输出回调,收集结果""" |