From aec10b515f525b0b74d614f4078a44d280c37d66 Mon Sep 17 00:00:00 2001 From: xushizhe Date: Tue, 27 Jun 2023 22:45:51 +0800 Subject: [PATCH] fixed 819ac0e from https://gitee.com/xsz233/developtools_packing_tool/pulls/560 fix hqf Signed-off-by: xushizhe --- adapter/ohos/Compressor.java | 15 +++++++-------- adapter/ohos/ModuleJsonUtil.java | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index 6882bf68..22c6cb49 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -61,6 +61,7 @@ public class Compressor { private static final String UPPERCASE_PNG_SUFFIX = ".PNG"; private static final String CONFIG_JSON = "config.json"; private static final String MODULE_JSON = "module.json"; + private static final String PATCH_JSON = "patch.json"; private static final String NAME = "name"; private static final String NULL_DIR_NAME = ""; private static final String RES_DIR_NAME = "res/"; @@ -1956,14 +1957,6 @@ public class Compressor { BufferedReader bufferedReader = null; InputStreamReader inputStreamReader = null; - Optional optional = FileUtils.getFileContent(utility.getJsonPath()); - String jsonString = optional.get(); - if (isModuleJSON(utility.getJsonPath())) { - utility.setModuleName(ModuleJsonUtil.parseStageModuleName(jsonString)); - } else { - utility.setModuleName(ModuleJsonUtil.parseFaModuleName(jsonString)); - } - try { fileInputStream = new FileInputStream(srcFile); inputStreamReader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8); @@ -1971,10 +1964,16 @@ public class Compressor { bufferedReader.mark((int) srcFile.length() + 1); bufferedReader.reset(); String srcName = srcFile.getName().toLowerCase(Locale.ENGLISH); + Optional optional = FileUtils.getFileContent(utility.getJsonPath()); + String jsonString = optional.get(); if (CONFIG_JSON.equals(srcName)) { parseCompressNativeLibs(bufferedReader, utility); + utility.setModuleName(ModuleJsonUtil.parseFaModuleName(jsonString)); } else if (MODULE_JSON.equals(srcName)) { parseStageCompressNativeLibs(bufferedReader, utility); + utility.setModuleName(ModuleJsonUtil.parseStageModuleName(jsonString)); + } else if (PATCH_JSON.equals(srcName)) { + utility.setModuleName(ModuleJsonUtil.parsePatchModuleName(jsonString)); } bufferedReader.reset(); parseDeviceType(bufferedReader, utility); diff --git a/adapter/ohos/ModuleJsonUtil.java b/adapter/ohos/ModuleJsonUtil.java index 9b943e7b..bc17d302 100644 --- a/adapter/ohos/ModuleJsonUtil.java +++ b/adapter/ohos/ModuleJsonUtil.java @@ -329,6 +329,36 @@ class ModuleJsonUtil { return moduleName; } + /** + * get the moduleName from json file for hqf. + * + * @param jsonString uncompress json object + * @return the result + * @throws BundleException Throws this exception if the json is not standard. + */ + public static String parsePatchModuleName(String jsonString) throws BundleException { + String moduleName = ""; + JSONObject jsonObject; + try { + jsonObject = JSON.parseObject(jsonString); + JSONObject moduleObj = jsonObject.getJSONObject(MODULE); + if (moduleObj == null) { + LOG.error("ModuleJsonUtil:parsePatchModuleName failed: json file do not contain module."); + throw new BundleException("ModuleJsonUtil:parsePatchModuleName failed: json file do not contain module."); + } + if (!moduleObj.containsKey(NAME)) { + LOG.error("ModuleJsonUtil:parsePatchModuleName failed: json file do not contain moduleName."); + throw new BundleException( + "ModuleJsonUtil:parsePatchModuleName failed: json file do not contain moduleName."); + } + moduleName = moduleObj.getString(NAME); + } catch (BundleException | JSONException e) { + LOG.error("ModuleJsonUtil:parseFaModuleName failed"); + throw new BundleException("ModuleJsonUtil:parseFaModuleName failed"); + } + return moduleName; + } + /** * get the package from json file for stage module. * -- Gitee