|
|
|
|
@@ -320,42 +320,62 @@ String _generateLicense(String prefix) {
|
|
|
|
|
|
|
|
|
|
Future<void> verifyNoMissingLicense(String workingDirectory, { bool checkMinimums = true }) async {
|
|
|
|
|
final int? overrideMinimumMatches = checkMinimums ? null : 0;
|
|
|
|
|
await _verifyNoMissingLicenseForExtension(workingDirectory, 'dart', overrideMinimumMatches ?? 2000, _generateLicense('// '));
|
|
|
|
|
await _verifyNoMissingLicenseForExtension(workingDirectory, 'java', overrideMinimumMatches ?? 39, _generateLicense('// '));
|
|
|
|
|
await _verifyNoMissingLicenseForExtension(workingDirectory, 'h', overrideMinimumMatches ?? 30, _generateLicense('// '));
|
|
|
|
|
await _verifyNoMissingLicenseForExtension(workingDirectory, 'm', overrideMinimumMatches ?? 30, _generateLicense('// '));
|
|
|
|
|
await _verifyNoMissingLicenseForExtension(workingDirectory, 'swift', overrideMinimumMatches ?? 10, _generateLicense('// '));
|
|
|
|
|
await _verifyNoMissingLicenseForExtension(workingDirectory, 'gradle', overrideMinimumMatches ?? 80, _generateLicense('// '));
|
|
|
|
|
await _verifyNoMissingLicenseForExtension(workingDirectory, 'gn', overrideMinimumMatches ?? 0, _generateLicense('# '));
|
|
|
|
|
await _verifyNoMissingLicenseForExtension(workingDirectory, 'sh', overrideMinimumMatches ?? 1, '#!/usr/bin/env bash\n${_generateLicense('# ')}');
|
|
|
|
|
await _verifyNoMissingLicenseForExtension(workingDirectory, 'bat', overrideMinimumMatches ?? 1, '@ECHO off\n${_generateLicense('REM ')}');
|
|
|
|
|
await _verifyNoMissingLicenseForExtension(workingDirectory, 'ps1', overrideMinimumMatches ?? 1, _generateLicense('# '));
|
|
|
|
|
await _verifyNoMissingLicenseForExtension(workingDirectory, 'html', overrideMinimumMatches ?? 1, '<!DOCTYPE HTML>\n<!-- ${_generateLicense('')} -->', trailingBlank: false);
|
|
|
|
|
await _verifyNoMissingLicenseForExtension(workingDirectory, 'xml', overrideMinimumMatches ?? 1, '<!-- ${_generateLicense('')} -->');
|
|
|
|
|
int failed = 0;
|
|
|
|
|
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'dart', overrideMinimumMatches ?? 3000, _generateLicense('// '));
|
|
|
|
|
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'java', overrideMinimumMatches ?? 30, _generateLicense('// '));
|
|
|
|
|
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'h', overrideMinimumMatches ?? 60, _generateLicense('// '));
|
|
|
|
|
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'm', overrideMinimumMatches ?? 40, _generateLicense('// '));
|
|
|
|
|
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'swift', overrideMinimumMatches ?? 35, _generateLicense('// '));
|
|
|
|
|
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'gradle', overrideMinimumMatches ?? 100, _generateLicense('// '));
|
|
|
|
|
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'gn', overrideMinimumMatches ?? 0, _generateLicense('# '));
|
|
|
|
|
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'sh', overrideMinimumMatches ?? 1, _generateLicense('# '), header: r'#!/usr/bin/env bash\n',);
|
|
|
|
|
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'bat', overrideMinimumMatches ?? 1, _generateLicense('REM '), header: r'@ECHO off\n');
|
|
|
|
|
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'ps1', overrideMinimumMatches ?? 1, _generateLicense('# '));
|
|
|
|
|
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'html', overrideMinimumMatches ?? 1, '<!-- ${_generateLicense('')} -->', trailingBlank: false, header: r'<!DOCTYPE HTML>\n');
|
|
|
|
|
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'xml', overrideMinimumMatches ?? 1, '<!-- ${_generateLicense('')} -->', header: r'(<\?xml version="1.0" encoding="utf-8"\?>\n)?');
|
|
|
|
|
if (failed > 0) {
|
|
|
|
|
exitWithError(<String>['License check failed.']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _verifyNoMissingLicenseForExtension(String workingDirectory, String extension, int minimumMatches, String license, { bool trailingBlank = true }) async {
|
|
|
|
|
Future<int> _verifyNoMissingLicenseForExtension(
|
|
|
|
|
String workingDirectory,
|
|
|
|
|
String extension,
|
|
|
|
|
int minimumMatches,
|
|
|
|
|
String license, {
|
|
|
|
|
bool trailingBlank = true,
|
|
|
|
|
// The "header" is a regular expression matching the header that comes before
|
|
|
|
|
// the license in some files.
|
|
|
|
|
String header = '',
|
|
|
|
|
}) async {
|
|
|
|
|
assert(!license.endsWith('\n'));
|
|
|
|
|
final String licensePattern = '$license\n${trailingBlank ? '\n' : ''}';
|
|
|
|
|
final String licensePattern = RegExp.escape('$license\n${trailingBlank ? '\n' : ''}');
|
|
|
|
|
final List<String> errors = <String>[];
|
|
|
|
|
await for (final File file in _allFiles(workingDirectory, extension, minimumMatches: minimumMatches)) {
|
|
|
|
|
final String contents = file.readAsStringSync().replaceAll('\r\n', '\n');
|
|
|
|
|
if (contents.isEmpty)
|
|
|
|
|
continue; // let's not go down the /bin/true rabbit hole
|
|
|
|
|
if (!contents.startsWith(licensePattern))
|
|
|
|
|
if (!contents.startsWith(RegExp(header + licensePattern)))
|
|
|
|
|
errors.add(file.path);
|
|
|
|
|
}
|
|
|
|
|
// Fail if any errors
|
|
|
|
|
if (errors.isNotEmpty) {
|
|
|
|
|
final String s = errors.length == 1 ? ' does' : 's do';
|
|
|
|
|
exitWithError(<String>[
|
|
|
|
|
'${bold}The following ${errors.length} file$s not have the right license header:$reset',
|
|
|
|
|
...errors,
|
|
|
|
|
final String redLine = '$red━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$reset';
|
|
|
|
|
final String fileDoes = errors.length == 1 ? 'file does' : '${errors.length} files do';
|
|
|
|
|
print(<String>[
|
|
|
|
|
redLine,
|
|
|
|
|
'${bold}The following $fileDoes not have the right license header for $extension files:$reset',
|
|
|
|
|
...errors.map<String>((String error) => ' $error'),
|
|
|
|
|
'The expected license header is:',
|
|
|
|
|
if (header.isNotEmpty) 'A header matching the regular expression "$header",',
|
|
|
|
|
if (header.isNotEmpty) 'followed by the following license text:',
|
|
|
|
|
license,
|
|
|
|
|
if (trailingBlank) '...followed by a blank line.',
|
|
|
|
|
]);
|
|
|
|
|
redLine,
|
|
|
|
|
].join('\n'));
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _TestSkip {
|
|
|
|
|
|