diff --git a/bin/data/test_ProjectSettings.xml b/bin/data/test_ProjectSettings.xml index 457d962f..7f3fd6fd 100644 --- a/bin/data/test_ProjectSettings.xml +++ b/bin/data/test_ProjectSettings.xml @@ -1,5 +1,5 @@ - the/awesome/path/to/the/code + data diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index a028a83f..a8457fdf 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -35,5 +35,6 @@ void Application::loadProject() m_componentManager->setup(); m_project = Project::create(m_codeAccess, m_graphAccess); + m_project->loadProjectSettings("data/test_ProjectSettings.xml"); m_project->parseCode(); } diff --git a/src/lib/ApplicationSettings.h b/src/lib/ApplicationSettings.h index 77a3c7e4..e620436b 100644 --- a/src/lib/ApplicationSettings.h +++ b/src/lib/ApplicationSettings.h @@ -18,5 +18,4 @@ private: static std::shared_ptr s_instance; }; - #endif // APPLICATION_SETTINGS_H diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index 3f2bf7dd..fe03438a 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -1,9 +1,11 @@ #include "Project.h" -#include #include +#include #include "data/parser/cxx/CxxParser.h" +#include "utility/FileSystem.h" +#include "utility/logging/logging.h" std::shared_ptr Project::create( std::shared_ptr codeAccess, @@ -27,16 +29,22 @@ Project::~Project() { } -const ProjectSettings& Project::getProjectSettings() const +bool Project::loadProjectSettings(const std::string& projectSettingsFile) { - return m_settings; + return ProjectSettings::getInstance()->load(projectSettingsFile); } void Project::parseCode() { - std::vector filePaths; - filePaths.push_back("data/test_code.cpp"); + if (ProjectSettings::getInstance()->getSourcePath() != "") + { + std::vector extension; + extension.push_back(".cpp"); + extension.push_back(".h"); - CxxParser parser(m_storage); - parser.parseFiles(filePaths); + CxxParser parser(m_storage); + parser.parseFiles( + FileSystem::getSourceFilesFromDirectory(ProjectSettings::getInstance()->getSourcePath(), extension) + ); + } } diff --git a/src/lib/Project.h b/src/lib/Project.h index 9fc56e22..646ebeed 100644 --- a/src/lib/Project.h +++ b/src/lib/Project.h @@ -18,8 +18,7 @@ public: ~Project(); - const ProjectSettings& getProjectSettings() const; - + bool loadProjectSettings(const std::string& projectSettingsFile); void parseCode(); private: @@ -27,10 +26,7 @@ private: Project(const Project&); Project operator=(const Project&); - ProjectSettings m_settings; - std::shared_ptr m_storage; - std::shared_ptr m_codeAccess; std::shared_ptr m_graphAccess; }; diff --git a/src/lib/ProjectSettings.cpp b/src/lib/ProjectSettings.cpp index 84f01262..f0273377 100644 --- a/src/lib/ProjectSettings.cpp +++ b/src/lib/ProjectSettings.cpp @@ -1 +1,71 @@ #include "ProjectSettings.h" + +#include "utility/logging/logging.h" + +#include "utility/text/TextAccess.h" + +#include "utility/FileSystem.h" + +std::shared_ptr ProjectSettings::s_instance; + +std::shared_ptr ProjectSettings::getInstance() +{ + if (!s_instance) + { + s_instance = std::shared_ptr(new ProjectSettings()); + } + + return s_instance; +} + +ProjectSettings::ProjectSettings() +{ +} + +ProjectSettings::~ProjectSettings() +{ +} + +bool ProjectSettings::load(const std::string& projectSettingsFilePath) +{ + m_config.reset(); + if (FileSystem::exists(projectSettingsFilePath)) + { + m_config = ConfigManager::createAndLoad(TextAccess::createFromFile(projectSettingsFilePath)); + } + else + { + LOG_WARNING("File for Projectsettings not found"); + return false; + } +} + +void ProjectSettings::save(const std::string& projectSettingsFilePath) +{ + if(m_config) + { + m_config->save(); + } +} + +std::string ProjectSettings::getSourcePath() const +{ + if(m_config) + { + std::string sourcePath; + if(m_config->getValue("SourcePath", sourcePath)) + { + return sourcePath; + } + } + return ""; +} + +void ProjectSettings::setSourcePath(const std::string& sourcePath) +{ + if(m_config) + { + m_config->setValue("SourcePath", sourcePath); + } + +} diff --git a/src/lib/ProjectSettings.h b/src/lib/ProjectSettings.h index f4ad1b9e..a1b9ad73 100644 --- a/src/lib/ProjectSettings.h +++ b/src/lib/ProjectSettings.h @@ -1,9 +1,31 @@ #ifndef PROJECT_SETTINGS_H #define PROJECT_SETTINGS_H +#include +#include + +#include "utility/ConfigManager.h" + class ProjectSettings { +public: + static std::shared_ptr getInstance(); + ~ProjectSettings(); + + bool load(const std::string& projectSettingsFilePath); + void save(const std::string& projectSettingsFilePath); + +std::string getSourcePath() const; + + void setSourcePath(const std::string& sourcePath); + +private: + static std::shared_ptr s_instance; + ProjectSettings(); + ProjectSettings(const ProjectSettings&); + void operator=(const ProjectSettings&); + + std::shared_ptr m_config; }; - #endif // PROJECT_SETTINGS_H diff --git a/src/lib/utility/ConfigManager.cpp b/src/lib/utility/ConfigManager.cpp index 27e613b6..be72fc1a 100644 --- a/src/lib/utility/ConfigManager.cpp +++ b/src/lib/utility/ConfigManager.cpp @@ -1,5 +1,6 @@ #include "utility/ConfigManager.h" +#include "logging/logging.h" #include "utility/text/TextAccess.h" std::shared_ptr ConfigManager::createAndLoad(const std::shared_ptr textAccess) @@ -111,6 +112,7 @@ void ConfigManager::load() void ConfigManager::save() { + LOG_ERROR("function: configmanager::save not implemented"); // LOG ("Saving config to file: " + m_filePath) } diff --git a/src/lib/utility/ConfigManager.h b/src/lib/utility/ConfigManager.h index b17d2c90..f6040f5e 100644 --- a/src/lib/utility/ConfigManager.h +++ b/src/lib/utility/ConfigManager.h @@ -1,7 +1,6 @@ #ifndef CONFIG_MANAGER_H #define CONFIG_MANAGER_H - #include #include #include @@ -31,7 +30,7 @@ public: private: ConfigManager(const std::shared_ptr textAccess); ConfigManager(const ConfigManager&); - ConfigManager operator=(const ConfigManager&); + void operator=(const ConfigManager&); void parseSubtree(TiXmlNode* parentElement, const std::string& currentPath); @@ -39,5 +38,4 @@ private: std::map m_values; }; - #endif // CONFIG_MANAGER_H diff --git a/src/lib/utility/FileSystem.cpp b/src/lib/utility/FileSystem.cpp index f48da4a7..4ff3e45b 100644 --- a/src/lib/utility/FileSystem.cpp +++ b/src/lib/utility/FileSystem.cpp @@ -8,6 +8,7 @@ std::vector FileSystem::getSourceFilesFromDirectory( ) { std::vector files; + if (boost::filesystem::is_directory(path)) { boost::filesystem::recursive_directory_iterator it(path); @@ -27,6 +28,7 @@ std::vector FileSystem::getSourceFilesFromDirectory( bool FileSystem::isValidExtension(const std::string& filepath, const std::vector& extensions) { boost::filesystem::path path(filepath); + for(std::string extension : extensions) { if(path.extension() == extension) @@ -41,3 +43,4 @@ bool FileSystem::exists(const std::string& path) { return boost::filesystem::exists(boost::filesystem::path(path)); } + diff --git a/src/lib/utility/logging/LogManagerImplementation.cpp b/src/lib/utility/logging/LogManagerImplementation.cpp index 4201fa1f..92b008c9 100644 --- a/src/lib/utility/logging/LogManagerImplementation.cpp +++ b/src/lib/utility/logging/LogManagerImplementation.cpp @@ -1,5 +1,7 @@ #include "LogManagerImplementation.h" +#include + LogManagerImplementation::LogManagerImplementation() { } diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 52876a2d..e46416d9 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -6,6 +6,7 @@ add_files( FileSystemTestSuite.h LogManagerTestSuite.h MessageQueueTestSuite.h + ProjectSettingsTestSuite.h TestSuiteFixture.cpp TestSuiteFixture.h TextAccessTestSuite.h diff --git a/src/test/ProjectSettingsTestSuite.h b/src/test/ProjectSettingsTestSuite.h new file mode 100644 index 00000000..740042cb --- /dev/null +++ b/src/test/ProjectSettingsTestSuite.h @@ -0,0 +1,18 @@ +#include + +#include "ProjectSettings.h" + +class ProjectSettingsTestSuite : public CxxTest::TestSuite +{ +public: + void test_loading_projectSettings_from_file() + { + TS_ASSERT(ProjectSettings::getInstance()->load("data/test_ProjectSettings.xml")); + } + + void test_load_sourcepath_from_file() + { + ProjectSettings::getInstance()->load("data/test_ProjectSettings.xml"); + TS_ASSERT_EQUALS(ProjectSettings::getInstance()->getSourcePath(), "data"); + } +};