Delta info file parser 18/50418/4 accepted/tizen/mobile/20151105.020208 accepted/tizen/tv/20151105.020216 accepted/tizen/wearable/20151105.020225 submit/tizen/20151104.130422
authorTomasz Iwanek <t.iwanek@samsung.com>
Wed, 28 Oct 2015 08:28:38 +0000 (09:28 +0100)
committerPawel Sikorski <p.sikorski@samsung.com>
Wed, 4 Nov 2015 13:02:17 +0000 (05:02 -0800)
Change-Id: Ia2b22ecdc6becdc1435412cdc25edad3ce16b9f0

CMakeLists.txt
packaging/manifest-parser.spec
src/CMakeLists.txt
src/delta/CMakeLists.txt [new file with mode: 0644]
src/delta/delta-manifest-handlers.pc.in [new file with mode: 0644]
src/delta/delta_handler.cc [new file with mode: 0644]
src/delta/delta_handler.h [new file with mode: 0644]
src/delta/delta_parser.cc [new file with mode: 0644]
src/delta/delta_parser.h [new file with mode: 0644]

index d495555..780ed50 100644 (file)
@@ -25,6 +25,7 @@ SET(CMAKE_CXX_FLAGS_CCOV       "-O0 -std=c++11 -g --coverage")
 # Targets
 SET(TARGET_LIBNAME_MANIFEST_HANDLERS "manifest-handlers")
 SET(TARGET_LIBNAME_TPK_MANIFEST_HANDLERS "tpk-manifest-handlers")
+SET(TARGET_LIBNAME_DELTA_MANIFEST_HANDLERS "delta-manifest-handlers")
 SET(TARGET_LIBNAME_PARSER "manifest-parser")
 SET(TARGET_LIBNAME_UTILS "manifest-parser-utils")
 SET(TARGET_EXAMPLES "parser-example")
index e79728c..078fb3b 100644 (file)
@@ -75,6 +75,7 @@ make %{?_smp_mflags}
 %{_libdir}/libmanifest-parser-utils.so*
 %{_libdir}/libmanifest-handlers.so*
 %{_libdir}/libtpk-manifest-handlers.so*
+%{_libdir}/libdelta-manifest-handlers.so*
 %license LICENSE LICENSE-xwalk
 
 %files devel
index f9963f5..0e25727 100644 (file)
@@ -4,3 +4,4 @@ ADD_SUBDIRECTORY(tpk_manifest_handlers)
 ADD_SUBDIRECTORY(unit_tests)
 ADD_SUBDIRECTORY(utils)
 ADD_SUBDIRECTORY(examples)
