Added glob pattern support in paths filter
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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__
|
||||
|
||||
@@ -10,6 +10,6 @@ diagrams:
|
||||
namespaces:
|
||||
- clanguml::t00061
|
||||
paths:
|
||||
- include/t00061_a.h
|
||||
- include/*_a.h
|
||||
using_namespace:
|
||||
- clanguml::t00061
|
||||
@@ -10,9 +10,10 @@ diagrams:
|
||||
- src/**/*.h
|
||||
include:
|
||||
paths:
|
||||
- class_diagram/
|
||||
- class_d*/
|
||||
- common
|
||||
- util
|
||||
- util/*.h
|
||||
- util/*.cc
|
||||
- main.cc
|
||||
exclude:
|
||||
paths:
|
||||
|
||||
Reference in New Issue
Block a user