From c6d32fdbc9603a19cf8013da55f9a6e13f79320a Mon Sep 17 00:00:00 2001 From: nj1868 Date: Wed, 12 Mar 2025 17:51:13 +0800 Subject: [PATCH] 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