+ADD_SUBDIRECTORY(delta)
diff --git a/src/delta/CMakeLists.txt b/src/delta/CMakeLists.txt
new file mode 100644 (file)
index 0000000..5b8f0c7
--- /dev/null
@@ -0,0 +1,26 @@
+# Target - sources
+SET(SRCS
+  delta_handler.cc
+  delta_parser.cc
+)
+# Target - definition
+ADD_LIBRARY(${TARGET_LIBNAME_DELTA_MANIFEST_HANDLERS} SHARED ${SRCS})
+# Target - includes
+TARGET_INCLUDE_DIRECTORIES(${TARGET_LIBNAME_DELTA_MANIFEST_HANDLERS} PUBLIC
+                           "${CMAKE_CURRENT_SOURCE_DIR}/../")
+
+# Extra
+SET_TARGET_PROPERTIES(${TARGET_LIBNAME_MANIFEST_HANDLERS} PROPERTIES VERSION ${VERSION})
+SET_TARGET_PROPERTIES(${TARGET_LIBNAME_MANIFEST_HANDLERS} PROPERTIES SOVERSION ${VERSION_MAJOR})
+
+# Install
+INSTALL(TARGETS ${TARGET_LIBNAME_DELTA_MANIFEST_HANDLERS} DESTINATION ${LIB_INSTALL_DIR})
+
+# Install includes
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION ${INCLUDEDIR}
+        FILES_MATCHING PATTERN "*.h")
+
+# Configure and install pkgconfig file
+SET(PKG_FILE delta-manifest-handlers.pc)
+CONFIGURE_FILE(${PKG_FILE}.in ${PKG_FILE} @ONLY)
+INSTALL(FILES ${PKG_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
diff --git a/src/delta/delta-manifest-handlers.pc.in b/src/delta/delta-manifest-handlers.pc.in
new file mode 100644 (file)
index 0000000..c070202
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=@PREFIX@
+exec_prefix=@PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: delta-manifest-handlers
+Description: Delta manifest handlers for manifest parser
+Version: @VERSION@
+Requires: manifest-parser
+Libs: -L${libdir} -ldelta-manifest-handlers
+Cflags: -I${includedir}
diff --git a/src/delta/delta_handler.cc b/src/delta/delta_handler.cc
new file mode 100644 (file)
index 0000000..6617d62
--- /dev/null
@@ -0,0 +1,75 @@
+// 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 "delta/delta_handler.h"
+
+namespace {
+
+const char kAddFilesKey[] = "add-files";
+const char kModifyFilesKey[] = "modify-files";
+const char kRemoveFilesKey[] = "remove-files";
+const char kFileNameKey[] = "@name";
+const char kFileKey[] = "file";
+
+bool GetFilesForKey(const parser::DictionaryValue* dict, const std::string& key,
+                    std::vector<std::string>* files, std::string* error) {
+  for (const auto& item : parser::GetOneOrMany(dict, key, "")) {
+    for (const auto& file : parser::GetOneOrMany(item, kFileKey, "")) {
+      std::string position;
+      if (!file->GetString(kFileNameKey, &position)) {
+        *error = std::string("Malformed tag: ") + key;
+        return false;
+      }
+      files->push_back(position);
+    }
+  }
+  return true;
+}
+
+}  // namespace
+
+namespace delta {
+
+const char kDeltaInfoKey[] = "delta";
+
+bool DeltaHandler::Parse(
+    const parser::Manifest& manifest,
+    std::shared_ptr<parser::ManifestData>* output,
+    std::string* error) {
+  parser::Value* value = nullptr;
+  if (!manifest.Get(kDeltaInfoKey, &value)) {
+    *error = "Cannot find root element <delta>";
+    return false;
+  }
+  const parser::DictionaryValue* dict = nullptr;
+  if (!value->GetAsDictionary(&dict)) {
+    *error = "Root element malformed";
+    return false;
+  }
+  std::shared_ptr<DeltaInfo> delta_info(new DeltaInfo());
+
+  std::vector<std::string> added;
+  if (!GetFilesForKey(dict, kAddFilesKey, &added, error))
+    return false;
+  delta_info->set_added(added);
+
+  std::vector<std::string> modified;
+  if (!GetFilesForKey(dict, kModifyFilesKey, &modified, error))
+    return false;
+  delta_info->set_modified(modified);
+
+  std::vector<std::string> removed;
+  if (!GetFilesForKey(dict, kRemoveFilesKey, &removed, error))
+    return false;
+  delta_info->set_removed(removed);
+
+  *output = std::static_pointer_cast<parser::ManifestData>(delta_info);
+  return true;
+}
+
+std::string DeltaHandler::Key() const {
+  return kDeltaInfoKey;
+}
+
+}  // namespace delta
diff --git a/src/delta/delta_handler.h b/src/delta/delta_handler.h
new file mode 100644 (file)
index 0000000..96e1c7a
--- /dev/null
@@ -0,0 +1,60 @@
+// 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.
+
+#ifndef DELTA_DELTA_HANDLER_H_
+#define DELTA_DELTA_HANDLER_H_
+
+#include <string>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+
+namespace delta {
+
+extern const char kDeltaInfoKey[];
+
+class DeltaInfo : public parser::ManifestData {
+ public:
+  void set_added(const std::vector<std::string>& added) {
+    added_ = added;
+  }
+  const std::vector<std::string>& added() const {
+    return added_;
+  }
+  void set_modified(const std::vector<std::string>& modified) {
+    modified_ = modified;
+  }
+  const std::vector<std::string>& modified() const {
+    return modified_;
+  }
+  void set_removed(const std::vector<std::string>& removed) {
+    removed_ = removed;
+  }
+  const std::vector<std::string>& removed() const {
+    return removed_;
+  }
+
+ private:
+  std::vector<std::string> added_;
+  std::vector<std::string> modified_;
+  std::vector<std::string> removed_;
+};
+
+/**
+ * @brief The DeltaHandler class
+ *
+ * Main handler for all tags in delta file
+ */
+class DeltaHandler : public parser::ManifestHandler {
+ public:
+  bool Parse(
+      const parser::Manifest& manifest,
+      std::shared_ptr<parser::ManifestData>* output,
+      std::string* error) override;
+  std::string Key() const override;
+};
+
+}  // namespace delta
+
+#endif  // DELTA_DELTA_HANDLER_H_
diff --git a/src/delta/delta_parser.cc b/src/delta/delta_parser.cc
new file mode 100644 (file)
index 0000000..66e2c71
--- /dev/null
@@ -0,0 +1,43 @@
+// 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 "delta/delta_parser.h"
+
+#include <vector>
+
+#include "delta/delta_handler.h"
+#include "manifest_parser/manifest_handler.h"
+
+namespace delta {
+
+DeltaParser::DeltaParser() {
+  std::vector<parser::ManifestHandler*> handlers = {
+    new DeltaHandler,
+  };
+
+  std::unique_ptr<parser::ManifestHandlerRegistry> registry(
+      new parser::ManifestHandlerRegistry(handlers));
+
+  parser_.reset(new parser::ManifestParser(std::move(registry)));
+}
+
+std::shared_ptr<const parser::ManifestData> DeltaParser::GetManifestData(
+    const std::string& key) {
+  return parser_->GetManifestData(key);
+}
+
+const std::string& DeltaParser::GetErrorMessage() const {
+  if (!error_.empty())
+    return error_;
+  return parser_->GetErrorMessage();
+}
+
+bool DeltaParser::ParseManifest(const boost::filesystem::path& path) {
+  if (!parser_->ParseManifest(path))
+    return false;
+
+  return true;
+}
+
+}  // namespace delta
diff --git a/src/delta/delta_parser.h b/src/delta/delta_parser.h
new file mode 100644 (file)
index 0000000..1e520b9
--- /dev/null
@@ -0,0 +1,49 @@
+// 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.
+
+#ifndef DELTA_DELTA_PARSER_H_
+#define DELTA_DELTA_PARSER_H_
+
+#include <boost/filesystem/path.hpp>
+
+#include <memory>
+#include <string>
+
+#include "manifest_parser/manifest_parser.h"
+
+namespace delta {
+
+/**
+ * @brief The DeltaParser class
+ *        Parser class of delta info file.
+ *
+ * Instance of this class may be used to parse delta file.
+ * Depending on boolean result of @ref ParseManifest method, client code may
+ * call:
+ *  - on success -> @ref GetManifestData(), passing the key of ManifestData
+ *                  instance that it is interested in.
+ *  - on failure -> @ref GetErrorMessage(), to get value of error which was set
+ *                  during the processing of config.xml
+ *
+ * To investigate which key do you need to get certain parsed piece of data,
+ * check the key reported by handler's @ref ManifestHandler::Key() method.
+ * Key returned by this method is the key to access data set by handler.
+ */
+class DeltaParser {
+ public:
+  DeltaParser();
+
+  std::shared_ptr<const parser::ManifestData> GetManifestData(
+      const std::string& key);
+  const std::string& GetErrorMessage() const;
+  bool ParseManifest(const boost::filesystem::path& path);
+
+ private:
+  std::unique_ptr<parser::ManifestParser> parser_;
+  std::string error_;
+};
+
+}  // namespace delta
+
+#endif  // DELTA_DELTA_PARSER_H_