src: Added logic and UI for excluding files and directories from analysis

bug id = 68, 47
This commit is contained in:
Eberhard Graether
2016-06-07 10:46:36 +02:00
parent 6edcd77eb2
commit b10c55e7f9
10 changed files with 113 additions and 7 deletions
@@ -40,6 +40,10 @@
<use_source_paths_for_header_search><!-- BOOL: If enabled all subfolder of the source paths will be used for header search --></use_source_paths_for_header_search>
<exclude_paths>
<exclude_path><!-- STRING: path to file or directory to exclude from analysis --></source_path>
</exclude_paths>
<build_file_path>
<vs_solution_path><!-- STRING: path to Visual Studio solution *.sln --></vs_solution_path>
<compilation_db_path><!-- STRING: path to Compilation Database --></compilation_db_path>
+3 -1
View File
@@ -254,9 +254,11 @@ void Project::updateFileManager()
sourcePaths = TaskParseCxx::getSourceFilesFromCDB(projSettings->getCompilationDatabasePath());
}
std::vector<FilePath> excludePaths = projSettings->getAbsoluteExcludePaths();
std::vector<std::string> sourceExtensions = projSettings->getSourceExtensions();
m_fileManager.setPaths(sourcePaths, headerPaths, sourceExtensions);
m_fileManager.setPaths(sourcePaths, headerPaths, excludePaths, sourceExtensions);
}
Parser::Arguments Project::getParserArguments() const
+19
View File
@@ -44,6 +44,7 @@ bool ProjectSettings::operator==(const ProjectSettings& other) const
utility::isPermutation<FilePath>(getSourcePaths(), other.getSourcePaths()) &&
utility::isPermutation<FilePath>(getHeaderSearchPaths(), other.getHeaderSearchPaths()) &&
utility::isPermutation<FilePath>(getFrameworkSearchPaths(), other.getFrameworkSearchPaths()) &&
utility::isPermutation<FilePath>(getExcludePaths(), other.getExcludePaths()) &&
utility::isPermutation<std::string>(getCompilerFlags(), other.getCompilerFlags()) &&
utility::isPermutation<std::string>(getSourceExtensions(), other.getSourceExtensions());
}
@@ -171,6 +172,24 @@ bool ProjectSettings::setUseSourcePathsForHeaderSearch(bool useSourcePathsForHea
return setValue<bool>("source/use_source_paths_for_header_search", useSourcePathsForHeaderSearch);
}
std::vector<FilePath> ProjectSettings::getExcludePaths() const
{
return getPathValues("source/exclude_paths/exclude_path");
}
std::vector<FilePath> ProjectSettings::getAbsoluteExcludePaths() const
{
std::vector<FilePath> paths = getExcludePaths();
expandPaths(paths);
makePathsAbsolute(paths);
return paths;
}
bool ProjectSettings::setExcludePaths(const std::vector<FilePath>& excludePaths)
{
return setPathValues("source/exclude_paths/exclude_path", excludePaths);
}
FilePath ProjectSettings::getVisualStudioSolutionPath() const
{
return FilePath(getValue<std::string>("source/build_file_path/vs_solution_path", ""));
+4 -3
View File
@@ -44,16 +44,17 @@ public:
std::vector<std::string> getCompilerFlags() const;
bool setCompilerFlags(const std::vector<std::string>& compilerFlags);
std::vector<std::string> getHeaderExtensions() const;
std::vector<std::string> getSourceExtensions() const;
bool setHeaderExtensions(const std::vector<std::string>& headerExtensions);
bool setSourceExtensions(const std::vector<std::string>& sourceExtensions);
bool isUseSourcePathsForHeaderSearchDefined() const;
bool getUseSourcePathsForHeaderSearch() const;
bool setUseSourcePathsForHeaderSearch(bool useSourcePathsForHeaderSearch);
std::vector<FilePath> getExcludePaths() const;
std::vector<FilePath> getAbsoluteExcludePaths() const;
bool setExcludePaths(const std::vector<FilePath>& excludePaths);
FilePath getVisualStudioSolutionPath() const;
bool setVisualStudioSolutionPath(const FilePath& visualStudioSolutionPath);
+25
View File
@@ -23,10 +23,12 @@ const std::vector<FilePath>& FileManager::getSourcePaths() const
void FileManager::setPaths(
std::vector<FilePath> sourcePaths,
std::vector<FilePath> headerPaths,
std::vector<FilePath> excludePaths,
std::vector<std::string> sourceExtensions
){
m_sourcePaths = sourcePaths;
m_headerPaths = headerPaths;
m_excludePaths = excludePaths;
m_sourceExtensions = sourceExtensions;
}
@@ -65,6 +67,11 @@ void FileManager::fetchFilePaths(const std::vector<FileInfo>& oldFileInfos)
for (FileInfo fileInfo: fileInfos)
{
const FilePath& filePath = fileInfo.path;
if (isExcluded(filePath))
{
continue;
}
std::map<FilePath, FileInfo>::iterator it = m_files.find(filePath);
if (it != m_files.end())
{
@@ -110,6 +117,11 @@ bool FileManager::hasFilePath(const FilePath& filePath) const
return true;
}
if (isExcluded(filePath))
{
return false;
}
for (FilePath path : m_headerPaths)
{
if (path == filePath || path.contains(filePath))
@@ -137,3 +149,16 @@ const FileInfo FileManager::getFileInfo(const FilePath& filePath) const
return it->second;
}
bool FileManager::isExcluded(const FilePath& filePath) const
{
for (FilePath path : m_excludePaths)
{
if (path == filePath || path.contains(filePath))
{
return true;
}
}
return false;
}
+4 -1
View File
@@ -18,6 +18,7 @@ public:
void setPaths(
std::vector<FilePath> sourcePaths,
std::vector<FilePath> headerPaths,
std::vector<FilePath> excludePaths,
std::vector<std::string> sourceExtensions
);
@@ -33,13 +34,15 @@ public:
virtual const FileInfo getFileInfo(const FilePath& filePath) const;
private:
bool isExcluded(const FilePath& filePath) const;
std::map<FilePath, FileInfo> m_files;
std::vector<FilePath> m_sourcePaths;
std::vector<FilePath> m_headerPaths;
std::vector<FilePath> m_excludePaths;
std::vector<std::string> m_sourceExtensions;
std::vector<std::string> m_includeExtensions;
std::set<FilePath> m_addedFiles;
std::set<FilePath> m_updatedFiles;
@@ -571,6 +571,7 @@ void QtProjectWizzard::showSummary()
summary->addContent(new QtProjectWizzardContentFlags(settings, window), true, false);
summary->addContent(new QtProjectWizzardContentExtensions(settings, window), true, true);
summary->addContent(new QtProjectWizzardContentPathsExclude(settings, window), true, true);
window->setup();
@@ -244,7 +244,7 @@ bool QtProjectWizzardContentPathsSource::check()
QStringList QtProjectWizzardContentPathsSource::getFileNames() const
{
std::vector<FilePath> sourcePaths = m_settings->getAbsoluteSourcePaths();
std::vector<FilePath> excludePaths = m_settings->getAbsoluteExcludePaths();
std::vector<std::string> extensions = m_settings->getSourceExtensions();
std::vector<FileInfo> fileInfos = FileSystem::getFileInfosFromPaths(sourcePaths, extensions);
@@ -255,6 +255,21 @@ QStringList QtProjectWizzardContentPathsSource::getFileNames() const
{
FilePath path = info.path;
bool excluded = false;
for (FilePath p : excludePaths)
{
if (p == path || p.contains(path))
{
excluded = true;
break;
}
}
if (excluded)
{
continue;
}
if (projectPath.exists())
{
path = path.relativeTo(projectPath);
@@ -294,6 +309,30 @@ QtProjectWizzardContentPathsCDBHeader::QtProjectWizzardContentPathsCDBHeader(
);
}
QtProjectWizzardContentPathsExclude::QtProjectWizzardContentPathsExclude(
ProjectSettings* settings, QtProjectWizzardWindow* window
)
: QtProjectWizzardContentPaths(settings, window)
{
setInfo(
"Exclude Paths",
"Add all directories or files you want to exclude from the analysis.",
"Exclude Paths define the files and directories that will be left out from the analysis by Coati."
);
}
void QtProjectWizzardContentPathsExclude::load()
{
m_list->setList(m_settings->getExcludePaths());
}
void QtProjectWizzardContentPathsExclude::save()
{
m_settings->setExcludePaths(m_list->getList());
}
QtProjectWizzardContentPathsHeaderSearch::QtProjectWizzardContentPathsHeaderSearch(
ProjectSettings* settings, QtProjectWizzardWindow* window
)
@@ -79,6 +79,17 @@ public:
};
class QtProjectWizzardContentPathsExclude
: public QtProjectWizzardContentPaths
{
public:
QtProjectWizzardContentPathsExclude(ProjectSettings* settings, QtProjectWizzardWindow* window);
virtual void load() override;
virtual void save() override;
};
class QtProjectWizzardContentPathsHeaderSearch
: public QtProjectWizzardContentPaths
{
+2 -1
View File
@@ -20,12 +20,13 @@ public:
sourcePaths.push_back("./data/FileManagerTestSuite/src/");
sourcePaths.push_back("./data/FileManagerTestSuite/include/");
std::vector<FilePath> headerPaths;
std::vector<FilePath> excludePaths;
std::vector<std::string> sourceExtensions;
sourceExtensions.push_back(".cpp");
sourceExtensions.push_back(".c");
FileManager fm;
fm.setPaths(sourcePaths, headerPaths, sourceExtensions);
fm.setPaths(sourcePaths, headerPaths, excludePaths, sourceExtensions);
fm.fetchFilePaths(std::vector<FileInfo>());
TS_ASSERT_EQUALS(fm.getAddedFilePaths().size(), 2);