just some refactoring thoughts
This commit is contained in:
parent
198677fc18
commit
b92b66c101
10 changed files with 159 additions and 5 deletions
|
@ -5,6 +5,7 @@
|
|||
#include "project.h"
|
||||
|
||||
constexpr std::string_view downloads("downloads");
|
||||
constexpr std::string_view sources("sources");
|
||||
constexpr std::string_view build("build");
|
||||
|
||||
constexpr std::string_view acceptJson("accept: application/json");
|
||||
|
@ -20,7 +21,8 @@ Dependency::Dependency(
|
|||
path(path),
|
||||
type(type),
|
||||
name(name),
|
||||
version(version)
|
||||
version(version),
|
||||
location()
|
||||
{}
|
||||
|
||||
Dependency::Type Dependency::getType() const {
|
||||
|
@ -35,6 +37,13 @@ std::optional<std::string> Dependency::getVersion() const {
|
|||
return version;
|
||||
}
|
||||
|
||||
std::optional<std::filesystem::path> Dependency::getLocation() const {
|
||||
if (location.empty())
|
||||
return std::nullopt;
|
||||
else
|
||||
return location;
|
||||
}
|
||||
|
||||
bool Dependency::prepare(const std::filesystem::path& source, const std::filesystem::path& destination) {
|
||||
std::smatch results;
|
||||
if (std::regex_search(path, results, repo)) {
|
||||
|
@ -60,8 +69,10 @@ bool Dependency::prepare(const std::filesystem::path& source, const std::filesys
|
|||
case Type::mason:
|
||||
if (std::filesystem::exists(temp/"mason.json"))
|
||||
break;
|
||||
else
|
||||
else {
|
||||
Project::warn("Project " + path + " is supposed to me a mason project, but no mason.json was found in the project directory");
|
||||
success = false;
|
||||
}
|
||||
|
||||
break;
|
||||
case Type::simple:
|
||||
|
@ -108,7 +119,8 @@ bool Dependency::downloadRepo(
|
|||
if (res) {
|
||||
Project::info("Successfully downloaded " + archivePath.string());
|
||||
|
||||
res = extract(archivePath, destination/build);
|
||||
location = destination/sources;
|
||||
res = extract(archivePath, location);
|
||||
if (res) {
|
||||
out = destination/build/repo;
|
||||
if (!std::filesystem::is_directory(out)) {
|
||||
|
@ -119,6 +131,9 @@ bool Dependency::downloadRepo(
|
|||
Project::error("Couldn't extract archive " + fileName);
|
||||
}
|
||||
|
||||
if (!res)
|
||||
location.clear();
|
||||
|
||||
return res;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
Type getType() const;
|
||||
std::optional<std::string> getName() const;
|
||||
std::optional<std::string> getVersion() const;
|
||||
std::optional<std::filesystem::path> getLocation() const;
|
||||
|
||||
bool prepare(const std::filesystem::path& source, const std::filesystem::path& destination);
|
||||
|
||||
|
@ -64,4 +65,5 @@ private:
|
|||
Type type;
|
||||
std::optional<std::string> name;
|
||||
std::optional<std::string> version;
|
||||
std::filesystem::path location;
|
||||
};
|
||||
|
|
|
@ -18,6 +18,7 @@ std::map<std::string, Dependency::Type> types({
|
|||
Logger* Project::logger = nullptr;
|
||||
|
||||
Project::Project(const std::filesystem::path& location, const std::filesystem::path& destination):
|
||||
parent(nullptr),
|
||||
location(location),
|
||||
destination(destination),
|
||||
state(State::unknown),
|
||||
|
@ -31,6 +32,15 @@ Project::Project(const std::filesystem::path& location, const std::filesystem::p
|
|||
}
|
||||
}
|
||||
|
||||
Project::Project(const std::filesystem::path& location, const std::filesystem::path& destination, Project* parent):
|
||||
parent(parent),
|
||||
location(location),
|
||||
destination(destination),
|
||||
state(State::unknown),
|
||||
name(),
|
||||
dependencies(),
|
||||
root(false) {}
|
||||
|
||||
Project::~Project() {
|
||||
if (root) {
|
||||
curl_global_cleanup();
|
||||
|
@ -156,9 +166,20 @@ void Project::createDepencencyFromObject(const nlohmann::json& entry) {
|
|||
void Project::discover() {
|
||||
int fine = 0;
|
||||
for (std::pair<const std::string, Dependency>& pair : dependencies) {
|
||||
bool success = pair.second.prepare(location, destination);
|
||||
if (success)
|
||||
Dependency& dep = pair.second;
|
||||
bool success = dep.prepare(location, destination);
|
||||
if (success) {
|
||||
switch (dep.getType()) {
|
||||
case Dependency::Type::mason:
|
||||
break;
|
||||
case Dependency::Type::simple:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
fine++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -44,11 +44,14 @@ public:
|
|||
static void addProject(const std::filesystem::path& location, const std::filesystem::path& destination);
|
||||
|
||||
private:
|
||||
Project(const std::filesystem::path& location, const std::filesystem::path& destination, Project* parent);
|
||||
|
||||
void parse(const nlohmann::json& json);
|
||||
void createDepencencyFromString(const std::string& entry);
|
||||
void createDepencencyFromObject(const nlohmann::json& entry);
|
||||
|
||||
private:
|
||||
Project* parent;
|
||||
std::filesystem::path location;
|
||||
std::filesystem::path destination;
|
||||
State state;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue