diff --git a/adapter/ohos/CompressVerify.java b/adapter/ohos/CompressVerify.java index 83256f75b278322ba1b62f4f636bc3281b5645bb..2de67edc6fc285b2900c3682df8e7f13692fbac2 100644 --- a/adapter/ohos/CompressVerify.java +++ b/adapter/ohos/CompressVerify.java @@ -158,29 +158,35 @@ public class CompressVerify { private static boolean validatePackageNormalizeMode(Utility utility) { if (utility.getHspList().isEmpty()) { - LOG.error("CompressVerify::validatePackageNormalizeMode hsp-list is empty."); + String errMsg = "--hsp-list is empty."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } else { if (!compatibleProcess(utility, utility.getHspList(), utility.getFormattedHspPathList(), HSP_SUFFIX)) { - LOG.error("CompressVerify::validatePackageNormalizeMode hsp-list is invalid."); + String errMsg = "--hsp-list is invalid."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!isBundleNameValid(utility.getBundleName())) { - LOG.error("CompressVerify::validatePackageNormalizeMode bundle-name is invalid."); + String errMsg = "--bundle-name is invalid."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getVersionCode() <= 0) { - LOG.error("CompressVerify::validatePackageNormalizeMode version-code is invalid."); + String errMsg = "--version-code is invalid."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getOutPath().isEmpty()) { - LOG.error("CompressVerify::validatePackageNormalizeMode out-path is empty."); + String errMsg = "--out-path is empty."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } File outDir = new File(utility.getOutPath()); if (!outDir.isDirectory()) { - LOG.error("CompressVerify::validatePackageNormalizeMode out-path is not a directory."); + String errMsg = "--out-path is not a directory."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -188,45 +194,53 @@ public class CompressVerify { private static boolean validateVersionNormalizeMode(Utility utility) { if (utility.getInputList().isEmpty()) { - LOG.error("CompressVerify::validateVersionNormalizeMode input-list is empty."); + String errMsg = "--input-list is empty."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!handleHapAndHspInput(utility, utility.getInputList(), utility.getFormattedHapList())) { - LOG.error("CompressVerify::validateVersionNormalizeMode input-list is invalid."); + String errMsg = "--input-list is invalid."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getFormattedHapList().isEmpty()) { - LOG.error("CompressVerify::validateVersionNormalizeMode input-list is empty."); + String errMsg = "--input-list is empty."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getVersionCode() <= 0) { - LOG.error("CompressVerify::validateVersionNormalizeMode version-code is invalid."); + String errMsg = "--version-code is invalid."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getVersionName().isEmpty()) { - LOG.error("CompressVerify::validateVersionNormalizeMode version-name is empty."); + String errMsg = "--version-name is empty."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } Pattern versionNamePattern = Pattern.compile(VERSION_NAME_PATTERN); Matcher versionNameMatcher = versionNamePattern.matcher(utility.getVersionName()); if (!versionNameMatcher.matches()) { - LOG.error("CompressVerify::validateVersionNormalizeMode version-name is not valid."); + String errMsg = "--version-name is not valid."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getOutPath().isEmpty()) { - LOG.error("CompressVerify::validateVersionNormalizeMode out-path is empty."); + String errMsg = "--out-path is empty."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } File outDir = new File(utility.getOutPath()); if (!outDir.isDirectory()) { - LOG.error("CompressVerify::validateVersionNormalizeMode out-path is not a directory."); + String errMsg = "--out-path is not a directory."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -447,45 +461,53 @@ public class CompressVerify { */ private static boolean isVerifyValidInHarMode(Utility utility) { if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::isArgsValidInHarMode json-path is empty."); + String errMsg = "--json-path is empty."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!isPathValid(utility.getJsonPath(), TYPE_FILE, JSON_PROFILE) && !isPathValid(utility.getJsonPath(), TYPE_FILE, MODULE_PROFILE)) { - LOG.error("CompressVerify::isArgsValidInHarMode json-path must be config.json file."); + String errMsg = "--json-path must be config.json file."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getJarPath().isEmpty() && !compatibleProcess(utility, utility.getJarPath(), utility.getFormattedJarPathList(), JAR_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHarMode jar-path is invalid."); + String errMsg = "--jar-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getTxtPath().isEmpty() && !compatibleProcess(utility, utility.getTxtPath(), utility.getFormattedTxtPathList(), TXT_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHarMode txt-path is invalid."); + String errMsg = "--txt-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getLibPath().isEmpty() && !isPathValid(utility.getLibPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode lib-path is invalid."); + String errMsg = "--lib-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getResPath().isEmpty() && !isPathValid(utility.getResPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode res-path is invalid."); + String errMsg = "--res-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getResourcesPath().isEmpty() || !isPathValid(utility.getResourcesPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode resources-path is invalid."); + String errMsg = "--resources-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getAssetsPath().isEmpty() && !isPathValid(utility.getAssetsPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode assets-path is invalid."); + String errMsg = "--assets-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -629,41 +651,48 @@ public class CompressVerify { */ private static boolean isVerifyValidInMultiAppMode(Utility utility) { if (utility.getAppList().isEmpty() && utility.getHapList().isEmpty() && utility.getHspList().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode input app-list, hap-list and hsp-list are null."); + String errMsg = "Input --app-list, --hap-list and --hsp-list are empty."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getAppList().isEmpty()) { if (!compatibleProcess(utility, utility.getAppList(), utility.getFormattedAppList(), APP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode app-list is invalid."); + String errMsg = "--app-list is invalid."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!utility.getHapList().isEmpty()) { if (!compatibleProcess(utility, utility.getHapList(), utility.getFormattedHapList(), HAP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode hap-list is invalid."); + String errMsg = "--hap-list is invalid."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!utility.getHspList().isEmpty()) { if (!compatibleProcess(utility, utility.getHspList(), utility.getFormattedHapList(), HSP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode hsp-list is invalid."); + String errMsg = "--hsp-list is invalid."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!isValidEncryptJsonFile(utility)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode encrypt-path is invalid."); + String errMsg = "--encrypt-path is invalid."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } File outFile = new File(utility.getOutPath()); if (("false".equals(utility.getForceRewrite())) && outFile.exists()) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode out file already existed."); + String errMsg = "--out-path file already existed, but --force is 'false'."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(APP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode out-path must end with .app."); + String errMsg = "--out-path must end with .app."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -678,18 +707,20 @@ public class CompressVerify { */ private static boolean isVerifyValidInResMode(Utility utility) { if (!isPathValid(utility.getPackInfoPath(), TYPE_FILE, PACK_INFO)) { - LOG.error("CompressVerify::isArgsValidInResMode pack-info-path is invalid."); + String errMsg = "--pack-info-path is invalid."; + LOG.error(PackingToolErrMsg.RES_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!isDirectoryValidStrictCase(utility.getEntryCardPath(), ENTRY_CARD_DIRECTORY_NAME)) { - LOG.error("CompressVerify::isArgsValidInResMode the level-1 directory name must is EntryCard" + - ", current is " + utility.getEntryCardPath()); + String errMsg = "The level-1 directory name must be EntryCard, current is " + utility.getEntryCardPath(); + LOG.error(PackingToolErrMsg.RES_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!compatibleProcess(utility, utility.getEntryCardPath(), utility.getformattedEntryCardPathList(), PNG_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInResMode entrycard-path is invalid."); + String errMsg = "--entrycard-path is invalid."; + LOG.error(PackingToolErrMsg.RES_MODE_ARGS_INVALID.toString(errMsg)); return false; } return isOutPathValid(utility, RES_SUFFIX); @@ -697,38 +728,45 @@ public class CompressVerify { private static boolean isVerifyValidInHQFMode(Utility utility) { if (utility.getJsonPath().isEmpty()) { - LOG.error("must input patch.json file when pack hqf file."); + String errMsg = "--json-path is empty, must input patch.json file when pack hqf file."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getEtsPath().isEmpty()) { if (!isPathValid(utility.getEtsPath(), TYPE_DIR, null)) { - LOG.error("must input valid ets path when pack hqf file."); + String errMsg = "--ets-path is invalid."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!isPathValid(utility.getJsonPath(), TYPE_FILE, PATCH_PROFILE)) { - LOG.error("input patch.json is invalid when pack hqf file."); + String errMsg = "--json-path is invalid."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getLibPath().isEmpty()) { if (!isPathValid(utility.getLibPath(), TYPE_DIR, null)) { - LOG.error("input lib path is invalid when pack hqf file."); + String errMsg = "--lib-path is invalid."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!utility.getResourcesPath().isEmpty()) { if (!isPathValid(utility.getResourcesPath(), TYPE_DIR, null)) { - LOG.error("input resources path is invalid when pack hqf file."); + String errMsg = "--resources-path is invalid."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } } File outFile = new File(utility.getOutPath()); if ((FALSE.equals(utility.getForceRewrite())) && (outFile.exists())) { - LOG.error(outFile.getName() + " already exist."); + String errMsg = outFile.getName() + " already exist."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getOutPath().endsWith(HQF_SUFFIX)) { - LOG.error("input out file must end with .hqf."); + String errMsg = "--out-path file must end with .hqf."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -736,20 +774,24 @@ public class CompressVerify { private static boolean isVerifyValidInAPPQFMode(Utility utility) { if (utility.getHqfList().isEmpty()) { - LOG.error("input hqf list is empty."); + String errMsg = "--hqf-list is empty."; + LOG.error(PackingToolErrMsg.APPQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!compatibleProcess(utility, utility.getHqfList(), utility.getFormatedHQFList(), HQF_SUFFIX)) { - LOG.error("input hqf list is invalid."); + String errMsg = "--hqf-list is invalid."; + LOG.error(PackingToolErrMsg.APPQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } File outFile = new File(utility.getOutPath()); if ((FALSE.equals(utility.getForceRewrite())) && outFile.exists()) { - LOG.error("Error out file already existed."); + String errMsg = "--out-path file already existed, but --force is 'false'."; + LOG.error(PackingToolErrMsg.APPQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(APPQF_SUFFIX)) { - LOG.error("Error out-path must end with .app."); + String errMsg = "--out-path must end with .appqf."; + LOG.error(PackingToolErrMsg.APPQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -813,7 +855,8 @@ public class CompressVerify { formattedPathItem = utility.getFormattedPath(pathItem); if (!isPathValid(formattedPathItem, TYPE_FILE, HSP_SUFFIX) && !isPathValid(formattedPathItem, TYPE_FILE, HAP_SUFFIX)) { - LOG.error("input file " + formattedPathItem + " not valid"); + String errMsg = "Input file " + formattedPathItem + " is invalid"; + LOG.error(PackingToolErrMsg.INPUT_PATH_INVALID.toString(errMsg)); return false; } fileList.add(formattedPathItem); @@ -923,8 +966,8 @@ public class CompressVerify { private static boolean isDirectoryValidStrictCase(String path, String directoryName) { File file = new File(path); if (!file.exists()) { - LOG.error("CompressVerify::isDirectoryValidStrictCase directory is not exist, directoryPath: " - + path + "."); + String errMsg = "The directory does not exist, directory path is: " + path + "."; + LOG.error(PackingToolErrMsg.DIRECTORY_INVALID.toString(errMsg)); return false; } if (file.isDirectory()) { @@ -1069,48 +1112,58 @@ public class CompressVerify { private static boolean isVerifyValidInHapAdditionMode(Utility utility) { if (utility.getHapPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hapPath is empty."); + String errMsg = "--hap-path is empty."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } String hapPath = utility.getAbsoluteHapPath(); File hapFile = new File(hapPath); if (hapFile.isDirectory()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hapPath cannot be a folder."); + String errMsg = "--hap-path cannot be a folder."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!(hapPath.endsWith(HAP_SUFFIX) || hapPath.endsWith(HSP_SUFFIX))) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hapPath is invalid."); + String errMsg = "--hap-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!hapFile.exists()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hap file does not exist."); + String errMsg = "--hap-path file does not exist."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode jsonPath is empty."); + String errMsg = "--json-path is empty."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getJsonPath().endsWith(JSON_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode jsonPath is invalid."); + String errMsg = "--json-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } File jsonFile = new File(utility.getJsonPath()); if (!jsonFile.exists()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode json file does not exist."); + String errMsg = "--json-path file does not exist."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!checkJsonIsValid(jsonFile)) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode json format is incorrect."); + String errMsg = "--json-path file is invalid."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getOutPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode outPath is empty."); + String errMsg = "--out-path is empty."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } File dir = new File(utility.getOutPath()); if (dir.exists() && dir.isFile()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode outPath is file."); + String errMsg = "--out-path is file."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } File absoluteHapFile = new File(utility.getAbsoluteHapPath()); @@ -1118,7 +1171,8 @@ public class CompressVerify { String destPath = utility.getOutPath() + LINUX_FILE_SEPARATOR + hapFileName; File destFile = new File(destPath); if ("false".equals(utility.getForceRewrite()) && destFile.exists()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode target file already exists."); + String errMsg = "--out-path file already existed, but --force is 'false'."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -1133,7 +1187,8 @@ public class CompressVerify { jsonData.append((char) ch); } } catch (IOException e) { - LOG.error("CompressVerify::CheckJsonIsValid failed: " + e.getMessage()); + String errMsg = "Check json file is valid exist IOException: "; + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg + e.getMessage())); return false; } JSONValidator validator = JSONValidator.from(jsonData.toString()); @@ -1237,7 +1292,8 @@ public class CompressVerify { try { Optional optional = FileUtils.getFileContent(utility.getJsonPath()); if(optional.isPresent()) { - return ModuleJsonUtil.parseModuleType(optional.get()).equals(BUNDLE_TYPE_SHARE) && !ModuleJsonUtil.parseAbilityNames(optional.get()).isEmpty(); + return ModuleJsonUtil.parseModuleType(optional.get()).equals(BUNDLE_TYPE_SHARE) && + !ModuleJsonUtil.parseAbilityNames(optional.get()).isEmpty(); } else { String errMsg = "Parse --json-path content failed."; LOG.error(PackingToolErrMsg.HSP_HAS_ABILITIES_FAILED.toString(errMsg)); diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index e4a74a8f87fb0d7863856fc78ea14e4a2213cb56..dddc89eb4124b6df8bbed6a8cd75641c119d3969 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -525,7 +525,7 @@ public class Compressor { throw new BundleException("Verify has generate build hash failed."); } catch (JSONException | IOException e) { LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString( - "Verify has generate build hash exist Exception(JSONException | IOException): " + e.getMessage())); + "Verify has generate build hash exist Exception (JSONException | IOException): " + e.getMessage())); throw new BundleException("Verify has generate build hash failed."); } finally { FileUtils.closeStream(json); @@ -576,7 +576,7 @@ public class Compressor { throw new BundleException("Compressor::setGenerateBuildHash failed."); } catch (NullPointerException | IOException | JSONException e) { LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString( - "json data err, exist Exception(NullPointerException | IOException | JSONException): " + e.getMessage())); + "json data err, exist Exception (NullPointerException | IOException | JSONException): " + e.getMessage())); throw new BundleException("Set generate build hash failed, json data err."); } finally { FileUtils.closeStream(json); @@ -661,7 +661,8 @@ public class Compressor { } while (numRead != -1); return complete.digest(); } catch (IOException | NoSuchAlgorithmException e) { - LOG.error("Compressor::checkSum failed, IOException or NoSuchAlgorithmException: " + e.getMessage()); + LOG.error(PackingToolErrMsg.CHECK_SUM_FAILED.toString("Check sum exist Exception (IOException | " + + "NoSuchAlgorithmException): " + e.getMessage())); throw new BundleException("Compressor::checkSum failed."); } } @@ -1315,15 +1316,14 @@ public class Compressor { } // check hap is valid if (!checkHapIsValid(fileList, utility.getSharedApp())) { - String msg = "Compressor::checkHapIsValid verify failed, check version, " + - "apiVersion, moduleName, packageName."; - LOG.error(msg); - throw new BundleException(msg); + throw new BundleException("Compress file verify hap failed, check version, " + + "apiVersion, moduleName, packageName."); } // packApp packFastApp(utility, fileList); } catch (IOException ex) { - LOG.error("Compressor::compressAppMode compress failed: " + ex.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Compress fast app mode exist IOException: " + + ex.getMessage())); throw new BundleException("Compressor::compressAppMode compress failed."); } finally { if (tmpDir != null) { @@ -1414,8 +1414,9 @@ public class Compressor { //pack encrypt.json file packEncryptJsonFile(utility); } catch (BundleException | IOException exception) { - String errMsg = "Compressor::compressAppModeForMultiProject file failed: " + exception.getMessage(); - LOG.error(errMsg); + String errMsg = "Compress app mode for multi project file exist Exception (BundleException | IOException): " + + exception.getMessage(); + LOG.error(PackingToolErrMsg.COMPRESS_APP_MODE_FORMULTI_PROJECT_FAILED.toString(errMsg)); throw new BundleException(errMsg); } finally { deleteFile(tempPath); @@ -1436,7 +1437,7 @@ public class Compressor { File outParentFile = destFile.getParentFile(); if ((outParentFile != null) && (!outParentFile.exists())) { if (!outParentFile.mkdirs()) { - LOG.error("Compressor::hapAddition create out file parent directory failed."); + LOG.error(PackingToolErrMsg.HAP_ADDITION_FAILED.toString("Create out file parent directory failed.")); } } FileOutputStream fileOut = null; @@ -1453,7 +1454,8 @@ public class Compressor { compressHapAddition(utility, hapAdditionPath); } catch (BundleException | IOException exception) { - LOG.error("Compressor::HapAddition hapFile not found exception" + exception.getMessage()); + LOG.error(PackingToolErrMsg.HAP_ADDITION_FAILED.toString("Hap addition exist Exception" + + "(BundleException | IOException): " + exception.getMessage())); copyFileSafely(backName, hapPathOri); } finally { closeZipOutputStream(); @@ -1481,7 +1483,8 @@ public class Compressor { File destFile = new File(dest); FileUtils.copyFile(sourceFile, destFile); } catch (IOException | BundleException e) { - LOG.error("copyFileSafely failed: " + e.getMessage()); + LOG.error(PackingToolErrMsg.COPY_FILE_SAFELY_FAILED.toString("Copy file safely exist Exception" + + "(IOException | BundleException): " + e.getMessage())); } } @@ -1506,10 +1509,12 @@ public class Compressor { fileWriter.write(jsonString); fileWriter.flush(); } catch (IOException exception) { - LOG.error("writeJsonFile failed, " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Write json File exist IOException: " + + exception.getMessage())); throw new BundleException(exception.getMessage()); } catch (JSONException e) { - LOG.error("json file is invalid: " + e.getMessage()); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("Json file is exist JSONException: " + + e.getMessage())); throw new BundleException(e.getMessage()); } } @@ -1575,14 +1580,16 @@ public class Compressor { File targetParent = new File(targetParentPath); if (!targetParent.exists()) { if (!targetParent.mkdirs()) { - LOG.error("Compressor::compressHapAddition create target file parent directory failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HAP_ADDITION_FAILED.toString( + "Create target file parent directory failed.")); } } String targetPath = targetParentPath + LINUX_FILE_SEPARATOR + ADDITION_JSON; writeJsonFile(data, targetPath); } catch (IOException | JSONException | BundleException e) { - String errMsg = "Compressor::compressHapAddition generate addition.json file failed, " + e.getMessage(); - LOG.error(errMsg); + String errMsg = "Generate addition.json file exist Exception" + + "(IOException | JSONException | BundleException): " + e.getMessage(); + LOG.error(PackingToolErrMsg.COMPRESS_HAP_ADDITION_FAILED.toString(errMsg)); throw new BundleException(errMsg); } @@ -1590,8 +1597,8 @@ public class Compressor { try { setUtilityParameter(hapAdditionPath, utility); } catch (IOException e) { - String errMsg = "Compressor::compressHapAddition setUtilityParameter failed."; - LOG.error(errMsg); + String errMsg = "Set utility parameter exist IOException: " + e.getMessage(); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } if (utility.getHapPath().endsWith(HAP_SUFFIX)) { @@ -1599,8 +1606,9 @@ public class Compressor { } else if (utility.getHapPath().endsWith(HSP_SUFFIX)) { compressHsp(utility); } else { - String errMsg = "Compressor::compressHapAddition compressFile failed."; - LOG.error(errMsg); + String errMsg = "Compression add failed because file (" + utility.getHapPath() + + ") is an unsupported file type."; + LOG.error(PackingToolErrMsg.COMPRESS_HAP_ADDITION_FAILED.toString(errMsg)); throw new BundleException(errMsg); } } @@ -1626,8 +1634,8 @@ public class Compressor { finalAppPackInfo = selectHapInApp(appPath, seletedHaps, tempDir, finalAppPackInfo); } } catch (BundleException | IOException e) { - String errMsg = "Compressor:disposeApp disposeApp failed."; - LOG.error(errMsg); + String errMsg = "Dispose app exist Exception (BundleException | IOException): " + e.getMessage(); + LOG.error(PackingToolErrMsg.DISPOSE_APP_FAILED.toString(errMsg)); throw new BundleException(errMsg); } return finalAppPackInfo; @@ -1648,8 +1656,8 @@ public class Compressor { // rebuild pack.info String packInfoStr = FileUtils.getJsonInZips(new File(appPath), PACKINFO_NAME); if (packInfoStr.isEmpty()) { - String errorMsg = "Compressor:selectHapInApp failed, app has no pack.info."; - LOG.error(errorMsg); + String errorMsg = "Select hap from app find that app does not contain pack.info."; + LOG.error(PackingToolErrMsg.NO_PACK_INFO.toString(errorMsg)); throw new BundleException(errorMsg); } if (finalAppPackInfo.isEmpty()) { @@ -1689,7 +1697,8 @@ public class Compressor { } // copy duplicated hap to duplicated dir and get moduleName of duplicated hap if (selectedHaps.contains(zipEntry.getName())) { - LOG.error("Compressor::copyHapFromApp file duplicated, file is " + zipEntry.getName() + "."); + LOG.error(PackingToolErrMsg.COMPRESS_FILE_DUPLICATE.toString("Hap or hsp with duplicate " + + "file names. file is " + zipEntry.getName() + ".")); throw new BundleException("Compressor::copyHapFromApp file duplicated, file is " + zipEntry.getName() + "."); } else { @@ -1709,8 +1718,8 @@ public class Compressor { inputStream.close(); } } catch (IOException e) { - String errMsg = "Compressor:copyHapFromApp app path not found."; - LOG.error(errMsg); + String errMsg = "Copy hap and hsp from app exist IOException: " + e.getMessage(); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } finally { Utility.closeStream(zipInput); @@ -1756,7 +1765,8 @@ public class Compressor { } for (String hapPath : utility.getFormattedHapList()) { if (seletedHaps.contains(new File(hapPath).getName())) { - LOG.error("Compressor::disposeHap file duplicated, file is " + new File(hapPath).getName() + "."); + LOG.error(PackingToolErrMsg.COMPRESS_FILE_DUPLICATE.toString("Hap with duplicate file names, file is " + + new File(hapPath).getName() + ".")); throw new BundleException("Compressor::disposeHap file duplicated, file is " + new File(hapPath).getName() + "."); } @@ -1767,8 +1777,8 @@ public class Compressor { String packInfo = FileUtils.getJsonInZips(hapFile, PACKINFO_NAME); if (packInfo.isEmpty()) { - String errMsg = "Compressor::disposeHap failed, hap has no pack.info."; - LOG.error(errMsg); + String errMsg = "Hap does not contain a valid pack.info."; + LOG.error(PackingToolErrMsg.NO_PACK_INFO.toString(errMsg)); throw new BundleException(errMsg); } if (finalPackInfoStr.isEmpty()) { @@ -1793,8 +1803,8 @@ public class Compressor { fwriter = new FileWriter(filePath); fwriter.write(packInfoStr); } catch (IOException e) { - String errMsg = "Compressor:writePackInfo failed."; - LOG.error(errMsg); + String errMsg = "Write pack info exist IOException: " + e.getMessage(); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } finally { if (fwriter != null) { @@ -1894,21 +1904,22 @@ public class Compressor { String fName = fileName.trim(); String[] temp = fName.replace("\\", "/").split("/"); if (temp.length < 4) { - LOG.error("Compressor::compressPackResMode the hap file path is invalid, length: " - + temp.length + "."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE_FAILED.toString("The hap file path is " + + "invalid, length is " + temp.length + ", expected at least 4.")); continue; } String fileLanguageCountryName = temp[temp.length - 3]; if (!isThirdLevelDirectoryNameValid(fileLanguageCountryName)) { - LOG.error("Compressor::compressProcess compress failed third level directory name: " - + fileLanguageCountryName + " is invalid, please check it with reference to this example: " - + "zh_Hani_CN-vertical-car-mdpi-dark or zh_Hani_CN-vertical-car-mdpi."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE_FAILED.toString("Third level " + + "directory name: " + fileLanguageCountryName + " is invalid, please check it with " + + "reference to this example: zh_Hani_CN-vertical-car-mdpi-dark or " + + "zh_Hani_CN-vertical-car-mdpi.")); throw new BundleException("Compress failed third level directory name Error."); } String filePicturingName = temp[temp.length - 1]; if (!isPicturing(filePicturingName, utility)) { - LOG.error("Compressor::compressProcess Compress pack.res failed, Invalid resource file" + - " name: " + filePicturingName + ", correct format example is formName-2x2.png."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE_FAILED.toString("Invalid resource file" + + " name: " + filePicturingName + ", correct format example is formName-2x2.png.")); throw new BundleException("Compress pack.res failed, Invalid resource file name: " + filePicturingName + ", correct format example is formName-2x2.png."); } @@ -1918,7 +1929,7 @@ public class Compressor { snapshotNameList.add(fullSnapshotName); } else { - LOG.error("Compressor::compressProcess compress failed No image in PNG format is found."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE_FAILED.toString("No PNG format image found.")); throw new BundleException("Compress pack.res failed, compress failed No image in" + " PNG format is found."); } @@ -1926,8 +1937,9 @@ public class Compressor { for (String formName : formNamesList) { if (!snapshotNameList.contains(formName)) { - LOG.error("Compressor::compressProcess compress failed entryCard " + formName - + " has no related snapshot " + snapshotNameList.toString() + "."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE_FAILED.toString("EntryCard has no related " + + "snapshot. " + formName + " has no related snapshot " + + snapshotNameList.toString() + ".")); throw new BundleException("Compress pack.res failed, compress failed entryCard has no related snapshot."); } } @@ -2014,7 +2026,8 @@ public class Compressor { private boolean checkLanguage(String language) { if (!Pattern.compile(REGEX_LANGUAGE).matcher(language).matches()) { - LOG.error("Compressor::compressProcess language " + language + " is not in ISO 639-1 list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(language + + " is not in ISO 639-1 list.")); return false; } return true; @@ -2022,7 +2035,8 @@ public class Compressor { private boolean checkScript(String script) { if (!Pattern.compile(REGEX_SCRIPT).matcher(script).matches()) { - LOG.error("Compressor::compressProcess script " + script + " is not in ISO 15924 list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(script + + " is not in ISO 15924 list.")); return false; } return true; @@ -2030,7 +2044,8 @@ public class Compressor { private boolean checkCountry(String country) { if (!Pattern.compile(REGEX_COUNTRY).matcher(country).matches()) { - LOG.error("Compressor::compressProcess country " + country + " is not in ISO 3166-1 list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(country + + " is not in ISO 3166-1 list.")); return false; } return true; @@ -2038,8 +2053,8 @@ public class Compressor { private boolean checkOrientation(String orientation) { if (!Pattern.compile(REGEX_ORIENTATION).matcher(orientation).matches()) { - LOG.error("Compressor::compressProcess orientation " + orientation + - " is not in {vertical, horizontal} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(orientation + + " is not in {vertical, horizontal} list.")); return false; } return true; @@ -2047,8 +2062,8 @@ public class Compressor { private boolean checkDeviceType(String deviceType) { if (!Pattern.compile(REGEX_DEVICE_TYPE).matcher(deviceType).matches()) { - LOG.error("Compressor::compressProcess deviceType " + deviceType + - " is not in {phone, tablet, car, tv, wearable, liteWearable, 2in1} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(deviceType + + " is not in {phone, tablet, car, tv, wearable, liteWearable, 2in1} list.")); return false; } return true; @@ -2056,8 +2071,8 @@ public class Compressor { private boolean checkScreenDensity(String screenDensity) { if (!Pattern.compile(REGEX_SCREEN_DENSITY).matcher(screenDensity).matches()) { - LOG.error("Compressor::compressProcess screenDensity " + screenDensity + - " is not in {sdpi, mdpi, ldpi, xldpi, xxldpi} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(screenDensity + + " is not in {sdpi, mdpi, ldpi, xldpi, xxldpi} list.")); return false; } return true; @@ -2065,8 +2080,8 @@ public class Compressor { private boolean checkColorMode(String colorMode) { if (!Pattern.compile(REGEX_COLOR_MODE).matcher(colorMode).matches()) { - LOG.error("Compressor::compressProcess colorMode " + colorMode + - " is not in {light, dark} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(colorMode + + " is not in {light, dark} list.")); return false; } return true; @@ -2077,8 +2092,8 @@ public class Compressor { Pattern.compile(REGEX_SHAPE).matcher(tmp).matches()) { return true; } - LOG.error("Compressor::compressProcess " + tmp + - " is neither in colorMode list {light, dark} nor in shape list {circle}."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(tmp + + " is neither in colorMode list {light, dark} nor in shape list {circle}.")); return false; } @@ -2086,7 +2101,7 @@ public class Compressor { if (Pattern.compile(REGEX_SHAPE).matcher(shape).matches()) { return true; } - LOG.error("Compressor::compressProcess shape" + shape + " is not in {circle} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(shape + " is not in {circle} list.")); return false; } @@ -2103,24 +2118,26 @@ public class Compressor { return isSpecifications; } if (!name.endsWith(PNG_SUFFIX) && !name.endsWith(UPPERCASE_PNG_SUFFIX)) { - LOG.error("isPicturing: the suffix is not .png or .PNG."); + LOG.error(PackingToolErrMsg.IS_PICTURING_FAILED.toString("The suffix is not .png or .PNG.")); return false; } int delimiterIndex = name.lastIndexOf("-"); if (delimiterIndex < 0) { - LOG.error("isPicturing: the entry card naming format is invalid and should be separated by '-'."); + LOG.error(PackingToolErrMsg.IS_PICTURING_FAILED.toString( + "The entry card naming format is invalid and should be separated by '-'.")); return false; } String formName = name.substring(0, delimiterIndex); if (!utility.getFormNameList().contains(formName)) { - LOG.error("isPicturing: the name is not same as formName, name: " + formName + " is not in " + - utility.getFormNameList().toString() + "."); + LOG.error(PackingToolErrMsg.IS_PICTURING_FAILED.toString( + "The name is not same as formName, name: " + formName + " is not in " + + utility.getFormNameList().toString() + ".")); return false; } String dimension = name.substring(delimiterIndex + 1, name.lastIndexOf(".")); if (!supportDimensionsList.contains(dimension)) { - LOG.error("isPicturing: the dimension: " + dimension + " is invalid, is not in the following list: " - + "{1X2, 2X2, 2X4, 4X4, 1X1, 6X4}."); + LOG.error(PackingToolErrMsg.IS_PICTURING_FAILED.toString(dimension + " is invalid, is not in the " + + "following list: {1X2, 2X2, 2X4, 4X4, 1X1, 6X4}.")); return false; } @@ -2130,12 +2147,14 @@ public class Compressor { private void getFileList(final String filePath) throws BundleException { File file = new File(filePath); if (!file.exists()) { - LOG.error("getFileList: file is not exists."); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("File does not exist. File path is " + + filePath + ".")); return; } File[] files = file.listFiles(); if (files == null) { - LOG.error("getFileList: no file in this file path."); + LOG.error(PackingToolErrMsg.GET_FILE_LIST_FAILED.toString("No files found in the specified path: " + + filePath + ".")); return; } for (File f : files) { @@ -2147,8 +2166,8 @@ public class Compressor { } String snapshotDirectoryName = f.getParentFile().getName(); if (!ENTRYCARD_SNAPSHOT_NAME.equals(snapshotDirectoryName)) { - LOG.error("The level-4 directory of EntryCard must be named as snapshot" + - ", but current is: " + snapshotDirectoryName + "."); + LOG.error(PackingToolErrMsg.GET_FILE_LIST_FAILED.toString("The level-4 directory of EntryCard " + + "must be named as snapshot, but current is: " + snapshotDirectoryName + ".")); throw new BundleException("The level-4 directory of EntryCard must be named as snapshot" + ", but current is: " + snapshotDirectoryName + "."); } @@ -2156,10 +2175,11 @@ public class Compressor { } else if (f.isDirectory()) { getFileList(f.getCanonicalPath()); } else { - LOG.error("It's not file or directory."); + LOG.error(PackingToolErrMsg.GET_FILE_LIST_FAILED.toString("It's not file or directory.")); } } catch (IOException msg) { - LOG.error("IOException error: " + msg.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Get file list exist IOException: " + + msg.getMessage())); return; } } @@ -2249,7 +2269,7 @@ public class Compressor { zipCreator.writeTo(zipOut); } catch (IOException | InterruptedException | ExecutionException e) { LOG.error(PackingToolErrMsg.COMPRESS_PARALLEL_EXCEPTION.toString( - "Parallel compress exist Exception(IOException | InterruptedException | ExecutionException): " + e.getMessage())); + "Parallel compress exist Exception (IOException | InterruptedException | ExecutionException): " + e.getMessage())); throw new BundleException("Parallel compress exception. " + e.getMessage()); } } @@ -2589,15 +2609,16 @@ public class Compressor { ModuleJsonUtil.parsePackInfoFormsName(jsonString, nameList, formNamesList); for (String formName : nameList) { if (formName.isEmpty()) { - LOG.error("Compressor::infoSpecialJsonFileProcess form name is empty."); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("Form name parsed from " + + "pack.info is empty.")); continue; } utility.addFormNameList(formName); } } catch (JSONException e) { - LOG.error("Compressor::infoSpecialJsonFileProcess json Path: " + jsonPath + - "json exception: " + e.getMessage()); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("Parse pack.info eixst JSONException: " + + e.getMessage())); } } @@ -2628,7 +2649,8 @@ public class Compressor { str = bufferedReader.readLine(); } } catch (IOException exception) { - LOG.error("Compressor::jsonSpecialProcess io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("pack.info special process exist IOException: " + + exception.getMessage())); throw new BundleException("Json special process failed."); } finally { Utility.closeStream(bufferedReader); @@ -2731,7 +2753,8 @@ public class Compressor { } } } catch (IOException exception) { - LOG.error("Compressor::parseModuleName io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Parse module name exist IOException: " + + exception.getMessage())); throw new BundleException("Parse module name failed."); } } @@ -2808,19 +2831,22 @@ public class Compressor { try { int endIndex = lineStr.lastIndexOf(SEMICOLON); if (endIndex <= 0) { - LOG.error("Compressor::getModuleNameFromString field the json is not standard."); + LOG.error(PackingToolErrMsg.GET_MODULE_NAME_FROM_STRING_FAILED.toString("Unable to find '\"' " + + "in the lineStr.")); throw new BundleException("Parse module name failed, module-name is invalid."); } int startIndex = lineStr.lastIndexOf(SEMICOLON, endIndex - 1) + 1; String moduleName = lineStr.substring(startIndex, endIndex); list.add(moduleName); if (moduleName == null || moduleName.isEmpty()) { - LOG.error("Compressor::getModuleNameFromString field module-name is empty."); + LOG.error(PackingToolErrMsg.GET_MODULE_NAME_FROM_STRING_FAILED.toString("moduleName or module-name " + + "is empty.")); throw new BundleException("Parse module name failed, module-name is empty."); } utility.setModuleName(moduleName); } catch (StringIndexOutOfBoundsException exception) { - LOG.error("Compressor::parseModuleName field module-name is fault: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.GET_MODULE_NAME_FROM_STRING_FAILED.toString("Get Module name from line string " + + "exist StringIndexOutOfBoundsException: " + exception.getMessage())); throw new BundleException("Parse module name failed, module-name is invalid."); } } @@ -3096,8 +3122,8 @@ public class Compressor { private void compressAPPQFMode(Utility utility) throws BundleException { List fileList = utility.getFormatedHQFList(); if (!checkHQFIsValid(fileList)) { - LOG.error("checkHQFIsValid failed when pack appqf file."); - throw new BundleException("checkHQFIsValid failed when pack appqf file."); + LOG.error(PackingToolErrMsg.COMPRESS_APPQF_FAILED.toString("Verify failed when compress appqf.")); + throw new BundleException("Verify failed when compress appqf."); } for (String hapPath : fileList) { pathToFile(utility, hapPath, NULL_DIR_NAME, false); @@ -3116,7 +3142,7 @@ public class Compressor { hqfVerifyInfos.add(ModuleJsonUtil.parseHQFInfo(file)); } if (!HQFVerify.checkHQFIsValid(hqfVerifyInfos)) { - LOG.error("input hqf is invalid."); + LOG.error(PackingToolErrMsg.CHECK_HQF_INVALID.toString("Input hqf is invalid.")); return false; } return true; @@ -3243,7 +3269,7 @@ public class Compressor { tempDir.toAbsolutePath() + LINUX_FILE_SEPARATOR + PACKINFO_NAME); if (moduleFile.exists() && configFile.exists()) { - LOG.error("versionNormalize failed, invalid hap structure."); + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_FAILED.toString("Invalid hap structure.")); throw new BundleException("versionNormalize failed, invalid hap structure."); } if (moduleFile.exists()) { @@ -3253,7 +3279,7 @@ public class Compressor { String configJsonPath = tempDir.resolve(CONFIG_JSON).toString(); util = parseAndModifyConfigJson(configJsonPath, utility); } else { - LOG.error("versionNormalize failed, invalid hap structure."); + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_FAILED.toString("Invalid hap structure.")); throw new BundleException("versionNormalize failed, invalid hap structure."); } if (packInfoFile.exists()) { @@ -3268,7 +3294,8 @@ public class Compressor { LINUX_FILE_SEPARATOR + Paths.get(hapPath).getFileName().toString(); compressDirToHap(tempDir, modifiedHapPath); } catch (IOException | BundleException e) { - LOG.error("versionNormalize failed " + e.getMessage()); + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_FAILED.toString( + "Version normalize exist Exception (IOException | BundleException): " + e.getMessage())); } finally { if (tempDir != null) { deleteDirectory(tempDir.toFile()); @@ -3284,33 +3311,38 @@ public class Compressor { try (FileInputStream jsonStream = new FileInputStream(jsonFilePath)) { JSONObject jsonObject = JSON.parseObject(jsonStream, JSONObject.class); if (!jsonObject.containsKey(APP)) { - LOG.error("parseAndModifyJson failed, json file not valid."); - throw new BundleException("parseAndModifyJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The module.json file " + + "does not contain 'app'. ")); + throw new BundleException("The module.json file does not contain 'app'. "); } JSONObject appObject = jsonObject.getJSONObject(APP); if (!appObject.containsKey(VERSION_CODE)) { - LOG.error("parseAndModifyJson failed, json file not valid."); - throw new BundleException("parseAndModifyJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The module.json file " + + "does not contain 'versionCode'. ")); + throw new BundleException("The module.json file does not contain 'versionCode'. "); } if (!appObject.containsKey(VERSION_NAME)) { - LOG.error("parseAndModifyJson failed, json file not valid."); - throw new BundleException("parseAndModifyJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The module.json file " + + "does not contain 'versionName'. ")); + throw new BundleException("The module.json file does not contain 'versionName'. "); } util.setOriginVersionCode(appObject.getIntValue(VERSION_CODE)); util.setOriginVersionName(appObject.getString(VERSION_NAME)); JSONObject moduleObject = jsonObject.getJSONObject(MODULE); if (!moduleObject.containsKey(NAME)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); - throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The module.json file " + + "does not contain 'name'. ")); + throw new BundleException("The module.json file does not contain 'name'. "); } util.setModuleName(moduleObject.getString(NAME)); appObject.put(VERSION_CODE, utility.getVersionCode()); appObject.put(VERSION_NAME, utility.getVersionName()); writeJson(jsonFilePath, jsonObject); } catch (IOException e) { - LOG.error("parseAndModifyModuleJson failed, IOException." + e.getMessage()); - throw new BundleException("parseAndModifyModuleJson failed, IOException." + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Parse and modify module.json exist IOException: " + + e.getMessage())); + throw new BundleException("Parse and modify module.json exist IOException: " + e.getMessage()); } return util; } @@ -3355,7 +3387,8 @@ public class Compressor { new FileOutputStream(jsonFilePath), StandardCharsets.UTF_8)); bw.write(pretty); } catch (IOException exception) { - LOG.error("Compressor::writeJson failed for IOException " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Write json exist IOException: " + + exception.getMessage())); throw new BundleException("Compressor::writeJson failed for IOException"); } finally { if (bw != null) { @@ -3371,30 +3404,35 @@ public class Compressor { try (FileInputStream jsonStream = new FileInputStream(jsonFilePath)) { JSONObject jsonObject = JSON.parseObject(jsonStream, JSONObject.class); if (!jsonObject.containsKey(APP)) { - LOG.error("parseAndModifyJson failed, json file not valid."); - throw new BundleException("parseAndModifyJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The config.json file " + + "does not contain 'app'. ")); + throw new BundleException("The config.json file does not contain 'app'. "); } JSONObject appObject = jsonObject.getJSONObject(APP); if (!appObject.containsKey(VERSION)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); - throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The config.json file " + + "does not contain 'version'. ")); + throw new BundleException("The config.json file does not contain 'version'. "); } JSONObject versionObj = appObject.getJSONObject(VERSION); if (!versionObj.containsKey(CODE)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); - throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The config.json file " + + "does not contain 'code'. ")); + throw new BundleException("The config.json file does not contain 'code'. "); } util.setOriginVersionCode(versionObj.getIntValue(CODE)); if (!versionObj.containsKey(NAME)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); - throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The config.json file " + + "does not contain 'name'. ")); + throw new BundleException("The config.json file does not contain 'name'. "); } util.setOriginVersionName(versionObj.getString(NAME)); JSONObject moduleObject = jsonObject.getJSONObject(MODULE); if (!moduleObject.containsKey(NAME)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); - throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The config.json file " + + "does not contain 'name'. ")); + throw new BundleException("The config.json file does not contain 'name'. "); } util.setModuleName(moduleObject.getString(NAME)); @@ -3402,8 +3440,9 @@ public class Compressor { versionObj.put(NAME, utility.getVersionName()); writeJson(jsonFilePath, jsonObject); } catch (IOException e) { - LOG.error("parseAndModifyModuleJson IOException." + e.getMessage()); - throw new BundleException("parseAndModifyModuleJson IOException." + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Parse and modify config.json exist IOException: " + + e.getMessage())); + throw new BundleException("Parse and modify config.json exist IOException: " + e.getMessage()); } return util; } @@ -3494,7 +3533,8 @@ public class Compressor { try (FileWriter fileWriter = new FileWriter(outPath + LINUX_FILE_SEPARATOR + VERSION_RECORD)) { fileWriter.write(jsonString); } catch (IOException e) { - LOG.error("writeVersionRecord failed " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Write version record exist IOException: " + + e.getMessage())); } } @@ -3503,7 +3543,7 @@ public class Compressor { if (versionNormalizeUtil.getOriginVersionCode() > utility.getVersionCode()) { String errorMsg = "versionNormalize failed, module " + versionNormalizeUtil.getModuleName() + " version code less than input version code"; - LOG.error(errorMsg); + LOG.error(PackingToolErrMsg.VERIFY_MODULE_VERSION_FAILED.toString(errorMsg)); throw new BundleException(errorMsg); } else if (versionNormalizeUtil.getOriginVersionCode() == utility.getVersionCode()) { LOG.warning("versionNormalize warning: module " + @@ -3543,7 +3583,7 @@ public class Compressor { zipInputStream.closeEntry(); } } catch (IOException e) { - LOG.error("unpack hap failed IOException " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Unpack hap exist IOException: " + e.getMessage())); throw new BundleException("unpack hap failed IOException " + e.getMessage()); } } diff --git a/adapter/ohos/FileUtils.java b/adapter/ohos/FileUtils.java index a854c27c0f081c2a0f40d77ef2ca236788aea6e5..3d7417ef06e4b4b1eb8ff62c920f899c6575e87c 100644 --- a/adapter/ohos/FileUtils.java +++ b/adapter/ohos/FileUtils.java @@ -344,8 +344,8 @@ class FileUtils { */ public static void copyFile(File sourceFile, File destFile) throws IOException, BundleException { if (sourceFile == null || destFile == null) { - String errMsg = "CompressorFileUtil::copyFile input file is null."; - LOG.error(errMsg); + String errMsg = "Source file or destination file is null."; + LOG.error(PackingToolErrMsg.COPY_FILE_FAILED.toString(errMsg)); throw new BundleException(errMsg); } InputStream inputStream = null; @@ -372,8 +372,8 @@ class FileUtils { */ public static void makeDir(File dirFile) throws IOException, BundleException { if (dirFile == null) { - String errMsg = "CompressorFileUtil::makeDir input file is null."; - LOG.error(errMsg); + String errMsg = "Input file is null."; + LOG.error(PackingToolErrMsg.MAKE_DIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } dirFile.mkdirs(); @@ -414,7 +414,8 @@ class FileUtils { } jsonStr = new StringBuilder(jsonStr.toString().replaceAll("\r|\n|\t", "")); } catch (IOException exception) { - LOG.error("Compressor::checkModuleTypeInHaps io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "Get Json in zips exist IOException: " + exception.getMessage())); throw new BundleException("Compressor::checkModuleTypeInHaps failed."); } finally { Utility.closeStream(zipFile); @@ -447,7 +448,8 @@ class FileUtils { } } } catch (IOException e) { - LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Get profile json exist IOExpection: " + e.getMessage())); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "Get profile json exist IOException: " + e.getMessage())); throw new BundleException("Get profile json failed."); } return resourceMap; diff --git a/adapter/ohos/HQFVerify.java b/adapter/ohos/HQFVerify.java index a872ddfe423443aea7d6523d4eeebd776b25df74..610ea157d10a8bdaac55e0a56e31052df9424092 100644 --- a/adapter/ohos/HQFVerify.java +++ b/adapter/ohos/HQFVerify.java @@ -33,15 +33,15 @@ class HQFVerify { public static boolean checkHQFIsValid(List hqfVerifyInfos) { // check app fields if (hqfVerifyInfos.isEmpty()) { - LOG.error("input hqf file is empty."); + LOG.error(PackingToolErrMsg.CHECK_HQF_INVALID.toString("Input hqf file is empty.")); return false; } if (!checkAppFields(hqfVerifyInfos)) { - LOG.error("input hqf file has different fields in app."); + LOG.error(PackingToolErrMsg.CHECK_HQF_INVALID.toString("Input hqf file has different fields in app.")); return false; } if (!checkModuleIsValid(hqfVerifyInfos)) { - LOG.error("input hqf file moduleName is invalid."); + LOG.error(PackingToolErrMsg.CHECK_HQF_INVALID.toString("Input hqf file moduleName is invalid.")); return false; } return true; @@ -61,23 +61,28 @@ class HQFVerify { String patchVersionName = hqfVerifyInfos.get(0).getPatchVersionName(); for (HQFInfo hqfVerifyInfo : hqfVerifyInfos) { if (bundleName == null || !bundleName.equals(hqfVerifyInfo.getBundleName())) { - LOG.error("input hqf file has different bundleName."); + String errMsg = "Input hqf file has different bundleName."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_FAILED.toString(errMsg)); return false; } if (versionCode != hqfVerifyInfo.getVersionCode()) { - LOG.error("input hqf file has different versionCode."); + String errMsg = "Input hqf file has different versionCode."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_FAILED.toString(errMsg)); return false; } if (versionName == null || !versionName.equals(hqfVerifyInfo.getVersionName())) { - LOG.error("input hqf file has different versionName."); + String errMsg = "Input hqf file has different versionName."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_FAILED.toString(errMsg)); return false; } if (patchVersionCode != hqfVerifyInfo.getPatchVersionCode()) { - LOG.error("input hqf file has different patchVersionCode."); + String errMsg = "Input hqf file has different patchVersionCode."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_FAILED.toString(errMsg)); return false; } if (patchVersionName == null || !patchVersionName.equals(hqfVerifyInfo.getPatchVersionName())) { - LOG.error("input hqf file has different patchVersionName."); + String errMsg = "Input hqf file has different patchVersionName."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_FAILED.toString(errMsg)); return false; } } @@ -94,7 +99,8 @@ class HQFVerify { for (int i = 0; i < hqfVerifyInfos.size(); ++i) { for (int j = i + 1; j < hqfVerifyInfos.size(); ++j) { if (checkModuleIsDuplicated(hqfVerifyInfos.get(i), hqfVerifyInfos.get(j))) { - LOG.error("input hqf file moduleName duplicated."); + String errMsg = "Input hqf file moduleName duplicated."; + LOG.error(PackingToolErrMsg.CHECK_MODULE_INVALID.toString(errMsg)); return false; } } diff --git a/adapter/ohos/ModuleJsonUtil.java b/adapter/ohos/ModuleJsonUtil.java index 569022e09241b39c6ea7d947f433e809ea57544d..aaf0dfb42de93cbae712324b3677277bc5a3ce9e 100644 --- a/adapter/ohos/ModuleJsonUtil.java +++ b/adapter/ohos/ModuleJsonUtil.java @@ -392,13 +392,16 @@ class ModuleJsonUtil { finalPackObj = JSON.parseObject(finalPackInfo); JSONObject srcPackObj = JSON.parseObject(srcPackInfo); if (!verifyPackInfo(finalPackObj, srcPackObj)) { - LOG.error("ModuleJsonUtil:mergeTwoPackInfo verify pack.info failed."); - throw new BundleException("ModuleJsonUtil:mergeTwoPackInfo verify pack.info failed."); + String errMsg = "Verify pack.info failed."; + LOG.error(PackingToolErrMsg.MERGE_TWO_PACKINFO_FAILED.toString(errMsg)); + throw new BundleException(errMsg); } desPackInfo = mergePackInfoObj(finalPackObj, srcPackObj); } catch (BundleException | JSONException e) { - LOG.error("ModuleJsonUtil:mergeTwoPackInfo merge pack.info failed: " + e.getMessage()); - throw new BundleException("ModuleJsonUtil:mergeTwoPackInfo merge pack.info failed."); + String errMsg = "Merge two pack.info file into one pack.info exist " + + "exception(BundleException | JSONException): "; + LOG.error(PackingToolErrMsg.MERGE_TWO_PACKINFO_FAILED.toString(errMsg + e.getMessage())); + throw new BundleException(errMsg + e.getMessage()); } return desPackInfo; } @@ -412,24 +415,28 @@ class ModuleJsonUtil { */ public static boolean verifyPackInfo(JSONObject finalPackObj, JSONObject srcPackObj) throws BundleException { if (finalPackObj == null || srcPackObj == null) { - LOG.error("ModuleJsonUtil:verifyPackInfo fail to read pack.info."); + String errMsg = "Input json Objects (final pack.info or src pack.info) are null."; + LOG.error(PackingToolErrMsg.VERIFY_PACKINFO_FAILED.toString(errMsg)); return false; } JSONObject finalSummaryObj = finalPackObj.getJSONObject(SUMMARY); JSONObject srcSummaryObj = srcPackObj.getJSONObject(SUMMARY); if (finalSummaryObj == null || srcSummaryObj == null) { - LOG.error("ModuleJsonUtil:verifyPackInfo pack.info do not contain summary."); + String errMsg = "pack.info does not contain summary."; + LOG.error(PackingToolErrMsg.VERIFY_PACKINFO_FAILED.toString(errMsg)); return false; } // check app info JSONObject finalAppObj = finalSummaryObj.getJSONObject(APP); JSONObject srcAppObj = srcSummaryObj.getJSONObject(APP); if (finalAppObj == null || srcAppObj == null) { - LOG.error("ModuleJsonUtil:verifyPackInfo pack.info do not contain app."); + String errMsg = "pack.info does not contain app."; + LOG.error(PackingToolErrMsg.VERIFY_PACKINFO_FAILED.toString(errMsg)); return false; } if (!verifyAppInPackInfo(finalAppObj, srcAppObj)) { - LOG.error("ModuleJsonUtil:verifyPackInfo verify app failed."); + String errMsg = "Verify app field in pack.info failed."; + LOG.error(PackingToolErrMsg.VERIFY_PACKINFO_FAILED.toString(errMsg)); return false; } @@ -445,32 +452,37 @@ class ModuleJsonUtil { */ public static boolean verifyAppInPackInfo(JSONObject finalAppObj, JSONObject srcAppObj) { if (finalAppObj == null || srcAppObj == null) { - LOG.error("ModuleJsonUtil:verifyAppInPackInfo input null json object."); + String errMsg = "Input JSON objects (finalAppObj or srcAppObj) are null."; + LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } // check bundleName String finalBundleName = finalAppObj.getString(BUNDLE_NAME); String srcBundleName = srcAppObj.getString(BUNDLE_NAME); if (!finalBundleName.equals(srcBundleName)) { - LOG.error("ModuleJsonUtil:verifyAppInPackInfo bundleName is different."); + String errMsg = "BundleName is different between final bundleName and src bundleName."; + LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } // check bundleType if (!checkBundleTypeInPackInfo(finalAppObj, srcAppObj)) { - LOG.error("ModuleJsonUtil:verifyAppInPackInfo bundleType is different."); + String errMsg = "BundleType is different between final app object and src app object."; + LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } // check version JSONObject finalVersionObj = finalAppObj.getJSONObject(VERSION); JSONObject srcVersionObj = srcAppObj.getJSONObject(VERSION); if (finalVersionObj == null || srcVersionObj == null) { - LOG.error("ModuleJsonUtil:verifyAppInPackInfo version object is empty."); + String errMsg = "Final version object or src version object is empty."; + LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } int finalVersionCode = finalVersionObj.getIntValue(CODE); int srcVersionCode = srcVersionObj.getIntValue(CODE); if (finalVersionCode != srcVersionCode) { - LOG.error("ModuleJsonUtil:verifyAppInPackInfo versionCode is different."); + String errMsg = "Code is different between final version object and src version object."; + LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } return true; @@ -485,7 +497,8 @@ class ModuleJsonUtil { */ public static boolean checkBundleTypeInPackInfo(JSONObject finalAppObj, JSONObject srcAppObj) { if (finalAppObj.isEmpty() || srcAppObj.isEmpty()) { - LOG.error("ModuleJsonUtil:checkBundleTypeInPackInfo pack.info has empty module."); + String errMsg = "Input JSON objects (finalAppObj or srcAppObj) are null."; + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_PACKINFO_INVALID.toString(errMsg)); return false; } String finalBundleType = "app"; @@ -497,7 +510,8 @@ class ModuleJsonUtil { srcBundleType = getJsonString(srcAppObj, BUNDLE_TYPE); } if (!finalBundleType.equals(srcBundleType)) { - LOG.error("bundleType in pack.info is not same."); + String errMsg = "BundleType is different between final bundleType and src bundleType."; + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_PACKINFO_INVALID.toString(errMsg)); return false; } return true; @@ -553,13 +567,15 @@ class ModuleJsonUtil { throws BundleException { JSONObject jsonObject = JSONObject.parseObject(jsonString); if (jsonObject == null || !jsonObject.containsKey(SUMMARY)) { - LOG.error("ModuleJsonUtil::parsePackInfoFormsName error: summary is null."); + String errMsg = "json object does not contain summary."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_NAME_FAILED.toString(errMsg)); throw new BundleException("Parse pack info forms name failed, summary is null."); } JSONObject summaryJson = jsonObject.getJSONObject(SUMMARY); if (summaryJson == null || !summaryJson.containsKey("modules")) { - LOG.error("ModuleJsonUtil::parsePackInfoFormsName error: summary.modules is null."); + String errMsg = "summary object does not contain modules."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_NAME_FAILED.toString(errMsg)); return; } @@ -567,13 +583,15 @@ class ModuleJsonUtil { for (int i = 0; i < moduleJsonList.size(); i++) { JSONObject moduleJson = moduleJsonList.getJSONObject(i); if (moduleJson == null || !moduleJson.containsKey(DISTRO)) { - LOG.error("ModuleJsonUtil::parsePackInfoFormsName error: summary.modules.distro is null."); + String errMsg = "modules object does not contain distro."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_NAME_FAILED.toString(errMsg)); continue; } JSONObject distroObj = moduleJson.getJSONObject(DISTRO); if (distroObj == null || !distroObj.containsKey(MODULE_NAME)) { - LOG.error("ModuleJsonUtil::parsePackInfoFormsName error: summary.modules.distro.moduleName is null."); + String errMsg = "distro object does not contain moduleName."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_NAME_FAILED.toString(errMsg)); continue; } @@ -658,23 +676,23 @@ class ModuleJsonUtil { */ public static String mergePackInfoObj(JSONObject finalPackinfoObj, JSONObject srcPackinfoObj) throws BundleException { if (finalPackinfoObj == null || srcPackinfoObj == null) { - String errMsg = "ModuleJsonUtil:mergePackInfoObj input an invalid json object."; - LOG.error(errMsg); + String errMsg = "Input JSON objects (finalPackinfoObj or srcPackinfoObj) are null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_FAILED.toString(errMsg)); throw new BundleException(errMsg); } JSONObject finalSummaryObj = finalPackinfoObj.getJSONObject(SUMMARY); JSONObject srcSummaryObj = srcPackinfoObj.getJSONObject(SUMMARY); if (finalSummaryObj == null || srcSummaryObj == null) { - String errMsg = "ModuleJsonUtil:mergePackInfoObj input json file has empty summary."; - LOG.error(errMsg); + String errMsg = "Input JSON objects (finalSummaryObj or srcSummaryObj) are null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // merge modules JSONArray finalModuleObs = finalSummaryObj.getJSONArray(MODULES); JSONArray srcModuleObs = srcSummaryObj.getJSONArray(MODULES); if (finalModuleObs == null || srcModuleObs == null) { - String errMsg = "ModuleJsonUtil:mergePackInfoObj input json file has empty module."; - LOG.error(errMsg); + String errMsg = "Input JSON array (finalModuleObs or srcModuleObs) are null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_FAILED.toString(errMsg)); throw new BundleException(errMsg); } finalModuleObs.addAll(srcModuleObs); @@ -682,8 +700,8 @@ class ModuleJsonUtil { JSONArray finalPackageObs = finalPackinfoObj.getJSONArray(PACKAGES); JSONArray srcPackageObs = srcPackinfoObj.getJSONArray(PACKAGES); if (finalPackageObs == null || srcPackageObs == null) { - String errMsg = "ModuleJsonUtil:mergePackInfoObj input json file has empty packages."; - LOG.error(errMsg); + String errMsg = "Input JSON array (finalPackageObs or srcPackageObs) are null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_FAILED.toString(errMsg)); throw new BundleException(errMsg); } finalPackageObs.addAll(srcPackageObs); @@ -707,8 +725,8 @@ class ModuleJsonUtil { finalPackObj = JSON.parseObject(finalPackInfo); srcPackObj = JSON.parseObject(srcPackInfo); } catch (JSONException exception) { - String errMsg = "parse JSONObject failed: " + exception.getMessage(); - LOG.error(errMsg); + String errMsg = "Merge two pack.info exist JSONException: " + exception.getMessage(); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // verify app in pack.info @@ -717,8 +735,8 @@ class ModuleJsonUtil { JSONObject srcSummaryObj = srcPackObj.getJSONObject(SUMMARY); JSONObject srcAppObj = srcSummaryObj.getJSONObject(APP); if (!verifyAppInPackInfo(finalAppObj, srcAppObj)) { - String errMsg = "verify pack.info failed, different version, bundleType or bundleName."; - LOG.error(errMsg); + String errMsg = "Verify pack.info failed, different version, bundleType or bundleName."; + LOG.error(PackingToolErrMsg.MERGE_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } for (HashMap.Entry entry : packagePair.entrySet()) { @@ -740,22 +758,23 @@ class ModuleJsonUtil { public static void mergeTwoPackInfoObjByPackagePair(JSONObject finalPackObj, JSONObject srcPackObj, String packageName, String moduleName) throws BundleException { if (finalPackObj == null || srcPackObj == null) { - String errMsg = "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair failed: pack.info is not json object."; - LOG.error(errMsg); + String errMsg = "Input JSON objects (finalPackObj or srcPackObj) are null."; + LOG.error(PackingToolErrMsg.MERGE_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // merge module JSONObject finalSummaryObj = finalPackObj.getJSONObject(SUMMARY); JSONObject srcSummaryObj = srcPackObj.getJSONObject(SUMMARY); if (finalSummaryObj == null || srcSummaryObj == null) { - String errMsg = "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair failed: pack.info do not contain summary."; - LOG.error(errMsg); + String errMsg = "Input JSON objects (finalSummaryObj or srcSummaryObj) are null."; + LOG.error(PackingToolErrMsg.MERGE_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } JSONArray finalModules = finalSummaryObj.getJSONArray(MODULES); JSONArray srcModules = srcSummaryObj.getJSONArray(MODULES); if (finalModules == null || srcModules == null) { - LOG.error("ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair input json file has empty module."); + String errMsg = "Input JSON Array (finalModules or srcModules) are null."; + LOG.error(PackingToolErrMsg.MERGE_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException("ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair input json file has empty module."); } @@ -770,18 +789,16 @@ class ModuleJsonUtil { } } if (!findModule) { - String errMsg = "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair" + - " input json do not contain " + moduleName + "."; - LOG.error(errMsg); + String errMsg = "Input json does not contain " + moduleName + "."; + LOG.error(PackingToolErrMsg.MERGE_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // merge package JSONArray finalPackages = finalPackObj.getJSONArray(PACKAGES); JSONArray srcPackages = srcPackObj.getJSONArray(PACKAGES); if (finalPackages == null || srcPackages == null) { - String errMsg = - "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair failed: pack.info do not contain packages."; - LOG.error(errMsg); + String errMsg = "Input JSON Array (finalPackages or srcPackages) are null."; + LOG.error(PackingToolErrMsg.MERGE_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } boolean findPackage = false; @@ -794,9 +811,8 @@ class ModuleJsonUtil { } } if (!findPackage) { - String errMsg = "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair input json do not contain " - + packageName + "."; - LOG.error(errMsg); + String errMsg = "Input json does not contain " + packageName + "."; + LOG.error(PackingToolErrMsg.MERGE_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } } @@ -1344,7 +1360,8 @@ class ModuleJsonUtil { return APP; } else if (bundleType.equals(ATOMIC_SERVICE)) { if (!installationFree) { - String errMsg = "'installationFree' must be true in module '" + moduleName + "' when 'bundleType' is atomicService."; + String errMsg = "'installationFree' must be true in module '" + moduleName + + "' when 'bundleType' is atomicService."; String solution = "Set 'installationFree' to true in the module.json when 'bundleType'" + "is atomicService."; LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); @@ -2070,20 +2087,20 @@ class ModuleJsonUtil { String name = formObj.getString(NAME); formNameList.add(name); if (!formObj.containsKey(DEFAULTDIMENSION)) { - LOG.error("ModuleJsonUtil::parsePackInfoForms exception: " + - "summary.modules.extensionAbilities.forms.defaultDimension is null."); + String errMsg = "formObj object does not contain defaultDimension."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_FAILED.toString(errMsg)); throw new BundleException("Parse pack info defaultDimension failed, defaultDimension is null."); } String defaultDimension = formObj.getString(DEFAULTDIMENSION); if (getCount(defaultDimension, '*') != 1) { - LOG.error("ModuleJsonUtil::parsePackInfoForms exception: " + - "summary.modules.extensionAbilities.forms.defaultDimension is not only 1."); + String errMsg = "summary.modules.extensionAbilities.forms.defaultDimension is not only 1."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_FAILED.toString(errMsg)); throw new BundleException("Parse pack info defaultDimension failed, defaultDimension is not only 1."); } if (!formObj.containsKey(SUPPORTDIMENSIONS)) { - LOG.error("ModuleJsonUtil::parsePackInfoForms exception: " + - "summary.modules.extensionAbilities.forms.supportDimensions is null."); + String errMsg = "formObj object does not contain supportDimensions."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_FAILED.toString(errMsg)); throw new BundleException("Parse pack info supportDimensions failed, supportDimensions is null."); } diff --git a/adapter/ohos/PackageNormalize.java b/adapter/ohos/PackageNormalize.java index 5bca1f855e440f5b9d091d8bfbd919dd67c73687..31a7e3bfa5cd3a99f88f60fd5b42d91dcceac5ad 100644 --- a/adapter/ohos/PackageNormalize.java +++ b/adapter/ohos/PackageNormalize.java @@ -70,10 +70,12 @@ public class PackageNormalize { try { normalize(Paths.get(hspPath), outPath, utility.getBundleName(), utility.getVersionCode()); } catch (BundleException ex) { - LOG.error("PackageNormalize::normalize BundleException: " + ex.getMessage()); + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_FAILED.toString( + "Package normalize exist BundleException:" + ex.getMessage())); return false; } catch (IOException ex) { - LOG.error("PackageNormalize::normalize IOException: " + ex.getMessage()); + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_FAILED.toString( + "Package normalize exist IOException:" + ex.getMessage())); return false; } } @@ -135,11 +137,13 @@ public class PackageNormalize { try (FileInputStream input = new FileInputStream(moduleJson.toFile())) { JSONObject jsonObject = JSON.parseObject(input, JSONObject.class); if (jsonObject == null) { - LOG.error("updateModuleJson failed, parse json is null."); + LOG.error(PackingToolErrMsg.UPDATE_MODULE_JSON_FAILED.toString( + "Failed to parse module.json: invalid JSON format.")); throw new BundleException("updateModuleJson failed, parse json is null."); } if (!jsonObject.containsKey(APP)) { - LOG.error("updateModuleJson failed, json format not invalid."); + LOG.error(PackingToolErrMsg.UPDATE_MODULE_JSON_FAILED.toString( + "The module.json file does not contain 'app'.")); throw new BundleException("updateModuleJson failed, json format invalid."); } JSONObject appObject = jsonObject.getJSONObject(APP); @@ -156,23 +160,27 @@ public class PackageNormalize { try (FileInputStream input = new FileInputStream(packInfo.toFile())) { JSONObject jsonObject = JSON.parseObject(input, JSONObject.class); if (jsonObject == null) { - LOG.error("updatePackInfo failed, json format invalid."); + LOG.error(PackingToolErrMsg.UPDATE_PACKINFO_FAILED.toString( + "Failed to parse pack.info: Invalid JSON format.")); throw new BundleException("updatePackInfo failed, json format invalid."); } JSONObject summaryObject = jsonObject.getJSONObject(SUMMARY); if (summaryObject == null) { - LOG.error("updatePackInfo failed, json format invalid."); + LOG.error(PackingToolErrMsg.UPDATE_PACKINFO_FAILED.toString( + "The pack.info file does not contain 'summary'.")); throw new BundleException("updatePackInfo failed, json format invalid."); } JSONObject appObject = summaryObject.getJSONObject(APP); if (appObject == null) { - LOG.error("updatePackInfo failed, json format invalid."); + LOG.error(PackingToolErrMsg.UPDATE_PACKINFO_FAILED.toString( + "The pack.info file does not contain 'app'.")); throw new BundleException("updatePackInfo failed, json format invalid."); } appObject.put(BUNDLE_NAME, bundleName); JSONObject versionObject = appObject.getJSONObject(VERSION); if (versionObject == null) { - LOG.error("updatePackInfo failed, json format invalid."); + LOG.error(PackingToolErrMsg.UPDATE_PACKINFO_FAILED.toString( + "The pack.info file does not contain 'version'.")); throw new BundleException("updatePackInfo failed, json format invalid."); } versionObject.put(CODE, versionCode); @@ -242,10 +250,12 @@ public class PackageNormalize { count = fileInputStream.read(buffer); } } catch (FileNotFoundException ignored) { - LOG.error("PackageNormalize::getCrcFromFile file not found exception: " + ignored.getMessage()); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString( + "Get Crc from file exist FileNotFoundExpection: " + ignored.getMessage())); throw new BundleException("Get Crc from file failed."); } catch (IOException exception) { - LOG.error("PackageNormalize::getCrcFromFile io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "Get Crc from file exist IOException: " + exception.getMessage())); throw new BundleException("Get Crc from file failed, io exception."); } return crc; diff --git a/adapter/ohos/PackageUtil.java b/adapter/ohos/PackageUtil.java index 0e5650028693ccd88d673f3aececa9cf1f628e21..2f5a6d5c7c18f46533785b807472833d1634fdf8 100644 --- a/adapter/ohos/PackageUtil.java +++ b/adapter/ohos/PackageUtil.java @@ -356,7 +356,8 @@ public class PackageUtil { try { return hspFile.getInputStream(zipEntry); } catch (IOException e) { - LOG.error("addArchiveEntry err: " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Repack hsp exist IOException: " + + e.getMessage())); return null; } }; @@ -364,8 +365,9 @@ public class PackageUtil { } zipCreator.writeTo(zipOut); } catch (InterruptedException | ExecutionException e) { - String errMsg = "repackHsp err: " + e.getMessage(); - LOG.error(errMsg); + String errMsg = "Repack hsp exist Exception (InterruptedException | ExecutionException): " + + e.getMessage(); + LOG.error(PackingToolErrMsg.INTERRUPTED_OR_EXECUTION_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } return outHsp; @@ -435,8 +437,8 @@ public class PackageUtil { // write to zip zipCreator.writeTo(zipOut); } catch (InterruptedException | ExecutionException e) { - String errMsg = "packDir err: " + e.getMessage(); - LOG.error(errMsg); + String errMsg = "Pack dir exist Exception (InterruptedException | ExecutionException): " + e.getMessage(); + LOG.error(PackingToolErrMsg.INTERRUPTED_OR_EXECUTION_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } return outHap; @@ -509,8 +511,8 @@ public class PackageUtil { addArchiveEntry(file, baseDir, zipCreator, compress); } } catch (IOException e) { - String errMsg = "pathToZip err: " + e.getMessage(); - LOG.error(errMsg); + String errMsg = "Path to zip entry exist IOException: " + e.getMessage(); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } } @@ -521,7 +523,7 @@ public class PackageUtil { if (file.isDirectory()) { File[] files = file.listFiles(); if (files == null) { - LOG.error("listFiles null: " + file.getName()); + LOG.error(PackingToolErrMsg.ADD_ARCHIVE_ENTRY_FAILED.toString("listFiles null: " + file.getName())); return; } if (files.length == 0) { @@ -549,7 +551,8 @@ public class PackageUtil { try { return getInputStream(entryName, file); } catch (IOException e) { - LOG.error("addArchiveEntry err: " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Add Archive Entry exist IOException: " + + e.getMessage())); return null; } }; @@ -646,8 +649,8 @@ public class PackageUtil { addArchiveEntry(file, baseDir, zipOut, compress); } } catch (IOException e) { - String errMsg = "pathToZip err: " + e.getMessage(); - LOG.error(errMsg); + String errMsg = "Path to zip entry exist IOException: " + e.getMessage(); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } } @@ -657,7 +660,7 @@ public class PackageUtil { if (file.isDirectory()) { File[] files = file.listFiles(); if (files == null) { - LOG.error("listFiles null: " + file.getName()); + LOG.error(PackingToolErrMsg.ADD_ARCHIVE_ENTRY_FAILED.toString("listFiles null: " + file.getName())); return; } if (files.length == 0) { @@ -705,13 +708,13 @@ public class PackageUtil { } for (String hapPath : hapPathList) { if (!bundleType.equals(getBundleTypeFromPath(Paths.get(hapPath)))) { - LOG.error("bundleType is not same"); + LOG.error(PackingToolErrMsg.CHECK_BUNDLE_TYPE_CONSISTENCY.toString("Hap bundle type is not same")); return false; } } for (String hspPath : hspPathList) { if (!bundleType.equals(getBundleTypeFromPath(Paths.get(hspPath)))) { - LOG.error("bundleType is not same"); + LOG.error(PackingToolErrMsg.CHECK_BUNDLE_TYPE_CONSISTENCY.toString("Hsp bundle type is not same")); return false; } } @@ -725,11 +728,11 @@ public class PackageUtil { for (String hapPath : hapPathList) { Path path = Paths.get(hapPath); if (!Files.exists(path.resolve(Constants.FILE_MODULE_JSON))) { - LOG.error("not found module.json in path: " + path); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found module.json in hap path: " + path)); return false; } if (!Files.exists(path.resolve(Constants.FILE_PACK_INFO))) { - LOG.error("not found pack.info in path: " + path); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found pack.info in hap path: " + path)); return false; } } @@ -737,11 +740,11 @@ public class PackageUtil { Path path = Paths.get(hspPath); if (Files.isDirectory(path)) { if (!Files.exists(path.resolve(Constants.FILE_MODULE_JSON))) { - LOG.error("not found module.json in path: " + path); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found module.json in hsp path: " + path)); return false; } if (!Files.exists(path.resolve(Constants.FILE_PACK_INFO))) { - LOG.error("not found pack.info in path: " + path); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found pack.info in hsp path: " + path)); return false; } } @@ -771,45 +774,46 @@ public class PackageUtil { if (!utility.getHapPath().isEmpty() && (!isFormatPathValid(utility.getHapPath(), utility.getFormattedHapPathList()) || !isHapPathValid(utility.getFormattedHapPathList()))) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode hap-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--hap-path is invalid.")); return false; } if (!utility.getHspPath().isEmpty() && (!isFormatPathValid(utility.getHspPath(), utility.getFormattedHspPathList()) || !isHspPathValid(utility.getFormattedHspPathList()))) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode hsp-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--hsp-path is invalid.")); return false; } if (utility.getHapPath().isEmpty() && utility.getHspPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode hap-path and hsp-path is empty."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--hap-path and --hsp-path is empty.")); return false; } if (!moduleJsonAndPackInfoExists(utility.getFormattedHapPathList(), utility.getFormattedHspPathList())) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode hap-path or hsp-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--hap-path or --hsp-path is invalid.")); return false; } if (!checkBundleTypeConsistency( utility.getFormattedHapPathList(), utility.getFormattedHspPathList(), utility)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode bundleType is inconsistent."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("Bundle type is inconsistent.")); return false; } if (!isPackInfoValid(Paths.get(utility.getPackInfoPath()), utility.getFormattedHapPathList(), utility.getFormattedHspPathList())) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode pack.info is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("pack.info is invalid.")); return false; } if (!utility.getEncryptPath().isEmpty() && !isFileValid(utility.getEncryptPath(), Constants.FILE_ENCRYPT_JSON)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode encrypt-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--encrypt-path is invalid.")); return false; } Path outPath = Paths.get(utility.getOutPath()); if (utility.getForceRewrite().equals(Constants.FALSE) && Files.exists(outPath)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode out file already existed."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--out-path file already existed, but " + + "--force is 'false'.")); return false; } if (!outPath.getFileName().toString().endsWith(Constants.APP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode out-path must end with .app."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--out-path must end with .app.")); return false; } return true; @@ -817,34 +821,34 @@ public class PackageUtil { private static boolean isVerifyValid(Utility utility) { if (utility.getPackInfoPath().isEmpty()) { - LOG.error("CompressVerify::isArgsValidInAppMode pack-info-path is empty."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--pack-info-path is empty.")); return false; } if (!isFileValid(utility.getPackInfoPath(), Constants.FILE_PACK_INFO)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode pack-info-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--pack-info-path is invalid.")); return false; } if (!utility.getSignaturePath().isEmpty() && !isFileValid(utility.getSignaturePath(), "")) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode signature-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--signature-path is invalid.")); return false; } if (!utility.getCertificatePath().isEmpty() && !isFileValid(utility.getCertificatePath(), "")) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode certificate-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--certificate-path is invalid.")); return false; } if (!utility.getPackResPath().isEmpty() && !isFileValid(utility.getPackResPath(), Constants.FILE_PACK_RES)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode pack-res-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--pack-res-path is invalid.")); return false; } if (!utility.getEntryCardPath().isEmpty() && !CompressVerify.compatibleProcess(utility, utility.getEntryCardPath(), utility.getformattedEntryCardPathList(), Constants.PNG_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode entrycard-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--entrycard-path is invalid.")); return false; } if (utility.getOutPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode out-path is empty."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--out-path is empty.")); return false; } return true; @@ -876,11 +880,12 @@ public class PackageUtil { if (Files.exists(realpath)) { formatPathSet.add(realpath.toString()); } else { - LOG.error("PackageUtil::formatPath not exists: " + realpath); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Format path not exists. Path: " + realpath)); return false; } } catch (IOException ex) { - LOG.error("PackageUtil::formatPath err: " + ex.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Format path exist IOException: " + + ex.getMessage())); return false; } } @@ -892,27 +897,29 @@ public class PackageUtil { List allPackages = getPackageNameFromPath(packInfo); Set allPackageSet = new HashSet<>(allPackages); if (allPackages.size() > allPackageSet.size()) { - LOG.error("package name is redundant in app pack.info: " + packInfo); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Package name is redundant in app pack.info: " + + packInfo)); return false; } if (allPackages.isEmpty()) { - LOG.error("app pack.info format err: " + packInfo); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("App pack.info format error: " + packInfo)); return false; } Set packages = new HashSet<>(); for (String hapPath : hapPathList) { List list = getPackageNameFromPath(Paths.get(hapPath)); if (list.size() != 1) { - LOG.error("module pack.info format err: " + hapPath); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info format error: " + hapPath)); return false; } String packageName = list.get(0); if (!allPackages.contains(packageName)) { - LOG.error("module pack.info name not exist in app pack.info name list: " + hapPath); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info name not exist in app " + + "pack.info name list: " + hapPath)); return false; } if (packages.contains(packageName)) { - LOG.error("package name is redundant in " + hapPath); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Package name is redundant in " + hapPath)); return false; } packages.add(packageName); @@ -920,22 +927,24 @@ public class PackageUtil { for (String hspPath : hspPathList) { List list = getPackageNameFromPath(Paths.get(hspPath)); if (list.size() != 1) { - LOG.error("module pack.info format err: " + hspPath); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info format err: " + hspPath)); return false; } String packageName = list.get(0); if (!allPackages.contains(packageName)) { - LOG.error("module pack.info name not exist in app pack.info name list: " + hspPath); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info name not exist in app " + + "pack.info name list: " + hspPath)); return false; } if (packages.contains(packageName)) { - LOG.error("package name is redundant in " + hspPath); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Package name is redundant in " + hspPath)); return false; } packages.add(packageName); } if (!allPackageSet.equals(packages)) { - LOG.error("package name not same between module and app pack.info."); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Package name not same between module " + + "and app pack.info.")); return false; } return true; diff --git a/adapter/ohos/PackingToolErrMsg.java b/adapter/ohos/PackingToolErrMsg.java index e8d48fef8237134cafafa2bf3c582218ebe2d423..9ac549aa362df660992584732993356bf1b44393 100644 --- a/adapter/ohos/PackingToolErrMsg.java +++ b/adapter/ohos/PackingToolErrMsg.java @@ -85,6 +85,76 @@ public class PackingToolErrMsg { .setCause("%s") .build(); + /** + * MULTI_APP_MODE_ARGS_INVALID + */ + public static final ErrorMsg MULTI_APP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("004") + .setDescription("Parse and check args invalid in multiApp mode.") + .setCause("%s") + .build(); + + /** + * RES_MODE_ARGS_INVALID + */ + public static final ErrorMsg RES_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("005") + .setDescription("Parse and check args invalid in res mode.") + .setCause("%s") + .build(); + + /** + * HQF_MODE_ARGS_INVALID + */ + public static final ErrorMsg HQF_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("006") + .setDescription("Parse and check args invalid in hqf mode.") + .setCause("%s") + .build(); + + /** + * APPQF_MODE_ARGS_INVALID + */ + public static final ErrorMsg APPQF_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("007") + .setDescription("Parse and check args invalid in appqf mode.") + .setCause("%s") + .build(); + + /** + * PACKAGE_NORMALIZE_MODE_ARGS_INVALID + */ + public static final ErrorMsg PACKAGE_NORMALIZE_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("008") + .setDescription("Parse and check args invalid in packageNormalize mode.") + .setCause("%s") + .build(); + + /** + * VERSION_NORMALIZE_MODE_ARGS_INVALID + */ + public static final ErrorMsg VERSION_NORMALIZE_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("009") + .setDescription("Parse and check args invalid in versionNormalize mode.") + .setCause("%s") + .build(); + + /** + * HAR_MODE_ARGS_INVALID + */ + public static final ErrorMsg HAR_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("010") + .setDescription("Parse and check args invalid in har mode.") + .setCause("%s") + .build(); + /** * COMMAND_MODE_INVALID */ @@ -165,6 +235,67 @@ public class PackingToolErrMsg { .setCause("%s") .build(); + /** + * DIRECTORY_INVALID + */ + public static final ErrorMsg DIRECTORY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("019") + .setDescription("directory is not exist.") + .setCause("%s") + .build(); + + /** + * HAP_ADDITION_MODE_ARGS_INVALID + */ + public static final ErrorMsg HAP_ADDITION_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("020") + .setDescription("Parse and check args invalid in hapAddition mode.") + .setCause("%s") + .build(); + + /** + * INPUT_PATH_INVALID + */ + public static final ErrorMsg INPUT_PATH_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("021") + .setDescription("input_path is invalid.") + .setCause("%s") + .build(); + + /** + * CHECK_BUNDLE_TYPE_CONSISTENCY + */ + public static final ErrorMsg CHECK_BUNDLE_TYPE_CONSISTENCY = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("022") + .setDescription("Checking bundle type consistency failed.") + .setCause("%s") + .build(); + + /** + * CHECK_BUNDLE_TYPE_CONSISTENCY + */ + public static final ErrorMsg FAST_APP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("023") + .setDescription("Parse and check args invalid in fast app mode.") + .setCause("%s") + .build(); + + /** + * PACK_INFO_INVALID + */ + public static final ErrorMsg PACK_INFO_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("024") + .setDescription("Pack info invalid.") + .setCause("%s") + .build(); + + // compress process error /** * COMPRESS_PROCESS_FAILED @@ -432,6 +563,278 @@ public class PackingToolErrMsg { .addSolution("Please check the related size check error message and reduce related module size.") .build(); + /** + * COMPRESS_APP_MODE_FORMULTI_PROJECT_FAILED + */ + public static final ErrorMsg COMPRESS_APP_MODE_FORMULTI_PROJECT_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("025") + .setDescription("Compress app mode for multi project failed.") + .setCause("%s") + .build(); + + /** + * HAP_ADDITION_FAILED + */ + public static final ErrorMsg HAP_ADDITION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("026") + .setDescription("Hap addition failed.") + .setCause("%s") + .build(); + + /** + * COMPRESS_HAP_ADDITION_FAILED + */ + public static final ErrorMsg COMPRESS_HAP_ADDITION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("027") + .setDescription("Compress hap addition failed.") + .setCause("%s") + .build(); + + /** + * DISPOSE_APP_FAILED + */ + public static final ErrorMsg DISPOSE_APP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("028") + .setDescription("Dispose app failed.") + .setCause("%s") + .build(); + + /** + * NO_PACK_INFO + */ + public static final ErrorMsg NO_PACK_INFO = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("029") + .setDescription("No pack.info available.") + .setCause("%s") + .build(); + + /** + * COMPRESS_PACK_RES_MODE_FAILED + */ + public static final ErrorMsg COMPRESS_PACK_RES_MODE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("030") + .setDescription("Compress pack res mode failed.") + .setCause("%s") + .build(); + + /** + * INVALID_THIRD_LEVEL_DIRECTORY_NAME + */ + public static final ErrorMsg INVALID_THIRD_LEVEL_DIRECTORY_NAME = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("031") + .setDescription("Invalid third level directory name.") + .setCause("%s") + .addSolution("Please check it with reference to this example: \n" + + "zh_Hani_CN-vertical-car-mdpi-dark or zh_Hani_CN-vertical-car-mdpi.") + .build(); + + /** + * IS_PICTURING_FAILED + */ + public static final ErrorMsg IS_PICTURING_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("032") + .setDescription("Is picturing failed.") + .setCause("%s") + .build(); + + /** + * GET_FILE_LIST_FAILED + */ + public static final ErrorMsg GET_FILE_LIST_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("033") + .setDescription("Get file list failed.") + .setCause("%s") + .build(); + + /** + * GET_MODULE_NAME_FROM_STRING_FAILED + */ + public static final ErrorMsg GET_MODULE_NAME_FROM_STRING_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("034") + .setDescription("Get module name from line string failed.") + .setCause("%s") + .build(); + + /** + * COMPRESS_APPQF_FAILED + */ + public static final ErrorMsg COMPRESS_APPQF_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("035") + .setDescription("Compress appqf Mode failed.") + .setCause("%s") + .build(); + + /** + * CHECK_HQF_INVALID + */ + public static final ErrorMsg CHECK_HQF_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("036") + .setDescription("HQF is valid.") + .setCause("%s") + .build(); + + /** + * VERSION_NORMALIZE_FAILED + */ + public static final ErrorMsg VERSION_NORMALIZE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("037") + .setDescription("Version normalize failed.") + .setCause("%s") + .build(); + + /** + * VERIFY_MODULE_VERSION_FAILED + */ + public static final ErrorMsg VERIFY_MODULE_VERSION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("038") + .setDescription("Verify module version failed.") + .setCause("%s") + .build(); + + /** + * CHECK_SUM_FAILED + */ + public static final ErrorMsg CHECK_SUM_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("039") + .setDescription("Check sum failed.") + .setCause("%s") + .build(); + + /** + * MERGE_TWO_PACKINFO_FAILED + */ + public static final ErrorMsg MERGE_TWO_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("040") + .setDescription("Merge two pack info failed.") + .setCause("%s") + .build(); + + /** + * VERIFY_PACKINFO_FAILED + */ + public static final ErrorMsg VERIFY_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("041") + .setDescription("Verify pack info failed.") + .setCause("%s") + .build(); + + /** + * VERIFY_APP_PACKINFO_FAILED + */ + public static final ErrorMsg VERIFY_APP_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("042") + .setDescription("Verify app pack info failed.") + .setCause("%s") + .build(); + + /** + * BUNDLE_TYPE_PACKINFO_INVALID + */ + public static final ErrorMsg BUNDLE_TYPE_PACKINFO_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("043") + .setDescription("Invalid bundle type in pack info.") + .setCause("%s") + .build(); + + /** + * PARSE_PACKINFO_FORMS_NAME_FAILED + */ + public static final ErrorMsg PARSE_PACKINFO_FORMS_NAME_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("044") + .setDescription("Parse pack info forms name error.") + .setCause("%s") + .build(); + + /** + * MERGE_PACKINFO_OBJ_FAILED + */ + public static final ErrorMsg MERGE_PACKINFO_OBJ_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("045") + .setDescription("Failed to merge package information object.") + .setCause("%s") + .build(); + + /** + * MERGE_BY_PACKAGE_PAIR_FAILED + */ + public static final ErrorMsg MERGE_BY_PACKAGE_PAIR_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("046") + .setDescription("Failed to merge two pack.info files into one pack.info file through packagePair.") + .setCause("%s") + .build(); + + /** + * MERGE_OBJBY_PACKAGE_PAIR_FAILED + */ + public static final ErrorMsg MERGE_OBJ_BY_PACKAGE_PAIR_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("047") + .setDescription("Failed to merge two pack.info objects into one pack.info through packagePair.") + .setCause("%s") + .build(); + + /** + * PARSE_PACKINFO_FORMS_FAILED + */ + public static final ErrorMsg PARSE_PACKINFO_FORMS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("048") + .setDescription("Failed to parse package information form.") + .setCause("%s") + .build(); + + /** + * INTERRUPTED_OR_EXECUTION_EXCEPTION + */ + public static final ErrorMsg INTERRUPTED_OR_EXECUTION_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("049") + .setDescription("Exists interrupted or execution exception.") + .setCause("%s") + .build(); + + /** + * ADD_ARCHIVE_ENTRY_FAILED + */ + public static final ErrorMsg ADD_ARCHIVE_ENTRY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("050") + .setDescription("Add archive entry failed.") + .setCause("%s") + .build(); + + /** + * COMPRESS_FAST_APP_FAILED + */ + public static final ErrorMsg COMPRESS_FAST_APP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("051") + .setDescription("Compress fast app file failed.") + .setCause("%s") + .build(); + // module json check error /** * PARSE_JSON_OBJECT_EXCEPTION @@ -670,6 +1073,60 @@ public class PackingToolErrMsg { .addSolution("Verify you have the necessary permissions to delete the file.") .build(); + /** + * DIR_CREATION_FAILED + */ + public static final ErrorMsg DIR_CREATION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("010") + .setDescription("Directory creation failed exception.") + .setCause("%s") + .addSolution("Please check the following:\n" + + "1. Please check the directory path and ensure that the parent " + + "directories exist and are accessible.\n" + + "2. Ensure that you have the necessary permissions to create directories.") + .build(); + + /** + * COMPRESS_FILE_DUPLICATE + */ + public static final ErrorMsg COMPRESS_FILE_DUPLICATE = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("011") + .setDescription("File duplicated.") + .setCause("%s") + .build(); + + /** + * COPY_FILE_SAFELY_FAILED + */ + public static final ErrorMsg COPY_FILE_SAFELY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("012") + .setDescription("Copy file safely failed.") + .setCause("%s") + .build(); + + /** + * COPY_FILE_FAILED + */ + public static final ErrorMsg COPY_FILE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("013") + .setDescription("Copy file failed.") + .setCause("%s") + .build(); + + /** + * MAKE_DIR_FAILED + */ + public static final ErrorMsg MAKE_DIR_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("014") + .setDescription("Make dir failed.") + .setCause("%s") + .build(); + // io exception /** * IO_EXCEPTION @@ -906,4 +1363,55 @@ public class PackingToolErrMsg { .addSolution("Ensure the Entry type module distributionFilter file policy " + "settings is 'exclude' or 'include'.") .build(); + + /** + * CHECK_APP_FIELDS_FAILED + */ + public static final ErrorMsg CHECK_APP_FIELDS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("020") + .setDescription("Check app fields is failed.") + .setCause("%s") + .build(); + + /** + * CHECK_MODULE_INVALID + */ + public static final ErrorMsg CHECK_MODULE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("021") + .setDescription("Check module is invalid.") + .setCause("%s") + .build(); + + // package normalize error + /** + * PACKAGE_NORMALIZE_FAILED + */ + public static final ErrorMsg PACKAGE_NORMALIZE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("17") + .setErrCode("001") + .setDescription("Normalize HSP bundleName and versionCode failed.") + .setCause("%s") + .build(); + + /** + * UPDATE_MODULE_JSON_FAILED + */ + public static final ErrorMsg UPDATE_MODULE_JSON_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("17") + .setErrCode("002") + .setDescription("Update module.json failed.") + .setCause("%s") + .build(); + + /** + * UPDATE_PACKINFO_FAILED + */ + public static final ErrorMsg UPDATE_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("17") + .setErrCode("003") + .setDescription("Update pack.info failed.") + .setCause("%s") + .build(); } diff --git a/adapter/ohos/Utility.java b/adapter/ohos/Utility.java index 496930cae599e3d3f0e30cdd9920854c50cc1b3b..81bf99679bcaaee2b43d8b6fd403459945b7f306 100644 --- a/adapter/ohos/Utility.java +++ b/adapter/ohos/Utility.java @@ -706,7 +706,8 @@ public class Utility { canonicalPath = file.getCanonicalPath(); } catch (IOException exception) { canonicalPath = INVALID_PATH; - LOG.error("Utility::getFormattedPath exception," + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "Get formatted path exist IOException: " + exception.getMessage())); } return canonicalPath; }