Implement dependency, description fillup functions
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 11 May 2021 06:50:21 +0000 (15:50 +0900)
committer연정현/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <jungh.yeon@samsung.com>
Wed, 12 May 2021 07:12:49 +0000 (16:12 +0900)
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/rpk/step/configuration/step_parse_rpk_manifest.cc
src/rpk/step/configuration/step_parse_rpk_manifest.h

index ac0e35e..6131ccd 100644 (file)
@@ -5,9 +5,14 @@
 #include "step/configuration/step_parse_rpk_manifest.h"
 
 #include <pkgmgr-info.h>
+#include <pkgmgr_parser.h>
 
-#include <rpk_manifest_handlers/package_handler.h>
 #include <rpk_manifest_handlers/allowed_package_handler.h>
+#include <rpk_manifest_handlers/author_handler.h>
+#include <rpk_manifest_handlers/description_handler.h>
+#include <rpk_manifest_handlers/dependencies_handler.h>
+#include <rpk_manifest_handlers/package_handler.h>
+
 
 #include <common/installer_context.h>
 #include <common/step/step.h>
@@ -24,6 +29,11 @@ const char kManifestKey[] = "manifest";
 
 const char kAllowedPackageKey[] = "manifest.allowed-package";
 
+const char kAuthorKey[] = "manifest.author";
+
+const char kDescriptionKey[] = "manifest.description";
+
+const char kDependenciesKey[] = "manifest.dependencies";
 
 }  // namespace
 
@@ -90,6 +100,7 @@ common_installer::Step::Status StepParseRpkManifest::process() {
                <<  parser_->GetErrorMessage();
     return Step::Status::PARSE_ERROR;
   }
+
 /*
   // TODO: add this code when recovery logic has added
   // write pkgid for recovery file
@@ -98,6 +109,7 @@ common_installer::Step::Status StepParseRpkManifest::process() {
     context_->recovery_info.get().recovery_file->WriteAndCommitFileContent();
   }
 */
+
   LOG(INFO) << "Parsed package id: " << info->package();
 
   switch (store_location_) {
@@ -188,16 +200,13 @@ bool StepParseRpkManifest::FillManifestX(manifest_x* manifest) {
   if (!FillAllowedPackageInfo(manifest))
     return false;
 
-  // author
-  if (!FillAuthor(manifest))
+  if (!FillAuthorInfo(manifest))
     return false;
 
-  // description
-  if (!FillDescription(manifest))
+  if (!FillDescriptionInfo(manifest))
     return false;
 
-  // dependencies
-  if (!FillDependencies(manifest))
+  if (!FillDependencyInfo(manifest))
     return false;
 
   return true;
@@ -238,6 +247,7 @@ bool StepParseRpkManifest::FillAllowedPackageInfo(manifest_x* manifest) {
   auto& allowed_pkg_list = allowed_pkg_info_list->allowed_packages();
   if (allowed_pkg_list.size() == 0)
     return true;
+
 /*
   // TODO: this should be activated after manifest has variables for these
   for (auto& allowed_pkg : allowed_pkg_list) {
@@ -250,16 +260,71 @@ bool StepParseRpkManifest::FillAllowedPackageInfo(manifest_x* manifest) {
   return true;
 }
 
-bool StepParseRpkManifest::FillAuthor(manifest_x* manifest) {
+bool StepParseRpkManifest::FillAuthorInfo(manifest_x* manifest) {
+  std::shared_ptr<const rpk::parse::AuthorInfo> author_info =
+      std::static_pointer_cast<const rpk::parse::AuthorInfo>(
+          parser_->GetManifestData(kAuthorKey));
+  if (!author_info)
+    return true;
+
+  author_x* author = reinterpret_cast<author_x*>(calloc(1, sizeof(author_x)));
+  if (!author) {
+    LOG(ERROR) << "Out of memory";
+    return false;
+  }
+  author->text = strdup(author_info->name().c_str());
+  author->email = strdup(author_info->email().c_str());
+  author->href = strdup(author_info->href().c_str());
+  author->lang = strdup(DEFAULT_LOCALE);
+  manifest->author = g_list_append(manifest->author, author);
+
   return true;
 }
 
-bool StepParseRpkManifest::FillDescription(manifest_x* manifest) {
+bool StepParseRpkManifest::FillDescriptionInfo(manifest_x* manifest) {
+  std::shared_ptr<const rpk::parse::DescriptionInfoList> description_info =
+      std::static_pointer_cast<const rpk::parse::DescriptionInfoList>(
+          parser_->GetManifestData(kDescriptionKey));
+  if (!description_info)
+    return true;
+
+  for (auto& desc : description_info->descriptions) {
+    description_x* description = reinterpret_cast<description_x*>
+        (calloc(1, sizeof(description_x)));
+    if (!description) {
+      LOG(ERROR) << "Out of memory";
+      return false;
+    }
+    description->text = strdup(desc.description().c_str());
+    description->lang = !desc.xml_lang().empty() ?
+        strdup(desc.xml_lang().c_str()) : strdup(DEFAULT_LOCALE);
+    manifest->description = g_list_append(manifest->description, description);
+  }
+
   return true;
 }
 
-  // dependencies
-bool StepParseRpkManifest::FillDependencies(manifest_x* manifest) {
+bool StepParseRpkManifest::FillDependencyInfo(manifest_x* manifest) {
+  std::shared_ptr<const rpk::parse::DependenciesInfo> dependencies_info =
+      std::static_pointer_cast<const rpk::parse::DependenciesInfo>(
+          parser_->GetManifestData(kDependenciesKey));
+  if (!dependencies_info)
+    return true;
+
+  for (const auto& dependency : dependencies_info->dependencies()) {
+    dependency_x* dep =
+        static_cast<dependency_x*>(calloc(1, sizeof(dependency_x)));
+    if (!dep) {
+      LOG(ERROR) << "Out of memory";
+      return false;
+    }
+    dep->depends_on = strdup(dependency.pkgid().c_str());
+    dep->type = strdup(dependency.type().c_str());
+    if (!dependency.required_version().empty())
+      dep->required_version = strdup(dependency.required_version().c_str());
+    manifest->dependencies = g_list_append(manifest->dependencies, dep);
+  }
+
   return true;
 }
 
index 6976372..cd5b124 100644 (file)
@@ -50,9 +50,9 @@ class StepParseRpkManifest : public common_installer::Step {
   bool FillManifestX(manifest_x* manifest);
   bool FillPackageInfo(manifest_x* manifest);
   bool FillAllowedPackageInfo(manifest_x* manifest);
-  bool FillAuthor(manifest_x* manifest);
-  bool FillDescription(manifest_x* manifest);
-  bool FillDependencies(manifest_x* manifest);
+  bool FillAuthorInfo(manifest_x* manifest);
+  bool FillDescriptionInfo(manifest_x* manifest);
+  bool FillDependencyInfo(manifest_x* manifest);
 
   std::unique_ptr<rpk::parse::RPKConfigParser> parser_;
   ManifestLocation manifest_location_;