From 894f7695bebea3913ed3a01f07493960942d457b Mon Sep 17 00:00:00 2001 From: nj1868 Date: Wed, 12 Mar 2025 17:51:13 +0800 Subject: [PATCH 1/3] fix codecheck Signed-off-by: nj1868 Change-Id: I5cebee46e1f1c3997474a6b0c004ff3fef1be31f --- adapter/ohos/CommandParser.java | 9 +- adapter/ohos/CompressVerify.java | 9 +- adapter/ohos/Compressor.java | 90 ++++--- adapter/ohos/ErrorMsg.java | 370 +++++++++++++--------------- adapter/ohos/HapVerify.java | 119 +++++---- adapter/ohos/ModuleJsonUtil.java | 46 ++-- adapter/ohos/PackingToolErrMsg.java | 4 +- 7 files changed, 346 insertions(+), 301 deletions(-) diff --git a/adapter/ohos/CommandParser.java b/adapter/ohos/CommandParser.java index 0a957d8c..d7b5b0ad 100644 --- a/adapter/ohos/CommandParser.java +++ b/adapter/ohos/CommandParser.java @@ -362,14 +362,16 @@ public class CommandParser { try { int compressLevel = Integer.parseInt(level); if (compressLevel < 1 || compressLevel > 9) { - LOG.error(PackingToolErrMsg.COMMAND_PARSER_FAILED.toString("--compress-level value not number between 1-9.")); + LOG.error(PackingToolErrMsg.COMMAND_PARSER_FAILED.toString( + "--compress-level value not number between 1-9.")); return false; } else { entry.getKey().setCompressLevel(compressLevel); return true; } } catch (NumberFormatException ex) { - LOG.error(PackingToolErrMsg.COMMAND_PARSER_FAILED.toString("--compress-level value not number between 1-9.")); + LOG.error(PackingToolErrMsg.COMMAND_PARSER_FAILED.toString( + "--compress-level value not number between 1-9.")); return false; } }); @@ -405,7 +407,8 @@ public class CommandParser { ++i; } else if (CMD_PARSE_MODE.equals(key)) { if (i + PARSE_MODE_VALUE_LENGTH >= args.length) { - LOG.error(PackingToolErrMsg.COMMAND_PARSER_FAILED.toString("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/CompressVerify.java b/adapter/ohos/CompressVerify.java index 83256f75..058d4145 100644 --- a/adapter/ohos/CompressVerify.java +++ b/adapter/ohos/CompressVerify.java @@ -977,7 +977,8 @@ public class CompressVerify { return false; } if (hspHasExtensionAbilities) { - LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString("shared/appService hsp has extensionAbilities.")); + LOG.error(PackingToolErrMsg.HSP_MODE_ARGS_INVALID.toString( + "shared/appService hsp has extensionAbilities.")); return false; } } @@ -1260,7 +1261,8 @@ public class CompressVerify { LOG.error(PackingToolErrMsg.HSP_HAS_EXTENSION_ABILITIES_FAILED.toString(errMsg)); } } catch (BundleException e) { - LOG.error(PackingToolErrMsg.HSP_HAS_EXTENSION_ABILITIES_FAILED.toString("BundleException: " + e.getMessage())); + LOG.error(PackingToolErrMsg.HSP_HAS_EXTENSION_ABILITIES_FAILED.toString( + "BundleException: " + e.getMessage())); } return false; } @@ -1318,7 +1320,8 @@ public class CompressVerify { LOG.info("CompressVerify::hasHomeExtensionAbility result = " + result); return result; } catch (BundleException e) { - LOG.error(PackingToolErrMsg.HAS_HOME_EXTENSION_ABILITY_INVALID.toString("BundleException: " + e.getMessage())); + LOG.error(PackingToolErrMsg.HAS_HOME_EXTENSION_ABILITY_INVALID.toString( + "BundleException: " + e.getMessage())); return false; } } diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index e4a74a8f..7003a10b 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -365,10 +365,12 @@ public class Compressor { compressExcute(utility); } catch (FileNotFoundException exception) { compressResult = false; - LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("Compress exist FileNotFoundException: " + exception.getMessage())); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString( + "Compress exist FileNotFoundException: " + exception.getMessage())); } catch (BundleException ex) { compressResult = false; - LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_EXCEPTION.toString("Compress exist BundleException: " + ex.getMessage())); + LOG.error(PackingToolErrMsg.COMPRESS_PROCESS_EXCEPTION.toString( + "Compress exist BundleException: " + ex.getMessage())); } finally { closeZipOutputStream(); Utility.closeStream(zipOut); @@ -378,8 +380,8 @@ public class Compressor { if (compressResult && !checkAppAtomicServiceCompressedSizeValid(utility)) { compressResult = false; - String errMsg = - "The size of a single module, or the size of a module plus its dependencies, exceeds " + getEntryModuleSizeLimit() + "MB."; + String errMsg = "The size of a single module, or the size of a module plus its dependencies, exceeds " + + getEntryModuleSizeLimit() + "MB."; LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_SIZE_FAILED.toString(errMsg)); } @@ -434,29 +436,35 @@ public class Compressor { Optional optional = FileUtils.getFileContent(utility.getJsonPath()); String jsonString = optional.get(); if (!checkStageAsanTsanEnabledValid(jsonString)) { - LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Check the asanTsanEnabled parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString( + "Check the asanTsanEnabled parameter in the Stage module failed.")); throw new BundleException("Compress hsp failed."); } if (!checkStageHwasanEnabledValid(jsonString)) { - LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Check the hwasanEnabled parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString( + "Check the hwasanEnabled parameter in the Stage module failed.")); throw new BundleException("Compress hsp failed."); } if (!checkStageUbsanEnabledValid(jsonString)) { - LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Check the ubsanEnabled parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString( + "Check the ubsanEnabled parameter in the Stage module failed.")); throw new BundleException("Compress hsp failed."); } if (!checkStageAtomicService(jsonString)) { - LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Check the atomicService parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString( + "Check the atomicService parameter in the Stage module failed.")); throw new BundleException("Check stage AtomicService failed."); } // check continueBundleName in module.json if (!checkContinueBundleNameIsValid(jsonString)) { - LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Check the continueBundleName parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString( + "Check the continueBundleName parameter in the Stage module failed.")); throw new BundleException("Compress hsp failed."); } // check whether is an overlay hsp or not if (!checkStageOverlayCfg(jsonString)) { - LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString("Check the overlay config in the Stage module failed.")); + LOG.error(PackingToolErrMsg.COMPRESS_HSP_FAILED.toString( + "Check the overlay config in the Stage module failed.")); throw new BundleException("Compress hsp failed."); } String moduleType = ModuleJsonUtil.parseModuleType(jsonString); @@ -478,7 +486,8 @@ public class Compressor { setGenerateBuildHash(utility); if (isModuleJSON(utility.getJsonPath())) { if (!checkStageHap(utility)) { - LOG.error(PackingToolErrMsg.COMPRESS_HAP_FAILED.toString("Verify the module.json file of the Stage HAP package failed.")); + LOG.error(PackingToolErrMsg.COMPRESS_HAP_FAILED.toString( + "Verify the module.json file of the Stage HAP package failed.")); throw new BundleException("Verify the module.json file of the Stage HAP package failed."); } Optional optional = FileUtils.getFileContent(utility.getJsonPath()); @@ -521,7 +530,8 @@ public class Compressor { res = true; } } catch (BundleException exception) { - LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString("Verify has generate build hash exist BundleException: " + exception.getMessage())); + LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString( + "Verify has generate build hash exist BundleException: " + exception.getMessage())); throw new BundleException("Verify has generate build hash failed."); } catch (JSONException | IOException e) { LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString( @@ -572,11 +582,13 @@ public class Compressor { new FileOutputStream(utility.getJsonPath()), StandardCharsets.UTF_8)); bw.write(pretty); } catch (BundleException exception) { - LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString("Set generate build hash exist BundleException: " + exception.getMessage())); + LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString( + "Set generate build hash exist BundleException: " + exception.getMessage())); throw new BundleException("Compressor::setGenerateBuildHash failed."); } catch (NullPointerException | IOException | JSONException e) { LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString( - "json data err, exist Exception(NullPointerException | IOException | JSONException): " + e.getMessage())); + "json data err, exist Exception(NullPointerException | IOException | JSONException): " + + e.getMessage())); throw new BundleException("Set generate build hash failed, json data err."); } finally { FileUtils.closeStream(json); @@ -707,7 +719,8 @@ public class Compressor { LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Put build hash exist IOException: " + e.getMessage())); throw new BundleException("Put build hash failed."); } catch (NullPointerException e) { - LOG.error(PackingToolErrMsg.NULL_POINTER_EXCEPTION.toString("The json data err, exist NullPointerException: " + e.getMessage())); + LOG.error(PackingToolErrMsg.NULL_POINTER_EXCEPTION.toString( + "The json data err, exist NullPointerException: " + e.getMessage())); throw new BundleException("Put build hash failed, json data err."); } finally { FileUtils.closeStream(json); @@ -753,10 +766,12 @@ public class Compressor { return HapVerify.checkFileSizeIsValid(hapVerifyInfos); } catch (IOException exception) { - LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString("IOException: " + exception.getMessage())); + LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString( + "IOException: " + exception.getMessage())); return false; } catch (BundleException ignored) { - LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString("BundleException: " + ignored.getMessage())); + LOG.error(PackingToolErrMsg.APP_ATOMICSERVICE_COMPRESSED_SIZE_INVALID.toString( + "BundleException: " + ignored.getMessage())); return false; } } @@ -765,25 +780,30 @@ public class Compressor { Optional optional = FileUtils.getFileContent(utility.getJsonPath()); String jsonString = optional.get(); if (!checkStageAsanTsanEnabledValid(jsonString)) { - LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("Check the asanTsanEnabled parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString( + "Check the asanTsanEnabled parameter in the Stage module failed.")); return false; } if (!checkStageHwasanEnabledValid(jsonString)) { - LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("Check the hwasanEnabled parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString( + "Check the hwasanEnabled parameter in the Stage module failed.")); return false; } if (!checkStageUbsanEnabledValid(jsonString)) { - LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("Check the ubsanEnabled parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString( + "Check the ubsanEnabled parameter in the Stage module failed.")); return false; } // check atomicService in module.json if (!checkStageAtomicService(jsonString)) { - LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("Check the atomicService parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString( + "Check the atomicService parameter in the Stage module failed.")); return false; } // check continueBundleName in module.json if (!checkContinueBundleNameIsValid(jsonString)) { - LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString("Check the continueBundleName parameter in the Stage module failed.")); + LOG.error(PackingToolErrMsg.CHECK_STAGE_HAP_FAILED.toString( + "Check the continueBundleName parameter in the Stage module failed.")); return false; } return true; @@ -875,7 +895,8 @@ public class Compressor { } // check entry module must have ability if (!ModuleJsonUtil.checkEntryInAtomicService(jsonString)) { - LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_FAILED.toString("Check the atomicService entry module failed.")); + LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_FAILED.toString( + "Check the atomicService entry module failed.")); return false; } // check installationFree @@ -896,7 +917,8 @@ public class Compressor { // check targetModuleName and requestPermission if (ModuleJsonUtil.isExistedStageRequestPermissions(jsonString)) { LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString( - "The module(" + moduleName + ") targetModuleName and requestPermissions cannot be configured at the same time.")); + "The module(" + moduleName + ") targetModuleName and requestPermissions " + + "cannot be configured at the same time.")); return false; } // check targetModuleName and name @@ -908,7 +930,8 @@ public class Compressor { } else { if (ModuleJsonUtil.isExistedStageModuleTargetPriority(jsonString)) { LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString( - "The targetPriority cannot be existed without the targetModuleName in module.json. The moduleName is " + moduleName + ".")); + "The targetPriority cannot be existed without the targetModuleName in module.json. " + + "The moduleName is " + moduleName + ".")); return false; } } @@ -916,8 +939,8 @@ public class Compressor { String targetBundleName = ModuleJsonUtil.getStageTargetBundleName(jsonString); if (!targetBundleName.isEmpty()) { if (targetModuleName.isEmpty()) { - LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString( - "The module(" + moduleName + ") targetModuleName settings is necessary in the overlay bundle.")); + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString("The module(" + moduleName + + ") targetModuleName settings is necessary in the overlay bundle.")); return false; } if (targetBundleName.equals(ModuleJsonUtil.parseBundleName(jsonString))) { @@ -927,8 +950,8 @@ public class Compressor { } } else { if (ModuleJsonUtil.isExistedStageAppTargetPriority(jsonString)) { - LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString( - "The targetPriority cannot be existed without the targetBundleName in app.json. The moduleName is " + moduleName + ".")); + LOG.error(PackingToolErrMsg.CHECK_OVERLAY_CFG_FAILED.toString("The targetPriority cannot be existed " + + "without the targetBundleName in app.json. The moduleName is " + moduleName + ".")); return false; } } @@ -2249,7 +2272,8 @@ public class Compressor { zipCreator.writeTo(zipOut); } catch (IOException | InterruptedException | ExecutionException e) { LOG.error(PackingToolErrMsg.COMPRESS_PARALLEL_EXCEPTION.toString( - "Parallel compress exist Exception(IOException | InterruptedException | ExecutionException): " + e.getMessage())); + "Parallel compress exist Exception(IOException | InterruptedException | ExecutionException): " + + e.getMessage())); throw new BundleException("Parallel compress exception. " + e.getMessage()); } } @@ -2421,8 +2445,7 @@ public class Compressor { count = fileInputStream.read(buffer); } } catch (FileNotFoundException ignored) { - LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString( - "Get Crc from file exist FileNotFoundException: " + ignored.getMessage())); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("File not found when getting Crc.")); throw new BundleException("Get Crc from file failed."); } catch (IOException exception) { LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( @@ -2568,8 +2591,7 @@ public class Compressor { count = fileInputStream.read(buffer); } } catch (FileNotFoundException ignored) { - LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString( - "Get Crc32 from file exist FileNotFoundException: " + ignored.getMessage())); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString("File not found when getting Crc.")); throw new BundleException("Get Crc from file failed: " + file.getName()); } catch (IOException exception) { LOG.error(PackingToolErrMsg.FILE_IO_EXCEPTION.toString( diff --git a/adapter/ohos/ErrorMsg.java b/adapter/ohos/ErrorMsg.java index cb93d8bf..040e7cab 100644 --- a/adapter/ohos/ErrorMsg.java +++ b/adapter/ohos/ErrorMsg.java @@ -1,193 +1,177 @@ -/* - * Copyright (c) 2025-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - package ohos; - import java.util.ArrayList; - import java.util.List; - import java.util.Locale; - import java.util.MissingFormatArgumentException; - - /** - * ErrorMsg - * - * @since 2025/01/21 - */ - public class ErrorMsg { - private static final Log LOG = new Log(ErrorMsg.class.toString()); - - private static final String PACKING_TOOL_SUB_SYSTEM_CODE = "100"; - - private final String code; - - private final String description; - - private final String cause; - - private final List solutions; - - /** - * ErrorMsg constructor - * - * @param code code - * @param description description - * @param cause cause - * @param solutions solutions - */ - public ErrorMsg(String code, String description, String cause, - List solutions) { - this.code = code; - this.description = description; - this.cause = cause; - this.solutions = solutions; - } - - /** - * getPackingToolErrBuilder - * - * @return Builder - */ - public static Builder getPackingToolErrBuilder() { - return new Builder(PACKING_TOOL_SUB_SYSTEM_CODE); - } - - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append(code) - .append(" ") - .append(description) - .append(System.lineSeparator()) - .append("Error Message: ") - .append(cause) - .append(System.lineSeparator()); - - if (solutions != null && !solutions.isEmpty()) { - sb.append(System.lineSeparator()).append("* Try the following: ").append(System.lineSeparator()); - for (String s : solutions) { - sb.append(" > ").append(s).append(System.lineSeparator()); - } - } - return sb.toString(); - } - - /** - * to String - * - * @param args args - * @return String - */ - public String toString(Object... args) { - try { - return String.format(Locale.ROOT, this.toString(), args); - } catch (MissingFormatArgumentException e) { - LOG.error("args format failed: " + args); - return this.toString(); - } - } - - /** - * Builder - * - * @since 2025/01/21 - */ - public static class Builder { - private String sysCode; - - private String errCode; - - private String typeCode; - - private String description; - - private String cause; - - private List solutions = new ArrayList<>(); - - /** - * Builder Constructor - * - * @param sysCode sysCode - */ - public Builder(String sysCode) { - this.sysCode = sysCode; - } - - /** - * setErrCode - * - * @param errCode errCode - * @return Builder - */ - public Builder setErrCode(String errCode) { - this.errCode = errCode; - return this; - } - - /** - * setTypeCode - * - * @param typeCode typeCode - * @return Builder - */ - public Builder setTypeCode(String typeCode) { - this.typeCode = typeCode; - return this; - } - - /** - * setDescription - * - * @param description description - * @return Builder - */ - public Builder setDescription(String description) { - this.description = description; - return this; - } - - /** - * setCause - * - * @param cause cause - * @return Builder - */ - public Builder setCause(String cause) { - this.cause = cause; - return this; - } - - /** - * addSolution - * - * @param solution solution - * @return Builder - */ - public Builder addSolution(String solution) { - this.solutions.add(solution); - return this; - } - - /** - * build - * - * @return ErrorMsg - */ - public ErrorMsg build() { - return new ErrorMsg(sysCode + typeCode + errCode, description, cause, solutions); - } - } - } - \ No newline at end of file +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.MissingFormatArgumentException; + +/** + * ErrorMsg + * + * @since 2025/01/21 + */ +public class ErrorMsg { + private static final Log LOG = new Log(ErrorMsg.class.toString()); + private static final String PACKING_TOOL_SUB_SYSTEM_CODE = "100"; + + private final String code; + private final String description; + private final String cause; + private final List solutions; + + /** + * ErrorMsg constructor + * + * @param code code + * @param description description + * @param cause cause + * @param solutions solutions + */ + public ErrorMsg(String code, String description, String cause, List solutions) { + this.code = code; + this.description = description; + this.cause = cause; + this.solutions = solutions; + } + + /** + * getPackingToolErrBuilder + * + * @return Builder + */ + public static Builder getPackingToolErrBuilder() { + return new Builder(PACKING_TOOL_SUB_SYSTEM_CODE); + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append(code).append(" ").append(description).append(System.lineSeparator()).append("Error Message: ") + .append(cause).append(System.lineSeparator()); + + if (solutions != null && !solutions.isEmpty()) { + sb.append(System.lineSeparator()).append("* Try the following: ").append(System.lineSeparator()); + for (String s : solutions) { + sb.append(" > ").append(s).append(System.lineSeparator()); + } + } + return sb.toString(); + } + + /** + * to String + * + * @param args args + * @return String + */ + public String toString(Object... args) { + try { + return String.format(Locale.ROOT, this.toString(), args); + } catch (MissingFormatArgumentException e) { + LOG.error("args format failed: " + args); + return this.toString(); + } + } + + /** + * Builder + * + * @since 2025/01/21 + */ + public static class Builder { + private String sysCode; + private String errCode; + private String typeCode; + private String description; + private String cause; + private List solutions = new ArrayList<>(); + + /** + * Builder Constructor + * + * @param sysCode sysCode + */ + public Builder(String sysCode) { + this.sysCode = sysCode; + } + + /** + * setErrCode + * + * @param errCode errCode + * @return Builder + */ + public Builder setErrCode(String errCode) { + this.errCode = errCode; + return this; + } + + /** + * setTypeCode + * + * @param typeCode typeCode + * @return Builder + */ + public Builder setTypeCode(String typeCode) { + this.typeCode = typeCode; + return this; + } + + /** + * setDescription + * + * @param description description + * @return Builder + */ + public Builder setDescription(String description) { + this.description = description; + return this; + } + + /** + * setCause + * + * @param cause cause + * @return Builder + */ + public Builder setCause(String cause) { + this.cause = cause; + return this; + } + + /** + * addSolution + * + * @param solution solution + * @return Builder + */ + public Builder addSolution(String solution) { + this.solutions.add(solution); + return this; + } + + /** + * build + * + * @return ErrorMsg + */ + public ErrorMsg build() { + return new ErrorMsg(sysCode + typeCode + errCode, description, cause, solutions); + } + } +} \ No newline at end of file diff --git a/adapter/ohos/HapVerify.java b/adapter/ohos/HapVerify.java index b94e41ea..aa19f93e 100644 --- a/adapter/ohos/HapVerify.java +++ b/adapter/ohos/HapVerify.java @@ -214,8 +214,8 @@ class HapVerify { } if (!hapVerifyInfo.getDependencyItemList().isEmpty()) { String cause = "The shared App cannot depend on other modules."; - String solution = - "Remove dependencies settings in 'module.json5' and ensure module does not contain dependencies."; + String solution = "Remove dependencies settings in 'module.json5' and ensure module does " + + "not contain dependencies."; LOG.error(PackingToolErrMsg.CHECK_SHARED_APP_INVALID.toString(cause, solution)); return false; } @@ -324,18 +324,18 @@ class HapVerify { if (hap.getVersion().minCompatibleVersionCode != hapInfo.getVersion().minCompatibleVersionCode || hap.getApiVersion().getTargetApiVersion() != hapInfo.getApiVersion().getTargetApiVersion()) { String errMsg = "Hap minCompatibleVersionCode or targetApiVersion different."; - String solution = - "Ensure that the values of 'minCompatibleVersionCode' and 'targetApiVersion' in the module.json file of each HAP module are the same."; + String solution = "Ensure that the values of 'minCompatibleVersionCode' and 'targetApiVersion' " + + "in the module.json file of each HAP module are the same."; LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(errMsg, solution)); return false; } } if (hap.getVersion().minCompatibleVersionCode < minCompatibleVersionCode || hap.getApiVersion().getTargetApiVersion() < targetApiVersion) { - String cause = "The values of minCompatibleVersionCode or targetApiVersion in the module.json file of the HAP " + - "module are smaller than those of the HSP module."; - String solution = "Ensure that the values of aminCompatibleVersionCode and targetApiVersion in the module.json file " + - "of the HAP module are greater than or equal to those of the HSP module."; + String cause = "The values of minCompatibleVersionCode or targetApiVersion in the module.json file " + + "of the HAP module are smaller than those of the HSP module."; + String solution = "Ensure that the values of aminCompatibleVersionCode and targetApiVersion in the " + + "module.json file of the HAP module are greater than or equal to those of the HSP module."; LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(cause, solution)); return false; } @@ -442,16 +442,17 @@ class HapVerify { String cause = "Module: (" + hapVerifyInfos.get(i).getModuleName() + ") and Module: (" + hapVerifyInfos.get(j).getModuleName() + ") have the same moduleName, " + "please check deviceType or distroFilter of the module.\n" + "Module: " + - hapVerifyInfos.get(i).getModuleName() + " has deviceType " + hapVerifyInfos.get(i).getDeviceType() + - ".\n" + "Another Module: " + hapVerifyInfos.get(j).getModuleName() + " has deviceType " + + hapVerifyInfos.get(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())) { cause += "\n" + "Module: " + hapVerifyInfos.get(i).getModuleName() + " DistroFilter is " + hapVerifyInfos.get(i).getDistroFilter().dump() + "."; } if (!EMPTY_STRING.equals(hapVerifyInfos.get(j).getDistroFilter().dump())) { - cause += "\n" +"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() + "."; } String solution = "Make sure the module name is valid and unique.\n" + "Reference: " + REFERENCE_LINK + "."; @@ -481,16 +482,17 @@ class HapVerify { 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(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())) { cause += "\n" + "Module: " + hapVerifyInfos.get(i).getModuleName() + " DistroFilter is " + hapVerifyInfos.get(i).getDistroFilter().dump() + "."; } if (!EMPTY_STRING.equals(hapVerifyInfos.get(j).getDistroFilter().dump())) { - cause += "\n" + "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() + "."; } String solution = "Make sure package name is valid and unique.\n" + "Reference: " + REFERENCE_LINK + "."; @@ -616,7 +618,8 @@ class HapVerify { for (String uri : info.getProxyDataUris()) { if (uriSet.contains(uri)) { String moduleName = info.getModuleName(); - String cause = "The uri(" + uri + ") in proxyData settings of Module(" + moduleName + ") is duplicated."; + String cause = "The uri(" + uri + ") in proxyData settings of Module(" + moduleName + + ") 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; @@ -672,9 +675,8 @@ class HapVerify { " DistroFilter is " + entryHapVerifyInfos.get(j).getDistroFilter().dump() + "."; } - String solution = - "Make sure the entry module is valid and unique, and the HAP uniqueness check logic passes.\n" + - "Reference: " + REFERENCE_LINK + "."; + String solution = "Make sure the entry module is valid and unique, and the HAP uniqueness " + + "check logic passes.\nReference: " + REFERENCE_LINK + "."; LOG.error(PackingToolErrMsg.CHECK_ENTRY_INVALID.toString(cause, solution)); return false; } @@ -707,7 +709,7 @@ class HapVerify { } // check distroFilter if (checkDistroFilterDisjoint(hapVerifyInfoLeft.getDistroFilter(), hapVerifyInfoRight.getDistroFilter(), - hapVerifyInfoLeft.getModuleName(), hapVerifyInfoRight.getModuleName())) { + hapVerifyInfoLeft.getModuleName(), hapVerifyInfoRight.getModuleName())) { return true; } @@ -719,42 +721,48 @@ class HapVerify { * * @param distroFilterLeft is one distroFilter * @param distroFilterRight is another distroFilter will be checked - * @throws BundleException Throws this exception if the json is not standard. + * @param moduleNameLeft is the moduleName associated with distroFilterLeft + * @param moduleNameRight is the moduleName associated with distroFilterRight * @return true if two distroFilter is disjoint + * @throws BundleException Throws this exception if the json is not standard. */ private static boolean checkDistroFilterDisjoint(DistroFilter distroFilterLeft, DistroFilter distroFilterRight, - String moduleNameLeft, String moduleNameRight) - throws BundleException { + String moduleNameLeft, String moduleNameRight) throws BundleException { if (distroFilterLeft == null || distroFilterRight == null) { return false; } if (distroFilterLeft.apiVersion != null && distroFilterRight.apiVersion != null) { if (checkPolicyValueDisjoint(distroFilterLeft.apiVersion.policy, distroFilterLeft.apiVersion.value, - distroFilterRight.apiVersion.policy, distroFilterRight.apiVersion.value, moduleNameLeft, moduleNameRight)) { + distroFilterRight.apiVersion.policy, distroFilterRight.apiVersion.value, + moduleNameLeft, moduleNameRight)) { return true; } } if (distroFilterLeft.screenShape != null && distroFilterRight.screenShape != null) { if (checkPolicyValueDisjoint(distroFilterLeft.screenShape.policy, distroFilterLeft.screenShape.value, - distroFilterRight.screenShape.policy, distroFilterRight.screenShape.value, moduleNameLeft, moduleNameRight)) { + distroFilterRight.screenShape.policy, distroFilterRight.screenShape.value, + moduleNameLeft, moduleNameRight)) { return true; } } if (distroFilterLeft.screenDensity != null && distroFilterRight.screenDensity != null) { if (checkPolicyValueDisjoint(distroFilterLeft.screenDensity.policy, distroFilterLeft.screenDensity.value, - distroFilterRight.screenDensity.policy, distroFilterRight.screenDensity.value, moduleNameLeft, moduleNameRight)) { + distroFilterRight.screenDensity.policy, distroFilterRight.screenDensity.value, + moduleNameLeft, moduleNameRight)) { return true; } } if (distroFilterLeft.screenWindow != null && distroFilterRight.screenWindow != null) { if (checkPolicyValueDisjoint(distroFilterLeft.screenWindow.policy, distroFilterLeft.screenWindow.value, - distroFilterRight.screenWindow.policy, distroFilterRight.screenWindow.value, moduleNameLeft, moduleNameRight)) { + distroFilterRight.screenWindow.policy, distroFilterRight.screenWindow.value, + moduleNameLeft, moduleNameRight)) { return true; } } if (distroFilterLeft.countryCode != null && distroFilterRight.countryCode != null) { if (checkPolicyValueDisjoint(distroFilterLeft.countryCode.policy, distroFilterLeft.countryCode.value, - distroFilterRight.countryCode.policy, distroFilterRight.countryCode.value, moduleNameLeft, moduleNameRight)) { + distroFilterRight.countryCode.policy, distroFilterRight.countryCode.value, + moduleNameLeft, moduleNameRight)) { return true; } } @@ -772,12 +780,11 @@ class HapVerify { * @throws BundleException Throws this exception if the json is not standard. */ private static boolean checkPolicyValueDisjoint(String policyLeft, List valueLeft, String policyRight, - List valueRight, String moduleNameLeft, String ModuleNameRight) - throws BundleException { + List valueRight, String moduleNameLeft, String moduleNameRight) throws BundleException { if (valueLeft == null || valueRight == null) { String errMsg = "The variable 'value' in the distributionFilter setting is empty."; String solution = "Ensure that all distributionFilter file and filter settings has 'value' setting."; - solution += "Module " + moduleNameLeft + " and " + ModuleNameRight + " can be checked in priority."; + solution += "Module " + moduleNameLeft + " and " + moduleNameRight + " can be checked in priority."; LOG.error(PackingToolErrMsg.CHECK_POLICY_DISJOINT_ERROR.toString(errMsg, solution)); throw new BundleException("Check policy value disjoint value should not empty."); } @@ -797,8 +804,9 @@ class HapVerify { return false; } else { String errMsg = "Check distributionFilter 'policy' setting is invalid."; - String solution = "Ensure all distributionFilter file and filter settings 'policy' value must 'include' or 'exclude'.\n"; - solution += "Module " + moduleNameLeft + " and " + ModuleNameRight + " can be checked in priority."; + String solution = "Ensure all distributionFilter file and filter settings 'policy' value must " + + "'include' or 'exclude'.\n"; + solution += "Module " + moduleNameLeft + " and " + moduleNameRight + " can be checked in priority."; LOG.error(PackingToolErrMsg.CHECK_POLICY_DISJOINT_ERROR.toString(errMsg, solution)); throw new BundleException("Check policy value disjoint input policy is invalid."); } @@ -936,8 +944,8 @@ class HapVerify { flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Entry module(" + hapVerifyInfo.getModuleName() + ") apiVersion policy '" + hapVerifyInfo.getDistroFilter().apiVersion.policy + - "' is invalid.")); + "Entry module(" + hapVerifyInfo.getModuleName() + ") apiVersion policy '" + + hapVerifyInfo.getDistroFilter().apiVersion.policy + "' is invalid.")); throw new BundleException("Check apiVersion covered input policy is invalid."); } } @@ -987,7 +995,8 @@ class HapVerify { flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Entry module(" + hapVerifyInfo.getModuleName() + ") screenShape policy '" + hapVerifyInfo.getDistroFilter().screenShape.policy + "' is invalid.")); + "Entry module(" + hapVerifyInfo.getModuleName() + ") screenShape policy '" + + hapVerifyInfo.getDistroFilter().screenShape.policy + "' is invalid.")); throw new BundleException("Check screenShape covered input policy is invalid."); } } @@ -1009,6 +1018,7 @@ class HapVerify { * @param screenWindow is the screenWindow of feature hap * @param entryHaps is the haps that feature matched * @return screenWindow is valid + * @throws BundleException when input policy is invalid */ private static boolean checkScreenWindowCovered(ScreenWindow screenWindow, List entryHaps) throws BundleException { @@ -1036,7 +1046,8 @@ class HapVerify { flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Entry module(" + hapVerifyInfo.getModuleName() + ") screenWindow policy '" + hapVerifyInfo.getDistroFilter().screenWindow.policy + "' is invalid.")); + "Entry module(" + hapVerifyInfo.getModuleName() + ") screenWindow policy '" + + hapVerifyInfo.getDistroFilter().screenWindow.policy + "' is invalid.")); throw new BundleException("Check screenWindow covered input policy is invalid."); } } @@ -1058,6 +1069,7 @@ class HapVerify { * @param screenDensity is the screenDensity of feature hap * @param entryHaps is the haps that feature matched * @return screenDensity is valid + * @throws BundleException when input policy is invalid */ private static boolean checkScreenDensityCovered(ScreenDensity screenDensity, List entryHaps) throws BundleException { @@ -1085,7 +1097,8 @@ class HapVerify { flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Entry module(" + hapVerifyInfo.getModuleName() + ") screenDensity policy '" + hapVerifyInfo.getDistroFilter().screenDensity.policy + "' is invalid.")); + "Entry module(" + hapVerifyInfo.getModuleName() + ") screenDensity policy '" + + hapVerifyInfo.getDistroFilter().screenDensity.policy + "' is invalid.")); throw new BundleException("Check screenDensity covered input policy is invalid."); } } @@ -1107,6 +1120,7 @@ class HapVerify { * @param countryCode is the countryCode of feature hap * @param entryHaps is the haps that feature matched * @return countryCode is valid + * @throws BundleException when input policy is invalid */ private static boolean checkCountryCodeCovered(CountryCode countryCode, List entryHaps) throws BundleException { @@ -1134,7 +1148,8 @@ class HapVerify { flatMap(Collection::stream).distinct().collect(Collectors.toList()); } else { LOG.error(PackingToolErrMsg.CHECK_FEATURE_DISTRO_FILTER_INVALID.toString( - "Entry module(" + hapVerifyInfo.getModuleName() + ") countryCode policy '" + hapVerifyInfo.getDistroFilter().countryCode.policy + "' is invalid.")); + "Entry module(" + hapVerifyInfo.getModuleName() + ") countryCode policy '" + + hapVerifyInfo.getDistroFilter().countryCode.policy + "' is invalid.")); throw new BundleException("Check countryCode covered input policy is invalid."); } } @@ -1244,7 +1259,7 @@ class HapVerify { if (isInstallationFree != hapVerifyInfo.isInstallationFree()) { 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)); + LOG.error(PackingToolErrMsg.CHECK_DEPENDENCY_INVALID.toString(cause, solution)); return false; } } @@ -1288,7 +1303,8 @@ class HapVerify { for (HapVerifyInfo item : layerDependencyList) { if (FEATURE.equals(item.getModuleType()) || ENTRY.equals(item.getModuleType())) { String cause = - "HAP or HSP cannot depend on the feature or entry module. The dependeny module(" + item.getModuleName() + ") type is feature or entry."; + "HAP or HSP cannot depend on the feature or entry module. The dependeny module(" + + item.getModuleName() + ") type is feature or entry."; String solution = "Remove module dependencies on module (" + item.getModuleName() + ") to ensure the dependency list is valid."; LOG.error(PackingToolErrMsg.DEPENDENCY_LIST_INVALID.toString(cause, solution)); @@ -1426,7 +1442,8 @@ class HapVerify { } if (!hapVerifyInfo.getModuleType().equals(ENTRY) && (fileSize >= notEntryLimit * FILE_LENGTH_1M)) { String errMsg = "Module " + hapVerifyInfo.getModuleName() + " and it's dependencies size sum is " + - getCeilFileSize(fileSize, notEntryLimit) + "MB, which is overlarge than " + notEntryLimit + "MB."; + getCeilFileSize(fileSize, notEntryLimit) + "MB, which is overlarge than " + notEntryLimit + + "MB."; LOG.error(PackingToolErrMsg.CHECK_ATOMIC_SERVICE_MODULE_SIZE.toString(errMsg)); return false; } @@ -1487,7 +1504,7 @@ class HapVerify { List hapVerifyInfos = deviceInfoMap.get(device); if (!checkAtomicServicePreloadsIsValid(hapVerifyInfos)) { LOG.error(PackingToolErrMsg.CHECK_ATOMICSERVICE_INVALID.toString( - "Check whether atomicService preloads are valid failed on device "+ device + ".")); + "Check whether atomicService preloads are valid failed on device " + device + ".")); return false; } } @@ -1530,19 +1547,21 @@ class HapVerify { for (PreloadItem preloadItem : preloadItems) { String moduleName = preloadItem.getModuleName(); if (preloadModuleName.contains(moduleName)) { - LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("Preloads a duplicate module, module(" - + hapVerifyInfo.getModuleName() + ") cannot preloads module (" + moduleName + ").")); + LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString( + "Preloads a duplicate module, module(" + hapVerifyInfo.getModuleName() + + ") cannot preloads module (" + moduleName + ").")); return false; } preloadModuleName.add(moduleName); if (!moduleNames.contains(moduleName)) { - LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("Preloads a not exist module, module(" - + hapVerifyInfo.getModuleName() + ") cannot preloads module(" + moduleName + ").")); + LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString( + "Preloads a not exist module, module(" + hapVerifyInfo.getModuleName() + + ") cannot preloads module(" + moduleName + ").")); return false; } if (moduleName.equals(hapVerifyInfo.getModuleName())) { - LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("Cannot preload self, module " - + hapVerifyInfo.getModuleName() + " cannot preloads self.")); + LOG.error(PackingToolErrMsg.ATOMICSERVICE_PRELOADS_INVALID.toString("Cannot preload self, module " + + hapVerifyInfo.getModuleName() + " cannot preloads self.")); return false; } } diff --git a/adapter/ohos/ModuleJsonUtil.java b/adapter/ohos/ModuleJsonUtil.java index 569022e0..5e96c495 100644 --- a/adapter/ohos/ModuleJsonUtil.java +++ b/adapter/ohos/ModuleJsonUtil.java @@ -243,7 +243,8 @@ class ModuleJsonUtil { if (!appObj.containsKey(API_VERSION)) { String errMsg = "The config.json file does not contain 'apiVersion'."; LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString(errMsg)); - throw new BundleException("Parse FA module APIVersion failed: The config.json file does not contain 'apiVersion'."); + throw new BundleException( + "Parse FA module APIVersion failed: The config.json file does not contain 'apiVersion'."); } JSONObject apiVersionObj = appObj.getJSONObject(API_VERSION); ModuleApiVersion moduleApiVersion = new ModuleApiVersion(); @@ -336,7 +337,8 @@ class ModuleJsonUtil { if (moduleObj.containsKey(PACKAGE)) { packageStr = moduleObj.getString(PACKAGE); } else { - LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString("The config.json file does not contain 'package'.")); + LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString( + "The config.json file does not contain 'package'.")); throw new BundleException("The config.json file does not contain 'package'."); } return packageStr; @@ -355,7 +357,8 @@ class ModuleJsonUtil { if (appObject.containsKey(BUNDLE_NAME)) { bundleName = appObject.getString(BUNDLE_NAME); } else { - LOG.error(PackingToolErrMsg.PARSE_BUNDLE_NAME_FAILED.toString("The module.json or config.json file does not contain 'bundleName'.")); + LOG.error(PackingToolErrMsg.PARSE_BUNDLE_NAME_FAILED.toString( + "The module.json or config.json file does not contain 'bundleName'.")); throw new BundleException("Parse module.json or config.json file does not contain 'bundleName'."); } return bundleName; @@ -1317,7 +1320,8 @@ class ModuleJsonUtil { String moduleName = parseStageModuleName(jsonString); if (!moduleObj.containsKey(TYPE)) { String errMsg = "Module: '" + moduleName + "' does not contain 'type' in module.json."; - String solution = "Ensure the module.json file includes a valid 'type' field for module '" + moduleName + "'."; + 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); } @@ -1326,7 +1330,8 @@ class ModuleJsonUtil { JSONObject appObj = getAppObj(jsonString); if (!appObj.containsKey(BUNDLE_TYPE)) { if (installationFree) { - String errMsg = "The app.json5 file configuration does not match the 'installationFree' setting of true."; + String errMsg = + "The app.json5 file configuration does not match the 'installationFree' setting of true."; 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); @@ -1336,7 +1341,8 @@ class ModuleJsonUtil { 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."; + String errMsg = + "'installationFree' must be false in module '" + moduleName + "' when 'bundleType' is app."; String solution = "Set 'installationFree' to false in the module.json when 'bundleType' is app."; LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); throw new BundleException(errMsg); @@ -1344,7 +1350,8 @@ class ModuleJsonUtil { return APP; } else if (bundleType.equals(ATOMIC_SERVICE)) { if (!installationFree) { - String errMsg = "'installationFree' must be true in module '" + moduleName + "' when 'bundleType' is atomicService."; + String errMsg = "'installationFree' must be true in module '" + moduleName + + "' when 'bundleType' is atomicService."; String solution = "Set 'installationFree' to true in the module.json when 'bundleType'" + "is atomicService."; LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); @@ -1354,7 +1361,7 @@ class ModuleJsonUtil { } else if (SHARED.equals(bundleType)) { if (!SHARED.equals(type)) { String errMsg = "'type' must be shared in module '" + moduleName + "' when 'bundleType' is shared."; - String solution = "Set the 'type' to shared in the module.json when 'bundleType' is shared.";; + String solution = "Set the 'type' to shared in the module.json when 'bundleType' is shared."; LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); throw new BundleException(errMsg); } @@ -1405,7 +1412,8 @@ class ModuleJsonUtil { JSONObject itemObj = proxyData.getJSONObject(i); if (!itemObj.containsKey(PROXY_URI)) { String errMsg = "proxyData object does not contain " + PROXY_URI + "."; - String solution = "Ensure that each item in the " + PROXY_DATA + " array includes a valid " + PROXY_URI + " field."; + String solution = "Ensure that each item in the " + PROXY_DATA + " array includes a valid " + + PROXY_URI + " field."; LOG.error(PackingToolErrMsg.PARSE_PROXY_DATA_URI_FAILED.toString(errMsg, solution)); throw new BundleException("Parse json object failed in parse proxyData and uri."); } @@ -1418,7 +1426,8 @@ class ModuleJsonUtil { JSONObject itemObj = proxyDatas.getJSONObject(i); if (!itemObj.containsKey(PROXY_URI)) { String errMsg = "proxyDatas object does not contain " + PROXY_URI + "."; - String solution = "Ensure that each item in the " + PROXY_DATAS + " array includes a valid " + PROXY_URI + " field."; + String solution = "Ensure that each item in the " + PROXY_DATAS + " array includes a valid " + + PROXY_URI + " field."; LOG.error(PackingToolErrMsg.PARSE_PROXY_DATA_URI_FAILED.toString(errMsg, solution)); throw new BundleException("Parse json object failed in parse proxyDatas and uri."); } @@ -1440,7 +1449,8 @@ class ModuleJsonUtil { } JSONObject appObj = jsonObject.getJSONObject(APP); if (appObj == null) { - LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("The module.json or config.json does not contain 'app'.")); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString( + "The module.json or config.json does not contain 'app'.")); throw new BundleException("json do not contain app."); } return appObj; @@ -1461,7 +1471,8 @@ class ModuleJsonUtil { } JSONObject moduleObj = jsonObj.getJSONObject(MODULE); if (moduleObj == null) { - LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("The module.json or config.json file does not contain 'module'.")); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString( + "The module.json or config.json file does not contain 'module'.")); throw new BundleException("The module.json or config.json file does not contain 'module'."); } return moduleObj; @@ -1507,7 +1518,8 @@ class ModuleJsonUtil { JSONObject moduleObj = getModuleObj(jsonString); JSONObject distroObj = moduleObj.getJSONObject(DISTRO); if (distroObj == null) { - LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString("The config.json file does not contain 'distro'.")); + LOG.error(PackingToolErrMsg.PARSE_FA_JSON_FAILED.toString( + "The config.json file does not contain 'distro'.")); throw new BundleException("Parse FA installationFree failed: config.json file does not contain 'distro'."); } if (distroObj.containsKey(INSTALLATION_FREE)) { @@ -1715,7 +1727,9 @@ class ModuleJsonUtil { try { jsonObject = JSON.parseObject(jsonString); } catch (JSONException exception) { - PackingToolErrMsg.PARSE_JSON_FAILED.toString("Parse json object failed when get debug parameter in config.json, JSONException: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString( + "Parse json object failed when get debug parameter in config.json, JSONException: " + + exception.getMessage())); throw new BundleException("Parse JSONObject failed when get debug parameter in config.json."); } JSONObject deviceConfigObj = jsonObject.getJSONObject(DEVICE_CONFIG); @@ -1863,7 +1877,7 @@ class ModuleJsonUtil { } JSONObject appObj = jsonObject.getJSONObject(fatherProperty); if (appObj == null) { - String errMsg = "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 + "."); @@ -1935,7 +1949,7 @@ class ModuleJsonUtil { } if (parseModuleType(jsonString).equals(ENTRY) && parseAbilityNames(jsonString).isEmpty()) { String moduleName = parseStageModuleName(jsonString); - String errMsg = "Entry module(" + moduleName +") must contain at least one ability."; + String errMsg = "Entry module(" + moduleName + ") must contain at least one ability."; LOG.error(PackingToolErrMsg.CHECK_LEASTONE_ABILITY.toString(errMsg)); return false; } diff --git a/adapter/ohos/PackingToolErrMsg.java b/adapter/ohos/PackingToolErrMsg.java index e8d48fef..29fbbc76 100644 --- a/adapter/ohos/PackingToolErrMsg.java +++ b/adapter/ohos/PackingToolErrMsg.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025-2025 Huawei Device Co., Ltd. + * Copyright (c) 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 @@ -685,7 +685,7 @@ public class PackingToolErrMsg { .addSolution("4. Review the related error message for further insights.") .build(); - /* + /** * NULL_POINTER_EXCEPTION */ public static final ErrorMsg NULL_POINTER_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() -- Gitee From d2c0413ef211e3e2c86665608b2f48e80ff82715 Mon Sep 17 00:00:00 2001 From: nj1868 Date: Tue, 11 Mar 2025 10:16:54 +0800 Subject: [PATCH 2/3] add errcode v0 Signed-off-by: nj1868 Change-Id: Ic976212ea440021d1f141459cb4368946e731404 --- adapter/ohos/CompressVerify.java | 176 ++++++---- adapter/ohos/Compressor.java | 264 ++++++++------- adapter/ohos/FileUtils.java | 14 +- adapter/ohos/HQFVerify.java | 24 +- adapter/ohos/ModuleJsonUtil.java | 122 ++++--- adapter/ohos/PackageNormalize.java | 30 +- adapter/ohos/PackageUtil.java | 99 +++--- adapter/ohos/PackingToolErrMsg.java | 508 ++++++++++++++++++++++++++++ adapter/ohos/Utility.java | 3 +- 9 files changed, 943 insertions(+), 297 deletions(-) diff --git a/adapter/ohos/CompressVerify.java b/adapter/ohos/CompressVerify.java index 058d4145..20ec4c3f 100644 --- a/adapter/ohos/CompressVerify.java +++ b/adapter/ohos/CompressVerify.java @@ -158,29 +158,35 @@ public class CompressVerify { private static boolean validatePackageNormalizeMode(Utility utility) { if (utility.getHspList().isEmpty()) { - LOG.error("CompressVerify::validatePackageNormalizeMode hsp-list is empty."); + String errMsg = "--hsp-list is empty."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } else { if (!compatibleProcess(utility, utility.getHspList(), utility.getFormattedHspPathList(), HSP_SUFFIX)) { - LOG.error("CompressVerify::validatePackageNormalizeMode hsp-list is invalid."); + String errMsg = "--hsp-list is invalid."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!isBundleNameValid(utility.getBundleName())) { - LOG.error("CompressVerify::validatePackageNormalizeMode bundle-name is invalid."); + String errMsg = "--bundle-name is invalid."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getVersionCode() <= 0) { - LOG.error("CompressVerify::validatePackageNormalizeMode version-code is invalid."); + String errMsg = "--version-code is invalid."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getOutPath().isEmpty()) { - LOG.error("CompressVerify::validatePackageNormalizeMode out-path is empty."); + String errMsg = "--out-path is empty."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } File outDir = new File(utility.getOutPath()); if (!outDir.isDirectory()) { - LOG.error("CompressVerify::validatePackageNormalizeMode out-path is not a directory."); + String errMsg = "--out-path is not a directory."; + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -188,45 +194,53 @@ public class CompressVerify { private static boolean validateVersionNormalizeMode(Utility utility) { if (utility.getInputList().isEmpty()) { - LOG.error("CompressVerify::validateVersionNormalizeMode input-list is empty."); + String errMsg = "--input-list is empty."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!handleHapAndHspInput(utility, utility.getInputList(), utility.getFormattedHapList())) { - LOG.error("CompressVerify::validateVersionNormalizeMode input-list is invalid."); + String errMsg = "--input-list is invalid."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getFormattedHapList().isEmpty()) { - LOG.error("CompressVerify::validateVersionNormalizeMode input-list is empty."); + String errMsg = "--input-list is empty."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getVersionCode() <= 0) { - LOG.error("CompressVerify::validateVersionNormalizeMode version-code is invalid."); + String errMsg = "--version-code is invalid."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getVersionName().isEmpty()) { - LOG.error("CompressVerify::validateVersionNormalizeMode version-name is empty."); + String errMsg = "--version-name is empty."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } Pattern versionNamePattern = Pattern.compile(VERSION_NAME_PATTERN); Matcher versionNameMatcher = versionNamePattern.matcher(utility.getVersionName()); if (!versionNameMatcher.matches()) { - LOG.error("CompressVerify::validateVersionNormalizeMode version-name is not valid."); + String errMsg = "--version-name is not valid."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getOutPath().isEmpty()) { - LOG.error("CompressVerify::validateVersionNormalizeMode out-path is empty."); + String errMsg = "--out-path is empty."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } File outDir = new File(utility.getOutPath()); if (!outDir.isDirectory()) { - LOG.error("CompressVerify::validateVersionNormalizeMode out-path is not a directory."); + String errMsg = "--out-path is not a directory."; + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -447,45 +461,53 @@ public class CompressVerify { */ private static boolean isVerifyValidInHarMode(Utility utility) { if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::isArgsValidInHarMode json-path is empty."); + String errMsg = "--json-path is empty."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!isPathValid(utility.getJsonPath(), TYPE_FILE, JSON_PROFILE) && !isPathValid(utility.getJsonPath(), TYPE_FILE, MODULE_PROFILE)) { - LOG.error("CompressVerify::isArgsValidInHarMode json-path must be config.json file."); + String errMsg = "--json-path must be config.json file."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getJarPath().isEmpty() && !compatibleProcess(utility, utility.getJarPath(), utility.getFormattedJarPathList(), JAR_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHarMode jar-path is invalid."); + String errMsg = "--jar-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getTxtPath().isEmpty() && !compatibleProcess(utility, utility.getTxtPath(), utility.getFormattedTxtPathList(), TXT_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInHarMode txt-path is invalid."); + String errMsg = "--txt-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getLibPath().isEmpty() && !isPathValid(utility.getLibPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode lib-path is invalid."); + String errMsg = "--lib-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getResPath().isEmpty() && !isPathValid(utility.getResPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode res-path is invalid."); + String errMsg = "--res-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getResourcesPath().isEmpty() || !isPathValid(utility.getResourcesPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode resources-path is invalid."); + String errMsg = "--resources-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getAssetsPath().isEmpty() && !isPathValid(utility.getAssetsPath(), TYPE_DIR, null)) { - LOG.error("CompressVerify::isArgsValidInHarMode assets-path is invalid."); + String errMsg = "--assets-path is invalid."; + LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -629,41 +651,48 @@ public class CompressVerify { */ private static boolean isVerifyValidInMultiAppMode(Utility utility) { if (utility.getAppList().isEmpty() && utility.getHapList().isEmpty() && utility.getHspList().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode input app-list, hap-list and hsp-list are null."); + String errMsg = "Input --app-list, --hap-list and --hsp-list are empty."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getAppList().isEmpty()) { if (!compatibleProcess(utility, utility.getAppList(), utility.getFormattedAppList(), APP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode app-list is invalid."); + String errMsg = "--app-list is invalid."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!utility.getHapList().isEmpty()) { if (!compatibleProcess(utility, utility.getHapList(), utility.getFormattedHapList(), HAP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode hap-list is invalid."); + String errMsg = "--hap-list is invalid."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!utility.getHspList().isEmpty()) { if (!compatibleProcess(utility, utility.getHspList(), utility.getFormattedHapList(), HSP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode hsp-list is invalid."); + String errMsg = "--hsp-list is invalid."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!isValidEncryptJsonFile(utility)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode encrypt-path is invalid."); + String errMsg = "--encrypt-path is invalid."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } File outFile = new File(utility.getOutPath()); if (("false".equals(utility.getForceRewrite())) && outFile.exists()) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode out file already existed."); + String errMsg = "--out-path file already existed, but --force is 'false'."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(APP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInMultiAppMode out-path must end with .app."); + String errMsg = "--out-path must end with .app."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -678,18 +707,20 @@ public class CompressVerify { */ private static boolean isVerifyValidInResMode(Utility utility) { if (!isPathValid(utility.getPackInfoPath(), TYPE_FILE, PACK_INFO)) { - LOG.error("CompressVerify::isArgsValidInResMode pack-info-path is invalid."); + String errMsg = "--pack-info-path is invalid."; + LOG.error(PackingToolErrMsg.RES_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!isDirectoryValidStrictCase(utility.getEntryCardPath(), ENTRY_CARD_DIRECTORY_NAME)) { - LOG.error("CompressVerify::isArgsValidInResMode the level-1 directory name must is EntryCard" + - ", current is " + utility.getEntryCardPath()); + String errMsg = "The level-1 directory name must be EntryCard, current is " + utility.getEntryCardPath(); + LOG.error(PackingToolErrMsg.RES_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!compatibleProcess(utility, utility.getEntryCardPath(), utility.getformattedEntryCardPathList(), PNG_SUFFIX)) { - LOG.error("CompressVerify::isArgsValidInResMode entrycard-path is invalid."); + String errMsg = "--entrycard-path is invalid."; + LOG.error(PackingToolErrMsg.RES_MODE_ARGS_INVALID.toString(errMsg)); return false; } return isOutPathValid(utility, RES_SUFFIX); @@ -697,38 +728,45 @@ public class CompressVerify { private static boolean isVerifyValidInHQFMode(Utility utility) { if (utility.getJsonPath().isEmpty()) { - LOG.error("must input patch.json file when pack hqf file."); + String errMsg = "--json-path is empty, must input patch.json file when pack hqf file."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getEtsPath().isEmpty()) { if (!isPathValid(utility.getEtsPath(), TYPE_DIR, null)) { - LOG.error("must input valid ets path when pack hqf file."); + String errMsg = "--ets-path is invalid."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!isPathValid(utility.getJsonPath(), TYPE_FILE, PATCH_PROFILE)) { - LOG.error("input patch.json is invalid when pack hqf file."); + String errMsg = "--json-path is invalid."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getLibPath().isEmpty()) { if (!isPathValid(utility.getLibPath(), TYPE_DIR, null)) { - LOG.error("input lib path is invalid when pack hqf file."); + String errMsg = "--lib-path is invalid."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } } if (!utility.getResourcesPath().isEmpty()) { if (!isPathValid(utility.getResourcesPath(), TYPE_DIR, null)) { - LOG.error("input resources path is invalid when pack hqf file."); + String errMsg = "--resources-path is invalid."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } } File outFile = new File(utility.getOutPath()); if ((FALSE.equals(utility.getForceRewrite())) && (outFile.exists())) { - LOG.error(outFile.getName() + " already exist."); + String errMsg = outFile.getName() + " already exist."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getOutPath().endsWith(HQF_SUFFIX)) { - LOG.error("input out file must end with .hqf."); + String errMsg = "--out-path file must end with .hqf."; + LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -736,20 +774,24 @@ public class CompressVerify { private static boolean isVerifyValidInAPPQFMode(Utility utility) { if (utility.getHqfList().isEmpty()) { - LOG.error("input hqf list is empty."); + String errMsg = "--hqf-list is empty."; + LOG.error(PackingToolErrMsg.APPQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!compatibleProcess(utility, utility.getHqfList(), utility.getFormatedHQFList(), HQF_SUFFIX)) { - LOG.error("input hqf list is invalid."); + String errMsg = "--hqf-list is invalid."; + LOG.error(PackingToolErrMsg.APPQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } File outFile = new File(utility.getOutPath()); if ((FALSE.equals(utility.getForceRewrite())) && outFile.exists()) { - LOG.error("Error out file already existed."); + String errMsg = "--out-path file already existed, but --force is 'false'."; + LOG.error(PackingToolErrMsg.APPQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!outFile.getName().toLowerCase(Locale.ENGLISH).endsWith(APPQF_SUFFIX)) { - LOG.error("Error out-path must end with .app."); + String errMsg = "--out-path must end with .appqf."; + LOG.error(PackingToolErrMsg.APPQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -813,7 +855,8 @@ public class CompressVerify { formattedPathItem = utility.getFormattedPath(pathItem); if (!isPathValid(formattedPathItem, TYPE_FILE, HSP_SUFFIX) && !isPathValid(formattedPathItem, TYPE_FILE, HAP_SUFFIX)) { - LOG.error("input file " + formattedPathItem + " not valid"); + String errMsg = "Input file " + formattedPathItem + " is invalid"; + LOG.error(PackingToolErrMsg.INPUT_PATH_INVALID.toString(errMsg)); return false; } fileList.add(formattedPathItem); @@ -923,8 +966,8 @@ public class CompressVerify { private static boolean isDirectoryValidStrictCase(String path, String directoryName) { File file = new File(path); if (!file.exists()) { - LOG.error("CompressVerify::isDirectoryValidStrictCase directory is not exist, directoryPath: " - + path + "."); + String errMsg = "The directory does not exist, directory path is: " + path + "."; + LOG.error(PackingToolErrMsg.DIRECTORY_INVALID.toString(errMsg)); return false; } if (file.isDirectory()) { @@ -1070,48 +1113,58 @@ public class CompressVerify { private static boolean isVerifyValidInHapAdditionMode(Utility utility) { if (utility.getHapPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hapPath is empty."); + String errMsg = "--hap-path is empty."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } String hapPath = utility.getAbsoluteHapPath(); File hapFile = new File(hapPath); if (hapFile.isDirectory()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hapPath cannot be a folder."); + String errMsg = "--hap-path cannot be a folder."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!(hapPath.endsWith(HAP_SUFFIX) || hapPath.endsWith(HSP_SUFFIX))) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hapPath is invalid."); + String errMsg = "--hap-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!hapFile.exists()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode hap file does not exist."); + String errMsg = "--hap-path file does not exist."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getJsonPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode jsonPath is empty."); + String errMsg = "--json-path is empty."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!utility.getJsonPath().endsWith(JSON_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode jsonPath is invalid."); + String errMsg = "--json-path is invalid."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } File jsonFile = new File(utility.getJsonPath()); if (!jsonFile.exists()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode json file does not exist."); + String errMsg = "--json-path file does not exist."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (!checkJsonIsValid(jsonFile)) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode json format is incorrect."); + String errMsg = "--json-path file is invalid."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } if (utility.getOutPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode outPath is empty."); + String errMsg = "--out-path is empty."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } File dir = new File(utility.getOutPath()); if (dir.exists() && dir.isFile()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode outPath is file."); + String errMsg = "--out-path is file."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } File absoluteHapFile = new File(utility.getAbsoluteHapPath()); @@ -1119,7 +1172,8 @@ public class CompressVerify { String destPath = utility.getOutPath() + LINUX_FILE_SEPARATOR + hapFileName; File destFile = new File(destPath); if ("false".equals(utility.getForceRewrite()) && destFile.exists()) { - LOG.error("CompressVerify::isVerifyValidInHapAdditionMode target file already exists."); + String errMsg = "--out-path file already existed, but --force is 'false'."; + LOG.error(PackingToolErrMsg.HAP_ADDITION_MODE_ARGS_INVALID.toString(errMsg)); return false; } return true; @@ -1134,7 +1188,8 @@ public class CompressVerify { jsonData.append((char) ch); } } catch (IOException e) { - LOG.error("CompressVerify::CheckJsonIsValid failed: " + e.getMessage()); + String errMsg = "Check json file is valid exist IOException: "; + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg + e.getMessage())); return false; } JSONValidator validator = JSONValidator.from(jsonData.toString()); @@ -1238,7 +1293,8 @@ public class CompressVerify { try { Optional optional = FileUtils.getFileContent(utility.getJsonPath()); if(optional.isPresent()) { - return ModuleJsonUtil.parseModuleType(optional.get()).equals(BUNDLE_TYPE_SHARE) && !ModuleJsonUtil.parseAbilityNames(optional.get()).isEmpty(); + return ModuleJsonUtil.parseModuleType(optional.get()).equals(BUNDLE_TYPE_SHARE) && + !ModuleJsonUtil.parseAbilityNames(optional.get()).isEmpty(); } else { String errMsg = "Parse --json-path content failed."; LOG.error(PackingToolErrMsg.HSP_HAS_ABILITIES_FAILED.toString(errMsg)); diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index 7003a10b..ac285d7b 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -535,7 +535,7 @@ public class Compressor { throw new BundleException("Verify has generate build hash failed."); } catch (JSONException | IOException e) { LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString( - "Verify has generate build hash exist Exception(JSONException | IOException): " + e.getMessage())); + "Verify has generate build hash exist Exception (JSONException | IOException): " + e.getMessage())); throw new BundleException("Verify has generate build hash failed."); } finally { FileUtils.closeStream(json); @@ -587,8 +587,7 @@ public class Compressor { throw new BundleException("Compressor::setGenerateBuildHash failed."); } catch (NullPointerException | IOException | JSONException e) { LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString( - "json data err, exist Exception(NullPointerException | IOException | JSONException): " + - e.getMessage())); + "json data err, exist Exception (NullPointerException | IOException | JSONException): " + e.getMessage())); throw new BundleException("Set generate build hash failed, json data err."); } finally { FileUtils.closeStream(json); @@ -673,7 +672,8 @@ public class Compressor { } while (numRead != -1); return complete.digest(); } catch (IOException | NoSuchAlgorithmException e) { - LOG.error("Compressor::checkSum failed, IOException or NoSuchAlgorithmException: " + e.getMessage()); + LOG.error(PackingToolErrMsg.CHECK_SUM_FAILED.toString("Check sum exist Exception (IOException | " + + "NoSuchAlgorithmException): " + e.getMessage())); throw new BundleException("Compressor::checkSum failed."); } } @@ -1338,15 +1338,14 @@ public class Compressor { } // check hap is valid if (!checkHapIsValid(fileList, utility.getSharedApp())) { - String msg = "Compressor::checkHapIsValid verify failed, check version, " + - "apiVersion, moduleName, packageName."; - LOG.error(msg); - throw new BundleException(msg); + throw new BundleException("Compress file verify hap failed, check version, " + + "apiVersion, moduleName, packageName."); } // packApp packFastApp(utility, fileList); } catch (IOException ex) { - LOG.error("Compressor::compressAppMode compress failed: " + ex.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Compress fast app mode exist IOException: " + + ex.getMessage())); throw new BundleException("Compressor::compressAppMode compress failed."); } finally { if (tmpDir != null) { @@ -1437,8 +1436,9 @@ public class Compressor { //pack encrypt.json file packEncryptJsonFile(utility); } catch (BundleException | IOException exception) { - String errMsg = "Compressor::compressAppModeForMultiProject file failed: " + exception.getMessage(); - LOG.error(errMsg); + String errMsg = "Compress app mode for multi project file exist Exception (BundleException | IOException): " + + exception.getMessage(); + LOG.error(PackingToolErrMsg.COMPRESS_APP_MODE_FORMULTI_PROJECT_FAILED.toString(errMsg)); throw new BundleException(errMsg); } finally { deleteFile(tempPath); @@ -1459,7 +1459,7 @@ public class Compressor { File outParentFile = destFile.getParentFile(); if ((outParentFile != null) && (!outParentFile.exists())) { if (!outParentFile.mkdirs()) { - LOG.error("Compressor::hapAddition create out file parent directory failed."); + LOG.error(PackingToolErrMsg.HAP_ADDITION_FAILED.toString("Create out file parent directory failed.")); } } FileOutputStream fileOut = null; @@ -1476,7 +1476,8 @@ public class Compressor { compressHapAddition(utility, hapAdditionPath); } catch (BundleException | IOException exception) { - LOG.error("Compressor::HapAddition hapFile not found exception" + exception.getMessage()); + LOG.error(PackingToolErrMsg.HAP_ADDITION_FAILED.toString("Hap addition exist Exception" + + "(BundleException | IOException): " + exception.getMessage())); copyFileSafely(backName, hapPathOri); } finally { closeZipOutputStream(); @@ -1504,7 +1505,8 @@ public class Compressor { File destFile = new File(dest); FileUtils.copyFile(sourceFile, destFile); } catch (IOException | BundleException e) { - LOG.error("copyFileSafely failed: " + e.getMessage()); + LOG.error(PackingToolErrMsg.COPY_FILE_SAFELY_FAILED.toString("Copy file safely exist Exception" + + "(IOException | BundleException): " + e.getMessage())); } } @@ -1529,10 +1531,12 @@ public class Compressor { fileWriter.write(jsonString); fileWriter.flush(); } catch (IOException exception) { - LOG.error("writeJsonFile failed, " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Write json File exist IOException: " + + exception.getMessage())); throw new BundleException(exception.getMessage()); } catch (JSONException e) { - LOG.error("json file is invalid: " + e.getMessage()); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("Json file is exist JSONException: " + + e.getMessage())); throw new BundleException(e.getMessage()); } } @@ -1598,14 +1602,16 @@ public class Compressor { File targetParent = new File(targetParentPath); if (!targetParent.exists()) { if (!targetParent.mkdirs()) { - LOG.error("Compressor::compressHapAddition create target file parent directory failed."); + LOG.error(PackingToolErrMsg.COMPRESS_HAP_ADDITION_FAILED.toString( + "Create target file parent directory failed.")); } } String targetPath = targetParentPath + LINUX_FILE_SEPARATOR + ADDITION_JSON; writeJsonFile(data, targetPath); } catch (IOException | JSONException | BundleException e) { - String errMsg = "Compressor::compressHapAddition generate addition.json file failed, " + e.getMessage(); - LOG.error(errMsg); + String errMsg = "Generate addition.json file exist Exception" + + "(IOException | JSONException | BundleException): " + e.getMessage(); + LOG.error(PackingToolErrMsg.COMPRESS_HAP_ADDITION_FAILED.toString(errMsg)); throw new BundleException(errMsg); } @@ -1613,8 +1619,8 @@ public class Compressor { try { setUtilityParameter(hapAdditionPath, utility); } catch (IOException e) { - String errMsg = "Compressor::compressHapAddition setUtilityParameter failed."; - LOG.error(errMsg); + String errMsg = "Set utility parameter exist IOException: " + e.getMessage(); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } if (utility.getHapPath().endsWith(HAP_SUFFIX)) { @@ -1622,8 +1628,9 @@ public class Compressor { } else if (utility.getHapPath().endsWith(HSP_SUFFIX)) { compressHsp(utility); } else { - String errMsg = "Compressor::compressHapAddition compressFile failed."; - LOG.error(errMsg); + String errMsg = "Compression add failed because file (" + utility.getHapPath() + + ") is an unsupported file type."; + LOG.error(PackingToolErrMsg.COMPRESS_HAP_ADDITION_FAILED.toString(errMsg)); throw new BundleException(errMsg); } } @@ -1649,8 +1656,8 @@ public class Compressor { finalAppPackInfo = selectHapInApp(appPath, seletedHaps, tempDir, finalAppPackInfo); } } catch (BundleException | IOException e) { - String errMsg = "Compressor:disposeApp disposeApp failed."; - LOG.error(errMsg); + String errMsg = "Dispose app exist Exception (BundleException | IOException): " + e.getMessage(); + LOG.error(PackingToolErrMsg.DISPOSE_APP_FAILED.toString(errMsg)); throw new BundleException(errMsg); } return finalAppPackInfo; @@ -1671,8 +1678,8 @@ public class Compressor { // rebuild pack.info String packInfoStr = FileUtils.getJsonInZips(new File(appPath), PACKINFO_NAME); if (packInfoStr.isEmpty()) { - String errorMsg = "Compressor:selectHapInApp failed, app has no pack.info."; - LOG.error(errorMsg); + String errorMsg = "Select hap from app find that app does not contain pack.info."; + LOG.error(PackingToolErrMsg.NO_PACK_INFO.toString(errorMsg)); throw new BundleException(errorMsg); } if (finalAppPackInfo.isEmpty()) { @@ -1712,7 +1719,8 @@ public class Compressor { } // copy duplicated hap to duplicated dir and get moduleName of duplicated hap if (selectedHaps.contains(zipEntry.getName())) { - LOG.error("Compressor::copyHapFromApp file duplicated, file is " + zipEntry.getName() + "."); + LOG.error(PackingToolErrMsg.COMPRESS_FILE_DUPLICATE.toString("Hap or hsp with duplicate " + + "file names. file is " + zipEntry.getName() + ".")); throw new BundleException("Compressor::copyHapFromApp file duplicated, file is " + zipEntry.getName() + "."); } else { @@ -1732,8 +1740,8 @@ public class Compressor { inputStream.close(); } } catch (IOException e) { - String errMsg = "Compressor:copyHapFromApp app path not found."; - LOG.error(errMsg); + String errMsg = "Copy hap and hsp from app exist IOException: " + e.getMessage(); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } finally { Utility.closeStream(zipInput); @@ -1779,7 +1787,8 @@ public class Compressor { } for (String hapPath : utility.getFormattedHapList()) { if (seletedHaps.contains(new File(hapPath).getName())) { - LOG.error("Compressor::disposeHap file duplicated, file is " + new File(hapPath).getName() + "."); + LOG.error(PackingToolErrMsg.COMPRESS_FILE_DUPLICATE.toString("Hap with duplicate file names, file is " + + new File(hapPath).getName() + ".")); throw new BundleException("Compressor::disposeHap file duplicated, file is " + new File(hapPath).getName() + "."); } @@ -1790,8 +1799,8 @@ public class Compressor { String packInfo = FileUtils.getJsonInZips(hapFile, PACKINFO_NAME); if (packInfo.isEmpty()) { - String errMsg = "Compressor::disposeHap failed, hap has no pack.info."; - LOG.error(errMsg); + String errMsg = "Hap does not contain a valid pack.info."; + LOG.error(PackingToolErrMsg.NO_PACK_INFO.toString(errMsg)); throw new BundleException(errMsg); } if (finalPackInfoStr.isEmpty()) { @@ -1816,8 +1825,8 @@ public class Compressor { fwriter = new FileWriter(filePath); fwriter.write(packInfoStr); } catch (IOException e) { - String errMsg = "Compressor:writePackInfo failed."; - LOG.error(errMsg); + String errMsg = "Write pack info exist IOException: " + e.getMessage(); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } finally { if (fwriter != null) { @@ -1917,21 +1926,22 @@ public class Compressor { String fName = fileName.trim(); String[] temp = fName.replace("\\", "/").split("/"); if (temp.length < 4) { - LOG.error("Compressor::compressPackResMode the hap file path is invalid, length: " - + temp.length + "."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE_FAILED.toString("The hap file path is " + + "invalid, length is " + temp.length + ", expected at least 4.")); continue; } String fileLanguageCountryName = temp[temp.length - 3]; if (!isThirdLevelDirectoryNameValid(fileLanguageCountryName)) { - LOG.error("Compressor::compressProcess compress failed third level directory name: " - + fileLanguageCountryName + " is invalid, please check it with reference to this example: " - + "zh_Hani_CN-vertical-car-mdpi-dark or zh_Hani_CN-vertical-car-mdpi."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE_FAILED.toString("Third level " + + "directory name: " + fileLanguageCountryName + " is invalid, please check it with " + + "reference to this example: zh_Hani_CN-vertical-car-mdpi-dark or " + + "zh_Hani_CN-vertical-car-mdpi.")); throw new BundleException("Compress failed third level directory name Error."); } String filePicturingName = temp[temp.length - 1]; if (!isPicturing(filePicturingName, utility)) { - LOG.error("Compressor::compressProcess Compress pack.res failed, Invalid resource file" + - " name: " + filePicturingName + ", correct format example is formName-2x2.png."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE_FAILED.toString("Invalid resource file" + + " name: " + filePicturingName + ", correct format example is formName-2x2.png.")); throw new BundleException("Compress pack.res failed, Invalid resource file name: " + filePicturingName + ", correct format example is formName-2x2.png."); } @@ -1941,7 +1951,7 @@ public class Compressor { snapshotNameList.add(fullSnapshotName); } else { - LOG.error("Compressor::compressProcess compress failed No image in PNG format is found."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE_FAILED.toString("No PNG format image found.")); throw new BundleException("Compress pack.res failed, compress failed No image in" + " PNG format is found."); } @@ -1949,8 +1959,9 @@ public class Compressor { for (String formName : formNamesList) { if (!snapshotNameList.contains(formName)) { - LOG.error("Compressor::compressProcess compress failed entryCard " + formName - + " has no related snapshot " + snapshotNameList.toString() + "."); + LOG.error(PackingToolErrMsg.COMPRESS_PACK_RES_MODE_FAILED.toString("EntryCard has no related " + + "snapshot. " + formName + " has no related snapshot " + + snapshotNameList.toString() + ".")); throw new BundleException("Compress pack.res failed, compress failed entryCard has no related snapshot."); } } @@ -2037,7 +2048,8 @@ public class Compressor { private boolean checkLanguage(String language) { if (!Pattern.compile(REGEX_LANGUAGE).matcher(language).matches()) { - LOG.error("Compressor::compressProcess language " + language + " is not in ISO 639-1 list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(language + + " is not in ISO 639-1 list.")); return false; } return true; @@ -2045,7 +2057,8 @@ public class Compressor { private boolean checkScript(String script) { if (!Pattern.compile(REGEX_SCRIPT).matcher(script).matches()) { - LOG.error("Compressor::compressProcess script " + script + " is not in ISO 15924 list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(script + + " is not in ISO 15924 list.")); return false; } return true; @@ -2053,7 +2066,8 @@ public class Compressor { private boolean checkCountry(String country) { if (!Pattern.compile(REGEX_COUNTRY).matcher(country).matches()) { - LOG.error("Compressor::compressProcess country " + country + " is not in ISO 3166-1 list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(country + + " is not in ISO 3166-1 list.")); return false; } return true; @@ -2061,8 +2075,8 @@ public class Compressor { private boolean checkOrientation(String orientation) { if (!Pattern.compile(REGEX_ORIENTATION).matcher(orientation).matches()) { - LOG.error("Compressor::compressProcess orientation " + orientation + - " is not in {vertical, horizontal} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(orientation + + " is not in {vertical, horizontal} list.")); return false; } return true; @@ -2070,8 +2084,8 @@ public class Compressor { private boolean checkDeviceType(String deviceType) { if (!Pattern.compile(REGEX_DEVICE_TYPE).matcher(deviceType).matches()) { - LOG.error("Compressor::compressProcess deviceType " + deviceType + - " is not in {phone, tablet, car, tv, wearable, liteWearable, 2in1} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(deviceType + + " is not in {phone, tablet, car, tv, wearable, liteWearable, 2in1} list.")); return false; } return true; @@ -2079,8 +2093,8 @@ public class Compressor { private boolean checkScreenDensity(String screenDensity) { if (!Pattern.compile(REGEX_SCREEN_DENSITY).matcher(screenDensity).matches()) { - LOG.error("Compressor::compressProcess screenDensity " + screenDensity + - " is not in {sdpi, mdpi, ldpi, xldpi, xxldpi} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(screenDensity + + " is not in {sdpi, mdpi, ldpi, xldpi, xxldpi} list.")); return false; } return true; @@ -2088,8 +2102,8 @@ public class Compressor { private boolean checkColorMode(String colorMode) { if (!Pattern.compile(REGEX_COLOR_MODE).matcher(colorMode).matches()) { - LOG.error("Compressor::compressProcess colorMode " + colorMode + - " is not in {light, dark} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(colorMode + + " is not in {light, dark} list.")); return false; } return true; @@ -2100,8 +2114,8 @@ public class Compressor { Pattern.compile(REGEX_SHAPE).matcher(tmp).matches()) { return true; } - LOG.error("Compressor::compressProcess " + tmp + - " is neither in colorMode list {light, dark} nor in shape list {circle}."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(tmp + + " is neither in colorMode list {light, dark} nor in shape list {circle}.")); return false; } @@ -2109,7 +2123,7 @@ public class Compressor { if (Pattern.compile(REGEX_SHAPE).matcher(shape).matches()) { return true; } - LOG.error("Compressor::compressProcess shape" + shape + " is not in {circle} list."); + LOG.error(PackingToolErrMsg.INVALID_THIRD_LEVEL_DIRECTORY_NAME.toString(shape + " is not in {circle} list.")); return false; } @@ -2126,24 +2140,26 @@ public class Compressor { return isSpecifications; } if (!name.endsWith(PNG_SUFFIX) && !name.endsWith(UPPERCASE_PNG_SUFFIX)) { - LOG.error("isPicturing: the suffix is not .png or .PNG."); + LOG.error(PackingToolErrMsg.IS_PICTURING_FAILED.toString("The suffix is not .png or .PNG.")); return false; } int delimiterIndex = name.lastIndexOf("-"); if (delimiterIndex < 0) { - LOG.error("isPicturing: the entry card naming format is invalid and should be separated by '-'."); + LOG.error(PackingToolErrMsg.IS_PICTURING_FAILED.toString( + "The entry card naming format is invalid and should be separated by '-'.")); return false; } String formName = name.substring(0, delimiterIndex); if (!utility.getFormNameList().contains(formName)) { - LOG.error("isPicturing: the name is not same as formName, name: " + formName + " is not in " + - utility.getFormNameList().toString() + "."); + LOG.error(PackingToolErrMsg.IS_PICTURING_FAILED.toString( + "The name is not same as formName, name: " + formName + " is not in " + + utility.getFormNameList().toString() + ".")); return false; } String dimension = name.substring(delimiterIndex + 1, name.lastIndexOf(".")); if (!supportDimensionsList.contains(dimension)) { - LOG.error("isPicturing: the dimension: " + dimension + " is invalid, is not in the following list: " - + "{1X2, 2X2, 2X4, 4X4, 1X1, 6X4}."); + LOG.error(PackingToolErrMsg.IS_PICTURING_FAILED.toString(dimension + " is invalid, is not in the " + + "following list: {1X2, 2X2, 2X4, 4X4, 1X1, 6X4}.")); return false; } @@ -2153,12 +2169,14 @@ public class Compressor { private void getFileList(final String filePath) throws BundleException { File file = new File(filePath); if (!file.exists()) { - LOG.error("getFileList: file is not exists."); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("File does not exist. File path is " + + filePath + ".")); return; } File[] files = file.listFiles(); if (files == null) { - LOG.error("getFileList: no file in this file path."); + LOG.error(PackingToolErrMsg.GET_FILE_LIST_FAILED.toString("No files found in the specified path: " + + filePath + ".")); return; } for (File f : files) { @@ -2170,8 +2188,8 @@ public class Compressor { } String snapshotDirectoryName = f.getParentFile().getName(); if (!ENTRYCARD_SNAPSHOT_NAME.equals(snapshotDirectoryName)) { - LOG.error("The level-4 directory of EntryCard must be named as snapshot" + - ", but current is: " + snapshotDirectoryName + "."); + LOG.error(PackingToolErrMsg.GET_FILE_LIST_FAILED.toString("The level-4 directory of EntryCard " + + "must be named as snapshot, but current is: " + snapshotDirectoryName + ".")); throw new BundleException("The level-4 directory of EntryCard must be named as snapshot" + ", but current is: " + snapshotDirectoryName + "."); } @@ -2179,10 +2197,11 @@ public class Compressor { } else if (f.isDirectory()) { getFileList(f.getCanonicalPath()); } else { - LOG.error("It's not file or directory."); + LOG.error(PackingToolErrMsg.GET_FILE_LIST_FAILED.toString("It's not file or directory.")); } } catch (IOException msg) { - LOG.error("IOException error: " + msg.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Get file list exist IOException: " + + msg.getMessage())); return; } } @@ -2272,8 +2291,7 @@ public class Compressor { zipCreator.writeTo(zipOut); } catch (IOException | InterruptedException | ExecutionException e) { LOG.error(PackingToolErrMsg.COMPRESS_PARALLEL_EXCEPTION.toString( - "Parallel compress exist Exception(IOException | InterruptedException | ExecutionException): " + - e.getMessage())); + "Parallel compress exist Exception (IOException | InterruptedException | ExecutionException): " + e.getMessage())); throw new BundleException("Parallel compress exception. " + e.getMessage()); } } @@ -2611,15 +2629,16 @@ public class Compressor { ModuleJsonUtil.parsePackInfoFormsName(jsonString, nameList, formNamesList); for (String formName : nameList) { if (formName.isEmpty()) { - LOG.error("Compressor::infoSpecialJsonFileProcess form name is empty."); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("Form name parsed from " + + "pack.info is empty.")); continue; } utility.addFormNameList(formName); } } catch (JSONException e) { - LOG.error("Compressor::infoSpecialJsonFileProcess json Path: " + jsonPath + - "json exception: " + e.getMessage()); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString("Parse pack.info eixst JSONException: " + + e.getMessage())); } } @@ -2650,7 +2669,8 @@ public class Compressor { str = bufferedReader.readLine(); } } catch (IOException exception) { - LOG.error("Compressor::jsonSpecialProcess io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("pack.info special process exist IOException: " + + exception.getMessage())); throw new BundleException("Json special process failed."); } finally { Utility.closeStream(bufferedReader); @@ -2753,7 +2773,8 @@ public class Compressor { } } } catch (IOException exception) { - LOG.error("Compressor::parseModuleName io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Parse module name exist IOException: " + + exception.getMessage())); throw new BundleException("Parse module name failed."); } } @@ -2830,19 +2851,22 @@ public class Compressor { try { int endIndex = lineStr.lastIndexOf(SEMICOLON); if (endIndex <= 0) { - LOG.error("Compressor::getModuleNameFromString field the json is not standard."); + LOG.error(PackingToolErrMsg.GET_MODULE_NAME_FROM_STRING_FAILED.toString("Unable to find '\"' " + + "in the lineStr.")); throw new BundleException("Parse module name failed, module-name is invalid."); } int startIndex = lineStr.lastIndexOf(SEMICOLON, endIndex - 1) + 1; String moduleName = lineStr.substring(startIndex, endIndex); list.add(moduleName); if (moduleName == null || moduleName.isEmpty()) { - LOG.error("Compressor::getModuleNameFromString field module-name is empty."); + LOG.error(PackingToolErrMsg.GET_MODULE_NAME_FROM_STRING_FAILED.toString("moduleName or module-name " + + "is empty.")); throw new BundleException("Parse module name failed, module-name is empty."); } utility.setModuleName(moduleName); } catch (StringIndexOutOfBoundsException exception) { - LOG.error("Compressor::parseModuleName field module-name is fault: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.GET_MODULE_NAME_FROM_STRING_FAILED.toString("Get Module name from line string " + + "exist StringIndexOutOfBoundsException: " + exception.getMessage())); throw new BundleException("Parse module name failed, module-name is invalid."); } } @@ -3118,8 +3142,8 @@ public class Compressor { private void compressAPPQFMode(Utility utility) throws BundleException { List fileList = utility.getFormatedHQFList(); if (!checkHQFIsValid(fileList)) { - LOG.error("checkHQFIsValid failed when pack appqf file."); - throw new BundleException("checkHQFIsValid failed when pack appqf file."); + LOG.error(PackingToolErrMsg.COMPRESS_APPQF_FAILED.toString("Verify failed when compress appqf.")); + throw new BundleException("Verify failed when compress appqf."); } for (String hapPath : fileList) { pathToFile(utility, hapPath, NULL_DIR_NAME, false); @@ -3138,7 +3162,7 @@ public class Compressor { hqfVerifyInfos.add(ModuleJsonUtil.parseHQFInfo(file)); } if (!HQFVerify.checkHQFIsValid(hqfVerifyInfos)) { - LOG.error("input hqf is invalid."); + LOG.error(PackingToolErrMsg.CHECK_HQF_INVALID.toString("Input hqf is invalid.")); return false; } return true; @@ -3265,7 +3289,7 @@ public class Compressor { tempDir.toAbsolutePath() + LINUX_FILE_SEPARATOR + PACKINFO_NAME); if (moduleFile.exists() && configFile.exists()) { - LOG.error("versionNormalize failed, invalid hap structure."); + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_FAILED.toString("Invalid hap structure.")); throw new BundleException("versionNormalize failed, invalid hap structure."); } if (moduleFile.exists()) { @@ -3275,7 +3299,7 @@ public class Compressor { String configJsonPath = tempDir.resolve(CONFIG_JSON).toString(); util = parseAndModifyConfigJson(configJsonPath, utility); } else { - LOG.error("versionNormalize failed, invalid hap structure."); + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_FAILED.toString("Invalid hap structure.")); throw new BundleException("versionNormalize failed, invalid hap structure."); } if (packInfoFile.exists()) { @@ -3290,7 +3314,8 @@ public class Compressor { LINUX_FILE_SEPARATOR + Paths.get(hapPath).getFileName().toString(); compressDirToHap(tempDir, modifiedHapPath); } catch (IOException | BundleException e) { - LOG.error("versionNormalize failed " + e.getMessage()); + LOG.error(PackingToolErrMsg.VERSION_NORMALIZE_FAILED.toString( + "Version normalize exist Exception (IOException | BundleException): " + e.getMessage())); } finally { if (tempDir != null) { deleteDirectory(tempDir.toFile()); @@ -3306,33 +3331,38 @@ public class Compressor { try (FileInputStream jsonStream = new FileInputStream(jsonFilePath)) { JSONObject jsonObject = JSON.parseObject(jsonStream, JSONObject.class); if (!jsonObject.containsKey(APP)) { - LOG.error("parseAndModifyJson failed, json file not valid."); - throw new BundleException("parseAndModifyJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The module.json file " + + "does not contain 'app'. ")); + throw new BundleException("The module.json file does not contain 'app'. "); } JSONObject appObject = jsonObject.getJSONObject(APP); if (!appObject.containsKey(VERSION_CODE)) { - LOG.error("parseAndModifyJson failed, json file not valid."); - throw new BundleException("parseAndModifyJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The module.json file " + + "does not contain 'versionCode'. ")); + throw new BundleException("The module.json file does not contain 'versionCode'. "); } if (!appObject.containsKey(VERSION_NAME)) { - LOG.error("parseAndModifyJson failed, json file not valid."); - throw new BundleException("parseAndModifyJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The module.json file " + + "does not contain 'versionName'. ")); + throw new BundleException("The module.json file does not contain 'versionName'. "); } util.setOriginVersionCode(appObject.getIntValue(VERSION_CODE)); util.setOriginVersionName(appObject.getString(VERSION_NAME)); JSONObject moduleObject = jsonObject.getJSONObject(MODULE); if (!moduleObject.containsKey(NAME)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); - throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The module.json file " + + "does not contain 'name'. ")); + throw new BundleException("The module.json file does not contain 'name'. "); } util.setModuleName(moduleObject.getString(NAME)); appObject.put(VERSION_CODE, utility.getVersionCode()); appObject.put(VERSION_NAME, utility.getVersionName()); writeJson(jsonFilePath, jsonObject); } catch (IOException e) { - LOG.error("parseAndModifyModuleJson failed, IOException." + e.getMessage()); - throw new BundleException("parseAndModifyModuleJson failed, IOException." + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Parse and modify module.json exist IOException: " + + e.getMessage())); + throw new BundleException("Parse and modify module.json exist IOException: " + e.getMessage()); } return util; } @@ -3377,7 +3407,8 @@ public class Compressor { new FileOutputStream(jsonFilePath), StandardCharsets.UTF_8)); bw.write(pretty); } catch (IOException exception) { - LOG.error("Compressor::writeJson failed for IOException " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Write json exist IOException: " + + exception.getMessage())); throw new BundleException("Compressor::writeJson failed for IOException"); } finally { if (bw != null) { @@ -3393,30 +3424,35 @@ public class Compressor { try (FileInputStream jsonStream = new FileInputStream(jsonFilePath)) { JSONObject jsonObject = JSON.parseObject(jsonStream, JSONObject.class); if (!jsonObject.containsKey(APP)) { - LOG.error("parseAndModifyJson failed, json file not valid."); - throw new BundleException("parseAndModifyJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The config.json file " + + "does not contain 'app'. ")); + throw new BundleException("The config.json file does not contain 'app'. "); } JSONObject appObject = jsonObject.getJSONObject(APP); if (!appObject.containsKey(VERSION)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); - throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The config.json file " + + "does not contain 'version'. ")); + throw new BundleException("The config.json file does not contain 'version'. "); } JSONObject versionObj = appObject.getJSONObject(VERSION); if (!versionObj.containsKey(CODE)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); - throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The config.json file " + + "does not contain 'code'. ")); + throw new BundleException("The config.json file does not contain 'code'. "); } util.setOriginVersionCode(versionObj.getIntValue(CODE)); if (!versionObj.containsKey(NAME)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); - throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The config.json file " + + "does not contain 'name'. ")); + throw new BundleException("The config.json file does not contain 'name'. "); } util.setOriginVersionName(versionObj.getString(NAME)); JSONObject moduleObject = jsonObject.getJSONObject(MODULE); if (!moduleObject.containsKey(NAME)) { - LOG.error("parseAndModifyModuleJson failed, json file not valid."); - throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); + LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The config.json file " + + "does not contain 'name'. ")); + throw new BundleException("The config.json file does not contain 'name'. "); } util.setModuleName(moduleObject.getString(NAME)); @@ -3424,8 +3460,9 @@ public class Compressor { versionObj.put(NAME, utility.getVersionName()); writeJson(jsonFilePath, jsonObject); } catch (IOException e) { - LOG.error("parseAndModifyModuleJson IOException." + e.getMessage()); - throw new BundleException("parseAndModifyModuleJson IOException." + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Parse and modify config.json exist IOException: " + + e.getMessage())); + throw new BundleException("Parse and modify config.json exist IOException: " + e.getMessage()); } return util; } @@ -3516,7 +3553,8 @@ public class Compressor { try (FileWriter fileWriter = new FileWriter(outPath + LINUX_FILE_SEPARATOR + VERSION_RECORD)) { fileWriter.write(jsonString); } catch (IOException e) { - LOG.error("writeVersionRecord failed " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Write version record exist IOException: " + + e.getMessage())); } } @@ -3525,7 +3563,7 @@ public class Compressor { if (versionNormalizeUtil.getOriginVersionCode() > utility.getVersionCode()) { String errorMsg = "versionNormalize failed, module " + versionNormalizeUtil.getModuleName() + " version code less than input version code"; - LOG.error(errorMsg); + LOG.error(PackingToolErrMsg.VERIFY_MODULE_VERSION_FAILED.toString(errorMsg)); throw new BundleException(errorMsg); } else if (versionNormalizeUtil.getOriginVersionCode() == utility.getVersionCode()) { LOG.warning("versionNormalize warning: module " + @@ -3565,7 +3603,7 @@ public class Compressor { zipInputStream.closeEntry(); } } catch (IOException e) { - LOG.error("unpack hap failed IOException " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Unpack hap exist IOException: " + e.getMessage())); throw new BundleException("unpack hap failed IOException " + e.getMessage()); } } diff --git a/adapter/ohos/FileUtils.java b/adapter/ohos/FileUtils.java index a854c27c..3d7417ef 100644 --- a/adapter/ohos/FileUtils.java +++ b/adapter/ohos/FileUtils.java @@ -344,8 +344,8 @@ class FileUtils { */ public static void copyFile(File sourceFile, File destFile) throws IOException, BundleException { if (sourceFile == null || destFile == null) { - String errMsg = "CompressorFileUtil::copyFile input file is null."; - LOG.error(errMsg); + String errMsg = "Source file or destination file is null."; + LOG.error(PackingToolErrMsg.COPY_FILE_FAILED.toString(errMsg)); throw new BundleException(errMsg); } InputStream inputStream = null; @@ -372,8 +372,8 @@ class FileUtils { */ public static void makeDir(File dirFile) throws IOException, BundleException { if (dirFile == null) { - String errMsg = "CompressorFileUtil::makeDir input file is null."; - LOG.error(errMsg); + String errMsg = "Input file is null."; + LOG.error(PackingToolErrMsg.MAKE_DIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } dirFile.mkdirs(); @@ -414,7 +414,8 @@ class FileUtils { } jsonStr = new StringBuilder(jsonStr.toString().replaceAll("\r|\n|\t", "")); } catch (IOException exception) { - LOG.error("Compressor::checkModuleTypeInHaps io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "Get Json in zips exist IOException: " + exception.getMessage())); throw new BundleException("Compressor::checkModuleTypeInHaps failed."); } finally { Utility.closeStream(zipFile); @@ -447,7 +448,8 @@ class FileUtils { } } } catch (IOException e) { - LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Get profile json exist IOExpection: " + e.getMessage())); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "Get profile json exist IOException: " + e.getMessage())); throw new BundleException("Get profile json failed."); } return resourceMap; diff --git a/adapter/ohos/HQFVerify.java b/adapter/ohos/HQFVerify.java index a872ddfe..610ea157 100644 --- a/adapter/ohos/HQFVerify.java +++ b/adapter/ohos/HQFVerify.java @@ -33,15 +33,15 @@ class HQFVerify { public static boolean checkHQFIsValid(List hqfVerifyInfos) { // check app fields if (hqfVerifyInfos.isEmpty()) { - LOG.error("input hqf file is empty."); + LOG.error(PackingToolErrMsg.CHECK_HQF_INVALID.toString("Input hqf file is empty.")); return false; } if (!checkAppFields(hqfVerifyInfos)) { - LOG.error("input hqf file has different fields in app."); + LOG.error(PackingToolErrMsg.CHECK_HQF_INVALID.toString("Input hqf file has different fields in app.")); return false; } if (!checkModuleIsValid(hqfVerifyInfos)) { - LOG.error("input hqf file moduleName is invalid."); + LOG.error(PackingToolErrMsg.CHECK_HQF_INVALID.toString("Input hqf file moduleName is invalid.")); return false; } return true; @@ -61,23 +61,28 @@ class HQFVerify { String patchVersionName = hqfVerifyInfos.get(0).getPatchVersionName(); for (HQFInfo hqfVerifyInfo : hqfVerifyInfos) { if (bundleName == null || !bundleName.equals(hqfVerifyInfo.getBundleName())) { - LOG.error("input hqf file has different bundleName."); + String errMsg = "Input hqf file has different bundleName."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_FAILED.toString(errMsg)); return false; } if (versionCode != hqfVerifyInfo.getVersionCode()) { - LOG.error("input hqf file has different versionCode."); + String errMsg = "Input hqf file has different versionCode."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_FAILED.toString(errMsg)); return false; } if (versionName == null || !versionName.equals(hqfVerifyInfo.getVersionName())) { - LOG.error("input hqf file has different versionName."); + String errMsg = "Input hqf file has different versionName."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_FAILED.toString(errMsg)); return false; } if (patchVersionCode != hqfVerifyInfo.getPatchVersionCode()) { - LOG.error("input hqf file has different patchVersionCode."); + String errMsg = "Input hqf file has different patchVersionCode."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_FAILED.toString(errMsg)); return false; } if (patchVersionName == null || !patchVersionName.equals(hqfVerifyInfo.getPatchVersionName())) { - LOG.error("input hqf file has different patchVersionName."); + String errMsg = "Input hqf file has different patchVersionName."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_FAILED.toString(errMsg)); return false; } } @@ -94,7 +99,8 @@ class HQFVerify { for (int i = 0; i < hqfVerifyInfos.size(); ++i) { for (int j = i + 1; j < hqfVerifyInfos.size(); ++j) { if (checkModuleIsDuplicated(hqfVerifyInfos.get(i), hqfVerifyInfos.get(j))) { - LOG.error("input hqf file moduleName duplicated."); + String errMsg = "Input hqf file moduleName duplicated."; + LOG.error(PackingToolErrMsg.CHECK_MODULE_INVALID.toString(errMsg)); return false; } } diff --git a/adapter/ohos/ModuleJsonUtil.java b/adapter/ohos/ModuleJsonUtil.java index 5e96c495..0458ba35 100644 --- a/adapter/ohos/ModuleJsonUtil.java +++ b/adapter/ohos/ModuleJsonUtil.java @@ -395,13 +395,16 @@ class ModuleJsonUtil { finalPackObj = JSON.parseObject(finalPackInfo); JSONObject srcPackObj = JSON.parseObject(srcPackInfo); if (!verifyPackInfo(finalPackObj, srcPackObj)) { - LOG.error("ModuleJsonUtil:mergeTwoPackInfo verify pack.info failed."); - throw new BundleException("ModuleJsonUtil:mergeTwoPackInfo verify pack.info failed."); + String errMsg = "Verify pack.info failed."; + LOG.error(PackingToolErrMsg.MERGE_TWO_PACKINFO_FAILED.toString(errMsg)); + throw new BundleException(errMsg); } desPackInfo = mergePackInfoObj(finalPackObj, srcPackObj); } catch (BundleException | JSONException e) { - LOG.error("ModuleJsonUtil:mergeTwoPackInfo merge pack.info failed: " + e.getMessage()); - throw new BundleException("ModuleJsonUtil:mergeTwoPackInfo merge pack.info failed."); + String errMsg = "Merge two pack.info file into one pack.info exist " + + "exception(BundleException | JSONException): "; + LOG.error(PackingToolErrMsg.MERGE_TWO_PACKINFO_FAILED.toString(errMsg + e.getMessage())); + throw new BundleException(errMsg + e.getMessage()); } return desPackInfo; } @@ -415,24 +418,28 @@ class ModuleJsonUtil { */ public static boolean verifyPackInfo(JSONObject finalPackObj, JSONObject srcPackObj) throws BundleException { if (finalPackObj == null || srcPackObj == null) { - LOG.error("ModuleJsonUtil:verifyPackInfo fail to read pack.info."); + String errMsg = "Input json Objects (final pack.info or src pack.info) are null."; + LOG.error(PackingToolErrMsg.VERIFY_PACKINFO_FAILED.toString(errMsg)); return false; } JSONObject finalSummaryObj = finalPackObj.getJSONObject(SUMMARY); JSONObject srcSummaryObj = srcPackObj.getJSONObject(SUMMARY); if (finalSummaryObj == null || srcSummaryObj == null) { - LOG.error("ModuleJsonUtil:verifyPackInfo pack.info do not contain summary."); + String errMsg = "pack.info does not contain summary."; + LOG.error(PackingToolErrMsg.VERIFY_PACKINFO_FAILED.toString(errMsg)); return false; } // check app info JSONObject finalAppObj = finalSummaryObj.getJSONObject(APP); JSONObject srcAppObj = srcSummaryObj.getJSONObject(APP); if (finalAppObj == null || srcAppObj == null) { - LOG.error("ModuleJsonUtil:verifyPackInfo pack.info do not contain app."); + String errMsg = "pack.info does not contain app."; + LOG.error(PackingToolErrMsg.VERIFY_PACKINFO_FAILED.toString(errMsg)); return false; } if (!verifyAppInPackInfo(finalAppObj, srcAppObj)) { - LOG.error("ModuleJsonUtil:verifyPackInfo verify app failed."); + String errMsg = "Verify app field in pack.info failed."; + LOG.error(PackingToolErrMsg.VERIFY_PACKINFO_FAILED.toString(errMsg)); return false; } @@ -448,32 +455,37 @@ class ModuleJsonUtil { */ public static boolean verifyAppInPackInfo(JSONObject finalAppObj, JSONObject srcAppObj) { if (finalAppObj == null || srcAppObj == null) { - LOG.error("ModuleJsonUtil:verifyAppInPackInfo input null json object."); + String errMsg = "Input JSON objects (finalAppObj or srcAppObj) are null."; + LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } // check bundleName String finalBundleName = finalAppObj.getString(BUNDLE_NAME); String srcBundleName = srcAppObj.getString(BUNDLE_NAME); if (!finalBundleName.equals(srcBundleName)) { - LOG.error("ModuleJsonUtil:verifyAppInPackInfo bundleName is different."); + String errMsg = "BundleName is different between final bundleName and src bundleName."; + LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } // check bundleType if (!checkBundleTypeInPackInfo(finalAppObj, srcAppObj)) { - LOG.error("ModuleJsonUtil:verifyAppInPackInfo bundleType is different."); + String errMsg = "BundleType is different between final app object and src app object."; + LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } // check version JSONObject finalVersionObj = finalAppObj.getJSONObject(VERSION); JSONObject srcVersionObj = srcAppObj.getJSONObject(VERSION); if (finalVersionObj == null || srcVersionObj == null) { - LOG.error("ModuleJsonUtil:verifyAppInPackInfo version object is empty."); + String errMsg = "Final version object or src version object is empty."; + LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } int finalVersionCode = finalVersionObj.getIntValue(CODE); int srcVersionCode = srcVersionObj.getIntValue(CODE); if (finalVersionCode != srcVersionCode) { - LOG.error("ModuleJsonUtil:verifyAppInPackInfo versionCode is different."); + String errMsg = "Code is different between final version object and src version object."; + LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } return true; @@ -488,7 +500,8 @@ class ModuleJsonUtil { */ public static boolean checkBundleTypeInPackInfo(JSONObject finalAppObj, JSONObject srcAppObj) { if (finalAppObj.isEmpty() || srcAppObj.isEmpty()) { - LOG.error("ModuleJsonUtil:checkBundleTypeInPackInfo pack.info has empty module."); + String errMsg = "Input JSON objects (finalAppObj or srcAppObj) are null."; + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_PACKINFO_INVALID.toString(errMsg)); return false; } String finalBundleType = "app"; @@ -500,7 +513,8 @@ class ModuleJsonUtil { srcBundleType = getJsonString(srcAppObj, BUNDLE_TYPE); } if (!finalBundleType.equals(srcBundleType)) { - LOG.error("bundleType in pack.info is not same."); + String errMsg = "BundleType is different between final bundleType and src bundleType."; + LOG.error(PackingToolErrMsg.BUNDLE_TYPE_PACKINFO_INVALID.toString(errMsg)); return false; } return true; @@ -556,13 +570,15 @@ class ModuleJsonUtil { throws BundleException { JSONObject jsonObject = JSONObject.parseObject(jsonString); if (jsonObject == null || !jsonObject.containsKey(SUMMARY)) { - LOG.error("ModuleJsonUtil::parsePackInfoFormsName error: summary is null."); + String errMsg = "json object does not contain summary."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_NAME_FAILED.toString(errMsg)); throw new BundleException("Parse pack info forms name failed, summary is null."); } JSONObject summaryJson = jsonObject.getJSONObject(SUMMARY); if (summaryJson == null || !summaryJson.containsKey("modules")) { - LOG.error("ModuleJsonUtil::parsePackInfoFormsName error: summary.modules is null."); + String errMsg = "summary object does not contain modules."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_NAME_FAILED.toString(errMsg)); return; } @@ -570,13 +586,15 @@ class ModuleJsonUtil { for (int i = 0; i < moduleJsonList.size(); i++) { JSONObject moduleJson = moduleJsonList.getJSONObject(i); if (moduleJson == null || !moduleJson.containsKey(DISTRO)) { - LOG.error("ModuleJsonUtil::parsePackInfoFormsName error: summary.modules.distro is null."); + String errMsg = "modules object does not contain distro."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_NAME_FAILED.toString(errMsg)); continue; } JSONObject distroObj = moduleJson.getJSONObject(DISTRO); if (distroObj == null || !distroObj.containsKey(MODULE_NAME)) { - LOG.error("ModuleJsonUtil::parsePackInfoFormsName error: summary.modules.distro.moduleName is null."); + String errMsg = "distro object does not contain moduleName."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_NAME_FAILED.toString(errMsg)); continue; } @@ -661,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 = "Input JSON objects (finalPackinfoObj or srcPackinfoObj) are null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_FAILED.toString(errMsg)); throw new BundleException(errMsg); } JSONObject finalSummaryObj = finalPackinfoObj.getJSONObject(SUMMARY); JSONObject srcSummaryObj = srcPackinfoObj.getJSONObject(SUMMARY); if (finalSummaryObj == null || srcSummaryObj == null) { - String errMsg = "ModuleJsonUtil:mergePackInfoObj input json file has empty summary."; - LOG.error(errMsg); + String errMsg = "Input JSON objects (finalSummaryObj or srcSummaryObj) are null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // merge modules JSONArray finalModuleObs = finalSummaryObj.getJSONArray(MODULES); JSONArray srcModuleObs = srcSummaryObj.getJSONArray(MODULES); if (finalModuleObs == null || srcModuleObs == null) { - String errMsg = "ModuleJsonUtil:mergePackInfoObj input json file has empty module."; - LOG.error(errMsg); + String errMsg = "Input JSON array (finalModuleObs or srcModuleObs) are null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_FAILED.toString(errMsg)); throw new BundleException(errMsg); } finalModuleObs.addAll(srcModuleObs); @@ -685,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 = "Input JSON array (finalPackageObs or srcPackageObs) are null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_FAILED.toString(errMsg)); throw new BundleException(errMsg); } finalPackageObs.addAll(srcPackageObs); @@ -710,8 +728,8 @@ class ModuleJsonUtil { finalPackObj = JSON.parseObject(finalPackInfo); srcPackObj = JSON.parseObject(srcPackInfo); } catch (JSONException exception) { - String errMsg = "parse JSONObject failed: " + exception.getMessage(); - LOG.error(errMsg); + String errMsg = "Merge two pack.info exist JSONException: " + exception.getMessage(); + LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // verify app in pack.info @@ -720,8 +738,8 @@ class ModuleJsonUtil { JSONObject srcSummaryObj = srcPackObj.getJSONObject(SUMMARY); JSONObject srcAppObj = srcSummaryObj.getJSONObject(APP); if (!verifyAppInPackInfo(finalAppObj, srcAppObj)) { - String errMsg = "verify pack.info failed, different version, bundleType or bundleName."; - LOG.error(errMsg); + String errMsg = "Verify pack.info failed, different version, bundleType or bundleName."; + LOG.error(PackingToolErrMsg.MERGE_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } for (HashMap.Entry entry : packagePair.entrySet()) { @@ -743,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 = "Input JSON objects (finalPackObj or srcPackObj) are null."; + LOG.error(PackingToolErrMsg.MERGE_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // merge module JSONObject finalSummaryObj = finalPackObj.getJSONObject(SUMMARY); JSONObject srcSummaryObj = srcPackObj.getJSONObject(SUMMARY); if (finalSummaryObj == null || srcSummaryObj == null) { - String errMsg = "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair failed: pack.info do not contain summary."; - LOG.error(errMsg); + String errMsg = "Input JSON objects (finalSummaryObj or srcSummaryObj) are null."; + LOG.error(PackingToolErrMsg.MERGE_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } JSONArray finalModules = finalSummaryObj.getJSONArray(MODULES); JSONArray srcModules = srcSummaryObj.getJSONArray(MODULES); if (finalModules == null || srcModules == null) { - LOG.error("ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair input json file has empty module."); + String errMsg = "Input JSON Array (finalModules or srcModules) are null."; + LOG.error(PackingToolErrMsg.MERGE_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException("ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair input json file has empty module."); } @@ -773,18 +792,16 @@ class ModuleJsonUtil { } } if (!findModule) { - String errMsg = "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair" + - " input json do not contain " + moduleName + "."; - LOG.error(errMsg); + String errMsg = "Input json does not contain " + moduleName + "."; + LOG.error(PackingToolErrMsg.MERGE_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // merge package JSONArray finalPackages = finalPackObj.getJSONArray(PACKAGES); JSONArray srcPackages = srcPackObj.getJSONArray(PACKAGES); if (finalPackages == null || srcPackages == null) { - String errMsg = - "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair failed: pack.info do not contain packages."; - LOG.error(errMsg); + String errMsg = "Input JSON Array (finalPackages or srcPackages) are null."; + LOG.error(PackingToolErrMsg.MERGE_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } boolean findPackage = false; @@ -797,9 +814,8 @@ class ModuleJsonUtil { } } if (!findPackage) { - String errMsg = "ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair input json do not contain " - + packageName + "."; - LOG.error(errMsg); + String errMsg = "Input json does not contain " + packageName + "."; + LOG.error(PackingToolErrMsg.MERGE_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } } @@ -1350,8 +1366,8 @@ class ModuleJsonUtil { return APP; } else if (bundleType.equals(ATOMIC_SERVICE)) { if (!installationFree) { - String errMsg = "'installationFree' must be true in module '" + moduleName + - "' when 'bundleType' is atomicService."; + String errMsg = "'installationFree' must be true in module '" + moduleName + + "' when 'bundleType' is atomicService."; String solution = "Set 'installationFree' to true in the module.json when 'bundleType'" + "is atomicService."; LOG.error(PackingToolErrMsg.PARSE_STAGE_BUNDLE_TYPE_FAILED.toString(errMsg, solution)); @@ -2084,20 +2100,20 @@ class ModuleJsonUtil { String name = formObj.getString(NAME); formNameList.add(name); if (!formObj.containsKey(DEFAULTDIMENSION)) { - LOG.error("ModuleJsonUtil::parsePackInfoForms exception: " + - "summary.modules.extensionAbilities.forms.defaultDimension is null."); + String errMsg = "formObj object does not contain defaultDimension."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_FAILED.toString(errMsg)); throw new BundleException("Parse pack info defaultDimension failed, defaultDimension is null."); } String defaultDimension = formObj.getString(DEFAULTDIMENSION); if (getCount(defaultDimension, '*') != 1) { - LOG.error("ModuleJsonUtil::parsePackInfoForms exception: " + - "summary.modules.extensionAbilities.forms.defaultDimension is not only 1."); + String errMsg = "summary.modules.extensionAbilities.forms.defaultDimension is not only 1."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_FAILED.toString(errMsg)); throw new BundleException("Parse pack info defaultDimension failed, defaultDimension is not only 1."); } if (!formObj.containsKey(SUPPORTDIMENSIONS)) { - LOG.error("ModuleJsonUtil::parsePackInfoForms exception: " + - "summary.modules.extensionAbilities.forms.supportDimensions is null."); + String errMsg = "formObj object does not contain supportDimensions."; + LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_FAILED.toString(errMsg)); throw new BundleException("Parse pack info supportDimensions failed, supportDimensions is null."); } diff --git a/adapter/ohos/PackageNormalize.java b/adapter/ohos/PackageNormalize.java index 5bca1f85..31a7e3bf 100644 --- a/adapter/ohos/PackageNormalize.java +++ b/adapter/ohos/PackageNormalize.java @@ -70,10 +70,12 @@ public class PackageNormalize { try { normalize(Paths.get(hspPath), outPath, utility.getBundleName(), utility.getVersionCode()); } catch (BundleException ex) { - LOG.error("PackageNormalize::normalize BundleException: " + ex.getMessage()); + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_FAILED.toString( + "Package normalize exist BundleException:" + ex.getMessage())); return false; } catch (IOException ex) { - LOG.error("PackageNormalize::normalize IOException: " + ex.getMessage()); + LOG.error(PackingToolErrMsg.PACKAGE_NORMALIZE_FAILED.toString( + "Package normalize exist IOException:" + ex.getMessage())); return false; } } @@ -135,11 +137,13 @@ public class PackageNormalize { try (FileInputStream input = new FileInputStream(moduleJson.toFile())) { JSONObject jsonObject = JSON.parseObject(input, JSONObject.class); if (jsonObject == null) { - LOG.error("updateModuleJson failed, parse json is null."); + LOG.error(PackingToolErrMsg.UPDATE_MODULE_JSON_FAILED.toString( + "Failed to parse module.json: invalid JSON format.")); throw new BundleException("updateModuleJson failed, parse json is null."); } if (!jsonObject.containsKey(APP)) { - LOG.error("updateModuleJson failed, json format not invalid."); + LOG.error(PackingToolErrMsg.UPDATE_MODULE_JSON_FAILED.toString( + "The module.json file does not contain 'app'.")); throw new BundleException("updateModuleJson failed, json format invalid."); } JSONObject appObject = jsonObject.getJSONObject(APP); @@ -156,23 +160,27 @@ public class PackageNormalize { try (FileInputStream input = new FileInputStream(packInfo.toFile())) { JSONObject jsonObject = JSON.parseObject(input, JSONObject.class); if (jsonObject == null) { - LOG.error("updatePackInfo failed, json format invalid."); + LOG.error(PackingToolErrMsg.UPDATE_PACKINFO_FAILED.toString( + "Failed to parse pack.info: Invalid JSON format.")); throw new BundleException("updatePackInfo failed, json format invalid."); } JSONObject summaryObject = jsonObject.getJSONObject(SUMMARY); if (summaryObject == null) { - LOG.error("updatePackInfo failed, json format invalid."); + LOG.error(PackingToolErrMsg.UPDATE_PACKINFO_FAILED.toString( + "The pack.info file does not contain 'summary'.")); throw new BundleException("updatePackInfo failed, json format invalid."); } JSONObject appObject = summaryObject.getJSONObject(APP); if (appObject == null) { - LOG.error("updatePackInfo failed, json format invalid."); + LOG.error(PackingToolErrMsg.UPDATE_PACKINFO_FAILED.toString( + "The pack.info file does not contain 'app'.")); throw new BundleException("updatePackInfo failed, json format invalid."); } appObject.put(BUNDLE_NAME, bundleName); JSONObject versionObject = appObject.getJSONObject(VERSION); if (versionObject == null) { - LOG.error("updatePackInfo failed, json format invalid."); + LOG.error(PackingToolErrMsg.UPDATE_PACKINFO_FAILED.toString( + "The pack.info file does not contain 'version'.")); throw new BundleException("updatePackInfo failed, json format invalid."); } versionObject.put(CODE, versionCode); @@ -242,10 +250,12 @@ public class PackageNormalize { count = fileInputStream.read(buffer); } } catch (FileNotFoundException ignored) { - LOG.error("PackageNormalize::getCrcFromFile file not found exception: " + ignored.getMessage()); + LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString( + "Get Crc from file exist FileNotFoundExpection: " + ignored.getMessage())); throw new BundleException("Get Crc from file failed."); } catch (IOException exception) { - LOG.error("PackageNormalize::getCrcFromFile io exception: " + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "Get Crc from file exist IOException: " + exception.getMessage())); throw new BundleException("Get Crc from file failed, io exception."); } return crc; diff --git a/adapter/ohos/PackageUtil.java b/adapter/ohos/PackageUtil.java index 0e565002..2f5a6d5c 100644 --- a/adapter/ohos/PackageUtil.java +++ b/adapter/ohos/PackageUtil.java @@ -356,7 +356,8 @@ public class PackageUtil { try { return hspFile.getInputStream(zipEntry); } catch (IOException e) { - LOG.error("addArchiveEntry err: " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Repack hsp exist IOException: " + + e.getMessage())); return null; } }; @@ -364,8 +365,9 @@ public class PackageUtil { } zipCreator.writeTo(zipOut); } catch (InterruptedException | ExecutionException e) { - String errMsg = "repackHsp err: " + e.getMessage(); - LOG.error(errMsg); + String errMsg = "Repack hsp exist Exception (InterruptedException | ExecutionException): " + + e.getMessage(); + LOG.error(PackingToolErrMsg.INTERRUPTED_OR_EXECUTION_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } return outHsp; @@ -435,8 +437,8 @@ public class PackageUtil { // write to zip zipCreator.writeTo(zipOut); } catch (InterruptedException | ExecutionException e) { - String errMsg = "packDir err: " + e.getMessage(); - LOG.error(errMsg); + String errMsg = "Pack dir exist Exception (InterruptedException | ExecutionException): " + e.getMessage(); + LOG.error(PackingToolErrMsg.INTERRUPTED_OR_EXECUTION_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } return outHap; @@ -509,8 +511,8 @@ public class PackageUtil { addArchiveEntry(file, baseDir, zipCreator, compress); } } catch (IOException e) { - String errMsg = "pathToZip err: " + e.getMessage(); - LOG.error(errMsg); + String errMsg = "Path to zip entry exist IOException: " + e.getMessage(); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } } @@ -521,7 +523,7 @@ public class PackageUtil { if (file.isDirectory()) { File[] files = file.listFiles(); if (files == null) { - LOG.error("listFiles null: " + file.getName()); + LOG.error(PackingToolErrMsg.ADD_ARCHIVE_ENTRY_FAILED.toString("listFiles null: " + file.getName())); return; } if (files.length == 0) { @@ -549,7 +551,8 @@ public class PackageUtil { try { return getInputStream(entryName, file); } catch (IOException e) { - LOG.error("addArchiveEntry err: " + e.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Add Archive Entry exist IOException: " + + e.getMessage())); return null; } }; @@ -646,8 +649,8 @@ public class PackageUtil { addArchiveEntry(file, baseDir, zipOut, compress); } } catch (IOException e) { - String errMsg = "pathToZip err: " + e.getMessage(); - LOG.error(errMsg); + String errMsg = "Path to zip entry exist IOException: " + e.getMessage(); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } } @@ -657,7 +660,7 @@ public class PackageUtil { if (file.isDirectory()) { File[] files = file.listFiles(); if (files == null) { - LOG.error("listFiles null: " + file.getName()); + LOG.error(PackingToolErrMsg.ADD_ARCHIVE_ENTRY_FAILED.toString("listFiles null: " + file.getName())); return; } if (files.length == 0) { @@ -705,13 +708,13 @@ public class PackageUtil { } for (String hapPath : hapPathList) { if (!bundleType.equals(getBundleTypeFromPath(Paths.get(hapPath)))) { - LOG.error("bundleType is not same"); + LOG.error(PackingToolErrMsg.CHECK_BUNDLE_TYPE_CONSISTENCY.toString("Hap bundle type is not same")); return false; } } for (String hspPath : hspPathList) { if (!bundleType.equals(getBundleTypeFromPath(Paths.get(hspPath)))) { - LOG.error("bundleType is not same"); + LOG.error(PackingToolErrMsg.CHECK_BUNDLE_TYPE_CONSISTENCY.toString("Hsp bundle type is not same")); return false; } } @@ -725,11 +728,11 @@ public class PackageUtil { for (String hapPath : hapPathList) { Path path = Paths.get(hapPath); if (!Files.exists(path.resolve(Constants.FILE_MODULE_JSON))) { - LOG.error("not found module.json in path: " + path); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found module.json in hap path: " + path)); return false; } if (!Files.exists(path.resolve(Constants.FILE_PACK_INFO))) { - LOG.error("not found pack.info in path: " + path); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found pack.info in hap path: " + path)); return false; } } @@ -737,11 +740,11 @@ public class PackageUtil { Path path = Paths.get(hspPath); if (Files.isDirectory(path)) { if (!Files.exists(path.resolve(Constants.FILE_MODULE_JSON))) { - LOG.error("not found module.json in path: " + path); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found module.json in hsp path: " + path)); return false; } if (!Files.exists(path.resolve(Constants.FILE_PACK_INFO))) { - LOG.error("not found pack.info in path: " + path); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found pack.info in hsp path: " + path)); return false; } } @@ -771,45 +774,46 @@ public class PackageUtil { if (!utility.getHapPath().isEmpty() && (!isFormatPathValid(utility.getHapPath(), utility.getFormattedHapPathList()) || !isHapPathValid(utility.getFormattedHapPathList()))) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode hap-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--hap-path is invalid.")); return false; } if (!utility.getHspPath().isEmpty() && (!isFormatPathValid(utility.getHspPath(), utility.getFormattedHspPathList()) || !isHspPathValid(utility.getFormattedHspPathList()))) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode hsp-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--hsp-path is invalid.")); return false; } if (utility.getHapPath().isEmpty() && utility.getHspPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode hap-path and hsp-path is empty."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--hap-path and --hsp-path is empty.")); return false; } if (!moduleJsonAndPackInfoExists(utility.getFormattedHapPathList(), utility.getFormattedHspPathList())) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode hap-path or hsp-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--hap-path or --hsp-path is invalid.")); return false; } if (!checkBundleTypeConsistency( utility.getFormattedHapPathList(), utility.getFormattedHspPathList(), utility)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode bundleType is inconsistent."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("Bundle type is inconsistent.")); return false; } if (!isPackInfoValid(Paths.get(utility.getPackInfoPath()), utility.getFormattedHapPathList(), utility.getFormattedHspPathList())) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode pack.info is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("pack.info is invalid.")); return false; } if (!utility.getEncryptPath().isEmpty() && !isFileValid(utility.getEncryptPath(), Constants.FILE_ENCRYPT_JSON)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode encrypt-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--encrypt-path is invalid.")); return false; } Path outPath = Paths.get(utility.getOutPath()); if (utility.getForceRewrite().equals(Constants.FALSE) && Files.exists(outPath)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode out file already existed."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--out-path file already existed, but " + + "--force is 'false'.")); return false; } if (!outPath.getFileName().toString().endsWith(Constants.APP_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode out-path must end with .app."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--out-path must end with .app.")); return false; } return true; @@ -817,34 +821,34 @@ public class PackageUtil { private static boolean isVerifyValid(Utility utility) { if (utility.getPackInfoPath().isEmpty()) { - LOG.error("CompressVerify::isArgsValidInAppMode pack-info-path is empty."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--pack-info-path is empty.")); return false; } if (!isFileValid(utility.getPackInfoPath(), Constants.FILE_PACK_INFO)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode pack-info-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--pack-info-path is invalid.")); return false; } if (!utility.getSignaturePath().isEmpty() && !isFileValid(utility.getSignaturePath(), "")) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode signature-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--signature-path is invalid.")); return false; } if (!utility.getCertificatePath().isEmpty() && !isFileValid(utility.getCertificatePath(), "")) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode certificate-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--certificate-path is invalid.")); return false; } if (!utility.getPackResPath().isEmpty() && !isFileValid(utility.getPackResPath(), Constants.FILE_PACK_RES)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode pack-res-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--pack-res-path is invalid.")); return false; } if (!utility.getEntryCardPath().isEmpty() && !CompressVerify.compatibleProcess(utility, utility.getEntryCardPath(), utility.getformattedEntryCardPathList(), Constants.PNG_SUFFIX)) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode entrycard-path is invalid."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--entrycard-path is invalid.")); return false; } if (utility.getOutPath().isEmpty()) { - LOG.error("CompressVerify::isVerifyValidInFastAppMode out-path is empty."); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--out-path is empty.")); return false; } return true; @@ -876,11 +880,12 @@ public class PackageUtil { if (Files.exists(realpath)) { formatPathSet.add(realpath.toString()); } else { - LOG.error("PackageUtil::formatPath not exists: " + realpath); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Format path not exists. Path: " + realpath)); return false; } } catch (IOException ex) { - LOG.error("PackageUtil::formatPath err: " + ex.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Format path exist IOException: " + + ex.getMessage())); return false; } } @@ -892,27 +897,29 @@ public class PackageUtil { List allPackages = getPackageNameFromPath(packInfo); Set allPackageSet = new HashSet<>(allPackages); if (allPackages.size() > allPackageSet.size()) { - LOG.error("package name is redundant in app pack.info: " + packInfo); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Package name is redundant in app pack.info: " + + packInfo)); return false; } if (allPackages.isEmpty()) { - LOG.error("app pack.info format err: " + packInfo); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("App pack.info format error: " + packInfo)); return false; } Set packages = new HashSet<>(); for (String hapPath : hapPathList) { List list = getPackageNameFromPath(Paths.get(hapPath)); if (list.size() != 1) { - LOG.error("module pack.info format err: " + hapPath); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info format error: " + hapPath)); return false; } String packageName = list.get(0); if (!allPackages.contains(packageName)) { - LOG.error("module pack.info name not exist in app pack.info name list: " + hapPath); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info name not exist in app " + + "pack.info name list: " + hapPath)); return false; } if (packages.contains(packageName)) { - LOG.error("package name is redundant in " + hapPath); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Package name is redundant in " + hapPath)); return false; } packages.add(packageName); @@ -920,22 +927,24 @@ public class PackageUtil { for (String hspPath : hspPathList) { List list = getPackageNameFromPath(Paths.get(hspPath)); if (list.size() != 1) { - LOG.error("module pack.info format err: " + hspPath); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info format err: " + hspPath)); return false; } String packageName = list.get(0); if (!allPackages.contains(packageName)) { - LOG.error("module pack.info name not exist in app pack.info name list: " + hspPath); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info name not exist in app " + + "pack.info name list: " + hspPath)); return false; } if (packages.contains(packageName)) { - LOG.error("package name is redundant in " + hspPath); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Package name is redundant in " + hspPath)); return false; } packages.add(packageName); } if (!allPackageSet.equals(packages)) { - LOG.error("package name not same between module and app pack.info."); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Package name not same between module " + + "and app pack.info.")); return false; } return true; diff --git a/adapter/ohos/PackingToolErrMsg.java b/adapter/ohos/PackingToolErrMsg.java index 29fbbc76..7b49a716 100644 --- a/adapter/ohos/PackingToolErrMsg.java +++ b/adapter/ohos/PackingToolErrMsg.java @@ -85,6 +85,76 @@ public class PackingToolErrMsg { .setCause("%s") .build(); + /** + * MULTI_APP_MODE_ARGS_INVALID + */ + public static final ErrorMsg MULTI_APP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("004") + .setDescription("Parse and check args invalid in multiApp mode.") + .setCause("%s") + .build(); + + /** + * RES_MODE_ARGS_INVALID + */ + public static final ErrorMsg RES_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("005") + .setDescription("Parse and check args invalid in res mode.") + .setCause("%s") + .build(); + + /** + * HQF_MODE_ARGS_INVALID + */ + public static final ErrorMsg HQF_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("006") + .setDescription("Parse and check args invalid in hqf mode.") + .setCause("%s") + .build(); + + /** + * APPQF_MODE_ARGS_INVALID + */ + public static final ErrorMsg APPQF_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("007") + .setDescription("Parse and check args invalid in appqf mode.") + .setCause("%s") + .build(); + + /** + * PACKAGE_NORMALIZE_MODE_ARGS_INVALID + */ + public static final ErrorMsg PACKAGE_NORMALIZE_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("008") + .setDescription("Parse and check args invalid in packageNormalize mode.") + .setCause("%s") + .build(); + + /** + * VERSION_NORMALIZE_MODE_ARGS_INVALID + */ + public static final ErrorMsg VERSION_NORMALIZE_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("009") + .setDescription("Parse and check args invalid in versionNormalize mode.") + .setCause("%s") + .build(); + + /** + * HAR_MODE_ARGS_INVALID + */ + public static final ErrorMsg HAR_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("010") + .setDescription("Parse and check args invalid in har mode.") + .setCause("%s") + .build(); + /** * COMMAND_MODE_INVALID */ @@ -165,6 +235,67 @@ public class PackingToolErrMsg { .setCause("%s") .build(); + /** + * DIRECTORY_INVALID + */ + public static final ErrorMsg DIRECTORY_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("019") + .setDescription("directory is not exist.") + .setCause("%s") + .build(); + + /** + * HAP_ADDITION_MODE_ARGS_INVALID + */ + public static final ErrorMsg HAP_ADDITION_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("020") + .setDescription("Parse and check args invalid in hapAddition mode.") + .setCause("%s") + .build(); + + /** + * INPUT_PATH_INVALID + */ + public static final ErrorMsg INPUT_PATH_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("021") + .setDescription("input_path is invalid.") + .setCause("%s") + .build(); + + /** + * CHECK_BUNDLE_TYPE_CONSISTENCY + */ + public static final ErrorMsg CHECK_BUNDLE_TYPE_CONSISTENCY = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("022") + .setDescription("Checking bundle type consistency failed.") + .setCause("%s") + .build(); + + /** + * CHECK_BUNDLE_TYPE_CONSISTENCY + */ + public static final ErrorMsg FAST_APP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("023") + .setDescription("Parse and check args invalid in fast app mode.") + .setCause("%s") + .build(); + + /** + * PACK_INFO_INVALID + */ + public static final ErrorMsg PACK_INFO_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("11") + .setErrCode("024") + .setDescription("Pack info invalid.") + .setCause("%s") + .build(); + + // compress process error /** * COMPRESS_PROCESS_FAILED @@ -432,6 +563,278 @@ public class PackingToolErrMsg { .addSolution("Please check the related size check error message and reduce related module size.") .build(); + /** + * COMPRESS_APP_MODE_FORMULTI_PROJECT_FAILED + */ + public static final ErrorMsg COMPRESS_APP_MODE_FORMULTI_PROJECT_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("025") + .setDescription("Compress app mode for multi project failed.") + .setCause("%s") + .build(); + + /** + * HAP_ADDITION_FAILED + */ + public static final ErrorMsg HAP_ADDITION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("026") + .setDescription("Hap addition failed.") + .setCause("%s") + .build(); + + /** + * COMPRESS_HAP_ADDITION_FAILED + */ + public static final ErrorMsg COMPRESS_HAP_ADDITION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("027") + .setDescription("Compress hap addition failed.") + .setCause("%s") + .build(); + + /** + * DISPOSE_APP_FAILED + */ + public static final ErrorMsg DISPOSE_APP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("028") + .setDescription("Dispose app failed.") + .setCause("%s") + .build(); + + /** + * NO_PACK_INFO + */ + public static final ErrorMsg NO_PACK_INFO = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("029") + .setDescription("No pack.info available.") + .setCause("%s") + .build(); + + /** + * COMPRESS_PACK_RES_MODE_FAILED + */ + public static final ErrorMsg COMPRESS_PACK_RES_MODE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("030") + .setDescription("Compress pack res mode failed.") + .setCause("%s") + .build(); + + /** + * INVALID_THIRD_LEVEL_DIRECTORY_NAME + */ + public static final ErrorMsg INVALID_THIRD_LEVEL_DIRECTORY_NAME = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("031") + .setDescription("Invalid third level directory name.") + .setCause("%s") + .addSolution("Please check it with reference to this example: \n" + + "zh_Hani_CN-vertical-car-mdpi-dark or zh_Hani_CN-vertical-car-mdpi.") + .build(); + + /** + * IS_PICTURING_FAILED + */ + public static final ErrorMsg IS_PICTURING_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("032") + .setDescription("Is picturing failed.") + .setCause("%s") + .build(); + + /** + * GET_FILE_LIST_FAILED + */ + public static final ErrorMsg GET_FILE_LIST_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("033") + .setDescription("Get file list failed.") + .setCause("%s") + .build(); + + /** + * GET_MODULE_NAME_FROM_STRING_FAILED + */ + public static final ErrorMsg GET_MODULE_NAME_FROM_STRING_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("034") + .setDescription("Get module name from line string failed.") + .setCause("%s") + .build(); + + /** + * COMPRESS_APPQF_FAILED + */ + public static final ErrorMsg COMPRESS_APPQF_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("035") + .setDescription("Compress appqf Mode failed.") + .setCause("%s") + .build(); + + /** + * CHECK_HQF_INVALID + */ + public static final ErrorMsg CHECK_HQF_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("036") + .setDescription("HQF is valid.") + .setCause("%s") + .build(); + + /** + * VERSION_NORMALIZE_FAILED + */ + public static final ErrorMsg VERSION_NORMALIZE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("037") + .setDescription("Version normalize failed.") + .setCause("%s") + .build(); + + /** + * VERIFY_MODULE_VERSION_FAILED + */ + public static final ErrorMsg VERIFY_MODULE_VERSION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("038") + .setDescription("Verify module version failed.") + .setCause("%s") + .build(); + + /** + * CHECK_SUM_FAILED + */ + public static final ErrorMsg CHECK_SUM_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("039") + .setDescription("Check sum failed.") + .setCause("%s") + .build(); + + /** + * MERGE_TWO_PACKINFO_FAILED + */ + public static final ErrorMsg MERGE_TWO_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("040") + .setDescription("Merge two pack info failed.") + .setCause("%s") + .build(); + + /** + * VERIFY_PACKINFO_FAILED + */ + public static final ErrorMsg VERIFY_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("041") + .setDescription("Verify pack info failed.") + .setCause("%s") + .build(); + + /** + * VERIFY_APP_PACKINFO_FAILED + */ + public static final ErrorMsg VERIFY_APP_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("042") + .setDescription("Verify app pack info failed.") + .setCause("%s") + .build(); + + /** + * BUNDLE_TYPE_PACKINFO_INVALID + */ + public static final ErrorMsg BUNDLE_TYPE_PACKINFO_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("043") + .setDescription("Invalid bundle type in pack info.") + .setCause("%s") + .build(); + + /** + * PARSE_PACKINFO_FORMS_NAME_FAILED + */ + public static final ErrorMsg PARSE_PACKINFO_FORMS_NAME_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("044") + .setDescription("Parse pack info forms name error.") + .setCause("%s") + .build(); + + /** + * MERGE_PACKINFO_OBJ_FAILED + */ + public static final ErrorMsg MERGE_PACKINFO_OBJ_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("045") + .setDescription("Failed to merge package information object.") + .setCause("%s") + .build(); + + /** + * MERGE_BY_PACKAGE_PAIR_FAILED + */ + public static final ErrorMsg MERGE_BY_PACKAGE_PAIR_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("046") + .setDescription("Failed to merge two pack.info files into one pack.info file through packagePair.") + .setCause("%s") + .build(); + + /** + * MERGE_OBJBY_PACKAGE_PAIR_FAILED + */ + public static final ErrorMsg MERGE_OBJ_BY_PACKAGE_PAIR_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("047") + .setDescription("Failed to merge two pack.info objects into one pack.info through packagePair.") + .setCause("%s") + .build(); + + /** + * PARSE_PACKINFO_FORMS_FAILED + */ + public static final ErrorMsg PARSE_PACKINFO_FORMS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("048") + .setDescription("Failed to parse package information form.") + .setCause("%s") + .build(); + + /** + * INTERRUPTED_OR_EXECUTION_EXCEPTION + */ + public static final ErrorMsg INTERRUPTED_OR_EXECUTION_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("049") + .setDescription("Exists interrupted or execution exception.") + .setCause("%s") + .build(); + + /** + * ADD_ARCHIVE_ENTRY_FAILED + */ + public static final ErrorMsg ADD_ARCHIVE_ENTRY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("050") + .setDescription("Add archive entry failed.") + .setCause("%s") + .build(); + + /** + * COMPRESS_FAST_APP_FAILED + */ + public static final ErrorMsg COMPRESS_FAST_APP_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("051") + .setDescription("Compress fast app file failed.") + .setCause("%s") + .build(); + // module json check error /** * PARSE_JSON_OBJECT_EXCEPTION @@ -670,6 +1073,60 @@ public class PackingToolErrMsg { .addSolution("Verify you have the necessary permissions to delete the file.") .build(); + /** + * DIR_CREATION_FAILED + */ + public static final ErrorMsg DIR_CREATION_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("010") + .setDescription("Directory creation failed exception.") + .setCause("%s") + .addSolution("Please check the following:\n" + + "1. Please check the directory path and ensure that the parent " + + "directories exist and are accessible.\n" + + "2. Ensure that you have the necessary permissions to create directories.") + .build(); + + /** + * COMPRESS_FILE_DUPLICATE + */ + public static final ErrorMsg COMPRESS_FILE_DUPLICATE = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("011") + .setDescription("File duplicated.") + .setCause("%s") + .build(); + + /** + * COPY_FILE_SAFELY_FAILED + */ + public static final ErrorMsg COPY_FILE_SAFELY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("012") + .setDescription("Copy file safely failed.") + .setCause("%s") + .build(); + + /** + * COPY_FILE_FAILED + */ + public static final ErrorMsg COPY_FILE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("013") + .setDescription("Copy file failed.") + .setCause("%s") + .build(); + + /** + * MAKE_DIR_FAILED + */ + public static final ErrorMsg MAKE_DIR_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("14") + .setErrCode("014") + .setDescription("Make dir failed.") + .setCause("%s") + .build(); + // io exception /** * IO_EXCEPTION @@ -906,4 +1363,55 @@ public class PackingToolErrMsg { .addSolution("Ensure the Entry type module distributionFilter file policy " + "settings is 'exclude' or 'include'.") .build(); + + /** + * CHECK_APP_FIELDS_FAILED + */ + public static final ErrorMsg CHECK_APP_FIELDS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("020") + .setDescription("Check app fields is failed.") + .setCause("%s") + .build(); + + /** + * CHECK_MODULE_INVALID + */ + public static final ErrorMsg CHECK_MODULE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("16") + .setErrCode("021") + .setDescription("Check module is invalid.") + .setCause("%s") + .build(); + + // package normalize error + /** + * PACKAGE_NORMALIZE_FAILED + */ + public static final ErrorMsg PACKAGE_NORMALIZE_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("17") + .setErrCode("001") + .setDescription("Normalize HSP bundleName and versionCode failed.") + .setCause("%s") + .build(); + + /** + * UPDATE_MODULE_JSON_FAILED + */ + public static final ErrorMsg UPDATE_MODULE_JSON_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("17") + .setErrCode("002") + .setDescription("Update module.json failed.") + .setCause("%s") + .build(); + + /** + * UPDATE_PACKINFO_FAILED + */ + public static final ErrorMsg UPDATE_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("17") + .setErrCode("003") + .setDescription("Update pack.info failed.") + .setCause("%s") + .build(); } diff --git a/adapter/ohos/Utility.java b/adapter/ohos/Utility.java index 496930ca..81bf9967 100644 --- a/adapter/ohos/Utility.java +++ b/adapter/ohos/Utility.java @@ -706,7 +706,8 @@ public class Utility { canonicalPath = file.getCanonicalPath(); } catch (IOException exception) { canonicalPath = INVALID_PATH; - LOG.error("Utility::getFormattedPath exception," + exception.getMessage()); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( + "Get formatted path exist IOException: " + exception.getMessage())); } return canonicalPath; } -- Gitee From 536c7f741ec4627d952cc81c839ea51b39940d0f Mon Sep 17 00:00:00 2001 From: nj1868 Date: Thu, 13 Mar 2025 21:57:57 +0800 Subject: [PATCH 3/3] add errcode v1 Signed-off-by: nj1868 Change-Id: I9c1695f6dc2305bddeb9664c02e94f8673471458 --- adapter/ohos/CompressVerify.java | 10 +- adapter/ohos/Compressor.java | 94 ++++----- adapter/ohos/HQFVerify.java | 2 +- adapter/ohos/ModuleJsonUtil.java | 70 +++---- adapter/ohos/PackageNormalize.java | 6 +- adapter/ohos/PackageUtil.java | 56 ++--- adapter/ohos/PackingToolErrMsg.java | 315 ++++++++++++++-------------- 7 files changed, 277 insertions(+), 276 deletions(-) diff --git a/adapter/ohos/CompressVerify.java b/adapter/ohos/CompressVerify.java index 20ec4c3f..ddbd5f68 100644 --- a/adapter/ohos/CompressVerify.java +++ b/adapter/ohos/CompressVerify.java @@ -468,7 +468,7 @@ public class CompressVerify { if (!isPathValid(utility.getJsonPath(), TYPE_FILE, JSON_PROFILE) && !isPathValid(utility.getJsonPath(), TYPE_FILE, MODULE_PROFILE)) { - String errMsg = "--json-path must be config.json file."; + String errMsg = "--json-path must be config.json or module.json file."; LOG.error(PackingToolErrMsg.HAR_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -651,7 +651,7 @@ public class CompressVerify { */ private static boolean isVerifyValidInMultiAppMode(Utility utility) { if (utility.getAppList().isEmpty() && utility.getHapList().isEmpty() && utility.getHspList().isEmpty()) { - String errMsg = "Input --app-list, --hap-list and --hsp-list are empty."; + String errMsg = "Input --app-list, --hap-list and --hsp-list are all empty."; LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -760,7 +760,7 @@ public class CompressVerify { } File outFile = new File(utility.getOutPath()); if ((FALSE.equals(utility.getForceRewrite())) && (outFile.exists())) { - String errMsg = outFile.getName() + " already exist."; + String errMsg = outFile.getName() + " already exist, but --force is 'false'."; LOG.error(PackingToolErrMsg.HQF_MODE_ARGS_INVALID.toString(errMsg)); return false; } @@ -856,7 +856,7 @@ public class CompressVerify { if (!isPathValid(formattedPathItem, TYPE_FILE, HSP_SUFFIX) && !isPathValid(formattedPathItem, TYPE_FILE, HAP_SUFFIX)) { String errMsg = "Input file " + formattedPathItem + " is invalid"; - LOG.error(PackingToolErrMsg.INPUT_PATH_INVALID.toString(errMsg)); + LOG.error(PackingToolErrMsg.HANDLE_HAP_HSP_INPUT_FAILED.toString(errMsg)); return false; } fileList.add(formattedPathItem); @@ -967,7 +967,7 @@ public class CompressVerify { File file = new File(path); if (!file.exists()) { String errMsg = "The directory does not exist, directory path is: " + path + "."; - LOG.error(PackingToolErrMsg.DIRECTORY_INVALID.toString(errMsg)); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString(errMsg)); return false; } if (file.isDirectory()) { diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index ac285d7b..afb1e8dc 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -535,7 +535,7 @@ public class Compressor { throw new BundleException("Verify has generate build hash failed."); } catch (JSONException | IOException e) { LOG.error(PackingToolErrMsg.HAS_GENERATE_BUILD_HASH.toString( - "Verify has generate build hash exist Exception (JSONException | IOException): " + e.getMessage())); + "Verify has generate build hash exist Exception(JSONException | IOException): " + e.getMessage())); throw new BundleException("Verify has generate build hash failed."); } finally { FileUtils.closeStream(json); @@ -587,7 +587,8 @@ public class Compressor { throw new BundleException("Compressor::setGenerateBuildHash failed."); } catch (NullPointerException | IOException | JSONException e) { LOG.error(PackingToolErrMsg.SET_GENERATE_BUILD_HASH.toString( - "json data err, exist Exception (NullPointerException | IOException | JSONException): " + e.getMessage())); + "json data err, exist Exception(NullPointerException | IOException | JSONException): " + + e.getMessage())); throw new BundleException("Set generate build hash failed, json data err."); } finally { FileUtils.closeStream(json); @@ -672,8 +673,7 @@ public class Compressor { } while (numRead != -1); return complete.digest(); } catch (IOException | NoSuchAlgorithmException e) { - LOG.error(PackingToolErrMsg.CHECK_SUM_FAILED.toString("Check sum exist Exception (IOException | " - + "NoSuchAlgorithmException): " + e.getMessage())); + LOG.error("Compressor::checkSum failed, IOException or NoSuchAlgorithmException: " + e.getMessage()); throw new BundleException("Compressor::checkSum failed."); } } @@ -1338,14 +1338,15 @@ public class Compressor { } // check hap is valid if (!checkHapIsValid(fileList, utility.getSharedApp())) { - throw new BundleException("Compress file verify hap failed, check version, " - + "apiVersion, moduleName, packageName."); + String msg = "Compressor::checkHapIsValid verify failed, check version, " + + "apiVersion, moduleName, packageName."; + LOG.error(msg); + throw new BundleException(msg); } // packApp packFastApp(utility, fileList); } catch (IOException ex) { - LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Compress fast app mode exist IOException: " - + ex.getMessage())); + LOG.error("Compressor::compressAppMode compress failed: " + ex.getMessage()); throw new BundleException("Compressor::compressAppMode compress failed."); } finally { if (tmpDir != null) { @@ -1476,8 +1477,7 @@ public class Compressor { compressHapAddition(utility, hapAdditionPath); } catch (BundleException | IOException exception) { - LOG.error(PackingToolErrMsg.HAP_ADDITION_FAILED.toString("Hap addition exist Exception" + - "(BundleException | IOException): " + exception.getMessage())); + LOG.error("Compressor::HapAddition hapFile not found exception" + exception.getMessage()); copyFileSafely(backName, hapPathOri); } finally { closeZipOutputStream(); @@ -1505,8 +1505,7 @@ public class Compressor { File destFile = new File(dest); FileUtils.copyFile(sourceFile, destFile); } catch (IOException | BundleException e) { - LOG.error(PackingToolErrMsg.COPY_FILE_SAFELY_FAILED.toString("Copy file safely exist Exception" - + "(IOException | BundleException): " + e.getMessage())); + LOG.error("copyFileSafely failed: " + e.getMessage()); } } @@ -1609,9 +1608,8 @@ public class Compressor { String targetPath = targetParentPath + LINUX_FILE_SEPARATOR + ADDITION_JSON; writeJsonFile(data, targetPath); } catch (IOException | JSONException | BundleException e) { - String errMsg = "Generate addition.json file exist Exception" - + "(IOException | JSONException | BundleException): " + e.getMessage(); - LOG.error(PackingToolErrMsg.COMPRESS_HAP_ADDITION_FAILED.toString(errMsg)); + String errMsg = "Compressor::compressHapAddition generate addition.json file failed, " + e.getMessage(); + LOG.error(errMsg); throw new BundleException(errMsg); } @@ -1678,8 +1676,8 @@ public class Compressor { // rebuild pack.info String packInfoStr = FileUtils.getJsonInZips(new File(appPath), PACKINFO_NAME); if (packInfoStr.isEmpty()) { - String errorMsg = "Select hap from app find that app does not contain pack.info."; - LOG.error(PackingToolErrMsg.NO_PACK_INFO.toString(errorMsg)); + String errorMsg = "Compressor:selectHapInApp failed, app has no pack.info."; + LOG.error(errorMsg); throw new BundleException(errorMsg); } if (finalAppPackInfo.isEmpty()) { @@ -1719,8 +1717,7 @@ public class Compressor { } // copy duplicated hap to duplicated dir and get moduleName of duplicated hap if (selectedHaps.contains(zipEntry.getName())) { - LOG.error(PackingToolErrMsg.COMPRESS_FILE_DUPLICATE.toString("Hap or hsp with duplicate " - + "file names. file is " + zipEntry.getName() + ".")); + LOG.error("Compressor::copyHapFromApp file duplicated, file is " + zipEntry.getName() + "."); throw new BundleException("Compressor::copyHapFromApp file duplicated, file is " + zipEntry.getName() + "."); } else { @@ -1787,8 +1784,7 @@ public class Compressor { } for (String hapPath : utility.getFormattedHapList()) { if (seletedHaps.contains(new File(hapPath).getName())) { - LOG.error(PackingToolErrMsg.COMPRESS_FILE_DUPLICATE.toString("Hap with duplicate file names, file is " - + new File(hapPath).getName() + ".")); + LOG.error("Compressor::disposeHap file duplicated, file is " + new File(hapPath).getName() + "."); throw new BundleException("Compressor::disposeHap file duplicated, file is " + new File(hapPath).getName() + "."); } @@ -1799,8 +1795,8 @@ public class Compressor { String packInfo = FileUtils.getJsonInZips(hapFile, PACKINFO_NAME); if (packInfo.isEmpty()) { - String errMsg = "Hap does not contain a valid pack.info."; - LOG.error(PackingToolErrMsg.NO_PACK_INFO.toString(errMsg)); + String errMsg = "Compressor::disposeHap failed, hap has no pack.info."; + LOG.error(errMsg); throw new BundleException(errMsg); } if (finalPackInfoStr.isEmpty()) { @@ -3331,38 +3327,33 @@ public class Compressor { try (FileInputStream jsonStream = new FileInputStream(jsonFilePath)) { JSONObject jsonObject = JSON.parseObject(jsonStream, JSONObject.class); if (!jsonObject.containsKey(APP)) { - LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The module.json file " - + "does not contain 'app'. ")); - throw new BundleException("The module.json file does not contain 'app'. "); + LOG.error("parseAndModifyJson failed, json file not valid."); + throw new BundleException("parseAndModifyJson failed, json file not valid."); } JSONObject appObject = jsonObject.getJSONObject(APP); if (!appObject.containsKey(VERSION_CODE)) { - LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The module.json file " - + "does not contain 'versionCode'. ")); - throw new BundleException("The module.json file does not contain 'versionCode'. "); + LOG.error("parseAndModifyJson failed, json file not valid."); + throw new BundleException("parseAndModifyJson failed, json file not valid."); } if (!appObject.containsKey(VERSION_NAME)) { - LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The module.json file " - + "does not contain 'versionName'. ")); - throw new BundleException("The module.json file does not contain 'versionName'. "); + LOG.error("parseAndModifyJson failed, json file not valid."); + throw new BundleException("parseAndModifyJson failed, json file not valid."); } util.setOriginVersionCode(appObject.getIntValue(VERSION_CODE)); util.setOriginVersionName(appObject.getString(VERSION_NAME)); JSONObject moduleObject = jsonObject.getJSONObject(MODULE); if (!moduleObject.containsKey(NAME)) { - LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The module.json file " - + "does not contain 'name'. ")); - throw new BundleException("The module.json file does not contain 'name'. "); + LOG.error("parseAndModifyModuleJson failed, json file not valid."); + throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); } util.setModuleName(moduleObject.getString(NAME)); appObject.put(VERSION_CODE, utility.getVersionCode()); appObject.put(VERSION_NAME, utility.getVersionName()); writeJson(jsonFilePath, jsonObject); } catch (IOException e) { - LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Parse and modify module.json exist IOException: " - + e.getMessage())); - throw new BundleException("Parse and modify module.json exist IOException: " + e.getMessage()); + LOG.error("parseAndModifyModuleJson failed, IOException." + e.getMessage()); + throw new BundleException("parseAndModifyModuleJson failed, IOException." + e.getMessage()); } return util; } @@ -3424,35 +3415,30 @@ public class Compressor { try (FileInputStream jsonStream = new FileInputStream(jsonFilePath)) { JSONObject jsonObject = JSON.parseObject(jsonStream, JSONObject.class); if (!jsonObject.containsKey(APP)) { - LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The config.json file " - + "does not contain 'app'. ")); - throw new BundleException("The config.json file does not contain 'app'. "); + LOG.error("parseAndModifyJson failed, json file not valid."); + throw new BundleException("parseAndModifyJson failed, json file not valid."); } JSONObject appObject = jsonObject.getJSONObject(APP); if (!appObject.containsKey(VERSION)) { - LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The config.json file " - + "does not contain 'version'. ")); - throw new BundleException("The config.json file does not contain 'version'. "); + LOG.error("parseAndModifyModuleJson failed, json file not valid."); + throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); } JSONObject versionObj = appObject.getJSONObject(VERSION); if (!versionObj.containsKey(CODE)) { - LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The config.json file " - + "does not contain 'code'. ")); - throw new BundleException("The config.json file does not contain 'code'. "); + LOG.error("parseAndModifyModuleJson failed, json file not valid."); + throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); } util.setOriginVersionCode(versionObj.getIntValue(CODE)); if (!versionObj.containsKey(NAME)) { - LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The config.json file " - + "does not contain 'name'. ")); - throw new BundleException("The config.json file does not contain 'name'. "); + LOG.error("parseAndModifyModuleJson failed, json file not valid."); + throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); } util.setOriginVersionName(versionObj.getString(NAME)); JSONObject moduleObject = jsonObject.getJSONObject(MODULE); if (!moduleObject.containsKey(NAME)) { - LOG.error(PackingToolErrMsg.PARSE_JSON_OBJECT_EXCEPTION.toString("The config.json file " - + "does not contain 'name'. ")); - throw new BundleException("The config.json file does not contain 'name'. "); + LOG.error("parseAndModifyModuleJson failed, json file not valid."); + throw new BundleException("parseAndModifyModuleJson failed, json file not valid."); } util.setModuleName(moduleObject.getString(NAME)); @@ -3563,7 +3549,7 @@ public class Compressor { if (versionNormalizeUtil.getOriginVersionCode() > utility.getVersionCode()) { String errorMsg = "versionNormalize failed, module " + versionNormalizeUtil.getModuleName() + " version code less than input version code"; - LOG.error(PackingToolErrMsg.VERIFY_MODULE_VERSION_FAILED.toString(errorMsg)); + LOG.error(errorMsg); throw new BundleException(errorMsg); } else if (versionNormalizeUtil.getOriginVersionCode() == utility.getVersionCode()) { LOG.warning("versionNormalize warning: module " + diff --git a/adapter/ohos/HQFVerify.java b/adapter/ohos/HQFVerify.java index 610ea157..2576c19a 100644 --- a/adapter/ohos/HQFVerify.java +++ b/adapter/ohos/HQFVerify.java @@ -99,7 +99,7 @@ class HQFVerify { for (int i = 0; i < hqfVerifyInfos.size(); ++i) { for (int j = i + 1; j < hqfVerifyInfos.size(); ++j) { if (checkModuleIsDuplicated(hqfVerifyInfos.get(i), hqfVerifyInfos.get(j))) { - String errMsg = "Input hqf file moduleName duplicated."; + String errMsg = "Input hqf file moduleName is duplicated."; LOG.error(PackingToolErrMsg.CHECK_MODULE_INVALID.toString(errMsg)); return false; } diff --git a/adapter/ohos/ModuleJsonUtil.java b/adapter/ohos/ModuleJsonUtil.java index 0458ba35..239b6db9 100644 --- a/adapter/ohos/ModuleJsonUtil.java +++ b/adapter/ohos/ModuleJsonUtil.java @@ -401,8 +401,8 @@ class ModuleJsonUtil { } desPackInfo = mergePackInfoObj(finalPackObj, srcPackObj); } catch (BundleException | JSONException e) { - String errMsg = "Merge two pack.info file into one pack.info exist " - + "exception(BundleException | JSONException): "; + String errMsg = "Merge two pack.info file into one pack.info exist " + + "exception (BundleException | JSONException): "; LOG.error(PackingToolErrMsg.MERGE_TWO_PACKINFO_FAILED.toString(errMsg + e.getMessage())); throw new BundleException(errMsg + e.getMessage()); } @@ -418,14 +418,14 @@ class ModuleJsonUtil { */ public static boolean verifyPackInfo(JSONObject finalPackObj, JSONObject srcPackObj) throws BundleException { if (finalPackObj == null || srcPackObj == null) { - String errMsg = "Input json Objects (final pack.info or src pack.info) are null."; + String errMsg = "Input json objects (final pack.info or src pack.info) is null."; LOG.error(PackingToolErrMsg.VERIFY_PACKINFO_FAILED.toString(errMsg)); return false; } JSONObject finalSummaryObj = finalPackObj.getJSONObject(SUMMARY); JSONObject srcSummaryObj = srcPackObj.getJSONObject(SUMMARY); if (finalSummaryObj == null || srcSummaryObj == null) { - String errMsg = "pack.info does not contain summary."; + String errMsg = "Final pack.info or src pack.info does not contain 'summary'."; LOG.error(PackingToolErrMsg.VERIFY_PACKINFO_FAILED.toString(errMsg)); return false; } @@ -433,12 +433,12 @@ class ModuleJsonUtil { JSONObject finalAppObj = finalSummaryObj.getJSONObject(APP); JSONObject srcAppObj = srcSummaryObj.getJSONObject(APP); if (finalAppObj == null || srcAppObj == null) { - String errMsg = "pack.info does not contain app."; + String errMsg = "Final pack.info or src pack.info does not contain 'app'."; LOG.error(PackingToolErrMsg.VERIFY_PACKINFO_FAILED.toString(errMsg)); return false; } if (!verifyAppInPackInfo(finalAppObj, srcAppObj)) { - String errMsg = "Verify app field in pack.info failed."; + String errMsg = "Verify app field in final pack.info and src pack.info failed."; LOG.error(PackingToolErrMsg.VERIFY_PACKINFO_FAILED.toString(errMsg)); return false; } @@ -455,7 +455,7 @@ class ModuleJsonUtil { */ public static boolean verifyAppInPackInfo(JSONObject finalAppObj, JSONObject srcAppObj) { if (finalAppObj == null || srcAppObj == null) { - String errMsg = "Input JSON objects (finalAppObj or srcAppObj) are null."; + String errMsg = "Input json objects (finalAppObj or srcAppObj) is null."; LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } @@ -463,13 +463,13 @@ class ModuleJsonUtil { String finalBundleName = finalAppObj.getString(BUNDLE_NAME); String srcBundleName = srcAppObj.getString(BUNDLE_NAME); if (!finalBundleName.equals(srcBundleName)) { - String errMsg = "BundleName is different between final bundleName and src bundleName."; + String errMsg = "The bundleName is different between final bundleName and src bundleName."; LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } // check bundleType if (!checkBundleTypeInPackInfo(finalAppObj, srcAppObj)) { - String errMsg = "BundleType is different between final app object and src app object."; + String errMsg = "The bundleType is different between final app object and src app object."; LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } @@ -484,7 +484,7 @@ class ModuleJsonUtil { int finalVersionCode = finalVersionObj.getIntValue(CODE); int srcVersionCode = srcVersionObj.getIntValue(CODE); if (finalVersionCode != srcVersionCode) { - String errMsg = "Code is different between final version object and src version object."; + String errMsg = "The code is different between final version object and src version object."; LOG.error(PackingToolErrMsg.VERIFY_APP_PACKINFO_FAILED.toString(errMsg)); return false; } @@ -500,7 +500,7 @@ class ModuleJsonUtil { */ public static boolean checkBundleTypeInPackInfo(JSONObject finalAppObj, JSONObject srcAppObj) { if (finalAppObj.isEmpty() || srcAppObj.isEmpty()) { - String errMsg = "Input JSON objects (finalAppObj or srcAppObj) are null."; + String errMsg = "Input json objects (finalAppObj or srcAppObj) is null."; LOG.error(PackingToolErrMsg.BUNDLE_TYPE_PACKINFO_INVALID.toString(errMsg)); return false; } @@ -513,7 +513,7 @@ class ModuleJsonUtil { srcBundleType = getJsonString(srcAppObj, BUNDLE_TYPE); } if (!finalBundleType.equals(srcBundleType)) { - String errMsg = "BundleType is different between final bundleType and src bundleType."; + String errMsg = "The bundleType is different between final bundleType and src bundleType."; LOG.error(PackingToolErrMsg.BUNDLE_TYPE_PACKINFO_INVALID.toString(errMsg)); return false; } @@ -570,14 +570,14 @@ class ModuleJsonUtil { throws BundleException { JSONObject jsonObject = JSONObject.parseObject(jsonString); if (jsonObject == null || !jsonObject.containsKey(SUMMARY)) { - String errMsg = "json object does not contain summary."; + String errMsg = "The json object is null or does not contain 'summary'."; LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_NAME_FAILED.toString(errMsg)); throw new BundleException("Parse pack info forms name failed, summary is null."); } JSONObject summaryJson = jsonObject.getJSONObject(SUMMARY); if (summaryJson == null || !summaryJson.containsKey("modules")) { - String errMsg = "summary object does not contain modules."; + String errMsg = "The summary object does not contain 'modules'."; LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_NAME_FAILED.toString(errMsg)); return; } @@ -586,14 +586,14 @@ class ModuleJsonUtil { for (int i = 0; i < moduleJsonList.size(); i++) { JSONObject moduleJson = moduleJsonList.getJSONObject(i); if (moduleJson == null || !moduleJson.containsKey(DISTRO)) { - String errMsg = "modules object does not contain distro."; + String errMsg = "The modules object does not contain 'distro'."; LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_NAME_FAILED.toString(errMsg)); continue; } JSONObject distroObj = moduleJson.getJSONObject(DISTRO); if (distroObj == null || !distroObj.containsKey(MODULE_NAME)) { - String errMsg = "distro object does not contain moduleName."; + String errMsg = "The distro object does not contain 'moduleName'."; LOG.error(PackingToolErrMsg.PARSE_PACKINFO_FORMS_NAME_FAILED.toString(errMsg)); continue; } @@ -674,19 +674,19 @@ class ModuleJsonUtil { * merge pack.info file. * * @param finalPackinfoObj is the final pack.info objects - * @param srcPackinfoObj is the final pack.info objects + * @param srcPackinfoObj is the src pack.info objects * @return the result */ public static String mergePackInfoObj(JSONObject finalPackinfoObj, JSONObject srcPackinfoObj) throws BundleException { if (finalPackinfoObj == null || srcPackinfoObj == null) { - String errMsg = "Input JSON objects (finalPackinfoObj or srcPackinfoObj) are null."; + String errMsg = "Input JSON objects (final pack.info object or src pack.info object) is null."; LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_FAILED.toString(errMsg)); throw new BundleException(errMsg); } JSONObject finalSummaryObj = finalPackinfoObj.getJSONObject(SUMMARY); JSONObject srcSummaryObj = srcPackinfoObj.getJSONObject(SUMMARY); if (finalSummaryObj == null || srcSummaryObj == null) { - String errMsg = "Input JSON objects (finalSummaryObj or srcSummaryObj) are null."; + String errMsg = "Input JSON objects (final SummaryObj or src SummaryObj) is null."; LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_FAILED.toString(errMsg)); throw new BundleException(errMsg); } @@ -694,7 +694,7 @@ class ModuleJsonUtil { JSONArray finalModuleObs = finalSummaryObj.getJSONArray(MODULES); JSONArray srcModuleObs = srcSummaryObj.getJSONArray(MODULES); if (finalModuleObs == null || srcModuleObs == null) { - String errMsg = "Input JSON array (finalModuleObs or srcModuleObs) are null."; + String errMsg = "Input JSON array (final ModuleObs or src ModuleObs) is null."; LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_FAILED.toString(errMsg)); throw new BundleException(errMsg); } @@ -703,7 +703,7 @@ class ModuleJsonUtil { JSONArray finalPackageObs = finalPackinfoObj.getJSONArray(PACKAGES); JSONArray srcPackageObs = srcPackinfoObj.getJSONArray(PACKAGES); if (finalPackageObs == null || srcPackageObs == null) { - String errMsg = "Input JSON array (finalPackageObs or srcPackageObs) are null."; + String errMsg = "Input JSON array (final PackageObs or src PackageObs) is null."; LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_FAILED.toString(errMsg)); throw new BundleException(errMsg); } @@ -728,8 +728,8 @@ class ModuleJsonUtil { finalPackObj = JSON.parseObject(finalPackInfo); srcPackObj = JSON.parseObject(srcPackInfo); } catch (JSONException exception) { - String errMsg = "Merge two pack.info exist JSONException: " + exception.getMessage(); - LOG.error(PackingToolErrMsg.PARSE_JSON_FAILED.toString(errMsg)); + String errMsg = "Parse final pack.info or src pack.info exist JSONException: " + exception.getMessage(); + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // verify app in pack.info @@ -738,8 +738,8 @@ class ModuleJsonUtil { JSONObject srcSummaryObj = srcPackObj.getJSONObject(SUMMARY); JSONObject srcAppObj = srcSummaryObj.getJSONObject(APP); if (!verifyAppInPackInfo(finalAppObj, srcAppObj)) { - String errMsg = "Verify pack.info failed, different version, bundleType or bundleName."; - LOG.error(PackingToolErrMsg.MERGE_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); + String errMsg = "Verify app in pack.info failed: different version, bundleType or bundleName."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } for (HashMap.Entry entry : packagePair.entrySet()) { @@ -761,23 +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 = "Input JSON objects (finalPackObj or srcPackObj) are null."; - LOG.error(PackingToolErrMsg.MERGE_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); + String errMsg = "Input json objects (final pack.info or src pack.info) is null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // merge module JSONObject finalSummaryObj = finalPackObj.getJSONObject(SUMMARY); JSONObject srcSummaryObj = srcPackObj.getJSONObject(SUMMARY); if (finalSummaryObj == null || srcSummaryObj == null) { - String errMsg = "Input JSON objects (finalSummaryObj or srcSummaryObj) are null."; - LOG.error(PackingToolErrMsg.MERGE_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); + String errMsg = "Input json objects (final summaryObj or src summaryObj) is null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } JSONArray finalModules = finalSummaryObj.getJSONArray(MODULES); JSONArray srcModules = srcSummaryObj.getJSONArray(MODULES); if (finalModules == null || srcModules == null) { - String errMsg = "Input JSON Array (finalModules or srcModules) are null."; - LOG.error(PackingToolErrMsg.MERGE_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); + String errMsg = "Input json array (final modules or src modules) is null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException("ModuleJsonUtil:mergeTwoPackInfoObjByPackagePair input json file has empty module."); } @@ -793,15 +793,15 @@ class ModuleJsonUtil { } if (!findModule) { String errMsg = "Input json does not contain " + moduleName + "."; - LOG.error(PackingToolErrMsg.MERGE_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } // merge package JSONArray finalPackages = finalPackObj.getJSONArray(PACKAGES); JSONArray srcPackages = srcPackObj.getJSONArray(PACKAGES); if (finalPackages == null || srcPackages == null) { - String errMsg = "Input JSON Array (finalPackages or srcPackages) are null."; - LOG.error(PackingToolErrMsg.MERGE_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); + String errMsg = "Input json array (final packages or src packages) is null."; + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } boolean findPackage = false; @@ -815,7 +815,7 @@ class ModuleJsonUtil { } if (!findPackage) { String errMsg = "Input json does not contain " + packageName + "."; - LOG.error(PackingToolErrMsg.MERGE_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); + LOG.error(PackingToolErrMsg.MERGE_PACKINFO_OBJ_BY_PACKAGE_PAIR_FAILED.toString(errMsg)); throw new BundleException(errMsg); } } diff --git a/adapter/ohos/PackageNormalize.java b/adapter/ohos/PackageNormalize.java index 31a7e3bf..39a17ed1 100644 --- a/adapter/ohos/PackageNormalize.java +++ b/adapter/ohos/PackageNormalize.java @@ -138,7 +138,7 @@ public class PackageNormalize { JSONObject jsonObject = JSON.parseObject(input, JSONObject.class); if (jsonObject == null) { LOG.error(PackingToolErrMsg.UPDATE_MODULE_JSON_FAILED.toString( - "Failed to parse module.json: invalid JSON format.")); + "Failed to parse module.json: invalid json format.")); throw new BundleException("updateModuleJson failed, parse json is null."); } if (!jsonObject.containsKey(APP)) { @@ -161,7 +161,7 @@ public class PackageNormalize { JSONObject jsonObject = JSON.parseObject(input, JSONObject.class); if (jsonObject == null) { LOG.error(PackingToolErrMsg.UPDATE_PACKINFO_FAILED.toString( - "Failed to parse pack.info: Invalid JSON format.")); + "Failed to parse pack.info: invalid json format.")); throw new BundleException("updatePackInfo failed, json format invalid."); } JSONObject summaryObject = jsonObject.getJSONObject(SUMMARY); @@ -251,7 +251,7 @@ public class PackageNormalize { } } catch (FileNotFoundException ignored) { LOG.error(PackingToolErrMsg.FILE_NOT_FOUND.toString( - "Get Crc from file exist FileNotFoundExpection: " + ignored.getMessage())); + "Get Crc from file exist FileNotFoundException: " + ignored.getMessage())); throw new BundleException("Get Crc from file failed."); } catch (IOException exception) { LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString( diff --git a/adapter/ohos/PackageUtil.java b/adapter/ohos/PackageUtil.java index 2f5a6d5c..00c148e9 100644 --- a/adapter/ohos/PackageUtil.java +++ b/adapter/ohos/PackageUtil.java @@ -356,8 +356,8 @@ public class PackageUtil { try { return hspFile.getInputStream(zipEntry); } catch (IOException e) { - LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Repack hsp exist IOException: " - + e.getMessage())); + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Repack hsp exist IOException: " + + e.getMessage())); return null; } }; @@ -365,9 +365,9 @@ public class PackageUtil { } zipCreator.writeTo(zipOut); } catch (InterruptedException | ExecutionException e) { - String errMsg = "Repack hsp exist Exception (InterruptedException | ExecutionException): " - + e.getMessage(); - LOG.error(PackingToolErrMsg.INTERRUPTED_OR_EXECUTION_EXCEPTION.toString(errMsg)); + String errMsg = "Repack hsp exist Exception (InterruptedException | ExecutionException): " + + e.getMessage(); + LOG.error(PackingToolErrMsg.REPACK_HSP_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } return outHsp; @@ -438,7 +438,7 @@ public class PackageUtil { zipCreator.writeTo(zipOut); } catch (InterruptedException | ExecutionException e) { String errMsg = "Pack dir exist Exception (InterruptedException | ExecutionException): " + e.getMessage(); - LOG.error(PackingToolErrMsg.INTERRUPTED_OR_EXECUTION_EXCEPTION.toString(errMsg)); + LOG.error(PackingToolErrMsg.PACK_MULTI_THREAD_EXCEPTION.toString(errMsg)); throw new BundleException(errMsg); } return outHap; @@ -523,7 +523,8 @@ public class PackageUtil { if (file.isDirectory()) { File[] files = file.listFiles(); if (files == null) { - LOG.error(PackingToolErrMsg.ADD_ARCHIVE_ENTRY_FAILED.toString("listFiles null: " + file.getName())); + LOG.error(PackingToolErrMsg.ADD_ARCHIVE_ENTRY_FAILED.toString("listFiles null, directory name is " + + file.getName())); return; } if (files.length == 0) { @@ -551,7 +552,7 @@ public class PackageUtil { try { return getInputStream(entryName, file); } catch (IOException e) { - LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Add Archive Entry exist IOException: " + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Add ArchiveEntry exist IOException: " + e.getMessage())); return null; } @@ -660,7 +661,8 @@ public class PackageUtil { if (file.isDirectory()) { File[] files = file.listFiles(); if (files == null) { - LOG.error(PackingToolErrMsg.ADD_ARCHIVE_ENTRY_FAILED.toString("listFiles null: " + file.getName())); + LOG.error(PackingToolErrMsg.ADD_ARCHIVE_ENTRY_FAILED.toString("listFiles null, directory name is " + + file.getName())); return; } if (files.length == 0) { @@ -708,13 +710,13 @@ public class PackageUtil { } for (String hapPath : hapPathList) { if (!bundleType.equals(getBundleTypeFromPath(Paths.get(hapPath)))) { - LOG.error(PackingToolErrMsg.CHECK_BUNDLE_TYPE_CONSISTENCY.toString("Hap bundle type is not same")); + LOG.error(PackingToolErrMsg.CHECK_BUNDLE_TYPE_CONSISTENCY.toString("Hap bundleType is not same")); return false; } } for (String hspPath : hspPathList) { if (!bundleType.equals(getBundleTypeFromPath(Paths.get(hspPath)))) { - LOG.error(PackingToolErrMsg.CHECK_BUNDLE_TYPE_CONSISTENCY.toString("Hsp bundle type is not same")); + LOG.error(PackingToolErrMsg.CHECK_BUNDLE_TYPE_CONSISTENCY.toString("Hsp bundleType is not same")); return false; } } @@ -728,11 +730,11 @@ public class PackageUtil { for (String hapPath : hapPathList) { Path path = Paths.get(hapPath); if (!Files.exists(path.resolve(Constants.FILE_MODULE_JSON))) { - LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found module.json in hap path: " + path)); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found module.json in the hap path: " + path)); return false; } if (!Files.exists(path.resolve(Constants.FILE_PACK_INFO))) { - LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found pack.info in hap path: " + path)); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found pack.info in the hap path: " + path)); return false; } } @@ -740,11 +742,13 @@ public class PackageUtil { Path path = Paths.get(hspPath); if (Files.isDirectory(path)) { if (!Files.exists(path.resolve(Constants.FILE_MODULE_JSON))) { - LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found module.json in hsp path: " + path)); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found module.json in the hsp path: " + + path)); return false; } if (!Files.exists(path.resolve(Constants.FILE_PACK_INFO))) { - LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found pack.info in hsp path: " + path)); + LOG.error(PackingToolErrMsg.FILE_NOT_EXIST.toString("Not found pack.info in the hsp path: " + + path)); return false; } } @@ -793,7 +797,7 @@ public class PackageUtil { } if (!checkBundleTypeConsistency( utility.getFormattedHapPathList(), utility.getFormattedHspPathList(), utility)) { - LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("Bundle type is inconsistent.")); + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("The bundleType is inconsistent.")); return false; } if (!isPackInfoValid(Paths.get(utility.getPackInfoPath()), @@ -884,7 +888,7 @@ public class PackageUtil { return false; } } catch (IOException ex) { - LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Format path exist IOException: " + LOG.error(PackingToolErrMsg.IO_EXCEPTION.toString("Verify format path exist IOException: " + ex.getMessage())); return false; } @@ -897,25 +901,25 @@ public class PackageUtil { List allPackages = getPackageNameFromPath(packInfo); Set allPackageSet = new HashSet<>(allPackages); if (allPackages.size() > allPackageSet.size()) { - LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Package name is redundant in app pack.info: " + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Package name is redundant in app pack.info, the path is " + packInfo)); return false; } if (allPackages.isEmpty()) { - LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("App pack.info format error: " + packInfo)); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("App pack.info format error, the path is " + packInfo)); return false; } Set packages = new HashSet<>(); for (String hapPath : hapPathList) { List list = getPackageNameFromPath(Paths.get(hapPath)); if (list.size() != 1) { - LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info format error: " + hapPath)); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info format error, the path is " + hapPath)); return false; } String packageName = list.get(0); if (!allPackages.contains(packageName)) { - LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info name not exist in app " - + "pack.info name list: " + hapPath)); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info name does not exist in app " + + "pack.info name list, the path is " + hapPath)); return false; } if (packages.contains(packageName)) { @@ -927,13 +931,13 @@ public class PackageUtil { for (String hspPath : hspPathList) { List list = getPackageNameFromPath(Paths.get(hspPath)); if (list.size() != 1) { - LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info format err: " + hspPath)); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info format err, the path is " + hspPath)); return false; } String packageName = list.get(0); if (!allPackages.contains(packageName)) { - LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info name not exist in app " - + "pack.info name list: " + hspPath)); + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Module pack.info name does not exist in app " + + "pack.info name list, the path is " + hspPath)); return false; } if (packages.contains(packageName)) { @@ -943,7 +947,7 @@ public class PackageUtil { packages.add(packageName); } if (!allPackageSet.equals(packages)) { - LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Package name not same between module " + LOG.error(PackingToolErrMsg.PACK_INFO_INVALID.toString("Package name is not same between module " + "and app pack.info.")); return false; } diff --git a/adapter/ohos/PackingToolErrMsg.java b/adapter/ohos/PackingToolErrMsg.java index 7b49a716..ff3649ac 100644 --- a/adapter/ohos/PackingToolErrMsg.java +++ b/adapter/ohos/PackingToolErrMsg.java @@ -235,67 +235,26 @@ public class PackingToolErrMsg { .setCause("%s") .build(); - /** - * DIRECTORY_INVALID - */ - public static final ErrorMsg DIRECTORY_INVALID = ErrorMsg.getPackingToolErrBuilder() - .setTypeCode("11") - .setErrCode("019") - .setDescription("directory is not exist.") - .setCause("%s") - .build(); - /** * HAP_ADDITION_MODE_ARGS_INVALID */ public static final ErrorMsg HAP_ADDITION_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("11") - .setErrCode("020") + .setErrCode("019") .setDescription("Parse and check args invalid in hapAddition mode.") .setCause("%s") .build(); /** - * INPUT_PATH_INVALID - */ - public static final ErrorMsg INPUT_PATH_INVALID = ErrorMsg.getPackingToolErrBuilder() - .setTypeCode("11") - .setErrCode("021") - .setDescription("input_path is invalid.") - .setCause("%s") - .build(); - - /** - * CHECK_BUNDLE_TYPE_CONSISTENCY - */ - public static final ErrorMsg CHECK_BUNDLE_TYPE_CONSISTENCY = ErrorMsg.getPackingToolErrBuilder() - .setTypeCode("11") - .setErrCode("022") - .setDescription("Checking bundle type consistency failed.") - .setCause("%s") - .build(); - - /** - * CHECK_BUNDLE_TYPE_CONSISTENCY - */ - public static final ErrorMsg FAST_APP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() - .setTypeCode("11") - .setErrCode("023") - .setDescription("Parse and check args invalid in fast app mode.") - .setCause("%s") - .build(); - - /** - * PACK_INFO_INVALID + * HANDLE_HAP_HSP_INPUT_FAILED */ - public static final ErrorMsg PACK_INFO_INVALID = ErrorMsg.getPackingToolErrBuilder() + public static final ErrorMsg HANDLE_HAP_HSP_INPUT_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("11") - .setErrCode("024") - .setDescription("Pack info invalid.") + .setErrCode("020") + .setDescription("Handle hap and hsp input failed.") .setCause("%s") .build(); - // compress process error /** * COMPRESS_PROCESS_FAILED @@ -569,7 +528,7 @@ public class PackingToolErrMsg { public static final ErrorMsg COMPRESS_APP_MODE_FORMULTI_PROJECT_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") .setErrCode("025") - .setDescription("Compress app mode for multi project failed.") + .setDescription("Compress in app mode for multi project.failed.") .setCause("%s") .build(); @@ -609,7 +568,7 @@ public class PackingToolErrMsg { public static final ErrorMsg NO_PACK_INFO = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") .setErrCode("029") - .setDescription("No pack.info available.") + .setDescription("pack.info does not find in hap or app.") .setCause("%s") .build(); @@ -619,7 +578,7 @@ public class PackingToolErrMsg { public static final ErrorMsg COMPRESS_PACK_RES_MODE_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") .setErrCode("030") - .setDescription("Compress pack res mode failed.") + .setDescription("Compress in res mode failed.") .setCause("%s") .build(); @@ -641,7 +600,7 @@ public class PackingToolErrMsg { public static final ErrorMsg IS_PICTURING_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") .setErrCode("032") - .setDescription("Is picturing failed.") + .setDescription("Check whether picturingName meets specifications failed.") .setCause("%s") .build(); @@ -671,7 +630,7 @@ public class PackingToolErrMsg { public static final ErrorMsg COMPRESS_APPQF_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") .setErrCode("035") - .setDescription("Compress appqf Mode failed.") + .setDescription("Compress in appqf mode failed.") .setCause("%s") .build(); @@ -681,7 +640,27 @@ public class PackingToolErrMsg { public static final ErrorMsg CHECK_HQF_INVALID = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") .setErrCode("036") - .setDescription("HQF is valid.") + .setDescription("Input hqf is invalid.") + .setCause("%s") + .build(); + + /** + * CHECK_APP_FIELDS_FAILED + */ + public static final ErrorMsg CHECK_APP_FIELDS_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("037") + .setDescription("Check hqf has same app fields failed.") + .setCause("%s") + .build(); + + /** + * CHECK_MODULE_INVALID + */ + public static final ErrorMsg CHECK_MODULE_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("038") + .setDescription("Check hqf module is invalid.") .setCause("%s") .build(); @@ -690,7 +669,7 @@ public class PackingToolErrMsg { */ public static final ErrorMsg VERSION_NORMALIZE_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") - .setErrCode("037") + .setErrCode("039") .setDescription("Version normalize failed.") .setCause("%s") .build(); @@ -700,18 +679,18 @@ public class PackingToolErrMsg { */ public static final ErrorMsg VERIFY_MODULE_VERSION_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") - .setErrCode("038") + .setErrCode("040") .setDescription("Verify module version failed.") .setCause("%s") .build(); /** - * CHECK_SUM_FAILED + * SHA256_CALCULATION_FAILED */ - public static final ErrorMsg CHECK_SUM_FAILED = ErrorMsg.getPackingToolErrBuilder() + public static final ErrorMsg SHA256_CALCULATION_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") - .setErrCode("039") - .setDescription("Check sum failed.") + .setErrCode("041") + .setDescription("SHA-256 hash calculation failed.") .setCause("%s") .build(); @@ -720,8 +699,8 @@ public class PackingToolErrMsg { */ public static final ErrorMsg MERGE_TWO_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") - .setErrCode("040") - .setDescription("Merge two pack info failed.") + .setErrCode("042") + .setDescription("Merge two pack.info into one pack.info file failed.") .setCause("%s") .build(); @@ -730,8 +709,8 @@ public class PackingToolErrMsg { */ public static final ErrorMsg VERIFY_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") - .setErrCode("041") - .setDescription("Verify pack info failed.") + .setErrCode("043") + .setDescription("Verify pack.info file failed.") .setCause("%s") .build(); @@ -740,8 +719,8 @@ public class PackingToolErrMsg { */ public static final ErrorMsg VERIFY_APP_PACKINFO_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") - .setErrCode("042") - .setDescription("Verify app pack info failed.") + .setErrCode("044") + .setDescription("Verify app in pack.info failed.") .setCause("%s") .build(); @@ -750,8 +729,8 @@ public class PackingToolErrMsg { */ public static final ErrorMsg BUNDLE_TYPE_PACKINFO_INVALID = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") - .setErrCode("043") - .setDescription("Invalid bundle type in pack info.") + .setErrCode("045") + .setDescription("Verify bundleType in pack.info file failed.") .setCause("%s") .build(); @@ -760,8 +739,8 @@ public class PackingToolErrMsg { */ public static final ErrorMsg PARSE_PACKINFO_FORMS_NAME_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") - .setErrCode("044") - .setDescription("Parse pack info forms name error.") + .setErrCode("046") + .setDescription("Parse forms name in pack.info file failed.") .setCause("%s") .build(); @@ -770,28 +749,29 @@ public class PackingToolErrMsg { */ public static final ErrorMsg MERGE_PACKINFO_OBJ_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") - .setErrCode("045") - .setDescription("Failed to merge package information object.") + .setErrCode("047") + .setDescription("Failed to merge pack.info objects.") .setCause("%s") .build(); /** - * MERGE_BY_PACKAGE_PAIR_FAILED + * MERGE_PACKINFO_BY_PACKAGE_PAIR_FAILED */ - public static final ErrorMsg MERGE_BY_PACKAGE_PAIR_FAILED = ErrorMsg.getPackingToolErrBuilder() + public static final ErrorMsg MERGE_PACKINFO_BY_PACKAGE_PAIR_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") - .setErrCode("046") - .setDescription("Failed to merge two pack.info files into one pack.info file through packagePair.") + .setErrCode("048") + .setDescription("Failed to merge two pack.info files into one pack.info file by packagePair.") .setCause("%s") .build(); /** - * MERGE_OBJBY_PACKAGE_PAIR_FAILED + * MERGE_PACKINFO_OBJ_BY_PACKAGE_PAIR_FAILED */ - public static final ErrorMsg MERGE_OBJ_BY_PACKAGE_PAIR_FAILED = ErrorMsg.getPackingToolErrBuilder() + public static final ErrorMsg MERGE_PACKINFO_OBJ_BY_PACKAGE_PAIR_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") - .setErrCode("047") - .setDescription("Failed to merge two pack.info objects into one pack.info through packagePair.") + .setErrCode("049") + .setDescription( + "Failed to merge two pack.info json objects into one pack.info json object by packagePair.") .setCause("%s") .build(); @@ -800,38 +780,68 @@ public class PackingToolErrMsg { */ public static final ErrorMsg PARSE_PACKINFO_FORMS_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") - .setErrCode("048") - .setDescription("Failed to parse package information form.") + .setErrCode("050") + .setDescription("Failed to parse pack.info forms.") .setCause("%s") .build(); /** - * INTERRUPTED_OR_EXECUTION_EXCEPTION + * COMPRESS_FILE_DUPLICATE */ - public static final ErrorMsg INTERRUPTED_OR_EXECUTION_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + public static final ErrorMsg COMPRESS_FILE_DUPLICATE = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") - .setErrCode("049") - .setDescription("Exists interrupted or execution exception.") + .setErrCode("051") + .setDescription("File duplicated.") .setCause("%s") .build(); /** - * ADD_ARCHIVE_ENTRY_FAILED + * COPY_FILE_FAILED */ - public static final ErrorMsg ADD_ARCHIVE_ENTRY_FAILED = ErrorMsg.getPackingToolErrBuilder() + public static final ErrorMsg COPY_FILE_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") - .setErrCode("050") - .setDescription("Add archive entry failed.") + .setErrCode("052") + .setDescription("Copy file failed.") .setCause("%s") .build(); /** - * COMPRESS_FAST_APP_FAILED + * MAKE_DIR_FAILED */ - public static final ErrorMsg COMPRESS_FAST_APP_FAILED = ErrorMsg.getPackingToolErrBuilder() + public static final ErrorMsg MAKE_DIR_FAILED = ErrorMsg.getPackingToolErrBuilder() .setTypeCode("12") - .setErrCode("051") - .setDescription("Compress fast app file failed.") + .setErrCode("053") + .setDescription("Make dir failed.") + .setCause("%s") + .build(); + + /** + * COPY_FILE_SAFELY_FAILED + */ + public static final ErrorMsg COPY_FILE_SAFELY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("054") + .setDescription("Copy file safely failed.") + .setCause("%s") + .build(); + + /** + * PARSE_MODIFY_CONFIG_JSON_FAILED + */ + public static final ErrorMsg PARSE_MODIFY_CONFIG_JSON_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("055") + .setDescription("Parse and modify config.json failed.") + .setCause("%s") + .build(); + + /** + * PARSE_AND_MODIFY_MODULEJSON_FAILED + */ + public static final ErrorMsg PARSE_AND_MODIFY_MODULEJSON_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("12") + .setErrCode("056") + .setDescription("Parse and modify module.json failed.") .setCause("%s") .build(); @@ -1087,46 +1097,6 @@ public class PackingToolErrMsg { "2. Ensure that you have the necessary permissions to create directories.") .build(); - /** - * COMPRESS_FILE_DUPLICATE - */ - public static final ErrorMsg COMPRESS_FILE_DUPLICATE = ErrorMsg.getPackingToolErrBuilder() - .setTypeCode("14") - .setErrCode("011") - .setDescription("File duplicated.") - .setCause("%s") - .build(); - - /** - * COPY_FILE_SAFELY_FAILED - */ - public static final ErrorMsg COPY_FILE_SAFELY_FAILED = ErrorMsg.getPackingToolErrBuilder() - .setTypeCode("14") - .setErrCode("012") - .setDescription("Copy file safely failed.") - .setCause("%s") - .build(); - - /** - * COPY_FILE_FAILED - */ - public static final ErrorMsg COPY_FILE_FAILED = ErrorMsg.getPackingToolErrBuilder() - .setTypeCode("14") - .setErrCode("013") - .setDescription("Copy file failed.") - .setCause("%s") - .build(); - - /** - * MAKE_DIR_FAILED - */ - public static final ErrorMsg MAKE_DIR_FAILED = ErrorMsg.getPackingToolErrBuilder() - .setTypeCode("14") - .setErrCode("014") - .setDescription("Make dir failed.") - .setCause("%s") - .build(); - // io exception /** * IO_EXCEPTION @@ -1364,26 +1334,6 @@ public class PackingToolErrMsg { "settings is 'exclude' or 'include'.") .build(); - /** - * CHECK_APP_FIELDS_FAILED - */ - public static final ErrorMsg CHECK_APP_FIELDS_FAILED = ErrorMsg.getPackingToolErrBuilder() - .setTypeCode("16") - .setErrCode("020") - .setDescription("Check app fields is failed.") - .setCause("%s") - .build(); - - /** - * CHECK_MODULE_INVALID - */ - public static final ErrorMsg CHECK_MODULE_INVALID = ErrorMsg.getPackingToolErrBuilder() - .setTypeCode("16") - .setErrCode("021") - .setDescription("Check module is invalid.") - .setCause("%s") - .build(); - // package normalize error /** * PACKAGE_NORMALIZE_FAILED @@ -1414,4 +1364,65 @@ public class PackingToolErrMsg { .setDescription("Update pack.info failed.") .setCause("%s") .build(); + + // package util error + /** + * FAST_APP_MODE_ARGS_INVALID + */ + public static final ErrorMsg FAST_APP_MODE_ARGS_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("18") + .setErrCode("001") + .setDescription("Parse and check args invalid in fast app mode.") + .setCause("%s") + .build(); + + /** + * CHECK_BUNDLE_TYPE_CONSISTENCY + */ + public static final ErrorMsg CHECK_BUNDLE_TYPE_CONSISTENCY = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("18") + .setErrCode("002") + .setDescription("Check bundleType consistency failed.") + .setCause("%s") + .build(); + + /** + * PACK_INFO_INVALID + */ + public static final ErrorMsg PACK_INFO_INVALID = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("18") + .setErrCode("003") + .setDescription("Pack.info is invalid.") + .setCause("%s") + .build(); + + /** + * ADD_ARCHIVE_ENTRY_FAILED + */ + public static final ErrorMsg ADD_ARCHIVE_ENTRY_FAILED = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("18") + .setErrCode("004") + .setDescription("Add archive entry failed.") + .setCause("%s") + .build(); + + /** + * PACK_MULTI_THREAD_EXCEPTION + */ + public static final ErrorMsg PACK_MULTI_THREAD_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("18") + .setErrCode("005") + .setDescription("Pack multi thread exception.") + .setCause("%s") + .build(); + + /** + * REPACK_HSP_EXCEPTION + */ + public static final ErrorMsg REPACK_HSP_EXCEPTION = ErrorMsg.getPackingToolErrBuilder() + .setTypeCode("18") + .setErrCode("006") + .setDescription("Repack hsp exception.") + .setCause("%s") + .build(); } -- Gitee