Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / step / configuration / step_parse_manifest.cc
index 39a3341..633c509 100644 (file)
@@ -4,8 +4,6 @@
 
 #include "common/step/configuration/step_parse_manifest.h"
 
-#include <boost/tokenizer.hpp>
-
 #include <pkgmgr/pkgmgr_parser.h>
 #include <pkgmgr-info.h>
 
@@ -31,7 +29,9 @@
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
+#include <filesystem>
 #include <memory>
+#include <regex>
 #include <set>
 #include <type_traits>
 #include <string>
@@ -48,7 +48,7 @@
 #include "common/utils/time_util.h"
 
 namespace app_keys = tpk::application_keys;
-namespace bf = boost::filesystem;
+namespace fs = std::filesystem;
 
 namespace {
 
@@ -102,26 +102,26 @@ Step::Status StepParseManifest::precheck() {
 }
 
 bool StepParseManifest::LocateConfigFile() {
-  boost::filesystem::path manifest;
+  std::filesystem::path manifest;
   switch (manifest_location_) {
     case ManifestLocation::RECOVERY: {
-      bf::path backup_path = common_installer::GetBackupPathForPackagePath(
+      fs::path backup_path = common_installer::GetBackupPathForPackagePath(
           context_->GetPkgPath()) / kManifestFileName;
-      bf::path in_package_path = context_->GetPkgPath() / kManifestFileName;
-      bf::path install_path =
-          bf::path(getUserManifestPath(context_->uid.get(),
+      fs::path in_package_path = context_->GetPkgPath() / kManifestFileName;
+      fs::path install_path =
+          fs::path(getUserManifestPath(context_->uid.get(),
                       context_->is_readonly_package.get()))
-              / bf::path(context_->pkgid.get());
+              / fs::path(context_->pkgid.get());
       install_path += ".xml";
-      bf::path backup_install_path =
+      fs::path backup_install_path =
           common_installer::GetBackupPathForManifestFile(install_path);
-      if (bf::exists(backup_install_path))
+      if (fs::exists(backup_install_path))
         manifest = backup_install_path;
-      else if (bf::exists(backup_path))
+      else if (fs::exists(backup_path))
         manifest = backup_path;
-      else if (bf::exists(install_path))
+      else if (fs::exists(install_path))
         manifest = install_path;
-      else if (bf::exists(in_package_path))
+      else if (fs::exists(in_package_path))
         manifest = in_package_path;
       break;
     }
@@ -133,13 +133,13 @@ bool StepParseManifest::LocateConfigFile() {
         uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
       else
         uid = context_->uid.get();
-      bf::path xml_path =
-          bf::path(getUserManifestPath(uid, is_readonly))
-          / bf::path(context_->pkgid.get());
+      fs::path xml_path =
+          fs::path(getUserManifestPath(uid, is_readonly))
+          / fs::path(context_->pkgid.get());
       xml_path += ".xml";
       context_->xml_path.set(xml_path);
       manifest = context_->xml_path.get();
-      if (!boost::filesystem::exists(manifest)) {
+      if (!std::filesystem::exists(manifest)) {
         /* This routine has added for platform update */
         manifest = context_->unpacked_dir_path.get();
         manifest /= kManifestFileName;
@@ -159,7 +159,7 @@ bool StepParseManifest::LocateConfigFile() {
 
   LOG(DEBUG) << "manifest path: " << manifest;
 
-  if (!boost::filesystem::exists(manifest))
+  if (!std::filesystem::exists(manifest))
     return false;
 
   path_ = manifest;
@@ -374,7 +374,7 @@ bool StepParseManifest::FillPrivileges(manifest_x* manifest) {
     privilege->value = strdup(priv.privilege.c_str());
     privilege->type = strdup(priv.type.c_str());
     if (!priv.license.empty()) {
-      if (bf::path(priv.license).is_absolute())
+      if (fs::path(priv.license).is_absolute())
         privilege->license = strdup(priv.license.c_str());
       else
         privilege->license = strdup((context_->GetPkgPath()
@@ -410,7 +410,7 @@ bool StepParseManifest::FillProvidesAppDefinedPrivileges(
     privilege->value = strdup(priv.privilege.c_str());
     privilege->type = strdup(priv.type.c_str());
     if (!priv.license.empty()) {
-      if (bf::path(priv.license).is_absolute())
+      if (fs::path(priv.license).is_absolute())
         privilege->license = strdup(priv.license.c_str());
       else
         privilege->license = strdup((context_->GetPkgPath()
@@ -478,7 +478,7 @@ bool StepParseManifest::FillWidgetApplication(manifest_x* manifest) {
     else
       widget_app->api_version = strdup(manifest->api_version);
     manifest->application = g_list_append(manifest->application, widget_app);
-    if (bf::path(application.app_info.exec().c_str()).is_absolute())
+    if (fs::path(application.app_info.exec().c_str()).is_absolute())
       widget_app->exec = strdup(application.app_info.exec().c_str());
     else
       widget_app->exec = strdup((context_->root_application_path.get()
@@ -554,7 +554,7 @@ bool StepParseManifest::FillServiceApplication(manifest_x* manifest) {
     else
       service_app->api_version = strdup(manifest->api_version);
     manifest->application = g_list_append(manifest->application, service_app);
-    if (bf::path(application.app_info.exec().c_str()).is_absolute())
+    if (fs::path(application.app_info.exec().c_str()).is_absolute())
       service_app->exec = strdup(application.app_info.exec().c_str());
     else
       service_app->exec = strdup((context_->root_application_path.get()
@@ -657,7 +657,7 @@ bool StepParseManifest::FillUIApplication(manifest_x* manifest) {
     else
       ui_app->api_version = strdup(manifest->api_version);
     manifest->application = g_list_append(manifest->application, ui_app);
-    if (bf::path(application.app_info.exec().c_str()).is_absolute())
+    if (fs::path(application.app_info.exec().c_str()).is_absolute())
       ui_app->exec = strdup(application.app_info.exec().c_str());
     else
       ui_app->exec = strdup((context_->root_application_path.get()
@@ -709,7 +709,7 @@ bool StepParseManifest::FillWatchApplication(manifest_x* manifest) {
     }
     watch_app->appid = strdup(watch_application.app_info.appid().c_str());
 
-    if (bf::path(watch_application.app_info.exec().c_str()).is_absolute())
+    if (fs::path(watch_application.app_info.exec().c_str()).is_absolute())
       watch_app->exec = strdup(watch_application.app_info.exec().c_str());
     else
       watch_app->exec = strdup(
@@ -924,8 +924,8 @@ bool StepParseManifest::FillApplicationIconPaths(application_x* app,
       LOG(ERROR) << "Out of memory";
       return false;
     }
-    bf::path text;
-    if (bf::path(application_icon.path()).is_absolute()) {
+    fs::path text;
+    if (fs::path(application_icon.path()).is_absolute()) {
       text = application_icon.path();
     } else {
       text = context_->root_application_path.get()
@@ -1013,11 +1013,11 @@ void StepParseManifest::AppendSplashScreen(application_x* app,
     LOG(ERROR) << "Out of memory";
     return;
   }
-  if (bf::path(src).is_absolute()) {
+  if (fs::path(src).is_absolute()) {
     splashscreen->src = strdup(src.c_str());
   } else {
-    bf::path full_path = context_->GetPkgPath() / src;
-    splashscreen->src = strdup(full_path.string().c_str());
+    fs::path full_path = context_->GetPkgPath() / src;
+    splashscreen->src = strdup(full_path.c_str());
   }
   if (src.substr(src.find_last_of(".") + 1) == "edj")
     splashscreen->type = strdup("edj");
@@ -1053,7 +1053,7 @@ bool StepParseManifest::FillSplashScreen(application_x* app,
     if (context_->is_readonly_package.get())
       src = splash_screen.src();
     else
-      src = bf::path(context_->root_application_path.get()
+      src = fs::path(context_->root_application_path.get()
         / app->package / "shared" / "res" / splash_screen.src()).string();
 
     AppendSplashScreen(app, src, splash_screen.type(), splash_screen.dpi(),
@@ -1093,12 +1093,9 @@ bool StepParseManifest::FillResControl(application_x* app,
 void StepParseManifest::GetLegacySplashScreenFromMetadata(application_x* app,
     const std::string& key, const std::string& val) {
   std::string operation;
-  if (key.find(kOperationEffectKey) != std::string::npos) {
-    boost::char_separator<char> sep("=");
-    boost::tokenizer<boost::char_separator<char>> tokens(key, sep);
-    auto iter = tokens.begin();
-    iter++;
-    operation = *iter;
+  auto pos = key.find(kOperationEffectKey);
+  if (pos != std::string::npos) {
+    operation = key.substr(pos + 1, key.size());
   } else if (key.find(kLaunchEffectKey) != std::string::npos) {
     operation = std::string("launch-effect");
   } else {
@@ -1106,25 +1103,23 @@ void StepParseManifest::GetLegacySplashScreenFromMetadata(application_x* app,
     return;
   }
 
-  boost::char_separator<char> sep("=|");
-  boost::tokenizer<boost::char_separator<char>> tokens(val, sep);
-  auto iter = tokens.begin();
   std::string portrait_src;
   std::string landscape_src;
   std::string indicatordisplay;
-  while (iter != tokens.end()) {
-    if (!(*iter).compare(kPortraitEffectImageValue)) {
-      iter++;
-      portrait_src = *iter;
-    } else if (!(*iter).compare(kLandscapeEffectImageValue)) {
-      iter++;
-      landscape_src = *iter;
-    } else if (!(*iter).compare(kIndicatorDisplayValue)) {
-      iter++;
-      indicatordisplay = *iter;
-    }
-    iter++;
+
+  std::regex re("[=|]");
+  std::sregex_token_iterator first(val.begin(), val.end(), re, -1);
+  std::sregex_token_iterator last;
+  std::vector<std::string> tokens(first, last);
+  for (const auto t : tokens) {
+    if (t.compare(kPortraitEffectImageValue))
+      portrait_src = t;
+    else if (t.compare(kLandscapeEffectImageValue))
+      landscape_src = t;
+    else if (t.compare(kIndicatorDisplayValue))
+      indicatordisplay = t;
   }
+
   if (!portrait_src.empty())
     AppendSplashScreen(app, portrait_src, {}, {}, kPortraitOrientation,
         indicatordisplay, operation, {});
@@ -1268,7 +1263,7 @@ bool StepParseManifest::FillComponentBasedApplicationInfo(
     app->splash_screen_display =
         strdup(application.app_info.splash_screen_display().c_str());
     manifest->application = g_list_append(manifest->application, app);
-    if (bf::path(application.app_info.exec().c_str()).is_absolute()) {
+    if (fs::path(application.app_info.exec().c_str()).is_absolute()) {
       app->exec = strdup(application.app_info.exec().c_str());
     } else {
       app->exec = strdup((context_->root_application_path.get()
@@ -1348,7 +1343,7 @@ Step::Status StepParseManifest::process() {
   if (!parser_->ParseManifest(path_)) {
     if (manifest_location_ == ManifestLocation::RECOVERY) {
       LOG(DEBUG) << "Manifest for recovery is invalid";
-      bf::remove(path_);
+      fs::remove(path_);
       return Step::Status::OK;
     }
     LOG(ERROR) << "[Parse] Parse failed. " <<  parser_->GetErrorMessage();