1/* 2 * Copyright (c) 2024 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 */ 15 16import { IOptions } from '../configs/IOptions'; 17import { FileUtils } from './FileUtils'; 18 19export class UnitTestUtil { 20 // The paths in mKeepFileSourceCode are relative paths. Join them with the directory where the obfuscation configuration file is located 21 // to get the absolute path. 22 static initKeepPathConfig(customProfiles: IOptions, configPath: string): void { 23 if (customProfiles.mKeepFileSourceCode) { 24 const keepFileSourceCode = customProfiles.mKeepFileSourceCode; 25 const tempKeepSourceOfPaths = new Set<string>(); 26 const tempkeepFilesAndDependencies = new Set<string>(); 27 28 const processPaths = (paths: Set<string>, targetPaths: Set<string>): void => { 29 paths.forEach(tempPath => { 30 const absPath = FileUtils.getAbsPathBaseConfigPath(configPath, tempPath); 31 targetPaths.add(absPath); 32 }); 33 }; 34 35 processPaths(keepFileSourceCode.mKeepSourceOfPaths, tempKeepSourceOfPaths); 36 processPaths(keepFileSourceCode.mkeepFilesAndDependencies, tempkeepFilesAndDependencies); 37 38 keepFileSourceCode.mKeepSourceOfPaths = tempKeepSourceOfPaths; 39 keepFileSourceCode.mkeepFilesAndDependencies = tempkeepFilesAndDependencies; 40 } 41 } 42} 43