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
+2
View File
@@ -352,6 +352,8 @@ add_files(
utility/file/FileManager.h
utility/file/FilePath.cpp
utility/file/FilePath.h
utility/file/FilePathFilter.cpp
utility/file/FilePathFilter.h
utility/file/FileRegister.cpp
utility/file/FileRegister.h
utility/file/FileRegisterStateData.cpp
+7 -6
View File
@@ -3,11 +3,12 @@
#include "utility/utilityString.h"
IndexerCommand::IndexerCommand(
const FilePath& sourceFilePath, const std::set<FilePath>& indexedPaths, const std::set<FilePath>& excludedPaths
const FilePath& sourceFilePath, const std::set<FilePath>& indexedPaths,
const std::set<FilePathFilter>& excludeFilters
)
: m_sourceFilePath(sourceFilePath)
, m_indexedPaths(indexedPaths)
, m_excludedPaths(excludedPaths)
, m_excludeFilters(excludeFilters)
{
}
@@ -24,9 +25,9 @@ size_t IndexerCommand::getByteSize(size_t stringSize) const
size += stringSize + utility::encodeToUtf8(path.wstr()).size();
}
for (const FilePath& path : m_excludedPaths)
for (const FilePathFilter& filter : m_excludeFilters)
{
size += stringSize + utility::encodeToUtf8(path.wstr()).size();
size += stringSize + utility::encodeToUtf8(filter.wstr()).size();
}
return size;
@@ -42,7 +43,7 @@ const std::set<FilePath>& IndexerCommand::getIndexedPaths() const
return m_indexedPaths;
}
const std::set<FilePath>& IndexerCommand::getExcludedPath() const
const std::set<FilePathFilter>& IndexerCommand::getExcludeFilters() const
{
return m_excludedPaths;
return m_excludeFilters;
}
+4 -3
View File
@@ -6,11 +6,12 @@
#include "data/indexer/IndexerCommandType.h"
#include "utility/file/FilePath.h"
#include "utility/file/FilePathFilter.h"
class IndexerCommand
{
public:
IndexerCommand(const FilePath& sourceFilePath, const std::set<FilePath>& indexedPaths, const std::set<FilePath>& excludedPaths);
IndexerCommand(const FilePath& sourceFilePath, const std::set<FilePath>& indexedPaths, const std::set<FilePathFilter>& excludeFilters);
virtual ~IndexerCommand();
virtual IndexerCommandType getIndexerCommandType() const = 0;
@@ -19,12 +20,12 @@ public:
const FilePath& getSourceFilePath() const;
const std::set<FilePath>& getIndexedPaths() const;
const std::set<FilePath>& getExcludedPath() const;
const std::set<FilePathFilter>& getExcludeFilters() const;
private:
FilePath m_sourceFilePath;
std::set<FilePath> m_indexedPaths;
std::set<FilePath> m_excludedPaths;
std::set<FilePathFilter> m_excludeFilters;
};
#endif // INDEXER_COMMAND_H
@@ -54,7 +54,7 @@ void InterprocessIndexer::work()
data.setIndexedFiles(m_interprocessIndexingStatusManager.getIndexedFiles());
std::shared_ptr<FileRegister> fileRegister = std::make_shared<FileRegister>(
data, indexerCommand->getSourceFilePath(), indexerCommand->getIndexedPaths(), indexerCommand->getExcludedPath()
data, indexerCommand->getSourceFilePath(), indexerCommand->getIndexedPaths(), indexerCommand->getExcludeFilters()
);
LOG_INFO_STREAM(<< m_processId << " starting to index current file");
@@ -11,7 +11,7 @@ void SharedIndexerCommand::fromLocal(IndexerCommand* indexerCommand)
{
setSourceFilePath(indexerCommand->getSourceFilePath());
setIndexedPaths(indexerCommand->getIndexedPaths());
setExcludedPaths(indexerCommand->getExcludedPath());
setExcludeFilters(indexerCommand->getExcludeFilters());
if (dynamic_cast<IndexerCommandCxxCdb*>(indexerCommand) != nullptr)
{
@@ -58,7 +58,7 @@ std::shared_ptr<IndexerCommand> SharedIndexerCommand::fromShared(const SharedInd
std::shared_ptr<IndexerCommand> command = std::make_shared<IndexerCommandCxxCdb>(
indexerCommand.getSourceFilePath(),
indexerCommand.getIndexedPaths(),
indexerCommand.getExcludedPaths(),
indexerCommand.getExcludeFilters(),
indexerCommand.getWorkingDirectory(),
indexerCommand.getCompilerFlags(),
indexerCommand.getSystemHeaderSearchPaths(),
@@ -71,7 +71,7 @@ std::shared_ptr<IndexerCommand> SharedIndexerCommand::fromShared(const SharedInd
std::shared_ptr<IndexerCommand> command = std::make_shared<IndexerCommandCxxEmpty>(
indexerCommand.getSourceFilePath(),
indexerCommand.getIndexedPaths(),
indexerCommand.getExcludedPaths(),
indexerCommand.getExcludeFilters(),
indexerCommand.getWorkingDirectory(),
indexerCommand.getLanguageStandard(),
indexerCommand.getSystemHeaderSearchPaths(),
@@ -85,7 +85,7 @@ std::shared_ptr<IndexerCommand> SharedIndexerCommand::fromShared(const SharedInd
return std::make_shared<IndexerCommandJava>(
indexerCommand.getSourceFilePath(),
indexerCommand.getIndexedPaths(),
indexerCommand.getExcludedPaths(),
indexerCommand.getExcludeFilters(),
indexerCommand.getLanguageStandard(),
indexerCommand.getClassPaths()
);
@@ -104,7 +104,7 @@ SharedIndexerCommand::SharedIndexerCommand(SharedMemory::Allocator* allocator)
: m_type(Type::UNKNOWN)
, m_sourceFilePath("", allocator)
, m_indexedPaths(allocator)
, m_excludedPaths(allocator)
, m_excludeFilters(allocator)
, m_workingDirectory("", allocator)
, m_languageStandard("", allocator)
, m_compilerFlags(allocator)
@@ -152,27 +152,27 @@ void SharedIndexerCommand::setIndexedPaths(const std::set<FilePath>& indexedPath
}
}
std::set<FilePath> SharedIndexerCommand::getExcludedPaths() const
std::set<FilePathFilter> SharedIndexerCommand::getExcludeFilters() const
{
std::set<FilePath> result;
std::set<FilePathFilter> result;
for (unsigned int i = 0; i < m_excludedPaths.size(); i++)
for (unsigned int i = 0; i < m_excludeFilters.size(); i++)
{
result.insert(FilePath(utility::decodeFromUtf8(m_excludedPaths[i].c_str())));
result.insert(FilePathFilter(utility::decodeFromUtf8(m_excludeFilters[i].c_str())));
}
return result;
}
void SharedIndexerCommand::setExcludedPaths(const std::set<FilePath>& excludedPaths)
void SharedIndexerCommand::setExcludeFilters(const std::set<FilePathFilter>& excludeFilters)
{
m_excludedPaths.clear();
m_excludeFilters.clear();
for (const FilePath& excludedPath : excludedPaths)
for (const FilePathFilter& excludeFilter : excludeFilters)
{
SharedMemory::String path(m_excludedPaths.get_allocator());
path = utility::encodeToUtf8(excludedPath.wstr()).c_str();
m_excludedPaths.push_back(path);
SharedMemory::String path(m_excludeFilters.get_allocator());
path = utility::encodeToUtf8(excludeFilter.wstr()).c_str();
m_excludeFilters.push_back(path);
}
}
@@ -4,6 +4,7 @@
#include <set>
#include "utility/file/FilePath.h"
#include "utility/file/FilePathFilter.h"
#include "utility/interprocess/SharedMemory.h"
class IndexerCommand;
@@ -23,8 +24,8 @@ public:
std::set<FilePath> getIndexedPaths() const;
void setIndexedPaths(const std::set<FilePath>& indexedPaths);
std::set<FilePath> getExcludedPaths() const;
void setExcludedPaths(const std::set<FilePath>& excludedPaths);
std::set<FilePathFilter> getExcludeFilters() const;
void setExcludeFilters(const std::set<FilePathFilter>& excludeFilters);
FilePath getWorkingDirectory() const;
void setWorkingDirectory(const FilePath& workingDirectory);
@@ -61,7 +62,7 @@ private:
// indexer command
SharedMemory::String m_sourceFilePath;
SharedMemory::Vector<SharedMemory::String> m_indexedPaths;
SharedMemory::Vector<SharedMemory::String> m_excludedPaths;
SharedMemory::Vector<SharedMemory::String> m_excludeFilters;
// cxx
SharedMemory::String m_workingDirectory;
+4 -3
View File
@@ -4,6 +4,7 @@
#include "utility/file/FileManager.h"
#include "utility/file/FilePath.h"
#include "utility/file/FileSystem.h"
#include "utility/utility.h"
SourceGroup::~SourceGroup()
{
@@ -29,7 +30,7 @@ void SourceGroup::fetchAllSourceFilePaths()
FileManager fileManager;
fileManager.update(
getAllSourcePaths(),
getSourceGroupSettings()->getExcludePathsExpandedAndAbsolute(),
getSourceGroupSettings()->getExcludeFiltersExpandedAndAbsolute(),
getSourceGroupSettings()->getSourceExtensions()
);
m_allSourceFilePaths = fileManager.getAllSourceFilePaths();
@@ -40,9 +41,9 @@ std::set<FilePath> SourceGroup::getIndexedPaths() const
return findAndAddSymlinkedDirectories(getSourceGroupSettings()->getSourcePathsExpandedAndAbsolute());
}
std::set<FilePath> SourceGroup::getExcludedPaths() const
std::set<FilePathFilter> SourceGroup::getExcludeFilters() const
{
return findAndAddSymlinkedDirectories(getSourceGroupSettings()->getExcludePathsExpandedAndAbsolute());
return utility::toSet(getSourceGroupSettings()->getExcludeFiltersExpandedAndAbsolute());
}
std::set<FilePath> SourceGroup::getAllSourceFilePaths() const
+2 -1
View File
@@ -9,6 +9,7 @@
#include "settings/SourceGroupStatusType.h"
#include "settings/SourceGroupType.h"
#include "utility/file/FilePath.h"
#include "utility/file/FilePathFilter.h"
class IndexerCommand;
class SourceGroupSettings;
@@ -26,7 +27,7 @@ public:
void fetchAllSourceFilePaths();
std::set<FilePath> getIndexedPaths() const;
std::set<FilePath> getExcludedPaths() const;
std::set<FilePathFilter> getExcludeFilters() const;
std::set<FilePath> getAllSourceFilePaths() const;
std::set<FilePath> getSourceFilePathsToIndex(const std::set<FilePath>& staticSourceFilePaths) const;
+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;
};
+5 -4
View File
@@ -4,6 +4,7 @@
#include "utility/file/FileSystem.h"
#include "utility/file/FilePath.h"
#include "utility/file/FilePathFilter.h"
FileManager::FileManager()
{
@@ -15,11 +16,11 @@ FileManager::~FileManager()
void FileManager::update(
const std::vector<FilePath>& sourcePaths,
const std::vector<FilePath>& excludePaths,
const std::vector<FilePathFilter>& excludeFilters,
const std::vector<std::wstring>& sourceExtensions
){
m_sourcePaths = sourcePaths;
m_excludePaths = makeCanonical(excludePaths);
m_excludeFilters = excludeFilters;
m_sourceExtensions = sourceExtensions;
m_allSourceFilePaths.clear();
@@ -85,9 +86,9 @@ std::vector<FilePath> FileManager::makeCanonical(const std::vector<FilePath>& fi
bool FileManager::isExcluded(const FilePath& filePath) const
{
for (const FilePath& path : m_excludePaths)
for (const FilePathFilter& filter : m_excludeFilters)
{
if (path == filePath || path.contains(filePath))
if (filter.isMatching(filePath))
{
return true;
}
+3 -2
View File
@@ -7,6 +7,7 @@
#include <vector>
class FilePath;
class FilePathFilter;
class FileManager
{
@@ -16,7 +17,7 @@ public:
void update(
const std::vector<FilePath>& sourcePaths,
const std::vector<FilePath>& excludePaths,
const std::vector<FilePathFilter>& excludeFilters,
const std::vector<std::wstring>& sourceExtensions
);
@@ -35,7 +36,7 @@ private:
bool isExcluded(const FilePath& filePath) const;
std::vector<FilePath> m_sourcePaths;
std::vector<FilePath> m_excludePaths;
std::vector<FilePathFilter> m_excludeFilters;
std::vector<std::wstring> m_sourceExtensions;
std::set<FilePath> m_allSourceFilePaths;
+101
View File
@@ -0,0 +1,101 @@
#include "utility/file/FilePathFilter.h"
FilePathFilter::FilePathFilter(const std::wstring& filterString)
: m_filterString(filterString)
, m_filterRegex(convertFilterStringToRegex(filterString))
{
}
std::wstring FilePathFilter::wstr() const
{
return m_filterString;
}
bool FilePathFilter::isMatching(const FilePath& filePath) const
{
const std::wstring s = filePath.wstr();
std::wsmatch match;
return std::regex_match(s, match, m_filterRegex);
}
bool FilePathFilter::operator<(const FilePathFilter& other) const
{
return m_filterString.compare(other.m_filterString) < 0;
}
std::wregex FilePathFilter::convertFilterStringToRegex(const std::wstring& filterString)
{
std::wstring regexFilterString = filterString;
{
std::wregex regex(L"[\\\\/]");
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\\\/]");
}
{
std::wregex regex(L"([^\\\\])([^/])([\\]])");
regexFilterString = std::regex_replace(regexFilterString, regex, L"$1$2[\\]]");
}
{
std::wregex regex(L"([\\[])([^\\\\])");
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\[]$2");
}
{
std::wregex regex(L"[\\(]");
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\(]");
}
{
std::wregex regex(L"[\\)]");
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\)]");
}
{
std::wregex regex(L"[\\{]");
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\{]");
}
{
std::wregex regex(L"[\\}]");
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\}]");
}
{
std::wregex regex(L"[\\+]");
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\+]");
}
{
std::wregex regex(L"[\\-]");
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\-]");
}
{
std::wregex regex(L"[\\$]");
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\$]");
}
{
std::wregex regex(L"[\\.]");
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\.]");
}
{
std::wregex regex(L"[\\^]");
regexFilterString = std::regex_replace(regexFilterString, regex, L"[\\^]");
}
{
std::wregex regex(L"[\\*][\\*]");
regexFilterString = std::regex_replace(regexFilterString, regex, L".{0,}");
}
{
std::wregex regex(L"[\\*]");
regexFilterString = std::regex_replace(regexFilterString, regex, L"[^\\\\/]*");
}
return std::wregex(regexFilterString);
}
+27
View File
@@ -0,0 +1,27 @@
#ifndef FILE_PATH_FILTER_H
#define FILE_PATH_FILTER_H
#include <regex>
#include <string>
#include "utility/file/FilePath.h"
class FilePathFilter
{
public:
FilePathFilter(const std::wstring& filterString);
std::wstring wstr() const;
bool isMatching(const FilePath& filePath) const;
bool operator<(const FilePathFilter& other) const;
private:
static std::wregex convertFilterStringToRegex(const std::wstring& filterString);
std::wstring m_filterString;
std::wregex m_filterRegex;
};
#endif // FILE_PATH_FILTER_H
+7 -17
View File
@@ -1,17 +1,18 @@
#include "utility/file/FileRegister.h"
#include "utility/file/FilePath.h"
#include "utility/file/FilePathFilter.h"
FileRegister::FileRegister(
const FileRegisterStateData& stateData,
const FilePath& currentPath,
const std::set<FilePath>& indexedPaths,
const std::set<FilePath>& excludedPaths
const std::set<FilePathFilter>& excludeFilters
)
: m_stateData(stateData)
, m_currentPath(currentPath)
, m_indexedPaths(indexedPaths)
, m_excludedPaths(excludedPaths)
, m_excludeFilters(excludeFilters)
, m_hasFilePathCache(
[&](const std::wstring& f)
{
@@ -48,23 +49,12 @@ FileRegister::FileRegister(
if (ret)
{
for (const FilePath& excluded: m_excludedPaths)
for (const FilePathFilter& excludeFilter: m_excludeFilters)
{
if (excluded.isDirectory())
if (excludeFilter.isMatching(filePath))
{
if (excluded.contains(filePath))
{
ret = false;
break;
}
}
else
{
if (excluded == filePath)
{
ret = false;
break;
}
ret = false;
break;
}
}
}
+4 -2
View File
@@ -6,6 +6,8 @@
#include "utility/file/FileRegisterStateData.h"
#include "utility/UnorderedCache.h"
class FilePathFilter;
class FileRegister
{
public:
@@ -13,7 +15,7 @@ public:
const FileRegisterStateData& stateData,
const FilePath& currentPath,
const std::set<FilePath>& indexedPaths,
const std::set<FilePath>& excludedPaths
const std::set<FilePathFilter>& excludeFilters
);
virtual ~FileRegister();
@@ -28,7 +30,7 @@ private:
FileRegisterStateData m_stateData;
const FilePath& m_currentPath;
const std::set<FilePath> m_indexedPaths;
const std::set<FilePath> m_excludedPaths;
const std::set<FilePathFilter> m_excludeFilters;
mutable UnorderedCache<std::wstring, bool> m_hasFilePathCache;
};
+5 -1
View File
@@ -132,10 +132,14 @@ std::vector<FileInfo> FileSystem::getFileInfosFromPaths(
return files;
}
std::set<FilePath> FileSystem::getSymLinkedDirectories(const FilePath& path)
{
return getSymLinkedDirectories(std::vector<FilePath>{path});
}
std::set<FilePath> FileSystem::getSymLinkedDirectories(const std::vector<FilePath>& paths)
{
std::set<boost::filesystem::path> symlinkDirs;
std::set<boost::filesystem::path> filePaths;
for (const FilePath& path: paths)
{
+1
View File
@@ -19,6 +19,7 @@ public:
static std::vector<FileInfo> getFileInfosFromPaths(
const std::vector<FilePath>& paths, const std::vector<std::wstring>& fileExtensions, bool followSymLinks = true);
static std::set<FilePath> getSymLinkedDirectories(const FilePath& path);
static std::set<FilePath> getSymLinkedDirectories(const std::vector<FilePath>& paths);
static unsigned long long getFileByteSize(const FilePath& filePath);
+14
View File
@@ -67,6 +67,9 @@ namespace utility
template<typename SourceType, typename TargetType>
std::vector<TargetType> convert(const std::vector<SourceType>& sourceContainer, std::function<TargetType(const SourceType&)> conversion);
template<typename SourceType, typename TargetType>
std::vector<TargetType> convert(const std::vector<SourceType>& sourceContainer);
template<typename T>
std::vector<std::string> toStrings(const std::vector<T>& d);
template<>
@@ -239,6 +242,17 @@ std::vector<TargetType> utility::convert(const std::vector<SourceType>& sourceCo
return targetContainer;
}
template<typename SourceType, typename TargetType>
std::vector<TargetType> utility::convert(const std::vector<SourceType>& sourceContainer)
{
std::vector<TargetType> targetContainer;
for (const SourceType& sourceElement : sourceContainer)
{
targetContainer.push_back(TargetType(sourceElement));
}
return targetContainer;
}
template<typename T>
std::vector<std::string> utility::toStrings(const std::vector<T>& d)
{