1#ifndef SOURCEMETA_BLAZE_CONFIGURATION_H_
2#define SOURCEMETA_BLAZE_CONFIGURATION_H_
13#ifndef SOURCEMETA_BLAZE_CONFIGURATION_EXPORT
14#include <sourcemeta/blaze/configuration_export.h>
18#include <sourcemeta/blaze/configuration_error.h>
21#include <sourcemeta/core/json.h>
22#include <sourcemeta/core/jsonschema.h>
23#include <sourcemeta/core/uri.h>
34#include <unordered_map>
36#include <unordered_set>
39namespace sourcemeta::blaze {
45#pragma warning(disable : 4251 4275)
51 std::optional<sourcemeta::core::JSON::String> title;
52 std::optional<sourcemeta::core::JSON::String> description;
53 std::optional<sourcemeta::core::JSON::String> email;
54 std::optional<sourcemeta::core::JSON::String> github;
55 std::optional<sourcemeta::core::JSON::String> website;
56 std::filesystem::path absolute_path;
57 bool absolute_path_explicit{
false};
58 std::filesystem::path base_path;
59 sourcemeta::core::JSON::String base;
60 sourcemeta::core::URI base_uri;
61 std::optional<sourcemeta::core::JSON::String> default_dialect;
62 std::unordered_set<sourcemeta::core::JSON::String> extension{
".json",
".yml",
64 std::unordered_map<sourcemeta::core::JSON::String,
65 sourcemeta::core::JSON::String>
68 std::map<sourcemeta::core::JSON::String, std::filesystem::path> dependencies;
69 std::vector<std::filesystem::path> ignore;
73 std::filesystem::path path;
74 bool top_level{
false};
77 std::vector<Rule> rules;
78 std::unordered_set<sourcemeta::core::JSON::String> exclude;
82 sourcemeta::core::JSON extra = sourcemeta::core::JSON::make_object();
87 std::function<std::string(
const std::filesystem::path &)>;
90 class SOURCEMETA_BLAZE_CONFIGURATION_EXPORT
Lock {
93 std::filesystem::path path;
95 sourcemeta::core::JSON::String hash;
96 enum class HashAlgorithm : std::uint8_t { SHA256 };
97 HashAlgorithm hash_algorithm;
98 enum class Status : std::uint8_t {
107 using const_iterator =
108 std::map<sourcemeta::core::JSON::String, Entry>::const_iterator;
111 emplace(
const sourcemeta::core::JSON::String &uri,
112 const std::filesystem::path &path,
113 const sourcemeta::core::JSON::String &hash,
114 Entry::HashAlgorithm hash_algorithm = Entry::HashAlgorithm::SHA256)
116 auto erase(
const sourcemeta::core::JSON::String &uri) -> void;
118 [[nodiscard]]
auto size() const noexcept -> std::
size_t;
119 [[nodiscard]] auto at(const sourcemeta::core::JSON::String &uri) const
120 -> std::optional<std::reference_wrapper<const
Entry>>;
121 [[nodiscard]] auto begin() const noexcept -> const_iterator;
122 [[nodiscard]] auto end() const noexcept -> const_iterator;
125 auto check(const sourcemeta::core::JSON::String &uri,
126 const std::filesystem::path &expected_path,
129 static auto from_json(const sourcemeta::core::JSON &value,
130 const std::filesystem::path &lock_base_path) ->
Lock;
132 auto to_json(const std::filesystem::path &lock_base_path) const
133 -> sourcemeta::core::JSON;
137 std::map<sourcemeta::core::JSON::String,
Entry> entries_;
142 enum class Type : std::uint8_t {
162 std::filesystem::path path;
166 std::exception_ptr exception;
168 using Callback = std::function<bool(
const FetchEvent &)>;
173 std::function<sourcemeta::core::JSON(std::string_view uri)>;
177 const sourcemeta::core::JSON &)>;
189 const sourcemeta::core::SchemaResolver &resolver,
191 const FetchEvent::Callback &on_event,
FetchMode mode,
193 std::size_t concurrency = 1) const ->
void;
197 const sourcemeta::core::SchemaResolver &resolver,
201 std::
size_t concurrency = 1) const ->
void;
205 const std::filesystem::path &path) ->
void;
210 auto
applies_to(const std::filesystem::path &path) const ->
bool;
214 static auto
from_json(const sourcemeta::core::JSON &value,
215 const std::filesystem::path &base_path)
220 auto
to_json() const -> sourcemeta::core::JSON;
224 static auto
read_json(const std::filesystem::path &path,
229 static auto
find(const std::filesystem::path &path)
230 -> std::optional<std::filesystem::path>;
234#pragma warning(default : 4251 4275)
static auto find(const std::filesystem::path &path) -> std::optional< std::filesystem::path >
A nearest ancestor configuration lookup.
static auto read_json(const std::filesystem::path &path, const ReadCallback &reader) -> Configuration
Read and parse a configuration file.
std::function< void(const std::filesystem::path &, const sourcemeta::core::JSON &)> WriteCallback
A callback to write a JSON Schema to a path.
Definition configuration.h:176
std::function< std::string(const std::filesystem::path &)> ReadCallback
A callback to read file contents from a path.
Definition configuration.h:85
auto to_json() const -> sourcemeta::core::JSON
Serialize a configuration to JSON.
auto applies_to(const std::filesystem::path &path) const -> bool
FetchMode
The mode for fetching dependencies with a mutable lock.
Definition configuration.h:180
auto fetch(Lock &lock, const FetchCallback &fetcher, const sourcemeta::core::SchemaResolver &resolver, const ReadCallback &reader, const WriteCallback &writer, const FetchEvent::Callback &on_event, FetchMode mode, std::size_t concurrency=1) const -> void
Fetch dependencies, modifying the lock in-place.
static auto from_json(const sourcemeta::core::JSON &value, const std::filesystem::path &base_path) -> Configuration
Parse a configuration file from its contents.
auto add_dependency(const sourcemeta::core::URI &uri, const std::filesystem::path &path) -> void
Add a dependency to the configuration.
std::function< sourcemeta::core::JSON(std::string_view uri)> FetchCallback
A callback to fetch a JSON Schema from a URI.
Definition configuration.h:172
std::function< void( const EvaluationType, bool, const Instruction &, const InstructionExtra &, const sourcemeta::core::WeakPointer &, const sourcemeta::core::WeakPointer &, const sourcemeta::core::JSON &)> Callback
Definition evaluator.h:77
Definition configuration.h:92