From b10c55e7f9da9461e3831416278b76d039351e09 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Tue, 7 Jun 2016 10:46:36 +0200 Subject: [PATCH] src: Added logic and UI for excluding files and directories from analysis bug id = 68, 47 --- bin/app/data/ProjectSettings_template.xml | 4 ++ src/lib/Project.cpp | 4 +- src/lib/settings/ProjectSettings.cpp | 19 +++++++++ src/lib/settings/ProjectSettings.h | 7 ++-- src/lib/utility/file/FileManager.cpp | 25 +++++++++++ src/lib/utility/file/FileManager.h | 5 ++- .../project_wizzard/QtProjectWizzard.cpp | 1 + .../QtProjectWizzardContentPaths.cpp | 41 ++++++++++++++++++- .../QtProjectWizzardContentPaths.h | 11 +++++ src/test/FileManagerTestSuite.h | 3 +- 10 files changed, 113 insertions(+), 7 deletions(-) diff --git a/bin/app/data/ProjectSettings_template.xml b/bin/app/data/ProjectSettings_template.xml index a057e8f2..ea44e49f 100644 --- a/bin/app/data/ProjectSettings_template.xml +++ b/bin/app/data/ProjectSettings_template.xml @@ -40,6 +40,10 @@ + + + + diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index 0b2bcb90..e0a82a31 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -254,9 +254,11 @@ void Project::updateFileManager() sourcePaths = TaskParseCxx::getSourceFilesFromCDB(projSettings->getCompilationDatabasePath()); } + std::vector excludePaths = projSettings->getAbsoluteExcludePaths(); + std::vector sourceExtensions = projSettings->getSourceExtensions(); - m_fileManager.setPaths(sourcePaths, headerPaths, sourceExtensions); + m_fileManager.setPaths(sourcePaths, headerPaths, excludePaths, sourceExtensions); } Parser::Arguments Project::getParserArguments() const diff --git a/src/lib/settings/ProjectSettings.cpp b/src/lib/settings/ProjectSettings.cpp index 746a00db..474e584f 100644 --- a/src/lib/settings/ProjectSettings.cpp +++ b/src/lib/settings/ProjectSettings.cpp @@ -44,6 +44,7 @@ bool ProjectSettings::operator==(const ProjectSettings& other) const utility::isPermutation(getSourcePaths(), other.getSourcePaths()) && utility::isPermutation(getHeaderSearchPaths(), other.getHeaderSearchPaths()) && utility::isPermutation(getFrameworkSearchPaths(), other.getFrameworkSearchPaths()) && + utility::isPermutation(getExcludePaths(), other.getExcludePaths()) && utility::isPermutation(getCompilerFlags(), other.getCompilerFlags()) && utility::isPermutation(getSourceExtensions(), other.getSourceExtensions()); } @@ -171,6 +172,24 @@ bool ProjectSettings::setUseSourcePathsForHeaderSearch(bool useSourcePathsForHea return setValue("source/use_source_paths_for_header_search", useSourcePathsForHeaderSearch); } +std::vector ProjectSettings::getExcludePaths() const +{ + return getPathValues("source/exclude_paths/exclude_path"); +} + +std::vector ProjectSettings::getAbsoluteExcludePaths() const +{ + std::vector paths = getExcludePaths(); + expandPaths(paths); + makePathsAbsolute(paths); + return paths; +} + +bool ProjectSettings::setExcludePaths(const std::vector& excludePaths) +{ + return setPathValues("source/exclude_paths/exclude_path", excludePaths); +} + FilePath ProjectSettings::getVisualStudioSolutionPath() const { return FilePath(getValue("source/build_file_path/vs_solution_path", "")); diff --git a/src/lib/settings/ProjectSettings.h b/src/lib/settings/ProjectSettings.h index deab2029..121950e4 100644 --- a/src/lib/settings/ProjectSettings.h +++ b/src/lib/settings/ProjectSettings.h @@ -44,16 +44,17 @@ public: std::vector getCompilerFlags() const; bool setCompilerFlags(const std::vector& compilerFlags); - std::vector getHeaderExtensions() const; std::vector getSourceExtensions() const; - - bool setHeaderExtensions(const std::vector& headerExtensions); bool setSourceExtensions(const std::vector& sourceExtensions); bool isUseSourcePathsForHeaderSearchDefined() const; bool getUseSourcePathsForHeaderSearch() const; bool setUseSourcePathsForHeaderSearch(bool useSourcePathsForHeaderSearch); + std::vector getExcludePaths() const; + std::vector getAbsoluteExcludePaths() const; + bool setExcludePaths(const std::vector& excludePaths); + FilePath getVisualStudioSolutionPath() const; bool setVisualStudioSolutionPath(const FilePath& visualStudioSolutionPath); diff --git a/src/lib/utility/file/FileManager.cpp b/src/lib/utility/file/FileManager.cpp index a8a91939..b79124e4 100644 --- a/src/lib/utility/file/FileManager.cpp +++ b/src/lib/utility/file/FileManager.cpp @@ -23,10 +23,12 @@ const std::vector& FileManager::getSourcePaths() const void FileManager::setPaths( std::vector sourcePaths, std::vector headerPaths, + std::vector excludePaths, std::vector sourceExtensions ){ m_sourcePaths = sourcePaths; m_headerPaths = headerPaths; + m_excludePaths = excludePaths; m_sourceExtensions = sourceExtensions; } @@ -65,6 +67,11 @@ void FileManager::fetchFilePaths(const std::vector& oldFileInfos) for (FileInfo fileInfo: fileInfos) { const FilePath& filePath = fileInfo.path; + if (isExcluded(filePath)) + { + continue; + } + std::map::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; +} diff --git a/src/lib/utility/file/FileManager.h b/src/lib/utility/file/FileManager.h index 947c26a7..7ac8117b 100644 --- a/src/lib/utility/file/FileManager.h +++ b/src/lib/utility/file/FileManager.h @@ -18,6 +18,7 @@ public: void setPaths( std::vector sourcePaths, std::vector headerPaths, + std::vector excludePaths, std::vector sourceExtensions ); @@ -33,13 +34,15 @@ public: virtual const FileInfo getFileInfo(const FilePath& filePath) const; private: + bool isExcluded(const FilePath& filePath) const; + std::map m_files; std::vector m_sourcePaths; std::vector m_headerPaths; + std::vector m_excludePaths; std::vector m_sourceExtensions; - std::vector m_includeExtensions; std::set m_addedFiles; std::set m_updatedFiles; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp index 107b4181..8371be9c 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp @@ -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(); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp index 6de53855..ca1970a5 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp @@ -244,7 +244,7 @@ bool QtProjectWizzardContentPathsSource::check() QStringList QtProjectWizzardContentPathsSource::getFileNames() const { std::vector sourcePaths = m_settings->getAbsoluteSourcePaths(); - + std::vector excludePaths = m_settings->getAbsoluteExcludePaths(); std::vector extensions = m_settings->getSourceExtensions(); std::vector 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 ) diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h index 55148e02..e4101ec5 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h @@ -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 { diff --git a/src/test/FileManagerTestSuite.h b/src/test/FileManagerTestSuite.h index 78fe9318..653c3324 100644 --- a/src/test/FileManagerTestSuite.h +++ b/src/test/FileManagerTestSuite.h @@ -20,12 +20,13 @@ public: sourcePaths.push_back("./data/FileManagerTestSuite/src/"); sourcePaths.push_back("./data/FileManagerTestSuite/include/"); std::vector headerPaths; + std::vector excludePaths; std::vector 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()); TS_ASSERT_EQUALS(fm.getAddedFilePaths().size(), 2);