Rename 'application' back to 'module', and make 'app' the default again for templates. (#22888)

We decided that redefining the default for templates was premature. We're going to go back to having "module" in experimental land again, and we'll try again when we have the feature set fully baked.

This keeps the writing of the .metadata files, and writing the template type to them, because that was a good improvement, and there are still a bunch of added tests that improve our coverage.
diff --git a/packages/flutter_tools/test/commands/create_test.dart b/packages/flutter_tools/test/commands/create_test.dart
index 912e265..485a3e9 100644
--- a/packages/flutter_tools/test/commands/create_test.dart
+++ b/packages/flutter_tools/test/commands/create_test.dart
@@ -43,46 +43,12 @@
     tryToDelete(tempDir);
   });
 
-  // Verify that we create a default project ('application') that is
+  // Verify that we create a default project ('app') that is
   // well-formed.
   testUsingContext('can create a default project', () async {
-    await _createAndAnalyzeProject(projectDir, <String>[], <String>[
-      '.android/app/',
-      '.gitignore',
-      '.ios/Flutter',
-      '.metadata',
-      'lib/main.dart',
-      'pubspec.yaml',
-      'README.md',
-      'test/widget_test.dart',
-    ], unexpectedPaths: <String>[
-      'android/',
-      'ios/',
-    ]);
-    return _runFlutterTest(projectDir);
-  }, timeout: allowForRemotePubInvocation);
-
-  testUsingContext('can create a default project if empty directory exists', () async {
-    await projectDir.create(recursive: true);
-    return _createAndAnalyzeProject(projectDir, <String>[], <String>[
-      '.android/app/',
-      '.gitignore',
-      '.ios/Flutter',
-      '.metadata',
-      'lib/main.dart',
-      'pubspec.yaml',
-      'README.md',
-      'test/widget_test.dart',
-    ], unexpectedPaths: <String>[
-      'android/',
-      'ios/',
-    ]);
-  }, timeout: allowForRemotePubInvocation);
-
-  testUsingContext('creates a legacy app project correctly', () async {
     await _createAndAnalyzeProject(
       projectDir,
-      <String>['--template=app'],
+      <String>[],
       <String>[
         'android/app/src/main/java/com/example/flutterproject/MainActivity.java',
         'android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java',
@@ -95,22 +61,26 @@
     return _runFlutterTest(projectDir);
   }, timeout: allowForRemotePubInvocation);
 
-  testUsingContext('cannot create a project if non-empty non-project directory exists with .metadata', () async {
-    await projectDir.absolute.childDirectory('blag').create(recursive: true);
-    await projectDir.absolute.childFile('.metadata').writeAsString('project_type: blag\n');
-    expect(() async => await _createAndAnalyzeProject(projectDir, <String>[], <String>[
-    ], unexpectedPaths: <String>[
-      'android/',
-      'ios/',
-      '.android/',
-      '.ios/',
-    ]), throwsToolExit(message: 'Sorry, unable to detect the type of project to recreate'));
+  testUsingContext('can create a default project if empty directory exists', () async {
+    await projectDir.create(recursive: true);
+    await _createAndAnalyzeProject(
+      projectDir,
+      <String>[],
+      <String>[
+        'android/app/src/main/java/com/example/flutterproject/MainActivity.java',
+        'android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java',
+        'flutter_project.iml',
+        'ios/Flutter/AppFrameworkInfo.plist',
+        'ios/Runner/AppDelegate.m',
+        'ios/Runner/GeneratedPluginRegistrant.h',
+      ],
+    );
   }, timeout: allowForRemotePubInvocation);
 
-  testUsingContext('Will create an application project if non-empty non-project directory exists without .metadata', () async {
-    await projectDir.absolute.childDirectory('blag').create(recursive: true);
-    await projectDir.absolute.childDirectory('.idea').create(recursive: true);
-    return _createAndAnalyzeProject(projectDir, <String>[], <String>[
+  testUsingContext('creates a module project correctly', () async {
+    await _createAndAnalyzeProject(projectDir, <String>[
+      '--template=module'
+    ], <String>[
       '.android/app/',
       '.gitignore',
       '.ios/Flutter',
@@ -123,23 +93,51 @@
       'android/',
       'ios/',
     ]);
+    return _runFlutterTest(projectDir);
   }, timeout: allowForRemotePubInvocation);
 
-  testUsingContext('detects and recreates an application project correctly', () async {
-    await projectDir.absolute.childDirectory('lib').create(recursive: true);
-    await projectDir.absolute.childDirectory('.ios').create(recursive: true);
-    return _createAndAnalyzeProject(projectDir, <String>[], <String>[
-      '.android/app/',
-      '.gitignore',
-      '.ios/Flutter',
-      '.metadata',
-      'lib/main.dart',
-      'pubspec.yaml',
-      'README.md',
-      'test/widget_test.dart',
+  testUsingContext('cannot create a project if non-empty non-project directory exists with .metadata', () async {
+    await projectDir.absolute.childDirectory('blag').create(recursive: true);
+    await projectDir.absolute.childFile('.metadata').writeAsString('project_type: blag\n');
+    expect(
+        () async => await _createAndAnalyzeProject(projectDir, <String>[], <String>[], unexpectedPaths: <String>[
+              'android/',
+              'ios/',
+              '.android/',
+              '.ios/',
+            ]),
+        throwsToolExit(message: 'Sorry, unable to detect the type of project to recreate'));
+  }, timeout: allowForRemotePubInvocation);
+
+  testUsingContext('Will create an app project if non-empty non-project directory exists without .metadata', () async {
+    await projectDir.absolute.childDirectory('blag').create(recursive: true);
+    await projectDir.absolute.childDirectory('.idea').create(recursive: true);
+    await _createAndAnalyzeProject(projectDir, <String>[], <String>[
+      'android/app/src/main/java/com/example/flutterproject/MainActivity.java',
+      'android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java',
+      'flutter_project.iml',
+      'ios/Flutter/AppFrameworkInfo.plist',
+      'ios/Runner/AppDelegate.m',
+      'ios/Runner/GeneratedPluginRegistrant.h',
     ], unexpectedPaths: <String>[
-      'android/',
-      'ios/',
+      '.android/',
+      '.ios/',
+    ]);
+  }, timeout: allowForRemotePubInvocation);
+
+  testUsingContext('detects and recreates an app project correctly', () async {
+    await projectDir.absolute.childDirectory('lib').create(recursive: true);
+    await projectDir.absolute.childDirectory('ios').create(recursive: true);
+    await _createAndAnalyzeProject(projectDir, <String>[], <String>[
+      'android/app/src/main/java/com/example/flutterproject/MainActivity.java',
+      'android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java',
+      'flutter_project.iml',
+      'ios/Flutter/AppFrameworkInfo.plist',
+      'ios/Runner/AppDelegate.m',
+      'ios/Runner/GeneratedPluginRegistrant.h',
+    ], unexpectedPaths: <String>[
+      '.android/',
+      '.ios/',
     ]);
   }, timeout: allowForRemotePubInvocation);
 
@@ -193,41 +191,6 @@
     );
   }, timeout: allowForRemotePubInvocation);
 
-  testUsingContext('detects and recreates a legacy app project correctly', () async {
-    await projectDir.absolute.childDirectory('lib').create(recursive: true);
-    await projectDir.absolute.childDirectory('ios').childDirectory('Flutter').create(recursive: true);
-    return _createAndAnalyzeProject(
-      projectDir,
-      <String>[],
-      <String>[
-        'android/app/src/main/java/com/example/flutterproject/MainActivity.java',
-        'android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java',
-        'flutter_project.iml',
-        'ios/Flutter/AppFrameworkInfo.plist',
-        'ios/Runner/AppDelegate.m',
-        'ios/Runner/GeneratedPluginRegistrant.h',
-      ],
-    );
-  }, timeout: allowForRemotePubInvocation);
-
-  testUsingContext('can create a legacy module project', () async {
-    return _createAndAnalyzeProject(projectDir, <String>[
-      '--template=module',
-    ], <String>[
-      '.android/app/',
-      '.gitignore',
-      '.ios/Flutter',
-      '.metadata',
-      'lib/main.dart',
-      'pubspec.yaml',
-      'README.md',
-      'test/widget_test.dart',
-    ], unexpectedPaths: <String>[
-      'android/',
-      'ios/',
-    ]);
-  }, timeout: allowForRemotePubInvocation);
-
   testUsingContext('kotlin/swift legacy app project', () async {
     return _createProject(
       projectDir,
@@ -343,9 +306,9 @@
     );
   }, timeout: allowForRemotePubInvocation);
 
-  testUsingContext('application project with pub', () async {
+  testUsingContext('module project with pub', () async {
     return _createProject(projectDir, <String>[
-      '--template=application'
+      '--template=module'
     ], <String>[
       '.android/build.gradle',
       '.android/Flutter/build.gradle',
@@ -375,7 +338,7 @@
     ]);
   }, timeout: allowForRemotePubInvocation);
 
-  testUsingContext('has correct content and formatting with applicaiton template', () async {
+  testUsingContext('has correct content and formatting with module template', () async {
     Cache.flutterRoot = '../..';
     when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
     when(mockFlutterVersion.channel).thenReturn(frameworkChannel);
@@ -383,7 +346,7 @@
     final CreateCommand command = CreateCommand();
     final CommandRunner<void> runner = createTestCommandRunner(command);
 
-    await runner.run(<String>['create', '--template=application', '--no-pub', '--org', 'com.foo.bar', projectDir.path]);
+    await runner.run(<String>['create', '--template=module', '--no-pub', '--org', 'com.foo.bar', projectDir.path]);
 
     void expectExists(String relPath) {
       expect(fs.isFileSync('${projectDir.path}/$relPath'), true);
@@ -446,7 +409,7 @@
     FlutterVersion: () => mockFlutterVersion,
   }, timeout: allowForCreateFlutterProject);
 
-  testUsingContext('has correct content and formatting with legacy app template', () async {
+  testUsingContext('has correct content and formatting with app template', () async {
     Cache.flutterRoot = '../..';
     when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
     when(mockFlutterVersion.channel).thenReturn(frameworkChannel);
@@ -526,9 +489,12 @@
     await runner.run(<String>['create', '--no-pub', projectDir.path]);
 
     await runner.run(<String>['create', '--no-pub', projectDir.path]);
+
+    final String metadata = fs.file(fs.path.join(projectDir.path, '.metadata')).readAsStringSync();
+    expect(metadata, contains('project_type: app\n'));
   }, timeout: allowForCreateFlutterProject);
 
-  testUsingContext('can re-gen default template over existing legacy app project with no metadta and detect the type', () async {
+  testUsingContext('can re-gen default template over existing app project with no metadta and detect the type', () async {
     Cache.flutterRoot = '../..';
 
     final CreateCommand command = CreateCommand();
@@ -545,7 +511,7 @@
     expect(metadata, contains('project_type: app\n'));
   }, timeout: allowForCreateFlutterProject);
 
-  testUsingContext('can re-gen default template over existing legacy app project and detect the type', () async {
+  testUsingContext('can re-gen app template over existing app project and detect the type', () async {
     Cache.flutterRoot = '../..';
 
     final CreateCommand command = CreateCommand();
@@ -559,6 +525,20 @@
     expect(metadata, contains('project_type: app\n'));
   }, timeout: allowForCreateFlutterProject);
 
+  testUsingContext('can re-gen template over existing module project and detect the type', () async {
+    Cache.flutterRoot = '../..';
+
+    final CreateCommand command = CreateCommand();
+    final CommandRunner<void> runner = createTestCommandRunner(command);
+
+    await runner.run(<String>['create', '--no-pub', '--template=module', projectDir.path]);
+
+    await runner.run(<String>['create', '--no-pub', projectDir.path]);
+
+    final String metadata = fs.file(fs.path.join(projectDir.path, '.metadata')).readAsStringSync();
+    expect(metadata, contains('project_type: module\n'));
+  }, timeout: allowForCreateFlutterProject);
+
   testUsingContext('can re-gen default template over existing plugin project and detect the type', () async {
     Cache.flutterRoot = '../..';
 
@@ -587,10 +567,10 @@
     expect(metadata, contains('project_type: package'));
   }, timeout: allowForCreateFlutterProject);
 
-  testUsingContext('can re-gen application .android/ folder, reusing custom org', () async {
+  testUsingContext('can re-gen module .android/ folder, reusing custom org', () async {
     await _createProject(
       projectDir,
-      <String>['--template=application', '--org', 'com.bar.foo'],
+      <String>['--template=module', '--org', 'com.bar.foo'],
       <String>[],
     );
     projectDir.childDirectory('.android').deleteSync(recursive: true);
@@ -603,10 +583,10 @@
     );
   }, timeout: allowForRemotePubInvocation);
 
-  testUsingContext('can re-gen application .ios/ folder, reusing custom org', () async {
+  testUsingContext('can re-gen module .ios/ folder, reusing custom org', () async {
     await _createProject(
       projectDir,
-      <String>['--template=application', '--org', 'com.bar.foo'],
+      <String>['--template=module', '--org', 'com.bar.foo'],
       <String>[],
     );
     projectDir.childDirectory('.ios').deleteSync(recursive: true);
@@ -618,7 +598,7 @@
     );
   }, timeout: allowForRemotePubInvocation);
 
-  testUsingContext('can re-gen legacy app android/ folder, reusing custom org', () async {
+  testUsingContext('can re-gen app android/ folder, reusing custom org', () async {
     await _createProject(
       projectDir,
       <String>['--no-pub', '--template=app', '--org', 'com.bar.foo'],
@@ -637,7 +617,7 @@
     );
   }, timeout: allowForCreateFlutterProject);
 
-  testUsingContext('can re-gen legacy app ios/ folder, reusing custom org', () async {
+  testUsingContext('can re-gen app ios/ folder, reusing custom org', () async {
     await _createProject(
       projectDir,
       <String>['--no-pub', '--template=app', '--org', 'com.bar.foo'],
diff --git a/packages/flutter_tools/test/commands/packages_test.dart b/packages/flutter_tools/test/commands/packages_test.dart
index c8cad27..051bd39 100644
--- a/packages/flutter_tools/test/commands/packages_test.dart
+++ b/packages/flutter_tools/test/commands/packages_test.dart
@@ -45,8 +45,8 @@
       tryToDelete(tempDir);
     });
 
-    Future<String> createProjectWithPlugin(String plugin) async {
-      final String projectPath = await createProject(tempDir);
+    Future<String> createProjectWithPlugin(String plugin, {List<String> arguments}) async {
+      final String projectPath = await createProject(tempDir, arguments: arguments);
       final File pubspec = fs.file(fs.path.join(projectPath, 'pubspec.yaml'));
       String content = await pubspec.readAsString();
       content = content.replaceFirst(
@@ -114,7 +114,7 @@
       'android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java',
     ];
 
-    const List<String> applicationPluginRegistrants = <String>[
+    const List<String> modulePluginRegistrants = <String>[
       '.ios/Flutter/FlutterPluginRegistrant/Classes/GeneratedPluginRegistrant.h',
       '.ios/Flutter/FlutterPluginRegistrant/Classes/GeneratedPluginRegistrant.m',
       '.android/Flutter/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java',
@@ -125,7 +125,7 @@
       'ios/Podfile',
     ];
 
-    const List<String> applicationPluginWitnesses = <String>[
+    const List<String> modulePluginWitnesses = <String>[
       '.flutter-plugins',
       '.ios/Podfile',
     ];
@@ -135,7 +135,7 @@
       'ios/Flutter/Release.xcconfig': '#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"',
     };
 
-    const Map<String, String> applicationPluginContentWitnesses = <String, String>{
+    const Map<String, String> modulePluginContentWitnesses = <String, String>{
       '.ios/Config/Debug.xcconfig': '#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"',
       '.ios/Config/Release.xcconfig': '#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"',
     };
@@ -147,13 +147,13 @@
     }
 
     void expectZeroPluginsInjected(String projectPath) {
-      for (final String registrant in applicationPluginRegistrants) {
+      for (final String registrant in modulePluginRegistrants) {
         expectExists(projectPath, registrant);
       }
       for (final String witness in pluginWitnesses) {
         expectNotExists(projectPath, witness);
       }
-      applicationPluginContentWitnesses.forEach((String witness, String content) {
+      modulePluginContentWitnesses.forEach((String witness, String content) {
         expectNotContains(projectPath, witness, content);
       });
     }
@@ -170,14 +170,14 @@
       });
     }
 
-    void expectApplicationPluginInjected(String projectPath) {
-      for (final String registrant in applicationPluginRegistrants) {
+    void expectModulePluginInjected(String projectPath) {
+      for (final String registrant in modulePluginRegistrants) {
         expectExists(projectPath, registrant);
       }
-      for (final String witness in applicationPluginWitnesses) {
+      for (final String witness in modulePluginWitnesses) {
         expectExists(projectPath, witness);
       }
-      applicationPluginContentWitnesses.forEach((String witness, String content) {
+      modulePluginContentWitnesses.forEach((String witness, String content) {
         expectContains(projectPath, witness, content);
       });
     }
@@ -185,7 +185,7 @@
     void removeGeneratedFiles(String projectPath) {
       final Iterable<String> allFiles = <List<String>>[
         pubOutput,
-        applicationPluginRegistrants,
+        modulePluginRegistrants,
         pluginWitnesses,
       ].expand<String>((List<String> list) => list);
       for (String path in allFiles) {
@@ -196,7 +196,8 @@
     }
 
     testUsingContext('get fetches packages', () async {
-      final String projectPath = await createProject(tempDir);
+      final String projectPath = await createProject(tempDir,
+        arguments: <String>['--no-pub', '--template=module']);
       removeGeneratedFiles(projectPath);
 
       await runCommandIn(projectPath, 'get');
@@ -206,7 +207,8 @@
     }, timeout: allowForRemotePubInvocation);
 
     testUsingContext('get --offline fetches packages', () async {
-      final String projectPath = await createProject(tempDir);
+      final String projectPath = await createProject(tempDir,
+        arguments: <String>['--no-pub', '--template=module']);
       removeGeneratedFiles(projectPath);
 
       await runCommandIn(projectPath, 'get', args: <String>['--offline']);
@@ -216,7 +218,8 @@
     }, timeout: allowForCreateFlutterProject);
 
     testUsingContext('upgrade fetches packages', () async {
-      final String projectPath = await createProject(tempDir);
+      final String projectPath = await createProject(tempDir,
+        arguments: <String>['--no-pub', '--template=module']);
       removeGeneratedFiles(projectPath);
 
       await runCommandIn(projectPath, 'upgrade');
@@ -226,13 +229,14 @@
     }, timeout: allowForRemotePubInvocation);
 
     testUsingContext('get fetches packages and injects plugin', () async {
-      final String projectPath = await createProjectWithPlugin('path_provider');
+      final String projectPath = await createProjectWithPlugin('path_provider',
+        arguments: <String>['--no-pub', '--template=module']);
       removeGeneratedFiles(projectPath);
 
       await runCommandIn(projectPath, 'get');
 
       expectDependenciesResolved(projectPath);
-      expectApplicationPluginInjected(projectPath);
+      expectModulePluginInjected(projectPath);
     }, timeout: allowForRemotePubInvocation);
 
     testUsingContext('get fetches packages and injects plugin in plugin project', () async {