Remove unused xml_parser 87/48987/2
authorTomasz Iwanek <t.iwanek@samsung.com>
Fri, 2 Oct 2015 13:13:08 +0000 (15:13 +0200)
committerPawel Sikorski <p.sikorski@samsung.com>
Mon, 5 Oct 2015 11:13:44 +0000 (04:13 -0700)
It was replaced by tpk manifest handlers.

Change-Id: Ic9d56952b8ed4206eb659ab5ff4c08e658d008bc

src/tpk/CMakeLists.txt
src/tpk/tpk_app_query_interface.cc
src/tpk/xml_parser/xml_parser.cc [deleted file]
src/tpk/xml_parser/xml_parser.h [deleted file]
src/unit_tests/CMakeLists.txt
src/unit_tests/xml_parser_unittest.cc [deleted file]

index 99697f1..461b310 100644 (file)
@@ -4,7 +4,6 @@ SET(SRCS
     step/step_parse_recovery.cc
     tpk_app_query_interface.cc
     tpk_installer.cc
-    xml_parser/xml_parser.cc
 )
 ADD_LIBRARY(${TARGET_LIBNAME_TPK} STATIC ${SRCS})
 ADD_EXECUTABLE(${TARGET_TPK_BACKEND} "tpk_backend.cc")
index 6a06b13..f5dbbc7 100644 (file)
@@ -10,6 +10,9 @@
 #include <boost/filesystem/operations.hpp>
 #include <boost/filesystem/path.hpp>
 #include <boost/system/error_code.hpp>
+#include <tpk_manifest_handlers/application_manifest_constants.h>
+#include <tpk_manifest_handlers/package_handler.h>
+#include <tpk_manifest_handlers/tpk_config_parser.h>
 
 #include <memory>
 #include <string>
 #include "common/request.h"
 #include "common/utils/file_util.h"
 #include "common/utils/logging.h"
-#include "tpk/xml_parser/xml_parser.h"
 
 namespace bf = boost::filesystem;
 namespace bs = boost::system;
 namespace ci = common_installer;
-namespace xp = xml_parser;
 
 namespace {
 
@@ -58,19 +59,15 @@ std::string GetPkgIdFromPath(const std::string& path) {
     bf::remove_all(tmp_path, code);
     return {};
   }
-  xp::XmlParser parser;
-  std::unique_ptr<xp::XmlTree> tree(parser.ParseAndGetNewTree(
-      manifest_path.c_str()));
-  if (!tree) {
-    bf::remove_all(tmp_path, code);
+
+  tpk::parse::TPKConfigParser parser;
+  if (!parser.ParseManifest(manifest_path))
     return {};
-  }
-  xp::XmlElement* manifest = tree->GetRootElement();
-  if (!manifest) {
-    bf::remove_all(tmp_path, code);
+  auto package_info = std::static_pointer_cast<const tpk::parse::PackageInfo>(
+      parser.GetManifestData(tpk::manifest_keys::kManifestKey));
+  if (!package_info)
     return {};
-  }
-  std::string pkg_id = manifest->attr("package");
+  std::string pkg_id = package_info->package();
   bf::remove_all(tmp_path, code);
   return pkg_id;
 }
