logic : projectsettings loading
loading projectsetting via file review id = 21 fortune cookie message = in dreams and in life, nothing is impossible
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<config>
|
||||
<SourcePath>the/awesome/path/to/the/code</SourcePath>
|
||||
<SourcePath>data</SourcePath>
|
||||
</config>
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -18,5 +18,4 @@ private:
|
||||
static std::shared_ptr<ApplicationSettings> s_instance;
|
||||
};
|
||||
|
||||
|
||||
#endif // APPLICATION_SETTINGS_H
|
||||
|
||||
+15
-7
@@ -1,9 +1,11 @@
|
||||
#include "Project.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "data/parser/cxx/CxxParser.h"
|
||||
#include "utility/FileSystem.h"
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
std::shared_ptr<Project> Project::create(
|
||||
std::shared_ptr<CodeAccess> 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<std::string> filePaths;
|
||||
filePaths.push_back("data/test_code.cpp");
|
||||
if (ProjectSettings::getInstance()->getSourcePath() != "")
|
||||
{
|
||||
std::vector<std::string> 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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-5
@@ -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<Storage> m_storage;
|
||||
|
||||
std::shared_ptr<CodeAccess> m_codeAccess;
|
||||
std::shared_ptr<GraphAccess> m_graphAccess;
|
||||
};
|
||||
|
||||
@@ -1 +1,71 @@
|
||||
#include "ProjectSettings.h"
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
#include "utility/text/TextAccess.h"
|
||||
|
||||
#include "utility/FileSystem.h"
|
||||
|
||||
std::shared_ptr<ProjectSettings> ProjectSettings::s_instance;
|
||||
|
||||
std::shared_ptr<ProjectSettings> ProjectSettings::getInstance()
|
||||
{
|
||||
if (!s_instance)
|
||||
{
|
||||
s_instance = std::shared_ptr<ProjectSettings>(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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,31 @@
|
||||
#ifndef PROJECT_SETTINGS_H
|
||||
#define PROJECT_SETTINGS_H
|
||||
|
||||
#include <string>
|
||||
#include <memory.h>
|
||||
|
||||
#include "utility/ConfigManager.h"
|
||||
|
||||
class ProjectSettings
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<ProjectSettings> 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<ProjectSettings> s_instance;
|
||||
ProjectSettings();
|
||||
ProjectSettings(const ProjectSettings&);
|
||||
void operator=(const ProjectSettings&);
|
||||
|
||||
std::shared_ptr<ConfigManager> m_config;
|
||||
};
|
||||
|
||||
|
||||
#endif // PROJECT_SETTINGS_H
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "utility/ConfigManager.h"
|
||||
|
||||
#include "logging/logging.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
|
||||
std::shared_ptr<ConfigManager> ConfigManager::createAndLoad(const std::shared_ptr<TextAccess> 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)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef CONFIG_MANAGER_H
|
||||
#define CONFIG_MANAGER_H
|
||||
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -31,7 +30,7 @@ public:
|
||||
private:
|
||||
ConfigManager(const std::shared_ptr<TextAccess> 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<std::string, std::string> m_values;
|
||||
};
|
||||
|
||||
|
||||
#endif // CONFIG_MANAGER_H
|
||||
|
||||
@@ -8,6 +8,7 @@ std::vector<std::string> FileSystem::getSourceFilesFromDirectory(
|
||||
)
|
||||
{
|
||||
std::vector<std::string> files;
|
||||
|
||||
if (boost::filesystem::is_directory(path))
|
||||
{
|
||||
boost::filesystem::recursive_directory_iterator it(path);
|
||||
@@ -27,6 +28,7 @@ std::vector<std::string> FileSystem::getSourceFilesFromDirectory(
|
||||
bool FileSystem::isValidExtension(const std::string& filepath, const std::vector<std::string>& 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));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "LogManagerImplementation.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
LogManagerImplementation::LogManagerImplementation()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ add_files(
|
||||
FileSystemTestSuite.h
|
||||
LogManagerTestSuite.h
|
||||
MessageQueueTestSuite.h
|
||||
ProjectSettingsTestSuite.h
|
||||
TestSuiteFixture.cpp
|
||||
TestSuiteFixture.h
|
||||
TextAccessTestSuite.h
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#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");
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user