7
7
import 'dart:io' ;
8
8
9
9
import 'package:file/file.dart' ;
10
+ import 'package:flutter_tools/src/android/android_sdk.dart' ;
10
11
import 'package:flutter_tools/src/android/application_package.dart' ;
11
12
import 'package:flutter_tools/src/application_package.dart' ;
12
- import 'package:flutter_tools/src/flutter_application_package.dart' ;
13
13
import 'package:flutter_tools/src/base/common.dart' ;
14
+ import 'package:flutter_tools/src/base/logger.dart' ;
14
15
import 'package:flutter_tools/src/base/terminal.dart' ;
16
+ import 'package:flutter_tools/src/base/user_messages.dart' ;
15
17
import 'package:flutter_tools/src/build_info.dart' ;
18
+ import 'package:flutter_tools/src/flutter_application_package.dart' ;
16
19
import 'package:flutter_tools/src/globals.dart' as globals;
17
20
import 'package:flutter_tools/src/project.dart' ;
18
21
import 'package:meta/meta.dart' ;
22
+ import 'package:process/process.dart' ;
19
23
import 'package:xml/xml.dart' ;
20
24
21
25
import 'tizen_project.dart' ;
22
26
23
27
/// [FlutterApplicationPackageFactory] extended for Tizen.
24
28
class TizenApplicationPackageFactory extends FlutterApplicationPackageFactory {
25
- TizenApplicationPackageFactory ()
26
- : super (
27
- androidSdk: globals.androidSdk,
28
- processManager: globals.processManager,
29
- logger: globals.logger,
30
- userMessages: globals.userMessages,
31
- fileSystem: globals.fs,
29
+ TizenApplicationPackageFactory ({
30
+ @required AndroidSdk androidSdk,
31
+ @required ProcessManager processManager,
32
+ @required Logger logger,
33
+ @required UserMessages userMessages,
34
+ @required FileSystem fileSystem,
35
+ }) : super (
36
+ androidSdk: androidSdk,
37
+ processManager: processManager,
38
+ logger: logger,
39
+ userMessages: userMessages,
40
+ fileSystem: fileSystem,
32
41
);
33
42
34
43
@override
@@ -39,7 +48,7 @@ class TizenApplicationPackageFactory extends FlutterApplicationPackageFactory {
39
48
}) async {
40
49
if (platform == TargetPlatform .tester) {
41
50
return applicationBinary == null
42
- ? await TizenTpk .fromTizenProject (FlutterProject .current ())
51
+ ? await TizenTpk .fromProject (FlutterProject .current ())
43
52
: await TizenTpk .fromTpk (applicationBinary);
44
53
}
45
54
return super .getPackageForPlatform (platform,
@@ -54,7 +63,8 @@ class TizenTpk extends ApplicationPackage {
54
63
@required this .manifest,
55
64
this .signature,
56
65
}) : assert (file != null ),
57
- super (id: manifest? .packageId);
66
+ assert (manifest != null ),
67
+ super (id: manifest.packageId);
58
68
59
69
static Future <TizenTpk > fromTpk (File tpkFile) async {
60
70
final Directory tempDir = globals.fs.systemTempDirectory.createTempSync ();
@@ -86,8 +96,7 @@ class TizenTpk extends ApplicationPackage {
86
96
);
87
97
}
88
98
89
- static Future <TizenTpk > fromTizenProject (
90
- FlutterProject flutterProject) async {
99
+ static Future <TizenTpk > fromProject (FlutterProject flutterProject) async {
91
100
final TizenProject project = TizenProject .fromFlutter (flutterProject);
92
101
93
102
final File tpkFile = flutterProject.directory
@@ -115,7 +124,7 @@ class TizenTpk extends ApplicationPackage {
115
124
final Signature signature;
116
125
117
126
/// The application id if applicable.
118
- String get applicationId => manifest? .applicationId;
127
+ String get applicationId => manifest.applicationId;
119
128
120
129
@override
121
130
String get name => file.basename;
@@ -134,7 +143,7 @@ class TizenTpk extends ApplicationPackage {
134
143
class TizenManifest {
135
144
TizenManifest (this ._document) : applicationId = _findApplicationId (_document);
136
145
137
- factory TizenManifest . parseFromXml (File xmlFile) {
146
+ static TizenManifest parseFromXml (File xmlFile) {
138
147
if (xmlFile == null || ! xmlFile.existsSync ()) {
139
148
throwToolExit ('tizen-manifest.xml could not be found.' );
140
149
}
@@ -164,7 +173,7 @@ class TizenManifest {
164
173
set version (String value) => _manifest.setAttribute ('version' , value);
165
174
166
175
/// The target API version number.
167
- String get apiVersion => _manifest.getAttribute ('api-version' );
176
+ String get apiVersion => _manifest.getAttribute ('api-version' ) ?? '4.0' ;
168
177
169
178
XmlElement get _profile {
170
179
if (_manifest.findElements ('profile' ).isEmpty) {
@@ -198,7 +207,7 @@ class TizenManifest {
198
207
}
199
208
if (applicationId == null ) {
200
209
throwToolExit ('Found no *-application element with appid attribute'
201
- ' in tizen-manifest.xml' );
210
+ ' in tizen-manifest.xml. ' );
202
211
}
203
212
if (! _warningShown) {
204
213
if (count > 1 ) {
@@ -220,7 +229,7 @@ class TizenManifest {
220
229
return applicationId;
221
230
}
222
231
223
- /// To prevent spamming log with warnings, remember they have been shown
232
+ /// To prevent spamming log with warnings, remember they have been shown.
224
233
static bool _warningShown = false ;
225
234
226
235
@override
@@ -231,7 +240,7 @@ class TizenManifest {
231
240
class Signature {
232
241
const Signature (this ._document);
233
242
234
- factory Signature . parseFromXml (File xmlFile) {
243
+ static Signature parseFromXml (File xmlFile) {
235
244
if (xmlFile == null || ! xmlFile.existsSync ()) {
236
245
return null ;
237
246
}
@@ -245,10 +254,7 @@ class Signature {
245
254
try {
246
255
document = XmlDocument .parse (data);
247
256
} on XmlException catch (ex) {
248
- globals.printStatus (
249
- 'Warning: Failed to parse ${xmlFile .basename }: $ex ' ,
250
- color: TerminalColor .yellow,
251
- );
257
+ globals.printError ('Failed to parse ${xmlFile .basename }: $ex ' );
252
258
return null ;
253
259
}
254
260
return Signature (document);
@@ -265,81 +271,10 @@ class Signature {
265
271
}
266
272
}
267
273
268
- class Certificate {
269
- Certificate ._({
270
- @required this .key,
271
- @required this .password,
272
- @required this .distributorNumber,
273
- @required this .ca,
274
- });
275
-
276
- factory Certificate .parseFromXmlElement (XmlElement profileItem) {
277
- final String ca = profileItem.getAttribute ('ca' );
278
- final String key = profileItem.getAttribute ('key' );
279
- final String password = profileItem.getAttribute ('password' );
280
- final String distributorNumber = profileItem.getAttribute ('distributor' );
281
-
282
- // The data doesn't exist and the xml element exists only as a placeholder.
283
- if (key.isEmpty || password.isEmpty) {
284
- return null ;
285
- }
286
-
287
- return Certificate ._(
288
- key: key,
289
- password: password,
290
- distributorNumber: distributorNumber,
291
- ca: ca,
292
- );
293
- }
294
-
295
- final String key;
296
- final String password;
297
- final String distributorNumber;
298
- final String ca;
299
- }
300
-
301
- class SecurityProfile {
302
- SecurityProfile (
303
- this .name, {
304
- @required this .authorCertificate,
305
- @required this .distributorCertificates,
306
- });
307
-
308
- factory SecurityProfile .parseFromXmlElement (XmlElement profile) {
309
- Certificate authorCertificate;
310
- final List <Certificate > distributorCertificates = < Certificate > [];
311
-
312
- // The element that holds a single certifcate key, password pair
313
- for (final XmlElement profileItem
314
- in profile.findAllElements ('profileitem' )) {
315
- final Certificate certificate =
316
- Certificate .parseFromXmlElement (profileItem);
317
- if (certificate != null ) {
318
- // distributor number 0 specifies an author certificate
319
- if (certificate.distributorNumber == '0' ) {
320
- authorCertificate = certificate;
321
- } else {
322
- distributorCertificates.add (certificate);
323
- }
324
- }
325
- }
326
-
327
- return SecurityProfile (
328
- profile.getAttribute ('name' ),
329
- authorCertificate: authorCertificate,
330
- distributorCertificates: distributorCertificates,
331
- );
332
- }
333
-
334
- final String name;
335
- final Certificate authorCertificate;
336
- final List <Certificate > distributorCertificates;
337
- }
338
-
339
274
class SecurityProfiles {
340
- SecurityProfiles ._(this .active, this ._profiles );
275
+ SecurityProfiles ._(this .profiles, { @required this .active} );
341
276
342
- factory SecurityProfiles . parseFromXml (File xmlFile) {
277
+ static SecurityProfiles parseFromXml (File xmlFile) {
343
278
if (xmlFile == null || ! xmlFile.existsSync ()) {
344
279
return null ;
345
280
}
@@ -353,37 +288,29 @@ class SecurityProfiles {
353
288
try {
354
289
document = XmlDocument .parse (data);
355
290
} on XmlException catch (ex) {
356
- throwToolExit ('Failed to parse ${xmlFile .basename }: $ex ' );
291
+ globals.printError ('Failed to parse ${xmlFile .basename }: $ex ' );
292
+ return null ;
357
293
}
358
294
359
- final String activeName = document.rootElement.getAttribute ('active' );
360
-
361
- SecurityProfile activeProfile ;
362
- final List < SecurityProfile > profiles = < SecurityProfile > [];
295
+ String active = document.rootElement.getAttribute ('active' );
296
+ if (active != null && active.isEmpty) {
297
+ active = null ;
298
+ }
363
299
364
- for (final XmlElement profileXml
300
+ final List <String > profiles = < String > [];
301
+ for (final XmlElement profile
365
302
in document.rootElement.findAllElements ('profile' )) {
366
- final SecurityProfile profile =
367
- SecurityProfile .parseFromXmlElement (profileXml);
368
- profiles.add (profile);
369
- if (profile.name == activeName) {
370
- activeProfile = profile;
303
+ final String name = profile.getAttribute ('name' );
304
+ if (name != null ) {
305
+ profiles.add (name);
371
306
}
372
307
}
373
308
374
- return SecurityProfiles ._(activeProfile, profiles );
309
+ return SecurityProfiles ._(profiles, active : active );
375
310
}
376
311
377
- final SecurityProfile active ;
378
- final List < SecurityProfile > _profiles ;
312
+ final List < String > profiles ;
313
+ final String active ;
379
314
380
- List <String > get names =>
381
- _profiles.map ((SecurityProfile profile) => profile.name).toList ();
382
-
383
- SecurityProfile getProfile (String name) {
384
- return _profiles.firstWhere (
385
- (SecurityProfile profile) => profile.name == name,
386
- orElse: () => null ,
387
- );
388
- }
315
+ bool contains (String name) => profiles.contains (name);
389
316
}
0 commit comments