From: Tomasz Iwanek Date: Tue, 11 Aug 2015 08:28:21 +0000 (+0200) Subject: Add static tpk backend library X-Git-Tag: accepted/tizen/mobile/20150818.220141~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F38%2F46138%2F3;p=platform%2Fcore%2Fappfw%2Fapp-installers.git Add static tpk backend library For linking with testsuites. Task was renamed to TpkInstaller class. HOSTTEST was removed due to missing files for this configuration in project files. Change-Id: I97de47bb1b4a622cfea89c8f7a692253056a1535 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 94bb3e0..6f1f24c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ SET(CMAKE_CXX_FLAGS_CCOV "-O0 -std=c++11 -g --coverage") # Targets SET(TARGET_LIBNAME_COMMON "common-installer") SET(TARGET_LIBNAME_WGT "wgt-installer") +SET(TARGET_LIBNAME_TPK "tpk-installer") SET(TARGET_WGT_BACKEND "wgt-backend") SET(TARGET_TPK_BACKEND "tpk-backend") diff --git a/src/tpk/CMakeLists.txt b/src/tpk/CMakeLists.txt index 00188ad..6b3a2e5 100644 --- a/src/tpk/CMakeLists.txt +++ b/src/tpk/CMakeLists.txt @@ -1,36 +1,22 @@ -IF(NOT DEFINED TARGET_TPK_BACKEND) - SET(TARGET_TPK_BACKEND "tpk-backend") -ENDIF(NOT DEFINED TARGET_TPK_BACKEND) - -SET(TARGET_TPK ${TARGET_TPK_BACKEND}) -OPTION(HOSTTEST "Option for the test on the host PC" OFF) SET(SRCS - main.cc - task.cc step/step_parse.cc step/step_create_symbolic_link.cc step/step_copy_manifest_xml.cc tpk_app_query_interface.cc + tpk_installer.cc xml_parser/xml_parser.cc ) -ADD_EXECUTABLE(${TARGET_TPK} ${SRCS}) - -SET(TPK_LDFLAGS -rdynamic) -IF(${HOSTTEST}) - MESSAGE("Host Test mode.") -SET(TPK_CFLAGS ${TPK_CFLAGS} -DHOSTTEST) - SET(MOCK_MODULES test/mock_pkgmgr_installer.c) -SET(SRCS ${SRCS} ${MOCK_MODULES}) +ADD_LIBRARY(${TARGET_LIBNAME_TPK} STATIC ${SRCS}) +ADD_EXECUTABLE(${TARGET_TPK_BACKEND} "tpk_backend.cc") -ELSE(${HOSTTEST}) - SET(TPK_CFLAGS ${TPK_CFLAGS} -I${CMAKE_CURRENT_SOURCE_DIR}/../) - ADD_DEFINITIONS(${TPK_CFLAGS}) -ENDIF(${HOSTTEST}) +TARGET_INCLUDE_DIRECTORIES(${TARGET_LIBNAME_TPK} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../") +TARGET_INCLUDE_DIRECTORIES(${TARGET_TPK_BACKEND} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../") -APPLY_PKG_CONFIG(${TARGET_TPK} +APPLY_PKG_CONFIG(${TARGET_LIBNAME_TPK} PUBLIC PKGMGR_DEPS Boost ) -TARGET_LINK_LIBRARIES(${TARGET_TPK} PUBLIC ${TARGET_LIBNAME_COMMON}) +TARGET_LINK_LIBRARIES(${TARGET_LIBNAME_TPK} PUBLIC ${TARGET_LIBNAME_COMMON}) +TARGET_LINK_LIBRARIES(${TARGET_TPK_BACKEND} PRIVATE ${TARGET_LIBNAME_TPK}) -INSTALL(TARGETS ${TARGET_TPK} DESTINATION ${BINDIR}) +INSTALL(TARGETS ${TARGET_TPK_BACKEND} DESTINATION ${BINDIR}) diff --git a/src/tpk/main.cc b/src/tpk/main.cc deleted file mode 100644 index e960ed0..0000000 --- a/src/tpk/main.cc +++ /dev/null @@ -1,18 +0,0 @@ -/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */ -#include -#include "tpk/task.h" -#include "common/utils/logging.h" - - -int main(const int argc, char* argv[]) { - tpk::Task t; - if (!t.Init(argc, argv)) { - std::cerr << "Task init failure" << std::endl; - return -1; - } - if (!t.Run()) { - std::cerr << "Task run failure" << std::endl; - return -1; - } - return 0; -} diff --git a/src/tpk/task.cc b/src/tpk/task.cc deleted file mode 100644 index 3fb50f3..0000000 --- a/src/tpk/task.cc +++ /dev/null @@ -1,139 +0,0 @@ -/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */ -#include "tpk/task.h" -#ifdef HOSTTEST -#include "test/mock_pkgmgr_installer.h" -#else -#include "common/app_installer.h" -#include "common/step/step_configure.h" -#include "common/step/step_backup_icons.h" -#include "common/step/step_backup_manifest.h" -#include "common/step/step_create_icons.h" -#include "common/step/step_create_storage_directories.h" -#include "common/step/step_copy.h" -#include "common/step/step_copy_backup.h" -#include "common/step/step_check_old_certificate.h" -#include "common/step/step_generate_xml.h" -#include "common/step/step_old_manifest.h" -#include "common/step/step_parse.h" -#include "common/step/step_register_app.h" -#include "common/step/step_remove_icons.h" -#include "common/step/step_remove_files.h" -#include "common/step/step_revoke_security.h" -#include "common/step/step_register_security.h" -#include "common/step/step_check_signature.h" -#include "common/step/step_unregister_app.h" -#include "common/step/step_unzip.h" -#include "common/step/step_update_app.h" -#include "common/step/step_update_security.h" -#include "common/utils/logging.h" -#include "tpk/step/step_copy_manifest_xml.h" -#include "tpk/step/step_create_symbolic_link.h" -#include "tpk/step/step_parse.h" -#endif - -namespace ci = common_installer; - -namespace { - -const char kPkgType[] = "tpk"; - -} // namespace - -namespace tpk { - -Task::Task() { -} - -Task::~Task() { -} - -bool Task::Init(int argc, char** argv) { - query_interface_.reset(new TpkAppQueryInterface()); - pkgmgr_ = ci::PkgMgrInterface::Create(argc, argv, query_interface_.get()); - if (!pkgmgr_) { - LOG(ERROR) << "Cannot connect to PkgMgrInstaller"; - return false; - } - return true; -} - -bool Task::Run() { - switch (pkgmgr_->GetRequestType()) { - case ci::RequestType::Install: - return Install(); - case ci::RequestType::Update: - return Update(); - case ci::RequestType::Uninstall: - return Uninstall(); - case ci::RequestType::Reinstall: - return Reinstall(); - case ci::RequestType::Recovery: - // TODO(t.iwanek): recovery mode invocation... - return false; - default: - break; - } - return false; -} - -bool Task::Install() { - ci::AppInstaller ai(kPkgType, pkgmgr_); - - ai.AddStep(pkgmgr_); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - - return ai.Run() == ci::AppInstaller::Result::OK; -} - -bool Task::Update() { - ci::AppInstaller ai(kPkgType, pkgmgr_); - - ai.AddStep(pkgmgr_); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - // TODO(t.iwanek): handle coping storage directories - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - - return ai.Run() == ci::AppInstaller::Result::OK; -} - -bool Task::Uninstall() { - ci::AppInstaller ai(kPkgType, pkgmgr_); - - ai.AddStep(pkgmgr_); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - ai.AddStep(); - - return ai.Run() == ci::AppInstaller::Result::OK; -} - -bool Task::Reinstall() { - return false; -} - -} // namespace tpk - diff --git a/src/tpk/task.h b/src/tpk/task.h deleted file mode 100644 index e913190..0000000 --- a/src/tpk/task.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */ -#ifndef TPK_TASK_H_ -#define TPK_TASK_H_ - -#include - -#ifdef HOSTTEST -#include "test/mock_pkgmgr_installer.h" -#endif -#include "common/utils/logging.h" - -#include "common/pkgmgr_interface.h" -#include "tpk/tpk_app_query_interface.h" - -namespace tpk { - -class Task { - public: - Task(); - ~Task(); - bool Init(int argc, char** argv); - bool Run(); - - private: - bool Install(); - bool Update(); - bool Uninstall(); - bool Reinstall(); - - common_installer::PkgMgrPtr pkgmgr_; - std::unique_ptr query_interface_; - - SCOPE_LOG_TAG(TpkTask) -}; // class Task - -} // namespace tpk - -#endif // TPK_TASK_H_ diff --git a/src/tpk/tpk_backend.cc b/src/tpk/tpk_backend.cc new file mode 100644 index 0000000..09c1270 --- /dev/null +++ b/src/tpk/tpk_backend.cc @@ -0,0 +1,25 @@ +/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */ + +#include + +#include "common/pkgmgr_interface.h" +#include "common/utils/logging.h" +#include "tpk/tpk_app_query_interface.h" +#include "tpk/tpk_installer.h" + +namespace ci = common_installer; + +int main(const int argc, char* argv[]) { + tpk::TpkAppQueryInterface interface; + ci::PkgMgrPtr pkgmgr = ci::PkgMgrInterface::Create(argc, argv, &interface); + if (!pkgmgr) { + LOG(ERROR) << "Failed to create pkgmgr interface"; + return -1; + } + tpk::TpkInstaller t(pkgmgr); + if (t.Run() != ci::AppInstaller::Result::OK) { + LOG(ERROR) << "TpkInstaller run failure"; + return -1; + } + return 0; +} diff --git a/src/tpk/tpk_installer.cc b/src/tpk/tpk_installer.cc new file mode 100644 index 0000000..d33b7f8 --- /dev/null +++ b/src/tpk/tpk_installer.cc @@ -0,0 +1,121 @@ +/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */ +#include "tpk/tpk_installer.h" +#include "common/app_installer.h" +#include "common/step/step_configure.h" +#include "common/step/step_backup_icons.h" +#include "common/step/step_backup_manifest.h" +#include "common/step/step_create_icons.h" +#include "common/step/step_create_storage_directories.h" +#include "common/step/step_copy.h" +#include "common/step/step_copy_backup.h" +#include "common/step/step_check_old_certificate.h" +#include "common/step/step_fail.h" +#include "common/step/step_generate_xml.h" +#include "common/step/step_old_manifest.h" +#include "common/step/step_parse.h" +#include "common/step/step_register_app.h" +#include "common/step/step_remove_icons.h" +#include "common/step/step_remove_files.h" +#include "common/step/step_revoke_security.h" +#include "common/step/step_register_security.h" +#include "common/step/step_check_signature.h" +#include "common/step/step_unregister_app.h" +#include "common/step/step_unzip.h" +#include "common/step/step_update_app.h" +#include "common/step/step_update_security.h" +#include "common/utils/logging.h" +#include "tpk/step/step_copy_manifest_xml.h" +#include "tpk/step/step_create_symbolic_link.h" +#include "tpk/step/step_parse.h" + +namespace ci = common_installer; + +namespace { + +const char kPkgType[] = "tpk"; + +} // namespace + +namespace tpk { + +TpkInstaller::TpkInstaller(common_installer::PkgMgrPtr pkgmgr) + : AppInstaller(kPkgType, pkgmgr) { + Prepare(); +} + +TpkInstaller::~TpkInstaller() { +} + +void TpkInstaller::Prepare() { + switch (pkgmgr_->GetRequestType()) { + case ci::RequestType::Install: + InstallSteps(); + break; + case ci::RequestType::Update: + UpdateSteps(); + break; + case ci::RequestType::Uninstall: + UninstallSteps(); + break; + case ci::RequestType::Reinstall: + ReinstallSteps(); + break; + case ci::RequestType::Recovery: + AddStep(); + // TODO(t.iwanek): recovery mode invocation... + break; + default: + AddStep(); + break; + } +} + +void TpkInstaller::InstallSteps() { + AddStep(pkgmgr_); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); +} + +void TpkInstaller::UpdateSteps() { + AddStep(pkgmgr_); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + // TODO(t.iwanek): handle coping storage directories + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); +} + +void TpkInstaller::UninstallSteps() { + AddStep(pkgmgr_); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); +} + +void TpkInstaller::ReinstallSteps() { + AddStep(); +} + +} // namespace tpk + diff --git a/src/tpk/tpk_installer.h b/src/tpk/tpk_installer.h new file mode 100644 index 0000000..f7d723c --- /dev/null +++ b/src/tpk/tpk_installer.h @@ -0,0 +1,37 @@ +/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */ + +#ifndef TPK_TPK_INSTALLER_H_ +#define TPK_TPK_INSTALLER_H_ + +#include "common/app_installer.h" +#include "common/pkgmgr_interface.h" +#include "common/utils/logging.h" + +namespace tpk { + +/** + * @brief The TpkInstaller class + * Handles request of tpk packages. + * + * This class is main class for installation/update/deinstallation of tpk + * packages. Pkgmgr request is parsed within and sequence of steps is built to + * be run. + */ +class TpkInstaller : public common_installer::AppInstaller { + public: + explicit TpkInstaller(common_installer::PkgMgrPtr pkgmgr); + ~TpkInstaller(); + void Prepare(); + + private: + void InstallSteps(); + void UpdateSteps(); + void UninstallSteps(); + void ReinstallSteps(); + + SCOPE_LOG_TAG(TpkInstaller) +}; + +} // namespace tpk + +#endif // TPK_TPK_INSTALLER_H_