mirror of
https://github.com/flutter/flutter
synced 2024-08-27 03:50:33 +00:00
Verify that committed GeneratedPluginRegistrant are up-to-date (#13541)
This commit is contained in:
parent
998bf194a3
commit
e5846d962e
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -41,7 +41,6 @@ unlinked.ds
|
|||
unlinked_spec.ds
|
||||
|
||||
# Android related
|
||||
**/android/**/GeneratedPluginRegistrant.java
|
||||
**/android/**/gradle-wrapper.jar
|
||||
**/android/.gradle
|
||||
**/android/captures/
|
||||
|
@ -60,8 +59,6 @@ unlinked_spec.ds
|
|||
**/ios/**/.tags*
|
||||
**/ios/**/.vagrant/
|
||||
**/ios/**/DerivedData/
|
||||
**/ios/**/GeneratedPluginRegistrant.h
|
||||
**/ios/**/GeneratedPluginRegistrant.m
|
||||
**/ios/**/Icon?
|
||||
**/ios/**/Pods/
|
||||
**/ios/**/profile
|
||||
|
|
|
@ -87,6 +87,7 @@ Future<Null> _verifyInternationalizations() async {
|
|||
}
|
||||
|
||||
Future<Null> _analyzeRepo() async {
|
||||
await _verifyGeneratedPluginRegistrants(flutterRoot);
|
||||
await _verifyNoBadImports(flutterRoot);
|
||||
await _verifyInternationalizations();
|
||||
|
||||
|
@ -477,3 +478,63 @@ void _printProgress(String action, String workingDir, String command) {
|
|||
const String arrow = '⏩';
|
||||
print('$arrow $action: cd $cyan$workingDir$reset; $yellow$command$reset');
|
||||
}
|
||||
|
||||
Future<Null> _verifyGeneratedPluginRegistrants(String flutterRoot) async {
|
||||
final Directory flutterRootDir = new Directory(flutterRoot);
|
||||
|
||||
final Map<String, List<File>> packageToRegistrants = <String, List<File>>{};
|
||||
|
||||
for (FileSystemEntity entity in flutterRootDir.listSync(recursive: true)) {
|
||||
if (entity is! File)
|
||||
continue;
|
||||
if (_isGeneratedPluginRegistrant(entity)) {
|
||||
final String package = _getPackageFor(entity, flutterRootDir);
|
||||
final List<File> registrants = packageToRegistrants.putIfAbsent(package, () => <File>[]);
|
||||
registrants.add(entity);
|
||||
}
|
||||
}
|
||||
|
||||
final Set<String> outOfDate = new Set<String>();
|
||||
|
||||
for (String package in packageToRegistrants.keys) {
|
||||
final Map<File, String> fileToContent = new Map<File, String>.fromIterable(packageToRegistrants[package],
|
||||
key: (File f) => f,
|
||||
value: (File f) => f.readAsStringSync(),
|
||||
);
|
||||
await _runCommand(flutter, <String>['inject-plugins'],
|
||||
workingDirectory: package,
|
||||
printOutput: false,
|
||||
);
|
||||
for (File registrant in fileToContent.keys) {
|
||||
if (registrant.readAsStringSync() != fileToContent[registrant]) {
|
||||
outOfDate.add(registrant.path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (outOfDate.isNotEmpty) {
|
||||
print('$red━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$reset');
|
||||
print('${bold}The following GeneratedPluginRegistrants are out of date:$reset');
|
||||
for (String registrant in outOfDate) {
|
||||
print(' - $registrant');
|
||||
}
|
||||
print('$red━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$reset');
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
String _getPackageFor(File entity, Directory flutterRootDir) {
|
||||
for (Directory dir = entity.parent; dir != flutterRootDir; dir = dir.parent) {
|
||||
if (new File(path.join(dir.path, 'pubspec.yaml')).existsSync()) {
|
||||
return dir.path;
|
||||
}
|
||||
}
|
||||
throw new ArgumentError('$entity is not within a dart package.');
|
||||
}
|
||||
|
||||
bool _isGeneratedPluginRegistrant(File file) {
|
||||
final String filename = path.basename(file.path);
|
||||
return filename == 'GeneratedPluginRegistrant.java' ||
|
||||
filename == 'GeneratedPluginRegistrant.h' ||
|
||||
filename == 'GeneratedPluginRegistrant.m';
|
||||
}
|
||||
|
|
|
@ -7,5 +7,17 @@ import io.flutter.plugin.common.PluginRegistry;
|
|||
*/
|
||||
public final class GeneratedPluginRegistrant {
|
||||
public static void registerWith(PluginRegistry registry) {
|
||||
if (alreadyRegisteredWith(registry)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean alreadyRegisteredWith(PluginRegistry registry) {
|
||||
final String key = GeneratedPluginRegistrant.class.getCanonicalName();
|
||||
if (registry.hasPlugin(key)) {
|
||||
return true;
|
||||
}
|
||||
registry.registrarFor(key);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,5 +7,17 @@ import io.flutter.plugin.common.PluginRegistry;
|
|||
*/
|
||||
public final class GeneratedPluginRegistrant {
|
||||
public static void registerWith(PluginRegistry registry) {
|
||||
if (alreadyRegisteredWith(registry)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean alreadyRegisteredWith(PluginRegistry registry) {
|
||||
final String key = GeneratedPluginRegistrant.class.getCanonicalName();
|
||||
if (registry.hasPlugin(key)) {
|
||||
return true;
|
||||
}
|
||||
registry.registrarFor(key);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,5 +7,17 @@ import io.flutter.plugin.common.PluginRegistry;
|
|||
*/
|
||||
public final class GeneratedPluginRegistrant {
|
||||
public static void registerWith(PluginRegistry registry) {
|
||||
if (alreadyRegisteredWith(registry)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean alreadyRegisteredWith(PluginRegistry registry) {
|
||||
final String key = GeneratedPluginRegistrant.class.getCanonicalName();
|
||||
if (registry.hasPlugin(key)) {
|
||||
return true;
|
||||
}
|
||||
registry.registrarFor(key);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,9 +11,21 @@ import io.flutter.videoplayer.VideoPlayerPlugin;
|
|||
*/
|
||||
public final class GeneratedPluginRegistrant {
|
||||
public static void registerWith(PluginRegistry registry) {
|
||||
if (alreadyRegisteredWith(registry)) {
|
||||
return;
|
||||
}
|
||||
ConnectivityPlugin.registerWith(registry.registrarFor("io.flutter.plugins.connectivity.ConnectivityPlugin"));
|
||||
DeviceInfoPlugin.registerWith(registry.registrarFor("io.flutter.plugins.deviceinfo.DeviceInfoPlugin"));
|
||||
UrlLauncherPlugin.registerWith(registry.registrarFor("io.flutter.plugins.urllauncher.UrlLauncherPlugin"));
|
||||
VideoPlayerPlugin.registerWith(registry.registrarFor("io.flutter.videoplayer.VideoPlayerPlugin"));
|
||||
}
|
||||
|
||||
private static boolean alreadyRegisteredWith(PluginRegistry registry) {
|
||||
final String key = GeneratedPluginRegistrant.class.getCanonicalName();
|
||||
if (registry.hasPlugin(key)) {
|
||||
return true;
|
||||
}
|
||||
registry.registrarFor(key);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,5 +7,17 @@ import io.flutter.plugin.common.PluginRegistry;
|
|||
*/
|
||||
public final class GeneratedPluginRegistrant {
|
||||
public static void registerWith(PluginRegistry registry) {
|
||||
if (alreadyRegisteredWith(registry)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean alreadyRegisteredWith(PluginRegistry registry) {
|
||||
final String key = GeneratedPluginRegistrant.class.getCanonicalName();
|
||||
if (registry.hasPlugin(key)) {
|
||||
return true;
|
||||
}
|
||||
registry.registrarFor(key);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,5 +7,17 @@ import io.flutter.plugin.common.PluginRegistry;
|
|||
*/
|
||||
public final class GeneratedPluginRegistrant {
|
||||
public static void registerWith(PluginRegistry registry) {
|
||||
if (alreadyRegisteredWith(registry)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean alreadyRegisteredWith(PluginRegistry registry) {
|
||||
final String key = GeneratedPluginRegistrant.class.getCanonicalName();
|
||||
if (registry.hasPlugin(key)) {
|
||||
return true;
|
||||
}
|
||||
registry.registrarFor(key);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,5 +7,17 @@ import io.flutter.plugin.common.PluginRegistry;
|
|||
*/
|
||||
public final class GeneratedPluginRegistrant {
|
||||
public static void registerWith(PluginRegistry registry) {
|
||||
if (alreadyRegisteredWith(registry)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean alreadyRegisteredWith(PluginRegistry registry) {
|
||||
final String key = GeneratedPluginRegistrant.class.getCanonicalName();
|
||||
if (registry.hasPlugin(key)) {
|
||||
return true;
|
||||
}
|
||||
registry.registrarFor(key);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package io.flutter.plugins;
|
||||
|
||||
import io.flutter.plugin.common.PluginRegistry;
|
||||
|
||||
/**
|
||||
* Generated file. Do not edit.
|
||||
*/
|
||||
public final class GeneratedPluginRegistrant {
|
||||
public static void registerWith(PluginRegistry registry) {
|
||||
if (alreadyRegisteredWith(registry)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean alreadyRegisteredWith(PluginRegistry registry) {
|
||||
final String key = GeneratedPluginRegistrant.class.getCanonicalName();
|
||||
if (registry.hasPlugin(key)) {
|
||||
return true;
|
||||
}
|
||||
registry.registrarFor(key);
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -7,5 +7,17 @@ import io.flutter.plugin.common.PluginRegistry;
|
|||
*/
|
||||
public final class GeneratedPluginRegistrant {
|
||||
public static void registerWith(PluginRegistry registry) {
|
||||
if (alreadyRegisteredWith(registry)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean alreadyRegisteredWith(PluginRegistry registry) {
|
||||
final String key = GeneratedPluginRegistrant.class.getCanonicalName();
|
||||
if (registry.hasPlugin(key)) {
|
||||
return true;
|
||||
}
|
||||
registry.registrarFor(key);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import 'src/commands/drive.dart';
|
|||
import 'src/commands/format.dart';
|
||||
import 'src/commands/fuchsia_reload.dart';
|
||||
import 'src/commands/ide_config.dart';
|
||||
import 'src/commands/inject_plugins.dart';
|
||||
import 'src/commands/install.dart';
|
||||
import 'src/commands/logs.dart';
|
||||
import 'src/commands/packages.dart';
|
||||
|
@ -45,6 +46,7 @@ Future<Null> main(List<String> args) async {
|
|||
new BuildCommand(verboseHelp: verboseHelp),
|
||||
new ChannelCommand(),
|
||||
new CleanCommand(),
|
||||
new InjectPluginsCommand(hidden: !verboseHelp),
|
||||
new ConfigCommand(verboseHelp: verboseHelp),
|
||||
new CreateCommand(),
|
||||
new DaemonCommand(hidden: !verboseHelp),
|
||||
|
|
34
packages/flutter_tools/lib/src/commands/inject_plugins.dart
Normal file
34
packages/flutter_tools/lib/src/commands/inject_plugins.dart
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import '../globals.dart';
|
||||
import '../plugins.dart';
|
||||
import '../runner/flutter_command.dart';
|
||||
|
||||
class InjectPluginsCommand extends FlutterCommand {
|
||||
InjectPluginsCommand({ this.hidden: false }) {
|
||||
requiresPubspecYaml();
|
||||
}
|
||||
|
||||
@override
|
||||
final String name = 'inject-plugins';
|
||||
|
||||
@override
|
||||
final String description = 'Re-generates the GeneratedPluginRegistrants.';
|
||||
|
||||
@override
|
||||
final bool hidden;
|
||||
|
||||
@override
|
||||
Future<Null> runCommand() async {
|
||||
final bool result = injectPlugins();
|
||||
if (result) {
|
||||
printStatus('GeneratedPluginRegistrants successfully written.');
|
||||
} else {
|
||||
printStatus('This project does not use plugins, no GeneratedPluginRegistrants have been created.');
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue