checkAllPackageLicenses<D> function
Future<List<LicenseDisplayWithPriority<D> > >
checkAllPackageLicenses<D>({
- required bool showDirectDepsOnly,
- required bool filterApproved,
- required LicenseDisplayFunction<
D> licenseDisplay, - required PackageChecker packageConfig,
- bool sortByPriority = false,
- bool sortByName = false,
Checks all licenses in a the package.
Returns a list of LicenseDisplayWithPriority that contains all the parsed
licenses. If filterApproved
is true, then this list will not contain approved
package.
Throws a FileSystemException if the necessary files are not found.
Implementation
Future<List<LicenseDisplayWithPriority<D>>> checkAllPackageLicenses<D>({
required bool showDirectDepsOnly,
required bool filterApproved,
required LicenseDisplayFunction<D> licenseDisplay,
required PackageChecker packageConfig,
bool sortByPriority = false,
bool sortByName = false,
}) async {
List<LicenseDisplayWithPriority<D>> licenses = [];
for (DependencyChecker package in packageConfig.packages) {
if (showDirectDepsOnly) {
// Ignore dependencies not defined in the packages pubspec.yaml
if (!packageConfig.pubspec.dependencies.containsKey(package.name)) {
continue;
}
}
LicenseStatus status = await package.packageLicenseStatus;
if (!filterApproved ||
(filterApproved &&
status != LicenseStatus.approved &&
status != LicenseStatus.permitted)) {
licenses.add(
LicenseDisplayWithPriority.withStatusPriority(
display: await checkPackageLicense(
package: package,
licenseDisplay: licenseDisplay,
),
licenseStatus: status,
packageName: package.name,
),
);
}
}
if (sortByPriority && sortByName) {
// sort by priority first
licenses.sort((a, b) {
int cmp = _prioritySort(a, b);
if (cmp != 0) {
return cmp;
}
return _alphaSort(a, b);
});
} else {
if (sortByPriority) {
// Sort by priority
licenses.sort(_prioritySort);
}
if (sortByName) {
// Sort by name
licenses.sort(_alphaSort);
}
}
return licenses;
}