src: Project Refactoring

* Added language specific Project and ProjectSettings
* moved project specific code from Application to Project
* made Application a singleton
* added handleDialog method to Application which displays a dialog window and waits for user input
* Added ScopedFunctor that executes a function when deleted
This commit is contained in:
malte_langkabel
2016-08-11 12:17:13 +02:00
parent 6b51c7cfe4
commit c847fba568
63 changed files with 1375 additions and 874 deletions
+96 -168
View File
@@ -23,55 +23,56 @@
#include "settings/ColorScheme.h"
#include "settings/ProjectSettings.h"
std::shared_ptr<Application> Application::create(
void Application::createInstance(
const Version& version, ViewFactory* viewFactory, NetworkFactory* networkFactory
){
Version::setApplicationVersion(version);
loadSettings();
std::shared_ptr<Application> ptr(new Application());
TaskScheduler::getInstance();
MessageQueue::getInstance();
ptr->m_storageCache = std::make_shared<StorageCache>();
bool hasGui = (viewFactory != nullptr);
s_instance = std::shared_ptr<Application>(new Application(hasGui));
ptr->m_componentManager = ComponentManager::create(viewFactory, ptr->m_storageCache.get());
s_instance->m_storageCache = std::make_shared<StorageCache>();
ptr->m_mainView = viewFactory->createMainView();
ptr->m_mainView->setTitle("Coati");
if (viewFactory != nullptr)
{
s_instance->m_componentManager = ComponentManager::create(viewFactory, s_instance->m_storageCache.get());
MessageDispatchWhenLicenseValid(std::make_shared<MessageShowStartScreen>()).dispatch();
s_instance->m_mainView = viewFactory->createMainView();
s_instance->m_mainView->setTitle("Coati");
ptr->m_componentManager->setup(ptr->m_mainView.get());
ptr->m_mainView->loadLayout();
MessageDispatchWhenLicenseValid(std::make_shared<MessageShowStartScreen>()).dispatch();
ptr->m_project = Project::create(ptr->m_storageCache.get());
s_instance->m_componentManager->setup(s_instance->m_mainView.get());
s_instance->m_mainView->loadLayout();
}
ptr->m_ideCommunicationController = networkFactory->createIDECommunicationController(ptr->m_storageCache.get());
if (networkFactory != nullptr)
{
s_instance->m_ideCommunicationController = networkFactory->createIDECommunicationController(s_instance->m_storageCache.get());
}
ptr->startMessagingAndScheduling();
return ptr;
s_instance->startMessagingAndScheduling();
}
std::shared_ptr<Application> Application::create(const Version& version)
std::shared_ptr<Application> Application::getInstance()
{
Version::setApplicationVersion(version);
loadSettings();
return s_instance;
}
std::shared_ptr<Application> ptr(new Application(false));
ptr->m_storageCache = std::make_shared<StorageCache>();
ptr->m_project = Project::create(ptr->m_storageCache.get());
ptr->startMessagingAndScheduling();
return ptr;
void Application::destroyInstance()
{
s_instance.reset();
}
void Application::loadSettings()
{
ApplicationSettings::getInstance()->load(FilePath(UserPaths::getAppSettingsPath()));
loadStyle(ApplicationSettings::getInstance()->getColorSchemePath());
std::shared_ptr<ApplicationSettings> settings = ApplicationSettings::getInstance();
settings->load(FilePath(UserPaths::getAppSettingsPath()));
loadStyle(settings->getColorSchemePath());
}
void Application::loadStyle(const FilePath& colorSchemePath)
@@ -80,6 +81,8 @@ void Application::loadStyle(const FilePath& colorSchemePath)
GraphViewStyle::loadStyleSettings();
}
std::shared_ptr<Application> Application::s_instance;
Application::Application(bool withGUI)
: m_hasGUI(withGUI)
{
@@ -96,29 +99,55 @@ Application::~Application()
}
}
const std::shared_ptr<Project> Application::getCurrentProject()
{
return m_project;
}
bool Application::hasGUI()
{
return m_hasGUI;
}
int Application::handleDialog(const std::string& message)
{
return m_mainView->confirm(message);
}
int Application::handleDialog(const std::string& message, const std::vector<std::string>& options)
{
return m_mainView->confirm(message, options);
}
void Application::setTitle(const std::string& title)
{
m_mainView->setTitle(title);
}
void Application::createAndLoadProject(const FilePath& projectSettingsFilePath)
{
MessageStatus("Loading Project: " + projectSettingsFilePath.str(), false, true).dispatch();
loadSettings();
updateRecentProjects(projectSettingsFilePath);
m_storageCache->clear();
m_project = Project::create(m_storageCache.get());
loadProject(projectSettingsFilePath);
if (m_hasGUI)
try
{
m_mainView->setTitle("Coati - " + projectSettingsFilePath.fileName());
m_mainView->hideStartScreen();
updateRecentProjects(projectSettingsFilePath);
m_componentManager->refreshViews();
m_storageCache->clear();
m_project = Project::create(projectSettingsFilePath, m_storageCache.get());
loadProject(projectSettingsFilePath);
if (m_hasGUI)
{
setTitle("Coati - " + projectSettingsFilePath.fileName());
m_mainView->hideStartScreen();
m_componentManager->refreshViews();
}
}
catch (...)
{
LOG_ERROR_STREAM(<< "Failed to load project.");
MessageStatus("Failed to load project.", true).dispatch();
}
}
@@ -128,82 +157,25 @@ void Application::loadProject(const FilePath& projectSettingsFilePath)
{
m_componentManager->clearComponents();
}
bool reparse = false;
Project::ProjectState state = m_project->load(projectSettingsFilePath);
if (state == Project::PROJECT_OUTDATED)
{
if (m_hasGUI && !isTrial())
{
std::vector<std::string> options;
options.push_back("Yes");
options.push_back("No");
int result = m_mainView->confirm(
"The project file was changed after the last indexing. The project needs to get fully reindexed to "
"reflect the current project state. Do you want to reindex the project?", options);
reparse = (result == 0);
}
}
else if (state == Project::PROJECT_OUTVERSIONED)
{
MessageStatus("Can't load project").dispatch();
reparse = true;
if (m_hasGUI)
{
std::vector<std::string> options;
options.push_back("Yes");
options.push_back("No");
int result = m_mainView->confirm(
"This project was indexed with a different version of Coati. It needs to be fully reindexed to be used "
"with this version of Coati. Do you want to reindex the project?", options);
reparse = (result == 0);
}
}
if (reparse)
{
m_project->clearStorage();
m_project->load(projectSettingsFilePath);
}
}
void Application::refreshProject()
void Application::refreshProject(bool force)
{
MessageStatus("Refreshing Project").dispatch();
FilePath cdbPath = ProjectSettings::getInstance()->getCompilationDatabasePath();
if (!cdbPath.empty() && !cdbPath.exists())
{
MessageStatus("Can't refresh project").dispatch();
if (m_hasGUI)
{
std::vector<std::string> options;
options.push_back("Ok");
m_mainView->confirm(
"Can't refresh. The compilation database of the project does not exist anymore: " + cdbPath.str(),
options);
}
return;
}
m_storageCache->clear();
if (m_hasGUI)
{
m_componentManager->refreshViews();
}
Project::ProjectState state = m_project->reload();
if (state != Project::PROJECT_LOADED)
if (force)
{
MessageStatus("Can't refresh project").dispatch();
loadProject(m_project->getProjectSettingsFilePath());
m_project->forceRefresh();
}
else
{
m_project->refresh();
}
}
@@ -228,83 +200,41 @@ void Application::handleMessage(MessageLoadProject* message)
{
TRACE("app load project");
loadSettings();
FilePath projectSettingsFilePath(message->projectSettingsFilePath);
if (projectSettingsFilePath.empty())
{
projectSettingsFilePath = m_project->getProjectSettingsFilePath();
if (projectSettingsFilePath.empty())
{
return;
}
return;
}
if (message->forceRefresh && !isTrial())
{
if (m_hasGUI)
{
FilePath path = projectSettingsFilePath;
FilePath oldPath = m_project->getProjectSettingsFilePath();
std::vector<std::string> options;
options.push_back("Yes");
options.push_back("No");
int result = m_mainView->confirm(
"Some settings were changed, the project needs to be fully reindexed. "
"Do you want to reindex the project?", options);
if (oldPath.exists() && oldPath != path)
if (result == 1)
{
std::vector<std::string> options;
options.push_back("Yes");
options.push_back("No");
int result = m_mainView->confirm(
"You changed the project location. The project file (.coatiproject) and the database file (.coatidb) will "
"be moved to the new location. Do you want to keep a copy of the files in the previous location?"
, options);
FilePath dbPath = FilePath(path).replaceExtension("coatidb");
FilePath olddbPath = FilePath(oldPath).replaceExtension("coatidb");
m_project = Project::create(m_storageCache.get());
if (result == 0)
if (!m_project || projectSettingsFilePath != m_project->getProjectSettingsFilePath())
{
FileSystem::copyFile(olddbPath, dbPath);
}
else
{
FileSystem::remove(oldPath);
FileSystem::rename(olddbPath, dbPath);
}
}
else
{
std::vector<std::string> options;
options.push_back("Yes");
options.push_back("No");
int result = m_mainView->confirm(
"Some settings were changed, the project needs to be fully reindexed. "
"Do you want to reindex the project?", options);
if (result == 1)
{
m_project->load(projectSettingsFilePath);
updateRecentProjects(projectSettingsFilePath);
m_mainView->setTitle("Coati - " + projectSettingsFilePath.fileName());
createAndLoadProject(projectSettingsFilePath);
return;
}
}
}
m_project->clearStorage();
refreshProject(true);
}
else if (projectSettingsFilePath == m_project->getProjectSettingsFilePath())
{
return;
}
try
else if (!m_project || projectSettingsFilePath != m_project->getProjectSettingsFilePath())
{
createAndLoadProject(projectSettingsFilePath);
}
catch (...)
{
LOG_ERROR_STREAM(<< "Failed to load project.");
MessageStatus("Failed to load project.", true).dispatch();
}
}
void Application::handleMessage(MessageRefresh* message)
@@ -318,16 +248,14 @@ void Application::handleMessage(MessageRefresh* message)
if (message->uiOnly)
{
m_componentManager->refreshViews();
}
else if (message->all)
{
m_project->clearStorage();
refreshProject();
if (m_hasGUI)
{
m_componentManager->refreshViews();
}
}
else
{
refreshProject();
refreshProject(message->all);
}
}
+15 -4
View File
@@ -27,19 +27,30 @@ class Application
, public MessageListener<MessageSwitchColorScheme>
{
public:
static std::shared_ptr<Application> create(const Version& version, ViewFactory* viewFactory, NetworkFactory* networkFactory);
static std::shared_ptr<Application> create(const Version& version);
static void createInstance(const Version& version, ViewFactory* viewFactory, NetworkFactory* networkFactory);
static std::shared_ptr<Application> getInstance();
static void destroyInstance();
static void loadSettings();
static void loadStyle(const FilePath& colorSchemePath);
~Application();
const std::shared_ptr<Project> getCurrentProject();
void createAndLoadProject(const FilePath& projectSettingsFilePath);
void loadProject(const FilePath& projectSettingsFilePath);
void refreshProject();
void refreshProject(bool force);
bool hasGUI();
int handleDialog(const std::string& message);
int handleDialog(const std::string& message, const std::vector<std::string>& options);
void setTitle(const std::string& title);
private:
static std::shared_ptr<Application> s_instance;
Application(bool withGUI=true);
virtual void handleMessage(MessageActivateWindow* message);
@@ -52,7 +63,7 @@ private:
void updateRecentProjects(const FilePath& projectSettingsFilePath);
bool m_hasGUI;
const bool m_hasGUI;
std::shared_ptr<Project> m_project;
std::shared_ptr<StorageCache> m_storageCache;
+12
View File
@@ -195,6 +195,12 @@ add_files(
settings/ApplicationSettings.h
settings/ColorScheme.cpp
settings/ColorScheme.h
settings/CxxProjectSettings.cpp
settings/CxxProjectSettings.h
settings/JavaProjectSettings.cpp
settings/JavaProjectSettings.h
settings/LanguageType.cpp
settings/LanguageType.h
settings/ProjectSettings.cpp
settings/ProjectSettings.h
settings/Settings.cpp
@@ -329,6 +335,8 @@ add_files(
utility/Property.h
utility/ResourcePaths.cpp
utility/ResourcePaths.h
utility/ScopedFunctor.cpp
utility/ScopedFunctor.h
utility/ScopedSwitcher.h
utility/TimePoint.cpp
utility/TimePoint.h
@@ -346,7 +354,11 @@ add_files(
Application.cpp
Application.h
CxxProject.cpp
CxxProject.h
isTrial.h
JavaProject.cpp
JavaProject.h
LicenseChecker.cpp
LicenseChecker.h
Project.cpp
+132
View File
@@ -0,0 +1,132 @@
#include "CxxProject.h"
#include "settings/ApplicationSettings.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/utility.h"
#include "Application.h"
#include "utility/file/FileRegister.h"
#include "utility/file/FileSystem.h"
#include "data/parser/cxx/TaskParseCxx.h"
CxxProject::~CxxProject()
{
}
std::shared_ptr<ProjectSettings> CxxProject::getProjectSettings()
{
return m_projectSettings;
}
const std::shared_ptr<ProjectSettings> CxxProject::getProjectSettings() const
{
return m_projectSettings;
}
CxxProject::CxxProject(std::shared_ptr<CxxProjectSettings> projectSettings, StorageAccessProxy* storageAccessProxy)
: Project(storageAccessProxy)
, m_projectSettings(projectSettings)
{
}
bool CxxProject::allowsRefresh()
{
FilePath cdbPath = m_projectSettings->getCompilationDatabasePath();
if (!cdbPath.empty() && !cdbPath.exists())
{
MessageStatus("Can't refresh project").dispatch();
if (Application::getInstance()->hasGUI())
{
std::vector<std::string> options;
options.push_back("Ok");
Application::getInstance()->handleDialog(
"Can't refresh. The compilation database of the project does not exist anymore: " + cdbPath.str(),
options
);
}
return false;
}
return true;
}
std::shared_ptr<Task> CxxProject::createIndexerTask(
PersistentStorage* storage,
std::shared_ptr<std::mutex> storageMutex,
std::shared_ptr<FileRegister> fileRegister)
{
return std::make_shared<TaskParseCxx>(
storage,
storageMutex,
fileRegister,
getParserArguments()
);
}
void CxxProject::updateFileManager(FileManager& fileManager)
{
std::vector<FilePath> sourcePaths = m_projectSettings->getAbsoluteSourcePaths();
std::vector<FilePath> headerPaths = sourcePaths;
std::vector<std::string> sourceExtensions;
if (m_projectSettings->getCompilationDatabasePath().exists())
{
sourcePaths = TaskParseCxx::getSourceFilesFromCDB(m_projectSettings->getCompilationDatabasePath());
}
else
{
sourceExtensions = m_projectSettings->getSourceExtensions();
}
std::vector<FilePath> excludePaths = m_projectSettings->getAbsoluteExcludePaths();
fileManager.setPaths(sourcePaths, headerPaths, excludePaths, sourceExtensions);
}
Parser::Arguments CxxProject::getParserArguments() const
{
std::shared_ptr<ApplicationSettings> appSettings = ApplicationSettings::getInstance();
Parser::Arguments args;
utility::append(args.compilerFlags, m_projectSettings->getCompilerFlags());
// MAYBE DO THIS IN PARSER! AND ONLY ADD THE PATH OF THE CURRENT FILE!!
// Add the source paths as HeaderSearchPaths as well, so clang will also look here when searching include files.
//utility::append(args.systemHeaderSearchPaths, m_fileManager.getSourcePaths());
utility::append(args.systemHeaderSearchPaths, m_projectSettings->getAbsoluteHeaderSearchPaths());
utility::append(args.systemHeaderSearchPaths, appSettings->getHeaderSearchPathsExpanded());
// Add all subdirectories of the header search paths
if (m_projectSettings->getUseSourcePathsForHeaderSearch())
{
std::vector<FilePath> headerSearchSubPaths;
for (FilePath p : m_projectSettings->getSourcePaths())
{
utility::append(headerSearchSubPaths, FileSystem::getSubDirectories(p));
}
utility::append(args.systemHeaderSearchPaths, utility::unique(headerSearchSubPaths));
}
utility::append(args.frameworkSearchPaths, m_projectSettings->getAbsoluteFrameworkSearchPaths());
utility::append(args.frameworkSearchPaths, appSettings->getFrameworkSearchPathsExpanded());
args.language = m_projectSettings->getLanguage();
args.languageStandard = m_projectSettings->getStandard();
args.compilationDatabasePath = m_projectSettings->getCompilationDatabasePath();
return args;
}
+39
View File
@@ -0,0 +1,39 @@
#ifndef CXX_PROJECT_H
#define CXX_PROJECT_H
#include <memory>
#include "settings/CxxProjectSettings.h"
#include "Project.h"
class CxxProject: public Project
{
public:
virtual ~CxxProject();
protected:
virtual std::shared_ptr<ProjectSettings> getProjectSettings();
virtual const std::shared_ptr<ProjectSettings> getProjectSettings() const;
private:
CxxProject(std::shared_ptr<CxxProjectSettings> projectSettings, StorageAccessProxy* storageAccessProxy);
CxxProject(const CxxProject&);
virtual bool allowsRefresh();
virtual std::shared_ptr<Task> createIndexerTask(
PersistentStorage* storage,
std::shared_ptr<std::mutex> storageMutex,
std::shared_ptr<FileRegister> fileRegister);
virtual void updateFileManager(FileManager& fileManager);
Parser::Arguments getParserArguments() const;
std::shared_ptr<CxxProjectSettings> m_projectSettings;
friend Project;
};
#endif // CXX_PROJECT_H
+80
View File
@@ -0,0 +1,80 @@
#include "JavaProject.h"
#include "data/parser/java/JavaEnvironmentFactory.h"
#include "data/parser/java/TaskParseJava.h"
JavaProject::~JavaProject()
{
}
std::shared_ptr<ProjectSettings> JavaProject::getProjectSettings()
{
return m_projectSettings;
}
const std::shared_ptr<ProjectSettings> JavaProject::getProjectSettings() const
{
return m_projectSettings;
}
JavaProject::JavaProject(std::shared_ptr<JavaProjectSettings> projectSettings, StorageAccessProxy* storageAccessProxy)
: Project(storageAccessProxy)
, m_projectSettings(projectSettings)
{
if (!JavaEnvironmentFactory::getInstance())
{
JavaEnvironmentFactory::createInstance(
"data/java/asm-5.0.3.jar;"
"data/java/cglib-3.1.jar;"
"data/java/easymock-3.3.1.jar;"
"data/java/guava-18.0.jar;"
"data/java/hamcrest-core-1.3.jar;"
"data/java/java-indexer.jar;"
"data/java/javaparser-core-2.4.1-SNAPSHOT.jar;"
"data/java/javaslang-2.0.0-beta.jar;"
"data/java/javassist-3.19.0-GA.jar;"
"data/java/java-symbol-solver-core-0.2.0-SNAPSHOT.jar;"
"data/java/java-symbol-solver-logic-0.2.0-SNAPSHOT.jar;"
"data/java/java-symbol-solver-model-0.2.0-SNAPSHOT.jar;"
"data/java/objenesis-2.1.jar;"
);
}
}
std::shared_ptr<Task> JavaProject::createIndexerTask(
PersistentStorage* storage,
std::shared_ptr<std::mutex> storageMutex,
std::shared_ptr<FileRegister> fileRegister)
{
Parser::Arguments arguments;
for (FilePath classpath: m_projectSettings->getAbsoluteClasspaths())
{
arguments.javaClassPaths.push_back(classpath.str());
}
for (FilePath sourcePath: m_projectSettings->getAbsoluteSourcePaths())
{
if (sourcePath.extension().empty())
{
arguments.javaClassPaths.push_back(sourcePath.str());
}
}
return std::make_shared<TaskParseJava>(
storage,
storageMutex,
fileRegister,
arguments
);
}
void JavaProject::updateFileManager(FileManager& fileManager)
{
std::vector<FilePath> sourcePaths = m_projectSettings->getAbsoluteSourcePaths();
std::vector<FilePath> headerPaths = sourcePaths;
std::vector<std::string> sourceExtensions = m_projectSettings->getSourceExtensions();
std::vector<FilePath> excludePaths = m_projectSettings->getAbsoluteExcludePaths();
fileManager.setPaths(sourcePaths, headerPaths, excludePaths, sourceExtensions);
}
+34
View File
@@ -0,0 +1,34 @@
#ifndef JAVA_PROJECT_H
#define JAVA_PROJECT_H
#include <memory>
#include "settings/JavaProjectSettings.h"
#include "Project.h"
class JavaProject: public Project
{
public:
virtual ~JavaProject();
protected:
virtual std::shared_ptr<ProjectSettings> getProjectSettings();
virtual const std::shared_ptr<ProjectSettings> getProjectSettings() const;
private:
JavaProject(std::shared_ptr<JavaProjectSettings> projectSettings, StorageAccessProxy* storageAccessProxy);
JavaProject(const JavaProject&);
virtual std::shared_ptr<Task> createIndexerTask(
PersistentStorage* storage,
std::shared_ptr<std::mutex> storageMutex,
std::shared_ptr<FileRegister> fileRegister);
virtual void updateFileManager(FileManager& fileManager);
std::shared_ptr<JavaProjectSettings> m_projectSettings;
friend Project;
};
#endif // JAVA_PROJECT_H
+158 -229
View File
@@ -2,12 +2,11 @@
#include "data/access/StorageAccessProxy.h"
#include "data/graph/Token.h"
#include "data/parser/cxx/TaskParseCxx.h"
#include "data/parser/cxx/TaskParseWrapper.h"
#include "data/parser/java/JavaEnvironmentFactory.h"
#include "data/parser/java/TaskParseJava.h"
#include "data/PersistentStorage.h"
#include "data/TaskCleanStorage.h"
#include "settings/ApplicationSettings.h"
#include "settings/ProjectSettings.h"
@@ -17,103 +16,201 @@
#include "utility/messaging/type/MessageFinishedParsing.h"
#include "utility/scheduling/TaskGroupSequential.h"
#include "utility/scheduling/TaskGroupParallel.h"
#include "utility/text/TextAccess.h"
#include "utility/utility.h"
#include "utility/utilityString.h"
#include "utility/Version.h"
std::shared_ptr<Project> Project::create(StorageAccessProxy* storageAccessProxy)
#include "Application.h"
#include "CxxProject.h"
#include "JavaProject.h"
#include "isTrial.h"
std::shared_ptr<Project> Project::create(const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy)
{
std::shared_ptr<Project> ptr(new Project(storageAccessProxy));
return ptr;
std::shared_ptr<Project> project;
switch (ProjectSettings::getLanguageOfProject(projectSettingsFile))
{
case LANGUAGE_C:
case LANGUAGE_CPP:
{
project = std::shared_ptr<CxxProject>(new CxxProject(
std::make_shared<CxxProjectSettings>(projectSettingsFile), storageAccessProxy
));
}
break;
case LANGUAGE_JAVA:
{
project = std::shared_ptr<JavaProject>(new JavaProject(
std::make_shared<JavaProjectSettings>(projectSettingsFile), storageAccessProxy
));
}
break;
}
if (project)
{
project->load();
}
return project;
}
Project::~Project()
{
}
const FilePath& Project::getProjectSettingsFilePath() const
void Project::refresh()
{
return m_projectSettingsFilepath;
if (allowsRefresh())
{
bool loadedSettings = getProjectSettings()->load();
updateFileManager(m_fileManager);
buildIndex();
m_state = PROJECT_STATE_LOADED;
}
}
Project::ProjectState Project::load(const FilePath& projectSettingsFile)
void Project::forceRefresh()
{
m_state = PROJECT_NONE;
bool success = true;
if (!projectSettingsFile.empty())
if (allowsRefresh())
{
success = ProjectSettings::getInstance()->load(projectSettingsFile);
clearStorage();
}
refresh();
}
if (success)
FilePath Project::getProjectSettingsFilePath() const
{
return getProjectSettings()->getFilePath();
}
std::string Project::getDescription() const
{
return getProjectSettings()->getDescription();
}
bool Project::settingsEqualExceptNameAndLocation(const ProjectSettings& otherSettings) const
{
return getProjectSettings()->equalsExceptNameAndLocation(otherSettings);
}
void Project::logStats() const
{
m_storage->logStats();
}
Project::Project(StorageAccessProxy* storageAccessProxy)
: m_storageAccessProxy(storageAccessProxy)
, m_state(PROJECT_STATE_NOT_LOADED)
{
}
void Project::load()
{
const std::shared_ptr<ProjectSettings> projectSettings = getProjectSettings();
bool loadedSettings = projectSettings->load();
if (loadedSettings)
{
setProjectSettingsFilePath(projectSettingsFile);
updateFileManager();
const FilePath projectSettingsPath = projectSettings->getFilePath();
const FilePath dbPath = FilePath(projectSettingsPath).replaceExtension("coatidb");
m_storage = std::make_shared<PersistentStorage>(dbPath);
m_storageAccessProxy->setSubject(m_storage.get());
if (m_storage->isEmpty())
{
m_state = PROJECT_STATE_EMPTY;
m_storage->setup();
}
else if (m_storage->isIncompatible())
{
m_state = PROJECT_STATE_OUTVERSIONED;
}
else if (TextAccess::createFromFile(projectSettingsPath.str())->getText() != m_storage->getProjectSettingsText())
{
m_state = PROJECT_STATE_OUTDATED;
}
else
{
m_state = PROJECT_STATE_LOADED;
}
updateFileManager(m_fileManager);
bool reparse = false;
switch (m_state)
{
case PROJECT_NONE:
break;
case PROJECT_STATE_EMPTY:
buildIndex();
m_state = PROJECT_STATE_LOADED;
break;
case PROJECT_STATE_OUTDATED:
if (Application::getInstance()->hasGUI() && !isTrial())
{
std::vector<std::string> options;
options.push_back("Yes");
options.push_back("No");
int result = Application::getInstance()->handleDialog(
"The project file was changed after the last indexing. The project needs to get fully reindexed to "
"reflect the current project state. Do you want to reindex the project?", options);
case PROJECT_EMPTY:
parseCode();
break;
reparse = (result == 0);
}
// dont break here.
case PROJECT_STATE_LOADED:
m_storage->finishParsing();
MessageFinishedParsing(0, 0, 0, true).dispatch();
break;
case PROJECT_STATE_OUTVERSIONED:
MessageStatus("Can't load project").dispatch();
case PROJECT_LOADED:
case PROJECT_OUTDATED:
m_storage->finishParsing();
MessageFinishedParsing(0, 0, 0, true).dispatch();
break;
reparse = true;
case PROJECT_OUTVERSIONED:
m_storage.reset();
break;
if (Application::getInstance()->hasGUI() && !isTrial())
{
std::vector<std::string> options;
options.push_back("Yes");
options.push_back("No");
int result = Application::getInstance()->handleDialog(
"This project was indexed with a different version of Coati. It needs to be fully reindexed to be used "
"with this version of Coati. Do you want to reindex the project?", options);
reparse = (result == 0);
}
m_storage.reset();
break;
}
if (reparse)
{
forceRefresh();
}
}
return m_state;
}
Project::ProjectState Project::reload()
{
if (m_state == PROJECT_LOADED &&
FileSystem::getFileInfoForPath(m_projectSettingsFilepath).lastWriteTime >
FileSystem::getFileInfoForPath(m_storage->getDbFilePath()).lastWriteTime)
{
m_state = PROJECT_OUTDATED;
}
else if (!m_projectSettingsFilepath.empty() && (m_state == PROJECT_EMPTY || m_state == PROJECT_LOADED))
{
ProjectSettings::getInstance()->load(m_projectSettingsFilepath);
updateFileManager();
parseCode();
}
return m_state;
}
void Project::clearStorage()
{
if (m_state == PROJECT_OUTVERSIONED)
if (!m_storage)
{
loadStorage(m_projectSettingsFilepath);
const FilePath projectSettingsPath = getProjectSettings()->getFilePath();
const FilePath dbPath = FilePath(projectSettingsPath).replaceExtension("coatidb");
m_storage = std::make_shared<PersistentStorage>(dbPath);
}
if (m_storage)
{
m_storage->clear();
m_state = PROJECT_EMPTY;
m_state = PROJECT_STATE_EMPTY;
}
}
void Project::parseCode()
void Project::buildIndex()
{
if (m_projectSettingsFilepath.empty())
{
return;
}
m_storage->setProjectSettingsText(TextAccess::createFromFile(getProjectSettingsFilePath().str())->getText());
m_fileManager.fetchFilePaths(m_storage->getInfoOnAllFiles());
std::set<FilePath> addedFilePaths = m_fileManager.getAddedFilePaths();
@@ -131,7 +228,6 @@ void Project::parseCode()
filesToParse.insert(filesToParse.end(), addedFilePaths.begin(), addedFilePaths.end());
filesToParse.insert(filesToParse.end(), updatedFilePaths.begin(), updatedFilePaths.end());
m_state = PROJECT_LOADED;
if (!filesToClean.size() && !filesToParse.size())
{
@@ -147,28 +243,6 @@ void Project::parseCode()
std::shared_ptr<FileRegister> fileRegister = std::make_shared<FileRegister>(&m_fileManager, indexerThreadCount > 1);
fileRegister->setFilePaths(filesToParse);
if (ProjectSettings::getInstance()->getLanguage() == "Java")
{
if (!JavaEnvironmentFactory::getInstance())
{
JavaEnvironmentFactory::createInstance(
"data/java/asm-5.0.3.jar;"
"data/java/cglib-3.1.jar;"
"data/java/easymock-3.3.1.jar;"
"data/java/guava-18.0.jar;"
"data/java/hamcrest-core-1.3.jar;"
"data/java/java-indexer.jar;"
"data/java/javaparser-core-2.4.1-SNAPSHOT.jar;"
"data/java/javaslang-2.0.0-beta.jar;"
"data/java/javassist-3.19.0-GA.jar;"
"data/java/java-symbol-solver-core-0.2.0-SNAPSHOT.jar;"
"data/java/java-symbol-solver-logic-0.2.0-SNAPSHOT.jar;"
"data/java/java-symbol-solver-model-0.2.0-SNAPSHOT.jar;"
"data/java/objenesis-2.1.jar;"
);
}
}
std::shared_ptr<TaskParseWrapper> taskParserWrapper = std::make_shared<TaskParseWrapper>(
m_storage.get(),
fileRegister
@@ -182,160 +256,15 @@ void Project::parseCode()
for (int i = 0; i < indexerThreadCount; i++)
{
if (ProjectSettings::getInstance()->getLanguage() == "Java")
{
std::shared_ptr<ProjectSettings> projSettings = ProjectSettings::getInstance();
Parser::Arguments arguments;
for (FilePath classpath: projSettings->getAbsoluteJavaClasspaths())
{
arguments.javaClassPaths.push_back(classpath.str());
}
for (FilePath sourcePath: projSettings->getAbsoluteSourcePaths())
{
if (sourcePath.extension().empty())
{
arguments.javaClassPaths.push_back(sourcePath.str());
}
}
taskParallelIndexing->addTask(
std::make_shared<TaskParseJava>(
m_storage.get(),
storageMutex,
fileRegister,
arguments
)
);
}
else // c or cxx
{
taskParallelIndexing->addTask(std::make_shared<TaskParseCxx>(
m_storage.get(),
storageMutex,
fileRegister,
getParserArguments()
));
}
taskParallelIndexing->addTask(createIndexerTask(m_storage.get(), storageMutex, fileRegister));
}
Task::dispatch(taskSequential);
}
void Project::logStats() const
bool Project::allowsRefresh()
{
m_storage->logStats();
return true;
}
void Project::setProjectSettingsFilePath(const FilePath& path)
{
if (path.empty())
{
m_storage.reset();
m_state = PROJECT_NONE;
}
else
{
loadStorage(path);
if (m_storage->isEmpty())
{
m_state = PROJECT_EMPTY;
m_storage->setup();
}
else if (m_storage->isIncompatible())
{
m_state = PROJECT_OUTVERSIONED;
m_storage.reset();
}
else if (FileSystem::getFileInfoForPath(path).lastWriteTime > FileSystem::getFileInfoForPath(m_storage->getDbFilePath()).lastWriteTime)
{
m_state = PROJECT_OUTDATED;
}
else
{
m_state = PROJECT_LOADED;
}
}
m_storageAccessProxy->setSubject(m_storage.get());
m_projectSettingsFilepath = path;
}
void Project::loadStorage(const FilePath& path)
{
FilePath dbPath = FilePath(path).replaceExtension("coatidb");
if (!m_storage || path != m_projectSettingsFilepath || !dbPath.exists())
{
m_storage = std::make_shared<PersistentStorage>(dbPath);
}
}
void Project::updateFileManager()
{
std::shared_ptr<ProjectSettings> projSettings = ProjectSettings::getInstance();
std::vector<FilePath> sourcePaths = projSettings->getAbsoluteSourcePaths();
std::vector<FilePath> headerPaths = sourcePaths;
std::vector<std::string> sourceExtensions;
if (projSettings->getCompilationDatabasePath().exists())
{
sourcePaths = TaskParseCxx::getSourceFilesFromCDB(projSettings->getCompilationDatabasePath());
}
else
{
sourceExtensions = projSettings->getSourceExtensions();
}
std::vector<FilePath> excludePaths = projSettings->getAbsoluteExcludePaths();
m_fileManager.setPaths(sourcePaths, headerPaths, excludePaths, sourceExtensions);
}
Parser::Arguments Project::getParserArguments() const
{
std::shared_ptr<ProjectSettings> projSettings = ProjectSettings::getInstance();
std::shared_ptr<ApplicationSettings> appSettings = ApplicationSettings::getInstance();
Parser::Arguments args;
utility::append(args.compilerFlags, projSettings->getCompilerFlags());
// Add the source paths as HeaderSearchPaths as well, so clang will also look here when searching include files.
utility::append(args.systemHeaderSearchPaths, m_fileManager.getSourcePaths());
utility::append(args.systemHeaderSearchPaths, projSettings->getAbsoluteHeaderSearchPaths());
utility::append(args.systemHeaderSearchPaths, appSettings->getHeaderSearchPathsExpanded());
// Add all subdirectories of the header search paths
if (projSettings->getUseSourcePathsForHeaderSearch())
{
std::vector<FilePath> headerSearchSubPaths;
for (FilePath p : projSettings->getSourcePaths())
{
utility::append(headerSearchSubPaths, FileSystem::getSubDirectories(p));
}
utility::append(args.systemHeaderSearchPaths, utility::unique(headerSearchSubPaths));
}
utility::append(args.frameworkSearchPaths, projSettings->getAbsoluteFrameworkSearchPaths());
utility::append(args.frameworkSearchPaths, appSettings->getFrameworkSearchPathsExpanded());
args.language = projSettings->getLanguage();
args.languageStandard = projSettings->getStandard();
args.compilationDatabasePath = projSettings->getCompilationDatabasePath();
return args;
}
Project::Project(StorageAccessProxy* storageAccessProxy)
: m_storageAccessProxy(storageAccessProxy)
, m_state(PROJECT_NONE)
{
}
+36 -28
View File
@@ -2,57 +2,65 @@
#define PROJECT_H
#include <memory>
#include <mutex>
#include "utility/file/FileManager.h"
#include "data/parser/Parser.h"
#include "settings/ProjectSettings.h" // todo: use forward declaration here
#include "utility/scheduling/Task.h"
class PersistentStorage;
class StorageAccessProxy;
class FileRegister;
class Project
{
public:
enum ProjectState
{
PROJECT_NONE,
PROJECT_EMPTY,
PROJECT_LOADED,
PROJECT_OUTDATED,
PROJECT_OUTVERSIONED
};
static std::shared_ptr<Project> create(const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy);
static std::shared_ptr<Project> create(StorageAccessProxy* storageAccessProxy);
virtual ~Project();
~Project();
const FilePath& getProjectSettingsFilePath() const;
ProjectState load(const FilePath& projectSettingsFile);
ProjectState reload();
void clearStorage();
void refresh();
void forceRefresh();
FilePath getProjectSettingsFilePath() const;
std::string getDescription() const;
bool settingsEqualExceptNameAndLocation(const ProjectSettings& otherSettings) const;
void logStats() const;
private:
protected:
Project(StorageAccessProxy* storageAccessProxy);
virtual std::shared_ptr<ProjectSettings> getProjectSettings() = 0;
virtual const std::shared_ptr<ProjectSettings> getProjectSettings() const = 0;
private:
enum ProjectStateType
{
PROJECT_STATE_NOT_LOADED,
PROJECT_STATE_EMPTY,
PROJECT_STATE_LOADED,
PROJECT_STATE_OUTDATED,
PROJECT_STATE_OUTVERSIONED
};
Project(const Project&);
Project operator=(const Project&);
void parseCode();
void load();
void clearStorage();
void buildIndex();
void setProjectSettingsFilePath(const FilePath& path);
void loadStorage(const FilePath& path);
void updateFileManager();
Parser::Arguments getParserArguments() const;
virtual bool allowsRefresh();
virtual std::shared_ptr<Task> createIndexerTask(
PersistentStorage* storage,
std::shared_ptr<std::mutex> storageMutex,
std::shared_ptr<FileRegister> fileRegister) = 0;
virtual void updateFileManager(FileManager& fileManager) = 0;
StorageAccessProxy* const m_storageAccessProxy;
ProjectState m_state;
FilePath m_projectSettingsFilepath;
ProjectStateType m_state;
FileManager m_fileManager;
std::shared_ptr<PersistentStorage> m_storage;
@@ -14,7 +14,7 @@
#include "data/location/TokenLocationFile.h"
#include "data/location/TokenLocationLine.h"
#include "settings/ApplicationSettings.h"
#include "settings/ProjectSettings.h"
#include "Application.h"
CodeController::CodeController(StorageAccess* storageAccess)
: m_storageAccess(storageAccess)
@@ -47,7 +47,7 @@ void CodeController::handleMessage(MessageActivateAll* message)
statsSnippet.locationFile = std::make_shared<TokenLocationFile>(FilePath());
statsSnippet.locationFile->isWholeCopy = true;
statsSnippet.title = ProjectSettings::getInstance()->getFilePath().withoutExtension().fileName();
statsSnippet.title = Application::getInstance()->getCurrentProject()->getProjectSettingsFilePath().withoutExtension().fileName();
std::vector<std::string> description = getProjectDescription(statsSnippet.locationFile.get());
@@ -662,7 +662,7 @@ std::shared_ptr<TokenLocationFile> CodeController::getTokenLocationOfParentScope
std::vector<std::string> CodeController::getProjectDescription(TokenLocationFile* locationFile) const
{
std::string description = ProjectSettings::getInstance()->getDescription();
std::string description = Application::getInstance()->getCurrentProject()->getDescription();
if (!description.size())
{
+10
View File
@@ -248,6 +248,16 @@ bool PersistentStorage::isIncompatible() const
return m_sqliteStorage.isIncompatible();
}
std::string PersistentStorage::getProjectSettingsText() const
{
return m_sqliteStorage.getProjectSettingsText();
}
void PersistentStorage::setProjectSettingsText(std::string text)
{
m_sqliteStorage.setProjectSettingsText(text);
}
void PersistentStorage::setup()
{
m_sqliteStorage.setup();
+2
View File
@@ -52,6 +52,8 @@ public:
bool isEmpty() const;
bool isIncompatible() const;
std::string getProjectSettingsText() const;
void setProjectSettingsText(std::string text);
void setup();
void clear();
+11 -1
View File
@@ -11,7 +11,7 @@
#include "utility/utilityString.h"
#include "utility/Version.h"
const size_t SqliteStorage::STORAGE_VERSION = 2;
const size_t SqliteStorage::STORAGE_VERSION = 3;
SqliteStorage::SqliteStorage(const FilePath& dbFilePath)
: m_dbFilePath(dbFilePath)
@@ -90,6 +90,16 @@ bool SqliteStorage::isIncompatible() const
return false;
}
std::string SqliteStorage::getProjectSettingsText() const
{
return getMetaValue("project_settings");
}
void SqliteStorage::setProjectSettingsText(std::string text)
{
insertOrUpdateMetaValue("project_settings", text);
}
void SqliteStorage::setVersion()
{
setStorageVersion();
+2
View File
@@ -35,6 +35,8 @@ public:
bool isEmpty() const;
bool isIncompatible() const;
std::string getProjectSettingsText() const;
void setProjectSettingsText(std::string text);
void setVersion();
+124
View File
@@ -0,0 +1,124 @@
#include "settings/CxxProjectSettings.h"
#include "utility/utility.h"
CxxProjectSettings::CxxProjectSettings()
{
// setlanguage...
}
CxxProjectSettings::CxxProjectSettings(const FilePath& projectFilePath)
: ProjectSettings(projectFilePath)
{
// setlanguage...
}
CxxProjectSettings::CxxProjectSettings(std::string projectName, const FilePath& projectFileLocation)
: ProjectSettings(projectName, projectFileLocation)
{
// setlanguage...
}
CxxProjectSettings::~CxxProjectSettings()
{
}
bool CxxProjectSettings::equalsExceptNameAndLocation(const ProjectSettings& other) const
{
if (other.getLanguage() == getLanguage())
{
const CxxProjectSettings* typedOther = dynamic_cast<const CxxProjectSettings*>(&other);
return(
ProjectSettings::equalsExceptNameAndLocation(other)// &&
// utility::isPermutation<FilePath>(getClasspaths(), typedOther->getClasspaths())
);
}
return false;
}
std::vector<FilePath> CxxProjectSettings::getHeaderSearchPaths() const
{
return getPathValues("source/header_search_paths/header_search_path");
}
std::vector<FilePath> CxxProjectSettings::getAbsoluteHeaderSearchPaths() const
{
std::vector<FilePath> paths = getHeaderSearchPaths();
expandPaths(paths);
makePathsAbsolute(paths);
return paths;
}
bool CxxProjectSettings::setHeaderSearchPaths(const std::vector<FilePath>& headerSearchPaths)
{
return setPathValues("source/header_search_paths/header_search_path", headerSearchPaths);
}
std::vector<FilePath> CxxProjectSettings::getFrameworkSearchPaths() const
{
return getPathValues("source/framework_search_paths/framework_search_path");
}
std::vector<FilePath> CxxProjectSettings::getAbsoluteFrameworkSearchPaths() const
{
std::vector<FilePath> paths = getFrameworkSearchPaths();
expandPaths(paths);
makePathsAbsolute(paths);
return paths;
}
bool CxxProjectSettings::setFrameworkSearchPaths(const std::vector<FilePath>& frameworkSearchPaths)
{
return setPathValues("source/framework_search_paths/framework_search_path", frameworkSearchPaths);
}
std::vector<std::string> CxxProjectSettings::getCompilerFlags() const
{
std::vector<std::string> defaultValues;
return getValues("source/compiler_flags/compiler_flag", defaultValues);
}
bool CxxProjectSettings::setCompilerFlags(const std::vector<std::string>& compilerFlags)
{
return setValues("source/compiler_flags/compiler_flag", compilerFlags);
}
bool CxxProjectSettings::getUseSourcePathsForHeaderSearch() const
{
return getValue<bool>("source/use_source_paths_for_header_search", false);
}
bool CxxProjectSettings::setUseSourcePathsForHeaderSearch(bool useSourcePathsForHeaderSearch)
{
return setValue<bool>("source/use_source_paths_for_header_search", useSourcePathsForHeaderSearch);
}
FilePath CxxProjectSettings::getVisualStudioSolutionPath() const
{
return FilePath(getValue<std::string>("source/build_file_path/vs_solution_path", ""));
}
bool CxxProjectSettings::setVisualStudioSolutionPath(const FilePath& visualStudioSolutionPath)
{
return setValue<std::string>("source/build_file_path/vs_solution_path", visualStudioSolutionPath.str());
}
FilePath CxxProjectSettings::getCompilationDatabasePath() const
{
return FilePath(getValue<std::string>("source/build_file_path/compilation_db_path", ""));
}
bool CxxProjectSettings::setCompilationDatabasePath(const FilePath& compilationDatabasePath)
{
return setValue<std::string>("source/build_file_path/compilation_db_path", compilationDatabasePath.str());
}
std::vector<std::string> CxxProjectSettings::getDefaultSourceExtensions() const
{
std::vector<std::string> defaultValues;
defaultValues.push_back(".c");
defaultValues.push_back(".cpp");
defaultValues.push_back(".cxx");
defaultValues.push_back(".cc");
return defaultValues;
}
+40
View File
@@ -0,0 +1,40 @@
#ifndef CXX_PROJECT_SETTINGS_H
#define CXX_PROJECT_SETTINGS_H
#include "settings/ProjectSettings.h"
class CxxProjectSettings: public ProjectSettings
{
public:
CxxProjectSettings();
CxxProjectSettings(const FilePath& projectFilePath);
CxxProjectSettings(std::string projectName, const FilePath& projectFileLocation);
virtual ~CxxProjectSettings();
virtual bool equalsExceptNameAndLocation(const ProjectSettings& other) const;
std::vector<FilePath> getHeaderSearchPaths() const;
std::vector<FilePath> getAbsoluteHeaderSearchPaths() const;
bool setHeaderSearchPaths(const std::vector<FilePath>& headerSearchPaths);
std::vector<FilePath> getFrameworkSearchPaths() const;
std::vector<FilePath> getAbsoluteFrameworkSearchPaths() const;
bool setFrameworkSearchPaths(const std::vector<FilePath>& frameworkSearchPaths);
std::vector<std::string> getCompilerFlags() const;
bool setCompilerFlags(const std::vector<std::string>& compilerFlags);
bool getUseSourcePathsForHeaderSearch() const;
bool setUseSourcePathsForHeaderSearch(bool useSourcePathsForHeaderSearch);
FilePath getVisualStudioSolutionPath() const;
bool setVisualStudioSolutionPath(const FilePath& visualStudioSolutionPath);
FilePath getCompilationDatabasePath() const;
bool setCompilationDatabasePath(const FilePath& compilationDatabasePath);
private:
virtual std::vector<std::string> getDefaultSourceExtensions() const;
};
#endif // CXX_PROJECT_SETTINGS_H
+62
View File
@@ -0,0 +1,62 @@
#include "settings/JavaProjectSettings.h"
#include "utility/utility.h"
JavaProjectSettings::JavaProjectSettings()
{
// setlanguage...
}
JavaProjectSettings::JavaProjectSettings(const FilePath& projectFilePath)
: ProjectSettings(projectFilePath)
{
// setlanguage...
}
JavaProjectSettings::JavaProjectSettings(std::string projectName, const FilePath& projectFileLocation)
: ProjectSettings(projectName, projectFileLocation)
{
// setlanguage...
}
JavaProjectSettings::~JavaProjectSettings()
{
}
bool JavaProjectSettings::equalsExceptNameAndLocation(const ProjectSettings& other) const
{
if (other.getLanguage() == getLanguage())
{
const JavaProjectSettings* typedOther = dynamic_cast<const JavaProjectSettings*>(&other);
return(
ProjectSettings::equalsExceptNameAndLocation(other) &&
utility::isPermutation<FilePath>(getClasspaths(), typedOther->getClasspaths())
);
}
return false;
}
std::vector<FilePath> JavaProjectSettings::getClasspaths() const
{
return getPathValues("source/class_paths/class_path");
}
std::vector<FilePath> JavaProjectSettings::getAbsoluteClasspaths() const
{
std::vector<FilePath> paths = getClasspaths();
expandPaths(paths);
makePathsAbsolute(paths);
return paths;
}
bool JavaProjectSettings::setClasspaths(const std::vector<FilePath>& paths)
{
return setPathValues("source/class_paths/class_path", paths);
}
std::vector<std::string> JavaProjectSettings::getDefaultSourceExtensions() const
{
std::vector<std::string> defaultValues;
defaultValues.push_back(".java");
return defaultValues;
}
+24
View File
@@ -0,0 +1,24 @@
#ifndef JAVA_PROJECT_SETTINGS_H
#define JAVA_PROJECT_SETTINGS_H
#include "settings/ProjectSettings.h"
class JavaProjectSettings: public ProjectSettings
{
public:
JavaProjectSettings();
JavaProjectSettings(const FilePath& projectFilePath);
JavaProjectSettings(std::string projectName, const FilePath& projectFileLocation);
virtual ~JavaProjectSettings();
virtual bool equalsExceptNameAndLocation(const ProjectSettings& other) const;
std::vector<FilePath> getClasspaths() const;
std::vector<FilePath> getAbsoluteClasspaths() const;
bool setClasspaths(const std::vector<FilePath>& headerSearchPaths);
private:
virtual std::vector<std::string> getDefaultSourceExtensions() const;
};
#endif // JAVA_PROJECT_SETTINGS_H
+32
View File
@@ -0,0 +1,32 @@
#include "settings/LanguageType.h"
std::string languageTypeToString(LanguageType t)
{
switch (t)
{
case LANGUAGE_C:
return "C";
case LANGUAGE_CPP:
return "C++";
case LANGUAGE_JAVA:
return "Java";
}
return "unknown";
}
LanguageType stringToLanguageType(std::string s)
{
if (s == "C")
{
return LANGUAGE_C;
}
else if (s == "C++")
{
return LANGUAGE_CPP;
}
else if (s == "Java")
{
return LANGUAGE_JAVA;
}
return LANGUAGE_UNKNOWN;
}
+17
View File
@@ -0,0 +1,17 @@
#ifndef LANGUAGE_TYPE_H
#define LANGUAGE_TYPE_H
#include <string>
enum LanguageType
{
LANGUAGE_C,
LANGUAGE_CPP,
LANGUAGE_JAVA,
LANGUAGE_UNKNOWN
};
std::string languageTypeToString(LanguageType t);
LanguageType stringToLanguageType(std::string s);
#endif // LANGUAGE_TYPE_H
+57 -169
View File
@@ -1,75 +1,83 @@
#include "settings/ProjectSettings.h"
#include "settings/CxxProjectSettings.h"
#include "settings/JavaProjectSettings.h"
#include "utility/utility.h"
std::vector<std::string> ProjectSettings::getDefaultSourceExtensions()
LanguageType ProjectSettings::getLanguageOfProject(FilePath projectFilePath)
{
std::vector<std::string> defaultValues;
defaultValues.push_back(".c");
defaultValues.push_back(".cpp");
defaultValues.push_back(".cxx");
defaultValues.push_back(".cc");
return defaultValues;
}
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 tempSettings(projectFilePath);
tempSettings.load();
return tempSettings.getLanguage();
}
ProjectSettings::ProjectSettings()
{
}
ProjectSettings::ProjectSettings(const FilePath& projectFilePath)
{
setFilePath(projectFilePath);
}
ProjectSettings::ProjectSettings(std::string projectName, const FilePath& projectFileLocation)
{
setFilePath(FilePath(projectFileLocation.str() + "/" + projectName + ".coatiproject"));
}
ProjectSettings::~ProjectSettings()
{
}
bool ProjectSettings::operator==(const ProjectSettings& other) const
bool ProjectSettings::equalsExceptNameAndLocation(const ProjectSettings& other) const
{
return
getFilePath() == other.getFilePath() &&
return (
getLanguage() == other.getLanguage() &&
getStandard() == other.getStandard() &&
getVisualStudioSolutionPath() == other.getVisualStudioSolutionPath() &&
getCompilationDatabasePath() == other.getCompilationDatabasePath() &&
getUseSourcePathsForHeaderSearch() == other.getUseSourcePathsForHeaderSearch() &&
utility::isPermutation<FilePath>(getSourcePaths(), other.getSourcePaths()) &&
utility::isPermutation<FilePath>(getHeaderSearchPaths(), other.getHeaderSearchPaths()) &&
utility::isPermutation<FilePath>(getFrameworkSearchPaths(), other.getFrameworkSearchPaths()) &&
utility::isPermutation<FilePath>(getExcludePaths(), other.getExcludePaths()) &&
utility::isPermutation<std::string>(getCompilerFlags(), other.getCompilerFlags()) &&
utility::isPermutation<std::string>(getSourceExtensions(), other.getSourceExtensions());
utility::isPermutation<std::string>(getSourceExtensions(), other.getSourceExtensions())
);
}
bool ProjectSettings::operator!=(const ProjectSettings& other) const
bool ProjectSettings::load()
{
return !(*this == other);
return Settings::load(getFilePath());
}
void ProjectSettings::save(const FilePath& filePath)
std::string ProjectSettings::getProjectName() const
{
m_projectName = "";
m_projectFileLocation = "";
Settings::save(filePath);
return getFilePath().withoutExtension().fileName();
}
std::string ProjectSettings::getLanguage() const
void ProjectSettings::setProjectName(const std::string& name)
{
return getValue<std::string>("language_settings/language", "C++");
setFilePath(FilePath(getProjectFileLocation().str() + "/" + name + ".coatiproject"));
}
bool ProjectSettings::setLanguage(const std::string& language)
FilePath ProjectSettings::getProjectFileLocation() const
{
return setValue<std::string>("language_settings/language", language);
return getFilePath().parentDirectory();
}
void ProjectSettings::setProjectFileLocation(const FilePath& location)
{
setFilePath(FilePath(location.str() + "/" + getProjectName() + ".coatiproject"));
}
std::string ProjectSettings::getDescription() const
{
return getValue<std::string>("info/description", "");
}
LanguageType ProjectSettings::getLanguage() const
{
return stringToLanguageType(getValue<std::string>("language_settings/language", languageTypeToString(LANGUAGE_UNKNOWN)));
}
bool ProjectSettings::setLanguage(LanguageType language)
{
return setValue<std::string>("language_settings/language", languageTypeToString(language));
}
std::string ProjectSettings::getStandard() const
@@ -82,19 +90,6 @@ bool ProjectSettings::setStandard(const std::string& standard)
return setValue<std::string>("language_settings/standard", standard);
}
std::vector<FilePath> ProjectSettings::getJavaClasspaths() const
{
return getPathValues("source/class_paths/class_path");
}
std::vector<FilePath> ProjectSettings::getAbsoluteJavaClasspaths() const
{
std::vector<FilePath> paths = getJavaClasspaths();
expandPaths(paths);
makePathsAbsolute(paths);
return paths;
}
std::vector<FilePath> ProjectSettings::getSourcePaths() const
{
return getPathValues("source/source_paths/source_path");
@@ -113,73 +108,6 @@ bool ProjectSettings::setSourcePaths(const std::vector<FilePath>& sourcePaths)
return setPathValues("source/source_paths/source_path", sourcePaths);
}
std::vector<FilePath> ProjectSettings::getHeaderSearchPaths() const
{
return getPathValues("source/header_search_paths/header_search_path");
}
std::vector<FilePath> ProjectSettings::getAbsoluteHeaderSearchPaths() const
{
std::vector<FilePath> paths = getHeaderSearchPaths();
expandPaths(paths);
makePathsAbsolute(paths);
return paths;
}
bool ProjectSettings::setHeaderSearchPaths(const std::vector<FilePath>& headerSearchPaths)
{
return setPathValues("source/header_search_paths/header_search_path", headerSearchPaths);
}
std::vector<FilePath> ProjectSettings::getFrameworkSearchPaths() const
{
return getPathValues("source/framework_search_paths/framework_search_path");
}
std::vector<FilePath> ProjectSettings::getAbsoluteFrameworkSearchPaths() const
{
std::vector<FilePath> paths = getFrameworkSearchPaths();
expandPaths(paths);
makePathsAbsolute(paths);
return paths;
}
bool ProjectSettings::setFrameworkSearchPaths(const std::vector<FilePath>& frameworkSearchPaths)
{
return setPathValues("source/framework_search_paths/framework_search_path", frameworkSearchPaths);
}
std::vector<std::string> ProjectSettings::getCompilerFlags() const
{
std::vector<std::string> defaultValues;
return getValues("source/compiler_flags/compiler_flag", defaultValues);
}
bool ProjectSettings::setCompilerFlags(const std::vector<std::string>& compilerFlags)
{
return setValues("source/compiler_flags/compiler_flag", compilerFlags);
}
std::vector<std::string> ProjectSettings::getSourceExtensions() const
{
return getValues("source/extensions/source_extensions", getDefaultSourceExtensions());
}
bool ProjectSettings::setSourceExtensions(const std::vector<std::string> &sourceExtensions)
{
return setValues("source/extensions/source_extensions", sourceExtensions);
}
bool ProjectSettings::getUseSourcePathsForHeaderSearch() const
{
return getValue<bool>("source/use_source_paths_for_header_search", false);
}
bool ProjectSettings::setUseSourcePathsForHeaderSearch(bool useSourcePathsForHeaderSearch)
{
return setValue<bool>("source/use_source_paths_for_header_search", useSourcePathsForHeaderSearch);
}
std::vector<FilePath> ProjectSettings::getExcludePaths() const
{
return getPathValues("source/exclude_paths/exclude_path");
@@ -198,59 +126,14 @@ bool ProjectSettings::setExcludePaths(const std::vector<FilePath>& excludePaths)
return setPathValues("source/exclude_paths/exclude_path", excludePaths);
}
FilePath ProjectSettings::getVisualStudioSolutionPath() const
std::vector<std::string> ProjectSettings::getSourceExtensions() const
{
return FilePath(getValue<std::string>("source/build_file_path/vs_solution_path", ""));
return getValues("source/extensions/source_extensions", getDefaultSourceExtensions());
}
bool ProjectSettings::setVisualStudioSolutionPath(const FilePath& visualStudioSolutionPath)
bool ProjectSettings::setSourceExtensions(const std::vector<std::string> &sourceExtensions)
{
return setValue<std::string>("source/build_file_path/vs_solution_path", visualStudioSolutionPath.str());
}
FilePath ProjectSettings::getCompilationDatabasePath() const
{
return FilePath(getValue<std::string>("source/build_file_path/compilation_db_path", ""));
}
bool ProjectSettings::setCompilationDatabasePath(const FilePath& compilationDatabasePath)
{
return setValue<std::string>("source/build_file_path/compilation_db_path", compilationDatabasePath.str());
}
std::string ProjectSettings::getDescription() const
{
return getValue<std::string>("info/description", "");
}
std::string ProjectSettings::getProjectName() const
{
if (m_projectName.size())
{
return m_projectName;
}
return getFilePath().withoutExtension().fileName();
}
void ProjectSettings::setProjectName(const std::string& name)
{
m_projectName = name;
}
FilePath ProjectSettings::getProjectFileLocation() const
{
if (!m_projectFileLocation.empty())
{
return m_projectFileLocation;
}
return getFilePath().parentDirectory();
}
void ProjectSettings::setProjectFileLocation(const FilePath& location)
{
m_projectFileLocation = location;
return setValues("source/extensions/source_extensions", sourceExtensions);
}
void ProjectSettings::makePathsAbsolute(std::vector<FilePath>& paths) const
@@ -264,3 +147,8 @@ void ProjectSettings::makePathsAbsolute(std::vector<FilePath>& paths) const
}
}
}
std::vector<std::string> ProjectSettings::getDefaultSourceExtensions() const
{
return std::vector<std::string>();
}
+29 -58
View File
@@ -5,82 +5,53 @@
#include <vector>
#include "settings/Settings.h"
#include "settings/LanguageType.h"
class ProjectSettings
: public Settings
{
public:
static std::vector<std::string> getDefaultSourceExtensions();
static LanguageType getLanguageOfProject(FilePath projectFilePath);
static std::shared_ptr<ProjectSettings> getInstance();
ProjectSettings();
~ProjectSettings();
ProjectSettings(const FilePath& projectFilePath);
ProjectSettings(std::string projectName, const FilePath& projectFileLocation);
virtual ~ProjectSettings();
bool operator==(const ProjectSettings& other) const;
bool operator!=(const ProjectSettings& other) const;
virtual bool equalsExceptNameAndLocation(const ProjectSettings& other) const;
virtual void save(const FilePath& filePath);
virtual bool load();
// language settings
std::string getLanguage() const;
bool setLanguage(const std::string& language);
std::string getStandard() const;
bool setStandard(const std::string& standard);
// java... todo: move this
std::vector<FilePath> getJavaClasspaths() const;
std::vector<FilePath> getAbsoluteJavaClasspaths() const;
// source
std::vector<FilePath> getSourcePaths() const;
std::vector<FilePath> getAbsoluteSourcePaths() const;
bool setSourcePaths(const std::vector<FilePath>& sourcePaths);
std::vector<FilePath> getHeaderSearchPaths() const;
std::vector<FilePath> getAbsoluteHeaderSearchPaths() const;
bool setHeaderSearchPaths(const std::vector<FilePath>& headerSearchPaths);
std::vector<FilePath> getFrameworkSearchPaths() const;
std::vector<FilePath> getAbsoluteFrameworkSearchPaths() const;
bool setFrameworkSearchPaths(const std::vector<FilePath>& frameworkSearchPaths);
std::vector<std::string> getCompilerFlags() const;
bool setCompilerFlags(const std::vector<std::string>& compilerFlags);
std::vector<std::string> getSourceExtensions() const;
bool setSourceExtensions(const std::vector<std::string>& sourceExtensions);
bool getUseSourcePathsForHeaderSearch() const;
bool setUseSourcePathsForHeaderSearch(bool useSourcePathsForHeaderSearch);
std::vector<FilePath> getExcludePaths() const;
std::vector<FilePath> getAbsoluteExcludePaths() const;
bool setExcludePaths(const std::vector<FilePath>& excludePaths);
FilePath getVisualStudioSolutionPath() const;
bool setVisualStudioSolutionPath(const FilePath& visualStudioSolutionPath);
FilePath getCompilationDatabasePath() const;
bool setCompilationDatabasePath(const FilePath& compilationDatabasePath);
// info
std::string getDescription() const;
// used in project wizzard
std::string getProjectName() const;
void setProjectName(const std::string& name);
FilePath getProjectFileLocation() const;
void setProjectFileLocation(const FilePath& location);
private:
std::string getDescription() const;
LanguageType getLanguage() const;
bool setLanguage(LanguageType language);
std::string getStandard() const;
bool setStandard(const std::string& standard);
std::vector<FilePath> getSourcePaths() const;
std::vector<FilePath> getAbsoluteSourcePaths() const;
bool setSourcePaths(const std::vector<FilePath>& sourcePaths);
std::vector<FilePath> getExcludePaths() const;
std::vector<FilePath> getAbsoluteExcludePaths() const;
bool setExcludePaths(const std::vector<FilePath>& excludePaths);
std::vector<std::string> getSourceExtensions() const;
bool setSourceExtensions(const std::vector<std::string>& sourceExtensions);
protected:
void makePathsAbsolute(std::vector<FilePath>& paths) const;
std::string m_projectName;
FilePath m_projectFileLocation;
static std::shared_ptr<ProjectSettings> s_instance;
private:
virtual std::vector<std::string> getDefaultSourceExtensions() const;
};
#endif // PROJECT_SETTINGS_H
+4 -3
View File
@@ -15,12 +15,13 @@ public:
Settings& operator=(const Settings& other);
virtual ~Settings();
bool load(const FilePath& filePath);
void save();
virtual bool load(const FilePath& filePath);
virtual void save();
virtual void save(const FilePath& filePath);
void clear();
const FilePath& getFilePath() const;
virtual const FilePath& getFilePath() const;
protected:
Settings();
+11
View File
@@ -0,0 +1,11 @@
#include "utility/ScopedFunctor.h"
ScopedFunctor::ScopedFunctor(std::function<void(void)> onDestroy)
: m_onDestroy(onDestroy)
{
}
ScopedFunctor::~ScopedFunctor()
{
m_onDestroy();
}
+16
View File
@@ -0,0 +1,16 @@
#ifndef SCOPED_FUNCTOR_H
#define SCOPED_FUNCTOR_H
#include <functional>
class ScopedFunctor
{
public:
ScopedFunctor(std::function<void(void)> onDestroy);
~ScopedFunctor();
private:
std::function<void(void)> m_onDestroy;
};
#endif // SCOPED_FUNCTOR_H
+1 -1
View File
@@ -28,7 +28,7 @@ public:
virtual std::vector<std::string> getProjectItems() = 0;
virtual std::vector<std::string> getCompileFlags() = 0;
virtual ProjectSettings getProjectSettings(const std::string& solutionFilePath) = 0;
virtual std::shared_ptr<ProjectSettings> getProjectSettings(const std::string& solutionFilePath) = 0;
virtual std::string getIdeName() const = 0;
virtual std::string getButtonText() const = 0;
@@ -4,6 +4,7 @@
#include "SolutionParserUtility.h"
#include "settings/CxxProjectSettings.h"
#include "utility/logging/logging.h"
SolutionParserCodeBlocks::SolutionParserCodeBlocks()
@@ -174,14 +175,12 @@ std::vector<std::string> SolutionParserCodeBlocks::getCompileFlags()
return compilerFlags;
}
ProjectSettings SolutionParserCodeBlocks::getProjectSettings(const std::string& solutionFilePath)
std::shared_ptr<ProjectSettings> SolutionParserCodeBlocks::getProjectSettings(const std::string& solutionFilePath)
{
openSolutionFile(solutionFilePath);
ProjectSettings settings;
settings.setProjectName(getSolutionName());
settings.setProjectFileLocation(getSolutionPath());
settings.setVisualStudioSolutionPath(solutionFilePath);
std::shared_ptr<CxxProjectSettings> settings = std::make_shared<CxxProjectSettings>(getSolutionName(), getSolutionPath());
settings->setVisualStudioSolutionPath(solutionFilePath); // why is it called vs solution if it is used for codeblocks as well?
std::vector<std::string> sourceFiles = getProjectItems();
std::vector<FilePath> sourcePaths;
@@ -197,8 +196,8 @@ ProjectSettings SolutionParserCodeBlocks::getProjectSettings(const std::string&
headerPaths.push_back(FilePath(p));
}
settings.setSourcePaths(sourcePaths);
settings.setHeaderSearchPaths(headerPaths);
settings->setSourcePaths(sourcePaths);
settings->setHeaderSearchPaths(headerPaths);
return settings;
}
@@ -21,7 +21,7 @@ public:
virtual std::vector<std::string> getIncludePaths();
virtual std::vector<std::string> getCompileFlags();
virtual ProjectSettings getProjectSettings(const std::string& solutionFilePath);
virtual std::shared_ptr<ProjectSettings> getProjectSettings(const std::string& solutionFilePath);
virtual std::string getIdeName() const;
virtual std::string getButtonText() const;
@@ -39,7 +39,7 @@ bool SolutionParserManager::canParseSolution(const std::string& ideId) const
return false;
}
ProjectSettings SolutionParserManager::getProjectSettings(const std::string& ideId, const std::string& solutionFilePath) const
std::shared_ptr<ProjectSettings> SolutionParserManager::getProjectSettings(const std::string& ideId, const std::string& solutionFilePath) const
{
std::string lIdeId = ideId;
boost::algorithm::to_lower(lIdeId);
@@ -57,7 +57,7 @@ ProjectSettings SolutionParserManager::getProjectSettings(const std::string& ide
LOG_ERROR_STREAM(<< "Solution type is unknown");
return ProjectSettings();
return std::shared_ptr<ProjectSettings>();
}
unsigned int SolutionParserManager::getParserCount() const
@@ -15,7 +15,7 @@ public:
bool canParseSolution(const std::string& ideId) const;
ProjectSettings getProjectSettings(const std::string& ideId, const std::string& solutionFilePath) const;
std::shared_ptr<ProjectSettings> getProjectSettings(const std::string& ideId, const std::string& solutionFilePath) const;
unsigned int getParserCount() const;
@@ -9,6 +9,7 @@
#include "SolutionParserUtility.h"
#include "settings/CxxProjectSettings.h"
#include "utility/logging/logging.h"
SolutionParserVisualStudio::SolutionParserVisualStudio()
@@ -202,7 +203,7 @@ std::vector<std::string> SolutionParserVisualStudio::getCompileFlags()
return compilerFlags;
}
ProjectSettings SolutionParserVisualStudio::getProjectSettings(const std::string& solutionFilePath)
std::shared_ptr<ProjectSettings> SolutionParserVisualStudio::getProjectSettings(const std::string& solutionFilePath)
{
LOG_INFO_STREAM(<< "Starting to parse VS solution");
@@ -218,10 +219,8 @@ ProjectSettings SolutionParserVisualStudio::getProjectSettings(const std::string
LOG_INFO_STREAM(<< "Setting meta information");
ProjectSettings settings;
settings.setProjectName(getSolutionName());
settings.setProjectFileLocation(getSolutionPath());
settings.setVisualStudioSolutionPath(solutionFilePath);
std::shared_ptr<CxxProjectSettings> settings = std::make_shared<CxxProjectSettings>(getSolutionName(), getSolutionPath());
settings->setVisualStudioSolutionPath(solutionFilePath);
LOG_INFO_STREAM(<< "Parsing project files");
@@ -247,10 +246,10 @@ ProjectSettings SolutionParserVisualStudio::getProjectSettings(const std::string
LOG_INFO_STREAM(<< "Setting compile flags");
std::vector<std::string> compilerFlags = getCompileFlags();
settings.setCompilerFlags(compilerFlags);
settings->setCompilerFlags(compilerFlags);
settings.setSourcePaths(sourcePaths);
settings.setHeaderSearchPaths(headerPaths);
settings->setSourcePaths(sourcePaths);
settings->setHeaderSearchPaths(headerPaths);
LOG_INFO_STREAM(<< "Done parsing VS solution");
@@ -21,7 +21,7 @@ public:
virtual std::vector<std::string> getIncludePaths();
virtual std::vector<std::string> getCompileFlags();
virtual ProjectSettings getProjectSettings(const std::string& solutionFilePath);
virtual std::shared_ptr<ProjectSettings> getProjectSettings(const std::string& solutionFilePath);
virtual std::string getIdeName() const;
virtual std::string getButtonText() const;