tca ql 工具分析函数 :param params: 执行需要的参数 :return :
(self, params, lang)
| 273 | return |
| 274 | |
| 275 | def analyze(self, params, lang): |
| 276 | """ |
| 277 | tca ql 工具分析函数 |
| 278 | :param params: 执行需要的参数 |
| 279 | :return : |
| 280 | """ |
| 281 | source_dir = params.source_dir |
| 282 | relpos = len(source_dir) + 1 |
| 283 | work_dir = params.work_dir |
| 284 | db_dir = os.path.join(work_dir, "db") |
| 285 | repo_id = params.repo_id |
| 286 | envs = os.environ |
| 287 | HADES_HOME = envs.get("HADES_HOME", None) |
| 288 | scm_revision = params["scm_revision"] |
| 289 | version = self.__get_zeus_version(params) |
| 290 | db_name = f"{repo_id}_{scm_revision}_{lang}_{version}" |
| 291 | db_path = os.path.join(db_dir, f"{db_name}.db") |
| 292 | if not os.path.exists(db_path): |
| 293 | if not os.path.exists(db_dir): |
| 294 | os.makedirs(db_dir) |
| 295 | logger.info(f"本地未找到数据库文件{db_path},从文件服务器下载") |
| 296 | if not self.__download_database(params, db_name): |
| 297 | logger.info("本地没有找到数据库,缓存数据库下载失败,可能分析文件为空") |
| 298 | return [] |
| 299 | rules = params["rule_list"] |
| 300 | inc = params["incr_scan"] |
| 301 | want_suffix = lang_map[lang] |
| 302 | if inc: |
| 303 | diffs = SCMMgr(params).get_scm_diff() |
| 304 | toscans = [ |
| 305 | diff.path.replace(os.sep, "/") |
| 306 | for diff in diffs |
| 307 | if diff.path.endswith(tuple(want_suffix)) and diff.state != "del" |
| 308 | ] |
| 309 | else: |
| 310 | toscans = [ |
| 311 | path.replace(os.sep, "/")[relpos:] |
| 312 | for path in PathMgr().get_dir_files(source_dir, want_suffix=tuple(want_suffix)) |
| 313 | ] |
| 314 | # 过滤文件以及过滤文件取相对路径 |
| 315 | toscans = FilterPathUtil(params).get_include_files([os.path.join(source_dir, path) for path in toscans], relpos) |
| 316 | toscans = [path[relpos:] for path in toscans] |
| 317 | toscans = PathMgr().format_cmd_arg_list(toscans) |
| 318 | if not toscans: |
| 319 | logger.warning("分析文件为空") |
| 320 | if os.path.exists(db_path): |
| 321 | self.__upload_database(params, db_name) |
| 322 | return [] |
| 323 | output_json = os.path.join(work_dir, "result.json") |
| 324 | setting_file = self.__generate_config_file(rules, work_dir, source_dir, toscans) |
| 325 | analyze_cmd = self.get_cmd( |
| 326 | "Hades", |
| 327 | [ |
| 328 | "analyze", |
| 329 | "-l", |
| 330 | lang, |
| 331 | "-cc", |
| 332 | db_dir, |
nothing calls this directly
no test coverage detected