Remove flag from plugins 66/162166/6
authorJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 29 Nov 2017 09:56:32 +0000 (18:56 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 5 Dec 2017 06:08:16 +0000 (15:08 +0900)
- Flag in plugin list used to identify uniqueness of each plugins
  but name could be identifier of uniqueness.

Change-Id: I77e5701f99622fadb6000f05d1375fd8810a4674
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/plugins/plugin_list_parser.cc
src/common/plugins/plugin_list_parser.h
src/common/plugins/plugins_list.txt.in
src/unit_tests/plugins_unittest.cc
src/unit_tests/test_samples/plugins/invalid_plugin_list.txt
src/unit_tests/test_samples/plugins/test_plugin_list.txt

index 58c4a74..f162ce9 100644 (file)
@@ -9,16 +9,13 @@
 
 namespace common_installer {
 
-PluginInfo::PluginInfo(int flag, const std::string& type,
+PluginInfo::PluginInfo(const std::string& type,
                        const std::string& name,
                        const boost::filesystem::path& path)
-    : flag_(flag),
-      type_(std::move(type)),
+    : type_(std::move(type)),
       name_(std::move(name)),
       path_(std::move(path)) {}
 
-int PluginInfo::flag() const { return flag_; }
-
 const std::string& PluginInfo::type() const { return type_; }
 
 const std::string& PluginInfo::name() const { return name_; }
@@ -35,16 +32,6 @@ bool PluginsListParser::ValidType(const std::string& type) {
   return std::regex_search(type, re_valid);
 }
 
-bool PluginsListParser::ValidFlag(const std::string& flag) {
-  if (flag.empty()) {
-    LOG(ERROR) << "Flag is empty (valid function)";
-    return false;
-  }
-
-  std::regex re_valid(R"(0x[01248]+)");
-  return std::regex_match(flag, re_valid);
-}
-
 bool PluginsListParser::ValidName(const std::string& name) {
   if (name.empty()) {
     LOG(ERROR) << "Name is empty (valid function)";
@@ -89,11 +76,6 @@ std::string PluginsListParser::ExtractRaw(const std::string& data,
   return match[1];
 }
 
-std::string PluginsListParser::ExtractFlag(const std::string& flag) {
-  std::regex re_extract(R"(flag\s*\=\s*\"(.*)\")");
-  return ExtractRaw(flag, re_extract);
-}
-
 std::string PluginsListParser::ExtractName(const std::string& type) {
   std::regex re_extract(R"(name\s*\=\s*\"(.*)\")");
   return ExtractRaw(type, re_extract);
@@ -160,8 +142,6 @@ bool PluginsListParser::ParsePluginsRawData(
     const std::vector<std::string>& lines) {
   plugin_info_list_.clear();
 
-  std::vector<int> flag_container;
-
   for (const std::string& line : lines) {
     std::vector<std::string> parts;
     if (!SplitPluginLine(line, &parts)) {
@@ -169,26 +149,21 @@ bool PluginsListParser::ParsePluginsRawData(
       return false;
     }
 
-    std::string flag = ExtractFlag(parts.at(Flag));
     std::string type = ExtractType(parts.at(Type));
     std::string name = ExtractName(parts.at(Name));
     std::string path = ExtractPath(parts.at(Path));
-
-    if (!ValidFlag(flag)) {
-      LOG(ERROR) << "Invalid flag: " << flag;
+    if (!ValidName(name)) {
+      LOG(ERROR) << "Invalid name: " << name;
       return false;
     }
 
-    const int kConvertStringBase = 16;
-    int _flag = std::strtoul(flag.c_str(), nullptr, kConvertStringBase);
-
-    // flag should be unique
-    if (std::find(flag_container.begin(), flag_container.end(), _flag) !=
-        flag_container.end()) {
-      LOG(ERROR) << "Flag isn't unique, flag:  " << _flag;
+    // name should be unique
+    if (std::find_if(plugin_info_list_.begin(), plugin_info_list_.end(),
+        [&name](std::shared_ptr<PluginInfo>& plugin) {
+          return plugin->name() == name;
+        }) != plugin_info_list_.end()) {
+      LOG(ERROR) << "Name isn't unique, name:  " << name;
       return false;
-    } else {
-      flag_container.push_back(_flag);
     }
 
     if (!ValidType(type)) {
@@ -196,11 +171,6 @@ bool PluginsListParser::ParsePluginsRawData(
       return false;
     }
 
-    if (!ValidName(name)) {
-      LOG(ERROR) << "Invalid name: " << name;
-      return false;
-    }
-
     if (!ValidPath(path)) {
       LOG(ERROR) << "Invalid path: " << path;
       return false;
@@ -209,7 +179,7 @@ bool PluginsListParser::ParsePluginsRawData(
     boost::filesystem::path _path = boost::filesystem::path(path);
 
     plugin_info_list_.push_back(
-        std::make_shared<PluginInfo>(_flag, type, name, _path));
+        std::make_shared<PluginInfo>(type, name, _path));
   }
 
   return true;
@@ -217,7 +187,7 @@ bool PluginsListParser::ParsePluginsRawData(
 
 bool PluginsListParser::SplitPluginLine(const std::string& line,
                                         std::vector<std::string>* parts) {
-  static const char kPartsInLine = 4;
+  static const char kPartsInLine = 3;
 
   std::vector<std::string> _parts;
   boost::algorithm::split(_parts, line, boost::algorithm::is_any_of(";"));
index 949b367..3388da0 100644 (file)
@@ -28,15 +28,13 @@ namespace common_installer {
 /** this class include information about plugin */
 class PluginInfo {
  public:
-  PluginInfo(int flag, const std::string& type, const std::string& name,
+  PluginInfo(const std::string& type, const std::string& name,
              const boost::filesystem::path& path);
-  int flag() const;
   const std::string& type() const;
   const std::string& name() const;
   const boost::filesystem::path& path() const;
 
  private:
-  int flag_;
   std::string type_;
   std::string name_;
   boost::filesystem::path path_;
@@ -53,7 +51,7 @@ class PluginsListParser {
   const PluginList& PluginInfoList() const;
 
  private:
-  enum Column { Flag, Type, Name, Path };
+  enum Column { Type, Name, Path };
 
   bool ReadLinesFromFile(std::vector<std::string>* lines);
   bool ParsePluginsRawData(const std::vector<std::string>& lines);
@@ -61,11 +59,9 @@ class PluginsListParser {
                        std::vector<std::string>* parts);
 
   std::string ExtractRaw(const std::string& data, const std::regex& re_extract);
-  std::string ExtractFlag(const std::string& flag);
   std::string ExtractType(const std::string& type);
   std::string ExtractName(const std::string& name);
   std::string ExtractPath(const std::string& path);
-  bool ValidFlag(const std::string& flag);
   bool ValidType(const std::string& type);
   bool ValidName(const std::string& name);
   bool ValidPath(const std::string& path);
index 01e285f..c62df36 100644 (file)
@@ -1,28 +1,28 @@
-flag="0x00000001";type="tag";name="shortcut-list";path="/etc/package-manager/parserlib/libshortcut-list.so"
-flag="0x00000002";type="tag";name="account";path="/etc/package-manager/parserlib/libaccount.so"
-flag="0x00000004";type="tag";name="notifications";path="/etc/package-manager/parserlib/libnotifications.so"
-flag="0x00000008";type="tag";name="privileges";path="/etc/package-manager/parserlib/libprivileges.so"
-flag="0x00000010";type="tag";name="ime";path="/etc/package-manager/parserlib/libime.so"
-flag="0x00000020";type="category";name="http://tizen.org/category/downloadable_font";path="/etc/package-manager/parserlib/category/libdownloadable_font.so"
-flag="0x00000040";type="metadata";name="http://developer.samsung.com/tizen/metadata/sticker";path="/etc/package-manager/parserlib/metadata/libsticker.so"
-flag="0x00000080";type="metadata";name="http://developer.samsung.com/tizen/metadata/ttsengine";path="/etc/package-manager/parserlib/metadata/libttsengine.so"
-flag="0x00000100";type="metadata";name="http://developer.samsung.com/tizen/metadata/downloadable_filters";path="/etc/package-manager/parserlib/metadata/libdownloadable_filters.so"
-flag="0x00000200";type="metadata";name="http://developer.samsung.com/tizen/metadata/dictionary";path="/etc/package-manager/parserlib/metadata/libdictionary.so"
-flag="0x00000400";type="category";name="http://tizen.org/category/antivirus";path="/etc/package-manager/parserlib/category/libantivirus.so"
-flag="0x00000800";type="metadata";name="http://developer.samsung.com/tizen/metadata/profile";path="/etc/package-manager/parserlib/metadata/libtheme.so"
-flag="0x00001000";type="category";name="http://tizen.org/category/tts";path="/etc/package-manager/parserlib/category/libsamsung_tts.so"
-flag="0x00002000";type="tag";name="livebox";path="/etc/package-manager/parserlib/liblivebox.so"
-flag="0x00004000";type="tag";name="watch-application";path="/etc/package-manager/parserlib/libwatch-application.so"
-flag="0x00008000";type="tag";name="widget-application";path="/etc/package-manager/parserlib/libwidget-application.so"
-flag="0x00010000";type="metadata";name="http://tizen.org/metadata/nfc_cardemulation";path="/usr/etc/package-manager/parserlib/metadata/libcardemulation_plugin.so"
-flag="0x00020000";type="metadata";name="http://developer.samsung.com/tizen/metadata/useese";path="/usr/etc/package-manager/parserlib/metadata/libuseese_plugin.so"
-flag="0x00040000";type="tag";name="app-context";path="/etc/package-manager/parserlib/libapp-context.so"
-flag="0x00080000";type="metadata";name="http://tizen.org/metadata/stt-engine";path="/etc/package-manager/parserlib/metadata/libstt-engine-parser.so"
-flag="0x00100000";type="metadata";name="http://tizen.org/metadata/tts-engine";path="/etc/package-manager/parserlib/metadata/libtts-engine-parser.so"
-flag="0x00200000";type="metadata";name="http://tizen.org/metadata/aliasappid";path="/etc/package-manager/parserlib/metadata/libaul-parser.so"
-flag="0x00400000";type="metadata";name="http://tizen.org/metadata/allowedappid";path="/etc/package-manager/parserlib/metadata/libaul-parser.so"
-flag="0x00800000";type="category";name="http://tizen.org/category/ime";path="/etc/package-manager/parserlib/category/libimeparser.so"
-flag="0x01000000";type="metadata";name="http://tizen.org/metadata/prefer_dotnet_aot";path="/etc/package-manager/parserlib/metadata/libprefer_dotnet_aot_plugin.so"
-flag="0x02000000";type="category";name="http://tizen.org/category/tzdata";path="/etc/package-manager/parserlib/category/libtzdata-update-parser.so"
-flag="0x04000000";type="tag";name="activity";path="/etc/package-manager/parserlib/libactivity-parser.so"
-flag="0x08000000";type="tag";name="upgrade-policy";path="/etc/package-manager/parserlib/libapp-upgrade-parser.so"
+type="tag";name="shortcut-list";path="/etc/package-manager/parserlib/libshortcut-list.so"
+type="tag";name="account";path="/etc/package-manager/parserlib/libaccount.so"
+type="tag";name="notifications";path="/etc/package-manager/parserlib/libnotifications.so"
+type="tag";name="privileges";path="/etc/package-manager/parserlib/libprivileges.so"
+type="tag";name="ime";path="/etc/package-manager/parserlib/libime.so"
+type="category";name="http://tizen.org/category/downloadable_font";path="/etc/package-manager/parserlib/category/libdownloadable_font.so"
+type="metadata";name="http://developer.samsung.com/tizen/metadata/sticker";path="/etc/package-manager/parserlib/metadata/libsticker.so"
+type="metadata";name="http://developer.samsung.com/tizen/metadata/ttsengine";path="/etc/package-manager/parserlib/metadata/libttsengine.so"
+type="metadata";name="http://developer.samsung.com/tizen/metadata/downloadable_filters";path="/etc/package-manager/parserlib/metadata/libdownloadable_filters.so"
+type="metadata";name="http://developer.samsung.com/tizen/metadata/dictionary";path="/etc/package-manager/parserlib/metadata/libdictionary.so"
+type="category";name="http://tizen.org/category/antivirus";path="/etc/package-manager/parserlib/category/libantivirus.so"
+type="metadata";name="http://developer.samsung.com/tizen/metadata/profile";path="/etc/package-manager/parserlib/metadata/libtheme.so"
+type="category";name="http://tizen.org/category/tts";path="/etc/package-manager/parserlib/category/libsamsung_tts.so"
+type="tag";name="livebox";path="/etc/package-manager/parserlib/liblivebox.so"
+type="tag";name="watch-application";path="/etc/package-manager/parserlib/libwatch-application.so"
+type="tag";name="widget-application";path="/etc/package-manager/parserlib/libwidget-application.so"
+type="metadata";name="http://tizen.org/metadata/nfc_cardemulation";path="/usr/etc/package-manager/parserlib/metadata/libcardemulation_plugin.so"
+type="metadata";name="http://developer.samsung.com/tizen/metadata/useese";path="/usr/etc/package-manager/parserlib/metadata/libuseese_plugin.so"
+type="tag";name="app-context";path="/etc/package-manager/parserlib/libapp-context.so"
+type="metadata";name="http://tizen.org/metadata/stt-engine";path="/etc/package-manager/parserlib/metadata/libstt-engine-parser.so"
+type="metadata";name="http://tizen.org/metadata/tts-engine";path="/etc/package-manager/parserlib/metadata/libtts-engine-parser.so"
+type="metadata";name="http://tizen.org/metadata/aliasappid";path="/etc/package-manager/parserlib/metadata/libaul-parser.so"
+type="metadata";name="http://tizen.org/metadata/allowedappid";path="/etc/package-manager/parserlib/metadata/libaul-parser.so"
+type="category";name="http://tizen.org/category/ime";path="/etc/package-manager/parserlib/category/libimeparser.so"
+type="metadata";name="http://tizen.org/metadata/prefer_dotnet_aot";path="/etc/package-manager/parserlib/metadata/libprefer_dotnet_aot_plugin.so"
+type="category";name="http://tizen.org/category/tzdata";path="/etc/package-manager/parserlib/category/libtzdata-update-parser.so"
+type="tag";name="activity";path="/etc/package-manager/parserlib/libactivity-parser.so"
+type="tag";name="upgrade-policy";path="/etc/package-manager/parserlib/libapp-upgrade-parser.so"
index 87abee7..b02b641 100644 (file)
@@ -112,15 +112,12 @@ TEST_F(PluginTest, PluginsListParser_Valid) {
   ASSERT_TRUE(parser.Parse());
   auto list = parser.PluginInfoList();
   ASSERT_EQ(list.size(), 3);
-  ASSERT_EQ(list[0]->flag(), 1);
   ASSERT_EQ(list[0]->type(), "tag");
   ASSERT_EQ(list[0]->name(), "test");
   ASSERT_EQ(list[0]->path(), kTestTagPlugin.string());
-  ASSERT_EQ(list[1]->flag(), 2);
   ASSERT_EQ(list[1]->type(), "category");
   ASSERT_EQ(list[1]->name(), "http://tizen.org/category/test_category");
   ASSERT_EQ(list[1]->path(), kTestCategoryPlugin.string());
-  ASSERT_EQ(list[2]->flag(), 4);
   ASSERT_EQ(list[2]->type(), "metadata");
   ASSERT_EQ(list[2]->name(),
       "http://developer.samsung.com/tizen/metadata/test_metadata");
@@ -135,18 +132,18 @@ TEST_F(PluginTest, PluginsListParser_Invalid) {
 
 TEST_F(PluginTest, PluginFactory_CreatingPlugins) {
   PluginFactory factory;
-  PluginInfo tag_info(1, "tag", "test", kTestTagPlugin.string());
+  PluginInfo tag_info("tag", "test", kTestTagPlugin.string());
   ASSERT_TRUE(!!factory.CreatePluginByPluginInfo(tag_info));
-  PluginInfo category_info(2, "category", "category",
+  PluginInfo category_info("category", "category",
                            kTestCategoryPlugin.string());
   ASSERT_TRUE(!!factory.CreatePluginByPluginInfo(category_info));
-  PluginInfo metadata_info(3, "metadata", "metadata",
+  PluginInfo metadata_info("metadata", "metadata",
                            kTestMetadataPlugin.string());
   ASSERT_TRUE(!!factory.CreatePluginByPluginInfo(metadata_info));
-  PluginInfo missing_info(1, "tag", "test",
+  PluginInfo missing_info("tag", "test",
                           "/usr/lib/libmynonexistingplugin.so");
   ASSERT_FALSE(!!factory.CreatePluginByPluginInfo(missing_info));
-  PluginInfo new_info(1, "newtype", "test", kTestTagPlugin.string());
+  PluginInfo new_info("newtype", "test", kTestTagPlugin.string());
   ASSERT_FALSE(!!factory.CreatePluginByPluginInfo(new_info));
 }
 
index 513365b..a32d8ee 100644 (file)
@@ -1,3 +1,3 @@
-flag="0x00000001";type="tag";name="test";path="/usr/share/app-installers-ut/test_samples/plugins/libtest-tag-plugin.so"
-flag="0x00000002";type="category";;;;;;name="http://tizen.org/category/test_category";path="/usr/share/app-installers-ut/test_samples/plugins/libtest-category-plugin.so"
-flag="0x00000004";type="metadata";name="http://developer.samsung.com/tizen/metadata/test_metadata";path="/usr/share/app-installers-ut/test_samples/plugins/libtest-metadata-plugin.so"
+type="tag";name="test";path="/usr/share/app-installers-ut/test_samples/plugins/libtest-tag-plugin.so"
+type="category";;;;;;name="http://tizen.org/category/test_category";path="/usr/share/app-installers-ut/test_samples/plugins/libtest-category-plugin.so"
+type="metadata";name="http://developer.samsung.com/tizen/metadata/test_metadata";path="/usr/share/app-installers-ut/test_samples/plugins/libtest-metadata-plugin.so"
index 283cea8..9ac1637 100644 (file)
@@ -1,3 +1,3 @@
-flag="0x00000001";type="tag";name="test";path="/usr/share/app-installers-ut/test_samples/plugins/libtest-tag-plugin.so"
-flag="0x00000002";type="category";name="http://tizen.org/category/test_category";path="/usr/share/app-installers-ut/test_samples/plugins/libtest-category-plugin.so"
-flag="0x00000004";type="metadata";name="http://developer.samsung.com/tizen/metadata/test_metadata";path="/usr/share/app-installers-ut/test_samples/plugins/libtest-metadata-plugin.so"
+type="tag";name="test";path="/usr/share/app-installers-ut/test_samples/plugins/libtest-tag-plugin.so"
+type="category";name="http://tizen.org/category/test_category";path="/usr/share/app-installers-ut/test_samples/plugins/libtest-category-plugin.so"
+type="metadata";name="http://developer.samsung.com/tizen/metadata/test_metadata";path="/usr/share/app-installers-ut/test_samples/plugins/libtest-metadata-plugin.so"