mirror of
https://github.com/flutter/packages.git
synced 2025-08-16 04:30:37 +08:00
[flutter_plugin_tools] Adds update-excerpts command (#5339)
This commit is contained in:
@ -3,7 +3,9 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:git/git.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:platform/platform.dart';
|
||||
|
||||
import 'common/core.dart';
|
||||
import 'common/plugin_command.dart';
|
||||
@ -105,7 +107,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
/// Validates that code files have copyright and license blocks.
|
||||
class LicenseCheckCommand extends PluginCommand {
|
||||
/// Creates a new license check command for [packagesDir].
|
||||
LicenseCheckCommand(Directory packagesDir) : super(packagesDir);
|
||||
LicenseCheckCommand(Directory packagesDir,
|
||||
{Platform platform = const LocalPlatform(), GitDir? gitDir})
|
||||
: super(packagesDir, platform: platform, gitDir: gitDir);
|
||||
|
||||
@override
|
||||
final String name = 'license-check';
|
||||
@ -116,7 +120,14 @@ class LicenseCheckCommand extends PluginCommand {
|
||||
|
||||
@override
|
||||
Future<void> run() async {
|
||||
final Iterable<File> allFiles = await _getAllFiles();
|
||||
// Create a set of absolute paths to submodule directories, with trailing
|
||||
// separator, to do prefix matching with to test directory inclusion.
|
||||
final Iterable<String> submodulePaths = (await _getSubmoduleDirectories())
|
||||
.map(
|
||||
(Directory dir) => '${dir.absolute.path}${platform.pathSeparator}');
|
||||
|
||||
final Iterable<File> allFiles = (await _getAllFiles()).where(
|
||||
(File file) => !submodulePaths.any(file.absolute.path.startsWith));
|
||||
|
||||
final Iterable<File> codeFiles = allFiles.where((File file) =>
|
||||
_codeFileExtensions.contains(p.extension(file.path)) &&
|
||||
@ -275,6 +286,24 @@ class LicenseCheckCommand extends PluginCommand {
|
||||
.where((FileSystemEntity entity) => entity is File)
|
||||
.map((FileSystemEntity file) => file as File)
|
||||
.toList();
|
||||
|
||||
// Returns the directories containing mapped submodules, if any.
|
||||
Future<Iterable<Directory>> _getSubmoduleDirectories() async {
|
||||
final List<Directory> submodulePaths = <Directory>[];
|
||||
final Directory repoRoot =
|
||||
packagesDir.fileSystem.directory((await gitDir).path);
|
||||
final File submoduleSpec = repoRoot.childFile('.gitmodules');
|
||||
if (submoduleSpec.existsSync()) {
|
||||
final RegExp pathLine = RegExp(r'path\s*=\s*(.*)');
|
||||
for (final String line in submoduleSpec.readAsLinesSync()) {
|
||||
final RegExpMatch? match = pathLine.firstMatch(line);
|
||||
if (match != null) {
|
||||
submodulePaths.add(repoRoot.childDirectory(match.group(1)!.trim()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return submodulePaths;
|
||||
}
|
||||
}
|
||||
|
||||
enum _LicenseFailureType { incorrectFirstParty, unknownThirdParty }
|
||||
|
Reference in New Issue
Block a user