Line data Source code
1 : /*! 2 : * \file esys/repo/manifest/repository_manifest.cpp 3 : * \brief 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2020-2021 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/manifest/repository.h" 20 : #include "esys/repo/manifest/group.h" 21 : #include "esys/repo/manifest/location.h" 22 : 23 : #include <boost/filesystem.hpp> 24 : 25 : namespace esys::repo::manifest 26 : { 27 : 28 786 : Repository::Repository() = default; 29 : 30 74 : Repository::Repository(const std::string &name, const std::string &path) 31 74 : : m_name(name) 32 74 : , m_path(path) 33 : { 34 74 : } 35 : 36 860 : Repository::~Repository() = default; 37 : 38 785 : void Repository::set_name(const std::string &name) 39 : { 40 785 : m_name = name; 41 785 : } 42 : 43 1605 : const std::string &Repository::get_name() const 44 : { 45 1605 : return m_name; 46 : } 47 : 48 784 : void Repository::set_path(const std::string &path) 49 : { 50 784 : boost::filesystem::path gen_path = path; 51 : 52 2352 : m_path = gen_path.generic_path().string(); 53 784 : } 54 : 55 3277 : const std::string &Repository::get_path() const 56 : { 57 3277 : return m_path; 58 : } 59 : 60 299 : void Repository::set_revision(const std::string &revision) 61 : { 62 299 : m_revision = revision; 63 299 : } 64 : 65 527 : const std::string &Repository::get_revision() const 66 : { 67 527 : return m_revision; 68 : } 69 : 70 1326 : void Repository::set_location(const std::string &location_str) 71 : { 72 1326 : m_location_str = location_str; 73 1326 : } 74 : 75 39 : const std::string &Repository::get_location_str() const 76 : { 77 39 : return m_location_str; 78 : } 79 : 80 1264 : void Repository::set_location(Location *location) 81 : { 82 1264 : m_location = location; 83 1264 : if (location == nullptr) return; 84 : 85 1264 : set_location(location->get_name()); 86 : } 87 : 88 249 : Location *Repository::get_location() const 89 : { 90 249 : return m_location; 91 : } 92 : 93 28 : std::string Repository::get_url() const 94 : { 95 28 : if (get_location() == nullptr) return ""; 96 : 97 28 : std::string url = get_location()->get_address() + "/" + get_name(); 98 56 : return url; 99 28 : } 100 : 101 260 : std::vector<Group *> &Repository::get_groups() 102 : { 103 260 : return m_groups; 104 : } 105 : 106 42 : const std::vector<Group *> &Repository::get_groups() const 107 : { 108 42 : return m_groups; 109 : } 110 : 111 11 : void Repository::set_sync_s(std::optional<bool> sync_s) 112 : { 113 11 : m_sync_s = sync_s; 114 11 : } 115 : 116 294 : const std::optional<bool> &Repository::get_sync_s() const 117 : { 118 294 : return m_sync_s; 119 : } 120 : 121 7 : void Repository::add_depends(std::shared_ptr<Depends> depends) 122 : { 123 7 : if (depends == nullptr) return; 124 7 : m_depends.push_back(depends); 125 : } 126 : 127 995 : std::vector<std::shared_ptr<Depends>> &Repository::get_depends() 128 : { 129 995 : return m_depends; 130 : } 131 : 132 30 : const std::vector<std::shared_ptr<Depends>> &Repository::get_depends() const 133 : { 134 30 : return m_depends; 135 : } 136 : 137 1 : void Repository::clear_depends() 138 : { 139 1 : m_depends.clear(); 140 1 : } 141 : 142 10 : void Repository::set_sharing(std::optional<sharing::Config> sharing) 143 : { 144 10 : m_sharing = std::move(sharing); 145 10 : } 146 : 147 397 : const std::optional<sharing::Config> &Repository::get_sharing() const 148 : { 149 397 : return m_sharing; 150 : } 151 : 152 10 : void Repository::set_workspace(std::optional<WorkspaceConfig> workspace) 153 : { 154 10 : m_workspace = std::move(workspace); 155 10 : } 156 : 157 24 : const std::optional<WorkspaceConfig> &Repository::get_workspace() const 158 : { 159 24 : return m_workspace; 160 : } 161 : 162 549 : bool Repository::is_nested_workspace() const 163 : { 164 549 : return m_workspace.has_value() && m_workspace->get_nested(); 165 : } 166 : 167 8 : bool Repository::operator==(const Repository &repository) const 168 : { 169 8 : if (get_name() != repository.get_name()) return false; 170 8 : if (get_path() != repository.get_path()) return false; 171 8 : if (get_revision() != repository.get_revision()) return false; 172 8 : if (get_location_str() != repository.get_location_str()) return false; 173 8 : if (get_url() != repository.get_url()) return false; 174 16 : if (get_sync_s() != repository.get_sync_s()) return false; 175 8 : if (get_sharing() != repository.get_sharing()) return false; 176 8 : if (get_workspace() != repository.get_workspace()) return false; 177 : 178 8 : if (get_groups().size() != repository.get_groups().size()) return false; 179 : 180 14 : for (std::size_t idx = 0; idx < get_groups().size(); ++idx) 181 : { 182 6 : if (get_groups()[idx]->get_name() != repository.get_groups()[idx]->get_name()) return false; 183 : } 184 : 185 8 : if (get_depends().size() != repository.get_depends().size()) return false; 186 8 : for (std::size_t idx = 0; idx < get_depends().size(); ++idx) 187 : { 188 0 : if (*get_depends()[idx] != *repository.get_depends()[idx]) return false; 189 : } 190 : 191 : return true; 192 : } 193 : 194 8 : bool Repository::operator!=(const Repository &repository) const 195 : { 196 8 : return !operator==(repository); 197 : } 198 : 199 : } // namespace esys::repo::manifest