From 7f32830dca3c9c9190bdfafa3d4ec26d12ce3beb Mon Sep 17 00:00:00 2001 From: z30034863 Date: Wed, 7 May 2025 16:23:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=89=93=E5=8C=85=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0pac.json=E6=96=87=E4=BB=B6=E6=89=93=E5=8C=85?= =?UTF-8?q?=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: z30034863 --- adapter/ohos/CommandParser.java | 5 +++++ adapter/ohos/CompressVerify.java | 28 ++++++++++++++++++++++++++++ adapter/ohos/Compressor.java | 17 ++++++++++++++++- adapter/ohos/Constants.java | 5 +++++ adapter/ohos/PackageUtil.java | 5 +++++ adapter/ohos/ShowHelp.java | 3 ++- adapter/ohos/Utility.java | 9 +++++++++ 7 files changed, 70 insertions(+), 2 deletions(-) diff --git a/adapter/ohos/CommandParser.java b/adapter/ohos/CommandParser.java index 19615008..bdec936f 100644 --- a/adapter/ohos/CommandParser.java +++ b/adapter/ohos/CommandParser.java @@ -65,6 +65,7 @@ public class CommandParser { private static final String CMD_OUT_PATH = "--out-path"; private static final String CMD_PACK_INFO_PATH = "--pack-info-path"; private static final String CMD_ENCRYPT_PATH = "--encrypt-path"; + private static final String CMD_PAC_JSON_PATH = "--pac-json-path"; private static final String CMD_BIN_PATH = "--bin-path"; private static final String CMD_JAR_PATH = "--jar-path"; private static final String CMD_TXT_PATH = "--txt-path"; @@ -249,6 +250,10 @@ public class CommandParser { entry.getKey().setEncryptPath(entry.getValue()); return true; }); + commandFuncs.put(CMD_PAC_JSON_PATH, entry -> { + entry.getKey().setPacJsonPath(entry.getValue()); + return true; + }); commandFuncs.put(CMD_BIN_PATH, entry -> { entry.getKey().setBinPath(entry.getValue()); return true; diff --git a/adapter/ohos/CompressVerify.java b/adapter/ohos/CompressVerify.java index 1bdd37d6..a6f535b2 100644 --- a/adapter/ohos/CompressVerify.java +++ b/adapter/ohos/CompressVerify.java @@ -715,6 +715,12 @@ public class CompressVerify { return false; } + if (!isValidPacJsonFile(utility)) { + String errMsg = "--pac-json-path is invalid."; + LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); + return false; + } + if (!utility.getSignaturePath().isEmpty() && !(new File(utility.getSignaturePath())).isFile()) { String errMsg = "--signature-path is invalid."; LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); @@ -835,6 +841,12 @@ public class CompressVerify { return false; } + if (!isValidPacJsonFile(utility)) { + String errMsg = "--pac-json-path is invalid."; + LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); + return false; + } + File outFile = new File(utility.getOutPath()); if (("false".equals(utility.getForceRewrite())) && outFile.exists()) { String errMsg = "--out-path file already exist, but --force is not 'true'."; @@ -1511,6 +1523,22 @@ public class CompressVerify { return true; } + /** + * Indicates whether the "--pac-json-path" parameter is valid. + * + * @param utility - compress parameters + * @return true if "--pac-json-path" param exists and the file name is pac.json, or the "--pac-json-path" + * param is empty, or has no "--pac-json-path" param + * false other situations + */ + private static boolean isValidPacJsonFile(Utility utility) { + if (!utility.getPacJsonPath().isEmpty()) { + File filePacJson = new File(utility.getPacJsonPath()); + return filePacJson.isFile() && Constants.FILE_PAC_JSON.equals(filePacJson.getName()); + } + return true; + } + private static boolean hasHomeExtensionAbility(Utility utility) { try { boolean result = false; diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index 256d7ef5..792de8d6 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -1464,6 +1464,8 @@ public class Compressor { compressFile(utility, file, NULL_DIR_NAME, false); // pack encrypt.json file packEncryptJsonFile(utility); + // pack pac.json file + packPacJsonFile(utility); } catch (BundleException e) { LOG.error(PackingToolErrMsg.COMPRESS_APP_FAILED.toString( "Compress app file exist BundleException: " + e.getMessage())); @@ -1521,6 +1523,8 @@ public class Compressor { pathToFile(utility, utility.getPackInfoPath(), NULL_DIR_NAME, false); // pack encrypt.json file packEncryptJsonFile(utility); + // pack pac.json file + packPacJsonFile(utility); // hap/hsp for (String hapPath : fileList) { HapVerifyInfo hapVerifyInfo = hapVerifyInfoMap.get(getFileNameByPath(hapPath)); @@ -1597,6 +1601,8 @@ public class Compressor { compressFile(utility, file, NULL_DIR_NAME, false); //pack encrypt.json file packEncryptJsonFile(utility); + // pack pac.json file + packPacJsonFile(utility); } catch (BundleException | IOException exception) { String errMsg = "Compress app mode for multi project file exist Exception (BundleException | IOException): " + exception.getMessage(); @@ -2675,7 +2681,8 @@ public class Compressor { if (!entryName.contains(RAW_FILE_PATH) && !entryName.contains(RES_FILE_PATH) && srcFile.getName().toLowerCase(Locale.ENGLISH).endsWith(JSON_SUFFIX) - && !entryName.equals(Constants.FILE_ENCRYPT_JSON)) { + && !entryName.equals(Constants.FILE_ENCRYPT_JSON) + && !entryName.equals(Constants.FILE_PAC_JSON)) { zipEntry.setMethod(ZipEntry.STORED); if (jsonSpecialProcess(utility, srcFile, zipEntry)) { return; @@ -3795,6 +3802,14 @@ public class Compressor { } } + private void packPacJsonFile(Utility utility) throws BundleException { + if (!utility.getPacJsonPath().isEmpty()) { + pathToFile(utility, utility.getPacJsonPath(), NULL_DIR_NAME, false); + } else { + LOG.info("Compressor::packPacJsonFile has no pac.json"); + } + } + private void generalNormalize(Utility utility) { List> recordList = new ArrayList<>(); Path tempDir = null; diff --git a/adapter/ohos/Constants.java b/adapter/ohos/Constants.java index 98d2cf23..11151542 100644 --- a/adapter/ohos/Constants.java +++ b/adapter/ohos/Constants.java @@ -151,6 +151,11 @@ public class Constants { */ public static final String FILE_ENCRYPT_JSON = "encrypt.json"; + /** + * Indicates the file name: pac.json + */ + public static final String FILE_PAC_JSON = "pac.json"; + /** * Indicates the file name: module.json */ diff --git a/adapter/ohos/PackageUtil.java b/adapter/ohos/PackageUtil.java index 6c246226..26335ccc 100644 --- a/adapter/ohos/PackageUtil.java +++ b/adapter/ohos/PackageUtil.java @@ -812,6 +812,11 @@ public class PackageUtil { LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--encrypt-path is invalid.")); return false; } + if (!utility.getPacJsonPath().isEmpty() + && !isFileValid(utility.getPacJsonPath(), Constants.FILE_PAC_JSON)) { + LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--pac-json-path is invalid.")); + return false; + } Path outPath = Paths.get(utility.getOutPath()); if (utility.getForceRewrite().equals(Constants.FALSE) && Files.exists(outPath)) { LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--out-path file already existed, but " + diff --git a/adapter/ohos/ShowHelp.java b/adapter/ohos/ShowHelp.java index bb0430db..b4f71c60 100644 --- a/adapter/ohos/ShowHelp.java +++ b/adapter/ohos/ShowHelp.java @@ -87,7 +87,8 @@ public interface ShowHelp { " out file if exists.\n" + " --signature-path signature file path.\n" + " --certificate-path certificate file path.\n" + - " --encrypt-path encrypt.json file path."); + " --encrypt-path encrypt.json file path." + + " --pac-json-path pac.json file path."); } /** diff --git a/adapter/ohos/Utility.java b/adapter/ohos/Utility.java index 3866fb82..c8597fc6 100644 --- a/adapter/ohos/Utility.java +++ b/adapter/ohos/Utility.java @@ -69,6 +69,7 @@ public class Utility { private String outPath = ""; private String packInfoPath = ""; private String encryptPath = ""; + private String pacJsonPath = ""; private String binPath = ""; private boolean isCompressNativeLibs = false; private String moduleName = ""; @@ -436,6 +437,14 @@ public class Utility { } } + public String getPacJsonPath() { + return pacJsonPath; + } + + public void setPacJsonPath(String pacJsonPath) { + this.pacJsonPath = pacJsonPath; + } + public String getJarPath() { return jarPath; } -- Gitee From 6a127acd653cf80d242aef56878e129e9093660a Mon Sep 17 00:00:00 2001 From: z30034863 Date: Wed, 7 May 2025 20:16:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Revert=20"=E6=89=93=E5=8C=85=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E5=A2=9E=E5=8A=A0pac.json=E6=96=87=E4=BB=B6=E6=89=93?= =?UTF-8?q?=E5=8C=85=E8=83=BD=E5=8A=9B"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 7f32830dca3c9c9190bdfafa3d4ec26d12ce3beb. --- adapter/ohos/CommandParser.java | 5 ----- adapter/ohos/CompressVerify.java | 28 ---------------------------- adapter/ohos/Compressor.java | 17 +---------------- adapter/ohos/Constants.java | 5 ----- adapter/ohos/PackageUtil.java | 5 ----- adapter/ohos/ShowHelp.java | 3 +-- adapter/ohos/Utility.java | 9 --------- 7 files changed, 2 insertions(+), 70 deletions(-) diff --git a/adapter/ohos/CommandParser.java b/adapter/ohos/CommandParser.java index bdec936f..19615008 100644 --- a/adapter/ohos/CommandParser.java +++ b/adapter/ohos/CommandParser.java @@ -65,7 +65,6 @@ public class CommandParser { private static final String CMD_OUT_PATH = "--out-path"; private static final String CMD_PACK_INFO_PATH = "--pack-info-path"; private static final String CMD_ENCRYPT_PATH = "--encrypt-path"; - private static final String CMD_PAC_JSON_PATH = "--pac-json-path"; private static final String CMD_BIN_PATH = "--bin-path"; private static final String CMD_JAR_PATH = "--jar-path"; private static final String CMD_TXT_PATH = "--txt-path"; @@ -250,10 +249,6 @@ public class CommandParser { entry.getKey().setEncryptPath(entry.getValue()); return true; }); - commandFuncs.put(CMD_PAC_JSON_PATH, entry -> { - entry.getKey().setPacJsonPath(entry.getValue()); - return true; - }); commandFuncs.put(CMD_BIN_PATH, entry -> { entry.getKey().setBinPath(entry.getValue()); return true; diff --git a/adapter/ohos/CompressVerify.java b/adapter/ohos/CompressVerify.java index a6f535b2..1bdd37d6 100644 --- a/adapter/ohos/CompressVerify.java +++ b/adapter/ohos/CompressVerify.java @@ -715,12 +715,6 @@ public class CompressVerify { return false; } - if (!isValidPacJsonFile(utility)) { - String errMsg = "--pac-json-path is invalid."; - LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); - return false; - } - if (!utility.getSignaturePath().isEmpty() && !(new File(utility.getSignaturePath())).isFile()) { String errMsg = "--signature-path is invalid."; LOG.error(PackingToolErrMsg.APP_MODE_ARGS_INVALID.toString(errMsg)); @@ -841,12 +835,6 @@ public class CompressVerify { return false; } - if (!isValidPacJsonFile(utility)) { - String errMsg = "--pac-json-path is invalid."; - LOG.error(PackingToolErrMsg.MULTI_APP_MODE_ARGS_INVALID.toString(errMsg)); - return false; - } - File outFile = new File(utility.getOutPath()); if (("false".equals(utility.getForceRewrite())) && outFile.exists()) { String errMsg = "--out-path file already exist, but --force is not 'true'."; @@ -1523,22 +1511,6 @@ public class CompressVerify { return true; } - /** - * Indicates whether the "--pac-json-path" parameter is valid. - * - * @param utility - compress parameters - * @return true if "--pac-json-path" param exists and the file name is pac.json, or the "--pac-json-path" - * param is empty, or has no "--pac-json-path" param - * false other situations - */ - private static boolean isValidPacJsonFile(Utility utility) { - if (!utility.getPacJsonPath().isEmpty()) { - File filePacJson = new File(utility.getPacJsonPath()); - return filePacJson.isFile() && Constants.FILE_PAC_JSON.equals(filePacJson.getName()); - } - return true; - } - private static boolean hasHomeExtensionAbility(Utility utility) { try { boolean result = false; diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index 792de8d6..256d7ef5 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -1464,8 +1464,6 @@ public class Compressor { compressFile(utility, file, NULL_DIR_NAME, false); // pack encrypt.json file packEncryptJsonFile(utility); - // pack pac.json file - packPacJsonFile(utility); } catch (BundleException e) { LOG.error(PackingToolErrMsg.COMPRESS_APP_FAILED.toString( "Compress app file exist BundleException: " + e.getMessage())); @@ -1523,8 +1521,6 @@ public class Compressor { pathToFile(utility, utility.getPackInfoPath(), NULL_DIR_NAME, false); // pack encrypt.json file packEncryptJsonFile(utility); - // pack pac.json file - packPacJsonFile(utility); // hap/hsp for (String hapPath : fileList) { HapVerifyInfo hapVerifyInfo = hapVerifyInfoMap.get(getFileNameByPath(hapPath)); @@ -1601,8 +1597,6 @@ public class Compressor { compressFile(utility, file, NULL_DIR_NAME, false); //pack encrypt.json file packEncryptJsonFile(utility); - // pack pac.json file - packPacJsonFile(utility); } catch (BundleException | IOException exception) { String errMsg = "Compress app mode for multi project file exist Exception (BundleException | IOException): " + exception.getMessage(); @@ -2681,8 +2675,7 @@ public class Compressor { if (!entryName.contains(RAW_FILE_PATH) && !entryName.contains(RES_FILE_PATH) && srcFile.getName().toLowerCase(Locale.ENGLISH).endsWith(JSON_SUFFIX) - && !entryName.equals(Constants.FILE_ENCRYPT_JSON) - && !entryName.equals(Constants.FILE_PAC_JSON)) { + && !entryName.equals(Constants.FILE_ENCRYPT_JSON)) { zipEntry.setMethod(ZipEntry.STORED); if (jsonSpecialProcess(utility, srcFile, zipEntry)) { return; @@ -3802,14 +3795,6 @@ public class Compressor { } } - private void packPacJsonFile(Utility utility) throws BundleException { - if (!utility.getPacJsonPath().isEmpty()) { - pathToFile(utility, utility.getPacJsonPath(), NULL_DIR_NAME, false); - } else { - LOG.info("Compressor::packPacJsonFile has no pac.json"); - } - } - private void generalNormalize(Utility utility) { List> recordList = new ArrayList<>(); Path tempDir = null; diff --git a/adapter/ohos/Constants.java b/adapter/ohos/Constants.java index 11151542..98d2cf23 100644 --- a/adapter/ohos/Constants.java +++ b/adapter/ohos/Constants.java @@ -151,11 +151,6 @@ public class Constants { */ public static final String FILE_ENCRYPT_JSON = "encrypt.json"; - /** - * Indicates the file name: pac.json - */ - public static final String FILE_PAC_JSON = "pac.json"; - /** * Indicates the file name: module.json */ diff --git a/adapter/ohos/PackageUtil.java b/adapter/ohos/PackageUtil.java index 26335ccc..6c246226 100644 --- a/adapter/ohos/PackageUtil.java +++ b/adapter/ohos/PackageUtil.java @@ -812,11 +812,6 @@ public class PackageUtil { LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--encrypt-path is invalid.")); return false; } - if (!utility.getPacJsonPath().isEmpty() - && !isFileValid(utility.getPacJsonPath(), Constants.FILE_PAC_JSON)) { - LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--pac-json-path is invalid.")); - return false; - } Path outPath = Paths.get(utility.getOutPath()); if (utility.getForceRewrite().equals(Constants.FALSE) && Files.exists(outPath)) { LOG.error(PackingToolErrMsg.FAST_APP_MODE_ARGS_INVALID.toString("--out-path file already existed, but " + diff --git a/adapter/ohos/ShowHelp.java b/adapter/ohos/ShowHelp.java index b4f71c60..bb0430db 100644 --- a/adapter/ohos/ShowHelp.java +++ b/adapter/ohos/ShowHelp.java @@ -87,8 +87,7 @@ public interface ShowHelp { " out file if exists.\n" + " --signature-path signature file path.\n" + " --certificate-path certificate file path.\n" + - " --encrypt-path encrypt.json file path." + - " --pac-json-path pac.json file path."); + " --encrypt-path encrypt.json file path."); } /** diff --git a/adapter/ohos/Utility.java b/adapter/ohos/Utility.java index c8597fc6..3866fb82 100644 --- a/adapter/ohos/Utility.java +++ b/adapter/ohos/Utility.java @@ -69,7 +69,6 @@ public class Utility { private String outPath = ""; private String packInfoPath = ""; private String encryptPath = ""; - private String pacJsonPath = ""; private String binPath = ""; private boolean isCompressNativeLibs = false; private String moduleName = ""; @@ -437,14 +436,6 @@ public class Utility { } } - public String getPacJsonPath() { - return pacJsonPath; - } - - public void setPacJsonPath(String pacJsonPath) { - this.pacJsonPath = pacJsonPath; - } - public String getJarPath() { return jarPath; } -- Gitee