Added glob pattern support in paths filter
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "class_diagram/model/class.h"
|
#include "class_diagram/model/class.h"
|
||||||
#include "common/model/package.h"
|
#include "common/model/package.h"
|
||||||
|
#include "glob/glob.hpp"
|
||||||
#include "include_diagram/model/diagram.h"
|
#include "include_diagram/model/diagram.h"
|
||||||
#include "package_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,
|
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}
|
: filter_visitor{type}
|
||||||
, root_{root}
|
, root_{root}
|
||||||
{
|
{
|
||||||
for (const auto &path : p) {
|
for (const auto &path : p) {
|
||||||
std::filesystem::path absolute_path;
|
std::filesystem::path absolute_path;
|
||||||
|
|
||||||
if (path.string().empty() || path.string() == ".")
|
if (path.empty() || path == ".")
|
||||||
absolute_path = root;
|
absolute_path = root;
|
||||||
else if (path.is_relative())
|
else if (std::filesystem::path{path}.is_relative())
|
||||||
absolute_path = root / path;
|
absolute_path = root / path;
|
||||||
else
|
else
|
||||||
absolute_path = path;
|
absolute_path = path;
|
||||||
|
|
||||||
try {
|
bool match_successful{false};
|
||||||
absolute_path = absolute(absolute_path);
|
for (auto &resolved_glob_path :
|
||||||
absolute_path = canonical(absolute_path.lexically_normal());
|
glob::glob(absolute_path.string(), true)) {
|
||||||
}
|
try {
|
||||||
catch (std::filesystem::filesystem_error &e) {
|
auto resolved_absolute_path = absolute(resolved_glob_path);
|
||||||
LOG_WARN("Cannot add non-existent path {} to paths filter",
|
resolved_absolute_path =
|
||||||
absolute_path.string());
|
canonical(resolved_absolute_path.lexically_normal());
|
||||||
continue;
|
|
||||||
|
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();
|
if (!match_successful)
|
||||||
|
LOG_WARN(
|
||||||
paths_.emplace_back(std::move(absolute_path));
|
"Paths filter pattern '{}' did not match any files...", path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -374,7 +374,7 @@ private:
|
|||||||
|
|
||||||
struct paths_filter : public filter_visitor {
|
struct paths_filter : public filter_visitor {
|
||||||
paths_filter(filter_t type, const std::filesystem::path &root,
|
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;
|
~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_>;
|
using namespace_or_regex = common::or_regex<common::model::namespace_>;
|
||||||
|
|
||||||
|
struct path_or_regex : public or_regex<std::filesystem::path> { };
|
||||||
|
|
||||||
} // namespace clanguml::common
|
} // namespace clanguml::common
|
||||||
@@ -109,7 +109,7 @@ struct filter {
|
|||||||
|
|
||||||
std::vector<common::string_or_regex> context;
|
std::vector<common::string_or_regex> context;
|
||||||
|
|
||||||
std::vector<std::filesystem::path> paths;
|
std::vector<std::string> paths;
|
||||||
|
|
||||||
std::vector<method_type> method_types;
|
std::vector<method_type> method_types;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ std::string get_os_name()
|
|||||||
#elif _WIN64
|
#elif _WIN64
|
||||||
return "Windows, 64-bit";
|
return "Windows, 64-bit";
|
||||||
#elif __has_include(<sys/utsname.h>)
|
#elif __has_include(<sys/utsname.h>)
|
||||||
utsname utsn;
|
struct utsname utsn; // NOLINT
|
||||||
uname(&utsn);
|
uname(&utsn);
|
||||||
return fmt::format("{} {} {}", utsn.sysname, utsn.machine, utsn.release);
|
return fmt::format("{} {} {}", utsn.sysname, utsn.machine, utsn.release);
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
|
|||||||
@@ -10,6 +10,6 @@ diagrams:
|
|||||||
namespaces:
|
namespaces:
|
||||||
- clanguml::t00061
|
- clanguml::t00061
|
||||||
paths:
|
paths:
|
||||||
- include/t00061_a.h
|
- include/*_a.h
|
||||||
using_namespace:
|
using_namespace:
|
||||||
- clanguml::t00061
|
- clanguml::t00061
|
||||||
@@ -10,9 +10,10 @@ diagrams:
|
|||||||
- src/**/*.h
|
- src/**/*.h
|
||||||
include:
|
include:
|
||||||
paths:
|
paths:
|
||||||
- class_diagram/
|
- class_d*/
|
||||||
- common
|
- common
|
||||||
- util
|
- util/*.h
|
||||||
|
- util/*.cc
|
||||||
- main.cc
|
- main.cc
|
||||||
exclude:
|
exclude:
|
||||||
paths:
|
paths:
|
||||||
|
|||||||
Reference in New Issue
Block a user