logic: source groups for project settings

* project can not have multiple source groups with different types
* language of a project is now inferred from source groups
* setting global NameHierarchy delimiter of first sourceGroup in project
* added project settings migrations for source groups
* Add Settings Migration classes (MoveKey, DeleteKey, Lambda)
* Update sample projects with migrations
* added method to config to retrieve sublevel key names
* implemented recursive removing of keys in settings
* moved project files out of top level
* removed solution parsing code as it is not used anymore

fortune cookie message = The secret of getting ahead is getting started.
This commit is contained in:
malte_langkabel
2017-03-31 16:11:37 +02:00
parent 25f3c4666a
commit 7b30ac18de
133 changed files with 2545 additions and 3386 deletions
+4 -6
View File
@@ -19,6 +19,7 @@
#include "data/StorageCache.h"
#include "LicenseChecker.h"
#include "settings/ApplicationSettings.h"
#include "settings/ProjectSettings.h"
#include "settings/ColorScheme.h"
void Application::createInstance(
@@ -105,11 +106,6 @@ Application::~Application()
}
}
void Application::addProjectFactoryModule(std::shared_ptr<ProjectFactoryModule> module)
{
m_projectFactory.addModule(module);
}
const std::shared_ptr<Project> Application::getCurrentProject()
{
return m_project;
@@ -155,10 +151,12 @@ void Application::createAndLoadProject(const FilePath& projectSettingsFilePath)
m_storageCache->clear();
m_storageCache->setSubject(nullptr);
m_project = m_projectFactory.createProject(projectSettingsFilePath, m_storageCache.get(), getDialogView());
m_project = std::make_shared<Project>(std::make_shared<ProjectSettings>(projectSettingsFilePath), m_storageCache.get());
if (m_project)
{
m_project->load();
if (m_hasGUI)
{
updateTitle();
+1 -6
View File
@@ -4,6 +4,7 @@
#include <memory>
#include "component/ComponentManager.h"
#include "project/Project.h"
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageActivateWindow.h"
#include "utility/messaging/type/MessageEnteredLicense.h"
@@ -11,8 +12,6 @@
#include "utility/messaging/type/MessageLoadProject.h"
#include "utility/messaging/type/MessageRefresh.h"
#include "utility/messaging/type/MessageSwitchColorScheme.h"
#include "Project.h"
#include "ProjectFactory.h"
class DialogView;
class IDECommunicationController;
@@ -21,7 +20,6 @@ class NetworkFactory;
class StorageCache;
class Version;
class ViewFactory;
class ProjectFactoryModule;
class Application
: public MessageListener<MessageActivateWindow>
@@ -39,8 +37,6 @@ public:
static void loadSettings();
static void loadStyle(const FilePath& colorSchemePath);
void addProjectFactoryModule(std::shared_ptr<ProjectFactoryModule> module);
~Application();
const std::shared_ptr<Project> getCurrentProject();
@@ -76,7 +72,6 @@ private:
void updateTitle();
const bool m_hasGUI;
ProjectFactory m_projectFactory;
std::shared_ptr<Project> m_project;
std::shared_ptr<StorageCache> m_storageCache;
+29 -24
View File
@@ -221,25 +221,45 @@ add_files(
data/TaskMergeStorages.h
data/TaskShowStatusDialog.cpp
data/TaskShowStatusDialog.h
project/Project.cpp
project/Project.h
project/SourceGroupFactory.cpp
project/SourceGroupFactory.h
project/SourceGroupFactoryModule.cpp
project/SourceGroupFactoryModule.h
project/SourceGroup.cpp
project/SourceGroup.h
settings/migration/Migration.cpp
settings/migration/Migration.h
settings/migration/MigrationDeleteKey.cpp
settings/migration/MigrationDeleteKey.h
settings/migration/MigrationLambda.cpp
settings/migration/MigrationLambda.h
settings/migration/MigrationMoveKey.cpp
settings/migration/MigrationMoveKey.h
settings/migration/SettingsMigrator.cpp
settings/migration/SettingsMigrator.h
settings/ApplicationSettings.cpp
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/ProjectType.cpp
settings/ProjectType.h
settings/Settings.cpp
settings/Settings.h
settings/SettingsMigrator.cpp
settings/SettingsMigrator.h
settings/SourceGroupSettings.cpp
settings/SourceGroupSettings.h
settings/SourceGroupSettingsCxx.cpp
settings/SourceGroupSettingsCxx.h
settings/SourceGroupSettingsJava.cpp
settings/SourceGroupSettingsJava.h
settings/SourceGroupType.cpp
settings/SourceGroupType.h
utility/commandline/CommandLineParser.cpp
utility/commandline/CommandLineParser.h
@@ -400,15 +420,6 @@ add_files(
utility/scheduling/TaskScheduler.h
utility/scheduling/TaskSetValue.h
utility/solution/ISolutionParser.cpp
utility/solution/ISolutionParser.h
utility/solution/SolutionParserCodeBlocks.cpp
utility/solution/SolutionParserCodeBlocks.h
utility/solution/SolutionParserManager.cpp
utility/solution/SolutionParserManager.h
utility/solution/SolutionParserUtility.cpp
utility/solution/SolutionParserUtility.h
utility/synchronization/ReaderWriterLock.cpp
utility/synchronization/ReaderWriterLock.h
utility/synchronization/ScopedReaderLock.cpp
@@ -458,10 +469,4 @@ add_files(
ApplicationStateMonitor.h
LicenseChecker.cpp
LicenseChecker.h
Project.cpp
Project.h
ProjectFactory.cpp
ProjectFactory.h
ProjectFactoryModule.cpp
ProjectFactoryModule.h
)
-81
View File
@@ -1,81 +0,0 @@
#ifndef PROJECT_H
#define PROJECT_H
#include <memory>
#include <mutex>
#include <set>
#include "utility/file/FileManager.h"
#include "data/parser/Parser.h"
#include "settings/LanguageType.h"
class DialogView;
class FileRegister;
class PersistentStorage;
class StorageProvider;
class ProjectSettings;
class StorageAccessProxy;
class IndexerCommand;
class Project
{
public:
virtual ~Project();
bool refresh(bool forceRefresh);
FilePath getProjectSettingsFilePath() const;
LanguageType getLanguage() const;
std::string getDescription() const;
std::set<FilePath> getSourceFilePaths() const;
bool settingsEqualExceptNameAndLocation(const ProjectSettings& otherSettings) const;
void setStateSettingsUpdated();
protected:
Project(StorageAccessProxy* storageAccessProxy, std::shared_ptr<DialogView> dialogView);
std::shared_ptr<DialogView> getDialogView() const;
std::vector<FilePath> getSourcePaths() const;
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_STATE_SETTINGS_UPDATED,
PROJECT_STATE_NEEDS_MIGRATION
};
Project(const Project&);
public: // todo: make private again
void load();
private:
bool requestIndex(bool forceRefresh, bool needsFullRefresh);
void buildIndex(const std::set<FilePath>& filesToClean, const std::set<FilePath>& filesToIndex, bool fullRefresh);
virtual bool prepareIndexing();
virtual bool prepareRefresh();
virtual std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands() = 0;
std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(const std::set<FilePath>& sourceFiles);
virtual void updateFileManager(FileManager& fileManager) = 0;
StorageAccessProxy* const m_storageAccessProxy;
std::shared_ptr<DialogView> m_dialogView;
ProjectStateType m_state;
FileManager m_fileManager;
std::shared_ptr<PersistentStorage> m_storage;
};
#endif // PROJECT_H
-35
View File
@@ -1,35 +0,0 @@
#include "ProjectFactory.h"
#include "component/view/DialogView.h"
#include "data/access/StorageAccessProxy.h"
#include "settings/ProjectSettings.h"
#include "utility/file/FilePath.h"
#include "Project.h"
#include "ProjectFactoryModule.h"
void ProjectFactory::addModule(std::shared_ptr<ProjectFactoryModule> module)
{
m_modules[module->getLanguage()] = module;
}
std::shared_ptr<Project> ProjectFactory::createProject(
const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, std::shared_ptr<DialogView> dialogView)
{
std::shared_ptr<Project> project;
std::map<LanguageType, std::shared_ptr<ProjectFactoryModule>>::const_iterator it = m_modules.find(
ProjectSettings::getLanguageOfProject(projectSettingsFile)
);
if (it != m_modules.end())
{
project = it->second->createProject(projectSettingsFile, storageAccessProxy, dialogView);
}
if (project)
{
project->load();
}
return project;
}
-27
View File
@@ -1,27 +0,0 @@
#ifndef PROJECT_FACTORY_H
#define PROJECT_FACTORY_H
#include <map>
#include <memory>
#include "settings/LanguageType.h"
class Project;
class FilePath;
class StorageAccessProxy;
class DialogView;
class ProjectFactoryModule;
class ProjectFactory
{
public:
void addModule(std::shared_ptr<ProjectFactoryModule> module);
std::shared_ptr<Project> createProject(
const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, std::shared_ptr<DialogView> dialogView);
private:
std::map<LanguageType, std::shared_ptr<ProjectFactoryModule>> m_modules;
};
#endif // PROJECT_FACTORY_H
-5
View File
@@ -1,5 +0,0 @@
#include "ProjectFactoryModule.h"
ProjectFactoryModule::~ProjectFactoryModule()
{
}
-24
View File
@@ -1,24 +0,0 @@
#ifndef PROJECT_FACTORY_MODULE_H
#define PROJECT_FACTORY_MODULE_H
#include <memory>
#include "settings/LanguageType.h"
class Project;
class FilePath;
class StorageAccessProxy;
class DialogView;
class ProjectFactoryModule
{
public:
virtual ~ProjectFactoryModule();
virtual LanguageType getLanguage() const = 0;
virtual std::shared_ptr<Project> createProject(
const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, std::shared_ptr<DialogView> dialogView
) = 0;
};
#endif // PROJECT_FACTORY_MODULE_H
+1 -1
View File
@@ -1476,7 +1476,7 @@ std::set<FilePath> PersistentStorage::getReferencedByIncludes(const std::set<Fil
std::set<FilePath> paths;
for (Id id: ids)
{
{ // TODO: performance optimize: use just one request for all ids!
paths.insert(getFileNodePath(id));
}
+11 -7
View File
@@ -4,19 +4,22 @@
#include "data/PersistentStorage.h"
#include "utility/scheduling/Blackboard.h"
#include "utility/utility.h"
#include "Application.h"
TaskCleanStorage::TaskCleanStorage(
PersistentStorage* storage, const std::vector<FilePath>& filePaths, std::shared_ptr<DialogView> dialogView
PersistentStorage* storage, const std::vector<FilePath>& filePaths
)
: m_storage(storage)
, m_filePaths(filePaths)
, m_dialogView(dialogView)
{
}
void TaskCleanStorage::doEnter(std::shared_ptr<Blackboard> blackboard)
{
m_dialogView->showStatusDialog("Clearing Files", std::to_string(m_filePaths.size()) + " Files");
if (std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView())
{
dialogView->showStatusDialog("Clearing Files", std::to_string(m_filePaths.size()) + " Files");
}
m_start = utility::durationStart();
@@ -28,10 +31,9 @@ void TaskCleanStorage::doEnter(std::shared_ptr<Blackboard> blackboard)
Task::TaskState TaskCleanStorage::doUpdate(std::shared_ptr<Blackboard> blackboard)
{
std::shared_ptr<DialogView> dialogView = m_dialogView;
m_storage->clearFileElements(m_filePaths, [=](int progress)
{
if (dialogView != nullptr)
if (std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView())
{
dialogView->showProgressDialog("Clearing", std::to_string(m_filePaths.size()) + " Files", progress);
}
@@ -46,8 +48,10 @@ Task::TaskState TaskCleanStorage::doUpdate(std::shared_ptr<Blackboard> blackboar
void TaskCleanStorage::doExit(std::shared_ptr<Blackboard> blackboard)
{
blackboard->set("clear_time", utility::duration(m_start));
m_dialogView->hideProgressDialog();
if (std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView())
{
dialogView->hideProgressDialog();
}
}
void TaskCleanStorage::doReset(std::shared_ptr<Blackboard> blackboard)
+1 -3
View File
@@ -16,8 +16,7 @@ class TaskCleanStorage
public:
TaskCleanStorage(
PersistentStorage* storage,
const std::vector<FilePath>& filePaths,
std::shared_ptr<DialogView> dialogView
const std::vector<FilePath>& filePaths
);
private:
@@ -28,7 +27,6 @@ private:
PersistentStorage* m_storage;
std::vector<FilePath> m_filePaths;
std::shared_ptr<DialogView> m_dialogView;
TimePoint m_start;
};
+12 -11
View File
@@ -6,15 +6,14 @@
#include "utility/messaging/type/MessageFinishedParsing.h"
#include "utility/scheduling/Blackboard.h"
#include "utility/utility.h"
#include "Application.h"
TaskFinishParsing::TaskFinishParsing(
PersistentStorage* storage,
StorageAccess* storageAccess,
std::shared_ptr<DialogView> dialogView
StorageAccess* storageAccess
)
: m_storage(storage)
, m_storageAccess(storageAccess)
, m_dialogView(dialogView)
{
}
@@ -31,21 +30,23 @@ Task::TaskState TaskFinishParsing::doUpdate(std::shared_ptr<Blackboard> blackboa
{
TimePoint start = utility::durationStart();
if (m_dialogView)
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView();
if (dialogView)
{
m_dialogView->showStatusDialog("Finish Indexing", "Optimizing database");
dialogView->showStatusDialog("Finish Indexing", "Optimizing database");
}
m_storage->optimizeMemory();
if (m_dialogView)
if (dialogView)
{
m_dialogView->showStatusDialog("Finish Indexing", "Building caches");
dialogView->showStatusDialog("Finish Indexing", "Building caches");
}
m_storage->buildCaches();
if (m_dialogView)
if (dialogView)
{
m_dialogView->hideStatusDialog();
dialogView->hideStatusDialog();
}
MessageFinishedParsing().dispatch();
@@ -71,9 +72,9 @@ Task::TaskState TaskFinishParsing::doUpdate(std::shared_ptr<Blackboard> blackboa
int sourceFileCount = 0;
blackboard->get("source_file_count", sourceFileCount);
if (m_dialogView)
if (dialogView)
{
m_dialogView->finishedIndexingDialog(
dialogView->finishedIndexingDialog(
indexedSourceFileCount,
sourceFileCount,
time,
+1 -3
View File
@@ -17,8 +17,7 @@ class TaskFinishParsing
public:
TaskFinishParsing(
PersistentStorage* storage,
StorageAccess* storageAccess,
std::shared_ptr<DialogView> dialogView
StorageAccess* storageAccess
);
virtual ~TaskFinishParsing();
@@ -31,7 +30,6 @@ private:
PersistentStorage* m_storage;
StorageAccess* m_storageAccess;
std::shared_ptr<DialogView> m_dialogView;
};
#endif // TASK_FINISH_PARSING_H
+5 -6
View File
@@ -1,15 +1,14 @@
#include "data/TaskShowStatusDialog.h"
#include "component/view/DialogView.h"
#include "Application.h"
TaskShowStatusDialog::TaskShowStatusDialog(
const std::string& title,
const std::string& message,
std::shared_ptr<DialogView> dialogView
const std::string& message
)
: m_title(title)
, m_message(message)
, m_dialogView(dialogView)
{
}
@@ -23,9 +22,9 @@ void TaskShowStatusDialog::doEnter(std::shared_ptr<Blackboard> blackboard)
Task::TaskState TaskShowStatusDialog::doUpdate(std::shared_ptr<Blackboard> blackboard)
{
if (m_dialogView)
{
m_dialogView->showStatusDialog(m_title, m_message);
if (std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView())
{
dialogView->showStatusDialog(m_title, m_message);
}
return STATE_SUCCESS;
}
+1 -3
View File
@@ -13,8 +13,7 @@ class TaskShowStatusDialog
public:
TaskShowStatusDialog(
const std::string& title,
const std::string& message,
std::shared_ptr<DialogView> dialogView
const std::string& message
);
virtual ~TaskShowStatusDialog();
@@ -27,7 +26,6 @@ private:
const std::string m_title;
const std::string m_message;
std::shared_ptr<DialogView> m_dialogView;
};
#endif // TASK_SHOW_STATUS_DIALOG_H
+4 -5
View File
@@ -9,17 +9,16 @@
#include "utility/file/FileRegisterStateData.h"
#include "utility/scheduling/Blackboard.h"
#include "ApplicationStateMonitor.h"
#include "Application.h"
TaskBuildIndex::TaskBuildIndex(
std::shared_ptr<IndexerCommandList> indexerCommandList,
std::shared_ptr<StorageProvider> storageProvider,
std::shared_ptr<FileRegisterStateData> fileRegisterStateData,
std::shared_ptr<DialogView> dialogView
std::shared_ptr<FileRegisterStateData> fileRegisterStateData
)
: m_indexerCommandList(indexerCommandList)
, m_storageProvider(storageProvider)
, m_fileRegisterStateData(fileRegisterStateData)
, m_dialogView(dialogView)
{
m_indexer = IndexerFactory::getInstance()->createCompositeIndexerForAllRegisteredModules();
}
@@ -57,9 +56,9 @@ Task::TaskState TaskBuildIndex::doUpdate(std::shared_ptr<Blackboard> blackboard)
int indexedSourceFileCount = 0;
blackboard->get("indexed_source_file_count", indexedSourceFileCount);
if (m_dialogView)
if (std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView())
{
m_dialogView->updateIndexingDialog(
dialogView->updateIndexingDialog(
indexedSourceFileCount, sourceFileCount, indexerCommand->getSourceFilePath().str()
);
}
+1 -3
View File
@@ -21,8 +21,7 @@ public:
TaskBuildIndex(
std::shared_ptr<IndexerCommandList> indexerCommandList,
std::shared_ptr<StorageProvider> storageProvider,
std::shared_ptr<FileRegisterStateData> fileRegisterStateData,
std::shared_ptr<DialogView> dialogView
std::shared_ptr<FileRegisterStateData> fileRegisterStateData
);
protected:
@@ -36,7 +35,6 @@ protected:
std::shared_ptr<IndexerCommandList> m_indexerCommandList;
std::shared_ptr<StorageProvider> m_storageProvider;
std::shared_ptr<FileRegisterStateData> m_fileRegisterStateData;
std::shared_ptr<DialogView> m_dialogView;
std::shared_ptr<IndexerBase> m_indexer;
};
+5 -8
View File
@@ -4,13 +4,10 @@
#include "data/PersistentStorage.h"
#include "utility/scheduling/Blackboard.h"
#include "utility/utility.h"
#include "Application.h"
TaskParseWrapper::TaskParseWrapper(
PersistentStorage* storage,
std::shared_ptr<DialogView> dialogView
)
TaskParseWrapper::TaskParseWrapper(PersistentStorage* storage)
: m_storage(storage)
, m_dialogView(dialogView)
{
}
@@ -30,9 +27,9 @@ void TaskParseWrapper::doEnter(std::shared_ptr<Blackboard> blackboard)
{
int sourceFileCount = 0;
blackboard->get("source_file_count", sourceFileCount);
if (m_dialogView)
{
m_dialogView->updateIndexingDialog(0, sourceFileCount, "");
if (std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView())
{
dialogView->updateIndexingDialog(0, sourceFileCount, "");
}
m_start = utility::durationStart();
+1 -5
View File
@@ -18,10 +18,7 @@ class TaskParseWrapper
: public TaskDecorator
{
public:
TaskParseWrapper(
PersistentStorage* storage,
std::shared_ptr<DialogView> dialogView
);
TaskParseWrapper(PersistentStorage* storage);
virtual ~TaskParseWrapper();
virtual void setTask(std::shared_ptr<Task> task);
@@ -33,7 +30,6 @@ private:
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
PersistentStorage* m_storage;
std::shared_ptr<DialogView> m_dialogView;
TimePoint m_start;
std::shared_ptr<TaskRunner> m_taskRunner;
@@ -1,4 +1,4 @@
#include "Project.h"
#include "project/Project.h"
#include "component/view/DialogView.h"
#include "data/access/StorageAccessProxy.h"
@@ -13,10 +13,14 @@
#include "data/TaskShowStatusDialog.h"
#include "data/TaskFinishParsing.h"
#include "data/TaskInjectStorage.h"
#include "project/SourceGroup.h"
#include "project/SourceGroupFactory.h"
#include "settings/ApplicationSettings.h"
#include "settings/ProjectSettings.h"
#include "utility/file/FilePath.h"
#include "utility/file/FileRegisterStateData.h"
#include "utility/file/FileSystem.h"
#include "utility/messaging/type/MessageClearErrorCount.h"
#include "utility/messaging/type/MessageDispatchWhenLicenseValid.h"
#include "utility/messaging/type/MessageFinishedParsing.h"
@@ -35,6 +39,13 @@
#include "Application.h"
Project::Project(std::shared_ptr<ProjectSettings> settings, StorageAccessProxy* storageAccessProxy)
: m_settings(settings)
, m_storageAccessProxy(storageAccessProxy)
, m_state(PROJECT_STATE_NOT_LOADED)
{
}
Project::~Project()
{
}
@@ -94,7 +105,7 @@ bool Project::refresh(bool forceRefresh)
std::vector<std::string> options;
options.push_back("Yes");
options.push_back("No");
int result = m_dialogView->confirm(question, options);
int result = Application::getInstance()->getDialogView()->confirm(question, options);
if (result == 1)
{
@@ -106,26 +117,28 @@ bool Project::refresh(bool forceRefresh)
{
std::vector<std::string> options;
options.push_back("Ok");
m_dialogView->confirm("You can't refresh the project in trial mode, please unlock with a license key.", options);
Application::getInstance()->getDialogView()->confirm("You can't refresh the project in trial mode, please unlock with a license key.", options);
MessageDispatchWhenLicenseValid(std::make_shared<MessageRefresh>()).dispatch();
return false;
}
if (!prepareRefresh())
{
return false;
}
if (m_state == PROJECT_STATE_NEEDS_MIGRATION)
{
getProjectSettings()->migrate();
m_settings->migrate();
}
getProjectSettings()->reload();
m_settings->reload();
updateFileManager(m_fileManager);
m_sourceGroups = SourceGroupFactory::getInstance()->createSourceGroups(m_settings->getAllSourceGroupSettings());
for (std::shared_ptr<SourceGroup> sourceGroup: m_sourceGroups)
{
if (!sourceGroup->prepareRefresh())
{
return false;
}
}
if (requestIndex(forceRefresh, needsFullRefresh))
{
@@ -141,27 +154,17 @@ bool Project::refresh(bool forceRefresh)
FilePath Project::getProjectSettingsFilePath() const
{
return getProjectSettings()->getFilePath();
}
LanguageType Project::getLanguage() const
{
return getProjectSettings()->getLanguage();
return m_settings->getFilePath();
}
std::string Project::getDescription() const
{
return getProjectSettings()->getDescription();
}
std::set<FilePath> Project::getSourceFilePaths() const
{
return m_fileManager.getSourceFilePaths();
return m_settings->getDescription();
}
bool Project::settingsEqualExceptNameAndLocation(const ProjectSettings& otherSettings) const
{
return getProjectSettings()->equalsExceptNameAndLocation(otherSettings);
return m_settings->equalsExceptNameAndLocation(otherSettings);
}
void Project::setStateSettingsUpdated()
@@ -172,45 +175,25 @@ void Project::setStateSettingsUpdated()
}
}
Project::Project(StorageAccessProxy* storageAccessProxy, std::shared_ptr<DialogView> dialogView)
: m_storageAccessProxy(storageAccessProxy)
, m_dialogView(dialogView)
, m_state(PROJECT_STATE_NOT_LOADED)
{
}
std::shared_ptr<DialogView> Project::getDialogView() const
{
return m_dialogView;
}
std::vector<FilePath> Project::getSourcePaths() const
{
return m_fileManager.getSourcePaths();
}
void Project::load()
{
m_storageAccessProxy->setSubject(nullptr);
std::shared_ptr<ProjectSettings> projectSettings = getProjectSettings();
bool loadedSettings = projectSettings->reload();
bool loadedSettings = m_settings->reload();
if (!loadedSettings)
{
return;
}
NameHierarchy::setDelimiter(getSymbolNameDelimiterForLanguage(projectSettings->getLanguage()));
const FilePath projectSettingsPath = projectSettings->getFilePath();
const FilePath projectSettingsPath = m_settings->getFilePath();
const FilePath dbPath = FilePath(projectSettingsPath).replaceExtension("coatidb");
m_storage = std::make_shared<PersistentStorage>(dbPath);
bool canLoad = false;
if (projectSettings->needMigration())
if (m_settings->needMigration())
{
m_state = PROJECT_STATE_NEEDS_MIGRATION;
@@ -246,6 +229,12 @@ void Project::load()
m_storage->buildCaches();
m_storageAccessProxy->setSubject(m_storage.get());
m_sourceGroups = SourceGroupFactory::getInstance()->createSourceGroups(m_settings->getAllSourceGroupSettings());
if (!m_sourceGroups.empty())
{
NameHierarchy::setDelimiter(getSymbolNameDelimiterForLanguage(m_sourceGroups.front()->getLanguage()));
}
MessageFinishedParsing().dispatch();
MessageStatus("Finished Loading", false, false).dispatch();
}
@@ -262,47 +251,58 @@ void Project::load()
bool Project::requestIndex(bool forceRefresh, bool needsFullRefresh)
{
if (!prepareIndexing())
std::set<FilePath> allSourceFilePaths;
for (std::shared_ptr<SourceGroup> sourceGroup: m_sourceGroups)
{
return false;
if (!sourceGroup->prepareIndexing())
{
return false;
}
sourceGroup->fetchAllSourceFilePaths();
utility::append(allSourceFilePaths, sourceGroup->getAllSourceFilePaths());
}
const FileManager::FileSets fileSets = m_fileManager.fetchFilePaths(m_storage->getInfoOnAllFiles());
std::set<FilePath> filesToClean;
std::set<FilePath> filesToIndex;
if (!needsFullRefresh)
{
utility::append(filesToClean, fileSets.removedFiles);
utility::append(filesToClean, fileSets.updatedFiles);
utility::append(filesToIndex, fileSets.addedFiles);
utility::append(filesToIndex, fileSets.updatedFiles);
// handle referencing paths
const std::set<FilePath> referencingFilePaths = m_storage->getReferencing(utility::concat(
fileSets.updatedFiles, fileSets.removedFiles
));
for (const FilePath& path : referencingFilePaths)
std::set<FilePath> unchangedFilePaths;
std::set<FilePath> changedFilePaths;
for (const FileInfo& info: m_storage->getInfoOnAllFiles())
{
if (fileSets.removedFiles.find(path) == fileSets.removedFiles.end())
if (info.path.exists())
{
filesToClean.insert(path);
filesToIndex.insert(path);
FileInfo newFileInfo = FileSystem::getFileInfoForPath(info.path);
if (newFileInfo.lastWriteTime > info.lastWriteTime)
{
// file has been updated
changedFilePaths.insert(info.path);
}
else
{
unchangedFilePaths.insert(info.path);
}
}
else
{
// file has been removed
changedFilePaths.insert(info.path);
}
}
filesToClean = changedFilePaths;
// handle referencing paths
utility::append(filesToClean, m_storage->getReferencing(changedFilePaths));
// handle referenced paths
std::set<FilePath> staticSourceFiles = fileSets.allSourceFilePaths;
for (const FilePath& path : fileSets.updatedFiles)
std::set<FilePath> staticSourceFiles = allSourceFilePaths;
for (const FilePath& path: changedFilePaths)
{
staticSourceFiles.erase(path);
}
const std::set<FilePath> staticReferencedFilePaths = m_storage->getReferenced(staticSourceFiles);
const std::set<FilePath> dynamicReferencedFilePaths = m_storage->getReferenced(utility::concat(
fileSets.updatedFiles, fileSets.removedFiles
));
const std::set<FilePath> dynamicReferencedFilePaths = m_storage->getReferenced(changedFilePaths);
for (const FilePath& path : dynamicReferencedFilePaths)
{
@@ -315,12 +315,29 @@ bool Project::requestIndex(bool forceRefresh, bool needsFullRefresh)
}
}
std::set<FilePath> staticSourceFilePaths;
for (const FilePath& path: allSourceFilePaths)
{
if (filesToClean.find(path) == filesToClean.end())
{
staticSourceFilePaths.insert(path);
}
}
std::set<FilePath> filesToIndex;
for (std::shared_ptr<SourceGroup> sourceGroup: m_sourceGroups)
{
sourceGroup->fetchSourceFilePathsToIndex(staticSourceFilePaths);
utility::append(filesToIndex, sourceGroup->getSourceFilePathsToIndex());
}
bool fullRefresh = forceRefresh | needsFullRefresh;
if (Application::getInstance()->hasGUI())
{
DialogView::IndexMode mode = m_dialogView->startIndexingDialog(
filesToClean.size(), filesToIndex.size(), fileSets.allSourceFilePaths.size(),
DialogView::IndexMode mode = Application::getInstance()->getDialogView()->startIndexingDialog(
filesToClean.size(), filesToIndex.size(), allSourceFilePaths.size(),
forceRefresh, needsFullRefresh
);
@@ -340,7 +357,7 @@ bool Project::requestIndex(bool forceRefresh, bool needsFullRefresh)
if (fullRefresh)
{
filesToClean.clear();
filesToIndex = fileSets.allSourceFilePaths;
filesToIndex = allSourceFilePaths;
}
if (!filesToClean.size() && !filesToIndex.size())
@@ -351,12 +368,12 @@ bool Project::requestIndex(bool forceRefresh, bool needsFullRefresh)
MessageStatus((fullRefresh ? "Reindexing Project" : "Refreshing Project"), false, true).dispatch();
buildIndex(filesToClean, filesToIndex, fullRefresh);
buildIndex(filesToClean, fullRefresh);
return true;
}
void Project::buildIndex(const std::set<FilePath>& filesToClean, const std::set<FilePath>& filesToIndex, bool fullRefresh)
void Project::buildIndex(const std::set<FilePath>& filesToClean, bool fullRefresh)
{
MessageClearErrorCount().dispatch();
@@ -374,20 +391,23 @@ void Project::buildIndex(const std::set<FilePath>& filesToClean, const std::set<
{
taskSequential->addTask(std::make_shared<TaskCleanStorage>(
m_storage.get(),
utility::toVector(filesToClean),
m_dialogView)
utility::toVector(filesToClean))
);
}
if (!filesToIndex.empty())
std::shared_ptr<IndexerCommandList> indexerCommandList = std::make_shared<IndexerCommandList>();
for (std::shared_ptr<SourceGroup> sourceGroup: m_sourceGroups)
{
for (std::shared_ptr<IndexerCommand> command: sourceGroup->getIndexerCommands(fullRefresh))
{
indexerCommandList->addCommand(command);
}
}
if (indexerCommandList->size() > 0)
{
const size_t indexerThreadCount = ApplicationSettings::getInstance()->getIndexerThreadCount();
std::shared_ptr<IndexerCommandList> indexerCommandList = std::make_shared<IndexerCommandList>();
for (std::shared_ptr<IndexerCommand> indexerCommand: getIndexerCommands(filesToIndex))
{
indexerCommandList->addCommand(indexerCommand);
}
if (indexerThreadCount > 1)
{
indexerCommandList->shuffle();
@@ -402,21 +422,18 @@ void Project::buildIndex(const std::set<FilePath>& filesToClean, const std::set<
taskSequential->addTask(std::make_shared<TaskSetValue<int>>("indexed_source_file_count", 0));
taskSequential->addTask(std::make_shared<TaskSetValue<int>>("indexer_count", 0));
std::shared_ptr<TaskParseWrapper> taskParserWrapper = std::make_shared<TaskParseWrapper>(
m_storage.get(),
m_dialogView
);
std::shared_ptr<TaskParseWrapper> taskParserWrapper = std::make_shared<TaskParseWrapper>(m_storage.get());
taskSequential->addTask(taskParserWrapper);
std::shared_ptr<TaskGroupParallel> taskParallelIndexing = std::make_shared<TaskGroupParallel>();
taskParserWrapper->setTask(taskParallelIndexing);
// add tasks for indexing and merging
for (size_t i = 0; i < indexerThreadCount && i < filesToIndex.size(); i++)
for (size_t i = 0; i < indexerThreadCount && i < indexerCommandList->size(); i++)
{
taskParallelIndexing->addChildTasks(
std::make_shared<TaskDecoratorRepeat>(TaskDecoratorRepeat::CONDITION_WHILE_SUCCESS, Task::STATE_SUCCESS)->addChildTask(
std::make_shared<TaskBuildIndex>(indexerCommandList, storageProvider, fileRegisterStateData, getDialogView())
std::make_shared<TaskBuildIndex>(indexerCommandList, storageProvider, fileRegisterStateData)
)
);
}
@@ -458,7 +475,7 @@ void Project::buildIndex(const std::set<FilePath>& filesToClean, const std::set<
// add task that notifies the user of what's going on
taskSequential->addTask( // we don't need to hide this dialog again, because it's overridden by other dialogs later on.
std::make_shared<TaskShowStatusDialog>("Finish Indexing", "Saving\nRemaining Data", m_dialogView)
std::make_shared<TaskShowStatusDialog>("Finish Indexing", "Saving\nRemaining Data")
);
// add task that injects the remaining intermediate storages into the persistent storage
@@ -469,42 +486,7 @@ void Project::buildIndex(const std::set<FilePath>& filesToClean, const std::set<
);
}
taskSequential->addTask(std::make_shared<TaskFinishParsing>(m_storage.get(), m_storageAccessProxy, m_dialogView));
taskSequential->addTask(std::make_shared<TaskFinishParsing>(m_storage.get(), m_storageAccessProxy));
Task::dispatch(taskSequential);
}
bool Project::prepareIndexing()
{
return true;
}
bool Project::prepareRefresh()
{
return true;
}
std::vector<std::shared_ptr<IndexerCommand>> Project::getIndexerCommands(const std::set<FilePath>& sourceFiles)
{
struct special_compare : public std::unary_function<FilePath, bool>
{
explicit special_compare(const FilePath& baseline) : m_baseline(baseline) {}
bool operator() (const FilePath& arg)
{
return arg.str() == m_baseline.str();
}
const FilePath m_baseline;
};
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
for (std::shared_ptr<IndexerCommand> indexerCommand: getIndexerCommands())
{
if (std::find_if(sourceFiles.begin(), sourceFiles.end(), special_compare(indexerCommand->getSourceFilePath())) != sourceFiles.end())
{
indexerCommands.push_back(indexerCommand);
}
}
return indexerCommands;
}
+60
View File
@@ -0,0 +1,60 @@
#ifndef PROJECT_H
#define PROJECT_H
#include <memory>
#include <string>
#include <set>
#include <vector>
#include "project/SourceGroup.h"
class FilePath;
class PersistentStorage;
class ProjectSettings;
class StorageAccessProxy;
class Project
{
public:
Project(std::shared_ptr<ProjectSettings> settings, StorageAccessProxy* storageAccessProxy);
virtual ~Project();
bool refresh(bool forceRefresh);
FilePath getProjectSettingsFilePath() const;
std::string getDescription() const;
bool settingsEqualExceptNameAndLocation(const ProjectSettings& otherSettings) const;
void setStateSettingsUpdated();
private:
enum ProjectStateType
{
PROJECT_STATE_NOT_LOADED,
PROJECT_STATE_EMPTY,
PROJECT_STATE_LOADED,
PROJECT_STATE_OUTDATED,
PROJECT_STATE_OUTVERSIONED,
PROJECT_STATE_SETTINGS_UPDATED,
PROJECT_STATE_NEEDS_MIGRATION
};
Project(const Project&);
public: // todo: make private again
void load();
private:
bool requestIndex(bool forceRefresh, bool needsFullRefresh);
void buildIndex(const std::set<FilePath>& filesToClean, bool fullRefresh);
std::shared_ptr<ProjectSettings> m_settings;
StorageAccessProxy* const m_storageAccessProxy;
ProjectStateType m_state;
std::shared_ptr<PersistentStorage> m_storage;
std::vector<std::shared_ptr<SourceGroup>> m_sourceGroups;
};
#endif // PROJECT_H
+41
View File
@@ -0,0 +1,41 @@
#include "project/SourceGroup.h"
SourceGroup::~SourceGroup()
{
}
LanguageType SourceGroup::getLanguage() const
{
return getLanguageTypeForSourceGroupType(getType());
}
bool SourceGroup::prepareRefresh()
{
return true;
}
bool SourceGroup::prepareIndexing()
{
return true;
}
void SourceGroup::fetchSourceFilePathsToIndex(const std::set<FilePath>& staticSourceFilePaths)
{
for (const FilePath& sourceFilePath: m_allSourceFilePaths)
{
if (staticSourceFilePaths.find(sourceFilePath) == staticSourceFilePaths.end())
{
m_sourceFilePathsToIndex.insert(sourceFilePath);
}
}
}
std::set<FilePath> SourceGroup::getAllSourceFilePaths() const
{
return m_allSourceFilePaths;
}
std::set<FilePath> SourceGroup::getSourceFilePathsToIndex() const
{
return m_sourceFilePathsToIndex;
}
+38
View File
@@ -0,0 +1,38 @@
#ifndef SOURCE_GROUP_H
#define SOURCE_GROUP_H
#include <memory>
#include <set>
#include <vector>
#include "utility/file/FilePath.h"
#include "settings/LanguageType.h"
#include "settings/SourceGroupType.h"
class IndexerCommand;
class SourceGroup
{
public:
virtual ~SourceGroup();
virtual SourceGroupType getType() const = 0;
LanguageType getLanguage() const;
virtual bool prepareRefresh();
virtual bool prepareIndexing();
virtual void fetchAllSourceFilePaths() = 0;
void fetchSourceFilePathsToIndex(const std::set<FilePath>& staticSourceFilePaths);
std::set<FilePath> getAllSourceFilePaths() const;
std::set<FilePath> getSourceFilePathsToIndex() const;
virtual std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(const bool fullRefresh) = 0;
protected:
std::set<FilePath> m_allSourceFilePaths;
std::set<FilePath> m_sourceFilePathsToIndex;
};
#endif // SOURCE_GROUP_H
+55
View File
@@ -0,0 +1,55 @@
#include "project/SourceGroupFactory.h"
#include "project/SourceGroup.h"
#include "project/SourceGroupFactoryModule.h"
#include "settings/SourceGroupSettings.h"
std::shared_ptr<SourceGroupFactory> SourceGroupFactory::getInstance()
{
if (!s_instance)
{
s_instance = std::shared_ptr<SourceGroupFactory>(new SourceGroupFactory());
}
return s_instance;
}
void SourceGroupFactory::addModule(std::shared_ptr<SourceGroupFactoryModule> module)
{
m_modules.push_back(module);
}
std::vector<std::shared_ptr<SourceGroup>> SourceGroupFactory::createSourceGroups(std::vector<std::shared_ptr<SourceGroupSettings>> allSourceGroupSettings)
{
std::vector<std::shared_ptr<SourceGroup>> sourceGroups;
for (std::shared_ptr<SourceGroupSettings> sourceGroupSettings: allSourceGroupSettings)
{
std::shared_ptr<SourceGroup> sourceGroup = createSourceGroup(sourceGroupSettings);
if (sourceGroup)
{
sourceGroups.push_back(sourceGroup);
}
}
return sourceGroups;
}
std::shared_ptr<SourceGroup> SourceGroupFactory::createSourceGroup(std::shared_ptr<SourceGroupSettings> settings)
{
std::shared_ptr<SourceGroup> sourceGroup;
for (std::shared_ptr<SourceGroupFactoryModule> module: m_modules)
{
if (module->supports(settings->getType()))
{
sourceGroup = module->createSourceGroup(settings);
break;
}
}
return sourceGroup;
}
std::shared_ptr<SourceGroupFactory> SourceGroupFactory::s_instance;
SourceGroupFactory::SourceGroupFactory()
{
}
+30
View File
@@ -0,0 +1,30 @@
#ifndef SOURCE_GROUP_FACTORY_H
#define SOURCE_GROUP_FACTORY_H
#include <memory>
#include <vector>
#include "settings/SourceGroupType.h"
class SourceGroup;
class SourceGroupSettings;
class SourceGroupFactoryModule;
class SourceGroupFactory
{
public:
static std::shared_ptr<SourceGroupFactory> getInstance();
void addModule(std::shared_ptr<SourceGroupFactoryModule> module);
std::vector<std::shared_ptr<SourceGroup>> createSourceGroups(std::vector<std::shared_ptr<SourceGroupSettings>> allSourceGroupSettings);
std::shared_ptr<SourceGroup> createSourceGroup(std::shared_ptr<SourceGroupSettings> settings);
private:
static std::shared_ptr<SourceGroupFactory> s_instance;
SourceGroupFactory();
std::vector<std::shared_ptr<SourceGroupFactoryModule>> m_modules;
};
#endif // SOURCE_GROUP_FACTORY_H
@@ -0,0 +1,5 @@
#include "project/SourceGroupFactoryModule.h"
SourceGroupFactoryModule::~SourceGroupFactoryModule()
{
}
@@ -0,0 +1,19 @@
#ifndef SOURCE_GROUP_FACTORY_MODULE_H
#define SOURCE_GROUP_FACTORY_MODULE_H
#include <memory>
#include "settings/SourceGroupType.h"
class SourceGroup;
class SourceGroupSettings;
class SourceGroupFactoryModule
{
public:
virtual ~SourceGroupFactoryModule();
virtual bool supports(SourceGroupType type) const = 0;
virtual std::shared_ptr<SourceGroup> createSourceGroup(std::shared_ptr<SourceGroupSettings> settings) = 0;
};
#endif // SOURCE_GROUP_FACTORY_MODULE_H
+10 -6
View File
@@ -1,5 +1,6 @@
#include "settings/ApplicationSettings.h"
#include "settings/migration/MigrationMoveKey.h"
#include "utility/ResourcePaths.h"
#include "utility/Status.h"
#include "utility/utility.h"
@@ -37,15 +38,18 @@ bool ApplicationSettings::load(const FilePath& filePath)
SettingsMigrator migrator;
migrator.addMigration(1,
migrator.addMigration(1, std::make_shared<MigrationMoveKey>(
"source/header_search_paths/header_search_path",
"indexing/cxx/header_search_paths/header_search_path");
migrator.addMigration(1,
"indexing/cxx/header_search_paths/header_search_path"
));
migrator.addMigration(1, std::make_shared<MigrationMoveKey>(
"source/framework_search_paths/framework_search_path",
"indexing/cxx/framework_search_paths/framework_search_path");
migrator.addMigration(1,
"indexing/cxx/framework_search_paths/framework_search_path"
));
migrator.addMigration(1, std::make_shared<MigrationMoveKey>(
"application/indexer_thread_count",
"indexing/indexer_thread_count");
"indexing/indexer_thread_count"
));
bool migrated = migrator.migrate(this, ApplicationSettings::VERSION);
-245
View File
@@ -1,245 +0,0 @@
#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()
{
}
ProjectType CxxProjectSettings::getProjectType() const
{
if (!getVisualStudioSolutionPath().empty()) // I think this is crap. VS solution path is not used anymore.. so vs projects are handled like cdb projects
{
return PROJECT_CXX_VS;
}
else if (!getCompilationDatabasePath().empty())
{
return PROJECT_CXX_CDB;
}
else
{
switch (getLanguage())
{
case LANGUAGE_C:
return PROJECT_C_EMPTY;
case LANGUAGE_CPP:
return PROJECT_CPP_EMPTY;
default:
return PROJECT_UNKNOWN;
}
}
return PROJECT_UNKNOWN;
}
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<std::string> CxxProjectSettings::getLanguageStandards() const
{
std::vector<std::string> standards;
switch (getLanguage())
{
case LANGUAGE_CPP:
standards.push_back("c++1z");
standards.push_back("gnu++1z");
standards.push_back("c++14");
standards.push_back("gnu++14");
standards.push_back("c++1y");
standards.push_back("gnu++1y");
standards.push_back("c++11");
standards.push_back("gnu++11");
standards.push_back("c++0x");
standards.push_back("gnu++0x");
standards.push_back("c++03");
standards.push_back("c++98");
standards.push_back("gnu++98");
break;
case LANGUAGE_C:
standards.push_back("c1x");
standards.push_back("gnu1x");
standards.push_back("iso9899:201x");
standards.push_back("c11");
standards.push_back("gnu11");
standards.push_back("iso9899:2011");
standards.push_back("c9x");
standards.push_back("gnu9x");
standards.push_back("iso9899:199x");
standards.push_back("c99");
standards.push_back("gnu99");
standards.push_back("iso9899:1999");
standards.push_back("iso9899:199409");
standards.push_back("c90");
standards.push_back("gnu90");
standards.push_back("iso9899:1990");
standards.push_back("c89");
standards.push_back("gnu89");
break;
default:
break;
}
return standards;
}
std::vector<FilePath> CxxProjectSettings::getHeaderSearchPaths() const
{
return getPathValues("source/header_search_paths/header_search_path");
}
std::vector<FilePath> CxxProjectSettings::getAbsoluteHeaderSearchPaths() const
{
return makePathsAbsolute(expandPaths(getHeaderSearchPaths()));
}
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
{
return makePathsAbsolute(expandPaths(getFrameworkSearchPaths()));
}
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);
}
bool CxxProjectSettings::getHasDefinedUseSourcePathsForHeaderSearch() const
{
return isValueDefined("source/use_source_paths_for_header_search");
}
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", ""));
}
FilePath CxxProjectSettings::getAbsoluteCompilationDatabasePath() const
{
return makePathAbsolute(expandPath(getCompilationDatabasePath()));
}
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;
switch (getLanguage())
{
case LANGUAGE_CPP:
defaultValues.push_back(".cpp");
defaultValues.push_back(".cxx");
defaultValues.push_back(".cc");
break;
case LANGUAGE_C:
defaultValues.push_back(".c");
break;
default:
break;
}
return defaultValues;
}
std::string CxxProjectSettings::getDefaultStandard() const
{
switch (getLanguage())
{
case LANGUAGE_CPP:
return "c++1z";
case LANGUAGE_C:
return "c1x";
default:
break;
}
return "";
}
-48
View File
@@ -1,48 +0,0 @@
#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 ProjectType getProjectType() const;
virtual bool equalsExceptNameAndLocation(const ProjectSettings& other) const;
virtual std::vector<std::string> getLanguageStandards() 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);
// deprecated
bool getUseSourcePathsForHeaderSearch() const;
bool setUseSourcePathsForHeaderSearch(bool useSourcePathsForHeaderSearch);
bool getHasDefinedUseSourcePathsForHeaderSearch() const;
FilePath getVisualStudioSolutionPath() const;
bool setVisualStudioSolutionPath(const FilePath& visualStudioSolutionPath);
FilePath getCompilationDatabasePath() const;
FilePath getAbsoluteCompilationDatabasePath() const;
bool setCompilationDatabasePath(const FilePath& compilationDatabasePath);
private:
virtual std::vector<std::string> getDefaultSourceExtensions() const;
virtual std::string getDefaultStandard() const;
};
#endif // CXX_PROJECT_SETTINGS_H
-117
View File
@@ -1,117 +0,0 @@
#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()
{
}
ProjectType JavaProjectSettings::getProjectType() const
{
if (!getMavenProjectFilePath().empty())
{
return PROJECT_JAVA_MAVEN;
}
return PROJECT_JAVA_EMPTY;
}
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<std::string> JavaProjectSettings::getLanguageStandards() const
{
return std::vector<std::string>(1, "8");
}
std::vector<FilePath> JavaProjectSettings::getClasspaths() const
{
return getPathValues("source/class_paths/class_path");
}
std::vector<FilePath> JavaProjectSettings::getAbsoluteClasspaths() const
{
return makePathsAbsolute(expandPaths(getClasspaths()));
}
bool JavaProjectSettings::setClasspaths(const std::vector<FilePath>& classpaths)
{
return setPathValues("source/class_paths/class_path", classpaths);
}
FilePath JavaProjectSettings::getMavenProjectFilePath() const
{
return FilePath(getValue<std::string>("source/maven/project_file_path", ""));
}
FilePath JavaProjectSettings::getAbsoluteMavenProjectFilePath() const
{
return makePathAbsolute(expandPath(getMavenProjectFilePath()));
}
bool JavaProjectSettings::setMavenProjectFilePath(const FilePath& path)
{
return setValue("source/maven/project_file_path", path.str());
}
FilePath JavaProjectSettings::getMavenDependenciesDirectory() const
{
return FilePath(getValue<std::string>("source/maven/dependencies_directory", ""));
}
FilePath JavaProjectSettings::getAbsoluteMavenDependenciesDirectory() const
{
return makePathAbsolute(expandPath(getMavenDependenciesDirectory()));
}
bool JavaProjectSettings::setMavenDependenciesDirectory(const FilePath& path)
{
return setValue("source/maven/dependencies_directory", path.str());
}
bool JavaProjectSettings::getShouldIndexMavenTests() const
{
return getValue<bool>("source/maven/should_index_tests", false);
}
void JavaProjectSettings::setShouldIndexMavenTests(bool value)
{
setValue<bool>("source/maven/should_index_tests", value);
}
std::vector<std::string> JavaProjectSettings::getDefaultSourceExtensions() const
{
std::vector<std::string> defaultValues;
defaultValues.push_back(".java");
return defaultValues;
}
std::string JavaProjectSettings::getDefaultStandard() const
{
return "8";
}
-41
View File
@@ -1,41 +0,0 @@
#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 ProjectType getProjectType() const;
virtual bool equalsExceptNameAndLocation(const ProjectSettings& other) const;
virtual std::vector<std::string> getLanguageStandards() const;
std::vector<FilePath> getClasspaths() const;
std::vector<FilePath> getAbsoluteClasspaths() const;
bool setClasspaths(const std::vector<FilePath>& classpaths);
FilePath getMavenProjectFilePath() const;
FilePath getAbsoluteMavenProjectFilePath() const;
bool setMavenProjectFilePath(const FilePath& path);
FilePath getMavenDependenciesDirectory() const;
FilePath getAbsoluteMavenDependenciesDirectory() const;
bool setMavenDependenciesDirectory(const FilePath& path);
bool getShouldIndexMavenTests() const;
void setShouldIndexMavenTests(bool value);
private:
virtual std::vector<std::string> getDefaultSourceExtensions() const;
virtual std::string getDefaultStandard() const;
};
#endif // JAVA_PROJECT_SETTINGS_H
+7 -7
View File
@@ -48,21 +48,21 @@ std::string getSymbolNameDelimiterForLanguage(LanguageType t)
return "@";
}
LanguageType getLanguageTypeForProjectType(ProjectType t)
LanguageType getLanguageTypeForSourceGroupType(SourceGroupType t)
{
switch (t)
{
case PROJECT_C_EMPTY:
case SOURCE_GROUP_C_EMPTY:
return LANGUAGE_C;
case PROJECT_CPP_EMPTY:
case SOURCE_GROUP_CPP_EMPTY:
return LANGUAGE_CPP;
case PROJECT_CXX_CDB:
case SOURCE_GROUP_CXX_CDB:
return LANGUAGE_CPP;
case PROJECT_CXX_VS:
case SOURCE_GROUP_CXX_VS:
return LANGUAGE_CPP;
case PROJECT_JAVA_EMPTY:
case SOURCE_GROUP_JAVA_EMPTY:
return LANGUAGE_JAVA;
case PROJECT_JAVA_MAVEN:
case SOURCE_GROUP_JAVA_MAVEN:
return LANGUAGE_JAVA;
default:
break;
+2 -2
View File
@@ -3,7 +3,7 @@
#include <string>
#include "settings/ProjectType.h"
#include "settings/SourceGroupType.h"
enum LanguageType
{
@@ -17,6 +17,6 @@ std::string languageTypeToString(LanguageType t);
LanguageType stringToLanguageType(std::string s);
std::string getSymbolNameDelimiterForLanguage(LanguageType t);
LanguageType getLanguageTypeForProjectType(ProjectType t);
LanguageType getLanguageTypeForSourceGroupType(SourceGroupType t);
#endif // LANGUAGE_TYPE_H
+230 -96
View File
@@ -1,17 +1,38 @@
#include "settings/ProjectSettings.h"
#include "settings/CxxProjectSettings.h"
#include "settings/JavaProjectSettings.h"
#include "settings/migration/MigrationDeleteKey.h"
#include "settings/migration/MigrationLambda.h"
#include "settings/migration/MigrationMoveKey.h"
#include "settings/SourceGroupSettingsCxx.h"
#include "settings/SourceGroupSettingsJava.h"
#include "utility/utility.h"
#include "utility/utilityString.h"
#include "utility/UUIDUtility.h"
const size_t ProjectSettings::VERSION = 1;
const size_t ProjectSettings::VERSION = 4;
LanguageType ProjectSettings::getLanguageOfProject(FilePath projectFilePath)
LanguageType ProjectSettings::getLanguageOfProject(const FilePath& filePath)
{
ProjectSettings tempSettings;
tempSettings.load(projectFilePath);
return tempSettings.getLanguage();
LanguageType languageType = LANGUAGE_UNKNOWN;
ProjectSettings projectSettings;
projectSettings.load(filePath);
for (std::shared_ptr<SourceGroupSettings> sourceGroupSettings: projectSettings.getAllSourceGroupSettings())
{
const LanguageType currentLanguageType = getLanguageTypeForSourceGroupType(sourceGroupSettings->getType());
if (languageType == LANGUAGE_UNKNOWN)
{
languageType = currentLanguageType;
}
else if (languageType != currentLanguageType)
{
// language is unknown if source groups have different languages.
languageType = LANGUAGE_UNKNOWN;
break;
}
}
return languageType;
}
ProjectSettings::ProjectSettings()
@@ -32,25 +53,35 @@ ProjectSettings::~ProjectSettings()
{
}
ProjectType ProjectSettings::getProjectType() const
{
return PROJECT_UNKNOWN;
}
bool ProjectSettings::equalsExceptNameAndLocation(const ProjectSettings& other) const
{
return (
getLanguage() == other.getLanguage() &&
getStandard() == other.getStandard() &&
utility::isPermutation<FilePath>(getSourcePaths(), other.getSourcePaths()) &&
utility::isPermutation<FilePath>(getExcludePaths(), other.getExcludePaths()) &&
utility::isPermutation<std::string>(getSourceExtensions(), other.getSourceExtensions())
);
}
const std::vector<std::shared_ptr<SourceGroupSettings>> allMySettings = getAllSourceGroupSettings();
const std::vector<std::shared_ptr<SourceGroupSettings>> allOtherSettings = other.getAllSourceGroupSettings();
std::vector<std::string> ProjectSettings::getLanguageStandards() const
{
return std::vector<std::string>();
if (allMySettings.size() != allOtherSettings.size())
{
return false;
}
for (std::shared_ptr<SourceGroupSettings> mySourceGroup: allMySettings)
{
bool matched = false;
for (std::shared_ptr<SourceGroupSettings> otherSourceGroup: allOtherSettings)
{
if (mySourceGroup->equals(otherSourceGroup))
{
matched = true;
break;
}
}
if (!matched)
{
return false;
}
}
return true;
}
bool ProjectSettings::needMigration() const
@@ -96,67 +127,123 @@ void ProjectSettings::setProjectFileLocation(const FilePath& location)
std::string ProjectSettings::getDescription() const
{
return getValue<std::string>("info/description", "");
return getValue<std::string>("description", "");
}
LanguageType ProjectSettings::getLanguage() const
std::vector<std::shared_ptr<SourceGroupSettings>> ProjectSettings::getAllSourceGroupSettings() const
{
return stringToLanguageType(getValue<std::string>("language_settings/language", languageTypeToString(LANGUAGE_UNKNOWN)));
std::vector<std::shared_ptr<SourceGroupSettings>> allSettings;
for (const std::string& key: m_config->getSublevelKeys("source_groups"))
{
const std::string id = key.substr(std::string("source_groups/source_group_").length());
const SourceGroupType type = stringToSourceGroupType(getValue<std::string>(key + "/type", ""));
std::shared_ptr<SourceGroupSettings> settings;
switch (type)
{
case SOURCE_GROUP_C_EMPTY:
case SOURCE_GROUP_CPP_EMPTY:
case SOURCE_GROUP_CXX_CDB:
{
std::shared_ptr<SourceGroupSettingsCxx> cxxSettings = std::make_shared<SourceGroupSettingsCxx>(id, type, this);
cxxSettings->setHeaderSearchPaths(getPathValues(key + "/header_search_paths/header_search_path"));
cxxSettings->setFrameworkSearchPaths(getPathValues(key + "/framework_search_paths/framework_search_path"));
cxxSettings->setCompilerFlags(getValues<std::string>(key + "/compiler_flags/compiler_flag", std::vector<std::string>()));
cxxSettings->setUseSourcePathsForHeaderSearch(getValue<bool>(key + "/use_source_paths_for_header_search", false));
cxxSettings->setHasDefinedUseSourcePathsForHeaderSearch(isValueDefined(key + "/use_source_paths_for_header_search"));
if (type == SOURCE_GROUP_CXX_CDB)
{
cxxSettings->setCompilationDatabasePath(FilePath(getValue<std::string>(key + "/build_file_path/compilation_db_path", "")));
}
settings = cxxSettings;
}
break;
case SOURCE_GROUP_JAVA_EMPTY:
case SOURCE_GROUP_JAVA_MAVEN:
{
std::shared_ptr<SourceGroupSettingsJava> javaSettings = std::make_shared<SourceGroupSettingsJava>(id, type, this);
javaSettings->setClasspaths(getPathValues(key + "/class_paths/class_path"));
if (type == SOURCE_GROUP_JAVA_MAVEN)
{
javaSettings->setMavenProjectFilePath(FilePath(getValue<std::string>(key + "/maven/project_file_path", "")));
javaSettings->setMavenDependenciesDirectory(FilePath(getValue<std::string>(key + "/maven/dependencies_directory", "")));
javaSettings->setShouldIndexMavenTests(getValue<bool>(key + "/maven/should_index_tests", false));
}
settings = javaSettings;
}
break;
default:
continue;
}
settings->setStandard(getValue<std::string>(key + "/standard", ""));
settings->setSourcePaths(getPathValues(key + "/source_paths/source_path"));
settings->setExcludePaths(getPathValues(key + "/exclude_paths/exclude_path"));
settings->setSourceExtensions(getValues(key + "/source_extensions/source_extension", std::vector<std::string>()));
allSettings.push_back(settings);
}
return allSettings;
}
bool ProjectSettings::setLanguage(LanguageType language)
void ProjectSettings::setAllSourceGroupSettings(std::vector<std::shared_ptr<SourceGroupSettings>> allSettings)
{
return setValue<std::string>("language_settings/language", languageTypeToString(language));
}
for (const std::string& key: m_config->getSublevelKeys("source_groups"))
{
m_config->removeValues(key);
}
std::string ProjectSettings::getStandard() const
{
return getValue<std::string>("language_settings/standard", getDefaultStandard());
}
for (std::shared_ptr<SourceGroupSettings> settings: allSettings)
{
const std::string key = "source_groups/source_group_" + settings->getId();
const SourceGroupType type = settings->getType();
bool ProjectSettings::setStandard(const std::string& standard)
{
return setValue<std::string>("language_settings/standard", standard);
}
setValue(key + "/type", sourceGroupTypeToString(type));
setValue(key + "/standard", settings->getStandard());
setPathValues(key + "/source_paths/source_path", settings->getSourcePaths());
setPathValues(key + "/exclude_paths/exclude_path", settings->getExcludePaths());
setValues(key + "/source_extensions/source_extension", settings->getSourceExtensions());
std::vector<FilePath> ProjectSettings::getSourcePaths() const // TODO: rename to getIndexedPaths
{
return getPathValues("source/source_paths/source_path");
}
switch (type)
{
case SOURCE_GROUP_C_EMPTY:
case SOURCE_GROUP_CPP_EMPTY:
case SOURCE_GROUP_CXX_CDB:
if (std::shared_ptr<SourceGroupSettingsCxx> cxxSettings = std::dynamic_pointer_cast<SourceGroupSettingsCxx>(settings))
{
setPathValues(key + "/header_search_paths/header_search_path", cxxSettings->getHeaderSearchPaths());
setPathValues(key + "/framework_search_paths/framework_search_path", cxxSettings->getFrameworkSearchPaths());
setValues(key + "/compiler_flags/compiler_flag", cxxSettings->getCompilerFlags());
if (cxxSettings->getHasDefinedUseSourcePathsForHeaderSearch())
{
setValue(key + "/use_source_paths_for_header_search", cxxSettings->getUseSourcePathsForHeaderSearch());
}
if (type == SOURCE_GROUP_CXX_CDB)
{
setValue(key + "/build_file_path/compilation_db_path", cxxSettings->getCompilationDatabasePath().str());
}
}
break;
case SOURCE_GROUP_JAVA_EMPTY:
case SOURCE_GROUP_JAVA_MAVEN:
if (std::shared_ptr<SourceGroupSettingsJava> javaSettings = std::dynamic_pointer_cast<SourceGroupSettingsJava>(settings))
{
setPathValues(key + "/class_paths/class_path", javaSettings->getClasspaths());
std::vector<FilePath> ProjectSettings::getAbsoluteSourcePaths() const
{
return makePathsAbsolute(expandPaths(getSourcePaths()));
}
bool ProjectSettings::setSourcePaths(const std::vector<FilePath>& sourcePaths)
{
return setPathValues("source/source_paths/source_path", sourcePaths);
}
std::vector<FilePath> ProjectSettings::getExcludePaths() const
{
return getPathValues("source/exclude_paths/exclude_path");
}
std::vector<FilePath> ProjectSettings::getAbsoluteExcludePaths() const
{
return makePathsAbsolute(expandPaths(getExcludePaths()));
}
bool ProjectSettings::setExcludePaths(const std::vector<FilePath>& excludePaths)
{
return setPathValues("source/exclude_paths/exclude_path", excludePaths);
}
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);
if (type == SOURCE_GROUP_JAVA_MAVEN)
{
setValue(key + "/maven/project_file_path", javaSettings->getMavenProjectFilePath().str());
setValue(key + "/maven/dependencies_directory", javaSettings->getMavenDependenciesDirectory().str());
setValue(key + "/maven/should_index_tests", javaSettings->getShouldIndexMavenTests());
}
}
break;
default:
continue;
}
}
}
std::vector<FilePath> ProjectSettings::makePathsAbsolute(const std::vector<FilePath>& paths) const
@@ -189,39 +276,86 @@ FilePath ProjectSettings::makePathAbsolute(const FilePath& path) const
return getProjectFileLocation().concat(path).canonical();
}
std::vector<std::string> ProjectSettings::getDefaultSourceExtensions() const
{
return std::vector<std::string>();
}
std::string ProjectSettings::getDefaultStandard() const
{
return "";
}
SettingsMigrator ProjectSettings::getMigrations() const
{
SettingsMigrator migrator;
migrator.addMigration(1, std::make_shared<MigrationLambda>(
[](const Migration* migration, Settings* settings)
{
const std::string language = migration->getValueFromSettings<std::string>(settings, "language_settings/language", "");
const std::string standard = migration->getValueFromSettings<std::string>(settings, "language_settings/standard", "");
if (getLanguage() == LANGUAGE_C || getLanguage() == LANGUAGE_CPP)
{
migrator.addLambdaMigration(1,
[](Settings* settings)
if (language == "C" && !utility::isPrefix("c", standard))
{
ProjectSettings* s = dynamic_cast<ProjectSettings*>(settings);
migration->setValueInSettings(settings, "language_settings/standard", "c" + standard);
}
if (s->getLanguage() == LANGUAGE_C && !utility::isPrefix("c", s->getStandard()))
if (language == "C++" && !utility::isPrefix("c++", standard))
{
migration->setValueInSettings(settings, "language_settings/standard", "c++" + standard);
}
}
));
const std::string sourceGroupKey = "source_groups/source_group_" + UUIDUtility::getUUIDString();
migrator.addMigration(2, std::make_shared<MigrationMoveKey>("info/description", "description"));
migrator.addMigration(2, std::make_shared<MigrationMoveKey>("language_settings/standard", sourceGroupKey + "/standard"));
migrator.addMigration(2, std::make_shared<MigrationMoveKey>("source/source_paths/source_path", sourceGroupKey + "/source_paths/source_path"));
migrator.addMigration(2, std::make_shared<MigrationMoveKey>("source/exclude_paths/exclude_path", sourceGroupKey + "/exclude_paths/exclude_path"));
migrator.addMigration(2, std::make_shared<MigrationMoveKey>("source/extensions/source_extensions", sourceGroupKey + "/source_extensions/source_extension"));
migrator.addMigration(2, std::make_shared<MigrationMoveKey>("source/header_search_paths/header_search_path", sourceGroupKey + "/header_search_paths/header_search_path"));
migrator.addMigration(2, std::make_shared<MigrationMoveKey>("source/use_source_paths_for_header_search", sourceGroupKey + "/use_source_paths_for_header_search"));
migrator.addMigration(2, std::make_shared<MigrationMoveKey>("source/framework_search_paths/framework_search_path", sourceGroupKey + "/framework_search_paths/framework_search_path"));
migrator.addMigration(2, std::make_shared<MigrationMoveKey>("source/compiler_flags/compiler_flag", sourceGroupKey + "/compiler_flags/compiler_flag"));
migrator.addMigration(2, std::make_shared<MigrationMoveKey>("source/build_file_path/compilation_db_path", sourceGroupKey + "/build_file_path/compilation_db_path"));
migrator.addMigration(2, std::make_shared<MigrationMoveKey>("source/class_paths/class_path", sourceGroupKey + "/class_paths/class_path"));
migrator.addMigration(2, std::make_shared<MigrationMoveKey>("source/maven/project_file_path", sourceGroupKey + "/maven/project_file_path"));
migrator.addMigration(2, std::make_shared<MigrationMoveKey>("source/maven/dependencies_directory", sourceGroupKey + "/maven/dependencies_directory"));
migrator.addMigration(2, std::make_shared<MigrationMoveKey>("source/maven/should_index_tests", sourceGroupKey + "/maven/should_index_tests"));
migrator.addMigration(3, std::make_shared<MigrationLambda>(
[=](const Migration* migration, Settings* settings)
{
const std::string language = migration->getValueFromSettings<std::string>(settings, "language_settings/language", "");
SourceGroupType type = SOURCE_GROUP_UNKNOWN;
if (language == "C" || language == "C++")
{
const std::string cdbPath = migration->getValueFromSettings<std::string>(settings, sourceGroupKey + "/build_file_path/compilation_db_path", "");
if (!cdbPath.empty())
{
s->setStandard("c" + s->getStandard());
type = SOURCE_GROUP_CXX_CDB;
}
if (s->getLanguage() == LANGUAGE_CPP && !utility::isPrefix("c++", s->getStandard()))
else if (language == "C")
{
s->setStandard("c++" + s->getStandard());
type = SOURCE_GROUP_C_EMPTY;
}
else
{
type = SOURCE_GROUP_CPP_EMPTY;
}
}
);
}
else if (language == "Java")
{
const std::string mavenProjectFilePath = migration->getValueFromSettings<std::string>(settings, sourceGroupKey + "/maven/project_file_path", "");
if (!mavenProjectFilePath.empty())
{
type = SOURCE_GROUP_JAVA_MAVEN;
}
else
{
type = SOURCE_GROUP_JAVA_EMPTY;
}
}
migration->setValueInSettings(settings, sourceGroupKey + "/type", sourceGroupTypeToString(type));
}
));
migrator.addMigration(4, std::make_shared<MigrationDeleteKey>("language_settings/language"));
migrator.addMigration(4, std::make_shared<MigrationDeleteKey>("source/build_file_path/vs_solution_path"));
migrator.addMigration(4, std::make_shared<MigrationDeleteKey>("source/extensions/header_extensions"));
return migrator;
}
+7 -27
View File
@@ -4,27 +4,24 @@
#include <memory>
#include <vector>
#include "settings/Settings.h"
#include "settings/LanguageType.h"
#include "settings/Settings.h"
class SourceGroupSettings;
class ProjectSettings
: public Settings
{
public:
static LanguageType getLanguageOfProject(FilePath projectFilePath);
static const size_t VERSION;
static LanguageType getLanguageOfProject(const FilePath& filePath);
ProjectSettings();
ProjectSettings(const FilePath& projectFilePath);
ProjectSettings(std::string projectName, const FilePath& projectFileLocation);
virtual ~ProjectSettings();
virtual ProjectType getProjectType() const;
virtual bool equalsExceptNameAndLocation(const ProjectSettings& other) const;
virtual std::vector<std::string> getLanguageStandards() const;
bool equalsExceptNameAndLocation(const ProjectSettings& other) const;
bool needMigration() const;
void migrate();
@@ -38,31 +35,14 @@ public:
void setProjectFileLocation(const FilePath& location);
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);
std::vector<std::shared_ptr<SourceGroupSettings>> getAllSourceGroupSettings() const;
void setAllSourceGroupSettings(std::vector<std::shared_ptr<SourceGroupSettings>> allSettings);
std::vector<FilePath> makePathsAbsolute(const std::vector<FilePath>& paths) const;
FilePath makePathAbsolute(const FilePath& path) const;
private:
virtual std::vector<std::string> getDefaultSourceExtensions() const;
virtual std::string getDefaultStandard() const;
SettingsMigrator getMigrations() const;
};
-53
View File
@@ -1,53 +0,0 @@
#include "settings/ProjectType.h"
std::string projectTypeToString(ProjectType v)
{
switch (v)
{
case PROJECT_C_EMPTY:
return "Empty C Project";
case PROJECT_CPP_EMPTY:
return "Empty C++ Project";
case PROJECT_CXX_CDB:
return "C/C++ from Compilation Database";
case PROJECT_CXX_VS:
return "C/C++ from Visual Studio";
case PROJECT_JAVA_EMPTY:
return "Empty Java Project";
case PROJECT_JAVA_MAVEN:
return "Java Project from Maven";
case PROJECT_UNKNOWN:
break;
}
return "unknown";
}
ProjectType stringToProjectType(std::string v)
{
if (v == projectTypeToString(PROJECT_C_EMPTY))
{
return PROJECT_C_EMPTY;
}
else if (v == projectTypeToString(PROJECT_CPP_EMPTY))
{
return PROJECT_CPP_EMPTY;
}
else if (v == projectTypeToString(PROJECT_CXX_CDB))
{
return PROJECT_CXX_CDB;
}
else if (v == projectTypeToString(PROJECT_CXX_VS))
{
return PROJECT_CXX_VS;
}
else if (v == projectTypeToString(PROJECT_JAVA_EMPTY))
{
return PROJECT_JAVA_EMPTY;
}
else if (v == projectTypeToString(PROJECT_JAVA_MAVEN))
{
return PROJECT_JAVA_MAVEN;
}
return PROJECT_UNKNOWN;
}
-20
View File
@@ -1,20 +0,0 @@
#ifndef PROJECT_TYPE_H
#define PROJECT_TYPE_H
#include <string>
enum ProjectType
{
PROJECT_C_EMPTY,
PROJECT_CPP_EMPTY,
PROJECT_CXX_CDB,
PROJECT_CXX_VS,
PROJECT_JAVA_EMPTY,
PROJECT_JAVA_MAVEN,
PROJECT_UNKNOWN
};
std::string projectTypeToString(ProjectType v);
ProjectType stringToProjectType(std::string v);
#endif // PROJECT_TYPE_H
+5 -1
View File
@@ -8,7 +8,8 @@
#include "utility/ConfigManager.h"
#include "utility/file/FilePath.h"
#include "settings/SettingsMigrator.h"
#include "settings/migration/SettingsMigrator.h"
#include "settings/migration/Migration.h"
class Settings
{
@@ -65,6 +66,9 @@ protected:
private:
FilePath m_filePath;
friend SettingsMigrator;
friend Migration;
};
template<typename T>
-89
View File
@@ -1,89 +0,0 @@
#include "settings/SettingsMigrator.h"
#include "settings/Settings.h"
SettingsMigrator::SettingsMigrator()
{
}
SettingsMigrator::~SettingsMigrator()
{
}
void SettingsMigrator::addMigration(size_t targetVersion, std::string oldKey, std::string newKey)
{
Migration migration;
migration.targetVersion = targetVersion;
migration.oldKey = oldKey;
migration.newKey = newKey;
m_migrations.emplace(targetVersion, migration);
}
void SettingsMigrator::addLambdaMigration(size_t targetVersion, std::function<void(Settings*)> lambda)
{
Migration migration;
migration.targetVersion = targetVersion;
migration.lambda = lambda;
m_migrations.emplace(targetVersion, migration);
}
bool SettingsMigrator::willMigrate(const Settings* settings, size_t targetVersion) const
{
size_t originVersion = settings->getVersion();
if (originVersion < targetVersion)
{
for (; originVersion <= targetVersion; originVersion++)
{
std::pair<std::multimap<size_t, Migration>::const_iterator, std::multimap<size_t, Migration>::const_iterator> ret;
ret = m_migrations.equal_range(originVersion);
for (std::multimap<size_t, Migration>::const_iterator it = ret.first; it != ret.second; it++)
{
return true;
}
}
}
return false;
}
bool SettingsMigrator::migrate(Settings* settings, size_t targetVersion) const
{
size_t originVersion = settings->getVersion();
if (originVersion < targetVersion)
{
for (; originVersion <= targetVersion; originVersion++)
{
std::pair<std::multimap<size_t, Migration>::const_iterator, std::multimap<size_t, Migration>::const_iterator> ret;
ret = m_migrations.equal_range(originVersion);
for (std::multimap<size_t, Migration>::const_iterator it = ret.first; it != ret.second; it++)
{
const Migration& migration = it->second;
if (!migration.oldKey.size())
{
migration.lambda(settings);
}
else if (!settings->isValueDefined(migration.newKey))
{
settings->setValues<std::string>(
migration.newKey,
settings->getValues<std::string>(migration.oldKey, std::vector<std::string>())
);
settings->removeValues(migration.oldKey);
}
}
}
settings->setVersion(targetVersion);
return true;
}
return false;
}
+104
View File
@@ -0,0 +1,104 @@
#include "settings/SourceGroupSettings.h"
#include "utility/utility.h"
SourceGroupSettings::SourceGroupSettings(const std::string& id, SourceGroupType type, const ProjectSettings* projectSettings)
: m_id(id)
, m_type(type)
, m_projectSettings(projectSettings)
{
}
SourceGroupSettings::~SourceGroupSettings()
{
}
bool SourceGroupSettings::equals(std::shared_ptr<SourceGroupSettings> other) const
{
return (
m_id == other->m_id &&
m_type == other->m_type &&
m_standard == other->m_standard &&
utility::isPermutation(m_sourcePaths, other->m_sourcePaths) &&
utility::isPermutation(m_excludePaths, other->m_excludePaths) &&
utility::isPermutation(m_sourceExtensions, other->m_sourceExtensions)
);
}
std::string SourceGroupSettings::getId() const
{
return m_id;
}
FilePath SourceGroupSettings::getProjectFileLocation() const
{
return m_projectSettings->getProjectFileLocation();
}
FilePath SourceGroupSettings::makePathAbsolute(const FilePath& path) const
{
return m_projectSettings->makePathAbsolute(path);
}
SourceGroupType SourceGroupSettings::getType() const
{
return m_type;
}
std::string SourceGroupSettings::getStandard() const
{
if (m_standard.empty())
{
return getDefaultStandard();
}
return m_standard;
}
void SourceGroupSettings::setStandard(const std::string& standard)
{
m_standard = standard;
}
std::vector<FilePath> SourceGroupSettings::getSourcePaths() const
{
return m_sourcePaths;
}
std::vector<FilePath> SourceGroupSettings::getAbsoluteSourcePaths() const
{
return m_projectSettings->makePathsAbsolute(getSourcePaths());
}
void SourceGroupSettings::setSourcePaths(const std::vector<FilePath>& sourcePaths)
{
m_sourcePaths = sourcePaths;
}
std::vector<FilePath> SourceGroupSettings::getExcludePaths() const
{
return m_excludePaths;
}
std::vector<FilePath> SourceGroupSettings::getAbsoluteExcludePaths() const
{
return m_projectSettings->makePathsAbsolute(getExcludePaths());
}
void SourceGroupSettings::setExcludePaths(const std::vector<FilePath>& excludePaths)
{
m_excludePaths = excludePaths;
}
std::vector<std::string> SourceGroupSettings::getSourceExtensions() const
{
if (m_sourceExtensions.empty())
{
return getDefaultSourceExtensions();
}
return m_sourceExtensions;
}
void SourceGroupSettings::setSourceExtensions(const std::vector<std::string>& sourceExtensions)
{
m_sourceExtensions = sourceExtensions;
}
+59
View File
@@ -0,0 +1,59 @@
#ifndef SOURCE_GROUP_SETTINGS_H
#define SOURCE_GROUP_SETTINGS_H
#include <memory>
#include <vector>
#include "settings/LanguageType.h"
#include "settings/ProjectSettings.h"
#include "settings/SourceGroupType.h"
class ProjectSettings;
class SourceGroupSettings
{
public:
SourceGroupSettings(const std::string& id, SourceGroupType type, const ProjectSettings* projectSettings);
virtual ~SourceGroupSettings();
virtual bool equals(std::shared_ptr<SourceGroupSettings> other) const;
std::string getId() const;
FilePath getProjectFileLocation() const;
FilePath makePathAbsolute(const FilePath& path) const;
virtual std::vector<std::string> getAvailableLanguageStandards() const = 0;
virtual SourceGroupType getType() const;
std::string getStandard() const;
void setStandard(const std::string& standard);
std::vector<FilePath> getSourcePaths() const;
std::vector<FilePath> getAbsoluteSourcePaths() const;
void setSourcePaths(const std::vector<FilePath>& sourcePaths);
std::vector<FilePath> getExcludePaths() const;
std::vector<FilePath> getAbsoluteExcludePaths() const;
void setExcludePaths(const std::vector<FilePath>& excludePaths);
std::vector<std::string> getSourceExtensions() const;
void setSourceExtensions(const std::vector<std::string>& sourceExtensions);
protected:
const ProjectSettings* m_projectSettings;
private:
virtual std::vector<std::string> getDefaultSourceExtensions() const = 0;
virtual std::string getDefaultStandard() const = 0;
const std::string m_id;
const SourceGroupType m_type;
std::string m_standard;
std::vector<FilePath> m_sourcePaths;
std::vector<FilePath> m_excludePaths;
std::vector<std::string> m_sourceExtensions;
};
#endif // SOURCE_GROUP_SETTINGS_H
+204
View File
@@ -0,0 +1,204 @@
#include "settings/SourceGroupSettingsCxx.h"
#include "utility/utility.h"
SourceGroupSettingsCxx::SourceGroupSettingsCxx(const std::string& id, SourceGroupType type, const ProjectSettings* projectSettings)
: SourceGroupSettings(id, type, projectSettings)
{
}
SourceGroupSettingsCxx::~SourceGroupSettingsCxx()
{
}
bool SourceGroupSettingsCxx::equals(std::shared_ptr<SourceGroupSettings> other) const
{
std::shared_ptr<SourceGroupSettingsCxx> otherCxx = std::dynamic_pointer_cast<SourceGroupSettingsCxx>(other);
return (
otherCxx &&
SourceGroupSettings::equals(other) &&
utility::isPermutation(m_headerSearchPaths, otherCxx->m_headerSearchPaths) &&
utility::isPermutation(m_frameworkSearchPaths, otherCxx->m_frameworkSearchPaths) &&
utility::isPermutation(m_compilerFlags, otherCxx->m_compilerFlags) &&
m_useSourcePathsForHeaderSearch == otherCxx->m_useSourcePathsForHeaderSearch &&
m_hasDefinedUseSourcePathsForHeaderSearch == otherCxx->m_hasDefinedUseSourcePathsForHeaderSearch &&
m_compilationDatabasePath == otherCxx->m_compilationDatabasePath
);
}
std::vector<std::string> SourceGroupSettingsCxx::getAvailableLanguageStandards() const
{
std::vector<std::string> standards;
switch (getType())
{
case SOURCE_GROUP_CPP_EMPTY:
case SOURCE_GROUP_CXX_CDB:
standards.push_back("c++1z");
standards.push_back("gnu++1z");
standards.push_back("c++14");
standards.push_back("gnu++14");
standards.push_back("c++1y");
standards.push_back("gnu++1y");
standards.push_back("c++11");
standards.push_back("gnu++11");
standards.push_back("c++0x");
standards.push_back("gnu++0x");
standards.push_back("c++03");
standards.push_back("c++98");
standards.push_back("gnu++98");
break;
case SOURCE_GROUP_C_EMPTY:
standards.push_back("c1x");
standards.push_back("gnu1x");
standards.push_back("iso9899:201x");
standards.push_back("c11");
standards.push_back("gnu11");
standards.push_back("iso9899:2011");
standards.push_back("c9x");
standards.push_back("gnu9x");
standards.push_back("iso9899:199x");
standards.push_back("c99");
standards.push_back("gnu99");
standards.push_back("iso9899:1999");
standards.push_back("iso9899:199409");
standards.push_back("c90");
standards.push_back("gnu90");
standards.push_back("iso9899:1990");
standards.push_back("c89");
standards.push_back("gnu89");
break;
default:
break;
}
return standards;
}
std::vector<FilePath> SourceGroupSettingsCxx::getHeaderSearchPaths() const
{
return m_headerSearchPaths;
}
std::vector<FilePath> SourceGroupSettingsCxx::getAbsoluteHeaderSearchPaths() const
{
return m_projectSettings->makePathsAbsolute(getHeaderSearchPaths());
}
void SourceGroupSettingsCxx::setHeaderSearchPaths(const std::vector<FilePath>& headerSearchPaths)
{
m_headerSearchPaths = headerSearchPaths;
}
std::vector<FilePath> SourceGroupSettingsCxx::getFrameworkSearchPaths() const
{
return m_frameworkSearchPaths;
}
std::vector<FilePath> SourceGroupSettingsCxx::getAbsoluteFrameworkSearchPaths() const
{
return m_projectSettings->makePathsAbsolute(getFrameworkSearchPaths());
}
void SourceGroupSettingsCxx::setFrameworkSearchPaths(const std::vector<FilePath>& frameworkSearchPaths)
{
m_frameworkSearchPaths = frameworkSearchPaths;
}
std::vector<std::string> SourceGroupSettingsCxx::getCompilerFlags() const
{
return m_compilerFlags;
}
void SourceGroupSettingsCxx::setCompilerFlags(const std::vector<std::string>& compilerFlags)
{
m_compilerFlags = compilerFlags;
}
bool SourceGroupSettingsCxx::getUseSourcePathsForHeaderSearch() const
{
return m_useSourcePathsForHeaderSearch;
}
void SourceGroupSettingsCxx::setUseSourcePathsForHeaderSearch(bool useSourcePathsForHeaderSearch)
{
m_useSourcePathsForHeaderSearch = useSourcePathsForHeaderSearch;
}
bool SourceGroupSettingsCxx::getHasDefinedUseSourcePathsForHeaderSearch() const
{
return m_hasDefinedUseSourcePathsForHeaderSearch;
}
void SourceGroupSettingsCxx::setHasDefinedUseSourcePathsForHeaderSearch(bool hasDefinedUseSourcePathsForHeaderSearch)
{
m_hasDefinedUseSourcePathsForHeaderSearch = hasDefinedUseSourcePathsForHeaderSearch;
}
FilePath SourceGroupSettingsCxx::getCompilationDatabasePath() const
{
return m_compilationDatabasePath;
}
FilePath SourceGroupSettingsCxx::getAbsoluteCompilationDatabasePath() const
{
return m_projectSettings->makePathAbsolute(getCompilationDatabasePath());
}
void SourceGroupSettingsCxx::setCompilationDatabasePath(const FilePath& compilationDatabasePath)
{
m_compilationDatabasePath = compilationDatabasePath;
}
std::vector<std::string> SourceGroupSettingsCxx::getDefaultSourceExtensions() const
{
std::vector<std::string> defaultValues;
switch (getType())
{
case SOURCE_GROUP_CPP_EMPTY:
case SOURCE_GROUP_CXX_CDB:
defaultValues.push_back(".cpp");
defaultValues.push_back(".cxx");
defaultValues.push_back(".cc");
break;
case SOURCE_GROUP_C_EMPTY:
defaultValues.push_back(".c");
break;
default:
break;
}
return defaultValues;
}
std::string SourceGroupSettingsCxx::getDefaultStandard() const
{
switch (getType())
{
case SOURCE_GROUP_CPP_EMPTY:
case SOURCE_GROUP_CXX_CDB:
return "c++1z";
case SOURCE_GROUP_C_EMPTY:
return "c1x";
default:
break;
}
return "";
}
+51
View File
@@ -0,0 +1,51 @@
#ifndef SOURCE_GROUP_SETTINGS_CXX_H
#define SOURCE_GROUP_SETTINGS_CXX_H
#include "settings/SourceGroupSettings.h"
class SourceGroupSettingsCxx
: public SourceGroupSettings
{
public:
SourceGroupSettingsCxx(const std::string& id, SourceGroupType type, const ProjectSettings* projectSettings);
virtual ~SourceGroupSettingsCxx();
virtual bool equals(std::shared_ptr<SourceGroupSettings> other) const;
virtual std::vector<std::string> getAvailableLanguageStandards() const;
std::vector<FilePath> getHeaderSearchPaths() const;
std::vector<FilePath> getAbsoluteHeaderSearchPaths() const;
void setHeaderSearchPaths(const std::vector<FilePath>& headerSearchPaths);
std::vector<FilePath> getFrameworkSearchPaths() const;
std::vector<FilePath> getAbsoluteFrameworkSearchPaths() const;
void setFrameworkSearchPaths(const std::vector<FilePath>& frameworkSearchPaths);
std::vector<std::string> getCompilerFlags() const;
void setCompilerFlags(const std::vector<std::string>& compilerFlags);
// deprecated begin
bool getUseSourcePathsForHeaderSearch() const;
void setUseSourcePathsForHeaderSearch(bool useSourcePathsForHeaderSearch);
bool getHasDefinedUseSourcePathsForHeaderSearch() const;
void setHasDefinedUseSourcePathsForHeaderSearch(bool hasDefinedUseSourcePathsForHeaderSearch);
// deprecated end
FilePath getCompilationDatabasePath() const;
FilePath getAbsoluteCompilationDatabasePath() const;
void setCompilationDatabasePath(const FilePath& compilationDatabasePath);
private:
virtual std::vector<std::string> getDefaultSourceExtensions() const;
virtual std::string getDefaultStandard() const;
std::vector<FilePath> m_headerSearchPaths;
std::vector<FilePath> m_frameworkSearchPaths;
std::vector<std::string> m_compilerFlags;
bool m_useSourcePathsForHeaderSearch;
bool m_hasDefinedUseSourcePathsForHeaderSearch;
FilePath m_compilationDatabasePath;
};
#endif // SOURCE_GROUP_SETTINGS_CXX_H
@@ -0,0 +1,96 @@
#include "settings/SourceGroupSettingsJava.h"
#include "utility/utility.h"
SourceGroupSettingsJava::SourceGroupSettingsJava(const std::string& id, SourceGroupType type, const ProjectSettings* projectSettings)
: SourceGroupSettings(id, type, projectSettings)
{
}
SourceGroupSettingsJava::~SourceGroupSettingsJava()
{
}
bool SourceGroupSettingsJava::equals(std::shared_ptr<SourceGroupSettings> other) const
{
std::shared_ptr<SourceGroupSettingsJava> otherJava = std::dynamic_pointer_cast<SourceGroupSettingsJava>(other);
return (
otherJava &&
SourceGroupSettings::equals(other) &&
utility::isPermutation(m_classpaths, otherJava->m_classpaths) &&
m_mavenProjectFilePath == otherJava->m_mavenProjectFilePath &&
m_mavenDependenciesDirectory == otherJava->m_mavenDependenciesDirectory &&
m_shouldIndexMavenTests == otherJava->m_shouldIndexMavenTests
);
}
std::vector<std::string> SourceGroupSettingsJava::getAvailableLanguageStandards() const
{
return std::vector<std::string>(1, "8");
}
std::vector<FilePath> SourceGroupSettingsJava::getClasspaths() const
{
return m_classpaths;
}
std::vector<FilePath> SourceGroupSettingsJava::getAbsoluteClasspaths() const
{
return m_projectSettings->makePathsAbsolute(getClasspaths());
}
void SourceGroupSettingsJava::setClasspaths(const std::vector<FilePath>& classpaths)
{
m_classpaths = classpaths;
}
FilePath SourceGroupSettingsJava::getMavenProjectFilePath() const
{
return m_mavenProjectFilePath;
}
FilePath SourceGroupSettingsJava::getAbsoluteMavenProjectFilePath() const
{
return m_projectSettings->makePathAbsolute(getMavenProjectFilePath());
}
void SourceGroupSettingsJava::setMavenProjectFilePath(const FilePath& path)
{
m_mavenProjectFilePath = path;
}
FilePath SourceGroupSettingsJava::getMavenDependenciesDirectory() const
{
return m_mavenDependenciesDirectory;
}
FilePath SourceGroupSettingsJava::getAbsoluteMavenDependenciesDirectory() const
{
return m_projectSettings->makePathAbsolute(getMavenDependenciesDirectory());
}
void SourceGroupSettingsJava::setMavenDependenciesDirectory(const FilePath& path)
{
m_mavenDependenciesDirectory = path;
}
bool SourceGroupSettingsJava::getShouldIndexMavenTests() const
{
return m_shouldIndexMavenTests;
}
void SourceGroupSettingsJava::setShouldIndexMavenTests(bool value)
{
m_shouldIndexMavenTests = value;
}
std::vector<std::string> SourceGroupSettingsJava::getDefaultSourceExtensions() const
{
return std::vector<std::string>(1, ".java");
}
std::string SourceGroupSettingsJava::getDefaultStandard() const
{
return "8";
}
@@ -0,0 +1,45 @@
#ifndef SOURCE_GROUP_SETTINGS_JAVA_H
#define SOURCE_GROUP_SETTINGS_JAVA_H
#include <memory>
#include <vector>
#include "settings/SourceGroupSettings.h"
class SourceGroupSettingsJava
: public SourceGroupSettings
{
public:
SourceGroupSettingsJava(const std::string& id, SourceGroupType type, const ProjectSettings* projectSettings);
virtual ~SourceGroupSettingsJava();
virtual bool equals(std::shared_ptr<SourceGroupSettings> other) const;
virtual std::vector<std::string> getAvailableLanguageStandards() const;
std::vector<FilePath> getClasspaths() const;
std::vector<FilePath> getAbsoluteClasspaths() const;
void setClasspaths(const std::vector<FilePath>& classpaths);
FilePath getMavenProjectFilePath() const;
FilePath getAbsoluteMavenProjectFilePath() const;
void setMavenProjectFilePath(const FilePath& path);
FilePath getMavenDependenciesDirectory() const;
FilePath getAbsoluteMavenDependenciesDirectory() const;
void setMavenDependenciesDirectory(const FilePath& path);
bool getShouldIndexMavenTests() const;
void setShouldIndexMavenTests(bool value);
private:
virtual std::vector<std::string> getDefaultSourceExtensions() const;
virtual std::string getDefaultStandard() const;
std::vector<FilePath> m_classpaths;
FilePath m_mavenProjectFilePath;
FilePath m_mavenDependenciesDirectory;
bool m_shouldIndexMavenTests;
};
#endif // SOURCE_GROUP_SETTINGS_JAVA_H
+53
View File
@@ -0,0 +1,53 @@
#include "settings/SourceGroupType.h"
std::string sourceGroupTypeToString(SourceGroupType v)
{
switch (v)
{
case SOURCE_GROUP_C_EMPTY:
return "C Source Group";
case SOURCE_GROUP_CPP_EMPTY:
return "C++ Source Group";
case SOURCE_GROUP_CXX_CDB:
return "C/C++ from Compilation Database";
case SOURCE_GROUP_CXX_VS:
return "C/C++ from Visual Studio";
case SOURCE_GROUP_JAVA_EMPTY:
return "Java Source Group";
case SOURCE_GROUP_JAVA_MAVEN:
return "Java Source Group from Maven";
case SOURCE_GROUP_UNKNOWN:
break;
}
return "unknown";
}
SourceGroupType stringToSourceGroupType(std::string v)
{
if (v == sourceGroupTypeToString(SOURCE_GROUP_C_EMPTY))
{
return SOURCE_GROUP_C_EMPTY;
}
else if (v == sourceGroupTypeToString(SOURCE_GROUP_CPP_EMPTY))
{
return SOURCE_GROUP_CPP_EMPTY;
}
else if (v == sourceGroupTypeToString(SOURCE_GROUP_CXX_CDB))
{
return SOURCE_GROUP_CXX_CDB;
}
else if (v == sourceGroupTypeToString(SOURCE_GROUP_CXX_VS))
{
return SOURCE_GROUP_CXX_VS;
}
else if (v == sourceGroupTypeToString(SOURCE_GROUP_JAVA_EMPTY))
{
return SOURCE_GROUP_JAVA_EMPTY;
}
else if (v == sourceGroupTypeToString(SOURCE_GROUP_JAVA_MAVEN))
{
return SOURCE_GROUP_JAVA_MAVEN;
}
return SOURCE_GROUP_UNKNOWN;
}
+20
View File
@@ -0,0 +1,20 @@
#ifndef SOURCE_GROUP_TYPE_H
#define SOURCE_GROUP_TYPE_H
#include <string>
enum SourceGroupType
{
SOURCE_GROUP_C_EMPTY,
SOURCE_GROUP_CPP_EMPTY,
SOURCE_GROUP_CXX_CDB,
SOURCE_GROUP_CXX_VS,
SOURCE_GROUP_JAVA_EMPTY,
SOURCE_GROUP_JAVA_MAVEN,
SOURCE_GROUP_UNKNOWN
};
std::string sourceGroupTypeToString(SourceGroupType v);
SourceGroupType stringToSourceGroupType(std::string v);
#endif // SOURCE_GROUP_TYPE_H
+17
View File
@@ -0,0 +1,17 @@
#include "settings/migration/Migration.h"
#include "settings/Settings.h"
Migration::~Migration()
{
}
bool Migration::isValueDefinedInSettings(const Settings* settings, const std::string& key) const
{
return settings->isValueDefined(key);
}
void Migration::removeValuesInSettings(Settings* settings, const std::string& key) const
{
settings->removeValues(key);
}
+56
View File
@@ -0,0 +1,56 @@
#ifndef MIGRATION_H
#define MIGRATION_H
#include <string>
#include <vector>
#include "settings/Settings.h"
class Migration
{
public:
virtual ~Migration();
virtual void apply(Settings* settings) const = 0;
bool isValueDefinedInSettings(const Settings* settings, const std::string& key) const;
template <typename T>
T getValueFromSettings(Settings* settings, const std::string& key, T defaultValue) const;
template<typename T>
std::vector<T> getValuesFromSettings(Settings* settings, const std::string& key, std::vector<T> defaultValues) const;
template<typename T>
bool setValueInSettings(Settings* settings, const std::string& key, T value) const;
template<typename T>
bool setValuesInSettings(Settings* settings, const std::string& key, std::vector<T> values) const;
void removeValuesInSettings(Settings* settings, const std::string& key) const;
};
template <typename T>
T Migration::getValueFromSettings(Settings* settings, const std::string& key, T defaultValue) const
{
return settings->getValue(key, defaultValue);
}
template <typename T>
std::vector<T> Migration::getValuesFromSettings(Settings* settings, const std::string& key, std::vector<T> defaultValues) const
{
return settings->getValues(key, defaultValues);
}
template <typename T>
bool Migration::setValueInSettings(Settings* settings, const std::string& key, T value) const
{
return settings->setValue(key, value);
}
template <typename T>
bool Migration::setValuesInSettings(Settings* settings, const std::string& key, std::vector<T> values) const
{
return settings->setValues(key, values);
}
#endif // MIGRATION_H
@@ -0,0 +1,11 @@
#include "settings/migration/MigrationDeleteKey.h"
MigrationDeleteKey::MigrationDeleteKey(const std::string& key)
: m_key(key)
{
}
void MigrationDeleteKey::apply(Settings* settings) const
{
removeValuesInSettings(settings, m_key);
}
@@ -0,0 +1,18 @@
#ifndef MIGRATION_DELETE_KEY_H
#define MIGRATION_DELETE_KEY_H
#include <string>
#include "settings/migration/Migration.h"
class MigrationDeleteKey: public Migration
{
public:
MigrationDeleteKey(const std::string& key);
virtual void apply(Settings* settings) const;
private:
const std::string m_key;
};
#endif // MIGRATION_DELETE_KEY_H
@@ -0,0 +1,11 @@
#include "settings/migration/MigrationLambda.h"
MigrationLambda::MigrationLambda(std::function<void(const Migration*, Settings*)> m_lambda)
: m_lambda(m_lambda)
{
}
void MigrationLambda::apply(Settings* settings) const
{
m_lambda(this, settings);
}
@@ -0,0 +1,18 @@
#ifndef MIGRATION_LAMBDA_H
#define MIGRATION_LAMBDA_H
#include <functional>
#include "settings/migration/Migration.h"
class MigrationLambda: public Migration
{
public:
MigrationLambda(std::function<void(const Migration*, Settings*)> m_lambda);
virtual void apply(Settings* settings) const;
private:
std::function<void(const Migration*, Settings*)> m_lambda;
};
#endif // MIGRATION_LAMBDA_H
@@ -0,0 +1,20 @@
#include "settings/migration/MigrationMoveKey.h"
MigrationMoveKey::MigrationMoveKey(const std::string& oldKey, const std::string& newKey)
: m_oldKey(oldKey)
, m_newKey(newKey)
{
}
void MigrationMoveKey::apply(Settings* settings) const
{
if (!isValueDefinedInSettings(settings, m_newKey))
{
setValuesInSettings<std::string>(
settings,
m_newKey,
getValuesFromSettings<std::string>(settings, m_oldKey, std::vector<std::string>())
);
removeValuesInSettings(settings, m_oldKey);
}
}
@@ -0,0 +1,17 @@
#ifndef MIGRATION_MOVE_KEY_H
#define MIGRATION_MOVE_KEY_H
#include "settings/migration/Migration.h"
class MigrationMoveKey: public Migration
{
public:
MigrationMoveKey(const std::string& oldKey, const std::string& newKey);
virtual void apply(Settings* settings) const;
private:
const std::string m_oldKey;
const std::string m_newKey;
};
#endif // MIGRATION_MOVE_KEY_H
@@ -0,0 +1,64 @@
#include "settings/migration/SettingsMigrator.h"
#include "settings/Settings.h"
SettingsMigrator::SettingsMigrator()
{
}
SettingsMigrator::~SettingsMigrator()
{
}
void SettingsMigrator::addMigration(size_t targetVersion, std::shared_ptr<Migration> migration)
{
if (migration)
{
m_migrations.emplace(targetVersion, migration);
}
}
bool SettingsMigrator::willMigrate(const Settings* settings, size_t targetVersion) const
{
size_t originVersion = settings->getVersion();
if (originVersion < targetVersion)
{
for (; originVersion <= targetVersion; originVersion++)
{
std::pair<std::multimap<size_t, std::shared_ptr<Migration>>::const_iterator, std::multimap<size_t, std::shared_ptr<Migration>>::const_iterator> ret;
ret = m_migrations.equal_range(originVersion);
for (std::multimap<size_t, std::shared_ptr<Migration>>::const_iterator it = ret.first; it != ret.second; it++)
{
return true;
}
}
}
return false;
}
bool SettingsMigrator::migrate(Settings* settings, size_t targetVersion) const
{
size_t originVersion = settings->getVersion();
if (originVersion < targetVersion)
{
for (; originVersion <= targetVersion; originVersion++)
{
std::pair<std::multimap<size_t, std::shared_ptr<Migration>>::const_iterator, std::multimap<size_t, std::shared_ptr<Migration>>::const_iterator> ret;
ret = m_migrations.equal_range(originVersion);
for (std::multimap<size_t, std::shared_ptr<Migration>>::const_iterator it = ret.first; it != ret.second; it++)
{
it->second->apply(settings);
}
}
settings->setVersion(targetVersion);
return true;
}
return false;
}
@@ -1,10 +1,11 @@
#ifndef SETTNGS_MIGRATOR_H
#define SETTNGS_MIGRATOR_H
#include <functional>
#include <map>
#include <memory>
#include <string>
class Migration;
class Settings;
class SettingsMigrator
@@ -15,23 +16,13 @@ public:
SettingsMigrator();
virtual ~SettingsMigrator();
void addMigration(size_t targetVersion, std::string oldKey, std::string newKey);
void addLambdaMigration(size_t targetVersion, std::function<void(Settings*)> lambda);
void addMigration(size_t targetVersion, std::shared_ptr<Migration> migration);
bool willMigrate(const Settings* settings, size_t targetVersion) const;
bool migrate(Settings* settings, size_t targetVersion) const;
private:
struct Migration
{
size_t targetVersion;
std::string oldKey;
std::string newKey;
std::function<void(Settings*)> lambda;
};
std::multimap<size_t, Migration> m_migrations;
std::multimap<size_t, std::shared_ptr<Migration>> m_migrations;
};
#endif // SETTINGS_MIGRATOR_H
+25
View File
@@ -1,9 +1,12 @@
#include "utility/ConfigManager.h"
#include <set>
#include "tinyxml/tinyxml.h"
#include "utility/logging/logging.h"
#include "utility/text/TextAccess.h"
#include "utility/utility.h"
#include "utility/utilityString.h"
std::shared_ptr<ConfigManager> ConfigManager::createEmpty()
@@ -222,6 +225,10 @@ void ConfigManager::setValues(const std::string& key, const std::vector<bool>& v
void ConfigManager::removeValues(const std::string& key)
{
for (const std::string& sublevelKey: getSublevelKeys(key))
{
removeValues(sublevelKey);
}
m_values.erase(key);
}
@@ -232,6 +239,24 @@ bool ConfigManager::isValueDefined(const std::string& key) const
return (it != m_values.end());
}
std::vector<std::string> ConfigManager::getSublevelKeys(const std::string& key) const
{
std::set<std::string> keys;
for (std::multimap<std::string, std::string>::const_iterator it = m_values.begin(); it != m_values.end(); it++)
{
if (utility::isPrefix(key, it->first))
{
size_t startPos = it->first.find("/", key.size());
if (startPos == key.size())
{
std::string sublevelKey = it->first.substr(0, it->first.find("/", startPos + 1));
keys.insert(sublevelKey);
}
}
}
return utility::toVector(keys);
}
bool ConfigManager::load(const std::shared_ptr<TextAccess> textAccess)
{
std::string text = textAccess->getText();
+1
View File
@@ -41,6 +41,7 @@ public:
void removeValues(const std::string& key);
bool isValueDefined(const std::string& key) const;
std::vector<std::string> getSublevelKeys(const std::string& key) const;
bool load(const std::shared_ptr<TextAccess> textAccess);
void save(const std::string filepath);
+13 -100
View File
@@ -1,10 +1,8 @@
#include "utility/file/FileManager.h"
#include <functional>
#include <set>
#include "utility/file/FileSystem.h"
#include "utility/logging/logging.h"
#include "utility/utility.h"
FileManager::FileManager()
@@ -15,51 +13,18 @@ FileManager::~FileManager()
{
}
void FileManager::setPaths(
std::vector<FilePath> sourcePaths,
std::vector<FilePath> headerPaths,
std::vector<FilePath> excludePaths,
std::vector<std::string> sourceExtensions
void FileManager::update(
const std::vector<FilePath>& sourcePaths,
const std::vector<FilePath>& excludePaths,
const std::vector<std::string>& sourceExtensions
){
m_sourcePaths = sourcePaths;
m_headerPaths = makeCanonical(headerPaths);
m_excludePaths = makeCanonical(excludePaths);
m_sourceExtensions = sourceExtensions;
}
FileManager::FileSets FileManager::fetchFilePaths(const std::vector<FileInfo>& oldFileInfos)
{
m_filesInfos.clear();
for (FileInfo oldFileInfo: oldFileInfos)
{
m_filesInfos.emplace(oldFileInfo.path, oldFileInfo);
}
m_allSourceFilePaths.clear();
FileSets fileSets;
// update old files that have been modified
// remove old files that don't exist anymore
for (std::map<FilePath, FileInfo>::iterator it = m_filesInfos.begin(); it != m_filesInfos.end(); it++)
{
const FilePath& filePath = it->first;
if (filePath.exists() && !hasSourceFilePath(filePath))
{
FileInfo newFileInfo = FileSystem::getFileInfoForPath(filePath);
if (newFileInfo.lastWriteTime > it->second.lastWriteTime)
{
it->second.lastWriteTime = newFileInfo.lastWriteTime;
fileSets.updatedFiles.insert(filePath);
}
}
else
{
fileSets.removedFiles.insert(filePath);
}
}
std::vector<FileInfo> fileInfos = FileSystem::getFileInfosFromPaths(m_sourcePaths, m_sourceExtensions);
for (FileInfo fileInfo: fileInfos)
for (FileInfo fileInfo: FileSystem::getFileInfosFromPaths(m_sourcePaths, m_sourceExtensions))
{
const FilePath& filePath = fileInfo.path;
if (isExcluded(filePath))
@@ -67,33 +32,8 @@ FileManager::FileSets FileManager::fetchFilePaths(const std::vector<FileInfo>& o
continue;
}
fileSets.allSourceFilePaths.insert(filePath);
std::map<FilePath, FileInfo>::iterator it = m_filesInfos.find(filePath);
if (it != m_filesInfos.end())
{
fileSets.removedFiles.erase(filePath);
if (fileInfo.lastWriteTime > it->second.lastWriteTime)
{
it->second.lastWriteTime = fileInfo.lastWriteTime;
fileSets.updatedFiles.insert(filePath);
}
}
else
{
m_filesInfos.insert(std::pair<FilePath, FileInfo>(filePath, fileInfo));
fileSets.addedFiles.insert(filePath);
}
m_allSourceFilePaths.insert(filePath);
}
for (const FilePath& filePath : fileSets.removedFiles)
{
m_filesInfos.erase(filePath);
}
m_sourceFilePaths = fileSets.allSourceFilePaths;
return fileSets;
}
std::vector<FilePath> FileManager::getSourcePaths() const
@@ -101,48 +41,21 @@ std::vector<FilePath> FileManager::getSourcePaths() const
return m_sourcePaths;
}
std::set<FilePath> FileManager::getSourceFilePaths() const
{
std::set<FilePath> sourceFilePaths;
for (const FileInfo& fileInfo: FileSystem::getFileInfosFromPaths(m_sourcePaths, m_sourceExtensions))
{
const FilePath& path = fileInfo.path;
bool excluded = false;
for (FilePath p: m_excludePaths)
{
if (p == path || p.contains(path))
{
excluded = true;
break;
}
}
if (!excluded)
{
sourceFilePaths.emplace(path);
}
}
return sourceFilePaths;
}
bool FileManager::hasSourceFilePath(const FilePath& filePath) const
{
if (m_sourceFilePaths.find(filePath) != m_sourceFilePaths.end())
if (m_allSourceFilePaths.find(filePath) != m_allSourceFilePaths.end())
{
for (FilePath p: m_excludePaths)
{
if (p == filePath || p.contains(filePath))
{
return false;
}
}
return true;
}
return false;
}
std::set<FilePath> FileManager::getAllSourceFilePaths() const
{
return m_allSourceFilePaths;
}
std::vector<FilePath> FileManager::makeCanonical(const std::vector<FilePath>& filePaths)
{
std::vector<FilePath> ret;
+8 -22
View File
@@ -10,47 +10,33 @@
class FileManager
{
public:
struct FileSets
{
std::set<FilePath> addedFiles;
std::set<FilePath> updatedFiles;
std::set<FilePath> removedFiles;
std::set<FilePath> allSourceFilePaths;
};
FileManager();
virtual ~FileManager();
void setPaths(
std::vector<FilePath> sourcePaths,
std::vector<FilePath> headerPaths,
std::vector<FilePath> excludePaths,
std::vector<std::string> sourceExtensions
void update(
const std::vector<FilePath>& sourcePaths,
const std::vector<FilePath>& excludePaths,
const std::vector<std::string>& sourceExtensions
);
FileSets fetchFilePaths(const std::vector<FileInfo>& oldFileInfos);
// returns a list of source paths (can be directories) specified in the project settings
std::vector<FilePath> getSourcePaths() const;
// returns a list of paths to all files that reside in the non-excluded source paths
std::set<FilePath> getSourceFilePaths() const;
// checks if file is in non-excluded source directory
bool hasSourceFilePath(const FilePath& filePath) const;
// returns a list of paths to all files that reside in the non-excluded source paths
std::set<FilePath> getAllSourceFilePaths() const;
private:
std::vector<FilePath> makeCanonical(const std::vector<FilePath>& filePaths);
bool isExcluded(const FilePath& filePath) const;
std::vector<FilePath> m_sourcePaths;
std::vector<FilePath> m_headerPaths;
std::vector<FilePath> m_excludePaths;
std::vector<std::string> m_sourceExtensions;
std::map<FilePath, FileInfo> m_filesInfos;
std::set<FilePath> m_sourceFilePaths;
std::set<FilePath> m_allSourceFilePaths;
};
#endif // FILE_MANAGER_H
@@ -1,73 +0,0 @@
#include "ISolutionParser.h"
std::string ISolutionParser::getSolutionPath()
{
return m_solutionPath;
}
std::string ISolutionParser::getToolID() const
{
return "NONE";
}
void ISolutionParser::openSolutionFile(const std::string& solutionFilePath)
{
m_solution = loadFile(solutionFilePath);
size_t pos = solutionFilePath.find_last_of("/");
if (pos == std::string::npos)
{
pos = solutionFilePath.find_last_of("\\");
}
if (pos != std::string::npos)
{
if (pos > 0)
{
pos += 1;
}
m_solutionPath = solutionFilePath.substr(0, pos);
m_solutionName = solutionFilePath.substr(pos);
}
}
unsigned int ISolutionParser::getSolutionCharCount() const
{
return m_solution.size();
}
std::string ISolutionParser::loadFile(const std::string& filePath)
{
std::string file = "";
std::ifstream ifstream;
ifstream.open(filePath);
if (ifstream.is_open())
{
file = std::string(std::istreambuf_iterator<char>(ifstream), std::istreambuf_iterator<char>());
}
return file;
}
std::vector<std::string> ISolutionParser::makePathsAbsolute(const std::vector<std::string>& paths)
{
std::vector<std::string> absolutePaths;
for (unsigned int i = 0; i < paths.size(); i++)
{
std::string path = paths[i];
boost::filesystem::path boostPath(path);
if (boostPath.is_relative())
{
path = m_solutionPath + path;
}
absolutePaths.push_back(path);
}
return absolutePaths;
}
@@ -1,49 +0,0 @@
#ifndef I_SOLUTION_PARSER_H
#define I_SOLUTION_PARSER_H
#include <fstream>
#include <vector>
#include "settings/ProjectSettings.h"
class ISolutionParser
{
public:
ISolutionParser()
: m_solutionPath("")
, m_solution("")
{};
virtual ~ISolutionParser(){};
virtual std::string getToolID() const;
void openSolutionFile(const std::string& solutionFilePath);
unsigned int getSolutionCharCount() const;
virtual std::string getSolutionName() = 0; // to be overwritten to account for different file endings
std::string getSolutionPath();
virtual std::vector<std::string> getProjects() = 0;
virtual std::vector<std::string> getProjectFiles() = 0;
virtual std::vector<std::string> getProjectItems() = 0;
virtual std::vector<std::string> getCompileFlags() = 0;
virtual std::shared_ptr<ProjectSettings> getProjectSettings(const std::string& solutionFilePath) = 0;
virtual std::string getIdeName() const = 0;
virtual std::string getButtonText() const = 0;
virtual std::string getDescription() const = 0;
virtual std::string getIconPath() const = 0;
virtual std::string getFileExtension() const = 0;
protected:
std::string loadFile(const std::string& filePath);
std::vector<std::string> makePathsAbsolute(const std::vector<std::string>& paths);
std::string m_solutionName;
std::string m_solutionPath;
std::string m_solution;
};
#endif // I_SOLUTION_PARSER_H
@@ -1,18 +0,0 @@
#include "SolutionParserCMake.h"
SolutionParserCMake::SolutionParserCMake()
{
}
SolutionParserCMake::~SolutionParserCMake()
{
}
std::vector<std::string> SolutionParserCMake::getProjects()
{
std::vector<std::string> projects;
return projects;
}
@@ -1,16 +0,0 @@
#ifndef SOLUTION_PARSER_C_MAKE_H
#define SOLUTION_PARSER_C_MAKE_H
#include "ISolutionParser.h"
class SolutionParserCMake : public ISolutionParser
{
public:
SolutionParserCMake();
virtual ~SolutionParserCMake();
virtual std::vector<std::string> getProjects();
virtual std::vector<std::string> getProjectFiles();
};
#endif // SOLUTION_PARSER_C_MAKE_H
@@ -1,228 +0,0 @@
#include "SolutionParserCodeBlocks.h"
#include <set>
#include "SolutionParserUtility.h"
#include "settings/CxxProjectSettings.h"
#include "utility/logging/logging.h"
SolutionParserCodeBlocks::SolutionParserCodeBlocks()
{
}
SolutionParserCodeBlocks::~SolutionParserCodeBlocks()
{
}
std::string SolutionParserCodeBlocks::getToolID() const
{
return "cb";
}
std::string SolutionParserCodeBlocks::getSolutionName()
{
std::string result = "";
if (m_solutionName.size() > 0)
{
size_t pos = m_solutionName.find(".cbp");
if (pos != std::string::npos)
{
result = m_solutionName.substr(0, pos);
}
else
{
result = m_solution;
}
}
return result;
}
std::vector<std::string> SolutionParserCodeBlocks::getProjects()
{
std::vector<std::string> projectFiles;
projectFiles.push_back(m_solutionName);
return projectFiles;
}
std::vector<std::string> SolutionParserCodeBlocks::getProjectFiles()
{
std::vector<std::string> projectFiles;
std::vector<std::string> projectFilesNames = getProjects();
projectFiles.push_back(loadFile(m_solutionPath + m_solutionName));
return projectFiles;
}
std::vector<std::string> SolutionParserCodeBlocks::getProjectItems()
{
std::vector<std::string> projectItems;
std::vector<std::string> projectFilesNames = getProjects();
std::vector<std::string> projectFiles = getProjectFiles();
std::vector<std::string> validFileExtensions;
validFileExtensions.push_back(".c");
validFileExtensions.push_back(".cpp");
validFileExtensions.push_back(".h");
validFileExtensions.push_back(".hpp");
for (unsigned int i = 0; i < projectFiles.size(); i++)
{
TiXmlDocument doc;
doc.Parse(projectFiles[i].c_str(), 0, TIXML_ENCODING_UTF8);
std::string error = doc.ErrorDesc();
if (error.length() > 0)
{
LOG_ERROR_STREAM(<< "Failed to parse project file " << i << ": " << error);
continue;
}
std::vector<TiXmlElement*> nodes = SolutionParserUtility::getAllTagsByNameWithAttribute(doc.RootElement(), "Unit", "filename");
if (nodes.size() > 0)
{
for (unsigned int i = 0; i < nodes.size(); i++)
{
std::string text = nodes[i]->Attribute("filename");
if (SolutionParserUtility::checkValidFileExtension(text, validFileExtensions))
{
if (boost::filesystem::exists(text))
{
projectItems.push_back(text);
continue;
}
text = m_solutionPath + "/" + text;
projectItems.push_back(text);
}
}
}
}
std::set<std::string> s(projectItems.begin(), projectItems.end());
projectItems.assign(s.begin(), s.end());
projectItems = SolutionParserUtility::resolveEnvironmentVariables(projectItems);
projectItems = makePathsAbsolute(projectItems);
return projectItems;
}
std::vector<std::string> SolutionParserCodeBlocks::getIncludePaths()
{
std::vector<std::string> includePaths;
std::vector<std::string> projectFiles = getProjectFiles();
std::vector<std::string> validExtensions;
validExtensions.push_back(".c");
validExtensions.push_back(".cpp");
validExtensions.push_back(".h");
validExtensions.push_back(".hpp");
for (unsigned int i = 0; i < projectFiles.size(); i++)
{
TiXmlDocument doc;
doc.Parse(projectFiles[i].c_str(), 0, TIXML_ENCODING_UTF8);
std::string error = doc.ErrorDesc();
if (error.length() > 0)
{
LOG_ERROR_STREAM(<< "Failed to parse project file " << i << ": " << error);
continue;
}
std::vector<TiXmlElement*> nodes = SolutionParserUtility::getAllTagsByNameWithAttribute(doc.RootElement(), "Add", "directory");
if (nodes.size() > 0)
{
for (unsigned int i = 0; i < nodes.size(); i++)
{
std::string text = nodes[i]->Attribute("directory");
includePaths.push_back(text);
}
}
}
std::set<std::string> s(includePaths.begin(), includePaths.end());
includePaths.assign(s.begin(), s.end());
includePaths = SolutionParserUtility::resolveEnvironmentVariables(includePaths);
includePaths = makePathsAbsolute(includePaths);
return includePaths;
}
std::vector<std::string> SolutionParserCodeBlocks::getCompileFlags()
{
std::vector<std::string> compilerFlags;
return compilerFlags;
}
std::shared_ptr<ProjectSettings> SolutionParserCodeBlocks::getProjectSettings(const std::string& solutionFilePath)
{
openSolutionFile(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;
for (const std::string& p : sourceFiles)
{
sourcePaths.push_back(FilePath(p));
}
std::vector<std::string> includePaths = getIncludePaths();
std::vector<FilePath> headerPaths;
for (const std::string& p : includePaths)
{
headerPaths.push_back(FilePath(p));
}
settings->setSourcePaths(sourcePaths);
settings->setHeaderSearchPaths(headerPaths);
return settings;
}
std::string SolutionParserCodeBlocks::getIdeName() const
{
return "Code Blocks";
}
std::string SolutionParserCodeBlocks::getButtonText() const
{
return "from Code\nBlocks Project";
}
std::string SolutionParserCodeBlocks::getDescription() const
{
return "idunno";
}
std::string SolutionParserCodeBlocks::getIconPath() const
{
return "icon/project_vs_256_256.png";
}
std::string SolutionParserCodeBlocks::getFileExtension() const
{
return ".cbp";
}
@@ -1,33 +0,0 @@
#ifndef SOLUTION_PARSER_CODE_BLOCKS_H
#define SOLUTION_PARSER_CODE_BLOCKS_H
#include "ISolutionParser.h"
#include "tinyxml/tinyxml.h"
class SolutionParserCodeBlocks : public ISolutionParser
{
public:
SolutionParserCodeBlocks();
virtual ~SolutionParserCodeBlocks();
virtual std::string getToolID() const;
virtual std::string getSolutionName();
virtual std::vector<std::string> getProjects();
virtual std::vector<std::string> getProjectFiles();
virtual std::vector<std::string> getProjectItems();
virtual std::vector<std::string> getIncludePaths();
virtual std::vector<std::string> getCompileFlags();
virtual std::shared_ptr<ProjectSettings> getProjectSettings(const std::string& solutionFilePath);
virtual std::string getIdeName() const;
virtual std::string getButtonText() const;
virtual std::string getDescription() const;
virtual std::string getIconPath() const;
virtual std::string getFileExtension() const;
};
#endif // SOLUTION_PARSER_CODE_BLOCKS_H
@@ -1,143 +0,0 @@
#include "SolutionParserManager.h"
#include <boost/algorithm/string.hpp>
#include "utility/logging/logging.h"
SolutionParserManager::SolutionParserManager()
: m_solutionParsers()
{
}
SolutionParserManager::~SolutionParserManager()
{
}
void SolutionParserManager::pushSolutionParser(const std::shared_ptr<ISolutionParser>& solutionParser)
{
m_solutionParsers.push_back(solutionParser);
}
bool SolutionParserManager::canParseSolution(const std::string& ideId) const
{
std::string lIdeId = ideId;
boost::algorithm::to_lower(lIdeId);
for (unsigned int i = 0; i < m_solutionParsers.size(); i++)
{
std::string parserIdeId = m_solutionParsers[i]->getToolID();
boost::algorithm::to_lower(parserIdeId);
if (lIdeId == parserIdeId)
{
return true;
}
}
return false;
}
std::shared_ptr<ProjectSettings> SolutionParserManager::getProjectSettings(const std::string& ideId, const std::string& solutionFilePath) const
{
std::string lIdeId = ideId;
boost::algorithm::to_lower(lIdeId);
for (unsigned int i = 0; i < m_solutionParsers.size(); i++)
{
std::string parserIdeId = m_solutionParsers[i]->getToolID();
boost::algorithm::to_lower(parserIdeId);
if (lIdeId == parserIdeId)
{
return m_solutionParsers[i]->getProjectSettings(solutionFilePath);
}
}
LOG_ERROR_STREAM(<< "Solution type is unknown");
return std::shared_ptr<ProjectSettings>();
}
unsigned int SolutionParserManager::getParserCount() const
{
return m_solutionParsers.size();
}
std::string SolutionParserManager::getParserName(const unsigned int idx) const
{
if (checkIndex(idx))
{
return m_solutionParsers[idx]->getIdeName();
}
LOG_WARNING_STREAM(<< "Index is out of range, was " << idx << ". Max is " << m_solutionParsers.size() - 1);
return "";
}
std::string SolutionParserManager::getParserButtonText(const unsigned int idx) const
{
if (checkIndex(idx))
{
return m_solutionParsers[idx]->getButtonText();
}
LOG_WARNING_STREAM(<< "Index is out of range, was " << idx << ". Max is " << m_solutionParsers.size() - 1);
return "";
}
std::string SolutionParserManager::getParserDescription(const unsigned int idx) const
{
if (checkIndex(idx))
{
return m_solutionParsers[idx]->getDescription();
}
LOG_WARNING_STREAM(<< "Index is out of range, was " << idx << ". Max is " << m_solutionParsers.size() - 1);
return "";
}
std::string SolutionParserManager::getParserFileEnding(const unsigned int idx) const
{
if (checkIndex(idx))
{
return m_solutionParsers[idx]->getFileExtension();
}
LOG_WARNING_STREAM(<< "Index is out of range, was " << idx << ". Max is " << m_solutionParsers.size() - 1);
return "";
}
std::string SolutionParserManager::getParserIdeId(const unsigned int idx) const
{
if (checkIndex(idx))
{
return m_solutionParsers[idx]->getToolID();
}
LOG_WARNING_STREAM(<< "Index is out of range, was " << idx << ". Max is " << m_solutionParsers.size() - 1);
return "";
}
std::string SolutionParserManager::getIconPath(const unsigned int idx) const
{
if (checkIndex(idx))
{
return m_solutionParsers[idx]->getIconPath();
}
LOG_WARNING_STREAM(<< "Index is out of range, was " << idx << ". Max is " << m_solutionParsers.size() - 1);
return "";
}
bool SolutionParserManager::checkIndex(const unsigned int idx) const
{
return (idx < m_solutionParsers.size());
}
@@ -1,35 +0,0 @@
#ifndef SOLUTION_PARSER_MANAGER_H
#define SOLUTION_PARSER_MANAGER_H
#include <vector>
#include "ISolutionParser.h"
class SolutionParserManager
{
public:
SolutionParserManager();
~SolutionParserManager();
void pushSolutionParser(const std::shared_ptr<ISolutionParser>& solutionParser);
bool canParseSolution(const std::string& ideId) const;
std::shared_ptr<ProjectSettings> getProjectSettings(const std::string& ideId, const std::string& solutionFilePath) const;
unsigned int getParserCount() const;
std::string getParserName(const unsigned int idx) const;
std::string getParserButtonText(const unsigned int idx) const;
std::string getParserDescription(const unsigned int idx) const;
std::string getParserFileEnding(const unsigned int idx) const;
std::string getParserIdeId(const unsigned int idx) const;
std::string getIconPath(const unsigned int idx) const;
private:
bool checkIndex(const unsigned int idx) const;
std::vector<std::shared_ptr<ISolutionParser>> m_solutionParsers;
};
#endif // SOLUTION_PARSER_MANAGER_H
@@ -1,328 +0,0 @@
#include "SolutionParserUtility.h"
#include "utility/logging/logging.h"
#include "utility/messaging/type/MessageStatus.h"
#include "boost/filesystem/path.hpp"
#include "boost/filesystem.hpp"
std::vector<std::string> SolutionParserUtility::m_ideMacros;
std::map<std::string, std::string> SolutionParserUtility::m_ideMacroValues;
TiXmlElement* SolutionParserUtility::getFirstTagByName(TiXmlElement* root, const std::string& tag)
{
TiXmlElement* element = root;
while (element)
{
if (element == NULL)
{
}
std::string value = element->Value();
if (value == tag) // "ClInclude") // || value == "ClCompile")
{
if (element->Parent() != NULL)
{
return element; // ->Parent()->ToElement();
}
}
if (element->FirstChildElement() != NULL)
{
element = element->FirstChildElement();
}
else if (element->NextSiblingElement() != NULL)
{
element = element->NextSiblingElement();
}
else
{
if (element == NULL)
{
}
while (element->Parent()->ToElement() != NULL && element->Parent()->NextSiblingElement() == NULL)
{
TiXmlElement* newElement = element->Parent()->ToElement();
if (newElement == NULL)
{
}
element = newElement;
}
if (element->Parent() != NULL && element->Parent()->NextSiblingElement() != NULL)
{
element = element->Parent()->NextSiblingElement();
}
else
{
return NULL;
}
}
}
return NULL;
}
TiXmlElement* SolutionParserUtility::getFirstTagByNameWithAttribute(TiXmlElement* root, const std::string& tag, const std::string& attribute)
{
TiXmlElement* element = root;
while (element)
{
if (element == NULL)
{
}
std::string value = element->Value();
bool hasAttribute = false;
if (element->Attribute(attribute.c_str()) != NULL)
{
hasAttribute = true;
}
if (value == tag && hasAttribute) // "ClInclude") // || value == "ClCompile")
{
if (element->Parent() != NULL)
{
return element; // ->Parent()->ToElement();
}
}
if (element->FirstChildElement() != NULL)
{
element = element->FirstChildElement();
}
else if (element->NextSiblingElement() != NULL)
{
element = element->NextSiblingElement();
}
else
{
while (element->Parent()->ToElement() != NULL && element->Parent()->NextSiblingElement() == NULL)
{
TiXmlElement* newElement = element->Parent()->ToElement();
element = newElement;
}
if (element->Parent() != NULL && element->Parent()->NextSiblingElement() != NULL)
{
element = element->Parent()->NextSiblingElement();
}
else
{
return NULL;
}
}
}
return NULL;
}
std::vector<TiXmlElement*> SolutionParserUtility::getAllTagsByNameWithAttribute(TiXmlElement* root, const std::string& tag, const std::string& attribute)
{
std::vector<TiXmlElement*> nodes;
TiXmlElement* element = root;
while (element)
{
std::string value = element->Value();
bool hasAttribute = false;
if (element->Attribute(attribute.c_str()) != NULL)
{
hasAttribute = true;
}
if (value == tag && hasAttribute)
{
nodes.push_back(element);
}
if (element->FirstChildElement() != NULL)
{
element = element->FirstChildElement();
}
else if (element->NextSiblingElement() != NULL)
{
element = element->NextSiblingElement();
}
else
{
while (element->Parent()->ToElement() != NULL && element->Parent()->NextSiblingElement() == NULL)
{
TiXmlElement* newElement = element->Parent()->ToElement();
element = newElement;
}
if (element->Parent() != NULL && element->Parent()->NextSiblingElement() != NULL)
{
element = element->Parent()->NextSiblingElement();
}
else
{
break;
}
}
}
return nodes;
}
bool SolutionParserUtility::checkValidFileExtension(const std::string& file, const std::vector<std::string>& validExtensions)
{
for (unsigned int i = 0; i < validExtensions.size(); i++)
{
size_t pos = file.find(validExtensions[i]);
if (pos != std::string::npos)
{
return true;
}
}
return false;
}
std::vector<std::string> SolutionParserUtility::resolveEnvironmentVariables(const std::vector<std::string>& paths)
{
std::vector<std::string> resolvedPaths;
for (unsigned int i = 0; i < paths.size(); i++)
{
std::string resolvedPath = "";
try
{
resolvedPath = findAndResolveEnvironmentVariable(paths[i]);
resolvedPaths.push_back(resolvedPath);
}
catch (std::exception &e)
{
LOG_ERROR_STREAM(<< "Failed to resolve environment variable, exception was: \"" << e.what() << "\"");
}
}
return resolvedPaths;
}
std::string SolutionParserUtility::findAndResolveEnvironmentVariable(const std::string& path)
{
std::string resolvedPath;
size_t pos = path.find("$(");
if (pos != std::string::npos)
{
size_t endPos = path.substr(pos).find(")");
std::string envVariable = path.substr(pos + 2, (endPos - 2) - pos);
std::string envPath = "";
std::string macro = checkIsIdeMacro(envVariable);
if (macro != "")
{
LOG_WARNING_STREAM(<< "Encountered IDE macro \"" << macro << "\"");
if (m_ideMacroValues.find(macro) == m_ideMacroValues.end())
{
LOG_WARNING_STREAM(<< "Could not resolve IDE macro \"" << macro << "\"");
return "";
}
else
{
envPath = m_ideMacroValues[macro];
}
}
else
{
envPath = getenv(envVariable.c_str());
}
std::string prePath = path.substr(0, pos);
std::string postPath = path.substr(endPos + 1);
resolvedPath = prePath + envPath + postPath;
}
else
{
resolvedPath = path;
}
return resolvedPath;
}
std::vector<std::string> SolutionParserUtility::makePathsCanonical(const std::vector<std::string>& paths)
{
std::vector<std::string> canonicalPaths;
int errorCount = 0;
for (unsigned int i = 0; i < paths.size(); i++)
{
try
{
boost::filesystem::path canonicalPath = boost::filesystem::canonical(boost::filesystem::path(paths[i]));
canonicalPaths.push_back(canonicalPath.string());
}
catch (std::exception& e)
{
std::string what = e.what();
LOG_WARNING_STREAM(<< e.what());
errorCount++;
}
}
if (errorCount > 0)
{
std::stringstream errorMessage;
errorMessage << "Detected " << errorCount << " invalid include file paths. Check if the include paths of your VS project exist.";
MessageStatus(errorMessage.str(), true).dispatch();
}
return canonicalPaths;
}
std::string SolutionParserUtility::makePathCanonical(const std::string& path)
{
std::string result = "";
try
{
boost::filesystem::path canonicalPath = boost::filesystem::canonical(boost::filesystem::path(path));
result = canonicalPath.string();
}
catch (std::exception& e)
{
std::string what = e.what();
LOG_WARNING_STREAM(<< e.what());
std::stringstream errorMessage;
errorMessage << "Could not make path \"" << path << "\" canonical. Check if it really exists.";
MessageStatus(errorMessage.str(), true).dispatch();
}
return result;
}
std::string SolutionParserUtility::checkIsIdeMacro(const std::string& text)
{
for (unsigned int i = 0; i < m_ideMacros.size(); i++)
{
if (text == m_ideMacros[i])
{
return m_ideMacros[i];
}
}
return "";
}
@@ -1,31 +0,0 @@
#ifndef SOLUTION_PARSER_UTILITY_H
#define SOLUTION_PARSER_UTILITY_H
#include <map>
#include <string>
#include <vector>
#include "tinyxml/tinyxml.h"
class SolutionParserUtility
{
public:
static TiXmlElement* getFirstTagByName(TiXmlElement* root, const std::string& tag);
static TiXmlElement* getFirstTagByNameWithAttribute(TiXmlElement* root, const std::string& tag, const std::string& attribute);
static std::vector<TiXmlElement*> getAllTagsByNameWithAttribute(TiXmlElement* root, const std::string& tag, const std::string& attribute);
static bool checkValidFileExtension(const std::string& file, const std::vector<std::string>& validExtensions);
static std::vector<std::string> resolveEnvironmentVariables(const std::vector<std::string>& paths);
static std::string findAndResolveEnvironmentVariable(const std::string& path);
static std::vector<std::string> makePathsCanonical(const std::vector<std::string>& paths);
static std::string makePathCanonical(const std::string& path);
static std::string checkIsIdeMacro(const std::string& text); // returns matching macro or empty string if no match was found
static std::vector<std::string> m_ideMacros;
static std::map<std::string, std::string> m_ideMacroValues; // to replace macros with known values
};
#endif // SOLUTION_PARSER_UTILITY_H
-16
View File
@@ -147,22 +147,6 @@ namespace utility
return text.size() >= postfix.size() && text.rfind(postfix) == (text.size() - postfix.size());
}
std::string switchCases(std::string s)
{
for (char& c: s)
{
if (islower(c))
{
c = toupper(c);
}
else if (isupper(c))
{
c = tolower(c);
}
}
return s;
}
std::string toUpperCase(const std::string& in)
{
std::string out;
-1
View File
@@ -38,7 +38,6 @@ namespace utility
bool isPrefix(const std::string& prefix, const std::string& text);
bool isPostfix(const std::string& postfix, const std::string& text);
std::string switchCases(std::string s);
std::string toUpperCase(const std::string& in);
std::string toLowerCase(const std::string& in);
bool equalsCaseInsensitive(const std::string& a, const std::string& b);