logic: implemented usage of FilePathFilters for excluded paths

* removed check in settings for existing paths of exclude filters
This commit is contained in:
mlangkabel
2018-03-12 08:51:38 +01:00
parent 31c9f9fecc
commit 6acfe0688f
44 changed files with 572 additions and 221 deletions
+64 -57
View File
@@ -12,7 +12,7 @@
#include "utility/utilityString.h"
#include "utility/utilityUuid.h"
const size_t ProjectSettings::VERSION = 4;
const size_t ProjectSettings::VERSION = 5;
const wchar_t PROJECT_FILE_EXTENSION[] = L".srctrlprj";
LanguageType ProjectSettings::getLanguageOfProject(const FilePath& filePath)
@@ -248,71 +248,78 @@ SettingsMigrator ProjectSettings::getMigrations() const
}
));
const std::string sourceGroupKey = "source_groups/source_group_" + utility::getUuidString();
{
const std::string sourceGroupKey = "source_groups/source_group_" + utility::getUuidString();
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("info/description", "description"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("language_settings/standard", sourceGroupKey + "/standard"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/source_paths/source_path", sourceGroupKey + "/source_paths/source_path"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/exclude_paths/exclude_path", sourceGroupKey + "/exclude_paths/exclude_path"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/extensions/source_extensions", sourceGroupKey + "/source_extensions/source_extension"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/header_search_paths/header_search_path", sourceGroupKey + "/header_search_paths/header_search_path"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/use_source_paths_for_header_search", sourceGroupKey + "/use_source_paths_for_header_search"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/framework_search_paths/framework_search_path", sourceGroupKey + "/framework_search_paths/framework_search_path"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/compiler_flags/compiler_flag", sourceGroupKey + "/compiler_flags/compiler_flag"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/build_file_path/compilation_db_path", sourceGroupKey + "/build_file_path/compilation_db_path"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/class_paths/class_path", sourceGroupKey + "/class_paths/class_path"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/maven/project_file_path", sourceGroupKey + "/maven/project_file_path"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/maven/dependencies_directory", sourceGroupKey + "/maven/dependencies_directory"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/maven/should_index_tests", sourceGroupKey + "/maven/should_index_tests"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("info/description", "description"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("language_settings/standard", sourceGroupKey + "/standard"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/source_paths/source_path", sourceGroupKey + "/source_paths/source_path"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/exclude_paths/exclude_path", sourceGroupKey + "/exclude_paths/exclude_path"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/extensions/source_extensions", sourceGroupKey + "/source_extensions/source_extension"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/header_search_paths/header_search_path", sourceGroupKey + "/header_search_paths/header_search_path"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/use_source_paths_for_header_search", sourceGroupKey + "/use_source_paths_for_header_search"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/framework_search_paths/framework_search_path", sourceGroupKey + "/framework_search_paths/framework_search_path"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/compiler_flags/compiler_flag", sourceGroupKey + "/compiler_flags/compiler_flag"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/build_file_path/compilation_db_path", sourceGroupKey + "/build_file_path/compilation_db_path"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/class_paths/class_path", sourceGroupKey + "/class_paths/class_path"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/maven/project_file_path", sourceGroupKey + "/maven/project_file_path"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/maven/dependencies_directory", sourceGroupKey + "/maven/dependencies_directory"));
migrator.addMigration(2, std::make_shared<SettingsMigrationMoveKey>("source/maven/should_index_tests", sourceGroupKey + "/maven/should_index_tests"));
migrator.addMigration(3, std::make_shared<SettingsMigrationLambda>(
[=](const SettingsMigration* 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++")
migrator.addMigration(3, std::make_shared<SettingsMigrationLambda>(
[=](const SettingsMigration* migration, Settings* settings)
{
const std::string cdbPath = migration->getValueFromSettings<std::string>(settings, sourceGroupKey + "/build_file_path/compilation_db_path", "");
if (!cdbPath.empty())
{
type = SOURCE_GROUP_CXX_CDB;
}
else if (language == "C")
{
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;
}
const std::string gradleProjectFilePath = migration->getValueFromSettings<std::string>(settings, sourceGroupKey + "/gradle/project_file_path", "");
if (!gradleProjectFilePath.empty())
{
type = SOURCE_GROUP_JAVA_GRADLE;
}
else
{
type = SOURCE_GROUP_JAVA_EMPTY;
}
}
const std::string language = migration->getValueFromSettings<std::string>(settings, "language_settings/language", "");
migration->setValueInSettings(settings, sourceGroupKey + "/type", sourceGroupTypeToString(type));
}
));
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())
{
type = SOURCE_GROUP_CXX_CDB;
}
else if (language == "C")
{
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;
}
const std::string gradleProjectFilePath = migration->getValueFromSettings<std::string>(settings, sourceGroupKey + "/gradle/project_file_path", "");
if (!gradleProjectFilePath.empty())
{
type = SOURCE_GROUP_JAVA_GRADLE;
}
else
{
type = SOURCE_GROUP_JAVA_EMPTY;
}
}
migration->setValueInSettings(settings, sourceGroupKey + "/type", sourceGroupTypeToString(type));
}
));
}
migrator.addMigration(4, std::make_shared<SettingsMigrationDeleteKey>("language_settings/language"));
migrator.addMigration(4, std::make_shared<SettingsMigrationDeleteKey>("source/build_file_path/vs_solution_path"));
migrator.addMigration(4, std::make_shared<SettingsMigrationDeleteKey>("source/extensions/header_extensions"));
for (std::shared_ptr<SourceGroupSettings> sourceGroupSettings : getAllSourceGroupSettings())
{
const std::string key = SourceGroupSettings::s_keyPrefix + sourceGroupSettings->getId();
migrator.addMigration(5, std::make_shared<SettingsMigrationMoveKey>(key + "/exclude_paths/exclude_path", key + "/exclude_filters/exclude_filter"));
}
return migrator;
}
+9 -2
View File
@@ -85,9 +85,16 @@ void Settings::setVersion(size_t version)
FilePath Settings::expandPath(const FilePath& path)
{
std::vector<FilePath> paths = path.expandEnvironmentVariables();
if (paths.size() >= 1)
if (!paths.empty())
{
return paths[0];
if (paths.size() > 1)
{
LOG_WARNING(
L"Environment variable in path \"" + path.wstr() + L"\" has been expanded to " + std::to_wstring(paths.size()) +
L"paths, but only \"" + paths.front().wstr() + L"\" will be used."
);
}
return paths.front();
}
return FilePath();
}
+57 -11
View File
@@ -1,8 +1,10 @@
#include "settings/SourceGroupSettings.h"
#include "utility/file/FileSystem.h"
#include "utility/utility.h"
std::string SourceGroupSettings::s_keyPrefix = "source_groups/source_group_";
const size_t SourceGroupSettings::s_version = 1;
const std::string SourceGroupSettings::s_keyPrefix = "source_groups/source_group_";
SourceGroupSettings::SourceGroupSettings(const std::string& id, SourceGroupType type, const ProjectSettings* projectSettings)
: m_projectSettings(projectSettings)
@@ -12,7 +14,7 @@ SourceGroupSettings::SourceGroupSettings(const std::string& id, SourceGroupType
, m_status(SOURCE_GROUP_STATUS_ENABLED)
, m_standard("")
, m_sourcePaths(std::vector<FilePath>())
, m_excludePaths(std::vector<FilePath>())
, m_excludeFilters(std::vector<std::wstring>())
, m_sourceExtensions(std::vector<std::wstring>())
{
}
@@ -34,7 +36,7 @@ void SourceGroupSettings::load(std::shared_ptr<const ConfigManager> config)
setStatus(stringToSourceGroupStatusType(getValue(key + "/status", sourceGroupStatusTypeToString(SOURCE_GROUP_STATUS_ENABLED), config)));
setStandard(getValue<std::string>(key + "/standard", "", config));
setSourcePaths(getPathValues(key + "/source_paths/source_path", config));
setExcludePaths(getPathValues(key + "/exclude_paths/exclude_path", config));
setExcludeFilterStrings(getValues(key + "/exclude_filters/exclude_filter", std::vector<std::wstring>(), config));
setSourceExtensions(getValues(key + "/source_extensions/source_extension", std::vector<std::wstring>(), config));
}
@@ -46,7 +48,7 @@ void SourceGroupSettings::save(std::shared_ptr<ConfigManager> config)
setValue(key + "/name", getName(), config);
setValue(key + "/standard", getStandard(), config);
setPathValues(key + "/source_paths/source_path", getSourcePaths(), config);
setPathValues(key + "/exclude_paths/exclude_path", getExcludePaths(), config);
setValues(key + "/exclude_filters/exclude_filter", getExcludeFilterStrings(), config);
setValues(key + "/source_extensions/source_extension", getSourceExtensions(), config);
}
@@ -59,7 +61,7 @@ bool SourceGroupSettings::equals(std::shared_ptr<SourceGroupSettings> other) con
m_status == other->m_status &&
m_standard == other->m_standard &&
utility::isPermutation(m_sourcePaths, other->m_sourcePaths) &&
utility::isPermutation(m_excludePaths, other->m_excludePaths) &&
utility::isPermutation(m_excludeFilters, other->m_excludeFilters) &&
utility::isPermutation(m_sourceExtensions, other->m_sourceExtensions)
);
}
@@ -143,19 +145,63 @@ void SourceGroupSettings::setSourcePaths(const std::vector<FilePath>& sourcePath
m_sourcePaths = sourcePaths;
}
std::vector<FilePath> SourceGroupSettings::getExcludePaths() const
std::vector<std::wstring> SourceGroupSettings::getExcludeFilterStrings() const
{
return m_excludePaths;
return m_excludeFilters;
}
std::vector<FilePath> SourceGroupSettings::getExcludePathsExpandedAndAbsolute() const
std::vector<FilePathFilter> SourceGroupSettings::getExcludeFiltersExpandedAndAbsolute() const
{
return m_projectSettings->makePathsExpandedAndAbsolute(getExcludePaths());
std::vector<FilePathFilter> result;
for (const FilePathFilter& filter : m_excludeFilters)
{
const std::wstring filterString = filter.wstr();
const size_t wildcardPos = filterString.find(L"*");
if (wildcardPos != filterString.npos)
{
std::wsmatch match;
if (std::regex_search(filterString, match, std::wregex(L"[\\\\/]")) && !match.empty() && match.position(0) < wildcardPos)
{
const FilePath p = m_projectSettings->makePathExpandedAndAbsolute(FilePath(match.prefix().str()));
std::set<FilePath> symLinkPaths = FileSystem::getSymLinkedDirectories(p);
symLinkPaths.insert(p);
utility::append(result,
utility::convert<FilePath, FilePathFilter>(
utility::toVector(symLinkPaths),
[match](const FilePath& filePath) { return FilePathFilter(filePath.wstr() + L"/" + match.suffix().str()); }
)
);
}
else
{
result.push_back(filter);
}
}
else
{
const FilePath p = m_projectSettings->makePathExpandedAndAbsolute(FilePath(filterString));
const bool isFile = p.exists() && !p.isDirectory();
std::set<FilePath> symLinkPaths = FileSystem::getSymLinkedDirectories(p);
symLinkPaths.insert(p);
utility::append(result,
utility::convert<FilePath, FilePathFilter>(
utility::toVector(symLinkPaths),
[isFile](const FilePath& filePath) { return FilePathFilter(filePath.wstr() + (isFile ? L"" : L"**")); }
)
);
}
}
return result;
}
void SourceGroupSettings::setExcludePaths(const std::vector<FilePath>& excludePaths)
void SourceGroupSettings::setExcludeFilterStrings(const std::vector<std::wstring>& excludeFilters)
{
m_excludePaths = excludePaths;
m_excludeFilters = excludeFilters;
}
std::vector<std::wstring> SourceGroupSettings::getSourceExtensions() const
+7 -5
View File
@@ -7,13 +7,15 @@
#include "settings/ProjectSettings.h"
#include "settings/SourceGroupStatusType.h"
#include "settings/SourceGroupType.h"
#include "utility/file/FilePathFilter.h"
class ProjectSettings;
class SourceGroupSettings
{
public:
static std::string s_keyPrefix;
static const size_t s_version;
static const std::string s_keyPrefix;
SourceGroupSettings(const std::string& id, SourceGroupType type, const ProjectSettings* projectSettings);
virtual ~SourceGroupSettings();
@@ -46,9 +48,9 @@ public:
std::vector<FilePath> getSourcePathsExpandedAndAbsolute() const;
void setSourcePaths(const std::vector<FilePath>& sourcePaths);
std::vector<FilePath> getExcludePaths() const;
std::vector<FilePath> getExcludePathsExpandedAndAbsolute() const;
void setExcludePaths(const std::vector<FilePath>& excludePaths);
std::vector<std::wstring> getExcludeFilterStrings() const;
std::vector<FilePathFilter> getExcludeFiltersExpandedAndAbsolute() const;
void setExcludeFilterStrings(const std::vector<std::wstring>& excludeFilters);
std::vector<std::wstring> getSourceExtensions() const;
void setSourceExtensions(const std::vector<std::wstring>& sourceExtensions);
@@ -83,7 +85,7 @@ private:
std::string m_standard;
std::vector<FilePath> m_sourcePaths;
std::vector<FilePath> m_excludePaths;
std::vector<std::wstring> m_excludeFilters;
std::vector<std::wstring> m_sourceExtensions;
};