keep on refactoring
This commit is contained in:
parent
d30e6ed759
commit
b07d017f86
@ -31,7 +31,7 @@ private:
|
||||
void printMessage(const Message& message, bool colored = false) const;
|
||||
|
||||
private:
|
||||
bool accumulate;
|
||||
const bool accumulate;
|
||||
const Severity currentSeverity;
|
||||
mutable std::list<Message> history;
|
||||
mutable std::mutex readMutex;
|
||||
|
40
src/main.cpp
40
src/main.cpp
@ -1,6 +1,8 @@
|
||||
#include <string>
|
||||
|
||||
#include "project.h"
|
||||
#include "collection.h"
|
||||
#include "taskmanager.h"
|
||||
#include "loggger.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
std::string firstArg;
|
||||
@ -15,20 +17,28 @@ int main(int argc, char *argv[]) {
|
||||
else
|
||||
secondArg = "./";
|
||||
|
||||
Project root(firstArg, secondArg);
|
||||
bool success = root.read();
|
||||
|
||||
int result = -1;
|
||||
if (success) {
|
||||
root.info("successfully parsed project " + root.getName());
|
||||
root.info("dependencies count is " + std::to_string(root.dependenciesCount()));
|
||||
std::shared_ptr<Logger> logger = std::make_shared<Logger>(Logger::Severity::debug);
|
||||
std::shared_ptr<TaskManager> taskManager = std::make_shared<TaskManager>();
|
||||
std::shared_ptr<Collection> collection = std::make_shared<Collection>(secondArg, "", logger, taskManager);
|
||||
|
||||
root.discover();
|
||||
result = 0;
|
||||
}
|
||||
|
||||
root.printLog();
|
||||
|
||||
|
||||
return result;
|
||||
taskManager->start();
|
||||
collection->addSource(firstArg);
|
||||
|
||||
taskManager->wait();
|
||||
taskManager->stop();
|
||||
|
||||
// int result = -1;
|
||||
// if (success) {
|
||||
// root.info("successfully parsed project " + root.getName());
|
||||
// root.info("dependencies count is " + std::to_string(root.dependenciesCount()));
|
||||
//
|
||||
// root.discover();
|
||||
// result = 0;
|
||||
// }
|
||||
//
|
||||
// root.printLog();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -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…
Reference in New Issue
Block a user