@@ -119,81 +119,88 @@ class TizenPlugin extends PluginPlatform implements NativeOrDartPlugin {
119
119
}
120
120
}
121
121
122
+ // TODO: Rename this mixin.
122
123
/// Any [FlutterCommand] that invokes [usesPubOption] or [targetFile] should
123
124
/// depend on this mixin to ensure plugins are correctly configured for Tizen.
124
125
///
125
126
/// See: [FlutterCommand.verifyThenRunCommand] in `flutter_command.dart`
126
127
mixin DartPluginRegistry on FlutterCommand {
127
- String _entrypoint;
128
-
129
- bool get _usesTargetOption => argParser.options.containsKey ('target' );
130
-
131
128
@override
132
129
Future <FlutterCommandResult > verifyThenRunCommand (String commandPath) async {
133
130
if (super .shouldRunPub) {
134
131
// TODO(swift-kim): Should run pub get first before injecting plugins.
135
132
await ensureReadyForTizenTooling (FlutterProject .current ());
136
133
}
137
- if (_usesTargetOption) {
138
- _entrypoint =
139
- await _createEntrypoint (FlutterProject .current (), super .targetFile);
140
- }
141
134
return super .verifyThenRunCommand (commandPath);
142
135
}
143
-
144
- @override
145
- String get targetFile => _entrypoint ?? super .targetFile;
146
136
}
147
137
148
- /// Creates an entrypoint wrapper of [targetFile] and returns its path.
149
- /// This effectively adds support for Dart plugins.
150
- ///
151
- /// Source: [WebEntrypointTarget.build] in `web.dart`
152
- Future <String > _createEntrypoint (
153
- FlutterProject project, String targetFile) async {
154
- final List <TizenPlugin > dartPlugins =
155
- await findTizenPlugins (project, dartOnly: true );
156
- if (dartPlugins.isEmpty) {
157
- return targetFile;
158
- }
159
-
160
- final TizenProject tizenProject = TizenProject .fromFlutter (project);
161
- if (! tizenProject.existsSync ()) {
162
- return targetFile;
138
+ /// Source: [generateMainDartWithPluginRegistrant] in `flutter_plugins.dart`
139
+ void createEntrypointWithPluginRegistrant (
140
+ List <TizenPlugin > plugins,
141
+ PackageConfig packageConfig,
142
+ String currentMainUri,
143
+ File newMainDart,
144
+ File mainFile,
145
+ ) {
146
+ if (plugins.isEmpty) {
147
+ try {
148
+ if (newMainDart.existsSync ()) {
149
+ newMainDart.deleteSync ();
150
+ }
151
+ } on FileSystemException catch (error) {
152
+ globals.printError (
153
+ 'Unable to remove ${newMainDart .path }, received error: $error .\n '
154
+ 'You might need to run flutter-tizen clean.' );
155
+ rethrow ;
156
+ }
157
+ return ;
163
158
}
164
-
165
- final File entrypoint = tizenProject.managedDirectory.childFile ('main.dart' )
166
- ..createSync (recursive: true );
167
- final PackageConfig packageConfig = await loadPackageConfigWithLogging (
168
- project.directory.childFile ('.packages' ),
169
- logger: globals.logger,
170
- );
171
- final FlutterProject flutterProject = FlutterProject .current ();
172
- final LanguageVersion languageVersion = determineLanguageVersion (
173
- globals.fs.file (targetFile),
174
- packageConfig[flutterProject.manifest.appName],
159
+ final LanguageVersion entrypointVersion = determineLanguageVersion (
160
+ mainFile,
161
+ packageConfig.packageOf (mainFile.absolute.uri),
175
162
Cache .flutterRoot,
176
163
);
177
-
178
- final Uri mainUri = globals.fs.file (targetFile).absolute.uri;
179
- final String mainImport =
180
- packageConfig.toPackageUri (mainUri)? .toString () ?? mainUri.toString ();
181
-
182
- entrypoint.writeAsStringSync ('''
164
+ final List <Map <String , dynamic >> pluginConfigs =
165
+ plugins.map ((TizenPlugin plugin) => plugin.toMap ()).toList ();
166
+ // TODO: Consider using PluginInterfaceResolution and implementing resolvePlatformImplementation().
167
+ final Map <String , dynamic > templateContext = < String , dynamic > {
168
+ 'mainEntrypoint' : currentMainUri,
169
+ 'dartLanguageVersion' : entrypointVersion.toString (),
170
+ 'plugins' : pluginConfigs,
171
+ };
172
+ try {
173
+ _renderTemplateToFile (
174
+ '''
183
175
//
184
176
// Generated file. Do not edit.
185
177
//
186
- // @dart=${ languageVersion . major }.${ languageVersion . minor }
178
+ // @dart = {{dartLanguageVersion} }
187
179
188
- import '$mainImport ' as entrypoint;
189
- import 'generated_plugin_registrant.dart';
180
+ import '{{mainEntrypoint}}' as entrypoint;
181
+ {{#plugins}}
182
+ import 'package:{{name}}/{{name}}.dart';
183
+ {{/plugins}}
184
+
185
+ void registerPlugins() {
186
+ {{#plugins}}
187
+ {{dartPluginClass}}.register();
188
+ {{/plugins}}
189
+ }
190
190
191
191
Future<void> main() async {
192
192
registerPlugins();
193
193
entrypoint.main();
194
194
}
195
- ''' );
196
- return entrypoint.path;
195
+ ''' ,
196
+ templateContext,
197
+ newMainDart.path,
198
+ );
199
+ } on FileSystemException catch (error) {
200
+ globals.printError (
201
+ 'Unable to write ${newMainDart .path }, received error: $error ' );
202
+ rethrow ;
203
+ }
197
204
}
198
205
199
206
/// https://github.com/flutter-tizen/plugins
@@ -239,18 +246,16 @@ Future<void> ensureReadyForTizenTooling(FlutterProject project) async {
239
246
final TizenProject tizenProject = TizenProject .fromFlutter (project);
240
247
await tizenProject.ensureReadyForPlatformSpecificTooling ();
241
248
249
+ // TODO(swift-kim): Consider renaming the function.
242
250
await injectTizenPlugins (project);
243
251
}
244
252
245
253
/// See: [injectPlugins] in `plugins.dart`
246
254
Future <void > injectTizenPlugins (FlutterProject project) async {
247
255
final TizenProject tizenProject = TizenProject .fromFlutter (project);
248
256
if (tizenProject.existsSync ()) {
249
- final List <TizenPlugin > dartPlugins =
250
- await findTizenPlugins (project, dartOnly: true );
251
257
final List <TizenPlugin > nativePlugins =
252
258
await findTizenPlugins (project, nativeOnly: true );
253
- _writeDartPluginRegistrant (tizenProject.managedDirectory, dartPlugins);
254
259
_writeCppPluginRegistrant (tizenProject.managedDirectory, nativePlugins);
255
260
_writeCsharpPluginRegistrant (tizenProject.managedDirectory, nativePlugins);
256
261
}
@@ -337,40 +342,6 @@ TizenPlugin _pluginFromPackage(String name, Uri packageRoot) {
337
342
);
338
343
}
339
344
340
- /// See: [_writeWebPluginRegistrant] in `plugins.dart`
341
- void _writeDartPluginRegistrant (
342
- Directory registryDirectory,
343
- List <TizenPlugin > plugins,
344
- ) {
345
- final List <Map <String , dynamic >> pluginConfigs =
346
- plugins.map ((TizenPlugin plugin) => plugin.toMap ()).toList ();
347
- final Map <String , dynamic > context = < String , dynamic > {
348
- 'plugins' : pluginConfigs,
349
- };
350
- _renderTemplateToFile (
351
- '''
352
- //
353
- // Generated file. Do not edit.
354
- //
355
-
356
- // ignore_for_file: lines_longer_than_80_chars
357
-
358
- {{#plugins}}
359
- import 'package:{{name}}/{{name}}.dart';
360
- {{/plugins}}
361
-
362
- // ignore: public_member_api_docs
363
- void registerPlugins() {
364
- {{#plugins}}
365
- {{dartPluginClass}}.register();
366
- {{/plugins}}
367
- }
368
- ''' ,
369
- context,
370
- registryDirectory.childFile ('generated_plugin_registrant.dart' ).path,
371
- );
372
- }
373
-
374
345
/// See: [_writeWindowsPluginFiles] in `plugins.dart`
375
346
void _writeCppPluginRegistrant (
376
347
Directory registryDirectory,
0 commit comments