Line data Source code
1 : /*! 2 : * \file esys/repo/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.h" 20 : #include "esys/repo/manifest/repository.h" 21 : 22 : #include <cassert> 23 : 24 : namespace esys::repo 25 : { 26 : 27 48 : Manifest::Manifest() = default; 28 : 29 49 : Manifest::~Manifest() = default; 30 : 31 50 : void Manifest::set_type(manifest::Type type) 32 : { 33 50 : m_type = type; 34 50 : } 35 : 36 5 : manifest::Type Manifest::get_type() const 37 : { 38 5 : return m_type; 39 : } 40 : 41 51 : void Manifest::set_kind(manifest::Kind kind) 42 : { 43 51 : m_kind = kind; 44 51 : } 45 : 46 29 : manifest::Kind Manifest::get_kind() const 47 : { 48 29 : return m_kind; 49 : } 50 : 51 25 : void Manifest::set_format(manifest::Format format) 52 : { 53 25 : m_format = format; 54 25 : } 55 : 56 9 : manifest::Format Manifest::get_format() const 57 : { 58 9 : return m_format; 59 : } 60 : 61 80 : int Manifest::add_location(std::shared_ptr<manifest::Location> location, bool is_default) 62 : { 63 80 : assert(location != nullptr); 64 80 : assert(!location->get_name().empty()); 65 : 66 80 : auto it = m_map_locations.find(location->get_name()); 67 80 : if (it != m_map_locations.end()) return -1; 68 : 69 80 : m_locations.push_back(location); 70 80 : m_map_locations[location->get_name()] = location; 71 82 : if (is_default) set_default_location(location); 72 : 73 : return 0; 74 : } 75 : 76 94 : std::vector<std::shared_ptr<manifest::Location>> &Manifest::get_locations() 77 : { 78 94 : return m_locations; 79 : } 80 : 81 6 : const std::vector<std::shared_ptr<manifest::Location>> &Manifest::get_locations() const 82 : { 83 6 : return m_locations; 84 : } 85 : 86 0 : std::map<std::string, std::shared_ptr<manifest::Location>> &Manifest::get_map_locations() 87 : { 88 0 : return m_map_locations; 89 : } 90 : 91 0 : const std::map<std::string, std::shared_ptr<manifest::Location>> &Manifest::get_map_locations() const 92 : { 93 0 : return m_map_locations; 94 : } 95 : 96 401 : std::shared_ptr<manifest::Location> Manifest::find_location(const std::string &name) 97 : { 98 401 : auto it = m_map_locations.find(name); 99 : 100 401 : if (it == m_map_locations.end()) return nullptr; 101 : 102 401 : return it->second; 103 : } 104 : 105 18 : std::shared_ptr<manifest::Repository> Manifest::find_repo_by_path(const std::string &path) 106 : { 107 18 : std::shared_ptr<manifest::Repository> repo; 108 : 109 35 : for (auto &location : get_locations()) 110 : { 111 70 : repo = location->find_repo_by_path(path); 112 35 : if (repo != nullptr) return repo; 113 : } 114 18 : return nullptr; 115 18 : } 116 : 117 0 : std::string Manifest::find_repo_path_by_url(const std::string &git_repo_name) 118 : { 119 0 : std::string path; 120 : 121 0 : for (auto &location : get_locations()) 122 : { 123 0 : path = location->find_repo_path_by_url(git_repo_name); 124 0 : if (!path.empty()) return path; 125 : } 126 0 : return ""; 127 0 : } 128 : 129 0 : std::shared_ptr<manifest::Repository> Manifest::find_repo_by_url(const std::string &url) 130 : { 131 0 : std::shared_ptr<manifest::Repository> repo; 132 : 133 0 : for (auto &location : get_locations()) 134 : { 135 0 : repo = location->find_repo_by_url(url); 136 0 : if (repo != nullptr) return repo; 137 : } 138 0 : return nullptr; 139 : 140 0 : } 141 : 142 1 : void Manifest::set_default_location(std::shared_ptr<manifest::Location> default_location) 143 : { 144 1 : m_default_location = default_location; 145 1 : } 146 : 147 355 : std::shared_ptr<manifest::Location> Manifest::get_default_location() 148 : { 149 355 : if (m_default_location != nullptr) return m_default_location; 150 : 151 343 : if (m_default_location_str.empty()) return nullptr; 152 : 153 343 : return find_location(m_default_location_str); 154 : } 155 : 156 23 : void Manifest::set_default_location(const std::string &default_location_str) 157 : { 158 23 : m_default_location_str = default_location_str; 159 23 : } 160 : 161 0 : const std::string &Manifest::get_default_location_str() const 162 : { 163 0 : return m_default_location_str; 164 : } 165 : 166 48 : void Manifest::set_default_revision(const std::string &default_revision) 167 : { 168 48 : m_default_revision = default_revision; 169 48 : } 170 : 171 72 : const std::string &Manifest::get_default_revision() const 172 : { 173 72 : return m_default_revision; 174 : } 175 : 176 48 : void Manifest::set_default_job_count(int default_job_count) 177 : { 178 48 : m_default_job_count = default_job_count; 179 48 : } 180 : 181 10 : int Manifest::get_default_job_count() const 182 : { 183 10 : return m_default_job_count; 184 : } 185 : 186 50 : std::string Manifest::get_repo_revision(std::shared_ptr<manifest::Repository> repo) 187 : { 188 50 : if (!repo->get_revision().empty()) return repo->get_revision(); 189 42 : return get_default_revision(); 190 : } 191 : 192 57 : void Manifest::clear() 193 : { 194 57 : m_type = manifest::Type::NOT_SET; 195 57 : m_locations.clear(); 196 57 : m_map_locations.clear(); 197 57 : m_map_locations_by_path.clear(); 198 57 : m_default_location.reset(); 199 57 : get_groups().clear(); 200 57 : m_map_locations_by_path.clear(); 201 57 : m_default_location_str.clear(); 202 57 : m_default_revision = "master"; 203 57 : m_default_job_count = 1; 204 57 : } 205 : 206 157 : manifest::Groups &Manifest::get_groups() 207 : { 208 157 : return m_groups; 209 : } 210 : 211 0 : const manifest::Groups &Manifest::get_groups() const 212 : { 213 0 : return m_groups; 214 : } 215 : 216 2 : void Manifest::add_include(std::shared_ptr<manifest::Include> include) 217 : { 218 2 : m_includes.push_back(include); 219 2 : } 220 : 221 : 222 4 : std::vector<std::shared_ptr<manifest::Include>> &Manifest::get_includes() 223 : { 224 4 : return m_includes; 225 : } 226 : 227 2 : const std::vector<std::shared_ptr<manifest::Include>> &Manifest::get_includes() const 228 : { 229 2 : return m_includes; 230 : } 231 : 232 1 : bool Manifest::operator==(const Manifest &other) const 233 : { 234 1 : if (get_type() != other.get_type()) return false; 235 : 236 1 : if (get_locations().size() != other.get_locations().size()) return false; 237 : 238 2 : for (std::size_t idx = 0; idx < get_locations().size(); ++idx) 239 : { 240 1 : if (*get_locations()[idx] != *other.get_locations()[idx]) return false; 241 : } 242 : 243 1 : if (get_includes().size() != other.get_includes().size()) return false; 244 : 245 : 246 : 247 : return true; 248 : } 249 : 250 0 : bool Manifest::operator!=(const Manifest &other) const 251 : { 252 0 : return !operator==(other); 253 : } 254 : 255 0 : ESYSREPO_API std::ostream &operator<<(std::ostream &os, const Manifest &manifest) 256 : { 257 0 : return os; 258 : } 259 : 260 : } // namespace esys::repo