|
|
|
|
@@ -14,6 +14,8 @@ import 'package:flutter_tools/src/base/platform.dart';
|
|
|
|
|
import 'package:flutter_tools/src/base/time.dart';
|
|
|
|
|
import 'package:flutter_tools/src/base/utils.dart';
|
|
|
|
|
import 'package:flutter_tools/src/features.dart';
|
|
|
|
|
import 'package:flutter_tools/src/dart/package_map.dart';
|
|
|
|
|
import 'package:flutter_tools/src/flutter_manifest.dart';
|
|
|
|
|
import 'package:flutter_tools/src/globals.dart' as globals;
|
|
|
|
|
import 'package:flutter_tools/src/ios/xcodeproj.dart';
|
|
|
|
|
import 'package:flutter_tools/src/plugins.dart';
|
|
|
|
|
@@ -21,6 +23,7 @@ import 'package:flutter_tools/src/project.dart';
|
|
|
|
|
import 'package:flutter_tools/src/version.dart';
|
|
|
|
|
import 'package:meta/meta.dart';
|
|
|
|
|
import 'package:mockito/mockito.dart';
|
|
|
|
|
import 'package:package_config/package_config.dart';
|
|
|
|
|
import 'package:yaml/yaml.dart';
|
|
|
|
|
|
|
|
|
|
import '../src/common.dart';
|
|
|
|
|
@@ -32,6 +35,7 @@ void main() {
|
|
|
|
|
group('plugins', () {
|
|
|
|
|
FileSystem fs;
|
|
|
|
|
MockFlutterProject flutterProject;
|
|
|
|
|
MockFlutterManifest flutterManifest;
|
|
|
|
|
MockIosProject iosProject;
|
|
|
|
|
MockMacOSProject macosProject;
|
|
|
|
|
MockAndroidProject androidProject;
|
|
|
|
|
@@ -48,6 +52,12 @@ void main() {
|
|
|
|
|
// Adds basic properties to the flutterProject and its subprojects.
|
|
|
|
|
void setUpProject(FileSystem fileSystem) {
|
|
|
|
|
flutterProject = MockFlutterProject();
|
|
|
|
|
|
|
|
|
|
flutterManifest = MockFlutterManifest();
|
|
|
|
|
when(flutterManifest.dependencies).thenReturn(<String>{});
|
|
|
|
|
|
|
|
|
|
when(flutterProject.manifest).thenReturn(flutterManifest);
|
|
|
|
|
|
|
|
|
|
when(flutterProject.directory).thenReturn(fileSystem.systemTempDirectory.childDirectory('app'));
|
|
|
|
|
// TODO(franciscojma): Remove logic for .flutter-plugins once it's deprecated.
|
|
|
|
|
when(flutterProject.flutterPluginsFile).thenReturn(flutterProject.directory.childFile('.flutter-plugins'));
|
|
|
|
|
@@ -1297,6 +1307,767 @@ flutter:
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group('resolvePlatformImplementation', () {
|
|
|
|
|
test('selects implementation from direct dependency', () async {
|
|
|
|
|
final FileSystem fs = MemoryFileSystem();
|
|
|
|
|
final Set<String> directDependencies = <String>{
|
|
|
|
|
'url_launcher_linux',
|
|
|
|
|
'url_launcher_macos',
|
|
|
|
|
};
|
|
|
|
|
final List<PluginInterfaceResolution> resolutions = resolvePlatformImplementation(<Plugin>[
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'url_launcher_linux',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'implements': 'url_launcher',
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'linux': <String, dynamic>{
|
|
|
|
|
'dartPluginClass': 'UrlLauncherPluginLinux',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'url_launcher_macos',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'implements': 'url_launcher',
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'macos': <String, dynamic>{
|
|
|
|
|
'dartPluginClass': 'UrlLauncherPluginMacOS',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'undirect_dependency_plugin',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'implements': 'url_launcher',
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'windows': <String, dynamic>{
|
|
|
|
|
'dartPluginClass': 'UrlLauncherPluginWindows',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
resolvePlatformImplementation(<Plugin>[
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'url_launcher_macos',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'implements': 'url_launcher',
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'macos': <String, dynamic>{
|
|
|
|
|
'dartPluginClass': 'UrlLauncherPluginMacOS',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
expect(resolutions.length, equals(2));
|
|
|
|
|
expect(resolutions[0].toMap(), equals(
|
|
|
|
|
<String, String>{
|
|
|
|
|
'pluginName': 'url_launcher_linux',
|
|
|
|
|
'dartClass': 'UrlLauncherPluginLinux',
|
|
|
|
|
'platform': 'linux',
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
expect(resolutions[1].toMap(), equals(
|
|
|
|
|
<String, String>{
|
|
|
|
|
'pluginName': 'url_launcher_macos',
|
|
|
|
|
'dartClass': 'UrlLauncherPluginMacOS',
|
|
|
|
|
'platform': 'macos',
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('selects default implementation', () async {
|
|
|
|
|
final FileSystem fs = MemoryFileSystem();
|
|
|
|
|
final Set<String> directDependencies = <String>{};
|
|
|
|
|
|
|
|
|
|
final List<PluginInterfaceResolution> resolutions = resolvePlatformImplementation(<Plugin>[
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'url_launcher',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'linux': <String, dynamic>{
|
|
|
|
|
'default_package': 'url_launcher_linux',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'url_launcher_linux',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'implements': 'url_launcher',
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'linux': <String, dynamic>{
|
|
|
|
|
'dartPluginClass': 'UrlLauncherPluginLinux',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
expect(resolutions.length, equals(1));
|
|
|
|
|
expect(resolutions[0].toMap(), equals(
|
|
|
|
|
<String, String>{
|
|
|
|
|
'pluginName': 'url_launcher_linux',
|
|
|
|
|
'dartClass': 'UrlLauncherPluginLinux',
|
|
|
|
|
'platform': 'linux',
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('selects default implementation if interface is direct dependency', () async {
|
|
|
|
|
final FileSystem fs = MemoryFileSystem();
|
|
|
|
|
final Set<String> directDependencies = <String>{'url_launcher'};
|
|
|
|
|
|
|
|
|
|
final List<PluginInterfaceResolution> resolutions = resolvePlatformImplementation(<Plugin>[
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'url_launcher',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'linux': <String, dynamic>{
|
|
|
|
|
'default_package': 'url_launcher_linux',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'url_launcher_linux',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'implements': 'url_launcher',
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'linux': <String, dynamic>{
|
|
|
|
|
'dartPluginClass': 'UrlLauncherPluginLinux',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
expect(resolutions.length, equals(1));
|
|
|
|
|
expect(resolutions[0].toMap(), equals(
|
|
|
|
|
<String, String>{
|
|
|
|
|
'pluginName': 'url_launcher_linux',
|
|
|
|
|
'dartClass': 'UrlLauncherPluginLinux',
|
|
|
|
|
'platform': 'linux',
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('selects user selected implementation despites default implementation', () async {
|
|
|
|
|
final FileSystem fs = MemoryFileSystem();
|
|
|
|
|
final Set<String> directDependencies = <String>{
|
|
|
|
|
'user_selected_url_launcher_implementation',
|
|
|
|
|
'url_launcher',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
final List<PluginInterfaceResolution> resolutions = resolvePlatformImplementation(<Plugin>[
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'url_launcher',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'linux': <String, dynamic>{
|
|
|
|
|
'default_package': 'url_launcher_linux',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'url_launcher_linux',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'implements': 'url_launcher',
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'linux': <String, dynamic>{
|
|
|
|
|
'dartPluginClass': 'UrlLauncherPluginLinux',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'user_selected_url_launcher_implementation',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'implements': 'url_launcher',
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'linux': <String, dynamic>{
|
|
|
|
|
'dartPluginClass': 'UrlLauncherPluginLinux',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
expect(resolutions.length, equals(1));
|
|
|
|
|
expect(resolutions[0].toMap(), equals(
|
|
|
|
|
<String, String>{
|
|
|
|
|
'pluginName': 'user_selected_url_launcher_implementation',
|
|
|
|
|
'dartClass': 'UrlLauncherPluginLinux',
|
|
|
|
|
'platform': 'linux',
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('selects user selected implementation despites default implementation', () async {
|
|
|
|
|
final FileSystem fs = MemoryFileSystem();
|
|
|
|
|
final Set<String> directDependencies = <String>{
|
|
|
|
|
'user_selected_url_launcher_implementation',
|
|
|
|
|
'url_launcher',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
final List<PluginInterfaceResolution> resolutions = resolvePlatformImplementation(<Plugin>[
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'url_launcher',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'linux': <String, dynamic>{
|
|
|
|
|
'default_package': 'url_launcher_linux',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'url_launcher_linux',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'implements': 'url_launcher',
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'linux': <String, dynamic>{
|
|
|
|
|
'dartPluginClass': 'UrlLauncherPluginLinux',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'user_selected_url_launcher_implementation',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'implements': 'url_launcher',
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'linux': <String, dynamic>{
|
|
|
|
|
'dartPluginClass': 'UrlLauncherPluginLinux',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
expect(resolutions.length, equals(1));
|
|
|
|
|
expect(resolutions[0].toMap(), equals(
|
|
|
|
|
<String, String>{
|
|
|
|
|
'pluginName': 'user_selected_url_launcher_implementation',
|
|
|
|
|
'dartClass': 'UrlLauncherPluginLinux',
|
|
|
|
|
'platform': 'linux',
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
testUsingContext('provides error when user selected multiple implementations', () async {
|
|
|
|
|
final FileSystem fs = MemoryFileSystem();
|
|
|
|
|
final Set<String> directDependencies = <String>{
|
|
|
|
|
'url_launcher_linux_1',
|
|
|
|
|
'url_launcher_linux_2',
|
|
|
|
|
};
|
|
|
|
|
expect(() {
|
|
|
|
|
resolvePlatformImplementation(<Plugin>[
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'url_launcher_linux_1',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'implements': 'url_launcher',
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'linux': <String, dynamic>{
|
|
|
|
|
'dartPluginClass': 'UrlLauncherPluginLinux',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'url_launcher_linux_2',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'implements': 'url_launcher',
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'linux': <String, dynamic>{
|
|
|
|
|
'dartPluginClass': 'UrlLauncherPluginLinux',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
testLogger.errorText,
|
|
|
|
|
'Plugin `url_launcher_linux_2` implements an interface for `linux`, which was already implemented by plugin `url_launcher_linux_1`.\n'
|
|
|
|
|
'To fix this issue, remove either dependency from pubspec.yaml.'
|
|
|
|
|
'\n\n'
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
throwsToolExit(
|
|
|
|
|
message: 'Please resolve the errors',
|
|
|
|
|
));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
testUsingContext('provides all errors when user selected multiple implementations', () async {
|
|
|
|
|
final FileSystem fs = MemoryFileSystem();
|
|
|
|
|
final Set<String> directDependencies = <String>{
|
|
|
|
|
'url_launcher_linux_1',
|
|
|
|
|
'url_launcher_linux_2',
|
|
|
|
|
};
|
|
|
|
|
expect(() {
|
|
|
|
|
resolvePlatformImplementation(<Plugin>[
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'url_launcher_linux_1',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'implements': 'url_launcher',
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'linux': <String, dynamic>{
|
|
|
|
|
'dartPluginClass': 'UrlLauncherPluginLinux',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'url_launcher_linux_2',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'implements': 'url_launcher',
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'linux': <String, dynamic>{
|
|
|
|
|
'dartPluginClass': 'UrlLauncherPluginLinux',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
testLogger.errorText,
|
|
|
|
|
'Plugin `url_launcher_linux_2` implements an interface for `linux`, which was already implemented by plugin `url_launcher_linux_1`.\n'
|
|
|
|
|
'To fix this issue, remove either dependency from pubspec.yaml.'
|
|
|
|
|
'\n\n'
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
throwsToolExit(
|
|
|
|
|
message: 'Please resolve the errors',
|
|
|
|
|
));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
testUsingContext('provides error when plugin pubspec.yaml doesn\'t have "implementation" nor "default_implementation"', () async {
|
|
|
|
|
final FileSystem fs = MemoryFileSystem();
|
|
|
|
|
final Set<String> directDependencies = <String>{
|
|
|
|
|
'url_launcher_linux_1',
|
|
|
|
|
};
|
|
|
|
|
expect(() {
|
|
|
|
|
resolvePlatformImplementation(<Plugin>[
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'url_launcher_linux_1',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'linux': <String, dynamic>{
|
|
|
|
|
'dartPluginClass': 'UrlLauncherPluginLinux',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
},
|
|
|
|
|
throwsToolExit(
|
|
|
|
|
message: 'Please resolve the errors'
|
|
|
|
|
));
|
|
|
|
|
expect(
|
|
|
|
|
testLogger.errorText,
|
|
|
|
|
'Plugin `url_launcher_linux_1` doesn\'t implement a plugin interface, '
|
|
|
|
|
'nor sets a default implementation in pubspec.yaml.\n\n'
|
|
|
|
|
'To set a default implementation, use:\n'
|
|
|
|
|
'flutter:\n'
|
|
|
|
|
' plugin:\n'
|
|
|
|
|
' platforms:\n'
|
|
|
|
|
' linux:\n'
|
|
|
|
|
' default_package: <plugin-implementation>\n'
|
|
|
|
|
'\n'
|
|
|
|
|
'To implement an interface, use:\n'
|
|
|
|
|
'flutter:\n'
|
|
|
|
|
' plugin:\n'
|
|
|
|
|
' implements: <plugin-interface>'
|
|
|
|
|
'\n\n'
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
testUsingContext('provides all errors when plugin pubspec.yaml doesn\'t have "implementation" nor "default_implementation"', () async {
|
|
|
|
|
final FileSystem fs = MemoryFileSystem();
|
|
|
|
|
final Set<String> directDependencies = <String>{
|
|
|
|
|
'url_launcher_linux',
|
|
|
|
|
'url_launcher_windows',
|
|
|
|
|
};
|
|
|
|
|
expect(() {
|
|
|
|
|
resolvePlatformImplementation(<Plugin>[
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'url_launcher_linux',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'linux': <String, dynamic>{
|
|
|
|
|
'dartPluginClass': 'UrlLauncherPluginLinux',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
Plugin.fromYaml(
|
|
|
|
|
'url_launcher_windows',
|
|
|
|
|
'',
|
|
|
|
|
YamlMap.wrap(<String, dynamic>{
|
|
|
|
|
'platforms': <String, dynamic>{
|
|
|
|
|
'windows': <String, dynamic>{
|
|
|
|
|
'dartPluginClass': 'UrlLauncherPluginWindows',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
<String>[],
|
|
|
|
|
fileSystem: fs,
|
|
|
|
|
appDependencies: directDependencies,
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
},
|
|
|
|
|
throwsToolExit(
|
|
|
|
|
message: 'Please resolve the errors'
|
|
|
|
|
));
|
|
|
|
|
expect(
|
|
|
|
|
testLogger.errorText,
|
|
|
|
|
'Plugin `url_launcher_linux` doesn\'t implement a plugin interface, '
|
|
|
|
|
'nor sets a default implementation in pubspec.yaml.\n\n'
|
|
|
|
|
'To set a default implementation, use:\n'
|
|
|
|
|
'flutter:\n'
|
|
|
|
|
' plugin:\n'
|
|
|
|
|
' platforms:\n'
|
|
|
|
|
' linux:\n'
|
|
|
|
|
' default_package: <plugin-implementation>\n'
|
|
|
|
|
'\n'
|
|
|
|
|
'To implement an interface, use:\n'
|
|
|
|
|
'flutter:\n'
|
|
|
|
|
' plugin:\n'
|
|
|
|
|
' implements: <plugin-interface>'
|
|
|
|
|
'\n\n'
|
|
|
|
|
'Plugin `url_launcher_windows` doesn\'t implement a plugin interface, '
|
|
|
|
|
'nor sets a default implementation in pubspec.yaml.\n\n'
|
|
|
|
|
'To set a default implementation, use:\n'
|
|
|
|
|
'flutter:\n'
|
|
|
|
|
' plugin:\n'
|
|
|
|
|
' platforms:\n'
|
|
|
|
|
' windows:\n'
|
|
|
|
|
' default_package: <plugin-implementation>\n'
|
|
|
|
|
'\n'
|
|
|
|
|
'To implement an interface, use:\n'
|
|
|
|
|
'flutter:\n'
|
|
|
|
|
' plugin:\n'
|
|
|
|
|
' implements: <plugin-interface>'
|
|
|
|
|
'\n\n'
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group('generateMainDartWithPluginRegistrant', () {
|
|
|
|
|
testUsingContext('Generates new entrypoint', () async {
|
|
|
|
|
when(flutterProject.isModule).thenReturn(false);
|
|
|
|
|
|
|
|
|
|
final List<Directory> directories = <Directory>[];
|
|
|
|
|
final Directory fakePubCache = fs.systemTempDirectory.childDirectory('cache');
|
|
|
|
|
final File packagesFile = flutterProject.directory
|
|
|
|
|
.childFile('.packages')
|
|
|
|
|
..createSync(recursive: true);
|
|
|
|
|
|
|
|
|
|
final Map<String, String> plugins = <String, String>{};
|
|
|
|
|
plugins['url_launcher_macos'] = '''
|
|
|
|
|
flutter:
|
|
|
|
|
plugin:
|
|
|
|
|
implements: url_launcher
|
|
|
|
|
platforms:
|
|
|
|
|
macos:
|
|
|
|
|
dartPluginClass: MacOSPlugin
|
|
|
|
|
''';
|
|
|
|
|
plugins['url_launcher_linux'] = '''
|
|
|
|
|
flutter:
|
|
|
|
|
plugin:
|
|
|
|
|
implements: url_launcher
|
|
|
|
|
platforms:
|
|
|
|
|
linux:
|
|
|
|
|
dartPluginClass: LinuxPlugin
|
|
|
|
|
''';
|
|
|
|
|
plugins['url_launcher_windows'] = '''
|
|
|
|
|
flutter:
|
|
|
|
|
plugin:
|
|
|
|
|
implements: url_launcher
|
|
|
|
|
platforms:
|
|
|
|
|
windows:
|
|
|
|
|
dartPluginClass: WindowsPlugin
|
|
|
|
|
''';
|
|
|
|
|
plugins['awesome_macos'] = '''
|
|
|
|
|
flutter:
|
|
|
|
|
plugin:
|
|
|
|
|
implements: awesome
|
|
|
|
|
platforms:
|
|
|
|
|
macos:
|
|
|
|
|
dartPluginClass: AwesomeMacOS
|
|
|
|
|
''';
|
|
|
|
|
for (final MapEntry<String, String> entry in plugins.entries) {
|
|
|
|
|
final String name = fs.path.basename(entry.key);
|
|
|
|
|
final Directory pluginDirectory = fakePubCache.childDirectory(name);
|
|
|
|
|
packagesFile.writeAsStringSync(
|
|
|
|
|
'$name:file://${pluginDirectory.childFile('lib').uri}\n',
|
|
|
|
|
mode: FileMode.writeOnlyAppend);
|
|
|
|
|
pluginDirectory.childFile('pubspec.yaml')
|
|
|
|
|
..createSync(recursive: true)
|
|
|
|
|
..writeAsStringSync(entry.value);
|
|
|
|
|
directories.add(pluginDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
when(flutterManifest.dependencies).thenReturn(<String>{...plugins.keys});
|
|
|
|
|
|
|
|
|
|
final Directory libDir = flutterProject.directory.childDirectory('lib');
|
|
|
|
|
libDir.createSync(recursive: true);
|
|
|
|
|
|
|
|
|
|
final File mainFile = libDir.childFile('main.dart');
|
|
|
|
|
mainFile.writeAsStringSync('''
|
|
|
|
|
// @dart = 2.8
|
|
|
|
|
void main() {
|
|
|
|
|
}
|
|
|
|
|
''');
|
|
|
|
|
final File flutterBuild = flutterProject.directory.childFile('generated_main.dart');
|
|
|
|
|
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
|
|
|
|
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json'),
|
|
|
|
|
logger: globals.logger,
|
|
|
|
|
throwOnError: false,
|
|
|
|
|
);
|
|
|
|
|
final bool didGenerate = await generateMainDartWithPluginRegistrant(
|
|
|
|
|
flutterProject,
|
|
|
|
|
packageConfig,
|
|
|
|
|
'package:app/main.dart',
|
|
|
|
|
flutterBuild,
|
|
|
|
|
mainFile,
|
|
|
|
|
);
|
|
|
|
|
expect(didGenerate, isTrue);
|
|
|
|
|
expect(flutterBuild.readAsStringSync(),
|
|
|
|
|
'//\n'
|
|
|
|
|
'// Generated file. Do not edit.\n'
|
|
|
|
|
'//\n'
|
|
|
|
|
'\n'
|
|
|
|
|
'// @dart = 2.8\n'
|
|
|
|
|
'\n'
|
|
|
|
|
'import \'package:app/main.dart\' as entrypoint;\n'
|
|
|
|
|
'import \'dart:io\'; // ignore: dart_io_import.\n'
|
|
|
|
|
'import \'package:url_launcher_linux${fs.path.separator}url_launcher_linux.dart\';\n'
|
|
|
|
|
'import \'package:awesome_macos/awesome_macos.dart\';\n'
|
|
|
|
|
'import \'package:url_launcher_macos${fs.path.separator}url_launcher_macos.dart\';\n'
|
|
|
|
|
'import \'package:url_launcher_windows${fs.path.separator}url_launcher_windows.dart\';\n'
|
|
|
|
|
'\n'
|
|
|
|
|
'@pragma(\'vm:entry-point\')\n'
|
|
|
|
|
'void _registerPlugins() {\n'
|
|
|
|
|
' if (Platform.isLinux) {\n'
|
|
|
|
|
' LinuxPlugin.registerWith();\n'
|
|
|
|
|
' } else if (Platform.isMacOS) {\n'
|
|
|
|
|
' AwesomeMacOS.registerWith();\n'
|
|
|
|
|
' MacOSPlugin.registerWith();\n'
|
|
|
|
|
' } else if (Platform.isWindows) {\n'
|
|
|
|
|
' WindowsPlugin.registerWith();\n'
|
|
|
|
|
' }\n'
|
|
|
|
|
'}\n'
|
|
|
|
|
'void main() {\n'
|
|
|
|
|
' entrypoint.main();\n'
|
|
|
|
|
'}\n'
|
|
|
|
|
'',
|
|
|
|
|
);
|
|
|
|
|
}, overrides: <Type, Generator>{
|
|
|
|
|
FileSystem: () => fs,
|
|
|
|
|
ProcessManager: () => FakeProcessManager.any(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
testUsingContext('Plugin without platform support throws tool exit', () async {
|
|
|
|
|
when(flutterProject.isModule).thenReturn(false);
|
|
|
|
|
|
|
|
|
|
final List<Directory> directories = <Directory>[];
|
|
|
|
|
final Directory fakePubCache = fs.systemTempDirectory.childDirectory('cache');
|
|
|
|
|
final File packagesFile = flutterProject.directory
|
|
|
|
|
.childFile('.packages')
|
|
|
|
|
..createSync(recursive: true);
|
|
|
|
|
final Map<String, String> plugins = <String, String>{};
|
|
|
|
|
plugins['url_launcher_macos'] = '''
|
|
|
|
|
flutter:
|
|
|
|
|
plugin:
|
|
|
|
|
implements: url_launcher
|
|
|
|
|
platforms:
|
|
|
|
|
macos:
|
|
|
|
|
invalid:
|
|
|
|
|
''';
|
|
|
|
|
for (final MapEntry<String, String> entry in plugins.entries) {
|
|
|
|
|
final String name = fs.path.basename(entry.key);
|
|
|
|
|
final Directory pluginDirectory = fakePubCache.childDirectory(name);
|
|
|
|
|
packagesFile.writeAsStringSync(
|
|
|
|
|
'$name:file://${pluginDirectory.childFile('lib').uri}\n',
|
|
|
|
|
mode: FileMode.writeOnlyAppend);
|
|
|
|
|
pluginDirectory.childFile('pubspec.yaml')
|
|
|
|
|
..createSync(recursive: true)
|
|
|
|
|
..writeAsStringSync(entry.value);
|
|
|
|
|
directories.add(pluginDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
when(flutterManifest.dependencies).thenReturn(<String>{...plugins.keys});
|
|
|
|
|
|
|
|
|
|
final Directory libDir = flutterProject.directory.childDirectory('lib');
|
|
|
|
|
libDir.createSync(recursive: true);
|
|
|
|
|
|
|
|
|
|
final File mainFile = libDir.childFile('main.dart')..writeAsStringSync('');
|
|
|
|
|
final File flutterBuild = flutterProject.directory.childFile('generated_main.dart');
|
|
|
|
|
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
|
|
|
|
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json'),
|
|
|
|
|
logger: globals.logger,
|
|
|
|
|
throwOnError: false,
|
|
|
|
|
);
|
|
|
|
|
await expectLater(
|
|
|
|
|
generateMainDartWithPluginRegistrant(
|
|
|
|
|
flutterProject,
|
|
|
|
|
packageConfig,
|
|
|
|
|
'package:app/main.dart',
|
|
|
|
|
flutterBuild,
|
|
|
|
|
mainFile,
|
|
|
|
|
), throwsToolExit(message:
|
|
|
|
|
'Invalid plugin specification url_launcher_macos.\n'
|
|
|
|
|
'Invalid "macos" plugin specification.'
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}, overrides: <Type, Generator>{
|
|
|
|
|
FileSystem: () => fs,
|
|
|
|
|
ProcessManager: () => FakeProcessManager.any(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
testUsingContext('Plugin with platform support without dart plugin class throws tool exit', () async {
|
|
|
|
|
when(flutterProject.isModule).thenReturn(false);
|
|
|
|
|
|
|
|
|
|
final List<Directory> directories = <Directory>[];
|
|
|
|
|
final Directory fakePubCache = fs.systemTempDirectory.childDirectory('cache');
|
|
|
|
|
final File packagesFile = flutterProject.directory
|
|
|
|
|
.childFile('.packages')
|
|
|
|
|
..createSync(recursive: true);
|
|
|
|
|
final Map<String, String> plugins = <String, String>{};
|
|
|
|
|
plugins['url_launcher_macos'] = '''
|
|
|
|
|
flutter:
|
|
|
|
|
plugin:
|
|
|
|
|
implements: url_launcher
|
|
|
|
|
''';
|
|
|
|
|
for (final MapEntry<String, String> entry in plugins.entries) {
|
|
|
|
|
final String name = fs.path.basename(entry.key);
|
|
|
|
|
final Directory pluginDirectory = fakePubCache.childDirectory(name);
|
|
|
|
|
packagesFile.writeAsStringSync(
|
|
|
|
|
'$name:file://${pluginDirectory.childFile('lib').uri}\n',
|
|
|
|
|
mode: FileMode.writeOnlyAppend);
|
|
|
|
|
pluginDirectory.childFile('pubspec.yaml')
|
|
|
|
|
..createSync(recursive: true)
|
|
|
|
|
..writeAsStringSync(entry.value);
|
|
|
|
|
directories.add(pluginDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
when(flutterManifest.dependencies).thenReturn(<String>{...plugins.keys});
|
|
|
|
|
|
|
|
|
|
final Directory libDir = flutterProject.directory.childDirectory('lib');
|
|
|
|
|
libDir.createSync(recursive: true);
|
|
|
|
|
|
|
|
|
|
final File mainFile = libDir.childFile('main.dart')..writeAsStringSync('');
|
|
|
|
|
final File flutterBuild = flutterProject.directory.childFile('generated_main.dart');
|
|
|
|
|
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
|
|
|
|
flutterProject.directory.childDirectory('.dart_tool').childFile('package_config.json'),
|
|
|
|
|
logger: globals.logger,
|
|
|
|
|
throwOnError: false,
|
|
|
|
|
);
|
|
|
|
|
await expectLater(
|
|
|
|
|
generateMainDartWithPluginRegistrant(
|
|
|
|
|
flutterProject,
|
|
|
|
|
packageConfig,
|
|
|
|
|
'package:app/main.dart',
|
|
|
|
|
flutterBuild,
|
|
|
|
|
mainFile,
|
|
|
|
|
), throwsToolExit(message:
|
|
|
|
|
'Invalid plugin specification url_launcher_macos.\n'
|
|
|
|
|
'Cannot find the `flutter.plugin.platforms` key in the `pubspec.yaml` file. '
|
|
|
|
|
'An instruction to format the `pubspec.yaml` can be found here: '
|
|
|
|
|
'https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms'
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}, overrides: <Type, Generator>{
|
|
|
|
|
FileSystem: () => fs,
|
|
|
|
|
ProcessManager: () => FakeProcessManager.any(),
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group('pubspec', () {
|
|
|
|
|
|
|
|
|
|
Directory projectDir;
|
|
|
|
|
@@ -1396,6 +2167,7 @@ flutter:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MockAndroidProject extends Mock implements AndroidProject {}
|
|
|
|
|
class MockFlutterManifest extends Mock implements FlutterManifest {}
|
|
|
|
|
class MockFlutterProject extends Mock implements FlutterProject {}
|
|
|
|
|
class MockIosProject extends Mock implements IosProject {}
|
|
|
|
|
class MockMacOSProject extends Mock implements MacOSProject {}
|
|
|
|
|
|