From 98f25dcc8ad3c2c7400d58e0f1ba715411b8b4ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Wed, 31 Jul 2024 11:17:14 +0800 Subject: [PATCH 01/27] add test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- ohos_packing_tool/frameworks/BUILD.gn | 41 +- .../frameworks/include/app_log_wrapper.h | 81 + .../frameworks/include/hap_packager.h | 5 +- .../frameworks/include/json/dependency_item.h | 31 + .../frameworks/include/json/distro_filter.h | 57 + .../frameworks/include/json/hap_verify_info.h | 358 +++ .../frameworks/include/json/hqf_info.h | 122 + .../frameworks/include/json/json_utils.h | 53 + .../include/json/module_api_version.h | 31 + .../frameworks/include/json/module_json.h | 187 ++ .../include/json/module_json_utils.h | 46 + .../include/json/module_metadata_info.h | 31 + .../frameworks/include/json/multi_app_mode.h | 31 + .../frameworks/include/json/pack_info.h | 95 + .../frameworks/include/json/pack_info_utils.h | 53 + .../frameworks/include/json/patch_json.h | 77 + .../include/json/patch_json_utils.h | 42 + .../frameworks/include/json/preload_item.h | 29 + .../frameworks/include/json/pt_json.h | 126 + .../frameworks/include/json/version.h | 31 + ohos_packing_tool/frameworks/include/log.h | 41 + .../frameworks/include/unzip_wrapper.h | 57 + ohos_packing_tool/frameworks/include/utils.h | 58 + .../frameworks/include/zip_constants.h | 58 + .../frameworks/include/zip_utils.h | 54 + .../frameworks/include/zip_wrapper.h | 75 + .../frameworks/src/hap_packager.cpp | 28 +- .../frameworks/src/json/distro_filter.cpp | 168 ++ .../frameworks/src/json/hap_verify_info.cpp | 40 + .../frameworks/src/json/json_utils.cpp | 79 + .../frameworks/src/json/module_json.cpp | 2152 +++++++++++++++++ .../frameworks/src/json/module_json_utils.cpp | 252 ++ .../frameworks/src/json/pack_info.cpp | 548 +++++ .../frameworks/src/json/pack_info_utils.cpp | 252 ++ .../frameworks/src/json/patch_json.cpp | 364 +++ .../frameworks/src/json/patch_json_utils.cpp | 57 + .../frameworks/src/json/pt_json.cpp | 555 +++++ ohos_packing_tool/frameworks/src/log.cpp | 56 + .../frameworks/src/unzip_wrapper.cpp | 143 ++ ohos_packing_tool/frameworks/src/utils.cpp | 251 ++ .../frameworks/src/zip_utils.cpp | 291 +++ .../frameworks/src/zip_wrapper.cpp | 166 ++ .../test/unittest/hap_packager_test/BUILD.gn | 39 + .../hap_packager_test/hap_packager_test.cpp | 116 + .../test/unittest/hsp_packager_test/BUILD.gn | 39 + .../hsp_packager_test/hsp_packager_test.cpp | 116 + .../unittest/json/distro_filter_test/BUILD.gn | 38 + .../distro_filter_test/distro_filter_test.cpp | 88 + .../unittest/json/patch_json_test/BUILD.gn | 38 + .../json/patch_json_test/patch_json_test.cpp | 345 +++ .../test/unittest/json/pt_json_test/BUILD.gn | 37 + .../json/pt_json_test/pt_json_test.cpp | 502 ++++ .../test/unittest/shell_command_test/BUILD.gn | 41 + .../shell_command_test/shell_command_test.cpp | 234 ++ .../test/unittest/unzip_wrapper_test/BUILD.gn | 39 + .../unzip_wrapper_test/unzip_wrapper_test.cpp | 121 + .../test/unittest/utils_Test/BUILD.gn | 37 + .../test/unittest/utils_Test/utils_test.cpp | 257 ++ .../test/unittest/zip_utils_test/BUILD.gn | 41 + .../zip_utils_test/zip_utils_test.cpp | 217 ++ .../test/unittest/zip_wrapper_test/BUILD.gn | 38 + .../zip_wrapper_test/zip_wrapper_test.cpp | 190 ++ 62 files changed, 9829 insertions(+), 16 deletions(-) create mode 100644 ohos_packing_tool/frameworks/include/app_log_wrapper.h create mode 100644 ohos_packing_tool/frameworks/include/json/dependency_item.h create mode 100644 ohos_packing_tool/frameworks/include/json/distro_filter.h create mode 100644 ohos_packing_tool/frameworks/include/json/hap_verify_info.h create mode 100644 ohos_packing_tool/frameworks/include/json/hqf_info.h create mode 100644 ohos_packing_tool/frameworks/include/json/json_utils.h create mode 100644 ohos_packing_tool/frameworks/include/json/module_api_version.h create mode 100644 ohos_packing_tool/frameworks/include/json/module_json.h create mode 100644 ohos_packing_tool/frameworks/include/json/module_json_utils.h create mode 100644 ohos_packing_tool/frameworks/include/json/module_metadata_info.h create mode 100644 ohos_packing_tool/frameworks/include/json/multi_app_mode.h create mode 100644 ohos_packing_tool/frameworks/include/json/pack_info.h create mode 100644 ohos_packing_tool/frameworks/include/json/pack_info_utils.h create mode 100644 ohos_packing_tool/frameworks/include/json/patch_json.h create mode 100644 ohos_packing_tool/frameworks/include/json/patch_json_utils.h create mode 100644 ohos_packing_tool/frameworks/include/json/preload_item.h create mode 100644 ohos_packing_tool/frameworks/include/json/pt_json.h create mode 100644 ohos_packing_tool/frameworks/include/json/version.h create mode 100644 ohos_packing_tool/frameworks/include/log.h create mode 100644 ohos_packing_tool/frameworks/include/unzip_wrapper.h create mode 100644 ohos_packing_tool/frameworks/include/utils.h create mode 100644 ohos_packing_tool/frameworks/include/zip_constants.h create mode 100644 ohos_packing_tool/frameworks/include/zip_utils.h create mode 100644 ohos_packing_tool/frameworks/include/zip_wrapper.h create mode 100644 ohos_packing_tool/frameworks/src/json/distro_filter.cpp create mode 100644 ohos_packing_tool/frameworks/src/json/hap_verify_info.cpp create mode 100644 ohos_packing_tool/frameworks/src/json/json_utils.cpp create mode 100644 ohos_packing_tool/frameworks/src/json/module_json.cpp create mode 100644 ohos_packing_tool/frameworks/src/json/module_json_utils.cpp create mode 100644 ohos_packing_tool/frameworks/src/json/pack_info.cpp create mode 100644 ohos_packing_tool/frameworks/src/json/pack_info_utils.cpp create mode 100644 ohos_packing_tool/frameworks/src/json/patch_json.cpp create mode 100644 ohos_packing_tool/frameworks/src/json/patch_json_utils.cpp create mode 100644 ohos_packing_tool/frameworks/src/json/pt_json.cpp create mode 100644 ohos_packing_tool/frameworks/src/log.cpp create mode 100644 ohos_packing_tool/frameworks/src/unzip_wrapper.cpp create mode 100644 ohos_packing_tool/frameworks/src/utils.cpp create mode 100644 ohos_packing_tool/frameworks/src/zip_utils.cpp create mode 100644 ohos_packing_tool/frameworks/src/zip_wrapper.cpp create mode 100644 ohos_packing_tool/frameworks/test/unittest/hap_packager_test/BUILD.gn create mode 100644 ohos_packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_test.cpp create mode 100644 ohos_packing_tool/frameworks/test/unittest/hsp_packager_test/BUILD.gn create mode 100644 ohos_packing_tool/frameworks/test/unittest/hsp_packager_test/hsp_packager_test.cpp create mode 100644 ohos_packing_tool/frameworks/test/unittest/json/distro_filter_test/BUILD.gn create mode 100644 ohos_packing_tool/frameworks/test/unittest/json/distro_filter_test/distro_filter_test.cpp create mode 100644 ohos_packing_tool/frameworks/test/unittest/json/patch_json_test/BUILD.gn create mode 100644 ohos_packing_tool/frameworks/test/unittest/json/patch_json_test/patch_json_test.cpp create mode 100644 ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/BUILD.gn create mode 100644 ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp create mode 100644 ohos_packing_tool/frameworks/test/unittest/shell_command_test/BUILD.gn create mode 100644 ohos_packing_tool/frameworks/test/unittest/shell_command_test/shell_command_test.cpp create mode 100644 ohos_packing_tool/frameworks/test/unittest/unzip_wrapper_test/BUILD.gn create mode 100644 ohos_packing_tool/frameworks/test/unittest/unzip_wrapper_test/unzip_wrapper_test.cpp create mode 100644 ohos_packing_tool/frameworks/test/unittest/utils_Test/BUILD.gn create mode 100644 ohos_packing_tool/frameworks/test/unittest/utils_Test/utils_test.cpp create mode 100644 ohos_packing_tool/frameworks/test/unittest/zip_utils_test/BUILD.gn create mode 100644 ohos_packing_tool/frameworks/test/unittest/zip_utils_test/zip_utils_test.cpp create mode 100644 ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/BUILD.gn create mode 100644 ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp diff --git a/ohos_packing_tool/frameworks/BUILD.gn b/ohos_packing_tool/frameworks/BUILD.gn index 78bb699a..9e24b093 100644 --- a/ohos_packing_tool/frameworks/BUILD.gn +++ b/ohos_packing_tool/frameworks/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. +# Copyright (c) 2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -14,21 +14,58 @@ import("//build/ohos.gni") ohos_executable("ohos_packing_tool") { - include_dirs = [ "include" ] + include_dirs = [ + "include", + "include/json" + ] sources = [ "src/hap_packager.cpp", "src/hsp_packager.cpp", "src/main.cpp", "src/packager.cpp", "src/shell_command.cpp", + "src/zip_wrapper.cpp", + "src/unzip_wrapper.cpp", + "src/zip_utils.cpp", + "src/log.cpp", + "src/utils.cpp", + "src/json/distro_filter.cpp", + "src/json/hap_verify_info.cpp", + "src/json/json_utils.cpp", + "src/json/module_json.cpp", + "src/json/module_json_utils.cpp", + "src/json/pack_info.cpp", + "src/json/pack_info_utils.cpp", + "src/json/patch_json.cpp", + "src/json/patch_json_utils.cpp", + "src/json/pt_json.cpp", ] configs = [] cflags = [] external_deps = [ "json:nlohmann_json_static", + "cJSON:cjson", + "hilog:libhilog", "zlib:libz", + "openssl:libcrypto_shared", ] install_enable = false subsystem_name = "developtools" part_name = "packing_tool" } + +group("unittest") { + testonly = true + deps = [ + "test/unittest/hap_packager_test:hap_packager_test", + "test/unittest/hsp_packager_test:hsp_packager_test", + "test/unittest/shell_command_test:shell_command_test", + "test/unittest/unzip_wrapper_test:unzip_wrapper_test", + "test/unittest/utils_Test:utils_Test", + "test/unittest/zip_utils_test:zip_utils_test", + "test/unittest/zip_wrapper_test:zip_wrapper_test", + "test/unittest/json/distro_filter_test:distro_filter_test", + "test/unittest/json/pt_json_test:pt_json_test", + "test/unittest/json/patch_json_test:patch_json_test", + ] +} \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/include/app_log_wrapper.h b/ohos_packing_tool/frameworks/include/app_log_wrapper.h new file mode 100644 index 00000000..360631d7 --- /dev/null +++ b/ohos_packing_tool/frameworks/include/app_log_wrapper.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_APPEXECFWK_STANDARD_COMMON_LOG_INCLUDE_APP_LOG_WRAPPER_H +#define FOUNDATION_APPEXECFWK_STANDARD_COMMON_LOG_INCLUDE_APP_LOG_WRAPPER_H + +#include "hilog/log.h" +#include + +namespace OHOS { +namespace AppExecFwk { +#ifndef LOG_DOMAIN +#define LOG_DOMAIN 0xD001100 +#endif + +#ifndef APP_LOG_TAG +#define APP_LOG_TAG "BundleMgrService" +#endif + +enum class AppLogLevel { DEBUG = 0, INFO, WARN, ERROR, FATAL }; + +static constexpr OHOS::HiviewDFX::HiLogLabel APP_LABEL = {LOG_CORE, LOG_DOMAIN, APP_LOG_TAG}; + +class AppLogWrapper { +public: + static bool JudgeLevel(const AppLogLevel &level); + + static void SetLogLevel(const AppLogLevel &level) + { + level_ = level; + } + + static const AppLogLevel &GetLogLevel() + { + return level_; + } + + static std::string GetBriefFileName(const char *str); + +private: + static AppLogLevel level_; +}; + +#define FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) +#define APP_LOGD(fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, LOG_DOMAIN, APP_LOG_TAG, \ + "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)) +#define APP_LOGI(fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, LOG_DOMAIN, APP_LOG_TAG, \ + "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)) +#define APP_LOGW(fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, LOG_DOMAIN, APP_LOG_TAG, \ + "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)) +#define APP_LOGE(fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, LOG_DOMAIN, APP_LOG_TAG, \ + "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)) +#define APP_LOGF(fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, LOG_DOMAIN, APP_LOG_TAG, \ + "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)) + +#define APP_LOGI_NOFUNC(fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, LOG_DOMAIN, APP_LOG_TAG, fmt, ##__VA_ARGS__)) +#define APP_LOGW_NOFUNC(fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, LOG_DOMAIN, APP_LOG_TAG, fmt, ##__VA_ARGS__)) +#define APP_LOGE_NOFUNC(fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, LOG_DOMAIN, APP_LOG_TAG, fmt, ##__VA_ARGS__)) +} // namespace AppExecFwk +} // namespace OHOS +#endif // FOUNDATION_APPEXECFWK_STANDARD_COMMON_LOG_INCLUDE_APP_LOG_WRAPPER_H diff --git a/ohos_packing_tool/frameworks/include/hap_packager.h b/ohos_packing_tool/frameworks/include/hap_packager.h index a6e14287..4054ee45 100644 --- a/ohos_packing_tool/frameworks/include/hap_packager.h +++ b/ohos_packing_tool/frameworks/include/hap_packager.h @@ -21,7 +21,7 @@ #include #include "packager.h" - +#include "zip_wrapper.h" namespace OHOS { namespace AppPackingTool { @@ -35,6 +35,9 @@ protected: int PreProcess() override; int Process() override; int PostProcess() override; + +private: + ZipWrapper zipWrapper_; }; } // namespace AppExecFwk diff --git a/ohos_packing_tool/frameworks/include/json/dependency_item.h b/ohos_packing_tool/frameworks/include/json/dependency_item.h new file mode 100644 index 00000000..b10b98c5 --- /dev/null +++ b/ohos_packing_tool/frameworks/include/json/dependency_item.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_DEPENDENCY_ITEM_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_DEPENDENCY_ITEM_H + +#include + +namespace OHOS { +namespace AppPackingTool { +struct DependencyItem { + std::string bundleName = ""; + std::string moduleName = ""; + int versionCode = 0; +}; +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_DEPENDENCY_ITEM_H diff --git a/ohos_packing_tool/frameworks/include/json/distro_filter.h b/ohos_packing_tool/frameworks/include/json/distro_filter.h new file mode 100644 index 00000000..0fe94505 --- /dev/null +++ b/ohos_packing_tool/frameworks/include/json/distro_filter.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_DISTRO_FILTER_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_DISTRO_FILTER_H + +#include +#include +#include + +namespace OHOS { +namespace AppPackingTool { + +struct PolicyValue { + std::string policy = ""; + std::list value; + + bool ParseFromString(const std::string& jsonString); + + bool IsEmpty() const; +}; + +typedef PolicyValue ApiVersion; +typedef PolicyValue ScreenShape; +typedef PolicyValue ScreenDensity; +typedef PolicyValue ScreenWindow; +typedef PolicyValue CountryCode; + +struct DistroFilter { + ApiVersion apiVersion; + ScreenShape screenShape; + ScreenDensity screenDensity; + ScreenWindow screenWindow; + CountryCode countryCode; + + bool ParseFromString(const std::string& jsonString); + + bool IsEmpty() const; + + std::string Dump(); +}; +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_DISTRO_FILTER_H diff --git a/ohos_packing_tool/frameworks/include/json/hap_verify_info.h b/ohos_packing_tool/frameworks/include/json/hap_verify_info.h new file mode 100644 index 00000000..61541159 --- /dev/null +++ b/ohos_packing_tool/frameworks/include/json/hap_verify_info.h @@ -0,0 +1,358 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_HAP_VERIFY_INFO_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_HAP_VERIFY_INFO_H + +#include +#include +#include +#include "version.h" +#include "module_api_version.h" +#include "distro_filter.h" +#include "dependency_item.h" +#include "preload_item.h" +#include "multi_app_mode.h" + +namespace OHOS { +namespace AppPackingTool { + + +class HapVerifyInfo { +public: + HapVerifyInfo(); + virtual ~HapVerifyInfo(); + + // HapVerifyInfo(const HapVerifyInfo &) = delete; + // HapVerifyInfo &operator=(const HapVerifyInfo &) = delete; + + const std::string& GetBundleName() const { + return bundleName_; + } + + void SetBundleName(const std::string& bundleName) { + bundleName_ = bundleName; + } + + const std::string& GetVendor() const { + return vendor_; + } + + void SetVendor(const std::string& vendor) { + vendor_ = vendor; + } + + const Version& GetVersion() const { + return version_; + } + + void SetVersion(const Version& version) { + version_ = version; + } + + const ModuleApiVersion& GetApiVersion() const { + return apiVersion_; + } + + void SetApiVersion(const ModuleApiVersion& apiVersion) { + apiVersion_ = apiVersion; + } + + const std::string& GetModuleName() const { + return moduleName_; + } + + void SetModuleName(const std::string& moduleName) { + moduleName_ = moduleName; + } + + const std::string& GetPackageName() const { + return packageName_; + } + + void SetPackageName(const std::string& packageName) { + packageName_ = packageName; + } + + const std::list& GetAbilityNames() const { + return abilityNames_; + } + + void SetAbilityNames(const std::list& abilityNames) { + abilityNames_ = abilityNames; + } + + void AddAbilityNames(const std::list& nameList) { + abilityNames_.insert(abilityNames_.end(), nameList.begin(), nameList.end()); + } + + const DistroFilter& GetDistroFilter() const { + return distroFilter_; + } + + void SetDistroFilter(const DistroFilter& distroFilter) { + distroFilter_ = distroFilter; + } + + const std::list& GetDeviceTypes() const { + return deviceTypes_; + } + + void SetDeviceTypes(const std::list& deviceTypes) { + deviceTypes_ = deviceTypes; + } + + const bool& IsStageModule() const { + return isStageModule_; + } + + void SetStageModule(const bool& isStageModule) { + isStageModule_ = isStageModule; + } + + const std::string& GetModuleType() const { + return moduleType_; + } + + void SetModuleType(const std::string& moduleType) { + moduleType_ = moduleType; + } + + const bool& IsInstallationFree() const { + return isInstallationFree_; + } + + void SetInstallationFree(const bool& isInstallationFree) { + isInstallationFree_ = isInstallationFree; + } + + const std::list& GetDependencies() const { + return dependencies_; + } + + void SetDependencies(const std::list& dependencies) { + dependencies_ = dependencies; + } + + const std::list& getDependencyItemList() const { + return dependencyItemList_; + } + + void SetDependencyItemList(const std::list& dependencyItemList) { + dependencyItemList_ = dependencyItemList; + ConvertToDependency(); + } + + // SUNJIAN: profile str is json string + const std::string& GetProfileStr() const { + return profileStr_; + } + + void SetProfileStr(const std::string& profileStr) { + profileStr_ = profileStr; + } + + const std::map& GetResourceMap() const { + return resourceMap_; + } + + void SetResourceMap(const std::map& resourceMap) { + resourceMap_ = resourceMap; + } + + const std::string& GetBundleType() const { + return bundleType_; + } + + void SetBundleType(const std::string& bundleType) { + bundleType_ = bundleType; + } + + const std::string& getAtomicServiceType() const { + return atomicServiceType_; + } + + void SetAtomicServiceType(const std::string& atomicServiceType) { + atomicServiceType_ = atomicServiceType; + } + + const std::list& GetPreloadItems() const { + return preloadItems_; + } + + void SetPreloadItems(const std::list& preloadItems) { + preloadItems_ = preloadItems; + } + + const std::string& GetTargetBundleName() const { + return targetBundleName_; + } + + void SetTargetBundleName(const std::string& targetBundleName) { + targetBundleName_ = targetBundleName; + } + + const int& GetTargetPriority() const { + return targetPriority_; + } + + void SetTargetPriority(const int& priority) { + targetPriority_ = priority; + } + + const std::string& GetTargetModuleName() const { + return targetModuleName_; + } + + void SetTargetModuleName(const std::string& targetModuleName) { + targetModuleName_ = targetModuleName; + } + + const int& GetTargetModulePriority() const { + return targetModulePriority_; + } + + void SetTargetModulePriority(const int& priority) { + targetModulePriority_ = priority; + } + + // SUNJIAN: the json file size + const int64_t& GetFileLength() const { + return fileLength_; + } + + void SetFileLength(const int64_t& fileLength) { + fileLength_ = fileLength; + } + + // SUNJIAN: What's this? + const int& GetEntrySizeLimit() const { + return entrySizeLimit_; + } + + void SetEntrySizeLimit(const int& limit) { + entrySizeLimit_ = limit; + } + + // SUNJIAN: What's this? + const int& GetNotEntrySizeLimit() const { + return notEntrySizeLimit_; + } + + void SetNotEntrySizeLimit(const int& notEntrySizeLimit) { + notEntrySizeLimit_ = notEntrySizeLimit; + } + + // SUNJIAN: What's this? + const int& GetSumSizeLimit() const { + return sumSizeLimit_; + } + + void SetSumSizeLimit(const int& sumSizeLimit) { + sumSizeLimit_ = sumSizeLimit; + } + + const bool& IsDebug() const { + return debug_; + } + + void SetDebug(const bool& debug) { + debug_ = debug; + } + + const std::string& GetCompileSdkVersion() const { + return compileSdkVersion_; + } + + void SetCompileSdkVersion(const std::string& compileSdkVersion) { + compileSdkVersion_ = compileSdkVersion; + } + + const std::string& GetCompileSdkType() const { + return compileSdkType_; + } + + void SetCompileSdkType(const std::string& compileSdkType) { + compileSdkType_ = compileSdkType; + } + + const std::list& GetProxyDataUris() const { + return proxyDataUris_; + } + + void SetProxyDataUris(const std::list& proxyDataUris) { + proxyDataUris_ = proxyDataUris; + } + + const std::map>& GetContinueTypeMap() const { + return continueTypeMap_; + } + + void SetContinueTypeMap(const std::map>& continueTypeMap) { + continueTypeMap_ = continueTypeMap; + } + + const MultiAppMode& GetMultiAppMode() const { + return multiAppMode_; + } + + void SetMultiAppMode(const MultiAppMode& multiAppMode) { + multiAppMode_ = multiAppMode; + } + +private: + void ConvertToDependency(); + +private: + std::string bundleName_ = ""; + std::string vendor_ = ""; + Version version_; + ModuleApiVersion apiVersion_; + std::string moduleName_ = ""; + std::string packageName_ = ""; + std::list abilityNames_; + DistroFilter distroFilter_; + std::list deviceTypes_; + bool isStageModule_ = true; + std::string moduleType_ = ""; + std::string atomicServiceType_ = ""; + bool isInstallationFree_ = false; + std::list dependencies_; + std::list dependencyItemList_; + std::string profileStr_ = ""; + std::map resourceMap_; + std::string bundleType_ = "app"; + std::string targetBundleName_ = ""; + int targetPriority_ = 0; + std::string targetModuleName_ = ""; + int targetModulePriority_ = 0; + std::list preloadItems_; + int64_t fileLength_ = 0L; + int entrySizeLimit_ = 2; + int notEntrySizeLimit_ = 2; + int sumSizeLimit_ = 10; + bool debug_ = false; + std::string compileSdkVersion_ = ""; + std::string compileSdkType_ = ""; + std::list proxyDataUris_; + std::map> continueTypeMap_; + MultiAppMode multiAppMode_; + +}; + +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_HAP_VERIFY_INFO_H diff --git a/ohos_packing_tool/frameworks/include/json/hqf_info.h b/ohos_packing_tool/frameworks/include/json/hqf_info.h new file mode 100644 index 00000000..eead0257 --- /dev/null +++ b/ohos_packing_tool/frameworks/include/json/hqf_info.h @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_HQF_INFO_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_HQF_INFO_H + +#include +#include +#include + +namespace OHOS { +namespace AppPackingTool { + +class HqfInfo { +public: + HqfInfo() {}; + virtual ~HqfInfo() {}; + + // HqfInfo(const HqfInfo &) = delete; + // HqfInfo &operator=(const HqfInfo &) = delete; + + const std::string& GetBundleName() const { + return bundleName_; + } + + void SetBundleName(const std::string& bundleName) { + bundleName_ = bundleName; + } + + const int32_t& GetVersionCode() const { + return versionCode_; + } + + void SetVersionCode(const int32_t& versionCode) { + versionCode_ = versionCode; + } + + const std::string& GetVersionName() const { + return versionName_; + } + + void SetVersionName(const std::string& versionName) { + versionName_ = versionName; + } + + const int32_t& GetPatchVersionCode() const { + return patchVersionCode_; + } + + void SetPatchVersionCode(const int32_t& patchVersionCode) { + patchVersionCode_ = patchVersionCode; + } + + const std::string& GetPatchVersionName() const { + return patchVersionName_; + } + + void SetPatchVersionName(const std::string& patchVersionName) { + patchVersionName_ = patchVersionName; + } + + const std::string& GetModuleName() const { + return moduleName_; + } + + void SetModuleName(const std::string& moduleName) { + moduleName_ = moduleName; + } + + const std::string& GetType() const { + return type_; + } + + void SetType(const std::string& type) { + type_ = type; + } + + const std::list& GetDeviceTypes() const { + return deviceTypes_; + } + + void SetDeviceTypes(const std::list& deviceTypes) { + deviceTypes_ = deviceTypes; + } + + const std::string& GetOriginalModuleHash() const { + return originalModuleHash_; + } + + void SetOriginalModuleHash(const std::string& originalModuleHash) { + originalModuleHash_ = originalModuleHash; + } + +private: + std::string bundleName_ = ""; + int32_t versionCode_ = -1; + std::string versionName_ = ""; + int32_t patchVersionCode_ = -1; + std::string patchVersionName_ = ""; + + std::string moduleName_ = ""; + std::string type_ = ""; + std::list deviceTypes_; + std::string originalModuleHash_ = ""; +}; + +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_HQF_INFO_H diff --git a/ohos_packing_tool/frameworks/include/json/json_utils.h b/ohos_packing_tool/frameworks/include/json/json_utils.h new file mode 100644 index 00000000..c8e1f1fc --- /dev/null +++ b/ohos_packing_tool/frameworks/include/json/json_utils.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_JSON_UTILS_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_JSON_UTILS_H + +#include +#include +#include +#include "pt_json.h" + +namespace fs = std::filesystem; + +namespace OHOS { +namespace AppPackingTool { + +const std::string MODULE_JSON = "module.json"; +const std::string CONFIG_JSON = "config.json"; +const std::string PATCH_JSON = "patch.json"; + +class JsonUtils { +public: + JsonUtils(); + virtual ~JsonUtils(); + + JsonUtils(const JsonUtils &) = delete; + JsonUtils &operator=(const JsonUtils &) = delete; + + static bool CheckFileName(const std::string filePath, const std::string fileName); + static bool IsModuleJson(const std::string filePath); + static bool IsConfigJson(const std::string filePath); + static bool IsPatchJson(const std::string filePath); + + static std::unique_ptr JsonFromFile(const std::string filePath); + static bool JsonToFile(std::unique_ptr json, const std::string filePath); +}; + +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_JSON_UTILS_H diff --git a/ohos_packing_tool/frameworks/include/json/module_api_version.h b/ohos_packing_tool/frameworks/include/json/module_api_version.h new file mode 100644 index 00000000..503514ce --- /dev/null +++ b/ohos_packing_tool/frameworks/include/json/module_api_version.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_MODULE_API_VERSION_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_MODULE_API_VERSION_H + +#include + +namespace OHOS { +namespace AppPackingTool { +struct ModuleApiVersion { + int compatibleApiVersion = -1; + int targetApiVersion = -1; + std::string releaseType = ""; +}; +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_MODULE_API_VERSION_H diff --git a/ohos_packing_tool/frameworks/include/json/module_json.h b/ohos_packing_tool/frameworks/include/json/module_json.h new file mode 100644 index 00000000..00242606 --- /dev/null +++ b/ohos_packing_tool/frameworks/include/json/module_json.h @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_MODULE_JSON_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_MODULE_JSON_H + +#include +#include +#include +#include +#include "pt_json.h" +#include "version.h" +#include "module_api_version.h" +#include "hap_verify_info.h" +#include "module_metadata_info.h" + +namespace OHOS { +namespace AppPackingTool { + +class ModuleJson { +public: + ModuleJson(); + virtual ~ModuleJson(); + + // ModuleJson(const ModuleJson &) = delete; + // ModuleJson &operator=(const ModuleJson &) = delete; + + bool ParseFromString(const std::string& jsonString); + bool ParseFromFile(const std::string& jsonFile); + std::string ToString(); + void Release(); + + bool IsValid(); + + // object funcs + bool GetAppObject(std::unique_ptr& appObj); + bool GetVersionObject(std::unique_ptr& versionObj); + bool GetModuleObject(std::unique_ptr& moduleObj); + bool GetDistroObject(std::unique_ptr& distroObj); + bool GetDistroObjectByModuleObj(std::unique_ptr& moduleObj, std::unique_ptr& distroObj); + bool GetApiVersionObject(std::unique_ptr& apiVersion); + + // stage funcs, module.json + bool GetStageVersion(Version& version); + bool GetStageVersionByAppObj(std::unique_ptr& obj, Version& version); + bool SetStageVersionCode(const int& versionCode); + bool SetStageVersionName(const std::string& versionName); + bool GetStageModuleApiVersion(ModuleApiVersion& moduleApiVersion); + bool GetStageModuleApiVersionByAppObj(std::unique_ptr& obj, ModuleApiVersion& moduleApiVersion); + bool GetStageModuleName(std::string& moduleName); + bool GetStageModuleNameByModuleObj(std::unique_ptr& obj, std::string& moduleName); + bool GetStageEntry(std::list& deviceTypes); + bool GetStageDeviceTypes(std::list& deviceTypes); + bool GetStageDeviceTypesByModuleObj(std::unique_ptr& obj, std::list& deviceTypes); + bool GetStageHapVerifyInfo(HapVerifyInfo& hapVerifyInfo); + bool GetStageDistroFilter(DistroFilter& distroFilter); + bool GetStageDistroFilterByModuleObj(std::unique_ptr& obj, DistroFilter& distroFilter); + bool GetStageInstallationFree(bool& installationFree); + bool GetStageInstallationFreeByModuleObj(std::unique_ptr& obj, bool& installationFree); + bool GetStageBundleType(std::string& bundleType); + bool GetStageCompileSdkType(std::string& compileSdkType); + bool GetStageCompileSdkTypeByAppObj(std::unique_ptr& obj, std::string& compileSdkType); + bool GetStageCompileSdkVersion(std::string& compileSdkVersion); + bool GetStageCompileSdkVersionByAppObj(std::unique_ptr& obj, std::string& compileSdkVersion); + bool GetStageModuleType(std::string& moduleType); + bool GetStageModuleTypeByModuleObj(std::unique_ptr& obj, std::string& moduleType); + bool GetStageDebug(bool& debug); + bool GetStageDebugByAppObj(std::unique_ptr& obj, bool& debug); + bool GetStageAsanEnabled(bool& asanEnabled); + bool GetStageAsanEnabledByAppObj(std::unique_ptr& obj, bool& asanEnabled); + bool GetStageTsanEnabled(bool& tsanEnabled); + bool GetStageTsanEnabledByAppObj(std::unique_ptr& obj, bool& tsanEnabled); + bool GetStageApiReleaseType(std::string& apiReleaseType); + bool GetStageApiReleaseTypeByAppObj(std::unique_ptr& obj, std::string& apiReleaseType); + bool GetStageCompressNativeLibs(bool& compressNativeLibs); + bool GetStageCompressNativeLibsByAppObj(std::unique_ptr& obj, bool& compressNativeLibs); + bool GetAbilityContinueTypeMap(std::map>& abilityContinueTypeMap); + bool GetAbilityContinueTypeMapByModuleObj(std::unique_ptr& obj, std::map>& abilityContinueTypeMap); + bool GetExtensionAbilityNames(std::list& extensionAbilityNames); + bool GetExtensionAbilityNamesByModuleObj(std::unique_ptr& obj, std::list& extensionAbilityNames); + bool GetModuleMetadatas(std::list& moduleMetadataInfos); + bool GetModuleMetadatasByModuleObj(std::unique_ptr& obj, std::list& moduleMetadataInfos); + bool ParseModuleMetadatasToDistroFilter(const std::list& moduleMetadataInfos, DistroFilter& distroFilter); + + bool IsExistedStageRequestPermissions(); + bool IsExistedStageModuleTargetPriority(); + bool IsExistedStageAppTargetPriority(); + + // fa funcs config.json + bool GetFaVersion(Version& version); + bool GetFaVersionByAppObj(std::unique_ptr& obj, Version& version); + bool GetFaVersionByVersionObj(std::unique_ptr& obj, Version& version); + bool SetFaVersionCode(const int& versionCode); + bool SetFaVersionName(const std::string& versionName); + bool GetFaInstallationFree(bool& installationFree); + bool GetFaInstallationFreeByModuleObj(std::unique_ptr& obj, bool& installationFree); + bool GetFaInstallationFreeByDistroObj(std::unique_ptr& obj, bool& installationFree); + bool GetFaBundleType(std::string& bundleType); + bool GetFaModuleApiVersion(ModuleApiVersion& moduleApiVersion); + bool GetFaModuleApiVersionByAppObj(std::unique_ptr& obj, ModuleApiVersion& moduleApiVersion); + bool GetFaModuleApiVersionByApiVersionObj(std::unique_ptr& obj, ModuleApiVersion& moduleApiVersion); + bool GetFaModuleName(std::string& faModuleName); + bool GetFaModuleNameByModuleObj(std::unique_ptr& obj, std::string& faModuleName); + bool GetFaModuleNameByDistroObj(std::unique_ptr& obj, std::string& faModuleName); + bool GetFaPackageStr(std::string& packageStr); + bool GetFaPackageStrByModuleObj(std::unique_ptr& obj, std::string& packageStr); + bool GetFaEntry(std::list& deviceTypes); + bool GetFaDeviceTypes(std::list& deviceTypes); + bool GetFaDeviceTypesByModuleObj(std::unique_ptr& obj, std::list& deviceTypes); + bool GetFaHapVerifyInfo(HapVerifyInfo& hapVerifyInfo); + bool GetFaDistroFilter(DistroFilter& distroFilter); + bool GetFaDistroFilterByModuleObj(std::unique_ptr& obj, DistroFilter& distroFilter); + bool GetFaCompileSdkType(std::string& compileSdkType); + bool GetFaCompileSdkTypeByAppObj(std::unique_ptr& obj, std::string& compileSdkType); + bool GetFaCompileSdkVersion(std::string& compileSdkVersion); + bool GetFaCompileSdkVersionByAppObj(std::unique_ptr& obj, std::string& compileSdkVersion); + bool GetFaModuleType(std::string& moduleType); + bool GetFaModuleTypeByModuleObj(std::unique_ptr& obj, std::string& moduleType); + bool GetFaDebug(bool& debug); + bool GetFaDebugByAppObj(std::unique_ptr& obj, bool& debug); + bool GetFaAsanEnabled(bool& asanEnabled); + bool GetFaAsanEnabledByAppObj(std::unique_ptr& obj, bool& asanEnabled); + bool GetFaReleaseType(std::string& releaseType); + bool GetFaReleaseTypeByAppObj(std::unique_ptr& obj, std::string& releaseType); + + // common funcs + bool GetBundleName(std::string& bundleName); + bool GetBundleNameByAppObj(std::unique_ptr& obj, std::string& bundleName); + bool SetBundleName(const std::string& bundleName); + bool GetModuleName(std::string& moduleName); + bool GetModuleNameByModuleObj(std::unique_ptr& obj, std::string& moduleName); + bool GetVendor(std::string& vendor); + bool GetVendorByAppObj(std::unique_ptr& obj, std::string& vendor); + bool GetTargetBundleName(std::string& targetBundleName); + bool GetTargetBundleNameByAppObj(std::unique_ptr& obj, std::string& targetBundleName); + bool GetTargetModuleName(std::string& targetModuleName); + bool GetTargetModuleNameByModuleObj(std::unique_ptr& obj, std::string& targetModuleName); + bool GetTargetPriority(int32_t& targetPriority); + bool GetTargetPriorityByAppObj(std::unique_ptr& obj, int32_t& targetPriority); + bool GetTargetModulePriority(int32_t& targetModulePriority); + bool GetTargetModulePriorityByModuleObj(std::unique_ptr& obj, int32_t& targetModulePriority); + // config.json or module.json + bool GetAbilityNames(std::list& abilityNames); + bool GetAbilityNamesByModuleObj(std::unique_ptr& obj, std::list& abilityNames); + // unknown + bool GetDependencyItems(std::list& dependencyItems, const std::string& defaultBundleName); + bool GetDependencyItemsByModuleObj(std::unique_ptr& obj, std::list& dependencyItems, const std::string& defaultBundleName); + bool GetAtomicServicePreloads(std::list& preloadItems); + bool GetAtomicServicePreloadsByModuleObj(std::unique_ptr& obj, std::list& preloadItems); + bool GetProxyDataUris(std::list& proxyDataUris); + bool GetProxyDataUrisByModuleObj(std::unique_ptr& obj, std::list& proxyDataUris); + bool GetProxyDataUrisByProxyDatasObj(std::unique_ptr& obj, std::list& proxyDataUris); + bool GetMultiAppMode(MultiAppMode& multiAppMode); + bool GetMultiAppModeByAppObj(std::unique_ptr& obj, MultiAppMode& multiAppMode); + + bool IsModuleAtomicServiceValid(); + bool CheckEntryInAtomicService(); + bool CheckAtomicServiceInstallationFree(); + + bool GetGenerateBuildHash(bool& generateBuildHash); + bool RemoveGenerateBuildHash(); + bool RemoveGenerateBuildHashFromAppObj(); + bool RemoveGenerateBuildHashFromModuleObj(); + + // json function for hqf + bool GetPatchModuleName(std::string& patchModuleName); + +private: + std::unique_ptr root_ = nullptr; +}; + +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_MODULE_JSON_H diff --git a/ohos_packing_tool/frameworks/include/json/module_json_utils.h b/ohos_packing_tool/frameworks/include/json/module_json_utils.h new file mode 100644 index 00000000..f3d4b4f2 --- /dev/null +++ b/ohos_packing_tool/frameworks/include/json/module_json_utils.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_MODULE_JSON_UTILS_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_MODULE_JSON_UTILS_H + +#include +#include "hap_verify_info.h" + +namespace OHOS { +namespace AppPackingTool { + +class ModuleJsonUtils { +public: + ModuleJsonUtils(); + virtual ~ModuleJsonUtils(); + + ModuleJsonUtils(const ModuleJsonUtils &) = delete; + ModuleJsonUtils &operator=(const ModuleJsonUtils &) = delete; + + static bool GetStageHapVerifyInfo(const std::string& hapFilePath, HapVerifyInfo& hapVerifyInfo); + static bool GetFaHapVerifyInfo(const std::string& hapFilePath, HapVerifyInfo& hapVerifyInfo); + static bool CheckHapsIsValid(const std::list& fileList, const bool& isSharedApp); + static bool IsModuleHap(const std::string hapFilePath); + +private: + static bool CheckSharedAppIsValid(const std::list& hapVerifyInfos, bool& isOverlay); + static bool CheckDuplicatedIsValid(const HapVerifyInfo& hapVerifyInfo1, const HapVerifyInfo& hapVerifyInfo2); + static bool CheckPolicyValueDisjoint(const PolicyValue& policyValue1, const PolicyValue& policyValue2); +}; +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_MODULE_JSON_UTILS_H diff --git a/ohos_packing_tool/frameworks/include/json/module_metadata_info.h b/ohos_packing_tool/frameworks/include/json/module_metadata_info.h new file mode 100644 index 00000000..04ca65f9 --- /dev/null +++ b/ohos_packing_tool/frameworks/include/json/module_metadata_info.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_MODULE_METADATA_INFO_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_MODULE_METADATA_INFO_H + +#include + +namespace OHOS { +namespace AppPackingTool { +struct ModuleMetadataInfo { + std::string name = ""; + std::string value = ""; + std::string resource = ""; +}; +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_MODULE_METADATA_INFO_H diff --git a/ohos_packing_tool/frameworks/include/json/multi_app_mode.h b/ohos_packing_tool/frameworks/include/json/multi_app_mode.h new file mode 100644 index 00000000..973488a1 --- /dev/null +++ b/ohos_packing_tool/frameworks/include/json/multi_app_mode.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_MULTI_APP_MODE_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_MULTI_APP_MODE_H + +#include + +namespace OHOS { +namespace AppPackingTool { +// java : java has two override functions: equals() and hashCode() +struct MultiAppMode { + std::string multiAppModeType = ""; + int maxCount = 0; +}; +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_MULTI_APP_MODE_H diff --git a/ohos_packing_tool/frameworks/include/json/pack_info.h b/ohos_packing_tool/frameworks/include/json/pack_info.h new file mode 100644 index 00000000..ada57a1d --- /dev/null +++ b/ohos_packing_tool/frameworks/include/json/pack_info.h @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PACK_INFO_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PACK_INFO_H + +#include +#include +#include "pt_json.h" + +namespace OHOS { +namespace AppPackingTool { +struct PackInfoVersion { + int code = -1; + std::string name = ""; +}; + +class PackInfo { +public: + PackInfo(); + virtual ~PackInfo(); + + // PackInfo(const PackInfo &) = delete; + // PackInfo &operator=(const PackInfo &) = delete; + + bool ParseFromString(const std::string& jsonString); + bool ParseFromFile(const std::string& jsonFile); + std::string ToString(); + void Release(); + + bool IsValid(); + + // object funcs + bool GetSummaryObject(std::unique_ptr& summaryObj); + bool GetPackagesObject(std::unique_ptr& packagesObj); + bool GetAppObject(std::unique_ptr& appObj); + bool GetModulesObject(std::unique_ptr& modulesObj); + bool GetVersionObject(std::unique_ptr& versionObj); + bool GetDistroObject(int32_t moduleIndex, std::unique_ptr& distroObj); + bool GetDistroObjectByModulesObj(const std::unique_ptr& modulesObj, + int32_t moduleIndex, std::unique_ptr& distroObj); + bool GetDistroObjectByModuleObj(const std::unique_ptr& moduleObj, + std::unique_ptr& distroObj); + bool GetPackageObject(int32_t packageIndex, std::unique_ptr& packageObj); + bool GetExtensionAbilitiesObj(int32_t moduleIndex, std::unique_ptr& extensionAbilitiesObj); + bool GetExtensionAbilitiesObjByModulesObj(const std::unique_ptr& modulesObj, + int32_t moduleIndex, std::unique_ptr& extensionAbilitiesObj); + bool GetExtensionAbilitiesObjByModuleObj(const std::unique_ptr& moduleObj, + std::unique_ptr& extensionAbilitiesObj); + bool GetFormsObjByExtensionAbilityObj(const std::unique_ptr& extensionAbilityObj, + std::unique_ptr& formsObj); + + // funcs + bool GetBundleName(std::string& bundleName); + bool GetBundleNameByAppObj(const std::unique_ptr& appObj, std::string& bundleName); + bool SetBundleName(const std::string& bundleName); + bool GetBundleType(std::string& bundleType, const std::string& defaultBundleType); + bool GetBundleTypeByAppObj(const std::unique_ptr& appObj, std::string& bundleType, + const std::string& defaultBundleType); + bool GetVersion(PackInfoVersion& version); + bool GetVersionByVersionObj(const std::unique_ptr& appObj, PackInfoVersion& version); + bool SetVersionCode(const int& versionCode); + bool SetVersionName(const std::string& versionName); + bool GetModuleNameByDistroObj(const std::unique_ptr& distroObj, std::string& moduleName); + bool GetNameByPackageObj(const std::unique_ptr& packageObj, std::string& name); + bool GetNameByFormObj(const std::unique_ptr& formObj, std::string& name); + bool GetDefaultDimensionByFormObj(const std::unique_ptr& formObj, std::string& defaultDimension); + bool GetSupportDimensionsByFormObj(const std::unique_ptr& formObj, std::list& supportDimensions); + bool GetFormNames(std::list& formNames, std::list& formFullNames); + bool GetFormNamesByExtensionAbilitiesObj(const std::unique_ptr& extensionAbilitiesObj, + std::string moduleName, std::list& formNames, std::list& formFullNames); + bool GetFormNamesByFormsObj(const std::unique_ptr& formsObj, + std::string moduleName, std::list& formNames, std::list& formFullNames); + + +private: + std::unique_ptr root_ = nullptr; +}; + +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PACK_INFO_H diff --git a/ohos_packing_tool/frameworks/include/json/pack_info_utils.h b/ohos_packing_tool/frameworks/include/json/pack_info_utils.h new file mode 100644 index 00000000..ff83b1d5 --- /dev/null +++ b/ohos_packing_tool/frameworks/include/json/pack_info_utils.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PACK_INFO_UTILS_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PACK_INFO_UTILS_H + +#include +#include +#include "pt_json.h" +#include "pack_info.h" + +namespace OHOS { +namespace AppPackingTool { + +class PackInfoUtils { +public: + PackInfoUtils(); + virtual ~PackInfoUtils(); + + PackInfoUtils(const PackInfoUtils &) = delete; + PackInfoUtils &operator=(const PackInfoUtils &) = delete; + + static bool MergeTwoPackInfos(std::string& srcPackInfoJsonStr1, std::string& srcPackInfoJsonStr2, + std::string& dstPackInfoJsonStr); + static bool MergeTwoPackInfosByPackagePair(std::string& srcPackInfoJsonStr1, std::string& srcPackInfoJsonStr2, + std::map, std::string& dstPackInfoJsonStr); + +private: + static bool MergeTwoPackInfos(PackInfo& srcPackInfo1, PackInfo& srcPackInfo2); + static bool MergeTwoPackInfosByPackagePair(PackInfo& srcPackInfo1, PackInfo& srcPackInfo2, + std::string& packageName, std::string& moduleName); + static bool VerifyPackInfos(PackInfo& finalPackInfo, PackInfo& srcPackInfo); + static bool CheckBundleNameInPackInfo(PackInfo& packInfo1, PackInfo& packInfo2); + static bool CheckBundleTypeInPackInfo(PackInfo& packInfo1, PackInfo& packInfo2); + static bool CheckVersionCodeInPackInfo(PackInfo& packInfo1, PackInfo& packInfo2); +}; + +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_MODULE_JSON_UTILS_H diff --git a/ohos_packing_tool/frameworks/include/json/patch_json.h b/ohos_packing_tool/frameworks/include/json/patch_json.h new file mode 100644 index 00000000..0e1a5a70 --- /dev/null +++ b/ohos_packing_tool/frameworks/include/json/patch_json.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PATCH_JSON_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PATCH_JSON_H + +#include +#include +#include "pt_json.h" +#include "hqf_info.h" + +namespace OHOS { +namespace AppPackingTool { + +class PatchJson { +public: + PatchJson(); + virtual ~PatchJson(); + + // PatchJson(const PatchJson &) = delete; + // PatchJson &operator=(const PatchJson &) = delete; + + bool ParseFromString(const std::string& jsonString); + bool ParseFromFile(const std::string& jsonFile); + std::string ToString(); + void Release(); + + bool IsValid(); + + // // object funcs + bool GetAppObject(std::unique_ptr& appObj); + bool GetModuleObject(std::unique_ptr& moduleObj); + + // app funcs + bool GetBundleName(std::string& bundleName); + bool GetBundleNameByAppObj(const std::unique_ptr& appObj, std::string& bundleName); + bool GetVersionCode(int32_t& versionCode); + bool GetVersionCodeByAppObj(const std::unique_ptr& appObj, int32_t& versionCode); + bool GetVersionName(std::string& versionName); + bool GetVersionNameByAppObj(const std::unique_ptr& appObj, std::string& versionName); + bool GetPatchVersionCode(int32_t& patchVersionCode); + bool GetPatchVersionCodeByAppObj(const std::unique_ptr& appObj, int32_t& patchVersionCode); + bool GetPatchVersionName(std::string& patchVersionName); + bool GetPatchVersionNameByAppObj(const std::unique_ptr& appObj, std::string& patchVersionName); + + // module funcs + bool GetName(std::string& name); + bool GetNameByModuleObj(const std::unique_ptr& moduleObj, std::string& name); + bool GetType(std::string& type); + bool GetTypeByModuleObj(const std::unique_ptr& moduleObj, std::string& type); + bool GetDeviceTypes(std::list& deviceTypes); + bool GetDeviceTypesByModuleObj(const std::unique_ptr& moduleObj, std::list& deviceTypes); + bool GetOriginalModuleHash(std::string& originalModuleHash); + bool GetOriginalModuleHashByModuleObj(const std::unique_ptr& moduleObj, std::string& originalModuleHash); + + bool GetHqfInfo(HqfInfo& hqfInfo); + +private: + std::unique_ptr root_ = nullptr; +}; + +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PATCH_JSON_H diff --git a/ohos_packing_tool/frameworks/include/json/patch_json_utils.h b/ohos_packing_tool/frameworks/include/json/patch_json_utils.h new file mode 100644 index 00000000..2e08b4f7 --- /dev/null +++ b/ohos_packing_tool/frameworks/include/json/patch_json_utils.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PATCH_JSON_UTILS_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PATCH_JSON_UTILS_H + +#include +#include +#include "patch_json.h" +#include "hqf_info.h" + +namespace OHOS { +namespace AppPackingTool { + +class PatchJsonUtils { +public: + PatchJsonUtils(); + virtual ~PatchJsonUtils(); + + PatchJsonUtils(const PatchJsonUtils &) = delete; + PatchJsonUtils &operator=(const PatchJsonUtils &) = delete; + + static bool ParsePatchByJsonFilePath(const std::string& patchJsonFilePath, HqfInfo& hqfInfo); + static bool ParsePatchByJsonStr(const std::string& patchJsonStr, HqfInfo& hqfInfo); +}; + +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PATCH_JSON_UTILS_H diff --git a/ohos_packing_tool/frameworks/include/json/preload_item.h b/ohos_packing_tool/frameworks/include/json/preload_item.h new file mode 100644 index 00000000..fc748789 --- /dev/null +++ b/ohos_packing_tool/frameworks/include/json/preload_item.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PRELOAD_ITEM_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PRELOAD_ITEM_H + +#include + +namespace OHOS { +namespace AppPackingTool { +struct PreloadItem { + std::string moduleName = ""; +}; +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_PRELOAD_ITEM_H diff --git a/ohos_packing_tool/frameworks/include/json/pt_json.h b/ohos_packing_tool/frameworks/include/json/pt_json.h new file mode 100644 index 00000000..6a993e7a --- /dev/null +++ b/ohos_packing_tool/frameworks/include/json/pt_json.h @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_TOOLING_BASE_PT_JSON_H +#define ECMASCRIPT_TOOLING_BASE_PT_JSON_H + +#include +#include + +#include "cJSON.h" + +namespace OHOS { +namespace AppPackingTool { + +enum class Result : uint8_t { + SUCCESS, + NOT_EXIST, + TYPE_ERROR, +}; + +class PtJson { +public: + PtJson() = default; + explicit PtJson(cJSON *object) : object_(object) {} + ~PtJson() = default; + + // Create empty json object + static std::unique_ptr CreateObject(); + static std::unique_ptr CreateArray(); + + // Release cJSON object memory + void ReleaseRoot(); + + // String parse to json + static std::unique_ptr Parse(const std::string &data); + + // To string + std::string Stringify() const; + + // Add Json child + bool Add(const char *key, bool value) const; + bool Add(const char *key, int32_t value) const; + bool Add(const char *key, int64_t value) const; + bool Add(const char *key, uint32_t value) const; + bool Add(const char *key, double value) const; + bool Add(const char *key, const char *value) const; + bool Add(const char *key, const std::unique_ptr &value) const; + + // Push back to array + bool Push(bool value) const; + bool Push(int32_t value) const; + bool Push(int64_t value) const; + bool Push(uint32_t value) const; + bool Push(double value) const; + bool Push(const char *value) const; + bool Push(const std::unique_ptr &value) const; + + // Remove Json child + bool Remove(const char *key) const; + + bool Contains(const char *key) const; + + std::string GetKey() const; + + cJSON *GetJson() const; + + // Type check + bool IsBool() const; + bool IsNumber() const; + bool IsString() const; + bool IsObject() const; + bool IsArray() const; + bool IsNull() const; + + // Object accessor + bool GetBool(bool defaultValue = false) const; + int32_t GetInt(int32_t defaultValue = 0) const; + int64_t GetInt64(int64_t defaultValue = 0) const; + uint32_t GetUInt(uint32_t defaultValue = 0) const; + uint64_t GetUInt64(uint64_t defaultValue = 0) const; + double GetDouble(double defaultValue = 0.0) const; + std::string GetString() const; + + // Array accessor + int32_t GetSize() const; + std::unique_ptr Get(int32_t index) const; + + // Child item accessor + Result GetBool(const char *key, bool *value) const; + Result GetInt(const char *key, int32_t *value) const; + Result GetInt64(const char *key, int64_t *value) const; + Result GetUInt(const char *key, uint32_t *value) const; + Result GetUInt64(const char *key, uint64_t *value) const; + Result GetDouble(const char *key, double *value) const; + Result GetString(const char *key, std::string *value) const; + Result GetObject(const char *key, std::unique_ptr *value) const; + Result GetArray(const char *key, std::unique_ptr *value) const; + Result GetAny(const char *key, std::unique_ptr *value) const; + + Result SetBool(const char *key, const bool& value); + Result SetInt(const char *key, const int32_t& value); + Result SetInt64(const char *key, const int64_t& value); + Result SetUInt(const char *key, const uint32_t& value); + Result SetUInt64(const char *key, const uint64_t& value); + Result SetDouble(const char *key, const double& value); + Result SetString(const char *key, const std::string& value); + +private: + cJSON *object_ = nullptr; +}; +} // namespace AppPackingTool +} // namespace OHOS + +#endif // ECMASCRIPT_TOOLING_BASE_PT_JSON_H diff --git a/ohos_packing_tool/frameworks/include/json/version.h b/ohos_packing_tool/frameworks/include/json/version.h new file mode 100644 index 00000000..1051ca11 --- /dev/null +++ b/ohos_packing_tool/frameworks/include/json/version.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_VERSION_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_VERSION_H + +#include + +namespace OHOS { +namespace AppPackingTool { +struct Version { + int versionCode = -1; + std::string versionName = ""; + int minCompatibleVersionCode = -1; +}; +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_VERSION_H diff --git a/ohos_packing_tool/frameworks/include/log.h b/ohos_packing_tool/frameworks/include/log.h new file mode 100644 index 00000000..c8b9e009 --- /dev/null +++ b/ohos_packing_tool/frameworks/include/log.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_LOG_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_LOG_H + +namespace OHOS { +namespace AppPackingTool { + +enum LOG_LEVEL { + LOG_LEVEL_DEBUG = 0, + LOG_LEVEL_INFO, + LOG_LEVEL_WARN, + LOG_LEVEL_ERROR, + LOG_LEVEL_FATAL +}; + +void log(char *file, char *func, int line, int level, char *format, ...); + +#define LOGD(format, ...) log((char *)__FILE__, (char *)__func__, __LINE__, LOG_LEVEL_DEBUG, (char *)format, ##__VA_ARGS__) +#define LOGI(format, ...) log((char *)__FILE__, (char *)__func__, __LINE__, LOG_LEVEL_INFO, (char *)format, ##__VA_ARGS__) +#define LOGW(format, ...) log((char *)__FILE__, (char *)__func__, __LINE__, LOG_LEVEL_WARN, (char *)format, ##__VA_ARGS__) +#define LOGE(format, ...) log((char *)__FILE__, (char *)__func__, __LINE__, LOG_LEVEL_ERROR, (char *)format, ##__VA_ARGS__) +#define LOGF(format, ...) log((char *)__FILE__, (char *)__func__, __LINE__, LOG_LEVEL_FATAL, (char *)format, ##__VA_ARGS__) + +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_ZIP_UTILS_H diff --git a/ohos_packing_tool/frameworks/include/unzip_wrapper.h b/ohos_packing_tool/frameworks/include/unzip_wrapper.h new file mode 100644 index 00000000..80eb0081 --- /dev/null +++ b/ohos_packing_tool/frameworks/include/unzip_wrapper.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_UNZIP_WRAPPER_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_UNZIP_WRAPPER_H + +#include +#include "zip_constants.h" + +namespace OHOS { +namespace AppPackingTool { + +#define ZIP_FILE_ATTR_DIRECTORY 16 + +class UnzipWrapper { +public: + UnzipWrapper(); + explicit UnzipWrapper(std::string path); + virtual ~UnzipWrapper(); + + UnzipWrapper(const UnzipWrapper &) = delete; + UnzipWrapper &operator=(const UnzipWrapper &) = delete; + + int Open(std::string& unzPath); + int Open(); + void Close(); + int UnzipFile(std::string filePath); + + bool IsOpen() const { + return (unzFile_ != nullptr); + } + +protected: + std::string ExtractFile(const std::string filePath); + +private: + unzFile unzFile_ = nullptr; + unz_global_info64 unzGlobalInfo_; + std::string unzFilePath_; +}; + +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_UNZIP_WRAPPER_H diff --git a/ohos_packing_tool/frameworks/include/utils.h b/ohos_packing_tool/frameworks/include/utils.h new file mode 100644 index 00000000..17328566 --- /dev/null +++ b/ohos_packing_tool/frameworks/include/utils.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_UTILS_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_UTILS_H + +#include +#include +#include + +namespace OHOS { +namespace AppPackingTool { + +class Utils +{ +public: + Utils(); + virtual ~Utils(); + + Utils(const Utils &) = delete; + Utils &operator=(const Utils &) = delete; + + static std::string GetFileContent(const std::string filePath); + static std::string ListToString(const std::list& lst); + static std::string ReplaceAll(std::string str, const std::string& from, const std::string& to); + static int64_t GetFileLength(const std::string filePath); + static bool EndsWith(const std::string& str, const std::string& suffix); + static bool CheckDisjoint(const std::list& list1, const std::list& list2); + static bool CheckContainsAll(const std::list& list1, const std::list& list2); + static std::string GetSha256Str(const std::string &str); + static std::string GetSha256File(const std::string &filePath); + + static bool IsFileExists(const std::string& file); + static bool IsFile(const std::string& file); + static bool IsDirectory(const std::string& dir); + static bool RemoveFile(const std::string& file); + static bool RemoveDirectory(const std::string& dir); + static std::string GetFilePathByDir(const std::string& dir, const std::string& fileName); + static bool ForceCreateDirectory(const std::string& dir); + static bool ForceRemoveDirectory(const std::string& dir, bool isDeleteSelf = true); +}; + +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_JSON_UTILS_H \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/include/zip_constants.h b/ohos_packing_tool/frameworks/include/zip_constants.h new file mode 100644 index 00000000..91512b6b --- /dev/null +++ b/ohos_packing_tool/frameworks/include/zip_constants.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_ZIP_CONSTANTS_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_ZIP_CONSTANTS_H + +#include +#include +#include + +#include "contrib/minizip/zip.h" +#include "contrib/minizip/unzip.h" + +namespace fs = std::filesystem; + +namespace OHOS { +namespace AppPackingTool { + +enum ZipErrCode { + ZIP_ERR_SUCCESS = 0, + ZIP_ERR_FAILURE +}; + +enum class ZipLevel : int32_t { + ZIP_LEVEL_DEFAULT = Z_DEFAULT_COMPRESSION, + ZIP_LEVEL_0 = Z_NO_COMPRESSION, + ZIP_LEVEL_1 = Z_BEST_SPEED, + ZIP_LEVEL_2, + ZIP_LEVEL_3, + ZIP_LEVEL_4, + ZIP_LEVEL_5, + ZIP_LEVEL_6, + ZIP_LEVEL_7, + ZIP_LEVEL_8, + ZIP_LEVEL_9 = Z_BEST_COMPRESSION +}; +#define ZIP_LEVEL_NO_COMPRESS ZipLevel::ZIP_LEVEL_0 +#define ZIP_LEVEL_BEST_SPEED ZipLevel::ZIP_LEVEL_1 +#define ZIP_LEVEL_BEST_COMPRESS ZipLevel::ZIP_LEVEL_9 + +#define MAX_ZIP_BUFFER_SIZE 4096 + +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_ZIP_CONSTANTS_H diff --git a/ohos_packing_tool/frameworks/include/zip_utils.h b/ohos_packing_tool/frameworks/include/zip_utils.h new file mode 100644 index 00000000..3883e34e --- /dev/null +++ b/ohos_packing_tool/frameworks/include/zip_utils.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_ZIP_UTILS_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_ZIP_UTILS_H + +#include "zip_wrapper.h" +#include "unzip_wrapper.h" + +namespace OHOS { +namespace AppPackingTool { + +class ZipUtils { +public: + ZipUtils(); + virtual ~ZipUtils(); + + ZipUtils(const ZipUtils &) = delete; + ZipUtils &operator=(const ZipUtils &) = delete; + + static int Zip(const std::string& filePath, const std::string& zipFilePath, + const std::string& zipPath = "", const ZipLevel& zipLevel = ZipLevel::ZIP_LEVEL_DEFAULT, + const int& append = APPEND_STATUS_CREATE); + + static int Unzip(const std::string& zipPath, const std::string& filePath); + + static bool IsFileExistsInZip(const std::string& zipFilePath, const std::string& filename); + static bool IsFileNameExistsInZip(const std::string& zipFilePath, const std::string& filename); + + static bool GetFileContentFromZip(const std::string& zipFilePath, const std::string& filename, + std::string& fileContent); + + static bool GetResourceMapFromZip(const std::string& zipFilePath, std::map& resourceMap); + +private: + static bool GetUnzipCurrentFileContent(unzFile& unzipFile, std::string& fileContent); +}; + +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_ZIP_UTILS_H diff --git a/ohos_packing_tool/frameworks/include/zip_wrapper.h b/ohos_packing_tool/frameworks/include/zip_wrapper.h new file mode 100644 index 00000000..33ab0db3 --- /dev/null +++ b/ohos_packing_tool/frameworks/include/zip_wrapper.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_ZIP_WRAPPER_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_ZIP_WRAPPER_H + +#include +#include +#include "zip_constants.h" + +namespace OHOS { +namespace AppPackingTool { + +class ZipWrapper { +public: + ZipWrapper(); + explicit ZipWrapper(std::string zipPath); + virtual ~ZipWrapper(); + + ZipWrapper(const ZipWrapper &) = delete; + ZipWrapper &operator=(const ZipWrapper &) = delete; + + int Open(std::string& zipPath, int append = APPEND_STATUS_CREATE); + int Open(int append = APPEND_STATUS_CREATE); + void Close(); + + void SetZipFilePath(std::string path) { + zipFilePath_ = path; + } + + void SetZipLevel(ZipLevel zipLevel) { + zipLevel_ = zipLevel; + } + + const zip_fileinfo& ZipFileInfo() const { + return zipFileInfo_; + } + + bool IsOpen() const { + return (zipFile_ != nullptr); + } + + int AddFileOrDirectoryToZip(const char *filePath, const char *zipPath); + int AddFileOrDirectoryToZip(const std::string &filePath, const std::string &zipPath); + int AddFileOrDirectoryToZip(const fs::path &fsFilePath, const fs::path &fsZipPath); + + int WriteStringToZip(const std::string &content, const std::string& zipPath); + +protected: + int AddFileToZip(const std::string &filePath, const std::string &zipPath); + int AddFileToZip(const fs::path &filePath, const fs::path &zipPath); + +private: + zipFile zipFile_ = nullptr; + zip_fileinfo zipFileInfo_ = {}; + std::string zipFilePath_; + ZipLevel zipLevel_ = ZipLevel::ZIP_LEVEL_DEFAULT; +}; + +} // namespace AppPackingTool +} // namespace OHOS + +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_ZIP_WRAPPER_H diff --git a/ohos_packing_tool/frameworks/src/hap_packager.cpp b/ohos_packing_tool/frameworks/src/hap_packager.cpp index fda8730b..fff4e1da 100644 --- a/ohos_packing_tool/frameworks/src/hap_packager.cpp +++ b/ohos_packing_tool/frameworks/src/hap_packager.cpp @@ -51,47 +51,49 @@ int HapPackager::Process() { std::cout << "Hap DoPackage" << std::endl; std::string outPath = parameterMap_.at(Constants::PARAM_OUT_PATH); - zipFile zf = zipOpen64(outPath.c_str(), APPEND_STATUS_CREATE); - if (zf == nullptr) { - std::cout << "err zipOpen64 null" << std::endl; + zipWrapper_.Open(outPath); + if (!zipWrapper_.IsOpen()) { + std::cout << "HapPackager::Process: zipWrapper Open failed!" << std::endl; return ERR_INVALID_VALUE; } - zip_fileinfo fi = {}; std::map::const_iterator it = parameterMap_.find(Constants::PARAM_JSON_PATH); if (it != parameterMap_.end()) { if (ParseJsonFile(moduleJson, it->second)) { - WriteStringToZip(zf, moduleJson.dump(), fs::path(Constants::MODULE_JSON), fi); + if (zipWrapper_.WriteStringToZip(moduleJson.dump(), Constants::MODULE_JSON) != ZipErrCode::ZIP_ERR_SUCCESS) { + std::cout << "HapPackager::Process: zipWrapper WriteStringToZip failed!" << std::endl; + return ERR_INVALID_VALUE; + } } } it = parameterMap_.find(Constants::PARAM_LIB_PATH); if (it != parameterMap_.end()) { - AddFileToZip(zf, fs::path(it->second), fs::path(Constants::LIB_PATH), fi); + zipWrapper_.AddFileOrDirectoryToZip(it->second, Constants::LIB_PATH); } it = parameterMap_.find(Constants::PARAM_RESOURCES_PATH); if (it != parameterMap_.end()) { - AddFileToZip(zf, fs::path(it->second), fs::path(Constants::RESOURCES_PATH), fi); + zipWrapper_.AddFileOrDirectoryToZip(it->second, Constants::RESOURCES_PATH); } it = parameterMap_.find(Constants::PARAM_INDEX_PATH); if (it != parameterMap_.end()) { - AddFileToZip(zf, fs::path(it->second), fs::path(Constants::RESOURCES_INDEX), fi); + zipWrapper_.AddFileOrDirectoryToZip(it->second, Constants::RESOURCES_INDEX); } it = parameterMap_.find(Constants::PARAM_PACK_INFO_PATH); if (it != parameterMap_.end()) { - AddFileToZip(zf, fs::path(it->second), fs::path(Constants::PACK_INFO), fi); + zipWrapper_.AddFileOrDirectoryToZip(it->second, Constants::PACK_INFO); } it = parameterMap_.find(Constants::PARAM_ETS_PATH); if (it != parameterMap_.end()) { - AddFileToZip(zf, fs::path(it->second), fs::path(Constants::ETS_PATH), fi); + zipWrapper_.AddFileOrDirectoryToZip(it->second, Constants::ETS_PATH); } it = parameterMap_.find(Constants::PARAM_RPCID_PATH); if (it != parameterMap_.end()) { - AddFileToZip(zf, fs::path(it->second), fs::path(Constants::RPCID_SC), fi); + zipWrapper_.AddFileOrDirectoryToZip(it->second, Constants::RPCID_SC); } it = parameterMap_.find(Constants::PARAM_PKG_CONTEXT_PATH); if (it != parameterMap_.end()) { - AddFileToZip(zf, fs::path(it->second), fs::path(Constants::PKG_CONTEXT_JSON), fi); + zipWrapper_.AddFileOrDirectoryToZip(it->second, Constants::PKG_CONTEXT_JSON); } - zipClose(zf, nullptr); + zipWrapper_.Close(); return ERR_OK; } diff --git a/ohos_packing_tool/frameworks/src/json/distro_filter.cpp b/ohos_packing_tool/frameworks/src/json/distro_filter.cpp new file mode 100644 index 00000000..2df1c5bc --- /dev/null +++ b/ohos_packing_tool/frameworks/src/json/distro_filter.cpp @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "distro_filter.h" +#include "pt_json.h" +#include "utils.h" + +namespace OHOS { +namespace AppPackingTool { +namespace { + const std::string API_VERSION = "apiVersion"; + const std::string SCREEN_SHAPE = "screenShape"; + const std::string SCREEN_DENSITY = "screenDensity"; + const std::string SCREEN_WINDOW = "screenWindow"; + const std::string COUNTRY_CODE = "countryCode"; + const std::string POLICY = "policy"; + const std::string VALUE = "value"; +} + +bool PolicyValue::ParseFromString(const std::string& jsonString) +{ + if (jsonString.length() == 0) { + return false; + } + std::unique_ptr root = PtJson::Parse(jsonString); + if (!root) { + return false; + } + if (root->Contains(POLICY.c_str())) { + if (root->GetString(POLICY.c_str(), &policy) != Result::SUCCESS) { + return false; + } + } + if (root->Contains(VALUE.c_str())) { + std::unique_ptr valueObj; + if (root->GetArray(VALUE.c_str(), &valueObj) != Result::SUCCESS) { + return false; + } + for (int i = 0; i< valueObj->GetSize(); i++) { + value.push_back(valueObj->Get(i)->GetString()); + } + } + return true; +} + +bool PolicyValue::IsEmpty() const +{ + return policy.empty(); +} + +bool DistroFilter::ParseFromString(const std::string& jsonString) +{ + if (jsonString.length() == 0) { + return false; + } + std::unique_ptr root = PtJson::Parse(jsonString); + if (!root) { + return false; + } + if (root->Contains(API_VERSION.c_str())) { + std::string apiVersionJsonStr; + if (root->GetString(API_VERSION.c_str(), &apiVersionJsonStr) != Result::SUCCESS) { + return false; + } + if (!apiVersion.ParseFromString(apiVersionJsonStr)) { + return false; + } + } + if (root->Contains(SCREEN_SHAPE.c_str())) { + std::string screenShapeJsonStr; + if (root->GetString(SCREEN_SHAPE.c_str(), &screenShapeJsonStr) != Result::SUCCESS) { + return false; + } + if (!screenShape.ParseFromString(screenShapeJsonStr)) { + return false; + } + } + if (root->Contains(SCREEN_DENSITY.c_str())) { + std::string screenDensityJsonStr; + if (root->GetString(SCREEN_DENSITY.c_str(), &screenDensityJsonStr) != Result::SUCCESS) { + return false; + } + if (!screenDensity.ParseFromString(screenDensityJsonStr)) { + return false; + } + } + if (root->Contains(SCREEN_WINDOW.c_str())) { + std::string screenWindowJsonStr; + if (root->GetString(SCREEN_WINDOW.c_str(), &screenWindowJsonStr) != Result::SUCCESS) { + return false; + } + if (!screenWindow.ParseFromString(screenWindowJsonStr)) { + return false; + } + } + if (root->Contains(COUNTRY_CODE.c_str())) { + std::string countryCodeJsonStr; + if (root->GetString(COUNTRY_CODE.c_str(), &countryCodeJsonStr) != Result::SUCCESS) { + return false; + } + if (!countryCode.ParseFromString(countryCodeJsonStr)) { + return false; + } + } + return true; +} + +bool DistroFilter::IsEmpty() const +{ + if (apiVersion.IsEmpty() && screenShape.IsEmpty() && screenDensity.IsEmpty() && + screenWindow.IsEmpty() && countryCode.IsEmpty()) { + return true; + } + return false; +} + +std::string DistroFilter::Dump() +{ + std::string dumpStr = ""; + if (apiVersion.policy.empty() && screenShape.policy.empty() && screenDensity.policy.empty() + && screenWindow.policy.empty() && countryCode.policy.empty()) { + return dumpStr; + } + dumpStr = "distroFilter:"; + if (!apiVersion.policy.empty()) { + std::string apiVersionStr = "apiVersion: policy is " + apiVersion.policy + ", value is " + + Utils::ListToString(apiVersion.value); + dumpStr += " " + apiVersionStr; + } + if (!screenShape.policy.empty()) { + std::string screenShapeStr = "screenShape: policy is " + screenShape.policy + ", value is " + + Utils::ListToString(screenShape.value); + dumpStr += " " + screenShapeStr; + } + if (!screenDensity.policy.empty()) { + std::string screenDensityStr = "screenDensity: policy is " + screenDensity.policy + ", value is " + + Utils::ListToString(screenDensity.value); + dumpStr += " " + screenDensityStr; + } + if (!screenWindow.policy.empty()) { + std::string screenWindowStr = "screenWindow: policy is " + screenWindow.policy + ", value is " + + Utils::ListToString(screenWindow.value); + dumpStr += " " + screenWindowStr; + } + if (!countryCode.policy.empty()) { + std::string countryCodeStr = "countryCode: policy is " + countryCode.policy + ", value is " + + Utils::ListToString(countryCode.value); + dumpStr += " " + countryCodeStr; + } + return dumpStr; +} +} // namespace AppPackingTool +} // namespace OHOS diff --git a/ohos_packing_tool/frameworks/src/json/hap_verify_info.cpp b/ohos_packing_tool/frameworks/src/json/hap_verify_info.cpp new file mode 100644 index 00000000..0a7c7a07 --- /dev/null +++ b/ohos_packing_tool/frameworks/src/json/hap_verify_info.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "hap_verify_info.h" + +namespace OHOS { +namespace AppPackingTool { +namespace {} + +HapVerifyInfo::HapVerifyInfo() +{ +} + +HapVerifyInfo::~HapVerifyInfo() +{ +} + +void HapVerifyInfo::ConvertToDependency() { + for (DependencyItem item : dependencyItemList_) { + if (!item.bundleName.empty() && item.bundleName.compare(bundleName_) == 0) { + dependencies_.emplace_back(item.bundleName); + } + } +} + +} // namespace AppPackingTool +} // namespace OHOS diff --git a/ohos_packing_tool/frameworks/src/json/json_utils.cpp b/ohos_packing_tool/frameworks/src/json/json_utils.cpp new file mode 100644 index 00000000..f6c0473c --- /dev/null +++ b/ohos_packing_tool/frameworks/src/json/json_utils.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "json_utils.h" + +namespace OHOS { +namespace AppPackingTool { +namespace {} + +JsonUtils::JsonUtils() +{} + +JsonUtils::~JsonUtils() +{} + +bool JsonUtils::CheckFileName(const std::string filePath, const std::string fileName) +{ + fs::path fsFilePath(filePath); + if (fs::is_regular_file(fsFilePath) && fsFilePath.filename().compare(fileName) == 0) { + return true; + } + return false; +} + +bool JsonUtils::IsModuleJson(const std::string filePath) +{ + return CheckFileName(filePath, MODULE_JSON); +} + +bool JsonUtils::IsConfigJson(const std::string filePath) +{ + return CheckFileName(filePath, CONFIG_JSON); +} + +bool JsonUtils::IsPatchJson(const std::string filePath) +{ + return CheckFileName(filePath, PATCH_JSON); +} + +std::unique_ptr JsonUtils::JsonFromFile(const std::string filePath) +{ + std::ifstream inFile(filePath, std::ios::in); + if (!inFile.is_open()) { + return nullptr; + } + std::string fileContent((std::istreambuf_iterator(inFile)), std::istreambuf_iterator()); + inFile.close(); + return PtJson::Parse(fileContent); +} + +bool JsonUtils::JsonToFile(std::unique_ptr json, const std::string filePath) +{ + if (json.get() == nullptr) { + return false; + } + std::ofstream outFile(filePath, std::ios::out); + if (!outFile.is_open()) { + return false; + } + outFile << json->Stringify(); + outFile.close(); + return true; +} +} // namespace AppPackingTool +} // namespace OHOS diff --git a/ohos_packing_tool/frameworks/src/json/module_json.cpp b/ohos_packing_tool/frameworks/src/json/module_json.cpp new file mode 100644 index 00000000..9984fec2 --- /dev/null +++ b/ohos_packing_tool/frameworks/src/json/module_json.cpp @@ -0,0 +1,2152 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "module_json.h" +#include "utils.h" + +namespace OHOS { +namespace AppPackingTool { +namespace { + const std::string APP = "app"; + const std::string BUNDLE_TYPE = "bundleType"; + const std::string ABILITIES = "abilities"; + const std::string VERSIONCODE = "versionCode"; + const std::string VERSIONNAME = "versionName"; + const std::string MIN_COMPATIBLE_VERSION_CODE = "minCompatibleVersionCode"; + const std::string API_VERSION = "apiVersion"; + const std::string MIN_API_VERSION = "minAPIVersion"; + const std::string TARGET_API_VERSION = "targetAPIVersion"; + const std::string API_RELEASE_TYPE = "apiReleaseType"; + const std::string DEBUG = "debug"; + const std::string COMPATIBLE = "compatible"; + const std::string RELEASE_TYPE = "releaseType"; + const std::string TARGET = "target"; + const std::string VERSION = "version"; + const std::string CODE = "code"; + const std::string NAME = "name"; + const std::string MODULE = "module"; + // const std::string MODULES = "modules"; + const std::string MODULE_NAME = "moduleName"; + const std::string MODULE_TYPE = "moduleType"; + const std::string DISTRO = "distro"; + const std::string PACKAGE = "package"; + // const std::string PACKAGES = "packages"; + // const std::string SUMMARY = "summary"; + const std::string BUNDLE_NAME = "bundleName"; + const std::string ENTRY = "entry"; + // const char DOT = '.'; + // const std::string CONFIG_JSON = "config.json"; + // const std::string MODULE_JSON = "module.json"; + const std::string DEVICE_TYPE = "deviceType"; + const std::string DEVICE_TYPES = "deviceTypes"; + const std::string TYPE= "type"; + const std::string VENDOR = "vendor"; + const std::string METADATA = "metadata"; + const std::string RESOURCE = "resource"; + const std::string PROFILE = "$profile:"; + const std::string VALUE = "value"; + const std::string JSON_PREFIX = ".json"; + const std::string DISTRO_FILTER = "distroFilter"; + const std::string DISTRIBUTION_FILTER = "distributionFilter"; + const std::string DEPENDENCIES = "dependencies"; + const std::string EXTENSION_ABILITIES = "extensionAbilities"; + const std::string INSTALLATION_FREE = "installationFree"; + // const std::string PATCH_JSON = "patch.json"; + // const std::string PATCH_VERSION_CODE = "patchVersionCode"; + // const std::string PATCH_VERSION_NAME = "patchVersionName"; + // const std::string ORIGINAL_MODULE_HASH = "originalModuleHash"; + // const std::string EMPTY_STRING = ""; + const std::string COMPRESS_NATIVE_LIBS = "compressNativeLibs"; + const std::string ASAN_ENABLED = "asanEnabled"; + const std::string TSAN_ENABLED = "tsanEnabled"; + const std::string ATOMIC_SERVICE = "atomicService"; + // const std::string SPLIT = "split"; + // const std::string MAIN = "main"; + const std::string PRELOADS = "preloads"; + const std::string SHARED = "shared"; + const std::string APP_SERVICE = "appService"; + const std::string REQUEST_PERMISSIONS = "requestPermissions"; + const std::string TARGET_MODULE_NAME = "targetModuleName"; + const std::string TARGET_PRIORITY = "targetPriority"; + const std::string TARGET_BUNDLE_NAME = "targetBundleName"; + const std::string DEVICE_CONFIG = "deviceConfig"; + const std::string DEFAULT = "default"; + const std::string COMPILE_SDK_VERSION = "compileSdkVersion"; + const std::string COMPILE_SDK_TYPE = "compileSdkType"; + const std::string PROXY_DATAS = "proxyDatas"; + const std::string PROXY_DATA = "proxyData"; + const std::string PROXY_URI = "uri"; + const std::string CONTINUE_TYPE = "continueType"; + const std::string MULTI_APP_MODE = "multiAppMode"; + const std::string MULTI_APP_MODE_TYPE = "multiAppModeType"; + const std::string MULTI_APP_MODE_NUMBER = "maxCount"; + // const std::string FORMS = "forms"; + // const std::string DEFAULTDIMENSION = "defaultDimension"; + // const std::string SUPPORTDIMENSIONS = "supportDimensions"; + const std::string GENERATE_BUILD_HASH = "generateBuildHash"; +} + +ModuleJson::ModuleJson() +{ +} + +ModuleJson::~ModuleJson() +{ +} + +bool ModuleJson::ParseFromString(const std::string& jsonString) +{ + Release(); + if (jsonString.length() == 0) { + return false; + } + root_ = PtJson::Parse(jsonString); + return IsValid(); +} + +bool ModuleJson::ParseFromFile(const std::string& jsonFile) +{ + Release(); + std::ifstream inFile(jsonFile, std::ios::in); + if (!inFile.is_open()) { + return false; + } + std::string fileContent((std::istreambuf_iterator(inFile)), std::istreambuf_iterator()); + inFile.close(); + root_ = PtJson::Parse(fileContent); + return IsValid(); +} + +std::string ModuleJson::ToString() +{ + return root_->Stringify(); +} + +void ModuleJson::Release() +{ + if (root_.get() != nullptr) { + root_->ReleaseRoot(); + root_ = nullptr; + } +} + +bool ModuleJson::IsValid() +{ + return (root_.get() != nullptr); +} + +bool ModuleJson::GetAppObject(std::unique_ptr& appObj) +{ + if (root_.get() == nullptr) { + return false; + } + if (!root_->Contains(APP.c_str())) { + return false; + } + if (root_->GetObject(APP.c_str(), &appObj) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::GetVersionObject(std::unique_ptr& versionObj) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + if (!appObj->Contains(VERSION.c_str())) { + return false; + } + if (appObj->GetObject(VERSION.c_str(), &versionObj) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::GetModuleObject(std::unique_ptr& moduleObj) +{ + if (root_.get() == nullptr) { + return false; + } + if (!root_->Contains(MODULE.c_str())) { + return false; + } + if (root_->GetObject(MODULE.c_str(), &moduleObj) != Result::SUCCESS) { + return false; + } + return true; +} + + +bool ModuleJson::GetDistroObject(std::unique_ptr& distroObj) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetDistroObjectByModuleObj(moduleObj, distroObj); +} + +bool ModuleJson::GetDistroObjectByModuleObj(std::unique_ptr& moduleObj, std::unique_ptr& distroObj) +{ + if (!moduleObj) { + return false; + } + if (!moduleObj->Contains(DISTRO.c_str())) { + return false; + } + if (moduleObj->GetObject(DISTRO.c_str(), &distroObj) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::GetApiVersionObject(std::unique_ptr& apiVersion) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + if (!appObj->Contains(API_VERSION.c_str())) { + return false; + } + if (appObj->GetObject(API_VERSION.c_str(), &apiVersion) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::GetStageVersion(Version& version) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetStageVersionByAppObj(appObj, version); +} + +bool ModuleJson::GetStageVersionByAppObj(std::unique_ptr& obj, Version& version) +{ + if (!obj) { + return false; + } + if (!obj->Contains(VERSIONCODE.c_str()) || !obj->Contains(VERSIONNAME.c_str())) { + return false; + } + if (obj->GetInt(VERSIONCODE.c_str(), &version.versionCode) != Result::SUCCESS) { + return false; + } + if (obj->GetString(VERSIONNAME.c_str(), &version.versionName) != Result::SUCCESS) { + return false; + } + if (obj->Contains(MIN_COMPATIBLE_VERSION_CODE.c_str())) { + if (obj->GetInt(MIN_COMPATIBLE_VERSION_CODE.c_str(), &version.minCompatibleVersionCode) != Result::SUCCESS) { + return false; + } + } else { + version.minCompatibleVersionCode = version.versionCode; + } + return true; +} + +bool ModuleJson::SetStageVersionCode(const int& versionCode) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + if (!appObj->Contains(VERSIONCODE.c_str())) { + return false; + } + if (appObj->SetInt(VERSIONCODE.c_str(), versionCode) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::SetStageVersionName(const std::string& versionName) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + if (!appObj->Contains(VERSIONNAME.c_str())) { + return false; + } + if (appObj->SetString(VERSIONNAME.c_str(), versionName) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::GetFaVersion(Version& version) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetFaVersionByAppObj(appObj, version); +} + +bool ModuleJson::GetFaVersionByAppObj(std::unique_ptr& obj, Version& version) +{ + if (!obj) { + return false; + } + if (!obj->Contains(VERSION.c_str())) { + return false; + } + std::unique_ptr versionObj; + if (obj->GetObject(VERSION.c_str(), &versionObj) != Result::SUCCESS) { + return false; + } + return GetFaVersionByVersionObj(versionObj, version); +} + +bool ModuleJson::GetFaVersionByVersionObj(std::unique_ptr& obj, Version& version) +{ + if (!obj) { + return false; + } + if (!obj->Contains(CODE.c_str()) || !obj->Contains(NAME.c_str())) { + return false; + } + if (obj->GetInt(CODE.c_str(), &version.versionCode) != Result::SUCCESS) { + return false; + } + if (obj->GetString(NAME.c_str(), &version.versionName) != Result::SUCCESS) { + return false; + } + if (obj->Contains(MIN_COMPATIBLE_VERSION_CODE.c_str())) { + if (obj->GetInt(MIN_COMPATIBLE_VERSION_CODE.c_str(), &version.minCompatibleVersionCode) != Result::SUCCESS) { + return false; + } + } else { + version.minCompatibleVersionCode = version.versionCode; + } + return true; +} + +bool ModuleJson::SetFaVersionCode(const int& versionCode) +{ + std::unique_ptr versionObj; + if (!GetVersionObject(versionObj)) { + return false; + } + if (!versionObj->Contains(CODE.c_str())) { + return false; + } + if (versionObj->SetInt(CODE.c_str(), versionCode) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::SetFaVersionName(const std::string& versionName) +{ + std::unique_ptr versionObj; + if (!GetVersionObject(versionObj)) { + return false; + } + if (!versionObj->Contains(NAME.c_str())) { + return false; + } + if (versionObj->SetString(NAME.c_str(), versionName) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::GetFaInstallationFree(bool& installationFree) +{ + std::unique_ptr distroObj; + if (!GetDistroObject(distroObj)) { + return false; + } + return GetFaInstallationFreeByDistroObj(distroObj, installationFree); +} + +bool ModuleJson::GetFaInstallationFreeByModuleObj(std::unique_ptr& obj, bool& installationFree) +{ + if (!obj) { + return false; + } + std::unique_ptr distroObj; + if (!GetDistroObjectByModuleObj(obj, distroObj)) { + return false; + } + return GetFaInstallationFreeByDistroObj(distroObj, installationFree); +} + +bool ModuleJson::GetFaInstallationFreeByDistroObj(std::unique_ptr& obj, bool& installationFree) +{ + if (!obj) { + return false; + } + if (!obj->Contains(INSTALLATION_FREE.c_str())) { + return false; + } + if (obj->GetBool(INSTALLATION_FREE.c_str(), &installationFree) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::GetStageInstallationFree(bool& installationFree) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetStageInstallationFreeByModuleObj(moduleObj, installationFree); +} + +bool ModuleJson::GetStageInstallationFreeByModuleObj(std::unique_ptr& obj, bool& installationFree) +{ + if (!obj) { + return false; + } + if (!obj->Contains(INSTALLATION_FREE.c_str())) { + return false; + } + if (obj->GetBool(INSTALLATION_FREE.c_str(), &installationFree) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::GetFaBundleType(std::string& bundleType) +{ + bool installationFree = false; + if (!GetFaInstallationFree(installationFree)) { + return false; + } + if (installationFree) { + bundleType = ATOMIC_SERVICE; + } else { + bundleType = APP; + } + return true; +} + +bool ModuleJson::GetStageModuleApiVersion(ModuleApiVersion& moduleApiVersion) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetStageModuleApiVersionByAppObj(appObj, moduleApiVersion); +} + +bool ModuleJson::GetStageModuleApiVersionByAppObj(std::unique_ptr& obj, ModuleApiVersion& moduleApiVersion) +{ + if (!obj) { + return false; + } + if (obj->Contains(MIN_API_VERSION.c_str())) { + if (obj->GetInt(MIN_API_VERSION.c_str(), &moduleApiVersion.compatibleApiVersion) != Result::SUCCESS) { + return false; + } + } + if (obj->Contains(TARGET_API_VERSION.c_str())) { + if (obj->GetInt(TARGET_API_VERSION.c_str(), &moduleApiVersion.targetApiVersion) != Result::SUCCESS) { + return false; + } + } + if (obj->Contains(API_RELEASE_TYPE.c_str())) { + if (obj->GetString(API_RELEASE_TYPE.c_str(), &moduleApiVersion.releaseType) != Result::SUCCESS) { + return false; + } + } + return true; +} + +bool ModuleJson::GetFaModuleApiVersion(ModuleApiVersion& moduleApiVersion) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetFaModuleApiVersionByAppObj(appObj, moduleApiVersion); +} + +bool ModuleJson::GetFaModuleApiVersionByAppObj(std::unique_ptr& obj, ModuleApiVersion& moduleApiVersion) +{ + if (!obj) { + return false; + } + if (!obj->Contains(API_VERSION.c_str())) { + return false; + } + std::unique_ptr apiVersionObj; + if (obj->GetObject(API_VERSION.c_str(), &apiVersionObj) != Result::SUCCESS) { + return false; + } + return GetFaModuleApiVersionByApiVersionObj(apiVersionObj, moduleApiVersion); +} + +bool ModuleJson::GetFaModuleApiVersionByApiVersionObj(std::unique_ptr& obj, ModuleApiVersion& moduleApiVersion) +{ + if (!obj) { + return false; + } + if (obj->Contains(COMPATIBLE.c_str())) { + if (obj->GetInt(COMPATIBLE.c_str(), &moduleApiVersion.compatibleApiVersion) != Result::SUCCESS) { + return false; + } + } + if (obj->Contains(TARGET.c_str())) { + if (obj->GetInt(TARGET.c_str(), &moduleApiVersion.targetApiVersion) != Result::SUCCESS) { + return false; + } + } + if (obj->Contains(RELEASE_TYPE.c_str())) { + if (obj->GetString(RELEASE_TYPE.c_str(), &moduleApiVersion.releaseType) != Result::SUCCESS) { + return false; + } + } + return true; +} + +bool ModuleJson::GetStageModuleName(std::string& stageModuleName) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetStageModuleNameByModuleObj(moduleObj, stageModuleName); +} + +bool ModuleJson::GetModuleName(std::string& moduleName) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetModuleNameByModuleObj(moduleObj, moduleName); +} + +bool ModuleJson::GetModuleNameByModuleObj(std::unique_ptr& obj, std::string& moduleName) +{ + if (!obj) { + return false; + } + if (!obj->Contains(NAME.c_str())) { + return false; + } + if (obj->GetString(NAME.c_str(), &moduleName) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::GetStageModuleNameByModuleObj(std::unique_ptr& obj, std::string& stageModuleName) +{ + if (!obj) { + return false; + } + if (!obj->Contains(NAME.c_str())) { + return false; + } + if (obj->GetString(NAME.c_str(), &stageModuleName) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::GetFaModuleName(std::string& faModuleName) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + std::unique_ptr distroObj; + return GetDistroObjectByModuleObj(moduleObj, distroObj); + if (!distroObj->Contains(MODULE_NAME.c_str())) { + return false; + } + if (distroObj->GetString(MODULE_NAME.c_str(), &faModuleName) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::GetFaModuleNameByModuleObj(std::unique_ptr& obj, std::string& faModuleName) +{ + if (!obj) { + return false; + } + std::unique_ptr distroObj; + if (!GetDistroObjectByModuleObj(obj, distroObj)) { + return false; + } + return GetFaModuleNameByDistroObj(distroObj, faModuleName); +} + +bool ModuleJson::GetFaModuleNameByDistroObj(std::unique_ptr& obj, std::string& faModuleName) +{ + if (!obj) { + return false; + } + if (!obj->Contains(MODULE_NAME.c_str())) { + return false; + } + if (obj->GetString(MODULE_NAME.c_str(), &faModuleName) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::GetPatchModuleName(std::string& patchModuleName) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + if (!moduleObj->Contains(NAME.c_str())) { + return false; + } + if (moduleObj->GetString(NAME.c_str(), &patchModuleName) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::GetFaPackageStr(std::string& packageStr) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetFaPackageStrByModuleObj(moduleObj, packageStr); +} + +bool ModuleJson::GetFaPackageStrByModuleObj(std::unique_ptr& obj, std::string& packageStr) +{ + if (!obj) { + return false; + } + if (!obj->Contains(PACKAGE.c_str())) { + return false; + } + if (obj->GetString(PACKAGE.c_str(), &packageStr) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::GetBundleName(std::string& bundleName) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetBundleNameByAppObj(appObj, bundleName); +} + +bool ModuleJson::GetBundleNameByAppObj(std::unique_ptr& obj, std::string& bundleName) +{ + if (!obj) { + return false; + } + if (!obj->Contains(BUNDLE_NAME.c_str())) { + return false; + } + if (obj->GetString(BUNDLE_NAME.c_str(), &bundleName) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::SetBundleName(const std::string& bundleName) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + if (!appObj->Contains(BUNDLE_NAME.c_str())) { + return false; + } + if (appObj->SetString(BUNDLE_NAME.c_str(), bundleName) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::GetVendor(std::string& vendor) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetVendorByAppObj(appObj, vendor); +} + +bool ModuleJson::GetVendorByAppObj(std::unique_ptr& obj, std::string& vendor) +{ + if (!obj) { + return false; + } + if (obj->Contains(VENDOR.c_str())) { + if (obj->GetString(VENDOR.c_str(), &vendor) != Result::SUCCESS) { + return false; + } + } else { + vendor = ""; + } + return true; +} + +bool ModuleJson::GetStageCompileSdkType(std::string& compileSdkType) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetStageCompileSdkTypeByAppObj(appObj, compileSdkType); +} + +bool ModuleJson::GetStageCompileSdkTypeByAppObj(std::unique_ptr& obj, std::string& compileSdkType) +{ + if (!obj) { + return false; + } + if (obj->Contains(COMPILE_SDK_TYPE.c_str())) { + if (obj->GetString(COMPILE_SDK_TYPE.c_str(), &compileSdkType) != Result::SUCCESS) { + return false; + } + } else { + compileSdkType = ""; + } + return true; +} + +bool ModuleJson::GetStageCompileSdkVersion(std::string& compileSdkVersion) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetStageCompileSdkVersionByAppObj(appObj, compileSdkVersion); +} + +bool ModuleJson::GetStageCompileSdkVersionByAppObj(std::unique_ptr& obj, std::string& compileSdkVersion) +{ + if (!obj) { + return false; + } + if (obj->Contains(COMPILE_SDK_VERSION.c_str())) { + if (obj->GetString(COMPILE_SDK_VERSION.c_str(), &compileSdkVersion) != Result::SUCCESS) { + return false; + } + } else { + compileSdkVersion = ""; + } + return true; +} + +bool ModuleJson::GetFaCompileSdkType(std::string& compileSdkType) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetFaCompileSdkTypeByAppObj(appObj, compileSdkType); +} + +bool ModuleJson::GetFaCompileSdkTypeByAppObj(std::unique_ptr& obj, std::string& compileSdkType) +{ + if (!obj) { + return false; + } + if (!obj->Contains(API_VERSION.c_str())) { + return false; + } + std::unique_ptr apiVersionObj; + if (obj->GetObject(API_VERSION.c_str(), &apiVersionObj) != Result::SUCCESS) { + return false; + } + if (apiVersionObj->Contains(COMPILE_SDK_TYPE.c_str())) { + if (apiVersionObj->GetString(COMPILE_SDK_TYPE.c_str(), &compileSdkType) != Result::SUCCESS) { + return false; + } + } else { + compileSdkType = ""; + } + return true; +} + +bool ModuleJson::GetFaCompileSdkVersion(std::string& compileSdkVersion) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetFaCompileSdkVersionByAppObj(appObj, compileSdkVersion); +} + +bool ModuleJson::GetFaCompileSdkVersionByAppObj(std::unique_ptr& obj, std::string& compileSdkVersion) +{ + if (!obj) { + return false; + } + if (!obj->Contains(API_VERSION.c_str())) { + return false; + } + std::unique_ptr apiVersionObj; + if (obj->GetObject(API_VERSION.c_str(), &apiVersionObj) != Result::SUCCESS) { + return false; + } + if (apiVersionObj->Contains(COMPILE_SDK_VERSION.c_str())) { + if (apiVersionObj->GetString(COMPILE_SDK_VERSION.c_str(), &compileSdkVersion) != Result::SUCCESS) { + return false; + } + } else { + compileSdkVersion = ""; + } + return true; +} + +bool ModuleJson::GetStageDebug(bool& debug) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetStageDebugByAppObj(appObj, debug); +} + +bool ModuleJson::GetStageDebugByAppObj(std::unique_ptr& obj, bool& debug) +{ + if (!obj) { + return false; + } + if (obj->Contains(DEBUG.c_str())) { + if (obj->GetBool(DEBUG.c_str(), &debug) != Result::SUCCESS) { + return false; + } + } else { + debug = false; + } + return true; +} + +bool ModuleJson::GetFaDebug(bool& debug) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetFaDebugByAppObj(appObj, debug); +} + +bool ModuleJson::GetFaDebugByAppObj(std::unique_ptr& obj, bool& debug) +{ + if (!obj) { + return false; + } + if (!obj->Contains(DEVICE_CONFIG.c_str())) { + return false; + } + std::unique_ptr deviceConfigObj; + if (obj->GetObject(DEVICE_CONFIG.c_str(), &deviceConfigObj) != Result::SUCCESS) { + return false; + } + if (!deviceConfigObj->Contains(DEFAULT.c_str())) { + return false; + } + if (deviceConfigObj->GetBool(DEFAULT.c_str(), &debug) != Result::SUCCESS) { + return false; + } + return true; +} + +bool ModuleJson::GetTargetBundleName(std::string& targetBundleName) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetTargetBundleNameByAppObj(appObj, targetBundleName); +} + +bool ModuleJson::GetTargetBundleNameByAppObj(std::unique_ptr& obj, std::string& targetBundleName) +{ + if (!obj) { + return false; + } + if (obj->Contains(TARGET_BUNDLE_NAME.c_str())) { + if (obj->GetString(TARGET_BUNDLE_NAME.c_str(), &targetBundleName) != Result::SUCCESS) { + return false; + } + } else { + targetBundleName = ""; + } + return true; +} + +bool ModuleJson::GetTargetPriority(int32_t& targetPriority) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetTargetPriorityByAppObj(appObj, targetPriority); +} + +bool ModuleJson::GetTargetPriorityByAppObj(std::unique_ptr& obj, int32_t& targetPriority) +{ + if (!obj) { + return false; + } + if (obj->Contains(TARGET_PRIORITY.c_str())) { + if (obj->GetInt(TARGET_PRIORITY.c_str(), &targetPriority) != Result::SUCCESS) { + return false; + } + } else { + targetPriority = 0; + } + return true; +} + +bool ModuleJson::GetTargetModuleName(std::string& targetModuleName) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetTargetModuleNameByModuleObj(moduleObj, targetModuleName); +} + +bool ModuleJson::GetTargetModuleNameByModuleObj(std::unique_ptr& obj, std::string& targetModuleName) +{ + if (!obj) { + return false; + } + if (obj->Contains(TARGET_MODULE_NAME.c_str())) { + if (obj->GetString(TARGET_MODULE_NAME.c_str(), &targetModuleName) != Result::SUCCESS) { + return false; + } + } else { + targetModuleName = ""; + } + return true; +} + +bool ModuleJson::GetTargetModulePriority(int32_t& targetModulePriority) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetTargetModulePriorityByModuleObj(moduleObj, targetModulePriority); +} + +bool ModuleJson::GetTargetModulePriorityByModuleObj(std::unique_ptr& obj, int32_t& targetModulePriority) +{ + if (!obj) { + return false; + } + if (obj->Contains(TARGET_PRIORITY.c_str())) { + if (obj->GetInt(TARGET_PRIORITY.c_str(), &targetModulePriority) != Result::SUCCESS) { + return false; + } + } else { + targetModulePriority = 0; + } + return true; +} + +// java: parseFaEntry / getDeviceTypeFromFAModule +// parseFaEntry not called anywhere +bool ModuleJson::GetFaEntry(std::list& deviceTypes) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + std::unique_ptr distroObj; + if (!moduleObj->Contains(DISTRO.c_str())) { + return false; + } + if (moduleObj->GetObject(DISTRO.c_str(), &distroObj) != Result::SUCCESS) { + return false; + } + std::string moduleType; + if (!distroObj->Contains(MODULE_TYPE.c_str())) { + return false; + } + if (distroObj->GetString(MODULE_TYPE.c_str(), &moduleType) != Result::SUCCESS) { + return false; + } + if (moduleType.compare(ENTRY) == 0) { + if (!GetFaDeviceTypesByModuleObj(moduleObj, deviceTypes)) { + return false; + } + } + return true; +} + +bool ModuleJson::GetFaDeviceTypes(std::list& deviceTypes) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetFaDeviceTypesByModuleObj(moduleObj, deviceTypes); +} + +bool ModuleJson::GetFaDeviceTypesByModuleObj(std::unique_ptr& obj, std::list& deviceTypes) +{ + if (!obj) { + return false; + } + if (!obj->Contains(DEVICE_TYPE.c_str())) { + return false; + } + std::unique_ptr deviceTypeObj; + if (obj->GetArray(DEVICE_TYPE.c_str(), &deviceTypeObj) != Result::SUCCESS) { + return false; + } + for (int i = 0; i < deviceTypeObj->GetSize(); i++) { + deviceTypes.push_back(deviceTypeObj->Get(i)->GetString()); + } + return true; +} + +// java: parseStageEntry / getDeviceTypesFromStageModule +bool ModuleJson::GetStageEntry(std::list& deviceTypes) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + std::string moduleType; + if (!moduleObj->Contains(TYPE.c_str())) { + return false; + } + if (moduleObj->GetString(TYPE.c_str(), &moduleType) != Result::SUCCESS) { + return false; + } + if (moduleType.compare(ENTRY) == 0) { + if (!GetStageDeviceTypesByModuleObj(moduleObj, deviceTypes)) { + return false; + } + } + return true; +} + +bool ModuleJson::GetStageDeviceTypes(std::list& deviceTypes) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetStageDeviceTypesByModuleObj(moduleObj, deviceTypes); +} + +bool ModuleJson::GetStageDeviceTypesByModuleObj(std::unique_ptr& obj, std::list& deviceTypes) +{ + if (!obj) { + return false; + } + if (!obj->Contains(DEVICE_TYPES.c_str())) { + return false; + } + std::unique_ptr deviceTypeObj; + if (obj->GetArray(DEVICE_TYPES.c_str(), &deviceTypeObj) != Result::SUCCESS) { + return false; + } + for (int i = 0; i < deviceTypeObj->GetSize(); i++) { + deviceTypes.push_back(deviceTypeObj->Get(i)->GetString()); + } + return true; +} + + +bool ModuleJson::GetModuleMetadatas(std::list& moduleMetadataInfos) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetModuleMetadatasByModuleObj(moduleObj, moduleMetadataInfos); +} + +bool ModuleJson::GetModuleMetadatasByModuleObj(std::unique_ptr& obj, std::list& moduleMetadataInfos) +{ + if (!obj) { + return false; + } + std::unique_ptr moduleMetadataInfosObj; + if (obj->Contains(METADATA.c_str())) { + if (obj->GetArray(METADATA.c_str(), &moduleMetadataInfosObj) != Result::SUCCESS) { + return false; + } + for (int i = 0; i < moduleMetadataInfosObj->GetSize(); i++) { + ModuleMetadataInfo moduleMetadataInfo; + std::unique_ptr moduleMetadataInfoObj = moduleMetadataInfosObj->Get(i); + if (moduleMetadataInfoObj->Contains(NAME.c_str())) { + if (moduleMetadataInfoObj->GetString(NAME.c_str(), &moduleMetadataInfo.name) != Result::SUCCESS) { + return false; + } + } + if (moduleMetadataInfoObj->Contains(VALUE.c_str())) { + if (moduleMetadataInfoObj->GetString(VALUE.c_str(), &moduleMetadataInfo.value) != Result::SUCCESS) { + return false; + } + } + if (moduleMetadataInfoObj->Contains(RESOURCE.c_str())) { + std::string resource; + if (moduleMetadataInfoObj->GetString(RESOURCE.c_str(), &resource) != Result::SUCCESS) { + return false; + } + moduleMetadataInfo.resource = Utils::ReplaceAll(resource, PROFILE, "") + JSON_PREFIX; + + } + moduleMetadataInfos.push_back(moduleMetadataInfo); + } + } + return true; +} + +bool ModuleJson::GetStageDistroFilter(DistroFilter& distroFilter) +{ + std::list moduleMetadataInfos; + if (!GetModuleMetadatas(moduleMetadataInfos)) { + return false; + } + return ParseModuleMetadatasToDistroFilter(moduleMetadataInfos, distroFilter); +} + +bool ModuleJson::GetStageDistroFilterByModuleObj(std::unique_ptr& obj, DistroFilter& distroFilter) +{ + std::list moduleMetadataInfos; + if (!GetModuleMetadatasByModuleObj(obj, moduleMetadataInfos)) { + return false; + } + return ParseModuleMetadatasToDistroFilter(moduleMetadataInfos, distroFilter); +} + +bool ModuleJson::ParseModuleMetadatasToDistroFilter(const std::list& moduleMetadataInfos, DistroFilter& distroFilter) +{ + for (auto& moduleMetadataInfo : moduleMetadataInfos) { + if (moduleMetadataInfo.resource.empty()) { + continue; + } + std::unique_ptr distroFilterObj = PtJson::Parse(moduleMetadataInfo.resource); + if (!distroFilterObj) { + return false; + } + std::string distroFilterJsonStr; + if (distroFilterObj->Contains(DISTRIBUTION_FILTER.c_str())) { + if (distroFilterObj->GetString(DISTRIBUTION_FILTER.c_str(), &distroFilterJsonStr) != Result::SUCCESS) { + return false; + } + } else if (distroFilterObj->Contains(DISTRO_FILTER.c_str())) { + if (distroFilterObj->GetString(DISTRO_FILTER.c_str(), &distroFilterJsonStr) != Result::SUCCESS) { + return false; + } + } + if (!distroFilter.ParseFromString(distroFilterJsonStr)) { + return false; + } + } + return true; +} + +bool ModuleJson::GetAbilityNames(std::list& abilityNames) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetAbilityNamesByModuleObj(moduleObj, abilityNames); +} + +bool ModuleJson::GetAbilityNamesByModuleObj(std::unique_ptr& obj, std::list& abilityNames) +{ + if (!obj) { + return false; + } + if (!obj->Contains(ABILITIES.c_str())) { + return false; + } + std::unique_ptr abilitiesObj; + if (obj->GetArray(ABILITIES.c_str(), &abilitiesObj) != Result::SUCCESS) { + return false; + } + for (int i = 0; i < abilitiesObj->GetSize(); i++) { + std::unique_ptr abilityObj = abilitiesObj->Get(i); + if (abilityObj->Contains(NAME.c_str())) { + std::string name; + if (abilityObj->GetString(NAME.c_str(), &name) != Result::SUCCESS) { + return false; + } + abilityNames.push_back(name); + } + } + return true; +} + +bool ModuleJson::GetProxyDataUris(std::list& proxyDataUris) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetProxyDataUrisByModuleObj(moduleObj, proxyDataUris); +} + +bool ModuleJson::GetProxyDataUrisByModuleObj(std::unique_ptr& obj, std::list& proxyDataUris) +{ + if (!obj) { + return false; + } + if (obj->Contains(PROXY_DATAS.c_str())) { + std::unique_ptr proxyDatasObj; + if (obj->GetArray(PROXY_DATAS.c_str(), &proxyDatasObj) != Result::SUCCESS) { + return false; + } + if (!GetProxyDataUrisByProxyDatasObj(proxyDatasObj, proxyDataUris)) { + return false; + } + } else if (obj->Contains(PROXY_DATA.c_str())) { + std::unique_ptr proxyDatasObj; + if (obj->GetArray(PROXY_DATA.c_str(), &proxyDatasObj) != Result::SUCCESS) { + return false; + } + if (!GetProxyDataUrisByProxyDatasObj(proxyDatasObj, proxyDataUris)) { + return false; + } + } + return true; +} + +bool ModuleJson::GetProxyDataUrisByProxyDatasObj(std::unique_ptr& obj, std::list& proxyDataUris) +{ + if (!obj || !obj->IsArray()) { + return false; + } + for (int i = 0; i < obj->GetSize(); i++) { + std::unique_ptr proxyDataObj = obj->Get(i); + if (!proxyDataObj->Contains(PROXY_URI.c_str())) { + return false; + } + std::string proxyUri; + if (proxyDataObj->GetString(PROXY_URI.c_str(), &proxyUri) != Result::SUCCESS) { + return false; + } + proxyDataUris.push_back(proxyUri); + } + return true; +} + +bool ModuleJson::GetExtensionAbilityNames(std::list& extensionAbilityNames) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetAbilityNamesByModuleObj(moduleObj, extensionAbilityNames); +} + +bool ModuleJson::GetExtensionAbilityNamesByModuleObj(std::unique_ptr& obj, std::list& extensionAbilityNames) +{ + if (!obj) { + return false; + } + if (!obj->Contains(EXTENSION_ABILITIES.c_str())) { + return false; + } + std::unique_ptr abilitiesObj; + if (obj->GetArray(EXTENSION_ABILITIES.c_str(), &abilitiesObj) != Result::SUCCESS) { + return false; + } + for (int i = 0; i < abilitiesObj->GetSize(); i++) { + std::unique_ptr abilityObj = abilitiesObj->Get(i); + if (abilityObj->Contains(NAME.c_str())) { + std::string name; + if (abilityObj->GetString(NAME.c_str(), &name) != Result::SUCCESS) { + return false; + } + extensionAbilityNames.push_back(name); + } + } + return true; +} + +bool ModuleJson::GetStageModuleType(std::string& moduleType) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetStageModuleTypeByModuleObj(moduleObj, moduleType); +} + +bool ModuleJson::GetStageModuleTypeByModuleObj(std::unique_ptr& obj, std::string& moduleType) +{ + if (!obj) { + return false; + } + if (obj->Contains(TYPE.c_str())) { + if (obj->GetString(TYPE.c_str(), &moduleType) != Result::SUCCESS) { + return false; + } + } else { + moduleType = ""; + } + return true; +} + +bool ModuleJson::GetFaModuleType(std::string& moduleType) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetFaModuleTypeByModuleObj(moduleObj, moduleType); +} + +// java : parseFAIsEntry +bool ModuleJson::GetFaModuleTypeByModuleObj(std::unique_ptr& obj, std::string& moduleType) +{ + if (!obj) { + return false; + } + moduleType = ""; + if (obj->Contains(DISTRO.c_str())) { + std::unique_ptr distroObj; + if (obj->GetObject(DISTRO.c_str(), &distroObj) != Result::SUCCESS) { + return false; + } + if (distroObj->Contains(MODULE_TYPE.c_str())) { + if (obj->GetString(MODULE_TYPE.c_str(), &moduleType) != Result::SUCCESS) { + return false; + } + } + } + return true; +} + +bool ModuleJson::GetFaReleaseType(std::string& releaseType) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetFaReleaseTypeByAppObj(appObj, releaseType); +} + +bool ModuleJson::GetFaReleaseTypeByAppObj(std::unique_ptr& obj, std::string& releaseType) +{ + if (!obj) { + return false; + } + std::unique_ptr apiVersionObj; + releaseType = ""; + if (obj->Contains(API_VERSION.c_str())) { + if (obj->GetObject(API_VERSION.c_str(), &apiVersionObj) != Result::SUCCESS) { + return false; + } + if (apiVersionObj->Contains(RELEASE_TYPE.c_str())) { + if (obj->GetString(RELEASE_TYPE.c_str(), &releaseType) != Result::SUCCESS) { + return false; + } + } + } + return true; +} + +bool ModuleJson::GetDependencyItems(std::list& dependencyItems, const std::string& defaultBundleName) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetDependencyItemsByModuleObj(moduleObj, dependencyItems, defaultBundleName); +} + +bool ModuleJson::GetDependencyItemsByModuleObj(std::unique_ptr& obj, std::list& dependencyItems, const std::string& defaultBundleName) +{ + if (!obj) { + return false; + } + if (obj->Contains(DEPENDENCIES.c_str())) { + std::unique_ptr dependencyItemsObj; + if (obj->GetArray(DEPENDENCIES.c_str(), &dependencyItemsObj) != Result::SUCCESS) { + return false; + } + for (int i = 0; i < dependencyItemsObj->GetSize(); i++) { + std::unique_ptr dependencyItemObj = dependencyItemsObj->Get(i); + DependencyItem dependencyItem; + if (dependencyItemObj->Contains(BUNDLE_NAME.c_str())) { + if (dependencyItemObj->GetString(BUNDLE_NAME.c_str(), &dependencyItem.bundleName) != Result::SUCCESS) { + return false; + } + } else { + dependencyItem.bundleName = defaultBundleName; + } + if (dependencyItemObj->Contains(MODULE_NAME.c_str())) { + if (dependencyItemObj->GetString(MODULE_NAME.c_str(), &dependencyItem.moduleName) != Result::SUCCESS) { + return false; + } + } + dependencyItems.push_back(dependencyItem); + } + } + + return true; +} + +bool ModuleJson::GetStageBundleType(std::string& bundleType) +{ + std::unique_ptr appObj; + std::unique_ptr moduleObj; + if (!GetAppObject(appObj) || !GetModuleObject(moduleObj)) { + return false; + } + if (!moduleObj->Contains(TYPE.c_str())) { + return false; + } + std::string moduleName; + std::string moduleType; + bool installationFree = false; + if (!GetStageModuleNameByModuleObj(moduleObj, moduleName)) { + return false; + } + if (!GetStageModuleTypeByModuleObj(moduleObj, moduleType)) { + return false; + } + GetStageInstallationFreeByModuleObj(moduleObj, installationFree); + if (!appObj->Contains(BUNDLE_TYPE.c_str())) { + if (installationFree) { + return false; + } + bundleType = APP; + return true; + } else if (appObj->GetString(BUNDLE_TYPE.c_str(), &bundleType) == Result::SUCCESS) { + if (bundleType.compare(APP) == 0) { + if (installationFree) { + return false; + } + return true; + } else if (bundleType.compare(ATOMIC_SERVICE) == 0) { + if (!installationFree) { + return false; + } + return true; + } else if (bundleType.compare(SHARED) == 0) { + if (moduleType.compare(SHARED) != 0) { + return false; + } + return true; + } else if (bundleType.compare(APP_SERVICE) == 0) { + return true; + } + } + return false; +} + +bool ModuleJson::GetAtomicServicePreloads(std::list& preloadItems) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetAtomicServicePreloadsByModuleObj(moduleObj, preloadItems); +} + +bool ModuleJson::GetAtomicServicePreloadsByModuleObj(std::unique_ptr& obj, std::list& preloadItems) +{ + if (!obj) { + return false; + } + + if (!obj->Contains(ATOMIC_SERVICE.c_str())) { + return true; + } + std::unique_ptr atomicServiceObj; + if (obj->GetObject(ATOMIC_SERVICE.c_str(), &atomicServiceObj) != Result::SUCCESS) { + return false; + } + + if (!atomicServiceObj->Contains(PRELOADS.c_str())) { + return true; + } + std::unique_ptr preloadsObj; + if (obj->GetArray(PRELOADS.c_str(), &preloadsObj) != Result::SUCCESS) { + return false; + } + for (int i = 0; i < preloadsObj->GetSize(); i++) { + std::unique_ptr preloadObj = preloadsObj->Get(i); + PreloadItem preloadItem; + std::string moduleName; + if (preloadObj->Contains(MODULE_NAME.c_str())) { + if (preloadObj->GetString(MODULE_NAME.c_str(), &moduleName) == Result::SUCCESS) { + preloadItem.moduleName = moduleName; + } + } + preloadItems.push_back(preloadItem); + } + + return true; +} + +bool ModuleJson::GetAbilityContinueTypeMap(std::map>& abilityContinueTypeMap) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetAbilityContinueTypeMapByModuleObj(moduleObj, abilityContinueTypeMap); +} + +bool ModuleJson::GetAbilityContinueTypeMapByModuleObj(std::unique_ptr& obj, std::map>& abilityContinueTypeMap) +{ + if (!obj) { + return false; + } + if (obj->Contains(ABILITIES.c_str())) { + std::unique_ptr abilitysObj; + if (obj->GetArray(PRELOADS.c_str(), &abilitysObj) != Result::SUCCESS) { + return false; + } + for (int i = 0; i < abilitysObj->GetSize(); i++) { + std::unique_ptr abilityObj = abilitysObj->Get(i); + if (!abilityObj->Contains(NAME.c_str())) { + return false; + } + std::string abilityName; + if (abilityObj->GetString(MODULE_NAME.c_str(), &abilityName) != Result::SUCCESS) { + return false; + } + std::list continueTypes; + if (abilityObj->Contains(CONTINUE_TYPE.c_str())) { + std::unique_ptr continueTypeObj; + if (obj->GetArray(CONTINUE_TYPE.c_str(), &continueTypeObj) != Result::SUCCESS) { + return false; + } + + for (int j = 0; j < continueTypeObj->GetSize(); i++) { + continueTypes.push_back(continueTypeObj->Get(i)->GetString()); + } + } + abilityContinueTypeMap.emplace(abilityName, continueTypes); + } + } + return true; +} + +bool ModuleJson::GetMultiAppMode(MultiAppMode& multiAppMode) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetMultiAppModeByAppObj(appObj, multiAppMode); +} +bool ModuleJson::GetMultiAppModeByAppObj(std::unique_ptr& obj, MultiAppMode& multiAppMode) +{ + if (!obj) { + return false; + } + if (obj->Contains(MULTI_APP_MODE.c_str())) { + std::unique_ptr multiAppModeObj; + if (obj->GetObject(MULTI_APP_MODE.c_str(), &multiAppModeObj) != Result::SUCCESS) { + return false; + } + multiAppMode.multiAppModeType = ""; + multiAppMode.maxCount = 0; + if (multiAppModeObj->Contains(MULTI_APP_MODE_TYPE.c_str())) { + if (obj->GetString(MULTI_APP_MODE_TYPE.c_str(), &multiAppMode.multiAppModeType) != Result::SUCCESS) { + return false; + } + } + if (multiAppModeObj->Contains(MULTI_APP_MODE_NUMBER.c_str())) { + if (obj->GetInt(MULTI_APP_MODE_NUMBER.c_str(), &multiAppMode.maxCount) != Result::SUCCESS) { + return false; + } + } + } + return true; +} + +bool ModuleJson::GetStageAsanEnabled(bool& asanEnabled) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetStageAsanEnabledByAppObj(appObj, asanEnabled); +} + +bool ModuleJson::GetStageAsanEnabledByAppObj(std::unique_ptr& obj, bool& asanEnabled) +{ + if (!obj) { + return false; + } + if (obj->Contains(ASAN_ENABLED.c_str())) { + if (obj->GetBool(ASAN_ENABLED.c_str(), &asanEnabled) != Result::SUCCESS) { + return false; + } + } else { + asanEnabled = false; + } + return true; +} + +bool ModuleJson::GetFaAsanEnabled(bool& asanEnabled) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetFaAsanEnabledByAppObj(appObj, asanEnabled); +} + +bool ModuleJson::GetFaAsanEnabledByAppObj(std::unique_ptr& obj, bool& asanEnabled) +{ + if (!obj) { + return false; + } + if (obj->Contains(ASAN_ENABLED.c_str())) { + if (obj->GetBool(ASAN_ENABLED.c_str(), &asanEnabled) != Result::SUCCESS) { + return false; + } + } else { + asanEnabled = false; + } + return true; +} + +bool ModuleJson::GetStageTsanEnabled(bool& tsanEnabled) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetStageTsanEnabledByAppObj(appObj, tsanEnabled); +} + +bool ModuleJson::GetStageTsanEnabledByAppObj(std::unique_ptr& obj, bool& tsanEnabled) +{ + if (!obj) { + return false; + } + if (obj->Contains(TSAN_ENABLED.c_str())) { + if (obj->GetBool(TSAN_ENABLED.c_str(), &tsanEnabled) != Result::SUCCESS) { + return false; + } + } else { + tsanEnabled = false; + } + return true; +} + +bool ModuleJson::GetStageCompressNativeLibs(bool& compressNativeLibs) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetStageCompressNativeLibsByAppObj(appObj, compressNativeLibs); +} + +bool ModuleJson::GetStageCompressNativeLibsByAppObj(std::unique_ptr& obj, bool& compressNativeLibs) +{ + if (!obj) { + return false; + } + if (obj->Contains(COMPRESS_NATIVE_LIBS.c_str())) { + if (obj->GetBool(COMPRESS_NATIVE_LIBS.c_str(), &compressNativeLibs) != Result::SUCCESS) { + return false; + } + } else { + compressNativeLibs = false; + } + return true; +} + +// apiReleaseType was included in ModuleApiVersion. +bool ModuleJson::GetStageApiReleaseType(std::string& apiReleaseType) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetStageApiReleaseTypeByAppObj(appObj, apiReleaseType); +} + +bool ModuleJson::GetStageApiReleaseTypeByAppObj(std::unique_ptr& obj, std::string& apiReleaseType) +{ + if (!obj) { + return false; + } + if (obj->Contains(API_RELEASE_TYPE.c_str())) { + if (obj->GetString(API_RELEASE_TYPE.c_str(), &apiReleaseType) != Result::SUCCESS) { + return false; + } + } else { + apiReleaseType = ""; + } + return true; +} + +bool ModuleJson::GetFaDistroFilter(DistroFilter& distroFilter) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetFaDistroFilterByModuleObj(moduleObj, distroFilter); +} + +bool ModuleJson::GetFaDistroFilterByModuleObj(std::unique_ptr& obj, DistroFilter& distroFilter) +{ + if (!obj) { + return false; + } + if (obj->Contains(DISTRO_FILTER.c_str())) { + std::string distroFilterStr; + if (obj->GetString(DISTRO_FILTER.c_str(), &distroFilterStr) != Result::SUCCESS) { + return false; + } + std::unique_ptr distroFilterObj = PtJson::Parse(distroFilterStr); + if (!distroFilterObj) { + return false; + } + std::string distroFilterJsonStr; + if (distroFilterObj->Contains(DISTRO_FILTER.c_str())) { + if (distroFilterObj->GetString(DISTRO_FILTER.c_str(), &distroFilterJsonStr) != Result::SUCCESS) { + return false; + } + } + if (!distroFilter.ParseFromString(distroFilterJsonStr)) { + return false; + } + } + return true; +} + +// java Compressor.java : parseStageHapVerifyInfo / ModuleJsonUtil.java : parseStageHapVerifyInfo +// The following parameters require additional settings +// SetStageModule: stage is true, fa is false +// SetFileLength +// SetResourceMap +// SetProfileStr: this param can be delete, because it is also parsed by MODULE_JSON file +bool ModuleJson::GetStageHapVerifyInfo(HapVerifyInfo& hapVerifyInfo) +{ + std::unique_ptr appObj; + std::unique_ptr moduleObj; + if (!GetAppObject(appObj)) { + return false; + } + if (!GetModuleObject(moduleObj)) { + return false; + } + std::string bundleName; + std::string vendor; + Version version; + ModuleApiVersion moduleApiVersion; + std::string moduleName; + // std::list moduleMetadataInfos; + DistroFilter distroFilter; + std::list deviceTypes; + std::list abilityNames; + std::list extensionAbilityNames; + std::string moduleType; + std::list dependencyItems; + bool installationFree = false; + std::string bundleType; + std::list preloadItems; + std::string targetBundleName; + int32_t targetPriority = 0; + std::string targetModuleName; + int32_t targetModulePriority = 0; + bool debug = false; + std::string compileSdkType; + std::string compileSdkVersion; + std::list proxyDataUris; + std::map> abilityContinueTypeMap; + MultiAppMode multiAppMode; + if (!GetBundleNameByAppObj(appObj, bundleName)) { + return false; + } + if (!GetVendorByAppObj(appObj, vendor)) { + return false; + } + if (!GetStageVersionByAppObj(appObj, version)) { + return false; + } + if (!GetStageModuleApiVersionByAppObj(appObj, moduleApiVersion)) { + return false; + } + if (!GetStageModuleNameByModuleObj(moduleObj, moduleName)) { + return false; + } + if (!GetStageModuleNameByModuleObj(moduleObj, moduleName)) { + return false; + } + if (!GetStageDistroFilterByModuleObj(moduleObj, distroFilter)) { + return false; + } + if (!GetStageDeviceTypesByModuleObj(moduleObj, deviceTypes)) { + return false; + } + if (!GetAbilityNamesByModuleObj(moduleObj, abilityNames)) { + return false; + } + if (!GetExtensionAbilityNamesByModuleObj(moduleObj, extensionAbilityNames)) { + return false; + } + if (!GetStageModuleTypeByModuleObj(moduleObj, moduleType)) { + return false; + } + if (!GetDependencyItemsByModuleObj(moduleObj, dependencyItems, bundleName)) { + return false; + } + if (!GetStageInstallationFreeByModuleObj(moduleObj, installationFree)) { + return false; + } + if (!GetStageBundleType(bundleType)) { + return false; + } + if (!GetAtomicServicePreloadsByModuleObj(moduleObj, preloadItems)) { + return false; + } + if (!GetTargetBundleNameByAppObj(appObj, targetBundleName)) { + return false; + } + if (!GetTargetPriorityByAppObj(appObj, targetPriority)) { + return false; + } + if (!GetTargetModuleNameByModuleObj(moduleObj, targetModuleName)) { + return false; + } + if (!GetTargetModulePriorityByModuleObj(moduleObj, targetModulePriority)) { + return false; + } + if (!GetStageDebugByAppObj(appObj, debug)) { + return false; + } + if (!GetStageCompileSdkTypeByAppObj(moduleObj, compileSdkType)) { + return false; + } + if (!GetStageCompileSdkVersionByAppObj(moduleObj, compileSdkVersion)) { + return false; + } + if (!GetProxyDataUrisByModuleObj(moduleObj, proxyDataUris)) { + return false; + } + if (!GetAbilityContinueTypeMapByModuleObj(moduleObj, abilityContinueTypeMap)) { + return false; + } + if (!GetMultiAppModeByAppObj(moduleObj, multiAppMode)) { + return false; + } + hapVerifyInfo.SetBundleName(bundleName); + hapVerifyInfo.SetVendor(vendor); + hapVerifyInfo.SetVersion(version); + hapVerifyInfo.SetApiVersion(moduleApiVersion); + hapVerifyInfo.SetModuleName(moduleName); + hapVerifyInfo.SetDistroFilter(distroFilter); + hapVerifyInfo.SetDeviceTypes(deviceTypes); + hapVerifyInfo.SetAbilityNames(abilityNames); + hapVerifyInfo.AddAbilityNames(extensionAbilityNames); + hapVerifyInfo.SetModuleType(moduleType); + hapVerifyInfo.SetDependencyItemList(dependencyItems); + hapVerifyInfo.SetInstallationFree(installationFree); + hapVerifyInfo.SetBundleType(bundleType); + hapVerifyInfo.SetPreloadItems(preloadItems); + hapVerifyInfo.SetTargetBundleName(targetBundleName); + hapVerifyInfo.SetTargetPriority(targetPriority); + hapVerifyInfo.SetTargetModuleName(targetModuleName); + hapVerifyInfo.SetTargetModulePriority(targetModulePriority); + hapVerifyInfo.SetDebug(debug); + hapVerifyInfo.SetCompileSdkType(compileSdkType); + hapVerifyInfo.SetCompileSdkVersion(compileSdkVersion); + hapVerifyInfo.SetProxyDataUris(proxyDataUris); + hapVerifyInfo.SetContinueTypeMap(abilityContinueTypeMap); + hapVerifyInfo.SetMultiAppMode(multiAppMode); + + return true; +} + +bool ModuleJson::GetFaHapVerifyInfo(HapVerifyInfo& hapVerifyInfo) +{ + std::unique_ptr appObj; + std::unique_ptr moduleObj; + if (!GetAppObject(appObj)) { + return false; + } + if (!GetModuleObject(moduleObj)) { + return false; + } + std::string bundleName; + std::string bundleType; + std::string vendor; + Version version; + ModuleApiVersion moduleApiVersion; + std::string moduleName; + DistroFilter distroFilter; + std::list deviceTypes; + std::list abilityNames; + std::string moduleType; + std::string packageStr; + std::list dependencyItems; + bool installationFree = false; + bool debug = false; + std::string compileSdkType; + std::string compileSdkVersion; + + if (!GetBundleNameByAppObj(appObj, bundleName)) { + return false; + } + if (!GetFaBundleType(bundleType)) { + return false; + } + if (!GetVendorByAppObj(appObj, vendor)) { + return false; + } + if (!GetFaVersionByAppObj(appObj, version)) { + return false; + } + if (!GetFaModuleApiVersionByAppObj(appObj, moduleApiVersion)) { + return false; + } + if (!GetFaModuleNameByModuleObj(moduleObj, moduleName)) { + return false; + } + if (!GetFaDistroFilterByModuleObj(moduleObj, distroFilter)) { + return false; + } + if (!GetStageDeviceTypesByModuleObj(moduleObj, deviceTypes)) { + return false; + } + if (!GetAbilityNamesByModuleObj(moduleObj, abilityNames)) { + return false; + } + if (!GetFaModuleTypeByModuleObj(moduleObj, moduleType)) { + return false; + } + if (!GetFaPackageStrByModuleObj(moduleObj, packageStr)) { + return false; + } + if (!GetDependencyItemsByModuleObj(moduleObj, dependencyItems, bundleName)) { + return false; + } + if (!GetFaInstallationFreeByModuleObj(moduleObj, installationFree)) { + return false; + } + if (!GetFaDebugByAppObj(appObj, debug)) { + return false; + } + if (!GetFaCompileSdkTypeByAppObj(moduleObj, compileSdkType)) { + return false; + } + if (!GetFaCompileSdkVersionByAppObj(moduleObj, compileSdkVersion)) { + return false; + } + + hapVerifyInfo.SetBundleName(bundleName); + hapVerifyInfo.SetBundleType(bundleType); + hapVerifyInfo.SetVendor(vendor); + hapVerifyInfo.SetVersion(version); + hapVerifyInfo.SetApiVersion(moduleApiVersion); + hapVerifyInfo.SetModuleName(moduleName); + hapVerifyInfo.SetDistroFilter(distroFilter); + hapVerifyInfo.SetDeviceTypes(deviceTypes); + hapVerifyInfo.SetAbilityNames(abilityNames); + hapVerifyInfo.SetModuleType(moduleType); + hapVerifyInfo.SetPackageName(packageStr); + hapVerifyInfo.SetDependencyItemList(dependencyItems); + hapVerifyInfo.SetInstallationFree(installationFree); + hapVerifyInfo.SetDebug(debug); + hapVerifyInfo.SetCompileSdkType(compileSdkType); + hapVerifyInfo.SetCompileSdkVersion(compileSdkVersion); + + return true; +} + +bool ModuleJson::IsExistedStageRequestPermissions() +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return moduleObj->Contains(REQUEST_PERMISSIONS.c_str()); +} + +bool ModuleJson::IsExistedStageModuleTargetPriority() +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return moduleObj->Contains(TARGET_PRIORITY.c_str()); +} + +bool ModuleJson::IsExistedStageAppTargetPriority() +{ + std::unique_ptr appObj; + if (!GetModuleObject(appObj)) { + return false; + } + return appObj->Contains(TARGET_PRIORITY.c_str()); +} + +bool ModuleJson::IsModuleAtomicServiceValid() +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + if (!moduleObj->Contains(ATOMIC_SERVICE.c_str())) { + return true; + } + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + if (moduleObj->Contains(ATOMIC_SERVICE.c_str()) && !appObj->Contains(BUNDLE_TYPE.c_str())) { + return false; + } else if (appObj->Contains(BUNDLE_TYPE.c_str())) { + std::string bundleType; + if (appObj->GetString(BUNDLE_TYPE.c_str(), &bundleType) != Result::SUCCESS) { + return false; + } + if (bundleType.compare(ATOMIC_SERVICE) != 0) { + return false; + } + } + return true; +} + +bool ModuleJson::CheckEntryInAtomicService() +{ + std::string bundleType; + if (!GetStageBundleType(bundleType)) { + return false; + } + if (bundleType.compare(ATOMIC_SERVICE) != 0) { + return true; + } + std::string moduleType; + std::list abilityNames; + if (!GetStageModuleType(moduleType) || !GetAbilityNames(abilityNames)) { + return false; + } + if (moduleType.compare(ENTRY) == 0 && abilityNames.empty()) { + return false; + } + return true; +} + +bool ModuleJson::CheckAtomicServiceInstallationFree() +{ + std::unique_ptr moduleObj; + std::unique_ptr appObj; + if (!GetModuleObject(moduleObj) || !GetAppObject(appObj)) { + return false; + } + bool installationFree = false; + if (!GetStageInstallationFreeByModuleObj(moduleObj, installationFree)) { + return false; + } + if (!appObj->Contains(BUNDLE_TYPE.c_str())) { + if (installationFree) { + return false; + } + return true; + } + std::string bundleType; + if (!GetStageBundleType(bundleType)) { + return false; + } + if ((bundleType.compare(APP) == 0) || + (bundleType.compare(SHARED) == 0) || + (bundleType.compare(APP_SERVICE) == 0)) { + if (installationFree) { + return false; + } + } else if (bundleType.compare(ATOMIC_SERVICE) == 0) { + if (!installationFree) { + return false; + } + } else { + return false; + } + return true; +} + +bool ModuleJson::GetGenerateBuildHash(bool& generateBuildHash) +{ + std::unique_ptr moduleObj; + std::unique_ptr appObj; + if (!GetModuleObject(moduleObj) || !GetAppObject(appObj)) { + return false; + } + if (appObj->Contains(GENERATE_BUILD_HASH.c_str())) { + if (appObj->GetBool(GENERATE_BUILD_HASH.c_str(), &generateBuildHash) != Result::SUCCESS) { + return false; + } + } else if (moduleObj->Contains(GENERATE_BUILD_HASH.c_str())) { + if (moduleObj->GetBool(GENERATE_BUILD_HASH.c_str(), &generateBuildHash) != Result::SUCCESS) { + return false; + } + } else { + return false; + } + return true; +} + +bool ModuleJson::RemoveGenerateBuildHash() +{ + if (!RemoveGenerateBuildHashFromAppObj() || !RemoveGenerateBuildHashFromModuleObj()) { + return false; + } + return true; +} + +bool ModuleJson::RemoveGenerateBuildHashFromAppObj() +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + if (appObj->Contains(GENERATE_BUILD_HASH.c_str())) { + appObj->Remove(GENERATE_BUILD_HASH.c_str()); + } + return true; +} + +bool ModuleJson::RemoveGenerateBuildHashFromModuleObj() +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + if (moduleObj->Contains(GENERATE_BUILD_HASH.c_str())) { + moduleObj->Remove(GENERATE_BUILD_HASH.c_str()); + } + return true; +} + +} // namespace AppPackingTool +} // namespace OHOS diff --git a/ohos_packing_tool/frameworks/src/json/module_json_utils.cpp b/ohos_packing_tool/frameworks/src/json/module_json_utils.cpp new file mode 100644 index 00000000..6afd274b --- /dev/null +++ b/ohos_packing_tool/frameworks/src/json/module_json_utils.cpp @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// #include +// #include +// #include +#include +#include +#include +#include "module_json.h" +#include "module_json_utils.h" +#include "zip_utils.h" +#include "log.h" +#include "utils.h" + +namespace fs = std::filesystem; + +namespace OHOS { +namespace AppPackingTool { +namespace { + const std::string MODULE_JSON = "module.json"; + const std::string CONFIG_JSON = "config.json"; + const std::string HAP_SUFFIX = ".hap"; + const std::string HSP_SUFFIX = ".hsp"; + const int SHARED_APP_HSP_LIMIT = 1; + const std::string TYPE_SHARED = "shared"; + const std::string INCLUDE = "include"; + const std::string EXCLUDE = "exclude"; +} + +ModuleJsonUtils::ModuleJsonUtils() +{} + +ModuleJsonUtils::~ModuleJsonUtils() +{} + +// java : parseStageHapVerifyInfo +bool ModuleJsonUtils::GetStageHapVerifyInfo(const std::string& hapFilePath, HapVerifyInfo& hapVerifyInfo) +{ + std::string fileContent; + std::map resourceMap; + int64_t fileLength = Utils::GetFileLength(hapFilePath); + if (fileLength < 0) { + LOGE("Get hap file length failed! hapFile=%s", hapFilePath.c_str()); + return false; + } + if (!ZipUtils::GetFileContentFromZip(hapFilePath, MODULE_JSON, fileContent)) { + LOGE("Get module.json content from hap file failed! hapFile=%s", hapFilePath.c_str()); + return false; + } + if (!ZipUtils::GetResourceMapFromZip(hapFilePath, resourceMap)) { + LOGE("Get resouce map from hap file failed! hapFile=%s", hapFilePath.c_str()); + return false; + } + ModuleJson moduleJson; + if (!moduleJson.ParseFromString(fileContent)) { + LOGE("Parse json string failed!"); + return false; + } + if (!moduleJson.GetStageHapVerifyInfo(hapVerifyInfo)) { + LOGE("Get stage hap verify info failed!"); + return false; + } + hapVerifyInfo.SetResourceMap(resourceMap); + hapVerifyInfo.SetProfileStr(fileContent); + hapVerifyInfo.SetStageModule(true); + hapVerifyInfo.SetFileLength(fileLength); + return true; +} + +bool ModuleJsonUtils::GetFaHapVerifyInfo(const std::string& hapFilePath, HapVerifyInfo& hapVerifyInfo) +{ + std::string fileContent; + int64_t fileLength = Utils::GetFileLength(hapFilePath); + if (fileLength < 0) { + LOGE("Get hap file length failed! hapFile=%s", hapFilePath.c_str()); + return false; + } + if (!ZipUtils::GetFileContentFromZip(hapFilePath, CONFIG_JSON, fileContent)) { + LOGE("Get module.json content from hap file failed! hapFile=%s", hapFilePath.c_str()); + return false; + } + ModuleJson moduleJson; + if (!moduleJson.ParseFromString(fileContent)) { + LOGE("Parse json string failed!"); + return false; + } + if (!moduleJson.GetFaHapVerifyInfo(hapVerifyInfo)) { + LOGE("Get stage hap verify info failed!"); + return false; + } + hapVerifyInfo.SetProfileStr(fileContent); + hapVerifyInfo.SetStageModule(false); + hapVerifyInfo.SetFileLength(fileLength); + return true; +} + +// java : HapVerify::checkPolicyValueDisjoint +bool ModuleJsonUtils::CheckPolicyValueDisjoint(const PolicyValue& policyValue1, const PolicyValue& policyValue2) +{ + if (policyValue1.policy.compare(EXCLUDE) == 0 && policyValue2.policy.compare(INCLUDE) == 0) { + if (policyValue2.value.empty() || Utils::CheckContainsAll(policyValue1.value, policyValue2.value)) { + return true; + } + } else if (policyValue1.policy.compare(INCLUDE) == 0 && policyValue2.policy.compare(INCLUDE) == 0) { + if (Utils::CheckDisjoint(policyValue1.value, policyValue2.value)) { + return true; + } + } else if (policyValue1.policy.compare(INCLUDE) == 0 && policyValue2.policy.compare(EXCLUDE) == 0) { + if (policyValue1.value.empty() || Utils::CheckContainsAll(policyValue2.value, policyValue1.value)) { + return true; + } + } else if (policyValue1.policy.compare(EXCLUDE) == 0 && policyValue2.policy.compare(EXCLUDE) == 0) { + return false; + } + return false; +} + +// java : HapVerify::checkDuplicatedIsValid / HapVerify::checkDistroFilterDisjoint +bool ModuleJsonUtils::CheckDuplicatedIsValid(const HapVerifyInfo& hapVerifyInfo1, const HapVerifyInfo& hapVerifyInfo2) +{ + if (Utils::CheckDisjoint(hapVerifyInfo1.GetDeviceTypes(), hapVerifyInfo2.GetDeviceTypes())) { + return true; + } + const DistroFilter& distroFilter1 = hapVerifyInfo1.GetDistroFilter(); + const DistroFilter& distroFilter2 = hapVerifyInfo2.GetDistroFilter(); + if (distroFilter1.IsEmpty() || distroFilter2.IsEmpty()) { + return false; + } + if (!distroFilter1.apiVersion.IsEmpty() && !distroFilter2.apiVersion.IsEmpty()) { + if (CheckPolicyValueDisjoint(distroFilter1.apiVersion, distroFilter2.apiVersion)) { + return true; + } + } + if (!distroFilter1.screenShape.IsEmpty() && !distroFilter2.screenShape.IsEmpty()) { + if (CheckPolicyValueDisjoint(distroFilter1.screenShape, distroFilter2.screenShape)) { + return true; + } + } + if (!distroFilter1.screenDensity.IsEmpty() && !distroFilter2.screenDensity.IsEmpty()) { + if (CheckPolicyValueDisjoint(distroFilter1.screenDensity, distroFilter2.screenDensity)) { + return true; + } + } + if (!distroFilter1.screenWindow.IsEmpty() && !distroFilter2.screenWindow.IsEmpty()) { + if (CheckPolicyValueDisjoint(distroFilter1.screenWindow, distroFilter2.screenWindow)) { + return true; + } + } + if (!distroFilter1.countryCode.IsEmpty() && !distroFilter2.countryCode.IsEmpty()) { + if (CheckPolicyValueDisjoint(distroFilter1.countryCode, distroFilter2.countryCode)) { + return true; + } + } + return false; +} + +// java : Compressor::checkSharedAppIsValid / HapVerify::checkSharedApppIsValid +bool ModuleJsonUtils::CheckSharedAppIsValid(const std::list& hapVerifyInfos, bool& isOverlay) +{ + if (hapVerifyInfos.empty()) { + return false; + } + if (hapVerifyInfos.size() > SHARED_APP_HSP_LIMIT) { + return false; + } + for (HapVerifyInfo hapVerifyInfo : hapVerifyInfos) { + if (!hapVerifyInfo.GetTargetBundleName().empty()) { + isOverlay = true; + return true; + } + } + std::string moduleName = hapVerifyInfos.front().GetModuleName(); + for (HapVerifyInfo hapVerifyInfo : hapVerifyInfos) { + if (hapVerifyInfo.GetModuleName().compare(moduleName) != 0) { + return false; + } + if (!hapVerifyInfo.getDependencyItemList().empty()) { + return false; + } + if (!hapVerifyInfo.GetModuleType().compare(TYPE_SHARED)) { + return false; + } + } + for (auto iter1 = hapVerifyInfos.begin(); iter1 != hapVerifyInfos.end(); iter1++) { + for (auto iter2 = std::next(iter1); iter2 != hapVerifyInfos.end(); iter2++) { + if (!CheckDuplicatedIsValid(*iter1, *iter2)) { + return false; + } + } + } + return true; +} + +bool ModuleJsonUtils::CheckHapsIsValid(const std::list& fileList, const bool& isSharedApp) +{ + std::list hapVerifyInfos; + for (auto& hapPath : fileList) { + if (hapPath.empty()) { + LOGE("Hap file path is empty!"); + return false; + } + fs::path fsHapPath(hapPath); + std::string fileName = fsHapPath.filename().string(); + if (fileName.empty()) { + LOGE("Hap file name is empty!"); + return false; + } + std::transform(fileName.begin(), fileName.end(), fileName.begin(), ::tolower); + if (!Utils::EndsWith(fileName, HAP_SUFFIX) && !Utils::EndsWith(fileName, HSP_SUFFIX)) { + LOGE("Hap file is not a hap or hsp file!"); + return false; + } + HapVerifyInfo hapVerifyInfo; + if (IsModuleHap(hapPath)) { + if (!GetStageHapVerifyInfo(hapPath, hapVerifyInfo)) { + return false; + } + } else { + if (!GetFaHapVerifyInfo(hapPath, hapVerifyInfo)) { + return false; + } + } + hapVerifyInfos.push_back(hapVerifyInfo); + } + + if (isSharedApp) { + + } else { + + } + return true; +} + +bool ModuleJsonUtils::IsModuleHap(const std::string hapFilePath) +{ + return ZipUtils::IsFileExistsInZip(hapFilePath, MODULE_JSON); +} +} // namespace AppPackingTool +} // namespace OHOS diff --git a/ohos_packing_tool/frameworks/src/json/pack_info.cpp b/ohos_packing_tool/frameworks/src/json/pack_info.cpp new file mode 100644 index 00000000..f069b5e0 --- /dev/null +++ b/ohos_packing_tool/frameworks/src/json/pack_info.cpp @@ -0,0 +1,548 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "pack_info.h" +#include "log.h" +#include "utils.h" + +namespace OHOS { +namespace AppPackingTool { +namespace { + const std::string SUMMARY = "summary"; + const std::string PACKAGES = "packages"; + const std::string APP = "app"; + const std::string MODULES = "modules"; + // const std::string MODULE = "module"; + const std::string BUNDLE_NAME = "bundleName"; + const std::string BUNDLE_TYPE = "bundleType"; + const std::string VERSION = "version"; + const std::string CODE = "code"; + const std::string NAME = "name"; + const std::string DISTRO = "distro"; + const std::string MODULE_NAME = "moduleName"; + const std::string EXTENSION_ABILITIES = "extensionAbilities"; + const std::string FORMS = "forms"; + const std::string DEFAULT_DIMENSION = "defaultDimension"; + const std::string SUPPORT_DIMENSIONS = "supportDimensions"; + const char ASTERISK = '*'; +} + +PackInfo::PackInfo() +{ +} + +PackInfo::~PackInfo() +{ +} + +bool PackInfo::ParseFromString(const std::string& jsonString) +{ + Release(); + if (jsonString.length() == 0) { + return false; + } + root_ = PtJson::Parse(jsonString); + return IsValid(); +} + +bool PackInfo::ParseFromFile(const std::string& jsonFile) +{ + Release(); + std::ifstream inFile(jsonFile, std::ios::in); + if (!inFile.is_open()) { + return false; + } + std::string fileContent((std::istreambuf_iterator(inFile)), std::istreambuf_iterator()); + inFile.close(); + root_ = PtJson::Parse(fileContent); + return IsValid(); +} + +std::string PackInfo::ToString() +{ + return root_->Stringify(); +} + +void PackInfo::Release() +{ + if (root_) { + root_->ReleaseRoot(); + root_ = nullptr; + } +} + +bool PackInfo::IsValid() +{ + return (root_.get() != nullptr); +} + +bool PackInfo::GetSummaryObject(std::unique_ptr& summaryObj) +{ + if (root_.get() == nullptr) { + return false; + } + if (!root_->Contains(SUMMARY.c_str())) { + return false; + } + if (root_->GetObject(SUMMARY.c_str(), &summaryObj) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PackInfo::GetPackagesObject(std::unique_ptr& packagesObj) +{ + if (root_.get() == nullptr) { + return false; + } + if (!root_->Contains(PACKAGES.c_str())) { + return false; + } + if (root_->GetArray(PACKAGES.c_str(), &packagesObj) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PackInfo::GetAppObject(std::unique_ptr& appObj) +{ + std::unique_ptr summaryObj; + if (!GetSummaryObject(summaryObj)) { + return false; + } + if (!summaryObj->Contains(APP.c_str())) { + return false; + } + if (summaryObj->GetObject(APP.c_str(), &appObj) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PackInfo::GetModulesObject(std::unique_ptr& modulesObj) +{ + std::unique_ptr summaryObj; + if (!GetSummaryObject(summaryObj)) { + return false; + } + if (!summaryObj->Contains(MODULES.c_str())) { + return false; + } + if (summaryObj->GetArray(MODULES.c_str(), &modulesObj) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PackInfo::GetBundleName(std::string& bundleName) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetBundleNameByAppObj(appObj, bundleName); +} + +bool PackInfo::GetBundleNameByAppObj(const std::unique_ptr& appObj, std::string& bundleName) +{ + if (!appObj) { + return false; + } + if (!appObj->Contains(BUNDLE_NAME.c_str())) { + return false; + } + if (appObj->GetString(BUNDLE_NAME.c_str(), &bundleName) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PackInfo::SetBundleName(const std::string& bundleName) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + if (!appObj->Contains(BUNDLE_NAME.c_str())) { + return false; + } + if (appObj->SetString(BUNDLE_NAME.c_str(), bundleName) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PackInfo::GetBundleType(std::string& bundleType, const std::string& defaultBundleType) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetBundleTypeByAppObj(appObj, bundleType, defaultBundleType); +} + +bool PackInfo::GetBundleTypeByAppObj(const std::unique_ptr& appObj, std::string& bundleType, const std::string& defaultBundleType) +{ + if (!appObj) { + return false; + } + if (appObj->Contains(BUNDLE_TYPE.c_str())) { + if (appObj->GetString(BUNDLE_TYPE.c_str(), &bundleType) != Result::SUCCESS) { + return false; + } + } else { + bundleType = defaultBundleType; + } + return true; +} + +bool PackInfo::GetVersionObject(std::unique_ptr& versionObj) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + if (!appObj->Contains(VERSION.c_str())) { + return false; + } + if (appObj->GetObject(VERSION.c_str(), &versionObj) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PackInfo::GetDistroObject(int32_t moduleIndex, std::unique_ptr& distroObj) +{ + std::unique_ptr modulesObj; + if (!GetModulesObject(modulesObj)) { + return false; + } + return GetDistroObjectByModulesObj(modulesObj, moduleIndex, distroObj); +} + +bool PackInfo::GetDistroObjectByModulesObj(const std::unique_ptr& modulesObj, + int32_t moduleIndex, std::unique_ptr& distroObj) +{ + if (!modulesObj || !modulesObj->IsArray()) { + return false; + } + if (moduleIndex >= modulesObj->GetSize()) { + return false; + } + std::unique_ptr moduleObj = modulesObj->Get(moduleIndex); + return GetDistroObjectByModuleObj(moduleObj, distroObj); +} + +bool PackInfo::GetDistroObjectByModuleObj(const std::unique_ptr& moduleObj, + std::unique_ptr& distroObj) +{ + if (!moduleObj) { + return false; + } + if (!moduleObj->Contains(DISTRO.c_str())) { + return false; + } + if (moduleObj->GetObject(DISTRO.c_str(), &distroObj) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PackInfo::GetExtensionAbilitiesObj(int32_t moduleIndex, std::unique_ptr& extensionAbilitiesObj) +{ + std::unique_ptr modulesObj; + if (!GetModulesObject(modulesObj)) { + return false; + } + return GetDistroObjectByModulesObj(modulesObj, moduleIndex, extensionAbilitiesObj); +} + +bool PackInfo::GetExtensionAbilitiesObjByModulesObj(const std::unique_ptr& modulesObj, + int32_t moduleIndex, std::unique_ptr& extensionAbilitiesObj) +{ + if (!modulesObj || !modulesObj->IsArray()) { + return false; + } + if (moduleIndex >= modulesObj->GetSize()) { + return false; + } + std::unique_ptr moduleObj = modulesObj->Get(moduleIndex); + return GetExtensionAbilitiesObjByModuleObj(moduleObj, extensionAbilitiesObj); +} + +bool PackInfo::GetExtensionAbilitiesObjByModuleObj(const std::unique_ptr& moduleObj, + std::unique_ptr& extensionAbilitiesObj) +{ + if (!moduleObj) { + return false; + } + if (!moduleObj->Contains(EXTENSION_ABILITIES.c_str())) { + return false; + } + if (moduleObj->GetArray(EXTENSION_ABILITIES.c_str(), &extensionAbilitiesObj) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PackInfo::GetFormsObjByExtensionAbilityObj(const std::unique_ptr& extensionAbilityObj, + std::unique_ptr& formsObj) +{ + if (!extensionAbilityObj) { + return false; + } + if (!extensionAbilityObj->Contains(FORMS.c_str())) { + return false; + } + if (extensionAbilityObj->GetArray(FORMS.c_str(), &formsObj) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PackInfo::GetPackageObject(int32_t packageIndex, std::unique_ptr& packageObj) +{ + std::unique_ptr packagesObj; + if (!GetPackagesObject(packagesObj)) { + return false; + } + if (!packagesObj->IsArray()) { + return false; + } + if (packageIndex >= packagesObj->GetSize()) { + return false; + } + packageObj = packagesObj->Get(packageIndex); + return true; +} + +bool PackInfo::GetVersion(PackInfoVersion& version) +{ + std::unique_ptr versionObj; + if (!GetVersionObject(versionObj)) { + return false; + } + return GetVersionByVersionObj(versionObj, version); +} + +bool PackInfo::GetVersionByVersionObj(const std::unique_ptr& versionObj, PackInfoVersion& version) +{ + if (!versionObj) { + return false; + } + if (!versionObj->Contains(CODE.c_str()) || !versionObj->Contains(NAME.c_str())) { + return false; + } + if (versionObj->GetInt(CODE.c_str(), &version.code) != Result::SUCCESS) { + return false; + } + if (versionObj->GetString(NAME.c_str(), &version.name) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PackInfo::SetVersionCode(const int& versionCode) +{ + std::unique_ptr versionObj; + if (!GetVersionObject(versionObj)) { + return false; + } + if (!versionObj->Contains(CODE.c_str())) { + return false; + } + if (versionObj->SetInt(CODE.c_str(), versionCode) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PackInfo::SetVersionName(const std::string& versionName) +{ + std::unique_ptr versionObj; + if (!GetVersionObject(versionObj)) { + return false; + } + if (!versionObj->Contains(NAME.c_str())) { + return false; + } + if (versionObj->SetString(NAME.c_str(), versionName) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PackInfo::GetModuleNameByDistroObj(const std::unique_ptr& distroObj, std::string& moduleName) +{ + if (!distroObj) { + return false; + } + if (distroObj->Contains(MODULE_NAME.c_str())) { + if (distroObj->GetString(MODULE_NAME.c_str(), &moduleName) != Result::SUCCESS) { + return false; + } + } else { + moduleName = ""; + } + return true; +} + +bool PackInfo::GetNameByPackageObj(const std::unique_ptr& packageObj, std::string& name) +{ + if (!packageObj) { + return false; + } + if (packageObj->Contains(NAME.c_str())) { + if (packageObj->GetString(NAME.c_str(), &name) != Result::SUCCESS) { + return false; + } + } else { + name = ""; + } + return true; +} + +bool PackInfo::GetNameByFormObj(const std::unique_ptr& formObj, std::string& name) +{ + if (!formObj) { + return false; + } + if (formObj->Contains(NAME.c_str())) { + if (formObj->GetString(NAME.c_str(), &name) != Result::SUCCESS) { + return false; + } + } else { + name = ""; + } + return true; +} + +bool PackInfo::GetDefaultDimensionByFormObj(const std::unique_ptr& formObj, std::string& defaultDimension) +{ + if (!formObj) { + return false; + } + if (!formObj->Contains(DEFAULT_DIMENSION.c_str())) { + return false; + } + if (formObj->GetString(DEFAULT_DIMENSION.c_str(), &defaultDimension) != Result::SUCCESS) { + return false; + } + if (std::count(defaultDimension.begin(), defaultDimension.end(), ASTERISK) != 1) { + return false; + } + return true; +} + +bool PackInfo::GetSupportDimensionsByFormObj(const std::unique_ptr& formObj, std::list& supportDimensions) +{ + if (!formObj) { + return false; + } + if (!formObj->Contains(SUPPORT_DIMENSIONS.c_str())) { + return false; + } + std::unique_ptr supportDimensionsObj; + if (formObj->GetArray(SUPPORT_DIMENSIONS.c_str(), &supportDimensionsObj) != Result::SUCCESS) { + return false; + } + for (int i = 0; i < supportDimensionsObj->GetSize(); i++) { + supportDimensions.push_back(supportDimensionsObj->Get(i)->GetString()); + } + return true; +} + +// java : parsePackInfoFormsName +bool PackInfo::GetFormNames(std::list& formNames, std::list& formFullNames) +{ + std::unique_ptr modulesObj; + if (!GetModulesObject(modulesObj)) { + return false; + } + if (!modulesObj->IsArray()) { + return false; + } + for (int i = 0; i < modulesObj->GetSize(); i++) { + std::unique_ptr distroObj; + if (!GetDistroObjectByModuleObj(modulesObj->Get(i), distroObj)) { + return false; + } + std::string moduleName; + if (!GetModuleNameByDistroObj(distroObj, moduleName) || moduleName.empty()) { + continue; + } + std::unique_ptr extensionAbilitiesObj; + if (!GetExtensionAbilitiesObjByModuleObj(modulesObj->Get(i), extensionAbilitiesObj)) { + return false; + } + if (!GetFormNamesByExtensionAbilitiesObj(extensionAbilitiesObj, moduleName, formNames, formFullNames)) { + return false; + } + } + return true; +} + +bool PackInfo::GetFormNamesByExtensionAbilitiesObj(const std::unique_ptr& extensionAbilitiesObj, + std::string moduleName, std::list& formNames, std::list& formFullNames) +{ + if (!extensionAbilitiesObj || !extensionAbilitiesObj->IsArray()) { + return false; + } + for (int j = 0; j < extensionAbilitiesObj->GetSize(); j++) { + std::unique_ptr formsObj; + if (!GetFormsObjByExtensionAbilityObj(extensionAbilitiesObj->Get(j), formsObj)) { + return false; + } + if (!GetFormNamesByFormsObj(formsObj, moduleName, formNames, formFullNames)) { + return false; + } + } + return true; +} + + +bool PackInfo::GetFormNamesByFormsObj(const std::unique_ptr& formsObj, + std::string moduleName, std::list& formNames, std::list& formFullNames) +{ + if (!formsObj || !formsObj->IsArray()) { + return false; + } + for (int k = 0; k < formsObj->GetSize(); k++) { + std::string formName; + std::string defaultDimension; + std::list supportDimensions; + std::string formFullName; + if (!GetNameByFormObj(formsObj->Get(k), formName) || formName.empty()) { + continue; + } + formNames.push_back(formName); + if (!GetDefaultDimensionByFormObj(formsObj->Get(k), defaultDimension)) { + return false; + } + if (!GetSupportDimensionsByFormObj(formsObj->Get(k), supportDimensions)) { + return false; + } + for (std::string supportDimension : supportDimensions) { + formFullName = moduleName + "/" + formName + "-" + Utils::ReplaceAll(supportDimension, "*", "x"); + formFullNames.push_back(formFullName); + } + } + return true; +} + +} // namespace AppPackingTool +} // namespace OHOS diff --git a/ohos_packing_tool/frameworks/src/json/pack_info_utils.cpp b/ohos_packing_tool/frameworks/src/json/pack_info_utils.cpp new file mode 100644 index 00000000..8db2c26e --- /dev/null +++ b/ohos_packing_tool/frameworks/src/json/pack_info_utils.cpp @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "pack_info_utils.h" +#include "log.h" + +namespace OHOS { +namespace AppPackingTool { +namespace { + const std::string DEFAULT_BUNDLE_TYPE = "APP"; + const std::string MODULE = "module"; + const std::string PACKAGES = "packages"; + const char DOT = '.'; +} + +PackInfoUtils::PackInfoUtils() +{ +} + +PackInfoUtils::~PackInfoUtils() +{ +} + +// java : mergeTwoPackInfo +bool PackInfoUtils::MergeTwoPackInfos(std::string& srcPackInfoJsonStr1, std::string& srcPackInfoJsonStr2, std::string& dstPackInfoJsonStr) +{ + PackInfo srcPackInfo1; + PackInfo srcPackInfo2; + if (!srcPackInfo1.ParseFromString(srcPackInfoJsonStr1)) { + return false; + } + if (!srcPackInfo2.ParseFromString(srcPackInfoJsonStr2)) { + return false; + } + if (!VerifyPackInfos(srcPackInfo1, srcPackInfo2)) { + return false; + } + if (!MergeTwoPackInfos(srcPackInfo1, srcPackInfo2)) { + return false; + } + dstPackInfoJsonStr = srcPackInfo1.ToString(); + return true; +} + +// java : mergePackInfoObj +bool PackInfoUtils::MergeTwoPackInfos(PackInfo& srcPackInfo1, PackInfo& srcPackInfo2) +{ + std::unique_ptr modulesObj1; + std::unique_ptr modulesObj2; + if (!srcPackInfo1.GetModulesObject(modulesObj1) || !srcPackInfo2.GetModulesObject(modulesObj2)) { + return false; + } + if (!modulesObj1->IsArray() || !modulesObj2->IsArray()) { + return false; + } + for (int i = 0; i < modulesObj2->GetSize(); i++) { + if (!modulesObj1->Push(modulesObj2->Get(i))) { + return false; + } + } + + std::unique_ptr packagesObj1; + std::unique_ptr packagesObj2; + if (!srcPackInfo1.GetPackagesObject(packagesObj1) || !srcPackInfo2.GetPackagesObject(packagesObj2)) { + LOGE("323"); + return false; + } + if (!packagesObj1->IsArray() || !packagesObj2->IsArray()) { + return false; + } + for (int i = 0; i < packagesObj2->GetSize(); i++) { + if (!packagesObj1->Push(packagesObj2->Get(i))) { + return false; + } + } + return true; +} + +// java : mergeTwoPackInfoByPackagePair +bool PackInfoUtils::MergeTwoPackInfosByPackagePair(std::string& srcPackInfoJsonStr1, std::string& srcPackInfoJsonStr2, + std::map packagesMap, std::string& dstPackInfoJsonStr) +{ + PackInfo srcPackInfo1; + PackInfo srcPackInfo2; + if (!srcPackInfo1.ParseFromString(srcPackInfoJsonStr1)) { + return false; + } + if (!srcPackInfo2.ParseFromString(srcPackInfoJsonStr2)) { + return false; + } + if (!VerifyPackInfos(srcPackInfo1, srcPackInfo2)) { + return false; + } + std::map::iterator iter = packagesMap.begin(); + while (iter != packagesMap.end()) + { + std::string packageName = iter->first; + std::string moduleName = iter->second; + std::string tmpStr = packageName.substr(0, packageName.find_last_of(DOT)); + if (!MergeTwoPackInfos(srcPackInfo1, srcPackInfo2)) { + return false; + } + ++iter; + } + dstPackInfoJsonStr = srcPackInfo1.ToString(); + return true; +} + +// java : mergeTwoPackInfoObjByPackagePair +bool PackInfoUtils::MergeTwoPackInfosByPackagePair(PackInfo& srcPackInfo1, PackInfo& srcPackInfo2, + std::string& packageName, std::string& moduleName) +{ + std::unique_ptr modulesObj1; + std::unique_ptr modulesObj2; + if (!srcPackInfo1.GetModulesObject(modulesObj1) || !srcPackInfo2.GetModulesObject(modulesObj2)) { + return false; + } + if (!modulesObj1->IsArray() || !modulesObj2->IsArray()) { + return false; + } + bool isFind = false; + for (int i = 0; i < modulesObj2->GetSize(); i++) { + std::unique_ptr distroObj; + if (!srcPackInfo2.GetDistroObject(i, distroObj)) { + return false; + } + std::string moduleNameInDistroObj; + if (!srcPackInfo2.GetModuleNameByDistroObj(distroObj, moduleNameInDistroObj)) { + return false; + } + if (moduleNameInDistroObj.compare(moduleName) == 0) { + if (!modulesObj1->Push(modulesObj2->Get(i))) { + return false; + } + isFind = true; + break; + } + } + if (!isFind) { + return false; + } + + std::unique_ptr packagesObj1; + std::unique_ptr packagesObj2; + if (!srcPackInfo1.GetPackagesObject(packagesObj1) || !srcPackInfo2.GetPackagesObject(packagesObj2)) { + return false; + } + if (!packagesObj1->IsArray() || !packagesObj2->IsArray()) { + return false; + } + isFind = false; + for (int i = 0; i < packagesObj2->GetSize(); i++) { + std::string packageNameInPackageObj; + if (!srcPackInfo2.GetNameByPackageObj(packagesObj2->Get(i), packageNameInPackageObj)) { + return false; + } + if (packageNameInPackageObj.compare(packageName) == 0) { + if (!packagesObj1->Push(packagesObj2->Get(i))) { + return false; + } + isFind = true; + break; + } + } + if (!isFind) { + return false; + } + return true; +} + +// java : verifyPackInfo +bool PackInfoUtils::VerifyPackInfos(PackInfo& packInfo1, PackInfo& packInfo2) +{ + std::unique_ptr appObj1; + std::unique_ptr appObj2; + if (!packInfo1.GetAppObject(appObj1) || !packInfo2.GetAppObject(appObj2)) { + return false; + } + if (!CheckBundleNameInPackInfo(packInfo1, packInfo2)) { + return false; + } + if (!CheckBundleTypeInPackInfo(packInfo1, packInfo2)) { + return false; + } + if (!CheckVersionCodeInPackInfo(packInfo1, packInfo2)) { + return false; + } + return true; +} + +bool PackInfoUtils::CheckBundleNameInPackInfo(PackInfo& packInfo1, PackInfo& packInfo2) +{ + std::string bundleName1; + std::string bundleName2; + if (!packInfo1.GetBundleName(bundleName1)) { + return false; + } + if (!packInfo2.GetBundleName(bundleName2)) { + return false; + } + if (bundleName1.compare(bundleName2) != 0) { + return false; + } + return true; +} + +bool PackInfoUtils::CheckBundleTypeInPackInfo(PackInfo& packInfo1, PackInfo& packInfo2) +{ + std::string bundleType1; + std::string bundleType2; + if (!packInfo1.GetBundleType(bundleType1, DEFAULT_BUNDLE_TYPE)) { + return false; + } + if (!packInfo2.GetBundleType(bundleType2, DEFAULT_BUNDLE_TYPE)) { + return false; + } + if (bundleType1.compare(bundleType2) != 0) { + return false; + } + return true; +} + +bool PackInfoUtils::CheckVersionCodeInPackInfo(PackInfo& packInfo1, PackInfo& packInfo2) +{ + PackInfoVersion version1; + PackInfoVersion version2; + if (!packInfo1.GetVersion(version1)) { + return false; + } + if (!packInfo2.GetVersion(version2)) { + return false; + } + if (version1.code != version2.code) { + return false; + } + return true; +} +} // namespace AppPackingTool +} // namespace OHOS diff --git a/ohos_packing_tool/frameworks/src/json/patch_json.cpp b/ohos_packing_tool/frameworks/src/json/patch_json.cpp new file mode 100644 index 00000000..b4747020 --- /dev/null +++ b/ohos_packing_tool/frameworks/src/json/patch_json.cpp @@ -0,0 +1,364 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "patch_json.h" +#include "log.h" + +namespace OHOS { +namespace AppPackingTool { +namespace { + const std::string APP = "app"; + const std::string MODULE = "module"; + const std::string BUNDLE_NAME = "bundleName"; + const std::string VERSION_CODE = "versionCode"; + const std::string VERSION_NAME = "versionName"; + const std::string PATCH_VERSION_CODE = "patchVersionCode"; + const std::string PATCH_VERSION_NAME = "patchVersionName"; + const std::string NAME = "name"; + const std::string TYPE= "type"; + const std::string DEVICE_TYPES = "deviceTypes"; + const std::string ORIGINAL_MODULE_HASH = "originalModuleHash"; +} + +PatchJson::PatchJson() +{ +} + +PatchJson::~PatchJson() +{ +} + +bool PatchJson::ParseFromString(const std::string& jsonString) +{ + Release(); + if (jsonString.length() == 0) { + return false; + } + root_ = PtJson::Parse(jsonString); + return IsValid(); +} + +bool PatchJson::ParseFromFile(const std::string& jsonFile) +{ + Release(); + std::ifstream inFile(jsonFile, std::ios::in); + if (!inFile.is_open()) { + return false; + } + std::string fileContent((std::istreambuf_iterator(inFile)), std::istreambuf_iterator()); + inFile.close(); + root_ = PtJson::Parse(fileContent); + return IsValid(); +} + +std::string PatchJson::ToString() +{ + return root_->Stringify(); +} + +void PatchJson::Release() +{ + // if (root_.get() != nullptr) { + if (root_) { + root_->ReleaseRoot(); + root_ = nullptr; + } +} + +bool PatchJson::IsValid() +{ + return (root_.get() != nullptr); +} + +bool PatchJson::GetAppObject(std::unique_ptr& appObj) +{ + if (root_.get() == nullptr) { + return false; + } + if (!root_->Contains(APP.c_str())) { + return false; + } + if (root_->GetObject(APP.c_str(), &appObj) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PatchJson::GetModuleObject(std::unique_ptr& moduleObj) +{ + if (root_.get() == nullptr) { + return false; + } + if (!root_->Contains(MODULE.c_str())) { + return false; + } + if (root_->GetObject(MODULE.c_str(), &moduleObj) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PatchJson::GetBundleName(std::string& bundleName) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetBundleNameByAppObj(appObj, bundleName); +} + +bool PatchJson::GetBundleNameByAppObj(const std::unique_ptr& appObj, std::string& bundleName) +{ + if (!appObj) { + return false; + } + if (!appObj->Contains(BUNDLE_NAME.c_str())) { + return false; + } + if (appObj->GetString(BUNDLE_NAME.c_str(), &bundleName) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PatchJson::GetVersionCode(int32_t& versionCode) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetVersionCodeByAppObj(appObj, versionCode); +} + +bool PatchJson::GetVersionCodeByAppObj(const std::unique_ptr& appObj, int32_t& versionCode) +{ + if (!appObj) { + return false; + } + if (!appObj->Contains(VERSION_CODE.c_str())) { + return false; + } + if (appObj->GetInt(VERSION_CODE.c_str(), &versionCode) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PatchJson::GetVersionName(std::string& versionName) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetVersionNameByAppObj(appObj, versionName); +} + +bool PatchJson::GetVersionNameByAppObj(const std::unique_ptr& appObj, std::string& versionName) +{ + if (!appObj) { + return false; + } + if (!appObj->Contains(VERSION_NAME.c_str())) { + return false; + } + if (appObj->GetString(VERSION_NAME.c_str(), &versionName) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PatchJson::GetPatchVersionCode(int32_t& patchVersionCode) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetPatchVersionCodeByAppObj(appObj, patchVersionCode); +} + +bool PatchJson::GetPatchVersionCodeByAppObj(const std::unique_ptr& appObj, int32_t& patchVersionCode) +{ + if (!appObj) { + return false; + } + if (!appObj->Contains(PATCH_VERSION_CODE.c_str())) { + return false; + } + if (appObj->GetInt(PATCH_VERSION_CODE.c_str(), &patchVersionCode) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PatchJson::GetPatchVersionName(std::string& patchVersionName) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + return false; + } + return GetPatchVersionNameByAppObj(appObj, patchVersionName); +} + +bool PatchJson::GetPatchVersionNameByAppObj(const std::unique_ptr& appObj, std::string& patchVersionName) +{ + if (!appObj) { + return false; + } + if (!appObj->Contains(PATCH_VERSION_NAME.c_str())) { + return false; + } + if (appObj->GetString(PATCH_VERSION_NAME.c_str(), &patchVersionName) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PatchJson::GetName(std::string& name) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetNameByModuleObj(moduleObj, name); +} + +bool PatchJson::GetNameByModuleObj(const std::unique_ptr& moduleObj, std::string& name) +{ + if (!moduleObj) { + return false; + } + if (!moduleObj->Contains(NAME.c_str())) { + return false; + } + if (moduleObj->GetString(NAME.c_str(), &name) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PatchJson::GetType(std::string& type) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetTypeByModuleObj(moduleObj, type); +} + +bool PatchJson::GetTypeByModuleObj(const std::unique_ptr& moduleObj, std::string& type) +{ + if (!moduleObj) { + return false; + } + if (!moduleObj->Contains(TYPE.c_str())) { + return false; + } + if (moduleObj->GetString(TYPE.c_str(), &type) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PatchJson::GetDeviceTypes(std::list& deviceTypes) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetDeviceTypesByModuleObj(moduleObj, deviceTypes); +} + +bool PatchJson::GetDeviceTypesByModuleObj(const std::unique_ptr& moduleObj, std::list& deviceTypes) +{ + if (!moduleObj) { + return false; + } + if (!moduleObj->Contains(DEVICE_TYPES.c_str())) { + return false; + } + std::unique_ptr deviceTypesObj; + if (moduleObj->GetArray(DEVICE_TYPES.c_str(), &deviceTypesObj) != Result::SUCCESS) { + return false; + } + for (int i = 0; i < deviceTypesObj->GetSize(); i++) { + deviceTypes.push_back(deviceTypesObj->Get(i)->GetString()); + } + return true; +} + +bool PatchJson::GetOriginalModuleHash(std::string& originalModuleHash) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + return false; + } + return GetOriginalModuleHashByModuleObj(moduleObj, originalModuleHash); +} + +bool PatchJson::GetOriginalModuleHashByModuleObj(const std::unique_ptr& moduleObj, std::string& originalModuleHash) +{ + if (!moduleObj) { + return false; + } + if (!moduleObj->Contains(ORIGINAL_MODULE_HASH.c_str())) { + return false; + } + if (moduleObj->GetString(ORIGINAL_MODULE_HASH.c_str(), &originalModuleHash) != Result::SUCCESS) { + return false; + } + return true; +} + +bool PatchJson::GetHqfInfo(HqfInfo& hqfInfo) +{ + std::unique_ptr appObj; + std::unique_ptr moduleObj; + if (!GetAppObject(appObj) || !GetModuleObject(moduleObj)) { + return false; + } + std::string bundleName = ""; + int32_t versionCode = -1; + std::string versionName = ""; + int32_t patchVersionCode = -1; + std::string patchVersionName = ""; + std::string moduleName = ""; + std::string type = ""; + std::list deviceTypes; + std::string originalModuleHash = ""; + if (!GetBundleNameByAppObj(appObj, bundleName) || + !GetVersionCodeByAppObj(appObj, versionCode) || + !GetVersionNameByAppObj(appObj, versionName) || + !GetPatchVersionCodeByAppObj(appObj, patchVersionCode) || + !GetPatchVersionNameByAppObj(appObj, patchVersionName) || + !GetNameByModuleObj(moduleObj, moduleName) || + !GetTypeByModuleObj(moduleObj, type) || + !GetDeviceTypesByModuleObj(moduleObj, deviceTypes) || + !GetOriginalModuleHashByModuleObj(moduleObj, originalModuleHash)) { + return false; + } + hqfInfo.SetBundleName(bundleName); + hqfInfo.SetVersionCode(versionCode); + hqfInfo.SetVersionName(versionName); + hqfInfo.SetPatchVersionCode(patchVersionCode); + hqfInfo.SetPatchVersionName(patchVersionName); + hqfInfo.SetModuleName(moduleName); + hqfInfo.SetType(type); + hqfInfo.SetDeviceTypes(deviceTypes); + hqfInfo.SetOriginalModuleHash(originalModuleHash); + return true; +} +} // namespace AppPackingTool +} // namespace OHOS diff --git a/ohos_packing_tool/frameworks/src/json/patch_json_utils.cpp b/ohos_packing_tool/frameworks/src/json/patch_json_utils.cpp new file mode 100644 index 00000000..75d62179 --- /dev/null +++ b/ohos_packing_tool/frameworks/src/json/patch_json_utils.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "patch_json_utils.h" +#include "log.h" + +namespace OHOS { +namespace AppPackingTool { +namespace {} + +PatchJsonUtils::PatchJsonUtils() +{ +} + +PatchJsonUtils::~PatchJsonUtils() +{ +} + +bool PatchJsonUtils::ParsePatchByJsonFilePath(const std::string& patchJsonFilePath, HqfInfo& hqfInfo) +{ + PatchJson patchJson; + if (!patchJson.ParseFromFile(patchJsonFilePath)) { + return false; + } + if (!patchJson.GetHqfInfo(hqfInfo)) { + return false; + } + return true; +} + +bool PatchJsonUtils::ParsePatchByJsonStr(const std::string& patchJsonStr, HqfInfo& hqfInfo) +{ + PatchJson patchJson; + if (!patchJson.ParseFromString(patchJsonStr)) { + return false; + } + if (!patchJson.GetHqfInfo(hqfInfo)) { + return false; + } + return true; +} + +} // namespace AppPackingTool +} // namespace OHOS diff --git a/ohos_packing_tool/frameworks/src/json/pt_json.cpp b/ohos_packing_tool/frameworks/src/json/pt_json.cpp new file mode 100644 index 00000000..c061aa16 --- /dev/null +++ b/ohos_packing_tool/frameworks/src/json/pt_json.cpp @@ -0,0 +1,555 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "pt_json.h" +#include +#include "../log.h" + +// #include "libpandabase/macros.h" + +namespace OHOS { +namespace AppPackingTool { +std::unique_ptr PtJson::CreateObject() +{ + return std::make_unique(cJSON_CreateObject()); +} + +std::unique_ptr PtJson::CreateArray() +{ + return std::make_unique(cJSON_CreateArray()); +} + +void PtJson::ReleaseRoot() +{ + if (object_ != nullptr) { + cJSON_Delete(object_); + object_ = nullptr; + } +} + +std::unique_ptr PtJson::Parse(const std::string &data) +{ + cJSON *value = cJSON_ParseWithOpts(data.c_str(), nullptr, true); + return std::make_unique(value); +} + +std::string PtJson::Stringify() const +{ + if (object_ == nullptr) { + return ""; + } + + char *str = cJSON_PrintUnformatted(object_); + if (str == nullptr) { + return ""; + } + std::string result(str); + cJSON_free(str); + return result; +} + +bool PtJson::Add(const char *key, bool value) const +{ + assert(key != nullptr && !Contains(key)); + + cJSON *node = cJSON_CreateBool(value); + if (node == nullptr) { + return false; + } + + cJSON_bool ret = cJSON_AddItemToObject(object_, key, node); + if (ret == 0) { + cJSON_Delete(node); + return false; + } + + return true; +} + +bool PtJson::Add(const char *key, int32_t value) const +{ + return Add(key, static_cast(value)); +} + +bool PtJson::Add(const char *key, int64_t value) const +{ + return Add(key, static_cast(value)); +} + +bool PtJson::Add(const char *key, uint32_t value) const +{ + return Add(key, static_cast(value)); +} + +bool PtJson::Add(const char *key, double value) const +{ + assert(key != nullptr && !Contains(key)); + + cJSON *node = cJSON_CreateNumber(value); + if (node == nullptr) { + return false; + } + + cJSON_bool ret = cJSON_AddItemToObject(object_, key, node); + if (ret == 0) { + cJSON_Delete(node); + return false; + } + + return true; +} + +bool PtJson::Add(const char *key, const char *value) const +{ + assert(key != nullptr && !Contains(key)); + + cJSON *node = cJSON_CreateString(value); + if (node == nullptr) { + return false; + } + + cJSON_bool ret = cJSON_AddItemToObject(object_, key, node); + if (ret == 0) { + cJSON_Delete(node); + return false; + } + + return true; +} + +bool PtJson::Add(const char *key, const std::unique_ptr &value) const +{ + assert(key != nullptr && !Contains(key)); + + cJSON *node = value->GetJson(); + if (node == nullptr) { + return false; + } + + cJSON_bool ret = cJSON_AddItemToObject(object_, key, node); + if (ret == 0) { + return false; + } + + return true; +} + +bool PtJson::Push(bool value) const +{ + cJSON *node = cJSON_CreateBool(value); + if (node == nullptr) { + return false; + } + + cJSON_bool ret = cJSON_AddItemToArray(object_, node); + if (ret == 0) { + cJSON_Delete(node); + return false; + } + + return true; +} + +bool PtJson::Push(int32_t value) const +{ + return Push(static_cast(value)); +} + +bool PtJson::Push(int64_t value) const +{ + return Push(static_cast(value)); +} + +bool PtJson::Push(uint32_t value) const +{ + return Push(static_cast(value)); +} + +bool PtJson::Push(double value) const +{ + cJSON *node = cJSON_CreateNumber(value); + if (node == nullptr) { + return false; + } + + cJSON_bool ret = cJSON_AddItemToArray(object_, node); + if (ret == 0) { + cJSON_Delete(node); + return false; + } + + return true; +} + +bool PtJson::Push(const char *value) const +{ + cJSON *node = cJSON_CreateString(value); + if (node == nullptr) { + return false; + } + + cJSON_bool ret = cJSON_AddItemToArray(object_, node); + if (ret == 0) { + cJSON_Delete(node); + return false; + } + + return true; +} + +bool PtJson::Push(const std::unique_ptr &value) const +{ + if (value == nullptr) { + return false; + } + + cJSON *node = value->GetJson(); + if (node == nullptr) { + return false; + } + + cJSON_bool ret = cJSON_AddItemToArray(object_, node); + if (ret == 0) { + return false; + } + + return true; +} + +bool PtJson::Remove(const char *key) const +{ + assert(key != nullptr && Contains(key)); + + cJSON_DeleteItemFromObject(object_, key); + return true; +} + +bool PtJson::Contains(const char *key) const +{ + cJSON *node = cJSON_GetObjectItemCaseSensitive(object_, key); + return node != nullptr; +} + +std::string PtJson::GetKey() const +{ + if (object_ == nullptr || object_->string == nullptr) { + return ""; + } + return std::string(object_->string); +} + +cJSON *PtJson::GetJson() const +{ + return object_; +} + +bool PtJson::IsBool() const +{ + return cJSON_IsBool(object_) != 0; +} + +bool PtJson::IsNumber() const +{ + return cJSON_IsNumber(object_) != 0; +} + +bool PtJson::IsString() const +{ + return cJSON_IsString(object_) != 0; +} + +bool PtJson::IsObject() const +{ + return cJSON_IsObject(object_) != 0; +} + +bool PtJson::IsArray() const +{ + return cJSON_IsArray(object_) != 0; +} + +bool PtJson::IsNull() const +{ + return cJSON_IsNull(object_) != 0; +} + +bool PtJson::GetBool(bool defaultValue) const +{ + if (!IsBool()) { + return defaultValue; + } + + return cJSON_IsTrue(object_) != 0; +} + +int32_t PtJson::GetInt(int32_t defaultValue) const +{ + if (!IsNumber()) { + return defaultValue; + } + + return static_cast(object_->valuedouble); +} + +int64_t PtJson::GetInt64(int64_t defaultValue) const +{ + if (!IsNumber()) { + return defaultValue; + } + + return static_cast(object_->valuedouble); +} + +uint32_t PtJson::GetUInt(uint32_t defaultValue) const +{ + if (!IsNumber()) { + return defaultValue; + } + + return static_cast(object_->valuedouble); +} + +uint64_t PtJson::GetUInt64(uint64_t defaultValue) const +{ + if (!IsNumber()) { + return defaultValue; + } + + return static_cast(object_->valuedouble); +} + +double PtJson::GetDouble(double defaultValue) const +{ + if (!IsNumber()) { + return defaultValue; + } + + return object_->valuedouble; +} + +std::string PtJson::GetString() const +{ + if (!IsString()) { + return ""; + } + + return std::string(object_->valuestring); +} + +int32_t PtJson::GetSize() const +{ + return cJSON_GetArraySize(object_); +} + +std::unique_ptr PtJson::Get(int32_t index) const +{ + return std::make_unique(cJSON_GetArrayItem(object_, index)); +} + +Result PtJson::GetBool(const char *key, bool *value) const +{ + cJSON *item = cJSON_GetObjectItem(object_, key); + if (item == nullptr) { + return Result::NOT_EXIST; + } + if (cJSON_IsBool(item) == 0) { + return Result::TYPE_ERROR; + } + + *value = cJSON_IsTrue(item) != 0; + return Result::SUCCESS; +} + +Result PtJson::SetBool(const char *key, const bool& value) +{ + cJSON *item = cJSON_GetObjectItem(object_, key); + if (item == nullptr) { + return Result::NOT_EXIST; + } + cJSON_ReplaceItemInObject(object_, key, cJSON_CreateBool(value)); + return Result::SUCCESS; +} + +Result PtJson::GetInt(const char *key, int32_t *value) const +{ + double result; + Result ret = GetDouble(key, &result); + if (ret == Result::SUCCESS) { + *value = static_cast(result); + } + return ret; +} + +Result PtJson::SetInt(const char *key, const int32_t& value) +{ + cJSON *item = cJSON_GetObjectItem(object_, key); + if (item == nullptr) { + return Result::NOT_EXIST; + } + cJSON_ReplaceItemInObject(object_, key, cJSON_CreateNumber(value)); + return Result::SUCCESS; +} + +Result PtJson::GetInt64(const char *key, int64_t *value) const +{ + double result; + Result ret = GetDouble(key, &result); + if (ret == Result::SUCCESS) { + *value = static_cast(result); + } + return ret; +} + +Result PtJson::SetInt64(const char *key, const int64_t& value) +{ + cJSON *item = cJSON_GetObjectItem(object_, key); + if (item == nullptr) { + return Result::NOT_EXIST; + } + cJSON_ReplaceItemInObject(object_, key, cJSON_CreateNumber(value)); + return Result::SUCCESS; +} + +Result PtJson::GetUInt(const char *key, uint32_t *value) const +{ + double result; + Result ret = GetDouble(key, &result); + if (ret == Result::SUCCESS) { + *value = static_cast(result); + } + return ret; +} + +Result PtJson::SetUInt(const char *key, const uint32_t& value) +{ + cJSON *item = cJSON_GetObjectItem(object_, key); + if (item == nullptr) { + return Result::NOT_EXIST; + } + cJSON_ReplaceItemInObject(object_, key, cJSON_CreateNumber(value)); + return Result::SUCCESS; +} + +Result PtJson::GetUInt64(const char *key, uint64_t *value) const +{ + double result; + Result ret = GetDouble(key, &result); + if (ret == Result::SUCCESS) { + *value = static_cast(result); + } + return ret; +} + +Result PtJson::SetUInt64(const char *key, const uint64_t& value) +{ + cJSON *item = cJSON_GetObjectItem(object_, key); + if (item == nullptr) { + return Result::NOT_EXIST; + } + cJSON_ReplaceItemInObject(object_, key, cJSON_CreateNumber(value)); + return Result::SUCCESS; +} + +Result PtJson::GetDouble(const char *key, double *value) const +{ + cJSON *item = cJSON_GetObjectItem(object_, key); + if (item == nullptr) { + return Result::NOT_EXIST; + } + if (cJSON_IsNumber(item) == 0) { + return Result::TYPE_ERROR; + } + + *value = item->valuedouble; + return Result::SUCCESS; +} + +Result PtJson::SetDouble(const char *key, const double& value) +{ + cJSON *item = cJSON_GetObjectItem(object_, key); + if (item == nullptr) { + return Result::NOT_EXIST; + } + cJSON_ReplaceItemInObject(object_, key, cJSON_CreateNumber(value)); + return Result::SUCCESS; +} + +Result PtJson::GetString(const char *key, std::string *value) const +{ + cJSON *item = cJSON_GetObjectItem(object_, key); + if (item == nullptr) { + return Result::NOT_EXIST; + } + if (cJSON_IsString(item) == 0) { + return Result::TYPE_ERROR; + } + + *value = item->valuestring; + return Result::SUCCESS; +} + +Result PtJson::SetString(const char *key, const std::string& value) +{ + cJSON *item = cJSON_GetObjectItem(object_, key); + if (item == nullptr) { + return Result::NOT_EXIST; + } + if (cJSON_IsString(item) == 0) { + return Result::TYPE_ERROR; + } + cJSON_SetValuestring(item, value.c_str()); + return Result::SUCCESS; +} + +Result PtJson::GetObject(const char *key, std::unique_ptr *value) const +{ + cJSON *item = cJSON_GetObjectItem(object_, key); + if (item == nullptr) { + return Result::NOT_EXIST; + } + if (cJSON_IsObject(item) == 0) { + return Result::TYPE_ERROR; + } + + *value = std::make_unique(item); + return Result::SUCCESS; +} + +Result PtJson::GetArray(const char *key, std::unique_ptr *value) const +{ + cJSON *item = cJSON_GetObjectItem(object_, key); + if (item == nullptr) { + return Result::NOT_EXIST; + } + if (cJSON_IsArray(item) == 0) { + return Result::TYPE_ERROR; + } + + *value = std::make_unique(item); + return Result::SUCCESS; +} + +Result PtJson::GetAny(const char *key, std::unique_ptr *value) const +{ + cJSON *item = cJSON_GetObjectItem(object_, key); + if (item == nullptr) { + return Result::NOT_EXIST; + } + + *value = std::make_unique(item); + return Result::SUCCESS; +} +} // namespace AppPackingTool +} // namespace OHOS diff --git a/ohos_packing_tool/frameworks/src/log.cpp b/ohos_packing_tool/frameworks/src/log.cpp new file mode 100644 index 00000000..a5c0110a --- /dev/null +++ b/ohos_packing_tool/frameworks/src/log.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "log.h" + +namespace OHOS { +namespace AppPackingTool { +#define MAX_LOG_SIZE 10240 +#define DEFAULT_LOG_LEVEL LOG_LEVEL_DEBUG +const char LogLevelFlag[5] = {'D', 'I', 'W', 'E', 'F'}; + +void log(char *file, char *func, int line, int level, char *format, ...) +{ + if (level < DEFAULT_LOG_LEVEL) { + return; + } + auto now = std::chrono::system_clock::now(); + std::time_t now_t = std::chrono::system_clock::to_time_t(now); + std::tm* now_tm = std::localtime(&now_t); + std::chrono::milliseconds ms = std::chrono::duration_cast(now.time_since_epoch()) % 1000; + + va_list args; + va_start(args, format); + char buffer[MAX_LOG_SIZE]; + std::vsnprintf(buffer, MAX_LOG_SIZE, format, args); + va_end(args); + + std::cout << "[" << std::put_time(now_tm, "%Y-%m-%d %H:%M:%S") + << '.' << std::setfill('0') << std::setw(3) << ms.count() + << std::setw(0) << "]" + << "[" << file << ":" << line << "]" + << "[" << func << "]" + << "[" << LogLevelFlag[level] << "] " + << buffer + << std::endl; +} + +} // namespace AppPackingTool +} // namespace OHOS diff --git a/ohos_packing_tool/frameworks/src/unzip_wrapper.cpp b/ohos_packing_tool/frameworks/src/unzip_wrapper.cpp new file mode 100644 index 00000000..9ec67b55 --- /dev/null +++ b/ohos_packing_tool/frameworks/src/unzip_wrapper.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "unzip_wrapper.h" +#include "log.h" + +namespace OHOS { +namespace AppPackingTool { +namespace {} + +UnzipWrapper::UnzipWrapper() +{} + +UnzipWrapper::UnzipWrapper(std::string path) : unzFilePath_(path) +{} + +UnzipWrapper::~UnzipWrapper() +{ + Close(); +} + +int UnzipWrapper::Open(std::string& unzPath) +{ + unzFilePath_ = unzPath; + return Open(); +} + +int UnzipWrapper::Open() +{ + if (unzFile_ != nullptr) { + LOGE("unzip file handle has open"); + return ZIP_ERR_SUCCESS; + } + unzFile_ = unzOpen64(unzFilePath_.c_str()); + if (unzFile_ == nullptr) { + LOGE("unzip file handle open failed"); + return ZIP_ERR_FAILURE; + } + return ZIP_ERR_SUCCESS; +} + +void UnzipWrapper::Close() +{ + if (unzFile_ != nullptr) { + unzClose(unzFile_); + unzFile_ = nullptr; + } +} + +std::string UnzipWrapper::ExtractFile(const std::string filePath) +{ + char filename[MAX_ZIP_BUFFER_SIZE] = {0}; + unz_file_info64 fileInfo; + if (unzGetCurrentFileInfo64(unzFile_, &fileInfo, filename, MAX_ZIP_BUFFER_SIZE, NULL, 0, NULL, 0) != UNZ_OK) { + LOGE("get current file info in zip failed!"); + return ""; + } + fs::path fsUnzipPath(filename); + fs::path fsFilePath(filePath); + fs::path fsFullFilePath = fsFilePath / filename; + if (fileInfo.external_fa == ZIP_FILE_ATTR_DIRECTORY || fsUnzipPath.string().rfind('/') == fsUnzipPath.string().length()) { + if (!fs::exists(fsFullFilePath)) { + LOGI("fsFullFilePath not exist, create: %s", fsFullFilePath.string().c_str()); + fs::create_directories(fsFullFilePath.string()); + } + return fsFullFilePath.string(); + } + if (!fs::exists(fsFullFilePath.parent_path())) { + LOGI("fsFullFilePath not exists, create : %s", fsFullFilePath.parent_path().string().c_str()); + fs::create_directories(fsFullFilePath.parent_path().string()); + } + if (unzOpenCurrentFile(unzFile_) != UNZ_OK) { + LOGE("open current file in zip failed![filename=%s]", filename); + return ""; + } + std::fstream file; + file.open(fsFullFilePath.string(), std::ios_base::out | std::ios_base::binary); + if (!file.is_open()) { + LOGE("open file failed![fsFullFilePath=%s]", fsFullFilePath.string().c_str()); + return ""; + } + char fileData[MAX_ZIP_BUFFER_SIZE] = {0}; + int32_t bytesRead; + do { + bytesRead = unzReadCurrentFile(unzFile_, (voidp)fileData, MAX_ZIP_BUFFER_SIZE); + if (bytesRead < 0) { + LOGE("Read current file in zip failed!!"); + file.close(); + return ""; + } + file.write(fileData, bytesRead); + + } while (bytesRead > 0); + file.close(); + unzCloseCurrentFile(unzFile_); + return fsFullFilePath.string(); +} + +int UnzipWrapper::UnzipFile(std::string filePath) +{ + LOGI("Unzip file[%s] to [%s]", unzFilePath_.c_str(), filePath.c_str()); + if (unzFile_ == nullptr) { + LOGE("zip file not open"); + return ZIP_ERR_FAILURE; + } + if (unzGetGlobalInfo64(unzFile_, &unzGlobalInfo_) != UNZ_OK ) { + LOGE("Get global info failed!"); + return ZIP_ERR_FAILURE; + } + int ret = UNZ_OK; + for (size_t i = 0; i < unzGlobalInfo_.number_entry; ++i) { + std::string f = ExtractFile(filePath); + if (f.empty()) { + LOGE("Extract file failed!"); + return ZIP_ERR_FAILURE; + } + ret = unzGoToNextFile(unzFile_); + if (ret == UNZ_END_OF_LIST_OF_FILE) { + break; + } else if (ret != UNZ_OK) { + LOGE("Go to next file in zip failed!"); + return ZIP_ERR_FAILURE; + } + } + return ZIP_ERR_SUCCESS; +} + +} // namespace AppPackingTool +} // namespace OHOS diff --git a/ohos_packing_tool/frameworks/src/utils.cpp b/ohos_packing_tool/frameworks/src/utils.cpp new file mode 100644 index 00000000..23e9f31a --- /dev/null +++ b/ohos_packing_tool/frameworks/src/utils.cpp @@ -0,0 +1,251 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "utils.h" + +namespace OHOS { +namespace AppPackingTool { +namespace { + const int BUFFER_SIZE = 1024; + const int HEX_WIDTH = 2; + const char PATH_DELIMITER = '/'; +} + +Utils::Utils() +{} + +Utils::~Utils() +{} + +std::string Utils::GetFileContent(const std::string filePath) +{ + std::ifstream inFile(filePath, std::ios::in); + if (!inFile.is_open()) { + return nullptr; + } + std::string fileContent((std::istreambuf_iterator(inFile)), std::istreambuf_iterator()); + inFile.close(); + return fileContent; +} + +std::string Utils::ListToString(const std::list& lst) { + std::stringstream ss; + for (auto str : lst) { + ss << str; + } + return ss.str(); +} + +std::string Utils::ReplaceAll(std::string str, const std::string& from, const std::string& to) +{ + size_t startPos = 0; + while ((startPos = str.find(from, startPos)) != std::string::npos) { + str.replace(startPos, from.length(), to); + startPos += to.length(); + } + return str; +} + +int64_t Utils::GetFileLength(const std::string filePath) +{ + struct stat statbuf = { 0 }; + if (stat(filePath.c_str(), &statbuf) != 0) { + return -1; + } + return statbuf.st_size; +} + +bool Utils::EndsWith(const std::string& str, const std::string& suffix) +{ + if (str.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), str.rbegin())) { + return true; + } + return false; +} + +// If there is no same element then returns true, else then returns false +bool Utils::CheckDisjoint(const std::list& list1, const std::list& list2) +{ + for (const std::string& str1 : list1) { + for (const std::string& str2 : list2) { + if (str1.compare(str2) == 0) { + return false; + } + } + } + return true; +} + +// If list1 contains all elements in list2, returns true, else returns false +bool Utils::CheckContainsAll(const std::list& list1, const std::list& list2) +{ + bool isFind = false; + for (const std::string& str2 : list2) { + isFind = false; + for (const std::string& str1 : list1) { + if (str2.compare(str1) == 0) { + isFind = true; + break; + } + } + if (!isFind) { + return false; + } + } + return true; +} + +std::string Utils::GetSha256Str(const std::string &str) +{ + unsigned char hash[SHA256_DIGEST_LENGTH]; + SHA256_CTX ctx; + SHA256_Init(&ctx); + SHA256_Update(&ctx, str.c_str(), str.length()); + SHA256_Final(hash, &ctx); + + // Convert hash to hex string + std::stringstream ss; + for (int i = 0; i < SHA256_DIGEST_LENGTH; ++i) { + ss << std::hex << std::setw(HEX_WIDTH) << std::setfill('0') << static_cast(hash[i]); + } + return ss.str(); +} + +std::string Utils::GetSha256File(const std::string &filePath) +{ + std::ifstream file(filePath, std::ios::binary); + if (!file) { + return ""; + } + SHA256_CTX ctx; + SHA256_Init(&ctx); + std::vector buffer(BUFFER_SIZE); + while (!file.eof()) { + file.read(buffer.data(), BUFFER_SIZE); + SHA256_Update(&ctx, buffer.data(), file.gcount()); + } + unsigned char hash[SHA256_DIGEST_LENGTH]; + SHA256_Final(hash, &ctx); + + // Convert hash to hex string + std::stringstream ss; + for (int i = 0; i < SHA256_DIGEST_LENGTH; ++i) { + ss << std::hex << std::setw(HEX_WIDTH) << std::setfill('0') << static_cast(hash[i]); + } + return ss.str(); +} + +bool Utils::IsFileExists(const std::string& file) +{ + return access(file.c_str(), F_OK) == 0; +} + +bool Utils::IsFile(const std::string& file) +{ + struct stat statBuf {}; + return lstat(file.c_str(), &statBuf) == 0 ? S_ISREG(statBuf.st_mode) : false; +} + +bool Utils::IsDirectory(const std::string& dir) +{ + struct stat statBuf {}; + return lstat(dir.c_str(), &statBuf) == 0 ? S_ISDIR(statBuf.st_mode) : false; +} + +bool Utils::RemoveFile(const std::string& file) +{ + return !IsFileExists(file) || (remove(file.c_str()) == 0); +} + +bool Utils::RemoveDirectory(const std::string& dir) +{ + return !IsFileExists(dir) || (rmdir(dir.c_str()) == 0); +} + +std::string Utils::GetFilePathByDir(const std::string& dir, const std::string& fileName) +{ + if (dir.empty()) { + return fileName; + } + std::string filePath = dir; + if (filePath.back() != '/') { + filePath.push_back(PATH_DELIMITER); + } + filePath.append(fileName); + return filePath; +} + +bool Utils::ForceCreateDirectory(const std::string& dir) +{ + std::string::size_type index = 0; + do { + std::string subPath; + index = dir.find('/', index + 1); // (index + 1) means the next char traversed + if (index == std::string::npos) { + subPath = dir; + } else { + subPath = dir.substr(0, index); + } + + if (!IsFileExists(subPath) && mkdir(subPath.c_str(), S_IRWXU) != 0) { + return false; + } + } while (index != std::string::npos); + return IsFileExists(dir); +} + +bool Utils::ForceRemoveDirectory(const std::string& dir, bool isDeleteSelf) +{ + if (IsFile(dir)) { + return RemoveFile(dir); + } else if (IsDirectory(dir)) { + DIR* dirPtr = opendir(dir.c_str()); + if (dirPtr == nullptr) { + return false; + } + struct dirent* dirInfo = nullptr; + while ((dirInfo = readdir(dirPtr)) != nullptr) { + // do not process the special dir + if (strcmp(dirInfo->d_name, ".") == 0 || strcmp(dirInfo->d_name, "..") == 0) { + continue; + } + std::string filePath = GetFilePathByDir(dir, dirInfo->d_name); + if (!ForceRemoveDirectory(filePath)) { + closedir(dirPtr); + return false; + } + } + closedir(dirPtr); + if (isDeleteSelf && !RemoveDirectory(dir)) { + return false; + } + } else { + return false; + } + return true; +} +} // namespace AppPackingTool +} // namespace OHOS \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/src/zip_utils.cpp b/ohos_packing_tool/frameworks/src/zip_utils.cpp new file mode 100644 index 00000000..9675e391 --- /dev/null +++ b/ohos_packing_tool/frameworks/src/zip_utils.cpp @@ -0,0 +1,291 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "zip_utils.h" +#include "log.h" +#include "utils.h" + +namespace OHOS { +namespace AppPackingTool { +namespace { + const std::string RESOURCE_PATH = "resources/base/profile/"; +} + +ZipUtils::ZipUtils() +{} + +ZipUtils::~ZipUtils() +{} + +int ZipUtils::Zip(const std::string& filePath, const std::string& zipFilePath, + const std::string& zipPath, const ZipLevel& zipLevel, const int& append) +{ + ZipWrapper zipWrapper(zipFilePath); + if (zipWrapper.Open(append) != ZIP_ERR_SUCCESS) { + LOGE("ZipWrapper Open failed!"); + return ZIP_ERR_FAILURE; + } + if (zipLevel != ZipLevel::ZIP_LEVEL_DEFAULT) { + zipWrapper.SetZipLevel(zipLevel); + } + int ret = zipWrapper.AddFileOrDirectoryToZip(filePath, zipPath); + if (ret != ZIP_ERR_SUCCESS) { + LOGE("ZipWrapper AddFileOrDirectoryToZip failed!"); + } + zipWrapper.Close(); + return ret; +} + +int ZipUtils::Unzip(const std::string& zipPath, const std::string& filePath) +{ + UnzipWrapper unzipWrapper(zipPath); + if (unzipWrapper.Open() != ZIP_ERR_SUCCESS) { + LOGE("UnzipWrapper Open failed!"); + return ZIP_ERR_FAILURE; + } + int ret = unzipWrapper.UnzipFile(filePath); + if (ret != ZIP_ERR_SUCCESS) { + LOGE("UnzipWrapper UnzipFile failed!"); + } + unzipWrapper.Close(); + return ret; +} + +bool ZipUtils::IsFileExistsInZip(const std::string& zipFilePath, const std::string& filename) +{ + fs::path fsZipFilePath(zipFilePath); + if (!fs::is_regular_file(fsZipFilePath)) { + LOGE("Zip file is not a regular file!"); + return false; + } + unzFile unzipFile = unzOpen64(zipFilePath.c_str()); + if (unzipFile == nullptr) { + LOGE("Open zip file failed! zipFilePath=%s", zipFilePath.c_str()); + return false; + } + unz_global_info64 unzGlobalInfo; + if (unzGetGlobalInfo64(unzipFile, &unzGlobalInfo) != UNZ_OK ) { + LOGE("Get zip global info! zipFilePath=%s", zipFilePath.c_str()); + unzClose(unzipFile); + return false; + } + char filePathInZip[MAX_ZIP_BUFFER_SIZE] = {0}; + unz_file_info64 fileInfo; + int ret = 0; + bool isExist = false; + for (size_t i = 0; i < unzGlobalInfo.number_entry; ++i) { + if (unzGetCurrentFileInfo64(unzipFile, &fileInfo, filePathInZip, MAX_ZIP_BUFFER_SIZE, NULL, 0, NULL, 0) != UNZ_OK) { + LOGE("Get current file info in zip failed!"); + break; + } + std::string strFilePathInZip(filePathInZip); + if (fileInfo.external_fa != ZIP_FILE_ATTR_DIRECTORY && strFilePathInZip.length() >= filename.length()) { + std::transform(strFilePathInZip.begin(), strFilePathInZip.end(), strFilePathInZip.begin(), ::tolower); + if (strFilePathInZip.compare(filename) == 0) { + isExist = true; + break; + } + } + ret = unzGoToNextFile(unzipFile); + if (ret == UNZ_END_OF_LIST_OF_FILE) { + break; + } else if (ret != UNZ_OK) { + LOGE("Go to next file in zip failed!"); + break; + } + } + unzClose(unzipFile); + return isExist; +} + +bool ZipUtils::IsFileNameExistsInZip(const std::string& zipFilePath, const std::string& filename) +{ + fs::path fsZipFilePath(zipFilePath); + if (!fs::is_regular_file(fsZipFilePath)) { + LOGE("Zip file is not a regular file!"); + return false; + } + unzFile unzipFile = unzOpen64(zipFilePath.c_str()); + if (unzipFile == nullptr) { + LOGE("Open zip file failed! zipFilePath=%s", zipFilePath.c_str()); + return false; + } + unz_global_info64 unzGlobalInfo; + if (unzGetGlobalInfo64(unzipFile, &unzGlobalInfo) != UNZ_OK ) { + LOGE("Get zip global info! zipFilePath=%s", zipFilePath.c_str()); + unzClose(unzipFile); + return false; + } + char filePathInZip[MAX_ZIP_BUFFER_SIZE] = {0}; + unz_file_info64 fileInfo; + int ret = 0; + bool isExist = false; + for (size_t i = 0; i < unzGlobalInfo.number_entry; ++i) { + if (unzGetCurrentFileInfo64(unzipFile, &fileInfo, filePathInZip, MAX_ZIP_BUFFER_SIZE, NULL, 0, NULL, 0) != UNZ_OK) { + LOGE("Get current file info in zip failed!"); + break; + } + std::string strFilePathInZip(filePathInZip); + if (fileInfo.external_fa != ZIP_FILE_ATTR_DIRECTORY && strFilePathInZip.length() >= filename.length()) { + if (strFilePathInZip.substr(strFilePathInZip.length() - filename.length()).compare(filename) == 0) { + isExist = true; + break; + } + } + ret = unzGoToNextFile(unzipFile); + if (ret == UNZ_END_OF_LIST_OF_FILE) { + break; + } else if (ret != UNZ_OK) { + LOGE("Go to next file in zip failed!"); + break; + } + } + unzClose(unzipFile); + return isExist; +} + +bool ZipUtils::GetFileContentFromZip(const std::string& zipFilePath, const std::string& filename, std::string& fileContent) +{ + fs::path fsZipFilePath(zipFilePath); + if (!fs::is_regular_file(fsZipFilePath)) { + LOGE("Zip file is not a regular file!"); + return false; + } + unzFile unzipFile = unzOpen64(zipFilePath.c_str()); + if (unzipFile == nullptr) { + LOGE("Open zip file failed! zipFilePath=%s", zipFilePath.c_str()); + return false; + } + if (unzLocateFile(unzipFile, filename.c_str(), 0) != UNZ_OK) { + LOGE("Locate file failed! filename=%s", filename.c_str()); + unzClose(unzipFile); + return false; + } + unz_file_info64 fileInfo; + char filePathInZip[MAX_ZIP_BUFFER_SIZE] = {0}; + if (unzGetCurrentFileInfo64(unzipFile, &fileInfo, filePathInZip, MAX_ZIP_BUFFER_SIZE, NULL, 0, NULL, 0) != UNZ_OK) { + LOGE("Get current file info in zip failed! filename=%s", filename.c_str()); + unzClose(unzipFile); + return false; + } + if (unzOpenCurrentFile(unzipFile) != UNZ_OK) { + LOGE("Open current file in zip failed! filename=%s", filename.c_str()); + unzClose(unzipFile); + return false; + } + char buffer[MAX_ZIP_BUFFER_SIZE]; + int readLen = 0; + fileContent = ""; + while(true) { + std::memset(buffer, 0, MAX_ZIP_BUFFER_SIZE); + readLen = unzReadCurrentFile(unzipFile, buffer, MAX_ZIP_BUFFER_SIZE); + if (readLen < 0) { + LOGE("Read current file in zip failed! filename=%s", filename.c_str()); + unzCloseCurrentFile(unzipFile); + unzClose(unzipFile); + return false; + } else if (readLen == 0) { + break; + } + fileContent += std::string(buffer); + } + unzCloseCurrentFile(unzipFile); + unzClose(unzipFile); + return true; +} + +bool ZipUtils::GetUnzipCurrentFileContent(unzFile& unzipFile, std::string& fileContent) +{ + if (unzipFile == nullptr) { + return false; + } + if (unzOpenCurrentFile(unzipFile) != UNZ_OK) { + LOGE("Open current file in zip failed!"); + return false; + } + char buffer[MAX_ZIP_BUFFER_SIZE]; + int readLen = 0; + fileContent = ""; + while(true) { + std::memset(buffer, 0, MAX_ZIP_BUFFER_SIZE); + readLen = unzReadCurrentFile(unzipFile, buffer, MAX_ZIP_BUFFER_SIZE); + if (readLen < 0) { + LOGE("Read current file in zip failed!"); + unzCloseCurrentFile(unzipFile); + return false; + } else if (readLen == 0) { + break; + } + fileContent += std::string(buffer); + } + unzCloseCurrentFile(unzipFile); + return true; +} + +bool ZipUtils::GetResourceMapFromZip(const std::string& zipFilePath, std::map& resourceMap) +{ + fs::path fsZipFilePath(zipFilePath); + if (!fs::is_regular_file(fsZipFilePath)) { + LOGE("Zip file is not a regular file!"); + return false; + } + unzFile unzipFile = unzOpen64(zipFilePath.c_str()); + if (unzipFile == nullptr) { + LOGE("Open zip file failed! zipFilePath=%s", zipFilePath.c_str()); + return false; + } + unz_global_info64 unzGlobalInfo; + if (unzGetGlobalInfo64(unzipFile, &unzGlobalInfo) != UNZ_OK ) { + LOGE("Get zip global info! zipFilePath=%s", zipFilePath.c_str()); + unzClose(unzipFile); + return false; + } + char filePathInZip[MAX_ZIP_BUFFER_SIZE] = {0}; + unz_file_info64 fileInfo; + int ret = 0; + for (size_t i = 0; i < unzGlobalInfo.number_entry; ++i) { + if (unzGetCurrentFileInfo64(unzipFile, &fileInfo, filePathInZip, MAX_ZIP_BUFFER_SIZE, NULL, 0, NULL, 0) != UNZ_OK) { + LOGE("Get current file info in zip failed!"); + break; + } + std::string strFilePathInZip(filePathInZip); + if (fileInfo.external_fa != ZIP_FILE_ATTR_DIRECTORY && strFilePathInZip.length() > RESOURCE_PATH.length()) { + if (strFilePathInZip.find(RESOURCE_PATH) != std::string::npos) { + std::string fileName = Utils::ReplaceAll(strFilePathInZip, RESOURCE_PATH, ""); + std::string fileContent; + if (!GetUnzipCurrentFileContent(unzipFile, fileContent)) { + LOGE("Get current file content failed! filename=%s", filePathInZip); + continue; + } + resourceMap.emplace(fileName, fileContent); + } + } + ret = unzGoToNextFile(unzipFile); + if (ret == UNZ_END_OF_LIST_OF_FILE) { + break; + } else if (ret != UNZ_OK) { + LOGE("Go to next file in zip failed!"); + break; + } + } + unzClose(unzipFile); + return true; +} +} // namespace AppPackingTool +} // namespace OHOS diff --git a/ohos_packing_tool/frameworks/src/zip_wrapper.cpp b/ohos_packing_tool/frameworks/src/zip_wrapper.cpp new file mode 100644 index 00000000..507d37ed --- /dev/null +++ b/ohos_packing_tool/frameworks/src/zip_wrapper.cpp @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "zip_wrapper.h" +#include "log.h" +#include "app_log_wrapper.h" + +namespace OHOS { +namespace AppPackingTool { +namespace {} + +ZipWrapper::ZipWrapper() : zipFile_(nullptr) +{} + +ZipWrapper::ZipWrapper(std::string zipPath) : zipFile_(nullptr), zipFilePath_(zipPath) +{} + +ZipWrapper::~ZipWrapper() +{ + Close(); +} + +int ZipWrapper::Open(std::string& zipPath, int append) +{ + zipFilePath_ = zipPath; + return Open(append); +} + +int ZipWrapper::Open(int append) +{ + if (zipFile_ != nullptr) { + LOGE("zip file handle has open"); + return ZIP_ERR_SUCCESS; + } + zipFile_ = zipOpen64(zipFilePath_.c_str(), append); + if (zipFile_ == nullptr) { + LOGE("zip file handle open failed"); + return ZIP_ERR_FAILURE; + } + return ZIP_ERR_SUCCESS; +} + +void ZipWrapper::Close() +{ + if (zipFile_ != nullptr) { + zipClose(zipFile_, nullptr); + zipFile_ = nullptr; + } +} + +int ZipWrapper::AddFileOrDirectoryToZip(const char *filePath, const char *zipPath) +{ + return AddFileOrDirectoryToZip(fs::path(filePath), fs::path(zipPath)); +} + +int ZipWrapper::AddFileOrDirectoryToZip(const std::string &filePath, const std::string &zipPath) +{ + return AddFileOrDirectoryToZip(fs::path(filePath), fs::path(zipPath)); +} + +int ZipWrapper::AddFileOrDirectoryToZip(const fs::path &fsFilePath, const fs::path &fsZipPath) +{ + APP_LOGD("Add [%{public}s] into zip[%{public}s]", fsFilePath.string().c_str(), fsZipPath.string().c_str()); + int ret = ZIP_ERR_SUCCESS; + if (fs::is_directory(fsFilePath)) { + for (const auto &entry : fs::directory_iterator(fsFilePath)) { + fs::path fsZipFullPath = fsZipPath / entry.path().filename(); + ret = AddFileOrDirectoryToZip(entry.path(), fsZipFullPath); + if (ret != ZIP_ERR_SUCCESS) { + return ret; + } + } + } else if (fs::is_regular_file(fsFilePath)) { + ret = AddFileToZip(fsFilePath, fsZipPath); + if (ret != ZIP_ERR_SUCCESS) { + return ret; + } + } + return ZIP_ERR_SUCCESS; +} + +int ZipWrapper::WriteStringToZip(const std::string &content, const std::string& zipPath) +{ + if (!IsOpen()) { + LOGE("zip file is not open"); + return ZIP_ERR_FAILURE; + } + int ret = zipOpenNewFileInZip64(zipFile_, zipPath.c_str(), &zipFileInfo_, nullptr, 0, + nullptr, 0, nullptr, 0, static_cast(zipLevel_), 1); + if (ret != ZIP_OK) { + LOGE("open file in zip failed![ret=%d][zipPath=%s]", ret, zipPath.c_str()); + return ZIP_ERR_FAILURE; + } + ret = zipWriteInFileInZip(zipFile_, content.data(), content.length()); + if (ret < 0) { + LOGE("write file in zip failed![errno=%d][ret=%d]", errno, ret); + ret = ZIP_ERR_FAILURE; + } + zipCloseFileInZip(zipFile_); + return ret; +} + +int ZipWrapper::AddFileToZip(const std::string &filePath, const std::string &zipPath) +{ + return AddFileToZip(fs::path(filePath), fs::path(zipPath)); +} + +int ZipWrapper::AddFileToZip(const fs::path &filePath, const fs::path &zipPath) +{ + if (!IsOpen()) { + LOGE("zip file is not open"); + return ZIP_ERR_FAILURE; + } + if (!fs::is_regular_file(filePath)) { + LOGE("filePath is not regular file![filePath=%s]", filePath.string().c_str()); + return ZIP_ERR_FAILURE; + } + std::ifstream file(filePath.string(), std::ios::binary); + if (!file.is_open()) { + LOGE("open file failed![filePath=%s]", filePath.string().c_str()); + return ZIP_ERR_FAILURE; + } + int ret = zipOpenNewFileInZip64(zipFile_, zipPath.string().c_str(), &zipFileInfo_, nullptr, 0, + nullptr, 0, nullptr, 0, static_cast(zipLevel_), 1); + if (ret != ZIP_OK) { + LOGE("open file in zip failed![ret=%d][zipPath=%s]", ret, zipPath.string().c_str()); + file.close(); + return ZIP_ERR_FAILURE; + } + ret = ZIP_ERR_SUCCESS; + char buffer[MAX_ZIP_BUFFER_SIZE]; + while (file.good()) { + file.read(buffer, sizeof(buffer)); + auto bytesRead = file.gcount(); + if (bytesRead <= 0) { + LOGE("read file bytes error![filePath=%s][bytesRead=%u]", filePath.c_str(), bytesRead); + ret = ZIP_ERR_FAILURE; + break; + } + if (zipWriteInFileInZip(zipFile_, buffer, bytesRead) < 0) { + LOGE("write file in zip failed!"); + ret = ZIP_ERR_FAILURE; + break; + } + } + zipCloseFileInZip(zipFile_); + file.close(); + return ret; +} + +} // namespace AppPackingTool +} // namespace OHOS diff --git a/ohos_packing_tool/frameworks/test/unittest/hap_packager_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/hap_packager_test/BUILD.gn new file mode 100644 index 00000000..ff0f1679 --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/hap_packager_test/BUILD.gn @@ -0,0 +1,39 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "developtools/packing_tool" + +ohos_unittest("hap_packager_test") { + module_out_path = module_output_path + include_dirs = [ + "../../../include", + ] + sources = [ + "hap_packager_test.cpp", + "../../../src/hap_packager.cpp", + "../../../src/packager.cpp", + "../../../src/zip_wrapper.cpp", + "../../../src/log.cpp", + ] + external_deps = [ + "json:nlohmann_json_static", + "cJSON:cjson", + "hilog:libhilog", + "zlib:libz", + "openssl:libssl_shared", + "openssl:libcrypto_shared", + ] +} \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_test.cpp b/ohos_packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_test.cpp new file mode 100644 index 00000000..4323a896 --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_test.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include "constants.h" +#define private public +#define protected public +#include "packager.h" +#include "hap_packager.h" +#include "zip_wrapper.h" +#include "log.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define OUT_PATH "/data/test_1.hqf" +#define FILE_PATH "/data/packager_test" +#define TEMP_PATH "/data/temp" +#define TEMP_PATH2 "/data" +#define LIBS_PATH "/data/temp/libs" +#define ETS_PATH "/data/temp/ets" +#define RESOURCES_PATH "/data/temp/resources" +#define JSON_PATH "/data/patch.json" + +class HapPackagerTest : public testing::Test { +public: + HapPackagerTest() {} + virtual ~HapPackagerTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void HapPackagerTest::SetUpTestCase() {} + +void HapPackagerTest::TearDownTestCase() {} + +void HapPackagerTest::SetUp() {} + +void HapPackagerTest::TearDown() {} + +/* + * @tc.name: InitAllowedParam_0100 + * @tc.desc: InitAllowedParam. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapPackagerTest, InitAllowedParam_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_JSON_PATH, JSON_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_LIB_PATH, FILE_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_ETS_PATH, FILE_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_RESOURCES_PATH, FILE_PATH}, + }; + + OHOS::AppPackingTool::HapPackager hapPackager(parameterMap, resultReceiver); + EXPECT_EQ(hapPackager.InitAllowedParam(), 0); + EXPECT_EQ(hapPackager.PreProcess(), 0); + EXPECT_EQ(hapPackager.PostProcess(), 0); +} + +/* + * @tc.name: Process_0200 + * @tc.desc: Process. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapPackagerTest, Process_0200, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_JSON_PATH, JSON_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_LIB_PATH, FILE_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_ETS_PATH, FILE_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_RESOURCES_PATH, FILE_PATH}, + }; + system("touch patch.json"); + + OHOS::AppPackingTool::HapPackager hapPackager(parameterMap, resultReceiver); + EXPECT_EQ(hapPackager.Process(), 0); + + system("rm -f patch.json"); + std::string cmd = {"rm -f "}; + cmd +=OUT_PATH; + system(cmd.c_str()); +} +} // namespace OHOS \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/hsp_packager_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/hsp_packager_test/BUILD.gn new file mode 100644 index 00000000..e3b3d727 --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/hsp_packager_test/BUILD.gn @@ -0,0 +1,39 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "developtools/packing_tool" + +ohos_unittest("hsp_packager_test") { + module_out_path = module_output_path + include_dirs = [ + "../../../include", + ] + sources = [ + "hsp_packager_test.cpp", + "../../../src/hsp_packager.cpp", + "../../../src/packager.cpp", + "../../../src/zip_wrapper.cpp", + "../../../src/log.cpp", + ] + external_deps = [ + "json:nlohmann_json_static", + "cJSON:cjson", + "hilog:libhilog", + "zlib:libz", + "openssl:libssl_shared", + "openssl:libcrypto_shared", + ] +} \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/hsp_packager_test/hsp_packager_test.cpp b/ohos_packing_tool/frameworks/test/unittest/hsp_packager_test/hsp_packager_test.cpp new file mode 100644 index 00000000..eecf44f9 --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/hsp_packager_test/hsp_packager_test.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include "constants.h" +#define private public +#define protected public +#include "packager.h" +#include "hsp_packager.h" +#include "zip_wrapper.h" +#include "log.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define OUT_PATH "/data/test_1.hqf" +#define FILE_PATH "/data/packager_test" +#define TEMP_PATH "/data/temp" +#define TEMP_PATH2 "/data" +#define LIBS_PATH "/data/temp/libs" +#define ETS_PATH "/data/temp/ets" +#define RESOURCES_PATH "/data/temp/resources" +#define JSON_PATH "/data/patch.json" + +class HspPackagerTest : public testing::Test { +public: + HspPackagerTest() {} + virtual ~HspPackagerTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void HspPackagerTest::SetUpTestCase() {} + +void HspPackagerTest::TearDownTestCase() {} + +void HspPackagerTest::SetUp() {} + +void HspPackagerTest::TearDown() {} + +/* + * @tc.name: InitAllowedParam_0100 + * @tc.desc: InitAllowedParam. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HspPackagerTest, InitAllowedParam_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_JSON_PATH, JSON_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_LIB_PATH, FILE_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_ETS_PATH, FILE_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_RESOURCES_PATH, FILE_PATH}, + }; + + OHOS::AppPackingTool::HspPackager hspPackager(parameterMap, resultReceiver); + EXPECT_EQ(hspPackager.InitAllowedParam(), 0); + EXPECT_EQ(hspPackager.PreProcess(), 0); + EXPECT_EQ(hspPackager.PostProcess(), 0); +} + +/* + * @tc.name: Process_0200 + * @tc.desc: Process. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HspPackagerTest, Process_0200, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_JSON_PATH, JSON_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_LIB_PATH, FILE_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_ETS_PATH, FILE_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_RESOURCES_PATH, FILE_PATH}, + }; + system("touch patch.json"); + + OHOS::AppPackingTool::HspPackager hspPackager(parameterMap, resultReceiver); + EXPECT_EQ(hspPackager.Process(), 0); + + system("rm -f patch.json"); + std::string cmd = {"rm -f "}; + cmd +=OUT_PATH; + system(cmd.c_str()); +} +} // namespace OHOS \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/json/distro_filter_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/json/distro_filter_test/BUILD.gn new file mode 100644 index 00000000..84376f6e --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/json/distro_filter_test/BUILD.gn @@ -0,0 +1,38 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "developtools/packing_tool" + +ohos_unittest("distro_filter_test") { + module_out_path = module_output_path + include_dirs = [ + "../../../../include", + "../../../../include/json" + ] + sources = [ + "distro_filter_test.cpp", + "../../../../src/json/distro_filter.cpp", + "../../../../src/json/pt_json.cpp", + "../../../../src/log.cpp", + ] + external_deps = [ + "json:nlohmann_json_static", + "cJSON:cjson", + "hilog:libhilog", + "zlib:libz", + "openssl:libcrypto_shared", + ] +} \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/json/distro_filter_test/distro_filter_test.cpp b/ohos_packing_tool/frameworks/test/unittest/json/distro_filter_test/distro_filter_test.cpp new file mode 100644 index 00000000..614524b5 --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/json/distro_filter_test/distro_filter_test.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#define private public +#define protected public +#include "distro_filter.h" +#include "pt_json.h" +#include "log.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +std::string content = "{" + "\"name\": \"Json.CN\"," + "\"app\": \"apptest\"," + "\"module\": {" + "\"name\": \"nametest\"," + "\"type\": \"typetest\"," + "\"deviceTypes\": [" + "\"aaaaaaaaaaa\"," + "\"bbbbbbbbbbb\"," + "\"ccccccccccc\"" + "]" + "}" + "\"bundleName\": \"bundleNametest\"," + "\"versionCode\": 100," + "\"versionName\": \"versionNametest\"," + "\"patchVersionCode\": 200," + "\"patchVersionName\": \"patchVersionNametest\"," + "\"originalModuleHash\": \"originalModuleHashtest\"," + "\"url\": \"http://www.json.cn\"," + "\"page\": 88," + "\"isNonProfit\": true" +"}"; + +class distroFilterTest : public testing::Test { +public: + distroFilterTest() {} + virtual ~distroFilterTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void distroFilterTest::SetUpTestCase() {} + +void distroFilterTest::TearDownTestCase() {} + +void distroFilterTest::SetUp() {} + +void distroFilterTest::TearDown() {} + +/* + * @tc.name: ParseFromString_0100 + * @tc.desc: ParseFromString. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(distroFilterTest, ParseFromString_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PolicyValue policyValue; + EXPECT_TRUE(policyValue.ParseFromString(content)); +} +} \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/json/patch_json_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/json/patch_json_test/BUILD.gn new file mode 100644 index 00000000..26c446cf --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/json/patch_json_test/BUILD.gn @@ -0,0 +1,38 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "developtools/packing_tool" + +ohos_unittest("patch_json_test") { + module_out_path = module_output_path + include_dirs = [ + "../../../../include", + "../../../../include/json" + ] + sources = [ + "patch_json_test.cpp", + "../../../../src/json/patch_json.cpp", + "../../../../src/json/pt_json.cpp", + "../../../../src/log.cpp", + ] + external_deps = [ + "json:nlohmann_json_static", + "cJSON:cjson", + "hilog:libhilog", + "zlib:libz", + "openssl:libcrypto_shared", + ] +} \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/json/patch_json_test/patch_json_test.cpp b/ohos_packing_tool/frameworks/test/unittest/json/patch_json_test/patch_json_test.cpp new file mode 100644 index 00000000..b5f7e6bf --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/json/patch_json_test/patch_json_test.cpp @@ -0,0 +1,345 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#define private public +#define protected public +#include "patch_json.h" +#include "pt_json.h" +#include "log.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +std::string content = "{" + "\"name\": \"Json.CN\"," + "\"app\": {" + "\"bundleName\": \"bundleNametest\"," + "\"versionCode\": 100," + "\"versionName\": \"versionNametest\"," + "\"patchVersionCode\": 200," + "\"patchVersionName\": \"patchVersionNametest\"" + "}," + "\"module\": {" + "\"name\": \"nametest\"," + "\"type\": \"typetest\"," + "\"originalModuleHash\": \"originalModuleHashtest\"," + "\"deviceTypes\": [" + "\"aaaaaaaaaaa\"," + "\"bbbbbbbbbbb\"," + "\"ccccccccccc\"" + "]" + "}" +"}"; + + +class PatchJsonTest : public testing::Test { +public: + PatchJsonTest() {} + virtual ~PatchJsonTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void PatchJsonTest::SetUpTestCase() {} + +void PatchJsonTest::TearDownTestCase() {} + +void PatchJsonTest::SetUp() {} + +void PatchJsonTest::TearDown() {} + +/* + * @tc.name: ParseFromString_0100 + * @tc.desc: ParseFromString. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, ParseFromString_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); +} + +/* + * @tc.name: ParseFromFile_0100 + * @tc.desc: ParseFromFile. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, ParseFromFile_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::string test("test.json"); + FILE *fp = fopen(test.c_str(), "w"); + EXPECT_TRUE(fp != nullptr); + if (fp != nullptr) + { + fwrite(content.c_str(), content.size(), 1, fp); + fclose(fp); + EXPECT_TRUE(patchJson.ParseFromFile(test)); + system("rm -f test.json"); + } +} + +/* + * @tc.name: Release_0100 + * @tc.desc: Release. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, Release_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + patchJson.Release(); + EXPECT_TRUE(patchJson.root_ == nullptr); +} + +/* + * @tc.name: IsValid_0100 + * @tc.desc: IsValid. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, IsValid_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + EXPECT_TRUE(patchJson.IsValid()); +} + +/* + * @tc.name: ToString_0100 + * @tc.desc: ToString. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, ToString_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::string contents = patchJson.ToString(); + EXPECT_TRUE(!contents.empty()); + EXPECT_TRUE(patchJson.IsValid()); +} + +/* + * @tc.name: GetAppObject_0100 + * @tc.desc: GetAppObject. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetAppObject_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::unique_ptr appObj; + EXPECT_TRUE(patchJson.GetAppObject(appObj)); +} + +/* + * @tc.name: GetModuleObject_0100 + * @tc.desc: GetModuleObject. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetModuleObject_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::unique_ptr appObj; + EXPECT_TRUE(patchJson.GetModuleObject(appObj)); +} + +/* + * @tc.name: GetBundleName_0100 + * @tc.desc: GetBundleName. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetBundleName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::string bundleName; + EXPECT_TRUE(patchJson.GetBundleName(bundleName)); + EXPECT_STREQ(bundleName.c_str(), "bundleNametest"); +} + +/* + * @tc.name: GetVersionCode_0100 + * @tc.desc: GetVersionCode. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetVersionCode_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + int32_t versionCode; + EXPECT_TRUE(patchJson.GetVersionCode(versionCode)); + EXPECT_EQ(versionCode, 100); +} + +/* + * @tc.name: GetVersionName_0100 + * @tc.desc: GetVersionName. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetVersionName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::string versionName; + EXPECT_TRUE(patchJson.GetVersionName(versionName)); + EXPECT_STREQ(versionName.c_str(), "versionNametest");; +} + +/* + * @tc.name: GetPatchVersionCode_0100 + * @tc.desc: GetPatchVersionCode. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetPatchVersionCode_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + int32_t patchVersionCode; + EXPECT_TRUE(patchJson.GetPatchVersionCode(patchVersionCode)); + EXPECT_EQ(patchVersionCode, 200); +} + +/* + * @tc.name: GetPatchVersionName_0100 + * @tc.desc: GetPatchVersionName. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetPatchVersionName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::string patchVersionName; + EXPECT_TRUE(patchJson.GetPatchVersionName(patchVersionName)); + EXPECT_STREQ(patchVersionName.c_str(), "patchVersionNametest"); +} + +/* + * @tc.name: GetName_0100 + * @tc.desc: GetName. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::string name; + EXPECT_TRUE(patchJson.GetName(name)); + EXPECT_STREQ(name.c_str(), "nametest"); +} + +/* + * @tc.name: GetType_0100 + * @tc.desc: GetType. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetType_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::string type; + EXPECT_TRUE(patchJson.GetType(type)); + EXPECT_STREQ(type.c_str(), "typetest"); +} + +/* + * @tc.name: GetDeviceTypes_0100 + * @tc.desc: GetDeviceTypes. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetDeviceTypes_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::list deviceTypes; + EXPECT_TRUE(patchJson.GetDeviceTypes(deviceTypes)); + EXPECT_STREQ(deviceTypes.front().c_str(), "aaaaaaaaaaa"); +} + +/* + * @tc.name: GetOriginalModuleHash_0100 + * @tc.desc: GetOriginalModuleHash. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetOriginalModuleHash_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::string originalModuleHash; + EXPECT_TRUE(patchJson.GetOriginalModuleHash(originalModuleHash)); + EXPECT_STREQ(originalModuleHash.c_str(), "originalModuleHashtest"); +} + +/* + * @tc.name: GetHqfInfo_0100 + * @tc.desc: GetHqfInfo. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetHqfInfo_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + OHOS::AppPackingTool::HqfInfo hqfInfo; + EXPECT_TRUE(patchJson.GetHqfInfo(hqfInfo)); + EXPECT_STREQ(hqfInfo.GetBundleName().c_str(), "bundleNametest"); +} +} // namespace OHOS \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/BUILD.gn new file mode 100644 index 00000000..3c2f26ee --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "developtools/packing_tool" + +ohos_unittest("pt_json_test") { + module_out_path = module_output_path + include_dirs = [ + "../../../../include", + "../../../../include/json" + ] + sources = [ + "pt_json_test.cpp", + "../../../../src/json/pt_json.cpp", + "../../../../src/log.cpp", + ] + external_deps = [ + "json:nlohmann_json_static", + "cJSON:cjson", + "hilog:libhilog", + "zlib:libz", + "openssl:libcrypto_shared", + ] +} \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp b/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp new file mode 100644 index 00000000..76f649de --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp @@ -0,0 +1,502 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#define private public +#define protected public +#include "pt_json.h" +#include "log.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +std::string content = "{" + "\"name\": \"Json.CN\"," + "\"app\": \"apptest\"," + "\"module\": {" + "\"name\": \"nametest\"," + "\"type\": \"typetest\"," + "\"deviceTypes\": [" + "\"aaaaaaaaaaa\"," + "\"bbbbbbbbbbb\"," + "\"ccccccccccc\"" + "]" + "}," + "\"bundleName\": \"bundleNametest\"," + "\"versionCode\": 100," + "\"versionName\": \"versionNametest\"," + "\"patchVersionCode\": 200," + "\"patchVersionName\": \"patchVersionNametest\"," + "\"originalModuleHash\": \"originalModuleHashtest\"" +"}"; + +class PtJsonTest : public testing::Test { +public: + PtJsonTest() {} + virtual ~PtJsonTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void PtJsonTest::SetUpTestCase() {} + +void PtJsonTest::TearDownTestCase() {} + +void PtJsonTest::SetUp() {} + +void PtJsonTest::TearDown() {} + +/* + * @tc.name: CreateObject_0100 + * @tc.desc: CreateObject. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, CreateObject_0100, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + std::unique_ptr ptjsonObject = ptJson.CreateObject(); + EXPECT_TRUE(ptjsonObject != NULL); +} + +/* + * @tc.name: CreateArray_0200 + * @tc.desc: CreateArray. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, CreateArray_0200, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + std::unique_ptr ptjsonArray = ptJson.CreateArray(); + EXPECT_TRUE(ptjsonArray != NULL); +} + +/* + * @tc.name: ReleaseRoot_0300 + * @tc.desc: ReleaseRoot. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, ReleaseRoot_0300, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + ptJson.ReleaseRoot(); + EXPECT_TRUE(ptJson.object_ == NULL); +} + +/* + * @tc.name: Parse_0400 + * @tc.desc: Parse. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, Parse_0400, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + std::unique_ptr ptjson = ptJson.Parse(content); + EXPECT_TRUE(ptjson != NULL); +} + +/* + * @tc.name: Stringify_0500 + * @tc.desc: Stringify. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, Stringify_0500, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + std::unique_ptr ptjson = ptJson.Parse(content); + EXPECT_TRUE(ptjson != NULL); + + EXPECT_TRUE(!ptjson->Stringify().empty()); +} + +/* + * @tc.name: Add_0600 + * @tc.desc: Add. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, Add_0600, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + std::unique_ptr ptjsonObject = ptJson.CreateObject(); + EXPECT_TRUE(ptjsonObject != NULL); + + EXPECT_TRUE(ptJson.Add("AAA", true)); + EXPECT_TRUE(ptJson.Add("BBB", 123)); + EXPECT_TRUE(ptJson.Add("CCC", 123.5)); + EXPECT_TRUE(ptJson.Add("DDD", "ABC")); + EXPECT_TRUE(ptJson.Add("EEE", ptjsonObject)); +} + +/* + * @tc.name: Push_0700 + * @tc.desc: Push. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, Push_0700, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + std::unique_ptr ptjsonObject = ptJson.CreateObject(); + EXPECT_TRUE(ptjsonObject != NULL); + + std::unique_ptr ptjsonArray = ptJson.CreateArray(); + EXPECT_TRUE(ptjsonArray != NULL); + + EXPECT_TRUE(ptJson.Add("AAA", true)); + EXPECT_TRUE(ptJson.Add("BBB", 123)); + EXPECT_TRUE(ptJson.Add("CCC", 123.5)); + EXPECT_TRUE(ptJson.Add("DDD", "ABC")); + EXPECT_TRUE(ptJson.Add("EEE", ptjsonObject)); + + EXPECT_TRUE(ptJson.Push(true)); + EXPECT_TRUE(ptJson.Push(123)); + EXPECT_TRUE(ptJson.Push(123.5)); + EXPECT_TRUE(ptJson.Push("ABC")); + EXPECT_TRUE(ptJson.Push(ptjsonArray)); +} + +/* + * @tc.name: Contains_0800 + * @tc.desc: Contains. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, Contains_0800, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + EXPECT_TRUE(ptJson.Add("AAA", true)); + + EXPECT_TRUE(ptJson.Remove("AAA")); +} + +/* + * @tc.name: Contains_0900 + * @tc.desc: Contains. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, Contains_0900, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + EXPECT_TRUE(ptJson.Add("AAA", true)); + + EXPECT_TRUE(ptJson.Contains("AAA")); +} + +/* + * @tc.name: GetKey_1000 + * @tc.desc: GetKey. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, GetKey_1000, Function | MediumTest | Level1) +{ + char a[]="{\"firstName\":\"Brett\"}"; + cJSON*root=cJSON_Parse(a); + cJSON*item=cJSON_GetObjectItem(root,"firstName"); + OHOS::AppPackingTool::PtJson ptJson(item); + EXPECT_TRUE(!ptJson.GetKey().empty()); + EXPECT_TRUE(!ptJson.Stringify().empty()); +} + +/* + * @tc.name: GetJson_1100 + * @tc.desc: GetJson. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, GetJson_1100, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + EXPECT_TRUE(ptJson.GetJson() != nullptr); +} + +/* + * @tc.name: IsBool_1200 + * @tc.desc: IsBool. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, IsBool_1200, Function | MediumTest | Level1) +{ + cJSON *node = cJSON_CreateBool(true); + OHOS::AppPackingTool::PtJson ptJsonBool(node); + + EXPECT_TRUE(ptJsonBool.IsBool()); + EXPECT_TRUE(ptJsonBool.GetBool(true)); +} + +/* + * @tc.name: IsNumber_1300 + * @tc.desc: IsNumber. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, IsNumber_1300, Function | MediumTest | Level1) +{ + cJSON *node = cJSON_CreateNumber(12345); + OHOS::AppPackingTool::PtJson ptJsonNumber(node); + + EXPECT_TRUE(ptJsonNumber.IsNumber()); + EXPECT_EQ(ptJsonNumber.GetInt(12345), 12345); + EXPECT_EQ(ptJsonNumber.GetInt64(12345), 12345); + EXPECT_EQ(ptJsonNumber.GetUInt(12345), 12345); + EXPECT_EQ(ptJsonNumber.GetUInt64(12345), 12345); + EXPECT_EQ(ptJsonNumber.GetDouble(12345.5), 12345); +} + +/* + * @tc.name: IsString_1400 + * @tc.desc: IsString. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, IsString_1400, Function | MediumTest | Level1) +{ + cJSON *node = cJSON_CreateString("abcd"); + OHOS::AppPackingTool::PtJson ptJsonString(node); + + EXPECT_TRUE(ptJsonString.IsString()); + EXPECT_STREQ(ptJsonString.GetString().c_str(), "abcd"); +} + +/* + * @tc.name: IsObject_1500 + * @tc.desc: IsObject. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, IsObject_1500, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + std::unique_ptr ptjsonObject = ptJson.CreateObject(); + EXPECT_TRUE(ptjsonObject != NULL); + EXPECT_TRUE(ptjsonObject->IsObject()); +} + +/* + * @tc.name: IsArray_1600 + * @tc.desc: IsArray. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, IsArray_1600, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + std::unique_ptr ptjsonArray = ptJson.CreateArray(); + EXPECT_TRUE(ptjsonArray != NULL); + EXPECT_TRUE(ptjsonArray->IsArray()); + ptjsonArray->Push("11111"); + ptjsonArray->Push("22222"); + EXPECT_STREQ(ptjsonArray->Get(1)->GetString().c_str(), "22222"); + EXPECT_TRUE(ptjsonArray->GetSize() > 0); +} + +/* + * @tc.name: IsNull_1700 + * @tc.desc: IsNull. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, IsNull_1700, Function | MediumTest | Level1) +{ + cJSON *cjson = cJSON_CreateNull(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + EXPECT_TRUE(ptJson.IsNull()); +} + +/* + * @tc.name: SetBool_1800 + * @tc.desc: SetBool. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, SetBool_1800, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + bool flag = false; + ptJson.Add("AAA", true); + EXPECT_EQ(ptJson.SetBool("AAA",flag), OHOS::AppPackingTool::Result::SUCCESS); + ptJson.GetBool("AAA",&flag); + EXPECT_FALSE(flag); +} + +/* + * @tc.name: SetInt_1900 + * @tc.desc: SetInt. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, SetInt_1900, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + EXPECT_TRUE(ptJson.Add("BBB", 123)); + int number = 0; + EXPECT_EQ(ptJson.SetInt("BBB",321), OHOS::AppPackingTool::Result::SUCCESS); + ptJson.GetInt("BBB", &number); + EXPECT_EQ(number, 321); +} + +/* + * @tc.name: SetInt64_2000 + * @tc.desc: SetInt64. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, SetInt64_2000, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + EXPECT_TRUE(ptJson.Add("BBB", 123)); + EXPECT_TRUE(ptJson.Add("CCC", 123.5)); + + int64_t value64 = 11111; + EXPECT_EQ(ptJson.SetInt64("BBB",value64), OHOS::AppPackingTool::Result::SUCCESS); + int64_t value642; + EXPECT_EQ(ptJson.GetInt64("BBB",&value642), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(value642, 11111); + + uint32_t value32 = 2222; + EXPECT_EQ(ptJson.SetUInt("BBB",value32), OHOS::AppPackingTool::Result::SUCCESS); + uint32_t value322; + EXPECT_EQ(ptJson.GetUInt("BBB",&value322), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(value322, 2222); + + uint64_t valueInt64 = 3333; + EXPECT_EQ(ptJson.SetUInt64("BBB",valueInt64), OHOS::AppPackingTool::Result::SUCCESS); + uint64_t valueInt642; + EXPECT_EQ(ptJson.GetUInt64("BBB",&valueInt642), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(valueInt642, 3333); + + double valueDouble = 4444; + EXPECT_EQ(ptJson.SetDouble("CCC",valueDouble), OHOS::AppPackingTool::Result::SUCCESS); + double valueDouble2; + EXPECT_EQ(ptJson.GetDouble("CCC",&valueDouble2), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(valueDouble2, 4444); +} + +/* + * @tc.name: SetString_2100 + * @tc.desc: SetString. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, SetString_2100, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + EXPECT_TRUE(ptJson.Add("DDD", "ABC")); + std::string str("1234567890"); + EXPECT_EQ(ptJson.SetString("DDD",str), OHOS::AppPackingTool::Result::SUCCESS); + std::string str2; + EXPECT_EQ(ptJson.GetString("DDD",&str2), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_STREQ(str2.c_str(), str.c_str()); +} + +/* + * @tc.name: GetObject_2200 + * @tc.desc: GetObject. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, GetObject_2200, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + std::unique_ptr ptjsonObject = ptJson.CreateObject(); + EXPECT_TRUE(ptjsonObject != NULL); + EXPECT_TRUE(ptJson.Add("EEE", ptjsonObject)); + std::unique_ptr Object; + EXPECT_EQ(ptJson.GetObject("EEE",&Object), OHOS::AppPackingTool::Result::SUCCESS); +} + +/* + * @tc.name: GetArray_2300 + * @tc.desc: GetArray. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, GetArray_2300, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + ptJson.Add("FFF", ptJson.CreateArray()); + std::unique_ptr Array; + EXPECT_EQ(ptJson.GetArray("FFF",&Array), OHOS::AppPackingTool::Result::SUCCESS); +} + +/* + * @tc.name: GetAny_2400 + * @tc.desc: GetAny. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, GetAny_2400, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + ptJson.Add("FFF", ptJson.CreateArray()); + std::unique_ptr Object; + EXPECT_EQ(ptJson.GetAny("FFF",&Object), OHOS::AppPackingTool::Result::SUCCESS); +} +} // namespace OHOS \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/shell_command_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/shell_command_test/BUILD.gn new file mode 100644 index 00000000..88584843 --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/shell_command_test/BUILD.gn @@ -0,0 +1,41 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "developtools/packing_tool" + +ohos_unittest("shell_command_test") { + module_out_path = module_output_path + include_dirs = [ + "../../../include", + ] + sources = [ + "shell_command_test.cpp", + "../../../src/shell_command.cpp", + "../../../src/hap_packager.cpp", + "../../../src/hsp_packager.cpp", + "../../../src/packager.cpp", + "../../../src/zip_wrapper.cpp", + "../../../src/log.cpp", + ] + external_deps = [ + "json:nlohmann_json_static", + "cJSON:cjson", + "hilog:libhilog", + "zlib:libz", + "openssl:libssl_shared", + "openssl:libcrypto_shared", + ] +} \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/shell_command_test/shell_command_test.cpp b/ohos_packing_tool/frameworks/test/unittest/shell_command_test/shell_command_test.cpp new file mode 100644 index 00000000..dd0da6a1 --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/shell_command_test/shell_command_test.cpp @@ -0,0 +1,234 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include "constants.h" +#include "zip_constants.h" +#define private public +#define protected public +#include "packager.h" +#include "hap_packager.h" +#include "hsp_packager.h" +#include "shell_command.h" +#include "zip_wrapper.h" +#include "zip_utils.h" +#include "unzip_wrapper.h" +#include "utils.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +class ShellCommandTest : public testing::Test { +public: + ShellCommandTest() {} + virtual ~ShellCommandTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void ShellCommandTest::SetUpTestCase() {} + +void ShellCommandTest::TearDownTestCase() {} + +void ShellCommandTest::SetUp() {} + +void ShellCommandTest::TearDown() {} + +/* + * @tc.name: CreateCommandMap_0100 + * @tc.desc: CreateCommandMap. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ShellCommandTest, CreateCommandMap_0100, Function | MediumTest | Level1) +{ + int argc = 2; + const char *argv[] = { + "ohos_packing_tool", + "pack", + }; + + OHOS::AppPackingTool::ShellCommand shellcmd(argc, const_cast(argv), OHOS::AppPackingTool::TOOL_NAME); + int ret = shellcmd.CreateCommandMap(); + EXPECT_EQ(ret, 0); +} + +/* + * @tc.name: getPackager_0200 + * @tc.desc: getPackager. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ShellCommandTest, getPackager_0200, Function | MediumTest | Level1) +{ + int argc = 16; + const char *argv[] = { + "ohos_packing_tool", + "pack", + "--mode", + "hap", + "--json-path", + "/data/testunpack/test_hqf_unpacking/patch.json", + "--lib-path", + "/data/testunpack/test_hqf_unpacking/libs", + "--resources-path", + "/data/testunpack/test_hqf_unpacking/resources", + "--ets-pat", + "/data/testunpack/test_hqf_unpacking/ets", + "--out-path", + "/data/hqfpacking/test_1.hqf", + "--force", + "true", + }; + + OHOS::AppPackingTool::ShellCommand shellcmd(argc, const_cast(argv), OHOS::AppPackingTool::TOOL_NAME); + int ret = shellcmd.ParseParam(); + EXPECT_EQ(ret, 0); + std::unique_ptr packager = shellcmd.getPackager(); + EXPECT_TRUE(packager != nullptr); + shellcmd.parameterMap_[OHOS::AppPackingTool::Constants::PARAM_MODE] = "hsp"; + std::unique_ptr packager2 = shellcmd.getPackager(); + EXPECT_TRUE(packager2 != nullptr); + shellcmd.parameterMap_[OHOS::AppPackingTool::Constants::PARAM_MODE] = ""; + std::unique_ptr packager3 = shellcmd.getPackager(); + EXPECT_TRUE(packager3 == nullptr); +} + +/* + * @tc.name: OnCommand_0300 + * @tc.desc: OnCommand. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ShellCommandTest, OnCommand_0300, Function | MediumTest | Level1) +{ + int argc = 2; + const char *argv[] = { + "ohos_packing_tool", + "help", + }; + + OHOS::AppPackingTool::ShellCommand shellcmd(argc, const_cast(argv), OHOS::AppPackingTool::TOOL_NAME); + int ret = shellcmd.CreateCommandMap(); + EXPECT_EQ(ret, 0); + ret = shellcmd.OnCommand(); + EXPECT_EQ(ret, 0); +} + +/* + * @tc.name: ExecCommand_0400 + * @tc.desc: ExecCommand. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ShellCommandTest, ExecCommand_0400, Function | MediumTest | Level1) +{ + int argc = 16; + const char *argv[] = { + "ohos_packing_tool", + "pack", + "--mode", + "hqf", + "--json-path", + "/data/testunpack/test_hqf_unpacking/patch.json", + "--lib-path", + "/data/testunpack/test_hqf_unpacking/libs", + "--resources-path", + "/data/testunpack/test_hqf_unpacking/resources", + "--ets-pat", + "/data/testunpack/test_hqf_unpacking/ets", + "--out-path", + "/data/hqfpacking/test_1.hqf", + "--force", + "true", + }; + + OHOS::AppPackingTool::ShellCommand shellcmd(argc, const_cast(argv), OHOS::AppPackingTool::TOOL_NAME); + std::string resultReceiver = shellcmd.ExecCommand(); + EXPECT_FALSE(resultReceiver.empty()); +} + +/* + * @tc.name: RunAsHelpCommand_0500 + * @tc.desc: RunAsHelpCommand. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ShellCommandTest, RunAsHelpCommand_0500, Function | MediumTest | Level1) +{ + int argc = 4; + const char *argv[] = { + "ohos_packing_tool", + "pack", + "--mode", + "hqf", + }; + + OHOS::AppPackingTool::ShellCommand shellcmd(argc, const_cast(argv), OHOS::AppPackingTool::TOOL_NAME); + EXPECT_EQ(shellcmd.RunAsHelpCommand(), 0); +} + +/* + * @tc.name: RunAsPackCommand_0600 + * @tc.desc: RunAsPackCommand. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ShellCommandTest, RunAsPackCommand_0600, Function | MediumTest | Level1) +{ + int argc = 4; + const char *argv[] = { + "ohos_packing_tool", + "pack", + "--mode", + "hqf", + }; + + OHOS::AppPackingTool::ShellCommand shellcmd(argc, const_cast(argv), OHOS::AppPackingTool::TOOL_NAME); + EXPECT_EQ(shellcmd.RunAsPackCommand(), 0); +} + +/* + * @tc.name: RunAsUnpackCommand_0700 + * @tc.desc: RunAsUnpackCommand. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ShellCommandTest, RunAsUnpackCommand_0700, Function | MediumTest | Level1) +{ + int argc = 4; + const char *argv[] = { + "ohos_packing_tool", + "pack", + "--mode", + "hqf", + }; + + OHOS::AppPackingTool::ShellCommand shellcmd(argc, const_cast(argv), OHOS::AppPackingTool::TOOL_NAME); + EXPECT_EQ(shellcmd.RunAsUnpackCommand(), 0); +} +} // namespace OHOS \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/unzip_wrapper_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/unzip_wrapper_test/BUILD.gn new file mode 100644 index 00000000..fc020703 --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/unzip_wrapper_test/BUILD.gn @@ -0,0 +1,39 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "developtools/packing_tool" + +ohos_unittest("unzip_wrapper_test") { + module_out_path = module_output_path + include_dirs = [ + "../../../include", + ] + sources = [ + "unzip_wrapper_test.cpp", + "../../../src/unzip_wrapper.cpp", + "../../../src/zip_wrapper.cpp", + "../../../src/packager.cpp", + "../../../src/log.cpp", + ] + external_deps = [ + "json:nlohmann_json_static", + "cJSON:cjson", + "hilog:libhilog", + "zlib:libz", + "openssl:libssl_shared", + "openssl:libcrypto_shared", + ] +} \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/unzip_wrapper_test/unzip_wrapper_test.cpp b/ohos_packing_tool/frameworks/test/unittest/unzip_wrapper_test/unzip_wrapper_test.cpp new file mode 100644 index 00000000..d2a8ad5d --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/unzip_wrapper_test/unzip_wrapper_test.cpp @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include "constants.h" +#define private public +#define protected public +#include "packager.h" +#include "zip_wrapper.h" +#include "unzip_wrapper.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define OUT_PATH "/data/test_1.hqf" +#define FILE_PATH "/data/unzip_wrapper_test" +#define TEMP_PATH "/data/temp" + +class UnzipWrapperTest : public testing::Test { +public: + UnzipWrapperTest() {} + virtual ~UnzipWrapperTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void UnzipWrapperTest::SetUpTestCase() {} + +void UnzipWrapperTest::TearDownTestCase() {} + +void UnzipWrapperTest::SetUp() {} + +void UnzipWrapperTest::TearDown() {} + +/* + * @tc.name: Open_0100 + * @tc.desc: Open. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UnzipWrapperTest, Open_0100, Function | MediumTest | Level1) +{ + std::string path(OUT_PATH); + std::string filepath(FILE_PATH); + OHOS::AppPackingTool::ZipWrapper zipWrapper(path); + + zipWrapper.Open(APPEND_STATUS_CREATE); + int ret = zipWrapper.AddFileOrDirectoryToZip(filepath, OHOS::AppPackingTool::Constants::PARAM_ETS_PATH); + EXPECT_EQ(ret, 0); + zipWrapper.Close(); + + OHOS::AppPackingTool::UnzipWrapper unzipWrapper; + unzipWrapper.Open(path); + EXPECT_TRUE(unzipWrapper.IsOpen()); + + unzipWrapper.Close(); +} + +/* + * @tc.name: Open_0200 + * @tc.desc: Open. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UnzipWrapperTest, Open_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::UnzipWrapper unzipWrapper(OUT_PATH); + unzipWrapper.Open(); + EXPECT_TRUE(unzipWrapper.IsOpen()); + + unzipWrapper.Close(); +} + +/* + * @tc.name: UnzipFile_0300 + * @tc.desc: UnzipFile. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UnzipWrapperTest, UnzipFile_0300, Function | MediumTest | Level1) +{ + std::string filepath(TEMP_PATH); + OHOS::AppPackingTool::UnzipWrapper unzipWrapper(OUT_PATH); + unzipWrapper.Open(); + int ret = unzipWrapper.UnzipFile(TEMP_PATH); + EXPECT_EQ(ret, 0); + + unzipWrapper.Close(); + + std::string cmd("rm -rf "); + cmd += TEMP_PATH; + system(cmd.c_str()); + std::string cmd2("rm -rf "); + cmd2 += OUT_PATH; + system(cmd2.c_str()); +} +} // namespace OHOS \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/utils_Test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/utils_Test/BUILD.gn new file mode 100644 index 00000000..ebedb778 --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/utils_Test/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "developtools/packing_tool" + +ohos_unittest("utils_Test") { + module_out_path = module_output_path + include_dirs = [ + "../../../include", + ] + sources = [ + "utils_test.cpp", + "../../../src/utils.cpp", + "../../../src/log.cpp", + ] + external_deps = [ + "json:nlohmann_json_static", + "cJSON:cjson", + "hilog:libhilog", + "zlib:libz", + "openssl:libssl_shared", + "openssl:libcrypto_shared", + ] +} \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/utils_Test/utils_test.cpp b/ohos_packing_tool/frameworks/test/unittest/utils_Test/utils_test.cpp new file mode 100644 index 00000000..440dfef3 --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/utils_Test/utils_test.cpp @@ -0,0 +1,257 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include "constants.h" +#define private public +#define protected public +#include "utils.h" +#include "log.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define FILE_PATH "/data/utils_Test" +#define TEMP_PATH "/data" + +class UtilsTest : public testing::Test { +public: + UtilsTest() {} + virtual ~UtilsTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void UtilsTest::SetUpTestCase() {} + +void UtilsTest::TearDownTestCase() {} + +void UtilsTest::SetUp() {} + +void UtilsTest::TearDown() {} + +/* + * @tc.name: GetFileContent_0100 + * @tc.desc: GetFileContent. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, GetFileContent_0100, Function | MediumTest | Level1) +{ + std::string content = OHOS::AppPackingTool::Utils::GetFileContent(FILE_PATH); + EXPECT_TRUE(!content.empty()); +} + +/* + * @tc.name: ReplaceAll_0200 + * @tc.desc: ReplaceAll. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, ReplaceAll_0200, Function | MediumTest | Level1) +{ + std::string str = {"1234567890"}; + std::string from = {"456"}; + std::string to = {"AAA"}; + str = OHOS::AppPackingTool::Utils::ReplaceAll(str, from, to); + EXPECT_NE(str.find(to), 0); +} + +/* + * @tc.name: GetFileLength_0300 + * @tc.desc: GetFileLength. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, GetFileLength_0300, Function | MediumTest | Level1) +{ + int64_t len = OHOS::AppPackingTool::Utils::GetFileLength(FILE_PATH); + EXPECT_NE(len, 0); +} + +/* + * @tc.name: GetFileLength_0400 + * @tc.desc: GetFileLength. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, GetFileLength_0400, Function | MediumTest | Level1) +{ + std::string str = {"test.txt"}; + std::string suffix = {".txt"}; + EXPECT_TRUE(OHOS::AppPackingTool::Utils::EndsWith(str, suffix)); +} + +/* + * @tc.name: CheckDisjoint_0500 + * @tc.desc: CheckDisjoint. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, CheckDisjoint_0500, Function | MediumTest | Level1) +{ + std::list list1 = {"111111", "2222222"}; + std::list list2 = {"3333333", "4444444"}; + EXPECT_TRUE(OHOS::AppPackingTool::Utils::CheckDisjoint(list1, list2)); +} + +/* + * @tc.name: CheckContainsAll_0600 + * @tc.desc: CheckContainsAll. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, CheckContainsAll_0600, Function | MediumTest | Level1) +{ + std::list list1 = {"111111", "2222222", "3333333", "4444444"}; + std::list list2 = {"111111", "2222222"}; + EXPECT_TRUE(OHOS::AppPackingTool::Utils::CheckContainsAll(list1, list2)); +} + +/* + * @tc.name: GetSha256Str_0700 + * @tc.desc: GetSha256Str. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, GetSha256Str_0700, Function | MediumTest | Level1) +{ + std::string str = {"1111112222222"}; + EXPECT_TRUE(!OHOS::AppPackingTool::Utils::GetSha256Str(str).empty()); +} + +/* + * @tc.name: GetSha256File_0800 + * @tc.desc: GetSha256File. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, GetSha256File_0800, Function | MediumTest | Level1) +{ + EXPECT_TRUE(!OHOS::AppPackingTool::Utils::GetSha256File(FILE_PATH).empty()); +} + +/* + * @tc.name: IsFileExists_0900 + * @tc.desc: IsFileExists. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, IsFileExists_0900, Function | MediumTest | Level1) +{ + EXPECT_TRUE(OHOS::AppPackingTool::Utils::IsFileExists(FILE_PATH)); +} + +/* + * @tc.name: IsFile_1000 + * @tc.desc: IsFile. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, IsFile_1000, Function | MediumTest | Level1) +{ + EXPECT_TRUE(OHOS::AppPackingTool::Utils::IsFile(FILE_PATH)); +} + +/* + * @tc.name: IsDirectory_1100 + * @tc.desc: IsDirectory. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, IsDirectory_1100, Function | MediumTest | Level1) +{ + EXPECT_TRUE(OHOS::AppPackingTool::Utils::IsDirectory(TEMP_PATH)); +} + +/* + * @tc.name: RemoveFile_1200 + * @tc.desc: RemoveFile. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, RemoveFile_1200, Function | MediumTest | Level1) +{ + system("touch patch.json"); + std::string file("patch.json"); + EXPECT_TRUE(OHOS::AppPackingTool::Utils::RemoveFile(file)); +} + +/* + * @tc.name: RemoveDirectory_1300 + * @tc.desc: RemoveDirectory. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, RemoveDirectory_1300, Function | MediumTest | Level1) +{ + system("mkdir tempdir"); + std::string path("tempdir"); + EXPECT_TRUE(OHOS::AppPackingTool::Utils::RemoveDirectory(path)); +} + +/* + * @tc.name: GetFilePathByDir_1400 + * @tc.desc: GetFilePathByDir. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, GetFilePathByDir_1400, Function | MediumTest | Level1) +{ + std::string path("tempdir"); + std::string file("testfile"); + std::string filePath("tempdir/testfile"); + std::string temp = OHOS::AppPackingTool::Utils::GetFilePathByDir(path, file); + EXPECT_EQ(temp.compare(filePath), 0); +} + +/* + * @tc.name: ForceCreateDirectory_1500 + * @tc.desc: ForceCreateDirectory. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, ForceCreateDirectory_1500, Function | MediumTest | Level1) +{ + std::string path("tempdir"); + EXPECT_TRUE(OHOS::AppPackingTool::Utils::ForceCreateDirectory(path)); +} + +/* + * @tc.name: ForceRemoveDirectory_1600 + * @tc.desc: ForceRemoveDirectory. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, ForceRemoveDirectory_1600, Function | MediumTest | Level1) +{ + std::string path("tempdir"); + EXPECT_TRUE(OHOS::AppPackingTool::Utils::ForceCreateDirectory(path)); + + EXPECT_TRUE(OHOS::AppPackingTool::Utils::ForceRemoveDirectory(path)); +} +} // namespace OHOS \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/zip_utils_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/zip_utils_test/BUILD.gn new file mode 100644 index 00000000..44bdf143 --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/zip_utils_test/BUILD.gn @@ -0,0 +1,41 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "developtools/packing_tool" + +ohos_unittest("zip_utils_test") { + module_out_path = module_output_path + include_dirs = [ + "../../../include", + ] + sources = [ + "zip_utils_test.cpp", + "../../../src/zip_utils.cpp", + "../../../src/packager.cpp", + "../../../src/unzip_wrapper.cpp", + "../../../src/zip_wrapper.cpp", + "../../../src/utils.cpp", + "../../../src/log.cpp", + ] + external_deps = [ + "json:nlohmann_json_static", + "cJSON:cjson", + "hilog:libhilog", + "zlib:libz", + "openssl:libssl_shared", + "openssl:libcrypto_shared", + ] +} \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/zip_utils_test/zip_utils_test.cpp b/ohos_packing_tool/frameworks/test/unittest/zip_utils_test/zip_utils_test.cpp new file mode 100644 index 00000000..1fcd1bdd --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/zip_utils_test/zip_utils_test.cpp @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include "constants.h" +#include "zip_constants.h" +#define private public +#define protected public +#include "utils.h" +#include "unzip_wrapper.h" +#include "zip_wrapper.h" +#include "zip_utils.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define OUT_PATH "/data/test_1.hqf" +#define FILE_PATH "/data/zip_utils_test" +#define TEMP_PATH "/data/temp" + +class ZipUtilsTest : public testing::Test { +public: + ZipUtilsTest() {} + virtual ~ZipUtilsTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void ZipUtilsTest::SetUpTestCase() {} + +void ZipUtilsTest::TearDownTestCase() {} + +void ZipUtilsTest::SetUp() {} + +void ZipUtilsTest::TearDown() {} + +/* + * @tc.name: Zip_0100 + * @tc.desc: zip. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipUtilsTest, Zip_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ZipUtils zipUtils; + std::string filepath(FILE_PATH); + std::string zippath(OUT_PATH); + + int ret = zipUtils.Zip(filepath, zippath, OHOS::AppPackingTool::Constants::LIB_PATH); + EXPECT_EQ(ret, 0); + } + +/* + * @tc.name: Unzip_0200 + * @tc.desc: Unzip. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipUtilsTest, Unzip_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ZipUtils zipUtils; + std::string filepath(TEMP_PATH); + std::string zippath(OUT_PATH); + int ret = zipUtils.Unzip(zippath, filepath); + EXPECT_EQ(ret, 0); + + std::string cmd("rm -rf "); + cmd += TEMP_PATH; + system(cmd.c_str()); + + std::string cmd2("rm -rf "); + cmd2 += OUT_PATH; + system(cmd2.c_str()); +} + +/* + * @tc.name: IsFileExistsInZip_0300 + * @tc.desc: IsFileExistsInZip. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipUtilsTest, IsFileExistsInZip_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ZipUtils zipUtils; + std::string filepath(FILE_PATH); + std::string zippath(OUT_PATH); + + int ret = zipUtils.Zip(filepath, zippath, "packager_test"); + EXPECT_EQ(ret, 0); + + auto exist = zipUtils.IsFileExistsInZip(zippath, std::string("packager_test")); + EXPECT_TRUE(exist); + + std::string cmd2("rm -rf "); + cmd2 += OUT_PATH; + system(cmd2.c_str()); +} + +/* + * @tc.name: IsFileNameExistsInZip_0400 + * @tc.desc: IsFileNameExistsInZip. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipUtilsTest, IsFileNameExistsInZip_0400, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ZipUtils zipUtils; + std::string filepath(FILE_PATH); + std::string zippath(OUT_PATH); + + int ret = zipUtils.Zip(filepath, zippath, "packager_test"); + EXPECT_EQ(ret, 0); + + auto exist = zipUtils.IsFileNameExistsInZip(zippath, std::string("packager_test")); + EXPECT_TRUE(exist); + + std::string cmd2("rm -rf "); + cmd2 += OUT_PATH; + system(cmd2.c_str()); +} + +/* + * @tc.name: GetFileContentFromZip_0500 + * @tc.desc: GetFileContentFromZip. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipUtilsTest, GetFileContentFromZip_0500, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ZipUtils zipUtils; + std::string filepath(FILE_PATH); + std::string zippath(OUT_PATH); + std::string fileContent; + + int ret = zipUtils.Zip(filepath, zippath, "packager_test"); + EXPECT_EQ(ret, 0); + + EXPECT_TRUE(zipUtils.GetFileContentFromZip(zippath, std::string("packager_test"), fileContent)); + EXPECT_TRUE(!fileContent.empty()); + + std::string cmd2("rm -rf "); + cmd2 += OUT_PATH; + system(cmd2.c_str()); +} + +/* + * @tc.name: GetUnzipCurrentFileContent_0600 + * @tc.desc: GetUnzipCurrentFileContent. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipUtilsTest, GetUnzipCurrentFileContent_0600, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ZipUtils zipUtils; + std::string filepath(FILE_PATH); + std::string zippath(OUT_PATH); + std::string fileContent; + + int ret = zipUtils.Zip(filepath, zippath, "packager_test"); + EXPECT_EQ(ret, 0); + + unzFile unzipFile = unzOpen64(zippath.c_str()); + EXPECT_TRUE(zipUtils.GetUnzipCurrentFileContent(unzipFile, fileContent)); + EXPECT_TRUE(!fileContent.empty()); + + std::string cmd2("rm -rf "); + cmd2 += OUT_PATH; + system(cmd2.c_str()); +} + +/* + * @tc.name: GetResourceMapFromZip_0700 + * @tc.desc: GetResourceMapFromZip. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipUtilsTest, GetResourceMapFromZip_0700, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ZipUtils zipUtils; + std::string filepath(FILE_PATH); + std::string zippath(OUT_PATH); + std::map resourceMap; + + int ret = zipUtils.Zip(filepath, zippath, "packager_test"); + EXPECT_EQ(ret, 0); + + EXPECT_TRUE(zipUtils.GetResourceMapFromZip(zippath, resourceMap)); + + std::string cmd2("rm -rf "); + cmd2 += OUT_PATH; + system(cmd2.c_str()); +} +} // namespace OHOS \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/BUILD.gn new file mode 100644 index 00000000..2932b913 --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/BUILD.gn @@ -0,0 +1,38 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "developtools/packing_tool" + +ohos_unittest("zip_wrapper_test") { + module_out_path = module_output_path + include_dirs = [ + "../../../include", + ] + sources = [ + "zip_wrapper_test.cpp", + "../../../src/packager.cpp", + "../../../src/zip_wrapper.cpp", + "../../../src/log.cpp", + ] + external_deps = [ + "json:nlohmann_json_static", + "cJSON:cjson", + "hilog:libhilog", + "zlib:libz", + "openssl:libssl_shared", + "openssl:libcrypto_shared", + ] +} \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp b/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp new file mode 100644 index 00000000..a869058b --- /dev/null +++ b/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include "constants.h" +#include "zip_constants.h" +#define private public +#define protected public +// #include "packager.h" +// #include "hap_packager.h" +// #include "hsp_packager.h" +// #include "shell_command.h" +#include "zip_wrapper.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define OUT_PATH "/data/test_1.hqf" +#define FILE_PATH "/data/packager_test" + +std::string content = "{" + "\"name\": \"Json.CN\"," + "\"url\": \"http://www.json.cn\"," + "\"page\": 88," + "\"isNonProfit\": true," + "\"address\": {" + "\"street\": \"科技园路.\"," + "\"city\": \"江苏苏州\"," + "\"country\": \"中国\"" + "}," + "\"links\": [" + "{" + "\"name\": \"Google\"," + "\"url\": \"http://www.google.com\"" + "}," + "{" + "\"name\": \"Baidu\"," + "\"url\": \"http://www.baidu.com\"" + "}," + "{" + "\"name\": \"SoSo\"," + "\"url\": \"http://www.SoSo.com\"" + "}" + "]" +"}"; + +class ZipWrapperTest : public testing::Test { +public: + ZipWrapperTest() {} + virtual ~ZipWrapperTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void ZipWrapperTest::SetUpTestCase() {} + +void ZipWrapperTest::TearDownTestCase() {} + +void ZipWrapperTest::SetUp() {} + +void ZipWrapperTest::TearDown() {} + +/* + * @tc.name: Open_0100 + * @tc.desc: Open. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipWrapperTest, Open_0100, Function | MediumTest | Level1) +{ + std::string path(OUT_PATH); + OHOS::AppPackingTool::ZipWrapper zipWrapper; + zipWrapper.Open(path); + EXPECT_TRUE(zipWrapper.IsOpen()); + + zipWrapper.Close(); + EXPECT_FALSE(zipWrapper.IsOpen()); +} + +/* + * @tc.name: Open_0200 + * @tc.desc: Open. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipWrapperTest, Open_0200, Function | MediumTest | Level1) +{ + std::string path(OUT_PATH); + OHOS::AppPackingTool::ZipWrapper zipWrapper(path); + zipWrapper.Open(APPEND_STATUS_CREATE); + EXPECT_TRUE(zipWrapper.IsOpen()); + + zipWrapper.Close(); + EXPECT_FALSE(zipWrapper.IsOpen()); +} + +/* + * @tc.name: AddFileOrDirectoryToZip_0300 + * @tc.desc: AddFileOrDirectoryToZip. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipWrapperTest, AddFileOrDirectoryToZip_0300, Function | MediumTest | Level1) +{ + std::string path(OUT_PATH); + OHOS::AppPackingTool::ZipWrapper zipWrapper(path); + + zipWrapper.Open(APPEND_STATUS_CREATE); + int ret = zipWrapper.AddFileOrDirectoryToZip(FILE_PATH,OUT_PATH); + EXPECT_EQ(ret, 0); + + zipWrapper.Close(); +} + +/* + * @tc.name: AddFileOrDirectoryToZip_0400 + * @tc.desc: AddFileOrDirectoryToZip. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipWrapperTest, AddFileOrDirectoryToZip_0400, Function | MediumTest | Level1) +{ + std::string path(OUT_PATH); + OHOS::AppPackingTool::ZipWrapper zipWrapper(path); + + zipWrapper.Open(APPEND_STATUS_CREATE); + std::string filepath(FILE_PATH); + std::string zippath(OUT_PATH); + int ret = zipWrapper.AddFileOrDirectoryToZip(filepath,zippath); + EXPECT_EQ(ret, 0); + + zipWrapper.Close(); +} + +/* + * @tc.name: WriteStringToZip_0500 + * @tc.desc: WriteStringToZip. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipWrapperTest, WriteStringToZip_0500, Function | MediumTest | Level1) +{ + std::string path(OUT_PATH); + OHOS::AppPackingTool::ZipWrapper zipWrapper(path); + + zipWrapper.Open(APPEND_STATUS_CREATE); + int ret = zipWrapper.WriteStringToZip(content, OHOS::AppPackingTool::Constants::PARAM_JSON_PATH); + EXPECT_EQ(ret, 0); + + std::string filepath(FILE_PATH); + ret = zipWrapper.AddFileOrDirectoryToZip(filepath, OHOS::AppPackingTool::Constants::PARAM_LIB_PATH); + EXPECT_EQ(ret, 0); + + ret = zipWrapper.AddFileOrDirectoryToZip(filepath, OHOS::AppPackingTool::Constants::PARAM_RESOURCES_PATH); + EXPECT_EQ(ret, 0); + + ret = zipWrapper.AddFileOrDirectoryToZip(filepath, OHOS::AppPackingTool::Constants::PARAM_ETS_PATH); + EXPECT_EQ(ret, 0); + + zipWrapper.Close(); + + std::string cmd = {"rm -f "}; + cmd += OUT_PATH; + system(cmd.c_str()); +} +} // namespace OHOS \ No newline at end of file -- Gitee From 69b11363664dd3cd31602dca388be3b847f930cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Wed, 31 Jul 2024 03:36:10 +0000 Subject: [PATCH 02/27] update ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../test/unittest/zip_wrapper_test/zip_wrapper_test.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp b/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp index a869058b..e07cf54a 100644 --- a/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp +++ b/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp @@ -20,10 +20,6 @@ #include "zip_constants.h" #define private public #define protected public -// #include "packager.h" -// #include "hap_packager.h" -// #include "hsp_packager.h" -// #include "shell_command.h" #include "zip_wrapper.h" #undef private #undef protected -- Gitee From 30d9165f0402851acb3e69acca45446d6e773ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Wed, 31 Jul 2024 03:38:31 +0000 Subject: [PATCH 03/27] update ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../json/pt_json_test/pt_json_test.cpp | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp b/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp index 76f649de..4218052d 100644 --- a/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp +++ b/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp @@ -369,8 +369,8 @@ HWTEST_F(PtJsonTest, SetBool_1800, Function | MediumTest | Level1) bool flag = false; ptJson.Add("AAA", true); - EXPECT_EQ(ptJson.SetBool("AAA",flag), OHOS::AppPackingTool::Result::SUCCESS); - ptJson.GetBool("AAA",&flag); + EXPECT_EQ(ptJson.SetBool("AAA", flag), OHOS::AppPackingTool::Result::SUCCESS); + ptJson.GetBool("AAA", &flag); EXPECT_FALSE(flag); } @@ -387,7 +387,7 @@ HWTEST_F(PtJsonTest, SetInt_1900, Function | MediumTest | Level1) EXPECT_TRUE(ptJson.Add("BBB", 123)); int number = 0; - EXPECT_EQ(ptJson.SetInt("BBB",321), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(ptJson.SetInt("BBB", 321), OHOS::AppPackingTool::Result::SUCCESS); ptJson.GetInt("BBB", &number); EXPECT_EQ(number, 321); } @@ -407,27 +407,27 @@ HWTEST_F(PtJsonTest, SetInt64_2000, Function | MediumTest | Level1) EXPECT_TRUE(ptJson.Add("CCC", 123.5)); int64_t value64 = 11111; - EXPECT_EQ(ptJson.SetInt64("BBB",value64), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(ptJson.SetInt64("BBB", value64), OHOS::AppPackingTool::Result::SUCCESS); int64_t value642; - EXPECT_EQ(ptJson.GetInt64("BBB",&value642), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(ptJson.GetInt64("BBB", &value642), OHOS::AppPackingTool::Result::SUCCESS); EXPECT_EQ(value642, 11111); uint32_t value32 = 2222; - EXPECT_EQ(ptJson.SetUInt("BBB",value32), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(ptJson.SetUInt("BBB", value32), OHOS::AppPackingTool::Result::SUCCESS); uint32_t value322; - EXPECT_EQ(ptJson.GetUInt("BBB",&value322), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(ptJson.GetUInt("BBB", &value322), OHOS::AppPackingTool::Result::SUCCESS); EXPECT_EQ(value322, 2222); uint64_t valueInt64 = 3333; - EXPECT_EQ(ptJson.SetUInt64("BBB",valueInt64), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(ptJson.SetUInt64("BBB", valueInt64), OHOS::AppPackingTool::Result::SUCCESS); uint64_t valueInt642; - EXPECT_EQ(ptJson.GetUInt64("BBB",&valueInt642), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(ptJson.GetUInt64("BBB", &valueInt642), OHOS::AppPackingTool::Result::SUCCESS); EXPECT_EQ(valueInt642, 3333); double valueDouble = 4444; - EXPECT_EQ(ptJson.SetDouble("CCC",valueDouble), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(ptJson.SetDouble("CCC", valueDouble), OHOS::AppPackingTool::Result::SUCCESS); double valueDouble2; - EXPECT_EQ(ptJson.GetDouble("CCC",&valueDouble2), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(ptJson.GetDouble("CCC", &valueDouble2), OHOS::AppPackingTool::Result::SUCCESS); EXPECT_EQ(valueDouble2, 4444); } @@ -444,9 +444,9 @@ HWTEST_F(PtJsonTest, SetString_2100, Function | MediumTest | Level1) EXPECT_TRUE(ptJson.Add("DDD", "ABC")); std::string str("1234567890"); - EXPECT_EQ(ptJson.SetString("DDD",str), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(ptJson.SetString("DDD", str), OHOS::AppPackingTool::Result::SUCCESS); std::string str2; - EXPECT_EQ(ptJson.GetString("DDD",&str2), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(ptJson.GetString("DDD", &str2), OHOS::AppPackingTool::Result::SUCCESS); EXPECT_STREQ(str2.c_str(), str.c_str()); } @@ -465,7 +465,7 @@ HWTEST_F(PtJsonTest, GetObject_2200, Function | MediumTest | Level1) EXPECT_TRUE(ptjsonObject != NULL); EXPECT_TRUE(ptJson.Add("EEE", ptjsonObject)); std::unique_ptr Object; - EXPECT_EQ(ptJson.GetObject("EEE",&Object), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(ptJson.GetObject("EEE", &Object), OHOS::AppPackingTool::Result::SUCCESS); } /* @@ -481,7 +481,7 @@ HWTEST_F(PtJsonTest, GetArray_2300, Function | MediumTest | Level1) ptJson.Add("FFF", ptJson.CreateArray()); std::unique_ptr Array; - EXPECT_EQ(ptJson.GetArray("FFF",&Array), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(ptJson.GetArray("FFF", &Array), OHOS::AppPackingTool::Result::SUCCESS); } /* @@ -497,6 +497,6 @@ HWTEST_F(PtJsonTest, GetAny_2400, Function | MediumTest | Level1) ptJson.Add("FFF", ptJson.CreateArray()); std::unique_ptr Object; - EXPECT_EQ(ptJson.GetAny("FFF",&Object), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(ptJson.GetAny("FFF", &Object), OHOS::AppPackingTool::Result::SUCCESS); } } // namespace OHOS \ No newline at end of file -- Gitee From bb979686dc4a35c5b53133c6c3dd7bb5387c51f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Wed, 31 Jul 2024 03:43:13 +0000 Subject: [PATCH 04/27] update ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp b/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp index 4218052d..472de0be 100644 --- a/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp +++ b/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp @@ -35,7 +35,7 @@ std::string content = "{" "\"name\": \"nametest\"," "\"type\": \"typetest\"," "\"deviceTypes\": [" - "\"aaaaaaaaaaa\"," + "\"aaaaaaaaaaa\"," "\"bbbbbbbbbbb\"," "\"ccccccccccc\"" "]" -- Gitee From bf0d1f2832a0594b73798d63d9f25c5d48f7a3d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Wed, 31 Jul 2024 03:45:14 +0000 Subject: [PATCH 05/27] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20oh?= =?UTF-8?q?os=5Fpacking=5Ftool/frameworks/test/unittest/json/distro=5Ffilt?= =?UTF-8?q?er=5Ftest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unittest/json/distro_filter_test/BUILD.gn | 38 -------- .../distro_filter_test/distro_filter_test.cpp | 88 ------------------- 2 files changed, 126 deletions(-) delete mode 100644 ohos_packing_tool/frameworks/test/unittest/json/distro_filter_test/BUILD.gn delete mode 100644 ohos_packing_tool/frameworks/test/unittest/json/distro_filter_test/distro_filter_test.cpp diff --git a/ohos_packing_tool/frameworks/test/unittest/json/distro_filter_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/json/distro_filter_test/BUILD.gn deleted file mode 100644 index 84376f6e..00000000 --- a/ohos_packing_tool/frameworks/test/unittest/json/distro_filter_test/BUILD.gn +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//build/test.gni") - -module_output_path = "developtools/packing_tool" - -ohos_unittest("distro_filter_test") { - module_out_path = module_output_path - include_dirs = [ - "../../../../include", - "../../../../include/json" - ] - sources = [ - "distro_filter_test.cpp", - "../../../../src/json/distro_filter.cpp", - "../../../../src/json/pt_json.cpp", - "../../../../src/log.cpp", - ] - external_deps = [ - "json:nlohmann_json_static", - "cJSON:cjson", - "hilog:libhilog", - "zlib:libz", - "openssl:libcrypto_shared", - ] -} \ No newline at end of file diff --git a/ohos_packing_tool/frameworks/test/unittest/json/distro_filter_test/distro_filter_test.cpp b/ohos_packing_tool/frameworks/test/unittest/json/distro_filter_test/distro_filter_test.cpp deleted file mode 100644 index 614524b5..00000000 --- a/ohos_packing_tool/frameworks/test/unittest/json/distro_filter_test/distro_filter_test.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include -#define private public -#define protected public -#include "distro_filter.h" -#include "pt_json.h" -#include "log.h" -#undef private -#undef protected - -using namespace testing; -using namespace testing::ext; - -namespace OHOS { - -std::string content = "{" - "\"name\": \"Json.CN\"," - "\"app\": \"apptest\"," - "\"module\": {" - "\"name\": \"nametest\"," - "\"type\": \"typetest\"," - "\"deviceTypes\": [" - "\"aaaaaaaaaaa\"," - "\"bbbbbbbbbbb\"," - "\"ccccccccccc\"" - "]" - "}" - "\"bundleName\": \"bundleNametest\"," - "\"versionCode\": 100," - "\"versionName\": \"versionNametest\"," - "\"patchVersionCode\": 200," - "\"patchVersionName\": \"patchVersionNametest\"," - "\"originalModuleHash\": \"originalModuleHashtest\"," - "\"url\": \"http://www.json.cn\"," - "\"page\": 88," - "\"isNonProfit\": true" -"}"; - -class distroFilterTest : public testing::Test { -public: - distroFilterTest() {} - virtual ~distroFilterTest() {} - - static void SetUpTestCase(); - - static void TearDownTestCase(); - - void SetUp(); - - void TearDown(); -}; - -void distroFilterTest::SetUpTestCase() {} - -void distroFilterTest::TearDownTestCase() {} - -void distroFilterTest::SetUp() {} - -void distroFilterTest::TearDown() {} - -/* - * @tc.name: ParseFromString_0100 - * @tc.desc: ParseFromString. - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(distroFilterTest, ParseFromString_0100, Function | MediumTest | Level1) -{ - OHOS::AppPackingTool::PolicyValue policyValue; - EXPECT_TRUE(policyValue.ParseFromString(content)); -} -} \ No newline at end of file -- Gitee From 11e1999f9f58bf9b5b6a3756fe882cdb661f2c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Wed, 31 Jul 2024 03:51:22 +0000 Subject: [PATCH 06/27] update ohos_packing_tool/frameworks/test/unittest/zip_utils_test/zip_utils_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../frameworks/test/unittest/zip_utils_test/zip_utils_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_packing_tool/frameworks/test/unittest/zip_utils_test/zip_utils_test.cpp b/ohos_packing_tool/frameworks/test/unittest/zip_utils_test/zip_utils_test.cpp index 1fcd1bdd..128b9868 100644 --- a/ohos_packing_tool/frameworks/test/unittest/zip_utils_test/zip_utils_test.cpp +++ b/ohos_packing_tool/frameworks/test/unittest/zip_utils_test/zip_utils_test.cpp @@ -72,7 +72,7 @@ HWTEST_F(ZipUtilsTest, Zip_0100, Function | MediumTest | Level1) int ret = zipUtils.Zip(filepath, zippath, OHOS::AppPackingTool::Constants::LIB_PATH); EXPECT_EQ(ret, 0); - } +} /* * @tc.name: Unzip_0200 -- Gitee From b47bd901b1656f415a4e1e94e4fb3c4d1debeb78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Wed, 31 Jul 2024 03:52:39 +0000 Subject: [PATCH 07/27] update ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../test/unittest/json/pt_json_test/pt_json_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp b/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp index 472de0be..6af19bce 100644 --- a/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp +++ b/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp @@ -237,11 +237,11 @@ HWTEST_F(PtJsonTest, Contains_0900, Function | MediumTest | Level1) HWTEST_F(PtJsonTest, GetKey_1000, Function | MediumTest | Level1) { char a[]="{\"firstName\":\"Brett\"}"; - cJSON*root=cJSON_Parse(a); + cJSON*root=cJSON_Parse(a); cJSON*item=cJSON_GetObjectItem(root,"firstName"); OHOS::AppPackingTool::PtJson ptJson(item); EXPECT_TRUE(!ptJson.GetKey().empty()); - EXPECT_TRUE(!ptJson.Stringify().empty()); + EXPECT_TRUE(!ptJson.Stringify().empty()); } /* -- Gitee From 0f864a9c469d122d3863a083ee905c84e75a0b25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Wed, 31 Jul 2024 03:54:58 +0000 Subject: [PATCH 08/27] update ohos_packing_tool/frameworks/test/unittest/json/patch_json_test/patch_json_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../test/unittest/json/patch_json_test/patch_json_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_packing_tool/frameworks/test/unittest/json/patch_json_test/patch_json_test.cpp b/ohos_packing_tool/frameworks/test/unittest/json/patch_json_test/patch_json_test.cpp index b5f7e6bf..4a3a549c 100644 --- a/ohos_packing_tool/frameworks/test/unittest/json/patch_json_test/patch_json_test.cpp +++ b/ohos_packing_tool/frameworks/test/unittest/json/patch_json_test/patch_json_test.cpp @@ -43,7 +43,7 @@ std::string content = "{" "\"type\": \"typetest\"," "\"originalModuleHash\": \"originalModuleHashtest\"," "\"deviceTypes\": [" - "\"aaaaaaaaaaa\"," + "\"aaaaaaaaaaa\"," "\"bbbbbbbbbbb\"," "\"ccccccccccc\"" "]" -- Gitee From 97ce84f0c92bfca8876603223585b273c4b4062f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Wed, 31 Jul 2024 03:59:55 +0000 Subject: [PATCH 09/27] update ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../test/unittest/zip_wrapper_test/zip_wrapper_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp b/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp index e07cf54a..20c28e36 100644 --- a/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp +++ b/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp @@ -126,7 +126,7 @@ HWTEST_F(ZipWrapperTest, AddFileOrDirectoryToZip_0300, Function | MediumTest | L OHOS::AppPackingTool::ZipWrapper zipWrapper(path); zipWrapper.Open(APPEND_STATUS_CREATE); - int ret = zipWrapper.AddFileOrDirectoryToZip(FILE_PATH,OUT_PATH); + int ret = zipWrapper.AddFileOrDirectoryToZip(FILE_PATH, OUT_PATH); EXPECT_EQ(ret, 0); zipWrapper.Close(); @@ -146,7 +146,7 @@ HWTEST_F(ZipWrapperTest, AddFileOrDirectoryToZip_0400, Function | MediumTest | L zipWrapper.Open(APPEND_STATUS_CREATE); std::string filepath(FILE_PATH); std::string zippath(OUT_PATH); - int ret = zipWrapper.AddFileOrDirectoryToZip(filepath,zippath); + int ret = zipWrapper.AddFileOrDirectoryToZip(filepath, zippath); EXPECT_EQ(ret, 0); zipWrapper.Close(); -- Gitee From b6da305ccb826e91bb2ecad3fd125d984bcddc02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Wed, 31 Jul 2024 04:03:45 +0000 Subject: [PATCH 10/27] update ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../test/unittest/json/pt_json_test/pt_json_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp b/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp index 6af19bce..bd7d2538 100644 --- a/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp +++ b/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp @@ -237,8 +237,8 @@ HWTEST_F(PtJsonTest, Contains_0900, Function | MediumTest | Level1) HWTEST_F(PtJsonTest, GetKey_1000, Function | MediumTest | Level1) { char a[]="{\"firstName\":\"Brett\"}"; - cJSON*root=cJSON_Parse(a); - cJSON*item=cJSON_GetObjectItem(root,"firstName"); + cJSON*root = cJSON_Parse(a); + cJSON*item = cJSON_GetObjectItem(root, "firstName"); OHOS::AppPackingTool::PtJson ptJson(item); EXPECT_TRUE(!ptJson.GetKey().empty()); EXPECT_TRUE(!ptJson.Stringify().empty()); -- Gitee From bbc4f66539a2aa71d8b131a12d3eef608d718b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Wed, 31 Jul 2024 04:09:49 +0000 Subject: [PATCH 11/27] update ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../zip_wrapper_test/zip_wrapper_test.cpp | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp b/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp index 20c28e36..fecee2f6 100644 --- a/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp +++ b/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp @@ -33,29 +33,10 @@ namespace OHOS { #define FILE_PATH "/data/packager_test" std::string content = "{" - "\"name\": \"Json.CN\"," - "\"url\": \"http://www.json.cn\"," + "\"name\": \"xxx.CN\"," + "\"url\": \"http://www.xxx.cn\"," "\"page\": 88," - "\"isNonProfit\": true," - "\"address\": {" - "\"street\": \"科技园路.\"," - "\"city\": \"江苏苏州\"," - "\"country\": \"中国\"" - "}," - "\"links\": [" - "{" - "\"name\": \"Google\"," - "\"url\": \"http://www.google.com\"" - "}," - "{" - "\"name\": \"Baidu\"," - "\"url\": \"http://www.baidu.com\"" - "}," - "{" - "\"name\": \"SoSo\"," - "\"url\": \"http://www.SoSo.com\"" - "}" - "]" + "\"isNonProfit\": true" "}"; class ZipWrapperTest : public testing::Test { -- Gitee From dbce671d3c31ca73c9655f0620633a070a5d75ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Wed, 31 Jul 2024 04:15:55 +0000 Subject: [PATCH 12/27] update ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp b/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp index bd7d2538..98c3118f 100644 --- a/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp +++ b/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp @@ -236,7 +236,7 @@ HWTEST_F(PtJsonTest, Contains_0900, Function | MediumTest | Level1) */ HWTEST_F(PtJsonTest, GetKey_1000, Function | MediumTest | Level1) { - char a[]="{\"firstName\":\"Brett\"}"; + char a[] = "{\"firstName\":\"Brett\"}"; cJSON*root = cJSON_Parse(a); cJSON*item = cJSON_GetObjectItem(root, "firstName"); OHOS::AppPackingTool::PtJson ptJson(item); -- Gitee From 4e0df4e1e0d1851169b7ca957eee536da79cd612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Thu, 1 Aug 2024 09:53:59 +0000 Subject: [PATCH 13/27] update bundle.json. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- bundle.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bundle.json b/bundle.json index 570c8e61..09f67872 100755 --- a/bundle.json +++ b/bundle.json @@ -25,6 +25,9 @@ "sub_component": [ "//developtools/packing_tool:packing_tool", "//developtools/packing_tool:ohos_packing_tool" + ], + "test": [ + "//developtools/packing_tool/ohos_packing_tool/frameworks:unittest" ] } } -- Gitee From 19930e6cbf2393061368de052f2bce0d09bcfafe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Fri, 2 Aug 2024 01:26:57 +0000 Subject: [PATCH 14/27] update bundle.json. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- bundle.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index 09f67872..366cc366 100755 --- a/bundle.json +++ b/bundle.json @@ -27,7 +27,7 @@ "//developtools/packing_tool:ohos_packing_tool" ], "test": [ - "//developtools/packing_tool/ohos_packing_tool/frameworks:unittest" + "//developtools/packing_tool/ohos_packing_tool/frameworks:unittest" ] } } -- Gitee From 01aa22531977b098e6f4bf8282ac162333c00a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Fri, 2 Aug 2024 01:28:28 +0000 Subject: [PATCH 15/27] update ohos_packing_tool/frameworks/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- ohos_packing_tool/frameworks/BUILD.gn | 44 +++++++++++++-------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/ohos_packing_tool/frameworks/BUILD.gn b/ohos_packing_tool/frameworks/BUILD.gn index 9e24b093..d9361a1b 100644 --- a/ohos_packing_tool/frameworks/BUILD.gn +++ b/ohos_packing_tool/frameworks/BUILD.gn @@ -16,19 +16,11 @@ import("//build/ohos.gni") ohos_executable("ohos_packing_tool") { include_dirs = [ "include", - "include/json" + "include/json", ] sources = [ "src/hap_packager.cpp", "src/hsp_packager.cpp", - "src/main.cpp", - "src/packager.cpp", - "src/shell_command.cpp", - "src/zip_wrapper.cpp", - "src/unzip_wrapper.cpp", - "src/zip_utils.cpp", - "src/log.cpp", - "src/utils.cpp", "src/json/distro_filter.cpp", "src/json/hap_verify_info.cpp", "src/json/json_utils.cpp", @@ -39,15 +31,23 @@ ohos_executable("ohos_packing_tool") { "src/json/patch_json.cpp", "src/json/patch_json_utils.cpp", "src/json/pt_json.cpp", + "src/log.cpp", + "src/main.cpp", + "src/packager.cpp", + "src/shell_command.cpp", + "src/unzip_wrapper.cpp", + "src/utils.cpp", + "src/zip_utils.cpp", + "src/zip_wrapper.cpp", ] configs = [] cflags = [] external_deps = [ - "json:nlohmann_json_static", "cJSON:cjson", "hilog:libhilog", - "zlib:libz", + "json:nlohmann_json_static", "openssl:libcrypto_shared", + "zlib:libz", ] install_enable = false subsystem_name = "developtools" @@ -57,15 +57,15 @@ ohos_executable("ohos_packing_tool") { group("unittest") { testonly = true deps = [ - "test/unittest/hap_packager_test:hap_packager_test", - "test/unittest/hsp_packager_test:hsp_packager_test", - "test/unittest/shell_command_test:shell_command_test", - "test/unittest/unzip_wrapper_test:unzip_wrapper_test", - "test/unittest/utils_Test:utils_Test", - "test/unittest/zip_utils_test:zip_utils_test", - "test/unittest/zip_wrapper_test:zip_wrapper_test", - "test/unittest/json/distro_filter_test:distro_filter_test", - "test/unittest/json/pt_json_test:pt_json_test", - "test/unittest/json/patch_json_test:patch_json_test", + "test/unittest/hap_packager_test:hap_packager_test", + "test/unittest/hsp_packager_test:hsp_packager_test", + "test/unittest/json/distro_filter_test:distro_filter_test", + "test/unittest/json/patch_json_test:patch_json_test", + "test/unittest/json/pt_json_test:pt_json_test", + "test/unittest/shell_command_test:shell_command_test", + "test/unittest/unzip_wrapper_test:unzip_wrapper_test", + "test/unittest/utils_Test:utils_Test", + "test/unittest/zip_utils_test:zip_utils_test", + "test/unittest/zip_wrapper_test:zip_wrapper_test", ] -} \ No newline at end of file +} -- Gitee From df62ba9d7568841e3365dec7fa141abd42675b59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Fri, 2 Aug 2024 02:15:40 +0000 Subject: [PATCH 16/27] update ohos_packing_tool/frameworks/test/unittest/hap_packager_test/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../test/unittest/hap_packager_test/BUILD.gn | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/ohos_packing_tool/frameworks/test/unittest/hap_packager_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/hap_packager_test/BUILD.gn index ff0f1679..b677bdfb 100644 --- a/ohos_packing_tool/frameworks/test/unittest/hap_packager_test/BUILD.gn +++ b/ohos_packing_tool/frameworks/test/unittest/hap_packager_test/BUILD.gn @@ -18,22 +18,20 @@ module_output_path = "developtools/packing_tool" ohos_unittest("hap_packager_test") { module_out_path = module_output_path - include_dirs = [ - "../../../include", - ] + include_dirs = [ "../../../include" ] sources = [ - "hap_packager_test.cpp", "../../../src/hap_packager.cpp", + "../../../src/log.cpp", "../../../src/packager.cpp", "../../../src/zip_wrapper.cpp", - "../../../src/log.cpp", + "hap_packager_test.cpp", ] external_deps = [ - "json:nlohmann_json_static", "cJSON:cjson", "hilog:libhilog", - "zlib:libz", - "openssl:libssl_shared", + "json:nlohmann_json_static", "openssl:libcrypto_shared", + "openssl:libssl_shared", + "zlib:libz", ] -} \ No newline at end of file +} -- Gitee From 16044980f5dcbb5ae662f153805058003610b3ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Fri, 2 Aug 2024 02:43:33 +0000 Subject: [PATCH 17/27] update ohos_packing_tool/frameworks/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- ohos_packing_tool/frameworks/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/ohos_packing_tool/frameworks/BUILD.gn b/ohos_packing_tool/frameworks/BUILD.gn index d9361a1b..76349857 100644 --- a/ohos_packing_tool/frameworks/BUILD.gn +++ b/ohos_packing_tool/frameworks/BUILD.gn @@ -59,7 +59,6 @@ group("unittest") { deps = [ "test/unittest/hap_packager_test:hap_packager_test", "test/unittest/hsp_packager_test:hsp_packager_test", - "test/unittest/json/distro_filter_test:distro_filter_test", "test/unittest/json/patch_json_test:patch_json_test", "test/unittest/json/pt_json_test:pt_json_test", "test/unittest/shell_command_test:shell_command_test", -- Gitee From 2200e32eebe1189b0f7cd1185419c3d16e091207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Fri, 2 Aug 2024 03:11:28 +0000 Subject: [PATCH 18/27] update ohos_packing_tool/frameworks/test/unittest/hap_packager_test/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../frameworks/test/unittest/hap_packager_test/BUILD.gn | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ohos_packing_tool/frameworks/test/unittest/hap_packager_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/hap_packager_test/BUILD.gn index b677bdfb..dcc778fc 100644 --- a/ohos_packing_tool/frameworks/test/unittest/hap_packager_test/BUILD.gn +++ b/ohos_packing_tool/frameworks/test/unittest/hap_packager_test/BUILD.gn @@ -35,3 +35,9 @@ ohos_unittest("hap_packager_test") { "zlib:libz", ] } + +group("unittest") { + testonly = true + + deps = [ ":hap_packager_test" ] +} -- Gitee From 5852a875acbb97dc946c27ebfaf8dffec71e091b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Fri, 2 Aug 2024 03:12:21 +0000 Subject: [PATCH 19/27] update ohos_packing_tool/frameworks/test/unittest/hsp_packager_test/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../frameworks/test/unittest/hsp_packager_test/BUILD.gn | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ohos_packing_tool/frameworks/test/unittest/hsp_packager_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/hsp_packager_test/BUILD.gn index e3b3d727..d3230ea6 100644 --- a/ohos_packing_tool/frameworks/test/unittest/hsp_packager_test/BUILD.gn +++ b/ohos_packing_tool/frameworks/test/unittest/hsp_packager_test/BUILD.gn @@ -36,4 +36,10 @@ ohos_unittest("hsp_packager_test") { "openssl:libssl_shared", "openssl:libcrypto_shared", ] +} + +group("unittest") { + testonly = true + + deps = [ ":hsp_packager_test" ] } \ No newline at end of file -- Gitee From b3cf36898cac8a318b1f7738228bbb704290c5cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Fri, 2 Aug 2024 03:13:13 +0000 Subject: [PATCH 20/27] update ohos_packing_tool/frameworks/test/unittest/json/patch_json_test/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../frameworks/test/unittest/json/patch_json_test/BUILD.gn | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ohos_packing_tool/frameworks/test/unittest/json/patch_json_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/json/patch_json_test/BUILD.gn index 26c446cf..8f50d918 100644 --- a/ohos_packing_tool/frameworks/test/unittest/json/patch_json_test/BUILD.gn +++ b/ohos_packing_tool/frameworks/test/unittest/json/patch_json_test/BUILD.gn @@ -35,4 +35,10 @@ ohos_unittest("patch_json_test") { "zlib:libz", "openssl:libcrypto_shared", ] +} + +group("unittest") { + testonly = true + + deps = [ ":patch_json_test" ] } \ No newline at end of file -- Gitee From dfdd5ddc4b1a7736df90a96b05c9554d5a10b86e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Fri, 2 Aug 2024 03:13:55 +0000 Subject: [PATCH 21/27] update ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../frameworks/test/unittest/json/pt_json_test/BUILD.gn | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/BUILD.gn index 3c2f26ee..d506d4a4 100644 --- a/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/BUILD.gn +++ b/ohos_packing_tool/frameworks/test/unittest/json/pt_json_test/BUILD.gn @@ -34,4 +34,10 @@ ohos_unittest("pt_json_test") { "zlib:libz", "openssl:libcrypto_shared", ] +} + +group("unittest") { + testonly = true + + deps = [ ":pt_json_test" ] } \ No newline at end of file -- Gitee From 2c53645ae91d748a1a7598e3a92afb48f46bbf0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Fri, 2 Aug 2024 03:14:38 +0000 Subject: [PATCH 22/27] update ohos_packing_tool/frameworks/test/unittest/shell_command_test/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../frameworks/test/unittest/shell_command_test/BUILD.gn | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ohos_packing_tool/frameworks/test/unittest/shell_command_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/shell_command_test/BUILD.gn index 88584843..c7581057 100644 --- a/ohos_packing_tool/frameworks/test/unittest/shell_command_test/BUILD.gn +++ b/ohos_packing_tool/frameworks/test/unittest/shell_command_test/BUILD.gn @@ -38,4 +38,10 @@ ohos_unittest("shell_command_test") { "openssl:libssl_shared", "openssl:libcrypto_shared", ] +} + +group("unittest") { + testonly = true + + deps = [ ":shell_command_test" ] } \ No newline at end of file -- Gitee From 885c34e41db2b4bc157efafe1bf6da06a158e9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Fri, 2 Aug 2024 03:15:21 +0000 Subject: [PATCH 23/27] update ohos_packing_tool/frameworks/test/unittest/unzip_wrapper_test/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../frameworks/test/unittest/unzip_wrapper_test/BUILD.gn | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ohos_packing_tool/frameworks/test/unittest/unzip_wrapper_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/unzip_wrapper_test/BUILD.gn index fc020703..22d5c53a 100644 --- a/ohos_packing_tool/frameworks/test/unittest/unzip_wrapper_test/BUILD.gn +++ b/ohos_packing_tool/frameworks/test/unittest/unzip_wrapper_test/BUILD.gn @@ -36,4 +36,10 @@ ohos_unittest("unzip_wrapper_test") { "openssl:libssl_shared", "openssl:libcrypto_shared", ] +} + +group("unittest") { + testonly = true + + deps = [ ":unzip_wrapper_test" ] } \ No newline at end of file -- Gitee From 6b8b33e668db55f65c827ae8af777dbcde34ff4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Fri, 2 Aug 2024 03:16:05 +0000 Subject: [PATCH 24/27] update ohos_packing_tool/frameworks/test/unittest/utils_Test/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../frameworks/test/unittest/utils_Test/BUILD.gn | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ohos_packing_tool/frameworks/test/unittest/utils_Test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/utils_Test/BUILD.gn index ebedb778..bc84b9de 100644 --- a/ohos_packing_tool/frameworks/test/unittest/utils_Test/BUILD.gn +++ b/ohos_packing_tool/frameworks/test/unittest/utils_Test/BUILD.gn @@ -34,4 +34,10 @@ ohos_unittest("utils_Test") { "openssl:libssl_shared", "openssl:libcrypto_shared", ] +} + +group("unittest") { + testonly = true + + deps = [ ":utils_Test" ] } \ No newline at end of file -- Gitee From 2dc31489d849bbebc9839f35b574c506c0f3d2b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Fri, 2 Aug 2024 03:17:26 +0000 Subject: [PATCH 25/27] update ohos_packing_tool/frameworks/test/unittest/zip_utils_test/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../frameworks/test/unittest/zip_utils_test/BUILD.gn | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ohos_packing_tool/frameworks/test/unittest/zip_utils_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/zip_utils_test/BUILD.gn index 44bdf143..aa57536e 100644 --- a/ohos_packing_tool/frameworks/test/unittest/zip_utils_test/BUILD.gn +++ b/ohos_packing_tool/frameworks/test/unittest/zip_utils_test/BUILD.gn @@ -38,4 +38,10 @@ ohos_unittest("zip_utils_test") { "openssl:libssl_shared", "openssl:libcrypto_shared", ] +} + +group("unittest") { + testonly = true + + deps = [ ":zip_utils_test" ] } \ No newline at end of file -- Gitee From bac568bf908c49807decf96fb2b87689cfe7f054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Fri, 2 Aug 2024 03:18:45 +0000 Subject: [PATCH 26/27] update ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../frameworks/test/unittest/zip_wrapper_test/BUILD.gn | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/BUILD.gn b/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/BUILD.gn index 2932b913..c95d4126 100644 --- a/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/BUILD.gn +++ b/ohos_packing_tool/frameworks/test/unittest/zip_wrapper_test/BUILD.gn @@ -35,4 +35,10 @@ ohos_unittest("zip_wrapper_test") { "openssl:libssl_shared", "openssl:libcrypto_shared", ] +} + +group("unittest") { + testonly = true + + deps = [ ":zip_wrapper_test" ] } \ No newline at end of file -- Gitee From 9bdabf4a448dacd39f45c16709b94385fe72c54c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Fri, 2 Aug 2024 03:44:00 +0000 Subject: [PATCH 27/27] update bundle.json. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- bundle.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index 366cc366..aed8e790 100755 --- a/bundle.json +++ b/bundle.json @@ -1,5 +1,5 @@ { - "name": "packing_tool", + "name": "@ohos/packing_tool", "version": "3.2", "license": "Apache License 2.0", "publishAs": "code-segment", -- Gitee