# 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")
%{_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
ADD_SUBDIRECTORY(unit_tests)
ADD_SUBDIRECTORY(utils)
ADD_SUBDIRECTORY(examples)
+ADD_SUBDIRECTORY(delta)
--- /dev/null
+# 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)
--- /dev/null
+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}
--- /dev/null
+// 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
--- /dev/null
+// 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_
--- /dev/null
+// 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
--- /dev/null
+// 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_