diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index 6882bf681c27d3d33122b0a8d9a254b346d80cd1..22c6cb49200188ac6142847dc759d0a2f07a0990 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 9b943e7b32364ad4de944a32af8fd9dc8746d6f9..c7e4cd47d19b80e484321c35195df14a1db085ce 100644 --- a/adapter/ohos/ModuleJsonUtil.java +++ b/adapter/ohos/ModuleJsonUtil.java @@ -89,7 +89,7 @@ class ModuleJsonUtil { private static final String DEFAULT = "default"; private static final String COMPILE_SDK_VERSION = "compileSdkVersion"; private static final String COMPILE_SDK_TYPE = "compileSdkType"; - private static final String PROXY_DATAS = "proxyDatas"; + private static final String PROXY_DATA = "proxyData"; private static final String PROXY_URI = "uri"; private static final Log LOG = new Log(ModuleJsonUtil.class.toString()); @@ -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. * @@ -1390,12 +1420,12 @@ class ModuleJsonUtil { throw new BundleException("parse JOSNObject failed in parseProxyDataUri."); } JSONObject moduleObj = jsonObject.getJSONObject(MODULE); - if (!moduleObj.containsKey(PROXY_DATAS)) { + if (!moduleObj.containsKey(PROXY_DATA)) { return proxyDataUris; } - JSONArray proxyDatas = moduleObj.getJSONArray(PROXY_DATAS); - for (int i = 0; i < proxyDatas.size(); ++i) { - JSONObject itemObj = proxyDatas.getJSONObject(i); + JSONArray proxyData = moduleObj.getJSONArray(PROXY_DATA); + for (int i = 0; i < proxyData.size(); ++i) { + JSONObject itemObj = proxyData.getJSONObject(i); if (!itemObj.containsKey(PROXY_URI)) { LOG.error("parse JOSNObject failed in parseProxyDataUri."); throw new BundleException("parse JOSNObject failed in parseProxyDataUri."); diff --git a/modulecheck/module.json b/modulecheck/module.json index b7a671bcc3aafac529362094bd61e8fd7a1f2454..3b96a6eb0453808dba5d10853237801cb892abbb 100644 --- a/modulecheck/module.json +++ b/modulecheck/module.json @@ -127,7 +127,7 @@ "compressNativeLibs", "atomicService", "generateBuildHash", - "proxyDatas", + "proxyData", "isolationMode" ] }, @@ -174,7 +174,7 @@ "compressNativeLibs", "atomicService", "generateBuildHash", - "proxyDatas", + "proxyData", "isolationMode" ] }, @@ -1241,7 +1241,7 @@ "type": "boolean", "default": false }, - "proxyDatas": { + "proxyData": { "description": "Indicates all the proxy data of the module.", "type": "array", "items": {