diff --git a/adapter/ohos/CommandParser.java b/adapter/ohos/CommandParser.java index 0a957d8cd31ab1081250c983f57870fe517bbece..d7b5b0adeb506bdd88324acf9a5910de0eac7207 100644 --- a/adapter/ohos/CommandParser.java +++ b/adapter/ohos/CommandParser.java @@ -362,14 +362,16 @@ public class CommandParser { try { int compressLevel = Integer.parseInt(level); if (compressLevel < 1 || compressLevel > 9) { - LOG.error(PackingToolErrMsg.COMMAND_PARSER_FAILED.toString("--compress-level value not number between 1-9.")); + LOG.error(PackingToolErrMsg.COMMAND_PARSER_FAILED.toString( + "--compress-level value not number between 1-9.")); return false; } else { entry.getKey().setCompressLevel(compressLevel); return true; } } catch (NumberFormatException ex) { - LOG.error(PackingToolErrMsg.COMMAND_PARSER_FAILED.toString("--compress-level value not number between 1-9.")); + LOG.error(PackingToolErrMsg.COMMAND_PARSER_FAILED.toString( + "--compress-level value not number between 1-9.")); return false; } }); @@ -405,7 +407,8 @@ public class CommandParser { ++i; } else if (CMD_PARSE_MODE.equals(key)) { if (i + PARSE_MODE_VALUE_LENGTH >= args.length) { - LOG.error(PackingToolErrMsg.COMMAND_PARSER_FAILED.toString("Input wrong number value for --p command.")); + LOG.error(PackingToolErrMsg.COMMAND_PARSER_FAILED.toString( + "Input wrong number value for --p command.")); return false; } utility.setParseMode(args[i + 1]); diff --git a/adapter/ohos/CompressVerify.java b/adapter/ohos/CompressVerify.java index 83256f75b278322ba1b62f4f636bc3281b5645bb..ddbd5f6856469498e7a69d89d2eff6cf8ebfe5e9 100644 --- a/adapter/ohos/CompressVerify.java +++ b/adapter/ohos/CompressVerify.java @@ -158,29 +158,35 @@ public class CompressVerify { private static boolean validatePackageNormalizeMode(Utility utility) { if (utility.getHspList().isEmpty()) { - LOG.error("CompressVerify::validatePackageNormalizeMode hsp-list is empty."); + String errMsg = "--hsp-list is empty."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } else { if (!compatibleProcess(utility, utility.getHspList(), utility.getFormattedHspPathList(), HSP_SUFFIX)) { - LOG.error("CompressVerify::validatePackageNormalizeMode hsp-list is invalid."); + String errMsg = "--hsp-list is invalid."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!isBundleNameValid(utility.getBundleName())) { - LOG.error("CompressVerify::validatePackageNormalizeMode bundle-name is invalid."); + String errMsg = "--bundle-name is invalid."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getVersionCode() <= 0) { - LOG.error("CompressVerify::validatePackageNormalizeMode version-code is invalid."); + String errMsg = "--version-code is invalid."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getOutPath().isEmpty()) { - LOG.error("CompressVerify::validatePackageNormalizeMode out-path is empty."); + String errMsg = "--out-path is empty."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } File outDir = new File(utility.getOutPath()); if (!outDir.isDirectory()) { - LOG.error("CompressVerify::validatePackageNormalizeMode out-path is not a directory."); + String errMsg = "--out-path is not a directory."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -188,45 +194,53 @@ public class CompressVerify { private static boolean validateVersionNormalizeMode(Utility utility) { if (utility.getInputList().isEmpty()) { - LOG.error("CompressVerify::validateVersionNormalizeMode input-list is empty."); + String errMsg = "--input-list is empty."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!handleHapAndHspInput(utility, utility.getInputList(), utility.getFormattedHapList())) { - LOG.error("CompressVerify::validateVersionNormalizeMode input-list is invalid."); + String errMsg = "--input-list is invalid."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getFormattedHapList().isEmpty()) { - LOG.error("CompressVerify::validateVersionNormalizeMode input-list is empty."); + String errMsg = "--input-list is empty."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getVersionCode() <= 0) { - LOG.error("CompressVerify::validateVersionNormalizeMode version-code is invalid."); + String errMsg = "--version-code is invalid."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getVersionName().isEmpty()) { - LOG.error("CompressVerify::validateVersionNormalizeMode version-name is empty."); + String errMsg = "--version-name is empty."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } Pattern versionNamePattern = Pattern.compile(VERSION_NAME_PATTERN); Matcher versionNameMatcher = versionNamePattern.matcher(utility.getVersionName()); if (!versionNameMatcher.matches()) { - LOG.error("CompressVerify::validateVersionNormalizeMode version-name is not valid."); + String errMsg = "--version-name is not valid."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getOutPath().isEmpty()) { - LOG.error("CompressVerify::validateVersionNormalizeMode out-path is empty."); + String errMsg = "--out-path is empty."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } File outDir = new File(utility.getOutPath()); if (!outDir.isDirectory()) { - LOG.error("CompressVerify::validateVersionNormalizeMode out-path is not a directory."); + String errMsg = "--out-path is not a directory."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -447,45 +461,53 @@ public class CompressVerify { */ private static boolean isVerifyValidInHarMode(Utility utility) { if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::isArgsValidInHarMode json-path is empty."); + String errMsg = "--json-path is empty."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!isPathValid(utility.getJsonPath(), TYPE_FILE, JSON_PROFILE) && !isPathValid(utility.getJsonPath(), TYPE_FILE, MODULE_PROFILE)) { - LOG.error("CompressVerify::isArgsValidInHarMode json-path must be config.json file."); + String errMsg = "--json-path must be config.json or module.json file."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getJarPath().isEmpty() && !compatibleProcess(utility, utility.getJarPath(), utility.getFormattedJarPathList(), JAR_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHarMode jar-path is invalid."); + String errMsg = "--jar-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getTxtPath().isEmpty() && !compatibleProcess(utility, utility.getTxtPath(), utility.getFormattedTxtPathList(), TXT_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHarMode txt-path is invalid."); + String errMsg = "--txt-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getLibPath().isEmpty() && !isPathValid(utility.getLibPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode lib-path is invalid."); + String errMsg = "--lib-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getResPath().isEmpty() && !isPathValid(utility.getResPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode res-path is invalid."); + String errMsg = "--res-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getResourcesPath().isEmpty() || !isPathValid(utility.getResourcesPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode resources-path is invalid."); + String errMsg = "--resources-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getAssetsPath().isEmpty() && !isPathValid(utility.getAssetsPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode assets-path is invalid."); + String errMsg = "--assets-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -629,41 +651,48 @@ public class CompressVerify { */ private static boolean isVerifyValidInMultiAppMode(Utility utility) { if (utility.getAppList().isEmpty() && utility.getHapList().isEmpty() && utility.getHspList().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode input app-list, hap-list and hsp-list are null."); + String errMsg = "Input --app-list, --hap-list and --hsp-list are all empty."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getAppList().isEmpty()) { if (!compatibleProcess(utility, utility.getAppList(), utility.getFormattedAppList(), APP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode app-list is invalid."); + String errMsg = "--app-list is invalid."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!utility.getHapList().isEmpty()) { if (!compatibleProcess(utility, utility.getHapList(), utility.getFormattedHapList(), HAP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode hap-list is invalid."); + String errMsg = "--hap-list is invalid."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!utility.getHspList().isEmpty()) { if (!compatibleProcess(utility, utility.getHspList(), utility.getFormattedHapList(), HSP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode hsp-list is invalid."); + String errMsg = "--hsp-list is invalid."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!isValidEncryptJsonFile(utility)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode encrypt-path is invalid."); + String errMsg = "--encrypt-path is invalid."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } File outFile = new File(utility.getOutPath()); if (("false".equals(utility.getForceRewrite())) && outFile.exists()) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode out file already existed."); + String errMsg = "--out-path file already existed, but --force is 'false'."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(APP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode out-path must end with .app."); + String errMsg = "--out-path must end with .app."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -678,18 +707,20 @@ public class CompressVerify { */ private static boolean isVerifyValidInResMode(Utility utility) { if (!isPathValid(utility.getPackInfoPath(), TYPE_FILE, PACK_INFO)) { - LOG.error("CompressVerify::isArgsValidInResMode pack-info-path is invalid."); + String errMsg = "--pack-info-path is invalid."; + LOG.error(PackingToolErrMsg.RES_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!isDirectoryValidStrictCase(utility.getEntryCardPath(), ENTRY_CARD_DIRECTORY_NAME)) { - LOG.error("CompressVerify::isArgsValidInResMode the level-1 directory name must is EntryCard" + - ", current is " + utility.getEntryCardPath()); + String errMsg = "The level-1 directory name must be EntryCard, current is " + utility.getEntryCardPath(); + LOG.error(PackingToolErrMsg.RES_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!compatibleProcess(utility, utility.getEntryCardPath(), utility.getformattedEntryCardPathList(), PNG_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInResMode entrycard-path is invalid."); + String errMsg = "--entrycard-path is invalid."; + LOG.error(PackingToolErrMsg.RES_MODE_ARGS_INVALID.toString(errMsg)); return false; } return isOutPathValid(utility, RES_SUFFIX); @@ -697,38 +728,45 @@ public class CompressVerify { private static boolean isVerifyValidInHQFMode(Utility utility) { if (utility.getJsonPath().isEmpty()) { - LOG.error("must input patch.json file when pack hqf file."); + String errMsg = "--json-path is empty, must input patch.json file when pack hqf file."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getEtsPath().isEmpty()) { if (!isPathValid(utility.getEtsPath(), TYPE_DIR, null)) { - LOG.error("must input valid ets path when pack hqf file."); + String errMsg = "--ets-path is invalid."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!isPathValid(utility.getJsonPath(), TYPE_FILE, PATCH_PROFILE)) { - LOG.error("input patch.json is invalid when pack hqf file."); + String errMsg = "--json-path is invalid."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getLibPath().isEmpty()) { if (!isPathValid(utility.getLibPath(), TYPE_DIR, null)) { - LOG.error("input lib path is invalid when pack hqf file."); + String errMsg = "--lib-path is invalid."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!utility.getResourcesPath().isEmpty()) { if (!isPathValid(utility.getResourcesPath(), TYPE_DIR, null)) { - LOG.error("input resources path is invalid when pack hqf file."); + String errMsg = "--resources-path is invalid."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } } File outFile = new File(utility.getOutPath()); if ((FALSE.equals(utility.getForceRewrite())) && (outFile.exists())) { - LOG.error(outFile.getName() + " already exist."); + String errMsg = outFile.getName() + " already exist, but --force is 'false'."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getOutPath().endsWith(HQF_SUFFIX)) { - LOG.error("input out file must end with .hqf."); + String errMsg = "--out-path file must end with .hqf."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -736,20 +774,24 @@ public class CompressVerify { private static boolean isVerifyValidInAPPQFMode(Utility utility) { if (utility.getHqfList().isEmpty()) { - LOG.error("input hqf list is empty."); + String errMsg = "--hqf-list is empty."; + LOG.error(PackingToolErrMsg.APPQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!compatibleProcess(utility, utility.getHqfList(), utility.getFormatedHQFList(), HQF_SUFFIX)) { - LOG.error("input hqf list is invalid."); + String errMsg = "--hqf-list is invalid."; + LOG.error(PackingToolErrMsg.APPQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } File outFile = new File(utility.getOutPath()); if ((FALSE.equals(utility.getForceRewrite())) && outFile.exists()) { - LOG.error("Error out file already existed."); + String errMsg = "--out-path file already existed, but --force is 'false'."; + LOG.error(PackingToolErrMsg.APPQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(APPQF_SUFFIX)) { - LOG.error("Error out-path must end with .app."); + String errMsg = "--out-path must end with .appqf."; + LOG.error(PackingToolErrMsg.APPQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -813,7 +855,8 @@ public class CompressVerify { formattedPathItem = utility.getFormattedPath(pathItem); if (!isPathValid(formattedPathItem, TYPE_FILE, HSP_SUFFIX) && !isPathValid(formattedPathItem, TYPE_FILE, HAP_SUFFIX)) { - LOG.error("input file " + formattedPathItem + " not valid"); + String errMsg = "Input file " + formattedPathItem + " is invalid"; + LOG.error(PackingToolErrMsg.HANDLE_HAP_HSP_INPUT_FAILED.toString(errMsg)); return false; } fileList.add(formattedPathItem); @@ -923,8 +966,8 @@ public class CompressVerify { private static boolean isDirectoryValidStrictCase(String path, String directoryName) { File file = new File(path); if (!file.exists()) { - LOG.error("CompressVerify::isDirectoryValidStrictCase directory is not exist, directoryPath: " - + path + "."); + String errMsg = "The directory does not exist, directory path is: " + path + "."; + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString(errMsg)); return false; } if (file.isDirectory()) { @@ -977,7 +1020,8 @@ public class CompressVerify { return false; } if (hspHasExtensionAbilities) { - LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString("shared/appService hsp has extensionAbilities.")); + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString( + "shared/appService hsp has extensionAbilities.")); return false; } } @@ -1069,48 +1113,58 @@ public class CompressVerify { private static boolean isVerifyValidInHapAdditionMode(Utility utility) { if (utility.getHapPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hapPath is empty."); + String errMsg = "--hap-path is empty."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } String hapPath = utility.getAbsoluteHapPath(); File hapFile = new File(hapPath); if (hapFile.isDirectory()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hapPath cannot be a folder."); + String errMsg = "--hap-path cannot be a folder."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!(hapPath.endsWith(HAP_SUFFIX) || hapPath.endsWith(HSP_SUFFIX))) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hapPath is invalid."); + String errMsg = "--hap-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!hapFile.exists()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hap file does not exist."); + String errMsg = "--hap-path file does not exist."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode jsonPath is empty."); + String errMsg = "--json-path is empty."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getJsonPath().endsWith(JSON_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode jsonPath is invalid."); + String errMsg = "--json-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } File jsonFile = new File(utility.getJsonPath()); if (!jsonFile.exists()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode json file does not exist."); + String errMsg = "--json-path file does not exist."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!checkJsonIsValid(jsonFile)) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode json format is incorrect."); + String errMsg = "--json-path file is invalid."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getOutPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode outPath is empty."); + String errMsg = "--out-path is empty."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } File dir = new File(utility.getOutPath()); if (dir.exists() && dir.isFile()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode outPath is file."); + String errMsg = "--out-path is file."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } File absoluteHapFile = new File(utility.getAbsoluteHapPath()); @@ -1118,7 +1172,8 @@ public class CompressVerify { String destPath = utility.getOutPath() + LINUX_FILE_SEPARATOR + hapFileName; File destFile = new File(destPath); if ("false".equals(utility.getForceRewrite()) && destFile.exists()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode target file already exists."); + String errMsg = "--out-path file already existed, but --force is 'false'."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -1133,7 +1188,8 @@ public class CompressVerify { jsonData.append((char) ch); } } catch (IOException e) { - LOG.error("CompressVerify::CheckJsonIsValid failed: " + e.getMessage()); + String errMsg = "Check json file is valid exist IOException: "; + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg + e.getMessage())); return false; } JSONValidator validator = JSONValidator.from(jsonData.toString()); @@ -1237,7 +1293,8 @@ public class CompressVerify { try { Optional optional = FileUtils.getFileContent(utility.getJsonPath()); if(optional.isPresent()) { - return ModuleJsonUtil.parseModuleType(optional.get()).equals(BUNDLE_TYPE_SHARE) && !ModuleJsonUtil.parseAbilityNames(optional.get()).isEmpty(); + return ModuleJsonUtil.parseModuleType(optional.get()).equals(BUNDLE_TYPE_SHARE) && + !ModuleJsonUtil.parseAbilityNames(optional.get()).isEmpty(); } else { String errMsg = "Parse --json-path content failed."; LOG.error(PackingToolErrMsg.HSP_HAS_ABILITIES_FAILED.toString(errMsg)); @@ -1260,7 +1317,8 @@ public class CompressVerify { LOG.error(PackingToolErrMsg.HSP_HAS_EXTENSION_ABILITIES_FAILED.toString(errMsg)); } } catch (BundleException e) { - LOG.error(PackingToolErrMsg.HSP_HAS_EXTENSION_ABILITIES_FAILED.toString("BundleException: " + e.getMessage())); + LOG.error(PackingToolErrMsg.HSP_HAS_EXTENSION_ABILITIES_FAILED.toString( + "BundleException: " + e.getMessage())); } return false; } @@ -1318,7 +1376,8 @@ public class CompressVerify { LOG.info("CompressVerify::hasHomeExtensionAbility result = " + result); return result; } catch (BundleException e) { - LOG.error(PackingToolErrMsg.HAS_HOME_EXTENSION_ABILITY_INVALID.toString("BundleException: " + e.getMessage())); + LOG.error(PackingToolErrMsg.HAS_HOME_EXTENSION_ABILITY_INVALID.toString( + "BundleException: " + e.getMessage())); return false; } } diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index e4a74a8f87fb0d7863856fc78ea14e4a2213cb56..afb1e8dc84697579e5ee2d3f61c1bf14ad305c3e 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -365,10 +365,12 @@ public class Compressor { compressExcute(utility); } catch (FileNotFoundException exception) { compressResult = false; - LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("Compress exist FileNotFoundException: " + exception.getMessage())); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString( + "Compress exist FileNotFoundException: " + exception.getMessage())); } catch (BundleException ex) { compressResult = false; - LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_EXCEPTION.toString("Compress exist BundleException: " + ex.getMessage())); + LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_EXCEPTION.toString( + "Compress exist BundleException: " + ex.getMessage())); } finally { closeZipOutputStream(); Utility.closeStream(zipOut); @@ -378,8 +380,8 @@ public class Compressor { if (compressResult && !checkAppAtomicServiceCompressedSizeValid(utility)) { compressResult = false; - String errMsg = - "The size of a single module, or the size of a module plus its dependencies, exceeds " + getEntryModuleSizeLimit() + "MB."; + String errMsg = "The size of a single module, or the size of a module plus its dependencies, exceeds " + + getEntryModuleSizeLimit() + "MB."; LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_SIZE_FAILED.toString(errMsg)); } @@ -434,29 +436,35 @@ public class Compressor { Optional optional = FileUtils.getFileContent(utility.getJsonPath()); String jsonString = optional.get(); if (!checkStageAsanTsanEnabledValid(jsonString)) { - LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Check the asanTsanEnabled parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString( + "Check the asanTsanEnabled parameter in the Stage module failed.")); throw new BundleException("Compress hsp failed."); } if (!checkStageHwasanEnabledValid(jsonString)) { - LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Check the hwasanEnabled parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString( + "Check the hwasanEnabled parameter in the Stage module failed.")); throw new BundleException("Compress hsp failed."); } if (!checkStageUbsanEnabledValid(jsonString)) { - LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Check the ubsanEnabled parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString( + "Check the ubsanEnabled parameter in the Stage module failed.")); throw new BundleException("Compress hsp failed."); } if (!checkStageAtomicService(jsonString)) { - LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Check the atomicService parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString( + "Check the atomicService parameter in the Stage module failed.")); throw new BundleException("Check stage AtomicService failed."); } // check continueBundleName in module.json if (!checkContinueBundleNameIsValid(jsonString)) { - LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Check the continueBundleName parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString( + "Check the continueBundleName parameter in the Stage module failed.")); throw new BundleException("Compress hsp failed."); } // check whether is an overlay hsp or not if (!checkStageOverlayCfg(jsonString)) { - LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Check the overlay config in the Stage module failed.")); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString( + "Check the overlay config in the Stage module failed.")); throw new BundleException("Compress hsp failed."); } String moduleType = ModuleJsonUtil.parseModuleType(jsonString); @@ -478,7 +486,8 @@ public class Compressor { setGenerateBuildHash(utility); if (isModuleJSON(utility.getJsonPath())) { if (!checkStageHap(utility)) { - LOG.error(PackingToolErrMsg.COMPRESS_HAP_FAILED.toString("Verify the module.json file of the Stage HAP package failed.")); + LOG.error(PackingToolErrMsg.COMPRESS_HAP_FAILED.toString( + "Verify the module.json file of the Stage HAP package failed.")); throw new BundleException("Verify the module.json file of the Stage HAP package failed."); } Optional optional = FileUtils.getFileContent(utility.getJsonPath()); @@ -521,7 +530,8 @@ public class Compressor { res = true; } } catch (BundleException exception) { - LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString("Verify has generate build hash exist BundleException: " + exception.getMessage())); + LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString( + "Verify has generate build hash exist BundleException: " + exception.getMessage())); throw new BundleException("Verify has generate build hash failed."); } catch (JSONException | IOException e) { LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString( @@ -572,11 +582,13 @@ public class Compressor { new FileOutputStream(utility.getJsonPath()), StandardCharsets.UTF_8)); bw.write(pretty); } catch (BundleException exception) { - LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString("Set generate build hash exist BundleException: " + exception.getMessage())); + LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString( + "Set generate build hash exist BundleException: " + exception.getMessage())); throw new BundleException("Compressor::setGenerateBuildHash failed."); } catch (NullPointerException | IOException | JSONException e) { LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString( - "json data err, exist Exception(NullPointerException | IOException | JSONException): " + e.getMessage())); + "json data err, exist Exception(NullPointerException | IOException | JSONException): " + + e.getMessage())); throw new BundleException("Set generate build hash failed, json data err."); } finally { FileUtils.closeStream(json); @@ -707,7 +719,8 @@ public class Compressor { LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Put build hash exist IOException: " + e.getMessage())); throw new BundleException("Put build hash failed."); } catch (NullPointerException e) { - LOG.error(PackingToolErrMsg.NULL_POINTER_EXCEPTION.toString("The json data err, exist NullPointerException: " + e.getMessage())); + LOG.error(PackingToolErrMsg.NULL_POINTER_EXCEPTION.toString( + "The json data err, exist NullPointerException: " + e.getMessage())); throw new BundleException("Put build hash failed, json data err."); } finally { FileUtils.closeStream(json); @@ -753,10 +766,12 @@ public class Compressor { return HapVerify.checkFileSizeIsValid(hapVerifyInfos); } catch (IOException exception) { - LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString("IOException: " + exception.getMessage())); + LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString( + "IOException: " + exception.getMessage())); return false; } catch (BundleException ignored) { - LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString("BundleException: " + ignored.getMessage())); + LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString( + "BundleException: " + ignored.getMessage())); return false; } } @@ -765,25 +780,30 @@ public class Compressor { Optional optional = FileUtils.getFileContent(utility.getJsonPath()); String jsonString = optional.get(); if (!checkStageAsanTsanEnabledValid(jsonString)) { - LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("Check the asanTsanEnabled parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString( + "Check the asanTsanEnabled parameter in the Stage module failed.")); return false; } if (!checkStageHwasanEnabledValid(jsonString)) { - LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("Check the hwasanEnabled parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString( + "Check the hwasanEnabled parameter in the Stage module failed.")); return false; } if (!checkStageUbsanEnabledValid(jsonString)) { - LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("Check the ubsanEnabled parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString( + "Check the ubsanEnabled parameter in the Stage module failed.")); return false; } // check atomicService in module.json if (!checkStageAtomicService(jsonString)) { - LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("Check the atomicService parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString( + "Check the atomicService parameter in the Stage module failed.")); return false; } // check continueBundleName in module.json if (!checkContinueBundleNameIsValid(jsonString)) { - LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("Check the continueBundleName parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString( + "Check the continueBundleName parameter in the Stage module failed.")); return false; } return true; @@ -875,7 +895,8 @@ public class Compressor { } // check entry module must have ability if (!ModuleJsonUtil.checkEntryInAtomicService(jsonString)) { - LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_FAILED.toString("Check the atomicService entry module failed.")); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_FAILED.toString( + "Check the atomicService entry module failed.")); return false; } // check installationFree @@ -896,7 +917,8 @@ public class Compressor { // check targetModuleName and requestPermission if (ModuleJsonUtil.isExistedStageRequestPermissions(jsonString)) { LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString( - "The module(" + moduleName + ") targetModuleName and requestPermissions cannot be configured at the same time.")); + "The module(" + moduleName + ") targetModuleName and requestPermissions " + + "cannot be configured at the same time.")); return false; } // check targetModuleName and name @@ -908,7 +930,8 @@ public class Compressor { } else { if (ModuleJsonUtil.isExistedStageModuleTargetPriority(jsonString)) { LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString( - "The targetPriority cannot be existed without the targetModuleName in module.json. The moduleName is " + moduleName + ".")); + "The targetPriority cannot be existed without the targetModuleName in module.json. " + + "The moduleName is " + moduleName + ".")); return false; } } @@ -916,8 +939,8 @@ public class Compressor { String targetBundleName = ModuleJsonUtil.getStageTargetBundleName(jsonString); if (!targetBundleName.isEmpty()) { if (targetModuleName.isEmpty()) { - LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString( - "The module(" + moduleName + ") targetModuleName settings is necessary in the overlay bundle.")); + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString("The module(" + moduleName + + ") targetModuleName settings is necessary in the overlay bundle.")); return false; } if (targetBundleName.equals(ModuleJsonUtil.parseBundleName(jsonString))) { @@ -927,8 +950,8 @@ public class Compressor { } } else { if (ModuleJsonUtil.isExistedStageAppTargetPriority(jsonString)) { - LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString( - "The targetPriority cannot be existed without the targetBundleName in app.json. The moduleName is " + moduleName + ".")); + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString("The targetPriority cannot be existed " + + "without the targetBundleName in app.json. The moduleName is " + moduleName + ".")); return false; } } @@ -1414,8 +1437,9 @@ public class Compressor { //pack encrypt.json file packEncryptJsonFile(utility); } catch (BundleException | IOException exception) { - String errMsg = "Compressor::compressAppModeForMultiProject file failed: " + exception.getMessage(); - LOG.error(errMsg); + String errMsg = "Compress app mode for multi project file exist Exception (BundleException | IOException): " + + exception.getMessage(); + LOG.error(PackingToolErrMsg.COMPRESS_APP_MODE_FORMULTI_PROJECT_FAILED.toString(errMsg)); throw new BundleException(errMsg); } finally { deleteFile(tempPath); @@ -1436,7 +1460,7 @@ public class Compressor { File outParentFile = destFile.getParentFile(); if ((outParentFile != null) && (!outParentFile.exists())) { if (!outParentFile.mkdirs()) { - LOG.error("Compressor::hapAddition create out file parent directory failed."); + LOG.error(PackingToolErrMsg.HAP_ADDITION_FAILED.toString("Create out file parent directory failed.")); } } FileOutputStream fileOut = null; @@ -1506,10 +1530,12 @@ public class Compressor { fileWriter.write(jsonString); fileWriter.flush(); } catch (IOException exception) { - LOG.error("writeJsonFile failed, " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Write json File exist IOException: " + + exception.getMessage())); throw new BundleException(exception.getMessage()); } catch (JSONException e) { - LOG.error("json file is invalid: " + e.getMessage()); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("Json file is exist JSONException: " + + e.getMessage())); throw new BundleException(e.getMessage()); } } @@ -1575,7 +1601,8 @@ public class Compressor { File targetParent = new File(targetParentPath); if (!targetParent.exists()) { if (!targetParent.mkdirs()) { - LOG.error("Compressor::compressHapAddition create target file parent directory failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HAP_ADDITION_FAILED.toString( + "Create target file parent directory failed.")); } } String targetPath = targetParentPath + LINUX_FILE_SEPARATOR + ADDITION_JSON; @@ -1590,8 +1617,8 @@ public class Compressor { try { setUtilityParameter(hapAdditionPath, utility); } catch (IOException e) { - String errMsg = "Compressor::compressHapAddition setUtilityParameter failed."; - LOG.error(errMsg); + String errMsg = "Set utility parameter exist IOException: " + e.getMessage(); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } if (utility.getHapPath().endsWith(HAP_SUFFIX)) { @@ -1599,8 +1626,9 @@ public class Compressor { } else if (utility.getHapPath().endsWith(HSP_SUFFIX)) { compressHsp(utility); } else { - String errMsg = "Compressor::compressHapAddition compressFile failed."; - LOG.error(errMsg); + String errMsg = "Compression add failed because file (" + utility.getHapPath() + + ") is an unsupported file type."; + LOG.error(PackingToolErrMsg.COMPRESS_HAP_ADDITION_FAILED.toString(errMsg)); throw new BundleException(errMsg); } } @@ -1626,8 +1654,8 @@ public class Compressor { finalAppPackInfo = selectHapInApp(appPath, seletedHaps, tempDir, finalAppPackInfo); } } catch (BundleException | IOException e) { - String errMsg = "Compressor:disposeApp disposeApp failed."; - LOG.error(errMsg); + String errMsg = "Dispose app exist Exception (BundleException | IOException): " + e.getMessage(); + LOG.error(PackingToolErrMsg.DISPOSE_APP_FAILED.toString(errMsg)); throw new BundleException(errMsg); } return finalAppPackInfo; @@ -1709,8 +1737,8 @@ public class Compressor { inputStream.close(); } } catch (IOException e) { - String errMsg = "Compressor:copyHapFromApp app path not found."; - LOG.error(errMsg); + String errMsg = "Copy hap and hsp from app exist IOException: " + e.getMessage(); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } finally { Utility.closeStream(zipInput); @@ -1793,8 +1821,8 @@ public class Compressor { fwriter = new FileWriter(filePath); fwriter.write(packInfoStr); } catch (IOException e) { - String errMsg = "Compressor:writePackInfo failed."; - LOG.error(errMsg); + String errMsg = "Write pack info exist IOException: " + e.getMessage(); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } finally { if (fwriter != null) { @@ -1894,21 +1922,22 @@ public class Compressor { String fName = fileName.trim(); String[] temp = fName.replace("\\", "/").split("/"); if (temp.length < 4) { - LOG.error("Compressor::compressPackResMode the hap file path is invalid, length: " - + temp.length + "."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE_FAILED.toString("The hap file path is " + + "invalid, length is " + temp.length + ", expected at least 4.")); continue; } String fileLanguageCountryName = temp[temp.length - 3]; if (!isThirdLevelDirectoryNameValid(fileLanguageCountryName)) { - LOG.error("Compressor::compressProcess compress failed third level directory name: " - + fileLanguageCountryName + " is invalid, please check it with reference to this example: " - + "zh_Hani_CN-vertical-car-mdpi-dark or zh_Hani_CN-vertical-car-mdpi."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE_FAILED.toString("Third level " + + "directory name: " + fileLanguageCountryName + " is invalid, please check it with " + + "reference to this example: zh_Hani_CN-vertical-car-mdpi-dark or " + + "zh_Hani_CN-vertical-car-mdpi.")); throw new BundleException("Compress failed third level directory name Error."); } String filePicturingName = temp[temp.length - 1]; if (!isPicturing(filePicturingName, utility)) { - LOG.error("Compressor::compressProcess Compress pack.res failed, Invalid resource file" + - " name: " + filePicturingName + ", correct format example is formName-2x2.png."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE_FAILED.toString("Invalid resource file" + + " name: " + filePicturingName + ", correct format example is formName-2x2.png.")); throw new BundleException("Compress pack.res failed, Invalid resource file name: " + filePicturingName + ", correct format example is formName-2x2.png."); } @@ -1918,7 +1947,7 @@ public class Compressor { snapshotNameList.add(fullSnapshotName); } else { - LOG.error("Compressor::compressProcess compress failed No image in PNG format is found."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE_FAILED.toString("No PNG format image found.")); throw new BundleException("Compress pack.res failed, compress failed No image in" + " PNG format is found."); } @@ -1926,8 +1955,9 @@ public class Compressor { for (String formName : formNamesList) { if (!snapshotNameList.contains(formName)) { - LOG.error("Compressor::compressProcess compress failed entryCard " + formName - + " has no related snapshot " + snapshotNameList.toString() + "."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE_FAILED.toString("EntryCard has no related " + + "snapshot. " + formName + " has no related snapshot " + + snapshotNameList.toString() + ".")); throw new BundleException("Compress pack.res failed, compress failed entryCard has no related snapshot."); } } @@ -2014,7 +2044,8 @@ public class Compressor { private boolean checkLanguage(String language) { if (!Pattern.compile(REGEX_LANGUAGE).matcher(language).matches()) { - LOG.error("Compressor::compressProcess language " + language + " is not in ISO 639-1 list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(language + + " is not in ISO 639-1 list.")); return false; } return true; @@ -2022,7 +2053,8 @@ public class Compressor { private boolean checkScript(String script) { if (!Pattern.compile(REGEX_SCRIPT).matcher(script).matches()) { - LOG.error("Compressor::compressProcess script " + script + " is not in ISO 15924 list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(script + + " is not in ISO 15924 list.")); return false; } return true; @@ -2030,7 +2062,8 @@ public class Compressor { private boolean checkCountry(String country) { if (!Pattern.compile(REGEX_COUNTRY).matcher(country).matches()) { - LOG.error("Compressor::compressProcess country " + country + " is not in ISO 3166-1 list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(country + + " is not in ISO 3166-1 list.")); return false; } return true; @@ -2038,8 +2071,8 @@ public class Compressor { private boolean checkOrientation(String orientation) { if (!Pattern.compile(REGEX_ORIENTATION).matcher(orientation).matches()) { - LOG.error("Compressor::compressProcess orientation " + orientation + - " is not in {vertical, horizontal} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(orientation + + " is not in {vertical, horizontal} list.")); return false; } return true; @@ -2047,8 +2080,8 @@ public class Compressor { private boolean checkDeviceType(String deviceType) { if (!Pattern.compile(REGEX_DEVICE_TYPE).matcher(deviceType).matches()) { - LOG.error("Compressor::compressProcess deviceType " + deviceType + - " is not in {phone, tablet, car, tv, wearable, liteWearable, 2in1} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(deviceType + + " is not in {phone, tablet, car, tv, wearable, liteWearable, 2in1} list.")); return false; } return true; @@ -2056,8 +2089,8 @@ public class Compressor { private boolean checkScreenDensity(String screenDensity) { if (!Pattern.compile(REGEX_SCREEN_DENSITY).matcher(screenDensity).matches()) { - LOG.error("Compressor::compressProcess screenDensity " + screenDensity + - " is not in {sdpi, mdpi, ldpi, xldpi, xxldpi} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(screenDensity + + " is not in {sdpi, mdpi, ldpi, xldpi, xxldpi} list.")); return false; } return true; @@ -2065,8 +2098,8 @@ public class Compressor { private boolean checkColorMode(String colorMode) { if (!Pattern.compile(REGEX_COLOR_MODE).matcher(colorMode).matches()) { - LOG.error("Compressor::compressProcess colorMode " + colorMode + - " is not in {light, dark} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(colorMode + + " is not in {light, dark} list.")); return false; } return true; @@ -2077,8 +2110,8 @@ public class Compressor { Pattern.compile(REGEX_SHAPE).matcher(tmp).matches()) { return true; } - LOG.error("Compressor::compressProcess " + tmp + - " is neither in colorMode list {light, dark} nor in shape list {circle}."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(tmp + + " is neither in colorMode list {light, dark} nor in shape list {circle}.")); return false; } @@ -2086,7 +2119,7 @@ public class Compressor { if (Pattern.compile(REGEX_SHAPE).matcher(shape).matches()) { return true; } - LOG.error("Compressor::compressProcess shape" + shape + " is not in {circle} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(shape + " is not in {circle} list.")); return false; } @@ -2103,24 +2136,26 @@ public class Compressor { return isSpecifications; } if (!name.endsWith(PNG_SUFFIX) && !name.endsWith(UPPERCASE_PNG_SUFFIX)) { - LOG.error("isPicturing: the suffix is not .png or .PNG."); + LOG.error(PackingToolErrMsg.IS_PICTURING_FAILED.toString("The suffix is not .png or .PNG.")); return false; } int delimiterIndex = name.lastIndexOf("-"); if (delimiterIndex < 0) { - LOG.error("isPicturing: the entry card naming format is invalid and should be separated by '-'."); + LOG.error(PackingToolErrMsg.IS_PICTURING_FAILED.toString( + "The entry card naming format is invalid and should be separated by '-'.")); return false; } String formName = name.substring(0, delimiterIndex); if (!utility.getFormNameList().contains(formName)) { - LOG.error("isPicturing: the name is not same as formName, name: " + formName + " is not in " + - utility.getFormNameList().toString() + "."); + LOG.error(PackingToolErrMsg.IS_PICTURING_FAILED.toString( + "The name is not same as formName, name: " + formName + " is not in " + + utility.getFormNameList().toString() + ".")); return false; } String dimension = name.substring(delimiterIndex + 1, name.lastIndexOf(".")); if (!supportDimensionsList.contains(dimension)) { - LOG.error("isPicturing: the dimension: " + dimension + " is invalid, is not in the following list: " - + "{1X2, 2X2, 2X4, 4X4, 1X1, 6X4}."); + LOG.error(PackingToolErrMsg.IS_PICTURING_FAILED.toString(dimension + " is invalid, is not in the " + + "following list: {1X2, 2X2, 2X4, 4X4, 1X1, 6X4}.")); return false; } @@ -2130,12 +2165,14 @@ public class Compressor { private void getFileList(final String filePath) throws BundleException { File file = new File(filePath); if (!file.exists()) { - LOG.error("getFileList: file is not exists."); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("File does not exist. File path is " + + filePath + ".")); return; } File[] files = file.listFiles(); if (files == null) { - LOG.error("getFileList: no file in this file path."); + LOG.error(PackingToolErrMsg.GET_FILE_LIST_FAILED.toString("No files found in the specified path: " + + filePath + ".")); return; } for (File f : files) { @@ -2147,8 +2184,8 @@ public class Compressor { } String snapshotDirectoryName = f.getParentFile().getName(); if (!ENTRYCARD_SNAPSHOT_NAME.equals(snapshotDirectoryName)) { - LOG.error("The level-4 directory of EntryCard must be named as snapshot" + - ", but current is: " + snapshotDirectoryName + "."); + LOG.error(PackingToolErrMsg.GET_FILE_LIST_FAILED.toString("The level-4 directory of EntryCard " + + "must be named as snapshot, but current is: " + snapshotDirectoryName + ".")); throw new BundleException("The level-4 directory of EntryCard must be named as snapshot" + ", but current is: " + snapshotDirectoryName + "."); } @@ -2156,10 +2193,11 @@ public class Compressor { } else if (f.isDirectory()) { getFileList(f.getCanonicalPath()); } else { - LOG.error("It's not file or directory."); + LOG.error(PackingToolErrMsg.GET_FILE_LIST_FAILED.toString("It's not file or directory.")); } } catch (IOException msg) { - LOG.error("IOException error: " + msg.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Get file list exist IOException: " + + msg.getMessage())); return; } } @@ -2249,7 +2287,7 @@ public class Compressor { zipCreator.writeTo(zipOut); } catch (IOException | InterruptedException | ExecutionException e) { LOG.error(PackingToolErrMsg.COMPRESS_PARALLEL_EXCEPTION.toString( - "Parallel compress exist Exception(IOException | InterruptedException | ExecutionException): " + e.getMessage())); + "Parallel compress exist Exception (IOException | InterruptedException | ExecutionException): " + e.getMessage())); throw new BundleException("Parallel compress exception. " + e.getMessage()); } } @@ -2421,8 +2459,7 @@ public class Compressor { count = fileInputStream.read(buffer); } } catch (FileNotFoundException ignored) { - LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString( - "Get Crc from file exist FileNotFoundException: " + ignored.getMessage())); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("File not found when getting Crc.")); throw new BundleException("Get Crc from file failed."); } catch (IOException exception) { LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( @@ -2568,8 +2605,7 @@ public class Compressor { count = fileInputStream.read(buffer); } } catch (FileNotFoundException ignored) { - LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString( - "Get Crc32 from file exist FileNotFoundException: " + ignored.getMessage())); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("File not found when getting Crc.")); throw new BundleException("Get Crc from file failed: " + file.getName()); } catch (IOException exception) { LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString( @@ -2589,15 +2625,16 @@ public class Compressor { ModuleJsonUtil.parsePackInfoFormsName(jsonString, nameList, formNamesList); for (String formName : nameList) { if (formName.isEmpty()) { - LOG.error("Compressor::infoSpecialJsonFileProcess form name is empty."); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("Form name parsed from " + + "pack.info is empty.")); continue; } utility.addFormNameList(formName); } } catch (JSONException e) { - LOG.error("Compressor::infoSpecialJsonFileProcess json Path: " + jsonPath + - "json exception: " + e.getMessage()); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("Parse pack.info eixst JSONException: " + + e.getMessage())); } } @@ -2628,7 +2665,8 @@ public class Compressor { str = bufferedReader.readLine(); } } catch (IOException exception) { - LOG.error("Compressor::jsonSpecialProcess io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("pack.info special process exist IOException: " + + exception.getMessage())); throw new BundleException("Json special process failed."); } finally { Utility.closeStream(bufferedReader); @@ -2731,7 +2769,8 @@ public class Compressor { } } } catch (IOException exception) { - LOG.error("Compressor::parseModuleName io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Parse module name exist IOException: " + + exception.getMessage())); throw new BundleException("Parse module name failed."); } } @@ -2808,19 +2847,22 @@ public class Compressor { try { int endIndex = lineStr.lastIndexOf(SEMICOLON); if (endIndex <= 0) { - LOG.error("Compressor::getModuleNameFromString field the json is not standard."); + LOG.error(PackingToolErrMsg.GET_MODULE_NAME_FROM_STRING_FAILED.toString("Unable to find '\"' " + + "in the lineStr.")); throw new BundleException("Parse module name failed, module-name is invalid."); } int startIndex = lineStr.lastIndexOf(SEMICOLON, endIndex - 1) + 1; String moduleName = lineStr.substring(startIndex, endIndex); list.add(moduleName); if (moduleName == null || moduleName.isEmpty()) { - LOG.error("Compressor::getModuleNameFromString field module-name is empty."); + LOG.error(PackingToolErrMsg.GET_MODULE_NAME_FROM_STRING_FAILED.toString("moduleName or module-name " + + "is empty.")); throw new BundleException("Parse module name failed, module-name is empty."); } utility.setModuleName(moduleName); } catch (StringIndexOutOfBoundsException exception) { - LOG.error("Compressor::parseModuleName field module-name is fault: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.GET_MODULE_NAME_FROM_STRING_FAILED.toString("Get Module name from line string " + + "exist StringIndexOutOfBoundsException: " + exception.getMessage())); throw new BundleException("Parse module name failed, module-name is invalid."); } } @@ -3096,8 +3138,8 @@ public class Compressor { private void compressAPPQFMode(Utility utility) throws BundleException { List fileList = utility.getFormatedHQFList(); if (!checkHQFIsValid(fileList)) { - LOG.error("checkHQFIsValid failed when pack appqf file."); - throw new BundleException("checkHQFIsValid failed when pack appqf file."); + LOG.error(PackingToolErrMsg.COMPRESS_APPQF_FAILED.toString("Verify failed when compress appqf.")); + throw new BundleException("Verify failed when compress appqf."); } for (String hapPath : fileList) { pathToFile(utility, hapPath, NULL_DIR_NAME, false); @@ -3116,7 +3158,7 @@ public class Compressor { hqfVerifyInfos.add(ModuleJsonUtil.parseHQFInfo(file)); } if (!HQFVerify.checkHQFIsValid(hqfVerifyInfos)) { - LOG.error("input hqf is invalid."); + LOG.error(PackingToolErrMsg.CHECK_HQF_INVALID.toString("Input hqf is invalid.")); return false; } return true; @@ -3243,7 +3285,7 @@ public class Compressor { tempDir.toAbsolutePath() + LINUX_FILE_SEPARATOR + PACKINFO_NAME); if (moduleFile.exists() && configFile.exists()) { - LOG.error("versionNormalize failed, invalid hap structure."); + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_FAILED.toString("Invalid hap structure.")); throw new BundleException("versionNormalize failed, invalid hap structure."); } if (moduleFile.exists()) { @@ -3253,7 +3295,7 @@ public class Compressor { String configJsonPath = tempDir.resolve(CONFIG_JSON).toString(); util = parseAndModifyConfigJson(configJsonPath, utility); } else { - LOG.error("versionNormalize failed, invalid hap structure."); + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_FAILED.toString("Invalid hap structure.")); throw new BundleException("versionNormalize failed, invalid hap structure."); } if (packInfoFile.exists()) { @@ -3268,7 +3310,8 @@ public class Compressor { LINUX_FILE_SEPARATOR + Paths.get(hapPath).getFileName().toString(); compressDirToHap(tempDir, modifiedHapPath); } catch (IOException | BundleException e) { - LOG.error("versionNormalize failed " + e.getMessage()); + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_FAILED.toString( + "Version normalize exist Exception (IOException | BundleException): " + e.getMessage())); } finally { if (tempDir != null) { deleteDirectory(tempDir.toFile()); @@ -3355,7 +3398,8 @@ public class Compressor { new FileOutputStream(jsonFilePath), StandardCharsets.UTF_8)); bw.write(pretty); } catch (IOException exception) { - LOG.error("Compressor::writeJson failed for IOException " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Write json exist IOException: " + + exception.getMessage())); throw new BundleException("Compressor::writeJson failed for IOException"); } finally { if (bw != null) { @@ -3402,8 +3446,9 @@ public class Compressor { versionObj.put(NAME, utility.getVersionName()); writeJson(jsonFilePath, jsonObject); } catch (IOException e) { - LOG.error("parseAndModifyModuleJson IOException." + e.getMessage()); - throw new BundleException("parseAndModifyModuleJson IOException." + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Parse and modify config.json exist IOException: " + + e.getMessage())); + throw new BundleException("Parse and modify config.json exist IOException: " + e.getMessage()); } return util; } @@ -3494,7 +3539,8 @@ public class Compressor { try (FileWriter fileWriter = new FileWriter(outPath + LINUX_FILE_SEPARATOR + VERSION_RECORD)) { fileWriter.write(jsonString); } catch (IOException e) { - LOG.error("writeVersionRecord failed " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Write version record exist IOException: " + + e.getMessage())); } } @@ -3543,7 +3589,7 @@ public class Compressor { zipInputStream.closeEntry(); } } catch (IOException e) { - LOG.error("unpack hap failed IOException " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Unpack hap exist IOException: " + e.getMessage())); throw new BundleException("unpack hap failed IOException " + e.getMessage()); } } diff --git a/adapter/ohos/ErrorMsg.java b/adapter/ohos/ErrorMsg.java index cb93d8bf9269cd72370a0067894ab4689482766b..040e7cabe0fc7b5bb52d4efceb47333bf31a3334 100644 --- a/adapter/ohos/ErrorMsg.java +++ b/adapter/ohos/ErrorMsg.java @@ -1,193 +1,177 @@ -/* - * Copyright (c) 2025-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - package ohos; - import java.util.ArrayList; - import java.util.List; - import java.util.Locale; - import java.util.MissingFormatArgumentException; - - /** - * ErrorMsg - * - * @since 2025/01/21 - */ - public class ErrorMsg { - private static final Log LOG = new Log(ErrorMsg.class.toString()); - - private static final String PACKING_TOOL_SUB_SYSTEM_CODE = "100"; - - private final String code; - - private final String description; - - private final String cause; - - private final List solutions; - - /** - * ErrorMsg constructor - * - * @param code code - * @param description description - * @param cause cause - * @param solutions solutions - */ - public ErrorMsg(String code, String description, String cause, - List solutions) { - this.code = code; - this.description = description; - this.cause = cause; - this.solutions = solutions; - } - - /** - * getPackingToolErrBuilder - * - * @return Builder - */ - public static Builder getPackingToolErrBuilder() { - return new Builder(PACKING_TOOL_SUB_SYSTEM_CODE); - } - - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append(code) - .append(" ") - .append(description) - .append(System.lineSeparator()) - .append("Error Message: ") - .append(cause) - .append(System.lineSeparator()); - - if (solutions != null && !solutions.isEmpty()) { - sb.append(System.lineSeparator()).append("* Try the following: ").append(System.lineSeparator()); - for (String s : solutions) { - sb.append(" > ").append(s).append(System.lineSeparator()); - } - } - return sb.toString(); - } - - /** - * to String - * - * @param args args - * @return String - */ - public String toString(Object... args) { - try { - return String.format(Locale.ROOT, this.toString(), args); - } catch (MissingFormatArgumentException e) { - LOG.error("args format failed: " + args); - return this.toString(); - } - } - - /** - * Builder - * - * @since 2025/01/21 - */ - public static class Builder { - private String sysCode; - - private String errCode; - - private String typeCode; - - private String description; - - private String cause; - - private List solutions = new ArrayList<>(); - - /** - * Builder Constructor - * - * @param sysCode sysCode - */ - public Builder(String sysCode) { - this.sysCode = sysCode; - } - - /** - * setErrCode - * - * @param errCode errCode - * @return Builder - */ - public Builder setErrCode(String errCode) { - this.errCode = errCode; - return this; - } - - /** - * setTypeCode - * - * @param typeCode typeCode - * @return Builder - */ - public Builder setTypeCode(String typeCode) { - this.typeCode = typeCode; - return this; - } - - /** - * setDescription - * - * @param description description - * @return Builder - */ - public Builder setDescription(String description) { - this.description = description; - return this; - } - - /** - * setCause - * - * @param cause cause - * @return Builder - */ - public Builder setCause(String cause) { - this.cause = cause; - return this; - } - - /** - * addSolution - * - * @param solution solution - * @return Builder - */ - public Builder addSolution(String solution) { - this.solutions.add(solution); - return this; - } - - /** - * build - * - * @return ErrorMsg - */ - public ErrorMsg build() { - return new ErrorMsg(sysCode + typeCode + errCode, description, cause, solutions); - } - } - } - \ No newline at end of file +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.MissingFormatArgumentException; + +/** + * ErrorMsg + * + * @since 2025/01/21 + */ +public class ErrorMsg { + private static final Log LOG = new Log(ErrorMsg.class.toString()); + private static final String PACKING_TOOL_SUB_SYSTEM_CODE = "100"; + + private final String code; + private final String description; + private final String cause; + private final List solutions; + + /** + * ErrorMsg constructor + * + * @param code code + * @param description description + * @param cause cause + * @param solutions solutions + */ + public ErrorMsg(String code, String description, String cause, List solutions) { + this.code = code; + this.description = description; + this.cause = cause; + this.solutions = solutions; + } + + /** + * getPackingToolErrBuilder + * + * @return Builder + */ + public static Builder getPackingToolErrBuilder() { + return new Builder(PACKING_TOOL_SUB_SYSTEM_CODE); + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append(code).append(" ").append(description).append(System.lineSeparator()).append("Error Message: ") + .append(cause).append(System.lineSeparator()); + + if (solutions != null && !solutions.isEmpty()) { + sb.append(System.lineSeparator()).append("* Try the following: ").append(System.lineSeparator()); + for (String s : solutions) { + sb.append(" > ").append(s).append(System.lineSeparator()); + } + } + return sb.toString(); + } + + /** + * to String + * + * @param args args + * @return String + */ + public String toString(Object... args) { + try { + return String.format(Locale.ROOT, this.toString(), args); + } catch (MissingFormatArgumentException e) { + LOG.error("args format failed: " + args); + return this.toString(); + } + } + + /** + * Builder + * + * @since 2025/01/21 + */ + public static class Builder { + private String sysCode; + private String errCode; + private String typeCode; + private String description; + private String cause; + private List solutions = new ArrayList<>(); + + /** + * Builder Constructor + * + * @param sysCode sysCode + */ + public Builder(String sysCode) { + this.sysCode = sysCode; + } + + /** + * setErrCode + * + * @param errCode errCode + * @return Builder + */ + public Builder setErrCode(String errCode) { + this.errCode = errCode; + return this; + } + + /** + * setTypeCode + * + * @param typeCode typeCode + * @return Builder + */ + public Builder setTypeCode(String typeCode) { + this.typeCode = typeCode; + return this; + } + + /** + * setDescription + * + * @param description description + * @return Builder + */ + public Builder setDescription(String description) { + this.description = description; + return this; + } + + /** + * setCause + * + * @param cause cause + * @return Builder + */ + public Builder setCause(String cause) { + this.cause = cause; + return this; + } + + /** + * addSolution + * + * @param solution solution + * @return Builder + */ + public Builder addSolution(String solution) { + this.solutions.add(solution); + return this; + } + + /** + * build + * + * @return ErrorMsg + */ + public ErrorMsg build() { + return new ErrorMsg(sysCode + typeCode + errCode, description, cause, solutions); + } + } +} \ No newline at end of file diff --git a/adapter/ohos/FileUtils.java b/adapter/ohos/FileUtils.java index a854c27c0f081c2a0f40d77ef2ca236788aea6e5..3d7417ef06e4b4b1eb8ff62c920f899c6575e87c 100644 --- a/adapter/ohos/FileUtils.java +++ b/adapter/ohos/FileUtils.java @@ -344,8 +344,8 @@ class FileUtils { */ public static void copyFile(File sourceFile, File destFile) throws IOException, BundleException { if (sourceFile == null || destFile == null) { - String errMsg = "CompressorFileUtil::copyFile input file is null."; - LOG.error(errMsg); + String errMsg = "Source file or destination file is null."; + LOG.error(PackingToolErrMsg.COPY_FILE_FAILED.toString(errMsg)); throw new BundleException(errMsg); } InputStream inputStream = null; @@ -372,8 +372,8 @@ class FileUtils { */ public static void makeDir(File dirFile) throws IOException, BundleException { if (dirFile == null) { - String errMsg = "CompressorFileUtil::makeDir input file is null."; - LOG.error(errMsg); + String errMsg = "Input file is null."; + LOG.error(PackingToolErrMsg.MAKE_DIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } dirFile.mkdirs(); @@ -414,7 +414,8 @@ class FileUtils { } jsonStr = new StringBuilder(jsonStr.toString().replaceAll("\r|\n|\t", "")); } catch (IOException exception) { - LOG.error("Compressor::checkModuleTypeInHaps io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "Get Json in zips exist IOException: " + exception.getMessage())); throw new BundleException("Compressor::checkModuleTypeInHaps failed."); } finally { Utility.closeStream(zipFile); @@ -447,7 +448,8 @@ class FileUtils { } } } catch (IOException e) { - LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Get profile json exist IOExpection: " + e.getMessage())); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "Get profile json exist IOException: " + e.getMessage())); throw new BundleException("Get profile json failed."); } return resourceMap; diff --git a/adapter/ohos/HQFVerify.java b/adapter/ohos/HQFVerify.java index a872ddfe423443aea7d6523d4eeebd776b25df74..2576c19a1a7d19c77c4b561b625b22274472080e 100644 --- a/adapter/ohos/HQFVerify.java +++ b/adapter/ohos/HQFVerify.java @@ -33,15 +33,15 @@ class HQFVerify { public static boolean checkHQFIsValid(List hqfVerifyInfos) { // check app fields if (hqfVerifyInfos.isEmpty()) { - LOG.error("input hqf file is empty."); + LOG.error(PackingToolErrMsg.CHECK_HQF_INVALID.toString("Input hqf file is empty.")); return false; } if (!checkAppFields(hqfVerifyInfos)) { - LOG.error("input hqf file has different fields in app."); + LOG.error(PackingToolErrMsg.CHECK_HQF_INVALID.toString("Input hqf file has different fields in app.")); return false; } if (!checkModuleIsValid(hqfVerifyInfos)) { - LOG.error("input hqf file moduleName is invalid."); + LOG.error(PackingToolErrMsg.CHECK_HQF_INVALID.toString("Input hqf file moduleName is invalid.")); return false; } return true; @@ -61,23 +61,28 @@ class HQFVerify { String patchVersionName = hqfVerifyInfos.get(0).getPatchVersionName(); for (HQFInfo hqfVerifyInfo : hqfVerifyInfos) { if (bundleName == null || !bundleName.equals(hqfVerifyInfo.getBundleName())) { - LOG.error("input hqf file has different bundleName."); + String errMsg = "Input hqf file has different bundleName."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_FAILED.toString(errMsg)); return false; } if (versionCode != hqfVerifyInfo.getVersionCode()) { - LOG.error("input hqf file has different versionCode."); + String errMsg = "Input hqf file has different versionCode."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_FAILED.toString(errMsg)); return false; } if (versionName == null || !versionName.equals(hqfVerifyInfo.getVersionName())) { - LOG.error("input hqf file has different versionName."); + String errMsg = "Input hqf file has different versionName."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_FAILED.toString(errMsg)); return false; } if (patchVersionCode != hqfVerifyInfo.getPatchVersionCode()) { - LOG.error("input hqf file has different patchVersionCode."); + String errMsg = "Input hqf file has different patchVersionCode."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_FAILED.toString(errMsg)); return false; } if (patchVersionName == null || !patchVersionName.equals(hqfVerifyInfo.getPatchVersionName())) { - LOG.error("input hqf file has different patchVersionName."); + String errMsg = "Input hqf file has different patchVersionName."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_FAILED.toString(errMsg)); return false; } } @@ -94,7 +99,8 @@ class HQFVerify { for (int i = 0; i < hqfVerifyInfos.size(); ++i) { for (int j = i + 1; j < hqfVerifyInfos.size(); ++j) { if (checkModuleIsDuplicated(hqfVerifyInfos.get(i), hqfVerifyInfos.get(j))) { - LOG.error("input hqf file moduleName duplicated."); + String errMsg = "Input hqf file moduleName is duplicated."; + LOG.error(PackingToolErrMsg.CHECK_MODULE_INVALID.toString(errMsg)); return false; } } diff --git a/adapter/ohos/HapVerify.java b/adapter/ohos/HapVerify.java index b94e41ea870bcaeaac7f7ab205d5dafc6d1a919d..aa19f93e8b28f2b459f00d719327865f10a26f51 100644 --- a/adapter/ohos/HapVerify.java +++ b/adapter/ohos/HapVerify.java @@ -214,8 +214,8 @@ class HapVerify { } if (!hapVerifyInfo.getDependencyItemList().isEmpty()) { String cause = "The shared App cannot depend on other modules."; - String solution = - "Remove dependencies settings in 'module.json5' and ensure module does not contain dependencies."; + String solution = "Remove dependencies settings in 'module.json5' and ensure module does " + + "not contain dependencies."; LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); return false; } @@ -324,18 +324,18 @@ class HapVerify { if (hap.getVersion().minCompatibleVersionCode != hapInfo.getVersion().minCompatibleVersionCode || hap.getApiVersion().getTargetApiVersion() != hapInfo.getApiVersion().getTargetApiVersion()) { String errMsg = "Hap minCompatibleVersionCode or targetApiVersion different."; - String solution = - "Ensure that the values of 'minCompatibleVersionCode' and 'targetApiVersion' in the module.json file of each HAP module are the same."; + String solution = "Ensure that the values of 'minCompatibleVersionCode' and 'targetApiVersion' " + + "in the module.json file of each HAP module are the same."; LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(errMsg, solution)); return false; } } if (hap.getVersion().minCompatibleVersionCode < minCompatibleVersionCode || hap.getApiVersion().getTargetApiVersion() < targetApiVersion) { - String cause = "The values of minCompatibleVersionCode or targetApiVersion in the module.json file of the HAP " + - "module are smaller than those of the HSP module."; - String solution = "Ensure that the values of aminCompatibleVersionCode and targetApiVersion in the module.json file " + - "of the HAP module are greater than or equal to those of the HSP module."; + String cause = "The values of minCompatibleVersionCode or targetApiVersion in the module.json file " + + "of the HAP module are smaller than those of the HSP module."; + String solution = "Ensure that the values of aminCompatibleVersionCode and targetApiVersion in the " + + "module.json file of the HAP module are greater than or equal to those of the HSP module."; LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); return false; } @@ -442,16 +442,17 @@ class HapVerify { String cause = "Module: (" + hapVerifyInfos.get(i).getModuleName() + ") and Module: (" + hapVerifyInfos.get(j).getModuleName() + ") have the same moduleName, " + "please check deviceType or distroFilter of the module.\n" + "Module: " + - hapVerifyInfos.get(i).getModuleName() + " has deviceType " + hapVerifyInfos.get(i).getDeviceType() + - ".\n" + "Another Module: " + hapVerifyInfos.get(j).getModuleName() + " has deviceType " + + hapVerifyInfos.get(i).getModuleName() + " has deviceType " + + hapVerifyInfos.get(i).getDeviceType() + ".\n" + "Another Module: " + + hapVerifyInfos.get(j).getModuleName() + " has deviceType " + hapVerifyInfos.get(j).getDeviceType() + "."; if (!EMPTY_STRING.equals(hapVerifyInfos.get(i).getDistroFilter().dump())) { cause += "\n" + "Module: " + hapVerifyInfos.get(i).getModuleName() + " DistroFilter is " + hapVerifyInfos.get(i).getDistroFilter().dump() + "."; } if (!EMPTY_STRING.equals(hapVerifyInfos.get(j).getDistroFilter().dump())) { - cause += "\n" +"Another Module: " + hapVerifyInfos.get(j).getModuleName() + " DistroFilter is " + - hapVerifyInfos.get(j).getDistroFilter().dump() + "."; + cause += "\n" + "Another Module: " + hapVerifyInfos.get(j).getModuleName() + + " DistroFilter is " + hapVerifyInfos.get(j).getDistroFilter().dump() + "."; } String solution = "Make sure the module name is valid and unique.\n" + "Reference: " + REFERENCE_LINK + "."; @@ -481,16 +482,17 @@ class HapVerify { String cause = "Module: (" + hapVerifyInfos.get(i).getModuleName() + ") and Module: (" + hapVerifyInfos.get(j).getModuleName() + ") have the same packageName, " + "please check deviceType or distroFilter of the module.\n" + "Module: " + - hapVerifyInfos.get(i).getModuleName() + " has deviceType " + hapVerifyInfos.get(i).getDeviceType() + - ".\n" + "Another Module: " + hapVerifyInfos.get(j).getModuleName() + " has deviceType " + + hapVerifyInfos.get(i).getModuleName() + " has deviceType " + + hapVerifyInfos.get(i).getDeviceType() + ".\n" + "Another Module: " + + hapVerifyInfos.get(j).getModuleName() + " has deviceType " + hapVerifyInfos.get(j).getDeviceType() + "."; if (!EMPTY_STRING.equals(hapVerifyInfos.get(i).getDistroFilter().dump())) { cause += "\n" + "Module: " + hapVerifyInfos.get(i).getModuleName() + " DistroFilter is " + hapVerifyInfos.get(i).getDistroFilter().dump() + "."; } if (!EMPTY_STRING.equals(hapVerifyInfos.get(j).getDistroFilter().dump())) { - cause += "\n" + "Another Module: " + hapVerifyInfos.get(j).getModuleName() + " DistroFilter is " + - hapVerifyInfos.get(j).getDistroFilter().dump() + "."; + cause += "\n" + "Another Module: " + hapVerifyInfos.get(j).getModuleName() + + " DistroFilter is " + hapVerifyInfos.get(j).getDistroFilter().dump() + "."; } String solution = "Make sure package name is valid and unique.\n" + "Reference: " + REFERENCE_LINK + "."; @@ -616,7 +618,8 @@ class HapVerify { for (String uri : info.getProxyDataUris()) { if (uriSet.contains(uri)) { String moduleName = info.getModuleName(); - String cause = "The uri(" + uri + ") in proxyData settings of Module(" + moduleName + ") is duplicated."; + String cause = "The uri(" + uri + ") in proxyData settings of Module(" + moduleName + + ") is duplicated."; String solution = "Ensure that the uri in proxyData is unique across different modules."; LOG.error(PackingToolErrMsg.PROXY_DATA_URI_NOT_UNIQUE.toString(cause, solution)); return false; @@ -672,9 +675,8 @@ class HapVerify { " DistroFilter is " + entryHapVerifyInfos.get(j).getDistroFilter().dump() + "."; } - String solution = - "Make sure the entry module is valid and unique, and the HAP uniqueness check logic passes.\n" + - "Reference: " + REFERENCE_LINK + "."; + String solution = "Make sure the entry module is valid and unique, and the HAP uniqueness " + + "check logic passes.\nReference: " + REFERENCE_LINK + "."; LOG.error(PackingToolErrMsg.CHECK_ENTRY_INVALID.toString(cause, solution)); return false; } @@ -707,7 +709,7 @@ class HapVerify { } // check distroFilter if (checkDistroFilterDisjoint(hapVerifyInfoLeft.getDistroFilter(), hapVerifyInfoRight.getDistroFilter(), - hapVerifyInfoLeft.getModuleName(), hapVerifyInfoRight.getModuleName())) { + hapVerifyInfoLeft.getModuleName(), hapVerifyInfoRight.getModuleName())) { return true; } @@ -719,42 +721,48 @@ class HapVerify { * * @param distroFilterLeft is one distroFilter * @param distroFilterRight is another distroFilter will be checked - * @throws BundleException Throws this exception if the json is not standard. + * @param moduleNameLeft is the moduleName associated with distroFilterLeft + * @param moduleNameRight is the moduleName associated with distroFilterRight * @return true if two distroFilter is disjoint + * @throws BundleException Throws this exception if the json is not standard. */ private static boolean checkDistroFilterDisjoint(DistroFilter distroFilterLeft, DistroFilter distroFilterRight, - String moduleNameLeft, String moduleNameRight) - throws BundleException { + String moduleNameLeft, String moduleNameRight) throws BundleException { if (distroFilterLeft == null || distroFilterRight == null) { return false; } if (distroFilterLeft.apiVersion != null && distroFilterRight.apiVersion != null) { if (checkPolicyValueDisjoint(distroFilterLeft.apiVersion.policy, distroFilterLeft.apiVersion.value, - distroFilterRight.apiVersion.policy, distroFilterRight.apiVersion.value, moduleNameLeft, moduleNameRight)) { + distroFilterRight.apiVersion.policy, distroFilterRight.apiVersion.value, + moduleNameLeft, moduleNameRight)) { return true; } } if (distroFilterLeft.screenShape != null && distroFilterRight.screenShape != null) { if (checkPolicyValueDisjoint(distroFilterLeft.screenShape.policy, distroFilterLeft.screenShape.value, - distroFilterRight.screenShape.policy, distroFilterRight.screenShape.value, moduleNameLeft, moduleNameRight)) { + distroFilterRight.screenShape.policy, distroFilterRight.screenShape.value, + moduleNameLeft, moduleNameRight)) { return true; } } if (distroFilterLeft.screenDensity != null && distroFilterRight.screenDensity != null) { if (checkPolicyValueDisjoint(distroFilterLeft.screenDensity.policy, distroFilterLeft.screenDensity.value, - distroFilterRight.screenDensity.policy, distroFilterRight.screenDensity.value, moduleNameLeft, moduleNameRight)) { + distroFilterRight.screenDensity.policy, distroFilterRight.screenDensity.value, + moduleNameLeft, moduleNameRight)) { return true; } } if (distroFilterLeft.screenWindow != null && distroFilterRight.screenWindow != null) { if (checkPolicyValueDisjoint(distroFilterLeft.screenWindow.policy, distroFilterLeft.screenWindow.value, - distroFilterRight.screenWindow.policy, distroFilterRight.screenWindow.value, moduleNameLeft, moduleNameRight)) { + distroFilterRight.screenWindow.policy, distroFilterRight.screenWindow.value, + moduleNameLeft, moduleNameRight)) { return true; } } if (distroFilterLeft.countryCode != null && distroFilterRight.countryCode != null) { if (checkPolicyValueDisjoint(distroFilterLeft.countryCode.policy, distroFilterLeft.countryCode.value, - distroFilterRight.countryCode.policy, distroFilterRight.countryCode.value, moduleNameLeft, moduleNameRight)) { + distroFilterRight.countryCode.policy, distroFilterRight.countryCode.value, + moduleNameLeft, moduleNameRight)) { return true; } } @@ -772,12 +780,11 @@ class HapVerify { * @throws BundleException Throws this exception if the json is not standard. */ private static boolean checkPolicyValueDisjoint(String policyLeft, List valueLeft, String policyRight, - List valueRight, String moduleNameLeft, String ModuleNameRight) - throws BundleException { + List valueRight, String moduleNameLeft, String moduleNameRight) throws BundleException { if (valueLeft == null || valueRight == null) { String errMsg = "The variable 'value' in the distributionFilter setting is empty."; String solution = "Ensure that all distributionFilter file and filter settings has 'value' setting."; - solution += "Module " + moduleNameLeft + " and " + ModuleNameRight + " can be checked in priority."; + solution += "Module " + moduleNameLeft + " and " + moduleNameRight + " can be checked in priority."; LOG.error(PackingToolErrMsg.CHECK_POLICY_DISJOINT_ERROR.toString(errMsg, solution)); throw new BundleException("Check policy value disjoint value should not empty."); } @@ -797,8 +804,9 @@ class HapVerify { return false; } else { String errMsg = "Check distributionFilter 'policy' setting is invalid."; - String solution = "Ensure all distributionFilter file and filter settings 'policy' value must 'include' or 'exclude'.\n"; - solution += "Module " + moduleNameLeft + " and " + ModuleNameRight + " can be checked in priority."; + String solution = "Ensure all distributionFilter file and filter settings 'policy' value must " + + "'include' or 'exclude'.\n"; + solution += "Module " + moduleNameLeft + " and " + moduleNameRight + " can be checked in priority."; LOG.error(PackingToolErrMsg.CHECK_POLICY_DISJOINT_ERROR.toString(errMsg, solution)); throw new BundleException("Check policy value disjoint input policy is invalid."); } @@ -936,8 +944,8 @@ class HapVerify { flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Entry module(" + hapVerifyInfo.getModuleName() + ") apiVersion policy '" + hapVerifyInfo.getDistroFilter().apiVersion.policy + - "' is invalid.")); + "Entry module(" + hapVerifyInfo.getModuleName() + ") apiVersion policy '" + + hapVerifyInfo.getDistroFilter().apiVersion.policy + "' is invalid.")); throw new BundleException("Check apiVersion covered input policy is invalid."); } } @@ -987,7 +995,8 @@ class HapVerify { flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Entry module(" + hapVerifyInfo.getModuleName() + ") screenShape policy '" + hapVerifyInfo.getDistroFilter().screenShape.policy + "' is invalid.")); + "Entry module(" + hapVerifyInfo.getModuleName() + ") screenShape policy '" + + hapVerifyInfo.getDistroFilter().screenShape.policy + "' is invalid.")); throw new BundleException("Check screenShape covered input policy is invalid."); } } @@ -1009,6 +1018,7 @@ class HapVerify { * @param screenWindow is the screenWindow of feature hap * @param entryHaps is the haps that feature matched * @return screenWindow is valid + * @throws BundleException when input policy is invalid */ private static boolean checkScreenWindowCovered(ScreenWindow screenWindow, List entryHaps) throws BundleException { @@ -1036,7 +1046,8 @@ class HapVerify { flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Entry module(" + hapVerifyInfo.getModuleName() + ") screenWindow policy '" + hapVerifyInfo.getDistroFilter().screenWindow.policy + "' is invalid.")); + "Entry module(" + hapVerifyInfo.getModuleName() + ") screenWindow policy '" + + hapVerifyInfo.getDistroFilter().screenWindow.policy + "' is invalid.")); throw new BundleException("Check screenWindow covered input policy is invalid."); } } @@ -1058,6 +1069,7 @@ class HapVerify { * @param screenDensity is the screenDensity of feature hap * @param entryHaps is the haps that feature matched * @return screenDensity is valid + * @throws BundleException when input policy is invalid */ private static boolean checkScreenDensityCovered(ScreenDensity screenDensity, List entryHaps) throws BundleException { @@ -1085,7 +1097,8 @@ class HapVerify { flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Entry module(" + hapVerifyInfo.getModuleName() + ") screenDensity policy '" + hapVerifyInfo.getDistroFilter().screenDensity.policy + "' is invalid.")); + "Entry module(" + hapVerifyInfo.getModuleName() + ") screenDensity policy '" + + hapVerifyInfo.getDistroFilter().screenDensity.policy + "' is invalid.")); throw new BundleException("Check screenDensity covered input policy is invalid."); } } @@ -1107,6 +1120,7 @@ class HapVerify { * @param countryCode is the countryCode of feature hap * @param entryHaps is the haps that feature matched * @return countryCode is valid + * @throws BundleException when input policy is invalid */ private static boolean checkCountryCodeCovered(CountryCode countryCode, List entryHaps) throws BundleException { @@ -1134,7 +1148,8 @@ class HapVerify { flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Entry module(" + hapVerifyInfo.getModuleName() + ") countryCode policy '" + hapVerifyInfo.getDistroFilter().countryCode.policy + "' is invalid.")); + "Entry module(" + hapVerifyInfo.getModuleName() + ") countryCode policy '" + + hapVerifyInfo.getDistroFilter().countryCode.policy + "' is invalid.")); throw new BundleException("Check countryCode covered input policy is invalid."); } } @@ -1244,7 +1259,7 @@ class HapVerify { if (isInstallationFree != hapVerifyInfo.isInstallationFree()) { String cause = "The installationFree value is different in input hap."; String solution = "Ensure that the installationFree field is same for all hap."; - LOG.error(PackingToolErrMsg.CHECK_DEPENDENCY_INVALID.toString(cause ,solution)); + LOG.error(PackingToolErrMsg.CHECK_DEPENDENCY_INVALID.toString(cause, solution)); return false; } } @@ -1288,7 +1303,8 @@ class HapVerify { for (HapVerifyInfo item : layerDependencyList) { if (FEATURE.equals(item.getModuleType()) || ENTRY.equals(item.getModuleType())) { String cause = - "HAP or HSP cannot depend on the feature or entry module. The dependeny module(" + item.getModuleName() + ") type is feature or entry."; + "HAP or HSP cannot depend on the feature or entry module. The dependeny module(" + + item.getModuleName() + ") type is feature or entry."; String solution = "Remove module dependencies on module (" + item.getModuleName() + ") to ensure the dependency list is valid."; LOG.error(PackingToolErrMsg.DEPENDENCY_LIST_INVALID.toString(cause, solution)); @@ -1426,7 +1442,8 @@ class HapVerify { } if (!hapVerifyInfo.getModuleType().equals(ENTRY) && (fileSize >= notEntryLimit * FILE_LENGTH_1M)) { String errMsg = "Module " + hapVerifyInfo.getModuleName() + " and it's dependencies size sum is " + - getCeilFileSize(fileSize, notEntryLimit) + "MB, which is overlarge than " + notEntryLimit + "MB."; + getCeilFileSize(fileSize, notEntryLimit) + "MB, which is overlarge than " + notEntryLimit + + "MB."; LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_MODULE_SIZE.toString(errMsg)); return false; } @@ -1487,7 +1504,7 @@ class HapVerify { List hapVerifyInfos = deviceInfoMap.get(device); if (!checkAtomicServicePreloadsIsValid(hapVerifyInfos)) { LOG.error(PackingToolErrMsg.CHECK_ATOMICSERVICE_INVALID.toString( - "Check whether atomicService preloads are valid failed on device "+ device + ".")); + "Check whether atomicService preloads are valid failed on device " + device + ".")); return false; } } @@ -1530,19 +1547,21 @@ class HapVerify { for (PreloadItem preloadItem : preloadItems) { String moduleName = preloadItem.getModuleName(); if (preloadModuleName.contains(moduleName)) { - LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("Preloads a duplicate module, module(" - + hapVerifyInfo.getModuleName() + ") cannot preloads module (" + moduleName + ").")); + LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString( + "Preloads a duplicate module, module(" + hapVerifyInfo.getModuleName() + + ") cannot preloads module (" + moduleName + ").")); return false; } preloadModuleName.add(moduleName); if (!moduleNames.contains(moduleName)) { - LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("Preloads a not exist module, module(" - + hapVerifyInfo.getModuleName() + ") cannot preloads module(" + moduleName + ").")); + LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString( + "Preloads a not exist module, module(" + hapVerifyInfo.getModuleName() + + ") cannot preloads module(" + moduleName + ").")); return false; } if (moduleName.equals(hapVerifyInfo.getModuleName())) { - LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("Cannot preload self, module " - + hapVerifyInfo.getModuleName() + " cannot preloads self.")); + LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("Cannot preload self, module " + + hapVerifyInfo.getModuleName() + " cannot preloads self.")); return false; } } diff --git a/adapter/ohos/ModuleJsonUtil.java b/adapter/ohos/ModuleJsonUtil.java index 569022e09241b39c6ea7d947f433e809ea57544d..239b6db9392f3efe4a9f202ca6e04ad8f387e962 100644 --- a/adapter/ohos/ModuleJsonUtil.java +++ b/adapter/ohos/ModuleJsonUtil.java @@ -243,7 +243,8 @@ class ModuleJsonUtil { if (!appObj.containsKey(API_VERSION)) { String errMsg = "The config.json file does not contain 'apiVersion'."; LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString(errMsg)); - throw new BundleException("Parse FA module APIVersion failed: The config.json file does not contain 'apiVersion'."); + throw new BundleException( + "Parse FA module APIVersion failed: The config.json file does not contain 'apiVersion'."); } JSONObject apiVersionObj = appObj.getJSONObject(API_VERSION); ModuleApiVersion moduleApiVersion = new ModuleApiVersion(); @@ -336,7 +337,8 @@ class ModuleJsonUtil { if (moduleObj.containsKey(PACKAGE)) { packageStr = moduleObj.getString(PACKAGE); } else { - LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString("The config.json file does not contain 'package'.")); + LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString( + "The config.json file does not contain 'package'.")); throw new BundleException("The config.json file does not contain 'package'."); } return packageStr; @@ -355,7 +357,8 @@ class ModuleJsonUtil { if (appObject.containsKey(BUNDLE_NAME)) { bundleName = appObject.getString(BUNDLE_NAME); } else { - LOG.error(PackingToolErrMsg.PARSE_BUNDLE_NAME_FAILED.toString("The module.json or config.json file does not contain 'bundleName'.")); + LOG.error(PackingToolErrMsg.PARSE_BUNDLE_NAME_FAILED.toString( + "The module.json or config.json file does not contain 'bundleName'.")); throw new BundleException("Parse module.json or config.json file does not contain 'bundleName'."); } return bundleName; @@ -392,13 +395,16 @@ class ModuleJsonUtil { finalPackObj = JSON.parseObject(finalPackInfo); JSONObject srcPackObj = JSON.parseObject(srcPackInfo); if (!verifyPackInfo(finalPackObj, srcPackObj)) { - LOG.error("ModuleJsonUtil:mergeTwoPackInfo verify pack.info failed."); - throw new BundleException("ModuleJsonUtil:mergeTwoPackInfo verify pack.info failed."); + String errMsg = "Verify pack.info failed."; + LOG.error(PackingToolErrMsg.MERGE_TWO_PACKINFO_FAILED.toString(errMsg)); + throw new BundleException(errMsg); } desPackInfo = mergePackInfoObj(finalPackObj, srcPackObj); } catch (BundleException | JSONException e) { - LOG.error("ModuleJsonUtil:mergeTwoPackInfo merge pack.info failed: " + e.getMessage()); - throw new BundleException("ModuleJsonUtil:mergeTwoPackInfo merge pack.info failed."); + String errMsg = "Merge two pack.info file into one pack.info exist " + + "exception (BundleException | JSONException): "; + LOG.error(PackingToolErrMsg.MERGE_TWO_PACKINFO_FAILED.toString(errMsg + e.getMessage())); + throw new BundleException(errMsg + e.getMessage()); } return desPackInfo; } @@ -412,24 +418,28 @@ class ModuleJsonUtil { */ public static boolean verifyPackInfo(JSONObject finalPackObj, JSONObject srcPackObj) throws BundleException { if (finalPackObj == null || srcPackObj == null) { - LOG.error("ModuleJsonUtil:verifyPackInfo fail to read pack.info."); + String errMsg = "Input json objects (final pack.info or src pack.info) is null."; + LOG.error(PackingToolErrMsg.VERIFY_PACKINFO_FAILED.toString(errMsg)); return false; } JSONObject finalSummaryObj = finalPackObj.getJSONObject(SUMMARY); JSONObject srcSummaryObj = srcPackObj.getJSONObject(SUMMARY); if (finalSummaryObj == null || srcSummaryObj == null) { - LOG.error("ModuleJsonUtil:verifyPackInfo pack.info do not contain summary."); + String errMsg = "Final pack.info or src pack.info does not contain 'summary'."; + LOG.error(PackingToolErrMsg.VERIFY_PACKINFO_FAILED.toString(errMsg)); return false; } // check app info JSONObject finalAppObj = finalSummaryObj.getJSONObject(APP); JSONObject srcAppObj = srcSummaryObj.getJSONObject(APP); if (finalAppObj == null || srcAppObj == null) { - LOG.error("ModuleJsonUtil:verifyPackInfo pack.info do not contain app."); + String errMsg = "Final pack.info or src pack.info does not contain 'app'."; + LOG.error(PackingToolErrMsg.VERIFY_PACKINFO_FAILED.toString(errMsg)); return false; } if (!verifyAppInPackInfo(finalAppObj, srcAppObj)) { - LOG.error("ModuleJsonUtil:verifyPackInfo verify app failed."); + String errMsg = "Verify app field in final pack.info and src pack.info failed."; + LOG.error(PackingToolErrMsg.VERIFY_PACKINFO_FAILED.toString(errMsg)); return false; } @@ -445,32 +455,37 @@ class ModuleJsonUtil { */ public static boolean verifyAppInPackInfo(JSONObject finalAppObj, JSONObject srcAppObj) { if (finalAppObj == null || srcAppObj == null) { - LOG.error("ModuleJsonUtil:verifyAppInPackInfo input null json object."); + String errMsg = "Input json objects (finalAppObj or srcAppObj) is null."; + LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } // check bundleName String finalBundleName = finalAppObj.getString(BUNDLE_NAME); String srcBundleName = srcAppObj.getString(BUNDLE_NAME); if (!finalBundleName.equals(srcBundleName)) { - LOG.error("ModuleJsonUtil:verifyAppInPackInfo bundleName is different."); + String errMsg = "The bundleName is different between final bundleName and src bundleName."; + LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } // check bundleType if (!checkBundleTypeInPackInfo(finalAppObj, srcAppObj)) { - LOG.error("ModuleJsonUtil:verifyAppInPackInfo bundleType is different."); + String errMsg = "The bundleType is different between final app object and src app object."; + LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } // check version JSONObject finalVersionObj = finalAppObj.getJSONObject(VERSION); JSONObject srcVersionObj = srcAppObj.getJSONObject(VERSION); if (finalVersionObj == null || srcVersionObj == null) { - LOG.error("ModuleJsonUtil:verifyAppInPackInfo version object is empty."); + String errMsg = "Final version object or src version object is empty."; + LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } int finalVersionCode = finalVersionObj.getIntValue(CODE); int srcVersionCode = srcVersionObj.getIntValue(CODE); if (finalVersionCode != srcVersionCode) { - LOG.error("ModuleJsonUtil:verifyAppInPackInfo versionCode is different."); + String errMsg = "The code is different between final version object and src version object."; + LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } return true; @@ -485,7 +500,8 @@ class ModuleJsonUtil { */ public static boolean checkBundleTypeInPackInfo(JSONObject finalAppObj, JSONObject srcAppObj) { if (finalAppObj.isEmpty() || srcAppObj.isEmpty()) { - LOG.error("ModuleJsonUtil:checkBundleTypeInPackInfo pack.info has empty module."); + String errMsg = "Input json objects (finalAppObj or srcAppObj) is null."; + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_PACKINFO_INVALID.toString(errMsg)); return false; } String finalBundleType = "app"; @@ -497,7 +513,8 @@ class ModuleJsonUtil { srcBundleType = getJsonString(srcAppObj, BUNDLE_TYPE); } if (!finalBundleType.equals(srcBundleType)) { - LOG.error("bundleType in pack.info is not same."); + String errMsg = "The bundleType is different between final bundleType and src bundleType."; + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_PACKINFO_INVALID.toString(errMsg)); return false; } return true; @@ -553,13 +570,15 @@ class ModuleJsonUtil { throws BundleException { JSONObject jsonObject = JSONObject.parseObject(jsonString); if (jsonObject == null || !jsonObject.containsKey(SUMMARY)) { - LOG.error("ModuleJsonUtil::parsePackInfoFormsName error: summary is null."); + String errMsg = "The json object is null or does not contain 'summary'."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_NAME_FAILED.toString(errMsg)); throw new BundleException("Parse pack info forms name failed, summary is null."); } JSONObject summaryJson = jsonObject.getJSONObject(SUMMARY); if (summaryJson == null || !summaryJson.containsKey("modules")) { - LOG.error("ModuleJsonUtil::parsePackInfoFormsName error: summary.modules is null."); + String errMsg = "The summary object does not contain 'modules'."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_NAME_FAILED.toString(errMsg)); return; } @@ -567,13 +586,15 @@ class ModuleJsonUtil { for (int i = 0; i < moduleJsonList.size(); i++) { JSONObject moduleJson = moduleJsonList.getJSONObject(i); if (moduleJson == null || !moduleJson.containsKey(DISTRO)) { - LOG.error("ModuleJsonUtil::parsePackInfoFormsName error: summary.modules.distro is null."); + String errMsg = "The modules object does not contain 'distro'."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_NAME_FAILED.toString(errMsg)); continue; } JSONObject distroObj = moduleJson.getJSONObject(DISTRO); if (distroObj == null || !distroObj.containsKey(MODULE_NAME)) { - LOG.error("ModuleJsonUtil::parsePackInfoFormsName error: summary.modules.distro.moduleName is null."); + String errMsg = "The distro object does not contain 'moduleName'."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_NAME_FAILED.toString(errMsg)); continue; } @@ -653,28 +674,28 @@ class ModuleJsonUtil { * merge pack.info file. * * @param finalPackinfoObj is the final pack.info objects - * @param srcPackinfoObj is the final pack.info objects + * @param srcPackinfoObj is the src pack.info objects * @return the result */ public static String mergePackInfoObj(JSONObject finalPackinfoObj, JSONObject srcPackinfoObj) throws BundleException { if (finalPackinfoObj == null || srcPackinfoObj == null) { - String errMsg = "ModuleJsonUtil:mergePackInfoObj input an invalid json object."; - LOG.error(errMsg); + String errMsg = "Input JSON objects (final pack.info object or src pack.info object) is null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_FAILED.toString(errMsg)); throw new BundleException(errMsg); } JSONObject finalSummaryObj = finalPackinfoObj.getJSONObject(SUMMARY); JSONObject srcSummaryObj = srcPackinfoObj.getJSONObject(SUMMARY); if (finalSummaryObj == null || srcSummaryObj == null) { - String errMsg = "ModuleJsonUtil:mergePackInfoObj input json file has empty summary."; - LOG.error(errMsg); + String errMsg = "Input JSON objects (final SummaryObj or src SummaryObj) is null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // merge modules JSONArray finalModuleObs = finalSummaryObj.getJSONArray(MODULES); JSONArray srcModuleObs = srcSummaryObj.getJSONArray(MODULES); if (finalModuleObs == null || srcModuleObs == null) { - String errMsg = "ModuleJsonUtil:mergePackInfoObj input json file has empty module."; - LOG.error(errMsg); + String errMsg = "Input JSON array (final ModuleObs or src ModuleObs) is null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_FAILED.toString(errMsg)); throw new BundleException(errMsg); } finalModuleObs.addAll(srcModuleObs); @@ -682,8 +703,8 @@ class ModuleJsonUtil { JSONArray finalPackageObs = finalPackinfoObj.getJSONArray(PACKAGES); JSONArray srcPackageObs = srcPackinfoObj.getJSONArray(PACKAGES); if (finalPackageObs == null || srcPackageObs == null) { - String errMsg = "ModuleJsonUtil:mergePackInfoObj input json file has empty packages."; - LOG.error(errMsg); + String errMsg = "Input JSON array (final PackageObs or src PackageObs) is null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_FAILED.toString(errMsg)); throw new BundleException(errMsg); } finalPackageObs.addAll(srcPackageObs); @@ -707,8 +728,8 @@ class ModuleJsonUtil { finalPackObj = JSON.parseObject(finalPackInfo); srcPackObj = JSON.parseObject(srcPackInfo); } catch (JSONException exception) { - String errMsg = "parse JSONObject failed: " + exception.getMessage(); - LOG.error(errMsg); + String errMsg = "Parse final pack.info or src pack.info exist JSONException: " + exception.getMessage(); + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // verify app in pack.info @@ -717,8 +738,8 @@ class ModuleJsonUtil { JSONObject srcSummaryObj = srcPackObj.getJSONObject(SUMMARY); JSONObject srcAppObj = srcSummaryObj.getJSONObject(APP); if (!verifyAppInPackInfo(finalAppObj, srcAppObj)) { - String errMsg = "verify pack.info failed, different version, bundleType or bundleName."; - LOG.error(errMsg); + String errMsg = "Verify app in pack.info failed: different version, bundleType or bundleName."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } for (HashMap.Entry entry : packagePair.entrySet()) { @@ -740,22 +761,23 @@ class ModuleJsonUtil { public static void mergeTwoPackInfoObjByPackagePair(JSONObject finalPackObj, JSONObject srcPackObj, String packageName, String moduleName) throws BundleException { if (finalPackObj == null || srcPackObj == null) { - String errMsg = "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair failed: pack.info is not json object."; - LOG.error(errMsg); + String errMsg = "Input json objects (final pack.info or src pack.info) is null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // merge module JSONObject finalSummaryObj = finalPackObj.getJSONObject(SUMMARY); JSONObject srcSummaryObj = srcPackObj.getJSONObject(SUMMARY); if (finalSummaryObj == null || srcSummaryObj == null) { - String errMsg = "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair failed: pack.info do not contain summary."; - LOG.error(errMsg); + String errMsg = "Input json objects (final summaryObj or src summaryObj) is null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } JSONArray finalModules = finalSummaryObj.getJSONArray(MODULES); JSONArray srcModules = srcSummaryObj.getJSONArray(MODULES); if (finalModules == null || srcModules == null) { - LOG.error("ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair input json file has empty module."); + String errMsg = "Input json array (final modules or src modules) is null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException("ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair input json file has empty module."); } @@ -770,18 +792,16 @@ class ModuleJsonUtil { } } if (!findModule) { - String errMsg = "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair" + - " input json do not contain " + moduleName + "."; - LOG.error(errMsg); + String errMsg = "Input json does not contain " + moduleName + "."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // merge package JSONArray finalPackages = finalPackObj.getJSONArray(PACKAGES); JSONArray srcPackages = srcPackObj.getJSONArray(PACKAGES); if (finalPackages == null || srcPackages == null) { - String errMsg = - "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair failed: pack.info do not contain packages."; - LOG.error(errMsg); + String errMsg = "Input json array (final packages or src packages) is null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } boolean findPackage = false; @@ -794,9 +814,8 @@ class ModuleJsonUtil { } } if (!findPackage) { - String errMsg = "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair input json do not contain " - + packageName + "."; - LOG.error(errMsg); + String errMsg = "Input json does not contain " + packageName + "."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } } @@ -1317,7 +1336,8 @@ class ModuleJsonUtil { String moduleName = parseStageModuleName(jsonString); if (!moduleObj.containsKey(TYPE)) { String errMsg = "Module: '" + moduleName + "' does not contain 'type' in module.json."; - String solution = "Ensure the module.json file includes a valid 'type' field for module '" + moduleName + "'."; + String solution = + "Ensure the module.json file includes a valid 'type' field for module '" + moduleName + "'."; LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); throw new BundleException(errMsg); } @@ -1326,7 +1346,8 @@ class ModuleJsonUtil { JSONObject appObj = getAppObj(jsonString); if (!appObj.containsKey(BUNDLE_TYPE)) { if (installationFree) { - String errMsg = "The app.json5 file configuration does not match the 'installationFree' setting of true."; + String errMsg = + "The app.json5 file configuration does not match the 'installationFree' setting of true."; String solution = "Add the bundleType field to the app.json5 file or set it atomicService."; LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); throw new BundleException(errMsg); @@ -1336,7 +1357,8 @@ class ModuleJsonUtil { String bundleType = getJsonString(appObj, BUNDLE_TYPE); if (bundleType.equals(APP)) { if (installationFree) { - String errMsg = "'installationFree' must be false in module '" + moduleName + "' when 'bundleType' is app."; + String errMsg = + "'installationFree' must be false in module '" + moduleName + "' when 'bundleType' is app."; String solution = "Set 'installationFree' to false in the module.json when 'bundleType' is app."; LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); throw new BundleException(errMsg); @@ -1344,7 +1366,8 @@ class ModuleJsonUtil { return APP; } else if (bundleType.equals(ATOMIC_SERVICE)) { if (!installationFree) { - String errMsg = "'installationFree' must be true in module '" + moduleName + "' when 'bundleType' is atomicService."; + String errMsg = "'installationFree' must be true in module '" + moduleName + + "' when 'bundleType' is atomicService."; String solution = "Set 'installationFree' to true in the module.json when 'bundleType'" + "is atomicService."; LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); @@ -1354,7 +1377,7 @@ class ModuleJsonUtil { } else if (SHARED.equals(bundleType)) { if (!SHARED.equals(type)) { String errMsg = "'type' must be shared in module '" + moduleName + "' when 'bundleType' is shared."; - String solution = "Set the 'type' to shared in the module.json when 'bundleType' is shared.";; + String solution = "Set the 'type' to shared in the module.json when 'bundleType' is shared."; LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); throw new BundleException(errMsg); } @@ -1405,7 +1428,8 @@ class ModuleJsonUtil { JSONObject itemObj = proxyData.getJSONObject(i); if (!itemObj.containsKey(PROXY_URI)) { String errMsg = "proxyData object does not contain " + PROXY_URI + "."; - String solution = "Ensure that each item in the " + PROXY_DATA + " array includes a valid " + PROXY_URI + " field."; + String solution = "Ensure that each item in the " + PROXY_DATA + " array includes a valid " + + PROXY_URI + " field."; LOG.error(PackingToolErrMsg.PARSE_PROXY_DATA_URI_FAILED.toString(errMsg, solution)); throw new BundleException("Parse json object failed in parse proxyData and uri."); } @@ -1418,7 +1442,8 @@ class ModuleJsonUtil { JSONObject itemObj = proxyDatas.getJSONObject(i); if (!itemObj.containsKey(PROXY_URI)) { String errMsg = "proxyDatas object does not contain " + PROXY_URI + "."; - String solution = "Ensure that each item in the " + PROXY_DATAS + " array includes a valid " + PROXY_URI + " field."; + String solution = "Ensure that each item in the " + PROXY_DATAS + " array includes a valid " + + PROXY_URI + " field."; LOG.error(PackingToolErrMsg.PARSE_PROXY_DATA_URI_FAILED.toString(errMsg, solution)); throw new BundleException("Parse json object failed in parse proxyDatas and uri."); } @@ -1440,7 +1465,8 @@ class ModuleJsonUtil { } JSONObject appObj = jsonObject.getJSONObject(APP); if (appObj == null) { - LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("The module.json or config.json does not contain 'app'.")); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString( + "The module.json or config.json does not contain 'app'.")); throw new BundleException("json do not contain app."); } return appObj; @@ -1461,7 +1487,8 @@ class ModuleJsonUtil { } JSONObject moduleObj = jsonObj.getJSONObject(MODULE); if (moduleObj == null) { - LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("The module.json or config.json file does not contain 'module'.")); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString( + "The module.json or config.json file does not contain 'module'.")); throw new BundleException("The module.json or config.json file does not contain 'module'."); } return moduleObj; @@ -1507,7 +1534,8 @@ class ModuleJsonUtil { JSONObject moduleObj = getModuleObj(jsonString); JSONObject distroObj = moduleObj.getJSONObject(DISTRO); if (distroObj == null) { - LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString("The config.json file does not contain 'distro'.")); + LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString( + "The config.json file does not contain 'distro'.")); throw new BundleException("Parse FA installationFree failed: config.json file does not contain 'distro'."); } if (distroObj.containsKey(INSTALLATION_FREE)) { @@ -1715,7 +1743,9 @@ class ModuleJsonUtil { try { jsonObject = JSON.parseObject(jsonString); } catch (JSONException exception) { - PackingToolErrMsg.PARSE_JSON_FAILED.toString("Parse json object failed when get debug parameter in config.json, JSONException: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString( + "Parse json object failed when get debug parameter in config.json, JSONException: " + + exception.getMessage())); throw new BundleException("Parse JSONObject failed when get debug parameter in config.json."); } JSONObject deviceConfigObj = jsonObject.getJSONObject(DEVICE_CONFIG); @@ -1863,7 +1893,7 @@ class ModuleJsonUtil { } JSONObject appObj = jsonObject.getJSONObject(fatherProperty); if (appObj == null) { - String errMsg = "Parse failed, input module.json is invalid, module.json has no "+ fatherProperty + "."; + String errMsg = "Parse failed, input module.json is invalid, module.json has no " + fatherProperty + "."; LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString(errMsg)); throw new BundleException("Parse failed, input module.json is invalid, module.json has no " + fatherProperty + "."); @@ -1935,7 +1965,7 @@ class ModuleJsonUtil { } if (parseModuleType(jsonString).equals(ENTRY) && parseAbilityNames(jsonString).isEmpty()) { String moduleName = parseStageModuleName(jsonString); - String errMsg = "Entry module(" + moduleName +") must contain at least one ability."; + String errMsg = "Entry module(" + moduleName + ") must contain at least one ability."; LOG.error(PackingToolErrMsg.CHECK_LEASTONE_ABILITY.toString(errMsg)); return false; } @@ -2070,20 +2100,20 @@ class ModuleJsonUtil { String name = formObj.getString(NAME); formNameList.add(name); if (!formObj.containsKey(DEFAULTDIMENSION)) { - LOG.error("ModuleJsonUtil::parsePackInfoForms exception: " + - "summary.modules.extensionAbilities.forms.defaultDimension is null."); + String errMsg = "formObj object does not contain defaultDimension."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_FAILED.toString(errMsg)); throw new BundleException("Parse pack info defaultDimension failed, defaultDimension is null."); } String defaultDimension = formObj.getString(DEFAULTDIMENSION); if (getCount(defaultDimension, '*') != 1) { - LOG.error("ModuleJsonUtil::parsePackInfoForms exception: " + - "summary.modules.extensionAbilities.forms.defaultDimension is not only 1."); + String errMsg = "summary.modules.extensionAbilities.forms.defaultDimension is not only 1."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_FAILED.toString(errMsg)); throw new BundleException("Parse pack info defaultDimension failed, defaultDimension is not only 1."); } if (!formObj.containsKey(SUPPORTDIMENSIONS)) { - LOG.error("ModuleJsonUtil::parsePackInfoForms exception: " + - "summary.modules.extensionAbilities.forms.supportDimensions is null."); + String errMsg = "formObj object does not contain supportDimensions."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_FAILED.toString(errMsg)); throw new BundleException("Parse pack info supportDimensions failed, supportDimensions is null."); } diff --git a/adapter/ohos/PackageNormalize.java b/adapter/ohos/PackageNormalize.java index 5bca1f855e440f5b9d091d8bfbd919dd67c73687..39a17ed12438dae02125870cb1facf20e72eeb7e 100644 --- a/adapter/ohos/PackageNormalize.java +++ b/adapter/ohos/PackageNormalize.java @@ -70,10 +70,12 @@ public class PackageNormalize { try { normalize(Paths.get(hspPath), outPath, utility.getBundleName(), utility.getVersionCode()); } catch (BundleException ex) { - LOG.error("PackageNormalize::normalize BundleException: " + ex.getMessage()); + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_FAILED.toString( + "Package normalize exist BundleException:" + ex.getMessage())); return false; } catch (IOException ex) { - LOG.error("PackageNormalize::normalize IOException: " + ex.getMessage()); + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_FAILED.toString( + "Package normalize exist IOException:" + ex.getMessage())); return false; } } @@ -135,11 +137,13 @@ public class PackageNormalize { try (FileInputStream input = new FileInputStream(moduleJson.toFile())) { JSONObject jsonObject = JSON.parseObject(input, JSONObject.class); if (jsonObject == null) { - LOG.error("updateModuleJson failed, parse json is null."); + LOG.error(PackingToolErrMsg.UPDATE_MODULE_JSON_FAILED.toString( + "Failed to parse module.json: invalid json format.")); throw new BundleException("updateModuleJson failed, parse json is null."); } if (!jsonObject.containsKey(APP)) { - LOG.error("updateModuleJson failed, json format not invalid."); + LOG.error(PackingToolErrMsg.UPDATE_MODULE_JSON_FAILED.toString( + "The module.json file does not contain 'app'.")); throw new BundleException("updateModuleJson failed, json format invalid."); } JSONObject appObject = jsonObject.getJSONObject(APP); @@ -156,23 +160,27 @@ public class PackageNormalize { try (FileInputStream input = new FileInputStream(packInfo.toFile())) { JSONObject jsonObject = JSON.parseObject(input, JSONObject.class); if (jsonObject == null) { - LOG.error("updatePackInfo failed, json format invalid."); + LOG.error(PackingToolErrMsg.UPDATE_PACKINFO_FAILED.toString( + "Failed to parse pack.info: invalid json format.")); throw new BundleException("updatePackInfo failed, json format invalid."); } JSONObject summaryObject = jsonObject.getJSONObject(SUMMARY); if (summaryObject == null) { - LOG.error("updatePackInfo failed, json format invalid."); + LOG.error(PackingToolErrMsg.UPDATE_PACKINFO_FAILED.toString( + "The pack.info file does not contain 'summary'.")); throw new BundleException("updatePackInfo failed, json format invalid."); } JSONObject appObject = summaryObject.getJSONObject(APP); if (appObject == null) { - LOG.error("updatePackInfo failed, json format invalid."); + LOG.error(PackingToolErrMsg.UPDATE_PACKINFO_FAILED.toString( + "The pack.info file does not contain 'app'.")); throw new BundleException("updatePackInfo failed, json format invalid."); } appObject.put(BUNDLE_NAME, bundleName); JSONObject versionObject = appObject.getJSONObject(VERSION); if (versionObject == null) { - LOG.error("updatePackInfo failed, json format invalid."); + LOG.error(PackingToolErrMsg.UPDATE_PACKINFO_FAILED.toString( + "The pack.info file does not contain 'version'.")); throw new BundleException("updatePackInfo failed, json format invalid."); } versionObject.put(CODE, versionCode); @@ -242,10 +250,12 @@ public class PackageNormalize { count = fileInputStream.read(buffer); } } catch (FileNotFoundException ignored) { - LOG.error("PackageNormalize::getCrcFromFile file not found exception: " + ignored.getMessage()); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString( + "Get Crc from file exist FileNotFoundException: " + ignored.getMessage())); throw new BundleException("Get Crc from file failed."); } catch (IOException exception) { - LOG.error("PackageNormalize::getCrcFromFile io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "Get Crc from file exist IOException: " + exception.getMessage())); throw new BundleException("Get Crc from file failed, io exception."); } return crc; diff --git a/adapter/ohos/PackageUtil.java b/adapter/ohos/PackageUtil.java index 0e5650028693ccd88d673f3aececa9cf1f628e21..00c148e9ad0c25dff8e31443be63a0b5ce1cab88 100644 --- a/adapter/ohos/PackageUtil.java +++ b/adapter/ohos/PackageUtil.java @@ -356,7 +356,8 @@ public class PackageUtil { try { return hspFile.getInputStream(zipEntry); } catch (IOException e) { - LOG.error("addArchiveEntry err: " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Repack hsp exist IOException: " + + e.getMessage())); return null; } }; @@ -364,8 +365,9 @@ public class PackageUtil { } zipCreator.writeTo(zipOut); } catch (InterruptedException | ExecutionException e) { - String errMsg = "repackHsp err: " + e.getMessage(); - LOG.error(errMsg); + String errMsg = "Repack hsp exist Exception (InterruptedException | ExecutionException): " + + e.getMessage(); + LOG.error(PackingToolErrMsg.REPACK_HSP_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } return outHsp; @@ -435,8 +437,8 @@ public class PackageUtil { // write to zip zipCreator.writeTo(zipOut); } catch (InterruptedException | ExecutionException e) { - String errMsg = "packDir err: " + e.getMessage(); - LOG.error(errMsg); + String errMsg = "Pack dir exist Exception (InterruptedException | ExecutionException): " + e.getMessage(); + LOG.error(PackingToolErrMsg.PACK_MULTI_THREAD_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } return outHap; @@ -509,8 +511,8 @@ public class PackageUtil { addArchiveEntry(file, baseDir, zipCreator, compress); } } catch (IOException e) { - String errMsg = "pathToZip err: " + e.getMessage(); - LOG.error(errMsg); + String errMsg = "Path to zip entry exist IOException: " + e.getMessage(); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } } @@ -521,7 +523,8 @@ public class PackageUtil { if (file.isDirectory()) { File[] files = file.listFiles(); if (files == null) { - LOG.error("listFiles null: " + file.getName()); + LOG.error(PackingToolErrMsg.ADD_ARCHIVE_ENTRY_FAILED.toString("listFiles null, directory name is " + + file.getName())); return; } if (files.length == 0) { @@ -549,7 +552,8 @@ public class PackageUtil { try { return getInputStream(entryName, file); } catch (IOException e) { - LOG.error("addArchiveEntry err: " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Add ArchiveEntry exist IOException: " + + e.getMessage())); return null; } }; @@ -646,8 +650,8 @@ public class PackageUtil { addArchiveEntry(file, baseDir, zipOut, compress); } } catch (IOException e) { - String errMsg = "pathToZip err: " + e.getMessage(); - LOG.error(errMsg); + String errMsg = "Path to zip entry exist IOException: " + e.getMessage(); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } } @@ -657,7 +661,8 @@ public class PackageUtil { if (file.isDirectory()) { File[] files = file.listFiles(); if (files == null) { - LOG.error("listFiles null: " + file.getName()); + LOG.error(PackingToolErrMsg.ADD_ARCHIVE_ENTRY_FAILED.toString("listFiles null, directory name is " + + file.getName())); return; } if (files.length == 0) { @@ -705,13 +710,13 @@ public class PackageUtil { } for (String hapPath : hapPathList) { if (!bundleType.equals(getBundleTypeFromPath(Paths.get(hapPath)))) { - LOG.error("bundleType is not same"); + LOG.error(PackingToolErrMsg.CHECK_BUNDLE_TYPE_CONSISTENCY.toString("Hap bundleType is not same")); return false; } } for (String hspPath : hspPathList) { if (!bundleType.equals(getBundleTypeFromPath(Paths.get(hspPath)))) { - LOG.error("bundleType is not same"); + LOG.error(PackingToolErrMsg.CHECK_BUNDLE_TYPE_CONSISTENCY.toString("Hsp bundleType is not same")); return false; } } @@ -725,11 +730,11 @@ public class PackageUtil { for (String hapPath : hapPathList) { Path path = Paths.get(hapPath); if (!Files.exists(path.resolve(Constants.FILE_MODULE_JSON))) { - LOG.error("not found module.json in path: " + path); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found module.json in the hap path: " + path)); return false; } if (!Files.exists(path.resolve(Constants.FILE_PACK_INFO))) { - LOG.error("not found pack.info in path: " + path); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found pack.info in the hap path: " + path)); return false; } } @@ -737,11 +742,13 @@ public class PackageUtil { Path path = Paths.get(hspPath); if (Files.isDirectory(path)) { if (!Files.exists(path.resolve(Constants.FILE_MODULE_JSON))) { - LOG.error("not found module.json in path: " + path); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found module.json in the hsp path: " + + path)); return false; } if (!Files.exists(path.resolve(Constants.FILE_PACK_INFO))) { - LOG.error("not found pack.info in path: " + path); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found pack.info in the hsp path: " + + path)); return false; } } @@ -771,45 +778,46 @@ public class PackageUtil { if (!utility.getHapPath().isEmpty() && (!isFormatPathValid(utility.getHapPath(), utility.getFormattedHapPathList()) || !isHapPathValid(utility.getFormattedHapPathList()))) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode hap-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--hap-path is invalid.")); return false; } if (!utility.getHspPath().isEmpty() && (!isFormatPathValid(utility.getHspPath(), utility.getFormattedHspPathList()) || !isHspPathValid(utility.getFormattedHspPathList()))) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode hsp-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--hsp-path is invalid.")); return false; } if (utility.getHapPath().isEmpty() && utility.getHspPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode hap-path and hsp-path is empty."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--hap-path and --hsp-path is empty.")); return false; } if (!moduleJsonAndPackInfoExists(utility.getFormattedHapPathList(), utility.getFormattedHspPathList())) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode hap-path or hsp-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--hap-path or --hsp-path is invalid.")); return false; } if (!checkBundleTypeConsistency( utility.getFormattedHapPathList(), utility.getFormattedHspPathList(), utility)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode bundleType is inconsistent."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("The bundleType is inconsistent.")); return false; } if (!isPackInfoValid(Paths.get(utility.getPackInfoPath()), utility.getFormattedHapPathList(), utility.getFormattedHspPathList())) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode pack.info is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("pack.info is invalid.")); return false; } if (!utility.getEncryptPath().isEmpty() && !isFileValid(utility.getEncryptPath(), Constants.FILE_ENCRYPT_JSON)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode encrypt-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--encrypt-path is invalid.")); return false; } Path outPath = Paths.get(utility.getOutPath()); if (utility.getForceRewrite().equals(Constants.FALSE) && Files.exists(outPath)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode out file already existed."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--out-path file already existed, but " + + "--force is 'false'.")); return false; } if (!outPath.getFileName().toString().endsWith(Constants.APP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode out-path must end with .app."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--out-path must end with .app.")); return false; } return true; @@ -817,34 +825,34 @@ public class PackageUtil { private static boolean isVerifyValid(Utility utility) { if (utility.getPackInfoPath().isEmpty()) { - LOG.error("CompressVerify::isArgsValidInAppMode pack-info-path is empty."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--pack-info-path is empty.")); return false; } if (!isFileValid(utility.getPackInfoPath(), Constants.FILE_PACK_INFO)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode pack-info-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--pack-info-path is invalid.")); return false; } if (!utility.getSignaturePath().isEmpty() && !isFileValid(utility.getSignaturePath(), "")) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode signature-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--signature-path is invalid.")); return false; } if (!utility.getCertificatePath().isEmpty() && !isFileValid(utility.getCertificatePath(), "")) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode certificate-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--certificate-path is invalid.")); return false; } if (!utility.getPackResPath().isEmpty() && !isFileValid(utility.getPackResPath(), Constants.FILE_PACK_RES)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode pack-res-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--pack-res-path is invalid.")); return false; } if (!utility.getEntryCardPath().isEmpty() && !CompressVerify.compatibleProcess(utility, utility.getEntryCardPath(), utility.getformattedEntryCardPathList(), Constants.PNG_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode entrycard-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--entrycard-path is invalid.")); return false; } if (utility.getOutPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode out-path is empty."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--out-path is empty.")); return false; } return true; @@ -876,11 +884,12 @@ public class PackageUtil { if (Files.exists(realpath)) { formatPathSet.add(realpath.toString()); } else { - LOG.error("PackageUtil::formatPath not exists: " + realpath); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Format path not exists. Path: " + realpath)); return false; } } catch (IOException ex) { - LOG.error("PackageUtil::formatPath err: " + ex.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Verify format path exist IOException: " + + ex.getMessage())); return false; } } @@ -892,27 +901,29 @@ public class PackageUtil { List allPackages = getPackageNameFromPath(packInfo); Set allPackageSet = new HashSet<>(allPackages); if (allPackages.size() > allPackageSet.size()) { - LOG.error("package name is redundant in app pack.info: " + packInfo); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Package name is redundant in app pack.info, the path is " + + packInfo)); return false; } if (allPackages.isEmpty()) { - LOG.error("app pack.info format err: " + packInfo); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("App pack.info format error, the path is " + packInfo)); return false; } Set packages = new HashSet<>(); for (String hapPath : hapPathList) { List list = getPackageNameFromPath(Paths.get(hapPath)); if (list.size() != 1) { - LOG.error("module pack.info format err: " + hapPath); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info format error, the path is " + hapPath)); return false; } String packageName = list.get(0); if (!allPackages.contains(packageName)) { - LOG.error("module pack.info name not exist in app pack.info name list: " + hapPath); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info name does not exist in app " + + "pack.info name list, the path is " + hapPath)); return false; } if (packages.contains(packageName)) { - LOG.error("package name is redundant in " + hapPath); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Package name is redundant in " + hapPath)); return false; } packages.add(packageName); @@ -920,22 +931,24 @@ public class PackageUtil { for (String hspPath : hspPathList) { List list = getPackageNameFromPath(Paths.get(hspPath)); if (list.size() != 1) { - LOG.error("module pack.info format err: " + hspPath); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info format err, the path is " + hspPath)); return false; } String packageName = list.get(0); if (!allPackages.contains(packageName)) { - LOG.error("module pack.info name not exist in app pack.info name list: " + hspPath); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info name does not exist in app " + + "pack.info name list, the path is " + hspPath)); return false; } if (packages.contains(packageName)) { - LOG.error("package name is redundant in " + hspPath); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Package name is redundant in " + hspPath)); return false; } packages.add(packageName); } if (!allPackageSet.equals(packages)) { - LOG.error("package name not same between module and app pack.info."); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Package name is not same between module " + + "and app pack.info.")); return false; } return true; diff --git a/adapter/ohos/PackingToolErrMsg.java b/adapter/ohos/PackingToolErrMsg.java index e8d48fef8237134cafafa2bf3c582218ebe2d423..ff3649ace059b8d3c8a9f952734492d209d184e3 100644 --- a/adapter/ohos/PackingToolErrMsg.java +++ b/adapter/ohos/PackingToolErrMsg.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025-2025 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -85,6 +85,76 @@ public class PackingToolErrMsg { .setCause("%s") .build(); + /** + * MULTI_APP_MODE_ARGS_INVALID + */ + public static final ErrorMsg MULTI_APP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("004") + .setDescription("Parse and check args invalid in multiApp mode.") + .setCause("%s") + .build(); + + /** + * RES_MODE_ARGS_INVALID + */ + public static final ErrorMsg RES_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("005") + .setDescription("Parse and check args invalid in res mode.") + .setCause("%s") + .build(); + + /** + * HQF_MODE_ARGS_INVALID + */ + public static final ErrorMsg HQF_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("006") + .setDescription("Parse and check args invalid in hqf mode.") + .setCause("%s") + .build(); + + /** + * APPQF_MODE_ARGS_INVALID + */ + public static final ErrorMsg APPQF_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("007") + .setDescription("Parse and check args invalid in appqf mode.") + .setCause("%s") + .build(); + + /** + * PACKAGE_NORMALIZE_MODE_ARGS_INVALID + */ + public static final ErrorMsg PACKAGE_NORMALIZE_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("008") + .setDescription("Parse and check args invalid in packageNormalize mode.") + .setCause("%s") + .build(); + + /** + * VERSION_NORMALIZE_MODE_ARGS_INVALID + */ + public static final ErrorMsg VERSION_NORMALIZE_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("009") + .setDescription("Parse and check args invalid in versionNormalize mode.") + .setCause("%s") + .build(); + + /** + * HAR_MODE_ARGS_INVALID + */ + public static final ErrorMsg HAR_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("010") + .setDescription("Parse and check args invalid in har mode.") + .setCause("%s") + .build(); + /** * COMMAND_MODE_INVALID */ @@ -165,6 +235,26 @@ public class PackingToolErrMsg { .setCause("%s") .build(); + /** + * HAP_ADDITION_MODE_ARGS_INVALID + */ + public static final ErrorMsg HAP_ADDITION_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("019") + .setDescription("Parse and check args invalid in hapAddition mode.") + .setCause("%s") + .build(); + + /** + * HANDLE_HAP_HSP_INPUT_FAILED + */ + public static final ErrorMsg HANDLE_HAP_HSP_INPUT_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("020") + .setDescription("Handle hap and hsp input failed.") + .setCause("%s") + .build(); + // compress process error /** * COMPRESS_PROCESS_FAILED @@ -432,6 +522,329 @@ public class PackingToolErrMsg { .addSolution("Please check the related size check error message and reduce related module size.") .build(); + /** + * COMPRESS_APP_MODE_FORMULTI_PROJECT_FAILED + */ + public static final ErrorMsg COMPRESS_APP_MODE_FORMULTI_PROJECT_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("025") + .setDescription("Compress in app mode for multi project.failed.") + .setCause("%s") + .build(); + + /** + * HAP_ADDITION_FAILED + */ + public static final ErrorMsg HAP_ADDITION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("026") + .setDescription("Hap addition failed.") + .setCause("%s") + .build(); + + /** + * COMPRESS_HAP_ADDITION_FAILED + */ + public static final ErrorMsg COMPRESS_HAP_ADDITION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("027") + .setDescription("Compress hap addition failed.") + .setCause("%s") + .build(); + + /** + * DISPOSE_APP_FAILED + */ + public static final ErrorMsg DISPOSE_APP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("028") + .setDescription("Dispose app failed.") + .setCause("%s") + .build(); + + /** + * NO_PACK_INFO + */ + public static final ErrorMsg NO_PACK_INFO = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("029") + .setDescription("pack.info does not find in hap or app.") + .setCause("%s") + .build(); + + /** + * COMPRESS_PACK_RES_MODE_FAILED + */ + public static final ErrorMsg COMPRESS_PACK_RES_MODE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("030") + .setDescription("Compress in res mode failed.") + .setCause("%s") + .build(); + + /** + * INVALID_THIRD_LEVEL_DIRECTORY_NAME + */ + public static final ErrorMsg INVALID_THIRD_LEVEL_DIRECTORY_NAME = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("031") + .setDescription("Invalid third level directory name.") + .setCause("%s") + .addSolution("Please check it with reference to this example: \n" + + "zh_Hani_CN-vertical-car-mdpi-dark or zh_Hani_CN-vertical-car-mdpi.") + .build(); + + /** + * IS_PICTURING_FAILED + */ + public static final ErrorMsg IS_PICTURING_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("032") + .setDescription("Check whether picturingName meets specifications failed.") + .setCause("%s") + .build(); + + /** + * GET_FILE_LIST_FAILED + */ + public static final ErrorMsg GET_FILE_LIST_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("033") + .setDescription("Get file list failed.") + .setCause("%s") + .build(); + + /** + * GET_MODULE_NAME_FROM_STRING_FAILED + */ + public static final ErrorMsg GET_MODULE_NAME_FROM_STRING_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("034") + .setDescription("Get module name from line string failed.") + .setCause("%s") + .build(); + + /** + * COMPRESS_APPQF_FAILED + */ + public static final ErrorMsg COMPRESS_APPQF_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("035") + .setDescription("Compress in appqf mode failed.") + .setCause("%s") + .build(); + + /** + * CHECK_HQF_INVALID + */ + public static final ErrorMsg CHECK_HQF_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("036") + .setDescription("Input hqf is invalid.") + .setCause("%s") + .build(); + + /** + * CHECK_APP_FIELDS_FAILED + */ + public static final ErrorMsg CHECK_APP_FIELDS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("037") + .setDescription("Check hqf has same app fields failed.") + .setCause("%s") + .build(); + + /** + * CHECK_MODULE_INVALID + */ + public static final ErrorMsg CHECK_MODULE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("038") + .setDescription("Check hqf module is invalid.") + .setCause("%s") + .build(); + + /** + * VERSION_NORMALIZE_FAILED + */ + public static final ErrorMsg VERSION_NORMALIZE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("039") + .setDescription("Version normalize failed.") + .setCause("%s") + .build(); + + /** + * VERIFY_MODULE_VERSION_FAILED + */ + public static final ErrorMsg VERIFY_MODULE_VERSION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("040") + .setDescription("Verify module version failed.") + .setCause("%s") + .build(); + + /** + * SHA256_CALCULATION_FAILED + */ + public static final ErrorMsg SHA256_CALCULATION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("041") + .setDescription("SHA-256 hash calculation failed.") + .setCause("%s") + .build(); + + /** + * MERGE_TWO_PACKINFO_FAILED + */ + public static final ErrorMsg MERGE_TWO_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("042") + .setDescription("Merge two pack.info into one pack.info file failed.") + .setCause("%s") + .build(); + + /** + * VERIFY_PACKINFO_FAILED + */ + public static final ErrorMsg VERIFY_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("043") + .setDescription("Verify pack.info file failed.") + .setCause("%s") + .build(); + + /** + * VERIFY_APP_PACKINFO_FAILED + */ + public static final ErrorMsg VERIFY_APP_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("044") + .setDescription("Verify app in pack.info failed.") + .setCause("%s") + .build(); + + /** + * BUNDLE_TYPE_PACKINFO_INVALID + */ + public static final ErrorMsg BUNDLE_TYPE_PACKINFO_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("045") + .setDescription("Verify bundleType in pack.info file failed.") + .setCause("%s") + .build(); + + /** + * PARSE_PACKINFO_FORMS_NAME_FAILED + */ + public static final ErrorMsg PARSE_PACKINFO_FORMS_NAME_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("046") + .setDescription("Parse forms name in pack.info file failed.") + .setCause("%s") + .build(); + + /** + * MERGE_PACKINFO_OBJ_FAILED + */ + public static final ErrorMsg MERGE_PACKINFO_OBJ_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("047") + .setDescription("Failed to merge pack.info objects.") + .setCause("%s") + .build(); + + /** + * MERGE_PACKINFO_BY_PACKAGE_PAIR_FAILED + */ + public static final ErrorMsg MERGE_PACKINFO_BY_PACKAGE_PAIR_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("048") + .setDescription("Failed to merge two pack.info files into one pack.info file by packagePair.") + .setCause("%s") + .build(); + + /** + * MERGE_PACKINFO_OBJ_BY_PACKAGE_PAIR_FAILED + */ + public static final ErrorMsg MERGE_PACKINFO_OBJ_BY_PACKAGE_PAIR_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("049") + .setDescription( + "Failed to merge two pack.info json objects into one pack.info json object by packagePair.") + .setCause("%s") + .build(); + + /** + * PARSE_PACKINFO_FORMS_FAILED + */ + public static final ErrorMsg PARSE_PACKINFO_FORMS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("050") + .setDescription("Failed to parse pack.info forms.") + .setCause("%s") + .build(); + + /** + * COMPRESS_FILE_DUPLICATE + */ + public static final ErrorMsg COMPRESS_FILE_DUPLICATE = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("051") + .setDescription("File duplicated.") + .setCause("%s") + .build(); + + /** + * COPY_FILE_FAILED + */ + public static final ErrorMsg COPY_FILE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("052") + .setDescription("Copy file failed.") + .setCause("%s") + .build(); + + /** + * MAKE_DIR_FAILED + */ + public static final ErrorMsg MAKE_DIR_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("053") + .setDescription("Make dir failed.") + .setCause("%s") + .build(); + + /** + * COPY_FILE_SAFELY_FAILED + */ + public static final ErrorMsg COPY_FILE_SAFELY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("054") + .setDescription("Copy file safely failed.") + .setCause("%s") + .build(); + + /** + * PARSE_MODIFY_CONFIG_JSON_FAILED + */ + public static final ErrorMsg PARSE_MODIFY_CONFIG_JSON_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("055") + .setDescription("Parse and modify config.json failed.") + .setCause("%s") + .build(); + + /** + * PARSE_AND_MODIFY_MODULEJSON_FAILED + */ + public static final ErrorMsg PARSE_AND_MODIFY_MODULEJSON_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("056") + .setDescription("Parse and modify module.json failed.") + .setCause("%s") + .build(); + // module json check error /** * PARSE_JSON_OBJECT_EXCEPTION @@ -670,6 +1083,20 @@ public class PackingToolErrMsg { .addSolution("Verify you have the necessary permissions to delete the file.") .build(); + /** + * DIR_CREATION_FAILED + */ + public static final ErrorMsg DIR_CREATION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("010") + .setDescription("Directory creation failed exception.") + .setCause("%s") + .addSolution("Please check the following:\n" + + "1. Please check the directory path and ensure that the parent " + + "directories exist and are accessible.\n" + + "2. Ensure that you have the necessary permissions to create directories.") + .build(); + // io exception /** * IO_EXCEPTION @@ -685,7 +1112,7 @@ public class PackingToolErrMsg { .addSolution("4. Review the related error message for further insights.") .build(); - /* + /** * NULL_POINTER_EXCEPTION */ public static final ErrorMsg NULL_POINTER_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() @@ -906,4 +1333,96 @@ public class PackingToolErrMsg { .addSolution("Ensure the Entry type module distributionFilter file policy " + "settings is 'exclude' or 'include'.") .build(); + + // package normalize error + /** + * PACKAGE_NORMALIZE_FAILED + */ + public static final ErrorMsg PACKAGE_NORMALIZE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("17") + .setErrCode("001") + .setDescription("Normalize HSP bundleName and versionCode failed.") + .setCause("%s") + .build(); + + /** + * UPDATE_MODULE_JSON_FAILED + */ + public static final ErrorMsg UPDATE_MODULE_JSON_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("17") + .setErrCode("002") + .setDescription("Update module.json failed.") + .setCause("%s") + .build(); + + /** + * UPDATE_PACKINFO_FAILED + */ + public static final ErrorMsg UPDATE_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("17") + .setErrCode("003") + .setDescription("Update pack.info failed.") + .setCause("%s") + .build(); + + // package util error + /** + * FAST_APP_MODE_ARGS_INVALID + */ + public static final ErrorMsg FAST_APP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("18") + .setErrCode("001") + .setDescription("Parse and check args invalid in fast app mode.") + .setCause("%s") + .build(); + + /** + * CHECK_BUNDLE_TYPE_CONSISTENCY + */ + public static final ErrorMsg CHECK_BUNDLE_TYPE_CONSISTENCY = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("18") + .setErrCode("002") + .setDescription("Check bundleType consistency failed.") + .setCause("%s") + .build(); + + /** + * PACK_INFO_INVALID + */ + public static final ErrorMsg PACK_INFO_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("18") + .setErrCode("003") + .setDescription("Pack.info is invalid.") + .setCause("%s") + .build(); + + /** + * ADD_ARCHIVE_ENTRY_FAILED + */ + public static final ErrorMsg ADD_ARCHIVE_ENTRY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("18") + .setErrCode("004") + .setDescription("Add archive entry failed.") + .setCause("%s") + .build(); + + /** + * PACK_MULTI_THREAD_EXCEPTION + */ + public static final ErrorMsg PACK_MULTI_THREAD_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("18") + .setErrCode("005") + .setDescription("Pack multi thread exception.") + .setCause("%s") + .build(); + + /** + * REPACK_HSP_EXCEPTION + */ + public static final ErrorMsg REPACK_HSP_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("18") + .setErrCode("006") + .setDescription("Repack hsp exception.") + .setCause("%s") + .build(); } diff --git a/adapter/ohos/Utility.java b/adapter/ohos/Utility.java index 496930cae599e3d3f0e30cdd9920854c50cc1b3b..81bf99679bcaaee2b43d8b6fd403459945b7f306 100644 --- a/adapter/ohos/Utility.java +++ b/adapter/ohos/Utility.java @@ -706,7 +706,8 @@ public class Utility { canonicalPath = file.getCanonicalPath(); } catch (IOException exception) { canonicalPath = INVALID_PATH; - LOG.error("Utility::getFormattedPath exception," + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "Get formatted path exist IOException: " + exception.getMessage())); } return canonicalPath; }