ZukeIndex.create constructor
ZukeIndex.create({
- required String root,
- required Iterable<
String> inputPaths, - required String generatedManifestContent,
- required String generatedManifestPath,
- required Iterable<
String> requirementIds, - required Iterable<
String> controlIds, - required Iterable<
String> bindingIds, - Iterable<
String> inputPatterns = const [], - Iterable<
String> patternInputPaths = const [], - Map<
String, String> ? inputContents,
Implementation
factory ZukeIndex.create({
required String root,
required Iterable<String> inputPaths,
required String generatedManifestContent,
required String generatedManifestPath,
required Iterable<String> requirementIds,
required Iterable<String> controlIds,
required Iterable<String> bindingIds,
Iterable<String> inputPatterns = const [],
Iterable<String> patternInputPaths = const [],
Map<String, String>? inputContents,
}) {
late final String rootPath;
try {
rootPath = Directory(root).resolveSymbolicLinksSync();
} catch (_) {
rootPath = Directory(root).absolute.path;
}
final inputs =
inputPaths
.map((path) {
try {
return File(path).resolveSymbolicLinksSync();
} catch (_) {
return File(path).absolute.path;
}
})
.where(
(path) =>
inputContents?.containsKey(path) == true ||
File(path).existsSync(),
)
.map((path) {
final cached = inputContents?[path];
final bytes = cached != null
? utf8.encode(cached)
: File(path).readAsBytesSync();
return ZukeIndexInput(
path: _relative(rootPath, path),
digest: _sha256(bytes),
);
})
.toList()
..sort((left, right) => left.path.compareTo(right.path));
final normalizedPatterns =
inputPatterns.map(_validatedPattern).toSet().toList()..sort();
final normalizedPatternInputs = patternInputPaths
.map((path) {
try {
return File(path).resolveSymbolicLinksSync();
} catch (_) {
return File(path).absolute.path;
}
})
.map((path) => _relative(rootPath, path))
.toSet();
final requirements = Set<String>.from(requirementIds)
..removeWhere((id) => id.isEmpty);
final controls = Set<String>.from(controlIds)
..removeWhere((id) => id.isEmpty);
final bindings = Set<String>.from(bindingIds)
..removeWhere((id) => id.isEmpty);
return ZukeIndex(
inputDigest: _inputDigest(
inputs,
requirements,
controls,
bindings,
normalizedPatterns,
normalizedPatternInputs,
),
generatedManifestDigest: _sha256(utf8.encode(generatedManifestContent)),
generatedManifestPath: _validatedRelativePath(generatedManifestPath),
inputs: List.unmodifiable(inputs),
inputPatterns: List.unmodifiable(normalizedPatterns),
patternInputs: Set.unmodifiable(normalizedPatternInputs),
requirementIds: Set.unmodifiable(requirements),
controlIds: Set.unmodifiable(controls),
bindingIds: Set.unmodifiable(bindings),
);
}