Rename module --> application in flutter create command. (#22565)
This renames the "module" template to the "application" template, and makes "application" the default. The existing "app" template is now deprecated. flutter create also now recognizes the type of project in an existing directory, and is able to recreate it without having the template type explicitly specified (although you can still do that). It does this now by first looking in the .metadata file for the new project_type field, and if it doesn't find that, then it looks at the directory structure. Also, the .metadata file is now overwritten even on an existing directory so that 1) the project_type can be added to legacy projects, and 2) the version of Flutter that updated the project last is updated. I also cleaned up a bunch of things in create_test.dart, added many more tests, and added an example test to the test/ directory in the generated output of the application template. Fixes #22530 Fixes #22344
This commit is contained in:
@@ -44,7 +44,7 @@ void main() {
|
||||
arguments: <String>['create', projectPath],
|
||||
statusTextContains: <String>[
|
||||
'All done!',
|
||||
'Your main program file is lib/main.dart',
|
||||
'Your application code is in ${fs.path.normalize(fs.path.join(fs.path.relative(projectPath), 'lib', 'main.dart'))}',
|
||||
],
|
||||
);
|
||||
expect(libMain.existsSync(), isTrue);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -114,16 +114,32 @@ void main() {
|
||||
'android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java',
|
||||
];
|
||||
|
||||
const List<String> applicationPluginRegistrants = <String>[
|
||||
'.ios/Flutter/FlutterPluginRegistrant/Classes/GeneratedPluginRegistrant.h',
|
||||
'.ios/Flutter/FlutterPluginRegistrant/Classes/GeneratedPluginRegistrant.m',
|
||||
'.android/Flutter/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java',
|
||||
];
|
||||
|
||||
const List<String> pluginWitnesses = <String>[
|
||||
'.flutter-plugins',
|
||||
'ios/Podfile',
|
||||
];
|
||||
|
||||
const List<String> applicationPluginWitnesses = <String>[
|
||||
'.flutter-plugins',
|
||||
'.ios/Podfile',
|
||||
];
|
||||
|
||||
const Map<String, String> pluginContentWitnesses = <String, String>{
|
||||
'ios/Flutter/Debug.xcconfig': '#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"',
|
||||
'ios/Flutter/Release.xcconfig': '#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"',
|
||||
};
|
||||
|
||||
const Map<String, String> applicationPluginContentWitnesses = <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"',
|
||||
};
|
||||
|
||||
void expectDependenciesResolved(String projectPath) {
|
||||
for (String output in pubOutput) {
|
||||
expectExists(projectPath, output);
|
||||
@@ -131,13 +147,13 @@ void main() {
|
||||
}
|
||||
|
||||
void expectZeroPluginsInjected(String projectPath) {
|
||||
for (final String registrant in pluginRegistrants) {
|
||||
for (final String registrant in applicationPluginRegistrants) {
|
||||
expectExists(projectPath, registrant);
|
||||
}
|
||||
for (final String witness in pluginWitnesses) {
|
||||
expectNotExists(projectPath, witness);
|
||||
}
|
||||
pluginContentWitnesses.forEach((String witness, String content) {
|
||||
applicationPluginContentWitnesses.forEach((String witness, String content) {
|
||||
expectNotContains(projectPath, witness, content);
|
||||
});
|
||||
}
|
||||
@@ -154,10 +170,22 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
void expectApplicationPluginInjected(String projectPath) {
|
||||
for (final String registrant in applicationPluginRegistrants) {
|
||||
expectExists(projectPath, registrant);
|
||||
}
|
||||
for (final String witness in applicationPluginWitnesses) {
|
||||
expectExists(projectPath, witness);
|
||||
}
|
||||
applicationPluginContentWitnesses.forEach((String witness, String content) {
|
||||
expectContains(projectPath, witness, content);
|
||||
});
|
||||
}
|
||||
|
||||
void removeGeneratedFiles(String projectPath) {
|
||||
final Iterable<String> allFiles = <List<String>>[
|
||||
pubOutput,
|
||||
pluginRegistrants,
|
||||
applicationPluginRegistrants,
|
||||
pluginWitnesses,
|
||||
].expand<String>((List<String> list) => list);
|
||||
for (String path in allFiles) {
|
||||
@@ -204,14 +232,13 @@ void main() {
|
||||
await runCommandIn(projectPath, 'get');
|
||||
|
||||
expectDependenciesResolved(projectPath);
|
||||
expectPluginInjected(projectPath);
|
||||
// TODO(mravn): This test fails on the Chrome windows bot only.
|
||||
// Skipping until resolved.
|
||||
}, timeout: allowForRemotePubInvocation, skip: true);
|
||||
expectApplicationPluginInjected(projectPath);
|
||||
}, timeout: allowForRemotePubInvocation);
|
||||
|
||||
testUsingContext('get fetches packages and injects plugin in plugin project', () async {
|
||||
final String projectPath = await createProject(
|
||||
tempDir,
|
||||
arguments: <String>['-t', 'plugin', '--no-pub'],
|
||||
arguments: <String>['--template=plugin', '--no-pub'],
|
||||
);
|
||||
final String exampleProjectPath = fs.path.join(projectPath, 'example');
|
||||
removeGeneratedFiles(projectPath);
|
||||
|
||||
@@ -355,20 +355,20 @@ flutter:
|
||||
''';
|
||||
final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest);
|
||||
expect(flutterManifest.isEmpty, false);
|
||||
expect(flutterManifest.isModule, false);
|
||||
expect(flutterManifest.isApplication, false);
|
||||
expect(flutterManifest.isPlugin, false);
|
||||
expect(flutterManifest.androidPackage, null);
|
||||
});
|
||||
|
||||
test('allows a module declaration', () async {
|
||||
test('allows an application declaration', () async {
|
||||
const String manifest = '''
|
||||
name: test
|
||||
flutter:
|
||||
module:
|
||||
application:
|
||||
androidPackage: com.example
|
||||
''';
|
||||
final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest);
|
||||
expect(flutterManifest.isModule, true);
|
||||
expect(flutterManifest.isApplication, true);
|
||||
expect(flutterManifest.androidPackage, 'com.example');
|
||||
});
|
||||
|
||||
|
||||
@@ -90,20 +90,20 @@ void main() {
|
||||
});
|
||||
|
||||
group('editable Android host app', () {
|
||||
testInMemory('fails on non-module', () async {
|
||||
testInMemory('fails on non-application', () async {
|
||||
final FlutterProject project = await someProject();
|
||||
await expectLater(
|
||||
project.android.makeHostAppEditable(),
|
||||
throwsA(isInstanceOf<AssertionError>()),
|
||||
);
|
||||
});
|
||||
testInMemory('exits on already editable module', () async {
|
||||
final FlutterProject project = await aModuleProject();
|
||||
testInMemory('exits on already editable application', () async {
|
||||
final FlutterProject project = await anApplicationProject();
|
||||
await project.android.makeHostAppEditable();
|
||||
return expectToolExitLater(project.android.makeHostAppEditable(), contains('already editable'));
|
||||
});
|
||||
testInMemory('creates android/app folder in place of .android/app', () async {
|
||||
final FlutterProject project = await aModuleProject();
|
||||
final FlutterProject project = await anApplicationProject();
|
||||
await project.android.makeHostAppEditable();
|
||||
expectNotExists(project.directory.childDirectory('.android').childDirectory('app'));
|
||||
expect(
|
||||
@@ -118,7 +118,7 @@ void main() {
|
||||
);
|
||||
});
|
||||
testInMemory('retains .android/Flutter folder and references it', () async {
|
||||
final FlutterProject project = await aModuleProject();
|
||||
final FlutterProject project = await anApplicationProject();
|
||||
await project.android.makeHostAppEditable();
|
||||
expectExists(project.directory.childDirectory('.android').childDirectory('Flutter'));
|
||||
expect(
|
||||
@@ -127,7 +127,7 @@ void main() {
|
||||
);
|
||||
});
|
||||
testInMemory('can be redone after deletion', () async {
|
||||
final FlutterProject project = await aModuleProject();
|
||||
final FlutterProject project = await anApplicationProject();
|
||||
await project.android.makeHostAppEditable();
|
||||
project.directory.childDirectory('android').deleteSync(recursive: true);
|
||||
await project.android.makeHostAppEditable();
|
||||
@@ -173,15 +173,15 @@ void main() {
|
||||
await project.ensureReadyForPlatformSpecificTooling();
|
||||
expectExists(project.android.hostAppGradleRoot.childFile('local.properties'));
|
||||
});
|
||||
testInMemory('creates Android library in module', () async {
|
||||
final FlutterProject project = await aModuleProject();
|
||||
testInMemory('creates Android library in application', () async {
|
||||
final FlutterProject project = await anApplicationProject();
|
||||
await project.ensureReadyForPlatformSpecificTooling();
|
||||
expectExists(project.android.hostAppGradleRoot.childFile('settings.gradle'));
|
||||
expectExists(project.android.hostAppGradleRoot.childFile('local.properties'));
|
||||
expectExists(androidPluginRegistrant(project.android.hostAppGradleRoot.childDirectory('Flutter')));
|
||||
});
|
||||
testInMemory('creates iOS pod in module', () async {
|
||||
final FlutterProject project = await aModuleProject();
|
||||
testInMemory('creates iOS pod in application', () async {
|
||||
final FlutterProject project = await anApplicationProject();
|
||||
await project.ensureReadyForPlatformSpecificTooling();
|
||||
final Directory flutter = project.ios.hostAppRoot.childDirectory('Flutter');
|
||||
expectExists(flutter.childFile('podhelper.rb'));
|
||||
@@ -194,20 +194,20 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('module status', () {
|
||||
testInMemory('is known for module', () async {
|
||||
final FlutterProject project = await aModuleProject();
|
||||
expect(project.isModule, isTrue);
|
||||
expect(project.android.isModule, isTrue);
|
||||
expect(project.ios.isModule, isTrue);
|
||||
group('application status', () {
|
||||
testInMemory('is known for application', () async {
|
||||
final FlutterProject project = await anApplicationProject();
|
||||
expect(project.isApplication, isTrue);
|
||||
expect(project.android.isApplication, isTrue);
|
||||
expect(project.ios.isApplication, isTrue);
|
||||
expect(project.android.hostAppGradleRoot.basename, '.android');
|
||||
expect(project.ios.hostAppRoot.basename, '.ios');
|
||||
});
|
||||
testInMemory('is known for non-module', () async {
|
||||
testInMemory('is known for non-application', () async {
|
||||
final FlutterProject project = await someProject();
|
||||
expect(project.isModule, isFalse);
|
||||
expect(project.android.isModule, isFalse);
|
||||
expect(project.ios.isModule, isFalse);
|
||||
expect(project.isApplication, isFalse);
|
||||
expect(project.android.isApplication, isFalse);
|
||||
expect(project.ios.isApplication, isFalse);
|
||||
expect(project.android.hostAppGradleRoot.basename, 'android');
|
||||
expect(project.ios.hostAppRoot.basename, 'ios');
|
||||
});
|
||||
@@ -351,13 +351,13 @@ flutter:
|
||||
return FlutterProject.fromDirectory(directory);
|
||||
}
|
||||
|
||||
Future<FlutterProject> aModuleProject() async {
|
||||
final Directory directory = fs.directory('module_project');
|
||||
Future<FlutterProject> anApplicationProject() async {
|
||||
final Directory directory = fs.directory('application_project');
|
||||
directory.childFile('.packages').createSync(recursive: true);
|
||||
directory.childFile('pubspec.yaml').writeAsStringSync('''
|
||||
name: my_module
|
||||
name: my_application
|
||||
flutter:
|
||||
module:
|
||||
application:
|
||||
androidPackage: com.example
|
||||
''');
|
||||
return FlutterProject.fromDirectory(directory);
|
||||
|
||||
Reference in New Issue
Block a user