From 86d3934627da041cef47152a5851109228ca9c57 Mon Sep 17 00:00:00 2001 From: zhrenqiang Date: Fri, 26 Apr 2024 16:19:05 +0800 Subject: [PATCH 01/20] add hnp_packages Signed-off-by: zhrenqiang --- modulecheck/module.json | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/modulecheck/module.json b/modulecheck/module.json index 902a85ee..7062e45b 100644 --- a/modulecheck/module.json +++ b/modulecheck/module.json @@ -135,7 +135,8 @@ "querySchemes", "routerMap", "appEnvironments", - "appStartup" + "appStartup", + "hnp_packages" ] }, "required": [ @@ -1464,6 +1465,35 @@ "type": "string", "pattern": "^[$]profile:[0-9a-zA-Z_.]+$", "maxLength": 255 + }, + "hnp_packages": { + "description": "Native package configuration file.", + "type": "array", + "items": { + "type": "object", + "propertyNames": { + "enum": [ + "package", + "type" + ] + }, + "properties": { + "package": { + "description": "Indicates the file name of native package.", + "type": "string", + "pattern": "^[a-zA-Z][0-9a-zA-Z_./]+$", + "maxLength": 255 + }, + "type": { + "description": "Indicates the type of native package.", + "type": "string", + "enum": [ + "public", + "private" + ] + } + } + } } } } -- Gitee From 83833bad08d94b212460431fde66deaff06f65c6 Mon Sep 17 00:00:00 2001 From: zhrenqiang Date: Fri, 10 May 2024 09:47:47 +0800 Subject: [PATCH 02/20] fix:json gbk -> utf8 Signed-off-by: zhrenqiang --- adapter/ohos/Compressor.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index 03e7549a..93b2c590 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; +import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -524,7 +525,8 @@ public class Compressor { String pretty = JSON.toJSONString(jsonObject, new SerializerFeature[]{ SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat}); - bw = new BufferedWriter(new FileWriter(utility.getJsonPath())); + bw = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream(utility.getJsonPath()), StandardCharsets.UTF_8)); bw.write(pretty); } catch (BundleException | IOException | JSONException exception) { LOG.error("Compressor::setGenerateBuildHash failed."); @@ -651,7 +653,7 @@ public class Compressor { moduleJson.put(BUILD_HASH, hash); String pretty = JSON.toJSONString(jsonObject, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat); - bw = new BufferedWriter(new FileWriter(jsonPath)); + bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(jsonPath), StandardCharsets.UTF_8)); bw.write(pretty); } catch (IOException e) { LOG.error("Compressor::putBuildHash failed, IOException: " + e.getMessage()); @@ -2974,7 +2976,8 @@ public class Compressor { try { String pretty = JSON.toJSONString(jsonObject, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat); - bw = new BufferedWriter(new FileWriter(jsonFilePath)); + bw = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream(jsonFilePath), StandardCharsets.UTF_8)); bw.write(pretty); } catch (IOException exception) { LOG.error("Compressor::writeJson failed for IOException " + exception.getMessage()); -- Gitee From 13c916de86e2386e620ea1f00444c42839debf59 Mon Sep 17 00:00:00 2001 From: zhrenqiang Date: Fri, 10 May 2024 18:09:15 +0800 Subject: [PATCH 03/20] check resources-path,ets-path, add log Signed-off-by: zhrenqiang --- adapter/ohos/CompressVerify.java | 10 ++++++++++ adapter/ohos/Compressor.java | 3 ++- adapter/ohos/Utility.java | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/adapter/ohos/CompressVerify.java b/adapter/ohos/CompressVerify.java index 520ee7dc..fbf0bc10 100644 --- a/adapter/ohos/CompressVerify.java +++ b/adapter/ohos/CompressVerify.java @@ -382,6 +382,11 @@ public class CompressVerify { return false; } + if (!utility.getEtsPath().isEmpty() && !isPathValid(utility.getEtsPath(), TYPE_DIR, null)) { + LOG.error("CompressVerify::isArgsValidInHapMode ets-path is invalid."); + return false; + } + return isOutPathValid(utility, HAP_SUFFIX); } @@ -944,6 +949,11 @@ public class CompressVerify { } } + if (!utility.getEtsPath().isEmpty() && !isPathValid(utility.getEtsPath(), TYPE_DIR, null)) { + LOG.error("CompressVerify::isArgsValidInHspMode ets-path is invalid."); + return false; + } + return isOutPathValid(utility, HSP_SUFFIX); } diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index 03e7549a..212c1312 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -2381,8 +2381,9 @@ public class Compressor { // compress data zipOut.putArchiveEntry(entry); zipOut.write(trimJson); - } catch (IOException exception) { + } catch (Exception exception) { LOG.error("Compressor::jsonSpecialProcess io exception: " + exception.getMessage()); + LOG.warning("Json format err: " + srcFile.getAbsolutePath()); throw new BundleException("Json special process failed."); } finally { Utility.closeStream(bufferedReader); diff --git a/adapter/ohos/Utility.java b/adapter/ohos/Utility.java index 8d58a0e6..b7ffcbf1 100644 --- a/adapter/ohos/Utility.java +++ b/adapter/ohos/Utility.java @@ -41,6 +41,7 @@ public class Utility { static final String FALSE_STRING = "false"; static final String TRUE_STRING = "true"; + private static final String INVALID_PATH = "invalid"; private static final String CMD_PREFIX = "--"; private static final Log LOG = new Log(Utility.class.toString()); @@ -664,7 +665,7 @@ public class Utility { try { canonicalPath = file.getCanonicalPath(); } catch (IOException exception) { - canonicalPath = ""; + canonicalPath = INVALID_PATH; LOG.error("Utility::getFormattedPath exception," + exception.getMessage()); } return canonicalPath; -- Gitee From bf59c798b5186bea084dc2fb57b7738ce0f05270 Mon Sep 17 00:00:00 2001 From: zhrenqiang Date: Sat, 11 May 2024 20:47:53 +0800 Subject: [PATCH 04/20] catch JSONException Signed-off-by: zhrenqiang --- adapter/ohos/JsonUtil.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/adapter/ohos/JsonUtil.java b/adapter/ohos/JsonUtil.java index 1ad3360a..5dce29cf 100644 --- a/adapter/ohos/JsonUtil.java +++ b/adapter/ohos/JsonUtil.java @@ -1530,12 +1530,16 @@ public class JsonUtil { if (jsonStr.isEmpty()) { continue; } - JSONObject jsonObj = JSON.parseObject(jsonStr); - if (jsonObj.containsKey("shortcuts")) { - JSONArray shortcutObjs = jsonObj.getJSONArray("shortcuts"); - for (int j = 0; j < shortcutObjs.size(); ++j) { - shortcuts.add(parseModuleShortcutObj(shortcutObjs.getJSONObject(j), data)); + try { + JSONObject jsonObj = JSON.parseObject(jsonStr); + if (jsonObj.containsKey("shortcuts")) { + JSONArray shortcutObjs = jsonObj.getJSONArray("shortcuts"); + for (int j = 0; j < shortcutObjs.size(); ++j) { + shortcuts.add(parseModuleShortcutObj(shortcutObjs.getJSONObject(j), data)); + } } + } catch (JSONException ignore) { + LOG.warning("ignored metadata: " + moduleMetadataInfo.name); } } return shortcuts; -- Gitee From e12a4e6c918caea90d4e745ad5c17874ed07b7e7 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Tue, 14 May 2024 14:44:53 +0800 Subject: [PATCH 05/20] modify runOnThread enum Signed-off-by: xinking129 --- modulecheck/appStartup.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modulecheck/appStartup.json b/modulecheck/appStartup.json index 2bc3d176..0d399e99 100644 --- a/modulecheck/appStartup.json +++ b/modulecheck/appStartup.json @@ -64,7 +64,7 @@ "type": "string", "enum": [ "mainThread", - "taskpool" + "taskPool" ], "default": "mainThread" }, -- Gitee From 833102a3513ad0389c3efdf914252d99ae787ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Tue, 14 May 2024 15:42:20 +0800 Subject: [PATCH 06/20] =?UTF-8?q?update=20packing=20tool=20Signed-off-by:?= =?UTF-8?q?=20=E5=AD=99=E6=97=AD=E8=BE=89=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README_zh.md | 1 + adapter/ohos/CommandParser.java | 5 +++++ adapter/ohos/CompressVerify.java | 5 +++++ adapter/ohos/Compressor.java | 10 ++++++++++ adapter/ohos/Utility.java | 5 +++++ 5 files changed, 26 insertions(+) diff --git a/README_zh.md b/README_zh.md index 85914a39..268852d9 100644 --- a/README_zh.md +++ b/README_zh.md @@ -52,6 +52,7 @@ java -jar app_packing_tool.jar --mode hap --json-path