diff --git a/src/tpk/xml_parser/xml_parser.cc b/src/tpk/xml_parser/xml_parser.cc
deleted file mode 100644 (file)
index 1c70a4a..0000000
+++ /dev/null
@@ -1,168 +0,0 @@
-/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */
-
-#include "tpk/xml_parser/xml_parser.h"
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <libxml/xmlstring.h>
-#include <iostream>
-#include <map>
-#include <string>
-#include <utility>
-#include <vector>
-
-using std::map;
-using std::string;
-using std::vector;
-
-namespace xml_parser {
-
-namespace {  // static namespace
-
-string xmlChar2string(const xmlChar *str) {
-  return string(const_cast<char*>(reinterpret_cast<const char*>(str)));
-}
-
-}  // namespace
-
-
-// class XmlElement
-XmlElement::XmlElement(xmlNode *node) {
-  name_ = xmlChar2string(node->name);
-  xmlChar* content = xmlNodeGetContent(node);  // NOTE: Needs to be freed
-  content_ = xmlChar2string(content);
-  xmlFree(content);
-  SetAttrMap(node);
-  node_ = node;
-}
-
-XmlElement::~XmlElement() {
-  attr_map_.clear();
-}
-
-const string& XmlElement::attr(const string& attrName) {
-  map<string, string>::iterator it = attr_map_.find(attrName);
-  if (it != attr_map_.end()) {
-    return it->second;
-  }
-  return XmlElement::null_string();
-}
-
-void XmlElement::SetAttrMap(xmlNode* node) {
-  xmlAttr* attr;
-
-  for (attr=node->properties; attr != nullptr; attr=attr->next) {
-    const xmlChar* name = attr->name;
-    xmlChar* value = xmlGetProp(node, name);  // NOTE: Needs to be freed
-
-    attr_map_.insert(map<string, string>::value_type(
-          xmlChar2string(name), xmlChar2string(value)));
-
-    xmlFree(value);
-  }
-}
-
-const string& XmlElement::null_string() {
-  // NOTE: check-coding-rule says that const/static string is to be changed to
-  // const char[], but here we need a string object reference, instead of
-  // C-style const char.
-  static const string nullstr = string("");
-  return nullstr;
-}
-
-
-// class XmlTree
-XmlTree::XmlTree(xmlDoc* doc) : root_(nullptr), doc_(doc) {
-}
-
-XmlTree::~XmlTree() {
-  xmlFreeDoc(doc_);
-
-  // Clear element_map_
-  for (auto& it : elements_map_) {
-    delete it.second;
-  }
-  elements_map_.clear();
-}
-
-void XmlTree::StoreElement(xmlNode* node, XmlElement *el) {
-  elements_map_.insert(std::pair<xmlNode*, XmlElement*>(node, el));
-}
-
-XmlElement* XmlTree::FindElement(xmlNode* node) {
-  map<xmlNode*, XmlElement*>::iterator it = elements_map_.find(node);
-  if (it != elements_map_.end()) {
-    return it->second;
-  }
-  return nullptr;
-}
-
-XmlElement* XmlTree::GetRootElement() {
-  if (root_) return root_;
-
-  xmlNode* root_node = xmlDocGetRootElement(doc_);
-  if (root_node == nullptr) {
-    return nullptr;
-  }
-
-  // Get information of the node
-  XmlElement* root = new XmlElement(root_node);
-  StoreElement(root_node, root);
-  root_ = root;
-
-  return root_;
-}
-
-vector<XmlElement*> XmlTree::Children(
-    XmlElement* parent,
-    const std::string& name) {
-  xmlNode* child;
-  XmlElement *el;
-  vector<XmlElement*> children;
-
-  for (child = xmlFirstElementChild(parent->node());
-      nullptr != child;
-      child = xmlNextElementSibling(child)) {
-    if (name == xmlChar2string(child->name)) {
-      // Found a matched node
-      // Search map
-      el = FindElement(child);
-      if (!el) {  // Not in elements_map_
-        el = new XmlElement(child);
-        StoreElement(child, el);
-      }
-      // Add to children
-      children.push_back(el);
-    }
-  }
-  return children;
-}
-
-
-
-// class XmlParser
-XmlParser::XmlParser() {
-}
-
-XmlParser::~XmlParser() {
-  // NOTE: These libxml2 cleanup funcs must be called after all libxml2 funcs
-  // are compelte.
-
-  // xmlCleanupParser();
-  // xmlMemoryDump();
-}
-
-XmlTree* XmlParser::ParseAndGetNewTree(const char* xmlFilePath) {
-  LIBXML_TEST_VERSION
-
-  XmlTree* t = nullptr;
-  xmlDocPtr doc = xmlReadFile(xmlFilePath, nullptr, 0);
-  if (doc) {
-    t = new XmlTree(doc);
-  } else {
-    // TODO(youmin.ha@samsung.com): Error log
-  }
-  return t;
-  // NOTE: doc will be freed by XmlTree.
-}
-
-}  // namespace xml_parser
diff --git a/src/tpk/xml_parser/xml_parser.h b/src/tpk/xml_parser/xml_parser.h
deleted file mode 100644 (file)
index 54612cf..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/* Copyright 2015 Samsung Electronics, license APACHE-2.0, see LICENSE file */
-#ifndef TPK_XML_PARSER_XML_PARSER_H_
-#define TPK_XML_PARSER_XML_PARSER_H_
-
-#include <libxml/tree.h>
-#include <map>
-#include <string>
-#include <vector>
-
-namespace xml_parser {
-
-class XmlElement {
- public:
-  static const std::string& null_string();
-
-  explicit XmlElement(xmlNode *node);
-  ~XmlElement();
-  const std::string& name() { return name_; }
-  const std::string& content() { return content_; }
-  const std::string& attr(const std::string& attrName);
-  xmlNode* node() { return node_; }
-
- private:
-  void SetAttrMap(xmlNode* node);
-
-  std::string name_;
-  std::string content_;
-  std::map<std::string, std::string> attr_map_;
-  xmlNode* node_;
-};
-
-class XmlTree {
- public:
-  explicit XmlTree(xmlDoc* doc);
-  ~XmlTree();
-
-  // Note: Each XmlElement* is available when the XmlTree object is valid.
-  XmlElement* GetRootElement();
-  std::vector<XmlElement*> Children(XmlElement* parent,
-      const std::string& name = "");
-
- private:
-  void StoreElement(xmlNode* node, XmlElement *el);
-  XmlElement* FindElement(xmlNode* node);
-
-  std::map<xmlNode*, XmlElement*> elements_map_;
-  XmlElement* root_;
-  xmlDoc* doc_;
-};
-
-
-class XmlParser {
- public:
-  XmlParser();
-  ~XmlParser();
-  XmlTree* ParseAndGetNewTree(const char* xmlFilePath = "");
-};
-
-}  // namespace xml_parser
-
-#endif  // TPK_XML_PARSER_XML_PARSER_H_
index afe7da0..588c87d 100644 (file)
@@ -1,6 +1,5 @@
 SET(TESTS
   signature_unittest
-  xml_parser_unittest
   smoke_test
 )
 SET(DESTINATION_DIR app-installers-ut)
