From cb401ca8c438c06c2fbc79bf3d941902f01562dc Mon Sep 17 00:00:00 2001 From: nj1868 Date: Tue, 11 Feb 2025 17:24:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=85=E7=AE=A1=E7=90=86=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: nj1868 --- adapter/ohos/CompressVerify.java | 234 +++++---- adapter/ohos/Compressor.java | 120 ++--- adapter/ohos/ModuleJsonUtil.java | 130 +++-- adapter/ohos/PackingToolErrMsg.java | 711 ++++++++++++++++++++++++++++ 4 files changed, 1009 insertions(+), 186 deletions(-) create mode 100644 adapter/ohos/PackingToolErrMsg.java diff --git a/adapter/ohos/CompressVerify.java b/adapter/ohos/CompressVerify.java index 6a4e05c9..b3196aeb 100644 --- a/adapter/ohos/CompressVerify.java +++ b/adapter/ohos/CompressVerify.java @@ -235,11 +235,13 @@ public class CompressVerify { if (!utility.getRpcidPath().isEmpty()) { File file = new File(utility.getRpcidPath()); if (!file.isFile()) { - LOG.error("CompressVerify::isArgsValidInHapMode rpcid-path is not a file."); + String errMsg = "CompressVerify::isArgsValidInHapMode rpcid-path is not a file."; + LOG.error(PackingToolErrMsg.RPCID_PATH_FAILED.toString(errMsg)); return false; } if (!RPCID_PROFILE.equals(file.getName())) { - LOG.error("CompressVerify::isArgsValidInHapMode rpcid-path must be rpcid.sc file."); + String errMsg = "CompressVerify::isArgsValidInHapMode rpcid-path must be rpcid.sc file."; + LOG.error(PackingToolErrMsg.RPCID_PATH_FAILED.toString(errMsg)); return false; } } @@ -250,11 +252,13 @@ public class CompressVerify { if (!utility.getPackInfoPath().isEmpty()) { File file = new File(utility.getPackInfoPath()); if (!file.isFile()) { - LOG.error("CompressVerify::isArgsValidInHapMode --pack-info-path is not a file."); + String errMsg = "CompressVerify::isArgsValidInHapMode --pack-info-path is not a file."; + LOG.error(PackingToolErrMsg.PACKINFO_PATH_FAILED.toString(errMsg)); return false; } if (!PACK_INFO.equals(file.getName())) { - LOG.error("CompressVerify::isArgsValidInHapMode --pack-info-path must be pack.info file."); + String errMsg = "CompressVerify::isArgsValidInHapMode --pack-info-path must be pack.info file."; + LOG.error(PackingToolErrMsg.PACKINFO_PATH_FAILED.toString(errMsg)); return false; } } @@ -263,12 +267,14 @@ public class CompressVerify { private static boolean isVerifyValidInHapCommonMode(Utility utility) { if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::commandPathVerify json-path is empty."); + String errMsg = "CompressVerify::commandPathVerify json-path is empty"; + LOG.error(PackingToolErrMsg.HAP_COMMON_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 = "CompressVerify::isArgsValidInHarMode json-path must be config.json file."; + LOG.error(PackingToolErrMsg.HAP_COMMON_ARGS_INVALID.toString(errMsg)); return false; } @@ -278,39 +284,45 @@ public class CompressVerify { if (!utility.getApkPath().isEmpty() && !compatibleProcess(utility, utility.getApkPath(), utility.getFormattedApkPathList(), APK_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode shell-apk-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode shell-apk-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_COMMON_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getProfilePath().isEmpty()) { File file = new File(utility.getProfilePath()); if (!file.isFile() || !PROFILE_NAME.equals(file.getName())) { - LOG.error("CompressVerify::isArgsValidInHapMode profile-path must be CAPABILITY.profile file."); + String errMsg = "CompressVerify::isArgsValidInHapMode profile-path must be CAPABILITY.profile file."; + LOG.error(PackingToolErrMsg.HAP_COMMON_ARGS_INVALID.toString(errMsg)); return false; } } if (!utility.getDexPath().isEmpty() && !compatibleProcess(utility, utility.getDexPath(), utility.getFormattedDexPathList(), DEX_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode dex-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode dex-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_COMMON_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getAbcPath().isEmpty() && !compatibleProcess(utility, utility.getAbcPath(), utility.getFormattedAbcPathList(), ABC_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode abc-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode abc-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_COMMON_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getDirList().isEmpty() && !splitDirList(utility, utility.getDirList(), utility.getFormatedDirList())) { - LOG.error("CompressVerify::isArgsValidInHapMode --dir-list is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode --dir-list is invalid."; + LOG.error(PackingToolErrMsg.HAP_COMMON_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getPkgContextPath().isEmpty()) { File file = new File(utility.getPkgContextPath()); if (!file.isFile() || !PKG_CONTEXT_INFO.equals(file.getName())) { - LOG.error("CompressVerify::isArgsValidInHapMode --pkg-context-path file must be " + PKG_CONTEXT_INFO); + String errMsg = "CompressVerify::isArgsValidInHapMode --pkg-context-path file must be "; + LOG.error(PackingToolErrMsg.HAP_COMMON_ARGS_INVALID.toString(errMsg + PKG_CONTEXT_INFO )); return false; } } @@ -326,76 +338,90 @@ public class CompressVerify { private static boolean isVerifyValidInHapMode(Utility utility) { File file = new File(utility.getIndexPath()); if (!utility.getIndexPath().isEmpty() && !file.isFile() && INDEX_PROFILE.equals(file.getName())) { - LOG.error("CompressVerify::isArgsValidInHapMode index-path must be resources.index file."); + String errMsg = "CompressVerify::isArgsValidInHapMode index-path must be resources.index file."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getSoPath().isEmpty() && !compatibleProcess(utility, utility.getSoPath(), utility.getFormattedSoPathList(), SO_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode maple-so-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode maple-so-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getAbilitySoPath().isEmpty() && !compatibleProcess(utility, utility.getAbilitySoPath(), utility.getFormattedAbilitySoPathList(), SO_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode ability-so-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode ability-so-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getSoDir())) { - LOG.error("CompressVerify::isArgsValidInHapMode maple-so-dir is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode maple-so-dir is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getLibPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode lib-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode lib-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getHnpPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode hnp-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode hnp-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getResPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode res-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode res-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getResourcesPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode resources-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode resources-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getAssetsPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode assets-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode assets-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getSharedLibsPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode shared-libs-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode shared-libs-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getJarPath().isEmpty() && !compatibleProcess(utility, utility.getJarPath(), utility.getFormattedJarPathList(), JAR_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode jar-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode jar-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getTxtPath().isEmpty() && !compatibleProcess(utility, utility.getTxtPath(), utility.getFormattedTxtPathList(), TXT_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode txt-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode txt-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getANPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode an-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode an-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getEtsPath().isEmpty() && !isPathExists(utility.getEtsPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode ets-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode ets-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -420,45 +446,53 @@ public class CompressVerify { */ private static boolean isVerifyValidInHarMode(Utility utility) { if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::isArgsValidInHarMode json-path is empty."); + String errMsg = "CompressVerify::isArgsValidInHarMode 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 = "CompressVerify::isArgsValidInHarMode json-path must be config.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 = "CompressVerify::isArgsValidInHarMode 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 = "CompressVerify::isArgsValidInHarMode 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 = "CompressVerify::isArgsValidInHarMode 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 = "CompressVerify::isArgsValidInHarMode 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 = "CompressVerify::isArgsValidInHarMode 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 = "CompressVerify::isArgsValidInHarMode assets-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -884,8 +918,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 = "CompressVerify::isDirectoryValidStrictCase directory is not exist, directoryPath: "; + LOG.error(PackingToolErrMsg.DIRECTORY_INVALID.toString(errMsg + path)); return false; } if (file.isDirectory()) { @@ -914,12 +948,14 @@ public class CompressVerify { private static boolean isVerifyValidInHspMode(Utility utility) { if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::isArgsValidInHspMode json-path is empty."); + String errMsg = "CompressVerify::isArgsValidInHspMode json-path is empty."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!isPathValid(utility.getJsonPath(), TYPE_FILE, MODULE_PROFILE)) { - LOG.error("CompressVerify::isArgsValidInHspMode json-path must be module.json file."); + String errMsg = "CompressVerify::isArgsValidInHspMode json-path must be module.json file."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -927,87 +963,99 @@ public class CompressVerify { boolean hspHasAbilities = hspHasAbilities(utility); boolean hspHasExtensionAbilities = hspHasExtensionAbilities(utility); if (hspHasAbilities && hspHasExtensionAbilities) { - LOG.error("shared/appService hsp has abilities and extensionAbilities"); + String errMsg = "shared/appService hsp has abilities and extensionAbilities"; + LOG.error(PackingToolErrMsg.HSP_MODE_ABILITIES_FAILED.toString(errMsg)); return false; } if (hspHasAbilities) { - LOG.error("shared/appService hsp has abilities"); + LOG.error(PackingToolErrMsg.HSP_MODE_ABILITIES_FAILED.toString("shared/appService hsp has abilities")); return false; } if (hspHasExtensionAbilities) { - LOG.error("shared/appService hsp has extensionAbilities"); + LOG.error(PackingToolErrMsg.HSP_MODE_ABILITIES_FAILED.toString("shared/appService hsp has extensionAbilities")); return false; } } if(hasHomeAbility(utility)) { - LOG.error("hsp has home ability"); + LOG.error(PackingToolErrMsg.HSP_MODE_HSPHIME_FAILED.toString("hsp has home ability")); return false; } if (hasHomeExtensionAbility(utility)) { - LOG.error("hsp has home extensionAbility"); + LOG.error(PackingToolErrMsg.HSP_MODE_HSPHIME_FAILED.toString("hsp has home extensionAbility")); return false; } if (!utility.getJarPath().isEmpty() && !compatibleProcess(utility, utility.getJarPath(), utility.getFormattedJarPathList(), JAR_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHspMode jar-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHspMode jar-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getTxtPath().isEmpty() && !compatibleProcess(utility, utility.getTxtPath(), utility.getFormattedTxtPathList(), TXT_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHspMode txt-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHspMode txt-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getLibPath().isEmpty() && !isPathValid(utility.getLibPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHspMode lib-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHspMode lib-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getResPath().isEmpty() && !isPathValid(utility.getResPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHspMode res-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHspMode res-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getResourcesPath().isEmpty() && !isPathValid(utility.getResourcesPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHspMode resources-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHspMode resources-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getAssetsPath().isEmpty() && !isPathValid(utility.getAssetsPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHspMode assets-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHspMode assets-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getDirList().isEmpty() && !splitDirList(utility, utility.getDirList(), utility.getFormatedDirList())) { - LOG.error("CompressVerify::isArgsValidInHapMode --dir-list is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode --dir-list is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getAPPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode ap-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode ap-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getANPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode an-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHapMode an-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getPkgContextPath().isEmpty()) { File file = new File(utility.getPkgContextPath()); if (!file.isFile() || !PKG_CONTEXT_INFO.equals(file.getName())) { - LOG.error("CompressVerify::isArgsValidInHspMode --pkg-context-path file must be " + PKG_CONTEXT_INFO); + String errMsg = "CompressVerify::isArgsValidInHspMode --pkg-context-path file must be "+ PKG_CONTEXT_INFO; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!utility.getEtsPath().isEmpty() && !isPathExists(utility.getEtsPath())) { - LOG.error("CompressVerify::isArgsValidInHspMode ets-path is invalid."); + String errMsg = "CompressVerify::isArgsValidInHspMode ets-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -1016,48 +1064,58 @@ public class CompressVerify { private static boolean isVerifyValidInHapAdditionMode(Utility utility) { if (utility.getHapPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hapPath is empty."); + String errMsg = "CompressVerify::isVerifyValidInHapAdditionMode hapPath is empty."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_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 = "CompressVerify::isVerifyValidInHapAdditionMode hapPath cannot be a folder."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_INVALID.toString(errMsg)); return false; } if (!(hapPath.endsWith(HAP_SUFFIX) || hapPath.endsWith(HSP_SUFFIX))) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hapPath is invalid."); + String errMsg = "CompressVerify::isVerifyValidInHapAdditionMode hapPath is invalid."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_INVALID.toString(errMsg)); return false; } if (!hapFile.exists()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hap file does not exist."); + String errMsg = "CompressVerify::isVerifyValidInHapAdditionMode hap file does not exist."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_INVALID.toString(errMsg)); return false; } if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode jsonPath is empty."); + String errMsg = "CompressVerify::isVerifyValidInHapAdditionMode jsonPath is empty."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_INVALID.toString(errMsg)); return false; } if (!utility.getJsonPath().endsWith(JSON_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode jsonPath is invalid."); + String errMsg = "CompressVerify::isVerifyValidInHapAdditionMode jsonPath is invalid."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_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 = "CompressVerify::isVerifyValidInHapAdditionMode json file does not exist."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_INVALID.toString(errMsg)); return false; } if (!checkJsonIsValid(jsonFile)) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode json format is incorrect."); + String errMsg = "CompressVerify::isVerifyValidInHapAdditionMode json format is incorrect."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_INVALID.toString(errMsg)); return false; } if (utility.getOutPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode outPath is empty."); + String errMsg = "CompressVerify::isVerifyValidInHapAdditionMode outPath is empty."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_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 = "CompressVerify::isVerifyValidInHapAdditionMode outPath is file."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_INVALID.toString(errMsg)); return false; } File absoluteHapFile = new File(utility.getAbsoluteHapPath()); @@ -1065,7 +1123,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 = "CompressVerify::isVerifyValidInHapAdditionMode target file already exists."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_INVALID.toString(errMsg)); return false; } return true; @@ -1080,7 +1139,8 @@ public class CompressVerify { jsonData.append((char) ch); } } catch (IOException e) { - LOG.error("CompressVerify::CheckJsonIsValid failed: " + e.getMessage()); + String errMsg = "CompressVerify::CheckJsonIsValid failed: "; + LOG.error(PackingToolErrMsg.CHECK_JSON_INVALID.toString(errMsg + e.getMessage())); return false; } JSONValidator validator = JSONValidator.from(jsonData.toString()); @@ -1154,11 +1214,13 @@ public class CompressVerify { if(optional.isPresent()) { return ModuleJsonUtil.parseStageBundleType(optional.get()).equals(BUNDLE_TYPE_SHARE); } else { - LOG.error("CompressVerify::isBundleTypeShared jsonPath content invalid"); + String errMsg = "CompressVerify::isBundleTypeShared jsonPath content invalid."; + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_SHARED_INVALID.toString(errMsg)); return false; } } catch (BundleException e) { - LOG.error("CompressVerify::isBundleTypeShared exception: " + e.getMessage()); + String errMsg = "CompressVerify::isBundleTypeShared exception:"; + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_SHARED_INVALID.toString(errMsg +e.getMessage())); return false; } } @@ -1169,11 +1231,13 @@ public class CompressVerify { if(optional.isPresent()) { return ModuleJsonUtil.parseStageBundleType(optional.get()).equals(BUNDLE_TYPE_APP_SERVICE); } else { - LOG.error("CompressVerify::isBundleTypeAppService jsonPath content invalid"); + String errMsg = "CompressVerify::isBundleTypeAppService jsonPath content invalid"; + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_APPSERVICE_INVALID.toString(errMsg)); return false; } } catch (BundleException e) { - LOG.error("CompressVerify::isBundleTypeAppService exception: " + e.getMessage()); + String errMsg = "CompressVerify::isBundleTypeAppService exception: "; + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_APPSERVICE_INVALID.toString(errMsg +e.getMessage())); return false; } } @@ -1184,11 +1248,13 @@ public class CompressVerify { if(optional.isPresent()) { return ModuleJsonUtil.parseModuleType(optional.get()).equals(BUNDLE_TYPE_SHARE) && !ModuleJsonUtil.parseAbilityNames(optional.get()).isEmpty(); } else { - LOG.error("CompressVerify::hspHasAbilities jsonPath content invalid"); + String errMsg = "CompressVerify::hspHasAbilities jsonPath content invalid"; + LOG.error(PackingToolErrMsg.HSP_HAS_ABILITIES_INVALID.toString(errMsg)); return false; } } catch (BundleException e) { - LOG.error("CompressVerify::hspHasAbilities exception: " + e.getMessage()); + String errMsg = "CompressVerify::hspHasAbilities exception: "; + LOG.error(PackingToolErrMsg.HSP_HAS_ABILITIES_INVALID.toString(errMsg +e.getMessage())); return false; } } @@ -1200,10 +1266,12 @@ public class CompressVerify { return ModuleJsonUtil.parseModuleType(optional.get()).equals(BUNDLE_TYPE_SHARE) && !ModuleJsonUtil.parseExtensionAbilityName(optional.get()).isEmpty(); } else { - LOG.error("CompressVerify::hspHasExtensionAbilities jsonPath content invalid"); + String errMsg = "CompressVerify::hspHasExtensionAbilities jsonPath content invalid"; + LOG.error(PackingToolErrMsg.HSP_HAS_EXTENSION_INVALID.toString(errMsg)); } } catch (BundleException e) { - LOG.error("CompressVerify::hspHasExtensionAbilities exception: " + e.getMessage()); + String errMsg = "CompressVerify::hspHasExtensionAbilities exception: "; + LOG.error(PackingToolErrMsg.HSP_HAS_EXTENSION_INVALID.toString(errMsg + e.getMessage())); } return false; } @@ -1213,17 +1281,20 @@ public class CompressVerify { boolean result = false; Optional optional = FileUtils.getFileContent(utility.getJsonPath()); if(!optional.isPresent()) { - LOG.error("CompressVerify::hasHomeAbility jsonPath content invalid"); + String errMsg = "CompressVerify::hasHomeAbility jsonPath content invalid"; + LOG.error(PackingToolErrMsg.HAS_HOME_ABILITY_INVALID.toString(errMsg)); return false; } Map abilitiesMap = ModuleJsonUtil.parseAbilitySkillsMap(optional.get()); if (abilitiesMap.containsValue(true)) { result = true; } - LOG.info("CompressVerify::hasHomeAbilities result = " + result); + String errMsg = "CompressVerify::hasHomeAbilities result = "; + LOG.error(PackingToolErrMsg.HAS_HOME_ABILITY_INVALID.toString(errMsg + result)); return result; } catch (BundleException e) { - LOG.error("CompressVerify::hasHomeAbilities exception: " + e.getMessage()); + String errMsg = "CompressVerify::hasHomeAbilities exception: "; + LOG.error(PackingToolErrMsg.HAS_HOME_ABILITY_INVALID.toString(errMsg + e.getMessage())); return false; } } @@ -1249,17 +1320,20 @@ public class CompressVerify { boolean result = false; Optional optional = FileUtils.getFileContent(utility.getJsonPath()); if (!optional.isPresent()) { - LOG.error("CompressVerify::hasHomeExtensionAbility jsonPath content invalid"); + String errMsg = "CompressVerify::hasHomeExtensionAbility jsonPath content invalid"; + LOG.error(PackingToolErrMsg.HAS_HOME_EXTENSION_INVALID.toString(errMsg)); return false; } Map extensionAbilitiesMap = ModuleJsonUtil.parseExtensionAbilitySkillsMap(optional.get()); if (extensionAbilitiesMap.containsValue(true)) { result = true; } - LOG.info("CompressVerify::hasHomeExtensionAbility result = " + result); + String errMsg = "CompressVerify::hasHomeExtensionAbility result = "; + LOG.error(PackingToolErrMsg.HAS_HOME_EXTENSION_INVALID.toString(errMsg + result)); return result; } catch (BundleException e) { - LOG.error("CompressVerify::hasHomeExtensionAbility exception: " + e.getMessage()); + String errMsg = "CompressVerify::hasHomeExtensionAbility exception: "; + LOG.error(PackingToolErrMsg.HAS_HOME_EXTENSION_INVALID.toString(errMsg + e.getMessage())); return false; } } diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index 33461812..8701391e 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -348,7 +348,9 @@ public class Compressor { File outParentFile = destFile.getParentFile(); if ((outParentFile != null) && (!outParentFile.exists())) { if (!outParentFile.mkdirs()) { - LOG.error("Compressor::compressProcess create out file parent directory failed."); + String errMsg = "create out file parent directory failed."; + String solution = "Check input out-path"; + LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_FAILED.toString(errMsg, solution)); return false; } } @@ -363,10 +365,10 @@ public class Compressor { compressExcute(utility); } catch (FileNotFoundException exception) { compressResult = false; - LOG.error("Compressor::compressProcess file not found exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString(exception.getMessage())); } catch (BundleException ex) { compressResult = false; - LOG.error("Compressor::compressProcess Bundle exception: " + ex.getMessage()); + LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_EXCEPTION.toString(ex.getMessage())); } finally { closeZipOutputStream(); Utility.closeStream(zipOut); @@ -376,14 +378,20 @@ public class Compressor { if (compressResult && !checkAppAtomicServiceCompressedSizeValid(utility)) { compressResult = false; - LOG.error("Compressor::compressProcess check atomic service size fail."); + String errMsg = "Execut compress failed."; + String solution = "Please check the related error message and modify."; + LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_FAILED.toString(errMsg, solution)); } // if compress failed, delete out file. if (!compressResult) { - LOG.error("Compressor::compressProcess compress failed."); + String errMsg = "Execut compress failed."; + String solution = "Please check the related error message and modify."; + LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_FAILED.toString(errMsg, solution)); if (!destFile.delete()) { - LOG.error("Compressor::compressProcess delete dest file failed."); + errMsg = "Delete out file failed."; + solution = "Try to close the out file using programme"; + LOG.error(PackingToolErrMsg.FILE_DELETE_FAILED.toString(errMsg, solution)); } } return compressResult; @@ -426,35 +434,35 @@ public class Compressor { Optional optional = FileUtils.getFileContent(utility.getJsonPath()); String jsonString = optional.get(); if (!checkStageAsanTsanEnabledValid(jsonString)) { - LOG.error("checkStageAsanTsanEnabledValid failed."); - throw new BundleException("compressHsp failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_ASANTSAN.toString("checkStageAsanTsanEnabledValid failed.")); + throw new BundleException(PackingToolErrMsg.COMPRESS_HSP.toString("compressHsp failed")); } if (!checkStageHwasanEnabledValid(jsonString)) { - LOG.error("checkStageHwasanEnabledValid failed."); - throw new BundleException("compressHsp failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HWASAN.toString("checkStageHwasanEnabledValid failed.")); + throw new BundleException(PackingToolErrMsg.COMPRESS_HSP.toString("compressHsp failed")); } if (!checkStageUbsanEnabledValid(jsonString)) { - LOG.error("checkStageUbsanEnabledValid failed."); - throw new BundleException("compressHsp failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_UBSAN.toString("checkStageUbsanEnabledValid failed.")); + throw new BundleException(PackingToolErrMsg.COMPRESS_HSP.toString("compressHsp failed")); } if (!checkStageAtomicService(jsonString)) { - LOG.error("checkStageAtomicService failed."); - throw new BundleException("checkStageAtomicService failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_ATOMIC.toString("checkStageAtomicService failed.")); + throw new BundleException(PackingToolErrMsg.CHECK_STAGE_ATOMIC.toString("checkStageAtomicService failed")); } // check continueBundleName in module.json if (!checkContinueBundleNameIsValid(jsonString)) { - LOG.error("checkContinueBundleNameIsValid failed."); - throw new BundleException("compressHsp failed."); + LOG.error(PackingToolErrMsg.CHECK_CONTINUE_BUNDLE.toString("checkContinueBundleNameIsValid failed.")); + throw new BundleException(PackingToolErrMsg.COMPRESS_HSP.toString("compressHsp failed")); } // check whether is an overlay hsp or not - if (!checkStageOverlayCfg(jsonString)) { - LOG.error("checkStageOverlayCfg failed."); - throw new BundleException("checkStageOverlayCfg failed."); + if (!checkStageOverlayCfg(jsonString)) {; + LOG.error(PackingToolErrMsg.CHECK_STAGE_OVERLAY.toString("checkStageOverlayCfg failed.")); + throw new BundleException(PackingToolErrMsg.CHECK_STAGE_OVERLAY.toString("checkStageOverlayCfg failed")); } String moduleType = ModuleJsonUtil.parseModuleType(jsonString); if (!TYPE_SHARED.equals(moduleType)) { - LOG.error("module type must be shared."); - throw new BundleException("compressHsp failed."); + LOG.error(PackingToolErrMsg.CHECK_MODULE_TYPE.toString("module type must be shared")); + throw new BundleException(PackingToolErrMsg.COMPRESS_HSP.toString("compressHsp failed")); } } compressHSPMode(utility); @@ -470,8 +478,7 @@ public class Compressor { setGenerateBuildHash(utility); if (isModuleJSON(utility.getJsonPath())) { if (!checkStageHap(utility)) { - LOG.error("checkStageHap failed."); - throw new BundleException("checkStageHap failed."); + throw new BundleException(PackingToolErrMsg.CHECK_STAGE_HAP.toString("checkStageHap failed")); } Optional optional = FileUtils.getFileContent(utility.getJsonPath()); String jsonString = optional.get(); @@ -749,25 +756,25 @@ public class Compressor { Optional optional = FileUtils.getFileContent(utility.getJsonPath()); String jsonString = optional.get(); if (!checkStageAsanTsanEnabledValid(jsonString)) { - LOG.error("checkStageAsanTsanEnabledValid failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_ASANTSAN.toString("checkStageAsanTsanEnabledValid failed.")); return false; } if (!checkStageHwasanEnabledValid(jsonString)) { - LOG.error("checkStageHwasanEnabledValid failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HWASAN.toString("checkStageHwasanEnabledValid failed.")); return false; } if (!checkStageUbsanEnabledValid(jsonString)) { - LOG.error("checkStageUbsanEnabledValid failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_UBSAN.toString("checkStageUbsanEnabledValid failed.")); return false; } // check atomicService in module.json if (!checkStageAtomicService(jsonString)) { - LOG.error("checkStageAtomicService failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_ATOMIC.toString("checkStageAtomicService failed.")); return false; } // check continueBundleName in module.json if (!checkContinueBundleNameIsValid(jsonString)) { - LOG.error("checkContinueBundleNameIsValid failed."); + LOG.error(PackingToolErrMsg.CHECK_CONTINUE_BUNDLE.toString("checkContinueBundleNameIsValid failed.")); return false; } return true; @@ -777,7 +784,7 @@ public class Compressor { boolean asanEnabled = ModuleJsonUtil.getStageAsanEnabled(jsonString); boolean tsanEnabled = ModuleJsonUtil.getStageTsanEnabled(jsonString); if (asanEnabled && tsanEnabled) { - LOG.error("asanEnabled and tsanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_AS_TSAN_ENABLED.toString("asanEnabled and tsanEnabled cannot be true at the same time.")); return false; } return true; @@ -789,15 +796,15 @@ public class Compressor { boolean gwpAsanEnabled = ModuleJsonUtil.getStageGwpAsanEnabled(jsonString); boolean hwasanEnabled = ModuleJsonUtil.getStageHwasanEnabled(jsonString); if (hwasanEnabled && asanEnabled) { - LOG.error("hwasanEnabled and asanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_HW_ASAN_ENABLED.toString("hwasanEnabled and asanEnabled cannot be true at the same time")); return false; } if (hwasanEnabled && tsanEnabled) { - LOG.error("hwasanEnabled and tsanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_HW_TSAN_ENABLED.toString("hwasanEnabled and tsanEnabled cannot be true at the same time")); return false; } if (hwasanEnabled && gwpAsanEnabled) { - LOG.error("hwasanEnabled and GWPAsanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_HW_GWPASAN_ENABLED.toString("hwasanEnabled and GWPAsanEnabled cannot be true at the same time")); return false; } return true; @@ -813,7 +820,7 @@ public class Compressor { } for (int i = 0; i < continueBundleNameList.size(); i++) { if (bundleName.equals(continueBundleNameList.get(i))) { - LOG.error("continueBundleName cannot include self."); + LOG.error(PackingToolErrMsg.CHECK_BUNDLENAME.toString("continueBundleName cannot include self.")); return false; } } @@ -827,15 +834,15 @@ public class Compressor { boolean hwasanEnabled = ModuleJsonUtil.getStageHwasanEnabled(jsonString); boolean ubsanEnabled = ModuleJsonUtil.getStageUbsanEnabled(jsonString); if(ubsanEnabled && asanEnabled) { - LOG.error("ubsanEnabled and asanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_UB_ASAN_ENABLED.toString("ubsanEnabled and asanEnabled cannot be true at the same time")); return false; } if(ubsanEnabled && tsanEnabled) { - LOG.error("ubsanEnabled and tsanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_UB_TSAN_ENABLED.toString("ubsanEnabled and tsanEnabled cannot be true at the same time.")); return false; } if(ubsanEnabled && hwasanEnabled) { - LOG.error("ubsanEnabled and hwasanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_UB_HWASAN_ENABLED.toString("ubsanEnabled and hwasanEnabled cannot be true at the same time")); return false; } return true; @@ -844,17 +851,17 @@ public class Compressor { private static boolean checkStageAtomicService(String jsonString) throws BundleException { // check consistency of atomicService if (!ModuleJsonUtil.isModuleAtomicServiceValid(jsonString)) { - LOG.error("check module atomicService failed."); + LOG.error(PackingToolErrMsg.CHECK_MODULE_ATOMIC.toString("check module atomicService failed.")); return false; } // check entry module must have ability if (!ModuleJsonUtil.checkEntryInAtomicService(jsonString)) { - LOG.error("checkEntryInAtomicService failed."); + LOG.error(PackingToolErrMsg.CHECK_ENTRYIN_ATOMIC.toString("checkEntryInAtomicService failed.")); return false; } // check installationFree if (!ModuleJsonUtil.checkAtomicServiceInstallationFree(jsonString)) { - LOG.error("check atomic service installationFree failed."); + LOG.error(PackingToolErrMsg.INSTALL_FREE_FAILED.toString("check atomic service installationFree failed.")); return false; } @@ -867,17 +874,17 @@ public class Compressor { if (!targetModuleName.isEmpty()) { // check targetModuleName and requestPermission if (ModuleJsonUtil.isExistedStageRequestPermissions(jsonString)) { - LOG.error("targetModuleName cannot be existed with requestPermissions."); + LOG.error(PackingToolErrMsg.CHECK_OVERLAYCF_PERMISSIONS_FAILED.toString("targetModuleName cannot be existed with requestPermissions.")); return false; } // check targetModuleName and name if (targetModuleName.equals(ModuleJsonUtil.parseStageModuleName(jsonString))) { - LOG.error("targetModuleName cannot be same with name in the overlay module."); + LOG.error(PackingToolErrMsg.CHECK_OVERLAYCF_MODULE_FAILED.toString("targetModuleName cannot be same with name in the overlay module.")); return false; } } else { if (ModuleJsonUtil.isExistedStageModuleTargetPriority(jsonString)) { - LOG.error("targetPriority cannot be existed without the targetModuleName in module.json."); + LOG.error(PackingToolErrMsg.CHECK_OVERLAYCF_TARGETMODULENAME_FAILED.toString("targetPriority cannot be existed without the targetModuleName in module.json.")); return false; } } @@ -885,16 +892,16 @@ public class Compressor { String targetBundleName = ModuleJsonUtil.getStageTargetBundleName(jsonString); if (!targetBundleName.isEmpty()) { if (targetModuleName.isEmpty()) { - LOG.error("targetModuleName is necessary in the overlay bundle."); + LOG.error(PackingToolErrMsg.CHECK_TARGETMODULENAME_ISEMPTY_FAILED.toString("targetModuleName is necessary in the overlay bundle.")); return false; } if (targetBundleName.equals(ModuleJsonUtil.parseBundleName(jsonString))) { - LOG.error("targetBundleName cannot be same with the bundleName."); + LOG.error(PackingToolErrMsg.CHECK_TARGETMODULENAME_EQUALS_FAILED.toString("targetBundleName cannot be same with the bundleName.")); return false; } } else { if (ModuleJsonUtil.isExistedStageAppTargetPriority(jsonString)) { - LOG.error("targetPriority cannot be existed without the targetBundleName in app.json."); + LOG.error(PackingToolErrMsg.CHECK_TARGETPRIORITY_FAILED.toString("targetPriority cannot be existed without the targetBundleName in app.json.")); return false; } } @@ -2796,7 +2803,7 @@ public class Compressor { } } } catch (IOException exception) { - LOG.error("Compressor::parseCompressNativeLibs io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.PARSE_COMPRESS_NATIVE_LIBS_FAILED.toString(exception.getMessage())); throw new BundleException("Parse compress native libs failed."); } } @@ -2853,7 +2860,7 @@ public class Compressor { break; } } catch (IOException exception) { - LOG.error("Compressor::parseDeviceType io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.PARSE_DEVICE_TYPE_FAILED.toString(exception.getMessage())); throw new BundleException("Parse device type failed."); } } @@ -2870,18 +2877,18 @@ public class Compressor { List hapVerifyInfos = new ArrayList<>(); for (String hapPath : fileLists) { if (hapPath.isEmpty()) { - LOG.error("Compressor::checkHapIsValid input wrong hap file."); + LOG.error(PackingToolErrMsg.INVALID_HAP_FILE.toString("Input wrong hap or hsp file.")); throw new BundleException("Compressor::checkHapIsValid input wrong hap file."); } File srcFile = new File(hapPath); String fileStr = srcFile.getName(); if (fileStr.isEmpty()) { - LOG.error("Compressor::checkHapIsValid get file name failed."); + LOG.error(PackingToolErrMsg.INVALID_HAP_FILE.toString("get file name failed.")); throw new BundleException("Compressor::checkHapIsValid get file name failed."); } if (!fileStr.toLowerCase(Locale.ENGLISH).endsWith(HAP_SUFFIX) && !fileStr.toLowerCase(Locale.ENGLISH).endsWith(HSP_SUFFIX)) { - LOG.error("Compressor::checkHapIsValid input wrong hap file."); + LOG.error(PackingToolErrMsg.INVALID_HAP_FILE.toString("input wrong hap file.")); throw new BundleException("Compressor::checkHapIsValid input wrong hap file."); } if (isModuleHap(hapPath)) { @@ -2907,8 +2914,9 @@ public class Compressor { for (HapVerifyInfo hapVerifyInfo : hapVerifyInfos) { String bundleType = hapVerifyInfo.getBundleType(); if (TYPE_SHARED.equals(bundleType)) { - LOG.error("Compressor::checkHapIsValid only one item can be entered in the -hsp-path" + - " when bundleType is shared."); + String cause = "Only one item can be entered in the -hsp-path when bundleType is 'shared'."; + String solution = "Ensure that only one item entered in the -hsp-path when bundleType is 'shared'"; + LOG.error(PackingToolErrMsg.CHECK_BUNDLETYPE_INVALID.toString(cause, solution)); return false; } } @@ -2987,7 +2995,8 @@ public class Compressor { hapVerifyInfo.setResourceMap(FileUtils.getProfileJson(zipFile)); hapVerifyInfo.setProfileStr(FileUtils.getFileStringFromZip(MODULE_JSON, zipFile)); } catch (IOException e) { - LOG.error("FileUtil::parseStageHapVerifyInfo file not available."); + LOG.error(PackingToolErrMsg.READ_STAGE_HAP_VERIFY_INFO_FAILED.toString( + "parse stage hap verify info file not available.")); throw new BundleException("FileUtil::parseStageHapVerifyInfo file not available."); } finally { Utility.closeStream(zipFile); @@ -3010,8 +3019,9 @@ public class Compressor { zipFile = new ZipFile(srcFile); hapVerifyInfo.setProfileStr(FileUtils.getFileStringFromZip(CONFIG_JSON, zipFile)); } catch (IOException e) { - LOG.error("FileUtil::parseStageHapVerifyInfo file not available."); - throw new BundleException("FileUtil::parseStageHapVerifyInfo file not available."); + LOG.error(PackingToolErrMsg.READ_FA_HAP_VERIFY_INFO_FAILED.toString( + "parse FA hap verify info file not available.")); + throw new BundleException("FileUtil::parseFAHapVerifyInfo file not available."); } finally { Utility.closeStream(zipFile); } diff --git a/adapter/ohos/ModuleJsonUtil.java b/adapter/ohos/ModuleJsonUtil.java index 6bbf2690..f6f2cd2b 100644 --- a/adapter/ohos/ModuleJsonUtil.java +++ b/adapter/ohos/ModuleJsonUtil.java @@ -387,13 +387,15 @@ 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 = "ModuleJsonUtil:mergeTwoPackInfo 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 = "ModuleJsonUtil:mergeTwoPackInfo merge pack.info failed: "; + LOG.error(PackingToolErrMsg.MERGE_TWO_PACKINFO_FAILED.toString(errMsg + e.getMessage())); + throw new BundleException(errMsg); } return desPackInfo; } @@ -407,24 +409,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 = "ModuleJsonUtil:verifyPackInfo fail to read pack.info."; + 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 = "ModuleJsonUtil:verifyPackInfo pack.info do 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 = "ModuleJsonUtil:verifyPackInfo pack.info do 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 = "ModuleJsonUtil:verifyPackInfo verify app failed."; + LOG.error(PackingToolErrMsg.VERIFY_PACKINFO_FAILED.toString(errMsg)); return false; } @@ -440,32 +446,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 = "ModuleJsonUtil:verifyAppInPackInfo input null json object."; + LOG.error(PackingToolErrMsg.APP_INPACKINFO_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 = "ModuleJsonUtil:verifyAppInPackInfo bundleName is different."; + LOG.error(PackingToolErrMsg.APP_INPACKINFO_FAILED.toString(errMsg)); return false; } // check bundleType if (!checkBundleTypeInPackInfo(finalAppObj, srcAppObj)) { - LOG.error("ModuleJsonUtil:verifyAppInPackInfo bundleType is different."); + String errMsg = "ModuleJsonUtil:verifyAppInPackInfo bundleType is different."; + LOG.error(PackingToolErrMsg.APP_INPACKINFO_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 = "ModuleJsonUtil:verifyAppInPackInfo version object is empty."; + LOG.error(PackingToolErrMsg.APP_INPACKINFO_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 = "ModuleJsonUtil:verifyAppInPackInfo versionCode is different."; + LOG.error(PackingToolErrMsg.APP_INPACKINFO_FAILED.toString(errMsg)); return false; } return true; @@ -480,7 +491,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 = "ModuleJsonUtil:checkBundleTypeInPackInfo pack.info has empty module."; + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_PACKINFO_INVALID.toString(errMsg)); return false; } String finalBundleType = "app"; @@ -492,7 +504,8 @@ class ModuleJsonUtil { srcBundleType = getJsonString(srcAppObj, BUNDLE_TYPE); } if (!finalBundleType.equals(srcBundleType)) { - LOG.error("bundleType in pack.info is not same."); + String errMsg = "bundleType in pack.info is not same."; + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_PACKINFO_INVALID.toString(errMsg)); return false; } return true; @@ -548,13 +561,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 = "ModuleJsonUtil::parsePackInfoFormsName error: summary is null."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMSNAME_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 = "ModuleJsonUtil::parsePackInfoFormsName error: summary.modules is null."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMSNAME_FAILED.toString(errMsg)); return; } @@ -562,13 +577,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 = "ModuleJsonUtil::parsePackInfoFormsName error: summary.modules.distro is null."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMSNAME_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 = "ModuleJsonUtil::parsePackInfoFormsName error: summary.modules.distro.moduleName is null."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMSNAME_FAILED.toString(errMsg)); continue; } @@ -623,22 +640,26 @@ class ModuleJsonUtil { String moduleName = ""; try { if (moduleObj == null) { - LOG.error("ModuleJsonUtil:parseFaModuleName failed: json file do not contain module."); + String errMsg = "ModuleJsonUtil:parseFaModuleName failed: json file do not contain module."; + LOG.error(PackingToolErrMsg.PARSE_DISTOR_MODULENAME_FAILED.toString(errMsg)); throw new BundleException("ModuleJsonUtil:parseFaModuleName failed: json file do not contain module."); } JSONObject distroObj = moduleObj.getJSONObject(DISTRO); if (distroObj == null) { - LOG.error("ModuleJsonUtil:parseFaModuleName failed: json file do not contain distro."); + String errMsg = "ModuleJsonUtil:parseFaModuleName failed: json file do not contain distro."; + LOG.error(PackingToolErrMsg.PARSE_DISTOR_MODULENAME_FAILED.toString(errMsg)); throw new BundleException("ModuleJsonUtil:parseFaModuleName failed: json file do not contain distro."); } if (!distroObj.containsKey(MODULE_NAME)) { - LOG.error("ModuleJsonUtil:parseFaModuleName failed: json file do not contain moduleName."); + String errMsg = "ModuleJsonUtil:parseFaModuleName failed: json file do not contain moduleName."; + LOG.error(PackingToolErrMsg.PARSE_DISTOR_MODULENAME_FAILED.toString(errMsg)); throw new BundleException("ModuleJsonUtil:parseFaModuleName failed:" + "json file do not contain moduleName."); } moduleName = distroObj.getString(MODULE_NAME); } catch (BundleException e) { - LOG.error("ModuleJsonUtil:parseFaModuleName failed."); + String errMsg = "ModuleJsonUtil:parseFaModuleName failed."; + LOG.error(PackingToolErrMsg.PARSE_DISTOR_MODULENAME_FAILED.toString(errMsg)); throw new BundleException("ModuleJsonUtil:parseFaModuleName failed."); } return moduleName; @@ -654,14 +675,14 @@ class ModuleJsonUtil { 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); + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_INVALID.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); + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_INVALID.toString(errMsg)); throw new BundleException(errMsg); } // merge modules @@ -669,7 +690,7 @@ class ModuleJsonUtil { JSONArray srcModuleObs = srcSummaryObj.getJSONArray(MODULES); if (finalModuleObs == null || srcModuleObs == null) { String errMsg = "ModuleJsonUtil:mergePackInfoObj input json file has empty module."; - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_INVALID.toString(errMsg)); throw new BundleException(errMsg); } finalModuleObs.addAll(srcModuleObs); @@ -678,7 +699,7 @@ class ModuleJsonUtil { JSONArray srcPackageObs = srcPackinfoObj.getJSONArray(PACKAGES); if (finalPackageObs == null || srcPackageObs == null) { String errMsg = "ModuleJsonUtil:mergePackInfoObj input json file has empty packages."; - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_INVALID.toString(errMsg)); throw new BundleException(errMsg); } finalPackageObs.addAll(srcPackageObs); @@ -703,7 +724,7 @@ class ModuleJsonUtil { srcPackObj = JSON.parseObject(srcPackInfo); } catch (JSONException exception) { String errMsg = "parse JSONObject failed: " + exception.getMessage(); - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.MERGE_BYPACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // verify app in pack.info @@ -713,7 +734,7 @@ class ModuleJsonUtil { JSONObject srcAppObj = srcSummaryObj.getJSONObject(APP); if (!verifyAppInPackInfo(finalAppObj, srcAppObj)) { String errMsg = "verify pack.info failed, different version, bundleType or bundleName."; - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.MERGE_BYPACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } for (HashMap.Entry entry : packagePair.entrySet()) { @@ -736,7 +757,7 @@ class ModuleJsonUtil { 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); + LOG.error(PackingToolErrMsg.MERGE_OBJBY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // merge module @@ -744,13 +765,14 @@ class ModuleJsonUtil { JSONObject srcSummaryObj = srcPackObj.getJSONObject(SUMMARY); if (finalSummaryObj == null || srcSummaryObj == null) { String errMsg = "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair failed: pack.info do not contain summary."; - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.MERGE_OBJBY_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 = "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair input json file has empty module."; + LOG.error(PackingToolErrMsg.MERGE_OBJBY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException("ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair input json file has empty module."); } @@ -767,7 +789,7 @@ class ModuleJsonUtil { if (!findModule) { String errMsg = "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair" + " input json do not contain " + moduleName + "."; - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.MERGE_OBJBY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // merge package @@ -776,7 +798,7 @@ class ModuleJsonUtil { if (finalPackages == null || srcPackages == null) { String errMsg = "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair failed: pack.info do not contain packages."; - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.MERGE_OBJBY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } boolean findPackage = false; @@ -791,7 +813,7 @@ class ModuleJsonUtil { if (!findPackage) { String errMsg = "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair input json do not contain " + packageName + "."; - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.MERGE_OBJBY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } } @@ -1842,12 +1864,13 @@ class ModuleJsonUtil { try { jsonObject = JSON.parseObject(jsonString); } catch (JSONException exception) { - LOG.error("parse JOSNObject failed in isExistedProperty."); + LOG.error(PackingToolErrMsg.PARSE_JSONOBJECT_FAILED.toString("parse JOSNObject failed in isExistedProperty.")); throw new BundleException("parse JOSNObject failed in isExistedProperty."); } JSONObject appObj = jsonObject.getJSONObject(fatherProperty); if (appObj == null) { - LOG.error("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_JSONOBJECT_FAILED.toString(errMsg)); throw new BundleException("parse failed, input module.json is invalid, module.json has no " + fatherProperty + "."); } @@ -1899,7 +1922,8 @@ class ModuleJsonUtil { if (moduleObj.containsKey(ATOMIC_SERVICE) && (!appObj.containsKey(BUNDLE_TYPE) || !getJsonString(appObj, BUNDLE_TYPE).equals(ATOMIC_SERVICE))) { - LOG.error("module can not config atomicService when bundleType is not atomicService."); + String errMsg = "module can not config atomicService when bundleType is not atomicService."; + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_BUNDLE.toString(errMsg)); return false; } return true; @@ -1916,7 +1940,8 @@ class ModuleJsonUtil { return true; } if (parseModuleType(jsonString).equals(ENTRY) && parseAbilityNames(jsonString).isEmpty()) { - LOG.error("entry module must contain at least one ability."); + String errMsg = "entry module must contain at least one ability."; + LOG.error(PackingToolErrMsg.CHECK_LEASTONE_ABILITY.toString(errMsg)); return false; } return true; @@ -1938,7 +1963,7 @@ class ModuleJsonUtil { if (installationFree) { String errMessage = "The app.json5 file configuration does not match the installationFree:" + " true settings. Add the bundleType field to the app.json5 file and set it atomicService."; - LOG.error(errMessage); + LOG.error(PackingToolErrMsg.ATOMIC_INSTALLATION_FREE_FAILED.toString(errMessage)); return false; } return true; @@ -1946,26 +1971,26 @@ class ModuleJsonUtil { String bundleType = getJsonString(appObj, BUNDLE_TYPE); if (bundleType.equals(APP)) { if (installationFree) { - LOG.error("installationFree must be false when bundleType is app."); + LOG.error(PackingToolErrMsg.ATOMIC_INSTALLATION_FREE_FAILED.toString("installationFree must be false when bundleType is app.")); return false; } } else if (bundleType.equals(ATOMIC_SERVICE)) { if (!installationFree) { - LOG.error("installationFree must be true when bundleType is atomicService."); + LOG.error(PackingToolErrMsg.ATOMIC_INSTALLATION_FREE_FAILED.toString("installationFree must be true when bundleType is atomicService.")); return false; } } else if (SHARED.equals(bundleType)) { if (installationFree) { - LOG.error("installationFree must be false when bundleType is shared."); + LOG.error(PackingToolErrMsg.ATOMIC_INSTALLATION_FREE_FAILED.toString("installationFree must be false when bundleType is shared.")); return false; } } else if (APP_SERVICE.equals(bundleType)) { if (installationFree) { - LOG.error("installationFree must be false when bundleType is appService."); + LOG.error(PackingToolErrMsg.ATOMIC_INSTALLATION_FREE_FAILED.toString("installationFree must be false when bundleType is appService.")); return false; } } else { - LOG.error("bundleType is invalid in app.json."); + LOG.error(PackingToolErrMsg.ATOMIC_INSTALLATION_FREE_FAILED.toString("bundleType is invalid in app.json.")); return false; } return true; @@ -2038,20 +2063,23 @@ 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 = "ModuleJsonUtil::parsePackInfoForms exception: " + + "summary.modules.extensionAbilities.forms.defaultDimension is null."; + 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 = "ModuleJsonUtil::parsePackInfoForms exception: " + + "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 = "ModuleJsonUtil::parsePackInfoForms exception: " + + "summary.modules.extensionAbilities.forms.supportDimensions is null."; + 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/PackingToolErrMsg.java b/adapter/ohos/PackingToolErrMsg.java new file mode 100644 index 00000000..7baa875c --- /dev/null +++ b/adapter/ohos/PackingToolErrMsg.java @@ -0,0 +1,711 @@ +/* + * 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; + +/** + * SignToolErrMsg + * + * @since 2025/01/06 + */ +public class PackingToolErrMsg { + + /** + * CHECK_STAGE_ATOMIC + */ + public static final ErrorMsg CHECK_STAGE_ATOMIC = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("10") + .addErrCode("001") + .addDescription("check StageHap AtomicService failed") + .addCause("%s") + .build(); + + /** + * CHECK_MODULE_ATOMIC + */ + public static final ErrorMsg CHECK_MODULE_ATOMIC = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("10") + .addErrCode("002") + .addDescription("check module atomicService failed.") + .addCause("%s") + .build(); + + /** + * CHECK_ATOMIC_BUNDLE + */ + public static final ErrorMsg CHECK_ATOMIC_BUNDLE = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("10") + .addErrCode("003") + .addDescription("when bundleType is not atomicService") + .addCause("%s") + .build(); + + /** + * CHECK_LEASTONE_ABILITY + */ + public static final ErrorMsg CHECK_LEASTONE_ABILITY = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("10") + .addErrCode("004") + .addDescription("check at least one ability") + .addCause("%s") + .build(); + + /** + * CHECK_ENTRYIN_ATOMIC + */ + public static final ErrorMsg CHECK_ENTRYIN_ATOMIC = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("10") + .addErrCode("005") + .addDescription("check EntryInAtomicService failed.") + .addCause("%s") + .build(); + + /** + * CHECK_STAGE_ASANTSAN + */ + public static final ErrorMsg CHECK_STAGE_ASANTSAN = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("001") + .addDescription("check AsanTsanEnabledValid failed") + .addCause("%s") + .build(); + + /** + * CHECK_STAGE_HWASAN + */ + public static final ErrorMsg CHECK_STAGE_HWASAN = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("002") + .addDescription("check HwasanEnabledValid failed") + .addCause("%s") + .build(); + + /** + * CHECK_STAGE_UBSAN + */ + public static final ErrorMsg CHECK_STAGE_UBSAN = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("003") + .addDescription("check UbsanEnabledValid failed") + .addCause("%s") + .build(); + /** + * CHECK_AS_TSAN_ENABLED + */ + public static final ErrorMsg CHECK_AS_TSAN_ENABLED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("004") + .addDescription("Check asanEnabled and tsanEnabled failed") + .addCause("%s") + .addSolution("Please set the correct values for the parameters.") + .build(); + + /** + * CHECK_HW_ASAN_ENABLED + */ + + public static final ErrorMsg CHECK_HW_ASAN_ENABLED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("005") + .addDescription("Check hwasanEnabled and asanEnabled failed") + .addCause("%s") + .addSolution("Please set the correct values for the parameters.") + .build(); + /** + * CHECK_HW_TSAN_ENABLED + */ + public static final ErrorMsg CHECK_HW_TSAN_ENABLED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("006") + .addDescription("Check hwasanEnabled and tsanEnabled failed") + .addCause("%s") + .addSolution("Please set the correct values for the parameters.") + .build(); + + /** + * CHECK_HW_GWPASAN_ENABLED + */ + public static final ErrorMsg CHECK_HW_GWPASAN_ENABLED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("007") + .addDescription("Check hwasanEnabled and GWPAsanEnabled failed") + .addCause("%s") + .addSolution("Please set the correct values for the parameters.") + .build(); + + /** + * CHECK_UB_ASAN_ENABLED + */ + public static final ErrorMsg CHECK_UB_ASAN_ENABLED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("008") + .addDescription("Check ubsanEnabled and asanEnabled failed") + .addCause("%s") + .addSolution("Please set the correct values for the parameters.") + .build(); + /** + * CHECK_UB_TSAN_ENABLED + */ + public static final ErrorMsg CHECK_UB_TSAN_ENABLED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("009") + .addDescription("Check ubsanEnabled and tsanEnabled failed") + .addCause("%s") + .addSolution("Please set the correct values for the parameters.") + .build(); + + /** + * CHECK_UB_HWASAN_ENABLED + */ + public static final ErrorMsg CHECK_UB_HWASAN_ENABLED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("010") + .addDescription("Check ubsanEnabled and hwasanEnabled failed") + .addCause("%s") + .addSolution("Please set the correct values for the parameters.") + .build(); + /** + * INSTALL_FREE_FAILED + */ + public static final ErrorMsg INSTALL_FREE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("001") + .addDescription("installationFree failed") + .addCause("%s") + .addSolution("") + .build(); + + /** + * ATOMIC_INSTALLATION_FREE_FAILED + */ + public static final ErrorMsg ATOMIC_INSTALLATION_FREE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("002") + .addDescription("file configuration does not match") + .addCause("%s") + .build(); + + //file operator failed + /** + * FILE_NOT_FOUND + */ + public static final ErrorMsg FILE_NOT_FOUND = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("14") + .addErrCode("001") + .addDescription("File not found exception.") + .addCause("%s") + .build(); + + /** + * FILE_DELETE_FAILED + */ + public static final ErrorMsg FILE_DELETE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("14") + .addErrCode("002") + .addDescription("File delete failed.") + .addCause("%s") + .build(); + + + // compress process error + /** + * COMPRESS_PROCESS_EXCEPTION + */ + public static final ErrorMsg COMPRESS_PROCESS_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") + .addErrCode("001") + .addDescription("Process compress exception.") + .addCause("%s") + .addSolution("Please check the related error message and modify. If the issue persists, review the logs for more details.") + .build(); + + /** + * INVALID_HAP_FILE + */ + public static final ErrorMsg INVALID_HAP_FILE = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("001") + .addDescription("Invaild hap or hsp file.") + .addCause("%s") + .build(); + + /** + * READ_STAGE_HAP_VERIFY_INFO_FAILED + */ + public static final ErrorMsg READ_STAGE_HAP_VERIFY_INFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("20") + .addErrCode("001") + .addDescription("Read stage hap verify info io exception.") + .addCause("%s") + .build(); + + /** + * READ_FA_HAP_VERIFY_INFO_FAILED + */ + public static final ErrorMsg READ_FA_HAP_VERIFY_INFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("20") + .addErrCode("002") + .addDescription("Read FA hap verify info io exception.") + .addCause("%s") + .build(); + + /** + * PARSE_COMPRESS_NATIVE_LIBS_FAILED + */ + public static final ErrorMsg PARSE_COMPRESS_NATIVE_LIBS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("007") + .addDescription("Failed to parse compress native libs.") + .addCause("%s") + .build(); + + /** + * PARSE_DEVICE_TYPE_FAILED + */ + public static final ErrorMsg PARSE_DEVICE_TYPE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("009") + .addDescription("parse DeviceType io exception.") + .addCause("%s") + .build(); + + /** + * CHECK_BUNDLETYPE_INVALID + */ + public static final ErrorMsg CHECK_BUNDLETYPE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("003") + .addDescription("Check bundleType is invalid") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_MODULE_TYPE + */ + public static final ErrorMsg CHECK_MODULE_TYPE = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("26") + .addErrCode("001") + .addDescription("moduleType does not match") + .addCause("%s") + .build(); + + /** + * CHECK_OVERLAYCF_PERMISSIONS_FAILED + */ + public static final ErrorMsg CHECK_OVERLAYCF_PERMISSIONS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("27") + .addErrCode("001") + .addDescription("Permissions failed") + .addCause("%s") + .build(); + + /** + * CHECK_OVERLAYCF_MODULE_FAILED + */ + public static final ErrorMsg CHECK_OVERLAYCF_MODULE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("27") + .addErrCode("002") + .addDescription("The names cannot be the same") + .addCause("%s") + .build(); + + /** + * CHECK_OVERLAYCF_TARGETMODULENAME_FAILED + */ + public static final ErrorMsg CHECK_OVERLAYCF_TARGETMODULENAME_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("27") + .addErrCode("003") + .addDescription("Check targetModuleName,targetPriority failed") + .addCause("%s") + .build(); + + /** + * CHECK_TARGETMODULENAME_ISEMPTY_FAILED + */ + public static final ErrorMsg CHECK_TARGETMODULENAME_ISEMPTY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("28") + .addErrCode("001") + .addDescription("Check if targetModuleName is empty") + .addCause("%s") + .build(); + + /** + * CHECK_TARGETMODULENAME_EQUALS_FAILED + */ + public static final ErrorMsg CHECK_TARGETMODULENAME_EQUALS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("28") + .addErrCode("002") + .addDescription("Check targetBundleName and bundleName failed") + .addCause("%s") + .addSolution("") + .build(); + + /** + * CHECK_TARGETPRIORITY_FAILED + */ + public static final ErrorMsg CHECK_TARGETPRIORITY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("28") + .addErrCode("003") + .addDescription("check is Existed StageApp targetPriority.") + .addCause("%s") + .addSolution("") + .build(); + + /** + * CHECK_BUNDLENAME + */ + public static final ErrorMsg CHECK_BUNDLENAME = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("28") + .addErrCode("004") + .addDescription("continueBundleName and BundleName cannot be the same") + .addCause("%s") + .addSolution("") + .build(); + + /** + * CHECK_CONTINUE_BUNDLE + */ + public static final ErrorMsg CHECK_CONTINUE_BUNDLE = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("28") + .addErrCode("005") + .addDescription("check ContinueBundleName failed.") + .addCause("%s") + .build(); + + /** + * CHECK_STAGE_HAP + */ + public static final ErrorMsg CHECK_STAGE_HAP = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("29") + .addErrCode("001") + .addDescription("check StageHap failed") + .addCause("%s") + .build(); + + /** + * COMPRESS_HSP + */ + public static final ErrorMsg COMPRESS_HSP = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("29") + .addErrCode("002") + .addDescription("Compress Hsp failed") + .addCause("%s") + .build(); + + /** + * CHECK_STAGE_OVERLAY + */ + public static final ErrorMsg CHECK_STAGE_OVERLAY = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("29") + .addErrCode("003") + .addDescription("check StageOverlayCfg failed") + .addCause("%s") + .build(); + + //packing process error + /** + * COMPRESS_PROCESS + */ + public static final ErrorMsg COMPRESS_PROCESS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("31") + .addErrCode("001") + .addDescription("Execute compress process failed.") + .addCause("%s") + .addSolution("%s") + .build(); + + + /** + * HSP_MODE_ARGS_INVALID + */ + public static final ErrorMsg HSP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("001") + .addDescription("isArgsValidInHspMode invalid") + .addCause("%s") + .build(); + + /** + * HSP_MODE_ABILITIES_FAILED + */ + public static final ErrorMsg HSP_MODE_ABILITIES_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("002") + .addDescription("at least one ability or extensionAbility.") + .addCause("%s") + .build(); + + /** + * HSP_MODE_HSPHIME_FAILED + */ + public static final ErrorMsg HSP_MODE_HSPHIME_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("003") + .addDescription("hsp has home FAILED.") + .addCause("%s") + .build(); + + /** + * HAP_ADD_VERIF_INVALID + */ + public static final ErrorMsg HAP_ADD_VERIF_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("004") + .addDescription("VerifyValidInHapAdditionMode invalid.") + .addCause("%s") + .build(); + + /** + * BUNDLE_TYPE_SHARED_INVALID + */ + public static final ErrorMsg BUNDLE_TYPE_SHARED_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("005") + .addDescription("isBundleTypeShared invalid.") + .addCause("%s") + .build(); + + /** + * BUNDLE_TYPE_APPSERVICE_INVALID + */ + public static final ErrorMsg BUNDLE_TYPE_APPSERVICE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("006") + .addDescription("isBundleTypeAppService invalid.") + .addCause("%s") + .build(); + + /** + * HSP_HAS_ABILITIES_INVALID + */ + public static final ErrorMsg HSP_HAS_ABILITIES_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("007") + .addDescription("hspHasAbilities invalid.") + .addCause("%s") + .build(); + + /** + * HSP_HAS_EXTENSION_INVALID + */ + public static final ErrorMsg HSP_HAS_EXTENSION_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("008") + .addDescription("hspHasExtensionAbilities invalid.") + .addCause("%s") + .build(); + + /** + * HAS_HOME_ABILITY_INVALID + */ + public static final ErrorMsg HAS_HOME_ABILITY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("009") + .addDescription("hasHomeAbility invalid.") + .addCause("%s") + .build(); + + /** + * HAS_HOME_EXTENSION_INVALID + */ + public static final ErrorMsg HAS_HOME_EXTENSION_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("010") + .addDescription("hasHomeExtensionAbility invalid.") + .addCause("%s") + .build(); + + /** + * CHECK_JSON_INVALID + */ + public static final ErrorMsg CHECK_JSON_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("011") + .addDescription("CheckJsonIsValid invalid.") + .addCause("%s") + .build(); + + /** + * DIRECTORY_INVALID + */ + public static final ErrorMsg DIRECTORY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("012") + .addDescription("directory is not exist.") + .addCause("%s") + .build(); + + /** + * HAR_MODE_ARGS_INVALID + */ + public static final ErrorMsg HAR_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("013") + .addDescription("isArgsValidInHarMode invalid.") + .addCause("%s") + .build(); + + /** + * HAP_MODE_ARGS_INVALID + */ + public static final ErrorMsg HAP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("014") + .addDescription("isArgsValidInHapMode invalid.") + .addCause("%s") + .build(); + + /** + * HAP_COMMON_ARGS_INVALID + */ + public static final ErrorMsg HAP_COMMON_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("015") + .addDescription("isArgsValidInHarMode invalid.") + .addCause("%s") + .build(); + + /** + * PACKINFO_PATH_FAILED + */ + public static final ErrorMsg PACKINFO_PATH_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("016") + .addDescription("isArgsValidInHapMode failed.") + .addCause("%s") + .build(); + + /** + * RPCID_PATH_FAILED + */ + public static final ErrorMsg RPCID_PATH_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("017") + .addDescription("isArgsValidInHapMode failed.") + .addCause("%s") + .build(); + + /** + * MERGE_TWO_PACKINFO_FAILED + */ + public static final ErrorMsg MERGE_TWO_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("001") + .addDescription("mergeTwoPackInfo failed.") + .addCause("%s") + .build(); + + /** + * VERIFY_PACKINFO_FAILED + */ + public static final ErrorMsg VERIFY_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("002") + .addDescription("verifyPackInfo failed.") + .addCause("%s") + .build(); + + /** + * APP_INPACKINFO_FAILED + */ + public static final ErrorMsg APP_INPACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("003") + .addDescription("verifyAppInPackInfo failed.") + .addCause("%s") + .build(); + + /** + * BUNDLE_TYPE_PACKINFO_INVALID + */ + public static final ErrorMsg BUNDLE_TYPE_PACKINFO_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("004") + .addDescription("bundleType invalid.") + .addCause("%s") + .build(); + + /** + * PARSE_PACKINFO_FORMSNAME_FAILED + */ + public static final ErrorMsg PARSE_PACKINFO_FORMSNAME_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("005") + .addDescription("parsePackInfoFormsName error") + .addCause("%s") + .build(); + + /** + * PARSE_DISTOR_MODULENAME_FAILED + */ + public static final ErrorMsg PARSE_DISTOR_MODULENAME_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("006") + .addDescription("parseFaModuleName failed") + .addCause("%s") + .build(); + + /** + * MERGE_PACKINFO_OBJ_INVALID + */ + public static final ErrorMsg MERGE_PACKINFO_OBJ_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("007") + .addDescription("mergePackInfoObj invalid") + .addCause("%s") + .build(); + + /** + * MERGE_BYPACKAGE_PAIR_FAILED + */ + public static final ErrorMsg MERGE_BYPACKAGE_PAIR_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("008") + .addDescription("packinfo failed") + .addCause("%s") + .build(); + + /** + * MERGE_OBJBY_PACKAGE_PAIR_FAILED + */ + public static final ErrorMsg MERGE_OBJBY_PACKAGE_PAIR_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("009") + .addDescription("mergeTwoPackInfoObjByPackagePair failed") + .addCause("%s") + .build(); + + /** + * PARSE_JSONOBJECT_FAILED + */ + public static final ErrorMsg PARSE_JSONOBJECT_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("010") + .addDescription("parse JOSNObject failed") + .addCause("%s") + .build(); + + /** + * PARSE_PACKINFO_FORMS_FAILED + */ + public static final ErrorMsg PARSE_PACKINFO_FORMS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("011") + .addDescription("parsePackInfoForms exception") + .addCause("%s") + .build(); + +} -- Gitee