执行分析任务 :param params: 需包含下面键值: 'rules': lint分析的规则列表 'incr_scan' : 是否增量分析 :return: return a :py:class:`IssueResponse`
(self, params)
| 157 | return rules |
| 158 | |
| 159 | def analyze(self, params): |
| 160 | """执行分析任务 |
| 161 | |
| 162 | :param params: 需包含下面键值: |
| 163 | 'rules': lint分析的规则列表 |
| 164 | 'incr_scan' : 是否增量分析 |
| 165 | |
| 166 | :return: return a :py:class:`IssueResponse` |
| 167 | """ |
| 168 | source_dir = params['source_dir'] |
| 169 | incr_scan = params['incr_scan'] |
| 170 | rules = self.__format_rules(params['rule_list']) |
| 171 | |
| 172 | logger.info('获取需要分析的文件') |
| 173 | |
| 174 | if incr_scan: |
| 175 | diffs = SCMMgr(params).get_scm_diff() |
| 176 | toscans = [os.path.join(source_dir, diff.path) for diff in diffs if diff.state != 'del'] |
| 177 | else: |
| 178 | toscans = PathMgr().get_dir_files(source_dir) |
| 179 | |
| 180 | # filter include and exclude path |
| 181 | relpos = len(source_dir) + 1 |
| 182 | toscans = FilterPathUtil(params).get_include_files(toscans, relpos) |
| 183 | |
| 184 | if not toscans: |
| 185 | logger.debug("To-be-scanned files is empty ") |
| 186 | return [] |
| 187 | |
| 188 | logger.debug("files to scan: %d" % len(toscans)) |
| 189 | |
| 190 | # 执行分析工具 |
| 191 | logger.debug('逐个文件执行正则匹配') |
| 192 | |
| 193 | issues = [] |
| 194 | for file_path in toscans: |
| 195 | file_issues = RegexScanner.scan_file(source_dir, file_path, rules) |
| 196 | if file_issues: |
| 197 | issues.extend(file_issues) |
| 198 | |
| 199 | if not issues: |
| 200 | logger.info("result is empty.") |
| 201 | |
| 202 | logger.debug(issues) |
| 203 | return issues |
| 204 | |
| 205 | def set_filter_type_list(self): |
| 206 | ''' |
nothing calls this directly
no test coverage detected