From 669e65e4c52ed2fa9810617a09a62193c82248a0 Mon Sep 17 00:00:00 2001 From: nj1868 Date: Mon, 3 Mar 2025 15:55:28 +0800 Subject: [PATCH] sync Signed-off-by: nj1868 --- adapter/ohos/CommandParser.java | 8 +- adapter/ohos/CompressEntrance.java | 8 +- adapter/ohos/CompressVerify.java | 389 ++++++--- adapter/ohos/Compressor.java | 511 +++++++----- adapter/ohos/ErrorMsg.java | 193 +++++ adapter/ohos/FileUtils.java | 13 +- adapter/ohos/HapVerify.java | 415 ++++++---- adapter/ohos/ModuleJsonUtil.java | 180 ++-- adapter/ohos/PackingToolErrMsg.java | 1198 +++++++++++++++++++++++++++ adapter/ohos/Utility.java | 3 +- build.py | 12 +- 11 files changed, 2329 insertions(+), 601 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..a6976e98 100644 --- a/adapter/ohos/CompressVerify.java +++ b/adapter/ohos/CompressVerify.java @@ -91,13 +91,13 @@ 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("--force must be either 'true' or 'false'.")); return false; } return commandPathVerify(utility); @@ -140,7 +140,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; } } @@ -157,29 +157,35 @@ public class CompressVerify { private static boolean validatePackageNormalizeMode(Utility utility) { if (utility.getHspList().isEmpty()) { - LOG.error("CompressVerify::validatePackageNormalizeMode hsp-list is empty."); + String errMsg = "hsp-list is empty."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } else { if (!compatibleProcess(utility, utility.getHspList(), utility.getFormattedHspPathList(), HSP_SUFFIX)) { - LOG.error("CompressVerify::validatePackageNormalizeMode hsp-list is invalid."); + String errMsg = "hsp-list is invalid."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!isBundleNameValid(utility.getBundleName())) { - LOG.error("CompressVerify::validatePackageNormalizeMode bundle-name is invalid."); + String errMsg = "bundle-name is invalid."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getVersionCode() <= 0) { - LOG.error("CompressVerify::validatePackageNormalizeMode version-code is invalid."); + String errMsg = "version-code is invalid."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getOutPath().isEmpty()) { - LOG.error("CompressVerify::validatePackageNormalizeMode out-path is empty."); + String errMsg = "out-path is empty."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } File outDir = new File(utility.getOutPath()); if (!outDir.isDirectory()) { - LOG.error("CompressVerify::validatePackageNormalizeMode out-path is not a directory."); + String errMsg = "out-path is not a directory."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -187,45 +193,53 @@ public class CompressVerify { private static boolean validateVersionNormalizeMode(Utility utility) { if (utility.getInputList().isEmpty()) { - LOG.error("CompressVerify::validateVersionNormalizeMode input-list is empty."); + String errMsg = "input-list is empty."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!handleHapAndHspInput(utility, utility.getInputList(), utility.getFormattedHapList())) { - LOG.error("CompressVerify::validateVersionNormalizeMode input-list is invalid."); + String errMsg = "input-list is invalid."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getFormattedHapList().isEmpty()) { - LOG.error("CompressVerify::validateVersionNormalizeMode input-list is empty."); + String errMsg = "input-list is empty."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getVersionCode() <= 0) { - LOG.error("CompressVerify::validateVersionNormalizeMode version-code is invalid."); + String errMsg = "version-code is invalid."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getVersionName().isEmpty()) { - LOG.error("CompressVerify::validateVersionNormalizeMode version-name is empty."); + String errMsg = "version-name is empty."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } Pattern versionNamePattern = Pattern.compile(VERSION_NAME_PATTERN); Matcher versionNameMatcher = versionNamePattern.matcher(utility.getVersionName()); if (!versionNameMatcher.matches()) { - LOG.error("CompressVerify::validateVersionNormalizeMode version-name is not valid."); + String errMsg = "version-name is not valid."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getOutPath().isEmpty()) { - LOG.error("CompressVerify::validateVersionNormalizeMode out-path is empty."); + String errMsg = "out-path is empty."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } File outDir = new File(utility.getOutPath()); if (!outDir.isDirectory()) { - LOG.error("CompressVerify::validateVersionNormalizeMode out-path is not a directory."); + String errMsg = "out-path is not a directory."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -235,11 +249,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 +266,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 +281,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 +298,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 +352,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; } @@ -420,45 +460,53 @@ public class CompressVerify { */ private static boolean isVerifyValidInHarMode(Utility utility) { if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::isArgsValidInHarMode json-path is empty."); + String errMsg = "json-path is empty."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!isPathValid(utility.getJsonPath(), TYPE_FILE, JSON_PROFILE) && !isPathValid(utility.getJsonPath(), TYPE_FILE, MODULE_PROFILE)) { - LOG.error("CompressVerify::isArgsValidInHarMode json-path must be config.json file."); + String errMsg = "json-path must be config.json file."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getJarPath().isEmpty() && !compatibleProcess(utility, utility.getJarPath(), utility.getFormattedJarPathList(), JAR_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHarMode jar-path is invalid."); + String errMsg = "jar-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getTxtPath().isEmpty() && !compatibleProcess(utility, utility.getTxtPath(), utility.getFormattedTxtPathList(), TXT_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHarMode txt-path is invalid."); + String errMsg = "txt-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getLibPath().isEmpty() && !isPathValid(utility.getLibPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode lib-path is invalid."); + String errMsg = "lib-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getResPath().isEmpty() && !isPathValid(utility.getResPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode res-path is invalid."); + String errMsg = "res-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getResourcesPath().isEmpty() || !isPathValid(utility.getResourcesPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode resources-path is invalid."); + String errMsg = "resources-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getAssetsPath().isEmpty() && !isPathValid(utility.getAssetsPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode assets-path is invalid."); + String errMsg = "assets-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -473,7 +521,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 +532,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 +601,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 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 modules.")); return false; } } @@ -590,41 +650,48 @@ public class CompressVerify { */ private static boolean isVerifyValidInMultiAppMode(Utility utility) { if (utility.getAppList().isEmpty() && utility.getHapList().isEmpty() && utility.getHspList().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode input app-list, hap-list and hsp-list are null."); + String errMsg = "input app-list, hap-list and hsp-list are null."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getAppList().isEmpty()) { if (!compatibleProcess(utility, utility.getAppList(), utility.getFormattedAppList(), APP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode app-list is invalid."); + String errMsg = "app-list is invalid."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!utility.getHapList().isEmpty()) { if (!compatibleProcess(utility, utility.getHapList(), utility.getFormattedHapList(), HAP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode hap-list is invalid."); + String errMsg = "hap-list is invalid."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!utility.getHspList().isEmpty()) { if (!compatibleProcess(utility, utility.getHspList(), utility.getFormattedHapList(), HSP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode hsp-list is invalid."); + String errMsg = "hsp-list is invalid."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!isValidEncryptJsonFile(utility)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode encrypt-path is invalid."); + String errMsg = "encrypt-path is invalid."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } File outFile = new File(utility.getOutPath()); if (("false".equals(utility.getForceRewrite())) && outFile.exists()) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode out file already existed."); + String errMsg = "--force is false, out file already existed."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(APP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode out-path must end with .app."); + String errMsg = "out-path must end with .app."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -639,18 +706,20 @@ public class CompressVerify { */ private static boolean isVerifyValidInResMode(Utility utility) { if (!isPathValid(utility.getPackInfoPath(), TYPE_FILE, PACK_INFO)) { - LOG.error("CompressVerify::isArgsValidInResMode pack-info-path is invalid."); + String errMsg = "pack-info-path is invalid."; + LOG.error(PackingToolErrMsg.RES_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!isDirectoryValidStrictCase(utility.getEntryCardPath(), ENTRY_CARD_DIRECTORY_NAME)) { - LOG.error("CompressVerify::isArgsValidInResMode the level-1 directory name must is EntryCard" + - ", current is " + utility.getEntryCardPath()); + String errMsg = "the level-1 directory name must is EntryCard, current is "; + LOG.error(PackingToolErrMsg.RES_MODE_ARGS_INVALID.toString(errMsg + utility.getEntryCardPath())); return false; } if (!compatibleProcess(utility, utility.getEntryCardPath(), utility.getformattedEntryCardPathList(), PNG_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInResMode entrycard-path is invalid."); + String errMsg = "entrycard-path is invalid."; + LOG.error(PackingToolErrMsg.RES_MODE_ARGS_INVALID.toString(errMsg)); return false; } return isOutPathValid(utility, RES_SUFFIX); @@ -658,38 +727,44 @@ public class CompressVerify { private static boolean isVerifyValidInHQFMode(Utility utility) { if (utility.getJsonPath().isEmpty()) { - LOG.error("must input patch.json file when pack hqf file."); + String errMsg = "must input patch.json file when pack hqf file."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getEtsPath().isEmpty()) { if (!isPathValid(utility.getEtsPath(), TYPE_DIR, null)) { - LOG.error("must input valid ets path when pack hqf file."); + String errMsg = "must input valid ets path when pack hqf file."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!isPathValid(utility.getJsonPath(), TYPE_FILE, PATCH_PROFILE)) { - LOG.error("input patch.json is invalid when pack hqf file."); + String errMsg = "input patch.json is invalid when pack hqf file."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getLibPath().isEmpty()) { if (!isPathValid(utility.getLibPath(), TYPE_DIR, null)) { - LOG.error("input lib path is invalid when pack hqf file."); + String errMsg = "input lib path is invalid when pack hqf file."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!utility.getResourcesPath().isEmpty()) { if (!isPathValid(utility.getResourcesPath(), TYPE_DIR, null)) { - LOG.error("input resources path is invalid when pack hqf file."); + String errMsg = "input resources path is invalid when pack hqf file."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } } File outFile = new File(utility.getOutPath()); if ((FALSE.equals(utility.getForceRewrite())) && (outFile.exists())) { - LOG.error(outFile.getName() + " already exist."); + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(outFile.getName() + " already exist.")); return false; } if (!utility.getOutPath().endsWith(HQF_SUFFIX)) { - LOG.error("input out file must end with .hqf."); + String errMsg = "input out file must end with .hqf."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -697,20 +772,24 @@ public class CompressVerify { private static boolean isVerifyValidInAPPQFMode(Utility utility) { if (utility.getHqfList().isEmpty()) { - LOG.error("input hqf list is empty."); + String errMsg = "input hqf list is empty."; + LOG.error(PackingToolErrMsg.APPQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!compatibleProcess(utility, utility.getHqfList(), utility.getFormatedHQFList(), HQF_SUFFIX)) { - LOG.error("input hqf list is invalid."); + String errMsg = "input hqf list is invalid."; + LOG.error(PackingToolErrMsg.APPQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } File outFile = new File(utility.getOutPath()); if ((FALSE.equals(utility.getForceRewrite())) && outFile.exists()) { - LOG.error("Error out file already existed."); + String errMsg = "Error out file already existed."; + LOG.error(PackingToolErrMsg.APPQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(APPQF_SUFFIX)) { - LOG.error("Error out-path must end with .app."); + String errMsg = "Error out-path must end with .app."; + LOG.error(PackingToolErrMsg.APPQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -774,7 +853,8 @@ public class CompressVerify { formattedPathItem = utility.getFormattedPath(pathItem); if (!isPathValid(formattedPathItem, TYPE_FILE, HSP_SUFFIX) && !isPathValid(formattedPathItem, TYPE_FILE, HAP_SUFFIX)) { - LOG.error("input file " + formattedPathItem + " not valid"); + LOG.error(PackingToolErrMsg.INPUT_PATH_INVALID.toString( + "input file " + formattedPathItem + " not valid")); return false; } fileList.add(formattedPathItem); @@ -806,13 +886,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 +901,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 +910,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 +919,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 +928,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; @@ -884,8 +964,8 @@ public class CompressVerify { private static boolean isDirectoryValidStrictCase(String path, String directoryName) { File file = new File(path); if (!file.exists()) { - LOG.error("CompressVerify::isDirectoryValidStrictCase directory is not exist, directoryPath: " - + path + "."); + String errMsg = "directory is not exist, directoryPath: "; + LOG.error(PackingToolErrMsg.DIRECTORY_INVALID.toString(errMsg + path)); return false; } if (file.isDirectory()) { @@ -914,12 +994,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 +1009,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 at the same time."; + 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; } @@ -1016,48 +1110,58 @@ public class CompressVerify { private static boolean isVerifyValidInHapAdditionMode(Utility utility) { if (utility.getHapPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hapPath is empty."); + String errMsg = "hapPath is empty."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } String hapPath = utility.getAbsoluteHapPath(); File hapFile = new File(hapPath); if (hapFile.isDirectory()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hapPath cannot be a folder."); + String errMsg = "hapPath cannot be a folder."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!(hapPath.endsWith(HAP_SUFFIX) || hapPath.endsWith(HSP_SUFFIX))) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hapPath is invalid."); + String errMsg = "hapPath is invalid."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!hapFile.exists()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hap file does not exist."); + String errMsg = "hap file does not exist."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode jsonPath is empty."); + String errMsg = "jsonPath is empty."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getJsonPath().endsWith(JSON_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode jsonPath is invalid."); + String errMsg = "jsonPath is invalid."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } File jsonFile = new File(utility.getJsonPath()); if (!jsonFile.exists()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode json file does not exist."); + String errMsg = "json file does not exist."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!checkJsonIsValid(jsonFile)) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode json format is incorrect."); + String errMsg = "json format is incorrect."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getOutPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode outPath is empty."); + String errMsg = "outPath is empty."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } File dir = new File(utility.getOutPath()); if (dir.exists() && dir.isFile()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode outPath is file."); + String errMsg = "outPath is file."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } File absoluteHapFile = new File(utility.getAbsoluteHapPath()); @@ -1065,7 +1169,8 @@ public class CompressVerify { String destPath = utility.getOutPath() + LINUX_FILE_SEPARATOR + hapFileName; File destFile = new File(destPath); if ("false".equals(utility.getForceRewrite()) && destFile.exists()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode target file already exists."); + String errMsg = "target file already exists."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -1080,7 +1185,8 @@ public class CompressVerify { jsonData.append((char) ch); } } catch (IOException e) { - LOG.error("CompressVerify::CheckJsonIsValid failed: " + e.getMessage()); + String errMsg = "IOException Check Json Is Valid failed: "; + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg + e.getMessage())); return false; } JSONValidator validator = JSONValidator.from(jsonData.toString()); @@ -1154,11 +1260,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 file 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 +1276,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 file 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; } } @@ -1182,13 +1290,15 @@ public class CompressVerify { try { Optional optional = FileUtils.getFileContent(utility.getJsonPath()); if(optional.isPresent()) { - return ModuleJsonUtil.parseModuleType(optional.get()).equals(BUNDLE_TYPE_SHARE) && !ModuleJsonUtil.parseAbilityNames(optional.get()).isEmpty(); + return ModuleJsonUtil.parseModuleType(optional.get()).equals(BUNDLE_TYPE_SHARE) && + !ModuleJsonUtil.parseAbilityNames(optional.get()).isEmpty(); } else { - LOG.error("CompressVerify::hspHasAbilities jsonPath content invalid"); + String errMsg = "Parse json path file 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 +1310,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 file 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 +1324,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 file content failed."; + LOG.error(PackingToolErrMsg.HAS_HOME_ABILITY_INVALID.toString(errMsg)); return false; } Map abilitiesMap = ModuleJsonUtil.parseAbilitySkillsMap(optional.get()); @@ -1223,7 +1335,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 +1361,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 file content failed."; + LOG.error(PackingToolErrMsg.HAS_HOME_EXTENSION_ABILITY_INVALID.toString(errMsg)); return false; } Map extensionAbilitiesMap = ModuleJsonUtil.parseExtensionAbilitySkillsMap(optional.get()); @@ -1259,7 +1372,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..9a7d7c23 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -348,7 +348,9 @@ public class Compressor { File outParentFile = destFile.getParentFile(); if ((outParentFile != null) && (!outParentFile.exists())) { if (!outParentFile.mkdirs()) { - LOG.error("Compressor::compressProcess create out file parent directory failed."); + String errMsg = "Create out file parent directory failed."; + String solution = "Check input --out-path."; + LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_FAILED.toString(errMsg, solution)); return false; } } @@ -363,10 +365,10 @@ public class Compressor { compressExcute(utility); } catch (FileNotFoundException exception) { compressResult = false; - LOG.error("Compressor::compressProcess file not found exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("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,17 @@ public class Compressor { if (compressResult && !checkAppAtomicServiceCompressedSizeValid(utility)) { compressResult = false; - LOG.error("Compressor::compressProcess check atomic service size fail."); } // 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 +431,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 ContinueBundleNameIs 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 +475,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 Stage Hap info failed.")); + throw new BundleException("Verify Stage Hap info failed."); } Optional optional = FileUtils.getFileContent(utility.getJsonPath()); String jsonString = optional.get(); @@ -494,8 +499,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 = "Parse json file not exist."; + LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString(errMsg)); + throw new BundleException("Verify has generate build hash failed for json file not exist."); } InputStream json = null; boolean res = false; @@ -503,8 +509,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("json file is invalid.")); + throw new BundleException("Parse json file is invalid."); } JSONObject appJson = jsonObject.getJSONObject(APP); JSONObject moduleJson = jsonObject.getJSONObject(MODULE); @@ -512,11 +518,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 +538,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 file not exist."; + LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString(errMsg)); + throw new BundleException("Set generate build hash failed for json file not exist."); } InputStream json = null; BufferedWriter bw = null; @@ -540,7 +548,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 file is invalid.")); throw new BundleException("json file is invalid."); } JSONObject appJson = jsonObject.getJSONObject(APP); @@ -561,11 +569,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 +582,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 +594,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 +618,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 +640,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."); } } @@ -646,7 +658,8 @@ public class Compressor { } while (numRead != -1); return complete.digest(); } catch (IOException | NoSuchAlgorithmException e) { - LOG.error("Compressor::checkSum failed, IOException or NoSuchAlgorithmException: " + e.getMessage()); + LOG.error(PackingToolErrMsg.CHECK_SUM_FAILED.toString("Check Sum failed, IOException | " + + "NoSuchAlgorithmException: " + e.getMessage())); throw new BundleException("Compressor::checkSum failed."); } } @@ -673,8 +686,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 +702,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 +736,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 +752,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 +764,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 +792,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 +805,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 +825,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 +833,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 +847,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 +868,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 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 +890,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 can not be set with requestPermissions 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 module(" + moduleName + ") targetModuleName can not be same with overlay module name.")); 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 can not be existed without the targetModuleName in module.json.")); return false; } } @@ -885,16 +915,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 +1225,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 failed, " + e.getMessage())); + throw new BundleException("Compress pack.info into hap failed."); } } @@ -1209,16 +1243,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 failed, " + 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 +1275,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) { @@ -1281,15 +1314,14 @@ public class Compressor { } // check hap is valid if (!checkHapIsValid(fileList, utility.getSharedApp())) { - String msg = "Compressor::checkHapIsValid verify failed, check version, " + - "apiVersion, moduleName, packageName."; - LOG.error(msg); - throw new BundleException(msg); + LOG.error(PackingToolErrMsg.COMPRESS_APP_FAILED.toString("Verify failed when compress fast app.")); + throw new BundleException("Compress file verify failed, check version, " + + "apiVersion,moduleName,packageName."); } - // packApp + // packApp packFastApp(utility, fileList); } catch (IOException ex) { - LOG.error("Compressor::compressAppMode compress failed: " + ex.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Compress fast app mode failed, IOException: " + ex.getMessage())); throw new BundleException("Compressor::compressAppMode compress failed."); } finally { if (tmpDir != null) { @@ -1380,8 +1412,8 @@ public class Compressor { //pack encrypt.json file packEncryptJsonFile(utility); } catch (BundleException | IOException exception) { - String errMsg = "Compressor::compressAppModeForMultiProject file failed: " + exception.getMessage(); - LOG.error(errMsg); + String errMsg = "Compress app mode for multi project file failed, BundleException | IOException: " + exception.getMessage(); + LOG.error(PackingToolErrMsg.COMPRESS_APP_MODE_FORMULTI_PROJECT_FAILED.toString(errMsg)); throw new BundleException(errMsg); } finally { deleteFile(tempPath); @@ -1402,7 +1434,7 @@ public class Compressor { File outParentFile = destFile.getParentFile(); if ((outParentFile != null) && (!outParentFile.exists())) { if (!outParentFile.mkdirs()) { - LOG.error("Compressor::hapAddition create out file parent directory failed."); + LOG.error(PackingToolErrMsg.DIR_CREATION_FAILED.toString("Create out file parent directory failed when compress in hapAddition mode.")); } } FileOutputStream fileOut = null; @@ -1419,7 +1451,8 @@ public class Compressor { compressHapAddition(utility, hapAdditionPath); } catch (BundleException | IOException exception) { - LOG.error("Compressor::HapAddition hapFile not found exception" + exception.getMessage()); + LOG.error(PackingToolErrMsg.HAP_ADDITION_FAILED.toString("Hap addition hapFile not found," + + "BundleException | IOException: " + exception.getMessage())); copyFileSafely(backName, hapPathOri); } finally { closeZipOutputStream(); @@ -1447,7 +1480,7 @@ public class Compressor { File destFile = new File(dest); FileUtils.copyFile(sourceFile, destFile); } catch (IOException | BundleException e) { - LOG.error("copyFileSafely failed: " + e.getMessage()); + LOG.error(PackingToolErrMsg.COPY_FILE_SAFELY_FAILED.toString("IOException | BundleException: " + e.getMessage())); } } @@ -1472,10 +1505,10 @@ public class Compressor { fileWriter.write(jsonString); fileWriter.flush(); } catch (IOException exception) { - LOG.error("writeJsonFile failed, " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Write json File failed, IOException: " + exception.getMessage())); throw new BundleException(exception.getMessage()); } catch (JSONException e) { - LOG.error("json file is invalid: " + e.getMessage()); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("Json file is invalid, JSONException: " + e.getMessage())); throw new BundleException(e.getMessage()); } } @@ -1541,14 +1574,14 @@ public class Compressor { File targetParent = new File(targetParentPath); if (!targetParent.exists()) { if (!targetParent.mkdirs()) { - LOG.error("Compressor::compressHapAddition create target file parent directory failed."); + LOG.error(PackingToolErrMsg.DIR_CREATION_FAILED.toString("Create target file parent directory failed when generate addition.json file.")); } } String targetPath = targetParentPath + LINUX_FILE_SEPARATOR + ADDITION_JSON; writeJsonFile(data, targetPath); } catch (IOException | JSONException | BundleException e) { - String errMsg = "Compressor::compressHapAddition generate addition.json file failed, " + e.getMessage(); - LOG.error(errMsg); + String errMsg = "Generate addition.json file failed, IOException | JSONException | BundleException e: " + e.getMessage(); + LOG.error(PackingToolErrMsg.COMPRESS_HAP_ADDITION_FAILED.toString(errMsg)); throw new BundleException(errMsg); } @@ -1556,8 +1589,8 @@ public class Compressor { try { setUtilityParameter(hapAdditionPath, utility); } catch (IOException e) { - String errMsg = "Compressor::compressHapAddition setUtilityParameter failed."; - LOG.error(errMsg); + String errMsg = "Set utility parameter failed."; + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg + " IOException: " + e.getMessage())); throw new BundleException(errMsg); } if (utility.getHapPath().endsWith(HAP_SUFFIX)) { @@ -1566,7 +1599,7 @@ public class Compressor { compressHsp(utility); } else { String errMsg = "Compressor::compressHapAddition compressFile failed."; - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.UNSUPPORTED_FILE_TYPE.toString(errMsg)); throw new BundleException(errMsg); } } @@ -1592,8 +1625,9 @@ public class Compressor { finalAppPackInfo = selectHapInApp(appPath, seletedHaps, tempDir, finalAppPackInfo); } } catch (BundleException | IOException e) { - String errMsg = "Compressor:disposeApp disposeApp failed."; - LOG.error(errMsg); + String errMsg = "Dispose app failed."; + LOG.error(PackingToolErrMsg.DISPOSE_APP_FAILED.toString(errMsg + + " BundleException | IOException: " + e.getMessage())); throw new BundleException(errMsg); } return finalAppPackInfo; @@ -1614,8 +1648,8 @@ public class Compressor { // rebuild pack.info String packInfoStr = FileUtils.getJsonInZips(new File(appPath), PACKINFO_NAME); if (packInfoStr.isEmpty()) { - String errorMsg = "Compressor:selectHapInApp failed, app has no pack.info."; - LOG.error(errorMsg); + String errorMsg = "Select hap in app failed, app has no pack.info."; + LOG.error(PackingToolErrMsg.NO_PACK_INFO.toString(errorMsg)); throw new BundleException(errorMsg); } if (finalAppPackInfo.isEmpty()) { @@ -1655,7 +1689,8 @@ public class Compressor { } // copy duplicated hap to duplicated dir and get moduleName of duplicated hap if (selectedHaps.contains(zipEntry.getName())) { - LOG.error("Compressor::copyHapFromApp file duplicated, file is " + zipEntry.getName() + "."); + LOG.error(PackingToolErrMsg.COMPRESS_FILE_DUPLICATE.toString("Copy hap from app file duplicated, file is " + + zipEntry.getName() + ".")); throw new BundleException("Compressor::copyHapFromApp file duplicated, file is " + zipEntry.getName() + "."); } else { @@ -1675,8 +1710,8 @@ public class Compressor { inputStream.close(); } } catch (IOException e) { - String errMsg = "Compressor:copyHapFromApp app path not found."; - LOG.error(errMsg); + String errMsg = "Copy hap filed with app path not found."; + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg + " IOException: " + e.getMessage())); throw new BundleException(errMsg); } finally { Utility.closeStream(zipInput); @@ -1722,7 +1757,8 @@ public class Compressor { } for (String hapPath : utility.getFormattedHapList()) { if (seletedHaps.contains(new File(hapPath).getName())) { - LOG.error("Compressor::disposeHap file duplicated, file is " + new File(hapPath).getName() + "."); + LOG.error(PackingToolErrMsg.COMPRESS_FILE_DUPLICATE.toString("Dispose hap file duplicated, file is " + + new File(hapPath).getName() + ".")); throw new BundleException("Compressor::disposeHap file duplicated, file is " + new File(hapPath).getName() + "."); } @@ -1733,8 +1769,8 @@ public class Compressor { String packInfo = FileUtils.getJsonInZips(hapFile, PACKINFO_NAME); if (packInfo.isEmpty()) { - String errMsg = "Compressor::disposeHap failed, hap has no pack.info."; - LOG.error(errMsg); + String errMsg = "Dispose hap failed, hap has no pack.info."; + LOG.error(PackingToolErrMsg.NO_PACK_INFO.toString(errMsg)); throw new BundleException(errMsg); } if (finalPackInfoStr.isEmpty()) { @@ -1759,8 +1795,8 @@ public class Compressor { fwriter = new FileWriter(filePath); fwriter.write(packInfoStr); } catch (IOException e) { - String errMsg = "Compressor:writePackInfo failed."; - LOG.error(errMsg); + String errMsg = "Write pack info failed."; + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg + " IOException: " + e.getMessage())); throw new BundleException(errMsg); } finally { if (fwriter != null) { @@ -1813,7 +1849,8 @@ public class Compressor { } append.closeEntry(); } catch (IOException exception) { - LOG.error("Compressor::compressPackinfoIntoHap io exception."); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Compress pack info into hap io exception. IOException: " + + exception.getMessage())); throw new BundleException("Compressor::compressPackinfoIntoHap io exception."); } finally { sourceHapFile.close(); @@ -1859,21 +1896,21 @@ public class Compressor { String fName = fileName.trim(); String[] temp = fName.replace("\\", "/").split("/"); if (temp.length < 4) { - LOG.error("Compressor::compressPackResMode the hap file path is invalid, length: " - + temp.length + "."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE.toString("Compress pack res mode the hap file path is invalid, length: " + + temp.length + ".")); continue; } String fileLanguageCountryName = temp[temp.length - 3]; if (!isThirdLevelDirectoryNameValid(fileLanguageCountryName)) { - LOG.error("Compressor::compressProcess compress failed third level directory name: " - + fileLanguageCountryName + " is invalid, please check it with reference to this example: " - + "zh_Hani_CN-vertical-car-mdpi-dark or zh_Hani_CN-vertical-car-mdpi."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE.toString("Compress failed third level directory name: " + + fileLanguageCountryName + " is invalid, please check it with reference to this example: " + + "zh_Hani_CN-vertical-car-mdpi-dark or zh_Hani_CN-vertical-car-mdpi.")); throw new BundleException("Compress failed third level directory name Error."); } String filePicturingName = temp[temp.length - 1]; if (!isPicturing(filePicturingName, utility)) { - LOG.error("Compressor::compressProcess Compress pack.res failed, Invalid resource file" + - " name: " + filePicturingName + ", correct format example is formName-2x2.png."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE.toString("Compress pack.res failed, Invalid resource file" + + " name: " + filePicturingName + ", correct format example is formName-2x2.png.")); throw new BundleException("Compress pack.res failed, Invalid resource file name: " + filePicturingName + ", correct format example is formName-2x2.png."); } @@ -1883,7 +1920,7 @@ public class Compressor { snapshotNameList.add(fullSnapshotName); } else { - LOG.error("Compressor::compressProcess compress failed No image in PNG format is found."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE.toString("Compress failed No image in PNG format is found.")); throw new BundleException("Compress pack.res failed, compress failed No image in" + " PNG format is found."); } @@ -1891,8 +1928,8 @@ public class Compressor { for (String formName : formNamesList) { if (!snapshotNameList.contains(formName)) { - LOG.error("Compressor::compressProcess compress failed entryCard " + formName - + " has no related snapshot " + snapshotNameList.toString() + "."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE.toString("Compress failed entryCard " + formName + + " has no related snapshot " + snapshotNameList.toString() + ".")); throw new BundleException("Compress pack.res failed, compress failed entryCard has no related snapshot."); } } @@ -1979,7 +2016,7 @@ public class Compressor { private boolean checkLanguage(String language) { if (!Pattern.compile(REGEX_LANGUAGE).matcher(language).matches()) { - LOG.error("Compressor::compressProcess language " + language + " is not in ISO 639-1 list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(language + " is not in ISO 639-1 list.")); return false; } return true; @@ -1987,7 +2024,7 @@ public class Compressor { private boolean checkScript(String script) { if (!Pattern.compile(REGEX_SCRIPT).matcher(script).matches()) { - LOG.error("Compressor::compressProcess script " + script + " is not in ISO 15924 list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(script + " is not in ISO 15924 list.")); return false; } return true; @@ -1995,7 +2032,7 @@ public class Compressor { private boolean checkCountry(String country) { if (!Pattern.compile(REGEX_COUNTRY).matcher(country).matches()) { - LOG.error("Compressor::compressProcess country " + country + " is not in ISO 3166-1 list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(country + " is not in ISO 3166-1 list.")); return false; } return true; @@ -2003,8 +2040,8 @@ public class Compressor { private boolean checkOrientation(String orientation) { if (!Pattern.compile(REGEX_ORIENTATION).matcher(orientation).matches()) { - LOG.error("Compressor::compressProcess orientation " + orientation + - " is not in {vertical, horizontal} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(orientation + + " is not in {vertical, horizontal} list.")); return false; } return true; @@ -2012,8 +2049,8 @@ public class Compressor { private boolean checkDeviceType(String deviceType) { if (!Pattern.compile(REGEX_DEVICE_TYPE).matcher(deviceType).matches()) { - LOG.error("Compressor::compressProcess deviceType " + deviceType + - " is not in {phone, tablet, car, tv, wearable, liteWearable, 2in1} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(deviceType + " is not in {phone, tablet, car, tv," + + "wearable, liteWearable, 2in1} list.")); return false; } return true; @@ -2021,8 +2058,8 @@ public class Compressor { private boolean checkScreenDensity(String screenDensity) { if (!Pattern.compile(REGEX_SCREEN_DENSITY).matcher(screenDensity).matches()) { - LOG.error("Compressor::compressProcess screenDensity " + screenDensity + - " is not in {sdpi, mdpi, ldpi, xldpi, xxldpi} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(screenDensity + + " is not in {sdpi, mdpi, ldpi, xldpi, xxldpi} list.")); return false; } return true; @@ -2030,8 +2067,8 @@ public class Compressor { private boolean checkColorMode(String colorMode) { if (!Pattern.compile(REGEX_COLOR_MODE).matcher(colorMode).matches()) { - LOG.error("Compressor::compressProcess colorMode " + colorMode + - " is not in {light, dark} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(colorMode + + " is not in {light, dark} list.")); return false; } return true; @@ -2042,8 +2079,8 @@ public class Compressor { Pattern.compile(REGEX_SHAPE).matcher(tmp).matches()) { return true; } - LOG.error("Compressor::compressProcess " + tmp + - " is neither in colorMode list {light, dark} nor in shape list {circle}."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(tmp + +" is neither in colorMode list {light, dark} nor in shape list {circle}.")); return false; } @@ -2051,7 +2088,7 @@ public class Compressor { if (Pattern.compile(REGEX_SHAPE).matcher(shape).matches()) { return true; } - LOG.error("Compressor::compressProcess shape" + shape + " is not in {circle} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(shape + " is not in {circle} list.")); return false; } @@ -2068,24 +2105,26 @@ public class Compressor { return isSpecifications; } if (!name.endsWith(PNG_SUFFIX) && !name.endsWith(UPPERCASE_PNG_SUFFIX)) { - LOG.error("isPicturing: the suffix is not .png or .PNG."); + LOG.error(PackingToolErrMsg.UNSUPPORTED_FILE_TYPE.toString("the suffix is not .png or .PNG.")); return false; } int delimiterIndex = name.lastIndexOf("-"); if (delimiterIndex < 0) { - LOG.error("isPicturing: the entry card naming format is invalid and should be separated by '-'."); + LOG.error(PackingToolErrMsg.IS_PICTURING_FAILED.toString( + "the entry card naming format is invalid and should be separated by '-'.")); return false; } String formName = name.substring(0, delimiterIndex); if (!utility.getFormNameList().contains(formName)) { - LOG.error("isPicturing: the name is not same as formName, name: " + formName + " is not in " + - utility.getFormNameList().toString() + "."); + LOG.error(PackingToolErrMsg.IS_PICTURING_FAILED.toString( + "the name is not same as formName, name: " + formName + " is not in " + + utility.getFormNameList().toString() + ".")); return false; } String dimension = name.substring(delimiterIndex + 1, name.lastIndexOf(".")); if (!supportDimensionsList.contains(dimension)) { - LOG.error("isPicturing: the dimension: " + dimension + " is invalid, is not in the following list: " - + "{1X2, 2X2, 2X4, 4X4, 1X1, 6X4}."); + LOG.error(PackingToolErrMsg.IS_PICTURING_FAILED.toString(dimension + " is invalid, is not in the following list: " + + "{1X2, 2X2, 2X4, 4X4, 1X1, 6X4}.")); return false; } @@ -2095,12 +2134,12 @@ public class Compressor { private void getFileList(final String filePath) throws BundleException { File file = new File(filePath); if (!file.exists()) { - LOG.error("getFileList: file is not exists."); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("File is not exists.")); return; } File[] files = file.listFiles(); if (files == null) { - LOG.error("getFileList: no file in this file path."); + LOG.error(PackingToolErrMsg.GET_FILE_LIST_FAILED.toString("No file in this file path.")); return; } for (File f : files) { @@ -2112,8 +2151,8 @@ public class Compressor { } String snapshotDirectoryName = f.getParentFile().getName(); if (!ENTRYCARD_SNAPSHOT_NAME.equals(snapshotDirectoryName)) { - LOG.error("The level-4 directory of EntryCard must be named as snapshot" + - ", but current is: " + snapshotDirectoryName + "."); + LOG.error(PackingToolErrMsg.GET_FILE_LIST_FAILED.toString("The level-4 directory of EntryCard must be named as snapshot" + + ", but current is: " + snapshotDirectoryName + ".")); throw new BundleException("The level-4 directory of EntryCard must be named as snapshot" + ", but current is: " + snapshotDirectoryName + "."); } @@ -2121,10 +2160,10 @@ public class Compressor { } else if (f.isDirectory()) { getFileList(f.getCanonicalPath()); } else { - LOG.error("It's not file or directory."); + LOG.error(PackingToolErrMsg.GET_FILE_LIST_FAILED.toString("It's not file or directory.")); } } catch (IOException msg) { - LOG.error("IOException error: " + msg.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("IOException error: " + msg.getMessage())); return; } } @@ -2213,9 +2252,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 +2276,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; } }; @@ -2352,11 +2392,13 @@ public class Compressor { } } } catch (FileNotFoundException ignored) { - LOG.error("Compressor::compressFile file not found exception."); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("File not found exception.")); } catch (IOException exception) { - LOG.error("Compressor::compressFile io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Compress file io exception: " + + exception.getMessage())); } catch (BundleException bundleException) { - LOG.error("Compressor::compressFile bundle exception" + bundleException.getMessage()); + LOG.error(PackingToolErrMsg.COMPRESS_FAILED.toString("Compress file bundle exception" + + bundleException.getMessage())); } finally { Utility.closeStream(in); } @@ -2385,10 +2427,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 +2508,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 +2543,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 +2574,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); @@ -2547,14 +2595,14 @@ public class Compressor { ModuleJsonUtil.parsePackInfoFormsName(jsonString, nameList, formNamesList); for (String formName : nameList) { if (formName.isEmpty()) { - LOG.error("Compressor::infoSpecialJsonFileProcess form name is empty."); + LOG.warning("Info special json file process form name is empty."); continue; } utility.addFormNameList(formName); } } catch (JSONException e) { - LOG.error("Compressor::infoSpecialJsonFileProcess json Path: " + jsonPath + + LOG.warning("Info special json file process json Path: " + jsonPath + "json exception: " + e.getMessage()); } } @@ -2586,7 +2634,8 @@ public class Compressor { str = bufferedReader.readLine(); } } catch (IOException exception) { - LOG.error("Compressor::jsonSpecialProcess io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Json special process failed. io exception: " + + exception.getMessage())); throw new BundleException("Json special process failed."); } finally { Utility.closeStream(bufferedReader); @@ -2656,7 +2705,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 { @@ -2689,7 +2738,8 @@ public class Compressor { } } } catch (IOException exception) { - LOG.error("Compressor::parseModuleName io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Parse module name failed. io exception: " + + exception.getMessage())); throw new BundleException("Parse module name failed."); } } @@ -2719,12 +2769,11 @@ public class Compressor { } } } catch (IOException exception) { - LOG.error("Compressor::parseModuleName io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Parse module name failed. io exception: " + exception.getMessage())); throw new BundleException("Parse module name failed."); } } - /** * Get name from line string * @@ -2767,19 +2816,20 @@ public class Compressor { try { int endIndex = lineStr.lastIndexOf(SEMICOLON); if (endIndex <= 0) { - LOG.error("Compressor::getModuleNameFromString field the json is not standard."); + LOG.error(PackingToolErrMsg.GET_MODULE_NAME_FROM_STRING_FAILED.toString("Json is not standard.")); throw new BundleException("Parse module name failed, module-name is invalid."); } int startIndex = lineStr.lastIndexOf(SEMICOLON, endIndex - 1) + 1; String moduleName = lineStr.substring(startIndex, endIndex); list.add(moduleName); if (moduleName == null || moduleName.isEmpty()) { - LOG.error("Compressor::getModuleNameFromString field module-name is empty."); + LOG.error(PackingToolErrMsg.GET_MODULE_NAME_FROM_STRING_FAILED.toString("Module-name is empty.")); throw new BundleException("Parse module name failed, module-name is empty."); } utility.setModuleName(moduleName); } catch (StringIndexOutOfBoundsException exception) { - LOG.error("Compressor::parseModuleName field module-name is fault: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.GET_MODULE_NAME_FROM_STRING_FAILED.toString("Module-name is fault: " + + exception.getMessage())); throw new BundleException("Parse module name failed, module-name is invalid."); } } @@ -2796,7 +2846,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 +2861,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 +2907,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 +2925,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 +2962,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 +3043,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 +3067,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); } @@ -3047,7 +3105,7 @@ public class Compressor { private void compressAPPQFMode(Utility utility) throws BundleException { List fileList = utility.getFormatedHQFList(); if (!checkHQFIsValid(fileList)) { - LOG.error("checkHQFIsValid failed when pack appqf file."); + LOG.error(PackingToolErrMsg.COMPRESS_APPQF_FAILED.toString("checkHQFIsValid failed when pack appqf file.")); throw new BundleException("checkHQFIsValid failed when pack appqf file."); } for (String hapPath : fileList) { @@ -3067,7 +3125,7 @@ public class Compressor { hqfVerifyInfos.add(ModuleJsonUtil.parseHQFInfo(file)); } if (!HQFVerify.checkHQFIsValid(hqfVerifyInfos)) { - LOG.error("input hqf is invalid."); + LOG.error(PackingToolErrMsg.CHECK_HQF_INVALID.toString("input hqf is invalid.")); return false; } return true; @@ -3158,11 +3216,15 @@ public class Compressor { private static boolean checkSharedAppIsValid(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos.isEmpty()) { - LOG.error("no module included"); + String cause = "No module included."; + String solution = "Ensure the Shared App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); 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) { @@ -3191,7 +3253,7 @@ public class Compressor { tempDir.toAbsolutePath() + LINUX_FILE_SEPARATOR + PACKINFO_NAME); if (moduleFile.exists() && configFile.exists()) { - LOG.error("versionNormalize failed, invalid hap structure."); + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_FAILED.toString("invalid hap structure.")); throw new BundleException("versionNormalize failed, invalid hap structure."); } if (moduleFile.exists()) { @@ -3201,7 +3263,7 @@ public class Compressor { String configJsonPath = tempDir.resolve(CONFIG_JSON).toString(); util = parseAndModifyConfigJson(configJsonPath, utility); } else { - LOG.error("versionNormalize failed, invalid hap structure."); + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_FAILED.toString("invalid hap structure.")); throw new BundleException("versionNormalize failed, invalid hap structure."); } if (packInfoFile.exists()) { @@ -3216,7 +3278,7 @@ public class Compressor { LINUX_FILE_SEPARATOR + Paths.get(hapPath).getFileName().toString(); compressDirToHap(tempDir, modifiedHapPath); } catch (IOException | BundleException e) { - LOG.error("versionNormalize failed " + e.getMessage()); + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_FAILED.toString("IOException | BundleException: " + e.getMessage())); } finally { if (tempDir != null) { deleteDirectory(tempDir.toFile()); @@ -3232,16 +3294,16 @@ public class Compressor { try (FileInputStream jsonStream = new FileInputStream(jsonFilePath)) { JSONObject jsonObject = JSON.parseObject(jsonStream, JSONObject.class); if (!jsonObject.containsKey(APP)) { - LOG.error("parseAndModifyJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("Parse and modify json failed, json file not valid.")); throw new BundleException("parseAndModifyJson failed, json file not valid."); } JSONObject appObject = jsonObject.getJSONObject(APP); if (!appObject.containsKey(VERSION_CODE)) { - LOG.error("parseAndModifyJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("Parse and modify json failed, json file not valid.")); throw new BundleException("parseAndModifyJson failed, json file not valid."); } if (!appObject.containsKey(VERSION_NAME)) { - LOG.error("parseAndModifyJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("Parse and modify json failed, json file not valid.")); throw new BundleException("parseAndModifyJson failed, json file not valid."); } util.setOriginVersionCode(appObject.getIntValue(VERSION_CODE)); @@ -3249,7 +3311,7 @@ public class Compressor { JSONObject moduleObject = jsonObject.getJSONObject(MODULE); if (!moduleObject.containsKey(NAME)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("Parse and modify failed, json file not valid.")); throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); } util.setModuleName(moduleObject.getString(NAME)); @@ -3257,7 +3319,7 @@ public class Compressor { appObject.put(VERSION_NAME, utility.getVersionName()); writeJson(jsonFilePath, jsonObject); } catch (IOException e) { - LOG.error("parseAndModifyModuleJson failed, IOException." + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Parse and modify failed, IOException:" + e.getMessage())); throw new BundleException("parseAndModifyModuleJson failed, IOException." + e.getMessage()); } return util; @@ -3298,12 +3360,13 @@ public class Compressor { BufferedWriter bw = null; try { String pretty = JSON.toJSONString(jsonObject, SerializerFeature.PrettyFormat, - SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat); + SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat); bw = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(jsonFilePath), StandardCharsets.UTF_8)); bw.write(pretty); } catch (IOException exception) { - LOG.error("Compressor::writeJson failed for IOException " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Write json failed, IOException: " + + exception.getMessage())); throw new BundleException("Compressor::writeJson failed for IOException"); } finally { if (bw != null) { @@ -3319,29 +3382,29 @@ public class Compressor { try (FileInputStream jsonStream = new FileInputStream(jsonFilePath)) { JSONObject jsonObject = JSON.parseObject(jsonStream, JSONObject.class); if (!jsonObject.containsKey(APP)) { - LOG.error("parseAndModifyJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("Parse and modify json failed, json file not valid.")); throw new BundleException("parseAndModifyJson failed, json file not valid."); } JSONObject appObject = jsonObject.getJSONObject(APP); if (!appObject.containsKey(VERSION)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("Parse and modify json failed, json file not valid.")); throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); } JSONObject versionObj = appObject.getJSONObject(VERSION); if (!versionObj.containsKey(CODE)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("Parse and modify json failed, json file not valid.")); throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); } util.setOriginVersionCode(versionObj.getIntValue(CODE)); if (!versionObj.containsKey(NAME)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("Parse and modify json failed, json file not valid.")); throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); } util.setOriginVersionName(versionObj.getString(NAME)); JSONObject moduleObject = jsonObject.getJSONObject(MODULE); if (!moduleObject.containsKey(NAME)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("Parse and modify json failed, json file not valid.")); throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); } util.setModuleName(moduleObject.getString(NAME)); @@ -3350,7 +3413,7 @@ public class Compressor { versionObj.put(NAME, utility.getVersionName()); writeJson(jsonFilePath, jsonObject); } catch (IOException e) { - LOG.error("parseAndModifyModuleJson IOException." + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Parse and modify json, IOException: " + e.getMessage())); throw new BundleException("parseAndModifyModuleJson IOException." + e.getMessage()); } return util; @@ -3442,7 +3505,7 @@ public class Compressor { try (FileWriter fileWriter = new FileWriter(outPath + LINUX_FILE_SEPARATOR + VERSION_RECORD)) { fileWriter.write(jsonString); } catch (IOException e) { - LOG.error("writeVersionRecord failed " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Write version record failed, IOException: " + e.getMessage())); } } @@ -3451,7 +3514,7 @@ public class Compressor { if (versionNormalizeUtil.getOriginVersionCode() > utility.getVersionCode()) { String errorMsg = "versionNormalize failed, module " + versionNormalizeUtil.getModuleName() + " version code less than input version code"; - LOG.error(errorMsg); + LOG.error(PackingToolErrMsg.VERIFY_MODULE_VERSION_FAILED.toString(errorMsg)); throw new BundleException(errorMsg); } else if (versionNormalizeUtil.getOriginVersionCode() == utility.getVersionCode()) { LOG.warning("versionNormalize warning: module " + @@ -3491,7 +3554,7 @@ public class Compressor { zipInputStream.closeEntry(); } } catch (IOException e) { - LOG.error("unpack hap failed IOException " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Unpack hap failed, IOException: " + e.getMessage())); throw new BundleException("unpack hap failed IOException " + e.getMessage()); } } diff --git a/adapter/ohos/ErrorMsg.java b/adapter/ohos/ErrorMsg.java new file mode 100644 index 00000000..b338c501 --- /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..0eb070e3 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 = "Verify hap is empty."; + LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.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,39 @@ class HapVerify { */ public static boolean checkSharedApppIsValid(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos == null || hapVerifyInfos.isEmpty()) { - LOG.error("HapVerify::checkSharedApppIsValid hapVerifyInfos is empty."); + String cause = "No module included."; + String solution = "Ensure the shared App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); 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 a 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 +249,9 @@ class HapVerify { */ private static boolean checkAppFieldsIsSame(List hapVerifyInfos) { if (hapVerifyInfos.isEmpty()) { - LOG.error("HapVerify::checkAppVariableIsSame failed, hapVerifyInfos is empty."); + String cause = "No module included."; + String solution = "Ensure the Shared App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); return false; } HapVerifyInfo verifyInfo = hapVerifyInfos.get(0); @@ -297,13 +325,19 @@ class HapVerify { 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 all module.json files have the same 'minCompatibleVersionCode' and 'targetApiVersion' setting."; + 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 minCompatibleVersionCode or targetApiVersion value in the module.json file of some hap files " + + "is less than the other hap's minCompatibleVersionCode or targetApiVersion."; + String solution = "Ensure that all hap minCompatibleVersionCode and targetApiVersion values" + + "are greater than or equal to other hap's minCompatibleVersionCode or targetApiVersion."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); return false; } return true; @@ -312,20 +346,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 +374,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 = "Input debug is 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 = "Input multiAppMode is 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 +432,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 = "Verify 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 +479,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 +572,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 modules are needed to pack with overlay 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 modules are missing: " + missingModules)); return false; } @@ -535,13 +590,17 @@ class HapVerify { private static boolean checkCompileSdkIsValid(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos.isEmpty()) { - LOG.error("hapVerifyInfos 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 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 +609,19 @@ class HapVerify { private static boolean checkProxyDataUriIsUnique(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos.isEmpty()) { - LOG.error("hapVerifyInfos 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; } 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 +658,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 +709,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 +725,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 +775,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 = "There is no 'value' setting in the distributionFilter setting."; + 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 +799,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 +920,9 @@ 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( + "Check feature apiVersion is subset of entry apiVersion failed, Entry module(" + + hapVerifyInfo.getModuleName() + ") policy is null.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().apiVersion.policy)) { @@ -861,8 +939,11 @@ 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( + "Check feature apiVersion is subset of entry apiVersion failed, 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 +975,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 screenShape is subset of entry screenShape failed, Entry module(" + + hapVerifyInfo.getModuleName() + ") policy is null.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().screenShape.policy)) { @@ -909,8 +992,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 screenShape is subset of entry 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 +1027,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 screenWindow is subset of entry screenWindow failed, Entry module(" + + hapVerifyInfo.getModuleName() + ") policy is null.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().screenWindow.policy)) { @@ -956,8 +1044,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 screenWindow is subset of entry 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 +1079,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 screenDensity is subset of entry screenDensity failed, Entry module(" + + hapVerifyInfo.getModuleName() + ") policy is null.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().screenDensity.policy)) { @@ -1003,8 +1096,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 screenDensity is subset of entry 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 +1131,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 countryCode is subset of entry countryCode failed, Entry module(" + + hapVerifyInfo.getModuleName() + ") policy is null.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().countryCode.policy)) { @@ -1050,8 +1148,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 countryCode is subset of entry 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 +1191,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 +1252,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 +1278,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 +1305,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 +1373,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 +1415,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 +1435,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 +1463,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 +1484,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 +1502,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 +1531,9 @@ class HapVerify { private static boolean checkAtomicServicePreloadsIsValid(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - LOG.error("checkAtomicServicePreloadsIsValid 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)); throw new BundleException("checkAtomicServicePreloadsIsValid failed, hapVerifyInfoList is empty."); } List moduleNames = new ArrayList<>(); @@ -1430,18 +1547,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 +1575,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 +1594,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.CHECK_FILE_SIZE_INVALID.toString("hapVerifyInfoList is empty.")); } if (!checkFileSize(hapVerifyInfoList)) { - LOG.error("checkFileSize failed."); return false; } return true; @@ -1488,7 +1604,7 @@ class HapVerify { private static boolean checkFileSize(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - LOG.error("checkFileSizeWhenSplit failed, hapVerifyInfoList is empty."); + LOG.error(PackingToolErrMsg.CHECK_FILE_SIZE_INVALID.toString("hapVerifyInfoList is empty.")); throw new BundleException("checkFileSizeWhenSplit failed, hapVerifyInfoList is empty."); } // check single file length @@ -1497,16 +1613,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 +1633,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..8d09cc74 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 = "json file do not contain version."; + 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 = "json file do not have version."; + LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString(errMsg)); + throw new BundleException("Parse FaVersion failed: json file do not have version object."); } 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 = "json file do not have version name or version 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: json file do not version name or version 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 = "json file does not contain apiVersion."; + LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString(errMsg)); + throw new BundleException("Parse FAAPIVersion json 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 = "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 = "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 = "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 = "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("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 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 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("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..b590439c --- /dev/null +++ b/adapter/ohos/PackingToolErrMsg.java @@ -0,0 +1,1198 @@ +/* + * 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(); + + /** + * MULTI_APP_MODE_ARGS_INVALID + */ + public static final ErrorMsg MULTI_APP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("004") + .setDescription("Parse and check args invalid in Multi app mode.") + .setCause("%s") + .build(); + + /** + * RES_MODE_ARGS_INVALID + */ + public static final ErrorMsg RES_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("005") + .setDescription("Parse and check args invalid in Res mode.") + .setCause("%s") + .build(); + + /** + * HQF_MODE_ARGS_INVALID + */ + public static final ErrorMsg HQF_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("006") + .setDescription("Parse and check args invalid in Hqf mode.") + .setCause("%s") + .build(); + /** + * APPQF_MODE_ARGS_INVALID + */ + public static final ErrorMsg APPQF_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("007") + .setDescription("Parse and check args invalid in APP QF mode.") + .setCause("%s") + .build(); + + /** + * HAP_ADDITION_MODE_ARGS_INVALID + */ + public static final ErrorMsg HAP_ADDITION_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("020") + .setDescription("Parse and check args invalid in Hap Addition mode.") + .setCause("%s") + .build(); + + /** + * PACKAGE_NORMALIZE_MODE_ARGS_INVALID + */ + public static final ErrorMsg PACKAGE_NORMALIZE_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("008") + .setDescription("Parse and check args invalid in Package Normalize mode.") + .setCause("%s") + .build(); + + /** + * VERSION_NORMALIZE_MODE_ARGS_INVALID + */ + public static final ErrorMsg VERSION_NORMALIZE_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("009") + .setDescription("Parse and check args invalid in Version Normalize mode.") + .setCause("%s") + .build(); + + /** + * HAR_MODE_ARGS_INVALID + */ + public static final ErrorMsg HAR_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("010") + .setDescription("Parse and check args invalid in Har mode.") + .setCause("%s") + .build(); + + /** + * COMMAND_MODE_INVALID + */ + 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(); + + /** + * DIRECTORY_INVALID + */ + public static final ErrorMsg DIRECTORY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("019") + .setDescription("directory is not exist.") + .setCause("%s") + .build(); + + /** + * INPUT_PATH_INVALID + */ + public static final ErrorMsg INPUT_PATH_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("021") + .setDescription("input_path is failed.") + .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_SUM_FAILED + */ + public static final ErrorMsg CHECK_SUM_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("024") + .setDescription("Check sum failed.") + .setCause("%s") + .build(); + + /** + * COMPRESS_APP_MODE_FORMULTI_PROJECT_FAILED + */ + public static final ErrorMsg COMPRESS_APP_MODE_FORMULTI_PROJECT_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("025") + .setDescription("Compress app mode for multi project failed.") + .setCause("%s") + .build(); + + /** + * HAP_ADDITION_FAILED + */ + public static final ErrorMsg HAP_ADDITION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("026") + .setDescription("Hap addition failed.") + .setCause("%s") + .build(); + + /** + * COMPRESS_HAP_ADDITION_FAILED + */ + public static final ErrorMsg COMPRESS_HAP_ADDITION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("027") + .setDescription("Compress hap addition failed.") + .setCause("%s") + .build(); + + /** + * DISPOSE_APP_FAILED + */ + public static final ErrorMsg DISPOSE_APP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("028") + .setDescription("Dispose app failed.") + .setCause("%s") + .build(); + + /** + * NO_PACK_INFO + */ + public static final ErrorMsg NO_PACK_INFO = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("029") + .setDescription("No packinfo available.") + .setCause("%s") + .build(); + + /** + * COMPRESS_PACK_RES_MODE + */ + public static final ErrorMsg COMPRESS_PACK_RES_MODE = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("030") + .setDescription("Compress pack res mode failed.") + .setCause("%s") + .build(); + /** + * INVALID_THIRD_LEVEL_DIRECTORY_NAME + */ + public static final ErrorMsg INVALID_THIRD_LEVEL_DIRECTORY_NAME = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("031") + .setDescription("Invalid third level directory name.") + .setCause("%s") + .addSolution("Please check it with reference to this example: \n" + + "zh_Hani_CN-vertical-car-mdpi-dark or zh_Hani_CN-vertical-car-mdpi.") + .build(); + /** + * IS_PICTURING_FAILED + */ + public static final ErrorMsg IS_PICTURING_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("032") + .setDescription("Is picturing failed.") + .setCause("%s") + .build(); + /** + * GET_FILE_LIST_FAILED + */ + public static final ErrorMsg GET_FILE_LIST_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("033") + .setDescription("Get file list failed.") + .setCause("%s") + .build(); + /** + * GET_MODULE_NAME_FROM_STRING_FAILED + */ + public static final ErrorMsg GET_MODULE_NAME_FROM_STRING_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("034") + .setDescription("Get module name from string failed.") + .setCause("%s") + .build(); + + /** + * COMPRESS_APPQF_FAILED + */ + public static final ErrorMsg COMPRESS_APPQF_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("035") + .setDescription("Compress appqf Mode failed.") + .setCause("%s") + .build(); + /** + * CHECK_HQF_INVALID + */ + public static final ErrorMsg CHECK_HQF_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("036") + .setDescription("HQF is valid.") + .setCause("%s") + .build(); + + /** + * VERSION_NORMALIZE_FAILED + */ + public static final ErrorMsg VERSION_NORMALIZE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("037") + .setDescription("Version normalize failed.") + .setCause("%s") + .build(); + /** + * VERIFY_MODULE_VERSION_FAILED + */ + public static final ErrorMsg VERIFY_MODULE_VERSION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("038") + .setDescription("Verify module version failed.") + .setCause("%s") + .build(); + + /** + * COMPRESS_FAILED + */ + public static final ErrorMsg COMPRESS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("039") + .setDescription("Compress failed.") + .setCause("%s") + .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(); + + /** + * DIR_CREATION_FAILED + */ + public static final ErrorMsg DIR_CREATION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("010") + .setDescription("Directory creation failed exception.") + .setCause("%s") + .addSolution("Please check the following:\n" + + "1. Please check the directory path and ensure that the parent directories exist and are accessible.\n" + + "2. Ensure that you have the necessary permissions to create directories.") + .build(); + + /** + * COMPRESS_FILE_DUPLICATE + */ + public static final ErrorMsg COMPRESS_FILE_DUPLICATE = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("011") + .setDescription("File duplicated.") + .setCause("%s") + .build(); + + /** + * COPY_FILE_SAFELY_FAILED + */ + public static final ErrorMsg COPY_FILE_SAFELY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("012") + .setDescription("Copy file safely failed.") + .setCause("%s") + .build(); + + /** + * UNSUPPORTED_FILE_TYPE + */ + public static final ErrorMsg UNSUPPORTED_FILE_TYPE = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("013") + .setDescription("Unsupported file types.") + .setCause("%s") + .addSolution("Please check the file type.") + .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(); +} 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