(self, params)
| 41 | } |
| 42 | |
| 43 | def analyze(self, params): |
| 44 | source_dir = params["source_dir"] |
| 45 | self.pos = len(source_dir) + 1 |
| 46 | self.rules = params["rules"] |
| 47 | envs = os.environ |
| 48 | rule_list = params["rule_list"] |
| 49 | incr_scan = params["incr_scan"] |
| 50 | scalastyle_home = envs.get("SCALASTYLE_HOME") |
| 51 | config_type = envs.get("SCALA_TYPE", None) |
| 52 | output_file = os.path.join(os.getcwd(), "result.xml") |
| 53 | # 根据是否配置使用腾讯代码规范设置配置文件 |
| 54 | if not config_type: |
| 55 | config_file = self.generate_config(rule_list) |
| 56 | # 使用规范配置 |
| 57 | elif config_type == "tencent": |
| 58 | config_file = os.path.join(scalastyle_home, "config", "standard.xml") |
| 59 | scan_cmd = [ |
| 60 | os.path.join(os.environ["JDK_8_HOME"], "bin", "java"), |
| 61 | "-jar", |
| 62 | os.path.join(os.environ["SCALASTYLE_HOME"], "scalastyle_2.12-1.0.0-batch.jar"), |
| 63 | "--config", |
| 64 | config_file, |
| 65 | "--xmlOutput", |
| 66 | output_file, |
| 67 | ] |
| 68 | toscans = [] |
| 69 | if incr_scan: |
| 70 | diffs = SCMMgr(params).get_scm_diff() |
| 71 | toscans = [ |
| 72 | os.path.join(source_dir, diff.path).replace(os.sep, "/") |
| 73 | for diff in diffs |
| 74 | if diff.path.endswith(tuple(".scala")) and diff.state != "del" |
| 75 | ] |
| 76 | relpos = len(source_dir) + 1 |
| 77 | # toscans = PathFilter.get_include_files(toscans, relpos, path_include, path_exclude) |
| 78 | toscans = FilterPathUtil(params).get_include_files(toscans, relpos) |
| 79 | else: |
| 80 | toscans = [source_dir] |
| 81 | if sys.platform == "win32" and len(max(toscans)) > 32500: |
| 82 | # 增量命令长度超过限制为了保证不失败进行全量分析 |
| 83 | toscans = [source_dir] |
| 84 | |
| 85 | if not toscans: |
| 86 | LogPrinter.debug("To-be-scanned files is empty ") |
| 87 | return [] |
| 88 | scan_cmd.extend(toscans) |
| 89 | issues = [] |
| 90 | LogPrinter.info(" ".join(scan_cmd)) |
| 91 | spc = SubProcController( |
| 92 | scan_cmd, |
| 93 | stdout_line_callback=ScalaStyle(params).print_log, |
| 94 | stderr_line_callback=ScalaStyle(params).print_log, |
| 95 | ) |
| 96 | spc.wait() |
| 97 | issues = self.format_issues(output_file) |
| 98 | return issues |
| 99 | |
| 100 | def generate_config(self, rule_list): |
nothing calls this directly
no test coverage detected