diff --git a/adapter/ohos/CommandParser.java b/adapter/ohos/CommandParser.java index 8b0463043a15380472c0f61e303b9815ca85bd29..e04c0c3b3416c7bd519c48bfcfe9412ebb40bade 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 dc3151de19d01393258c8d1090e7286539c41a0a..7b09300878fb9c8499cadfd6f570bc7f9dfbd22d 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 162a283b0d8a9a90669dba32ebcb1418b2a1d86c..bfbe20f737c8de619693cfcb10db47881ce628d9 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("commandVerify 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; } } @@ -235,11 +235,13 @@ public class CompressVerify { if (!utility.getRpcidPath().isEmpty()) { File file = new File(utility.getRpcidPath()); if (!file.isFile()) { - LOG.error("CompressVerify::isArgsValidInHapMode rpcid-path is not a file."); + String errMsg = "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 +252,13 @@ public class CompressVerify { if (!utility.getPackInfoPath().isEmpty()) { File file = new File(utility.getPackInfoPath()); if (!file.isFile()) { - LOG.error("CompressVerify::isArgsValidInHapMode --pack-info-path is not a file."); + String errMsg = "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 +267,14 @@ public class CompressVerify { private static boolean isVerifyValidInHapCommonMode(Utility utility) { if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::commandPathVerify json-path is empty."); + String errMsg = "commandPathVerify 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 +284,45 @@ public class CompressVerify { if (!utility.getApkPath().isEmpty() && !compatibleProcess(utility, utility.getApkPath(), utility.getFormattedApkPathList(), APK_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode shell-apk-path is invalid."); + String errMsg = "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 + PKG_CONTEXT_INFO )); return false; } } @@ -326,76 +338,90 @@ public class CompressVerify { private static boolean isVerifyValidInHapMode(Utility utility) { File file = new File(utility.getIndexPath()); if (!utility.getIndexPath().isEmpty() && !file.isFile() && INDEX_PROFILE.equals(file.getName())) { - LOG.error("CompressVerify::isArgsValidInHapMode index-path must be resources.index file."); + String errMsg = "isArgsValidInHapMode index-path must be resources.index file."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getSoPath().isEmpty() && !compatibleProcess(utility, utility.getSoPath(), utility.getFormattedSoPathList(), SO_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode maple-so-path is invalid."); + String errMsg = "isArgsValidInHapMode maple-so-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getAbilitySoPath().isEmpty() && !compatibleProcess(utility, utility.getAbilitySoPath(), utility.getFormattedAbilitySoPathList(), SO_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode ability-so-path is invalid."); + String errMsg = "isArgsValidInHapMode ability-so-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getSoDir())) { - LOG.error("CompressVerify::isArgsValidInHapMode maple-so-dir is invalid."); + String errMsg = "isArgsValidInHapMode maple-so-dir is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getLibPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode lib-path is invalid."); + String errMsg = "isArgsValidInHapMode lib-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getHnpPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode hnp-path is invalid."); + String errMsg = "isArgsValidInHapMode hnp-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getResPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode res-path is invalid."); + String errMsg = "isArgsValidInHapMode res-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getResourcesPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode resources-path is invalid."); + String errMsg = "isArgsValidInHapMode resources-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getAssetsPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode assets-path is invalid."); + String errMsg = "isArgsValidInHapMode assets-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getSharedLibsPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode shared-libs-path is invalid."); + String errMsg = "isArgsValidInHapMode shared-libs-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getJarPath().isEmpty() && !compatibleProcess(utility, utility.getJarPath(), utility.getFormattedJarPathList(), JAR_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode jar-path is invalid."); + String errMsg = "isArgsValidInHapMode jar-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getTxtPath().isEmpty() && !compatibleProcess(utility, utility.getTxtPath(), utility.getFormattedTxtPathList(), TXT_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode txt-path is invalid."); + String errMsg = "isArgsValidInHapMode txt-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getANPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode an-path is invalid."); + String errMsg = "isArgsValidInHapMode an-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getEtsPath().isEmpty() && !isPathExists(utility.getEtsPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode ets-path is invalid."); + String errMsg = "isArgsValidInHapMode ets-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -473,7 +499,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 +510,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 +579,21 @@ 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; } } @@ -806,13 +842,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 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 +857,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 +866,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 +875,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 +884,7 @@ public class CompressVerify { if (HSP_SUFFIX.equals(suffix)) { if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(HSP_SUFFIX)) { - LOG.error("CompressVerify::isOutPathValid out-path must end with .hsp."); + LOG.error(PackingToolErrMsg.OUT_PATH_INVALID.toString("out-path must end with .hsp.")); return false; } else { return true; @@ -914,12 +950,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 +965,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 = "isArgsValidInHspMode jar-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getTxtPath().isEmpty() && !compatibleProcess(utility, utility.getTxtPath(), utility.getFormattedTxtPathList(), TXT_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHspMode txt-path is invalid."); + String errMsg = "txt-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getLibPath().isEmpty() && !isPathValid(utility.getLibPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHspMode lib-path is invalid."); + String errMsg = "lib-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getResPath().isEmpty() && !isPathValid(utility.getResPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHspMode res-path is invalid."); + String errMsg = "res-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getResourcesPath().isEmpty() && !isPathValid(utility.getResourcesPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHspMode resources-path is invalid."); + String errMsg = "resources-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getAssetsPath().isEmpty() && !isPathValid(utility.getAssetsPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHspMode assets-path is invalid."); + String errMsg = "assets-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getDirList().isEmpty() && !splitDirList(utility, utility.getDirList(), utility.getFormatedDirList())) { - LOG.error("CompressVerify::isArgsValidInHapMode --dir-list is invalid."); + String errMsg = "dir-list is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getAPPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode ap-path is invalid."); + String errMsg = "ap-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getANPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode an-path is invalid."); + String errMsg = "an-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getPkgContextPath().isEmpty()) { File file = new File(utility.getPkgContextPath()); if (!file.isFile() || !PKG_CONTEXT_INFO.equals(file.getName())) { - LOG.error("CompressVerify::isArgsValidInHspMode --pkg-context-path file must be " + PKG_CONTEXT_INFO); + String errMsg = "pkg-context-path file must be "+ PKG_CONTEXT_INFO; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!utility.getEtsPath().isEmpty() && !isPathExists(utility.getEtsPath())) { - LOG.error("CompressVerify::isArgsValidInHspMode ets-path is invalid."); + String errMsg = "ets-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -1154,11 +1204,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 jsonPath 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(e.getMessage())); return false; } } @@ -1169,11 +1220,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 jsonPath 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(e.getMessage())); return false; } } @@ -1184,11 +1236,12 @@ public class CompressVerify { if(optional.isPresent()) { return ModuleJsonUtil.parseModuleType(optional.get()).equals(BUNDLE_TYPE_SHARE) && !ModuleJsonUtil.parseAbilityNames(optional.get()).isEmpty(); } else { - LOG.error("CompressVerify::hspHasAbilities jsonPath content invalid"); + String errMsg = "Parse jsonPath 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(e.getMessage())); return false; } } @@ -1200,10 +1253,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 jsonPath 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(e.getMessage())); } return false; } @@ -1213,7 +1267,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 jsonPath file content failed."; + LOG.error(PackingToolErrMsg.HAS_HOME_ABILITY_INVALID.toString(errMsg)); return false; } Map abilitiesMap = ModuleJsonUtil.parseAbilitySkillsMap(optional.get()); @@ -1223,7 +1278,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(e.getMessage())); return false; } } @@ -1249,7 +1304,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 jsonPath file content failed."; + LOG.error(PackingToolErrMsg.HAS_HOME_EXTENSION_ABILITY_INVALID.toString(errMsg)); return false; } Map extensionAbilitiesMap = ModuleJsonUtil.parseExtensionAbilitySkillsMap(optional.get()); @@ -1259,7 +1315,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(e.getMessage())); return false; } } diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index 3346181239db2cea508c5d383ca75fc0eb4f9a5b..9087ae47942713f3a4fd20c1bb4b1c28baeca94a 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -348,7 +348,9 @@ public class Compressor { File outParentFile = destFile.getParentFile(); if ((outParentFile != null) && (!outParentFile.exists())) { if (!outParentFile.mkdirs()) { - LOG.error("Compressor::compressProcess create out file parent directory failed."); + String errMsg = "create out file parent directory failed."; + String solution = "Check input out-path"; + LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_FAILED.toString(errMsg, solution)); return false; } } @@ -363,10 +365,10 @@ public class Compressor { compressExcute(utility); } catch (FileNotFoundException exception) { compressResult = false; - LOG.error("Compressor::compressProcess file not found exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString(exception.getMessage())); } catch (BundleException ex) { compressResult = false; - LOG.error("Compressor::compressProcess Bundle exception: " + ex.getMessage()); + LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_EXCEPTION.toString(ex.getMessage())); } finally { closeZipOutputStream(); Utility.closeStream(zipOut); @@ -376,14 +378,20 @@ public class Compressor { if (compressResult && !checkAppAtomicServiceCompressedSizeValid(utility)) { compressResult = false; - LOG.error("Compressor::compressProcess check atomic service size fail."); + String errMsg = "Execute compress failed."; + String solution = "Please check the related error message and modify."; + LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_FAILED.toString(errMsg, solution)); } // if compress failed, delete out file. if (!compressResult) { - LOG.error("Compressor::compressProcess compress failed."); + String errMsg = "Execute compress failed."; + String solution = "Please check the related error message and modify."; + LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_FAILED.toString(errMsg, solution)); if (!destFile.delete()) { - LOG.error("Compressor::compressProcess delete dest file failed."); + errMsg = "Delete out file failed."; + solution = "Try to close the out file using programme."; + LOG.error(PackingToolErrMsg.FILE_DELETE_FAILED.toString(errMsg, solution)); } } return compressResult; @@ -426,35 +434,35 @@ public class Compressor { Optional optional = FileUtils.getFileContent(utility.getJsonPath()); String jsonString = optional.get(); if (!checkStageAsanTsanEnabledValid(jsonString)) { - LOG.error("checkStageAsanTsanEnabledValid failed."); - throw new BundleException("compressHsp failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("check StageAsanTsanEnabledValid 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 StageHwasanEnabledValid 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 StageUbsanEnabledValid 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 StageAtomicService 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 ContinueBundleNameIsValid 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("checkStageOverlayCfg failed.")); + throw new BundleException("checkStageOverlayCfg failed"); } String moduleType = ModuleJsonUtil.parseModuleType(jsonString); if (!TYPE_SHARED.equals(moduleType)) { - LOG.error("module type must be shared."); - throw new BundleException("compressHsp failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("module type must be shared.")); + throw new BundleException("compressHsp failed"); } } compressHSPMode(utility); @@ -470,8 +478,8 @@ public class Compressor { setGenerateBuildHash(utility); if (isModuleJSON(utility.getJsonPath())) { if (!checkStageHap(utility)) { - LOG.error("checkStageHap failed."); - throw new BundleException("checkStageHap failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HAP_FAILED.toString("verify Stage Hap info failed.")); + throw new BundleException("verify Stage Hap info failed."); } Optional optional = FileUtils.getFileContent(utility.getJsonPath()); String jsonString = optional.get(); @@ -494,7 +502,8 @@ 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"); + String errMsg = "parse json file not exist."; + LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString(errMsg)); throw new BundleException("Compressor::hasGenerateBuildHash failed for json file not exist"); } InputStream json = null; @@ -503,8 +512,8 @@ public class Compressor { json = new FileInputStream(file); JSONObject jsonObject = JSON.parseObject(json, JSONObject.class); if (jsonObject == null || !jsonObject.containsKey(APP) || !jsonObject.containsKey(MODULE)) { - LOG.error("json file is invalid."); - throw new BundleException("json file is invalid."); + LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString("json file is invalid.")); + throw new BundleException("parse json file is invalid."); } JSONObject appJson = jsonObject.getJSONObject(APP); JSONObject moduleJson = jsonObject.getJSONObject(MODULE); @@ -512,10 +521,10 @@ public class Compressor { res = true; } } catch (BundleException exception) { - LOG.error("Compressor::hasGenerateBuildHash failed."); + LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString(exception.getMessage())); throw new BundleException("Compressor::hasGenerateBuildHash failed."); } catch (JSONException | IOException e) { - LOG.error("Compressor::hasGenerateBuildHash failed for json file is invalid." + e.getMessage()); + LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString(e.getMessage())); throw new BundleException("Compressor::hasGenerateBuildHash failed."); } finally { FileUtils.closeStream(json); @@ -531,7 +540,8 @@ public class Compressor { copyFileToTempDir(utility); File file = new File(utility.getJsonPath()); if (!file.exists()) { - LOG.error("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("Compressor::setGenerateBuildHash failed for json file not exist"); } InputStream json = null; @@ -540,7 +550,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,10 +571,10 @@ 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(exception.getMessage())); throw new BundleException("Compressor::setGenerateBuildHash failed."); } catch (NullPointerException | IOException | JSONException e) { - LOG.error("Compressor::setGenerateBuildHash failed, json data err: " + e.getMessage()); + LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString("json data err: " + e.getMessage())); throw new BundleException("Compressor::setGenerateBuildHash failed, json data err."); } finally { FileUtils.closeStream(json); @@ -573,7 +583,7 @@ public class Compressor { bw.flush(); bw.close(); } catch (IOException e) { - LOG.error("Compressor::setGenerateBuildHash failed for IOException " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("failed set generate build hash, IOException: " + e.getMessage())); throw new BundleException("Compressor::setGenerateBuildHash failed."); } } @@ -584,7 +594,8 @@ 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."); + String errMsg = "parse json file not found, parse json path is " + jsonPath + "."; + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString(errMsg)); throw new BundleException("Compressor::copyFileToTempDir failed for json file not found."); } String oldFileParent = oldfile.getParent(); @@ -607,7 +618,7 @@ public class Compressor { } utility.setJsonPath(tempPath); } catch (IOException e) { - LOG.error("Compressor::copyFileToTempDir failed, IOException: " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("copy file to temp Dir failed, IOException:" + e.getMessage())); throw new BundleException("Compressor::copyFileToTempDir failed."); } } @@ -628,7 +639,7 @@ public class Compressor { try { putBuildHash(utility, hash); } catch (IOException e) { - LOG.error("Compressor::putBuildHash failed, " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("putBuildHash failed: " + e.getMessage())); throw new BundleException("Compressor::putBuildHash failed."); } } @@ -673,7 +684,8 @@ 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"); + String errMsg = "parse json file not found, parse json path is " + jsonPath + "."; + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString(errMsg)); throw new BundleException("Compressor::putBuildHash failed for json file not exist"); } InputStream json = null; @@ -688,10 +700,10 @@ 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()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("putBuildHash failed, IOException: " + e.getMessage())); throw new BundleException("Compressor::putBuildHash failed."); } catch (NullPointerException e) { - LOG.error("Compressor::putBuildHash failed, json data err: " + e.getMessage()); + LOG.error(PackingToolErrMsg.NULL_POINTER_EXPECTION.toString("json data err: " + e.getMessage())); throw new BundleException("Compressor::putBuildHash failed, json data err."); } finally { FileUtils.closeStream(json); @@ -722,7 +734,7 @@ public class Compressor { } if (hapVerifyInfos.isEmpty()) { - LOG.error("Compressor::checkAppAtomicServiceCompressedSizeValid no hapVerifyInfo."); + LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString("no avaiable hapVerifyInfo.")); return false; } @@ -737,10 +749,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(exception.getMessage())); return false; } catch (BundleException ignored) { - LOG.error("Compressor::checkAppAtomicServiceCompressedSizeValid Bundle exception."); + LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString(ignored.getMessage())); return false; } } @@ -749,25 +761,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 StageAsanTsanEnabled valid failed.")); return false; } if (!checkStageHwasanEnabledValid(jsonString)) { - LOG.error("checkStageHwasanEnabledValid failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("check StageHwasanEnabled valid failed.")); return false; } if (!checkStageUbsanEnabledValid(jsonString)) { - LOG.error("checkStageUbsanEnabledValid failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("check StageUbsanEnabled 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 +789,7 @@ public class Compressor { boolean asanEnabled = ModuleJsonUtil.getStageAsanEnabled(jsonString); boolean tsanEnabled = ModuleJsonUtil.getStageTsanEnabled(jsonString); if (asanEnabled && tsanEnabled) { - LOG.error("asanEnabled and tsanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_AS_TSAN_ENABLED.toString("asanEnabled and tsanEnabled cannot be true at the same time.")); return false; } return true; @@ -789,15 +801,15 @@ public class Compressor { boolean gwpAsanEnabled = ModuleJsonUtil.getStageGwpAsanEnabled(jsonString); boolean hwasanEnabled = ModuleJsonUtil.getStageHwasanEnabled(jsonString); if (hwasanEnabled && asanEnabled) { - LOG.error("hwasanEnabled and asanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_HWASAN_ENABLED_INVALID.toString("hwasanEnabled and asanEnabled cannot be true at the same time")); return false; } if (hwasanEnabled && tsanEnabled) { - LOG.error("hwasanEnabled and tsanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_HWASAN_ENABLED_INVALID.toString("hwasanEnabled and tsanEnabled cannot be true at the same time")); return false; } if (hwasanEnabled && gwpAsanEnabled) { - LOG.error("hwasanEnabled and GWPAsanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_HWASAN_ENABLED_INVALID.toString("hwasanEnabled and GWPAsanEnabled cannot be true at the same time")); return false; } return true; @@ -813,7 +825,7 @@ public class Compressor { } for (int i = 0; i < continueBundleNameList.size(); i++) { if (bundleName.equals(continueBundleNameList.get(i))) { - LOG.error("continueBundleName cannot include self."); + LOG.error(PackingToolErrMsg.CHECK_CONTINUE_BUNDLENAME_INVALID.toString("continueBundleName include self.")); return false; } } @@ -827,15 +839,15 @@ public class Compressor { boolean hwasanEnabled = ModuleJsonUtil.getStageHwasanEnabled(jsonString); boolean ubsanEnabled = ModuleJsonUtil.getStageUbsanEnabled(jsonString); if(ubsanEnabled && asanEnabled) { - LOG.error("ubsanEnabled and asanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_UBASAN_ENABLED_INVALID.toString("ubsanEnabled and asanEnabled cannot be true at the same time.")); return false; } if(ubsanEnabled && tsanEnabled) { - LOG.error("ubsanEnabled and tsanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_UBASAN_ENABLED_INVALID.toString("ubsanEnabled and tsanEnabled cannot be true at the same time.")); return false; } if(ubsanEnabled && hwasanEnabled) { - LOG.error("ubsanEnabled and hwasanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_UBASAN_ENABLED_INVALID.toString("ubsanEnabled and hwasanEnabled cannot be true at the same time.")); return false; } return true; @@ -844,17 +856,17 @@ public class Compressor { private static boolean checkStageAtomicService(String jsonString) throws BundleException { // check consistency of atomicService if (!ModuleJsonUtil.isModuleAtomicServiceValid(jsonString)) { - LOG.error("check module atomicService failed."); + LOG.error(PackingToolErrMsg.CHECK_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 atomic service installationFree failed.")); return false; } @@ -867,17 +879,17 @@ public class Compressor { if (!targetModuleName.isEmpty()) { // check targetModuleName and requestPermission if (ModuleJsonUtil.isExistedStageRequestPermissions(jsonString)) { - LOG.error("targetModuleName cannot be existed with requestPermissions."); + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString("targetModuleName cannot be existed with requestPermissions.")); return false; } // check targetModuleName and name if (targetModuleName.equals(ModuleJsonUtil.parseStageModuleName(jsonString))) { - LOG.error("targetModuleName cannot be same with name in the overlay module."); + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString("targetModuleName cannot be same with name in the overlay module.")); return false; } } else { if (ModuleJsonUtil.isExistedStageModuleTargetPriority(jsonString)) { - LOG.error("targetPriority cannot be existed without the targetModuleName in module.json."); + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString("targetPriority cannot be existed without the targetModuleName in module.json.")); return false; } } @@ -885,16 +897,16 @@ public class Compressor { String targetBundleName = ModuleJsonUtil.getStageTargetBundleName(jsonString); if (!targetBundleName.isEmpty()) { if (targetModuleName.isEmpty()) { - LOG.error("targetModuleName is necessary in the overlay bundle."); + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString("targetModuleName is necessary in the overlay bundle.")); return false; } if (targetBundleName.equals(ModuleJsonUtil.parseBundleName(jsonString))) { - LOG.error("targetBundleName cannot be same with the bundleName."); + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString("targetBundleName cannot be same with the bundleName.")); return false; } } else { if (ModuleJsonUtil.isExistedStageAppTargetPriority(jsonString)) { - LOG.error("targetPriority cannot be existed without the targetBundleName in app.json."); + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString("targetPriority cannot be existed without the targetBundleName in app.json.")); return false; } } @@ -1192,7 +1204,8 @@ 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()); + LOG.error(PackingToolErrMsg.COMPRESS_APP_IO_EXCEPTION.toString("compress pack.info into hap failed, " + + e.getMessage())); throw new BundleException("Compressor::compressAppMode compress pack.info into hap failed."); } } @@ -1209,16 +1222,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()); + LOG.error(PackingToolErrMsg.COMPRESS_APP_IO_EXCEPTION.toString("compress pack.info into hsp failed, " + + e.getMessage())); throw new BundleException("Compressor::compressAppMode 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) { @@ -1246,8 +1257,8 @@ public class Compressor { //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(e.getMessage())); + throw new BundleException("Compress app failed."); } finally { // delete temp file for (String path : fileList) { @@ -1813,7 +1824,7 @@ public class Compressor { } append.closeEntry(); } catch (IOException exception) { - LOG.error("Compressor::compressPackinfoIntoHap io exception."); + LOG.error(PackingToolErrMsg.COMPRESS_FILE_EXCEPTION.toString("compress PackInfo into hap io exception" + exception.getMessage())); throw new BundleException("Compressor::compressPackinfoIntoHap io exception."); } finally { sourceHapFile.close(); @@ -2213,9 +2224,8 @@ 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(e.getMessage())); + throw new BundleException("Parallel compress exception." + e.getMessage()); } } @@ -2237,7 +2247,7 @@ 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(e.getMessage())); return null; } }; @@ -2385,10 +2395,10 @@ 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 failed.")); 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 failed." + exception.getMessage())); throw new BundleException("Get Crc from file failed."); } finally { Utility.closeStream(fileInputStream); @@ -2464,10 +2474,10 @@ 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(exception.getMessage())); + throw new BundleException("CompressFile failed."); } finally { Utility.closeStream(bufferedInputStream); Utility.closeStream(fileInputStream); @@ -2498,7 +2508,7 @@ public class Compressor { } } } catch (IOException exception) { - LOG.error("Compressor::isModuleHap io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("check module type io exception: " + exception.getMessage())); throw new BundleException("Compressor::isModuleHap failed."); } finally { Utility.closeStream(zipInput); @@ -2528,10 +2538,10 @@ public class Compressor { count = fileInputStream.read(buffer); } } catch (FileNotFoundException ignored) { - LOG.error("Compressor::getCrcFromFile FileNotFoundException : " + ignored.getMessage()); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("getCrcFromFile 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("getCrcFromFile io exception: " + exception.getMessage())); throw new BundleException("Get Crc from file failed."); } finally { Utility.closeStream(fileInputStream); @@ -2656,7 +2666,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.getMessage())); LOG.warning("Json format err: " + srcFile.getAbsolutePath()); return false; } finally { @@ -2796,7 +2806,7 @@ public class Compressor { } } } catch (IOException exception) { - LOG.error("Compressor::parseCompressNativeLibs io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(exception.getMessage())); throw new BundleException("Parse compress native libs failed."); } } @@ -2810,21 +2820,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("flush exception: " + + 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 io exception: " + + 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("finish exception: " + + exception.getMessage())); } } @@ -2853,7 +2866,7 @@ public class Compressor { break; } } catch (IOException exception) { - LOG.error("Compressor::parseDeviceType io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Parse device type failed." + exception.getMessage())); throw new BundleException("Parse device type failed."); } } @@ -2870,19 +2883,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("Compressor::checkHapIsValid 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."); + LOG.error(PackingToolErrMsg.INVALID_HAP_FILE.toString("get file name failed.")); throw new BundleException("Compressor::checkHapIsValid get file name failed."); } if (!fileStr.toLowerCase(Locale.ENGLISH).endsWith(HAP_SUFFIX) && !fileStr.toLowerCase(Locale.ENGLISH).endsWith(HSP_SUFFIX)) { - LOG.error("Compressor::checkHapIsValid input wrong hap file."); - 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("Compressor::checkHapIsValid input wrong hap or hsp file."); } if (isModuleHap(hapPath)) { hapVerifyInfos.add(parseStageHapVerifyInfo(hapPath)); @@ -2907,8 +2920,9 @@ public class Compressor { for (HapVerifyInfo hapVerifyInfo : hapVerifyInfos) { String bundleType = hapVerifyInfo.getBundleType(); if (TYPE_SHARED.equals(bundleType)) { - LOG.error("Compressor::checkHapIsValid only one item can be entered in the -hsp-path" + - " when bundleType is shared."); + String cause = "Only one item can be entered in the -hsp-path when bundleType is 'shared'."; + String solution = "Ensure that only one item entered in the -hsp-path when bundleType is 'shared'"; + LOG.error(PackingToolErrMsg.CHECK_BUNDLETYPE_INVALID.toString(cause, solution)); return false; } } @@ -2987,7 +3001,8 @@ public class Compressor { hapVerifyInfo.setResourceMap(FileUtils.getProfileJson(zipFile)); hapVerifyInfo.setProfileStr(FileUtils.getFileStringFromZip(MODULE_JSON, zipFile)); } catch (IOException e) { - LOG.error("FileUtil::parseStageHapVerifyInfo file not available."); + LOG.error(PackingToolErrMsg.READ_STAGE_HAP_VERIFY_INFO_FAILED.toString( + "stage hap verify info file not available.")); throw new BundleException("FileUtil::parseStageHapVerifyInfo file not available."); } finally { Utility.closeStream(zipFile); @@ -3010,8 +3025,10 @@ public class Compressor { zipFile = new ZipFile(srcFile); hapVerifyInfo.setProfileStr(FileUtils.getFileStringFromZip(CONFIG_JSON, zipFile)); } catch (IOException e) { + LOG.error(PackingToolErrMsg.READ_FA_HAP_VERIFY_INFO_FAILED.toString( + "FA hap verify info file not available.")); LOG.error("FileUtil::parseStageHapVerifyInfo file not available."); - throw new BundleException("FileUtil::parseStageHapVerifyInfo file not available."); + throw new BundleException("FileUtil::parseFAHapVerifyInfo file not available."); } finally { Utility.closeStream(zipFile); } @@ -3158,11 +3175,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) { diff --git a/adapter/ohos/ErrorMsg.java b/adapter/ohos/ErrorMsg.java new file mode 100644 index 0000000000000000000000000000000000000000..5ea1d74efe3fb3c58b62f8054eb97d7bdf78ea82 --- /dev/null +++ b/adapter/ohos/ErrorMsg.java @@ -0,0 +1,222 @@ +/* + * 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/06 + */ + 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 String position; + + private final List solutions; + + private MoreInfo moreInfo; + + /** + * ErrorMsg constructor + * + * @param code code + * @param description description + * @param cause cause + * @param position position + * @param solutions solutions + */ + public ErrorMsg(String code, String description, String cause, + String position, List solutions) { + this.code = code; + this.description = description; + this.cause = cause; + this.position = position; + this.solutions = solutions; + this.moreInfo = new MoreInfo(); + } + + /** + * 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); + + if (!StringUtils.isEmpty(position)) { + sb.append(System.lineSeparator()).append(" At ").append(position).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(); + } + } + + static class MoreInfo { + private String cn; + + private String en; + } + + /** + * Builder + * + * @since 2025/01/06 + */ + public static class Builder { + private String sysCode; + + private String errCode; + + private String typeCode; + + private String description; + + private String cause; + + private String position; + + private List solutions = new ArrayList<>(); + + /** + * Builder Constructor + * + * @param sysCode sysCode + */ + public Builder(String sysCode) { + this.sysCode = sysCode; + } + + /** + * addErrCode + * + * @param errCode errCode + * @return Builder + */ + public Builder addErrCode(String errCode) { + this.errCode = errCode; + return this; + } + + /** + * addTypeCode + * + * @param typeCode typeCode + * @return Builder + */ + public Builder addTypeCode(String typeCode) { + this.typeCode = typeCode; + return this; + } + + /** + * addDescription + * + * @param description description + * @return Builder + */ + public Builder addDescription(String description) { + this.description = description; + return this; + } + + /** + * addCause + * + * @param cause cause + * @return Builder + */ + public Builder addCause(String cause) { + this.cause = cause; + return this; + } + + /** + * addPosition + * + * @param position position + * @return Builder + */ + public Builder addPosition(String position) { + this.position = position; + 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, position, solutions); + } + } + } + \ No newline at end of file diff --git a/adapter/ohos/FileUtils.java b/adapter/ohos/FileUtils.java index 3064828dcc1d74ff10871a2a6897dee5d7c417e3..e0a8e6162de39d0d78723c5c636b41f3df43f395 100644 --- a/adapter/ohos/FileUtils.java +++ b/adapter/ohos/FileUtils.java @@ -155,7 +155,7 @@ 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(msg.getMessage())); return Optional.empty(); } finally { closeStream(reader); @@ -176,7 +176,7 @@ class FileUtils { fileStream.close(); } } catch (IOException msg) { - LOG.error("stream close Error, msg is " + msg.getMessage()); + LOG.error(PackingToolErrMsg.CLOSE_STREAM_EXPECTION.toString(msg.getMessage())); } } @@ -445,7 +445,7 @@ class FileUtils { } } } catch (IOException e) { - LOG.error("FileUtil::getProfileJson IOException: " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("getProfileJson failed: " + e.getMessage())); throw new BundleException("FileUtil::getProfileJson failed."); } return resourceMap; @@ -598,7 +598,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 8f485718803c6d2486de0ef38c501823a511998b..4d39c9d3ab340c2af32838da6843926b98fabfeb 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 cause = "verify hap is empty."; + LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(cause)); return false; } // check app variable is same if (!checkAppFieldsIsSame(hapVerifyInfos)) { - LOG.error("some app variable is different."); + String cause = "some app variable is different."; + LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(cause)); 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 = "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 = "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 AtomicServiceIsValid 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: (" + + String cause = "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); + 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 overlap."; + + LOG.error(PackingToolErrMsg.CONTINUE_TYPE_INVALID.toString(cause, solution)); return false; } return true; @@ -185,28 +200,38 @@ class HapVerify { */ public static boolean checkSharedApppIsValid(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos == null || hapVerifyInfos.isEmpty()) { - LOG.error("HapVerify::checkSharedApppIsValid hapVerifyInfos is empty."); + String cause = "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 = "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 +248,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 +324,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 +345,27 @@ class HapVerify { private static boolean appFieldsIsSame(VerifyCollection verifyCollection, HapVerifyInfo hapVerifyInfo) { if (hapVerifyInfo.getBundleName().isEmpty() || !verifyCollection.bundleName.equals(hapVerifyInfo.getBundleName())) { - LOG.error("input module bundleName is different."); + String errMsg = "Input module bundleName is different."; + String solution = "Check if the bundleName is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (!verifyCollection.getBundleType().equals(hapVerifyInfo.getBundleType())) { - LOG.error("input module bundleType is different."); + String errMsg = "Input module bundleType is different."; + String solution = "Check if the bundleType is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (verifyCollection.versionCode != hapVerifyInfo.getVersion().versionCode) { - LOG.error("input module versionCode is different."); + String errMsg = "Input module versionCode is different."; + String solution = "Check if the versionCode is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (verifyCollection.compatibleApiVersion != hapVerifyInfo.getApiVersion().getCompatibleApiVersion()) { - LOG.error("input module minApiVersion is different."); - return false; + String errMsg = "Input module minApiVersion is different."; + String solution = "Check if the minApiVersion is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); } if (!verifyCollection.releaseType.equals(hapVerifyInfo.getApiVersion().getReleaseType())) { if (verifyCollection.getModuleType().equals(TYPE_SHARED) || @@ -333,27 +373,35 @@ class HapVerify { LOG.warning("Module: (" + verifyCollection.getModuleName() + ") and Module: (" + hapVerifyInfo.getModuleName() + ") has different releaseType."); } else { - LOG.error("input module releaseType is different."); - LOG.error("Solutions: > Check if the releaseType is the same in different modules."); + String errMsg = "input module releaseType is different."; + String solution = "Check if the releaseType is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } } if (!verifyCollection.targetBundleName.equals(hapVerifyInfo.getTargetBundleName())) { - LOG.error("targetBundleName is different."); + String errMsg = "Input targetBundleName is different."; + String solution = "Check if the targetBundleName is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (verifyCollection.targetPriority != hapVerifyInfo.getTargetPriority()) { - LOG.error("targetPriority is different."); + String errMsg = "Input targetPriority is different."; + String solution = "Check if the targetPriority is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (verifyCollection.debug != hapVerifyInfo.isDebug()) { - LOG.error("debug is different."); - LOG.error("Solutions: > Check if the debug type is the same in different modules."); + String errMsg = "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 +431,30 @@ 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."); + 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("HapVerify::checkModuleNameIsValid 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: (" + + 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."); - 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() + "."); + "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 = "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 +477,22 @@ 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 = "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 +569,13 @@ 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 +585,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 the same compileSdkType."; + LOG.error(PackingToolErrMsg.COMPILE_SDK_TYPE_DIFFERENT.toString(cause, solution)); return false; } } @@ -550,15 +604,18 @@ 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 cause = "uri:" + uri + " in proxyData 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 +652,23 @@ 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 name 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; } } @@ -708,7 +765,9 @@ class HapVerify { private static boolean checkPolicyValueDisjoint(String policyLeft, List valueLeft, String policyRight, List valueRight) throws BundleException { if (valueLeft == null || valueRight == null) { - LOG.error("HapVerify::checkPolicyValueDisjoint value should not empty."); + String errMsg = "There is no 'value' setting in the distributionFilter setting."; + String solution = "Ensure that all distributionFilter has 'value' setting."; + LOG.error(PackingToolErrMsg.CHECK_POLICY_DISJOINT_ERROR.toString(errMsg, solution)); throw new BundleException("HapVerify::checkPolicyValueDisjoint value should not empty."); } if (EXCLUDE.equals(policyLeft) && INCLUDE.equals(policyRight)) { @@ -726,7 +785,9 @@ class HapVerify { } else if (EXCLUDE.equals(policyLeft) && EXCLUDE.equals(policyRight)) { return false; } else { - LOG.error("HapVerify::checkPolicyValueDisjoint input policy is invalid."); + String errMsg = "Check distributionFilter 'policy' setting is invalid."; + String solution = "Ensure all distributionFilter 'policy' value must 'include' or 'exclude'."; + LOG.error(PackingToolErrMsg.CHECK_POLICY_DISJOINT_ERROR.toString(errMsg, solution)); throw new BundleException("HapVerify::checkPolicyValueDisjoint input policy is invalid."); } return false; @@ -844,7 +905,8 @@ class HapVerify { return true; } if (hapVerifyInfo.getDistroFilter().apiVersion.policy == null) { - LOG.error("HapVerify::checkApiVersionCovered input none policy."); + LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( + "Check feature apiVersion is subset of entry apiVersion failed, input none policy.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().apiVersion.policy)) { @@ -861,7 +923,8 @@ 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."); + LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( + "Check feature apiVersion is subset of entry apiVersion failed, input policy is invalid.")); throw new BundleException("HapVerify::checkApiVersionCovered input policy is invalid."); } } @@ -894,7 +957,8 @@ 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, input none policy.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().screenShape.policy)) { @@ -909,7 +973,8 @@ 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."); + LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( + "Check feature screenShape is subset of entry screenShape failed, input policy is invalid.")); throw new BundleException("HapVerify::checkScreenShapeCovered input policy is invalid."); } } @@ -941,7 +1006,8 @@ 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, input none policy.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().screenWindow.policy)) { @@ -956,7 +1022,8 @@ 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."); + LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( + "Check feature screenWindow is subset of entry screenWindow failed, input policy is invalid.")); throw new BundleException("HapVerify::checkScreenWindowCovered input policy is invalid."); } } @@ -988,7 +1055,8 @@ 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, input none policy.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().screenDensity.policy)) { @@ -1003,7 +1071,8 @@ 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."); + LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( + "Check feature screenDensity is subset of entry screenDensity failed, input policy is invalid.")); throw new BundleException("HapVerify::checkScreenDensityCovered input policy is invalid."); } } @@ -1035,7 +1104,8 @@ 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, input none policy.")); return false; } if (INCLUDE.equals(hapVerifyInfo.getDistroFilter().countryCode.policy)) { @@ -1050,7 +1120,8 @@ 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."); + LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( + "Check feature countryCode is subset of entry countryCode failed, input policy is invalid.")); throw new BundleException("HapVerify::checkCountryCodeCovered input policy is invalid."); } } @@ -1090,6 +1161,8 @@ class HapVerify { private static boolean checkPolicyValueCovered( String policy, List value, List include, List exclude) { if (value == null || policy == null) { + LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( + "Check policy value failed, check policy value is null.")); LOG.error("checkPolicyValueCovered::failed value is null."); return false; } @@ -1151,13 +1224,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 +1250,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 +1277,9 @@ 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 dependent module (" + item.getModuleName() + ") type is feature or entry."; + String solution = "Remove dependencies on feature or entry modules to ensure the dependency list is valid."; + LOG.error(PackingToolErrMsg.DEPENDENCY_LIST_INVALID.toString(cause, solution)); return false; } dependencyList.add(item); @@ -1265,8 +1344,10 @@ 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 = "Remove circulate dependency module to ensure the dependency list is valid."; + LOG.error(PackingToolErrMsg.DEPENDENCY_LIST_INVALID.toString(cause, solution)); return true; } } @@ -1304,7 +1385,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 +1405,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 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 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 +1433,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 +1454,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 +1472,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("checkAtomicServicePreloadsIsValid failed on device " + + device + ".")); return false; } } @@ -1416,7 +1501,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 +1517,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 + " 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 + " 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() + " preload self.")); return false; } } @@ -1457,9 +1545,8 @@ 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, " + + hapVerifyInfo.getModuleName() + " preloads a " + moduleNameWithType.get(moduleName) + " module.")); return false; } } @@ -1476,11 +1563,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 +1573,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 +1582,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 " + - getCeilFileSize(hapVerifyInfo.getFileLength(), entryLimit) + - "MB, which is overlarge than " + entryLimit + "MB."); + String errMsg = "module " + hapVerifyInfo.getModuleName() + "'s size is " + + getCeilFileSize(hapVerifyInfo.getFileLength(), entryLimit) + + "MB, which is overlarge than " + entryLimit + "MB."; + LOG.error(PackingToolErrMsg.CHECK_FILE_SIZE_INVALID.toString(errMsg)); return false; } if (!hapVerifyInfo.getModuleType().equals(ENTRY) && (hapVerifyInfo.getFileLength() >= notEntryLimit * FILE_LENGTH_1M)) { - LOG.error("module " + hapVerifyInfo.getModuleName() + "'s size is " + + String errMsg = "module " + hapVerifyInfo.getModuleName() + "'s size is " + getCeilFileSize(hapVerifyInfo.getFileLength(), notEntryLimit) + - "MB, which is overlarge than " + notEntryLimit + "MB."); + "MB, which is overlarge than " + notEntryLimit + "MB."; + LOG.error(PackingToolErrMsg.CHECK_FILE_SIZE_INVALID.toString(errMsg)); return false; } } @@ -1515,7 +1602,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 ModuleSize 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 6bbf26904310f5d8c3875987e875d564116f5d92..7b2f52cf12e860ee445f019a45ba01a4dff8bd02 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,15 +154,17 @@ 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("ModuleJsonUtil:parseFaVersion 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."); } @@ -239,7 +241,8 @@ 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."); + String errMsg = "json file does not contain apiVersion."; + LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString(errMsg)); throw new BundleException("ModuleJsonUtil::parseFAAPIVersion json file do not contain apiVersion."); } JSONObject apiVersionObj = appObj.getJSONObject(API_VERSION); @@ -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 = "ModuleJsonUtil:parseFaModuleName failed: json file do 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 = "ModuleJsonUtil:parseFaModuleName failed: json file do 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,7 +355,7 @@ class ModuleJsonUtil { if (appObject.containsKey(BUNDLE_NAME)) { bundleName = appObject.getString(BUNDLE_NAME); } else { - LOG.error("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("ModuleJsonUtil::parseStageBundleName 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 FA distorFilter failed: " + 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."; + 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,7 +1404,9 @@ 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."); + 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 JOSNObject failed in parseProxyDataUri."); } String uri = itemObj.getString(PROXY_URI); @@ -1404,7 +1417,9 @@ 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."); + 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 JOSNObject failed in parseProxyDataUri."); } String uri = itemObj.getString(PROXY_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 failed.\n"; + 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 = "parse JSON object exception."; + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString(errMsg)); throw new BundleException(errMsg); } if (jsonObj == null) { - LOG.error("ModuleJsonUtil::parseStageInstallation jsonObj is null."); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("jsonObj is null.")); throw new BundleException("ModuleJsonUtil::parseStageInstallation 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("ModuleJsonUtil::parseFAInstallation 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 JOSNObject failed when get debug in config.json."); + throw new BundleException("parse JOSNObject failed when get debug in config.json."); } JSONObject deviceConfigObj = jsonObject.getJSONObject(DEVICE_CONFIG); if (deviceConfigObj == null) { @@ -1842,12 +1857,13 @@ class ModuleJsonUtil { try { jsonObject = JSON.parseObject(jsonString); } catch (JSONException exception) { - LOG.error("parse JOSNObject failed in isExistedProperty."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("parse JOSN Object failed in isExistedProperty.")); throw new BundleException("parse JOSNObject failed in isExistedProperty."); } JSONObject appObj = jsonObject.getJSONObject(fatherProperty); if (appObj == null) { - LOG.error("parse failed, input module.json is invalid, module.json has no " + fatherProperty + "."); + String errMsg = "parse failed, input module.json is invalid, module.json has no "+ fatherProperty; + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString(errMsg)); throw new BundleException("parse failed, input module.json is invalid, module.json has no " + fatherProperty + "."); } @@ -1899,7 +1915,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 +1933,8 @@ class ModuleJsonUtil { return true; } if (parseModuleType(jsonString).equals(ENTRY) && parseAbilityNames(jsonString).isEmpty()) { - LOG.error("entry module must contain at least one ability."); + String errMsg = "entry module must contain at least one ability."; + LOG.error(PackingToolErrMsg.CHECK_LEASTONE_ABILITY.toString(errMsg)); return false; } return true; @@ -1936,9 +1954,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:" + + String errMsg = "The app.json5 file configuration does not match the installationFree:" + " true settings. Add the bundleType field to the app.json5 file and set it atomicService."; - LOG.error(errMessage); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString(errMsg)); return false; } return true; @@ -1946,26 +1964,26 @@ class ModuleJsonUtil { String bundleType = getJsonString(appObj, BUNDLE_TYPE); if (bundleType.equals(APP)) { if (installationFree) { - LOG.error("installationFree must be false when bundleType is app."); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString("installationFree must be false when bundleType is app.")); return false; } } else if (bundleType.equals(ATOMIC_SERVICE)) { if (!installationFree) { - LOG.error("installationFree must be true when bundleType is atomicService."); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString("installationFree must be true when bundleType is atomicService.")); return false; } } else if (SHARED.equals(bundleType)) { if (installationFree) { - LOG.error("installationFree must be false when bundleType is shared."); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString("installationFree must be false when bundleType is shared.")); return false; } } else if (APP_SERVICE.equals(bundleType)) { if (installationFree) { - LOG.error("installationFree must be false when bundleType is appService."); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString("installationFree must be false when bundleType is appService.")); return false; } } else { - LOG.error("bundleType is invalid in app.json."); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString("bundleType is invalid in app.json.")); return false; } return true; diff --git a/adapter/ohos/PackingToolErrMsg.java b/adapter/ohos/PackingToolErrMsg.java new file mode 100644 index 0000000000000000000000000000000000000000..557e116c5033e584d7e34281104fcc81b0401d81 --- /dev/null +++ b/adapter/ohos/PackingToolErrMsg.java @@ -0,0 +1,886 @@ +/* + * 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/06 + */ +public class PackingToolErrMsg { + + // packing tool error + /** + * EXECUTE_PACKING_TOOL_FAILED + */ + public static final ErrorMsg EXECUTE_PACKING_TOOL_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("10") + .addErrCode("001") + .addDescription("Execute packing tool failed.") + .addCause("%s") + .addSolution("Please check the related log or error message and modify.") + .build(); + + /** + * EXECUTE_PACKING_TOOL_FAILED + */ + public static final ErrorMsg COMMAND_PARSER_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("10") + .addErrCode("002") + .addDescription("Command parser failed.") + .addCause("%s") + .build(); + + /** + * COMMAND_VERIFY_FAILED + */ + public static final ErrorMsg COMMAND_VERIFY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("10") + .addErrCode("003") + .addDescription("Command verify failed.") + .addCause("%s") + .build(); + + // compress error + /** + * HAP_MODE_ARGS_INVALID + */ + public static final ErrorMsg HAP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("001") + .addDescription("Parse and check args invalid in hap mode.") + .addCause("%s") + .build(); + + /** + * HSP_MODE_ARGS_INVALID + */ + public static final ErrorMsg HSP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("002") + .addDescription("Parse and check args invalid in hsp mode.") + .addCause("%s") + .build(); + + /** + * APP_MODE_ARGS_INVALID + */ + public static final ErrorMsg APP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("003") + .addDescription("Parse and check args invalid in app mode.") + .addCause("%s") + .build(); + + /** + * COMMAND_MODE_INVALID + */ + public static final ErrorMsg COMMAND_MODE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("011") + .addDescription("Command verify mode is invalid.") + .addCause("Input mode is invalid.") + .build(); + + /** + * BUNDLE_TYPE_SHARED_INVALID + */ + public static final ErrorMsg BUNDLE_TYPE_SHARED_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("012") + .addDescription("Check bundleTypeShared failed.") + .addCause("%s") + .addSolution("Please check the related error message and modify.") + .build(); + + /** + * BUNDLE_TYPE_APPSERVICE_INVALID + */ + public static final ErrorMsg BUNDLE_TYPE_APPSERVICE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("013") + .addDescription("Check BundleTypeAppService invalid.") + .addCause("%s") + .addSolution("Please check the related error message and modify.") + .build(); + + /** + * HSP_HAS_ABILITIES_FAILED + */ + public static final ErrorMsg HSP_HAS_ABILITIES_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("014") + .addDescription("Check hsp has abilities failed.") + .addCause("%s") + .build(); + + /** + * HSP_HAS_EXTENSION_ABILITIES_FAILED + */ + public static final ErrorMsg HSP_HAS_EXTENSION_ABILITIES_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("015") + .addDescription("Check hsp has extension abilities failed.") + .addCause("%s") + .build(); + + /** + * HAS_HOME_ABILITY_INVALID + */ + public static final ErrorMsg HAS_HOME_ABILITY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("016") + .addDescription("Check hsp has entry abilitiy failed.") + .addCause("%s") + .build(); + + /** + * HAS_HOME_EXTENSION_ABILITY_INVALID + */ + public static final ErrorMsg HAS_HOME_EXTENSION_ABILITY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("017") + .addDescription("Check hsp has entry ExtensionAbility failed.") + .addCause("%s") + .build(); + + /** + * OUT_PATH_INVALID + */ + public static final ErrorMsg OUT_PATH_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("018") + .addDescription("Invalid output path.") + .addCause("%s") + .build(); + + // compress process error + /** + * COMPRESS_PROCESS + */ + public static final ErrorMsg COMPRESS_PROCESS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("001") + .addDescription("Execute compress process failed.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * COMPRESS_HAP_FAILED + */ + public static final ErrorMsg COMPRESS_HAP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("002") + .addDescription("Compress Stage Hap failed.") + .addCause("%s") + .addSolution("Please check the related error message and modify.") + .build(); + + /** + * CHECK_STAGE_HAP_FAILED + */ + public static final ErrorMsg CHECK_STAGE_HAP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("003") + .addDescription("verify stage hap info failed.") + .addCause("%s") + .build(); + + /** + * CHECK_AS_TSAN_ENABLED + */ + public static final ErrorMsg CHECK_AS_TSAN_ENABLED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("004") + .addDescription("Check asanEnabled and tsanEnabled failed.") + .addCause("%s") + .addSolution("Please set the correct values for the parameters.") + .build(); + + /** + * CHECK_UBASAN_ENABLED_INVALID + */ + public static final ErrorMsg CHECK_UBASAN_ENABLED_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("005") + .addDescription("Check ubsanEnabled and asanEnabled failed.") + .addCause("%s") + .addSolution("Please set the correct values for the parameters.") + .build(); + + /** + * CHECK_HWASAN_ENABLED_INVALID + */ + public static final ErrorMsg CHECK_HWASAN_ENABLED_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("006") + .addDescription("Check hwasanEnabled and asanEnabled failed.") + .addCause("%s") + .addSolution("Please set the correct values for the parameters.") + .build(); + + /** + * CHECK_ATOMIC_SERVICE_FAILED + */ + public static final ErrorMsg CHECK_ATOMIC_SERVICE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("007") + .addDescription("Check atomicService failed.") + .addCause("%s") + .build(); + + /** + * CHECK_CONTINUE_BUNDLENAME_INVALID + */ + public static final ErrorMsg CHECK_CONTINUE_BUNDLENAME_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("008") + .addDescription("ContinueBundleName and BundleName cannot be the same.") + .addCause("%s") + .addSolution("Ensure continueBundleName not inclue self.") + .build(); + + /** + * COMPRESS_PROCESS_EXCEPTION + */ + public static final ErrorMsg COMPRESS_PROCESS_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("009") + .addDescription("Process compress exception.") + .addCause("%s") + .addSolution( + "Please check the related error message and modify. If the issue persists, review the logs for more details.") + .build(); + + /** + * HAS_GENERATE_BUILD_HASH + */ + public static final ErrorMsg HAS_GENERATE_BUILD_HASH = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("010") + .addDescription("Verify has generate build hash failed.") + .addCause("%s") + .build(); + + /** + * SET_GENERATE_BUILD_HASH + */ + public static final ErrorMsg SET_GENERATE_BUILD_HASH = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("011") + .addDescription("Set generate build hash failed.") + .addCause("%s") + .build(); + + /** + * CHECK_OVERLAY_CFG_FAILED + */ + public static final ErrorMsg CHECK_OVERLAY_CFG_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("012") + .addDescription("Check whether is an overlay hsp or not failed.") + .addCause("%s") + .build(); + + /** + * READ_STAGE_HAP_VERIFY_INFO_FAILED + */ + public static final ErrorMsg READ_STAGE_HAP_VERIFY_INFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("013") + .addDescription("Read stage hap verify info io exception.") + .addCause("%s") + .build(); + + /** + * COMPRESS_PARALLEL_EXCEPTION + */ + public static final ErrorMsg COMPRESS_PARALLEL_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("014") + .addDescription("Parallel compress exception.") + .addCause("%s") + .addSolution( + "Please check the related error message and modify the operation. If the issue persists, review the logs for more details.") + .build(); + + /** + * COMPRESS_APP_FAILED + */ + public static final ErrorMsg COMPRESS_APP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("015") + .addDescription("Compress app file failed.") + .addCause("%s") + .addSolution("Modified according to related verification errors.") + .build(); + + /** + * INVALID_HAP_FILE + */ + public static final ErrorMsg INVALID_HAP_FILE = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("016") + .addDescription("check input hap or hsp file is invalid.") + .addCause("%s") + .build(); + + /** + * CHECK_SHARED_APP_INVALID + */ + public static final ErrorMsg CHECK_SHARED_APP_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("017") + .addDescription("Check shared App mode invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_BUNDLETYPE_INVALID + */ + public static final ErrorMsg CHECK_BUNDLETYPE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("018") + .addDescription("Check bundleType is invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * COMPRESS_APP_VERIFY_FAILED + */ + public static final ErrorMsg APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("019") + .addDescription("Check app atomicservice compress size failed.") + .addCause("%s") + .build(); + + /** + * READ_FA_HAP_VERIFY_INFO_FAILED + */ + public static final ErrorMsg READ_FA_HAP_VERIFY_INFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("020") + .addDescription("Read FA hap verify info io exception.") + .addCause("%s") + .build(); + + /** + * COMPRESS_APP_IO_EXCEPTION + */ + public static final ErrorMsg COMPRESS_APP_IO_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("021") + .addDescription("Io exception when compress app.") + .addCause("%s") + .addSolution( + "Please check the related error message and modify the operation. If the issue persists, review the logs for more details.") + .build(); + + /** + * COMPRESS_HSP_FAILED + */ + public static final ErrorMsg COMPRESS_HSP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("022") + .addDescription("Compress Hsp failed.") + .addCause("%s") + .build(); + + /** + * JSON_SPECIAL_PROCESS_FAILED + */ + public static final ErrorMsg JSON_SPECIAL_PROCESS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("023") + .addDescription("Json SpecialProcess exception.") + .addCause("%s") + .addSolution("Please check the related error message and modify the operation.") + .build(); + + // module json check error + /** + * PARSE_JSON_OBJECT_EXCEPTION + */ + public static final ErrorMsg PARSE_JSON_OBJECT_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("001") + .addDescription("Parse json Object occur expection.") + .addCause("%s") + .build(); + + /** + * PARSE_JSON_FAILED + */ + public static final ErrorMsg PARSE_JSON_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("002") + .addDescription("Parse json profile failed.") + .addCause("%s") + .build(); + + /** + * CHECK_MODULE_ATOMIC_SERVICE_FAILED + */ + public static final ErrorMsg CHECK_MODULE_ATOMIC_SERVICE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("003") + .addDescription("Check module atomicService invalid.") + .addCause("%s") + .build(); + + /** + * PARSE_STAGE_JSON_FAILED + */ + public static final ErrorMsg PARSE_STAGE_JSON_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("004") + .addDescription("Failed to parse module.json for stage module.") + .addCause("%s") + .build(); + + /** + * PARSE_STAGE_BUNDLE_TYPE_FAILED + */ + public static final ErrorMsg PARSE_STAGE_BUNDLE_TYPE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("005") + .addDescription("Failed to parse module.json and bundleType.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_LEASTONE_ABILITY + */ + public static final ErrorMsg CHECK_LEASTONE_ABILITY = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("006") + .addDescription("Check entry module at least one ability failed.") + .addCause("%s") + .build(); + + /** + * CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED + */ + public static final ErrorMsg CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("007") + .addDescription("Check module atomic installation free invalid.") + .addCause("%s") + .build(); + + /** + * PARSE_BUNDLE_NAME + */ + public static final ErrorMsg PARSE_BUNDLE_NAME_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("008") + .addDescription("Get the bundleName from json file failed.") + .addCause("%s") + .build(); + + /** + * PARSE_PROXY_DATA_URI_FAILED + */ + public static final ErrorMsg PARSE_PROXY_DATA_URI_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("009") + .addDescription("Failed to parse module.json and proxyData object.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_BUNDLETYPE_CONSISTENCY_FAILED + */ + public static final ErrorMsg CHECK_BUNDLETYPE_CONSISTENCY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("010") + .addDescription("BundleType consistency check failed.") + .addCause("%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() + .addTypeCode("13") + .addErrCode("011") + .addDescription("Failed to parse patch module name from patch.json.") + .addCause("%s") + .build(); + + /** + * PARSE_FA_HAP_VERIFY_INFO_FAILED + */ + public static final ErrorMsg PARSE_FA_HAP_VERIFY_INFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("012") + .addDescription("Failed to parse FA hap verify info from config.json.") + .addCause("%s") + .build(); + + /** + * PARSE_STAGE_VERSION_FAILED + */ + public static final ErrorMsg PARSE_FA_JSON_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("013") + .addDescription("Failed to parse config.json for FA module.") + .addCause("%s") + .build(); + + // file operator error + /** + * FILE_NOT_FOUND + */ + public static final ErrorMsg FILE_NOT_FOUND = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("14") + .addErrCode("001") + .addDescription("File avaiable not found exception.") + .addCause("%s") + .addSolution( + "Please check the related error message, 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() + .addTypeCode("14") + .addErrCode("002") + .addDescription("close zip output stream exception.") + .addCause("%s") + .addSolution( + "Please check the related error message and modify the operation. If the issue persists, review the logs for more details.") + .build(); + + /** + * CLOSE_STREAM_EXPECTION + */ + public static final ErrorMsg CLOSE_STREAM_EXPECTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("14") + .addErrCode("003") + .addDescription("IO exception when closing stream.") + .addCause("%s") + .addSolution("Please check the related error message and modify the operation.") + .build(); + + /** + * GET_FILE_CONTENT_FAILED + */ + public static final ErrorMsg GET_FILE_CONTENT_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("14") + .addErrCode("004") + .addDescription("Get file content failed.") + .addCause("%s") + .addSolution("Please check the related error message and modify.") + .build(); + + /** + * FILE_NOT_EXIST + */ + public static final ErrorMsg FILE_NOT_EXIST = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("14") + .addErrCode("005") + .addDescription("Parse file not exist.") + .addCause("%s") + .build(); + + /** + * GET_FILE_SIZE_FAILED + */ + public static final ErrorMsg GET_FILE_SIZE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("14") + .addErrCode("006") + .addDescription("Get file size failed.") + .addCause("%s") + .build(); + + /** + * FILE_IO_EXCEPTION + */ + public static final ErrorMsg FILE_IO_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("14") + .addErrCode("007") + .addDescription("File io exception.") + .addCause("%s") + .addSolution("Please check the following:\n" + + "1. Ensure the file path is correct and the file exists.\n" + + "2. Verify you have the necessary permissions to access the file.\n" + + "3. Check for possible disk or file system errors.\n" + + "4. Review the related error message for further insights.") + .build(); + + /** + * COMPRESS_FILE_EXCEPTION + */ + public static final ErrorMsg COMPRESS_FILE_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("14") + .addErrCode("008") + .addDescription("Compress file exception.") + .addCause("%s") + .addSolution( + "Please check the related error message and modify the operation. If the issue persists, review the logs for more details.") + .build(); + + /** + * FILE_DELETE_FAILED + */ + public static final ErrorMsg FILE_DELETE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("14") + .addErrCode("009") + .addDescription("File delete failed.") + .addCause("%s") + .addSolution("%s") + .build(); + + // io exception + /** + * IO_EXCEPTION + */ + public static final ErrorMsg IO_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") + .addErrCode("001") + .addDescription("IO exception.") + .addCause("%s") + .addSolution("Please check the following:\n" + + "1. Ensure the file path is correct and the file exists.\n" + + "2. Verify you have the necessary permissions to access the file.\n" + + "3. Check for possible disk or file system errors.\n" + + "4. Review the related error message for further insights.") + .build(); + + /* + * NULL_POINTER_EXPECTION + */ + public static final ErrorMsg NULL_POINTER_EXPECTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") + .addErrCode("002") + .addDescription("Null pointer exception.") + .addCause("%s") + .addSolution("Please review the related error message for further insights.") + .build(); + + // hap verify error + /** + * APP_FIELDS_INVALID + */ + public static final ErrorMsg CHECK_APP_FIELDS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("001") + .addDescription("App fields is invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * APP_FIELDS_DIFFERENT_ERROR + */ + public static final ErrorMsg APP_FIELDS_DIFFERENT_ERROR = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("002") + .addDescription("Some app variable is different.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_MODULE_NAME_INVALID + */ + public static final ErrorMsg CHECK_POLICY_DISJOINT_ERROR = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("003") + .addDescription("Check two distroFilter policy disjoint invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_MODULE_NAME_INVALID + */ + public static final ErrorMsg CHECK_MODULE_NAME_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("004") + .addDescription("Check module name is invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_PACKAGE_NAME_INVALID + */ + public static final ErrorMsg CHECK_PACKAGE_NAME_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("005") + .addDescription("Check packageName invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_HAP_INVALID + */ + public static final ErrorMsg CHECK_HAP_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("006") + .addDescription("Verify hap info is invalid.") + .addCause("%s") + .addSolution("Please check the related error message and modify.") + .build(); + + /** + * CHECK_ENTRY_INVALID + */ + public static final ErrorMsg CHECK_ENTRY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("007") + .addDescription("Check entry module invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_ENTRY_INVALID + */ + public static final ErrorMsg CHECK_DEPENDENCY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("008") + .addDescription("Check dependency is invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * DEPENDENCY_LIST_INVALID + */ + public static final ErrorMsg DEPENDENCY_LIST_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("009") + .addDescription("Check dependency list is invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_ATOMICSERVICE_INVALID + */ + public static final ErrorMsg CHECK_ATOMICSERVICE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("010") + .addDescription("Check atomicservice is invalid.") + .addCause("%s") + .build(); + + /** + * ATOMICSERVICE_PRELOADS_INVALID + */ + public static final ErrorMsg ATOMICSERVICE_PRELOADS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("011") + .addDescription("Atomicservice preloads is invalid.") + .addCause("%s") + .build(); + + /** + * ATOMICSERVICE_INVALID + */ + public static final ErrorMsg TARGET_MODULE_NAME_NOT_EXIST = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("012") + .addDescription("Target ModuleName is not exist.") + .addCause("%s") + .addSolution("Make sure contain at least one vaild target module.") + .build(); + + /** + * COMPILE_SDK_INVALID + */ + public static final ErrorMsg COMPILE_SDK_TYPE_DIFFERENT = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("013") + .addDescription("CompileSdkType is different.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * PROXY_DATA_URI_NOT_UNIQUE + */ + public static final ErrorMsg PROXY_DATA_URI_NOT_UNIQUE = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("014") + .addDescription("Proxy data uri is not unique.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CONTINUE_TYPE_INVALID + */ + public static final ErrorMsg CONTINUE_TYPE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("015") + .addDescription("Check continueType is invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_FILE_SIZE_INVALID + */ + public static final ErrorMsg CHECK_FILE_SIZE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("016") + .addDescription("File size check failed.") + .addCause("%s") + .build(); + + /** + * CHECK_HAP_VERIFY_INFO_LIST_EMPTY + */ + public static final ErrorMsg CHECK_HAP_VERIFY_INFO_LIST_EMPTY = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("017") + .addDescription("The provided list of HapVerifyInfo is empty, unable to process.") + .addCause("Input list of HapVerifyInfo is empty.") + .build(); + + /** + * CHECK_FILE_SIZE_INVALID + */ + public static final ErrorMsg CHECK_ATOMIC_SERVICE_MODULE_SIZE = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("018") + .addDescription("AtomicService module size check failed.") + .addCause("%s") + .build(); + + /** + * CHECK_FEATURE_DISTRO_FILTER_INVALID + */ + public static final ErrorMsg CHECK_FEATURE_DISTRO_FILTER_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("019") + .addDescription("Check feature is invalid.") + .addCause("%s") + .build(); +} diff --git a/adapter/ohos/StringUtils.java b/adapter/ohos/StringUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..e6a454a445f359a8885bc3c3d783d32e3503ca07 --- /dev/null +++ b/adapter/ohos/StringUtils.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021-2022 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; + +/** + * StringUtils. + * + * @since 2021/12/28 + */ +public final class StringUtils { + private StringUtils() { + } + + /** + * Check whether the input string is empty. + * + * @param cs input string + * @return true, if cs is empty + */ + public static boolean isEmpty(final CharSequence cs) { + return cs == null || cs.length() == 0; + } + + /** + * Check whether the array contains string ignoring case. + * + * @param array input string array + * @param str input string + * @return true, if the array contains the str ignoring case + */ + public static boolean containsIgnoreCase(String[] array, String str) { + if (array == null) { + return false; + } + for (String s : array) { + if (s != null && s.equalsIgnoreCase(str)) { + return true; + } + } + return false; + } +} diff --git a/build.py b/build.py index ca00ba73a98974509cc565b669d2b494553b80f2..98ab75a525eb2ff89e9a249e476164f47899e21e 100755 --- a/build.py +++ b/build.py @@ -49,9 +49,12 @@ 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', + 'StringUtils.java', 'Utility.java' ] compile_java = get_compile_str(src_path, java_sources) @@ -72,7 +75,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,11 +83,11 @@ 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', - 'ShowHelp.java', 'SkillInfo.java', 'UncompressEntrance.java', + 'ShowHelp.java', 'SkillInfo.java', 'StringUtils.java', 'UncompressEntrance.java', 'Uncompress.java', 'UncompressResult.java', 'UncompressVerify.java', 'UriInfo.java', 'UsedScene.java', 'Utility.java', 'Want.java', 'ProxyDataItem.java' ] @@ -111,6 +114,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,11 +129,13 @@ 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', 'ScreenWindow.java', 'ShowHelp.java', + 'StringUtils.java', 'Utility.java', 'VerifyCollection.java', 'Version.java' @@ -149,9 +155,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', @@ -160,6 +168,7 @@ def compile_check_tool(root_path, src_path, jar_output, out_path, 'ScanStatSuffix.java', 'ScanVerify.java', 'ShowHelp.java', + 'StringUtils.java', 'Utility.java' ] compile_java = get_compile_str(src_path, java_sources)