2021-12-31 17:05:31 +00:00
|
|
|
#include "ProjectConfig.hpp"
|
2021-10-02 17:39:27 +01:00
|
|
|
|
2021-04-06 02:10:14 +01:00
|
|
|
#include "src/Logger/Logger.hpp"
|
|
|
|
|
#include "src/Exceptions/InvalidConfig.hpp"
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
namespace Bloom
|
|
|
|
|
{
|
|
|
|
|
ProjectConfig::ProjectConfig(const QJsonObject& jsonObject) {
|
|
|
|
|
if (!jsonObject.contains("environments")) {
|
|
|
|
|
throw Exceptions::InvalidConfig(
|
|
|
|
|
"No environments found - please review the bloom.json configuration file and ensure that "
|
|
|
|
|
"no syntax errors are present."
|
2021-04-04 21:04:12 +01:00
|
|
|
);
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-12-31 19:44:20 +00:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
// Extract all environment objects from JSON config.
|
|
|
|
|
auto environments = jsonObject.find("environments").value().toObject();
|
|
|
|
|
for (auto environmentIt = environments.begin(); environmentIt != environments.end(); environmentIt++) {
|
|
|
|
|
auto environmentName = environmentIt.key().toStdString();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
this->environments.insert(
|
|
|
|
|
std::pair(
|
|
|
|
|
environmentName,
|
|
|
|
|
EnvironmentConfig(environmentName, environmentIt.value().toObject())
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
} catch (Exceptions::InvalidConfig& exception) {
|
|
|
|
|
Logger::error("Invalid environment config for environment '" + environmentName + "': "
|
|
|
|
|
+ exception.getMessage() + " Environment will be ignored.");
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
if (jsonObject.contains("debugServer")) {
|
|
|
|
|
this->debugServerConfig = DebugServerConfig(jsonObject.find("debugServer")->toObject());
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
if (jsonObject.contains("insight")) {
|
|
|
|
|
this->insightConfig = InsightConfig(jsonObject.find("insight")->toObject());
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
if (jsonObject.contains("debugLoggingEnabled")) {
|
|
|
|
|
this->debugLoggingEnabled = jsonObject.find("debugLoggingEnabled").value().toBool();
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
InsightConfig::InsightConfig(const QJsonObject& jsonObject) {
|
|
|
|
|
if (jsonObject.contains("enabled")) {
|
|
|
|
|
this->insightEnabled = jsonObject.find("enabled").value().toBool();
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
EnvironmentConfig::EnvironmentConfig(std::string name, QJsonObject jsonObject) {
|
|
|
|
|
if (!jsonObject.contains("debugTool")) {
|
|
|
|
|
throw Exceptions::InvalidConfig("No debug tool configuration provided.");
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
if (!jsonObject.contains("target")) {
|
|
|
|
|
throw Exceptions::InvalidConfig("No target configuration provided.");
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
this->name = std::move(name);
|
2022-02-09 17:44:58 +00:00
|
|
|
this->shutdownPostDebugSession = jsonObject.value(
|
|
|
|
|
"shutdownPostDebugSession"
|
|
|
|
|
).toBool(this->shutdownPostDebugSession);
|
2022-02-05 15:32:08 +00:00
|
|
|
this->debugToolConfig = DebugToolConfig(jsonObject.find("debugTool")->toObject());
|
|
|
|
|
this->targetConfig = TargetConfig(jsonObject.find("target")->toObject());
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
if (jsonObject.contains("debugServer")) {
|
|
|
|
|
this->debugServerConfig = DebugServerConfig(jsonObject.find("debugServer")->toObject());
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
if (jsonObject.contains("insight")) {
|
|
|
|
|
this->insightConfig = InsightConfig(jsonObject.find("insight")->toObject());
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
TargetConfig::TargetConfig(const QJsonObject& jsonObject) {
|
|
|
|
|
if (!jsonObject.contains("name")) {
|
|
|
|
|
throw Exceptions::InvalidConfig("No target name found.");
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
this->name = jsonObject.find("name")->toString().toLower().toStdString();
|
|
|
|
|
|
|
|
|
|
if (jsonObject.contains("variantName")) {
|
|
|
|
|
this->variantName = jsonObject.find("variantName").value().toString().toLower().toStdString();
|
|
|
|
|
}
|
2021-04-08 20:42:23 +01:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
this->jsonObject = jsonObject;
|
2021-04-08 20:42:23 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
DebugToolConfig::DebugToolConfig(const QJsonObject& jsonObject) {
|
|
|
|
|
if (!jsonObject.contains("name")) {
|
|
|
|
|
throw Exceptions::InvalidConfig("No debug tool name found.");
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
this->name = jsonObject.find("name")->toString().toLower().toStdString();
|
2021-05-30 16:48:34 +01:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
if (jsonObject.contains("releasePostDebugSession")) {
|
|
|
|
|
this->releasePostDebugSession = jsonObject.find("releasePostDebugSession").value().toBool();
|
|
|
|
|
}
|
2021-05-30 16:48:34 +01:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
this->jsonObject = jsonObject;
|
2021-05-30 16:48:34 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
DebugServerConfig::DebugServerConfig(const QJsonObject& jsonObject) {
|
|
|
|
|
this->name = jsonObject.find("name")->toString().toLower().toStdString();
|
|
|
|
|
this->jsonObject = jsonObject;
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|