Added glob pattern support in paths filter

This commit is contained in:
Bartek Kryza
2023-06-10 11:16:26 +02:00
parent ac01127436
commit dc74069dfd
7 changed files with 35 additions and 20 deletions

View File

@@ -22,6 +22,7 @@
#include "class_diagram/model/class.h"
#include "common/model/package.h"
#include "glob/glob.hpp"
#include "include_diagram/model/diagram.h"
#include "package_diagram/model/diagram.h"
@@ -493,33 +494,44 @@ tvl::value_t context_filter::match(const diagram &d, const element &e) const
}
paths_filter::paths_filter(filter_t type, const std::filesystem::path &root,
const std::vector<std::filesystem::path> &p)
const std::vector<std::string> &p)
: filter_visitor{type}
, root_{root}
{
for (const auto &path : p) {
std::filesystem::path absolute_path;
if (path.string().empty() || path.string() == ".")
if (path.empty() || path == ".")
absolute_path = root;
else if (path.is_relative())
else if (std::filesystem::path{path}.is_relative())
absolute_path = root / path;
else
absolute_path = path;
try {
absolute_path = absolute(absolute_path);
absolute_path = canonical(absolute_path.lexically_normal());
}
catch (std::filesystem::filesystem_error &e) {
LOG_WARN("Cannot add non-existent path {} to paths filter",
absolute_path.string());
continue;
bool match_successful{false};
for (auto &resolved_glob_path :
glob::glob(absolute_path.string(), true)) {
try {
auto resolved_absolute_path = absolute(resolved_glob_path);
resolved_absolute_path =
canonical(resolved_absolute_path.lexically_normal());
resolved_absolute_path.make_preferred();
paths_.emplace_back(resolved_absolute_path);
match_successful = true;
}
catch (std::filesystem::filesystem_error &e) {
LOG_WARN("Cannot add non-existent path {} to paths filter",
absolute_path.string());
continue;
}
}
absolute_path.make_preferred();
paths_.emplace_back(std::move(absolute_path));
if (!match_successful)
LOG_WARN(
"Paths filter pattern '{}' did not match any files...", path);
}
}

View File

@@ -374,7 +374,7 @@ private:
struct paths_filter : public filter_visitor {
paths_filter(filter_t type, const std::filesystem::path &root,
const std::vector<std::filesystem::path> &p);
const std::vector<std::string> &p);
~paths_filter() override = default;

View File

@@ -235,4 +235,6 @@ std::string to_string(const string_or_regex &sr);
using namespace_or_regex = common::or_regex<common::model::namespace_>;
struct path_or_regex : public or_regex<std::filesystem::path> { };
} // namespace clanguml::common

View File

@@ -109,7 +109,7 @@ struct filter {
std::vector<common::string_or_regex> context;
std::vector<std::filesystem::path> paths;
std::vector<std::string> paths;
std::vector<method_type> method_types;
};

View File

@@ -134,7 +134,7 @@ std::string get_os_name()
#elif _WIN64
return "Windows, 64-bit";
#elif __has_include(<sys/utsname.h>)
utsname utsn;
struct utsname utsn; // NOLINT
uname(&utsn);
return fmt::format("{} {} {}", utsn.sysname, utsn.machine, utsn.release);
#elif __linux__

View File

@@ -10,6 +10,6 @@ diagrams:
namespaces:
- clanguml::t00061
paths:
- include/t00061_a.h
- include/*_a.h
using_namespace:
- clanguml::t00061

View File

@@ -10,9 +10,10 @@ diagrams:
- src/**/*.h
include:
paths:
- class_diagram/
- class_d*/
- common
- util
- util/*.h
- util/*.cc
- main.cc
exclude:
paths: