From f0c718dc26a9b6e59a2b6f7f41cd415b809fbf50 Mon Sep 17 00:00:00 2001 From: nj1868 Date: Fri, 28 Feb 2025 18:44:25 +0800 Subject: [PATCH 1/2] normalize errcode Signed-off-by: nj1868 Change-Id: I6a505a57cc578ba9d1223ae90aa355240d5e4b2f --- adapter/ohos/CommandParser.java | 8 +- adapter/ohos/CompressEntrance.java | 8 +- adapter/ohos/CompressVerify.java | 215 ++++--- adapter/ohos/Compressor.java | 303 +++++---- adapter/ohos/ErrorMsg.java | 193 ++++++ adapter/ohos/FileUtils.java | 13 +- adapter/ohos/HapVerify.java | 413 ++++++++----- adapter/ohos/ModuleJsonUtil.java | 180 +++--- adapter/ohos/PackingToolErrMsg.java | 919 ++++++++++++++++++++++++++++ adapter/ohos/Utility.java | 3 +- build.py | 12 +- 11 files changed, 1824 insertions(+), 443 deletions(-) create mode 100644 adapter/ohos/ErrorMsg.java create mode 100644 adapter/ohos/PackingToolErrMsg.java diff --git a/adapter/ohos/CommandParser.java b/adapter/ohos/CommandParser.java index 8b046304..e04c0c3b 100644 --- a/adapter/ohos/CommandParser.java +++ b/adapter/ohos/CommandParser.java @@ -362,14 +362,14 @@ public class CommandParser { try { int compressLevel = Integer.parseInt(level); if (compressLevel < 1 || compressLevel > 9) { - LOG.error("CommandParser::--compress-level value must be 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("CommandParser::--compress-level value must be number between 1-9"); + LOG.error(PackingToolErrMsg.COMMAND_PARSER_FAILED.toString("compress-level value not number between 1-9.")); return false; } }); @@ -393,7 +393,7 @@ public class CommandParser { */ public static boolean commandParser(Utility utility, String[] args) { if (args == null) { - LOG.error("CommandParser::commandParser args is null!"); + LOG.error(PackingToolErrMsg.COMMAND_PARSER_FAILED.toString("Parser args is null.")); return false; } for (int i = 0; i < args.length - 1; ++i) { @@ -405,7 +405,7 @@ public class CommandParser { ++i; } else if (CMD_PARSE_MODE.equals(key)) { if (i + PARSE_MODE_VALUE_LENGTH >= args.length) { - LOG.error("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/CompressEntrance.java b/adapter/ohos/CompressEntrance.java index dc3151de..2f2dfa12 100644 --- a/adapter/ohos/CompressEntrance.java +++ b/adapter/ohos/CompressEntrance.java @@ -97,20 +97,20 @@ public class CompressEntrance { Utility utility = new Utility(); if (!CommandParser.commandParser(utility, args)) { - LOG.error("CompressEntrance::main exit, parser failed"); + LOG.error(PackingToolErrMsg.EXECUTE_PACKING_TOOL_FAILED.toString("Command parser failed.")); ShowHelp.compressHelp(); System.exit(EXIT_STATUS_EXCEPTION); } if (!CompressVerify.commandVerify(utility)) { - LOG.error("CompressEntrance::main exit, verify failed"); + LOG.error(PackingToolErrMsg.EXECUTE_PACKING_TOOL_FAILED.toString("Command verify failed.")); ShowHelp.compressHelp(); System.exit(EXIT_STATUS_EXCEPTION); } Compressor compressor = new Compressor(); if (!compressor.compressProcess(utility)) { - LOG.error("CompressEntrance::main exit, compress failed"); + LOG.error(PackingToolErrMsg.EXECUTE_PACKING_TOOL_FAILED.toString("Compress failed.")); ShowHelp.compressHelp(); System.exit(EXIT_STATUS_EXCEPTION); } @@ -118,7 +118,7 @@ public class CompressEntrance { if (utility.getGenerateBuildHash()) { utility.setForceRewrite("true"); if (!compressor.compressProcess(utility)) { - LOG.error("CompressEntrance::main exit, compress failed"); + LOG.error(PackingToolErrMsg.EXECUTE_PACKING_TOOL_FAILED.toString("Compress failed.")); ShowHelp.compressHelp(); System.exit(EXIT_STATUS_EXCEPTION); } diff --git a/adapter/ohos/CompressVerify.java b/adapter/ohos/CompressVerify.java index 162a283b..c0a1bb58 100644 --- a/adapter/ohos/CompressVerify.java +++ b/adapter/ohos/CompressVerify.java @@ -91,13 +91,14 @@ public class CompressVerify { */ public static boolean commandVerify(Utility utility) { if (utility == null) { - LOG.error("CompressVerify::commandVerify utility is null."); + LOG.error(PackingToolErrMsg.COMMAND_VERIFY_FAILED.toString("Command verify utility is null.")); return false; } if (!utility.getForceRewrite().isEmpty() && !"true".equals(utility.getForceRewrite()) && !"false".equals(utility.getForceRewrite())) { - LOG.error("CompressVerify::commandVerify forceRewrite is invalid."); + LOG.error(PackingToolErrMsg.COMMAND_VERIFY_FAILED.toString( + "If the --force parameter is configured, the value must be either 'true' or 'false'.")); return false; } return commandPathVerify(utility); @@ -140,7 +141,7 @@ public class CompressVerify { case Utility.PACKAGE_NORMALIZE: return validatePackageNormalizeMode(utility); default: - LOG.error("CompressVerify::commandVerify mode is invalid."); + LOG.error(PackingToolErrMsg.COMMAND_MODE_INVALID.toString()); return false; } } @@ -235,11 +236,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 = "--rpcid-path is not a file."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!RPCID_PROFILE.equals(file.getName())) { - LOG.error("CompressVerify::isArgsValidInHapMode rpcid-path must be rpcid.sc file."); + String errMsg = "--rpcid-path must be rpcid.sc file."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } @@ -250,11 +253,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 = "--pack-info-path is not a file."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!PACK_INFO.equals(file.getName())) { - LOG.error("CompressVerify::isArgsValidInHapMode --pack-info-path must be pack.info file."); + String errMsg = "--pack-info-path must be pack.info file."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } @@ -263,12 +268,14 @@ public class CompressVerify { private static boolean isVerifyValidInHapCommonMode(Utility utility) { if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::commandPathVerify json-path is empty."); + String errMsg = "--json-path is empty"; + LOG.error(PackingToolErrMsg.HAP_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 file."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -278,39 +285,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 = "--shell-apk-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_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 = "--profile-path must be CAPABILITY.profile file."; + LOG.error(PackingToolErrMsg.HAP_MODE_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 = "--dex-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_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 = "--abc-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_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 = "--dir-list is invalid."; + LOG.error(PackingToolErrMsg.HAP_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::isArgsValidInHapMode --pkg-context-path file must be " + PKG_CONTEXT_INFO); + String errMsg = "--pkg-context-path file must be " + PKG_CONTEXT_INFO + "."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } @@ -326,76 +339,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 = "--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 = "--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 = "--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 = "--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 = "--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 = "--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 = "--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 = "--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 = "--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 = "--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 = "--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 = "--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 = "--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 = "--ets-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -473,7 +500,8 @@ public class CompressVerify { */ private static boolean isVerifyValidInAppMode(Utility utility) { if (!checkBundleTypeConsistency(utility)) { - LOG.error("CompressVerify::isArgsValidInAppMode bundleType is inconsistent."); + String errMsg = "Check bundleType is inconsistent."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -483,50 +511,59 @@ public class CompressVerify { if (!utility.getHapPath().isEmpty() && !compatibleProcess(utility, utility.getHapPath(), utility.getFormattedHapPathList(), HAP_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInAppMode hap-path is invalid."); + String errMsg = "--hap-path is invalid."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getHspPath().isEmpty() && !compatibleProcess(utility, utility.getHspPath(), utility.getFormattedHspPathList(), HSP_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInAppMode hsp-path is invalid."); + String errMsg = "--hsp-path is invalid."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getPackInfoPath().isEmpty()) { - LOG.error("CompressVerify::isArgsValidInAppMode pack-info-path is empty."); + String errMsg = "--pack-info-path is empty."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } File file = new File(utility.getPackInfoPath()); if (!file.isFile() || !PACK_INFO.equals(file.getName())) { - LOG.error("CompressVerify::isArgsValidInAppMode pack-info-path is invalid."); + String errMsg = "--pack-info-path is invalid."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!isValidEncryptJsonFile(utility)) { - LOG.error("CompressVerify::isVerifyValidInAppMode encrypt-path is invalid."); + String errMsg = "--encrypt-path is invalid."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getSignaturePath().isEmpty() && !(new File(utility.getSignaturePath())).isFile()) { - LOG.error("CompressVerify::isArgsValidInAppMode signature-path is invalid."); + String errMsg = "--signature-path is invalid."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getCertificatePath().isEmpty() && !(new File(utility.getCertificatePath())).isFile()) { - LOG.error("CompressVerify::isArgsValidInAppMode certificate-path is invalid."); + String errMsg = "--certificate-path is invalid."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getEntryCardPath().isEmpty() && !compatibleProcess(utility, utility.getEntryCardPath(), utility.getformattedEntryCardPathList(), PNG_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInAppMode entrycard-path is invalid."); + String errMsg = "--entrycard-path is invalid."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getPackResPath().isEmpty() && !isPathValid(utility.getPackResPath(), TYPE_FILE, PACK_RES)) { - LOG.error("CompressVerify::isArgsValidInAppMode pack-res-path is invalid."); + String errMsg = "--pack-res-path is invalid."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -543,21 +580,23 @@ public class CompressVerify { if (!tmpHapPathList.isEmpty()) { HapVerifyInfo hapVerifyInfo = Compressor.parseStageHapVerifyInfo(tmpHapPathList.get(0)); bundleType = hapVerifyInfo.getBundleType(); - } else { + } else if (!tmpHspPathList.isEmpty()) { HapVerifyInfo hapVerifyInfo = Compressor.parseStageHapVerifyInfo(tmpHspPathList.get(0)); bundleType = hapVerifyInfo.getBundleType(); } for (String hapPath : tmpHapPathList) { HapVerifyInfo hapVerifyInfo = Compressor.parseStageHapVerifyInfo(hapPath); if (!bundleType.equals(hapVerifyInfo.getBundleType())) { - LOG.error("bundleType is not same"); + LOG.error(PackingToolErrMsg.CHECK_BUNDLETYPE_CONSISTENCY_FAILED.toString( + "bundleType is not same for different hap modules.")); return false; } } for (String hspPath : tmpHspPathList) { HapVerifyInfo hapVerifyInfo = Compressor.parseStageHapVerifyInfo(hspPath); if (!bundleType.equals(hapVerifyInfo.getBundleType())) { - LOG.error("bundleType is not same"); + LOG.error(PackingToolErrMsg.CHECK_BUNDLETYPE_CONSISTENCY_FAILED.toString( + "bundleType is not same for different hsp modules.")); return false; } } @@ -806,13 +845,13 @@ public class CompressVerify { File outFile = new File(utility.getOutPath()); if (("false".equals(utility.getForceRewrite())) && (outFile.exists())) { - LOG.error("CompressVerify::isOutPathValid out file already existed."); + LOG.error(PackingToolErrMsg.OUT_PATH_INVALID.toString("--out-path file already existed.")); return false; } if (HAP_SUFFIX.equals(suffix)) { if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(HAP_SUFFIX)) { - LOG.error("CompressVerify::isOutPathValid out-path must end with .hap."); + LOG.error(PackingToolErrMsg.OUT_PATH_INVALID.toString("--out-path must end with .hap.")); return false; } else { return true; @@ -821,7 +860,7 @@ public class CompressVerify { if (HAR_SUFFIX.equals(suffix)) { if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(HAR_SUFFIX)) { - LOG.error("CompressVerify::isOutPathValid out-path must end with .har."); + LOG.error(PackingToolErrMsg.OUT_PATH_INVALID.toString("--out-path must end with .har.")); return false; } else { return true; @@ -830,7 +869,7 @@ public class CompressVerify { if (APP_SUFFIX.equals(suffix)) { if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(APP_SUFFIX)) { - LOG.error("CompressVerify::isOutPathValid out-path must end with .app."); + LOG.error(PackingToolErrMsg.OUT_PATH_INVALID.toString("--out-path must end with .app.")); return false; } else { return true; @@ -839,7 +878,7 @@ public class CompressVerify { if (RES_SUFFIX.equals(suffix)) { if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(RES_SUFFIX)) { - LOG.error("CompressVerify::isOutPathValid out-path must end with .res."); + LOG.error(PackingToolErrMsg.OUT_PATH_INVALID.toString("--out-path must end with .res.")); return false; } else { return true; @@ -848,7 +887,7 @@ public class CompressVerify { if (HSP_SUFFIX.equals(suffix)) { if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(HSP_SUFFIX)) { - LOG.error("CompressVerify::isOutPathValid out-path must end with .hsp."); + LOG.error(PackingToolErrMsg.OUT_PATH_INVALID.toString("--out-path must end with .hsp.")); return false; } else { return true; @@ -914,12 +953,14 @@ public class CompressVerify { private static boolean isVerifyValidInHspMode(Utility utility) { if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::isArgsValidInHspMode json-path is empty."); + String errMsg = "--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 = "--json-path must be module.json file."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -927,87 +968,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_ARGS_INVALID.toString(errMsg)); return false; } if (hspHasAbilities) { - LOG.error("shared/appService hsp has abilities"); + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString("shared/appService hsp has abilities.")); return false; } if (hspHasExtensionAbilities) { - LOG.error("shared/appService hsp has extensionAbilities"); + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString("shared/appService hsp has extensionAbilities.")); return false; } } if(hasHomeAbility(utility)) { - LOG.error("hsp has entry ability"); + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString("hsp has entry ability.")); return false; } if (hasHomeExtensionAbility(utility)) { - LOG.error("hsp has entry extensionAbility"); + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString("hsp has entry 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 = "--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 = "--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 = "--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 = "--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 = "--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 = "--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 = "--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 = "--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 = "--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 = "--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 = "--ets-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -1154,11 +1207,12 @@ 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 = "Parse --json-path content failed."; + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_SHARED_INVALID.toString(errMsg)); return false; } } catch (BundleException e) { - LOG.error("CompressVerify::isBundleTypeShared exception: " + e.getMessage()); + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_SHARED_INVALID.toString("BundleException: " + e.getMessage())); return false; } } @@ -1169,11 +1223,12 @@ 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 = "Parse --json-path content failed."; + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_APPSERVICE_INVALID.toString(errMsg)); return false; } } catch (BundleException e) { - LOG.error("CompressVerify::isBundleTypeAppService exception: " + e.getMessage()); + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_APPSERVICE_INVALID.toString("BundleException: " + e.getMessage())); return false; } } @@ -1184,11 +1239,12 @@ 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 = "Parse --json-path content failed."; + LOG.error(PackingToolErrMsg.HSP_HAS_ABILITIES_FAILED.toString(errMsg)); return false; } } catch (BundleException e) { - LOG.error("CompressVerify::hspHasAbilities exception: " + e.getMessage()); + LOG.error(PackingToolErrMsg.HSP_HAS_ABILITIES_FAILED.toString("BundleException: " + e.getMessage())); return false; } } @@ -1200,10 +1256,11 @@ 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 = "Parse --json-path content failed."; + LOG.error(PackingToolErrMsg.HSP_HAS_EXTENSION_ABILITIES_FAILED.toString(errMsg)); } } catch (BundleException e) { - LOG.error("CompressVerify::hspHasExtensionAbilities exception: " + e.getMessage()); + LOG.error(PackingToolErrMsg.HSP_HAS_EXTENSION_ABILITIES_FAILED.toString("BundleException: " + e.getMessage())); } return false; } @@ -1213,7 +1270,8 @@ public class CompressVerify { boolean result = false; Optional optional = FileUtils.getFileContent(utility.getJsonPath()); if(!optional.isPresent()) { - LOG.error("CompressVerify::hasHomeAbility jsonPath content invalid"); + String errMsg = "Parse --json-path content failed."; + LOG.error(PackingToolErrMsg.HAS_HOME_ABILITY_INVALID.toString(errMsg)); return false; } Map abilitiesMap = ModuleJsonUtil.parseAbilitySkillsMap(optional.get()); @@ -1223,7 +1281,7 @@ public class CompressVerify { LOG.info("CompressVerify::hasHomeAbilities result = " + result); return result; } catch (BundleException e) { - LOG.error("CompressVerify::hasHomeAbilities exception: " + e.getMessage()); + LOG.error(PackingToolErrMsg.HAS_HOME_ABILITY_INVALID.toString("BundleException: " + e.getMessage())); return false; } } @@ -1249,7 +1307,8 @@ public class CompressVerify { boolean result = false; Optional optional = FileUtils.getFileContent(utility.getJsonPath()); if (!optional.isPresent()) { - LOG.error("CompressVerify::hasHomeExtensionAbility jsonPath content invalid"); + String errMsg = "Parse --json-path content failed."; + LOG.error(PackingToolErrMsg.HAS_HOME_EXTENSION_ABILITY_INVALID.toString(errMsg)); return false; } Map extensionAbilitiesMap = ModuleJsonUtil.parseExtensionAbilitySkillsMap(optional.get()); @@ -1259,7 +1318,7 @@ public class CompressVerify { LOG.info("CompressVerify::hasHomeExtensionAbility result = " + result); return result; } catch (BundleException e) { - LOG.error("CompressVerify::hasHomeExtensionAbility exception: " + 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 33461812..068db3df 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 the --out-path parameter."; + 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("Compress exist FileNotFoundException: " + exception.getMessage())); } catch (BundleException ex) { compressResult = false; - LOG.error("Compressor::compressProcess Bundle exception: " + ex.getMessage()); + LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_EXCEPTION.toString("BundleException: " + 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 = + "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)); } // if compress failed, delete out file. if (!compressResult) { - LOG.error("Compressor::compressProcess compress failed."); + String errMsg = "Execute compress failed."; + String solution = "Please check the first error message for more details and modify accordingly."; + LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_FAILED.toString(errMsg, solution)); if (!destFile.delete()) { - LOG.error("Compressor::compressProcess delete dest file failed."); + errMsg = "Delete out file " + utility.getOutPath() + " failed."; + solution = "Try to close the out file using programme."; + LOG.error(PackingToolErrMsg.FILE_DELETE_FAILED.toString(errMsg, solution)); } } return compressResult; @@ -426,34 +434,34 @@ 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.COMPRESS_HSP_FAILED.toString("Check Stage AsanTsanEnabled valid failed.")); + throw new BundleException("Compress hsp failed."); } if (!checkStageHwasanEnabledValid(jsonString)) { - LOG.error("checkStageHwasanEnabledValid failed."); - throw new BundleException("compressHsp failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Check Stage HwasanEnabled valid failed.")); + throw new BundleException("Compress hsp failed."); } if (!checkStageUbsanEnabledValid(jsonString)) { - LOG.error("checkStageUbsanEnabledValid failed."); - throw new BundleException("compressHsp failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Check Stage UbsanEnabled valid failed.")); + throw new BundleException("Compress hsp failed."); } if (!checkStageAtomicService(jsonString)) { - LOG.error("checkStageAtomicService failed."); - throw new BundleException("checkStageAtomicService failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Check Stage AtomicService failed.")); + throw new BundleException("Check stage AtomicService failed."); } // check continueBundleName in module.json if (!checkContinueBundleNameIsValid(jsonString)) { - LOG.error("checkContinueBundleNameIsValid failed."); - throw new BundleException("compressHsp failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Check ContinueBundleName is valid failed.")); + throw new BundleException("Compress hsp failed."); } // check whether is an overlay hsp or not if (!checkStageOverlayCfg(jsonString)) { - LOG.error("checkStageOverlayCfg failed."); - throw new BundleException("checkStageOverlayCfg failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Check Stage overlay config failed.")); + throw new BundleException("Check stage OverlayCfg failed."); } String moduleType = ModuleJsonUtil.parseModuleType(jsonString); if (!TYPE_SHARED.equals(moduleType)) { - LOG.error("module type must be shared."); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Module type must be shared.")); throw new BundleException("compressHsp failed."); } } @@ -470,8 +478,8 @@ public class Compressor { setGenerateBuildHash(utility); if (isModuleJSON(utility.getJsonPath())) { if (!checkStageHap(utility)) { - LOG.error("checkStageHap failed."); - throw new BundleException("checkStageHap 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()); String jsonString = optional.get(); @@ -494,8 +502,9 @@ public class Compressor { private static boolean hasGenerateBuildHash(Utility utility) throws BundleException { File file = new File(utility.getJsonPath()); if (!file.exists()) { - LOG.error("Compressor::hasGenerateBuildHash failed for json file not exist"); - throw new BundleException("Compressor::hasGenerateBuildHash failed for json file not exist"); + String errMsg = "The --json-path file does not exist."; + LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString(errMsg)); + throw new BundleException("Verify has generate build hash failed for --json-path file does not exist."); } InputStream json = null; boolean res = false; @@ -503,8 +512,8 @@ public class Compressor { json = new FileInputStream(file); JSONObject jsonObject = JSON.parseObject(json, JSONObject.class); if (jsonObject == null || !jsonObject.containsKey(APP) || !jsonObject.containsKey(MODULE)) { - LOG.error("json file is invalid."); - throw new BundleException("json file is invalid."); + LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString("The --json-path file is invalid.")); + throw new BundleException("Parse --json-path file is invalid."); } JSONObject appJson = jsonObject.getJSONObject(APP); JSONObject moduleJson = jsonObject.getJSONObject(MODULE); @@ -512,11 +521,12 @@ public class Compressor { res = true; } } catch (BundleException exception) { - LOG.error("Compressor::hasGenerateBuildHash failed."); - throw new BundleException("Compressor::hasGenerateBuildHash failed."); + LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString("Check has generate build hash exist BundleException: " + exception.getMessage())); + throw new BundleException("Verify has generate build hash failed."); } catch (JSONException | IOException e) { - LOG.error("Compressor::hasGenerateBuildHash failed for json file is invalid." + e.getMessage()); - throw new BundleException("Compressor::hasGenerateBuildHash failed."); + LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString( + "Check has generate build hash exist Exception(JSONException | IOException): " + e.getMessage())); + throw new BundleException("Verify has generate build hash failed."); } finally { FileUtils.closeStream(json); } @@ -531,8 +541,9 @@ public class Compressor { copyFileToTempDir(utility); File file = new File(utility.getJsonPath()); if (!file.exists()) { - LOG.error("Compressor::setGenerateBuildHash failed for json file not exist"); - throw new BundleException("Compressor::setGenerateBuildHash failed for json file not exist"); + String errMsg = "Parse --json-path file does not exist."; + LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString(errMsg)); + throw new BundleException("Set generate build hash failed for --json-path file does not exist."); } InputStream json = null; BufferedWriter bw = null; @@ -540,7 +551,7 @@ public class Compressor { json = new FileInputStream(file); JSONObject jsonObject = JSON.parseObject(json, JSONObject.class); if (!jsonObject.containsKey(APP) || !jsonObject.containsKey(MODULE)) { - LOG.error("json file is invalid."); + LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString("Parse --json-path file is invalid.")); throw new BundleException("json file is invalid."); } JSONObject appJson = jsonObject.getJSONObject(APP); @@ -561,11 +572,12 @@ public class Compressor { new FileOutputStream(utility.getJsonPath()), StandardCharsets.UTF_8)); bw.write(pretty); } catch (BundleException exception) { - LOG.error("Compressor::setGenerateBuildHash failed."); + 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("Compressor::setGenerateBuildHash failed, json data err: " + e.getMessage()); - throw new BundleException("Compressor::setGenerateBuildHash failed, json data err."); + LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString( + "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); if (bw != null) { @@ -573,8 +585,9 @@ public class Compressor { bw.flush(); bw.close(); } catch (IOException e) { - LOG.error("Compressor::setGenerateBuildHash failed for IOException " + e.getMessage()); - throw new BundleException("Compressor::setGenerateBuildHash failed."); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "Set generate build hash exist IOException: " + e.getMessage())); + throw new BundleException("Set generate build hash failed."); } } } @@ -584,8 +597,9 @@ public class Compressor { String jsonPath = utility.getJsonPath(); File oldfile = new File(jsonPath); if (!oldfile.exists()) { - LOG.error("Compressor::copyFileToTempDir failed for json file not found."); - throw new BundleException("Compressor::copyFileToTempDir failed for json file not found."); + String errMsg = "Parse json file not found, parse json path is " + jsonPath + "."; + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString(errMsg)); + throw new BundleException("Copy file to temp dir failed for json file not found."); } String oldFileParent = oldfile.getParent(); String tempDir = TEMP_DIR + File.separator + UUID.randomUUID(); @@ -607,8 +621,9 @@ public class Compressor { } utility.setJsonPath(tempPath); } catch (IOException e) { - LOG.error("Compressor::copyFileToTempDir failed, IOException: " + e.getMessage()); - throw new BundleException("Compressor::copyFileToTempDir failed."); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "copy file to temp dir exist IOException:" + e.getMessage())); + throw new BundleException("Copy file to temp dir failed."); } } @@ -628,8 +643,8 @@ public class Compressor { try { putBuildHash(utility, hash); } catch (IOException e) { - LOG.error("Compressor::putBuildHash failed, " + e.getMessage()); - throw new BundleException("Compressor::putBuildHash failed."); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Build hash exist IOException: " + e.getMessage())); + throw new BundleException("Put build hash failed."); } } @@ -673,8 +688,9 @@ public class Compressor { String jsonPath = utility.getJsonPath(); File file = new File(jsonPath); if (!file.exists()) { - LOG.error("Compressor::putBuildHash failed for json file not exist"); - throw new BundleException("Compressor::putBuildHash failed for json file not exist"); + String errMsg = "Parse json file not found, parse json path is " + jsonPath + "."; + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString(errMsg)); + throw new BundleException("Put build hash failed for json file not exist."); } InputStream json = null; BufferedWriter bw = null; @@ -688,11 +704,11 @@ public class Compressor { bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(jsonPath), StandardCharsets.UTF_8)); bw.write(pretty); } catch (IOException e) { - LOG.error("Compressor::putBuildHash failed, IOException: " + e.getMessage()); - throw new BundleException("Compressor::putBuildHash failed."); + 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("Compressor::putBuildHash failed, json data err: " + e.getMessage()); - throw new BundleException("Compressor::putBuildHash failed, json data err."); + LOG.error(PackingToolErrMsg.NULL_POINTER_EXPECTION.toString("json data err, exist NullPointerException: " + e.getMessage())); + throw new BundleException("Put build hash failed, json data err."); } finally { FileUtils.closeStream(json); if (bw != null) { @@ -722,7 +738,8 @@ public class Compressor { } if (hapVerifyInfos.isEmpty()) { - LOG.error("Compressor::checkAppAtomicServiceCompressedSizeValid no hapVerifyInfo."); + LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString( + "No avaiable hap verify info.")); return false; } @@ -737,10 +754,10 @@ public class Compressor { return HapVerify.checkFileSizeIsValid(hapVerifyInfos); } catch (IOException exception) { - LOG.error("Compressor::checkAppAtomicServiceCompressedSizeValid file not found exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString("IOException: " + exception.getMessage())); return false; } catch (BundleException ignored) { - LOG.error("Compressor::checkAppAtomicServiceCompressedSizeValid Bundle exception."); + LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString("BundleException: " + ignored.getMessage())); return false; } } @@ -749,25 +766,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_HAP_FAILED.toString("Check Stage AsanTsanEnabled valid failed.")); return false; } if (!checkStageHwasanEnabledValid(jsonString)) { - LOG.error("checkStageHwasanEnabledValid failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("Check Stage HwasanEnabled valid failed.")); return false; } if (!checkStageUbsanEnabledValid(jsonString)) { - LOG.error("checkStageUbsanEnabledValid failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("Check Stage UbsanEnabled valid failed.")); return false; } // check atomicService in module.json if (!checkStageAtomicService(jsonString)) { - LOG.error("checkStageAtomicService failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("Check Stage atomicService failed.")); return false; } // check continueBundleName in module.json if (!checkContinueBundleNameIsValid(jsonString)) { - LOG.error("checkContinueBundleNameIsValid failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("Check ContinueBundleName valid failed.")); return false; } return true; @@ -777,7 +794,8 @@ 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 can not be true at the same time.")); return false; } return true; @@ -789,15 +807,18 @@ 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_HWASAN_ENABLED_INVALID.toString( + "hwasanEnabled and asanEnabled can not 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_HWASAN_ENABLED_INVALID.toString( + "hwasanEnabled and tsanEnabled can not 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_HWASAN_ENABLED_INVALID.toString( + "hwasanEnabled and GWPAsanEnabled can not be true at the same time")); return false; } return true; @@ -806,6 +827,7 @@ public class Compressor { private static boolean checkContinueBundleNameIsValid(String jsonString) throws BundleException { Map> continueBundleNameMap = ModuleJsonUtil.getAbilityContinueBundleNameMap(jsonString); String bundleName = ModuleJsonUtil.parseBundleName(jsonString); + String moduleName = ModuleJsonUtil.parseStageModuleName(jsonString); for (Map.Entry> entry : continueBundleNameMap.entrySet()) { List continueBundleNameList = entry.getValue(); if (continueBundleNameList == null) { @@ -813,7 +835,8 @@ 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_CONTINUE_BUNDLENAME_INVALID.toString( + "Module(" + moduleName + ") continueBundleName include self.")); return false; } } @@ -826,16 +849,19 @@ public class Compressor { boolean tsanEnabled = ModuleJsonUtil.getStageTsanEnabled(jsonString); 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."); + if (ubsanEnabled && asanEnabled) { + LOG.error(PackingToolErrMsg.CHECK_UBASAN_ENABLED_INVALID.toString( + "ubsanEnabled and asanEnabled can not be true at the same time.")); return false; } - if(ubsanEnabled && tsanEnabled) { - LOG.error("ubsanEnabled and tsanEnabled cannot be true at the same time."); + if (ubsanEnabled && tsanEnabled) { + LOG.error(PackingToolErrMsg.CHECK_UBASAN_ENABLED_INVALID.toString( + "ubsanEnabled and tsanEnabled can not be true at the same time.")); return false; } - if(ubsanEnabled && hwasanEnabled) { - LOG.error("ubsanEnabled and hwasanEnabled cannot be true at the same time."); + if (ubsanEnabled && hwasanEnabled) { + LOG.error(PackingToolErrMsg.CHECK_UBASAN_ENABLED_INVALID.toString( + "ubsanEnabled and hwasanEnabled can not be true at the same time.")); return false; } return true; @@ -844,17 +870,19 @@ 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_ATOMIC_SERVICE_FAILED.toString( + "Check consistency of atomicService failed.")); return false; } // check entry module must have ability if (!ModuleJsonUtil.checkEntryInAtomicService(jsonString)) { - LOG.error("checkEntryInAtomicService failed."); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_FAILED.toString("Check atomicService entry module failed.")); return false; } // check installationFree if (!ModuleJsonUtil.checkAtomicServiceInstallationFree(jsonString)) { - LOG.error("check atomic service installationFree failed."); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_FAILED.toString( + "Check atomicService installationFree failed.")); return false; } @@ -864,20 +892,24 @@ public class Compressor { private static boolean checkStageOverlayCfg(String jsonString) throws BundleException { // check module String targetModuleName = ModuleJsonUtil.getStageTargetModuleName(jsonString); + String moduleName = ModuleJsonUtil.parseStageModuleName(jsonString); if (!targetModuleName.isEmpty()) { // check targetModuleName and requestPermission if (ModuleJsonUtil.isExistedStageRequestPermissions(jsonString)) { - LOG.error("targetModuleName cannot be existed with requestPermissions."); + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString( + "The module(" + moduleName + ") targetModuleName and requestPermissions cannot be configured at the same time.")); return false; } // check targetModuleName and name - if (targetModuleName.equals(ModuleJsonUtil.parseStageModuleName(jsonString))) { - LOG.error("targetModuleName cannot be same with name in the overlay module."); + if (targetModuleName.equals(moduleName)) { + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString( + "The targetModuleName of module (" + moduleName + ") cannot be itself.")); return false; } } else { if (ModuleJsonUtil.isExistedStageModuleTargetPriority(jsonString)) { - LOG.error("targetPriority cannot be existed without the targetModuleName in module.json."); + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString( + "The module(" + moduleName + ") targetPriority and targetModuleName cannot be configured at the same time.")); return false; } } @@ -885,16 +917,19 @@ 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_OVERLAY_CFG_FAILED.toString( + "The module(" + moduleName + ") targetModuleName settings 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_OVERLAY_CFG_FAILED.toString( + "The module(" + moduleName + ") targetBundleName can not 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_OVERLAY_CFG_FAILED.toString( + "The module(" + moduleName + ") targetPriority can not be existed without the targetBundleName in app.json.")); return false; } } @@ -1192,8 +1227,9 @@ public class Compressor { compressPackinfoIntoHap(hapPathItem, hapTempPath, utility.getPackInfoPath(), utility.getCompressLevel()); } catch (IOException e) { - LOG.error("Compressor::compressAppMode compress pack.info into hap failed: " + e.getMessage()); - throw new BundleException("Compressor::compressAppMode compress pack.info into hap failed."); + LOG.error(PackingToolErrMsg.COMPRESS_APP_IO_EXCEPTION.toString( + "Compress pack.info into hap exist IOException: " + e.getMessage())); + throw new BundleException("Compress pack.info into hap failed."); } } @@ -1209,16 +1245,14 @@ public class Compressor { compressPackinfoIntoHap(hspPathItem, hspTempPath, utility.getPackInfoPath(), utility.getCompressLevel()); } catch (IOException e) { - LOG.error("Compressor::compressAppMode compress pack.info into hsp failed: " + e.getMessage()); - throw new BundleException("Compressor::compressAppMode compress pack.info into hsp failed."); + LOG.error(PackingToolErrMsg.COMPRESS_APP_IO_EXCEPTION.toString( + "compress pack.info into hsp exist IOException: " + e.getMessage())); + throw new BundleException("Compress pack.info into hsp failed."); } } // check hap is valid if (!checkHapIsValid(fileList, utility.getSharedApp())) { - LOG.error("Compressor::compressFile verify failed, check version, " + - "apiVersion,moduleName,packageName."); - throw new BundleException("Compressor::compressFile verify failed, check version, " + - "apiVersion,moduleName,packageName."); + throw new BundleException("Verify failed when compress app."); } for (String hapPath : fileList) { @@ -1243,11 +1277,12 @@ public class Compressor { } File file = new File(utility.getPackInfoPath()); compressFile(utility, file, NULL_DIR_NAME, false); - //pack encrypt.json file + // pack encrypt.json file packEncryptJsonFile(utility); } catch (BundleException e) { - LOG.error("Compressor::compressAppMode compress failed. msg: " + e.getMessage()); - throw new BundleException("Compressor::compressAppMode compress failed."); + LOG.error(PackingToolErrMsg.COMPRESS_APP_FAILED.toString( + "Compress app file exist BundleException: " + e.getMessage())); + throw new BundleException("Compress app failed."); } finally { // delete temp file for (String path : fileList) { @@ -1813,8 +1848,9 @@ public class Compressor { } append.closeEntry(); } catch (IOException exception) { - LOG.error("Compressor::compressPackinfoIntoHap io exception."); - throw new BundleException("Compressor::compressPackinfoIntoHap io exception."); + LOG.error(PackingToolErrMsg.COMPRESS_FILE_EXCEPTION.toString( + "Compress PackInfo into hap exist IOException: " + exception.getMessage())); + throw new BundleException("Compress PackInfo into hap IOException."); } finally { sourceHapFile.close(); append.close(); @@ -2213,9 +2249,9 @@ public class Compressor { } zipCreator.writeTo(zipOut); } catch (IOException | InterruptedException | ExecutionException e) { - String errMsg = "Compressor::compressNativeLibsParallel exception: " + e.getMessage(); - LOG.error(errMsg); - throw new BundleException(errMsg); + LOG.error(PackingToolErrMsg.COMPRESS_PARALLEL_EXCEPTION.toString( + "Parallel compress exist Exception(IOException | InterruptedException | ExecutionException): " + e.getMessage())); + throw new BundleException("Parallel compress exception. " + e.getMessage()); } } @@ -2237,7 +2273,8 @@ public class Compressor { try { return Files.newInputStream(file.toPath()); } catch (IOException e) { - LOG.error("Compressor::compressNativeLibsParallel exception: " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "Add archive entry exist IOException: " + e.getMessage())); return null; } }; @@ -2385,10 +2422,12 @@ public class Compressor { count = fileInputStream.read(buffer); } } catch (FileNotFoundException ignored) { - LOG.error("Uncompressor::getCrcFromFile file not found exception."); + 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("Uncompressor::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."); } finally { Utility.closeStream(fileInputStream); @@ -2464,10 +2503,11 @@ public class Compressor { count = bufferedInputStream.read(data); } } catch (FileNotFoundException ignored) { - throw new BundleException("CoompressFile failed."); + throw new BundleException("CompressFile failed."); } catch (IOException exception) { - LOG.error("Compressor::compressFile io exception: " + exception.getMessage()); - throw new BundleException("CoompressFile failed."); + LOG.error(PackingToolErrMsg.COMPRESS_FILE_EXCEPTION.toString( + "IOException: " + exception.getMessage())); + throw new BundleException("CompressFile failed."); } finally { Utility.closeStream(bufferedInputStream); Utility.closeStream(fileInputStream); @@ -2498,8 +2538,9 @@ public class Compressor { } } } catch (IOException exception) { - LOG.error("Compressor::isModuleHap io exception: " + exception.getMessage()); - throw new BundleException("Compressor::isModuleHap failed."); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString( + "Check module type exist IOException: " + exception.getMessage())); + throw new BundleException("Check module type for pack app failed."); } finally { Utility.closeStream(zipInput); Utility.closeStream(zin); @@ -2528,10 +2569,12 @@ public class Compressor { count = fileInputStream.read(buffer); } } catch (FileNotFoundException ignored) { - LOG.error("Compressor::getCrcFromFile FileNotFoundException : " + ignored.getMessage()); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString( + "Get Crc32 from file exist FileNotFoundException: " + ignored.getMessage())); throw new BundleException("Get Crc from file failed: " + file.getName()); } catch (IOException exception) { - LOG.error("Compressor::getCrcFromFile io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString( + "Get Crc32 from file exist IOException: " + exception.getMessage())); throw new BundleException("Get Crc from file failed."); } finally { Utility.closeStream(fileInputStream); @@ -2656,7 +2699,7 @@ public class Compressor { zipOut.putArchiveEntry(entry); zipOut.write(trimJson); } catch (Exception exception) { - LOG.error("Compressor::jsonSpecialProcess io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.JSON_SPECIAL_PROCESS_FAILED.toString("Exception: " + exception.getMessage())); LOG.warning("Json format err: " + srcFile.getAbsolutePath()); return false; } finally { @@ -2724,7 +2767,6 @@ public class Compressor { } } - /** * Get name from line string * @@ -2796,7 +2838,8 @@ public class Compressor { } } } catch (IOException exception) { - LOG.error("Compressor::parseCompressNativeLibs io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "Parse compress native libs exist IOException: " + exception.getMessage())); throw new BundleException("Parse compress native libs failed."); } } @@ -2810,21 +2853,24 @@ public class Compressor { zipOut.flush(); } } catch (IOException exception) { - LOG.error("Compressor::closeZipOutputStream flush exception " + exception.getMessage()); + LOG.error(PackingToolErrMsg.CLOSE_ZIP_OUTPUT_STREAM_EXPECTION.toString( + "Close zip output stream flush IOException: " + exception.getMessage())); } try { if (zipOut != null && isEntryOpen) { zipOut.closeArchiveEntry(); } } catch (IOException exception) { - LOG.error("Compressor::closeZipOutputStream close entry io exception " + exception.getMessage()); + LOG.error(PackingToolErrMsg.CLOSE_ZIP_OUTPUT_STREAM_EXPECTION.toString( + "Close entry IOException: " + exception.getMessage())); } try { if (zipOut != null) { zipOut.finish(); } } catch (IOException exception) { - LOG.error("Compressor::closeZipOutputStream finish exception " + exception.getMessage()); + LOG.error(PackingToolErrMsg.CLOSE_ZIP_OUTPUT_STREAM_EXPECTION.toString( + "Close zip output stream flush IOException: " + exception.getMessage())); } } @@ -2853,7 +2899,8 @@ public class Compressor { break; } } catch (IOException exception) { - LOG.error("Compressor::parseDeviceType io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "Parse device type exist IOException: " + exception.getMessage())); throw new BundleException("Parse device type failed."); } } @@ -2870,19 +2917,19 @@ public class Compressor { List hapVerifyInfos = new ArrayList<>(); for (String hapPath : fileLists) { if (hapPath.isEmpty()) { - LOG.error("Compressor::checkHapIsValid input wrong hap file."); - throw new BundleException("Compressor::checkHapIsValid input wrong hap file."); + LOG.error(PackingToolErrMsg.INVALID_HAP_FILE.toString("Input wrong hap or hsp file.")); + throw new BundleException("Check hap and hsp is valid exist that input wrong hap or hsp file."); } File srcFile = new File(hapPath); String fileStr = srcFile.getName(); if (fileStr.isEmpty()) { - LOG.error("Compressor::checkHapIsValid get file name failed."); - throw new BundleException("Compressor::checkHapIsValid get file name failed."); + LOG.error(PackingToolErrMsg.INVALID_HAP_FILE.toString("Get file name failed.")); + throw new BundleException("Check hap and hsp is valid exist that 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."); - throw new BundleException("Compressor::checkHapIsValid input wrong hap file."); + LOG.error(PackingToolErrMsg.INVALID_HAP_FILE.toString("Input wrong hap or hsp file.")); + throw new BundleException("Check hap and hsp is valid exist that input wrong hap or hsp file."); } if (isModuleHap(hapPath)) { hapVerifyInfos.add(parseStageHapVerifyInfo(hapPath)); @@ -2907,8 +2954,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,8 +3035,9 @@ 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."); - throw new BundleException("FileUtil::parseStageHapVerifyInfo file not available."); + LOG.error(PackingToolErrMsg.READ_STAGE_HAP_VERIFY_INFO_FAILED.toString( + "Read Stage hap verify info file exist IOExpection: " + e.getMessage())); + throw new BundleException("Parse stage hap verify info file exist IOExpection."); } finally { Utility.closeStream(zipFile); } @@ -3010,8 +3059,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( + "Read FA hap verify info file exist IOExpection: " + e.getMessage())); + throw new BundleException("Parse FA hap verify info file exist IOExpection."); } finally { Utility.closeStream(zipFile); } @@ -3158,11 +3208,14 @@ public class Compressor { private static boolean checkSharedAppIsValid(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos.isEmpty()) { - LOG.error("no module included"); + String cause = "Hap verify infos is empty."; + LOG.error(PackingToolErrMsg.HAP_VERIFY_INFO_EMPTY.toString(cause)); return false; } if (hapVerifyInfos.size() > SHARED_APP_HSP_LIMIT) { - LOG.error("Shared app only can contain one module"); + String cause = "Shared app only can contain one module."; + String solution = "Please ensure that there is only one module in Shared App."; + LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); return false; } for (HapVerifyInfo hapVerifyInfo : hapVerifyInfos) { diff --git a/adapter/ohos/ErrorMsg.java b/adapter/ohos/ErrorMsg.java new file mode 100644 index 00000000..cb93d8bf --- /dev/null +++ b/adapter/ohos/ErrorMsg.java @@ -0,0 +1,193 @@ +/* + * 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 diff --git a/adapter/ohos/FileUtils.java b/adapter/ohos/FileUtils.java index 3064828d..07025dbc 100644 --- a/adapter/ohos/FileUtils.java +++ b/adapter/ohos/FileUtils.java @@ -155,7 +155,8 @@ class FileUtils { content.append(tempString); } } catch (IOException msg) { - LOG.error("get file content fail, msg is " + msg.getMessage()); + LOG.error(PackingToolErrMsg.GET_FILE_CONTENT_FAILED.toString( + "IOException: " + msg.getMessage())); return Optional.empty(); } finally { closeStream(reader); @@ -176,7 +177,8 @@ class FileUtils { fileStream.close(); } } catch (IOException msg) { - LOG.error("stream close Error, msg is " + msg.getMessage()); + LOG.error(PackingToolErrMsg.CLOSE_STREAM_EXPECTION.toString( + "Close stream exist IOException: " + msg.getMessage())); } } @@ -445,8 +447,8 @@ class FileUtils { } } } catch (IOException e) { - LOG.error("FileUtil::getProfileJson IOException: " + e.getMessage()); - throw new BundleException("FileUtil::getProfileJson failed."); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Get profile json exist IOExpection: " + e.getMessage())); + throw new BundleException("Get ProfileJson failed."); } return resourceMap; } @@ -598,7 +600,8 @@ class FileUtils { if (file.exists() && file.isFile()) { return file.length(); } - LOG.error("input " + filePath + " is not a valid file."); + String errMsg = "input " + filePath + " is not a valid file."; + LOG.error(PackingToolErrMsg.GET_FILE_SIZE_FAILED.toString(errMsg)); return 0; } diff --git a/adapter/ohos/HapVerify.java b/adapter/ohos/HapVerify.java index 8f485718..9d9f45a1 100644 --- a/adapter/ohos/HapVerify.java +++ b/adapter/ohos/HapVerify.java @@ -58,12 +58,14 @@ class HapVerify { */ public static boolean checkHapIsValid(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos == null || hapVerifyInfos.isEmpty()) { - LOG.error("HapVerify::checkHapIsValid hapVerifyInfos is empty"); + String errMsg = "Hap verify infos is null or empty."; + LOG.error(PackingToolErrMsg.HAP_VERIFY_INFO_EMPTY.toString(errMsg)); return false; } // check app variable is same if (!checkAppFieldsIsSame(hapVerifyInfos)) { - LOG.error("some app variable is different."); + String errMsg = "Some app variable is different."; + LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } // check moduleName is valid @@ -72,7 +74,8 @@ class HapVerify { } // check package is valid if (!checkPackageNameIsValid(hapVerifyInfos)) { - LOG.error("packageName duplicated."); + String errMsg = "Check packageName duplicated."; + LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } // check entry is valid @@ -81,12 +84,14 @@ class HapVerify { } // check dependency is valid if (!checkDependencyIsValid(hapVerifyInfos)) { - LOG.error("module dependency is invalid."); + String errMsg = "Check module dependency is invalid."; + LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } // check atomic service is valid if (!checkAtomicServiceIsValid(hapVerifyInfos)) { - LOG.error("checkAtomicServiceIsValid failed."); + String errMsg = "Check AtomicService valid failed."; + LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } // check ability is valid @@ -95,15 +100,18 @@ class HapVerify { } // check targetModuleName if (!checkTargetModuleNameIsExisted(hapVerifyInfos)) { - LOG.error("target module is not found."); + String errMsg = "Target module is not found."; + LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } if (!checkCompileSdkIsValid(hapVerifyInfos)) { - LOG.error("compile sdk config is not same."); + String errMsg = "Compile sdk config is not same."; + LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } if (!checkProxyDataUriIsUnique(hapVerifyInfos)) { - LOG.error("uris in proxy data are not unique."); + String errMsg = "uris in proxy data are not unique."; + LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } if (!checkContinueTypeIsValid(hapVerifyInfos)) { @@ -144,11 +152,13 @@ class HapVerify { continue; } if (!Collections.disjoint(typeList, typeList2)) { - LOG.error("Module: (" + hapVerifyInfo.getModuleName() + "), Ability: (" + - abilityNames.get(i) + ") and Ability: (" + - abilityNames.get(j) + ") have same continueType."); - LOG.error("Ability: (" + abilityNames.get(i) + ") have continueType: " + typeList); - LOG.error("Another Ability: (" + abilityNames.get(j) + ") have continueType: " + typeList2); + String cause = "Module(" + hapVerifyInfo.getModuleName() + "), Ability(" + + abilityNames.get(i) + ") and Ability(" + + abilityNames.get(j) + ") have same continueType.\n"; + cause += "Ability(" + abilityNames.get(i) + ") have continueType: " + typeList + ", "; + cause += "Another Ability(" + abilityNames.get(j) + ") have continueType: " + typeList2 + "."; + String solution = "Please ensure that the continueType for different abilities do not overlap."; + LOG.error(PackingToolErrMsg.CONTINUE_TYPE_INVALID.toString(cause, solution)); return false; } } @@ -165,12 +175,17 @@ class HapVerify { List typeList2 = hapVerifyInfo2.getContinueTypeMap().values().stream() .flatMap(Collection::stream).collect(Collectors.toList()); if (!Collections.disjoint(typeList, typeList2)) { - LOG.error("Module: (" + hapVerifyInfo.getModuleName() + ") and Module: (" + - hapVerifyInfo2.getModuleName() + ") have same deviceType and continueType."); - LOG.error("Module: (" + hapVerifyInfo.getModuleName() + ") have deviceType: " + - hapVerifyInfo.getDeviceType() + " and continueType: " + typeList); - LOG.error("Another Module: (" + hapVerifyInfo2.getModuleName() + ") have deviceType: " + - hapVerifyInfo2.getDeviceType() + " and continueType: " + typeList2); + String cause = "Conflict detected between modules due to overlapping deviceType and continueType:\n" + + "- Module(" + hapVerifyInfo.getModuleName() + ") with deviceType: " + + hapVerifyInfo.getDeviceType() + " and continueType: " + typeList + "\n" + + "- Module(" + hapVerifyInfo2.getModuleName() + ") with deviceType: " + + hapVerifyInfo2.getDeviceType() + " and continueType: " + typeList2; + + String solution = "Ensure that the continueType fields in these modules are different. " + + "Update either (" + hapVerifyInfo.getModuleName() + ") or (" + hapVerifyInfo2.getModuleName() + + ") to avoid continueType or deviceType overlap."; + + LOG.error(PackingToolErrMsg.CONTINUE_TYPE_INVALID.toString(cause, solution)); return false; } return true; @@ -185,28 +200,38 @@ class HapVerify { */ public static boolean checkSharedApppIsValid(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos == null || hapVerifyInfos.isEmpty()) { - LOG.error("HapVerify::checkSharedApppIsValid hapVerifyInfos is empty."); + String cause = "Hap verify infos is null or empty"; + LOG.error(PackingToolErrMsg.HAP_VERIFY_INFO_EMPTY.toString(cause)); return false; } String moduleName = hapVerifyInfos.get(0).getModuleName(); for (HapVerifyInfo hapVerifyInfo : hapVerifyInfos) { if (!moduleName.equals(hapVerifyInfo.getModuleName())) { - LOG.error("HapVerify::checkSharedApppIsValid module name is different."); + String cause = "module name is different."; + String solution = "Ensure that all module have the same module name."; + LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); return false; } if (!hapVerifyInfo.getDependencyItemList().isEmpty()) { - LOG.error("HapVerify::checkSharedApppIsValid shared hsp cannot depend on other modules."); + String cause = "Shared app can not depend on other modules."; + 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; } if (!TYPE_SHARED.equals(hapVerifyInfo.getModuleType())) { - LOG.error("HapVerify::checkSharedApppIsValid module type is not shared app."); + String cause = "Module type is not shared app."; + String solution = "Ensure module type is 'shared' for all module."; + LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); return false; } } for (int i = 0; i < hapVerifyInfos.size(); i++) { for (int j = i + 1; j < hapVerifyInfos.size(); j++) { if (!checkDuplicatedIsValid(hapVerifyInfos.get(i), hapVerifyInfos.get(j))) { - LOG.error("HapVerify::checkSharedApppIsValid duplicated module."); + String cause = "There are duplicated modules in the packing file."; + String solution = "Ensure that there are no duplicated modules."; + LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); return false; } } @@ -223,7 +248,8 @@ class HapVerify { */ private static boolean checkAppFieldsIsSame(List hapVerifyInfos) { if (hapVerifyInfos.isEmpty()) { - LOG.error("HapVerify::checkAppVariableIsSame failed, hapVerifyInfos is empty."); + String cause = "Hap verify infos is empty."; + LOG.error(PackingToolErrMsg.HAP_VERIFY_INFO_EMPTY.toString(cause)); return false; } HapVerifyInfo verifyInfo = hapVerifyInfos.get(0); @@ -290,20 +316,27 @@ class HapVerify { private static boolean appFieldsIsValid(List hapVerifyInfos, int minCompatibleVersionCode, int targetApiVersion) { if (hapVerifyInfos.isEmpty()) { - LOG.warning("hapList empty"); + LOG.warning("Hap verify infos is empty"); return true; } HapVerifyInfo hap = hapVerifyInfos.get(0); for (HapVerifyInfo hapInfo : hapVerifyInfos) { if (hap.getVersion().minCompatibleVersionCode != hapInfo.getVersion().minCompatibleVersionCode || hap.getApiVersion().getTargetApiVersion() != hapInfo.getApiVersion().getTargetApiVersion()) { - LOG.error("hap minCompatibleVersionCode or targetApiVersion different"); + 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."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(errMsg, solution)); return false; } } if (hap.getVersion().minCompatibleVersionCode < minCompatibleVersionCode || hap.getApiVersion().getTargetApiVersion() < targetApiVersion) { - LOG.error("minCompatibleVersionCode or targetApiVersion property hap less than hsp"); + 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; } return true; @@ -312,20 +345,27 @@ class HapVerify { private static boolean appFieldsIsSame(VerifyCollection verifyCollection, HapVerifyInfo hapVerifyInfo) { if (hapVerifyInfo.getBundleName().isEmpty() || !verifyCollection.bundleName.equals(hapVerifyInfo.getBundleName())) { - LOG.error("input module bundleName is different."); + String errMsg = "Input module bundleName is different."; + String solution = "Check if the bundleName is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (!verifyCollection.getBundleType().equals(hapVerifyInfo.getBundleType())) { - LOG.error("input module bundleType is different."); + String errMsg = "Input module bundleType is different."; + String solution = "Check if the bundleType is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (verifyCollection.versionCode != hapVerifyInfo.getVersion().versionCode) { - LOG.error("input module versionCode is different."); + String errMsg = "Input module versionCode is different."; + String solution = "Check if the versionCode is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (verifyCollection.compatibleApiVersion != hapVerifyInfo.getApiVersion().getCompatibleApiVersion()) { - LOG.error("input module minApiVersion is different."); - return false; + String errMsg = "Input module minApiVersion is different."; + String solution = "Check if the minApiVersion is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); } if (!verifyCollection.releaseType.equals(hapVerifyInfo.getApiVersion().getReleaseType())) { if (verifyCollection.getModuleType().equals(TYPE_SHARED) || @@ -333,27 +373,35 @@ class HapVerify { LOG.warning("Module: (" + verifyCollection.getModuleName() + ") and Module: (" + hapVerifyInfo.getModuleName() + ") has different releaseType."); } else { - LOG.error("input module releaseType is different."); - LOG.error("Solutions: > Check if the releaseType is the same in different modules."); + String errMsg = "Input module releaseType is different."; + String solution = "Check if the releaseType is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } } if (!verifyCollection.targetBundleName.equals(hapVerifyInfo.getTargetBundleName())) { - LOG.error("targetBundleName is different."); + String errMsg = "Input targetBundleName is different."; + String solution = "Check if the targetBundleName is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (verifyCollection.targetPriority != hapVerifyInfo.getTargetPriority()) { - LOG.error("targetPriority is different."); + String errMsg = "Input targetPriority is different."; + String solution = "Check if the targetPriority is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (verifyCollection.debug != hapVerifyInfo.isDebug()) { - LOG.error("debug is different."); - LOG.error("Solutions: > Check if the debug type is the same in different modules."); + String errMsg = "The debug parameter values are different."; + String solution = "Check if the debug setting is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (isEntryOrFeature(verifyCollection.getModuleType()) && isEntryOrFeature(hapVerifyInfo.getModuleType())) { if (!verifyCollection.getMultiAppMode().equals(hapVerifyInfo.getMultiAppMode())) { - LOG.error("multiAppMode is different."); + String errMsg = "The multiAppMode parameter values are different."; + String solution = "Check if the multiAppMode is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } } @@ -383,29 +431,31 @@ class HapVerify { private static boolean checkModuleNameIsValid(List hapVerifyInfos) throws BundleException { for (int i = 0; i < hapVerifyInfos.size() - 1; ++i) { if (hapVerifyInfos.get(i).getModuleName().isEmpty()) { - LOG.error("HapVerify::checkModuleNameIsValid should not be empty."); - throw new BundleException("HapVerify::checkModuleNameIsValid should not be empty."); + String cause = "The module name in the HAP infos is empty."; + String solution = "Ensure that each HAP file contains a valid module name field before verification."; + LOG.error(PackingToolErrMsg.CHECK_MODULE_NAME_INVALID.toString(cause, solution)); + throw new BundleException("Check moduleName is valid should not be empty."); } for (int j = i + 1; j < hapVerifyInfos.size(); ++j) { if (hapVerifyInfos.get(i).getModuleName().equals(hapVerifyInfos.get(j).getModuleName()) && !checkDuplicatedIsValid(hapVerifyInfos.get(i), hapVerifyInfos.get(j))) { - LOG.error("Module: (" + hapVerifyInfos.get(i).getModuleName() + ") and Module: (" + - hapVerifyInfos.get(j).getModuleName() + ") have the same moduleName, " + - "please check deviceType or distroFilter of the module."); - LOG.error("Module: " + hapVerifyInfos.get(i).getModuleName() + " has deviceType " - + hapVerifyInfos.get(i).getDeviceType() + "."); - LOG.error("Another Module: " + hapVerifyInfos.get(j).getModuleName() + " has deviceType " - + hapVerifyInfos.get(j).getDeviceType() + "."); + 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(j).getDeviceType() + "."; if (!EMPTY_STRING.equals(hapVerifyInfos.get(i).getDistroFilter().dump())) { - LOG.error("Module: " + hapVerifyInfos.get(i).getModuleName() + " DistroFilter is : " - + 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())) { - LOG.error("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() + "."; } - LOG.error("Solution: Make sure the module name is valid and unique."); - LOG.error("Reference: " + REFERENCE_LINK + "."); + String solution = "Make sure the module name is valid and unique.\n" + + "Reference: " + REFERENCE_LINK + "."; + LOG.error(PackingToolErrMsg.CHECK_MODULE_NAME_INVALID.toString(cause, solution)); return false; } } @@ -428,23 +478,23 @@ class HapVerify { for (int j = i + 1; j < hapVerifyInfos.size(); ++j) { if (hapVerifyInfos.get(i).getPackageName().equals(hapVerifyInfos.get(j).getPackageName()) && !checkDuplicatedIsValid(hapVerifyInfos.get(i), hapVerifyInfos.get(j))) { - LOG.error("Module: (" + hapVerifyInfos.get(i).getModuleName() + ") and Module: (" + - hapVerifyInfos.get(j).getModuleName() + ") have the same packageName, " + - "please check deviceType or distroFilter of the module."); - LOG.error("Module: " + hapVerifyInfos.get(i).getModuleName() + " has deviceType " - + hapVerifyInfos.get(i).getDeviceType() + "."); - LOG.error("Another Module: " + hapVerifyInfos.get(j).getModuleName() + " has deviceType " - + hapVerifyInfos.get(j).getDeviceType() + "."); + 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(j).getDeviceType() + "."; if (!EMPTY_STRING.equals(hapVerifyInfos.get(i).getDistroFilter().dump())) { - LOG.error("Module: " + hapVerifyInfos.get(i).getModuleName() + " DistroFilter is : " + - 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())) { - LOG.error("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() + "."; } - LOG.error("Solution: Make sure package name is valid and unique."); - LOG.error("Reference: " + REFERENCE_LINK + "."); + String solution = "Make sure package name is valid and unique.\n" + + "Reference: " + REFERENCE_LINK + "."; + LOG.error(PackingToolErrMsg.CHECK_PACKAGE_NAME_INVALID.toString(cause, solution)); return false; } } @@ -521,11 +571,15 @@ class HapVerify { return true; } if (nonOverlayHap.isEmpty()) { - LOG.error("target modules are needed to pack with overlay module."); + LOG.error(PackingToolErrMsg.TARGET_MODULE_NAME_NOT_EXIST.toString( + "Target hap modules are needed to pack with overlay hap module.")); return false; } if (!moduleList.containsAll(targetModuleList)) { - LOG.error("target modules are needed to pack with overlay module."); + List missingModules = new ArrayList<>(targetModuleList); + missingModules.removeAll(moduleList); + LOG.error(PackingToolErrMsg.TARGET_MODULE_NAME_NOT_EXIST.toString( + "The following target overlay hap modules are missing: " + missingModules)); return false; } @@ -535,13 +589,17 @@ class HapVerify { private static boolean checkCompileSdkIsValid(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos.isEmpty()) { - LOG.error("hapVerifyInfos is empty"); + String cause = "Hap verify infos is empty"; + String solution = "Ensure the App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); return false; } String compileSdkType = hapVerifyInfos.get(0).getCompileSdkType(); for (HapVerifyInfo info : hapVerifyInfos) { if (!compileSdkType.equals(info.getCompileSdkType())) { - LOG.error("compile sdk type is not same."); + String cause = "CompileSdkType is not the same for all modules."; + String solution = "Ensure that all modules has same compileSdkType."; + LOG.error(PackingToolErrMsg.COMPILE_SDK_TYPE_DIFFERENT.toString(cause, solution)); return false; } } @@ -550,15 +608,19 @@ class HapVerify { private static boolean checkProxyDataUriIsUnique(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos.isEmpty()) { - LOG.error("hapVerifyInfos is empty"); + String cause = "Hap verify infos is empty"; + String solution = "Ensure the App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); return false; } Set uriSet = new HashSet<>(); for (HapVerifyInfo info : hapVerifyInfos) { for (String uri : info.getProxyDataUris()) { if (uriSet.contains(uri)) { - LOG.error("uri " + uri + " in proxy data is duplicated"); - LOG.error("Solutions: > Check if the uri in proxyData is unique in different modules."); + String moduleName = info.getModuleName(); + String cause = "Module(" + moduleName + ") and uri(" + uri + ") in proxyData settings 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; } else { uriSet.add(uri); @@ -595,23 +657,27 @@ class HapVerify { for (int i = 0; i < entryHapVerifyInfos.size() - 1; ++i) { for (int j = i + 1; j < entryHapVerifyInfos.size(); ++j) { if (!checkDuplicatedIsValid(entryHapVerifyInfos.get(i), entryHapVerifyInfos.get(j))) { - LOG.error("Module: (" + entryHapVerifyInfos.get(i).getModuleName() + ") and Module: (" + + String cause = "Module(" + entryHapVerifyInfos.get(i).getModuleName() + ") and Module(" + entryHapVerifyInfos.get(j).getModuleName() + ") are entry, " + - "please check deviceType or distroFilter of the module."); - LOG.error("Module: " + entryHapVerifyInfos.get(i).getModuleName() + " has deviceType " - + entryHapVerifyInfos.get(i).getDeviceType() + "."); - LOG.error("Another Module: " + entryHapVerifyInfos.get(j).getModuleName() + " has deviceType " - + entryHapVerifyInfos.get(j).getDeviceType() + "."); + "please check deviceType or distroFilter of the module.\n" + "Module: " + + entryHapVerifyInfos.get(i).getModuleName() + " has deviceType " + + entryHapVerifyInfos.get(i).getDeviceType() + ".\n" + "Another Module: " + + entryHapVerifyInfos.get(j).getModuleName() + " has deviceType " + + entryHapVerifyInfos.get(j).getDeviceType() + "."; + if (!EMPTY_STRING.equals(entryHapVerifyInfos.get(i).getDistroFilter().dump())) { - LOG.error("Module: " + entryHapVerifyInfos.get(i).getModuleName() + " DistroFilter is : " + - entryHapVerifyInfos.get(i).getDistroFilter().dump() + "."); + cause += "\n" + "Module: " + entryHapVerifyInfos.get(i).getModuleName() + " DistroFilter is : " + + entryHapVerifyInfos.get(i).getDistroFilter().dump() + "."; } if (!EMPTY_STRING.equals(entryHapVerifyInfos.get(j).getDistroFilter().dump())) { - LOG.error("Another Module: " + entryHapVerifyInfos.get(j).getModuleName() + - " DistroFilter is " + entryHapVerifyInfos.get(j).getDistroFilter().dump() + "."); + cause += "\n" + "Another Module: " + entryHapVerifyInfos.get(j).getModuleName() + + " DistroFilter is " + entryHapVerifyInfos.get(j).getDistroFilter().dump() + "."; } - LOG.error("Solution: Make sure entry name is valid and unique."); - LOG.error("Reference: " + REFERENCE_LINK + "."); + + String solution = + "Make sure the entry module is valid and unique, and the HAP uniqueness check logic passes.\n" + + "Reference: " + REFERENCE_LINK + "."; + LOG.error(PackingToolErrMsg.CHECK_ENTRY_INVALID.toString(cause, solution)); return false; } } @@ -642,7 +708,8 @@ class HapVerify { return true; } // check distroFilter - if (checkDistroFilterDisjoint(hapVerifyInfoLeft.getDistroFilter(), hapVerifyInfoRight.getDistroFilter())) { + if (checkDistroFilterDisjoint(hapVerifyInfoLeft.getDistroFilter(), hapVerifyInfoRight.getDistroFilter(), + hapVerifyInfoLeft.getModuleName(), hapVerifyInfoRight.getModuleName())) { return true; } @@ -657,38 +724,39 @@ class HapVerify { * @throws BundleException Throws this exception if the json is not standard. * @return true if two distroFilter is disjoint */ - private static boolean checkDistroFilterDisjoint(DistroFilter distroFilterLeft, DistroFilter distroFilterRight) + private static boolean checkDistroFilterDisjoint(DistroFilter distroFilterLeft, DistroFilter distroFilterRight, + 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)) { + 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)) { + 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)) { + 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)) { + 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)) { + distroFilterRight.countryCode.policy, distroFilterRight.countryCode.value, moduleNameLeft, moduleNameRight)) { return true; } } @@ -706,10 +774,14 @@ 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) throws BundleException { + List valueRight, String moduleNameLeft, String ModuleNameRight) + throws BundleException { if (valueLeft == null || valueRight == null) { - LOG.error("HapVerify::checkPolicyValueDisjoint value should not empty."); - throw new BundleException("HapVerify::checkPolicyValueDisjoint value should not empty."); + 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."; + LOG.error(PackingToolErrMsg.CHECK_POLICY_DISJOINT_ERROR.toString(errMsg, solution)); + throw new BundleException("Check policy value disjoint value should not empty."); } if (EXCLUDE.equals(policyLeft) && INCLUDE.equals(policyRight)) { if (valueRight.isEmpty() || valueLeft.containsAll(valueRight)) { @@ -726,8 +798,11 @@ class HapVerify { } else if (EXCLUDE.equals(policyLeft) && EXCLUDE.equals(policyRight)) { return false; } else { - LOG.error("HapVerify::checkPolicyValueDisjoint input policy is invalid."); - throw new BundleException("HapVerify::checkPolicyValueDisjoint input policy is invalid."); + 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."; + LOG.error(PackingToolErrMsg.CHECK_POLICY_DISJOINT_ERROR.toString(errMsg, solution)); + throw new BundleException("Check policy value disjoint input policy is invalid."); } return false; } @@ -844,7 +919,8 @@ class HapVerify { return true; } if (hapVerifyInfo.getDistroFilter().apiVersion.policy == null) { - LOG.error("HapVerify::checkApiVersionCovered input none policy."); + LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( + "Entry module(" + hapVerifyInfo.getModuleName() + ") policy is null.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().apiVersion.policy)) { @@ -861,8 +937,10 @@ class HapVerify { exclude = Stream.of(exclude, hapVerifyInfo.getDistroFilter().apiVersion.value). flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { - LOG.error("HapVerify::checkApiVersionCovered input policy is invalid."); - throw new BundleException("HapVerify::checkApiVersionCovered input policy is invalid."); + LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( + "Entry module(" + hapVerifyInfo.getModuleName() + ") policy '" + hapVerifyInfo.getDistroFilter().apiVersion.policy + + "' is invalid.")); + throw new BundleException("Check ApiVersion covered input policy is invalid."); } } if (include != null) { @@ -894,7 +972,9 @@ class HapVerify { return true; } if (hapVerifyInfo.getDistroFilter().screenShape.policy == null) { - LOG.error("HapVerify::checkScreenShapeCovered input none policy."); + LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( + "Check feature module screenShape is subset of entry module screenShape failed, Entry module(" + + hapVerifyInfo.getModuleName() + ") policy is null.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().screenShape.policy)) { @@ -909,8 +989,11 @@ class HapVerify { exclude = Stream.of(exclude, hapVerifyInfo.getDistroFilter().screenShape.value). flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { - LOG.error("HapVerify::checkScreenShapeCovered input policy is invalid."); - throw new BundleException("HapVerify::checkScreenShapeCovered input policy is invalid."); + LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( + "Check feature module screenShape is subset of entry module screenShape failed, Entry module(" + + hapVerifyInfo.getModuleName() + ") policy '" + hapVerifyInfo.getDistroFilter().screenShape.policy + + "' is invalid.")); + throw new BundleException("Check ScreenShape covered input policy is invalid."); } } if (include != null) { @@ -941,7 +1024,9 @@ class HapVerify { return true; } if (hapVerifyInfo.getDistroFilter().screenWindow.policy == null) { - LOG.error("HapVerify::checkScreenWindowCovered input none policy."); + LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( + "Check feature module screenWindow is subset of entry module screenWindow failed, Entry module(" + + hapVerifyInfo.getModuleName() + ") policy is null.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().screenWindow.policy)) { @@ -956,8 +1041,11 @@ class HapVerify { exclude = Stream.of(exclude, hapVerifyInfo.getDistroFilter().screenWindow.value). flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { - LOG.error("HapVerify::checkScreenWindowCovered input policy is invalid."); - throw new BundleException("HapVerify::checkScreenWindowCovered input policy is invalid."); + LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( + "Check feature module screenWindow is subset of entry module screenWindow failed, Entry module(" + + hapVerifyInfo.getModuleName() + ") policy '" + hapVerifyInfo.getDistroFilter().screenWindow.policy + + "' is invalid.")); + throw new BundleException("Check ScreenWindow covered input policy is invalid."); } } if (include != null) { @@ -988,7 +1076,9 @@ class HapVerify { return true; } if (hapVerifyInfo.getDistroFilter().screenDensity.policy == null) { - LOG.error("HapVerify::checkScreenDensityCovered input none policy."); + LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( + "Check feature module screenDensity is subset of entry module screenDensity failed, Entry module(" + + hapVerifyInfo.getModuleName() + ") policy is null.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().screenDensity.policy)) { @@ -1003,8 +1093,11 @@ class HapVerify { exclude = Stream.of(exclude, hapVerifyInfo.getDistroFilter().screenDensity.value). flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { - LOG.error("HapVerify::checkScreenDensityCovered input policy is invalid."); - throw new BundleException("HapVerify::checkScreenDensityCovered input policy is invalid."); + LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( + "Check feature module screenDensity is subset of entry module screenDensity failed, Entry module(" + + hapVerifyInfo.getModuleName() + ") policy '" + hapVerifyInfo.getDistroFilter().screenDensity.policy + + "' is invalid.")); + throw new BundleException("Check ScreenDensity covered input policy is invalid."); } } if (include != null) { @@ -1035,7 +1128,9 @@ class HapVerify { return true; } if (hapVerifyInfo.getDistroFilter().countryCode.policy == null) { - LOG.error("HapVerify::checkCountryCodeCovered input none policy."); + LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( + "Check feature module countryCode is subset of entry module countryCode failed, Entry module(" + + hapVerifyInfo.getModuleName() + ") policy is null.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().countryCode.policy)) { @@ -1050,8 +1145,11 @@ class HapVerify { exclude = Stream.of(exclude, hapVerifyInfo.getDistroFilter().countryCode.value). flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { - LOG.error("HapVerify::checkCountryCodeCovered input policy is invalid."); - throw new BundleException("HapVerify::checkCountryCodeCovered input policy is invalid."); + LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( + "Check feature module countryCode is subset of entry module countryCode failed, Entry module " + + hapVerifyInfo.getModuleName() + ") policy '" + hapVerifyInfo.getDistroFilter().countryCode.policy + + "' is invalid.")); + throw new BundleException("Check CountryCode covered input policy is invalid."); } } if (include != null) { @@ -1090,7 +1188,7 @@ class HapVerify { private static boolean checkPolicyValueCovered( String policy, List value, List include, List exclude) { if (value == null || policy == null) { - LOG.error("checkPolicyValueCovered::failed value is null."); + LOG.warning("checkPolicyValueCovered::failed covered value or policy is null."); return false; } if (EXCLUDE.equals(policy)) { @@ -1151,13 +1249,17 @@ class HapVerify { */ private static boolean checkDependencyIsValid(List allHapVerifyInfo) throws BundleException { if (allHapVerifyInfo.isEmpty()) { - LOG.error("HapVerify::checkDependencyIsValid failed, input none hap."); + String cause = "No module included."; + String solution = "Ensure the App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); throw new BundleException("HapVerify::checkDependencyIsValid failed, input none hap."); } boolean isInstallationFree = allHapVerifyInfo.get(0).isInstallationFree(); for (HapVerifyInfo hapVerifyInfo : allHapVerifyInfo) { if (isInstallationFree != hapVerifyInfo.isInstallationFree()) { - LOG.error("installationFree is different in input hap."); + 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)); return false; } } @@ -1173,7 +1275,7 @@ class HapVerify { } /** - * DFS traverse dependency, and check dependency list ia valid + * DFS traverse dependency, and check dependency list is valid * * @param hapVerifyInfo the first node of dependency list * @param allHapVerifyInfo is all input hap module @@ -1200,7 +1302,10 @@ class HapVerify { dependency.getModuleName(), hapVerifyInfo, allHapVerifyInfo); for (HapVerifyInfo item : layerDependencyList) { if (FEATURE.equals(item.getModuleType()) || ENTRY.equals(item.getModuleType())) { - LOG.error("HAP or HSP cannot depend on HAP" + item.getModuleName() + "."); + String cause = "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)); return false; } dependencyList.add(item); @@ -1265,8 +1370,11 @@ class HapVerify { for (int i = 0; i < dependencyList.size() - 1; ++i) { for (int j = i + 1; j < dependencyList.size(); ++j) { if (isSameHapVerifyInfo(dependencyList.get(i), dependencyList.get(j))) { - LOG.error("circular dependency, dependencyList is " - + getHapVerifyInfoListNames(dependencyList) + "."); + String cause = "Circular dependency, dependencyList is " + + getHapVerifyInfoListNames(dependencyList) + "."; + String solution = "Please check the dependecy against the module name in the list.\n"; + solution += "Remove circulate dependency module to ensure the dependency list is valid."; + LOG.error(PackingToolErrMsg.DEPENDENCY_LIST_INVALID.toString(cause, solution)); return true; } } @@ -1304,7 +1412,7 @@ class HapVerify { private static boolean checkAtomicServiceModuleSize(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - LOG.error("checkAtomicServiceIsValid failed, hapVerifyInfoList is empty."); + LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString()); return false; } int entryLimit = hapVerifyInfoList.get(0).getEntrySizeLimit(); @@ -1324,14 +1432,15 @@ class HapVerify { fileSize += dependency.getFileLength(); } if (hapVerifyInfo.getModuleType().equals(ENTRY) && (fileSize >= entryLimit * FILE_LENGTH_1M)) { - LOG.error("module " + hapVerifyInfo.getModuleName() + " and it's dependencies size is " + - getCeilFileSize(fileSize, entryLimit) + "MB, which is overlarge than " + entryLimit + "MB."); + String errMsg = "module " + hapVerifyInfo.getModuleName() + " and it's dependencies size sum is " + + getCeilFileSize(fileSize, entryLimit) + "MB, which is overlarge than " + entryLimit + "MB."; + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_MODULE_SIZE.toString(errMsg)); return false; } if (!hapVerifyInfo.getModuleType().equals(ENTRY) && (fileSize >= notEntryLimit * FILE_LENGTH_1M)) { - LOG.error("module " + hapVerifyInfo.getModuleName() + " and it's dependencies size is " + - getCeilFileSize(fileSize, notEntryLimit) + - "MB, which is overlarge than " + notEntryLimit + "MB."); + String errMsg = "module " + hapVerifyInfo.getModuleName() + " and it's dependencies size sum is " + + getCeilFileSize(fileSize, notEntryLimit) + "MB, which is overlarge than " + notEntryLimit + "MB."; + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_MODULE_SIZE.toString(errMsg)); return false; } } @@ -1351,7 +1460,7 @@ class HapVerify { private static Map> getDeviceHapVerifyInfoMap(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - LOG.error("getDeviceHapVerifyInfoMap failed, hapVerifyInfoList is empty."); + LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString()); throw new BundleException("getDeviceHapVerifyInfoMap failed, hapVerifyInfoList is empty."); } Map> deviceInfoMap = new HashMap>(); @@ -1372,7 +1481,9 @@ class HapVerify { private static boolean checkAtomicServiceIsValid(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - LOG.error("checkAtomicServiceIsValid failed, hapVerifyInfoList is empty."); + String cause = "No module included."; + String solution = "Ensure the App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); return false; } String bundleType = hapVerifyInfoList.get(0).getBundleType(); @@ -1388,7 +1499,8 @@ class HapVerify { for (String device : deviceInfoMap.keySet()) { List hapVerifyInfos = deviceInfoMap.get(device); if (!checkAtomicServicePreloadsIsValid(hapVerifyInfos)) { - LOG.error("checkAtomicServicePreloadsIsValid failed on device " + device + "."); + LOG.error(PackingToolErrMsg.CHECK_ATOMICSERVICE_INVALID.toString( + "Check whether AtomicService preloads are valid failed on device "+ device + ".")); return false; } } @@ -1416,7 +1528,8 @@ class HapVerify { private static boolean checkAtomicServicePreloadsIsValid(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - LOG.error("checkAtomicServicePreloadsIsValid failed, hapVerifyInfoList is empty."); + String cause = "Hap verify infos is empty."; + LOG.error(PackingToolErrMsg.HAP_VERIFY_INFO_EMPTY.toString(cause)); throw new BundleException("checkAtomicServicePreloadsIsValid failed, hapVerifyInfoList is empty."); } List moduleNames = new ArrayList<>(); @@ -1430,18 +1543,19 @@ class HapVerify { for (PreloadItem preloadItem : preloadItems) { String moduleName = preloadItem.getModuleName(); if (preloadModuleName.contains(moduleName)) { - LOG.error("preloads config a duplicate module " + moduleName + - " in " + hapVerifyInfo.getModuleName() + "."); + LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("Preloads a duplicate module, " + + moduleName + " cannot on module " + hapVerifyInfo.getModuleName() + ".")); return false; } preloadModuleName.add(moduleName); if (!moduleNames.contains(moduleName)) { - LOG.error("preloads config a invalid module " + moduleName + - " in " + hapVerifyInfo.getModuleName() + "."); + LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("Preloads a not exist module, " + + moduleName + " cannot on module " + hapVerifyInfo.getModuleName() + ".")); return false; } if (moduleName.equals(hapVerifyInfo.getModuleName())) { - LOG.error("can not preload self, " + hapVerifyInfo.getModuleName() + " preload self."); + LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("Can not preload self, module " + + hapVerifyInfo.getModuleName() + " cannot preload self.")); return false; } } @@ -1457,9 +1571,9 @@ class HapVerify { String moduleName = preloadItem.getModuleName(); if (moduleNameWithType.get(moduleName).equals(ENTRY) || moduleNameWithType.get(moduleName).equals(HAR)) { - LOG.error("feature or shared can not preload entry or har, " - + hapVerifyInfo.getModuleName() + " preloads a " - + moduleNameWithType.get(moduleName) + " module."); + LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString( + "feature or shared can not preload entry or har, module(" + hapVerifyInfo.getModuleName() + + ") cannot preloads module(" + moduleNameWithType.get(moduleName) + ").")); return false; } } @@ -1476,11 +1590,9 @@ class HapVerify { */ public static boolean checkFileSizeIsValid(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - LOG.error("checkFileSizeIsValid failed, hapVerifyInfoList is empty."); - throw new BundleException("checkFileSizeIsValid failed, hapVerifyInfoList is empty."); + LOG.error(PackingToolErrMsg.HAP_VERIFY_INFO_EMPTY.toString("Hap verify infos is empty.")); } if (!checkFileSize(hapVerifyInfoList)) { - LOG.error("checkFileSize failed."); return false; } return true; @@ -1488,7 +1600,7 @@ class HapVerify { private static boolean checkFileSize(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - LOG.error("checkFileSizeWhenSplit failed, hapVerifyInfoList is empty."); + LOG.error(PackingToolErrMsg.HAP_VERIFY_INFO_EMPTY.toString("Hap verify infos is empty.")); throw new BundleException("checkFileSizeWhenSplit failed, hapVerifyInfoList is empty."); } // check single file length @@ -1497,16 +1609,18 @@ class HapVerify { for (HapVerifyInfo hapVerifyInfo : hapVerifyInfoList) { if (hapVerifyInfo.getModuleType().equals(ENTRY) && (hapVerifyInfo.getFileLength() >= entryLimit * FILE_LENGTH_1M)) { - LOG.error("module " + hapVerifyInfo.getModuleName() + "'s size is " + + String errMsg = "module " + hapVerifyInfo.getModuleName() + "'s size is " + getCeilFileSize(hapVerifyInfo.getFileLength(), entryLimit) + - "MB, which is overlarge than " + entryLimit + "MB."); + "MB, which is overlarge than " + entryLimit + "MB."; + LOG.error(PackingToolErrMsg.CHECK_FILE_SIZE_INVALID.toString(errMsg)); return false; } if (!hapVerifyInfo.getModuleType().equals(ENTRY) && (hapVerifyInfo.getFileLength() >= notEntryLimit * FILE_LENGTH_1M)) { - LOG.error("module " + hapVerifyInfo.getModuleName() + "'s size is " + - getCeilFileSize(hapVerifyInfo.getFileLength(), notEntryLimit) + - "MB, which is overlarge than " + notEntryLimit + "MB."); + String errMsg = "module " + hapVerifyInfo.getModuleName() + "'s size is " + + getCeilFileSize(hapVerifyInfo.getFileLength(), notEntryLimit) + + "MB, which is overlarge than " + notEntryLimit + "MB."; + LOG.error(PackingToolErrMsg.CHECK_FILE_SIZE_INVALID.toString(errMsg)); return false; } } @@ -1515,7 +1629,8 @@ class HapVerify { for (String device : deviceInfoMap.keySet()) { ListhapVerifyInfoList1 = deviceInfoMap.get(device); if (!checkAtomicServiceModuleSize(hapVerifyInfoList1)) { - LOG.error("checkAtomicServiceModuleSize failed on device " + device + "."); + String errMsg = "Check AtomicService module size failed on device " + device + "."; + LOG.error(PackingToolErrMsg.CHECK_FILE_SIZE_INVALID.toString(errMsg)); return false; } } diff --git a/adapter/ohos/ModuleJsonUtil.java b/adapter/ohos/ModuleJsonUtil.java index 6bbf2690..eaf2237f 100644 --- a/adapter/ohos/ModuleJsonUtil.java +++ b/adapter/ohos/ModuleJsonUtil.java @@ -131,8 +131,8 @@ class ModuleJsonUtil { version.versionCode = appObj.getIntValue(VERSIONCODE); version.versionName = appObj.getString(VERSIONNAME); } else { - String errMsg = "ModuleJsonUtil:parseStageVersion json file do not contain version."; - LOG.error(errMsg); + String errMsg = "The module.json file does not contain versionCode or versionName."; + LOG.error(PackingToolErrMsg.PARSE_STAGE_JSON_FAILED.toString(errMsg)); throw new BundleException(errMsg); } if (appObj.containsKey(MIN_COMPATIBLE_VERSION_CODE)) { @@ -154,17 +154,19 @@ class ModuleJsonUtil { JSONObject appObj = getAppObj(jsonString); JSONObject versionObj = appObj.getJSONObject(VERSION); if (versionObj == null) { - LOG.error("ModuleJsonUtil:parseFaVersion failed : json file do not version."); - throw new BundleException("ModuleJsonUtil:parseFaVersion failed : json file do not version."); + String errMsg = "The config.json file does not have 'version'."; + LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString(errMsg)); + throw new BundleException("Parse FaVersion failed: the config.json file does not have 'version'."); } Version version = new Version(); if (versionObj.containsKey(CODE) && versionObj.containsKey(NAME)) { version.versionName = versionObj.getString(NAME); version.versionCode = versionObj.getIntValue(CODE); } else { - LOG.error("ModuleJsonUtil:parseFaVersion failed : json file do not version name or version code."); + String errMsg = "The config.json file does not have 'name' or 'code'."; + LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString(errMsg)); throw new BundleException( - "ModuleJsonUtil:parseFaVersion failed : json file do not version name or version code."); + "Parse FaVersion failed: the config.json file does not have 'name' or 'code'."); } if (versionObj.containsKey(MIN_COMPATIBLE_VERSION_CODE)) { version.minCompatibleVersionCode = versionObj.getIntValue(MIN_COMPATIBLE_VERSION_CODE); @@ -239,8 +241,9 @@ class ModuleJsonUtil { public static ModuleApiVersion parseFAModuleApiVersion(String jsonString) throws BundleException { JSONObject appObj = getAppObj(jsonString); if (!appObj.containsKey(API_VERSION)) { - LOG.error("ModuleJsonUtil::parseFAAPIVersion json file do not contain apiVersion."); - throw new BundleException("ModuleJsonUtil::parseFAAPIVersion json file do not contain apiVersion."); + 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 --json-path file do not contain apiVersion."); } JSONObject apiVersionObj = appObj.getJSONObject(API_VERSION); ModuleApiVersion moduleApiVersion = new ModuleApiVersion(); @@ -269,8 +272,9 @@ class ModuleJsonUtil { if (moduleObj.containsKey(NAME)) { moduleName = moduleObj.getString(NAME); } else { - LOG.error("ModuleJsonUtil:parseStageModuleName failed: json file do not contain module name."); - throw new BundleException("ModuleJsonUtil:parseStageModuleName failed: json file do not contain module name."); + String errMsg = "The module.json file do not contain module name."; + LOG.error(PackingToolErrMsg.PARSE_STAGE_JSON_FAILED.toString(errMsg)); + throw new BundleException(errMsg); } return moduleName; } @@ -287,13 +291,14 @@ class ModuleJsonUtil { JSONObject moduleObj = getModuleObj(jsonString); JSONObject distroObj = moduleObj.getJSONObject(DISTRO); if (distroObj == null) { - LOG.error("ModuleJsonUtil:parseFaModuleName failed: json file do not contain distro."); - throw new BundleException("ModuleJsonUtil:parseFaModuleName failed: json file do not contain distro."); + String errMsg = "The config.json file does not contain distro."; + LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString(errMsg)); + throw new BundleException(errMsg); } if (!distroObj.containsKey(MODULE_NAME)) { - LOG.error("ModuleJsonUtil:parseFaModuleName failed: json file do not contain moduleName."); - throw new BundleException( - "ModuleJsonUtil:parseFaModuleName failed: json file do not contain moduleName."); + String errMsg = "The config.json file does not contain moduleName."; + LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString(errMsg)); + throw new BundleException(errMsg); } moduleName = distroObj.getString(MODULE_NAME); return moduleName; @@ -310,9 +315,9 @@ class ModuleJsonUtil { String moduleName; JSONObject moduleObj = getModuleObj(jsonString); if (!moduleObj.containsKey(NAME)) { - LOG.error("ModuleJsonUtil:parsePatchModuleName failed: json file do not contain moduleName."); - throw new BundleException( - "ModuleJsonUtil:parsePatchModuleName failed: json file do not contain moduleName."); + String errMsg = "The patch.json file do not contain moduleName."; + LOG.error(PackingToolErrMsg.PARSE_PATCH_MODULE_NAME_FAILED.toString(errMsg)); + throw new BundleException(errMsg); } moduleName = moduleObj.getString(NAME); return moduleName; @@ -331,7 +336,7 @@ class ModuleJsonUtil { if (moduleObj.containsKey(PACKAGE)) { packageStr = moduleObj.getString(PACKAGE); } else { - LOG.error("ModuleJsonUtil:parseFaPackageStr failed: json file do not contain package."); + LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString("The config.json file do not contain package.")); throw new BundleException("ModuleJsonUtil:parseFaPackageStr failed: json file do not contain package."); } return packageStr; @@ -350,8 +355,8 @@ class ModuleJsonUtil { if (appObject.containsKey(BUNDLE_NAME)) { bundleName = appObject.getString(BUNDLE_NAME); } else { - LOG.error("ModuleJsonUtil::parseStageBundleName json object do not contain bundleNames."); - throw new BundleException("ModuleJsonUtil::parseStageBundleName json object do not contain bundleNames."); + LOG.error(PackingToolErrMsg.PARSE_BUNDLE_NAME_FAILED.toString("json object do not contain bundleName.")); + throw new BundleException("Parse stage bundleName json object do not contain bundleNames."); } return bundleName; } @@ -943,8 +948,9 @@ class ModuleJsonUtil { */ public static void parseFAHapVerifyInfo(HapVerifyInfo hapVerifyInfo) throws BundleException { if (hapVerifyInfo.getProfileStr().isEmpty()) { - LOG.error("ModuleJsonUtil::parseFAHapVerifyInfo failed, config.json is empty."); - throw new BundleException("ModuleJsonUtil::parseFAHapVerifyInfo failed, config.json is empty."); + String errMsg = "config.json is empty."; + LOG.error(PackingToolErrMsg.PARSE_FA_HAP_VERIFY_INFO_FAILED.toString(errMsg)); + throw new BundleException(errMsg); } String bundleName = parseBundleName(hapVerifyInfo.getProfileStr()); hapVerifyInfo.setBundleName(bundleName); @@ -1071,8 +1077,8 @@ class ModuleJsonUtil { } } } catch (JSONException exception) { - String errMsg = "parse JSONObject failed: " + exception.getMessage(); - LOG.error(errMsg); + String errMsg = "parse metadata info exist JSONException: " + exception.getMessage(); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString(exception.getMessage())); throw new BundleException(errMsg); } return distroFilter; @@ -1310,9 +1316,9 @@ class ModuleJsonUtil { JSONObject moduleObj = getModuleObj(jsonString); String moduleName = parseStageModuleName(jsonString); if (!moduleObj.containsKey(TYPE)) { - String errMsg = "parse failed, input module.json is invalid, " + - "module.json has no type in module: " + moduleName; - LOG.error(errMsg); + String errMsg = "Module: '" + moduleName + "' has no +'type' field in module.json."; + 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); } String type = moduleObj.getString(TYPE); @@ -1320,42 +1326,47 @@ class ModuleJsonUtil { JSONObject appObj = getAppObj(jsonString); if (!appObj.containsKey(BUNDLE_TYPE)) { 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); - throw new BundleException(errMessage); + String errMsg = "The app.json5 file configuration does not match the installationFree true settings."; + 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); } return APP; } else { 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."; - LOG.error(errMsg); + String errMsg = "installationFree must be false in module '" + moduleName + "' when bundleType is app."; + String solution = "Set 'installationFree' to false in the module configuration when 'bundleType' is 'app'."; + LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); throw new BundleException(errMsg); } return APP; } else if (bundleType.equals(ATOMIC_SERVICE)) { if (!installationFree) { - String errMsg = "installationFree must be true in module(" + - moduleName + ") when bundleType is atomicService."; - LOG.error(errMsg); + String errMsg = "installationFree must be true in module '" + moduleName + "' when bundleType is atomicService."; + String solution = "Set 'installationFree' to true in the module configuration when 'bundleType'" + + "is 'atomicService'."; + LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); throw new BundleException(errMsg); } return ATOMIC_SERVICE; } else if (SHARED.equals(bundleType)) { if (!SHARED.equals(type)) { - String errMsg = "type must be shared in module(" + moduleName + ") when bundleType is shared."; - LOG.error(errMsg); + String errMsg = "type must be shared in module '" + moduleName + "' when bundleType is shared."; + String solution = "Set the 'type' to 'shared' in the module configuration when 'bundleType' is 'shared'.";; + LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); throw new BundleException(errMsg); } return SHARED; } else if (APP_SERVICE.equals(bundleType)) { return APP_SERVICE; } else { - LOG.error("bundleType is invalid in app.json."); - throw new BundleException("bundleType is invalid in app.json."); + String errMsg = "bundleType is invalid in app.json."; + String solution = "Ensure that the 'bundleType' field in the app.json file is correctly set to one of" + + "the valid types: 'app', 'atomicService', 'shared', or 'appService'."; + LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); + throw new BundleException(errMsg); } } } @@ -1393,8 +1404,10 @@ class ModuleJsonUtil { for (int i = 0; i < proxyData.size(); ++i) { JSONObject itemObj = proxyData.getJSONObject(i); if (!itemObj.containsKey(PROXY_URI)) { - LOG.error("parse JOSNObject failed in parseProxyDataUri."); - throw new BundleException("parse JOSNObject failed in parseProxyDataUri."); + String errMsg = "Proxy data object does not contain " + PROXY_URI + "."; + 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."); } String uri = itemObj.getString(PROXY_URI); proxyDataUris.add(uri); @@ -1404,8 +1417,10 @@ class ModuleJsonUtil { for (int i = 0; i < proxyDatas.size(); ++i) { JSONObject itemObj = proxyDatas.getJSONObject(i); if (!itemObj.containsKey(PROXY_URI)) { - LOG.error("parse JOSNObject failed in parseProxyDataUri."); - throw new BundleException("parse JOSNObject failed in parseProxyDataUri."); + String errMsg = "Proxy data object does not contain " + PROXY_URI + "."; + 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."); } String uri = itemObj.getString(PROXY_URI); proxyDataUris.add(uri); @@ -1419,14 +1434,14 @@ class ModuleJsonUtil { try { jsonObject = JSON.parseObject(jsonString); } catch (JSONException exception) { - String errMsg = "parse JSONobject failed."; - LOG.error(errMsg); + String errMsg = "Parse app object exist JSONException: "; + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString(errMsg + exception.getMessage())); throw new BundleException(errMsg); } JSONObject appObj = jsonObject.getJSONObject(APP); if (appObj == null) { - LOG.error("ModuleJsonUtil::parseStageInstallation json do not contain app."); - throw new BundleException("ModuleJsonUtil::parseStageInstallation json do not contain app."); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("module.json or config.json do not contain app.")); + throw new BundleException("json do not contain app."); } return appObj; } @@ -1436,18 +1451,18 @@ class ModuleJsonUtil { try { jsonObj = JSON.parseObject(jsonString); } catch (JSONException exception) { - String errMsg = "parse JSONobject failed."; - LOG.error(errMsg); + String errMsg = "JSONException: " + exception.getMessage(); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString(errMsg)); throw new BundleException(errMsg); } if (jsonObj == null) { - LOG.error("ModuleJsonUtil::parseStageInstallation jsonObj is null."); - throw new BundleException("ModuleJsonUtil::parseStageInstallation jsonObj is null."); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("jsonObj is null.")); + throw new BundleException("Parse jsonObj is null."); } JSONObject moduleObj = jsonObj.getJSONObject(MODULE); if (moduleObj == null) { - LOG.error("ModuleJsonUtil::parseStageInstallation json do not contain module."); - throw new BundleException("ModuleJsonUtil::parseStageInstallation json do not contain module."); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("--json-path file do not contain module.")); + throw new BundleException("json file do not contain module."); } return moduleObj; } @@ -1492,8 +1507,8 @@ class ModuleJsonUtil { JSONObject moduleObj = getModuleObj(jsonString); JSONObject distroObj = moduleObj.getJSONObject(DISTRO); if (distroObj == null) { - LOG.error("ModuleJsonUtil::parseStageInstallation json do not contain distro."); - throw new BundleException("ModuleJsonUtil::parseStageInstallation json do not contain distro."); + LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString("The config.json do not contain distro.")); + throw new BundleException("Parse FA installationFree json do not contain distro."); } if (distroObj.containsKey(INSTALLATION_FREE)) { return distroObj.getBoolean(INSTALLATION_FREE); @@ -1700,8 +1715,8 @@ class ModuleJsonUtil { try { jsonObject = JSON.parseObject(jsonString); } catch (JSONException exception) { - LOG.error("parse JOSNObject failed in getStageApiReleaseType."); - throw new BundleException("parse JOSNObject failed in getStageApiReleaseType."); + PackingToolErrMsg.PARSE_JSON_FAILED.toString("Parse json object failed when get debug in config.json. JSONException: " + exception.getMessage()); + throw new BundleException("parse JSONObject failed when get debug in config.json."); } JSONObject deviceConfigObj = jsonObject.getJSONObject(DEVICE_CONFIG); if (deviceConfigObj == null) { @@ -1842,13 +1857,15 @@ class ModuleJsonUtil { try { jsonObject = JSON.parseObject(jsonString); } catch (JSONException exception) { - LOG.error("parse JOSNObject failed in isExistedProperty."); - throw new BundleException("parse JOSNObject failed in isExistedProperty."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString( + "Parse json for existence of property, exist JSONException: " + exception.getMessage())); + throw new BundleException("Parse JSONObject 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 + "."); - throw new BundleException("parse failed, input module.json is invalid, module.json has no " + + 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 + "."); } return appObj.containsKey(childProperty); @@ -1899,7 +1916,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_MODULE_ATOMIC_SERVICE_FAILED.toString(errMsg)); return false; } return true; @@ -1916,7 +1934,9 @@ class ModuleJsonUtil { return true; } if (parseModuleType(jsonString).equals(ENTRY) && parseAbilityNames(jsonString).isEmpty()) { - LOG.error("entry module must contain at least one ability."); + String moduleName = parseStageModuleName(jsonString); + String errMsg = "Entry module(" + moduleName +") must contain at least one ability."; + LOG.error(PackingToolErrMsg.CHECK_LEASTONE_ABILITY.toString(errMsg)); return false; } return true; @@ -1936,9 +1956,9 @@ class ModuleJsonUtil { boolean installationFree = getJsonBooleanValue(moduleObj, INSTALLATION_FREE, false); if (!appObj.containsKey(BUNDLE_TYPE)) { 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); + String errMsg = "The app.json5 file configuration does not match the installationFree true settings."; + String solution = "Add the bundleType field to the app.json5 file and set it atomicService."; + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString(errMsg, solution)); return false; } return true; @@ -1946,26 +1966,38 @@ class ModuleJsonUtil { String bundleType = getJsonString(appObj, BUNDLE_TYPE); if (bundleType.equals(APP)) { if (installationFree) { - LOG.error("installationFree must be false when bundleType is app."); + String errMsg = "installationFree must be false when bundleType is app."; + String solution = "Set 'installationFree' to false in the module configuration when 'bundleType' is 'app'."; + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString(errMsg, solution)); return false; } } else if (bundleType.equals(ATOMIC_SERVICE)) { if (!installationFree) { - LOG.error("installationFree must be true when bundleType is atomicService."); + String errMsg = "installationFree must be true when bundleType is atomicService."; + String solution = "Set 'installationFree' to true in the module configuration when 'bundleType'" + + "is 'atomicService'."; + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString(errMsg, solution)); return false; } } else if (SHARED.equals(bundleType)) { if (installationFree) { - LOG.error("installationFree must be false when bundleType is shared."); + String errMsg = "installationFree must be false when bundleType is shared."; + String solution = "Set 'installationFree' to false in the module configuration when 'bundleType' is 'shared'."; + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString(errMsg, solution)); return false; } } else if (APP_SERVICE.equals(bundleType)) { if (installationFree) { - LOG.error("installationFree must be false when bundleType is appService."); + String errMsg = "installationFree must be false when bundleType is appService."; + String solution = "Set 'installationFree' to false in the module configuration when 'bundleType' is 'appService'."; + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString(errMsg, solution)); return false; } } else { - LOG.error("bundleType is invalid in app.json."); + String errMsg = "bundleType is invalid in app.json."; + String solution = "Ensure that the 'bundleType' field in the app.json file is correctly set to one of " + + "the valid types: 'app', 'atomicService', 'shared', or 'appService'."; + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString(errMsg, solution)); return false; } return true; diff --git a/adapter/ohos/PackingToolErrMsg.java b/adapter/ohos/PackingToolErrMsg.java new file mode 100644 index 00000000..73fa4e21 --- /dev/null +++ b/adapter/ohos/PackingToolErrMsg.java @@ -0,0 +1,919 @@ +/* + * 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; + +/** + * PackingToolErrMsg + * + * @since 2025/01/21 + */ +public class PackingToolErrMsg { + + // packing tool error + /** + * EXECUTE_PACKING_TOOL_FAILED + */ + public static final ErrorMsg EXECUTE_PACKING_TOOL_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("10") + .setErrCode("001") + .setDescription("Execute packing tool failed.") + .setCause("%s") + .addSolution("Please check the first error message for more details and modify accordingly.") + .build(); + + /** + * COMMAND_PARSER_FAILED + */ + public static final ErrorMsg COMMAND_PARSER_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("10") + .setErrCode("002") + .setDescription("Command parser failed.") + .setCause("%s") + .build(); + + /** + * COMMAND_VERIFY_FAILED + */ + public static final ErrorMsg COMMAND_VERIFY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("10") + .setErrCode("003") + .setDescription("Command verify failed.") + .setCause("%s") + .build(); + + // compress verify error + /** + * HAP_MODE_ARGS_INVALID + */ + public static final ErrorMsg HAP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("001") + .setDescription("Parse and check args invalid in hap mode.") + .setCause("%s") + .build(); + + /** + * HSP_MODE_ARGS_INVALID + */ + public static final ErrorMsg HSP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("002") + .setDescription("Parse and check args invalid in hsp mode.") + .setCause("%s") + .build(); + + /** + * APP_MODE_ARGS_INVALID + */ + public static final ErrorMsg APP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("003") + .setDescription("Parse and check args invalid in app mode.") + .setCause("%s") + .build(); + + /** + * COMMAND_MODE_INVALID + */ + public static final ErrorMsg COMMAND_MODE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("011") + .setDescription("Command verify mode is invalid.") + .setCause("Input mode is invalid.") + .build(); + + /** + * BUNDLE_TYPE_SHARED_INVALID + */ + public static final ErrorMsg BUNDLE_TYPE_SHARED_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("012") + .setDescription("Check bundleType is shared failed.") + .setCause("%s") + .build(); + + /** + * BUNDLE_TYPE_APPSERVICE_INVALID + */ + public static final ErrorMsg BUNDLE_TYPE_APPSERVICE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("013") + .setDescription("Check BundleTypeAppService invalid.") + .setCause("%s") + .build(); + + /** + * HSP_HAS_ABILITIES_FAILED + */ + public static final ErrorMsg HSP_HAS_ABILITIES_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("014") + .setDescription("Check hsp has abilities failed.") + .setCause("%s") + .build(); + + /** + * HSP_HAS_EXTENSION_ABILITIES_FAILED + */ + public static final ErrorMsg HSP_HAS_EXTENSION_ABILITIES_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("015") + .setDescription("Check hsp has extension abilities failed.") + .setCause("%s") + .build(); + + /** + * HAS_HOME_ABILITY_INVALID + */ + public static final ErrorMsg HAS_HOME_ABILITY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("016") + .setDescription("Check hsp has entry abilitiy failed.") + .setCause("%s") + .build(); + + /** + * HAS_HOME_EXTENSION_ABILITY_INVALID + */ + public static final ErrorMsg HAS_HOME_EXTENSION_ABILITY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("017") + .setDescription("Check hsp has entry ExtensionAbility failed.") + .setCause("%s") + .build(); + + /** + * OUT_PATH_INVALID + */ + public static final ErrorMsg OUT_PATH_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("018") + .setDescription("Invalid output path.") + .setCause("%s") + .build(); + + // compress process error + /** + * COMPRESS_PROCESS_FAILED + */ + public static final ErrorMsg COMPRESS_PROCESS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("001") + .setDescription("Execute compress process failed.") + .setCause("%s") + .addSolution("%s") + .build(); + + /** + * COMPRESS_HAP_FAILED + */ + public static final ErrorMsg COMPRESS_HAP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("002") + .setDescription("Compress Stage Hap failed.") + .setCause("%s") + .addSolution("Please check the first error message for more details and modify accordingly.") + .build(); + + /** + * CHECK_STAGE_HAP_FAILED + */ + public static final ErrorMsg CHECK_STAGE_HAP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("003") + .setDescription("Verify stage hap info failed.") + .setCause("%s") + .addSolution("Please check the first error message for more details and modify accordingly.") + .build(); + + /** + * CHECK_AS_TSAN_ENABLED + */ + public static final ErrorMsg CHECK_AS_TSAN_ENABLED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("004") + .setDescription("Check asanEnabled failed.") + .setCause("%s") + .addSolution("Please ensure the parameters are correctly set. " + + "Review 'app.json' and adjust the configuration as needed.") + .build(); + + /** + * CHECK_HWASAN_ENABLED_INVALID + */ + public static final ErrorMsg CHECK_HWASAN_ENABLED_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("005") + .setDescription("Check hwasanEnabled failed.") + .setCause("%s") + .addSolution("Please ensure the parameters are correctly set. " + + "Review 'app.json' and adjust the configuration as needed.") + .build(); + + /** + * CHECK_ATOMIC_SERVICE_FAILED + */ + public static final ErrorMsg CHECK_ATOMIC_SERVICE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("006") + .setDescription("Check atomicService failed.") + .setCause("%s") + .addSolution("Please check the first error message for more details and modify accordingly.") + .build(); + + /** + * CHECK_CONTINUE_BUNDLENAME_INVALID + */ + public static final ErrorMsg CHECK_CONTINUE_BUNDLENAME_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("007") + .setDescription("Check continueBundleName invalid.") + .setCause("%s") + .addSolution("Ensure continueBundleName not inclue self.") + .build(); + + /** + * CHECK_OVERLAY_CFG_FAILED + */ + public static final ErrorMsg CHECK_OVERLAY_CFG_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("008") + .setDescription("Check whether is an overlay hsp failed.") + .setCause("%s") + .addSolution("Please check 'app.json5' and 'module.json5' file according to the error.") + .addSolution("Check targetBundleName, targetModuleName, and targetPriority in the related module.") + .addSolution("Note: Modules configured with the targetModuleName is overlay feature module.") + .addSolution("Note: Modules configured with the targetBundleName is overlay feature application.") + .build(); + + /** + * COMPRESS_PROCESS_EXCEPTION + */ + public static final ErrorMsg COMPRESS_PROCESS_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("009") + .setDescription("Process compress exception.") + .setCause("%s") + .addSolution("Please check the first error message for more details and modify accordingly.") + .build(); + + /** + * HAS_GENERATE_BUILD_HASH + */ + public static final ErrorMsg HAS_GENERATE_BUILD_HASH = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("010") + .setDescription("Verify has generate build hash failed.") + .setCause("%s") + .build(); + + /** + * SET_GENERATE_BUILD_HASH + */ + public static final ErrorMsg SET_GENERATE_BUILD_HASH = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("011") + .setDescription("Set generate build hash failed.") + .setCause("%s") + .build(); + + /** + * CHECK_UBASAN_ENABLED_INVALID + */ + public static final ErrorMsg CHECK_UBASAN_ENABLED_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("012") + .setDescription("Check ubsanEnabled failed.") + .setCause("%s") + .addSolution("Please ensure the parameters are correctly set. " + + "Review 'app.json' and adjust the configuration as needed.") + .build(); + + /** + * READ_STAGE_HAP_VERIFY_INFO_FAILED + */ + public static final ErrorMsg READ_STAGE_HAP_VERIFY_INFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("013") + .setDescription("Read stage hap verify info io exception.") + .setCause("%s") + .addSolution("Please check the exception message for more details and modify accordingly.") + .build(); + + /** + * COMPRESS_PARALLEL_EXCEPTION + */ + public static final ErrorMsg COMPRESS_PARALLEL_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("014") + .setDescription("Parallel compress exception.") + .setCause("%s") + .addSolution("Please check the related expection message and modify the operation.") + .build(); + + /** + * COMPRESS_APP_FAILED + */ + public static final ErrorMsg COMPRESS_APP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("015") + .setDescription("Compress app file failed.") + .setCause("%s") + .addSolution("Please check the first error message for more details and modify accordingly.") + .build(); + + /** + * INVALID_HAP_FILE + */ + public static final ErrorMsg INVALID_HAP_FILE = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("016") + .setDescription("check input hap or hsp file is invalid.") + .setCause("%s") + .build(); + + /** + * CHECK_SHARED_APP_INVALID + */ + public static final ErrorMsg CHECK_SHARED_APP_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("017") + .setDescription("Check shared App mode invalid.") + .setCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_BUNDLETYPE_INVALID + */ + public static final ErrorMsg CHECK_BUNDLETYPE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("018") + .setDescription("Check bundleType is invalid.") + .setCause("%s") + .addSolution("%s") + .build(); + + /** + * APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID + */ + public static final ErrorMsg APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("019") + .setDescription("Check app atomicservice compress size failed.") + .setCause("%s") + .build(); + + /** + * READ_FA_HAP_VERIFY_INFO_FAILED + */ + public static final ErrorMsg READ_FA_HAP_VERIFY_INFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("020") + .setDescription("Read FA hap verify info io exception.") + .setCause("%s") + .addSolution("Please check the first error message for more details and modify accordingly.") + .build(); + + /** + * COMPRESS_APP_IO_EXCEPTION + */ + public static final ErrorMsg COMPRESS_APP_IO_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("021") + .setDescription("IO exception when compress app.") + .setCause("%s") + .addSolution("Please check the related expection message and modify the operation.") + .build(); + + /** + * COMPRESS_HSP_FAILED + */ + public static final ErrorMsg COMPRESS_HSP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("022") + .setDescription("Compress Hsp failed.") + .setCause("%s") + .addSolution("Please check the first error message for more details and modify accordingly.") + .build(); + + /** + * JSON_SPECIAL_PROCESS_FAILED + */ + public static final ErrorMsg JSON_SPECIAL_PROCESS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("023") + .setDescription("Json special process exist exception.") + .setCause("%s") + .addSolution("Please check the expection message and modify.") + .build(); + + /** + * CHECK_ATOMIC_SERVICE_SIZE_FAILED + */ + public static final ErrorMsg CHECK_ATOMIC_SERVICE_SIZE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("024") + .setDescription("Atomic service size check failed.") + .setCause("%s") + .addSolution("Please check the related size check error message and reduce related module size.") + .build(); + + // module json check error + /** + * PARSE_JSON_OBJECT_EXCEPTION + */ + public static final ErrorMsg PARSE_JSON_OBJECT_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("13") + .setErrCode("001") + .setDescription("Parse json Object expection.") + .setCause("%s") + .build(); + + /** + * PARSE_JSON_FAILED + */ + public static final ErrorMsg PARSE_JSON_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("13") + .setErrCode("002") + .setDescription("Parse json profile failed.") + .setCause("%s") + .build(); + + /** + * CHECK_MODULE_ATOMIC_SERVICE_FAILED + */ + public static final ErrorMsg CHECK_MODULE_ATOMIC_SERVICE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("13") + .setErrCode("003") + .setDescription("Check module atomicService invalid.") + .setCause("%s") + .build(); + + /** + * PARSE_STAGE_JSON_FAILED + */ + public static final ErrorMsg PARSE_STAGE_JSON_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("13") + .setErrCode("004") + .setDescription("Failed to parse module.json for stage module.") + .setCause("%s") + .build(); + + /** + * PARSE_STAGE_BUNDLE_TYPE_FAILED + */ + public static final ErrorMsg PARSE_STAGE_BUNDLE_TYPE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("13") + .setErrCode("005") + .setDescription("Failed to parse module.json and bundleType.") + .setCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_LEASTONE_ABILITY + */ + public static final ErrorMsg CHECK_LEASTONE_ABILITY = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("13") + .setErrCode("006") + .setDescription("Check entry module at least one ability failed.") + .setCause("%s") + .addSolution("Ensure the entry type module contains at least one ability.") + .build(); + + /** + * CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED + */ + public static final ErrorMsg CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("13") + .setErrCode("007") + .setDescription("Check module atomicService installationFree invalid.") + .setCause("%s") + .addSolution("%s") + .build(); + + /** + * PARSE_BUNDLE_NAME_FAILED + */ + public static final ErrorMsg PARSE_BUNDLE_NAME_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("13") + .setErrCode("008") + .setDescription("Get the bundleName from json file failed.") + .setCause("%s") + .build(); + + /** + * PARSE_PROXY_DATA_URI_FAILED + */ + public static final ErrorMsg PARSE_PROXY_DATA_URI_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("13") + .setErrCode("009") + .setDescription("Failed to parse module.json and proxyData object.") + .setCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_BUNDLETYPE_CONSISTENCY_FAILED + */ + public static final ErrorMsg CHECK_BUNDLETYPE_CONSISTENCY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("13") + .setErrCode("010") + .setDescription("BundleType consistency check failed.") + .setCause("%s") + .addSolution("Make sure the bundleType is consistency for different modules.") + .build(); + + /** + * PARSE_PATCH_MODULE_NAME_FAILED + */ + public static final ErrorMsg PARSE_PATCH_MODULE_NAME_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("13") + .setErrCode("011") + .setDescription("Failed to parse patch module name from patch.json.") + .setCause("%s") + .build(); + + /** + * PARSE_FA_HAP_VERIFY_INFO_FAILED + */ + public static final ErrorMsg PARSE_FA_HAP_VERIFY_INFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("13") + .setErrCode("012") + .setDescription("Failed to parse FA hap verify info from config.json.") + .setCause("%s") + .build(); + + /** + * PARSE_FA_JSON_FAILED + */ + public static final ErrorMsg PARSE_FA_JSON_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("13") + .setErrCode("013") + .setDescription("Failed to parse config.json for FA module.") + .setCause("%s") + .build(); + + // file operator error + /** + * FILE_NOT_FOUND + */ + public static final ErrorMsg FILE_NOT_FOUND = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("001") + .setDescription("File avaiable not found exception.") + .setCause("%s") + .addSolution("Please check the related FileNotFoundException message.") + .addSolution("If the file is in use, close any applications or processes that might be using it.") + .build(); + + /** + * CLOSE_ZIP_OUTPUT_STREAM_EXPECTION + */ + public static final ErrorMsg CLOSE_ZIP_OUTPUT_STREAM_EXPECTION = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("002") + .setDescription("close zip output stream exception.") + .setCause("%s") + .addSolution("Please check the related error message and modify the operation.") + .build(); + + /** + * CLOSE_STREAM_EXPECTION + */ + public static final ErrorMsg CLOSE_STREAM_EXPECTION = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("003") + .setDescription("IO exception when closing stream.") + .setCause("%s") + .build(); + + /** + * GET_FILE_CONTENT_FAILED + */ + public static final ErrorMsg GET_FILE_CONTENT_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("004") + .setDescription("Get file content failed.") + .setCause("%s") + .addSolution("Please check the related expection message for more details and modify accordingly.") + .build(); + + /** + * FILE_NOT_EXIST + */ + public static final ErrorMsg FILE_NOT_EXIST = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("005") + .setDescription("Parse file not exist.") + .setCause("%s") + .build(); + + /** + * GET_FILE_SIZE_FAILED + */ + public static final ErrorMsg GET_FILE_SIZE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("006") + .setDescription("Get file size failed.") + .setCause("%s") + .build(); + + /** + * FILE_IO_EXCEPTION + */ + public static final ErrorMsg FILE_IO_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("007") + .setDescription("File IO exception.") + .setCause("%s") + .addSolution("1. Ensure the file path is correct and the file exists.") + .addSolution("2. Verify you have the necessary permissions to access the file.") + .addSolution("3. Check for possible disk or file system errors.") + .addSolution("4. Review the related IOException message for further insights.") + .build(); + + /** + * COMPRESS_FILE_EXCEPTION + */ + public static final ErrorMsg COMPRESS_FILE_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("008") + .setDescription("Compress file exception.") + .setCause("%s") + .addSolution("Please check the related exception message and modify.") + .build(); + + /** + * FILE_DELETE_FAILED + */ + public static final ErrorMsg FILE_DELETE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("009") + .setDescription("File delete failed.") + .setCause("%s") + .addSolution("%s") + .addSolution("Verify you have the necessary permissions to delete the file.") + .build(); + + // io exception + /** + * IO_EXCEPTION + */ + public static final ErrorMsg IO_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("15") + .setErrCode("001") + .setDescription("IO exception.") + .setCause("%s") + .addSolution("1. Ensure the file path is correct and the file exists.") + .addSolution("2. Verify you have the necessary permissions to access the file.") + .addSolution("3. Check for possible disk or file system errors.") + .addSolution("4. Review the related error message for further insights.") + .build(); + + /* + * NULL_POINTER_EXPECTION + */ + public static final ErrorMsg NULL_POINTER_EXPECTION = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("15") + .setErrCode("002") + .setDescription("Null pointer exception.") + .setCause("%s") + .addSolution("Please review the related error message for further insights.") + .build(); + + // hap verify error + /** + * CHECK_APP_FIELDS_INVALID + */ + public static final ErrorMsg CHECK_APP_FIELDS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("001") + .setDescription("App fields is invalid.") + .setCause("%s") + .addSolution("%s") + .build(); + + /** + * APP_FIELDS_DIFFERENT_ERROR + */ + public static final ErrorMsg APP_FIELDS_DIFFERENT_ERROR = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("002") + .setDescription("Some app variable is different.") + .setCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_POLICY_DISJOINT_ERROR + */ + public static final ErrorMsg CHECK_POLICY_DISJOINT_ERROR = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("003") + .setDescription("Check two distroFilter policy disjoint invalid.") + .setCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_MODULE_NAME_INVALID + */ + public static final ErrorMsg CHECK_MODULE_NAME_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("004") + .setDescription("Check module name is invalid.") + .setCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_PACKAGE_NAME_INVALID + */ + public static final ErrorMsg CHECK_PACKAGE_NAME_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("005") + .setDescription("Check packageName invalid.") + .setCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_HAP_INVALID + */ + public static final ErrorMsg CHECK_HAP_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("006") + .setDescription("Verify hap info is invalid.") + .setCause("%s") + .addSolution("Please check the first error message for more details and modify accordingly.") + .build(); + + /** + * CHECK_ENTRY_INVALID + */ + public static final ErrorMsg CHECK_ENTRY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("007") + .setDescription("Check entry module invalid.") + .setCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_DEPENDENCY_INVALID + */ + public static final ErrorMsg CHECK_DEPENDENCY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("008") + .setDescription("Check dependency is invalid.") + .setCause("%s") + .addSolution("%s") + .build(); + + /** + * DEPENDENCY_LIST_INVALID + */ + public static final ErrorMsg DEPENDENCY_LIST_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("009") + .setDescription("Check dependency list is invalid.") + .setCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_ATOMICSERVICE_INVALID + */ + public static final ErrorMsg CHECK_ATOMICSERVICE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("010") + .setDescription("Check atomicservice is invalid.") + .setCause("%s") + .addSolution("Please check the first error message for more details and modify accordingly.") + .build(); + + /** + * ATOMICSERVICE_PRELOADS_INVALID + */ + public static final ErrorMsg ATOMICSERVICE_PRELOADS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("011") + .setDescription("Atomicservice preloads is invalid.") + .setCause("%s") + .addSolution("Please check related error message and modify preloads settings.") + .build(); + + /** + * TARGET_MODULE_NAME_NOT_EXIST + */ + public static final ErrorMsg TARGET_MODULE_NAME_NOT_EXIST = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("012") + .setDescription("Target moduleName is not exist.") + .setCause("%s") + .addSolution("Make sure pack with vaild and existing target module.") + .addSolution("Create missing modules or check target moduleName whether valid.") + .build(); + + /** + * COMPILE_SDK_TYPE_DIFFERENT + */ + public static final ErrorMsg COMPILE_SDK_TYPE_DIFFERENT = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("013") + .setDescription("CompileSdkType is different.") + .setCause("%s") + .addSolution("%s") + .build(); + + /** + * PROXY_DATA_URI_NOT_UNIQUE + */ + public static final ErrorMsg PROXY_DATA_URI_NOT_UNIQUE = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("014") + .setDescription("Proxy data uri is not unique.") + .setCause("%s") + .addSolution("%s") + .build(); + + /** + * CONTINUE_TYPE_INVALID + */ + public static final ErrorMsg CONTINUE_TYPE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("015") + .setDescription("Check continueType is invalid.") + .setCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_FILE_SIZE_INVALID + */ + public static final ErrorMsg CHECK_FILE_SIZE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("016") + .setDescription("Check file size failed.") + .setCause("%s") + .addSolution("Please check and reduced related module size.") + .build(); + + /** + * CHECK_HAP_VERIFY_INFO_LIST_EMPTY + */ + public static final ErrorMsg CHECK_HAP_VERIFY_INFO_LIST_EMPTY = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("017") + .setDescription("The provided list of HapVerifyInfo is empty, unable to process.") + .setCause("Input list of HapVerifyInfo is empty.") + .build(); + + /** + * CHECK_ATOMIC_SERVICE_MODULE_SIZE + */ + public static final ErrorMsg CHECK_ATOMIC_SERVICE_MODULE_SIZE = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("018") + .setDescription("AtomicService module size check failed.") + .setCause("%s") + .addSolution("Please check and reduced related module size.") + .build(); + + /** + * CHECK_FEATURE_DISTRO_FILTER_INVALID + */ + public static final ErrorMsg CHECK_FEATURE_DISTRO_FILTER_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("019") + .setDescription("Check feature module distributionFilter is invalid.") + .setCause("%s") + .addSolution("Ensure the Entry type module distributionFilter file policy " + + "settings is 'exclude' or 'include'.") + .build(); + + /** + * HAP_VERIFY_INFO_NULL + */ + public static final ErrorMsg HAP_VERIFY_INFO_EMPTY = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("020") + .setDescription("Hap verify infos is empty.") + .setCause("%s") + .build(); +} diff --git a/adapter/ohos/Utility.java b/adapter/ohos/Utility.java index 1987c3d2..ecf5266e 100644 --- a/adapter/ohos/Utility.java +++ b/adapter/ohos/Utility.java @@ -721,7 +721,8 @@ public class Utility { try { stream.close(); } catch (IOException exception) { - LOG.error("Utility::closeStream io close exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.CLOSE_STREAM_EXPECTION.toString( + "Close stream exist IOException: " + exception.getMessage())); } } } diff --git a/build.py b/build.py index 12049106..1a59283e 100755 --- a/build.py +++ b/build.py @@ -49,9 +49,11 @@ def compile_haptobin_tool(root_path, src_path, jar_output, out_path, 'BinaryTool.java', 'BundleException.java', 'ConvertHapToBin.java', + 'ErrorMsg.java', 'FileUtils.java', 'Log.java', - 'PackFormatter.java', + 'PackFormatter.java', + 'PackingToolErrMsg.java', 'Utility.java' ] compile_java = get_compile_str(src_path, java_sources) @@ -72,7 +74,7 @@ def compile_unpacking_tool(root_path, src_path, jar_output, out_path, big_versio 'BundleException.java', 'CommandParser.java', 'CommonEvent.java', 'CountryCode.java', 'CustomizeData.java', 'DefinePermission.java', 'DefPermissionGroup.java', 'DefPermission.java', 'DependencyItem.java', - 'DeviceConfig.java', 'DistroFilter.java', 'Distro.java', + 'DeviceConfig.java', 'DistroFilter.java', 'Distro.java', 'ErrorMsg.java', 'ExtensionAbilityInfo.java', 'FileUtils.java', 'FormInfo.java', 'HapInfo.java', 'HapZipInfo.java', 'HQFInfo.java', 'IntentInfo.java', 'JsInfo.java', 'JsonUtil.java', @@ -80,7 +82,7 @@ def compile_unpacking_tool(root_path, src_path, jar_output, out_path, big_versio 'ModuleAbilityInfo.java', 'ModuleAdaption.java', 'ModuleAppInfo.java', 'ModuleAtomicService.java', 'ModuleDeviceType.java', 'ModuleInfo.java', 'ModuleMetadataInfo.java', 'ModuleProfileInfo.java', 'ModuleResult.java', - 'ModuleShortcut.java', 'PackFormatter.java', 'PackInfo.java', + 'ModuleShortcut.java', 'PackFormatter.java', 'PackInfo.java', 'PackingToolErrMsg.java', 'PreloadItem.java', 'ProfileInfo.java', 'ReqPermission.java', 'ResourceIndexResult.java', 'ResourcesParser.java', 'ScreenDensity.java', 'ScreenShape.java', 'ScreenWindow.java', 'Shortcut.java', @@ -111,6 +113,7 @@ def compile_packing_tool(root_path, src_path, jar_output, out_path, 'CountryCode.java', 'DependencyItem.java', 'DistroFilter.java', + 'ErrorMsg.java', 'FileUtils.java', 'HapVerify.java', 'HapVerifyInfo.java', @@ -125,6 +128,7 @@ def compile_packing_tool(root_path, src_path, jar_output, out_path, 'PackageNormalize.java', 'PackageUtil.java', 'PackFormatter.java', + 'PackingToolErrMsg.java', 'PreloadItem.java', 'ScreenDensity.java', 'ScreenShape.java', @@ -149,9 +153,11 @@ def compile_check_tool(root_path, src_path, jar_output, out_path, java_sources = [ 'BundleException.java', 'CommandParser.java', + 'ErrorMsg.java', 'FileUtils.java', 'Log.java', 'PackFormatter.java', + 'PackingToolErrMsg.java', 'Scan.java', 'ScanEntrance.java', 'ScanErrorEnum.java', -- Gitee From cf523f61af930eb26880678399ddec150a7ab87e Mon Sep 17 00:00:00 2001 From: nj1868 Date: Wed, 5 Mar 2025 18:32:26 +0800 Subject: [PATCH 2/2] update Signed-off-by: nj1868 Change-Id: I365a251dc7b2482794f7d18d11c3431f3c958f5e --- adapter/ohos/CommandParser.java | 4 +- adapter/ohos/CompressVerify.java | 22 ++-- adapter/ohos/Compressor.java | 121 +++++++++++---------- adapter/ohos/FileUtils.java | 4 +- adapter/ohos/HapVerify.java | 156 +++++++++++++--------------- adapter/ohos/ModuleJsonUtil.java | 90 ++++++++-------- adapter/ohos/PackingToolErrMsg.java | 82 +++++++-------- adapter/ohos/Utility.java | 2 +- 8 files changed, 229 insertions(+), 252 deletions(-) diff --git a/adapter/ohos/CommandParser.java b/adapter/ohos/CommandParser.java index e04c0c3b..0a957d8c 100644 --- a/adapter/ohos/CommandParser.java +++ b/adapter/ohos/CommandParser.java @@ -362,14 +362,14 @@ 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; } }); diff --git a/adapter/ohos/CompressVerify.java b/adapter/ohos/CompressVerify.java index c0a1bb58..83256f75 100644 --- a/adapter/ohos/CompressVerify.java +++ b/adapter/ohos/CompressVerify.java @@ -241,7 +241,7 @@ public class CompressVerify { return false; } if (!RPCID_PROFILE.equals(file.getName())) { - String errMsg = "--rpcid-path must be rpcid.sc file."; + String errMsg = "--rpcid-path must be the rpcid.sc file."; LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -258,7 +258,7 @@ public class CompressVerify { return false; } if (!PACK_INFO.equals(file.getName())) { - String errMsg = "--pack-info-path must be pack.info file."; + String errMsg = "--pack-info-path must be the pack.info file."; LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -274,7 +274,7 @@ public class CompressVerify { } if (!isPathValid(utility.getJsonPath(), TYPE_FILE, JSON_PROFILE) && !isPathValid(utility.getJsonPath(), TYPE_FILE, MODULE_PROFILE)) { - String errMsg = "--json-path must be config.json file."; + String errMsg = "--json-path must be the config.json file or module.json file."; LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -293,7 +293,7 @@ public class CompressVerify { if (!utility.getProfilePath().isEmpty()) { File file = new File(utility.getProfilePath()); if (!file.isFile() || !PROFILE_NAME.equals(file.getName())) { - String errMsg = "--profile-path must be CAPABILITY.profile file."; + String errMsg = "--profile-path must be the CAPABILITY.profile file."; LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -322,7 +322,7 @@ public class CompressVerify { if (!utility.getPkgContextPath().isEmpty()) { File file = new File(utility.getPkgContextPath()); if (!file.isFile() || !PKG_CONTEXT_INFO.equals(file.getName())) { - String errMsg = "--pkg-context-path file must be " + PKG_CONTEXT_INFO + "."; + String errMsg = "--pkg-context-path file must be the pkgContextInfo.json file."; LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -339,7 +339,7 @@ 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())) { - String errMsg = "--index-path must be resources.index file."; + String errMsg = "--index-path must be the resources.index file."; LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -500,7 +500,7 @@ public class CompressVerify { */ private static boolean isVerifyValidInAppMode(Utility utility) { if (!checkBundleTypeConsistency(utility)) { - String errMsg = "Check bundleType is inconsistent."; + String errMsg = "The bundleType is inconsistent for different HAP and HSP modules."; LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -588,7 +588,7 @@ public class CompressVerify { HapVerifyInfo hapVerifyInfo = Compressor.parseStageHapVerifyInfo(hapPath); if (!bundleType.equals(hapVerifyInfo.getBundleType())) { LOG.error(PackingToolErrMsg.CHECK_BUNDLETYPE_CONSISTENCY_FAILED.toString( - "bundleType is not same for different hap modules.")); + "The bundleType is not same for different HAP modules.")); return false; } } @@ -596,7 +596,7 @@ public class CompressVerify { HapVerifyInfo hapVerifyInfo = Compressor.parseStageHapVerifyInfo(hspPath); if (!bundleType.equals(hapVerifyInfo.getBundleType())) { LOG.error(PackingToolErrMsg.CHECK_BUNDLETYPE_CONSISTENCY_FAILED.toString( - "bundleType is not same for different hsp modules.")); + "The bundleType is not same for different HSP modules.")); return false; } } @@ -959,7 +959,7 @@ public class CompressVerify { } if (!isPathValid(utility.getJsonPath(), TYPE_FILE, MODULE_PROFILE)) { - String errMsg = "--json-path must be module.json file."; + String errMsg = "--json-path must be the module.json file."; LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -1052,7 +1052,7 @@ public class CompressVerify { if (!utility.getPkgContextPath().isEmpty()) { File file = new File(utility.getPkgContextPath()); if (!file.isFile() || !PKG_CONTEXT_INFO.equals(file.getName())) { - String errMsg = "--pkg-context-path file must be "+ PKG_CONTEXT_INFO; + String errMsg = "--pkg-context-path file must be the pkgContextInfo.json file."; LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index 068db3df..e4a74a8f 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -348,7 +348,7 @@ public class Compressor { File outParentFile = destFile.getParentFile(); if ((outParentFile != null) && (!outParentFile.exists())) { if (!outParentFile.mkdirs()) { - String errMsg = "Create out file parent directory failed."; + String errMsg = "Create output file's parent directory failed."; String solution = "Check the --out-path parameter."; LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_FAILED.toString(errMsg, solution)); return false; @@ -368,7 +368,7 @@ public class Compressor { LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("Compress exist FileNotFoundException: " + exception.getMessage())); } catch (BundleException ex) { compressResult = false; - LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_EXCEPTION.toString("BundleException: " + ex.getMessage())); + LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_EXCEPTION.toString("Compress exist BundleException: " + ex.getMessage())); } finally { closeZipOutputStream(); Utility.closeStream(zipOut); @@ -385,12 +385,12 @@ public class Compressor { // if compress failed, delete out file. if (!compressResult) { - String errMsg = "Execute compress failed."; + String errMsg = "Compress process failed."; String solution = "Please check the first error message for more details and modify accordingly."; LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_FAILED.toString(errMsg, solution)); if (!destFile.delete()) { - errMsg = "Delete out file " + utility.getOutPath() + " failed."; - solution = "Try to close the out file using programme."; + errMsg = "Delete the output file " + utility.getOutPath() + " failed."; + solution = "Try to close the output file using programme."; LOG.error(PackingToolErrMsg.FILE_DELETE_FAILED.toString(errMsg, solution)); } } @@ -434,35 +434,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 Stage AsanTsanEnabled valid 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 Stage HwasanEnabled valid 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 Stage UbsanEnabled valid 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 Stage AtomicService 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 ContinueBundleName is valid 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 Stage overlay config failed.")); - throw new BundleException("Check stage OverlayCfg 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); if (!TYPE_SHARED.equals(moduleType)) { LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Module type must be shared.")); - throw new BundleException("compressHsp failed."); + throw new BundleException("Compress hsp failed."); } } compressHSPMode(utility); @@ -521,11 +521,11 @@ public class Compressor { res = true; } } catch (BundleException exception) { - LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString("Check 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( - "Check has generate build hash exist Exception(JSONException | IOException): " + e.getMessage())); + "Verify has generate build hash exist Exception(JSONException | IOException): " + e.getMessage())); throw new BundleException("Verify has generate build hash failed."); } finally { FileUtils.closeStream(json); @@ -541,7 +541,7 @@ public class Compressor { copyFileToTempDir(utility); File file = new File(utility.getJsonPath()); if (!file.exists()) { - String errMsg = "Parse --json-path file does not exist."; + String errMsg = "The --json-path file does not exist."; LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString(errMsg)); throw new BundleException("Set generate build hash failed for --json-path file does not exist."); } @@ -552,7 +552,7 @@ public class Compressor { JSONObject jsonObject = JSON.parseObject(json, JSONObject.class); if (!jsonObject.containsKey(APP) || !jsonObject.containsKey(MODULE)) { LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString("Parse --json-path file is invalid.")); - throw new BundleException("json file is invalid."); + throw new BundleException("The --json-path file is invalid."); } JSONObject appJson = jsonObject.getJSONObject(APP); JSONObject moduleJson = jsonObject.getJSONObject(MODULE); @@ -597,9 +597,9 @@ public class Compressor { String jsonPath = utility.getJsonPath(); File oldfile = new File(jsonPath); if (!oldfile.exists()) { - String errMsg = "Parse json file not found, parse json path is " + jsonPath + "."; + String errMsg = "Parse --json-path file does not found, parse json path is " + jsonPath + "."; LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString(errMsg)); - throw new BundleException("Copy file to temp dir failed for json file not found."); + throw new BundleException("Copy file to temp dir failed for --json-path file not found."); } String oldFileParent = oldfile.getParent(); String tempDir = TEMP_DIR + File.separator + UUID.randomUUID(); @@ -622,7 +622,7 @@ public class Compressor { utility.setJsonPath(tempPath); } catch (IOException e) { LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( - "copy file to temp dir exist IOException:" + e.getMessage())); + "Copy file to temp dir exist IOException:" + e.getMessage())); throw new BundleException("Copy file to temp dir failed."); } } @@ -688,7 +688,7 @@ public class Compressor { String jsonPath = utility.getJsonPath(); File file = new File(jsonPath); if (!file.exists()) { - String errMsg = "Parse json file not found, parse json path is " + jsonPath + "."; + String errMsg = "The --json-path file does not exist."; LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString(errMsg)); throw new BundleException("Put build hash failed for json file not exist."); } @@ -707,7 +707,7 @@ 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_EXPECTION.toString("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); @@ -738,8 +738,7 @@ public class Compressor { } if (hapVerifyInfos.isEmpty()) { - LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString( - "No avaiable hap verify info.")); + LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString("Hap verify infos is empty")); return false; } @@ -766,25 +765,25 @@ 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 Stage AsanTsanEnabled valid 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 Stage HwasanEnabled valid 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 Stage UbsanEnabled valid 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 Stage atomicService 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 ContinueBundleName valid failed.")); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("Check the continueBundleName parameter in the Stage module failed.")); return false; } return true; @@ -795,7 +794,7 @@ public class Compressor { boolean tsanEnabled = ModuleJsonUtil.getStageTsanEnabled(jsonString); if (asanEnabled && tsanEnabled) { LOG.error(PackingToolErrMsg.CHECK_AS_TSAN_ENABLED.toString( - "asanEnabled and tsanEnabled can not be true at the same time.")); + "asanEnabled and tsanEnabled cannot be true at the same time.")); return false; } return true; @@ -808,17 +807,17 @@ public class Compressor { boolean hwasanEnabled = ModuleJsonUtil.getStageHwasanEnabled(jsonString); if (hwasanEnabled && asanEnabled) { LOG.error(PackingToolErrMsg.CHECK_HWASAN_ENABLED_INVALID.toString( - "hwasanEnabled and asanEnabled can not be true at the same time")); + "hwasanEnabled and asanEnabled cannot be true at the same time.")); return false; } if (hwasanEnabled && tsanEnabled) { LOG.error(PackingToolErrMsg.CHECK_HWASAN_ENABLED_INVALID.toString( - "hwasanEnabled and tsanEnabled can not be true at the same time")); + "hwasanEnabled and tsanEnabled cannot be true at the same time.")); return false; } if (hwasanEnabled && gwpAsanEnabled) { LOG.error(PackingToolErrMsg.CHECK_HWASAN_ENABLED_INVALID.toString( - "hwasanEnabled and GWPAsanEnabled can not be true at the same time")); + "hwasanEnabled and GWPAsanEnabled cannot be true at the same time.")); return false; } return true; @@ -851,17 +850,17 @@ public class Compressor { boolean ubsanEnabled = ModuleJsonUtil.getStageUbsanEnabled(jsonString); if (ubsanEnabled && asanEnabled) { LOG.error(PackingToolErrMsg.CHECK_UBASAN_ENABLED_INVALID.toString( - "ubsanEnabled and asanEnabled can not be true at the same time.")); + "ubsanEnabled and asanEnabled cannot be true at the same time.")); return false; } if (ubsanEnabled && tsanEnabled) { LOG.error(PackingToolErrMsg.CHECK_UBASAN_ENABLED_INVALID.toString( - "ubsanEnabled and tsanEnabled can not be true at the same time.")); + "ubsanEnabled and tsanEnabled cannot be true at the same time.")); return false; } if (ubsanEnabled && hwasanEnabled) { LOG.error(PackingToolErrMsg.CHECK_UBASAN_ENABLED_INVALID.toString( - "ubsanEnabled and hwasanEnabled can not be true at the same time.")); + "ubsanEnabled and hwasanEnabled cannot be true at the same time.")); return false; } return true; @@ -876,13 +875,13 @@ public class Compressor { } // check entry module must have ability if (!ModuleJsonUtil.checkEntryInAtomicService(jsonString)) { - LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_FAILED.toString("Check atomicService entry module failed.")); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_FAILED.toString("Check the atomicService entry module failed.")); return false; } // check installationFree if (!ModuleJsonUtil.checkAtomicServiceInstallationFree(jsonString)) { LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_FAILED.toString( - "Check atomicService installationFree failed.")); + "Check the installationFree parameter failed.")); return false; } @@ -903,13 +902,13 @@ public class Compressor { // check targetModuleName and name if (targetModuleName.equals(moduleName)) { LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString( - "The targetModuleName of module (" + moduleName + ") cannot be itself.")); + "The targetModuleName of module(" + moduleName + ") cannot be itself.")); return false; } } else { if (ModuleJsonUtil.isExistedStageModuleTargetPriority(jsonString)) { LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString( - "The module(" + moduleName + ") targetPriority and targetModuleName cannot be configured at the same time.")); + "The targetPriority cannot be existed without the targetModuleName in module.json. The moduleName is " + moduleName + ".")); return false; } } @@ -923,13 +922,13 @@ public class Compressor { } if (targetBundleName.equals(ModuleJsonUtil.parseBundleName(jsonString))) { LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString( - "The module(" + moduleName + ") targetBundleName can not be same with the bundleName.")); + "The module(" + moduleName + ") targetBundleName cannot be same with the bundleName.")); return false; } } else { if (ModuleJsonUtil.isExistedStageAppTargetPriority(jsonString)) { LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString( - "The module(" + moduleName + ") targetPriority can not be existed without the targetBundleName in app.json.")); + "The targetPriority cannot be existed without the targetBundleName in app.json. The moduleName is " + moduleName + ".")); return false; } } @@ -1246,7 +1245,7 @@ public class Compressor { utility.getCompressLevel()); } catch (IOException e) { LOG.error(PackingToolErrMsg.COMPRESS_APP_IO_EXCEPTION.toString( - "compress pack.info into hsp exist IOException: " + e.getMessage())); + "Compress pack.info into hsp exist IOException: " + e.getMessage())); throw new BundleException("Compress pack.info into hsp failed."); } } @@ -1849,7 +1848,7 @@ public class Compressor { append.closeEntry(); } catch (IOException exception) { LOG.error(PackingToolErrMsg.COMPRESS_FILE_EXCEPTION.toString( - "Compress PackInfo into hap exist IOException: " + exception.getMessage())); + "Compress pack.info into hap exist IOException: " + exception.getMessage())); throw new BundleException("Compress PackInfo into hap IOException."); } finally { sourceHapFile.close(); @@ -2853,7 +2852,7 @@ public class Compressor { zipOut.flush(); } } catch (IOException exception) { - LOG.error(PackingToolErrMsg.CLOSE_ZIP_OUTPUT_STREAM_EXPECTION.toString( + LOG.error(PackingToolErrMsg.CLOSE_ZIP_OUTPUT_STREAM_EXCEPTION.toString( "Close zip output stream flush IOException: " + exception.getMessage())); } try { @@ -2861,7 +2860,7 @@ public class Compressor { zipOut.closeArchiveEntry(); } } catch (IOException exception) { - LOG.error(PackingToolErrMsg.CLOSE_ZIP_OUTPUT_STREAM_EXPECTION.toString( + LOG.error(PackingToolErrMsg.CLOSE_ZIP_OUTPUT_STREAM_EXCEPTION.toString( "Close entry IOException: " + exception.getMessage())); } try { @@ -2869,7 +2868,7 @@ public class Compressor { zipOut.finish(); } } catch (IOException exception) { - LOG.error(PackingToolErrMsg.CLOSE_ZIP_OUTPUT_STREAM_EXPECTION.toString( + LOG.error(PackingToolErrMsg.CLOSE_ZIP_OUTPUT_STREAM_EXCEPTION.toString( "Close zip output stream flush IOException: " + exception.getMessage())); } } @@ -2917,19 +2916,19 @@ public class Compressor { List hapVerifyInfos = new ArrayList<>(); for (String hapPath : fileLists) { if (hapPath.isEmpty()) { - LOG.error(PackingToolErrMsg.INVALID_HAP_FILE.toString("Input wrong hap or hsp file.")); - throw new BundleException("Check hap and hsp is valid exist that input wrong hap or hsp file."); + LOG.error(PackingToolErrMsg.INVALID_HAP_FILE.toString("Invalid hap or hsp file input.")); + throw new BundleException("The hap or hsp files are invalid, or the wrong file was provided."); } File srcFile = new File(hapPath); String fileStr = srcFile.getName(); if (fileStr.isEmpty()) { LOG.error(PackingToolErrMsg.INVALID_HAP_FILE.toString("Get file name failed.")); - throw new BundleException("Check hap and hsp is valid exist that get file name failed."); + throw new BundleException("Get file name from the provided path failed."); } if (!fileStr.toLowerCase(Locale.ENGLISH).endsWith(HAP_SUFFIX) && !fileStr.toLowerCase(Locale.ENGLISH).endsWith(HSP_SUFFIX)) { - LOG.error(PackingToolErrMsg.INVALID_HAP_FILE.toString("Input wrong hap or hsp file.")); - throw new BundleException("Check hap and hsp is valid exist that input wrong hap or hsp file."); + LOG.error(PackingToolErrMsg.INVALID_HAP_FILE.toString("Invalid hap or hsp file input.")); + throw new BundleException("The provided file is not a valid hap or hsp file."); } if (isModuleHap(hapPath)) { hapVerifyInfos.add(parseStageHapVerifyInfo(hapPath)); @@ -2954,8 +2953,8 @@ public class Compressor { for (HapVerifyInfo hapVerifyInfo : hapVerifyInfos) { String bundleType = hapVerifyInfo.getBundleType(); if (TYPE_SHARED.equals(bundleType)) { - 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'"; + 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; } @@ -3036,8 +3035,8 @@ public class Compressor { hapVerifyInfo.setProfileStr(FileUtils.getFileStringFromZip(MODULE_JSON, zipFile)); } catch (IOException e) { LOG.error(PackingToolErrMsg.READ_STAGE_HAP_VERIFY_INFO_FAILED.toString( - "Read Stage hap verify info file exist IOExpection: " + e.getMessage())); - throw new BundleException("Parse stage hap verify info file exist IOExpection."); + "Read Stage hap verify info file exist IOException: " + e.getMessage())); + throw new BundleException("Parse Stage hap verify info file exist IOException."); } finally { Utility.closeStream(zipFile); } @@ -3060,8 +3059,8 @@ public class Compressor { hapVerifyInfo.setProfileStr(FileUtils.getFileStringFromZip(CONFIG_JSON, zipFile)); } catch (IOException e) { LOG.error(PackingToolErrMsg.READ_FA_HAP_VERIFY_INFO_FAILED.toString( - "Read FA hap verify info file exist IOExpection: " + e.getMessage())); - throw new BundleException("Parse FA hap verify info file exist IOExpection."); + "Read FA hap verify info file exist IOException: " + e.getMessage())); + throw new BundleException("Parse FA hap verify info file exist IOException."); } finally { Utility.closeStream(zipFile); } @@ -3209,12 +3208,12 @@ public class Compressor { private static boolean checkSharedAppIsValid(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos.isEmpty()) { String cause = "Hap verify infos is empty."; - LOG.error(PackingToolErrMsg.HAP_VERIFY_INFO_EMPTY.toString(cause)); + LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString(cause)); return false; } if (hapVerifyInfos.size() > SHARED_APP_HSP_LIMIT) { - String cause = "Shared app only can contain one module."; - String solution = "Please ensure that there is only one module in Shared App."; + String cause = "The shared App only can contain one module."; + String solution = "Please ensure that there is only one module in the shared App."; LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); return false; } diff --git a/adapter/ohos/FileUtils.java b/adapter/ohos/FileUtils.java index 07025dbc..a854c27c 100644 --- a/adapter/ohos/FileUtils.java +++ b/adapter/ohos/FileUtils.java @@ -177,7 +177,7 @@ class FileUtils { fileStream.close(); } } catch (IOException msg) { - LOG.error(PackingToolErrMsg.CLOSE_STREAM_EXPECTION.toString( + LOG.error(PackingToolErrMsg.CLOSE_STREAM_EXCEPTION.toString( "Close stream exist IOException: " + msg.getMessage())); } } @@ -448,7 +448,7 @@ class FileUtils { } } catch (IOException e) { LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Get profile json exist IOExpection: " + e.getMessage())); - throw new BundleException("Get ProfileJson failed."); + throw new BundleException("Get profile json failed."); } return resourceMap; } diff --git a/adapter/ohos/HapVerify.java b/adapter/ohos/HapVerify.java index 9d9f45a1..b94e41ea 100644 --- a/adapter/ohos/HapVerify.java +++ b/adapter/ohos/HapVerify.java @@ -59,7 +59,7 @@ class HapVerify { public static boolean checkHapIsValid(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos == null || hapVerifyInfos.isEmpty()) { String errMsg = "Hap verify infos is null or empty."; - LOG.error(PackingToolErrMsg.HAP_VERIFY_INFO_EMPTY.toString(errMsg)); + LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString(errMsg)); return false; } // check app variable is same @@ -74,7 +74,7 @@ class HapVerify { } // check package is valid if (!checkPackageNameIsValid(hapVerifyInfos)) { - String errMsg = "Check packageName duplicated."; + String errMsg = "Check packageName is duplicated."; LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } @@ -90,7 +90,7 @@ class HapVerify { } // check atomic service is valid if (!checkAtomicServiceIsValid(hapVerifyInfos)) { - String errMsg = "Check AtomicService valid failed."; + String errMsg = "Check atomicService is invalid."; LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } @@ -100,17 +100,17 @@ class HapVerify { } // check targetModuleName if (!checkTargetModuleNameIsExisted(hapVerifyInfos)) { - String errMsg = "Target module is not found."; + String errMsg = "Target module cannot found."; LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } if (!checkCompileSdkIsValid(hapVerifyInfos)) { - String errMsg = "Compile sdk config is not same."; + String errMsg = "The compileSdkType of each module is different."; LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } if (!checkProxyDataUriIsUnique(hapVerifyInfos)) { - String errMsg = "uris in proxy data are not unique."; + String errMsg = "The values of uri in proxyData of module.json are not unique."; LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } @@ -157,7 +157,7 @@ class HapVerify { abilityNames.get(j) + ") have same continueType.\n"; cause += "Ability(" + abilityNames.get(i) + ") have continueType: " + typeList + ", "; cause += "Another Ability(" + abilityNames.get(j) + ") have continueType: " + typeList2 + "."; - String solution = "Please ensure that the continueType for different abilities do not overlap."; + String solution = "Please ensure that the continueType for different abilities does not overlap."; LOG.error(PackingToolErrMsg.CONTINUE_TYPE_INVALID.toString(cause, solution)); return false; } @@ -201,27 +201,27 @@ class HapVerify { public static boolean checkSharedApppIsValid(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos == null || hapVerifyInfos.isEmpty()) { String cause = "Hap verify infos is null or empty"; - LOG.error(PackingToolErrMsg.HAP_VERIFY_INFO_EMPTY.toString(cause)); + LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString(cause)); return false; } String moduleName = hapVerifyInfos.get(0).getModuleName(); for (HapVerifyInfo hapVerifyInfo : hapVerifyInfos) { if (!moduleName.equals(hapVerifyInfo.getModuleName())) { - String cause = "module name is different."; - String solution = "Ensure that all module have the same module name."; + String cause = "The module name is different."; + String solution = "When the bundleType is shared, ensure that all modules have the same module name."; LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); return false; } if (!hapVerifyInfo.getDependencyItemList().isEmpty()) { - String cause = "Shared app can not depend on other modules."; + 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."; LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); return false; } if (!TYPE_SHARED.equals(hapVerifyInfo.getModuleType())) { - String cause = "Module type is not shared app."; - String solution = "Ensure module type is 'shared' for all module."; + String cause = "The module type is not shared."; + String solution = "Ensure module type is shared for all modules."; LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); return false; } @@ -249,7 +249,7 @@ class HapVerify { private static boolean checkAppFieldsIsSame(List hapVerifyInfos) { if (hapVerifyInfos.isEmpty()) { String cause = "Hap verify infos is empty."; - LOG.error(PackingToolErrMsg.HAP_VERIFY_INFO_EMPTY.toString(cause)); + LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString(cause)); return false; } HapVerifyInfo verifyInfo = hapVerifyInfos.get(0); @@ -345,25 +345,25 @@ class HapVerify { private static boolean appFieldsIsSame(VerifyCollection verifyCollection, HapVerifyInfo hapVerifyInfo) { if (hapVerifyInfo.getBundleName().isEmpty() || !verifyCollection.bundleName.equals(hapVerifyInfo.getBundleName())) { - String errMsg = "Input module bundleName is different."; + String errMsg = "The bundleName parameter values are different."; String solution = "Check if the bundleName is the same in different modules."; LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (!verifyCollection.getBundleType().equals(hapVerifyInfo.getBundleType())) { - String errMsg = "Input module bundleType is different."; + String errMsg = "The bundleType parameter values are different."; String solution = "Check if the bundleType is the same in different modules."; LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (verifyCollection.versionCode != hapVerifyInfo.getVersion().versionCode) { - String errMsg = "Input module versionCode is different."; + String errMsg = "The versionCode parameter values are different."; String solution = "Check if the versionCode is the same in different modules."; LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (verifyCollection.compatibleApiVersion != hapVerifyInfo.getApiVersion().getCompatibleApiVersion()) { - String errMsg = "Input module minApiVersion is different."; + String errMsg = "The minApiVersion parameter values are different."; String solution = "Check if the minApiVersion is the same in different modules."; LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); } @@ -373,20 +373,20 @@ class HapVerify { LOG.warning("Module: (" + verifyCollection.getModuleName() + ") and Module: (" + hapVerifyInfo.getModuleName() + ") has different releaseType."); } else { - String errMsg = "Input module releaseType is different."; + String errMsg = "The module releaseType parameter values are different."; String solution = "Check if the releaseType is the same in different modules."; LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } } if (!verifyCollection.targetBundleName.equals(hapVerifyInfo.getTargetBundleName())) { - String errMsg = "Input targetBundleName is different."; + String errMsg = "The targetBundleName parameter values are different."; String solution = "Check if the targetBundleName is the same in different modules."; LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (verifyCollection.targetPriority != hapVerifyInfo.getTargetPriority()) { - String errMsg = "Input targetPriority is different."; + String errMsg = "The targetPriority parameter values are different."; String solution = "Check if the targetPriority is the same in different modules."; LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; @@ -446,7 +446,7 @@ class HapVerify { ".\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 : " + + cause += "\n" + "Module: " + hapVerifyInfos.get(i).getModuleName() + " DistroFilter is " + hapVerifyInfos.get(i).getDistroFilter().dump() + "."; } if (!EMPTY_STRING.equals(hapVerifyInfos.get(j).getDistroFilter().dump())) { @@ -485,7 +485,7 @@ class HapVerify { ".\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 : " + + cause += "\n" + "Module: " + hapVerifyInfos.get(i).getModuleName() + " DistroFilter is " + hapVerifyInfos.get(i).getDistroFilter().dump() + "."; } if (!EMPTY_STRING.equals(hapVerifyInfos.get(j).getDistroFilter().dump())) { @@ -572,14 +572,14 @@ class HapVerify { } if (nonOverlayHap.isEmpty()) { LOG.error(PackingToolErrMsg.TARGET_MODULE_NAME_NOT_EXIST.toString( - "Target hap modules are needed to pack with overlay hap module.")); + "The target modules are needed to pack with the overlay module.")); return false; } if (!moduleList.containsAll(targetModuleList)) { List missingModules = new ArrayList<>(targetModuleList); missingModules.removeAll(moduleList); LOG.error(PackingToolErrMsg.TARGET_MODULE_NAME_NOT_EXIST.toString( - "The following target overlay hap modules are missing: " + missingModules)); + "The following target overlay modules are missing: " + missingModules)); return false; } @@ -590,8 +590,7 @@ class HapVerify { private static boolean checkCompileSdkIsValid(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos.isEmpty()) { String cause = "Hap verify infos is empty"; - String solution = "Ensure the App contains at least one module before proceeding."; - LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); + LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString(cause)); return false; } String compileSdkType = hapVerifyInfos.get(0).getCompileSdkType(); @@ -609,8 +608,7 @@ class HapVerify { private static boolean checkProxyDataUriIsUnique(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos.isEmpty()) { String cause = "Hap verify infos is empty"; - String solution = "Ensure the App contains at least one module before proceeding."; - LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); + LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString(cause)); return false; } Set uriSet = new HashSet<>(); @@ -618,7 +616,7 @@ class HapVerify { for (String uri : info.getProxyDataUris()) { if (uriSet.contains(uri)) { String moduleName = info.getModuleName(); - String cause = "Module(" + moduleName + ") and uri(" + uri + ") in proxyData settings 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; @@ -666,7 +664,7 @@ class HapVerify { entryHapVerifyInfos.get(j).getDeviceType() + "."; if (!EMPTY_STRING.equals(entryHapVerifyInfos.get(i).getDistroFilter().dump())) { - cause += "\n" + "Module: " + entryHapVerifyInfos.get(i).getModuleName() + " DistroFilter is : " + + cause += "\n" + "Module: " + entryHapVerifyInfos.get(i).getModuleName() + " DistroFilter is " + entryHapVerifyInfos.get(i).getDistroFilter().dump() + "."; } if (!EMPTY_STRING.equals(entryHapVerifyInfos.get(j).getDistroFilter().dump())) { @@ -920,7 +918,7 @@ class HapVerify { } if (hapVerifyInfo.getDistroFilter().apiVersion.policy == null) { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Entry module(" + hapVerifyInfo.getModuleName() + ") policy is null.")); + "Entry module(" + hapVerifyInfo.getModuleName() + ") apiVersion policy is null.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().apiVersion.policy)) { @@ -938,9 +936,9 @@ class HapVerify { flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Entry module(" + hapVerifyInfo.getModuleName() + ") policy '" + hapVerifyInfo.getDistroFilter().apiVersion.policy + + "Entry module(" + hapVerifyInfo.getModuleName() + ") apiVersion policy '" + hapVerifyInfo.getDistroFilter().apiVersion.policy + "' is invalid.")); - throw new BundleException("Check ApiVersion covered input policy is invalid."); + throw new BundleException("Check apiVersion covered input policy is invalid."); } } if (include != null) { @@ -973,8 +971,7 @@ class HapVerify { } if (hapVerifyInfo.getDistroFilter().screenShape.policy == null) { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Check feature module screenShape is subset of entry module screenShape failed, Entry module(" + - hapVerifyInfo.getModuleName() + ") policy is null.")); + "Entry module(" + hapVerifyInfo.getModuleName() + ") screenShape policy is null.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().screenShape.policy)) { @@ -990,10 +987,8 @@ class HapVerify { flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Check feature module screenShape is subset of entry module screenShape failed, Entry module(" + - hapVerifyInfo.getModuleName() + ") policy '" + hapVerifyInfo.getDistroFilter().screenShape.policy + - "' is invalid.")); - throw new BundleException("Check ScreenShape covered input 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."); } } if (include != null) { @@ -1025,8 +1020,7 @@ class HapVerify { } if (hapVerifyInfo.getDistroFilter().screenWindow.policy == null) { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Check feature module screenWindow is subset of entry module screenWindow failed, Entry module(" + - hapVerifyInfo.getModuleName() + ") policy is null.")); + "Entry module(" + hapVerifyInfo.getModuleName() + ") screenWindow policy is null.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().screenWindow.policy)) { @@ -1042,10 +1036,8 @@ class HapVerify { flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Check feature module screenWindow is subset of entry module screenWindow failed, Entry module(" + - hapVerifyInfo.getModuleName() + ") policy '" + hapVerifyInfo.getDistroFilter().screenWindow.policy + - "' is invalid.")); - throw new BundleException("Check ScreenWindow covered input 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."); } } if (include != null) { @@ -1077,8 +1069,7 @@ class HapVerify { } if (hapVerifyInfo.getDistroFilter().screenDensity.policy == null) { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Check feature module screenDensity is subset of entry module screenDensity failed, Entry module(" + - hapVerifyInfo.getModuleName() + ") policy is null.")); + "Entry module(" + hapVerifyInfo.getModuleName() + ") screenDensity policy is null.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().screenDensity.policy)) { @@ -1094,10 +1085,8 @@ class HapVerify { flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Check feature module screenDensity is subset of entry module screenDensity failed, Entry module(" + - hapVerifyInfo.getModuleName() + ") policy '" + hapVerifyInfo.getDistroFilter().screenDensity.policy + - "' is invalid.")); - throw new BundleException("Check ScreenDensity covered input 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."); } } if (include != null) { @@ -1129,8 +1118,7 @@ class HapVerify { } if (hapVerifyInfo.getDistroFilter().countryCode.policy == null) { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Check feature module countryCode is subset of entry module countryCode failed, Entry module(" + - hapVerifyInfo.getModuleName() + ") policy is null.")); + "Entry module(" + hapVerifyInfo.getModuleName() + ") countryCode policy is null.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().countryCode.policy)) { @@ -1146,10 +1134,8 @@ class HapVerify { flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Check feature module countryCode is subset of entry module countryCode failed, Entry module " + - hapVerifyInfo.getModuleName() + ") policy '" + hapVerifyInfo.getDistroFilter().countryCode.policy + - "' is invalid.")); - throw new BundleException("Check CountryCode covered input 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."); } } if (include != null) { @@ -1249,9 +1235,8 @@ class HapVerify { */ private static boolean checkDependencyIsValid(List allHapVerifyInfo) throws BundleException { if (allHapVerifyInfo.isEmpty()) { - String cause = "No module included."; - String solution = "Ensure the App contains at least one module before proceeding."; - LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); + String cause = "Hap verify infos is empty"; + LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString(cause)); throw new BundleException("HapVerify::checkDependencyIsValid failed, input none hap."); } boolean isInstallationFree = allHapVerifyInfo.get(0).isInstallationFree(); @@ -1302,7 +1287,8 @@ class HapVerify { dependency.getModuleName(), hapVerifyInfo, allHapVerifyInfo); for (HapVerifyInfo item : layerDependencyList) { if (FEATURE.equals(item.getModuleType()) || ENTRY.equals(item.getModuleType())) { - String cause = "The dependeny module(" + item.getModuleName() + ") type is feature or entry."; + String cause = + "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)); @@ -1412,7 +1398,8 @@ class HapVerify { private static boolean checkAtomicServiceModuleSize(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString()); + String cause = "Hap verify infos is empty"; + LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString(cause)); return false; } int entryLimit = hapVerifyInfoList.get(0).getEntrySizeLimit(); @@ -1432,13 +1419,13 @@ class HapVerify { fileSize += dependency.getFileLength(); } if (hapVerifyInfo.getModuleType().equals(ENTRY) && (fileSize >= entryLimit * FILE_LENGTH_1M)) { - String errMsg = "module " + hapVerifyInfo.getModuleName() + " and it's dependencies size sum is " + + String errMsg = "Module " + hapVerifyInfo.getModuleName() + " and it's dependencies size sum is " + getCeilFileSize(fileSize, entryLimit) + "MB, which is overlarge than " + entryLimit + "MB."; LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_MODULE_SIZE.toString(errMsg)); return false; } if (!hapVerifyInfo.getModuleType().equals(ENTRY) && (fileSize >= notEntryLimit * FILE_LENGTH_1M)) { - String errMsg = "module " + hapVerifyInfo.getModuleName() + " and it's dependencies size sum is " + + String errMsg = "Module " + hapVerifyInfo.getModuleName() + " and it's dependencies size sum is " + getCeilFileSize(fileSize, notEntryLimit) + "MB, which is overlarge than " + notEntryLimit + "MB."; LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_MODULE_SIZE.toString(errMsg)); return false; @@ -1460,7 +1447,8 @@ class HapVerify { private static Map> getDeviceHapVerifyInfoMap(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString()); + String cause = "Hap verify infos is empty"; + LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString(cause)); throw new BundleException("getDeviceHapVerifyInfoMap failed, hapVerifyInfoList is empty."); } Map> deviceInfoMap = new HashMap>(); @@ -1481,9 +1469,8 @@ class HapVerify { private static boolean checkAtomicServiceIsValid(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - String cause = "No module included."; - String solution = "Ensure the App contains at least one module before proceeding."; - LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); + String cause = "Hap verify infos is empty"; + LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString(cause)); return false; } String bundleType = hapVerifyInfoList.get(0).getBundleType(); @@ -1500,7 +1487,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; } } @@ -1529,7 +1516,7 @@ class HapVerify { throws BundleException { if (hapVerifyInfoList.isEmpty()) { String cause = "Hap verify infos is empty."; - LOG.error(PackingToolErrMsg.HAP_VERIFY_INFO_EMPTY.toString(cause)); + LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString(cause)); throw new BundleException("checkAtomicServicePreloadsIsValid failed, hapVerifyInfoList is empty."); } List moduleNames = new ArrayList<>(); @@ -1543,19 +1530,19 @@ 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, " - + moduleName + " cannot on module " + hapVerifyInfo.getModuleName() + ".")); + 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, " - + moduleName + " cannot on module " + hapVerifyInfo.getModuleName() + ".")); + 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("Can not preload self, module " - + hapVerifyInfo.getModuleName() + " cannot preload self.")); + LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("Cannot preload self, module " + + hapVerifyInfo.getModuleName() + " cannot preloads self.")); return false; } } @@ -1572,8 +1559,8 @@ class HapVerify { if (moduleNameWithType.get(moduleName).equals(ENTRY) || moduleNameWithType.get(moduleName).equals(HAR)) { LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString( - "feature or shared can not preload entry or har, module(" + hapVerifyInfo.getModuleName() + - ") cannot preloads module(" + moduleNameWithType.get(moduleName) + ").")); + "feature or shared cannot preload entry or har, module(" + hapVerifyInfo.getModuleName() + + ") cannot preloads module(" + moduleName + ").")); return false; } } @@ -1590,7 +1577,8 @@ class HapVerify { */ public static boolean checkFileSizeIsValid(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - LOG.error(PackingToolErrMsg.HAP_VERIFY_INFO_EMPTY.toString("Hap verify infos is empty.")); + LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString("Hap verify infos is empty.")); + throw new BundleException("Check file size is valid failed, hap verify infos is empty."); } if (!checkFileSize(hapVerifyInfoList)) { return false; @@ -1600,7 +1588,7 @@ class HapVerify { private static boolean checkFileSize(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - LOG.error(PackingToolErrMsg.HAP_VERIFY_INFO_EMPTY.toString("Hap verify infos is empty.")); + LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString("Hap verify infos is empty.")); throw new BundleException("checkFileSizeWhenSplit failed, hapVerifyInfoList is empty."); } // check single file length @@ -1609,7 +1597,7 @@ class HapVerify { for (HapVerifyInfo hapVerifyInfo : hapVerifyInfoList) { if (hapVerifyInfo.getModuleType().equals(ENTRY) && (hapVerifyInfo.getFileLength() >= entryLimit * FILE_LENGTH_1M)) { - String errMsg = "module " + hapVerifyInfo.getModuleName() + "'s size is " + + String errMsg = "Module " + hapVerifyInfo.getModuleName() + "'s size is " + getCeilFileSize(hapVerifyInfo.getFileLength(), entryLimit) + "MB, which is overlarge than " + entryLimit + "MB."; LOG.error(PackingToolErrMsg.CHECK_FILE_SIZE_INVALID.toString(errMsg)); @@ -1617,7 +1605,7 @@ class HapVerify { } if (!hapVerifyInfo.getModuleType().equals(ENTRY) && (hapVerifyInfo.getFileLength() >= notEntryLimit * FILE_LENGTH_1M)) { - String errMsg = "module " + hapVerifyInfo.getModuleName() + "'s size is " + + String errMsg = "Module " + hapVerifyInfo.getModuleName() + "'s size is " + getCeilFileSize(hapVerifyInfo.getFileLength(), notEntryLimit) + "MB, which is overlarge than " + notEntryLimit + "MB."; LOG.error(PackingToolErrMsg.CHECK_FILE_SIZE_INVALID.toString(errMsg)); @@ -1629,7 +1617,7 @@ class HapVerify { for (String device : deviceInfoMap.keySet()) { ListhapVerifyInfoList1 = deviceInfoMap.get(device); if (!checkAtomicServiceModuleSize(hapVerifyInfoList1)) { - String errMsg = "Check AtomicService module size failed on device " + device + "."; + String errMsg = "Check the atomicService module size failed on device " + device + "."; LOG.error(PackingToolErrMsg.CHECK_FILE_SIZE_INVALID.toString(errMsg)); return false; } diff --git a/adapter/ohos/ModuleJsonUtil.java b/adapter/ohos/ModuleJsonUtil.java index eaf2237f..569022e0 100644 --- a/adapter/ohos/ModuleJsonUtil.java +++ b/adapter/ohos/ModuleJsonUtil.java @@ -131,7 +131,7 @@ class ModuleJsonUtil { version.versionCode = appObj.getIntValue(VERSIONCODE); version.versionName = appObj.getString(VERSIONNAME); } else { - String errMsg = "The module.json file does not contain versionCode or versionName."; + String errMsg = "The module.json file does not contain 'versionCode' or 'versionName'."; LOG.error(PackingToolErrMsg.PARSE_STAGE_JSON_FAILED.toString(errMsg)); throw new BundleException(errMsg); } @@ -241,9 +241,9 @@ class ModuleJsonUtil { public static ModuleApiVersion parseFAModuleApiVersion(String jsonString) throws BundleException { JSONObject appObj = getAppObj(jsonString); if (!appObj.containsKey(API_VERSION)) { - String errMsg = "The config.json file does not contain apiVersion."; + 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 --json-path file do 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(); @@ -272,7 +272,7 @@ class ModuleJsonUtil { if (moduleObj.containsKey(NAME)) { moduleName = moduleObj.getString(NAME); } else { - String errMsg = "The module.json file do not contain module name."; + String errMsg = "The module.json file does not contain 'name'."; LOG.error(PackingToolErrMsg.PARSE_STAGE_JSON_FAILED.toString(errMsg)); throw new BundleException(errMsg); } @@ -291,12 +291,12 @@ class ModuleJsonUtil { JSONObject moduleObj = getModuleObj(jsonString); JSONObject distroObj = moduleObj.getJSONObject(DISTRO); if (distroObj == null) { - String errMsg = "The config.json file does not contain distro."; + String errMsg = "The config.json file does not contain 'distro'."; LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString(errMsg)); throw new BundleException(errMsg); } if (!distroObj.containsKey(MODULE_NAME)) { - String errMsg = "The config.json file does not contain moduleName."; + String errMsg = "The config.json file does not contain 'moduleName'."; LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString(errMsg)); throw new BundleException(errMsg); } @@ -315,7 +315,7 @@ class ModuleJsonUtil { String moduleName; JSONObject moduleObj = getModuleObj(jsonString); if (!moduleObj.containsKey(NAME)) { - String errMsg = "The patch.json file do not contain moduleName."; + String errMsg = "The patch.json file does not contain 'name'."; LOG.error(PackingToolErrMsg.PARSE_PATCH_MODULE_NAME_FAILED.toString(errMsg)); throw new BundleException(errMsg); } @@ -336,8 +336,8 @@ class ModuleJsonUtil { if (moduleObj.containsKey(PACKAGE)) { packageStr = moduleObj.getString(PACKAGE); } else { - LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString("The config.json file do not contain package.")); - throw new BundleException("ModuleJsonUtil:parseFaPackageStr failed: json file do 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,8 +355,8 @@ class ModuleJsonUtil { if (appObject.containsKey(BUNDLE_NAME)) { bundleName = appObject.getString(BUNDLE_NAME); } else { - LOG.error(PackingToolErrMsg.PARSE_BUNDLE_NAME_FAILED.toString("json object do not contain bundleName.")); - throw new BundleException("Parse stage bundleName json object do not contain bundleNames."); + 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; } @@ -1077,7 +1077,7 @@ class ModuleJsonUtil { } } } catch (JSONException exception) { - String errMsg = "parse metadata info exist JSONException: " + exception.getMessage(); + String errMsg = "Parse the metadata info exist JSONException: " + exception.getMessage(); LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString(exception.getMessage())); throw new BundleException(errMsg); } @@ -1316,7 +1316,7 @@ class ModuleJsonUtil { JSONObject moduleObj = getModuleObj(jsonString); String moduleName = parseStageModuleName(jsonString); if (!moduleObj.containsKey(TYPE)) { - String errMsg = "Module: '" + moduleName + "' has no +'type' field in module.json."; + 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 + "'."; LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); throw new BundleException(errMsg); @@ -1326,7 +1326,7 @@ 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 true settings."; + 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,25 +1336,25 @@ 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 solution = "Set 'installationFree' to false in the module configuration 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); } return APP; } else if (bundleType.equals(ATOMIC_SERVICE)) { if (!installationFree) { - String errMsg = "installationFree must be true in module '" + moduleName + "' when bundleType is atomicService."; - String solution = "Set 'installationFree' to true in the module configuration 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)); throw new BundleException(errMsg); } return ATOMIC_SERVICE; } 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 configuration when 'bundleType' is 'shared'.";; + 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.";; LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); throw new BundleException(errMsg); } @@ -1362,7 +1362,7 @@ class ModuleJsonUtil { } else if (APP_SERVICE.equals(bundleType)) { return APP_SERVICE; } else { - String errMsg = "bundleType is invalid in app.json."; + String errMsg = "'bundleType' is invalid in app.json."; String solution = "Ensure that the 'bundleType' field in the app.json file is correctly set to one of" + "the valid types: 'app', 'atomicService', 'shared', or 'appService'."; LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); @@ -1404,7 +1404,7 @@ class ModuleJsonUtil { for (int i = 0; i < proxyData.size(); ++i) { JSONObject itemObj = proxyData.getJSONObject(i); if (!itemObj.containsKey(PROXY_URI)) { - String errMsg = "Proxy data object does not contain " + 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."; LOG.error(PackingToolErrMsg.PARSE_PROXY_DATA_URI_FAILED.toString(errMsg, solution)); throw new BundleException("Parse json object failed in parse proxyData and uri."); @@ -1417,7 +1417,7 @@ class ModuleJsonUtil { for (int i = 0; i < proxyDatas.size(); ++i) { JSONObject itemObj = proxyDatas.getJSONObject(i); if (!itemObj.containsKey(PROXY_URI)) { - String errMsg = "Proxy data object does not contain " + 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."; 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 +1440,7 @@ class ModuleJsonUtil { } JSONObject appObj = jsonObject.getJSONObject(APP); if (appObj == null) { - LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("module.json or config.json do 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; @@ -1456,13 +1456,13 @@ class ModuleJsonUtil { throw new BundleException(errMsg); } if (jsonObj == null) { - LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("jsonObj is null.")); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("The jsonObj is null.")); throw new BundleException("Parse jsonObj is null."); } JSONObject moduleObj = jsonObj.getJSONObject(MODULE); if (moduleObj == null) { - LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("--json-path file do not contain module.")); - throw new BundleException("json file do 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,8 +1507,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 do not contain distro.")); - throw new BundleException("Parse FA installationFree json do 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)) { return distroObj.getBoolean(INSTALLATION_FREE); @@ -1715,8 +1715,8 @@ class ModuleJsonUtil { try { jsonObject = JSON.parseObject(jsonString); } catch (JSONException exception) { - PackingToolErrMsg.PARSE_JSON_FAILED.toString("Parse json object failed when get debug in config.json. JSONException: " + exception.getMessage()); - throw new BundleException("parse JSONObject failed when get debug in config.json."); + 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); if (deviceConfigObj == null) { @@ -1916,7 +1916,7 @@ class ModuleJsonUtil { if (moduleObj.containsKey(ATOMIC_SERVICE) && (!appObj.containsKey(BUNDLE_TYPE) || !getJsonString(appObj, BUNDLE_TYPE).equals(ATOMIC_SERVICE))) { - String errMsg = "Module can not config atomicService when bundleType is not atomicService."; + String errMsg = "Module cannot config atomicService when 'bundleType' is not atomicService."; LOG.error(PackingToolErrMsg.CHECK_MODULE_ATOMIC_SERVICE_FAILED.toString(errMsg)); return false; } @@ -1956,8 +1956,8 @@ class ModuleJsonUtil { boolean installationFree = getJsonBooleanValue(moduleObj, INSTALLATION_FREE, false); if (!appObj.containsKey(BUNDLE_TYPE)) { if (installationFree) { - String errMsg = "The app.json5 file configuration does not match the installationFree true settings."; - String solution = "Add the bundleType field to the app.json5 file and set it atomicService."; + 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 and set it atomicService."; LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString(errMsg, solution)); return false; } @@ -1966,35 +1966,35 @@ class ModuleJsonUtil { String bundleType = getJsonString(appObj, BUNDLE_TYPE); if (bundleType.equals(APP)) { if (installationFree) { - String errMsg = "installationFree must be false when bundleType is app."; - String solution = "Set 'installationFree' to false in the module configuration when 'bundleType' is 'app'."; + String errMsg = "'installationFree' must be false when bundleType is app."; + String solution = "Set 'installationFree' to false in the module.json when 'bundleType' is app."; LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString(errMsg, solution)); return false; } } else if (bundleType.equals(ATOMIC_SERVICE)) { if (!installationFree) { - String errMsg = "installationFree must be true when bundleType is atomicService."; - String solution = "Set 'installationFree' to true in the module configuration when 'bundleType'" + - "is 'atomicService'."; + String errMsg = "'installationFree' must be true when 'bundleType' is atomicService."; + String solution = "Set 'installationFree' to true in the module.json when 'bundleType'" + + "is atomicService."; LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString(errMsg, solution)); return false; } } else if (SHARED.equals(bundleType)) { if (installationFree) { - String errMsg = "installationFree must be false when bundleType is shared."; - String solution = "Set 'installationFree' to false in the module configuration when 'bundleType' is 'shared'."; + String errMsg = "'installationFree' must be false when bundleType is shared."; + String solution = "Set 'installationFree' to false in the module.json when 'bundleType' is shared."; LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString(errMsg, solution)); return false; } } else if (APP_SERVICE.equals(bundleType)) { if (installationFree) { - String errMsg = "installationFree must be false when bundleType is appService."; - String solution = "Set 'installationFree' to false in the module configuration when 'bundleType' is 'appService'."; + String errMsg = "'installationFree' must be false when 'bundleType' is appService."; + String solution = "Set 'installationFree' to false in the module.json when 'bundleType' is appService."; LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString(errMsg, solution)); return false; } } else { - String errMsg = "bundleType is invalid in app.json."; + String errMsg = "'bundleType' is invalid in the app.json."; String solution = "Ensure that the 'bundleType' field in the app.json file is correctly set to one of " + "the valid types: 'app', 'atomicService', 'shared', or 'appService'."; LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString(errMsg, solution)); diff --git a/adapter/ohos/PackingToolErrMsg.java b/adapter/ohos/PackingToolErrMsg.java index 73fa4e21..e8d48fef 100644 --- a/adapter/ohos/PackingToolErrMsg.java +++ b/adapter/ohos/PackingToolErrMsg.java @@ -111,7 +111,7 @@ public class PackingToolErrMsg { public static final ErrorMsg BUNDLE_TYPE_APPSERVICE_INVALID = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("11") .setErrCode("013") - .setDescription("Check BundleTypeAppService invalid.") + .setDescription("Check the bundleType is appService failed.") .setCause("%s") .build(); @@ -151,7 +151,7 @@ public class PackingToolErrMsg { public static final ErrorMsg HAS_HOME_EXTENSION_ABILITY_INVALID = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("11") .setErrCode("017") - .setDescription("Check hsp has entry ExtensionAbility failed.") + .setDescription("Check hsp has entry extensionAbility failed.") .setCause("%s") .build(); @@ -183,7 +183,7 @@ public class PackingToolErrMsg { public static final ErrorMsg COMPRESS_HAP_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") .setErrCode("002") - .setDescription("Compress Stage Hap failed.") + .setDescription("Compress Stage hap failed.") .setCause("%s") .addSolution("Please check the first error message for more details and modify accordingly.") .build(); @@ -194,7 +194,7 @@ public class PackingToolErrMsg { public static final ErrorMsg CHECK_STAGE_HAP_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") .setErrCode("003") - .setDescription("Verify stage hap info failed.") + .setDescription("Verify Stage hap info failed.") .setCause("%s") .addSolution("Please check the first error message for more details and modify accordingly.") .build(); @@ -308,7 +308,7 @@ public class PackingToolErrMsg { public static final ErrorMsg READ_STAGE_HAP_VERIFY_INFO_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") .setErrCode("013") - .setDescription("Read stage hap verify info io exception.") + .setDescription("Read Stage hap verify info exist exception.") .setCause("%s") .addSolution("Please check the exception message for more details and modify accordingly.") .build(); @@ -321,7 +321,7 @@ public class PackingToolErrMsg { .setErrCode("014") .setDescription("Parallel compress exception.") .setCause("%s") - .addSolution("Please check the related expection message and modify the operation.") + .addSolution("Please check the related exception message and modify the operation.") .build(); /** @@ -341,7 +341,7 @@ public class PackingToolErrMsg { public static final ErrorMsg INVALID_HAP_FILE = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") .setErrCode("016") - .setDescription("check input hap or hsp file is invalid.") + .setDescription("Check input hap or hsp file is invalid.") .setCause("%s") .build(); @@ -351,7 +351,7 @@ public class PackingToolErrMsg { public static final ErrorMsg CHECK_SHARED_APP_INVALID = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") .setErrCode("017") - .setDescription("Check shared App mode invalid.") + .setDescription("Check shared App invalid.") .setCause("%s") .addSolution("%s") .build(); @@ -383,7 +383,7 @@ public class PackingToolErrMsg { public static final ErrorMsg READ_FA_HAP_VERIFY_INFO_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") .setErrCode("020") - .setDescription("Read FA hap verify info io exception.") + .setDescription("Read FA hap verify info exist exception.") .setCause("%s") .addSolution("Please check the first error message for more details and modify accordingly.") .build(); @@ -396,7 +396,7 @@ public class PackingToolErrMsg { .setErrCode("021") .setDescription("IO exception when compress app.") .setCause("%s") - .addSolution("Please check the related expection message and modify the operation.") + .addSolution("Please check the related exception message and modify the operation.") .build(); /** @@ -418,7 +418,7 @@ public class PackingToolErrMsg { .setErrCode("023") .setDescription("Json special process exist exception.") .setCause("%s") - .addSolution("Please check the expection message and modify.") + .addSolution("Please check the exception message and modify.") .build(); /** @@ -427,7 +427,7 @@ public class PackingToolErrMsg { public static final ErrorMsg CHECK_ATOMIC_SERVICE_SIZE_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") .setErrCode("024") - .setDescription("Atomic service size check failed.") + .setDescription("Check atomicService size failed.") .setCause("%s") .addSolution("Please check the related size check error message and reduce related module size.") .build(); @@ -439,7 +439,7 @@ public class PackingToolErrMsg { public static final ErrorMsg PARSE_JSON_OBJECT_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("13") .setErrCode("001") - .setDescription("Parse json Object expection.") + .setDescription("Parse json object exception.") .setCause("%s") .build(); @@ -469,7 +469,7 @@ public class PackingToolErrMsg { public static final ErrorMsg PARSE_STAGE_JSON_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("13") .setErrCode("004") - .setDescription("Failed to parse module.json for stage module.") + .setDescription("Failed to parse module.json for the Stage module.") .setCause("%s") .build(); @@ -501,7 +501,7 @@ public class PackingToolErrMsg { public static final ErrorMsg CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("13") .setErrCode("007") - .setDescription("Check module atomicService installationFree invalid.") + .setDescription("Check module atomicService and installationFree invalid.") .setCause("%s") .addSolution("%s") .build(); @@ -533,7 +533,7 @@ public class PackingToolErrMsg { public static final ErrorMsg CHECK_BUNDLETYPE_CONSISTENCY_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("13") .setErrCode("010") - .setDescription("BundleType consistency check failed.") + .setDescription("Failed to check the consistency of bundleType.") .setCause("%s") .addSolution("Make sure the bundleType is consistency for different modules.") .build(); @@ -564,7 +564,7 @@ public class PackingToolErrMsg { public static final ErrorMsg PARSE_FA_JSON_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("13") .setErrCode("013") - .setDescription("Failed to parse config.json for FA module.") + .setDescription("Failed to parse config.json for the FA module.") .setCause("%s") .build(); @@ -582,24 +582,24 @@ public class PackingToolErrMsg { .build(); /** - * CLOSE_ZIP_OUTPUT_STREAM_EXPECTION + * CLOSE_ZIP_OUTPUT_STREAM_EXCEPTION */ - public static final ErrorMsg CLOSE_ZIP_OUTPUT_STREAM_EXPECTION = ErrorMsg.getPackingToolErrBuilder() + public static final ErrorMsg CLOSE_ZIP_OUTPUT_STREAM_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("14") .setErrCode("002") - .setDescription("close zip output stream exception.") + .setDescription("Close zip output stream exception.") .setCause("%s") - .addSolution("Please check the related error message and modify the operation.") + .addSolution("Please check the related exception message and modify the operation.") .build(); /** - * CLOSE_STREAM_EXPECTION + * CLOSE_STREAM_EXCEPTION */ - public static final ErrorMsg CLOSE_STREAM_EXPECTION = ErrorMsg.getPackingToolErrBuilder() + public static final ErrorMsg CLOSE_STREAM_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("14") .setErrCode("003") .setDescription("IO exception when closing stream.") - .setCause("%s") + .addSolution("Please check the related exception message for more details and modify accordingly.") .build(); /** @@ -610,7 +610,7 @@ public class PackingToolErrMsg { .setErrCode("004") .setDescription("Get file content failed.") .setCause("%s") - .addSolution("Please check the related expection message for more details and modify accordingly.") + .addSolution("Please check the related exception message for more details and modify accordingly.") .build(); /** @@ -686,14 +686,14 @@ public class PackingToolErrMsg { .build(); /* - * NULL_POINTER_EXPECTION + * NULL_POINTER_EXCEPTION */ - public static final ErrorMsg NULL_POINTER_EXPECTION = ErrorMsg.getPackingToolErrBuilder() + public static final ErrorMsg NULL_POINTER_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("15") .setErrCode("002") .setDescription("Null pointer exception.") .setCause("%s") - .addSolution("Please review the related error message for further insights.") + .addSolution("Please review the related exception message for further insights.") .build(); // hap verify error @@ -758,7 +758,7 @@ public class PackingToolErrMsg { public static final ErrorMsg CHECK_HAP_INVALID = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("16") .setErrCode("006") - .setDescription("Verify hap info is invalid.") + .setDescription("Check hap info is invalid.") .setCause("%s") .addSolution("Please check the first error message for more details and modify accordingly.") .build(); @@ -769,7 +769,7 @@ public class PackingToolErrMsg { public static final ErrorMsg CHECK_ENTRY_INVALID = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("16") .setErrCode("007") - .setDescription("Check entry module invalid.") + .setDescription("Check entry module is invalid.") .setCause("%s") .addSolution("%s") .build(); @@ -815,7 +815,7 @@ public class PackingToolErrMsg { .setErrCode("011") .setDescription("Atomicservice preloads is invalid.") .setCause("%s") - .addSolution("Please check related error message and modify preloads settings.") + .addSolution("Please check related preload message and modify preloads settings.") .build(); /** @@ -847,7 +847,7 @@ public class PackingToolErrMsg { public static final ErrorMsg PROXY_DATA_URI_NOT_UNIQUE = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("16") .setErrCode("014") - .setDescription("Proxy data uri is not unique.") + .setDescription("The values of uri in proxyData of module.json are not unique.") .setCause("%s") .addSolution("%s") .build(); @@ -880,8 +880,8 @@ public class PackingToolErrMsg { public static final ErrorMsg CHECK_HAP_VERIFY_INFO_LIST_EMPTY = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("16") .setErrCode("017") - .setDescription("The provided list of HapVerifyInfo is empty, unable to process.") - .setCause("Input list of HapVerifyInfo is empty.") + .setDescription("The provided list of HapVerifyInfos is empty.") + .setCause("%s") .build(); /** @@ -890,7 +890,7 @@ public class PackingToolErrMsg { public static final ErrorMsg CHECK_ATOMIC_SERVICE_MODULE_SIZE = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("16") .setErrCode("018") - .setDescription("AtomicService module size check failed.") + .setDescription("Check the atomicService module size failed.") .setCause("%s") .addSolution("Please check and reduced related module size.") .build(); @@ -901,19 +901,9 @@ public class PackingToolErrMsg { public static final ErrorMsg CHECK_FEATURE_DISTRO_FILTER_INVALID = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("16") .setErrCode("019") - .setDescription("Check feature module distributionFilter is invalid.") + .setDescription("Check the entry module distributionFilter is invalid.") .setCause("%s") .addSolution("Ensure the Entry type module distributionFilter file policy " + "settings is 'exclude' or 'include'.") .build(); - - /** - * HAP_VERIFY_INFO_NULL - */ - public static final ErrorMsg HAP_VERIFY_INFO_EMPTY = ErrorMsg.getPackingToolErrBuilder() - .setTypeCode("16") - .setErrCode("020") - .setDescription("Hap verify infos is empty.") - .setCause("%s") - .build(); } diff --git a/adapter/ohos/Utility.java b/adapter/ohos/Utility.java index ecf5266e..496930ca 100644 --- a/adapter/ohos/Utility.java +++ b/adapter/ohos/Utility.java @@ -721,7 +721,7 @@ public class Utility { try { stream.close(); } catch (IOException exception) { - LOG.error(PackingToolErrMsg.CLOSE_STREAM_EXPECTION.toString( + LOG.error(PackingToolErrMsg.CLOSE_STREAM_EXCEPTION.toString( "Close stream exist IOException: " + exception.getMessage())); } } -- Gitee