From fea41ec07aee3556f84a46555c2539783dd4a597 Mon Sep 17 00:00:00 2001 From: nj1868 Date: Thu, 20 Feb 2025 11:25:59 +0800 Subject: [PATCH] update Signed-off-by: nj1868 --- adapter/ohos/Compressor.java | 249 ++++---- adapter/ohos/PackingToolErrMsg.java | 885 ++++++++++++++++++++++++++++ 2 files changed, 1023 insertions(+), 111 deletions(-) create mode 100644 adapter/ohos/PackingToolErrMsg.java diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index 33461812..6d825541 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -494,7 +494,7 @@ public class Compressor { private static boolean hasGenerateBuildHash(Utility utility) throws BundleException { File file = new File(utility.getJsonPath()); if (!file.exists()) { - LOG.error("Compressor::hasGenerateBuildHash failed for json file not exist"); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("Compressor::hasGenerateBuildHash failed for json file not exist")); throw new BundleException("Compressor::hasGenerateBuildHash failed for json file not exist"); } InputStream json = null; @@ -503,7 +503,7 @@ public class Compressor { json = new FileInputStream(file); JSONObject jsonObject = JSON.parseObject(json, JSONObject.class); if (jsonObject == null || !jsonObject.containsKey(APP) || !jsonObject.containsKey(MODULE)) { - LOG.error("json file is invalid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("Compressor::hasGenerateBuildHash failed for json file is invalid.")); throw new BundleException("json file is invalid."); } JSONObject appJson = jsonObject.getJSONObject(APP); @@ -512,10 +512,11 @@ public class Compressor { res = true; } } catch (BundleException exception) { - LOG.error("Compressor::hasGenerateBuildHash failed."); + LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH_FAILED.toString("Compressor::hasGenerateBuildHash failed.")); throw new BundleException("Compressor::hasGenerateBuildHash failed."); } catch (JSONException | IOException e) { - LOG.error("Compressor::hasGenerateBuildHash failed for json file is invalid." + e.getMessage()); + LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH_FAILED.toString("Compressor::hasGenerateBuildHash" + + "failed for json file is invalid." + e.getMessage())); throw new BundleException("Compressor::hasGenerateBuildHash failed."); } finally { FileUtils.closeStream(json); @@ -531,7 +532,7 @@ public class Compressor { copyFileToTempDir(utility); File file = new File(utility.getJsonPath()); if (!file.exists()) { - LOG.error("Compressor::setGenerateBuildHash failed for json file not exist"); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("Compressor::setGenerateBuildHash failed for json file not exist")); throw new BundleException("Compressor::setGenerateBuildHash failed for json file not exist"); } InputStream json = null; @@ -540,7 +541,7 @@ public class Compressor { json = new FileInputStream(file); JSONObject jsonObject = JSON.parseObject(json, JSONObject.class); if (!jsonObject.containsKey(APP) || !jsonObject.containsKey(MODULE)) { - LOG.error("json file is invalid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("Compressor::setGenerateBuildHash failed for json file is invalid.")); throw new BundleException("json file is invalid."); } JSONObject appJson = jsonObject.getJSONObject(APP); @@ -561,10 +562,11 @@ public class Compressor { new FileOutputStream(utility.getJsonPath()), StandardCharsets.UTF_8)); bw.write(pretty); } catch (BundleException exception) { - LOG.error("Compressor::setGenerateBuildHash failed."); + LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH_FAILED.toString("Compressor::setGenerateBuildHash failed.")); throw new BundleException("Compressor::setGenerateBuildHash failed."); } catch (NullPointerException | IOException | JSONException e) { - LOG.error("Compressor::setGenerateBuildHash failed, json data err: " + e.getMessage()); + LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH_FAILED.toString("Compressor::setGenerateBuildHash" + + "failed, json data err: " + e.getMessage())); throw new BundleException("Compressor::setGenerateBuildHash failed, json data err."); } finally { FileUtils.closeStream(json); @@ -573,7 +575,7 @@ public class Compressor { bw.flush(); bw.close(); } catch (IOException e) { - LOG.error("Compressor::setGenerateBuildHash failed for IOException " + e.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("Compressor::setGenerateBuildHash failed for IOException " + e.getMessage())); throw new BundleException("Compressor::setGenerateBuildHash failed."); } } @@ -584,7 +586,7 @@ public class Compressor { String jsonPath = utility.getJsonPath(); File oldfile = new File(jsonPath); if (!oldfile.exists()) { - LOG.error("Compressor::copyFileToTempDir failed for json file not found."); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("Compressor::copyFileToTempDir failed for json file not exist")); throw new BundleException("Compressor::copyFileToTempDir failed for json file not found."); } String oldFileParent = oldfile.getParent(); @@ -607,7 +609,7 @@ public class Compressor { } utility.setJsonPath(tempPath); } catch (IOException e) { - LOG.error("Compressor::copyFileToTempDir failed, IOException: " + e.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("Compressor::copyFileToTempDir failed, IOException: " + e.getMessage())); throw new BundleException("Compressor::copyFileToTempDir failed."); } } @@ -628,7 +630,7 @@ public class Compressor { try { putBuildHash(utility, hash); } catch (IOException e) { - LOG.error("Compressor::putBuildHash failed, " + e.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("Compressor::putBuildHash failed, " + e.getMessage())); throw new BundleException("Compressor::putBuildHash failed."); } } @@ -646,7 +648,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("Compressor::checkSum failed, IOException or" + + "NoSuchAlgorithmException: " + e.getMessage())); throw new BundleException("Compressor::checkSum failed."); } } @@ -673,7 +676,7 @@ public class Compressor { String jsonPath = utility.getJsonPath(); File file = new File(jsonPath); if (!file.exists()) { - LOG.error("Compressor::putBuildHash failed for json file not exist"); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("Compressor::putBuildHash failed for json file not exist")); throw new BundleException("Compressor::putBuildHash failed for json file not exist"); } InputStream json = null; @@ -688,10 +691,10 @@ public class Compressor { bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(jsonPath), StandardCharsets.UTF_8)); bw.write(pretty); } catch (IOException e) { - LOG.error("Compressor::putBuildHash failed, IOException: " + e.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("Compressor::putBuildHash failed, IOException: " + e.getMessage())); throw new BundleException("Compressor::putBuildHash failed."); } catch (NullPointerException e) { - LOG.error("Compressor::putBuildHash failed, json data err: " + e.getMessage()); + LOG.error(PackingToolErrMsg.NULLPOINTER_EXCEPTION_ERROR.toString("Compressor::putBuildHash failed, json data err: " + e.getMessage())); throw new BundleException("Compressor::putBuildHash failed, json data err."); } finally { FileUtils.closeStream(json); @@ -1281,15 +1284,15 @@ 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); + String solution = "Modified according to related verification errors."; + LOG.error(PackingToolErrMsg.COMPRESS_APP_FAILED.toString("Verify failed when compress app.", solution)); + throw new BundleException("Compressor::compressFile verify failed, check version, " + + "apiVersion,moduleName,packageName."); } // packApp packFastApp(utility, fileList); } catch (IOException ex) { - LOG.error("Compressor::compressAppMode compress failed: " + ex.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("Compressor::compressAppMode compress failed: " + ex.getMessage())); throw new BundleException("Compressor::compressAppMode compress failed."); } finally { if (tmpDir != null) { @@ -1381,7 +1384,7 @@ public class Compressor { packEncryptJsonFile(utility); } catch (BundleException | IOException exception) { String errMsg = "Compressor::compressAppModeForMultiProject file failed: " + exception.getMessage(); - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.COMPRESS_APP_MODE_FORMULTI_PROJECT_FAILED.toString(errMsg)); throw new BundleException(errMsg); } finally { deleteFile(tempPath); @@ -1402,7 +1405,7 @@ public class Compressor { File outParentFile = destFile.getParentFile(); if ((outParentFile != null) && (!outParentFile.exists())) { if (!outParentFile.mkdirs()) { - LOG.error("Compressor::hapAddition create out file parent directory failed."); + LOG.error(PackingToolErrMsg.DIR_CREATION_FAILED.toString("Compressor::hapAddition create out file parent directory failed.")); } } FileOutputStream fileOut = null; @@ -1419,7 +1422,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("Compressor::HapAddition hapFile not found" + + "exception" + exception.getMessage())); copyFileSafely(backName, hapPathOri); } finally { closeZipOutputStream(); @@ -1447,7 +1451,7 @@ public class Compressor { File destFile = new File(dest); FileUtils.copyFile(sourceFile, destFile); } catch (IOException | BundleException e) { - LOG.error("copyFileSafely failed: " + e.getMessage()); + LOG.error(PackingToolErrMsg.COPY_FILE_SAFELY_FAILED.toString(e.getMessage())); } } @@ -1472,10 +1476,10 @@ public class Compressor { fileWriter.write(jsonString); fileWriter.flush(); } catch (IOException exception) { - LOG.error("writeJsonFile failed, " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("writeJsonFile failed, " + exception.getMessage())); throw new BundleException(exception.getMessage()); } catch (JSONException e) { - LOG.error("json file is invalid: " + e.getMessage()); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("json file is invalid: " + e.getMessage())); throw new BundleException(e.getMessage()); } } @@ -1541,7 +1545,7 @@ public class Compressor { File targetParent = new File(targetParentPath); if (!targetParent.exists()) { if (!targetParent.mkdirs()) { - LOG.error("Compressor::compressHapAddition create target file parent directory failed."); + LOG.error(PackingToolErrMsg.DIR_CREATION_FAILED.toString("Compressor::compressHapAddition create target file parent directory failed.")); } } String targetPath = targetParentPath + LINUX_FILE_SEPARATOR + ADDITION_JSON; @@ -1557,7 +1561,7 @@ public class Compressor { setUtilityParameter(hapAdditionPath, utility); } catch (IOException e) { String errMsg = "Compressor::compressHapAddition setUtilityParameter failed."; - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } if (utility.getHapPath().endsWith(HAP_SUFFIX)) { @@ -1566,7 +1570,7 @@ public class Compressor { compressHsp(utility); } else { String errMsg = "Compressor::compressHapAddition compressFile failed."; - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.UNSUPPORTED_FILE_TYPE.toString(errMsg)); throw new BundleException(errMsg); } } @@ -1615,7 +1619,7 @@ public class Compressor { 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); + LOG.error(PackingToolErrMsg.NO_PACK_INFO.toString(errorMsg)); throw new BundleException(errorMsg); } if (finalAppPackInfo.isEmpty()) { @@ -1655,7 +1659,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.FILE_DUPLICATE.toString("Compressor::copyHapFromApp file duplicated, file is " + + zipEntry.getName() + ".")); throw new BundleException("Compressor::copyHapFromApp file duplicated, file is " + zipEntry.getName() + "."); } else { @@ -1676,7 +1681,7 @@ public class Compressor { } } catch (IOException e) { String errMsg = "Compressor:copyHapFromApp app path not found."; - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } finally { Utility.closeStream(zipInput); @@ -1722,7 +1727,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.FILE_DUPLICATE.toString("Compressor::disposeHap file duplicated, file is " + + new File(hapPath).getName() + ".")); throw new BundleException("Compressor::disposeHap file duplicated, file is " + new File(hapPath).getName() + "."); } @@ -1734,7 +1740,7 @@ public class Compressor { if (packInfo.isEmpty()) { String errMsg = "Compressor::disposeHap failed, hap has no pack.info."; - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.NO_PACK_INFO.toString(errMsg)); throw new BundleException(errMsg); } if (finalPackInfoStr.isEmpty()) { @@ -1760,7 +1766,7 @@ public class Compressor { fwriter.write(packInfoStr); } catch (IOException e) { String errMsg = "Compressor:writePackInfo failed."; - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } finally { if (fwriter != null) { @@ -1813,7 +1819,7 @@ public class Compressor { } append.closeEntry(); } catch (IOException exception) { - LOG.error("Compressor::compressPackinfoIntoHap io exception."); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("Compressor::compressPackinfoIntoHap io exception.")); throw new BundleException("Compressor::compressPackinfoIntoHap io exception."); } finally { sourceHapFile.close(); @@ -1859,21 +1865,21 @@ public class Compressor { String fName = fileName.trim(); String[] temp = fName.replace("\\", "/").split("/"); if (temp.length < 4) { - LOG.error("Compressor::compressPackResMode the hap file path is invalid, length: " - + temp.length + "."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE.toString("Compressor::compressPackResMode the hap file path is invalid, length: " + + temp.length + ".")); continue; } String fileLanguageCountryName = temp[temp.length - 3]; if (!isThirdLevelDirectoryNameValid(fileLanguageCountryName)) { - LOG.error("Compressor::compressProcess compress failed third level directory name: " - + fileLanguageCountryName + " is invalid, please check it with reference to this example: " - + "zh_Hani_CN-vertical-car-mdpi-dark or zh_Hani_CN-vertical-car-mdpi."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE.toString("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.")); throw new BundleException("Compress failed third level directory name Error."); } String filePicturingName = temp[temp.length - 1]; if (!isPicturing(filePicturingName, utility)) { - LOG.error("Compressor::compressProcess Compress pack.res failed, Invalid resource file" + - " name: " + filePicturingName + ", correct format example is formName-2x2.png."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE.toString("Compressor::compressProcess Compress pack.res failed, Invalid resource file" + + " name: " + filePicturingName + ", correct format example is formName-2x2.png.")); throw new BundleException("Compress pack.res failed, Invalid resource file name: " + filePicturingName + ", correct format example is formName-2x2.png."); } @@ -1883,7 +1889,7 @@ public class Compressor { snapshotNameList.add(fullSnapshotName); } else { - LOG.error("Compressor::compressProcess compress failed No image in PNG format is found."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE.toString("Compressor::compressProcess compress failed No image in PNG format is found.")); throw new BundleException("Compress pack.res failed, compress failed No image in" + " PNG format is found."); } @@ -1891,8 +1897,8 @@ public class Compressor { for (String formName : formNamesList) { if (!snapshotNameList.contains(formName)) { - LOG.error("Compressor::compressProcess compress failed entryCard " + formName - + " has no related snapshot " + snapshotNameList.toString() + "."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE.toString("Compressor::compressProcess compress failed entryCard " + formName + + " has no related snapshot " + snapshotNameList.toString() + ".")); throw new BundleException("Compress pack.res failed, compress failed entryCard has no related snapshot."); } } @@ -1979,7 +1985,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( + "Compressor::compressProcess language " + language + " is not in ISO 639-1 list.")); return false; } return true; @@ -1987,7 +1994,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( + "Compressor::compressProcess script " + script + " is not in ISO 15924 list.")); return false; } return true; @@ -1995,7 +2003,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( + "Compressor::compressProcess country " + country + " is not in ISO 3166-1 list.")); return false; } return true; @@ -2003,8 +2012,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( + "Compressor::compressProcess orientation " + orientation + " is not in {vertical, horizontal} list.")); return false; } return true; @@ -2012,8 +2021,9 @@ 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( + "Compressor::compressProcess deviceType " + deviceType + + " is not in {phone, tablet, car, tv, wearable, liteWearable, 2in1} list.")); return false; } return true; @@ -2021,8 +2031,9 @@ 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( + "Compressor::compressProcess screenDensity " + screenDensity + + " is not in {sdpi, mdpi, ldpi, xldpi, xxldpi} list.")); return false; } return true; @@ -2030,8 +2041,9 @@ 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( + "Compressor::compressProcess colorMode " + colorMode + + " is not in {light, dark} list.")); return false; } return true; @@ -2042,8 +2054,9 @@ 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( + "Compressor::compressProcess " + tmp + + " is neither in colorMode list {light, dark} nor in shape list {circle}.")); return false; } @@ -2051,7 +2064,8 @@ 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( + "Compressor::compressProcess shape" + shape + " is not in {circle} list.")); return false; } @@ -2068,24 +2082,28 @@ public class Compressor { return isSpecifications; } if (!name.endsWith(PNG_SUFFIX) && !name.endsWith(UPPERCASE_PNG_SUFFIX)) { - LOG.error("isPicturing: the suffix is not .png or .PNG."); + LOG.error(PackingToolErrMsg.UNSUPPORTED_FILE_TYPE.toString( + "isPicturing: 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( + "isPicturing: the dimension: " + dimension + " is invalid, is not in the following list: " + + "{1X2, 2X2, 2X4, 4X4, 1X1, 6X4}.")); return false; } @@ -2095,12 +2113,12 @@ public class Compressor { private void getFileList(final String filePath) throws BundleException { File file = new File(filePath); if (!file.exists()) { - LOG.error("getFileList: file is not exists."); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("getFileList: file is not exists.")); return; } File[] files = file.listFiles(); if (files == null) { - LOG.error("getFileList: no file in this file path."); + LOG.error(PackingToolErrMsg.GET_FILE_LIST_FAILED.toString("no file in this file path.")); return; } for (File f : files) { @@ -2112,8 +2130,8 @@ public class Compressor { } String snapshotDirectoryName = f.getParentFile().getName(); if (!ENTRYCARD_SNAPSHOT_NAME.equals(snapshotDirectoryName)) { - LOG.error("The level-4 directory of EntryCard must be named as snapshot" + - ", but current is: " + snapshotDirectoryName + "."); + LOG.error(PackingToolErrMsg.GET_FILE_LIST_FAILED.toString("The level-4 directory of EntryCard must be named as snapshot" + + ", but current is: " + snapshotDirectoryName + ".")); throw new BundleException("The level-4 directory of EntryCard must be named as snapshot" + ", but current is: " + snapshotDirectoryName + "."); } @@ -2121,10 +2139,10 @@ public class Compressor { } else if (f.isDirectory()) { getFileList(f.getCanonicalPath()); } else { - LOG.error("It's not file or directory."); + LOG.error(PackingToolErrMsg.GET_FILE_LIST_FAILED.toString("It's not file or directory.")); } } catch (IOException msg) { - LOG.error("IOException error: " + msg.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("IOException error: " + msg.getMessage())); return; } } @@ -2352,9 +2370,10 @@ public class Compressor { } } } catch (FileNotFoundException ignored) { - LOG.error("Compressor::compressFile file not found exception."); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("Compressor::compressFile file not found exception.")); } catch (IOException exception) { - LOG.error("Compressor::compressFile io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("Compressor::compressFile io exception: " + + exception.getMessage())); } catch (BundleException bundleException) { LOG.error("Compressor::compressFile bundle exception" + bundleException.getMessage()); } finally { @@ -2385,10 +2404,11 @@ public class Compressor { count = fileInputStream.read(buffer); } } catch (FileNotFoundException ignored) { - LOG.error("Uncompressor::getCrcFromFile file not found exception."); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("Uncompressor::getCrcFromFile file not found exception.")); throw new BundleException("Get Crc from file failed."); } catch (IOException exception) { - LOG.error("Uncompressor::getCrcFromFile io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("Uncompressor::getCrcFromFile io exception: " + + exception.getMessage())); throw new BundleException("Get Crc from file failed."); } finally { Utility.closeStream(fileInputStream); @@ -2466,7 +2486,8 @@ public class Compressor { } catch (FileNotFoundException ignored) { throw new BundleException("CoompressFile failed."); } catch (IOException exception) { - LOG.error("Compressor::compressFile io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("Compressor::compressFile io exception: " + + exception.getMessage())); throw new BundleException("CoompressFile failed."); } finally { Utility.closeStream(bufferedInputStream); @@ -2498,7 +2519,8 @@ public class Compressor { } } } catch (IOException exception) { - LOG.error("Compressor::isModuleHap io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("Compressor::isModuleHap io exception: " + + exception.getMessage())); throw new BundleException("Compressor::isModuleHap failed."); } finally { Utility.closeStream(zipInput); @@ -2528,10 +2550,10 @@ public class Compressor { count = fileInputStream.read(buffer); } } catch (FileNotFoundException ignored) { - LOG.error("Compressor::getCrcFromFile FileNotFoundException : " + ignored.getMessage()); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("Compressor::getCrcFromFile FileNotFoundException : " + ignored.getMessage())); throw new BundleException("Get Crc from file failed: " + file.getName()); } catch (IOException exception) { - LOG.error("Compressor::getCrcFromFile io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("Compressor::getCrcFromFile io exception: " + exception.getMessage())); throw new BundleException("Get Crc from file failed."); } finally { Utility.closeStream(fileInputStream); @@ -2547,14 +2569,14 @@ public class Compressor { ModuleJsonUtil.parsePackInfoFormsName(jsonString, nameList, formNamesList); for (String formName : nameList) { if (formName.isEmpty()) { - LOG.error("Compressor::infoSpecialJsonFileProcess form name is empty."); + LOG.warning("Compressor::infoSpecialJsonFileProcess form name is empty."); continue; } utility.addFormNameList(formName); } } catch (JSONException e) { - LOG.error("Compressor::infoSpecialJsonFileProcess json Path: " + jsonPath + + LOG.warning("Compressor::infoSpecialJsonFileProcess json Path: " + jsonPath + "json exception: " + e.getMessage()); } } @@ -2586,7 +2608,8 @@ public class Compressor { str = bufferedReader.readLine(); } } catch (IOException exception) { - LOG.error("Compressor::jsonSpecialProcess io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("Compressor::jsonSpecialProcess io exception: " + + exception.getMessage())); throw new BundleException("Json special process failed."); } finally { Utility.closeStream(bufferedReader); @@ -2689,7 +2712,8 @@ public class Compressor { } } } catch (IOException exception) { - LOG.error("Compressor::parseModuleName io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("Compressor::parseModuleName io exception: " + + exception.getMessage())); throw new BundleException("Parse module name failed."); } } @@ -2719,7 +2743,7 @@ public class Compressor { } } } catch (IOException exception) { - LOG.error("Compressor::parseModuleName io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("Compressor::parseModuleName io exception: " + exception.getMessage())); throw new BundleException("Parse module name failed."); } } @@ -2767,19 +2791,20 @@ public class Compressor { try { int endIndex = lineStr.lastIndexOf(SEMICOLON); if (endIndex <= 0) { - LOG.error("Compressor::getModuleNameFromString field the json is not standard."); + LOG.error(PackingToolErrMsg.GET_MODULE_NAME_FROM_STRING_FAILED.toString("Json is not standard.")); throw new BundleException("Parse module name failed, module-name is invalid."); } int startIndex = lineStr.lastIndexOf(SEMICOLON, endIndex - 1) + 1; String moduleName = lineStr.substring(startIndex, endIndex); list.add(moduleName); if (moduleName == null || moduleName.isEmpty()) { - LOG.error("Compressor::getModuleNameFromString field module-name is empty."); + LOG.error(PackingToolErrMsg.GET_MODULE_NAME_FROM_STRING_FAILED.toString("Module-name is empty.")); throw new BundleException("Parse module name failed, module-name is empty."); } utility.setModuleName(moduleName); } catch (StringIndexOutOfBoundsException exception) { - LOG.error("Compressor::parseModuleName field module-name is fault: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.GET_MODULE_NAME_FROM_STRING_FAILED.toString("Module-name is fault: " + + exception.getMessage())); throw new BundleException("Parse module name failed, module-name is invalid."); } } @@ -2853,7 +2878,8 @@ public class Compressor { break; } } catch (IOException exception) { - LOG.error("Compressor::parseDeviceType io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("Compressor::parseDeviceType io exception: " + + exception.getMessage())); throw new BundleException("Parse device type failed."); } } @@ -3047,7 +3073,7 @@ public class Compressor { private void compressAPPQFMode(Utility utility) throws BundleException { List fileList = utility.getFormatedHQFList(); if (!checkHQFIsValid(fileList)) { - LOG.error("checkHQFIsValid failed when pack appqf file."); + LOG.error(PackingToolErrMsg.COMPRESS_APPQF_FAILED.toString("checkHQFIsValid failed when pack appqf file.")); throw new BundleException("checkHQFIsValid failed when pack appqf file."); } for (String hapPath : fileList) { @@ -3067,7 +3093,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; @@ -3191,7 +3217,7 @@ public class Compressor { tempDir.toAbsolutePath() + LINUX_FILE_SEPARATOR + PACKINFO_NAME); if (moduleFile.exists() && configFile.exists()) { - LOG.error("versionNormalize failed, invalid hap structure."); + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_FAILED.toString("invalid hap structure.")); throw new BundleException("versionNormalize failed, invalid hap structure."); } if (moduleFile.exists()) { @@ -3201,7 +3227,7 @@ public class Compressor { String configJsonPath = tempDir.resolve(CONFIG_JSON).toString(); util = parseAndModifyConfigJson(configJsonPath, utility); } else { - LOG.error("versionNormalize failed, invalid hap structure."); + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_FAILED.toString("invalid hap structure.")); throw new BundleException("versionNormalize failed, invalid hap structure."); } if (packInfoFile.exists()) { @@ -3216,7 +3242,7 @@ public class Compressor { LINUX_FILE_SEPARATOR + Paths.get(hapPath).getFileName().toString(); compressDirToHap(tempDir, modifiedHapPath); } catch (IOException | BundleException e) { - LOG.error("versionNormalize failed " + e.getMessage()); + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_FAILED.toString(e.getMessage())); } finally { if (tempDir != null) { deleteDirectory(tempDir.toFile()); @@ -3232,16 +3258,16 @@ public class Compressor { try (FileInputStream jsonStream = new FileInputStream(jsonFilePath)) { JSONObject jsonObject = JSON.parseObject(jsonStream, JSONObject.class); if (!jsonObject.containsKey(APP)) { - LOG.error("parseAndModifyJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("parseAndModifyJson failed, json file not valid.")); throw new BundleException("parseAndModifyJson failed, json file not valid."); } JSONObject appObject = jsonObject.getJSONObject(APP); if (!appObject.containsKey(VERSION_CODE)) { - LOG.error("parseAndModifyJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("parseAndModifyJson failed, json file not valid.")); throw new BundleException("parseAndModifyJson failed, json file not valid."); } if (!appObject.containsKey(VERSION_NAME)) { - LOG.error("parseAndModifyJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("parseAndModifyJson failed, json file not valid.")); throw new BundleException("parseAndModifyJson failed, json file not valid."); } util.setOriginVersionCode(appObject.getIntValue(VERSION_CODE)); @@ -3249,7 +3275,7 @@ public class Compressor { JSONObject moduleObject = jsonObject.getJSONObject(MODULE); if (!moduleObject.containsKey(NAME)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("parseAndModifyJson failed, json file not valid.")); throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); } util.setModuleName(moduleObject.getString(NAME)); @@ -3257,7 +3283,7 @@ public class Compressor { appObject.put(VERSION_NAME, utility.getVersionName()); writeJson(jsonFilePath, jsonObject); } catch (IOException e) { - LOG.error("parseAndModifyModuleJson failed, IOException." + e.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("parseAndModifyModuleJson failed, IOException." + e.getMessage())); throw new BundleException("parseAndModifyModuleJson failed, IOException." + e.getMessage()); } return util; @@ -3298,12 +3324,13 @@ public class Compressor { BufferedWriter bw = null; try { String pretty = JSON.toJSONString(jsonObject, SerializerFeature.PrettyFormat, - SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat); + SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat); bw = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(jsonFilePath), StandardCharsets.UTF_8)); bw.write(pretty); } catch (IOException exception) { - LOG.error("Compressor::writeJson failed for IOException " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("Compressor::writeJson failed for IOException " + + exception.getMessage())); throw new BundleException("Compressor::writeJson failed for IOException"); } finally { if (bw != null) { @@ -3319,29 +3346,29 @@ public class Compressor { try (FileInputStream jsonStream = new FileInputStream(jsonFilePath)) { JSONObject jsonObject = JSON.parseObject(jsonStream, JSONObject.class); if (!jsonObject.containsKey(APP)) { - LOG.error("parseAndModifyJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("parseAndModifyJson failed, json file not valid.")); throw new BundleException("parseAndModifyJson failed, json file not valid."); } JSONObject appObject = jsonObject.getJSONObject(APP); if (!appObject.containsKey(VERSION)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("parseAndModifyJson failed, json file not valid.")); throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); } JSONObject versionObj = appObject.getJSONObject(VERSION); if (!versionObj.containsKey(CODE)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("parseAndModifyJson failed, json file not valid.")); throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); } util.setOriginVersionCode(versionObj.getIntValue(CODE)); if (!versionObj.containsKey(NAME)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("parseAndModifyJson failed, json file not valid.")); throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); } util.setOriginVersionName(versionObj.getString(NAME)); JSONObject moduleObject = jsonObject.getJSONObject(MODULE); if (!moduleObject.containsKey(NAME)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("parseAndModifyJson failed, json file not valid.")); throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); } util.setModuleName(moduleObject.getString(NAME)); @@ -3350,7 +3377,7 @@ public class Compressor { versionObj.put(NAME, utility.getVersionName()); writeJson(jsonFilePath, jsonObject); } catch (IOException e) { - LOG.error("parseAndModifyModuleJson IOException." + e.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("parseAndModifyModuleJson IOException." + e.getMessage())); throw new BundleException("parseAndModifyModuleJson IOException." + e.getMessage()); } return util; @@ -3442,7 +3469,7 @@ public class Compressor { try (FileWriter fileWriter = new FileWriter(outPath + LINUX_FILE_SEPARATOR + VERSION_RECORD)) { fileWriter.write(jsonString); } catch (IOException e) { - LOG.error("writeVersionRecord failed " + e.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("writeVersionRecord failed " + e.getMessage())); } } @@ -3451,7 +3478,7 @@ public class Compressor { if (versionNormalizeUtil.getOriginVersionCode() > utility.getVersionCode()) { String errorMsg = "versionNormalize failed, module " + versionNormalizeUtil.getModuleName() + " version code less than input version code"; - LOG.error(errorMsg); + LOG.error(PackingToolErrMsg.VERIFY_MODULE_VERSION_FAILED.toString(errorMsg)); throw new BundleException(errorMsg); } else if (versionNormalizeUtil.getOriginVersionCode() == utility.getVersionCode()) { LOG.warning("versionNormalize warning: module " + @@ -3491,7 +3518,7 @@ public class Compressor { zipInputStream.closeEntry(); } } catch (IOException e) { - LOG.error("unpack hap failed IOException " + e.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("unpack hap failed IOException " + e.getMessage())); throw new BundleException("unpack hap failed IOException " + e.getMessage()); } } diff --git a/adapter/ohos/PackingToolErrMsg.java b/adapter/ohos/PackingToolErrMsg.java new file mode 100644 index 00000000..18c3f35b --- /dev/null +++ b/adapter/ohos/PackingToolErrMsg.java @@ -0,0 +1,885 @@ +/* + * Copyright (c) 2025-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos; + +/** + * PackingToolErrMsg + * + * @since 2025/01/06 + */ +public class PackingToolErrMsg { + + // io excepetion + /** + * COMPRESS_APP_IO_EXCEPTION + */ + public static final ErrorMsg COMPRESS_APP_IO_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("002") + .addDescription("Io exception when compress pack.info into hap or hsp.") + .addCause("%s") + .addSolution("Please check the related error message and modify the operation. If the issue persists, review the logs for more details.") + .build(); + + /** + * COMPRESS_PACK_INFO_INTO_HAP_FAILED + */ + public static final ErrorMsg COMPRESS_PACK_INFO_INTO_HAP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("003") + .addDescription("Io exception when compress pack info into hap or hsp.") + .addCause("%s") + .addSolution("Please check the related error message and modify the operation. If the issue persists, review the logs for more details.") + .build(); + + /** + * COMPRESS_PARALLEL_EXCEPTION + */ + public static final ErrorMsg COMPRESS_PARALLEL_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") + .addErrCode("002") + .addDescription("Parallel compress exception.") + .addCause("%s") + .addSolution("Please check the related error message and modify the operation. If the issue persists, review the logs for more details.") + .build(); + + /** + * COMPRESS_FILE_EXCEPTION + */ + public static final ErrorMsg COMPRESS_FILE_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") + .addErrCode("003") + .addDescription("Compress file exception.") + .addCause("%s") + .addSolution("Please check the related error message and modify the operation. If the issue persists, review the logs for more details.") + .build(); + + /** + * PARSE_BUNDLE_NAME + */ + public static final ErrorMsg PARSE_BUNDLE_NAME_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") + .addErrCode("004") + .addDescription("The json file is not standard.") + .addCause("%s") + .build(); + + //file operator failed + /** + * FILE_NOT_FOUND + */ + public static final ErrorMsg FILE_NOT_FOUND = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") + .addErrCode("001") + .addDescription("File available not found exception.") + .addCause("%s") + .addSolution("Please check the related error message, If the file is in use, close any applications or processes that might be using it.") + .build(); + + /** + * FILE_IO_EXCEPTION + */ + public static final ErrorMsg FILE_IO_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") + .addErrCode("002") + .addDescription("File io exception.") + .addCause("%s") + .addSolution("Please check the following:\n" + + "1. Ensure the file path is correct and the file exists.\n" + + "2. Verify you have the necessary permissions to access the file.\n" + + "3. Check for possible disk or file system errors.\n" + + "4. Review the related error message for further insights.") + .build(); + + /** + * UNSUPPORTED_FILE_TYPE + */ + public static final ErrorMsg UNSUPPORTED_FILE_TYPE = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") + .addErrCode("003") + .addDescription("unsupported file types.") + .addCause("%s") + .addSolution("Please check the file type.") + .build(); + /** + * FILE_DUPLICATE + */ + public static final ErrorMsg FILE_DUPLICATE = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") + .addErrCode("003") + .addDescription("File duplicated.") + .addCause("%s") + .build(); + + /** + * DIR_CREATION_FAILED + */ + public static final ErrorMsg DIR_CREATION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") + .addErrCode("003") + .addDescription("Directory creation failed exception.") + .addCause("%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(); + + /** + * COPY_FILE_SAFELY_FAILED + */ + public static final ErrorMsg COPY_FILE_SAFELY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") + .addErrCode("003") + .addDescription("copyFileSafely failed.") + .addCause("%s") + .build(); + // compress process error + /** + * COMPRESS_PROCESS_EXCEPTION + */ + public static final ErrorMsg COMPRESS_PROCESS_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") + .addErrCode("001") + .addDescription("Process compress exception.") + .addCause("%s") + .addSolution("Please check the related error message and modify. If the issue persists, review the logs for more details.") + .build(); + + //appmode verify error + /** + * INVALID_HAP_OR_HSP_FILE + */ + public static final ErrorMsg INVALID_HAP_FILE = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("007") + .addDescription("Invaild hap or hsp file.") + .addCause("%s") + .build(); + + // packing tool error + /** + * EXECUTE_PACKING_TOOL_FAILED + */ + public static final ErrorMsg COMMAND_PARSER_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("18") + .addErrCode("003") + .addDescription("Command parser failed.") + .addCause("%s") + .build(); + + public static final ErrorMsg COMMAND_VERIFY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("18") + .addErrCode("002") + .addDescription("Command verify failed.") + .addCause("%s") + .build(); + + public static final ErrorMsg EXECUTE_PACKING_TOOL_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("18") + .addErrCode("001") + .addDescription("Execute packing tool failed.") + .addCause("%s") + .addSolution("Please check the related log or error message and modify.") + .build(); + + + + + /** + * COMMAND_MODE_INVALID + */ + public static final ErrorMsg COMMAND_MODE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("006") + .addDescription("Invalid command mode.") + .addCause("%s") + .build(); + + // + /** + * READ_STAGE_HAP_VERIFY_INFO + */ + public static final ErrorMsg READ_STAGE_HAP_VERIFY_INFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("20") + .addErrCode("001") + .addDescription("Read stage hap verify info io exception.") + .addCause("%s") + .build(); + + /** + * READ_STAGE_HAP_VERIFY_INFO + */ + public static final ErrorMsg READ_FA_HAP_VERIFY_INFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("20") + .addErrCode("002") + .addDescription("Read FA hap verify info io exception.") + .addCause("%s") + .build(); + + //parse json file failed + /** + * GET_JSON_PROFILE_FAILED + */ + public static final ErrorMsg GET_JSON_PROFILE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("001") + .addDescription("Get json profile exception.") + .addCause("%s") + .build(); + + /** + * PARSE_JSON_FAILED + */ + public static final ErrorMsg PARSE_JSON_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("001") + .addDescription("Parse json profile failed.") + .addCause("%s") + .build(); + + /** + * GET_JSON_PROFILE_FAILED + */ + public static final ErrorMsg PARSE_CONFIG_JSON_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("003") + .addDescription("Get json profile io exception.") + .addCause("%s") + .build(); + /** + * PARSE_STAGE_VERSION_FAILED + */ + public static final ErrorMsg PARSE_STAGE_VERSION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("003") + .addDescription("Failed to parse stage version from module.json.") + .addCause("%s") + .build(); + +// /** +// * PARSE_STAGE_VERSION_FAILED +// */ +// public static final ErrorMsg PARSE_STAGE_VERSION_FAILED = ErrorMsg.getPackingToolErrBuilder() +// .addTypeCode("21") +// .addErrCode("003") +// .addDescription("Failed to parse stage version from module.json.") +// .addCause("%s") +// .build(); + + /** + * PARSE_STAGE_VERSION_FAILED + */ + public static final ErrorMsg PARSE_FA_VERSION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("003") + .addDescription("Failed to parse stage version from config.json.") + .addCause("%s") + .build(); + + /** + * PARSE_STAGE_MODULE_FAILED + */ + public static final ErrorMsg PARSE_STAGE_MODULE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("004") + .addDescription("Failed to parse json file for stage module.") + .addCause("%s") + .build(); + + /** + * PARSE_FA_MODULE_NAME_FAILED + */ + public static final ErrorMsg PARSE_FA_MODULE_NAME_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("004") + .addDescription("Failed to parse config.json.") + .addCause("%s") + .build(); + + /** + * PARSE_STAGE_BUNDLE_TYPE_FAILED + */ + public static final ErrorMsg PARSE_STAGE_BUNDLE_TYPE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("005") + .addDescription("Failed to parse module.json and bundleType.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * PARSE_PROXY_DATA_URI_FAILED + */ + public static final ErrorMsg PARSE_PROXY_DATA_URI_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("006") + .addDescription("Failed to parse module.json and proxyData object.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * APP_FIELDS_INVALID + */ + public static final ErrorMsg CHECK_BUNDLETYPE_CONSISTENCY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("007") + .addDescription("bundleType consistency check failed.") + .addCause("%s") + .addSolution("Make sure the bundleType is consistency for different modules.") + .build(); + + /** + * PARSE_JSON_OBJECT_EXCEPTION + */ + public static final ErrorMsg PARSE_JSON_OBJECT_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("002") + .addDescription("Failed to parse json Object.") + .addCause("%s") + .build(); + + /** + * FA_PACKAGE_STR_PARSE_FAILED + */ + public static final ErrorMsg FA_PACKAGE_STR_PARSE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("006") + .addDescription("Failed to parse config.json and package object.") + .addCause("%s") + .build(); + + /** + * FA_MODULE_API_VERSION_MISSING + */ + public static final ErrorMsg FA_MODULE_API_VERSION_MISSING = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("007") + .addDescription("Failed to parse FA apiVersion.") + .addCause("%s") + .build(); + + //compress verify error + /** + * APP_MODE_ARGS_INVALID + */ + public static final ErrorMsg APP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("23") + .addErrCode("003") + .addDescription("Parse and check args invalid in app mode.") + .addCause("%s") + .build(); + + /** + * GET_FILE_SIZE_FAILED + */ + public static final ErrorMsg GET_FILE_SIZE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("99") + .addErrCode("001") + .addDescription("Failed to get file size.") + .addCause("%s") + .build(); + + /** + * OUT_PATH_INVALID + */ + public static final ErrorMsg OUT_PATH_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("23") + .addErrCode("004") + .addDescription("Invalid output path.") + .addCause("%s") + .build(); + + //packing process error + /** + * COMPRESS_PROCESS + */ + public static final ErrorMsg COMPRESS_PROCESS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("31") + .addErrCode("001") + .addDescription("Execute compress process failed.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * PARSE_COMPRESS_NATIVE_LIBS_FAILED + */ + public static final ErrorMsg PARSE_COMPRESS_NATIVE_LIBS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("007") + .addDescription("Failed to parse compress native libs.") + .addCause("%s") + .build(); + + /** + * PARSE_PATCH_MODULE_NAME_FAILED + */ + public static final ErrorMsg PARSE_PATCH_MODULE_NAME_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("008") + .addDescription("Failed to parse patch module name from patch.json.") + .addCause("%s") + .build(); + + /** + * PARSE_DEVICE_TYPE_FAILED + */ + public static final ErrorMsg PARSE_DEVICE_TYPE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("009") + .addDescription("parse DeviceType io exception.") + .addCause("%s") + .build(); + + /** + * JSON_SPECIAL_PROCESS_FAILED + */ + public static final ErrorMsg JSON_SPECIAL_PROCESS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") + .addErrCode("005") + .addDescription("json SpecialProcess io exception.") + .addCause("%s") + .addSolution("Please check the related error message and modify the operation. If the issue persists, review the logs for more details.") + .build(); + + /** + * CLOSE_ZIP_OUTPUT_STREAM_EXPECTION + */ + public static final ErrorMsg CLOSE_ZIP_OUTPUT_STREAM_EXPECTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") + .addErrCode("006") + .addDescription("close zip output stream exception.") + .addCause("%s") + .addSolution("Please check the related error message and modify the operation. If the issue persists, review the logs for more details.") + .build(); + /** + * FA_HAP_VERIFY_INFO_FAILED + */ + public static final ErrorMsg FA_HAP_VERIFY_INFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("011") + .addDescription("Failed to parse FA hap verify info from config.json.") + .addCause("%s") + .build(); + /** + * NO_PACK_INFO + */ + public static final ErrorMsg NO_PACK_INFO = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("012") + .addDescription("Failed to parse FA hap verify info from config.json.") + .addCause("%s") + .build(); + + //pack res error + /** + * COMPRESS_PACK_RES_MODE + */ + public static final ErrorMsg COMPRESS_PACK_RES_MODE = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("001") + .addDescription("Compressor::compressPackResMode failed.") + .addCause("%s") + .build(); + /** + * INVALID_THIRD_LEVEL_DIRECTORY_NAME + */ + public static final ErrorMsg INVALID_THIRD_LEVEL_DIRECTORY_NAME = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("002") + .addDescription("Compressor::isThirdLevelDirectoryNameValid failed.") + .addCause("%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() + .addTypeCode("xx") + .addErrCode("003") + .addDescription("Compressor::isPicturing failed.") + .addCause("%s") + .build(); + /** + * GET_FILE_LIST_FAILED + */ + public static final ErrorMsg GET_FILE_LIST_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("004") + .addDescription("Compressor::getFileList failed.") + .addCause("%s") + .build(); + /** + * GET_MODULE_NAME_FROM_STRING_FAILED + */ + public static final ErrorMsg GET_MODULE_NAME_FROM_STRING_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("005") + .addDescription("Compressor::getModuleNameFromString failed.") + .addCause("%s") + .build(); + + //compress appqf error + /** + * COMPRESS_APPQF_FAILED + */ + public static final ErrorMsg COMPRESS_APPQF_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("001") + .addDescription("Compressor::compressAPPQFMode failed.") + .addCause("%s") + .build(); + /** + * CHECK_HQF_INVALID + */ + public static final ErrorMsg CHECK_HQF_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("002") + .addDescription("Compressor::checkHQFIsValid failed.") + .addCause("%s") + .build(); + + //version normalize error + /** + * VERSION_NORMALIZE_FAILED + */ + public static final ErrorMsg VERSION_NORMALIZE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("001") + .addDescription("Compressor::versionNormalize failed.") + .addCause("%s") + .build(); + /** + * VERIFY_MODULE_VERSION_FAILED + */ + public static final ErrorMsg VERIFY_MODULE_VERSION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("002") + .addDescription("Compressor::verifyModuleVersion failed.") + .addCause("%s") + .build(); + + + //verify app mode failed + /** + * CHECK_APP_MODE_FAILED + */ + public static final ErrorMsg CHECK_SHARED_APP_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") + .addErrCode("008") + .addDescription("Check shared App mode invalid") + .addCause("%s") + .addSolution("%s") + .build(); + + //verify error + /** + * CHECK_APP_MODE_FAILED + */ + public static final ErrorMsg VERIFY_SHARED_APP_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("005") + .addDescription("Verify SharedApp invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_APP_MODE_FAILED + */ + public static final ErrorMsg CHECK_BUNDLETYPE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("003") + .addDescription("Check bundleType invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * APP_FIELDS_INVALID + */ + public static final ErrorMsg CHECK_APP_FIELDS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("004") + .addDescription("app fields is invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * APP_FIELDS_DIFFERENT_ERROR + */ + public static final ErrorMsg APP_FIELDS_DIFFERENT_ERROR = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("005") + .addDescription("Some app variable is different.") + .addCause("%s") + .addSolution("%s") + .build(); + + //hap verify error + /** + * CHECK_HAP_INVALID + */ + public static final ErrorMsg CHECK_HAP_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("006") + .addDescription("Check hap info is invalid.") + .addCause("%s") + .addSolution("Please check the related error message and modify.") + .build(); + + /** + * CHECK_MODULE_NAME_INVALID + */ + public static final ErrorMsg CHECK_MODULE_NAME_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("007") + .addDescription("Check module name is invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_PACKAGE_NAME_INVALID + */ + public static final ErrorMsg CHECK_PACKAGE_NAME_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("008") + .addDescription("Check package name is invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + /** + * CHECK_ENTRY_INVALID + */ + public static final ErrorMsg CHECK_ENTRY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("009") + .addDescription("Check entry is invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_ENTRY_INVALID + */ + public static final ErrorMsg CHECK_DEPENDENCY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("010") + .addDescription("Check dependency is invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * DEPENDENCY_LIST_INVALID + */ + public static final ErrorMsg DEPENDENCY_LIST_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("011") + .addDescription("dependency list is invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * ATOMICSERVICE_PRELOADS_INVALID + */ + public static final ErrorMsg ATOMICSERVICE_PRELOADS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("012") + .addDescription("Check atomicservice preloads is invalid.") + .addCause("%s") + .build(); + + /** + * ATOMICSERVICE_INVALID + */ + public static final ErrorMsg ATOMICSERVICE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("013") + .addDescription("Check atomicservice is invalid.") + .addCause("%s") + .build(); + + /** + * ATOMICSERVICE_INVALID + */ + public static final ErrorMsg TARGET_MODULE_NAME_NOT_EXIST = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("014") + .addDescription("targetModuleName is not exist.") + .addCause("%s") + .build(); + + /** + * COMPILE_SDK_INVALID + */ + public static final ErrorMsg COMPILE_SDK_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("015") + .addDescription("compile sdk is invaild.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * PROXY_DATA_URI_NOT_UNIQUE + */ + public static final ErrorMsg PROXY_DATA_URI_NOT_UNIQUE = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("016") + .addDescription("proxy data uri is not unique.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CONTINUE_TYPE_INVALID + */ + public static final ErrorMsg CONTINUE_TYPE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("017") + .addDescription("ContinueType is invalid") + .addCause("%s") + .addSolution("%s") + .build(); + + // compress error + // 可以把各个模式的统一报错归到一类去 + /** + * COMPRESS_APP_VERIFY_FAILED + */ + public static final ErrorMsg COMPRESS_APP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("23") + .addErrCode("003") + .addDescription("Compress app file verify failed.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * COMPRESS_APP_VERIFY_FAILED + */ + public static final ErrorMsg APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("001") + .addDescription("Check app atomicservice compress size failed.") + .addCause("%s") + .build(); + + /** + * CHECK_FILE_SIZE_INVALID + */ + public static final ErrorMsg CHECK_FILE_SIZE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("001") + .addDescription("File size check failed.") + .addCause("%s") + .build(); + + /** + * CHECK_FILE_SIZE_INVALID + */ + public static final ErrorMsg CHECK_ATOMIC_SERVICE_MODULE_SIZE = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("001") + .addDescription("AtomicService module size check failed.") + .addCause("%s") + .build(); + + /** + * CHECK_HAP_VERIFY_INFO_LIST_EMPTY + */ + public static final ErrorMsg CHECK_HAP_VERIFY_INFO_LIST_EMPTY = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("002") + .addDescription("The provided list of HapVerifyInfo is empty, unable to process.") + .build(); + + /** + * FILE_DELETE_FAILED + */ + public static final ErrorMsg FILE_DELETE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("002") + .addDescription("File delete failed.") + .addCause("%s") + .build(); + + /** + * HAS_GENERATE_BUILD_HASH_FAILED + */ + public static final ErrorMsg HAS_GENERATE_BUILD_HASH_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("003") + .addDescription("HasGenerateBuildHash failed.") + .addCause("%s") + .build(); + + /** + * SET_GENERATE_BUILD_HASH_FAILED + */ + public static final ErrorMsg SET_GENERATE_BUILD_HASH_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("004") + .addDescription("SetGenerateBuildHash failed.") + .addCause("%s") + .build(); + + /** + * CHECK_SUM_FAILED + */ + public static final ErrorMsg CHECK_SUM_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("005") + .addDescription("checkSum failed.") + .addCause("%s") + .build(); + + /** + * COMPRESS_APP_MODE_FORMULTI_PROJECT_FAILED + */ + public static final ErrorMsg COMPRESS_APP_MODE_FORMULTI_PROJECT_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("006") + .addDescription("compressAppModeForMultiProject failed.") + .addCause("%s") + .build(); + + /** + * HAP_ADDITION_FAILED + */ + public static final ErrorMsg HAP_ADDITION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("007") + .addDescription("hapAddition failed.") + .addCause("%s") + .build(); + //exception error + /** + * NULLPOINTER_EXCEPTION_ERROR + */ + public static final ErrorMsg NULLPOINTER_EXCEPTION_ERROR = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("xx") + .addErrCode("002") + .addDescription("NullPointerException.") + .addCause("%s") + .build(); +} -- Gitee