From e19e3e9b52fd9f054b56043ae7ac8468027fed72 Mon Sep 17 00:00:00 2001 From: z30034863 Date: Fri, 18 Jul 2025 17:39:19 +0800 Subject: [PATCH] fix debug validation rules Signed-off-by: z30034863 --- adapter/ohos/HapVerify.java | 51 ++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/adapter/ohos/HapVerify.java b/adapter/ohos/HapVerify.java index e20bc602..317eea42 100644 --- a/adapter/ohos/HapVerify.java +++ b/adapter/ohos/HapVerify.java @@ -16,15 +16,8 @@ package ohos; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; +import java.util.*; +import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -284,6 +277,7 @@ class HapVerify { verifyInfo = optional.get(); } List hapList = new ArrayList<>(); + List hspList = new ArrayList<>(); int hspMinCompatibleVersionCodeMax = -1; int hspTargetApiVersionMax = -1; int hspMinApiVersionMax = -1; @@ -321,9 +315,10 @@ class HapVerify { LOG.warning("Module: (" + moduleName + ") and Module: (" + hapVerifyInfo.getModuleName() + ") has different values."); } - if (hapVerifyInfo.getFileType() == HAP_SUFFIX) { + if (Objects.equals(hapVerifyInfo.getFileType(), HAP_SUFFIX)) { hapList.add(hapVerifyInfo); - } else if (hapVerifyInfo.getFileType() == HSP_SUFFIX) { + } else if (Objects.equals(hapVerifyInfo.getFileType(), HSP_SUFFIX)) { + hspList.add(hapVerifyInfo); if (hapVerifyInfo.getVersion().minCompatibleVersionCode > hspMinCompatibleVersionCodeMax) { hspMinCompatibleVersionCodeMax = hapVerifyInfo.getVersion().minCompatibleVersionCode; } @@ -338,6 +333,9 @@ class HapVerify { if (!appFieldsIsValid(hapList, hspMinCompatibleVersionCodeMax, hspTargetApiVersionMax, hspMinApiVersionMax)) { return false; } + if (!moduleDebugValidation(hapList, hspList)) { + return false; + } return true; } @@ -373,6 +371,31 @@ class HapVerify { return true; } + private static boolean moduleDebugValidation(List hapVerifyInfos, + List hspVerifyInfos) { + if (hapVerifyInfos.isEmpty()) { + LOG.warning("Hap verify infos is empty"); + return true; + } + HapVerifyInfo hap = hapVerifyInfos.get(0); + for (HapVerifyInfo hapInfo : hapVerifyInfos) { + if (hap.isDebug() != hapInfo.isDebug()) { + String errMsg = "The debug fields of multiple Hap are different."; + String solution = "Ensure that the values of 'debug' 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.isDebug() && hspVerifyInfos.stream().anyMatch(HapVerifyInfo::isDebug)) { + String errMsg = "Detected HAP(s) with debug=false, but some HSP(s) are debug=true."; + String solution = "When the debug value of Hap is false,the debug value of Hsp should also be false."; + LOG.error(PackingToolErrMsg.CHECK_APP_FIELDS_INVALID.toString(errMsg, solution)); + return false; + } + return true; + } + private static boolean appFieldsIsSame(VerifyCollection verifyCollection, HapVerifyInfo hapVerifyInfo) { if (hapVerifyInfo.getBundleName().isEmpty() || !verifyCollection.bundleName.equals(hapVerifyInfo.getBundleName())) { @@ -417,12 +440,6 @@ class HapVerify { LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); return false; } - if (verifyCollection.debug != hapVerifyInfo.isDebug()) { - String errMsg = "The debug parameter values are different."; - String solution = "Check if the debug setting is the same in different modules."; - LOG.error(PackingToolErrMsg.APP_FIELDS_DIFFERENT_ERROR.toString(errMsg, solution)); - return false; - } if (isEntryOrFeature(verifyCollection.getModuleType()) && isEntryOrFeature(hapVerifyInfo.getModuleType())) { if (!verifyCollection.getMultiAppMode().equals(hapVerifyInfo.getMultiAppMode())) { String errMsg = "The multiAppMode parameter values are different."; -- Gitee