From: Kamil Nowac Date: Mon, 10 Jun 2013 11:51:49 +0000 (+0200) Subject: [Path Usage Unification] Plugin Installation Paths (further enhancements) X-Git-Tag: 2.2.1_release~10^2~43 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3072306199bad8fb07529d273167f39550cf4577;p=framework%2Fweb%2Fwrt-installer.git [Path Usage Unification] Plugin Installation Paths (further enhancements) [Issue#] LINUXWRT-422 [Problem] A lot of paths used in wrt are constructed manually [Cause] N/A [Solution] Created class PluginPath which gathers all manually constructed paths [Verification] 1. Build wrt-installer repo with --define "WITH_TESTS ON" 2. Install plugins by using wrt-installer -p and run tests wrt-installer-tests-general --output=text They shoud install without problems and tests should pass. Change-Id: I82f1f3d2e9b46b9363f93311557984da1aeaabbd --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fb19a2c..794e7f1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -100,6 +100,7 @@ SET(INSTALLER_SOURCES ${INSTALLER_SRC_DIR}/misc/libxml_utils.cpp ${INSTALLER_SRC_DIR}/misc/widget_location.cpp ${INSTALLER_SRC_DIR}/misc/widget_install_to_external.cpp + ${INSTALLER_SRC_DIR}/misc/plugin_path.cpp ${INSTALLER_SRC_DIR}/pkg-manager/pkgmgr_signal.cpp ) diff --git a/src/jobs/plugin_install/job_plugin_install.cpp b/src/jobs/plugin_install/job_plugin_install.cpp index 6cc3c3f..f26e3f1 100644 --- a/src/jobs/plugin_install/job_plugin_install.cpp +++ b/src/jobs/plugin_install/job_plugin_install.cpp @@ -28,7 +28,7 @@ namespace Jobs { namespace PluginInstall { -JobPluginInstall::JobPluginInstall(DPL::Utils::Path const &pluginPath, +JobPluginInstall::JobPluginInstall(PluginPath const &pluginPath, const PluginInstallerStruct &installerStruct) : Job(PluginInstallation), diff --git a/src/jobs/plugin_install/job_plugin_install.h b/src/jobs/plugin_install/job_plugin_install.h index c4a59ee..68a4e11 100644 --- a/src/jobs/plugin_install/job_plugin_install.h +++ b/src/jobs/plugin_install/job_plugin_install.h @@ -31,8 +31,6 @@ #include #include #include -#include - namespace Jobs { namespace PluginInstall { class JobPluginInstall : @@ -48,7 +46,7 @@ class JobPluginInstall : /** * @brief Automaticaly sets installation process */ - JobPluginInstall(DPL::Utils::Path const &pluginPath, + JobPluginInstall(PluginPath const &pluginPath, const PluginInstallerStruct &installerStruct); WrtDB::DbPluginHandle getNewPluginHandle() const diff --git a/src/jobs/plugin_install/plugin_install_task.cpp b/src/jobs/plugin_install/plugin_install_task.cpp index 097f9ac..55f4105 100644 --- a/src/jobs/plugin_install/plugin_install_task.cpp +++ b/src/jobs/plugin_install/plugin_install_task.cpp @@ -41,13 +41,10 @@ #include #include "plugin_objects.h" #include +#include using namespace WrtDB; -namespace { -const std::string DIRECTORY_SEPARATOR = std::string("/"); -} - #define SET_PLUGIN_INSTALL_PROGRESS(step, desc) \ m_context->installerTask->UpdateProgress( \ PluginInstallerContext::step, desc); @@ -99,20 +96,17 @@ void PluginInstallTask::stepParseConfigFile() { LogDebug("Plugin installation: step parse config file"); - DPL::Utils::Path filename = m_context->pluginFilePath; - filename /= GlobalConfig::GetPluginMetafileName(); - - if(!filename.Exists()){ + if(!m_context->pluginFilePath.getMetaFile().Exists()){ m_dataFromConfigXML = false; return; } - LogDebug("Plugin Config file::" << filename.Filename()); + LogInfo("Plugin Config file::" << m_context->pluginFilePath.getMetaFile()); Try { PluginMetafileReader reader; - reader.initialize(filename); + reader.initialize(m_context->pluginFilePath.getMetaFile()); reader.read(m_pluginInfo); FOREACH(it, m_pluginInfo.m_featureContainer) @@ -127,7 +121,8 @@ void PluginInstallTask::stepParseConfigFile() } Catch(ValidationCore::ParserSchemaException::Base) { - LogError("Error during file processing " << filename.Filename()); + LogError("Error during file processing " << + m_context->pluginFilePath.getMetaFile()); ThrowMsg(Exceptions::PluginMetafileFailed, "Metafile error"); } @@ -139,20 +134,8 @@ void PluginInstallTask::stepFindPluginLibrary() return; } LogDebug("Plugin installation: step find plugin library"); - DPL::Utils::Path pluginPath = m_context->pluginFilePath; - size_t indexpos = pluginPath.Fullpath().find_last_of('/'); - - if (std::string::npos == indexpos) { - indexpos = 0; - } else { - indexpos += 1; // move after '/' - } - - std::string libName = pluginPath.Fullpath().substr(indexpos); - libName = GlobalConfig::GetPluginPrefix() + libName + - GlobalConfig::GetPluginSuffix(); - LogDebug("Plugin .so: " << libName); - m_pluginInfo.m_libraryName = libName; + LogDebug("Plugin .so: " << m_context->pluginFilePath.getLibraryName()); + m_pluginInfo.m_libraryName = m_context->pluginFilePath.getLibraryName(); } void PluginInstallTask::stepCheckIfAlreadyInstalled() @@ -171,21 +154,18 @@ void PluginInstallTask::stepLoadPluginLibrary() DISABLE_IF_PLUGIN_WITHOUT_LIB() - DPL::Utils::Path filename = m_context->pluginFilePath; - filename /= m_pluginInfo.m_libraryName; - - LogDebug("Loading plugin: " << filename.Filename()); + LogDebug("Loading plugin: " << m_context->pluginFilePath.getLibraryName()); - fprintf(stderr, " - Try to dlopen() : [%s] ", filename.Fullpath().c_str()); + fprintf(stderr, " - Try to dlopen() : [%s] ", m_context->pluginFilePath.getLibraryPath().Fullpath().c_str()); - void *dlHandle = dlopen(filename.Fullpath().c_str(), RTLD_LAZY); + void *dlHandle = dlopen( m_context->pluginFilePath.getLibraryPath().Fullpath().c_str(), RTLD_LAZY); if (dlHandle == NULL) { const char* error = (const char*)dlerror(); fprintf(stderr, "-> Failed!\n %s\n", (error != NULL ? error : "unknown")); LogError( - "Failed to load plugin: " << filename.Filename() << + "Failed to load plugin: " << m_context->pluginFilePath.getLibraryName() << ". Reason: " << (error != NULL ? error : "unknown")); ThrowMsg(Exceptions::PluginLibraryError, "Library error"); } @@ -209,7 +189,7 @@ void PluginInstallTask::stepLoadPluginLibrary() if (rawEntityList == NULL) { dlclose(dlHandle); - LogError("Failed to read class name" << filename.Filename()); + LogError("Failed to read class name" << m_context->pluginFilePath.getLibraryName()); ThrowMsg(Exceptions::PluginLibraryError, "Library error"); } @@ -220,7 +200,7 @@ void PluginInstallTask::stepLoadPluginLibrary() if (NULL == onWidgetInitProc) { dlclose(dlHandle); - LogError("Failed to read onWidgetInit symbol" << filename.Filename()); + LogError("Failed to read onWidgetInit symbol" << m_context->pluginFilePath.getLibraryName()); ThrowMsg(Exceptions::PluginLibraryError, "Library error"); } @@ -272,7 +252,9 @@ void PluginInstallTask::stepLoadPluginLibrary() const js_entity_definition_t *rawEntityListIterator = rawEntityList; LogDebug("#####"); - LogDebug("##### Plugin: " << filename.Filename() << " supports new plugin API"); + LogDebug("##### Plugin: " + << m_context->pluginFilePath.getLibraryName() + << " supports new plugin API"); LogDebug("#####"); while (rawEntityListIterator->parent_name != NULL && @@ -317,7 +299,7 @@ void PluginInstallTask::stepRegisterFeatures() FOREACH(it, m_pluginInfo.m_featureContainer) { - LogError("PluginHandle: " << m_pluginHandle); + LogDebug("PluginHandle: " << m_pluginHandle); FeatureDAO::RegisterFeature(*it, m_pluginHandle); } SET_PLUGIN_INSTALL_PROGRESS(REGISTER_FEATURES, "Features registered"); diff --git a/src/jobs/plugin_install/plugin_installer_context.h b/src/jobs/plugin_install/plugin_installer_context.h index fbf2db5..1efd504 100644 --- a/src/jobs/plugin_install/plugin_installer_context.h +++ b/src/jobs/plugin_install/plugin_installer_context.h @@ -24,7 +24,7 @@ #include #include -#include +#include //#include using namespace WrtDB; @@ -51,7 +51,9 @@ struct PluginInstallerContext PLUGIN_INSTALL_END }; - DPL::Utils::Path pluginFilePath; ///< plugin directory + PluginPath pluginFilePath; ///< plugin directory + PluginPath metaFilePath; + bool m_dataFromConfigXML; WrtDB::DbPluginHandle pluginHandle; // if this value is true the plugin model may be created // if not plugin installation has failed from some reason @@ -60,5 +62,4 @@ struct PluginInstallerContext //used to set installation progress Jobs::PluginInstall::JobPluginInstall* installerTask; }; - #endif // WRT_SRC_INSTALLERCORE_PLUGININSTALLERTASKS_PLUGININSTALLERCONTEXT_H_ diff --git a/src/jobs/plugin_install/plugin_metafile_reader.cpp b/src/jobs/plugin_install/plugin_metafile_reader.cpp index b65c2e3..c7df516 100644 --- a/src/jobs/plugin_install/plugin_metafile_reader.cpp +++ b/src/jobs/plugin_install/plugin_metafile_reader.cpp @@ -21,6 +21,7 @@ */ #include "plugin_metafile_reader.h" +#include using namespace WrtDB; @@ -56,6 +57,19 @@ PluginMetafileReader::PluginMetafileReader() : m_parserSchema(this) &PluginMetafileReader::tokenEndDeviceCapability); } +void PluginMetafileReader::initialize(const PluginPath &filename) +{ + m_parserSchema.initialize(filename.Fullpath(), + true, + ValidationCore::SaxReader::VALIDATION_DTD, + std::string()); +} + +void PluginMetafileReader::read(WrtDB::PluginMetafileData &data) +{ + m_parserSchema.read(data); +} + void PluginMetafileReader::blankFunction(PluginMetafileData & /* data */) {} diff --git a/src/jobs/plugin_install/plugin_metafile_reader.h b/src/jobs/plugin_install/plugin_metafile_reader.h index 6a7734f..a3a3068 100644 --- a/src/jobs/plugin_install/plugin_metafile_reader.h +++ b/src/jobs/plugin_install/plugin_metafile_reader.h @@ -24,26 +24,18 @@ #define WRT_SRC_INSTALLER_CORE_PLUGIN_INSTALLER_TASKS_PLUGIN_METAFILE_READER_H_ #include -#include #include +class PluginPath; + class PluginMetafileReader { public: PluginMetafileReader(); - void initialize(const DPL::Utils::Path &filename) - { - m_parserSchema.initialize(filename.Fullpath(), - true, - ValidationCore::SaxReader::VALIDATION_DTD, - std::string()); - } - - void read(WrtDB::PluginMetafileData &data) - { - m_parserSchema.read(data); - } + void initialize(const PluginPath &filename); + + void read(WrtDB::PluginMetafileData &data); private: void blankFunction(WrtDB::PluginMetafileData &data); diff --git a/src/logic/installer_logic.cpp b/src/logic/installer_logic.cpp index a151125..a7927ce 100644 --- a/src/logic/installer_logic.cpp +++ b/src/logic/installer_logic.cpp @@ -106,7 +106,7 @@ Jobs::JobHandle InstallerLogic::UninstallWidget( } Jobs::JobHandle InstallerLogic::InstallPlugin( - std::string const & pluginPath, + std::string const & pluginPath, // TODO change type to PluginPath const PluginInstallerStruct & installerStruct) { @@ -118,9 +118,9 @@ Jobs::JobHandle InstallerLogic::InstallPlugin( LogDebug("New Plugin Installation"); - //Conversion to DPL::Utils::Path is temporary + // TODO Conversion to PluginPath is temporary m_job = - new Jobs::PluginInstall::JobPluginInstall(DPL::Utils::Path(pluginPath), installerStruct); + new Jobs::PluginInstall::JobPluginInstall(PluginPath(pluginPath), installerStruct); // before start install plugin, reset plugin data which is stopped // during installing. (PluginDAO::INSTALLATION_IN_PROGRESS) diff --git a/src/misc/plugin_path.cpp b/src/misc/plugin_path.cpp new file mode 100644 index 0000000..2b2ebdb --- /dev/null +++ b/src/misc/plugin_path.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ +/** + * @file plugin_path_builder.cpp + * @author Kamil Nować (k.nowac@partner.samgsung.com) + * @version + * @brief + */ + +#include +#include +#include + +using namespace DPL::Utils; + +PluginPath::PluginPath(const Path& fullPath) : Path(fullPath.Fullpath()) +{ + setLibraryCombinedName( + WrtDB::GlobalConfig::GetPluginPrefix(), + WrtDB::GlobalConfig::GetPluginSuffix()); +}; +PluginPath::PluginPath(const std::string& fullPath) : Path(fullPath) +{ + setLibraryCombinedName( + WrtDB::GlobalConfig::GetPluginPrefix(), + WrtDB::GlobalConfig::GetPluginSuffix()); +}; +PluginPath::PluginPath(const DPL::String& fullPath) : Path(fullPath) +{ + setLibraryCombinedName( + WrtDB::GlobalConfig::GetPluginPrefix(), + WrtDB::GlobalConfig::GetPluginSuffix()); +}; +PluginPath::PluginPath(){} + +PluginPath PluginPath::getMetaFile() const +{ + PluginPath metaFile = *this; + return metaFile /= WrtDB::GlobalConfig::GetPluginMetafileName(); +} \ No newline at end of file diff --git a/src/misc/plugin_path.h b/src/misc/plugin_path.h new file mode 100644 index 0000000..8ada790 --- /dev/null +++ b/src/misc/plugin_path.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ +/** + * @file plugin_path_builder.cpp + * @author Kamil Nować (k.nowac@partner.samgsung.com) + * @version + * @brief + */ + +#ifndef PLUGIN_PATH_H +#define PLUGIN_PATH_H + +#include +#include +#include + +class PluginPath: public DPL::Utils::Path{ +private: + std::string m_library; + +public: + PluginPath(const DPL::Utils::Path& fullPath); + PluginPath(const std::string& fullPath); + PluginPath(const DPL::String& fullPath); + PluginPath(); + + //getMetafile() this function adds metafile to current path. + PluginPath getMetaFile() const; + + //setLibraryCombinedName This function creates name for library by adding + //prefix and suffix to PluginPath object filename. + void setLibraryCombinedName(const std::string& prefix, const std::string& sufix) + { + this->m_library = prefix + this->Filename() + sufix; + } + + //getLibraryName returns library name + const std::string& getLibraryName() const + { + return m_library; + } + //getLibraryPath returns full path to the library + const PluginPath getLibraryPath() const + { + return this->operator /(m_library); + } +}; + +#endif // PLUGIN_PATH_H