packageDartFiles method
Gets a list of Dart files in a package directory from the lib and bin directories. Returns a list of absolute file paths, empty if none found or an exception is raised.
Implementation
List<String> packageDartFiles() {
var output = <String>[];
try {
// Lib
final libDir = Directory(path.join(_topLevelPath, SbomConstants.libDir));
// Lib directory must exist
final libFiles = libDir.listSync(recursive: true);
for (final entity in libFiles) {
if (entity is File) {
var file = entity.absolute;
if (path.extension(file.path) == SbomConstants.dartFiletype) {
output.add(file.path);
_dartFiles.add(entity);
}
}
}
// Bin
final binDir = Directory(path.join(_topLevelPath, SbomConstants.binDir));
// Bin directory may not exist
if (binDir.existsSync()) {
final binFiles = binDir.listSync(recursive: true);
for (final entity in binFiles) {
if (entity is File) {
var file = entity.absolute;
if (path.extension(file.path) == SbomConstants.dartFiletype) {
output.add(file.path);
_dartFiles.add(entity);
}
}
}
}
} catch (e) {
SbomUtilities.error(
'File Support - exception $e thrown getting package files, the SBOM generation will be incorrect');
}
// Sort the dart files
_dartFiles.sort((a, b) => a.path.compareTo(b.path));
return output;
}