Line data Source code
1 : /*! 2 : * \file esys/repo/loadfolder.cpp 3 : * \brief 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2022 Michel Gillet 9 : * Distributed under the MIT License. 10 : * (See accompanying file LICENSE.txt or 11 : * copy at https://opensource.org/licenses/MIT) 12 : * 13 : * __legal_e__ 14 : * \endcond 15 : * 16 : */ 17 : 18 : #include "esys/repo/esysrepo_prec.h" 19 : #include "esys/repo/loadfolder.h" 20 : #include "esys/repo/manifest/detect.h" 21 : #include "esys/repo/manifest/loader.h" 22 : 23 : namespace esys::repo 24 : { 25 : 26 2 : LoadFolder::LoadFolder(const std::string &folder_path) 27 2 : : m_folder_path(folder_path) 28 : { 29 2 : } 30 : 31 6 : LoadFolder::~LoadFolder() = default; 32 : 33 2 : void LoadFolder::set_folder_path(const std::string &folder_path) 34 : { 35 2 : m_folder_path = folder_path; 36 2 : } 37 : 38 2 : const std::string &LoadFolder::get_folder_path() const 39 : { 40 2 : return m_folder_path; 41 : } 42 : 43 2 : Result LoadFolder::run(const std::string &folder_path) 44 : { 45 2 : if (!folder_path.empty()) set_folder_path(folder_path); 46 : 47 2 : auto detect = std::make_unique<manifest::Detect>(); 48 : 49 2 : detect->set_folder_path(get_folder_path()); 50 2 : Result result = detect->detect(); 51 2 : if (result.error()) return ESYSREPO_RESULT(result); 52 : 53 2 : auto loader = std::make_unique<manifest::Loader>(); 54 3 : if (detect->get_config_folder() != nullptr) 55 : { 56 2 : loader->set_config_folder(detect->get_config_folder()); 57 : } 58 2 : else if (detect->get_config() != nullptr) 59 : { 60 2 : loader->set_config(detect->get_config()); 61 : } 62 : else 63 0 : return ESYSREPO_RESULT(ResultCode::INTERNAL_ERROR); 64 : 65 2 : m_config = loader->get_config(); 66 2 : m_config_folder = loader->get_config_folder(); 67 : 68 2 : result = loader->run(); 69 2 : if (result.error()) return ESYSREPO_RESULT(result); 70 2 : set_manifest(loader->get_manifest()); 71 2 : return ESYSREPO_RESULT(ResultCode::OK); 72 2 : } 73 : 74 0 : std::string LoadFolder::find_repo_path_by_url(const std::string &url) 75 : { 76 0 : if (get_manifest() == nullptr) return ""; 77 : 78 0 : return get_manifest()->find_repo_path_by_url(url); 79 : } 80 : 81 0 : std::shared_ptr<manifest::Repository> LoadFolder::find_repo_by_url(const std::string &url) 82 : { 83 0 : if (get_manifest() == nullptr) return nullptr; 84 : 85 0 : return get_manifest()->find_repo_by_url(url); 86 : } 87 : 88 0 : std::shared_ptr<Config> LoadFolder::get_config() const 89 : { 90 0 : return m_config; 91 : } 92 : 93 0 : std::shared_ptr<ConfigFolder> LoadFolder::get_config_folder() const 94 : { 95 0 : return m_config_folder; 96 : } 97 : 98 2 : std::shared_ptr<Manifest> LoadFolder::get_manifest() const 99 : { 100 2 : return m_manifest; 101 : } 102 : 103 2 : void LoadFolder::set_manifest(std::shared_ptr<Manifest> manifest) 104 : { 105 2 : m_manifest = manifest; 106 2 : } 107 : 108 : } // namespace esys::repo