keep on refactoring
This commit is contained in:
parent
d30e6ed759
commit
b07d017f86
6 changed files with 45 additions and 21 deletions
|
@ -19,7 +19,15 @@ Collection::Collection(
|
|||
downloadingSources(),
|
||||
readingSources(),
|
||||
buildingSources()
|
||||
{}
|
||||
{
|
||||
try {
|
||||
std::filesystem::create_directories(destination);
|
||||
} catch (const std::exception& e) {
|
||||
fatal(e.what());
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
void Collection::addSource(const std::string& source) {
|
||||
if (hasSource(source)) {
|
||||
|
@ -27,6 +35,7 @@ void Collection::addSource(const std::string& source) {
|
|||
return;
|
||||
}
|
||||
|
||||
debug("Adding source " + source);
|
||||
if (isRemote(source))
|
||||
queueDownload(source);
|
||||
else
|
||||
|
@ -95,7 +104,7 @@ void Collection::queueRead(const std::string& source, const std::filesystem::pat
|
|||
std::pair<Components::iterator, bool> res = readingSources.emplace(std::piecewise_construct,
|
||||
std::forward_as_tuple(source),
|
||||
std::forward_as_tuple(
|
||||
std::make_unique<Component>(location, std::shared_ptr<Collection>(this), logger)
|
||||
std::make_unique<Component>(location, shared_from_this(), logger)
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "download.h"
|
||||
#include "taskmanager.h"
|
||||
|
||||
class Collection : protected Loggable {
|
||||
class Collection : protected Loggable, public std::enable_shared_from_this<Collection> {
|
||||
using Sources = std::set<std::string>;
|
||||
using Downloads = std::map<std::string, std::unique_ptr<Download>>;
|
||||
using Components = std::map<std::string, std::unique_ptr<Component>>;
|
||||
|
|
|
@ -15,7 +15,7 @@ constexpr std::array<std::string_view, Component::done + 1> stringStates {
|
|||
|
||||
Component::Component(
|
||||
const std::filesystem::path& path,
|
||||
const std::shared_ptr<Collection>& collection,
|
||||
const std::weak_ptr<Collection>& collection,
|
||||
const std::shared_ptr<Logger>& logger
|
||||
):
|
||||
Loggable(logger),
|
||||
|
@ -81,9 +81,10 @@ bool Component::readAsMason() {
|
|||
return errorScenario(masonScenarion.string() + " dependencies are not organized as an array");
|
||||
|
||||
for (const nlohmann::json& dep : deps) {
|
||||
std::shared_ptr<Collection> col = collection.lock();
|
||||
switch (dep.type()) {
|
||||
case nlohmann::json::value_t::string:
|
||||
collection->addSource(dep);
|
||||
col->addSource(dep);
|
||||
break;
|
||||
case nlohmann::json::value_t::object: {
|
||||
nlohmann::json::const_iterator ditr = dep.find("path");
|
||||
|
@ -94,7 +95,7 @@ bool Component::readAsMason() {
|
|||
if (!path.is_string())
|
||||
return errorScenario(masonScenarion.string() + " object of unexpected format in dependecies");
|
||||
|
||||
collection->addSource(path);
|
||||
col->addSource(path);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -104,6 +105,7 @@ bool Component::readAsMason() {
|
|||
}
|
||||
|
||||
type = mason;
|
||||
info(location.string() + " seems to be a mason project");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -122,6 +124,9 @@ void Component::build(const std::filesystem::path& destination, const std::strin
|
|||
throw WrongState(state, "build");
|
||||
|
||||
state = building;
|
||||
|
||||
info("Building " + location.string() + " to " + destination.string());
|
||||
state = done;
|
||||
}
|
||||
|
||||
Component::State Component::getState() const {
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
|
||||
Component(
|
||||
const std::filesystem::path& path,
|
||||
const std::shared_ptr<Collection>& collection,
|
||||
const std::weak_ptr<Collection>& collection,
|
||||
const std::shared_ptr<Logger>& logger
|
||||
);
|
||||
|
||||
|
@ -55,7 +55,7 @@ private:
|
|||
private:
|
||||
State state;
|
||||
Type type;
|
||||
std::shared_ptr<Collection> collection;
|
||||
std::weak_ptr<Collection> collection;
|
||||
std::filesystem::path location;
|
||||
std::optional<nlohmann::json> scenario;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue