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:
@@ -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);
|
||||
|
||||
|
||||
@@ -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 "";
|
||||
}
|
||||
@@ -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
|
||||
@@ -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";
|
||||
}
|
||||
@@ -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
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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 "";
|
||||
}
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
+4
-13
@@ -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
|
||||
Reference in New Issue
Block a user