From 8a047eb6ac812331f521209aee9b12cac16c1316 Mon Sep 17 00:00:00 2001 From: Nav Date: Sun, 24 Jul 2022 12:17:44 +0100 Subject: [PATCH] Added bloom.json fallback to allow current Bloom users to continue using bloom.json for the project configuration. --- src/Application.cpp | 24 ++++++++++++++++++++---- src/ProjectConfig.hpp | 3 +++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index d181e03b..17978137 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -1,6 +1,7 @@ #include "Application.hpp" #include +#include #include #include @@ -237,13 +238,28 @@ namespace Bloom auto configFile = QFile(QString::fromStdString(Paths::projectConfigPath())); if (!configFile.exists()) { - throw InvalidConfig("Bloom configuration file (bloom.yaml) not found. Working directory: " - + Paths::projectDirPath()); + // Try looking for the old bloom.json config file + configFile.setFileName(QString::fromStdString(Paths::projectDirPath()) + "/bloom.json"); + + if (configFile.exists()) { + Logger::warning( + "The recommended project configuration file format changed from JSON to YAML in Bloom v0.11.0." + " Bloom could not find a bloom.yaml configuration file, but did find bloom.json. Please convert" + " bloom.json to YAML format and rename to \"bloom.yaml\". There are numerous online JSON -> YAML" + " converters. For now, bloom.json will be used in the absence of bloom.yaml." + ); + + } else { + throw InvalidConfig( + "Bloom configuration file (bloom.yaml) not found. Working directory: " + Paths::projectDirPath() + ); + } } if (!configFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - throw InvalidConfig("Failed to open Bloom configuration file (bloom.yaml) Working directory: " - + Paths::projectDirPath()); + throw InvalidConfig( + "Failed to open Bloom configuration file. Working directory: " + Paths::projectDirPath() + ); } const auto configNode = YAML::Load(configFile.readAll().toStdString()); diff --git a/src/ProjectConfig.hpp b/src/ProjectConfig.hpp index 12bcc248..1f02af99 100644 --- a/src/ProjectConfig.hpp +++ b/src/ProjectConfig.hpp @@ -33,6 +33,9 @@ namespace Bloom /* * Initially, we used the JSON format for project configuration files, but this was changed in version 0.11.0. * See https://github.com/navnavnav/Bloom/issues/50 for more. + * + * Because JSON is a subset of YAML, we can (and do) fallback to bloom.json in the absence of bloom.yaml. + * See Application::loadProjectConfiguration() for more. */ /**