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;
|
void printMessage(const Message& message, bool colored = false) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool accumulate;
|
const bool accumulate;
|
||||||
const Severity currentSeverity;
|
const Severity currentSeverity;
|
||||||
mutable std::list<Message> history;
|
mutable std::list<Message> history;
|
||||||
mutable std::mutex readMutex;
|
mutable std::mutex readMutex;
|
||||||
|
40
src/main.cpp
40
src/main.cpp
@ -1,6 +1,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "project.h"
|
#include "collection.h"
|
||||||
|
#include "taskmanager.h"
|
||||||
|
#include "loggger.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
std::string firstArg;
|
std::string firstArg;
|
||||||
@ -15,20 +17,28 @@ int main(int argc, char *argv[]) {
|
|||||||
else
|
else
|
||||||
secondArg = "./";
|
secondArg = "./";
|
||||||
|
|
||||||
Project root(firstArg, secondArg);
|
|
||||||
bool success = root.read();
|
|
||||||
|
|
||||||
int result = -1;
|
std::shared_ptr<Logger> logger = std::make_shared<Logger>(Logger::Severity::debug);
|
||||||
if (success) {
|
std::shared_ptr<TaskManager> taskManager = std::make_shared<TaskManager>();
|
||||||
root.info("successfully parsed project " + root.getName());
|
std::shared_ptr<Collection> collection = std::make_shared<Collection>(secondArg, "", logger, taskManager);
|
||||||
root.info("dependencies count is " + std::to_string(root.dependenciesCount()));
|
|
||||||
|
|
||||||
root.discover();
|
taskManager->start();
|
||||||
result = 0;
|
collection->addSource(firstArg);
|
||||||
}
|
|
||||||
|
taskManager->wait();
|
||||||
root.printLog();
|
taskManager->stop();
|
||||||
|
|
||||||
|
// int result = -1;
|
||||||
return result;
|
// 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(),
|
downloadingSources(),
|
||||||
readingSources(),
|
readingSources(),
|
||||||
buildingSources()
|
buildingSources()
|
||||||
{}
|
{
|
||||||
|
try {
|
||||||
|
std::filesystem::create_directories(destination);
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
fatal(e.what());
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Collection::addSource(const std::string& source) {
|
void Collection::addSource(const std::string& source) {
|
||||||
if (hasSource(source)) {
|
if (hasSource(source)) {
|
||||||
@ -27,6 +35,7 @@ void Collection::addSource(const std::string& source) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug("Adding source " + source);
|
||||||
if (isRemote(source))
|
if (isRemote(source))
|
||||||
queueDownload(source);
|
queueDownload(source);
|
||||||
else
|
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::pair<Components::iterator, bool> res = readingSources.emplace(std::piecewise_construct,
|
||||||
std::forward_as_tuple(source),
|
std::forward_as_tuple(source),
|
||||||
std::forward_as_tuple(
|
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 "download.h"
|
||||||
#include "taskmanager.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 Sources = std::set<std::string>;
|
||||||
using Downloads = std::map<std::string, std::unique_ptr<Download>>;
|
using Downloads = std::map<std::string, std::unique_ptr<Download>>;
|
||||||
using Components = std::map<std::string, std::unique_ptr<Component>>;
|
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(
|
Component::Component(
|
||||||
const std::filesystem::path& path,
|
const std::filesystem::path& path,
|
||||||
const std::shared_ptr<Collection>& collection,
|
const std::weak_ptr<Collection>& collection,
|
||||||
const std::shared_ptr<Logger>& logger
|
const std::shared_ptr<Logger>& logger
|
||||||
):
|
):
|
||||||
Loggable(logger),
|
Loggable(logger),
|
||||||
@ -81,9 +81,10 @@ bool Component::readAsMason() {
|
|||||||
return errorScenario(masonScenarion.string() + " dependencies are not organized as an array");
|
return errorScenario(masonScenarion.string() + " dependencies are not organized as an array");
|
||||||
|
|
||||||
for (const nlohmann::json& dep : deps) {
|
for (const nlohmann::json& dep : deps) {
|
||||||
|
std::shared_ptr<Collection> col = collection.lock();
|
||||||
switch (dep.type()) {
|
switch (dep.type()) {
|
||||||
case nlohmann::json::value_t::string:
|
case nlohmann::json::value_t::string:
|
||||||
collection->addSource(dep);
|
col->addSource(dep);
|
||||||
break;
|
break;
|
||||||
case nlohmann::json::value_t::object: {
|
case nlohmann::json::value_t::object: {
|
||||||
nlohmann::json::const_iterator ditr = dep.find("path");
|
nlohmann::json::const_iterator ditr = dep.find("path");
|
||||||
@ -94,7 +95,7 @@ bool Component::readAsMason() {
|
|||||||
if (!path.is_string())
|
if (!path.is_string())
|
||||||
return errorScenario(masonScenarion.string() + " object of unexpected format in dependecies");
|
return errorScenario(masonScenarion.string() + " object of unexpected format in dependecies");
|
||||||
|
|
||||||
collection->addSource(path);
|
col->addSource(path);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -104,6 +105,7 @@ bool Component::readAsMason() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type = mason;
|
type = mason;
|
||||||
|
info(location.string() + " seems to be a mason project");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,6 +124,9 @@ void Component::build(const std::filesystem::path& destination, const std::strin
|
|||||||
throw WrongState(state, "build");
|
throw WrongState(state, "build");
|
||||||
|
|
||||||
state = building;
|
state = building;
|
||||||
|
|
||||||
|
info("Building " + location.string() + " to " + destination.string());
|
||||||
|
state = done;
|
||||||
}
|
}
|
||||||
|
|
||||||
Component::State Component::getState() const {
|
Component::State Component::getState() const {
|
||||||
|
@ -37,7 +37,7 @@ public:
|
|||||||
|
|
||||||
Component(
|
Component(
|
||||||
const std::filesystem::path& path,
|
const std::filesystem::path& path,
|
||||||
const std::shared_ptr<Collection>& collection,
|
const std::weak_ptr<Collection>& collection,
|
||||||
const std::shared_ptr<Logger>& logger
|
const std::shared_ptr<Logger>& logger
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
State state;
|
State state;
|
||||||
Type type;
|
Type type;
|
||||||
std::shared_ptr<Collection> collection;
|
std::weak_ptr<Collection> collection;
|
||||||
std::filesystem::path location;
|
std::filesystem::path location;
|
||||||
std::optional<nlohmann::json> scenario;
|
std::optional<nlohmann::json> scenario;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user