1/* 2 * Copyright (c) 2024 - 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import Logger, { LOG_MODULE_TYPE } from 'arkanalyzer/lib/utils/logger'; 16import { ArkFile } from 'arkanalyzer'; 17import { Rule, BaseChecker } from '../../Index'; 18import { File2Check } from '../../model/File2Check'; 19import { Project2Check } from '../../model/Project2Check'; 20import { CheckerFactory } from './CheckerFactory'; 21 22 23const logger = Logger.getLogger(LOG_MODULE_TYPE.HOMECHECK, 'CheckBuilder'); 24 25export function fileCheckBuilder(arkFile: ArkFile, enabledRules: Rule[]): File2Check { 26 let checkIns = new File2Check(); 27 checkIns.arkFile = arkFile; 28 enabledRules.forEach(rule => { 29 const checkerInstance = CheckerFactory.getChecker(rule); 30 if (checkerInstance) { 31 checkIns.addChecker(rule.ruleId, checkerInstance as BaseChecker); 32 } else { 33 logger.error(`Cannot find checker according rule id: ${rule.ruleId}`); 34 } 35 }); 36 return checkIns; 37} 38 39export function projectCheckBuilder(arkFiles: ArkFile[], enabledRules: Rule[]): Project2Check { 40 let checkIns = new Project2Check(); 41 checkIns.arkFiles = arkFiles; 42 enabledRules.forEach(rule => { 43 const checkerInstance = CheckerFactory.getChecker(rule); 44 if (checkerInstance) { 45 checkIns.addChecker(rule.ruleId, checkerInstance as BaseChecker); 46 } else { 47 logger.log(`Cannot find checker according rule id: ${rule.ruleId}`); 48 } 49 }); 50 return checkIns; 51}