From 9eb9ea0ffa2cee9e4ea75c60e8c3d2c88cae0b3d Mon Sep 17 00:00:00 2001
From: xster <xster@google.com>
Date: Mon, 13 Jan 2020 21:30:42 -0800
Subject: [PATCH] Let the tool warn about all old API plugins (#48282)

---
 packages/flutter_tools/lib/src/plugins.dart   |  1 -
 .../test/general.shard/plugins_test.dart      | 37 ++++++++++++++++---
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/packages/flutter_tools/lib/src/plugins.dart b/packages/flutter_tools/lib/src/plugins.dart
index cd7eb4361d..0fb8421606 100644
--- a/packages/flutter_tools/lib/src/plugins.dart
+++ b/packages/flutter_tools/lib/src/plugins.dart
@@ -497,7 +497,6 @@ Future<void> _writeAndroidPluginRegistrant(FlutterProject project, List<Plugin>
               'following https://flutter.dev/go/android-plugin-migration.'
             );
           }
-          break;
         }
       }
       templateContent = _androidPluginRegistryTemplateNewEmbedding;
diff --git a/packages/flutter_tools/test/general.shard/plugins_test.dart b/packages/flutter_tools/test/general.shard/plugins_test.dart
index 30b4401873..635d0e92fd 100644
--- a/packages/flutter_tools/test/general.shard/plugins_test.dart
+++ b/packages/flutter_tools/test/general.shard/plugins_test.dart
@@ -129,7 +129,7 @@ flutter:
         );
     }
 
-    void createOldJavaPlugin3() {
+    void createOldJavaPlugin(String pluginName) {
       final Directory pluginUsingOldEmbeddingDir =
         fs.systemTempDirectory.createTempSync('flutter_plugin_using_old_embedding_dir.');
       pluginUsingOldEmbeddingDir
@@ -137,7 +137,7 @@ flutter:
         .writeAsStringSync('''
 flutter:
   plugin:
-    androidPackage: plugin3
+    androidPackage: $pluginName
     pluginClass: UseOldEmbedding
         ''');
       pluginUsingOldEmbeddingDir
@@ -145,14 +145,14 @@ flutter:
         .childDirectory('src')
         .childDirectory('main')
         .childDirectory('java')
-        .childDirectory('plugin3')
+        .childDirectory(pluginName)
         .childFile('UseOldEmbedding.java')
         ..createSync(recursive: true);
 
       flutterProject.directory
         .childFile('.packages')
         .writeAsStringSync(
-          'plugin3:${pluginUsingOldEmbeddingDir.childDirectory('lib').uri.toString()}\n',
+          '$pluginName:${pluginUsingOldEmbeddingDir.childDirectory('lib').uri.toString()}\n',
           mode: FileMode.append,
         );
     }
@@ -379,7 +379,7 @@ dependencies:
 
         createNewJavaPlugin1();
         createNewKotlinPlugin2();
-        createOldJavaPlugin3();
+        createOldJavaPlugin('plugin3');
 
         await injectPlugins(flutterProject);
 
@@ -497,7 +497,7 @@ dependencies:
         when(flutterProject.isModule).thenReturn(true);
         when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
 
-        createOldJavaPlugin3();
+        createOldJavaPlugin('plugin3');
 
         await injectPlugins(flutterProject);
 
@@ -558,6 +558,31 @@ dependencies:
         XcodeProjectInterpreter: () => xcodeProjectInterpreter,
       });
 
+      testUsingContext('Module using multiple old plugins all show warnings', () async {
+        when(flutterProject.isModule).thenReturn(true);
+        when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
+
+        createOldJavaPlugin('plugin3');
+        createOldJavaPlugin('plugin4');
+
+        await injectPlugins(flutterProject);
+
+        final File registrant = flutterProject.directory
+          .childDirectory(fs.path.join('android', 'app', 'src', 'main', 'java', 'io', 'flutter', 'plugins'))
+          .childFile('GeneratedPluginRegistrant.java');
+        expect(registrant.readAsStringSync(),
+          contains('plugin3.UseOldEmbedding.registerWith(shimPluginRegistry.registrarFor("plugin3.UseOldEmbedding"));'));
+        expect(registrant.readAsStringSync(),
+          contains('plugin4.UseOldEmbedding.registerWith(shimPluginRegistry.registrarFor("plugin4.UseOldEmbedding"));'));
+        expect(testLogger.statusText, contains('The plugin `plugin3` is built using an older version of the Android plugin API'));
+        expect(testLogger.statusText, contains('The plugin `plugin4` is built using an older version of the Android plugin API'));
+      }, overrides: <Type, Generator>{
+        FileSystem: () => fs,
+        ProcessManager: () => FakeProcessManager.any(),
+        FeatureFlags: () => featureFlags,
+        XcodeProjectInterpreter: () => xcodeProjectInterpreter,
+      });
+
       testUsingContext('Does not throw when AndroidManifest.xml is not found', () async {
         when(flutterProject.isModule).thenReturn(false);
 
-- 
2.21.0