[flutter_tools] Display "no platforms" message based on results when creating plugins project (#70215)
This commit is contained in:
@@ -32,6 +32,7 @@ import '../../src/context.dart';
|
||||
import '../../src/pubspec_schema.dart';
|
||||
import '../../src/testbed.dart';
|
||||
|
||||
const String _kNoPlatformsMessage = 'Must specify at least one platform using --platforms.\n';
|
||||
const String frameworkRevision = '12345678';
|
||||
const String frameworkChannel = 'omega';
|
||||
// TODO(fujino): replace FakePlatform.fromPlatform() with FakePlatform()
|
||||
@@ -390,8 +391,6 @@ void main() {
|
||||
'android/src/main/java/com/example/flutter_project/FlutterProjectPlugin.java',
|
||||
'example/android/app/src/main/java/com/example/flutter_project_example/MainActivity.java',
|
||||
'lib/flutter_project_web.dart',
|
||||
// TODO(cyanglaz): no-op iOS folder should be removed after 1.20.0 release
|
||||
// https://github.com/flutter/flutter/issues/59787
|
||||
],
|
||||
);
|
||||
return _runFlutterTest(projectDir.childDirectory('example'));
|
||||
@@ -422,6 +421,7 @@ void main() {
|
||||
// The platform is correctly registered
|
||||
expect(pubspec.flutter['plugin']['platforms']['web']['pluginClass'], 'FlutterProjectWeb');
|
||||
expect(pubspec.flutter['plugin']['platforms']['web']['fileName'], 'flutter_project_web.dart');
|
||||
expect(logger.errorText, isNot(contains(_kNoPlatformsMessage)));
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
|
||||
Pub: () => Pub(
|
||||
@@ -432,6 +432,7 @@ void main() {
|
||||
botDetector: globals.botDetector,
|
||||
platform: globals.platform,
|
||||
),
|
||||
Logger: ()=>logger,
|
||||
});
|
||||
|
||||
testUsingContext('plugin example app depends on plugin', () async {
|
||||
@@ -661,7 +662,9 @@ void main() {
|
||||
// Import for the new embedding class.
|
||||
expect(mainActivity.contains('import io.flutter.embedding.android.FlutterActivity'), true);
|
||||
|
||||
expect(testLogger.statusText, isNot(contains('https://flutter.dev/go/android-project-migration')));
|
||||
expect(logger.statusText, isNot(contains('https://flutter.dev/go/android-project-migration')));
|
||||
}, overrides: <Type, Generator>{
|
||||
Logger: () => logger,
|
||||
});
|
||||
|
||||
testUsingContext('app does not include desktop or web by default', () async {
|
||||
@@ -732,8 +735,10 @@ void main() {
|
||||
expect(projectDir.childDirectory('windows'), isNot(exists));
|
||||
expect(projectDir.childDirectory('macos'), isNot(exists));
|
||||
expect(projectDir.childDirectory('web'), isNot(exists));
|
||||
expect(logger.errorText, isNot(contains(_kNoPlatformsMessage)));
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
|
||||
Logger: () => logger,
|
||||
});
|
||||
|
||||
testUsingContext('plugin supports Linux if requested', () async {
|
||||
@@ -767,8 +772,10 @@ void main() {
|
||||
],
|
||||
pluginClass: 'FlutterProjectPlugin',
|
||||
unexpectedPlatforms: <String>['some_platform']);
|
||||
expect(logger.errorText, isNot(contains(_kNoPlatformsMessage)));
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
|
||||
Logger: () => logger,
|
||||
});
|
||||
|
||||
testUsingContext('app supports macOS if requested', () async {
|
||||
@@ -794,8 +801,10 @@ void main() {
|
||||
expect(projectDir.childDirectory('linux'), isNot(exists));
|
||||
expect(projectDir.childDirectory('windows'), isNot(exists));
|
||||
expect(projectDir.childDirectory('web'), isNot(exists));
|
||||
expect(logger.errorText, isNot(contains(_kNoPlatformsMessage)));
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
|
||||
Logger: () => logger,
|
||||
});
|
||||
|
||||
testUsingContext('plugin supports macOS if requested', () async {
|
||||
@@ -826,8 +835,10 @@ void main() {
|
||||
'macos',
|
||||
], pluginClass: 'FlutterProjectPlugin',
|
||||
unexpectedPlatforms: <String>['some_platform']);
|
||||
expect(logger.errorText, isNot(contains(_kNoPlatformsMessage)));
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
|
||||
Logger: () => logger,
|
||||
});
|
||||
|
||||
testUsingContext('app supports Windows if requested', () async {
|
||||
@@ -852,8 +863,10 @@ void main() {
|
||||
expect(projectDir.childDirectory('linux'), isNot(exists));
|
||||
expect(projectDir.childDirectory('macos'), isNot(exists));
|
||||
expect(projectDir.childDirectory('web'), isNot(exists));
|
||||
expect(logger.errorText, isNot(contains(_kNoPlatformsMessage)));
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
|
||||
Logger: () => logger,
|
||||
});
|
||||
|
||||
testUsingContext('Windows has correct VERSIONINFO', () async {
|
||||
@@ -914,8 +927,10 @@ void main() {
|
||||
'windows'
|
||||
], pluginClass: 'FlutterProjectPlugin',
|
||||
unexpectedPlatforms: <String>['some_platform']);
|
||||
expect(logger.errorText, isNot(contains(_kNoPlatformsMessage)));
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
|
||||
Logger: () => logger,
|
||||
});
|
||||
|
||||
testUsingContext('app supports web if requested', () async {
|
||||
@@ -941,8 +956,10 @@ void main() {
|
||||
expect(projectDir.childDirectory('linux'), isNot(exists));
|
||||
expect(projectDir.childDirectory('macos'), isNot(exists));
|
||||
expect(projectDir.childDirectory('windows'), isNot(exists));
|
||||
expect(logger.errorText, isNot(contains(_kNoPlatformsMessage)));
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
|
||||
Logger: () => logger,
|
||||
});
|
||||
|
||||
testUsingContext('plugin uses new platform schema', () async {
|
||||
@@ -1652,8 +1669,6 @@ void main() {
|
||||
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', projectDir.path]);
|
||||
|
||||
// TODO(cyanglaz): no-op iOS folder should be removed after 1.20.0 release
|
||||
// https://github.com/flutter/flutter/issues/59787
|
||||
expect(projectDir.childDirectory('ios'), isNot(exists));
|
||||
expect(projectDir.childDirectory('android'), isNot(exists));
|
||||
expect(projectDir.childDirectory('web'), isNot(exists));
|
||||
@@ -1661,8 +1676,6 @@ void main() {
|
||||
expect(projectDir.childDirectory('windows'), isNot(exists));
|
||||
expect(projectDir.childDirectory('macos'), isNot(exists));
|
||||
|
||||
// TODO(cyanglaz): no-op iOS folder should be removed after 1.20.0 release
|
||||
// https://github.com/flutter/flutter/issues/59787
|
||||
expect(projectDir.childDirectory('example').childDirectory('ios'),
|
||||
isNot(exists));
|
||||
expect(projectDir.childDirectory('example').childDirectory('android'),
|
||||
@@ -1683,7 +1696,6 @@ void main() {
|
||||
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: false),
|
||||
});
|
||||
|
||||
|
||||
testUsingContext('plugin supports ios if requested', () async {
|
||||
Cache.flutterRoot = '../..';
|
||||
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
|
||||
@@ -1700,8 +1712,10 @@ void main() {
|
||||
'ios',
|
||||
], pluginClass: 'FlutterProjectPlugin',
|
||||
unexpectedPlatforms: <String>['some_platform']);
|
||||
expect(logger.errorText, isNot(contains(_kNoPlatformsMessage)));
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: false),
|
||||
Logger: () => logger,
|
||||
});
|
||||
|
||||
testUsingContext('plugin supports android if requested', () async {
|
||||
@@ -1722,8 +1736,10 @@ void main() {
|
||||
], pluginClass: 'FlutterProjectPlugin',
|
||||
unexpectedPlatforms: <String>['some_platform'],
|
||||
androidIdentifier: 'com.example.flutter_project');
|
||||
expect(logger.errorText, isNot(contains(_kNoPlatformsMessage)));
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: false),
|
||||
Logger: () => logger,
|
||||
});
|
||||
|
||||
testUsingContext('plugin supports web if requested', () async {
|
||||
@@ -1744,8 +1760,10 @@ void main() {
|
||||
unexpectedPlatforms: <String>['some_platform'],
|
||||
androidIdentifier: 'com.example.flutter_project',
|
||||
webFileName: 'flutter_project_web.dart');
|
||||
expect(logger.errorText, isNot(contains(_kNoPlatformsMessage)));
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
|
||||
Logger: () => logger,
|
||||
});
|
||||
|
||||
testUsingContext('plugin doe not support web if feature is not enabled', () async {
|
||||
@@ -1764,8 +1782,10 @@ void main() {
|
||||
'some_platform'
|
||||
], pluginClass: 'somePluginClass',
|
||||
unexpectedPlatforms: <String>['web']);
|
||||
expect(logger.errorText, contains(_kNoPlatformsMessage));
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isWebEnabled: false),
|
||||
Logger: () => logger,
|
||||
});
|
||||
|
||||
testUsingContext('create an empty plugin, then add ios', () async {
|
||||
@@ -2081,7 +2101,9 @@ void main() {
|
||||
final CreateCommand command = CreateCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', '--platforms=android', projectDir.path]);
|
||||
expect(logger.statusText, isNot(contains('The `pubspec.yaml` under the project directory must be updated to support')));
|
||||
final String projectDirPath = globals.fs.path.normalize(projectDir.absolute.path);
|
||||
final String relativePluginPath = globals.fs.path.normalize(globals.fs.path.relative(projectDirPath));
|
||||
expect(logger.statusText, isNot(contains('You need to update $relativePluginPath/pubspec.yaml to support android.\n')));
|
||||
}, overrides: <Type, Generator> {
|
||||
Logger: () => logger,
|
||||
});
|
||||
@@ -2093,10 +2115,12 @@ void main() {
|
||||
|
||||
final CreateCommand command = CreateCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
final String projectDirPath = globals.fs.path.normalize(projectDir.absolute.path);
|
||||
final String relativePluginPath = globals.fs.path.normalize(globals.fs.path.relative(projectDirPath));
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', '--platforms=ios', projectDir.path]);
|
||||
expect(logger.statusText, isNot(contains('The `pubspec.yaml` under the project directory must be updated to support')));
|
||||
expect(logger.statusText, isNot(contains('You need to update $relativePluginPath/pubspec.yaml to support ios.\n')));
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', '--platforms=android', projectDir.path]);
|
||||
expect(logger.statusText, contains('The `pubspec.yaml` under the project directory must be updated to support'));
|
||||
expect(logger.statusText, contains('You need to update $relativePluginPath/pubspec.yaml to support android.\n'));
|
||||
}, overrides: <Type, Generator> {
|
||||
Logger: () => logger,
|
||||
});
|
||||
@@ -2276,6 +2300,39 @@ void main() {
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
|
||||
});
|
||||
|
||||
testUsingContext('created plugin supports no platforms should print `no platforms` message', () async {
|
||||
Cache.flutterRoot = '../..';
|
||||
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
|
||||
when(mockFlutterVersion.channel).thenReturn(frameworkChannel);
|
||||
|
||||
final CreateCommand command = CreateCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', projectDir.path]);
|
||||
expect(logger.errorText, contains(_kNoPlatformsMessage));
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: false),
|
||||
Logger: ()=> logger,
|
||||
});
|
||||
|
||||
testUsingContext('created plugin with no --platforms flag should not print `no platforms` message if the existing plugin supports a platform.', () async {
|
||||
Cache.flutterRoot = '../..';
|
||||
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
|
||||
when(mockFlutterVersion.channel).thenReturn(frameworkChannel);
|
||||
|
||||
final CreateCommand command = CreateCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', '--platforms=ios', projectDir.path]);
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', projectDir.path]);
|
||||
expect(logger.errorText, isNot(contains(_kNoPlatformsMessage)));
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: false),
|
||||
Logger: () => logger,
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _createProject(
|
||||
|
||||
@@ -972,6 +972,49 @@ flutter:
|
||||
expect(flutterManifest.supportedPlatforms, null);
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterManifest validSupportedPlatforms return null if the platform keys are not valid', () {
|
||||
const String manifest = '''
|
||||
name: test
|
||||
flutter:
|
||||
plugin:
|
||||
platforms:
|
||||
some_platform:
|
||||
pluginClass: SomeClass
|
||||
''';
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
|
||||
manifest,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(flutterManifest.isPlugin, true);
|
||||
expect(flutterManifest.validSupportedPlatforms, null);
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterManifest validSupportedPlatforms only returns valid platforms', () {
|
||||
const String manifest = '''
|
||||
name: test
|
||||
flutter:
|
||||
plugin:
|
||||
platforms:
|
||||
some_platform:
|
||||
pluginClass: SomeClass
|
||||
ios:
|
||||
pluginClass: SomeClass
|
||||
''';
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final FlutterManifest flutterManifest = FlutterManifest.createFromString(
|
||||
manifest,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(flutterManifest.isPlugin, true);
|
||||
expect(flutterManifest.validSupportedPlatforms['ios'],
|
||||
<String, dynamic>{'pluginClass': 'SomeClass'});
|
||||
expect(flutterManifest.validSupportedPlatforms['some_platform'],
|
||||
isNull);
|
||||
});
|
||||
|
||||
testWithoutContext('FlutterManifest getSupportedPlatforms returns valid platforms.', () {
|
||||
const String manifest = '''
|
||||
name: test
|
||||
|
||||
Reference in New Issue
Block a user