Replaced init() functions with proper constructors in ProjectConfig structs

This commit is contained in:
Nav
2021-12-31 19:44:20 +00:00
parent 7c08a37d82
commit d24587b992
3 changed files with 67 additions and 62 deletions

View File

@@ -170,7 +170,6 @@ void Application::shutdown() {
}
ProjectConfig Application::extractConfig() {
auto appConfig = ProjectConfig();
auto currentPath = std::filesystem::current_path().string();
auto jsonConfigFile = QFile(QString::fromStdString(currentPath + "/bloom.json"));
@@ -185,10 +184,9 @@ ProjectConfig Application::extractConfig() {
}
auto jsonObject = QJsonDocument::fromJson(jsonConfigFile.readAll()).object();
appConfig.init(jsonObject);
jsonConfigFile.close();
return appConfig;
return ProjectConfig(jsonObject);
}
int Application::presentHelpText() {

View File

@@ -5,7 +5,7 @@
using namespace Bloom;
void ProjectConfig::init(const QJsonObject& jsonObject) {
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 "
@@ -19,12 +19,13 @@ void ProjectConfig::init(const QJsonObject& jsonObject) {
auto environmentName = environmentIt.key().toStdString();
try {
auto environmentConfig = EnvironmentConfig();
environmentConfig.init(environmentName, environmentIt.value().toObject());
this->environments.insert(
std::pair<std::string, EnvironmentConfig>(environmentName, environmentConfig)
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.");
@@ -32,13 +33,11 @@ void ProjectConfig::init(const QJsonObject& jsonObject) {
}
if (jsonObject.contains("debugServer")) {
auto debugServerConfig = DebugServerConfig();
debugServerConfig.init(jsonObject.find("debugServer")->toObject());
this->debugServerConfig = debugServerConfig;
this->debugServerConfig = DebugServerConfig(jsonObject.find("debugServer")->toObject());
}
if (jsonObject.contains("insight")) {
this->insightConfig.init(jsonObject.find("insight")->toObject());
this->insightConfig = InsightConfig(jsonObject.find("insight")->toObject());
}
if (jsonObject.contains("debugLoggingEnabled")) {
@@ -46,13 +45,13 @@ void ProjectConfig::init(const QJsonObject& jsonObject) {
}
}
void InsightConfig::init(const QJsonObject& jsonObject) {
InsightConfig::InsightConfig(const QJsonObject& jsonObject) {
if (jsonObject.contains("enabled")) {
this->insightEnabled = jsonObject.find("enabled").value().toBool();
}
}
void EnvironmentConfig::init(std::string name, QJsonObject jsonObject) {
EnvironmentConfig::EnvironmentConfig(std::string name, QJsonObject jsonObject) {
if (!jsonObject.contains("debugTool")) {
throw Exceptions::InvalidConfig("No debug tool configuration provided.");
}
@@ -62,23 +61,19 @@ void EnvironmentConfig::init(std::string name, QJsonObject jsonObject) {
}
this->name = std::move(name);
this->debugToolConfig.init(jsonObject.find("debugTool")->toObject());
this->targetConfig.init(jsonObject.find("target")->toObject());
this->debugToolConfig = DebugToolConfig(jsonObject.find("debugTool")->toObject());
this->targetConfig = TargetConfig(jsonObject.find("target")->toObject());
if (jsonObject.contains("debugServer")) {
auto debugServerConfig = DebugServerConfig();
debugServerConfig.init(jsonObject.find("debugServer")->toObject());
this->debugServerConfig = debugServerConfig;
this->debugServerConfig = DebugServerConfig(jsonObject.find("debugServer")->toObject());
}
if (jsonObject.contains("insight")) {
auto insightConfig = InsightConfig();
insightConfig.init(jsonObject.find("insight")->toObject());
this->insightConfig = insightConfig;
this->insightConfig = InsightConfig(jsonObject.find("insight")->toObject());
}
}
void TargetConfig::init(const QJsonObject& jsonObject) {
TargetConfig::TargetConfig(const QJsonObject& jsonObject) {
if (!jsonObject.contains("name")) {
throw Exceptions::InvalidConfig("No target name found.");
}
@@ -92,7 +87,7 @@ void TargetConfig::init(const QJsonObject& jsonObject) {
this->jsonObject = jsonObject;
}
void DebugToolConfig::init(const QJsonObject& jsonObject) {
DebugToolConfig::DebugToolConfig(const QJsonObject& jsonObject) {
if (!jsonObject.contains("name")) {
throw Exceptions::InvalidConfig("No debug tool name found.");
}
@@ -106,7 +101,7 @@ void DebugToolConfig::init(const QJsonObject& jsonObject) {
this->jsonObject = jsonObject;
}
void DebugServerConfig::init(const QJsonObject& jsonObject) {
DebugServerConfig::DebugServerConfig(const QJsonObject& jsonObject) {
this->name = jsonObject.find("name")->toString().toLower().toStdString();
this->jsonObject = jsonObject;
}

View File

@@ -42,13 +42,6 @@ namespace Bloom
*/
struct TargetConfig
{
/**
* Obtains config parameters from JSON object.
*
* @param jsonObject
*/
void init(const QJsonObject& jsonObject);
/**
* The name of the selected target.
*/
@@ -62,6 +55,15 @@ namespace Bloom
std::optional<std::string> variantName;
QJsonObject jsonObject;
TargetConfig() = default;
/**
* Obtains config parameters from JSON object.
*
* @param jsonObject
*/
explicit TargetConfig(const QJsonObject& jsonObject);
};
/**
@@ -73,13 +75,6 @@ namespace Bloom
*/
struct DebugToolConfig
{
/**
* Obtains config parameters from JSON object.
*
* @param jsonObject
*/
void init(const QJsonObject& jsonObject);
/**
* The name of the selected debug tool.
*/
@@ -95,6 +90,15 @@ namespace Bloom
bool releasePostDebugSession = true;
QJsonObject jsonObject;
DebugToolConfig() = default;
/**
* Obtains config parameters from JSON object.
*
* @param jsonObject
*/
explicit DebugToolConfig(const QJsonObject& jsonObject);
};
/**
@@ -102,27 +106,31 @@ namespace Bloom
*/
struct DebugServerConfig
{
std::string name;
QJsonObject jsonObject;
DebugServerConfig() = default;
/**
* Obtains config parameters from JSON object.
*
* @param jsonObject
*/
void init(const QJsonObject& jsonObject);
std::string name;
QJsonObject jsonObject;
explicit DebugServerConfig(const QJsonObject& jsonObject);
};
struct InsightConfig
{
bool insightEnabled = true;
InsightConfig() = default;
/**
* Obtains config parameters from JSON object.
*
* @param jsonObject
*/
void init(const QJsonObject& jsonObject);
bool insightEnabled = true;
explicit InsightConfig(const QJsonObject& jsonObject);
};
/**
@@ -133,13 +141,6 @@ namespace Bloom
*/
struct EnvironmentConfig
{
/**
* Obtains config parameters from JSON object.
*
* @param jsonObject
*/
void init(std::string name, QJsonObject jsonObject);
/**
* The environment name is stored as the key to the JSON object containing the environment parameters.
*
@@ -171,6 +172,13 @@ namespace Bloom
* Insight configuration can be defined at an environment level as well as at an application level.
*/
std::optional<InsightConfig> insightConfig;
/**
* Obtains config parameters from JSON object.
*
* @param jsonObject
*/
EnvironmentConfig(std::string name, QJsonObject jsonObject);
};
/**
@@ -178,13 +186,6 @@ namespace Bloom
*/
struct ProjectConfig
{
/**
* Obtains config parameters from JSON object.
*
* @param jsonObject
*/
void init(const QJsonObject& jsonObject);
/**
* A mapping of environment names to EnvironmentConfig objects.
*/
@@ -196,8 +197,19 @@ namespace Bloom
*/
std::optional<DebugServerConfig> debugServerConfig;
InsightConfig insightConfig;
/**
* Application level Insight configuration. We use this as a fallback if no Insight config is provided at
* the environment level.
*/
std::optional<InsightConfig> insightConfig;
bool debugLoggingEnabled = false;
/**
* Obtains config parameters from JSON object.
*
* @param jsonObject
*/
explicit ProjectConfig(const QJsonObject& jsonObject);
};
}