From 94cd11b72e0cb5212115286e8b36c67212da8656 Mon Sep 17 00:00:00 2001 From: nj1868 Date: Wed, 12 Feb 2025 10:50:13 +0800 Subject: [PATCH 1/5] update Signed-off-by: nj1868 Change-Id: Ib73ca19b2deec3c2db3296d953db74026be33e4f --- adapter/ohos/CommandParser.java | 4 +- adapter/ohos/CompressEntrance.java | 8 +- adapter/ohos/CompressVerify.java | 55 ++- adapter/ohos/Compressor.java | 103 +++-- adapter/ohos/ErrorMsg.java | 225 +++++++++ adapter/ohos/FileUtils.java | 5 +- adapter/ohos/HapVerify.java | 289 +++++++----- adapter/ohos/ModuleJsonUtil.java | 124 ++--- adapter/ohos/PackingToolErrMsg.java | 684 ++++++++++++++++++++++++++++ adapter/ohos/StringUtils.java | 55 +++ 10 files changed, 1317 insertions(+), 235 deletions(-) create mode 100644 adapter/ohos/ErrorMsg.java create mode 100644 adapter/ohos/PackingToolErrMsg.java create mode 100644 adapter/ohos/StringUtils.java diff --git a/adapter/ohos/CommandParser.java b/adapter/ohos/CommandParser.java index 8b046304..7d747f6b 100644 --- a/adapter/ohos/CommandParser.java +++ b/adapter/ohos/CommandParser.java @@ -393,7 +393,7 @@ public class CommandParser { */ public static boolean commandParser(Utility utility, String[] args) { if (args == null) { - LOG.error("CommandParser::commandParser args is null!"); + LOG.error(PackingToolErrMsg.COMMAND_PARSER_FAILED.toString("Parser args is null.")); return false; } for (int i = 0; i < args.length - 1; ++i) { @@ -405,7 +405,7 @@ public class CommandParser { ++i; } else if (CMD_PARSE_MODE.equals(key)) { if (i + PARSE_MODE_VALUE_LENGTH >= args.length) { - LOG.error("input wrong number value for --p command"); + LOG.error(PackingToolErrMsg.COMMAND_PARSER_FAILED.toString("Input wrong number value for --p command.")); return false; } utility.setParseMode(args[i + 1]); diff --git a/adapter/ohos/CompressEntrance.java b/adapter/ohos/CompressEntrance.java index dc3151de..7b093008 100644 --- a/adapter/ohos/CompressEntrance.java +++ b/adapter/ohos/CompressEntrance.java @@ -97,20 +97,20 @@ public class CompressEntrance { Utility utility = new Utility(); if (!CommandParser.commandParser(utility, args)) { - LOG.error("CompressEntrance::main exit, parser failed"); + LOG.error(PackingToolErrMsg.EXECUTE_PACKING_TOOL_FAILED.toString("command parser failed.")); ShowHelp.compressHelp(); System.exit(EXIT_STATUS_EXCEPTION); } if (!CompressVerify.commandVerify(utility)) { - LOG.error("CompressEntrance::main exit, verify failed"); + LOG.error(PackingToolErrMsg.EXECUTE_PACKING_TOOL_FAILED.toString("command verify failed.")); ShowHelp.compressHelp(); System.exit(EXIT_STATUS_EXCEPTION); } Compressor compressor = new Compressor(); if (!compressor.compressProcess(utility)) { - LOG.error("CompressEntrance::main exit, compress failed"); + LOG.error(PackingToolErrMsg.EXECUTE_PACKING_TOOL_FAILED.toString("compress failed.")); ShowHelp.compressHelp(); System.exit(EXIT_STATUS_EXCEPTION); } @@ -118,7 +118,7 @@ public class CompressEntrance { if (utility.getGenerateBuildHash()) { utility.setForceRewrite("true"); if (!compressor.compressProcess(utility)) { - LOG.error("CompressEntrance::main exit, compress failed"); + LOG.error(PackingToolErrMsg.EXECUTE_PACKING_TOOL_FAILED.toString("compress failed.")); ShowHelp.compressHelp(); System.exit(EXIT_STATUS_EXCEPTION); } diff --git a/adapter/ohos/CompressVerify.java b/adapter/ohos/CompressVerify.java index 6a4e05c9..409afc4d 100644 --- a/adapter/ohos/CompressVerify.java +++ b/adapter/ohos/CompressVerify.java @@ -91,13 +91,13 @@ public class CompressVerify { */ public static boolean commandVerify(Utility utility) { if (utility == null) { - LOG.error("CompressVerify::commandVerify utility is null."); + LOG.error(PackingToolErrMsg.COMMAND_VERIFY_FAILED.toString("commandVerify utility is null.")); return false; } if (!utility.getForceRewrite().isEmpty() && !"true".equals(utility.getForceRewrite()) && !"false".equals(utility.getForceRewrite())) { - LOG.error("CompressVerify::commandVerify forceRewrite is invalid."); + LOG.error(PackingToolErrMsg.COMMAND_VERIFY_FAILED.toString("--force must be either 'true' or 'false'.")); return false; } return commandPathVerify(utility); @@ -140,7 +140,8 @@ public class CompressVerify { case Utility.PACKAGE_NORMALIZE: return validatePackageNormalizeMode(utility); default: - LOG.error("CompressVerify::commandVerify mode is invalid."); + String errMsg = "CompressVerify::commandVerify mode is invalid."; + LOG.error(PackingToolErrMsg.COMMAND_MODE_INVALID.toString(errMsg)); return false; } } @@ -473,7 +474,8 @@ public class CompressVerify { */ private static boolean isVerifyValidInAppMode(Utility utility) { if (!checkBundleTypeConsistency(utility)) { - LOG.error("CompressVerify::isArgsValidInAppMode bundleType is inconsistent."); + String errMsg = "Check bundleType is inconsistent."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -483,50 +485,59 @@ public class CompressVerify { if (!utility.getHapPath().isEmpty() && !compatibleProcess(utility, utility.getHapPath(), utility.getFormattedHapPathList(), HAP_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInAppMode hap-path is invalid."); + String errMsg = "hap-path is invalid."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getHspPath().isEmpty() && !compatibleProcess(utility, utility.getHspPath(), utility.getFormattedHspPathList(), HSP_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInAppMode hsp-path is invalid."); + String errMsg = "hsp-path is invalid."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getPackInfoPath().isEmpty()) { - LOG.error("CompressVerify::isArgsValidInAppMode pack-info-path is empty."); + String errMsg = "pack-info-path is empty."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } File file = new File(utility.getPackInfoPath()); if (!file.isFile() || !PACK_INFO.equals(file.getName())) { - LOG.error("CompressVerify::isArgsValidInAppMode pack-info-path is invalid."); + String errMsg = "pack-info-path is invalid."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!isValidEncryptJsonFile(utility)) { - LOG.error("CompressVerify::isVerifyValidInAppMode encrypt-path is invalid."); + String errMsg = "encrypt-path is invalid."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getSignaturePath().isEmpty() && !(new File(utility.getSignaturePath())).isFile()) { - LOG.error("CompressVerify::isArgsValidInAppMode signature-path is invalid."); + String errMsg = "signature-path is invalid."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getCertificatePath().isEmpty() && !(new File(utility.getCertificatePath())).isFile()) { - LOG.error("CompressVerify::isArgsValidInAppMode certificate-path is invalid."); + String errMsg = "certificate-path is invalid."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getEntryCardPath().isEmpty() && !compatibleProcess(utility, utility.getEntryCardPath(), utility.getformattedEntryCardPathList(), PNG_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInAppMode entrycard-path is invalid."); + String errMsg = "entrycard-path is invalid."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getPackResPath().isEmpty() && !isPathValid(utility.getPackResPath(), TYPE_FILE, PACK_RES)) { - LOG.error("CompressVerify::isArgsValidInAppMode pack-res-path is invalid."); + String errMsg = "pack-res-path is invalid."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -543,21 +554,21 @@ public class CompressVerify { if (!tmpHapPathList.isEmpty()) { HapVerifyInfo hapVerifyInfo = Compressor.parseStageHapVerifyInfo(tmpHapPathList.get(0)); bundleType = hapVerifyInfo.getBundleType(); - } else { + } else if (!tmpHspPathList.isEmpty()) { HapVerifyInfo hapVerifyInfo = Compressor.parseStageHapVerifyInfo(tmpHspPathList.get(0)); bundleType = hapVerifyInfo.getBundleType(); } for (String hapPath : tmpHapPathList) { HapVerifyInfo hapVerifyInfo = Compressor.parseStageHapVerifyInfo(hapPath); if (!bundleType.equals(hapVerifyInfo.getBundleType())) { - LOG.error("bundleType is not same"); + LOG.error(PackingToolErrMsg.CHECK_BUNDLETYPE_CONSISTENCY_FAILED.toString("bundleType is not same for different modules.")); return false; } } for (String hspPath : tmpHspPathList) { HapVerifyInfo hapVerifyInfo = Compressor.parseStageHapVerifyInfo(hspPath); if (!bundleType.equals(hapVerifyInfo.getBundleType())) { - LOG.error("bundleType is not same"); + LOG.error(PackingToolErrMsg.CHECK_BUNDLETYPE_CONSISTENCY_FAILED.toString("bundleType is not same for different modules.")); return false; } } @@ -806,13 +817,13 @@ public class CompressVerify { File outFile = new File(utility.getOutPath()); if (("false".equals(utility.getForceRewrite())) && (outFile.exists())) { - LOG.error("CompressVerify::isOutPathValid out file already existed."); + LOG.error(PackingToolErrMsg.OUT_PATH_INVALID.toString("out file already existed.")); return false; } if (HAP_SUFFIX.equals(suffix)) { if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(HAP_SUFFIX)) { - LOG.error("CompressVerify::isOutPathValid out-path must end with .hap."); + LOG.error(PackingToolErrMsg.OUT_PATH_INVALID.toString("out-path must end with .hap.")); return false; } else { return true; @@ -821,7 +832,7 @@ public class CompressVerify { if (HAR_SUFFIX.equals(suffix)) { if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(HAR_SUFFIX)) { - LOG.error("CompressVerify::isOutPathValid out-path must end with .har."); + LOG.error(PackingToolErrMsg.OUT_PATH_INVALID.toString("out-path must end with .har.")); return false; } else { return true; @@ -830,7 +841,7 @@ public class CompressVerify { if (APP_SUFFIX.equals(suffix)) { if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(APP_SUFFIX)) { - LOG.error("CompressVerify::isOutPathValid out-path must end with .app."); + LOG.error(PackingToolErrMsg.OUT_PATH_INVALID.toString("out-path must end with .app.")); return false; } else { return true; @@ -839,7 +850,7 @@ public class CompressVerify { if (RES_SUFFIX.equals(suffix)) { if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(RES_SUFFIX)) { - LOG.error("CompressVerify::isOutPathValid out-path must end with .res."); + LOG.error(PackingToolErrMsg.OUT_PATH_INVALID.toString("out-path must end with .res.")); return false; } else { return true; @@ -848,7 +859,7 @@ public class CompressVerify { if (HSP_SUFFIX.equals(suffix)) { if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(HSP_SUFFIX)) { - LOG.error("CompressVerify::isOutPathValid out-path must end with .hsp."); + LOG.error(PackingToolErrMsg.OUT_PATH_INVALID.toString("out-path must end with .hsp.")); return false; } else { return true; diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index 33461812..e2bed1e5 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -348,7 +348,9 @@ public class Compressor { File outParentFile = destFile.getParentFile(); if ((outParentFile != null) && (!outParentFile.exists())) { if (!outParentFile.mkdirs()) { - LOG.error("Compressor::compressProcess create out file parent directory failed."); + String errMsg = "create out file parent directory failed."; + String solution = "Check input out-path"; + LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_FAILED.toString(errMsg, solution)); return false; } } @@ -363,10 +365,10 @@ public class Compressor { compressExcute(utility); } catch (FileNotFoundException exception) { compressResult = false; - LOG.error("Compressor::compressProcess file not found exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString(exception.getMessage())); } catch (BundleException ex) { compressResult = false; - LOG.error("Compressor::compressProcess Bundle exception: " + ex.getMessage()); + LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_EXCEPTION.toString(ex.getMessage())); } finally { closeZipOutputStream(); Utility.closeStream(zipOut); @@ -376,14 +378,20 @@ public class Compressor { if (compressResult && !checkAppAtomicServiceCompressedSizeValid(utility)) { compressResult = false; - LOG.error("Compressor::compressProcess check atomic service size fail."); + String errMsg = "Execut compress failed."; + String solution = "Please check the related error message and modify."; + LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_FAILED.toString(errMsg, solution)); } // if compress failed, delete out file. if (!compressResult) { - LOG.error("Compressor::compressProcess compress failed."); + String errMsg = "Execut compress failed."; + String solution = "Please check the related error message and modify."; + LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_FAILED.toString(errMsg, solution)); if (!destFile.delete()) { - LOG.error("Compressor::compressProcess delete dest file failed."); + errMsg = "Delete out file failed."; + solution = "Try to close the out file using programme"; + LOG.error(PackingToolErrMsg.FILE_DELETE_FAILED.toString(errMsg, solution)); } } return compressResult; @@ -722,7 +730,7 @@ public class Compressor { } if (hapVerifyInfos.isEmpty()) { - LOG.error("Compressor::checkAppAtomicServiceCompressedSizeValid no hapVerifyInfo."); + LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString("no hapVerifyInfo")); return false; } @@ -737,10 +745,13 @@ public class Compressor { return HapVerify.checkFileSizeIsValid(hapVerifyInfos); } catch (IOException exception) { - LOG.error("Compressor::checkAppAtomicServiceCompressedSizeValid file not found exception: " + exception.getMessage()); + String errMsg = "file not found exception: " + exception.getMessage(); + LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString(errMsg)); return false; } catch (BundleException ignored) { - LOG.error("Compressor::checkAppAtomicServiceCompressedSizeValid Bundle exception."); + //TODO + String errMsg = "Bundle exception."; + LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString(errMsg)); return false; } } @@ -1192,7 +1203,8 @@ public class Compressor { compressPackinfoIntoHap(hapPathItem, hapTempPath, utility.getPackInfoPath(), utility.getCompressLevel()); } catch (IOException e) { - LOG.error("Compressor::compressAppMode compress pack.info into hap failed: " + e.getMessage()); + LOG.error(PackingToolErrMsg.COMPRESS_APP_IO_EXCEPTION.toString("compress pack.info into hap failed, " + + e.getMessage())); throw new BundleException("Compressor::compressAppMode compress pack.info into hap failed."); } } @@ -1209,14 +1221,15 @@ public class Compressor { compressPackinfoIntoHap(hspPathItem, hspTempPath, utility.getPackInfoPath(), utility.getCompressLevel()); } catch (IOException e) { - LOG.error("Compressor::compressAppMode compress pack.info into hsp failed: " + e.getMessage()); + LOG.error(PackingToolErrMsg.COMPRESS_APP_IO_EXCEPTION.toString("compress pack.info into hsp failed, " + + e.getMessage())); throw new BundleException("Compressor::compressAppMode compress pack.info into hsp failed."); } } // check hap is valid if (!checkHapIsValid(fileList, utility.getSharedApp())) { - LOG.error("Compressor::compressFile verify failed, check version, " + - "apiVersion,moduleName,packageName."); + 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."); } @@ -1246,7 +1259,8 @@ public class Compressor { //pack encrypt.json file packEncryptJsonFile(utility); } catch (BundleException e) { - LOG.error("Compressor::compressAppMode compress failed. msg: " + e.getMessage()); + String solution = "Modified according to related verification errors."; + LOG.error(PackingToolErrMsg.COMPRESS_APP_FAILED.toString(e.getMessage(), solution)); throw new BundleException("Compressor::compressAppMode compress failed."); } finally { // delete temp file @@ -1813,7 +1827,7 @@ public class Compressor { } append.closeEntry(); } catch (IOException exception) { - LOG.error("Compressor::compressPackinfoIntoHap io exception."); + LOG.error(PackingToolErrMsg.COMPRESS_FILE_EXCEPTION.toString("compress PackInfo into hap io exception" + exception.getMessage())); throw new BundleException("Compressor::compressPackinfoIntoHap io exception."); } finally { sourceHapFile.close(); @@ -2213,8 +2227,7 @@ public class Compressor { } zipCreator.writeTo(zipOut); } catch (IOException | InterruptedException | ExecutionException e) { - String errMsg = "Compressor::compressNativeLibsParallel exception: " + e.getMessage(); - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.COMPRESS_PARALLEL_EXCEPTION.toString(e.getMessage())); throw new BundleException(errMsg); } } @@ -2237,7 +2250,7 @@ public class Compressor { try { return Files.newInputStream(file.toPath()); } catch (IOException e) { - LOG.error("Compressor::compressNativeLibsParallel exception: " + e.getMessage()); + LOG.error(PackingToolErrMsg.COMPRESS_PARALLEL_EXCEPTION.toString(e.getMessage())); return null; } }; @@ -2464,10 +2477,10 @@ public class Compressor { count = bufferedInputStream.read(data); } } catch (FileNotFoundException ignored) { - throw new BundleException("CoompressFile failed."); + throw new BundleException("CompressFile failed."); } catch (IOException exception) { - LOG.error("Compressor::compressFile io exception: " + exception.getMessage()); - throw new BundleException("CoompressFile failed."); + LOG.error(PackingToolErrMsg.COMPRESS_FILE_EXCEPTION.toString(exception.getMessage())); + throw new BundleException("CompressFile failed."); } finally { Utility.closeStream(bufferedInputStream); Utility.closeStream(fileInputStream); @@ -2498,7 +2511,7 @@ public class Compressor { } } } catch (IOException exception) { - LOG.error("Compressor::isModuleHap io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("is moduleHap io exception:" + exception.getMessage())); throw new BundleException("Compressor::isModuleHap failed."); } finally { Utility.closeStream(zipInput); @@ -2528,10 +2541,10 @@ public class Compressor { count = fileInputStream.read(buffer); } } catch (FileNotFoundException ignored) { - LOG.error("Compressor::getCrcFromFile FileNotFoundException : " + ignored.getMessage()); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("getCrcFromFile FileNotFoundException: " + exception.getMessage())); throw new BundleException("Get Crc from file failed: " + file.getName()); } catch (IOException exception) { - LOG.error("Compressor::getCrcFromFile io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("getCrcFromFile io exception: " + exception.getMessage())); throw new BundleException("Get Crc from file failed."); } finally { Utility.closeStream(fileInputStream); @@ -2656,7 +2669,7 @@ public class Compressor { zipOut.putArchiveEntry(entry); zipOut.write(trimJson); } catch (Exception exception) { - LOG.error("Compressor::jsonSpecialProcess io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.JSON_SPECIAL_PROCESS_FAILED.toString(exception.getMessage())); LOG.warning("Json format err: " + srcFile.getAbsolutePath()); return false; } finally { @@ -2796,7 +2809,7 @@ public class Compressor { } } } catch (IOException exception) { - LOG.error("Compressor::parseCompressNativeLibs io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.PARSE_COMPRESS_NATIVE_LIBS_FAILED.toString(exception.getMessage())); throw new BundleException("Parse compress native libs failed."); } } @@ -2810,21 +2823,21 @@ public class Compressor { zipOut.flush(); } } catch (IOException exception) { - LOG.error("Compressor::closeZipOutputStream flush exception " + exception.getMessage()); + LOG.error(PackingToolErrMsg.CLOSE_ZIP_OUTPUT_STREAM_EXPECTION.toString("flush exception: " + exception.getMessage())) } try { if (zipOut != null && isEntryOpen) { zipOut.closeArchiveEntry(); } } catch (IOException exception) { - LOG.error("Compressor::closeZipOutputStream close entry io exception " + exception.getMessage()); + LOG.error(PackingToolErrMsg.CLOSE_ZIP_OUTPUT_STREAM_EXPECTION.toString("close entry io exception: " + exception.getMessage())) } try { if (zipOut != null) { zipOut.finish(); } } catch (IOException exception) { - LOG.error("Compressor::closeZipOutputStream finish exception " + exception.getMessage()); + LOG.error(PackingToolErrMsg.CLOSE_ZIP_OUTPUT_STREAM_EXPECTION.toString("finish exception: " + exception.getMessage())) } } @@ -2853,7 +2866,7 @@ public class Compressor { break; } } catch (IOException exception) { - LOG.error("Compressor::parseDeviceType io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.PARSE_DEVICE_TYPE_FAILED.toString(exception.getMessage())); throw new BundleException("Parse device type failed."); } } @@ -2870,19 +2883,19 @@ public class Compressor { List hapVerifyInfos = new ArrayList<>(); for (String hapPath : fileLists) { if (hapPath.isEmpty()) { - LOG.error("Compressor::checkHapIsValid input wrong hap file."); - throw new BundleException("Compressor::checkHapIsValid input wrong hap file."); + LOG.error(PackingToolErrMsg.INVALID_HAP_FILE.toString("Input wrong hap or hsp file.")); + throw new BundleException("Compressor::checkHapIsValid input wrong hap or hsp file."); } File srcFile = new File(hapPath); String fileStr = srcFile.getName(); if (fileStr.isEmpty()) { - LOG.error("Compressor::checkHapIsValid get file name failed."); + LOG.error(PackingToolErrMsg.INVALID_HAP_FILE.toString("get file name failed.")); throw new BundleException("Compressor::checkHapIsValid get file name failed."); } if (!fileStr.toLowerCase(Locale.ENGLISH).endsWith(HAP_SUFFIX) && !fileStr.toLowerCase(Locale.ENGLISH).endsWith(HSP_SUFFIX)) { - LOG.error("Compressor::checkHapIsValid input wrong hap file."); - throw new BundleException("Compressor::checkHapIsValid input wrong hap file."); + LOG.error(PackingToolErrMsg.INVALID_HAP_FILE.toString("Input wrong hap or hsp file.")); + throw new BundleException("Compressor::checkHapIsValid input wrong hap or hsp file."); } if (isModuleHap(hapPath)) { hapVerifyInfos.add(parseStageHapVerifyInfo(hapPath)); @@ -2907,8 +2920,9 @@ public class Compressor { for (HapVerifyInfo hapVerifyInfo : hapVerifyInfos) { String bundleType = hapVerifyInfo.getBundleType(); if (TYPE_SHARED.equals(bundleType)) { - LOG.error("Compressor::checkHapIsValid only one item can be entered in the -hsp-path" + - " when bundleType is shared."); + String cause = "Only one item can be entered in the -hsp-path when bundleType is 'shared'."; + String solution = "Ensure that only one item entered in the -hsp-path when bundleType is 'shared'"; + LOG.error(PackingToolErrMsg.CHECK_BUNDLETYPE_INVALID.toString(cause, solution)); return false; } } @@ -2987,7 +3001,8 @@ public class Compressor { hapVerifyInfo.setResourceMap(FileUtils.getProfileJson(zipFile)); hapVerifyInfo.setProfileStr(FileUtils.getFileStringFromZip(MODULE_JSON, zipFile)); } catch (IOException e) { - LOG.error("FileUtil::parseStageHapVerifyInfo file not available."); + LOG.error(PackingToolErrMsg.READ_STAGE_HAP_VERIFY_INFO_FAILED.toString( + "parse stage hap verify info file not available.")); throw new BundleException("FileUtil::parseStageHapVerifyInfo file not available."); } finally { Utility.closeStream(zipFile); @@ -3010,8 +3025,10 @@ public class Compressor { zipFile = new ZipFile(srcFile); hapVerifyInfo.setProfileStr(FileUtils.getFileStringFromZip(CONFIG_JSON, zipFile)); } catch (IOException e) { + LOG.error(PackingToolErrMsg.READ_FA_HAP_VERIFY_INFO_FAILED.toString( + "parse FA hap verify info file not available.")); LOG.error("FileUtil::parseStageHapVerifyInfo file not available."); - throw new BundleException("FileUtil::parseStageHapVerifyInfo file not available."); + throw new BundleException("FileUtil::parseFAHapVerifyInfo file not available."); } finally { Utility.closeStream(zipFile); } @@ -3158,11 +3175,15 @@ public class Compressor { private static boolean checkSharedAppIsValid(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos.isEmpty()) { - LOG.error("no module included"); + String cause = "no module included."; + String solution = "Ensure the Shared App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); return false; } if (hapVerifyInfos.size() > SHARED_APP_HSP_LIMIT) { - LOG.error("Shared app only can contain one module"); + String cause = "Shared app only can contain one module."; + String solution = "Please ensure that there is only one module in Shared App."; + LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); return false; } for (HapVerifyInfo hapVerifyInfo : hapVerifyInfos) { diff --git a/adapter/ohos/ErrorMsg.java b/adapter/ohos/ErrorMsg.java new file mode 100644 index 00000000..3acf0ca7 --- /dev/null +++ b/adapter/ohos/ErrorMsg.java @@ -0,0 +1,225 @@ +/* + * Copyright (c) 2025-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package ohos; + import java.util.ArrayList; + import java.util.List; + import java.util.Locale; + import java.util.MissingFormatArgumentException; + + /** + * ErrorMsg + * + * @since 2025/01/06 + */ + public class ErrorMsg { + private static final Log LOG = new Log(ErrorMsg.class.toString()); + + private static final String PACKING_TOOL_SUB_SYSTEM_CODE = "100"; + + private final String code; + + private final String description; + + private final String cause; + + private final String position; + + private final List solutions; + + private MoreInfo moreInfo; + + /** + * ErrorMsg constructor + * + * @param code code + * @param description description + * @param cause cause + * @param position position + * @param solutions solutions + */ + public ErrorMsg(String code, String description, String cause, + String position, List solutions) { + this.code = code; + this.description = description; + this.cause = cause; + this.position = position; + this.solutions = solutions; + this.moreInfo = new MoreInfo(); + } + + /** + * getPackingToolErrBuilder + * + * @return Builder + */ + public static Builder getPackingToolErrBuilder() { + return new Builder(PACKING_TOOL_SUB_SYSTEM_CODE); + } + + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append(code) + .append(" ") + .append(description) + .append(System.lineSeparator()) + .append("Error Message: ") + .append(cause) + .append(System.lineSeparator()); + + if (!StringUtils.isEmpty(position)) { + sb.append(" At ").append(position).append(System.lineSeparator()); + } + + if (solutions != null && !solutions.isEmpty()) { + sb.append(System.lineSeparator()).append("* Try the following: ").append(System.lineSeparator()); + for (String s : solutions) { + sb.append(" > ").append(s).append(System.lineSeparator()); + } + } + return sb.toString(); + } + + /** + * to String + * + * @param args args + * @return String + */ + public String toString(Object... args) { + try { + return String.format(Locale.ROOT, this.toString(), args); + } catch (MissingFormatArgumentException e) { + //log.error("args format failed: " + args); + //TODO args不确定 + LOG.error("args format failed: " + args); + return this.toString(); + } + } + + static class MoreInfo { + private String cn; + + private String en; + } + + /** + * Builder + * + * @since 2025/01/06 + */ + public static class Builder { + private String sysCode; + + private String errCode; + + private String typeCode; + + private String description; + + private String cause; + + private String position; + + private List solutions = new ArrayList<>(); + + /** + * Builder Constructor + * + * @param sysCode sysCode + */ + public Builder(String sysCode) { + this.sysCode = sysCode; + } + + /** + * addErrCode + * + * @param errCode errCode + * @return Builder + */ + public Builder addErrCode(String errCode) { + this.errCode = errCode; + return this; + } + + /** + * addTypeCode + * + * @param typeCode typeCode + * @return Builder + */ + public Builder addTypeCode(String typeCode) { + this.typeCode = typeCode; + return this; + } + + /** + * addDescription + * + * @param description description + * @return Builder + */ + public Builder addDescription(String description) { + this.description = description; + return this; + } + + /** + * addCause + * + * @param cause cause + * @return Builder + */ + public Builder addCause(String cause) { + this.cause = cause; + return this; + } + + /** + * addPosition + * + * @param position position + * @return Builder + */ + public Builder addPosition(String position) { + this.position = position; + return this; + } + + /** + * addSolution + * + * @param solution solution + * @return Builder + */ + public Builder addSolution(String solution) { + this.solutions.add(solution); + return this; + } + + /** + * build + * + * @return ErrorMsg + */ + public ErrorMsg build() { + return new ErrorMsg(sysCode + typeCode + errCode, description, cause, position, solutions); + } + } + } + \ No newline at end of file diff --git a/adapter/ohos/FileUtils.java b/adapter/ohos/FileUtils.java index 3064828d..19541d85 100644 --- a/adapter/ohos/FileUtils.java +++ b/adapter/ohos/FileUtils.java @@ -445,7 +445,7 @@ class FileUtils { } } } catch (IOException e) { - LOG.error("FileUtil::getProfileJson IOException: " + e.getMessage()); + LOG.error(PackingToolErrMsg.GET_JSON_PROFILE_FAILED.toString(e.getMessage())); throw new BundleException("FileUtil::getProfileJson failed."); } return resourceMap; @@ -598,7 +598,8 @@ class FileUtils { if (file.exists() && file.isFile()) { return file.length(); } - LOG.error("input " + filePath + " is not a valid file."); + String errMsg = "input " + filePath + " is not a valid file."; + LOG.error(PackingToolErrMsg.GET_FILE_SIZE_FAILED.toString(errMsg)); return 0; } diff --git a/adapter/ohos/HapVerify.java b/adapter/ohos/HapVerify.java index 8f485718..d85e3e71 100644 --- a/adapter/ohos/HapVerify.java +++ b/adapter/ohos/HapVerify.java @@ -58,12 +58,15 @@ class HapVerify { */ public static boolean checkHapIsValid(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos == null || hapVerifyInfos.isEmpty()) { - LOG.error("HapVerify::checkHapIsValid hapVerifyInfos is empty"); + String cause = "no module included."; + String solution = "Ensure the Shared App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); return false; } // check app variable is same if (!checkAppFieldsIsSame(hapVerifyInfos)) { - LOG.error("some app variable is different."); + String cause = "some app variable is different."; + LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(cause)); return false; } // check moduleName is valid @@ -72,7 +75,8 @@ class HapVerify { } // check package is valid if (!checkPackageNameIsValid(hapVerifyInfos)) { - LOG.error("packageName duplicated."); + String errMsg = "packageName duplicated."; + LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } // check entry is valid @@ -81,12 +85,14 @@ class HapVerify { } // check dependency is valid if (!checkDependencyIsValid(hapVerifyInfos)) { - LOG.error("module dependency is invalid."); + String errMsg = "module dependency is invalid."; + LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } // check atomic service is valid if (!checkAtomicServiceIsValid(hapVerifyInfos)) { - LOG.error("checkAtomicServiceIsValid failed."); + String errMsg = "checkAtomicServiceIsValid failed."; + LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } // check ability is valid @@ -95,15 +101,18 @@ class HapVerify { } // check targetModuleName if (!checkTargetModuleNameIsExisted(hapVerifyInfos)) { - LOG.error("target module is not found."); + String errMsg = "target module is not found."; + LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } if (!checkCompileSdkIsValid(hapVerifyInfos)) { - LOG.error("compile sdk config is not same."); + String errMsg = "compile sdk config is not same."; + LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } if (!checkProxyDataUriIsUnique(hapVerifyInfos)) { - LOG.error("uris in proxy data are not unique."); + String errMsg = "uris in proxy data are not unique."; + LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } if (!checkContinueTypeIsValid(hapVerifyInfos)) { @@ -165,12 +174,17 @@ class HapVerify { List typeList2 = hapVerifyInfo2.getContinueTypeMap().values().stream() .flatMap(Collection::stream).collect(Collectors.toList()); if (!Collections.disjoint(typeList, typeList2)) { - LOG.error("Module: (" + hapVerifyInfo.getModuleName() + ") and Module: (" + - hapVerifyInfo2.getModuleName() + ") have same deviceType and continueType."); - LOG.error("Module: (" + hapVerifyInfo.getModuleName() + ") have deviceType: " + - hapVerifyInfo.getDeviceType() + " and continueType: " + typeList); - LOG.error("Another Module: (" + hapVerifyInfo2.getModuleName() + ") have deviceType: " + - hapVerifyInfo2.getDeviceType() + " and continueType: " + typeList2); + String cause = "Conflict detected between modules due to overlapping deviceType and continueType:\n" + + "- Module: (" + hapVerifyInfo.getModuleName() + ") with deviceType: " + + hapVerifyInfo.getDeviceType() + " and continueType: " + typeList + "\n" + + "- Module: (" + hapVerifyInfo2.getModuleName() + ") with deviceType: " + + hapVerifyInfo2.getDeviceType() + " and continueType: " + typeList2; + + String solution = "Ensure that the deviceType and continueType fields in these modules are distinct. " + + "Update either (" + hapVerifyInfo.getModuleName() + ") or (" + hapVerifyInfo2.getModuleName() + + ") to avoid overlap."; + + LOG.error(PackingToolErrMsg.CONTINUE_TYPE_INVALID.toString(cause, solution)); return false; } return true; @@ -185,28 +199,38 @@ class HapVerify { */ public static boolean checkSharedApppIsValid(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos == null || hapVerifyInfos.isEmpty()) { - LOG.error("HapVerify::checkSharedApppIsValid hapVerifyInfos is empty."); + String cause = "no module included."; + String solution = "Ensure the shared App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.VERIFY_SHARED_APP_INVALID.toString(cause, solution)); return false; } String moduleName = hapVerifyInfos.get(0).getModuleName(); for (HapVerifyInfo hapVerifyInfo : hapVerifyInfos) { if (!moduleName.equals(hapVerifyInfo.getModuleName())) { - LOG.error("HapVerify::checkSharedApppIsValid module name is different."); + String cause = "module name is different."; + String solution = "Ensure that all module have the same module name."; + LOG.error(PackingToolErrMsg.VERIFY_SHARED_APP_INVALID.toString(cause, solution)); return false; } if (!hapVerifyInfo.getDependencyItemList().isEmpty()) { - LOG.error("HapVerify::checkSharedApppIsValid shared hsp cannot depend on other modules."); + String cause = "Shared app can not depend on other modules."; + String solution = "Ensure module does not contain dependencies."; + LOG.error(PackingToolErrMsg.VERIFY_SHARED_APP_INVALID.toString(cause, solution)); return false; } if (!TYPE_SHARED.equals(hapVerifyInfo.getModuleType())) { - LOG.error("HapVerify::checkSharedApppIsValid module type is not shared app."); + String cause = "Module type is not a shared app."; + String solution = "Ensure module type is 'shared' for all module."; + LOG.error(PackingToolErrMsg.VERIFY_SHARED_APP_INVALID.toString(cause, solution)); return false; } } for (int i = 0; i < hapVerifyInfos.size(); i++) { for (int j = i + 1; j < hapVerifyInfos.size(); j++) { if (!checkDuplicatedIsValid(hapVerifyInfos.get(i), hapVerifyInfos.get(j))) { - LOG.error("HapVerify::checkSharedApppIsValid duplicated module."); + String cause = "There are duplicated modules in the packing file."; + String solution = "Ensure that there are no duplicated modules."; + LOG.error(PackingToolErrMsg.VERIFY_SHARED_APP_INVALID.toString(cause, solution)); return false; } } @@ -223,7 +247,9 @@ class HapVerify { */ private static boolean checkAppFieldsIsSame(List hapVerifyInfos) { if (hapVerifyInfos.isEmpty()) { - LOG.error("HapVerify::checkAppVariableIsSame failed, hapVerifyInfos is empty."); + String cause = "no module included."; + String solution = "Ensure the Shared App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); return false; } HapVerifyInfo verifyInfo = hapVerifyInfos.get(0); @@ -297,13 +323,19 @@ class HapVerify { for (HapVerifyInfo hapInfo : hapVerifyInfos) { if (hap.getVersion().minCompatibleVersionCode != hapInfo.getVersion().minCompatibleVersionCode || hap.getApiVersion().getTargetApiVersion() != hapInfo.getApiVersion().getTargetApiVersion()) { - LOG.error("hap minCompatibleVersionCode or targetApiVersion different"); + String errMsg = "hap minCompatibleVersionCode or targetApiVersion different."; + String solution = "Ensure that all module.json files have the same 'minCompatibleVersionCode' and 'targetApiVersion' setting."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(errMsg, solution)); return false; } } if (hap.getVersion().minCompatibleVersionCode < minCompatibleVersionCode || hap.getApiVersion().getTargetApiVersion() < targetApiVersion) { - LOG.error("minCompatibleVersionCode or targetApiVersion property hap less than hsp"); + String cause = "The minCompatibleVersionCode or targetApiVersion value in the module.json file of some hap files " + + "is less than the other hap's minCompatibleVersionCode or targetApiVersion."; + String solution = "Ensure that all hap minCompatibleVersionCode and targetApiVersion values" + + "are greater than or equal to other hap's minCompatibleVersionCode or targetApiVersion."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); return false; } return true; @@ -312,20 +344,27 @@ class HapVerify { private static boolean appFieldsIsSame(VerifyCollection verifyCollection, HapVerifyInfo hapVerifyInfo) { if (hapVerifyInfo.getBundleName().isEmpty() || !verifyCollection.bundleName.equals(hapVerifyInfo.getBundleName())) { - LOG.error("input module bundleName is different."); + String errMsg = "Input module bundleName is different."; + String solution = "Check if the bundleName is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (!verifyCollection.getBundleType().equals(hapVerifyInfo.getBundleType())) { - LOG.error("input module bundleType is different."); + String errMsg = "Input module bundleType is different."; + String solution = "Check if the bundleType is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (verifyCollection.versionCode != hapVerifyInfo.getVersion().versionCode) { - LOG.error("input module versionCode is different."); + String errMsg = "Input module versionCode is different."; + String solution = "Check if the versionCode is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (verifyCollection.compatibleApiVersion != hapVerifyInfo.getApiVersion().getCompatibleApiVersion()) { - LOG.error("input module minApiVersion is different."); - return false; + String errMsg = "Input module minApiVersion is different."; + String solution = "Check if the minApiVersion is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); } if (!verifyCollection.releaseType.equals(hapVerifyInfo.getApiVersion().getReleaseType())) { if (verifyCollection.getModuleType().equals(TYPE_SHARED) || @@ -333,27 +372,35 @@ class HapVerify { LOG.warning("Module: (" + verifyCollection.getModuleName() + ") and Module: (" + hapVerifyInfo.getModuleName() + ") has different releaseType."); } else { - LOG.error("input module releaseType is different."); - LOG.error("Solutions: > Check if the releaseType is the same in different modules."); + String errMsg = "input module releaseType is different."; + String solution = "Check if the releaseType is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } } if (!verifyCollection.targetBundleName.equals(hapVerifyInfo.getTargetBundleName())) { - LOG.error("targetBundleName is different."); + String errMsg = "Input targetBundleName is different."; + String solution = "Check if the targetBundleName is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (verifyCollection.targetPriority != hapVerifyInfo.getTargetPriority()) { - LOG.error("targetPriority is different."); + String errMsg = "Input targetPriority is different."; + String solution = "Check if the targetPriority is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (verifyCollection.debug != hapVerifyInfo.isDebug()) { - LOG.error("debug is different."); - LOG.error("Solutions: > Check if the debug type is the same in different modules."); + String errMsg = "Input debug is different."; + String solution = "Check if the debug setting is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } if (isEntryOrFeature(verifyCollection.getModuleType()) && isEntryOrFeature(hapVerifyInfo.getModuleType())) { if (!verifyCollection.getMultiAppMode().equals(hapVerifyInfo.getMultiAppMode())) { - LOG.error("multiAppMode is different."); + String errMsg = "Input multiAppMode is different."; + String solution = "Check if the multiAppMode is the same in different modules."; + LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } } @@ -383,29 +430,30 @@ class HapVerify { private static boolean checkModuleNameIsValid(List hapVerifyInfos) throws BundleException { for (int i = 0; i < hapVerifyInfos.size() - 1; ++i) { if (hapVerifyInfos.get(i).getModuleName().isEmpty()) { - LOG.error("HapVerify::checkModuleNameIsValid should not be empty."); + String cause = "Verify hap infos is empty."; + String solution = "Ensure that each HAP file contains a valid module name field before verification."; + LOG.error(PackingToolErrMsg.CHECK_MODULE_NAME_INVALID.toString(cause, solution)); throw new BundleException("HapVerify::checkModuleNameIsValid should not be empty."); } for (int j = i + 1; j < hapVerifyInfos.size(); ++j) { if (hapVerifyInfos.get(i).getModuleName().equals(hapVerifyInfos.get(j).getModuleName()) && !checkDuplicatedIsValid(hapVerifyInfos.get(i), hapVerifyInfos.get(j))) { - LOG.error("Module: (" + hapVerifyInfos.get(i).getModuleName() + ") and Module: (" + + String cause = "Module: (" + hapVerifyInfos.get(i).getModuleName() + ") and Module: (" + hapVerifyInfos.get(j).getModuleName() + ") have the same moduleName, " + - "please check deviceType or distroFilter of the module."); - LOG.error("Module: " + hapVerifyInfos.get(i).getModuleName() + " has deviceType " - + hapVerifyInfos.get(i).getDeviceType() + "."); - LOG.error("Another Module: " + hapVerifyInfos.get(j).getModuleName() + " has deviceType " - + hapVerifyInfos.get(j).getDeviceType() + "."); + "please check deviceType or distroFilter of the module.\n" + "Module: " + hapVerifyInfos.get(i).getModuleName() + " has deviceType " + + hapVerifyInfos.get(i).getDeviceType() + ".\n" + "Another Module: " + hapVerifyInfos.get(j).getModuleName() + " has deviceType " + + hapVerifyInfos.get(j).getDeviceType() + "."; if (!EMPTY_STRING.equals(hapVerifyInfos.get(i).getDistroFilter().dump())) { - LOG.error("Module: " + hapVerifyInfos.get(i).getModuleName() + " DistroFilter is : " - + hapVerifyInfos.get(i).getDistroFilter().dump() + "."); + cause += "\n" + "Module: " + hapVerifyInfos.get(i).getModuleName() + " DistroFilter is : " + + hapVerifyInfos.get(i).getDistroFilter().dump() + "."; } if (!EMPTY_STRING.equals(hapVerifyInfos.get(j).getDistroFilter().dump())) { - LOG.error("Another Module: " + hapVerifyInfos.get(j).getModuleName() + " DistroFilter is " - + hapVerifyInfos.get(j).getDistroFilter().dump() + "."); + cause += "\n" +"Another Module: " + hapVerifyInfos.get(j).getModuleName() + " DistroFilter is " + + hapVerifyInfos.get(j).getDistroFilter().dump() + "."; } - LOG.error("Solution: Make sure the module name is valid and unique."); - LOG.error("Reference: " + REFERENCE_LINK + "."); + String solution = "Solution: Make sure the module name is valid and unique.\n" + + "Reference: " + REFERENCE_LINK + "."; + LOG.error(PackingToolErrMsg.CHECK_MODULE_NAME_INVALID.toString(cause, solution)); return false; } } @@ -428,23 +476,22 @@ class HapVerify { for (int j = i + 1; j < hapVerifyInfos.size(); ++j) { if (hapVerifyInfos.get(i).getPackageName().equals(hapVerifyInfos.get(j).getPackageName()) && !checkDuplicatedIsValid(hapVerifyInfos.get(i), hapVerifyInfos.get(j))) { - LOG.error("Module: (" + hapVerifyInfos.get(i).getModuleName() + ") and Module: (" + - hapVerifyInfos.get(j).getModuleName() + ") have the same packageName, " + - "please check deviceType or distroFilter of the module."); - LOG.error("Module: " + hapVerifyInfos.get(i).getModuleName() + " has deviceType " - + hapVerifyInfos.get(i).getDeviceType() + "."); - LOG.error("Another Module: " + hapVerifyInfos.get(j).getModuleName() + " has deviceType " - + hapVerifyInfos.get(j).getDeviceType() + "."); + String cause = "Module: (" + hapVerifyInfos.get(i).getModuleName() + ") and Module: (" + + hapVerifyInfos.get(j).getModuleName() + ") have the same packageName, " + + "please check deviceType or distroFilter of the module.\n" + "Module: " + hapVerifyInfos.get(i).getModuleName() + " has deviceType " + + hapVerifyInfos.get(i).getDeviceType() + ".\n" + "Another Module: " + hapVerifyInfos.get(j).getModuleName() + " has deviceType " + + hapVerifyInfos.get(j).getDeviceType() + "."; if (!EMPTY_STRING.equals(hapVerifyInfos.get(i).getDistroFilter().dump())) { - LOG.error("Module: " + hapVerifyInfos.get(i).getModuleName() + " DistroFilter is : " + - hapVerifyInfos.get(i).getDistroFilter().dump() + "."); + cause += "\n" + "Module: " + hapVerifyInfos.get(i).getModuleName() + " DistroFilter is : " + + hapVerifyInfos.get(i).getDistroFilter().dump() + "."; } if (!EMPTY_STRING.equals(hapVerifyInfos.get(j).getDistroFilter().dump())) { - LOG.error("Another Module: " + hapVerifyInfos.get(j).getModuleName() + " DistroFilter is " + - hapVerifyInfos.get(j).getDistroFilter().dump() + "."); + cause += "\n" + "Another Module: " + hapVerifyInfos.get(j).getModuleName() + " DistroFilter is " + + hapVerifyInfos.get(j).getDistroFilter().dump() + "."; } - LOG.error("Solution: Make sure package name is valid and unique."); - LOG.error("Reference: " + REFERENCE_LINK + "."); + String solution = "Solution: Make sure package name is valid and unique.\n" + + "Reference: " + REFERENCE_LINK + "."; + LOG.error(PackingToolErrMsg.CHECK_PACKAGE_NAME_INVALID.toString(cause, solution)); return false; } } @@ -521,11 +568,11 @@ class HapVerify { return true; } if (nonOverlayHap.isEmpty()) { - LOG.error("target modules are needed to pack with overlay module."); + LOG.error(PackingToolErrMsg.TARGET_MODULE_NAME_NOT_EXIST.toString("target modules are needed to pack with overlay module.")); return false; } if (!moduleList.containsAll(targetModuleList)) { - LOG.error("target modules are needed to pack with overlay module."); + LOG.error(PackingToolErrMsg.TARGET_MODULE_NAME_NOT_EXIST.toString("target modules are needed to pack with overlay module.")); return false; } @@ -535,13 +582,17 @@ class HapVerify { private static boolean checkCompileSdkIsValid(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos.isEmpty()) { - LOG.error("hapVerifyInfos is empty"); + String cause = "no module included."; + String solution = "Ensure the Shared App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_APP_MODE_FAILED.toString(cause, solution)); return false; } String compileSdkType = hapVerifyInfos.get(0).getCompileSdkType(); for (HapVerifyInfo info : hapVerifyInfos) { if (!compileSdkType.equals(info.getCompileSdkType())) { - LOG.error("compile sdk type is not same."); + String cause = "Compile sdk type is not the same for all modules."; + String solution = "Ensure that all modules the same complile sdk type."; + LOG.error(PackingToolErrMsg.COMPILE_SDK_INVALID.toString(cause, solution)); return false; } } @@ -550,15 +601,18 @@ class HapVerify { private static boolean checkProxyDataUriIsUnique(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos.isEmpty()) { - LOG.error("hapVerifyInfos is empty"); + String cause = "no module included."; + String solution = "Ensure the Shared App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_APP_MODE_FAILED.toString(cause, solution)); return false; } Set uriSet = new HashSet<>(); for (HapVerifyInfo info : hapVerifyInfos) { for (String uri : info.getProxyDataUris()) { if (uriSet.contains(uri)) { - LOG.error("uri " + uri + " in proxy data is duplicated"); - LOG.error("Solutions: > Check if the uri in proxyData is unique in different modules."); + String cause = "uri:" + uri + " in proxyData is duplicated"; + String solution = "Ensure that the uri in proxyData is unique across different modules."; + LOG.error(PackingToolErrMsg.PROXY_DATA_URI_NOT_UNIQUE.toString(cause, solution)); return false; } else { uriSet.add(uri); @@ -595,23 +649,23 @@ class HapVerify { for (int i = 0; i < entryHapVerifyInfos.size() - 1; ++i) { for (int j = i + 1; j < entryHapVerifyInfos.size(); ++j) { if (!checkDuplicatedIsValid(entryHapVerifyInfos.get(i), entryHapVerifyInfos.get(j))) { - LOG.error("Module: (" + entryHapVerifyInfos.get(i).getModuleName() + ") and Module: (" + + String cause = "Module: (" + entryHapVerifyInfos.get(i).getModuleName() + ") and Module: (" + entryHapVerifyInfos.get(j).getModuleName() + ") are entry, " + - "please check deviceType or distroFilter of the module."); - LOG.error("Module: " + entryHapVerifyInfos.get(i).getModuleName() + " has deviceType " - + entryHapVerifyInfos.get(i).getDeviceType() + "."); - LOG.error("Another Module: " + entryHapVerifyInfos.get(j).getModuleName() + " has deviceType " - + entryHapVerifyInfos.get(j).getDeviceType() + "."); + "please check deviceType or distroFilter of the module.\n" + "Module: " + entryHapVerifyInfos.get(i).getModuleName() + " has deviceType " + + entryHapVerifyInfos.get(i).getDeviceType() + ".\n" + "Another Module: " + entryHapVerifyInfos.get(j).getModuleName() + " has deviceType " + + entryHapVerifyInfos.get(j).getDeviceType() + "."; + if (!EMPTY_STRING.equals(entryHapVerifyInfos.get(i).getDistroFilter().dump())) { - LOG.error("Module: " + entryHapVerifyInfos.get(i).getModuleName() + " DistroFilter is : " + - entryHapVerifyInfos.get(i).getDistroFilter().dump() + "."); + cause += "\n" + "Module: " + entryHapVerifyInfos.get(i).getModuleName() + " DistroFilter is : " + + entryHapVerifyInfos.get(i).getDistroFilter().dump() + "."; } if (!EMPTY_STRING.equals(entryHapVerifyInfos.get(j).getDistroFilter().dump())) { - LOG.error("Another Module: " + entryHapVerifyInfos.get(j).getModuleName() + - " DistroFilter is " + entryHapVerifyInfos.get(j).getDistroFilter().dump() + "."); + cause += "\n" + "Another Module: " + entryHapVerifyInfos.get(j).getModuleName() + + " DistroFilter is " + entryHapVerifyInfos.get(j).getDistroFilter().dump() + "."; } - LOG.error("Solution: Make sure entry name is valid and unique."); - LOG.error("Reference: " + REFERENCE_LINK + "."); + + String solution = "Solution: Make sure entry name is valid and unique.\n" + "Reference: " + REFERENCE_LINK + "."; + LOG.error(PackingToolErrMsg.CHECK_ENTRY_INVALID.toString(cause, solution)); return false; } } @@ -708,6 +762,7 @@ class HapVerify { private static boolean checkPolicyValueDisjoint(String policyLeft, List valueLeft, String policyRight, List valueRight) throws BundleException { if (valueLeft == null || valueRight == null) { + LOG.error(PackingToolErrMsg.CHECK_POLICY_DISJOINT_ERROR.toString("check value is empty.")); LOG.error("HapVerify::checkPolicyValueDisjoint value should not empty."); throw new BundleException("HapVerify::checkPolicyValueDisjoint value should not empty."); } @@ -1151,13 +1206,17 @@ class HapVerify { */ private static boolean checkDependencyIsValid(List allHapVerifyInfo) throws BundleException { if (allHapVerifyInfo.isEmpty()) { - LOG.error("HapVerify::checkDependencyIsValid failed, input none hap."); + String cause = "no module included."; + String solution = "Ensure the Shared App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_APP_MODE_FAILED.toString(cause, solution)); throw new BundleException("HapVerify::checkDependencyIsValid failed, input none hap."); } boolean isInstallationFree = allHapVerifyInfo.get(0).isInstallationFree(); for (HapVerifyInfo hapVerifyInfo : allHapVerifyInfo) { if (isInstallationFree != hapVerifyInfo.isInstallationFree()) { - LOG.error("installationFree is different in input hap."); + String cause = "The installationFree value is different in input hap."; + String solution = "Ensure that the installationFree field is same for all hap."; + LOG.error(PackingToolErrMsg.CHECK_DEPENDENCY_INVALID.toString(cause ,solution)); return false; } } @@ -1200,7 +1259,10 @@ class HapVerify { dependency.getModuleName(), hapVerifyInfo, allHapVerifyInfo); for (HapVerifyInfo item : layerDependencyList) { if (FEATURE.equals(item.getModuleType()) || ENTRY.equals(item.getModuleType())) { - LOG.error("HAP or HSP cannot depend on HAP" + item.getModuleName() + "."); + //IDE + String cause = "The HAP or HSP depends on a module of type feature or entry: " + item.getModuleName() + "."; + String solution = "Remove dependencies on feature or entry modules to ensure the dependency list is valid."; + LOG.error(PackingToolErrMsg.DEPENDENCY_LIST_INVALID.toString(cause, solution)); return false; } dependencyList.add(item); @@ -1304,7 +1366,7 @@ class HapVerify { private static boolean checkAtomicServiceModuleSize(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - LOG.error("checkAtomicServiceIsValid failed, hapVerifyInfoList is empty."); + LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString()); return false; } int entryLimit = hapVerifyInfoList.get(0).getEntrySizeLimit(); @@ -1324,14 +1386,15 @@ class HapVerify { fileSize += dependency.getFileLength(); } if (hapVerifyInfo.getModuleType().equals(ENTRY) && (fileSize >= entryLimit * FILE_LENGTH_1M)) { - LOG.error("module " + hapVerifyInfo.getModuleName() + " and it's dependencies size is " + - getCeilFileSize(fileSize, entryLimit) + "MB, which is overlarge than " + entryLimit + "MB."); + String errMsg = "module " + hapVerifyInfo.getModuleName() + " and it's dependencies size is " + + getCeilFileSize(fileSize, entryLimit) + "MB, which is overlarge than " + entryLimit + "MB."; + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_MODULE_SIZE.toString(errMsg)); return false; } if (!hapVerifyInfo.getModuleType().equals(ENTRY) && (fileSize >= notEntryLimit * FILE_LENGTH_1M)) { - LOG.error("module " + hapVerifyInfo.getModuleName() + " and it's dependencies size is " + - getCeilFileSize(fileSize, notEntryLimit) + - "MB, which is overlarge than " + notEntryLimit + "MB."); + String errMsg = "module " + hapVerifyInfo.getModuleName() + " and it's dependencies size is " + + getCeilFileSize(fileSize, notEntryLimit) + "MB, which is overlarge than " + notEntryLimit + "MB."; + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_MODULE_SIZE.toString(errMsg)); return false; } } @@ -1351,7 +1414,7 @@ class HapVerify { private static Map> getDeviceHapVerifyInfoMap(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - LOG.error("getDeviceHapVerifyInfoMap failed, hapVerifyInfoList is empty."); + LOG.error(PackingToolErrMsg.CHECK_HAP_VERIFY_INFO_LIST_EMPTY.toString()); throw new BundleException("getDeviceHapVerifyInfoMap failed, hapVerifyInfoList is empty."); } Map> deviceInfoMap = new HashMap>(); @@ -1372,7 +1435,9 @@ class HapVerify { private static boolean checkAtomicServiceIsValid(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - LOG.error("checkAtomicServiceIsValid failed, hapVerifyInfoList is empty."); + String cause = "no module included."; + String solution = "Ensure the Shared App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_APP_MODE_FAILED.toString(cause, solution)); return false; } String bundleType = hapVerifyInfoList.get(0).getBundleType(); @@ -1388,7 +1453,8 @@ class HapVerify { for (String device : deviceInfoMap.keySet()) { List hapVerifyInfos = deviceInfoMap.get(device); if (!checkAtomicServicePreloadsIsValid(hapVerifyInfos)) { - LOG.error("checkAtomicServicePreloadsIsValid failed on device " + device + "."); + LOG.error(PackingToolErrMsg.ATOMICSERVICE_INVALID.toString("checkAtomicServicePreloadsIsValid failed on device " + + device + ".")); return false; } } @@ -1416,7 +1482,9 @@ class HapVerify { private static boolean checkAtomicServicePreloadsIsValid(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - LOG.error("checkAtomicServicePreloadsIsValid failed, hapVerifyInfoList is empty."); + String cause = "no module included."; + String solution = "Ensure the Shared App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_APP_MODE_FAILED.toString(cause, solution)); throw new BundleException("checkAtomicServicePreloadsIsValid failed, hapVerifyInfoList is empty."); } List moduleNames = new ArrayList<>(); @@ -1430,18 +1498,19 @@ class HapVerify { for (PreloadItem preloadItem : preloadItems) { String moduleName = preloadItem.getModuleName(); if (preloadModuleName.contains(moduleName)) { - LOG.error("preloads config a duplicate module " + moduleName + - " in " + hapVerifyInfo.getModuleName() + "."); + LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("preloads config a duplicate module " + + moduleName + " in " + hapVerifyInfo.getModuleName() + ".")); return false; } preloadModuleName.add(moduleName); if (!moduleNames.contains(moduleName)) { - LOG.error("preloads config a invalid module " + moduleName + - " in " + hapVerifyInfo.getModuleName() + "."); + LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("preloads config a invalid module " + + moduleName + " in " + hapVerifyInfo.getModuleName() + ".")); return false; } if (moduleName.equals(hapVerifyInfo.getModuleName())) { - LOG.error("can not preload self, " + hapVerifyInfo.getModuleName() + " preload self."); + LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("can not preload self, " + + hapVerifyInfo.getModuleName() + " preload self.")); return false; } } @@ -1457,9 +1526,8 @@ class HapVerify { String moduleName = preloadItem.getModuleName(); if (moduleNameWithType.get(moduleName).equals(ENTRY) || moduleNameWithType.get(moduleName).equals(HAR)) { - LOG.error("feature or shared can not preload entry or har, " - + hapVerifyInfo.getModuleName() + " preloads a " - + moduleNameWithType.get(moduleName) + " module."); + LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("feature or shared can not preload entry or har, " + + hapVerifyInfo.getModuleName() + " preloads a " + moduleNameWithType.get(moduleName) + " module.")); return false; } } @@ -1476,11 +1544,9 @@ class HapVerify { */ public static boolean checkFileSizeIsValid(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - LOG.error("checkFileSizeIsValid failed, hapVerifyInfoList is empty."); - throw new BundleException("checkFileSizeIsValid failed, hapVerifyInfoList is empty."); + LOG.error(PackingToolErrMsg.CHECK_FILE_SIZE_INVALID.toString("hapVerifyInfoList is empty.")); } if (!checkFileSize(hapVerifyInfoList)) { - LOG.error("checkFileSize failed."); return false; } return true; @@ -1488,7 +1554,7 @@ class HapVerify { private static boolean checkFileSize(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { - LOG.error("checkFileSizeWhenSplit failed, hapVerifyInfoList is empty."); + LOG.error(PackingToolErrMsg.CHECK_FILE_SIZE_INVALID.toString("hapVerifyInfoList is empty.")); throw new BundleException("checkFileSizeWhenSplit failed, hapVerifyInfoList is empty."); } // check single file length @@ -1497,16 +1563,18 @@ class HapVerify { for (HapVerifyInfo hapVerifyInfo : hapVerifyInfoList) { if (hapVerifyInfo.getModuleType().equals(ENTRY) && (hapVerifyInfo.getFileLength() >= entryLimit * FILE_LENGTH_1M)) { - LOG.error("module " + hapVerifyInfo.getModuleName() + "'s size is " + - getCeilFileSize(hapVerifyInfo.getFileLength(), entryLimit) + - "MB, which is overlarge than " + entryLimit + "MB."); + String errMsg = "module " + hapVerifyInfo.getModuleName() + "'s size is " + + getCeilFileSize(hapVerifyInfo.getFileLength(), entryLimit) + + "MB, which is overlarge than " + entryLimit + "MB."; + LOG.error(PackingToolErrMsg.CHECK_FILE_SIZE_INVALID.toString(errMsg)); return false; } if (!hapVerifyInfo.getModuleType().equals(ENTRY) && (hapVerifyInfo.getFileLength() >= notEntryLimit * FILE_LENGTH_1M)) { - LOG.error("module " + hapVerifyInfo.getModuleName() + "'s size is " + + String errMsg = "module " + hapVerifyInfo.getModuleName() + "'s size is " + getCeilFileSize(hapVerifyInfo.getFileLength(), notEntryLimit) + - "MB, which is overlarge than " + notEntryLimit + "MB."); + "MB, which is overlarge than " + notEntryLimit + "MB."; + LOG.error(PackingToolErrMsg.CHECK_FILE_SIZE_INVALID.toString(errMsg)); return false; } } @@ -1515,7 +1583,8 @@ class HapVerify { for (String device : deviceInfoMap.keySet()) { ListhapVerifyInfoList1 = deviceInfoMap.get(device); if (!checkAtomicServiceModuleSize(hapVerifyInfoList1)) { - LOG.error("checkAtomicServiceModuleSize failed on device " + device + "."); + String errMsg = "check AtomicService ModuleSize failed on device " + device + "."; + LOG.error(PackingToolErrMsg.CHECK_FILE_SIZE_INVALID.toString(errMsg)); return false; } } diff --git a/adapter/ohos/ModuleJsonUtil.java b/adapter/ohos/ModuleJsonUtil.java index 6bbf2690..d957296f 100644 --- a/adapter/ohos/ModuleJsonUtil.java +++ b/adapter/ohos/ModuleJsonUtil.java @@ -131,8 +131,8 @@ class ModuleJsonUtil { version.versionCode = appObj.getIntValue(VERSIONCODE); version.versionName = appObj.getString(VERSIONNAME); } else { - String errMsg = "ModuleJsonUtil:parseStageVersion json file do not contain version."; - LOG.error(errMsg); + String errMsg = "json file do not contain version."; + LOG.error(PackingToolErrMsg.PARSE_STAGE_VERSION_FAILED.toString(errMsg)); throw new BundleException(errMsg); } if (appObj.containsKey(MIN_COMPATIBLE_VERSION_CODE)) { @@ -154,15 +154,17 @@ class ModuleJsonUtil { JSONObject appObj = getAppObj(jsonString); JSONObject versionObj = appObj.getJSONObject(VERSION); if (versionObj == null) { - LOG.error("ModuleJsonUtil:parseFaVersion failed : json file do not version."); - throw new BundleException("ModuleJsonUtil:parseFaVersion failed : json file do not version."); + String errMsg = "json file do not have version."; + LOG.error(PackingToolErrMsg.PARSE_STAGE_VERSION_FAILED.toString(errMsg)); + throw new BundleException("ModuleJsonUtil:parseFaVersion failed : json file do not have version object."); } Version version = new Version(); if (versionObj.containsKey(CODE) && versionObj.containsKey(NAME)) { version.versionName = versionObj.getString(NAME); version.versionCode = versionObj.getIntValue(CODE); } else { - LOG.error("ModuleJsonUtil:parseFaVersion failed : json file do not version name or version code."); + String errMsg = "json file do not have version name or version code."; + LOG.error(PackingToolErrMsg.PARSE_STAGE_VERSION_FAILED.toString(errMsg)); throw new BundleException( "ModuleJsonUtil:parseFaVersion failed : json file do not version name or version code."); } @@ -239,7 +241,8 @@ class ModuleJsonUtil { public static ModuleApiVersion parseFAModuleApiVersion(String jsonString) throws BundleException { JSONObject appObj = getAppObj(jsonString); if (!appObj.containsKey(API_VERSION)) { - LOG.error("ModuleJsonUtil::parseFAAPIVersion json file do not contain apiVersion."); + String errMsg = "json file does not contain apiVersion."; + LOG.error(PackingToolErrMsg.FA_MODULE_API_VERSION_MISSING.toString(errMsg)); throw new BundleException("ModuleJsonUtil::parseFAAPIVersion json file do not contain apiVersion."); } JSONObject apiVersionObj = appObj.getJSONObject(API_VERSION); @@ -269,8 +272,9 @@ class ModuleJsonUtil { if (moduleObj.containsKey(NAME)) { moduleName = moduleObj.getString(NAME); } else { - LOG.error("ModuleJsonUtil:parseStageModuleName failed: json file do not contain module name."); - throw new BundleException("ModuleJsonUtil:parseStageModuleName failed: json file do not contain module name."); + String errMsg = "json file do not contain module name."; + LOG.error(PackingToolErrMsg.PARSE_STAGE_MODULE_FAILED.toString(errMsg)); + throw new BundleException(errMsg); } return moduleName; } @@ -287,13 +291,14 @@ class ModuleJsonUtil { JSONObject moduleObj = getModuleObj(jsonString); JSONObject distroObj = moduleObj.getJSONObject(DISTRO); if (distroObj == null) { - LOG.error("ModuleJsonUtil:parseFaModuleName failed: json file do not contain distro."); - throw new BundleException("ModuleJsonUtil:parseFaModuleName failed: json file do not contain distro."); + String errMsg = "ModuleJsonUtil:parseFaModuleName failed: json file do not contain distro."; + LOG.error(PackingToolErrMsg.PARSE_FA_MODULE_NAME_FAILED.toString(errMsg)); + throw new BundleException(errMsg); } if (!distroObj.containsKey(MODULE_NAME)) { - LOG.error("ModuleJsonUtil:parseFaModuleName failed: json file do not contain moduleName."); - throw new BundleException( - "ModuleJsonUtil:parseFaModuleName failed: json file do not contain moduleName."); + String errMsg = "ModuleJsonUtil:parseFaModuleName failed: json file do not contain moduleName."; + LOG.error(PackingToolErrMsg.PARSE_FA_MODULE_NAME_FAILED.toString(errMsg)); + throw new BundleException(errMsg); } moduleName = distroObj.getString(MODULE_NAME); return moduleName; @@ -310,9 +315,9 @@ class ModuleJsonUtil { String moduleName; JSONObject moduleObj = getModuleObj(jsonString); if (!moduleObj.containsKey(NAME)) { - LOG.error("ModuleJsonUtil:parsePatchModuleName failed: json file do not contain moduleName."); - throw new BundleException( - "ModuleJsonUtil:parsePatchModuleName failed: json file do not contain moduleName."); + String errMsg = "json file do not contain moduleName."; + LOG.error(PackingToolErrMsg.PARSE_PATCH_MODULE_NAME_FAILED.toString(errMsg)); + throw new BundleException(errMsg); } moduleName = moduleObj.getString(NAME); return moduleName; @@ -331,7 +336,8 @@ class ModuleJsonUtil { if (moduleObj.containsKey(PACKAGE)) { packageStr = moduleObj.getString(PACKAGE); } else { - LOG.error("ModuleJsonUtil:parseFaPackageStr failed: json file do not contain package."); + String errMsg = "ModuleJsonUtil:parseFaPackageStr failed: json file do not contain package."; + LOG.error(PackingToolErrMsg.FA_PACKAGE_STR_PARSE_FAILED.toString("json file do not contain package.")); throw new BundleException("ModuleJsonUtil:parseFaPackageStr failed: json file do not contain package."); } return packageStr; @@ -350,7 +356,7 @@ class ModuleJsonUtil { if (appObject.containsKey(BUNDLE_NAME)) { bundleName = appObject.getString(BUNDLE_NAME); } else { - LOG.error("ModuleJsonUtil::parseStageBundleName json object do not contain bundleNames."); + LOG.error(PackingToolErrMsg.PARSE_BUNDLE_NAME_FAILED.toString("json object do not contain bundleNames.")); throw new BundleException("ModuleJsonUtil::parseStageBundleName json object do not contain bundleNames."); } return bundleName; @@ -943,8 +949,9 @@ class ModuleJsonUtil { */ public static void parseFAHapVerifyInfo(HapVerifyInfo hapVerifyInfo) throws BundleException { if (hapVerifyInfo.getProfileStr().isEmpty()) { - LOG.error("ModuleJsonUtil::parseFAHapVerifyInfo failed, config.json is empty."); - throw new BundleException("ModuleJsonUtil::parseFAHapVerifyInfo failed, config.json is empty."); + String errMsg = "ModuleJsonUtil::parseFAHapVerifyInfo failed, config.json is empty."; + LOG.error(PackingToolErrMsg.FA_HAP_VERIFY_INFO_FAILED.toString(errMsg)); + throw new BundleException(errMsg); } String bundleName = parseBundleName(hapVerifyInfo.getProfileStr()); hapVerifyInfo.setBundleName(bundleName); @@ -1071,8 +1078,8 @@ class ModuleJsonUtil { } } } catch (JSONException exception) { - String errMsg = "parse JSONObject failed: " + exception.getMessage(); - LOG.error(errMsg); + String errMsg = "parse FA distorFilter failed: " + exception.getMessage(); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString(exception.getMessage())); throw new BundleException(errMsg); } return distroFilter; @@ -1310,9 +1317,9 @@ class ModuleJsonUtil { JSONObject moduleObj = getModuleObj(jsonString); String moduleName = parseStageModuleName(jsonString); if (!moduleObj.containsKey(TYPE)) { - String errMsg = "parse failed, input module.json is invalid, " + - "module.json has no type in module: " + moduleName; - LOG.error(errMsg); + String errMsg = "Module: '" + moduleName + "' has no type in module.json."; + String solution = "Ensure the module.json file includes a valid 'type' field for module '" + moduleName + "'."; + LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); throw new BundleException(errMsg); } String type = moduleObj.getString(TYPE); @@ -1320,42 +1327,47 @@ class ModuleJsonUtil { JSONObject appObj = getAppObj(jsonString); if (!appObj.containsKey(BUNDLE_TYPE)) { if (installationFree) { - String errMessage = "The app.json5 file configuration does not match the installationFree:" + - " true settings. Add the bundleType field to the app.json5 file and set it atomicService."; - LOG.error(errMessage); - throw new BundleException(errMessage); + String errMsg = "The app.json5 file configuration does not match the installationFree."; + String solution = "Add the bundleType field to the app.json5 file or set it atomicService."; + LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); + throw new BundleException(errMsg); } return APP; } else { String bundleType = getJsonString(appObj, BUNDLE_TYPE); if (bundleType.equals(APP)) { if (installationFree) { - String errMsg = "installationFree must be false in module(" + - moduleName + ") when bundleType is app."; - LOG.error(errMsg); + String errMsg = "installationFree must be false in module '" + moduleName + "' when bundleType is app."; + String solution = "Set 'installationFree' to false in the module configuration when 'bundleType' is 'app'."; + LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); throw new BundleException(errMsg); } return APP; } else if (bundleType.equals(ATOMIC_SERVICE)) { if (!installationFree) { - String errMsg = "installationFree must be true in module(" + - moduleName + ") when bundleType is atomicService."; - LOG.error(errMsg); + String errMsg = "installationFree must be true in module '" + moduleName + "' when bundleType is atomicService."; + String solution = "Set 'installationFree' to true in the module configuration when 'bundleType'" + + "is 'atomicService'."; + LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); throw new BundleException(errMsg); } return ATOMIC_SERVICE; } else if (SHARED.equals(bundleType)) { if (!SHARED.equals(type)) { - String errMsg = "type must be shared in module(" + moduleName + ") when bundleType is shared."; - LOG.error(errMsg); + String errMsg = "type must be shared in module '" + moduleName + "' when bundleType is shared."; + String solution = "Set the 'type' to 'shared' in the module configuration when 'bundleType' is 'shared'.";; + LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); throw new BundleException(errMsg); } return SHARED; } else if (APP_SERVICE.equals(bundleType)) { return APP_SERVICE; } else { - LOG.error("bundleType is invalid in app.json."); - throw new BundleException("bundleType is invalid in app.json."); + String errMsg = "bundleType is invalid in app.json."; + String solution = "Ensure that the 'bundleType' field in the app.json file is correctly set to one of" + + "the valid types: 'app', 'atomicService', 'shared', or 'appService'."; + LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); + throw new BundleException(errMsg); } } } @@ -1393,7 +1405,9 @@ class ModuleJsonUtil { for (int i = 0; i < proxyData.size(); ++i) { JSONObject itemObj = proxyData.getJSONObject(i); if (!itemObj.containsKey(PROXY_URI)) { - LOG.error("parse JOSNObject failed in parseProxyDataUri."); + String errMsg = "Proxy data object does not contain " + PROXY_URI + "."; + String solution = "Ensure that each item in the " + PROXY_DATA + " array includes a valid " + PROXY_URI + " field."; + LOG.error(PackingToolErrMsg.PARSE_PROXY_DATA_URI_FAILED.toString(errMsg, solution)); throw new BundleException("parse JOSNObject failed in parseProxyDataUri."); } String uri = itemObj.getString(PROXY_URI); @@ -1404,7 +1418,9 @@ class ModuleJsonUtil { for (int i = 0; i < proxyDatas.size(); ++i) { JSONObject itemObj = proxyDatas.getJSONObject(i); if (!itemObj.containsKey(PROXY_URI)) { - LOG.error("parse JOSNObject failed in parseProxyDataUri."); + String errMsg = "Proxy data object does not contain " + PROXY_URI + "."; + String solution = "Ensure that each item in the " + PROXY_DATAS + " array includes a valid " + PROXY_URI + " field."; + LOG.error(PackingToolErrMsg.PARSE_PROXY_DATA_URI_FAILED.toString(errMsg, solution)); throw new BundleException("parse JOSNObject failed in parseProxyDataUri."); } String uri = itemObj.getString(PROXY_URI); @@ -1419,14 +1435,14 @@ class ModuleJsonUtil { try { jsonObject = JSON.parseObject(jsonString); } catch (JSONException exception) { - String errMsg = "parse JSONobject failed."; - LOG.error(errMsg); + String errMsg = "parse App object failed.\n"; + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString(errMsg + exception.getMessage())); throw new BundleException(errMsg); } JSONObject appObj = jsonObject.getJSONObject(APP); if (appObj == null) { - LOG.error("ModuleJsonUtil::parseStageInstallation json do not contain app."); - throw new BundleException("ModuleJsonUtil::parseStageInstallation json do not contain app."); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("module.json or config.json do not contain app.")); + throw new BundleException("json do not contain app."); } return appObj; } @@ -1436,18 +1452,18 @@ class ModuleJsonUtil { try { jsonObj = JSON.parseObject(jsonString); } catch (JSONException exception) { - String errMsg = "parse JSONobject failed."; - LOG.error(errMsg); + String errMsg = "parse JSONobject exception."; + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString(errMsg)); throw new BundleException(errMsg); } if (jsonObj == null) { - LOG.error("ModuleJsonUtil::parseStageInstallation jsonObj is null."); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("jsonObj is null")); throw new BundleException("ModuleJsonUtil::parseStageInstallation jsonObj is null."); } JSONObject moduleObj = jsonObj.getJSONObject(MODULE); if (moduleObj == null) { - LOG.error("ModuleJsonUtil::parseStageInstallation json do not contain module."); - throw new BundleException("ModuleJsonUtil::parseStageInstallation json do not contain module."); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("json file do not contain module.")); + throw new BundleException("json file do not contain module."); } return moduleObj; } @@ -1492,8 +1508,8 @@ class ModuleJsonUtil { JSONObject moduleObj = getModuleObj(jsonString); JSONObject distroObj = moduleObj.getJSONObject(DISTRO); if (distroObj == null) { - LOG.error("ModuleJsonUtil::parseStageInstallation json do not contain distro."); - throw new BundleException("ModuleJsonUtil::parseStageInstallation json do not contain distro."); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("json do not contain distro.")); + throw new BundleException("ModuleJsonUtil::parseFAInstallation json do not contain distro."); } if (distroObj.containsKey(INSTALLATION_FREE)) { return distroObj.getBoolean(INSTALLATION_FREE); @@ -1700,8 +1716,8 @@ class ModuleJsonUtil { try { jsonObject = JSON.parseObject(jsonString); } catch (JSONException exception) { - LOG.error("parse JOSNObject failed in getStageApiReleaseType."); - throw new BundleException("parse JOSNObject failed in getStageApiReleaseType."); + PackingToolErrMsg.PARSE_JSON_FAILED.toString("parse JOSNObject failed when get debug in config.json.") + throw new BundleException("parse JOSNObject failed when get debug in config.json."); } JSONObject deviceConfigObj = jsonObject.getJSONObject(DEVICE_CONFIG); if (deviceConfigObj == null) { diff --git a/adapter/ohos/PackingToolErrMsg.java b/adapter/ohos/PackingToolErrMsg.java new file mode 100644 index 00000000..04973ff9 --- /dev/null +++ b/adapter/ohos/PackingToolErrMsg.java @@ -0,0 +1,684 @@ +/* + * 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_NOT_FOUND + */ + 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(); + // 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(); + + //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(); + +} diff --git a/adapter/ohos/StringUtils.java b/adapter/ohos/StringUtils.java new file mode 100644 index 00000000..e6a454a4 --- /dev/null +++ b/adapter/ohos/StringUtils.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos; + +/** + * StringUtils. + * + * @since 2021/12/28 + */ +public final class StringUtils { + private StringUtils() { + } + + /** + * Check whether the input string is empty. + * + * @param cs input string + * @return true, if cs is empty + */ + public static boolean isEmpty(final CharSequence cs) { + return cs == null || cs.length() == 0; + } + + /** + * Check whether the array contains string ignoring case. + * + * @param array input string array + * @param str input string + * @return true, if the array contains the str ignoring case + */ + public static boolean containsIgnoreCase(String[] array, String str) { + if (array == null) { + return false; + } + for (String s : array) { + if (s != null && s.equalsIgnoreCase(str)) { + return true; + } + } + return false; + } +} -- Gitee From 048e4fbab292e39f558d01e59923bff259c08c51 Mon Sep 17 00:00:00 2001 From: nj1868 Date: Thu, 13 Feb 2025 20:23:32 +0800 Subject: [PATCH 2/5] update code Signed-off-by: nj1868 Change-Id: I29ccb7c0ef52ae8b2d5872aeec00298736229117 --- adapter/ohos/CompressEntrance.java | 2 +- adapter/ohos/Compressor.java | 15 +- adapter/ohos/HapVerify.java | 56 +- adapter/ohos/ModuleJsonUtil.java | 13 +- adapter/ohos/PackingToolErrMsg.java | 818 +++++++++++++--------------- 5 files changed, 425 insertions(+), 479 deletions(-) diff --git a/adapter/ohos/CompressEntrance.java b/adapter/ohos/CompressEntrance.java index 7b093008..8603ecb7 100644 --- a/adapter/ohos/CompressEntrance.java +++ b/adapter/ohos/CompressEntrance.java @@ -122,7 +122,7 @@ public class CompressEntrance { ShowHelp.compressHelp(); System.exit(EXIT_STATUS_EXCEPTION); } - } + v } System.exit(EXIT_STATUS_NORMAL); } diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index e2bed1e5..a86c1062 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -2228,7 +2228,7 @@ public class Compressor { zipCreator.writeTo(zipOut); } catch (IOException | InterruptedException | ExecutionException e) { LOG.error(PackingToolErrMsg.COMPRESS_PARALLEL_EXCEPTION.toString(e.getMessage())); - throw new BundleException(errMsg); + throw new BundleException("Parallel compress exception." + e.getMessage()); } } @@ -2511,7 +2511,7 @@ public class Compressor { } } } catch (IOException exception) { - LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("is moduleHap io exception:" + exception.getMessage())); + LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("check module type io exception: " + exception.getMessage())); throw new BundleException("Compressor::isModuleHap failed."); } finally { Utility.closeStream(zipInput); @@ -2541,7 +2541,7 @@ public class Compressor { count = fileInputStream.read(buffer); } } catch (FileNotFoundException ignored) { - LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("getCrcFromFile FileNotFoundException: " + exception.getMessage())); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("getCrcFromFile FileNotFoundException: " + ignored.getMessage())); throw new BundleException("Get Crc from file failed: " + file.getName()); } catch (IOException exception) { LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString("getCrcFromFile io exception: " + exception.getMessage())); @@ -2823,21 +2823,24 @@ public class Compressor { zipOut.flush(); } } catch (IOException exception) { - LOG.error(PackingToolErrMsg.CLOSE_ZIP_OUTPUT_STREAM_EXPECTION.toString("flush exception: " + exception.getMessage())) + LOG.error(PackingToolErrMsg.CLOSE_ZIP_OUTPUT_STREAM_EXPECTION.toString("flush exception: " + + exception.getMessage())); } try { if (zipOut != null && isEntryOpen) { zipOut.closeArchiveEntry(); } } catch (IOException exception) { - LOG.error(PackingToolErrMsg.CLOSE_ZIP_OUTPUT_STREAM_EXPECTION.toString("close entry io exception: " + exception.getMessage())) + LOG.error(PackingToolErrMsg.CLOSE_ZIP_OUTPUT_STREAM_EXPECTION.toString("close entry io exception: " + + exception.getMessage())); } try { if (zipOut != null) { zipOut.finish(); } } catch (IOException exception) { - LOG.error(PackingToolErrMsg.CLOSE_ZIP_OUTPUT_STREAM_EXPECTION.toString("finish exception: " + exception.getMessage())) + LOG.error(PackingToolErrMsg.CLOSE_ZIP_OUTPUT_STREAM_EXPECTION.toString("finish exception: " + + exception.getMessage())); } } diff --git a/adapter/ohos/HapVerify.java b/adapter/ohos/HapVerify.java index d85e3e71..a3e88321 100644 --- a/adapter/ohos/HapVerify.java +++ b/adapter/ohos/HapVerify.java @@ -180,7 +180,7 @@ class HapVerify { "- Module: (" + hapVerifyInfo2.getModuleName() + ") with deviceType: " + hapVerifyInfo2.getDeviceType() + " and continueType: " + typeList2; - String solution = "Ensure that the deviceType and continueType fields in these modules are distinct. " + + String solution = "Ensure that the continueType fields in these modules are different. " + "Update either (" + hapVerifyInfo.getModuleName() + ") or (" + hapVerifyInfo2.getModuleName() + ") to avoid overlap."; @@ -572,7 +572,9 @@ class HapVerify { return false; } if (!moduleList.containsAll(targetModuleList)) { - LOG.error(PackingToolErrMsg.TARGET_MODULE_NAME_NOT_EXIST.toString("target modules are needed to pack with overlay module.")); + List missingModules = new ArrayList<>(targetModuleList); + missingModules.removeAll(moduleList); + LOG.error(PackingToolErrMsg.TARGET_MODULE_NAME_NOT_EXIST.toString("The following target overlay modules are missing: " + missingModules)); return false; } @@ -583,16 +585,16 @@ class HapVerify { private static boolean checkCompileSdkIsValid(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos.isEmpty()) { String cause = "no module included."; - String solution = "Ensure the Shared App contains at least one module before proceeding."; - LOG.error(PackingToolErrMsg.CHECK_APP_MODE_FAILED.toString(cause, solution)); + String solution = "Ensure the App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); return false; } String compileSdkType = hapVerifyInfos.get(0).getCompileSdkType(); for (HapVerifyInfo info : hapVerifyInfos) { if (!compileSdkType.equals(info.getCompileSdkType())) { - String cause = "Compile sdk type is not the same for all modules."; - String solution = "Ensure that all modules the same complile sdk type."; - LOG.error(PackingToolErrMsg.COMPILE_SDK_INVALID.toString(cause, solution)); + String cause = "compileSdkType is not the same for all modules."; + String solution = "Ensure that all modules the same compileSdkType."; + LOG.error(PackingToolErrMsg.COMPILE_SDK_TYPE_DIFFERENT.toString(cause, solution)); return false; } } @@ -602,8 +604,8 @@ class HapVerify { private static boolean checkProxyDataUriIsUnique(List hapVerifyInfos) throws BundleException { if (hapVerifyInfos.isEmpty()) { String cause = "no module included."; - String solution = "Ensure the Shared App contains at least one module before proceeding."; - LOG.error(PackingToolErrMsg.CHECK_APP_MODE_FAILED.toString(cause, solution)); + String solution = "Ensure the App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); return false; } Set uriSet = new HashSet<>(); @@ -664,7 +666,7 @@ class HapVerify { " DistroFilter is " + entryHapVerifyInfos.get(j).getDistroFilter().dump() + "."; } - String solution = "Solution: Make sure entry name is valid and unique.\n" + "Reference: " + REFERENCE_LINK + "."; + String solution = "Make sure the entry name is valid and unique, and the HAP uniqueness check logic passes.\n" + "Reference: " + REFERENCE_LINK + "."; LOG.error(PackingToolErrMsg.CHECK_ENTRY_INVALID.toString(cause, solution)); return false; } @@ -762,8 +764,9 @@ class HapVerify { private static boolean checkPolicyValueDisjoint(String policyLeft, List valueLeft, String policyRight, List valueRight) throws BundleException { if (valueLeft == null || valueRight == null) { - LOG.error(PackingToolErrMsg.CHECK_POLICY_DISJOINT_ERROR.toString("check value is empty.")); - LOG.error("HapVerify::checkPolicyValueDisjoint value should not empty."); + String errMsg = "There is no 'value' setting in the distributionFilter setting."; + String solution = "Ensure that all distributionFilter has 'value' setting."; + LOG.error(PackingToolErrMsg.CHECK_POLICY_DISJOINT_ERROR.toString(errMsg, solution)); throw new BundleException("HapVerify::checkPolicyValueDisjoint value should not empty."); } if (EXCLUDE.equals(policyLeft) && INCLUDE.equals(policyRight)) { @@ -781,7 +784,9 @@ class HapVerify { } else if (EXCLUDE.equals(policyLeft) && EXCLUDE.equals(policyRight)) { return false; } else { - LOG.error("HapVerify::checkPolicyValueDisjoint input policy is invalid."); + String errMsg = "Check distributionFilter 'policy' setting is invalid."; + String solution = "Ensure all distributionFilter 'policy' value must 'include' or 'exclude'."; + LOG.error(PackingToolErrMsg.CHECK_POLICY_DISJOINT_ERROR.toString(errMsg, solution)); throw new BundleException("HapVerify::checkPolicyValueDisjoint input policy is invalid."); } return false; @@ -1207,8 +1212,8 @@ class HapVerify { private static boolean checkDependencyIsValid(List allHapVerifyInfo) throws BundleException { if (allHapVerifyInfo.isEmpty()) { String cause = "no module included."; - String solution = "Ensure the Shared App contains at least one module before proceeding."; - LOG.error(PackingToolErrMsg.CHECK_APP_MODE_FAILED.toString(cause, solution)); + String solution = "Ensure the App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); throw new BundleException("HapVerify::checkDependencyIsValid failed, input none hap."); } boolean isInstallationFree = allHapVerifyInfo.get(0).isInstallationFree(); @@ -1259,8 +1264,7 @@ class HapVerify { dependency.getModuleName(), hapVerifyInfo, allHapVerifyInfo); for (HapVerifyInfo item : layerDependencyList) { if (FEATURE.equals(item.getModuleType()) || ENTRY.equals(item.getModuleType())) { - //IDE - String cause = "The HAP or HSP depends on a module of type feature or entry: " + item.getModuleName() + "."; + String cause = "The dependent module (" + item.getModuleName() + ") type is feature or entry."; String solution = "Remove dependencies on feature or entry modules to ensure the dependency list is valid."; LOG.error(PackingToolErrMsg.DEPENDENCY_LIST_INVALID.toString(cause, solution)); return false; @@ -1436,8 +1440,8 @@ class HapVerify { private static boolean checkAtomicServiceIsValid(List hapVerifyInfoList) throws BundleException { if (hapVerifyInfoList.isEmpty()) { String cause = "no module included."; - String solution = "Ensure the Shared App contains at least one module before proceeding."; - LOG.error(PackingToolErrMsg.CHECK_APP_MODE_FAILED.toString(cause, solution)); + String solution = "Ensure the App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); return false; } String bundleType = hapVerifyInfoList.get(0).getBundleType(); @@ -1483,8 +1487,8 @@ class HapVerify { throws BundleException { if (hapVerifyInfoList.isEmpty()) { String cause = "no module included."; - String solution = "Ensure the Shared App contains at least one module before proceeding."; - LOG.error(PackingToolErrMsg.CHECK_APP_MODE_FAILED.toString(cause, solution)); + String solution = "Ensure the App contains at least one module before proceeding."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); throw new BundleException("checkAtomicServicePreloadsIsValid failed, hapVerifyInfoList is empty."); } List moduleNames = new ArrayList<>(); @@ -1498,18 +1502,18 @@ class HapVerify { for (PreloadItem preloadItem : preloadItems) { String moduleName = preloadItem.getModuleName(); if (preloadModuleName.contains(moduleName)) { - LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("preloads config a duplicate module " - + moduleName + " in " + hapVerifyInfo.getModuleName() + ".")); + LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("preloads a duplicate module " + + moduleName + " on module " + hapVerifyInfo.getModuleName() + ".")); return false; } preloadModuleName.add(moduleName); if (!moduleNames.contains(moduleName)) { - LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("preloads config a invalid module " - + moduleName + " in " + hapVerifyInfo.getModuleName() + ".")); + LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("preloads a not exist module " + + moduleName + " on module " + hapVerifyInfo.getModuleName() + ".")); return false; } if (moduleName.equals(hapVerifyInfo.getModuleName())) { - LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("can not preload self, " + LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("can not preload self, module " + hapVerifyInfo.getModuleName() + " preload self.")); return false; } diff --git a/adapter/ohos/ModuleJsonUtil.java b/adapter/ohos/ModuleJsonUtil.java index d957296f..c667500f 100644 --- a/adapter/ohos/ModuleJsonUtil.java +++ b/adapter/ohos/ModuleJsonUtil.java @@ -242,7 +242,7 @@ class ModuleJsonUtil { JSONObject appObj = getAppObj(jsonString); if (!appObj.containsKey(API_VERSION)) { String errMsg = "json file does not contain apiVersion."; - LOG.error(PackingToolErrMsg.FA_MODULE_API_VERSION_MISSING.toString(errMsg)); + LOG.error(PackingToolErrMsg.PARSE_FA_MODULE_API_VERSION_FAILED.toString(errMsg)); throw new BundleException("ModuleJsonUtil::parseFAAPIVersion json file do not contain apiVersion."); } JSONObject apiVersionObj = appObj.getJSONObject(API_VERSION); @@ -336,8 +336,7 @@ class ModuleJsonUtil { if (moduleObj.containsKey(PACKAGE)) { packageStr = moduleObj.getString(PACKAGE); } else { - String errMsg = "ModuleJsonUtil:parseFaPackageStr failed: json file do not contain package."; - LOG.error(PackingToolErrMsg.FA_PACKAGE_STR_PARSE_FAILED.toString("json file do not contain package.")); + LOG.error(PackingToolErrMsg.PARSE_FA_PACKAGE_STR_FAILED.toString("json file do not contain package.")); throw new BundleException("ModuleJsonUtil:parseFaPackageStr failed: json file do not contain package."); } return packageStr; @@ -356,7 +355,7 @@ class ModuleJsonUtil { if (appObject.containsKey(BUNDLE_NAME)) { bundleName = appObject.getString(BUNDLE_NAME); } else { - LOG.error(PackingToolErrMsg.PARSE_BUNDLE_NAME_FAILED.toString("json object do not contain bundleNames.")); + LOG.error(PackingToolErrMsg.PARSE_BUNDLE_NAME_FAILED.toString("json object do not contain bundleName.")); throw new BundleException("ModuleJsonUtil::parseStageBundleName json object do not contain bundleNames."); } return bundleName; @@ -949,8 +948,8 @@ class ModuleJsonUtil { */ public static void parseFAHapVerifyInfo(HapVerifyInfo hapVerifyInfo) throws BundleException { if (hapVerifyInfo.getProfileStr().isEmpty()) { - String errMsg = "ModuleJsonUtil::parseFAHapVerifyInfo failed, config.json is empty."; - LOG.error(PackingToolErrMsg.FA_HAP_VERIFY_INFO_FAILED.toString(errMsg)); + String errMsg = "config.json is empty."; + LOG.error(PackingToolErrMsg.PARSE_FA_HAP_VERIFY_INFO_FAILED.toString(errMsg)); throw new BundleException(errMsg); } String bundleName = parseBundleName(hapVerifyInfo.getProfileStr()); @@ -1716,7 +1715,7 @@ class ModuleJsonUtil { try { jsonObject = JSON.parseObject(jsonString); } catch (JSONException exception) { - PackingToolErrMsg.PARSE_JSON_FAILED.toString("parse JOSNObject failed when get debug in config.json.") + PackingToolErrMsg.PARSE_JSON_FAILED.toString("parse JOSNObject failed when get debug in config.json."); throw new BundleException("parse JOSNObject failed when get debug in config.json."); } JSONObject deviceConfigObj = jsonObject.getJSONObject(DEVICE_CONFIG); diff --git a/adapter/ohos/PackingToolErrMsg.java b/adapter/ohos/PackingToolErrMsg.java index 04973ff9..d674c98a 100644 --- a/adapter/ohos/PackingToolErrMsg.java +++ b/adapter/ohos/PackingToolErrMsg.java @@ -22,25 +22,54 @@ package ohos; */ public class PackingToolErrMsg { + // 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(); + + /** + * EXECUTE_PACKING_TOOL_FAILED + */ + 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(); + // io excepetion /** * COMPRESS_APP_IO_EXCEPTION */ public static final ErrorMsg COMPRESS_APP_IO_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("13") - .addErrCode("002") + .addTypeCode("99") + .addErrCode("001") .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 + * COMPRESS_FILE_EXCEPTION */ - public static final ErrorMsg COMPRESS_PACK_INFO_INTO_HAP_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("13") + public static final ErrorMsg COMPRESS_FILE_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") .addErrCode("003") - .addDescription("Io exception when compress pack info into hap or hsp.") + .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(); @@ -50,29 +79,18 @@ public class PackingToolErrMsg { */ public static final ErrorMsg COMPRESS_PARALLEL_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() .addTypeCode("15") - .addErrCode("002") + .addErrCode("004") .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") + .addTypeCode("98") + .addErrCode("001") .addDescription("The json file is not standard.") .addCause("%s") .build(); @@ -103,13 +121,14 @@ public class PackingToolErrMsg { "3. Check for possible disk or file system errors.\n" + "4. Review the related error message for further insights.") .build(); + // compress process error /** * COMPRESS_PROCESS_EXCEPTION */ public static final ErrorMsg COMPRESS_PROCESS_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("15") - .addErrCode("001") + .addTypeCode("99") + .addErrCode("002") .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.") @@ -120,57 +139,18 @@ public class PackingToolErrMsg { * INVALID_HAP_OR_HSP_FILE */ public static final ErrorMsg INVALID_HAP_FILE = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("16") + .addTypeCode("15") .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") + .addTypeCode("15") .addErrCode("001") .addDescription("Read stage hap verify info io exception.") .addCause("%s") @@ -185,17 +165,6 @@ public class PackingToolErrMsg { .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 @@ -207,15 +176,16 @@ public class PackingToolErrMsg { .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_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(); + /** * PARSE_STAGE_VERSION_FAILED */ @@ -226,26 +196,6 @@ public class PackingToolErrMsg { .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 */ @@ -256,16 +206,6 @@ public class PackingToolErrMsg { .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 */ @@ -288,336 +228,336 @@ public class PackingToolErrMsg { .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(); + /** + * 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(); -/** - * 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 + * PARSE_FA_MODULE_NAME_FAILED */ - public static final ErrorMsg PARSE_PATCH_MODULE_NAME_FAILED = ErrorMsg.getPackingToolErrBuilder() + public static final ErrorMsg PARSE_FA_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.") + .addDescription("Failed to parse config.json.") .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(); - - //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(); + .build(); + + /** + * PARSE_FA_PACKAGE_STR_FAILED + */ + public static final ErrorMsg PARSE_FA_PACKAGE_STR_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("009") + .addDescription("Failed to parse config.json and package object.") + .addCause("%s") + .build(); + + /** + * FA_MODULE_API_VERSION_MISSING + */ + public static final ErrorMsg PARSE_FA_MODULE_API_VERSION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("010") + .addDescription("Failed to parse FA apiVersion.") + .addCause("%s") + .build(); + + /** + * PARSE_PATCH_MODULE_NAME_FAILED + */ + public static final ErrorMsg PARSE_PATCH_MODULE_NAME_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("011") + .addDescription("Failed to parse patch module name from patch.json.") + .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(); + + /** + * 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("99") + .addErrCode("003") + .addDescription("Failed to parse compress native libs.") + .addCause("%s") + .build(); + + /** + * PARSE_DEVICE_TYPE_FAILED + */ + public static final ErrorMsg PARSE_DEVICE_TYPE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("99") + .addErrCode("004") + .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("99") + .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(); + + /** + * PARSE_FA_HAP_VERIFY_INFO_FAILED + */ + public static final ErrorMsg PARSE_FA_HAP_VERIFY_INFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("21") + .addErrCode("012") + .addDescription("Failed to parse FA hap verify info from config.json.") + .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("15") + .addErrCode("011") + .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(); + /** + * 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(); + 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_MODULE_NAME_INVALID + */ + public static final ErrorMsg CHECK_POLICY_DISJOINT_ERROR = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("008") + .addDescription("Check two distroFilter policy disjoint invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_PACKAGE_NAME_INVALID + */ + public static final ErrorMsg CHECK_PACKAGE_NAME_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("009") + .addDescription("Check packageName invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_ENTRY_INVALID + */ + public static final ErrorMsg CHECK_ENTRY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("010") + .addDescription("Check entry module invalid.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_ENTRY_INVALID + */ + public static final ErrorMsg CHECK_DEPENDENCY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("011") + .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("012") + .addDescription("HAP or HSP cannot depend on feature or entry module.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * ATOMICSERVICE_PRELOADS_INVALID + */ + public static final ErrorMsg ATOMICSERVICE_PRELOADS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("013") + .addDescription("atomicservice preloads 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(); + /** + * COMPILE_SDK_INVALID + */ + public static final ErrorMsg COMPILE_SDK_TYPE_DIFFERENT = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("015") + .addDescription("compileSdkType is different.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * PROXY_DATA_URI_NOT_UNIQUE + */ + public static final ErrorMsg PROXY_DATA_URI_NOT_UNIQUE = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("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(); + + /** + * ATOMICSERVICE_INVALID + */ + public static final ErrorMsg ATOMICSERVICE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") + .addErrCode("018") + .addDescription("Check atomicservice is invalid.") + .addCause("%s") + .build(); // compress error // 可以把各个模式的统一报错归到一类去 @@ -625,7 +565,7 @@ public static final ErrorMsg FA_MODULE_API_VERSION_MISSING = ErrorMsg.getPacking * COMPRESS_APP_VERIFY_FAILED */ public static final ErrorMsg COMPRESS_APP_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("23") + .addTypeCode("15") .addErrCode("003") .addDescription("Compress app file verify failed.") .addCause("%s") @@ -636,7 +576,7 @@ public static final ErrorMsg FA_MODULE_API_VERSION_MISSING = ErrorMsg.getPacking * COMPRESS_APP_VERIFY_FAILED */ public static final ErrorMsg APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("xx") + .addTypeCode("99") .addErrCode("001") .addDescription("Check app atomicservice compress size failed.") .addCause("%s") @@ -646,7 +586,7 @@ public static final ErrorMsg FA_MODULE_API_VERSION_MISSING = ErrorMsg.getPacking * CHECK_FILE_SIZE_INVALID */ public static final ErrorMsg CHECK_FILE_SIZE_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("xx") + .addTypeCode("99") .addErrCode("001") .addDescription("File size check failed.") .addCause("%s") @@ -656,7 +596,7 @@ public static final ErrorMsg FA_MODULE_API_VERSION_MISSING = ErrorMsg.getPacking * CHECK_FILE_SIZE_INVALID */ public static final ErrorMsg CHECK_ATOMIC_SERVICE_MODULE_SIZE = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("xx") + .addTypeCode("99") .addErrCode("001") .addDescription("AtomicService module size check failed.") .addCause("%s") @@ -666,7 +606,7 @@ public static final ErrorMsg FA_MODULE_API_VERSION_MISSING = ErrorMsg.getPacking * CHECK_HAP_VERIFY_INFO_LIST_EMPTY */ public static final ErrorMsg CHECK_HAP_VERIFY_INFO_LIST_EMPTY = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("xx") + .addTypeCode("99") .addErrCode("002") .addDescription("The provided list of HapVerifyInfo is empty, unable to process.") .build(); -- Gitee From ad23fff7c0c7ea1fdfd2416c288a76cb6042a46a Mon Sep 17 00:00:00 2001 From: nj1868 Date: Tue, 11 Feb 2025 17:24:30 +0800 Subject: [PATCH 3/5] update Signed-off-by: nj1868 Change-Id: I8ceba86c8bc81e7c8c96d96db2c004ed504d7892 --- adapter/ohos/CompressEntrance.java | 2 +- adapter/ohos/HapVerify.java | 12 +- adapter/ohos/PackingToolErrMsg.java | 653 ++++++++++++++++++++++++---- 3 files changed, 581 insertions(+), 86 deletions(-) diff --git a/adapter/ohos/CompressEntrance.java b/adapter/ohos/CompressEntrance.java index 8603ecb7..7b093008 100644 --- a/adapter/ohos/CompressEntrance.java +++ b/adapter/ohos/CompressEntrance.java @@ -122,7 +122,7 @@ public class CompressEntrance { ShowHelp.compressHelp(); System.exit(EXIT_STATUS_EXCEPTION); } - v } + } System.exit(EXIT_STATUS_NORMAL); } diff --git a/adapter/ohos/HapVerify.java b/adapter/ohos/HapVerify.java index a3e88321..abd0357b 100644 --- a/adapter/ohos/HapVerify.java +++ b/adapter/ohos/HapVerify.java @@ -91,7 +91,7 @@ class HapVerify { } // check atomic service is valid if (!checkAtomicServiceIsValid(hapVerifyInfos)) { - String errMsg = "checkAtomicServiceIsValid failed."; + String errMsg = "check AtomicServiceIsValid failed."; LOG.error(PackingToolErrMsg.CHECK_HAP_INVALID.toString(errMsg)); return false; } @@ -201,7 +201,7 @@ class HapVerify { if (hapVerifyInfos == null || hapVerifyInfos.isEmpty()) { String cause = "no module included."; String solution = "Ensure the shared App contains at least one module before proceeding."; - LOG.error(PackingToolErrMsg.VERIFY_SHARED_APP_INVALID.toString(cause, solution)); + LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); return false; } String moduleName = hapVerifyInfos.get(0).getModuleName(); @@ -209,19 +209,19 @@ class HapVerify { if (!moduleName.equals(hapVerifyInfo.getModuleName())) { String cause = "module name is different."; String solution = "Ensure that all module have the same module name."; - LOG.error(PackingToolErrMsg.VERIFY_SHARED_APP_INVALID.toString(cause, solution)); + LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); return false; } if (!hapVerifyInfo.getDependencyItemList().isEmpty()) { String cause = "Shared app can not depend on other modules."; String solution = "Ensure module does not contain dependencies."; - LOG.error(PackingToolErrMsg.VERIFY_SHARED_APP_INVALID.toString(cause, solution)); + LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); return false; } if (!TYPE_SHARED.equals(hapVerifyInfo.getModuleType())) { String cause = "Module type is not a shared app."; String solution = "Ensure module type is 'shared' for all module."; - LOG.error(PackingToolErrMsg.VERIFY_SHARED_APP_INVALID.toString(cause, solution)); + LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); return false; } } @@ -230,7 +230,7 @@ class HapVerify { if (!checkDuplicatedIsValid(hapVerifyInfos.get(i), hapVerifyInfos.get(j))) { String cause = "There are duplicated modules in the packing file."; String solution = "Ensure that there are no duplicated modules."; - LOG.error(PackingToolErrMsg.VERIFY_SHARED_APP_INVALID.toString(cause, solution)); + LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); return false; } } diff --git a/adapter/ohos/PackingToolErrMsg.java b/adapter/ohos/PackingToolErrMsg.java index d674c98a..224e26a2 100644 --- a/adapter/ohos/PackingToolErrMsg.java +++ b/adapter/ohos/PackingToolErrMsg.java @@ -22,35 +22,539 @@ package ohos; */ public class PackingToolErrMsg { - // packing tool error + /** + * CHECK_MODULE_ATOMIC_SERVICE_FAILED + */ + public static final ErrorMsg CHECK_MODULE_ATOMIC_SERVICE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("10") + .addErrCode("003") + .addDescription("when bundleType is not atomicService") + .addCause("%s") + .build(); + /** - * EXECUTE_PACKING_TOOL_FAILED + * CHECK_LEASTONE_ABILITY */ - public static final ErrorMsg COMMAND_PARSER_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("18") + public static final ErrorMsg CHECK_LEASTONE_ABILITY = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("10") + .addErrCode("004") + .addDescription("check at least one ability") + .addCause("%s") + .build(); + + /** + * CHECK_ATOMIC_SERVICE_FAILED + */ + public static final ErrorMsg CHECK_ATOMIC_SERVICE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("10") + .addErrCode("005") + .addDescription("check EntryInAtomicService failed.") + .addCause("%s") + .build(); + + /** + * CHECK_STAGE_HAP_FAILED + */ + public static final ErrorMsg CHECK_STAGE_HAP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("001") + .addDescription("check AsanTsanEnabledValid failed") + .addCause("%s") + .build(); + + /** + * CHECK_AS_TSAN_ENABLED + */ + public static final ErrorMsg CHECK_AS_TSAN_ENABLED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("004") + .addDescription("Check asanEnabled and tsanEnabled failed") + .addCause("%s") + .addSolution("Please set the correct values for the parameters.") + .build(); + + /** + * CHECK_HWASAN_ENABLED_INVALID + */ + + public static final ErrorMsg CHECK_HWASAN_ENABLED_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("005") + .addDescription("Check hwasanEnabled and asanEnabled failed") + .addCause("%s") + .addSolution("Please set the correct values for the parameters.") + .build(); + + /** + * CHECK_UBASAN_ENABLED_INVALID + */ + public static final ErrorMsg CHECK_UBASAN_ENABLED_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("008") + .addDescription("Check ubsanEnabled and asanEnabled failed") + .addCause("%s") + .addSolution("Please set the correct values for the parameters.") + .build(); + + /** + * CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED + */ + public static final ErrorMsg CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("002") + .addDescription("file configuration does not match") + .addCause("%s") + .build(); + + //file operator failed + /** + * FILE_NOT_FOUND + */ + public static final ErrorMsg FILE_NOT_FOUND = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("14") + .addErrCode("001") + .addDescription("File not found exception.") + .addCause("%s") + .build(); + + /** + * FILE_DELETE_FAILED + */ + public static final ErrorMsg FILE_DELETE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("14") + .addErrCode("002") + .addDescription("File delete 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(); + + /** + * INVALID_HAP_FILE + */ + public static final ErrorMsg INVALID_HAP_FILE = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("16") + .addErrCode("001") + .addDescription("Invaild hap or hsp file.") + .addCause("%s") + .build(); + + /** + * READ_STAGE_HAP_VERIFY_INFO_FAILED + */ + 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_FA_HAP_VERIFY_INFO_FAILED + */ + 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_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_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(); + + /** + * CHECK_BUNDLETYPE_INVALID + */ + public static final ErrorMsg CHECK_BUNDLETYPE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("22") .addErrCode("003") - .addDescription("Command parser failed.") + .addDescription("Check bundleType is invalid") .addCause("%s") + .addSolution("%s") .build(); - public static final ErrorMsg COMMAND_VERIFY_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("18") - .addErrCode("002") - .addDescription("Command verify failed.") - .addCause("%s") - .build(); + /** + * CHECK_OVERLAYCF_CFG_FAILED + */ + public static final ErrorMsg CHECK_OVERLAYCF_CFG_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("27") + .addErrCode("002") + .addDescription("The names cannot be the same") + .addCause("%s") + .build(); - /** + /** + * CHECK_CONTINUE_BUNDLENAME_INVALID + */ + public static final ErrorMsg CHECK_CONTINUE_BUNDLENAME_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("28") + .addErrCode("004") + .addDescription("continueBundleName and BundleName cannot be the same") + .addCause("%s") + .addSolution("") + .build(); + + /** + * COMPRESS_HAP_FAILED + */ + public static final ErrorMsg COMPRESS_HAP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("29") + .addErrCode("001") + .addDescription("check StageHap failed") + .addCause("%s") + .build(); + + /** + * COMPRESS_HSP_FAILED + */ + public static final ErrorMsg COMPRESS_HSP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("29") + .addErrCode("002") + .addDescription("Compress Hsp failed") + .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(); + + + /** + * HSP_MODE_ARGS_INVALID + */ + public static final ErrorMsg HSP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("001") + .addDescription("ArgsValidInHspMode invalid") + .addCause("%s") + .build(); + + /** + * HAP_ADD_VERIF_INVALID + */ + public static final ErrorMsg HAP_ADD_VERIF_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("004") + .addDescription("VerifyValidInHapAdditionMode invalid.") + .addCause("%s") + .build(); + + /** + * BUNDLE_TYPE_SHARED_INVALID + */ + public static final ErrorMsg BUNDLE_TYPE_SHARED_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("005") + .addDescription("isBundleTypeShared invalid.") + .addCause("%s") + .build(); + + /** + * BUNDLE_TYPE_APPSERVICE_INVALID + */ + public static final ErrorMsg BUNDLE_TYPE_APPSERVICE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("006") + .addDescription("isBundleTypeAppService invalid.") + .addCause("%s") + .build(); + + /** + * HSP_HAS_ABILITIES_INVALID + */ + public static final ErrorMsg HSP_HAS_ABILITIES_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("007") + .addDescription("hspHasAbilities invalid.") + .addCause("%s") + .build(); + + /** + * HSP_HAS_EXTENSION_ABILITIES_INVALID + */ + public static final ErrorMsg HSP_HAS_EXTENSION_ABILITIES_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("008") + .addDescription("hspHasExtensionAbilities invalid.") + .addCause("%s") + .build(); + + /** + * HAS_HOME_ABILITY_INVALID + */ + public static final ErrorMsg HAS_HOME_ABILITY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("009") + .addDescription("hasHomeAbility invalid.") + .addCause("%s") + .build(); + + /** + * HAS_HOME_EXTENSION_ABILITY_INVALID + */ + public static final ErrorMsg HAS_HOME_EXTENSION_ABILITY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("010") + .addDescription("hasHomeExtensionAbility invalid.") + .addCause("%s") + .build(); + + /** + * CHECK_JSON_INVALID + */ + public static final ErrorMsg CHECK_JSON_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("011") + .addDescription("CheckJsonIsValid invalid.") + .addCause("%s") + .build(); + + /** + * DIRECTORY_INVALID + */ + public static final ErrorMsg DIRECTORY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("012") + .addDescription("directory is not exist.") + .addCause("%s") + .build(); + + /** + * HAR_MODE_ARGS_INVALID + */ + public static final ErrorMsg HAR_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("013") + .addDescription("isArgsValidInHarMode invalid.") + .addCause("%s") + .build(); + + /** + * HAP_MODE_ARGS_INVALID + */ + public static final ErrorMsg HAP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("014") + .addDescription("isArgsValidInHapMode invalid.") + .addCause("%s") + .build(); + + /** + * PACKINFO_PATH_FAILED + */ + public static final ErrorMsg PACKINFO_PATH_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("016") + .addDescription("isArgsValidInHapMode failed.") + .addCause("%s") + .build(); + + /** + * RPCID_PATH_INVALID + */ + public static final ErrorMsg RPCID_PATH_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("32") + .addErrCode("017") + .addDescription("isArgsValidInHapMode failed.") + .addCause("%s") + .build(); + + /** + * MERGE_TWO_PACKINFO_FAILED + */ + public static final ErrorMsg MERGE_TWO_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("001") + .addDescription("mergeTwoPackInfo failed.") + .addCause("%s") + .build(); + + /** + * VERIFY_PACKINFO_FAILED + */ + public static final ErrorMsg VERIFY_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("002") + .addDescription("verifyPackInfo failed.") + .addCause("%s") + .build(); + + /** + * VERIFY_APP_PACKINFO_FAILED + */ + public static final ErrorMsg VERIFY_APP_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("003") + .addDescription("verifyAppInPackInfo failed.") + .addCause("%s") + .build(); + + /** + * BUNDLE_TYPE_PACKINFO_INVALID + */ + public static final ErrorMsg BUNDLE_TYPE_PACKINFO_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("004") + .addDescription("bundleType invalid.") + .addCause("%s") + .build(); + + /** + * PARSE_PACKINFO_FORMS_NAME_FAILED + */ + public static final ErrorMsg PARSE_PACKINFO_FORMS_NAME_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("005") + .addDescription("parsePackInfoFormsName error") + .addCause("%s") + .build(); + + /** + * PARSE_DISTOR_MODULENAME_FAILED + */ + public static final ErrorMsg PARSE_DISTOR_MODULENAME_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("006") + .addDescription("parseFaModuleName failed") + .addCause("%s") + .build(); + + /** + * MERGE_PACKINFO_OBJ_FAILED + */ + public static final ErrorMsg MERGE_PACKINFO_OBJ_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("007") + .addDescription("mergePackInfoObj invalid") + .addCause("%s") + .build(); + + /** + * MERGE_BYPACKAGE_PAIR_FAILED + */ + public static final ErrorMsg MERGE_BYPACKAGE_PAIR_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("008") + .addDescription("packinfo failed") + .addCause("%s") + .build(); + + /** + * MERGE_OBJBY_PACKAGE_PAIR_FAILED + */ + public static final ErrorMsg MERGE_OBJBY_PACKAGE_PAIR_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("009") + .addDescription("mergeTwoPackInfoObjByPackagePair failed") + .addCause("%s") + .build(); + + /** + * PARSE_JSONOBJECT_FAILED + */ + public static final ErrorMsg PARSE_JSONOBJECT_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("010") + .addDescription("parse JOSNObject failed") + .addCause("%s") + .build(); + + /** + * PARSE_PACKINFO_FORMS_FAILED + */ + public static final ErrorMsg PARSE_PACKINFO_FORMS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("33") + .addErrCode("011") + .addDescription("parsePackInfoForms exception") + .addCause("%s") + .build(); + + /** + * COMMAND_FUNCS_FAILED + */ + public static final ErrorMsg COMMAND_FUNCS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("34") + .addErrCode("001") + .addDescription("version-code invalid") + .addCause("%s") + .build(); + + /** + * PACK_PATH_INVALID + */ + public static final ErrorMsg PACK_PATH_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("34") + .addErrCode("001") + .addDescription("Path invalid") + .addCause("%s") + .build(); + + // packing tool error + /** * EXECUTE_PACKING_TOOL_FAILED */ public static final ErrorMsg EXECUTE_PACKING_TOOL_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("18") + .addTypeCode("10") .addErrCode("001") .addDescription("Execute packing tool failed.") .addCause("%s") .addSolution("Please check the related log or error message and modify.") .build(); + /** + * EXECUTE_PACKING_TOOL_FAILED + */ + public static final ErrorMsg COMMAND_PARSER_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("10") + .addErrCode("002") + .addDescription("Command parser failed.") + .addCause("%s") + .build(); + + public static final ErrorMsg COMMAND_VERIFY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("10") + .addErrCode("003") + .addDescription("Command verify failed.") + .addCause("%s") + .build(); + + // io excepetion /** * COMPRESS_APP_IO_EXCEPTION @@ -67,7 +571,7 @@ public class PackingToolErrMsg { * COMPRESS_FILE_EXCEPTION */ public static final ErrorMsg COMPRESS_FILE_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("15") + .addTypeCode("12") .addErrCode("003") .addDescription("Compress file exception.") .addCause("%s") @@ -78,7 +582,7 @@ public class PackingToolErrMsg { * COMPRESS_PARALLEL_EXCEPTION */ public static final ErrorMsg COMPRESS_PARALLEL_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("15") + .addTypeCode("12") .addErrCode("004") .addDescription("Parallel compress exception.") .addCause("%s") @@ -100,18 +604,31 @@ public class PackingToolErrMsg { * FILE_NOT_FOUND */ public static final ErrorMsg FILE_NOT_FOUND = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("15") + .addTypeCode("12") .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(); + // compress error + // 可以把各个模式的统一报错归到一类去 + /** + * COMPRESS_APP_VERIFY_FAILED + */ + public static final ErrorMsg COMPRESS_APP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("002") + .addDescription("Compress app file verify failed.") + .addCause("%s") + .addSolution("%s") + .build(); + /** * FILE_NOT_FOUND */ public static final ErrorMsg FILE_IO_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("15") + .addTypeCode("12") .addErrCode("002") .addDescription("File io exception.") .addCause("%s") @@ -139,7 +656,7 @@ public class PackingToolErrMsg { * INVALID_HAP_OR_HSP_FILE */ public static final ErrorMsg INVALID_HAP_FILE = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("15") + .addTypeCode("12") .addErrCode("007") .addDescription("Invaild hap or hsp file.") .addCause("%s") @@ -150,9 +667,9 @@ public class PackingToolErrMsg { * READ_STAGE_HAP_VERIFY_INFO */ public static final ErrorMsg READ_STAGE_HAP_VERIFY_INFO_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("15") + .addTypeCode("11") .addErrCode("001") - .addDescription("Read stage hap verify info io exception.") + .addDescription("Read stage hap verify info failed.") .addCause("%s") .build(); @@ -160,8 +677,8 @@ public class PackingToolErrMsg { * READ_STAGE_HAP_VERIFY_INFO */ public static final ErrorMsg READ_FA_HAP_VERIFY_INFO_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("20") - .addErrCode("002") + .addTypeCode("12") + .addErrCode("010") .addDescription("Read FA hap verify info io exception.") .addCause("%s") .build(); @@ -170,7 +687,7 @@ public class PackingToolErrMsg { * PARSE_JSON_FAILED */ public static final ErrorMsg PARSE_JSON_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("21") + .addTypeCode("13") .addErrCode("001") .addDescription("Parse json profile failed.") .addCause("%s") @@ -180,17 +697,18 @@ public class PackingToolErrMsg { * PARSE_JSON_OBJECT_EXCEPTION */ public static final ErrorMsg PARSE_JSON_OBJECT_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("21") + .addTypeCode("13") .addErrCode("002") .addDescription("Failed to parse json Object.") .addCause("%s") .build(); + //compress.error /** * PARSE_STAGE_VERSION_FAILED */ public static final ErrorMsg PARSE_STAGE_VERSION_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("21") + .addTypeCode("13") .addErrCode("003") .addDescription("Failed to parse stage version from module.json.") .addCause("%s") @@ -200,7 +718,7 @@ public class PackingToolErrMsg { * PARSE_STAGE_MODULE_FAILED */ public static final ErrorMsg PARSE_STAGE_MODULE_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("21") + .addTypeCode("13") .addErrCode("004") .addDescription("Failed to parse json file for stage module.") .addCause("%s") @@ -210,7 +728,7 @@ public class PackingToolErrMsg { * PARSE_STAGE_BUNDLE_TYPE_FAILED */ public static final ErrorMsg PARSE_STAGE_BUNDLE_TYPE_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("21") + .addTypeCode("13") .addErrCode("005") .addDescription("Failed to parse module.json and bundleType.") .addCause("%s") @@ -221,7 +739,7 @@ public class PackingToolErrMsg { * PARSE_PROXY_DATA_URI_FAILED */ public static final ErrorMsg PARSE_PROXY_DATA_URI_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("21") + .addTypeCode("13") .addErrCode("006") .addDescription("Failed to parse module.json and proxyData object.") .addCause("%s") @@ -232,7 +750,7 @@ public class PackingToolErrMsg { * APP_FIELDS_INVALID */ public static final ErrorMsg CHECK_BUNDLETYPE_CONSISTENCY_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("21") + .addTypeCode("13") .addErrCode("007") .addDescription("bundleType consistency check failed.") .addCause("%s") @@ -243,7 +761,7 @@ public class PackingToolErrMsg { * PARSE_FA_MODULE_NAME_FAILED */ public static final ErrorMsg PARSE_FA_MODULE_NAME_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("21") + .addTypeCode("13") .addErrCode("008") .addDescription("Failed to parse config.json.") .addCause("%s") @@ -253,7 +771,7 @@ public class PackingToolErrMsg { * PARSE_FA_PACKAGE_STR_FAILED */ public static final ErrorMsg PARSE_FA_PACKAGE_STR_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("21") + .addTypeCode("13") .addErrCode("009") .addDescription("Failed to parse config.json and package object.") .addCause("%s") @@ -263,7 +781,7 @@ public class PackingToolErrMsg { * FA_MODULE_API_VERSION_MISSING */ public static final ErrorMsg PARSE_FA_MODULE_API_VERSION_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("21") + .addTypeCode("13") .addErrCode("010") .addDescription("Failed to parse FA apiVersion.") .addCause("%s") @@ -273,7 +791,7 @@ public class PackingToolErrMsg { * PARSE_PATCH_MODULE_NAME_FAILED */ public static final ErrorMsg PARSE_PATCH_MODULE_NAME_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("21") + .addTypeCode("13") .addErrCode("011") .addDescription("Failed to parse patch module name from patch.json.") .addCause("%s") @@ -284,7 +802,7 @@ public class PackingToolErrMsg { * APP_MODE_ARGS_INVALID */ public static final ErrorMsg APP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("23") + .addTypeCode("11") .addErrCode("003") .addDescription("Parse and check args invalid in app mode.") .addCause("%s") @@ -336,7 +854,7 @@ public class PackingToolErrMsg { * JSON_SPECIAL_PROCESS_FAILED */ public static final ErrorMsg JSON_SPECIAL_PROCESS_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("15") + .addTypeCode("12") .addErrCode("005") .addDescription("json SpecialProcess io exception.") .addCause("%s") @@ -358,7 +876,7 @@ public class PackingToolErrMsg { * PARSE_FA_HAP_VERIFY_INFO_FAILED */ public static final ErrorMsg PARSE_FA_HAP_VERIFY_INFO_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("21") + .addTypeCode("13") .addErrCode("012") .addDescription("Failed to parse FA hap verify info from config.json.") .addCause("%s") @@ -369,21 +887,9 @@ public class PackingToolErrMsg { * CHECK_APP_MODE_FAILED */ public static final ErrorMsg CHECK_SHARED_APP_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("15") + .addTypeCode("12") .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.") + .addDescription("Check shared App mode invalid.") .addCause("%s") .addSolution("%s") .build(); @@ -392,7 +898,7 @@ public class PackingToolErrMsg { * CHECK_APP_MODE_FAILED */ public static final ErrorMsg CHECK_BUNDLETYPE_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("15") + .addTypeCode("12") .addErrCode("011") .addDescription("Check bundleType invalid.") .addCause("%s") @@ -403,7 +909,7 @@ public class PackingToolErrMsg { * APP_FIELDS_INVALID */ public static final ErrorMsg CHECK_APP_FIELDS_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("22") + .addTypeCode("14") .addErrCode("004") .addDescription("app fields is invalid.") .addCause("%s") @@ -414,7 +920,7 @@ public class PackingToolErrMsg { * APP_FIELDS_DIFFERENT_ERROR */ public static final ErrorMsg APP_FIELDS_DIFFERENT_ERROR = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("22") + .addTypeCode("14") .addErrCode("005") .addDescription("Some app variable is different.") .addCause("%s") @@ -423,9 +929,9 @@ public class PackingToolErrMsg { //hap verify error public static final ErrorMsg CHECK_HAP_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("22") + .addTypeCode("14") .addErrCode("006") - .addDescription("Check hap info is invalid.") + .addDescription("Verify hap info is invalid.") .addCause("%s") .addSolution("Please check the related error message and modify.") .build(); @@ -434,7 +940,7 @@ public class PackingToolErrMsg { * CHECK_MODULE_NAME_INVALID */ public static final ErrorMsg CHECK_MODULE_NAME_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("22") + .addTypeCode("14") .addErrCode("007") .addDescription("Check module name is invalid.") .addCause("%s") @@ -445,7 +951,7 @@ public class PackingToolErrMsg { * CHECK_MODULE_NAME_INVALID */ public static final ErrorMsg CHECK_POLICY_DISJOINT_ERROR = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("22") + .addTypeCode("14") .addErrCode("008") .addDescription("Check two distroFilter policy disjoint invalid.") .addCause("%s") @@ -456,7 +962,7 @@ public class PackingToolErrMsg { * CHECK_PACKAGE_NAME_INVALID */ public static final ErrorMsg CHECK_PACKAGE_NAME_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("22") + .addTypeCode("14") .addErrCode("009") .addDescription("Check packageName invalid.") .addCause("%s") @@ -467,7 +973,7 @@ public class PackingToolErrMsg { * CHECK_ENTRY_INVALID */ public static final ErrorMsg CHECK_ENTRY_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("22") + .addTypeCode("14") .addErrCode("010") .addDescription("Check entry module invalid.") .addCause("%s") @@ -478,7 +984,7 @@ public class PackingToolErrMsg { * CHECK_ENTRY_INVALID */ public static final ErrorMsg CHECK_DEPENDENCY_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("22") + .addTypeCode("14") .addErrCode("011") .addDescription("Check dependency is invalid.") .addCause("%s") @@ -489,7 +995,7 @@ public class PackingToolErrMsg { * DEPENDENCY_LIST_INVALID */ public static final ErrorMsg DEPENDENCY_LIST_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("22") + .addTypeCode("14") .addErrCode("012") .addDescription("HAP or HSP cannot depend on feature or entry module.") .addCause("%s") @@ -500,7 +1006,7 @@ public class PackingToolErrMsg { * ATOMICSERVICE_PRELOADS_INVALID */ public static final ErrorMsg ATOMICSERVICE_PRELOADS_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("22") + .addTypeCode("14") .addErrCode("013") .addDescription("atomicservice preloads is invalid.") .addCause("%s") @@ -510,7 +1016,7 @@ public class PackingToolErrMsg { * ATOMICSERVICE_INVALID */ public static final ErrorMsg TARGET_MODULE_NAME_NOT_EXIST = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("22") + .addTypeCode("14") .addErrCode("014") .addDescription("targetModuleName is not exist.") .addCause("%s") @@ -520,7 +1026,7 @@ public class PackingToolErrMsg { * COMPILE_SDK_INVALID */ public static final ErrorMsg COMPILE_SDK_TYPE_DIFFERENT = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("22") + .addTypeCode("14") .addErrCode("015") .addDescription("compileSdkType is different.") .addCause("%s") @@ -531,7 +1037,7 @@ public class PackingToolErrMsg { * PROXY_DATA_URI_NOT_UNIQUE */ public static final ErrorMsg PROXY_DATA_URI_NOT_UNIQUE = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("22") + .addTypeCode("14") .addErrCode("016") .addDescription("proxy data uri is not unique.") .addCause("%s") @@ -542,7 +1048,7 @@ public class PackingToolErrMsg { * CONTINUE_TYPE_INVALID */ public static final ErrorMsg CONTINUE_TYPE_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("22") + .addTypeCode("14") .addErrCode("017") .addDescription("ContinueType is invalid") .addCause("%s") @@ -553,24 +1059,13 @@ public class PackingToolErrMsg { * ATOMICSERVICE_INVALID */ public static final ErrorMsg ATOMICSERVICE_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("22") + .addTypeCode("14") .addErrCode("018") .addDescription("Check atomicservice is invalid.") .addCause("%s") .build(); - // compress error - // 可以把各个模式的统一报错归到一类去 - /** - * COMPRESS_APP_VERIFY_FAILED - */ - public static final ErrorMsg COMPRESS_APP_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("15") - .addErrCode("003") - .addDescription("Compress app file verify failed.") - .addCause("%s") - .addSolution("%s") - .build(); + /** * COMPRESS_APP_VERIFY_FAILED -- Gitee From 9ca37aa3e603138e3f7ee8afd6040984dd0fb4c1 Mon Sep 17 00:00:00 2001 From: nj1868 Date: Mon, 17 Feb 2025 10:07:27 +0800 Subject: [PATCH 4/5] update Signed-off-by: nj1868 Change-Id: I62d737a8728e021ff33e5cc6091f9a50fe9e0a4a --- adapter/ohos/CompressVerify.java | 227 ++++++---- adapter/ohos/Compressor.java | 120 ++--- adapter/ohos/FileUtils.java | 4 +- adapter/ohos/ModuleJsonUtil.java | 160 ++++--- adapter/ohos/PackingToolErrMsg.java | 670 ++++++++++++++++------------ adapter/ohos/Utility.java | 4 +- 6 files changed, 682 insertions(+), 503 deletions(-) diff --git a/adapter/ohos/CompressVerify.java b/adapter/ohos/CompressVerify.java index 409afc4d..d2a73c43 100644 --- a/adapter/ohos/CompressVerify.java +++ b/adapter/ohos/CompressVerify.java @@ -140,8 +140,7 @@ public class CompressVerify { case Utility.PACKAGE_NORMALIZE: return validatePackageNormalizeMode(utility); default: - String errMsg = "CompressVerify::commandVerify mode is invalid."; - LOG.error(PackingToolErrMsg.COMMAND_MODE_INVALID.toString(errMsg)); + LOG.error(PackingToolErrMsg.COMMAND_MODE_INVALID.toString()); return false; } } @@ -236,11 +235,13 @@ public class CompressVerify { if (!utility.getRpcidPath().isEmpty()) { File file = new File(utility.getRpcidPath()); if (!file.isFile()) { - LOG.error("CompressVerify::isArgsValidInHapMode rpcid-path is not a file."); + String errMsg = "rpcid-path is not a file."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!RPCID_PROFILE.equals(file.getName())) { - LOG.error("CompressVerify::isArgsValidInHapMode rpcid-path must be rpcid.sc file."); + String errMsg = "rpcid-path must be rpcid.sc file."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } @@ -251,11 +252,13 @@ public class CompressVerify { if (!utility.getPackInfoPath().isEmpty()) { File file = new File(utility.getPackInfoPath()); if (!file.isFile()) { - LOG.error("CompressVerify::isArgsValidInHapMode --pack-info-path is not a file."); + String errMsg = "pack-info-path is not a file."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!PACK_INFO.equals(file.getName())) { - LOG.error("CompressVerify::isArgsValidInHapMode --pack-info-path must be pack.info file."); + String errMsg = "pack-info-path must be pack.info file."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } @@ -264,12 +267,14 @@ public class CompressVerify { private static boolean isVerifyValidInHapCommonMode(Utility utility) { if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::commandPathVerify json-path is empty."); + String errMsg = "commandPathVerify json-path is empty"; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!isPathValid(utility.getJsonPath(), TYPE_FILE, JSON_PROFILE) && !isPathValid(utility.getJsonPath(), TYPE_FILE, MODULE_PROFILE)) { - LOG.error("CompressVerify::isArgsValidInHarMode json-path must be config.json file."); + String errMsg = "json-path must be config.json file."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -279,39 +284,45 @@ public class CompressVerify { if (!utility.getApkPath().isEmpty() && !compatibleProcess(utility, utility.getApkPath(), utility.getFormattedApkPathList(), APK_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode shell-apk-path is invalid."); + String errMsg = "shell-apk-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getProfilePath().isEmpty()) { File file = new File(utility.getProfilePath()); if (!file.isFile() || !PROFILE_NAME.equals(file.getName())) { - LOG.error("CompressVerify::isArgsValidInHapMode profile-path must be CAPABILITY.profile file."); + String errMsg = "profile-path must be CAPABILITY.profile file."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!utility.getDexPath().isEmpty() && !compatibleProcess(utility, utility.getDexPath(), utility.getFormattedDexPathList(), DEX_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode dex-path is invalid."); + String errMsg = "dex-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getAbcPath().isEmpty() && !compatibleProcess(utility, utility.getAbcPath(), utility.getFormattedAbcPathList(), ABC_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode abc-path is invalid."); + String errMsg = "abc-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getDirList().isEmpty() && !splitDirList(utility, utility.getDirList(), utility.getFormatedDirList())) { - LOG.error("CompressVerify::isArgsValidInHapMode --dir-list is invalid."); + String errMsg = "dir-list is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getPkgContextPath().isEmpty()) { File file = new File(utility.getPkgContextPath()); if (!file.isFile() || !PKG_CONTEXT_INFO.equals(file.getName())) { - LOG.error("CompressVerify::isArgsValidInHapMode --pkg-context-path file must be " + PKG_CONTEXT_INFO); + String errMsg = "pkg-context-path file must be " + PKG_CONTEXT_INFO + "."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg + PKG_CONTEXT_INFO )); return false; } } @@ -327,76 +338,90 @@ public class CompressVerify { private static boolean isVerifyValidInHapMode(Utility utility) { File file = new File(utility.getIndexPath()); if (!utility.getIndexPath().isEmpty() && !file.isFile() && INDEX_PROFILE.equals(file.getName())) { - LOG.error("CompressVerify::isArgsValidInHapMode index-path must be resources.index file."); + String errMsg = "isArgsValidInHapMode index-path must be resources.index file."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getSoPath().isEmpty() && !compatibleProcess(utility, utility.getSoPath(), utility.getFormattedSoPathList(), SO_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode maple-so-path is invalid."); + String errMsg = "isArgsValidInHapMode maple-so-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getAbilitySoPath().isEmpty() && !compatibleProcess(utility, utility.getAbilitySoPath(), utility.getFormattedAbilitySoPathList(), SO_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode ability-so-path is invalid."); + String errMsg = "isArgsValidInHapMode ability-so-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getSoDir())) { - LOG.error("CompressVerify::isArgsValidInHapMode maple-so-dir is invalid."); + String errMsg = "isArgsValidInHapMode maple-so-dir is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getLibPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode lib-path is invalid."); + String errMsg = "isArgsValidInHapMode lib-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getHnpPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode hnp-path is invalid."); + String errMsg = "isArgsValidInHapMode hnp-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getResPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode res-path is invalid."); + String errMsg = "isArgsValidInHapMode res-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getResourcesPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode resources-path is invalid."); + String errMsg = "isArgsValidInHapMode resources-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getAssetsPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode assets-path is invalid."); + String errMsg = "isArgsValidInHapMode assets-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getSharedLibsPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode shared-libs-path is invalid."); + String errMsg = "isArgsValidInHapMode shared-libs-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getJarPath().isEmpty() && !compatibleProcess(utility, utility.getJarPath(), utility.getFormattedJarPathList(), JAR_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode jar-path is invalid."); + String errMsg = "isArgsValidInHapMode jar-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getTxtPath().isEmpty() && !compatibleProcess(utility, utility.getTxtPath(), utility.getFormattedTxtPathList(), TXT_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHapMode txt-path is invalid."); + String errMsg = "isArgsValidInHapMode txt-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getANPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode an-path is invalid."); + String errMsg = "isArgsValidInHapMode an-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getEtsPath().isEmpty() && !isPathExists(utility.getEtsPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode ets-path is invalid."); + String errMsg = "isArgsValidInHapMode ets-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -421,45 +446,53 @@ public class CompressVerify { */ private static boolean isVerifyValidInHarMode(Utility utility) { if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::isArgsValidInHarMode json-path is empty."); + String errMsg = "isArgsValidInHarMode 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 = "isArgsValidInHarMode 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 = "isArgsValidInHarMode 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 = "isArgsValidInHarMode 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 = "isArgsValidInHarMode 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 = "isArgsValidInHarMode 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 = "isArgsValidInHarMode 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 = "isArgsValidInHarMode assets-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -895,8 +928,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 = "isDirectoryValidStrictCase directory is not exist, directoryPath: "; + LOG.error(PackingToolErrMsg.DIRECTORY_INVALID.toString(errMsg + path)); return false; } if (file.isDirectory()) { @@ -925,12 +958,14 @@ public class CompressVerify { private static boolean isVerifyValidInHspMode(Utility utility) { if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::isArgsValidInHspMode json-path is empty."); + String errMsg = "json-path is empty."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!isPathValid(utility.getJsonPath(), TYPE_FILE, MODULE_PROFILE)) { - LOG.error("CompressVerify::isArgsValidInHspMode json-path must be module.json file."); + String errMsg = "json-path must be module.json file."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -938,87 +973,99 @@ public class CompressVerify { boolean hspHasAbilities = hspHasAbilities(utility); boolean hspHasExtensionAbilities = hspHasExtensionAbilities(utility); if (hspHasAbilities && hspHasExtensionAbilities) { - LOG.error("shared/appService hsp has abilities and extensionAbilities"); + String errMsg = "shared/appService hsp has abilities and extensionAbilities at the same time."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (hspHasAbilities) { - LOG.error("shared/appService hsp has abilities"); + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString("shared/appService hsp has abilities.")); return false; } if (hspHasExtensionAbilities) { - LOG.error("shared/appService hsp has extensionAbilities"); + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString("shared/appService hsp has extensionAbilities.")); return false; } } if(hasHomeAbility(utility)) { - LOG.error("hsp has home ability"); + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString("hsp has entry ability.")); return false; } if (hasHomeExtensionAbility(utility)) { - LOG.error("hsp has home extensionAbility"); + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString("hsp has entry extensionAbility.")); return false; } if (!utility.getJarPath().isEmpty() && !compatibleProcess(utility, utility.getJarPath(), utility.getFormattedJarPathList(), JAR_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHspMode jar-path is invalid."); + String errMsg = "isArgsValidInHspMode jar-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getTxtPath().isEmpty() && !compatibleProcess(utility, utility.getTxtPath(), utility.getFormattedTxtPathList(), TXT_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHspMode txt-path is invalid."); + String errMsg = "txt-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getLibPath().isEmpty() && !isPathValid(utility.getLibPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHspMode lib-path is invalid."); + String errMsg = "lib-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getResPath().isEmpty() && !isPathValid(utility.getResPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHspMode res-path is invalid."); + String errMsg = "res-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getResourcesPath().isEmpty() && !isPathValid(utility.getResourcesPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHspMode resources-path is invalid."); + String errMsg = "resources-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getAssetsPath().isEmpty() && !isPathValid(utility.getAssetsPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHspMode assets-path is invalid."); + String errMsg = "assets-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getDirList().isEmpty() && !splitDirList(utility, utility.getDirList(), utility.getFormatedDirList())) { - LOG.error("CompressVerify::isArgsValidInHapMode --dir-list is invalid."); + String errMsg = "dir-list is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getAPPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode ap-path is invalid."); + String errMsg = "ap-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (isHapPathValid(utility.getANPath())) { - LOG.error("CompressVerify::isArgsValidInHapMode an-path is invalid."); + String errMsg = "an-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getPkgContextPath().isEmpty()) { File file = new File(utility.getPkgContextPath()); if (!file.isFile() || !PKG_CONTEXT_INFO.equals(file.getName())) { - LOG.error("CompressVerify::isArgsValidInHspMode --pkg-context-path file must be " + PKG_CONTEXT_INFO); + String errMsg = "pkg-context-path file must be "+ PKG_CONTEXT_INFO; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!utility.getEtsPath().isEmpty() && !isPathExists(utility.getEtsPath())) { - LOG.error("CompressVerify::isArgsValidInHspMode ets-path is invalid."); + String errMsg = "ets-path is invalid."; + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -1027,48 +1074,58 @@ public class CompressVerify { private static boolean isVerifyValidInHapAdditionMode(Utility utility) { if (utility.getHapPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hapPath is empty."); + String errMsg = "isVerifyValidInHapAdditionMode hapPath is empty."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_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 = "isVerifyValidInHapAdditionMode hapPath cannot be a folder."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_INVALID.toString(errMsg)); return false; } if (!(hapPath.endsWith(HAP_SUFFIX) || hapPath.endsWith(HSP_SUFFIX))) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hapPath is invalid."); + String errMsg = "isVerifyValidInHapAdditionMode hapPath is invalid."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_INVALID.toString(errMsg)); return false; } if (!hapFile.exists()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hap file does not exist."); + String errMsg = "isVerifyValidInHapAdditionMode hap file does not exist."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_INVALID.toString(errMsg)); return false; } if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode jsonPath is empty."); + String errMsg = "isVerifyValidInHapAdditionMode jsonPath is empty."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_INVALID.toString(errMsg)); return false; } if (!utility.getJsonPath().endsWith(JSON_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode jsonPath is invalid."); + String errMsg = "isVerifyValidInHapAdditionMode jsonPath is invalid."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_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 = "isVerifyValidInHapAdditionMode json file does not exist."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_INVALID.toString(errMsg)); return false; } if (!checkJsonIsValid(jsonFile)) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode json format is incorrect."); + String errMsg = "isVerifyValidInHapAdditionMode json format is incorrect."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_INVALID.toString(errMsg)); return false; } if (utility.getOutPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode outPath is empty."); + String errMsg = "isVerifyValidInHapAdditionMode outPath is empty."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_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 = "isVerifyValidInHapAdditionMode outPath is file."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_INVALID.toString(errMsg)); return false; } File absoluteHapFile = new File(utility.getAbsoluteHapPath()); @@ -1076,7 +1133,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 = "isVerifyValidInHapAdditionMode target file already exists."; + LOG.error(PackingToolErrMsg.HAP_ADD_VERIF_INVALID.toString(errMsg)); return false; } return true; @@ -1091,7 +1149,8 @@ public class CompressVerify { jsonData.append((char) ch); } } catch (IOException e) { - LOG.error("CompressVerify::CheckJsonIsValid failed: " + e.getMessage()); + String errMsg = "CheckJsonIsValid failed: "; + LOG.error(PackingToolErrMsg.CHECK_JSON_INVALID.toString(errMsg + e.getMessage())); return false; } JSONValidator validator = JSONValidator.from(jsonData.toString()); @@ -1165,11 +1224,12 @@ public class CompressVerify { if(optional.isPresent()) { return ModuleJsonUtil.parseStageBundleType(optional.get()).equals(BUNDLE_TYPE_SHARE); } else { - LOG.error("CompressVerify::isBundleTypeShared jsonPath content invalid"); + String errMsg = "Parse jsonPath file content failed."; + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_SHARED_INVALID.toString(errMsg));//todo 试一下传一个空的json文件 验证 return false; } } catch (BundleException e) { - LOG.error("CompressVerify::isBundleTypeShared exception: " + e.getMessage()); + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_SHARED_INVALID.toString(e.getMessage())); return false; } } @@ -1180,11 +1240,12 @@ public class CompressVerify { if(optional.isPresent()) { return ModuleJsonUtil.parseStageBundleType(optional.get()).equals(BUNDLE_TYPE_APP_SERVICE); } else { - LOG.error("CompressVerify::isBundleTypeAppService jsonPath content invalid"); + String errMsg = "Parse jsonPath file content failed."; + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_APPSERVICE_INVALID.toString(errMsg)); return false; } } catch (BundleException e) { - LOG.error("CompressVerify::isBundleTypeAppService exception: " + e.getMessage()); + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_APPSERVICE_INVALID.toString(e.getMessage())); return false; } } @@ -1195,11 +1256,12 @@ public class CompressVerify { if(optional.isPresent()) { return ModuleJsonUtil.parseModuleType(optional.get()).equals(BUNDLE_TYPE_SHARE) && !ModuleJsonUtil.parseAbilityNames(optional.get()).isEmpty(); } else { - LOG.error("CompressVerify::hspHasAbilities jsonPath content invalid"); + String errMsg = "Parse jsonPath file content failed."; + LOG.error(PackingToolErrMsg.HSP_HAS_ABILITIES_FAILED.toString(errMsg)); return false; } } catch (BundleException e) { - LOG.error("CompressVerify::hspHasAbilities exception: " + e.getMessage()); + LOG.error(PackingToolErrMsg.HSP_HAS_ABILITIES_FAILED.toString(e.getMessage())); return false; } } @@ -1211,10 +1273,11 @@ public class CompressVerify { return ModuleJsonUtil.parseModuleType(optional.get()).equals(BUNDLE_TYPE_SHARE) && !ModuleJsonUtil.parseExtensionAbilityName(optional.get()).isEmpty(); } else { - LOG.error("CompressVerify::hspHasExtensionAbilities jsonPath content invalid"); + String errMsg = "Parse jsonPath file content failed."; + LOG.error(PackingToolErrMsg.HSP_HAS_EXTENSION_ABILITIES_FAILED.toString(errMsg)); } } catch (BundleException e) { - LOG.error("CompressVerify::hspHasExtensionAbilities exception: " + e.getMessage()); + LOG.error(PackingToolErrMsg.HSP_HAS_EXTENSION_ABILITIES_FAILED.toString(e.getMessage())); } return false; } @@ -1224,7 +1287,8 @@ public class CompressVerify { boolean result = false; Optional optional = FileUtils.getFileContent(utility.getJsonPath()); if(!optional.isPresent()) { - LOG.error("CompressVerify::hasHomeAbility jsonPath content invalid"); + String errMsg = "Parse jsonPath file content failed."; + LOG.error(PackingToolErrMsg.HAS_HOME_ABILITY_INVALID.toString(errMsg)); return false; } Map abilitiesMap = ModuleJsonUtil.parseAbilitySkillsMap(optional.get()); @@ -1234,7 +1298,7 @@ public class CompressVerify { LOG.info("CompressVerify::hasHomeAbilities result = " + result); return result; } catch (BundleException e) { - LOG.error("CompressVerify::hasHomeAbilities exception: " + e.getMessage()); + LOG.error(PackingToolErrMsg.HAS_HOME_ABILITY_INVALID.toString(e.getMessage())); return false; } } @@ -1260,17 +1324,18 @@ public class CompressVerify { boolean result = false; Optional optional = FileUtils.getFileContent(utility.getJsonPath()); if (!optional.isPresent()) { - LOG.error("CompressVerify::hasHomeExtensionAbility jsonPath content invalid"); + String errMsg = "Parse jsonPath file content failed."; + LOG.error(PackingToolErrMsg.HAS_HOME_EXTENSION_ABILITY_INVALID.toString(errMsg)); return false; } Map extensionAbilitiesMap = ModuleJsonUtil.parseExtensionAbilitySkillsMap(optional.get()); if (extensionAbilitiesMap.containsValue(true)) { result = true; } - LOG.info("CompressVerify::hasHomeExtensionAbility result = " + result); + LOG.info("CompressVerify::hasHomeAbilities result = " + result); return result; } catch (BundleException e) { - LOG.error("CompressVerify::hasHomeExtensionAbility exception: " + e.getMessage()); + LOG.error(PackingToolErrMsg.HAS_HOME_EXTENSION_ABILITY_INVALID.toString(e.getMessage())); return false; } } diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index a86c1062..caf04c90 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -434,35 +434,35 @@ public class Compressor { Optional optional = FileUtils.getFileContent(utility.getJsonPath()); String jsonString = optional.get(); if (!checkStageAsanTsanEnabledValid(jsonString)) { - LOG.error("checkStageAsanTsanEnabledValid failed."); - throw new BundleException("compressHsp failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("check StageAsanTsanEnabledValid failed.")); + throw new BundleException("compress hsp failed."); } if (!checkStageHwasanEnabledValid(jsonString)) { - LOG.error("checkStageHwasanEnabledValid failed."); - throw new BundleException("compressHsp failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("check StageHwasanEnabledValid failed.")); + throw new BundleException("compress hsp failed."); } if (!checkStageUbsanEnabledValid(jsonString)) { - LOG.error("checkStageUbsanEnabledValid failed."); - throw new BundleException("compressHsp failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("check StageUbsanEnabledValid failed.")); + throw new BundleException("compress hsp failed."); } if (!checkStageAtomicService(jsonString)) { - LOG.error("checkStageAtomicService failed."); - throw new BundleException("checkStageAtomicService failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("check StageAtomicService failed.")); + throw new BundleException("check Stage AtomicService failed."); } // check continueBundleName in module.json if (!checkContinueBundleNameIsValid(jsonString)) { - LOG.error("checkContinueBundleNameIsValid failed."); - throw new BundleException("compressHsp failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("check ContinueBundleNameIsValid failed.")); + throw new BundleException("compress hsp failed."); } // check whether is an overlay hsp or not if (!checkStageOverlayCfg(jsonString)) { - LOG.error("checkStageOverlayCfg failed."); - throw new BundleException("checkStageOverlayCfg failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("checkStageOverlayCfg failed.")); + throw new BundleException("checkStageOverlayCfg failed"); } String moduleType = ModuleJsonUtil.parseModuleType(jsonString); if (!TYPE_SHARED.equals(moduleType)) { - LOG.error("module type must be shared."); - throw new BundleException("compressHsp failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("module type must be shared.")); + throw new BundleException("compressHsp failed"); } } compressHSPMode(utility); @@ -472,14 +472,14 @@ public class Compressor { private void compressHap(Utility utility) throws BundleException { if (utility.getJsonPath().isEmpty() && !utility.getBinPath().isEmpty()) { // only for slim device - compressHapMode(utility); + compressHapMode(utility);//todo compress file return; } - setGenerateBuildHash(utility); + setGenerateBuildHash(utility);//todo if (isModuleJSON(utility.getJsonPath())) { if (!checkStageHap(utility)) { - LOG.error("checkStageHap failed."); - throw new BundleException("checkStageHap failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HAP_FAILED.toString("verify Stage Hap info failed.")); + throw new BundleException("verify Stage Hap info failed."); } Optional optional = FileUtils.getFileContent(utility.getJsonPath()); String jsonString = optional.get(); @@ -492,7 +492,7 @@ public class Compressor { LOG.warning("Compress mode is hap, but app type is shared."); } compressHapModeForModule(utility); - buildHash(utility); + buildHash(utility);//todo } else { compressHapMode(utility); buildHash(utility); @@ -502,7 +502,8 @@ public class Compressor { private static boolean hasGenerateBuildHash(Utility utility) throws BundleException { File file = new File(utility.getJsonPath()); if (!file.exists()) { - LOG.error("Compressor::hasGenerateBuildHash failed for json file not exist"); + String errMsg = "parse json file not exist."; + LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString(errMsg)); throw new BundleException("Compressor::hasGenerateBuildHash failed for json file not exist"); } InputStream json = null; @@ -511,8 +512,8 @@ public class Compressor { json = new FileInputStream(file); JSONObject jsonObject = JSON.parseObject(json, JSONObject.class); if (jsonObject == null || !jsonObject.containsKey(APP) || !jsonObject.containsKey(MODULE)) { - LOG.error("json file is invalid."); - throw new BundleException("json file is invalid."); + LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString("json file is invalid.")); + throw new BundleException("parse json file is invalid."); } JSONObject appJson = jsonObject.getJSONObject(APP); JSONObject moduleJson = jsonObject.getJSONObject(MODULE); @@ -520,10 +521,10 @@ public class Compressor { res = true; } } catch (BundleException exception) { - LOG.error("Compressor::hasGenerateBuildHash failed."); + LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString(exception.getMessage())); throw new BundleException("Compressor::hasGenerateBuildHash failed."); } catch (JSONException | IOException e) { - LOG.error("Compressor::hasGenerateBuildHash failed for json file is invalid." + e.getMessage()); + LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString(e.getMessage())); throw new BundleException("Compressor::hasGenerateBuildHash failed."); } finally { FileUtils.closeStream(json); @@ -539,7 +540,8 @@ public class Compressor { copyFileToTempDir(utility); File file = new File(utility.getJsonPath()); if (!file.exists()) { - LOG.error("Compressor::setGenerateBuildHash failed for json file not exist"); + String errMsg = "parse json file not exist."; + LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString(errMsg)); throw new BundleException("Compressor::setGenerateBuildHash failed for json file not exist"); } InputStream json = null; @@ -548,7 +550,7 @@ public class Compressor { json = new FileInputStream(file); JSONObject jsonObject = JSON.parseObject(json, JSONObject.class); if (!jsonObject.containsKey(APP) || !jsonObject.containsKey(MODULE)) { - LOG.error("json file is invalid."); + LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString("parse json file is invalid.")); throw new BundleException("json file is invalid."); } JSONObject appJson = jsonObject.getJSONObject(APP); @@ -569,10 +571,10 @@ public class Compressor { new FileOutputStream(utility.getJsonPath()), StandardCharsets.UTF_8)); bw.write(pretty); } catch (BundleException exception) { - LOG.error("Compressor::setGenerateBuildHash failed."); + LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString(exception.getMessage())); throw new BundleException("Compressor::setGenerateBuildHash failed."); } catch (NullPointerException | IOException | JSONException e) { - LOG.error("Compressor::setGenerateBuildHash failed, json data err: " + e.getMessage()); + LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString("json data err: " + e.getMessage())); throw new BundleException("Compressor::setGenerateBuildHash failed, json data err."); } finally { FileUtils.closeStream(json); @@ -581,7 +583,7 @@ public class Compressor { bw.flush(); bw.close(); } catch (IOException e) { - LOG.error("Compressor::setGenerateBuildHash failed for IOException " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("failed set generate build hash, IOException: " + e.getMessage())); throw new BundleException("Compressor::setGenerateBuildHash failed."); } } @@ -592,7 +594,8 @@ public class Compressor { String jsonPath = utility.getJsonPath(); File oldfile = new File(jsonPath); if (!oldfile.exists()) { - LOG.error("Compressor::copyFileToTempDir failed for json file not found."); + String errMsg = "parse json file not found, parse json path is " + jsonPath + "."; + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString(errMsg)); throw new BundleException("Compressor::copyFileToTempDir failed for json file not found."); } String oldFileParent = oldfile.getParent(); @@ -615,7 +618,7 @@ public class Compressor { } utility.setJsonPath(tempPath); } catch (IOException e) { - LOG.error("Compressor::copyFileToTempDir failed, IOException: " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("copy file to temp Dir failed, IOException:" + e.getMessage())); throw new BundleException("Compressor::copyFileToTempDir failed."); } } @@ -636,7 +639,7 @@ public class Compressor { try { putBuildHash(utility, hash); } catch (IOException e) { - LOG.error("Compressor::putBuildHash failed, " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("putBuildHash failed: " + e.getMessage())); throw new BundleException("Compressor::putBuildHash failed."); } } @@ -681,7 +684,8 @@ public class Compressor { String jsonPath = utility.getJsonPath(); File file = new File(jsonPath); if (!file.exists()) { - LOG.error("Compressor::putBuildHash failed for json file not exist"); + String errMsg = "parse json file not found, parse json path is " + jsonPath + "."; + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString(errMsg)); throw new BundleException("Compressor::putBuildHash failed for json file not exist"); } InputStream json = null; @@ -696,10 +700,10 @@ public class Compressor { bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(jsonPath), StandardCharsets.UTF_8)); bw.write(pretty); } catch (IOException e) { - LOG.error("Compressor::putBuildHash failed, IOException: " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("putBuildHash failed, IOException: " + e.getMessage())); throw new BundleException("Compressor::putBuildHash failed."); } catch (NullPointerException e) { - LOG.error("Compressor::putBuildHash failed, json data err: " + e.getMessage()); + LOG.error(PackingToolErrMsg.NULL_POINTER_EXPECTION.toString("json data err: " + e.getMessage())); throw new BundleException("Compressor::putBuildHash failed, json data err."); } finally { FileUtils.closeStream(json); @@ -730,7 +734,7 @@ public class Compressor { } if (hapVerifyInfos.isEmpty()) { - LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString("no hapVerifyInfo")); + LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString("no avaiable hapVerifyInfo.")); return false; } @@ -760,25 +764,25 @@ public class Compressor { Optional optional = FileUtils.getFileContent(utility.getJsonPath()); String jsonString = optional.get(); if (!checkStageAsanTsanEnabledValid(jsonString)) { - LOG.error("checkStageAsanTsanEnabledValid failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("check StageAsanTsanEnabled valid failed.")); return false; } if (!checkStageHwasanEnabledValid(jsonString)) { - LOG.error("checkStageHwasanEnabledValid failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("check StageHwasanEnabled valid failed.")); return false; } if (!checkStageUbsanEnabledValid(jsonString)) { - LOG.error("checkStageUbsanEnabledValid failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("check StageUbsanEnabled valid failed.")); return false; } // check atomicService in module.json if (!checkStageAtomicService(jsonString)) { - LOG.error("checkStageAtomicService failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("check Stage atomicService failed.")); return false; } // check continueBundleName in module.json if (!checkContinueBundleNameIsValid(jsonString)) { - LOG.error("checkContinueBundleNameIsValid failed."); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("check ContinueBundleName valid failed.")); return false; } return true; @@ -788,7 +792,7 @@ public class Compressor { boolean asanEnabled = ModuleJsonUtil.getStageAsanEnabled(jsonString); boolean tsanEnabled = ModuleJsonUtil.getStageTsanEnabled(jsonString); if (asanEnabled && tsanEnabled) { - LOG.error("asanEnabled and tsanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_AS_TSAN_ENABLED.toString("asanEnabled and tsanEnabled cannot be true at the same time.")); return false; } return true; @@ -800,15 +804,15 @@ public class Compressor { boolean gwpAsanEnabled = ModuleJsonUtil.getStageGwpAsanEnabled(jsonString); boolean hwasanEnabled = ModuleJsonUtil.getStageHwasanEnabled(jsonString); if (hwasanEnabled && asanEnabled) { - LOG.error("hwasanEnabled and asanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_HWASAN_ENABLED_INVALID.toString("hwasanEnabled and asanEnabled cannot be true at the same time")); return false; } if (hwasanEnabled && tsanEnabled) { - LOG.error("hwasanEnabled and tsanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_HWASAN_ENABLED_INVALID.toString("hwasanEnabled and tsanEnabled cannot be true at the same time")); return false; } if (hwasanEnabled && gwpAsanEnabled) { - LOG.error("hwasanEnabled and GWPAsanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_HWASAN_ENABLED_INVALID.toString("hwasanEnabled and GWPAsanEnabled cannot be true at the same time")); return false; } return true; @@ -824,7 +828,7 @@ public class Compressor { } for (int i = 0; i < continueBundleNameList.size(); i++) { if (bundleName.equals(continueBundleNameList.get(i))) { - LOG.error("continueBundleName cannot include self."); + LOG.error(PackingToolErrMsg.CHECK_CONTINUE_BUNDLENAME_INVALID.toString("continueBundleName include self.")); return false; } } @@ -838,15 +842,15 @@ public class Compressor { boolean hwasanEnabled = ModuleJsonUtil.getStageHwasanEnabled(jsonString); boolean ubsanEnabled = ModuleJsonUtil.getStageUbsanEnabled(jsonString); if(ubsanEnabled && asanEnabled) { - LOG.error("ubsanEnabled and asanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_UBASAN_ENABLED_INVALID.toString("ubsanEnabled and asanEnabled cannot be true at the same time.")); return false; } if(ubsanEnabled && tsanEnabled) { - LOG.error("ubsanEnabled and tsanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_UBASAN_ENABLED_INVALID.toString("ubsanEnabled and tsanEnabled cannot be true at the same time.")); return false; } if(ubsanEnabled && hwasanEnabled) { - LOG.error("ubsanEnabled and hwasanEnabled cannot be true at the same time."); + LOG.error(PackingToolErrMsg.CHECK_UBASAN_ENABLED_INVALID.toString("ubsanEnabled and hwasanEnabled cannot be true at the same time.")); return false; } return true; @@ -855,17 +859,17 @@ public class Compressor { private static boolean checkStageAtomicService(String jsonString) throws BundleException { // check consistency of atomicService if (!ModuleJsonUtil.isModuleAtomicServiceValid(jsonString)) { - LOG.error("check module atomicService failed."); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_FAILED.toString("check consistency of atomicService failed.")); return false; } // check entry module must have ability if (!ModuleJsonUtil.checkEntryInAtomicService(jsonString)) { - LOG.error("checkEntryInAtomicService failed."); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_FAILED.toString("check entry module failed.")); return false; } // check installationFree if (!ModuleJsonUtil.checkAtomicServiceInstallationFree(jsonString)) { - LOG.error("check atomic service installationFree failed."); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_FAILED.toString("check atomic service installationFree failed.")); return false; } @@ -878,17 +882,17 @@ public class Compressor { if (!targetModuleName.isEmpty()) { // check targetModuleName and requestPermission if (ModuleJsonUtil.isExistedStageRequestPermissions(jsonString)) { - LOG.error("targetModuleName cannot be existed with requestPermissions."); + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString("targetModuleName cannot be existed with requestPermissions.")); return false; } // check targetModuleName and name if (targetModuleName.equals(ModuleJsonUtil.parseStageModuleName(jsonString))) { - LOG.error("targetModuleName cannot be same with name in the overlay module."); + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString("targetModuleName cannot be same with name in the overlay module.")); return false; } } else { if (ModuleJsonUtil.isExistedStageModuleTargetPriority(jsonString)) { - LOG.error("targetPriority cannot be existed without the targetModuleName in module.json."); + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString("targetPriority cannot be existed without the targetModuleName in module.json.")); return false; } } @@ -896,16 +900,16 @@ public class Compressor { String targetBundleName = ModuleJsonUtil.getStageTargetBundleName(jsonString); if (!targetBundleName.isEmpty()) { if (targetModuleName.isEmpty()) { - LOG.error("targetModuleName is necessary in the overlay bundle."); + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString("targetModuleName is necessary in the overlay bundle.")); return false; } if (targetBundleName.equals(ModuleJsonUtil.parseBundleName(jsonString))) { - LOG.error("targetBundleName cannot be same with the bundleName."); + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString("targetBundleName cannot be same with the bundleName.")); return false; } } else { if (ModuleJsonUtil.isExistedStageAppTargetPriority(jsonString)) { - LOG.error("targetPriority cannot be existed without the targetBundleName in app.json."); + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString("targetPriority cannot be existed without the targetBundleName in app.json.")); return false; } } diff --git a/adapter/ohos/FileUtils.java b/adapter/ohos/FileUtils.java index 19541d85..620790fa 100644 --- a/adapter/ohos/FileUtils.java +++ b/adapter/ohos/FileUtils.java @@ -155,7 +155,7 @@ class FileUtils { content.append(tempString); } } catch (IOException msg) { - LOG.error("get file content fail, msg is " + msg.getMessage()); + LOG.error(PackingToolErrMsg.GET_FILE_CONTENT_FAILED.toString(msg.getMessage())); return Optional.empty(); } finally { closeStream(reader); @@ -176,7 +176,7 @@ class FileUtils { fileStream.close(); } } catch (IOException msg) { - LOG.error("stream close Error, msg is " + msg.getMessage()); + LOG.error(PackingToolErrMsg.CLOSE_STREAM_EXPECTION.toString(msg.getMessage())); } } diff --git a/adapter/ohos/ModuleJsonUtil.java b/adapter/ohos/ModuleJsonUtil.java index c667500f..d385fe25 100644 --- a/adapter/ohos/ModuleJsonUtil.java +++ b/adapter/ohos/ModuleJsonUtil.java @@ -392,13 +392,15 @@ 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 = "mergeTwoPackInfo 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 = "mergeTwoPackInfo merge pack.info failed: "; + LOG.error(PackingToolErrMsg.MERGE_TWO_PACKINFO_FAILED.toString(errMsg + e.getMessage())); + throw new BundleException(errMsg); } return desPackInfo; } @@ -412,24 +414,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 = "verifyPackInfo fail to read pack.info."; + 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 = "verifyPackInfo pack.info do 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 = "verifyPackInfo pack.info do 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 = "verifyPackInfo verify app failed."; + LOG.error(PackingToolErrMsg.VERIFY_PACKINFO_FAILED.toString(errMsg)); return false; } @@ -445,32 +451,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 = "verifyAppInPackInfo input null json object."; + 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 = "verifyAppInPackInfo bundleName is different."; + 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 = "verifyAppInPackInfo bundleType is different."; + 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 = "verifyAppInPackInfo 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 = "verifyAppInPackInfo versionCode is different."; + LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } return true; @@ -485,7 +496,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 = "checkBundleTypeInPackInfo pack.info has empty module."; + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_PACKINFO_INVALID.toString(errMsg)); return false; } String finalBundleType = "app"; @@ -497,7 +509,8 @@ class ModuleJsonUtil { srcBundleType = getJsonString(srcAppObj, BUNDLE_TYPE); } if (!finalBundleType.equals(srcBundleType)) { - LOG.error("bundleType in pack.info is not same."); + String errMsg = "bundleType in pack.info is not same."; + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_PACKINFO_INVALID.toString(errMsg)); return false; } return true; @@ -513,7 +526,7 @@ class ModuleJsonUtil { public static boolean verifyModuleInPackInfo(JSONArray finalModuleObs, JSONArray srcModuleObs) throws BundleException { if (finalModuleObs.isEmpty() || srcModuleObs.isEmpty()) { - LOG.error("ModuleJsonUtil:verifyModuleInPackInfo pack.info has empty module."); + LOG.error("verifyModuleInPackInfo pack.info has empty module."); throw new BundleException("ModuleJsonUtil:verifyModuleInPackInfo pack.info has empty module."); } List moduleNames = new ArrayList<>(); @@ -521,7 +534,7 @@ class ModuleJsonUtil { JSONObject finalModuleObj = finalModuleObs.getJSONObject(i); String moduleName = parseDistroModuleName(finalModuleObj); if (moduleNames.contains(moduleName)) { - LOG.error("ModuleJsonUtil:verifyModuleInPackInfo duplicated moduleName."); + LOG.error("verifyModuleInPackInfo duplicated moduleName."); return false; } else { moduleNames.add(moduleName); @@ -531,7 +544,7 @@ class ModuleJsonUtil { JSONObject srcModuleObj = srcModuleObs.getJSONObject(i); String moduleName = parseDistroModuleName(srcModuleObj); if (moduleNames.contains(moduleName)) { - LOG.error("ModuleJsonUtil:verifyModuleInPackInfo duplicated moduleName."); + LOG.error("verifyModuleInPackInfo duplicated moduleName."); return false; } else { moduleNames.add(moduleName); @@ -553,13 +566,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 = "parsePackInfoFormsName error: summary is null."; + 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 = "parsePackInfoFormsName error: summary.modules is null."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_NAME_FAILED.toString(errMsg)); return; } @@ -567,13 +582,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 = "parsePackInfoFormsName error: summary.modules.distro is null."; + 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 = "parsePackInfoFormsName error: summary.modules.distro.moduleName is null."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_NAME_FAILED.toString(errMsg)); continue; } @@ -628,22 +645,26 @@ class ModuleJsonUtil { String moduleName = ""; try { if (moduleObj == null) { - LOG.error("ModuleJsonUtil:parseFaModuleName failed: json file do not contain module."); + String errMsg = "parseFaModuleName failed: json file do not contain module."; + LOG.error(PackingToolErrMsg.PARSE_DISTOR_MODULENAME_FAILED.toString(errMsg)); throw new BundleException("ModuleJsonUtil:parseFaModuleName failed: json file do not contain module."); } JSONObject distroObj = moduleObj.getJSONObject(DISTRO); if (distroObj == null) { - LOG.error("ModuleJsonUtil:parseFaModuleName failed: json file do not contain distro."); + String errMsg = "parseFaModuleName failed: json file do not contain distro."; + LOG.error(PackingToolErrMsg.PARSE_DISTOR_MODULENAME_FAILED.toString(errMsg)); throw new BundleException("ModuleJsonUtil:parseFaModuleName failed: json file do not contain distro."); } if (!distroObj.containsKey(MODULE_NAME)) { - LOG.error("ModuleJsonUtil:parseFaModuleName failed: json file do not contain moduleName."); + String errMsg = "parseFaModuleName failed: json file do not contain moduleName."; + LOG.error(PackingToolErrMsg.PARSE_DISTOR_MODULENAME_FAILED.toString(errMsg)); throw new BundleException("ModuleJsonUtil:parseFaModuleName failed:" + "json file do not contain moduleName."); } moduleName = distroObj.getString(MODULE_NAME); } catch (BundleException e) { - LOG.error("ModuleJsonUtil:parseFaModuleName failed."); + String errMsg = "parseFaModuleName failed."; + LOG.error(PackingToolErrMsg.PARSE_DISTOR_MODULENAME_FAILED.toString(errMsg)); throw new BundleException("ModuleJsonUtil:parseFaModuleName failed."); } return moduleName; @@ -658,23 +679,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 = "mergePackInfoObj input an invalid json object."; + 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 = "mergePackInfoObj input json file has empty summary."; + 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 = "mergePackInfoObj input json file has empty module."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_FAILED.toString(errMsg)); throw new BundleException(errMsg); } finalModuleObs.addAll(srcModuleObs); @@ -682,8 +703,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 = "mergePackInfoObj input json file has empty packages."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_FAILED.toString(errMsg)); throw new BundleException(errMsg); } finalPackageObs.addAll(srcPackageObs); @@ -708,7 +729,7 @@ class ModuleJsonUtil { srcPackObj = JSON.parseObject(srcPackInfo); } catch (JSONException exception) { String errMsg = "parse JSONObject failed: " + exception.getMessage(); - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.MERGE_BYPACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // verify app in pack.info @@ -718,7 +739,7 @@ class ModuleJsonUtil { JSONObject srcAppObj = srcSummaryObj.getJSONObject(APP); if (!verifyAppInPackInfo(finalAppObj, srcAppObj)) { String errMsg = "verify pack.info failed, different version, bundleType or bundleName."; - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.MERGE_BYPACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } for (HashMap.Entry entry : packagePair.entrySet()) { @@ -740,22 +761,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 = "mergeTwoPackInfoObjByPackagePair failed: pack.info is not json object."; + LOG.error(PackingToolErrMsg.MERGE_OBJBY_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 = "mergeTwoPackInfoObjByPackagePair failed: pack.info do not contain summary."; + LOG.error(PackingToolErrMsg.MERGE_OBJBY_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 = "mergeTwoPackInfoObjByPackagePair input json file has empty module."; + LOG.error(PackingToolErrMsg.MERGE_OBJBY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException("ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair input json file has empty module."); } @@ -770,9 +792,9 @@ class ModuleJsonUtil { } } if (!findModule) { - String errMsg = "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair" + + String errMsg = "mergeTwoPackInfoObjByPackagePair" + " input json do not contain " + moduleName + "."; - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.MERGE_OBJBY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // merge package @@ -780,8 +802,8 @@ class ModuleJsonUtil { JSONArray srcPackages = srcPackObj.getJSONArray(PACKAGES); if (finalPackages == null || srcPackages == null) { String errMsg = - "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair failed: pack.info do not contain packages."; - LOG.error(errMsg); + "mergeTwoPackInfoObjByPackagePair failed: pack.info do not contain packages."; + LOG.error(PackingToolErrMsg.MERGE_OBJBY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } boolean findPackage = false; @@ -794,9 +816,9 @@ class ModuleJsonUtil { } } if (!findPackage) { - String errMsg = "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair input json do not contain " + String errMsg = "mergeTwoPackInfoObjByPackagePair input json do not contain " + packageName + "."; - LOG.error(errMsg); + LOG.error(PackingToolErrMsg.MERGE_OBJBY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } } @@ -1451,7 +1473,7 @@ class ModuleJsonUtil { try { jsonObj = JSON.parseObject(jsonString); } catch (JSONException exception) { - String errMsg = "parse JSONobject exception."; + String errMsg = "parse JSON object exception."; LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString(errMsg)); throw new BundleException(errMsg); } @@ -1857,12 +1879,13 @@ class ModuleJsonUtil { try { jsonObject = JSON.parseObject(jsonString); } catch (JSONException exception) { - LOG.error("parse JOSNObject failed in isExistedProperty."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("parse JOSN Object failed in isExistedProperty.")); throw new BundleException("parse JOSNObject failed in isExistedProperty."); } JSONObject appObj = jsonObject.getJSONObject(fatherProperty); if (appObj == null) { - LOG.error("parse failed, input module.json is invalid, module.json has no " + fatherProperty + "."); + String errMsg = "parse failed, input module.json is invalid, module.json has no "+ fatherProperty; + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString(errMsg)); throw new BundleException("parse failed, input module.json is invalid, module.json has no " + fatherProperty + "."); } @@ -1914,7 +1937,8 @@ class ModuleJsonUtil { if (moduleObj.containsKey(ATOMIC_SERVICE) && (!appObj.containsKey(BUNDLE_TYPE) || !getJsonString(appObj, BUNDLE_TYPE).equals(ATOMIC_SERVICE))) { - LOG.error("module can not config atomicService when bundleType is not atomicService."); + String errMsg = "module can not config atomicService when bundleType is not atomicService."; + LOG.error(PackingToolErrMsg.CHECK_MODULE_ATOMIC_SERVICE_FAILED.toString(errMsg)); return false; } return true; @@ -1931,7 +1955,8 @@ class ModuleJsonUtil { return true; } if (parseModuleType(jsonString).equals(ENTRY) && parseAbilityNames(jsonString).isEmpty()) { - LOG.error("entry module must contain at least one ability."); + String errMsg = "entry module must contain at least one ability."; + LOG.error(PackingToolErrMsg.CHECK_LEASTONE_ABILITY.toString(errMsg)); return false; } return true; @@ -1951,9 +1976,9 @@ class ModuleJsonUtil { boolean installationFree = getJsonBooleanValue(moduleObj, INSTALLATION_FREE, false); if (!appObj.containsKey(BUNDLE_TYPE)) { if (installationFree) { - String errMessage = "The app.json5 file configuration does not match the installationFree:" + + String errMsg = "The app.json5 file configuration does not match the installationFree:" + " true settings. Add the bundleType field to the app.json5 file and set it atomicService."; - LOG.error(errMessage); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString(errMessage)); return false; } return true; @@ -1961,26 +1986,26 @@ class ModuleJsonUtil { String bundleType = getJsonString(appObj, BUNDLE_TYPE); if (bundleType.equals(APP)) { if (installationFree) { - LOG.error("installationFree must be false when bundleType is app."); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString("installationFree must be false when bundleType is app.")); return false; } } else if (bundleType.equals(ATOMIC_SERVICE)) { if (!installationFree) { - LOG.error("installationFree must be true when bundleType is atomicService."); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString("installationFree must be true when bundleType is atomicService.")); return false; } } else if (SHARED.equals(bundleType)) { if (installationFree) { - LOG.error("installationFree must be false when bundleType is shared."); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString("installationFree must be false when bundleType is shared.")); return false; } } else if (APP_SERVICE.equals(bundleType)) { if (installationFree) { - LOG.error("installationFree must be false when bundleType is appService."); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString("installationFree must be false when bundleType is appService.")); return false; } } else { - LOG.error("bundleType is invalid in app.json."); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED.toString("bundleType is invalid in app.json.")); return false; } return true; @@ -2045,7 +2070,7 @@ class ModuleJsonUtil { for (int i = 0; i < formJsonList.size(); i++) { JSONObject formObj = formJsonList.getJSONObject(i); if (formObj == null || !formObj.containsKey(NAME)) { - LOG.warning("ModuleJsonUtil::parsePackInfoForms error: " + + LOG.warning("parsePackInfoForms error: " + "summary.modules.extensionAbilities.forms.name is null."); continue; } @@ -2053,20 +2078,23 @@ 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 = "parsePackInfoForms exception: " + + "summary.modules.extensionAbilities.forms.defaultDimension is null."; + 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 = "parsePackInfoForms exception: " + + "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 = "parsePackInfoForms exception: " + + "summary.modules.extensionAbilities.forms.supportDimensions is null."; + 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/PackingToolErrMsg.java b/adapter/ohos/PackingToolErrMsg.java index 224e26a2..fb61cf31 100644 --- a/adapter/ohos/PackingToolErrMsg.java +++ b/adapter/ohos/PackingToolErrMsg.java @@ -21,88 +21,356 @@ package ohos; * @since 2025/01/06 */ public class PackingToolErrMsg { - - /** - * CHECK_MODULE_ATOMIC_SERVICE_FAILED + + // packing tool error + /** + * EXECUTE_PACKING_TOOL_FAILED */ - public static final ErrorMsg CHECK_MODULE_ATOMIC_SERVICE_FAILED = ErrorMsg.getPackingToolErrBuilder() + public static final ErrorMsg EXECUTE_PACKING_TOOL_FAILED = ErrorMsg.getPackingToolErrBuilder() .addTypeCode("10") - .addErrCode("003") - .addDescription("when bundleType is not atomicService") + .addErrCode("001") + .addDescription("Execute packing tool failed.") .addCause("%s") + .addSolution("Please check the related log or error message and modify.") .build(); /** - * CHECK_LEASTONE_ABILITY + * EXECUTE_PACKING_TOOL_FAILED */ - public static final ErrorMsg CHECK_LEASTONE_ABILITY = ErrorMsg.getPackingToolErrBuilder() + public static final ErrorMsg COMMAND_PARSER_FAILED = ErrorMsg.getPackingToolErrBuilder() .addTypeCode("10") - .addErrCode("004") - .addDescription("check at least one ability") + .addErrCode("002") + .addDescription("Command parser failed.") .addCause("%s") .build(); + public static final ErrorMsg COMMAND_VERIFY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("10") + .addErrCode("003") + .addDescription("Command verify failed.") + .addCause("%s") + .build(); + + + //compress verify error + /** + * HAP_MODE_ARGS_INVALID + */ + public static final ErrorMsg HAP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("001") + .addDescription("Parse and check args invalid in hap mode.") + .addCause("%s") + .build(); + + /** + * HSP_MODE_ARGS_INVALID + */ + public static final ErrorMsg HSP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("002") + .addDescription("Parse and check args invalid in hsp mode.") + .addCause("%s") + .build(); + /** + * COMMAND_MODE_INVALID + */ + public static final ErrorMsg COMMAND_MODE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("011") + .addDescription("command verify mode is invalid.") + .addCause("Input mode is invalid.") + .build(); + + /** + * APP_MODE_ARGS_INVALID + */ + public static final ErrorMsg APP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("003") + .addDescription("Parse and check args invalid in app mode.") + .addCause("%s") + .build(); + /** - * CHECK_ATOMIC_SERVICE_FAILED + * BUNDLE_TYPE_SHARED_INVALID */ - public static final ErrorMsg CHECK_ATOMIC_SERVICE_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("10") + public static final ErrorMsg BUNDLE_TYPE_SHARED_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("004") + .addDescription("check bundleTypeShared failed.") + .addCause("%s") + .addSolution("Please check the related error message and modify.") + .build(); + + /** + * BUNDLE_TYPE_APPSERVICE_INVALID + */ + public static final ErrorMsg BUNDLE_TYPE_APPSERVICE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") .addErrCode("005") - .addDescription("check EntryInAtomicService failed.") + .addDescription("check BundleTypeAppService invalid.") .addCause("%s") + .addSolution("Please check the related error message and modify.") .build(); - /** - * CHECK_STAGE_HAP_FAILED + /** + * HSP_HAS_ABILITIES_FAILED */ - public static final ErrorMsg CHECK_STAGE_HAP_FAILED = ErrorMsg.getPackingToolErrBuilder() + public static final ErrorMsg HSP_HAS_ABILITIES_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("006") + .addDescription("check hsp has abilities failed.") + .addCause("%s") + .build(); + + /** + * HSP_HAS_EXTENSION_ABILITIES_FAILED + */ + public static final ErrorMsg HSP_HAS_EXTENSION_ABILITIES_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("007") + .addDescription("check hsp has extension abilities failed.") + .addCause("%s") + .build(); + + /** + * HAS_HOME_ABILITY_INVALID + */ + public static final ErrorMsg HAS_HOME_ABILITY_INVALID = ErrorMsg.getPackingToolErrBuilder() .addTypeCode("11") + .addErrCode("008") + .addDescription("check hsp has entry abilitiy failed.") + .addCause("%s") + .build(); + + /** + * HAS_HOME_EXTENSION_ABILITY_INVALID + */ + public static final ErrorMsg HAS_HOME_EXTENSION_ABILITY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("009") + .addDescription("check hsp has entry ExtensionAbility failed.") + .addCause("%s") + .build(); + /** + * RPCID_PATH_INVALID + */ + // public static final ErrorMsg RPCID_PATH_INVALID = ErrorMsg.getPackingToolErrBuilder() + // .addTypeCode("11") + // .addErrCode("030") + // .addDescription("isArgsValidInHapMode failed.") + // .addCause("%s") + // .build(); + +// /** +// * PACKINFO_PATH_FAILED +// */ +// public static final ErrorMsg PACKINFO_PATH_FAILED = ErrorMsg.getPackingToolErrBuilder() +// .addTypeCode("11") +// .addErrCode("031") +// .addDescription("isArgsValidInHapMode failed.") +// .addCause("%s") +// .build(); + + //packing process error(compress.java) + /** + * COMPRESS_PROCESS + */ + public static final ErrorMsg COMPRESS_PROCESS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") .addErrCode("001") - .addDescription("check AsanTsanEnabledValid failed") + .addDescription("Execute compress process failed.") .addCause("%s") + .addSolution("%s") .build(); /** + * COMPRESS_HAP_FAILED + */ + public static final ErrorMsg COMPRESS_HAP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("002") + .addDescription("Compress Stage Hap failed.") + .addCause("%s") + .addSolution("Please check the related error message and modify.") + .build(); + + /** + * CHECK_STAGE_HAP_FAILED + */ + public static final ErrorMsg CHECK_STAGE_HAP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("003") + .addDescription("verify stage hap info failed.") + .addCause("%s") + .build(); + + /** * CHECK_AS_TSAN_ENABLED */ public static final ErrorMsg CHECK_AS_TSAN_ENABLED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("11") + .addTypeCode("12") .addErrCode("004") - .addDescription("Check asanEnabled and tsanEnabled failed") + .addDescription("Check asanEnabled and tsanEnabled failed.") .addCause("%s") .addSolution("Please set the correct values for the parameters.") .build(); - /** - * CHECK_HWASAN_ENABLED_INVALID + /** + * CHECK_UBASAN_ENABLED_INVALID */ - - public static final ErrorMsg CHECK_HWASAN_ENABLED_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("11") + public static final ErrorMsg CHECK_UBASAN_ENABLED_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") .addErrCode("005") - .addDescription("Check hwasanEnabled and asanEnabled failed") + .addDescription("Check ubsanEnabled and asanEnabled failed.") .addCause("%s") .addSolution("Please set the correct values for the parameters.") .build(); - /** - * CHECK_UBASAN_ENABLED_INVALID + /** + * CHECK_HWASAN_ENABLED_INVALID */ - public static final ErrorMsg CHECK_UBASAN_ENABLED_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("11") + public static final ErrorMsg CHECK_HWASAN_ENABLED_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("005") + .addDescription("Check hwasanEnabled and asanEnabled failed") + .addCause("%s") + .addSolution("Please set the correct values for the parameters.") + .build(); + + /** + * CHECK_ATOMIC_SERVICE_FAILED + */ + public static final ErrorMsg CHECK_ATOMIC_SERVICE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("006") + .addDescription("check atomicService failed.") + .addCause("%s") + .build(); + + /** + * CHECK_CONTINUE_BUNDLENAME_INVALID + */ + public static final ErrorMsg CHECK_CONTINUE_BUNDLENAME_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("007") + .addDescription("continueBundleName and BundleName cannot be the same.") + .addCause("%s") + .addSolution("Ensure continueBundleName not inclue self.") + .build(); + + /** + * COMPRESS_PROCESS_EXCEPTION + */ + public static final ErrorMsg COMPRESS_PROCESS_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") .addErrCode("008") - .addDescription("Check ubsanEnabled and asanEnabled failed") + .addDescription("Process compress exception.") + .addCause("%s") + .addSolution("Please check the related error message and modify. If the issue persists, review the logs for more details.") + .build(); + + /** + * HAS_GENERATE_BUILD_HASH + */ + public static final ErrorMsg HAS_GENERATE_BUILD_HASH = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("009") + .addDescription("verify has generate build hash failed.") .addCause("%s") - .addSolution("Please set the correct values for the parameters.") .build(); + /** + * SET_GENERATE_BUILD_HASH + */ + public static final ErrorMsg SET_GENERATE_BUILD_HASH = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("010") + .addDescription("set generate build hash failed.") + .addCause("%s") + .build(); + + /** + * CHECK_OVERLAY_CFG_FAILED + */ + public static final ErrorMsg CHECK_OVERLAY_CFG_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("12") + .addErrCode("011") + .addDescription("check whether is an overlay hsp or not failed.") + .addCause("%s") + .build(); + + //module json check error (modulejsonutil.java) + /** + * PARSE_JSON_OBJECT_EXCEPTION + */ + public static final ErrorMsg PARSE_JSON_OBJECT_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("001") + .addDescription("Failed to parse json Object.") + .addCause("%s") + .build(); + + /** + * PARSE_JSON_FAILED + */ + public static final ErrorMsg PARSE_JSON_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("002") + .addDescription("Parse json profile failed.") + .addCause("%s") + .build(); + + /** + * CHECK_MODULE_ATOMIC_SERVICE_FAILED + */ + public static final ErrorMsg CHECK_MODULE_ATOMIC_SERVICE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("003") + .addDescription("check module atomicService invalid.") + .addCause("%s") + .build(); + + /** + * PARSE_STAGE_MODULE_FAILED + */ + public static final ErrorMsg PARSE_STAGE_MODULE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("004") + .addDescription("Failed to parse json file for stage module.") + .addCause("%s") + .build(); + + /** + * PARSE_STAGE_BUNDLE_TYPE_FAILED + */ + public static final ErrorMsg PARSE_STAGE_BUNDLE_TYPE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("005") + .addDescription("Failed to parse module.json and bundleType.") + .addCause("%s") + .addSolution("%s") + .build(); + + /** + * CHECK_LEASTONE_ABILITY + */ + public static final ErrorMsg CHECK_LEASTONE_ABILITY = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("13") + .addErrCode("006") + .addDescription("check entry module at least one ability failed.") + .addCause("%s") + .build(); + + /** * CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED */ public static final ErrorMsg CHECK_ATOMIC_SERVICE_INSTALLATION_FREE_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("12") - .addErrCode("002") - .addDescription("file configuration does not match") + .addTypeCode("13") + .addErrCode("007") + .addDescription("check module atomic installation free invalid.") .addCause("%s") .build(); @@ -113,9 +381,81 @@ public class PackingToolErrMsg { public static final ErrorMsg FILE_NOT_FOUND = ErrorMsg.getPackingToolErrBuilder() .addTypeCode("14") .addErrCode("001") - .addDescription("File not found exception.") + .addDescription("File avaiable not found exception.") + .addCause("%s") + .build(); + + /** + * CLOSE_ZIP_OUTPUT_STREAM_EXPECTION + */ + public static final ErrorMsg CLOSE_ZIP_OUTPUT_STREAM_EXPECTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("14") + .addErrCode("002") + .addDescription("close zip output stream exception.") + .addCause("%s") + .addSolution("Please check the related error message and modify the operation. If the issue persists, review the logs for more details.") + .build(); + /* + * CLOSE_STREAM_EXPECTION + */ + public static final ErrorMsg CLOSE_STREAM_EXPECTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("14") + .addErrCode("003") + .addDescription("IO exception when closing stream.") + .addCause("%s") + .addSolution("Please check the related error message and modify the operation.") + .build(); + /* + * GET_FILE_CONTENT_FAILED + */ + public static final ErrorMsg GET_FILE_CONTENT_FAILED = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("14") + .addErrCode("004") + .addDescription("Get file content failed.") + .addCause("%s") + .addSolution("Please check the related error message and modify.") + .build(); + + /** + * FILE_NOT_EXIST + */ + public static final ErrorMsg FILE_NOT_EXIST = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("14") + .addErrCode("005") + .addDescription("Parse file not exist.") .addCause("%s") .build(); + + //io exception + /** + * IO_EXCEPTION + */ + public static final ErrorMsg IO_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") + .addErrCode("001") + .addDescription("io exception.") + .addCause("%s") + .addSolution("Please check the following:\n" + + "1. Ensure the file path is correct and the file exists.\n" + + "2. Verify you have the necessary permissions to access the file.\n" + + "3. Check for possible disk or file system errors.\n" + + "4. Review the related error message for further insights.") + .build(); + + /* + * NULL_POINTER_EXPECTION + */ + public static final ErrorMsg NULL_POINTER_EXPECTION = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("15") + .addErrCode("002") + .addDescription("null pointer exception.") + .addCause("%s") + .addSolution("Please review the related error message for further insights.") + .build(); + +////////////////////////////////////////////////////---//////////////////////// + //module json check error (modulejsonutil.java) + /** * FILE_DELETE_FAILED @@ -129,16 +469,6 @@ public class PackingToolErrMsg { // 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(); /** * INVALID_HAP_FILE @@ -201,37 +531,6 @@ public class PackingToolErrMsg { .addSolution("%s") .build(); - /** - * CHECK_OVERLAYCF_CFG_FAILED - */ - public static final ErrorMsg CHECK_OVERLAYCF_CFG_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("27") - .addErrCode("002") - .addDescription("The names cannot be the same") - .addCause("%s") - .build(); - - /** - * CHECK_CONTINUE_BUNDLENAME_INVALID - */ - public static final ErrorMsg CHECK_CONTINUE_BUNDLENAME_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("28") - .addErrCode("004") - .addDescription("continueBundleName and BundleName cannot be the same") - .addCause("%s") - .addSolution("") - .build(); - - /** - * COMPRESS_HAP_FAILED - */ - public static final ErrorMsg COMPRESS_HAP_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("29") - .addErrCode("001") - .addDescription("check StageHap failed") - .addCause("%s") - .build(); - /** * COMPRESS_HSP_FAILED */ @@ -242,28 +541,8 @@ public class PackingToolErrMsg { .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(); - /** - * HSP_MODE_ARGS_INVALID - */ - public static final ErrorMsg HSP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("32") - .addErrCode("001") - .addDescription("ArgsValidInHspMode invalid") - .addCause("%s") - .build(); /** * HAP_ADD_VERIF_INVALID @@ -275,66 +554,6 @@ public class PackingToolErrMsg { .addCause("%s") .build(); - /** - * BUNDLE_TYPE_SHARED_INVALID - */ - public static final ErrorMsg BUNDLE_TYPE_SHARED_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("32") - .addErrCode("005") - .addDescription("isBundleTypeShared invalid.") - .addCause("%s") - .build(); - - /** - * BUNDLE_TYPE_APPSERVICE_INVALID - */ - public static final ErrorMsg BUNDLE_TYPE_APPSERVICE_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("32") - .addErrCode("006") - .addDescription("isBundleTypeAppService invalid.") - .addCause("%s") - .build(); - - /** - * HSP_HAS_ABILITIES_INVALID - */ - public static final ErrorMsg HSP_HAS_ABILITIES_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("32") - .addErrCode("007") - .addDescription("hspHasAbilities invalid.") - .addCause("%s") - .build(); - - /** - * HSP_HAS_EXTENSION_ABILITIES_INVALID - */ - public static final ErrorMsg HSP_HAS_EXTENSION_ABILITIES_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("32") - .addErrCode("008") - .addDescription("hspHasExtensionAbilities invalid.") - .addCause("%s") - .build(); - - /** - * HAS_HOME_ABILITY_INVALID - */ - public static final ErrorMsg HAS_HOME_ABILITY_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("32") - .addErrCode("009") - .addDescription("hasHomeAbility invalid.") - .addCause("%s") - .build(); - - /** - * HAS_HOME_EXTENSION_ABILITY_INVALID - */ - public static final ErrorMsg HAS_HOME_EXTENSION_ABILITY_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("32") - .addErrCode("010") - .addDescription("hasHomeExtensionAbility invalid.") - .addCause("%s") - .build(); - /** * CHECK_JSON_INVALID */ @@ -365,36 +584,6 @@ public class PackingToolErrMsg { .addCause("%s") .build(); - /** - * HAP_MODE_ARGS_INVALID - */ - public static final ErrorMsg HAP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("32") - .addErrCode("014") - .addDescription("isArgsValidInHapMode invalid.") - .addCause("%s") - .build(); - - /** - * PACKINFO_PATH_FAILED - */ - public static final ErrorMsg PACKINFO_PATH_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("32") - .addErrCode("016") - .addDescription("isArgsValidInHapMode failed.") - .addCause("%s") - .build(); - - /** - * RPCID_PATH_INVALID - */ - public static final ErrorMsg RPCID_PATH_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("32") - .addErrCode("017") - .addDescription("isArgsValidInHapMode failed.") - .addCause("%s") - .build(); - /** * MERGE_TWO_PACKINFO_FAILED */ @@ -525,34 +714,6 @@ public class PackingToolErrMsg { .addCause("%s") .build(); - // packing tool error - /** - * EXECUTE_PACKING_TOOL_FAILED - */ - public static final ErrorMsg EXECUTE_PACKING_TOOL_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("10") - .addErrCode("001") - .addDescription("Execute packing tool failed.") - .addCause("%s") - .addSolution("Please check the related log or error message and modify.") - .build(); - - /** - * EXECUTE_PACKING_TOOL_FAILED - */ - public static final ErrorMsg COMMAND_PARSER_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("10") - .addErrCode("002") - .addDescription("Command parser failed.") - .addCause("%s") - .build(); - - public static final ErrorMsg COMMAND_VERIFY_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("10") - .addErrCode("003") - .addDescription("Command verify failed.") - .addCause("%s") - .build(); // io excepetion @@ -640,16 +801,6 @@ public class PackingToolErrMsg { .build(); // compress process error - /** - * COMPRESS_PROCESS_EXCEPTION - */ - public static final ErrorMsg COMPRESS_PROCESS_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("99") - .addErrCode("002") - .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 /** @@ -683,25 +834,7 @@ public class PackingToolErrMsg { .addCause("%s") .build(); - /** - * PARSE_JSON_FAILED - */ - public static final ErrorMsg PARSE_JSON_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("13") - .addErrCode("001") - .addDescription("Parse json profile failed.") - .addCause("%s") - .build(); - /** - * PARSE_JSON_OBJECT_EXCEPTION - */ - public static final ErrorMsg PARSE_JSON_OBJECT_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("13") - .addErrCode("002") - .addDescription("Failed to parse json Object.") - .addCause("%s") - .build(); //compress.error /** @@ -714,26 +847,6 @@ public class PackingToolErrMsg { .addCause("%s") .build(); - /** - * PARSE_STAGE_MODULE_FAILED - */ - public static final ErrorMsg PARSE_STAGE_MODULE_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("13") - .addErrCode("004") - .addDescription("Failed to parse json file for stage module.") - .addCause("%s") - .build(); - - /** - * PARSE_STAGE_BUNDLE_TYPE_FAILED - */ - public static final ErrorMsg PARSE_STAGE_BUNDLE_TYPE_FAILED = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("13") - .addErrCode("005") - .addDescription("Failed to parse module.json and bundleType.") - .addCause("%s") - .addSolution("%s") - .build(); /** * PARSE_PROXY_DATA_URI_FAILED @@ -797,16 +910,6 @@ public class PackingToolErrMsg { .addCause("%s") .build(); - //compress verify error - /** - * APP_MODE_ARGS_INVALID - */ - public static final ErrorMsg APP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("11") - .addErrCode("003") - .addDescription("Parse and check args invalid in app mode.") - .addCause("%s") - .build(); /** * OUT_PATH_INVALID @@ -818,17 +921,6 @@ public class PackingToolErrMsg { .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 @@ -861,16 +953,6 @@ public class PackingToolErrMsg { .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("99") - .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(); /** * PARSE_FA_HAP_VERIFY_INFO_FAILED diff --git a/adapter/ohos/Utility.java b/adapter/ohos/Utility.java index 1987c3d2..b9df26ed 100644 --- a/adapter/ohos/Utility.java +++ b/adapter/ohos/Utility.java @@ -706,7 +706,7 @@ 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("getFormattedPath exception: " + exception.getMessage())); } return canonicalPath; } @@ -721,7 +721,7 @@ public class Utility { try { stream.close(); } catch (IOException exception) { - LOG.error("Utility::closeStream io close exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.CLOSE_STREAM_EXPECTION.toString(exception.getMessage())); } } } -- Gitee From bd090e9dd98f7221356e51de9a9ed1d33586048a Mon Sep 17 00:00:00 2001 From: nj1868 Date: Tue, 18 Feb 2025 15:49:29 +0800 Subject: [PATCH 5/5] update Signed-off-by: nj1868 Change-Id: I4f85b33c20bab401281e3ceb0f70caa3ae8d9cbb --- adapter/ohos/PackingToolErrMsg.java | 64 +++++++++++------------------ 1 file changed, 23 insertions(+), 41 deletions(-) diff --git a/adapter/ohos/PackingToolErrMsg.java b/adapter/ohos/PackingToolErrMsg.java index fb61cf31..97046988 100644 --- a/adapter/ohos/PackingToolErrMsg.java +++ b/adapter/ohos/PackingToolErrMsg.java @@ -72,15 +72,6 @@ public class PackingToolErrMsg { .addDescription("Parse and check args invalid in hsp mode.") .addCause("%s") .build(); - /** - * COMMAND_MODE_INVALID - */ - public static final ErrorMsg COMMAND_MODE_INVALID = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("11") - .addErrCode("011") - .addDescription("command verify mode is invalid.") - .addCause("Input mode is invalid.") - .build(); /** * APP_MODE_ARGS_INVALID @@ -153,25 +144,16 @@ public class PackingToolErrMsg { .addDescription("check hsp has entry ExtensionAbility failed.") .addCause("%s") .build(); - /** - * RPCID_PATH_INVALID - */ - // public static final ErrorMsg RPCID_PATH_INVALID = ErrorMsg.getPackingToolErrBuilder() - // .addTypeCode("11") - // .addErrCode("030") - // .addDescription("isArgsValidInHapMode failed.") - // .addCause("%s") - // .build(); - -// /** -// * PACKINFO_PATH_FAILED -// */ -// public static final ErrorMsg PACKINFO_PATH_FAILED = ErrorMsg.getPackingToolErrBuilder() -// .addTypeCode("11") -// .addErrCode("031") -// .addDescription("isArgsValidInHapMode failed.") -// .addCause("%s") -// .build(); + + /** + * COMMAND_MODE_INVALID + */ + public static final ErrorMsg COMMAND_MODE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .addTypeCode("11") + .addErrCode("011") + .addDescription("command verify mode is invalid.") + .addCause("Input mode is invalid.") + .build(); //packing process error(compress.java) /** @@ -233,7 +215,7 @@ public class PackingToolErrMsg { */ public static final ErrorMsg CHECK_HWASAN_ENABLED_INVALID = ErrorMsg.getPackingToolErrBuilder() .addTypeCode("12") - .addErrCode("005") + .addErrCode("006") .addDescription("Check hwasanEnabled and asanEnabled failed") .addCause("%s") .addSolution("Please set the correct values for the parameters.") @@ -244,7 +226,7 @@ public class PackingToolErrMsg { */ public static final ErrorMsg CHECK_ATOMIC_SERVICE_FAILED = ErrorMsg.getPackingToolErrBuilder() .addTypeCode("12") - .addErrCode("006") + .addErrCode("007") .addDescription("check atomicService failed.") .addCause("%s") .build(); @@ -254,7 +236,7 @@ public class PackingToolErrMsg { */ public static final ErrorMsg CHECK_CONTINUE_BUNDLENAME_INVALID = ErrorMsg.getPackingToolErrBuilder() .addTypeCode("12") - .addErrCode("007") + .addErrCode("008") .addDescription("continueBundleName and BundleName cannot be the same.") .addCause("%s") .addSolution("Ensure continueBundleName not inclue self.") @@ -265,7 +247,7 @@ public class PackingToolErrMsg { */ public static final ErrorMsg COMPRESS_PROCESS_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() .addTypeCode("12") - .addErrCode("008") + .addErrCode("009") .addDescription("Process compress exception.") .addCause("%s") .addSolution("Please check the related error message and modify. If the issue persists, review the logs for more details.") @@ -276,7 +258,7 @@ public class PackingToolErrMsg { */ public static final ErrorMsg HAS_GENERATE_BUILD_HASH = ErrorMsg.getPackingToolErrBuilder() .addTypeCode("12") - .addErrCode("009") + .addErrCode("010") .addDescription("verify has generate build hash failed.") .addCause("%s") .build(); @@ -286,7 +268,7 @@ public class PackingToolErrMsg { */ public static final ErrorMsg SET_GENERATE_BUILD_HASH = ErrorMsg.getPackingToolErrBuilder() .addTypeCode("12") - .addErrCode("010") + .addErrCode("011") .addDescription("set generate build hash failed.") .addCause("%s") .build(); @@ -296,7 +278,7 @@ public class PackingToolErrMsg { */ public static final ErrorMsg CHECK_OVERLAY_CFG_FAILED = ErrorMsg.getPackingToolErrBuilder() .addTypeCode("12") - .addErrCode("011") + .addErrCode("012") .addDescription("check whether is an overlay hsp or not failed.") .addCause("%s") .build(); @@ -306,11 +288,11 @@ public class PackingToolErrMsg { * PARSE_JSON_OBJECT_EXCEPTION */ public static final ErrorMsg PARSE_JSON_OBJECT_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() - .addTypeCode("13") - .addErrCode("001") - .addDescription("Failed to parse json Object.") - .addCause("%s") - .build(); + .addTypeCode("13") + .addErrCode("001") + .addDescription("Failed to parse json Object.") + .addCause("%s") + .build(); /** * PARSE_JSON_FAILED @@ -453,7 +435,7 @@ public class PackingToolErrMsg { .addSolution("Please review the related error message for further insights.") .build(); -////////////////////////////////////////////////////---//////////////////////// +////////////////////////////////////////////////////---//////////////////////// 改行以下未二次分类 //module json check error (modulejsonutil.java) -- Gitee