#pragma once #include #include #include #include #include #include #include #include #include #include #include #include "loggable.h" #include "loggger.h" class Collection; class Component : protected Loggable { public: class WrongState; class WrongType; enum State { initial, reading, ready, building, error, done }; enum Type { file, directory, mason, unknown }; Component( const std::filesystem::path& path, Collection* collection, const std::shared_ptr& logger, const std::optional& name = std::nullopt ); Type getType() const; State getState() const; std::filesystem::path getLocation() const; std::string getLibrariesPath() const; std::string getName() const; bool successfullyRead() const; bool successfullyBuilt() const; void read(); void build(const std::filesystem::path& destination, const std::string& target, bool useName = true); private: bool tryReadingBuildScenarios(); bool readAsMason(); bool errorScenario(const std::string& message); void buildAsFile(const std::filesystem::path& destination); void buildAsDirectory(const std::filesystem::path& destination); void buildAsMason(const std::filesystem::path& destination, std::string target); bool readMasonDependencies(const nlohmann::json& deps, const std::string& manifestPath); void copyFile(const std::filesystem::path& from, const std::filesystem::path& to) const; std::string validateMasonTarget(std::string target) const; void masonFilesArray(const nlohmann::json& files, const std::filesystem::path& destination); bool masonFileObject(const nlohmann::json& object, const std::filesystem::path& destination); bool allowedForMasonTarget(const nlohmann::json& object, const std::string& target) const; void getMasonTargets(const nlohmann::json& object, std::set& out) const; std::optional getFileSource(const nlohmann::json& object) const; std::optional getFileTarget(const nlohmann::json& object) const; static std::optional tryStringValue (const nlohmann::json& object, const std::string& key); private: State state; Type type; Collection* collection; std::filesystem::path location; std::optional manifest; std::optional name; }; class Component::WrongState : public std::runtime_error { public: explicit WrongState(State state, const std::string& action); }; class Component::WrongType : public std::runtime_error { public: explicit WrongType(Type type, const std::string& action); };