@@ -11,10 +10,6 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../)
 ADD_EXECUTABLE(signature_unittest
   signature_unittest.cc
 )
-ADD_EXECUTABLE(xml_parser_unittest
-  xml_parser_unittest.cc
-  ../tpk/xml_parser/xml_parser.cc
-)
 ADD_EXECUTABLE(smoke_test
   smoke_test.cc
 )
@@ -25,7 +20,6 @@ INSTALL(FILES run-unit-tests.sh DESTINATION ${BINDIR}/app-installers-ut/
 
 FOREACH(test ${TESTS})
 APPLY_PKG_CONFIG(${test} PUBLIC
-  LIBXML_DEPS
   Boost
   GTEST
 )
@@ -35,7 +29,6 @@ ENDFOREACH(test)
 # GTest main libraries is still missing, so additional linking of
 # GTEST_MAIN_LIBRARIES is needed.
 target_link_libraries(signature_unittest PUBLIC ${TARGET_LIBNAME_COMMON} ${GTEST_MAIN_LIBRARIES})
-target_link_libraries(xml_parser_unittest PUBLIC ${TARGET_LIBNAME_PARSER} ${GTEST_MAIN_LIBRARIES})
 target_link_libraries(smoke_test PRIVATE ${TARGET_LIBNAME_WGT} ${TARGET_LIBNAME_TPK})
 
 FOREACH(test ${TESTS})
diff --git a/src/unit_tests/xml_parser_unittest.cc b/src/unit_tests/xml_parser_unittest.cc
deleted file mode 100644 (file)
index 642be04..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by an apache 2.0 license that can be
-// found in the LICENSE file.
-
-#include <gtest/gtest.h>
-#include <boost/filesystem/path.hpp>
-#include <iostream>
-#include <memory>
-#include "tpk/xml_parser/xml_parser.h"
-
-namespace {
-
-using std::cout;
-using std::cerr;
-using std::endl;
-using std::unique_ptr;
-using xml_parser::XmlElement;
-using xml_parser::XmlTree;
-using xml_parser::XmlParser;
-
-namespace bf = boost::filesystem;
-
-class TestXmlParser : public testing::Test {
-};
-
-// Tests manifest parser with proper manifest
-TEST_F(TestXmlParser, ReadManifestXml) {
-  const char* filename =
-      "/usr/share/app-installers-ut/test_samples/tpk-sample-manifest.xml";
-  XmlParser p;
-
-  unique_ptr<XmlTree> t(p.ParseAndGetNewTree(filename));
-  ASSERT_NE(t, nullptr);
-
-  XmlElement* root = t->GetRootElement();
-  ASSERT_EQ(root->name(), "manifest");
-  ASSERT_EQ(root->attr("api-version"), "2.3");
-
-  XmlElement* ui_application = t->Children(root, "ui-application")[0];
-  ASSERT_EQ(ui_application->attr("appid"), "org.tizen.testapp");
-
-  XmlElement* app_control0 = t->Children(ui_application, "app-control")[0];
-  XmlElement* operation = t->Children(app_control0, "operation")[0];
-  ASSERT_EQ(operation->attr("name"),
-      "http://tizen.org/appcontrol/operation/edit");
-
-  XmlElement* privileges = t->Children(root, "privileges")[0];
-  XmlElement* privilege1 = t->Children(privileges, "privilege")[1];
-  ASSERT_EQ(privilege1->content(),
-      "http://tizen.org/privilege/packagemanager.info");
-
-  XmlElement* feature3 = t->Children(root, "feature")[3];
-  ASSERT_EQ(feature3->attr("name"),
-      "http://tizen.org/feature/camera.front");
-  ASSERT_EQ(feature3->content(), "true");
-
-  // null_string equality test(should be true)
-  ASSERT_EQ(feature3->attr("nonexist_attr"), XmlElement::null_string());
-}
-
-}  // namespace