Skip to content

Conversation

@chingjun
Copy link
Contributor

@chingjun chingjun commented Dec 8, 2021

Parse the Plist in XML format instead of JSON so that it can accept data that is not representable in JSON.

Move the part that reads the plist file content to a separate method so that it can be overridden to use a different tool other than plutil (which is Mac only).

Rename getValueFromFile to getStringValueFromFile now that we have the ability to read value of any type from the plist file.

Fixes #62160

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@chingjun chingjun requested a review from jmagman December 8, 2021 14:55
@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Dec 8, 2021
Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I swear I tried this a few years ago and hit some road block, but now I can't remember the details. Glad you're tackling it.

return _parseXml(xmlContent);
}

Map<String, dynamic> _parseXml(String xmlContent) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you convert all the dynamics in this file to Object or Object? while you're here? It was missed in the null safety migration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/// valid property list file, this will return null.
///
/// The [plistFilePath] argument must not be null.
String? plistXmlContent(String plistFilePath) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is used outside this library.

Suggested change
String? plistXmlContent(String plistFilePath) {
String? _plistXmlContent(String plistFilePath) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually intend to override this internally to use plistutil so that PlistParser can be used on Linux.

///
/// The [plistFilePath] and [key] arguments must not be null.
String? getValueFromFile(String plistFilePath, String key) {
dynamic getValueFromFile(String plistFilePath, String key) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handles all the valid plist xml types, but is not used except in getStringValueFromFile. Will it be used for something other than strings in g3? If not, we could get rid of this method and make getStringValueFromFile call:

plutil -extract $key raw -expect string $plistFilePath

instead of parsing the whole file. And we can implement other types as needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be used for something other than strings in g3?

No. My intention is only to replace plutil (mac only) with plistutil (runs on linux).

If not, we could get rid of this method and make getStringValueFromFile call:
plutil -extract $key raw -expect string $plistFilePath
instead of parsing the whole file.

Getting rid of this method SGTM.

About calling plutil -extract for getStringValueFromFile, we already need to call plutil -convert for parseFile. I personally think it would be a better idea to consolidate the call to external tool in a single place, and plist files are generally small and parsing it is usually fast.

I've removed getValueFromFile and changed getStringValueFromFile to return parseFile(plistFilePath)[key] as String?. Do let me know if you still think we should use plutil -extract for getStringValueFromFile.

Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it's a cheap operation. Let's keep it simple for the g3 case.

Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chingjun chingjun merged commit 8186fb7 into flutter:master Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider using xml parser instead of json for parsing plist

2 participants