"Fossies" - the Fresh Open Source Software Archive

Member "flutter-1.22.4/packages/flutter_tools/lib/src/ios/plist_parser.dart" (13 Nov 2020, 2854 Bytes) of package /linux/misc/flutter-1.22.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Dart source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Copyright 2014 The Flutter Authors. All rights reserved.
    2 // Use of this source code is governed by a BSD-style license that can be
    3 // found in the LICENSE file.
    4 
    5 import 'package:meta/meta.dart';
    6 import 'package:process/process.dart';
    7 
    8 import '../base/file_system.dart';
    9 import '../base/io.dart';
   10 import '../base/logger.dart';
   11 import '../base/process.dart';
   12 import '../base/utils.dart';
   13 import '../convert.dart';
   14 
   15 class PlistParser {
   16   PlistParser({
   17     @required FileSystem fileSystem,
   18     @required Logger logger,
   19     @required ProcessManager processManager,
   20   }) : _fileSystem = fileSystem,
   21        _logger = logger,
   22        _processUtils = ProcessUtils(logger: logger, processManager: processManager);
   23 
   24   final FileSystem _fileSystem;
   25   final Logger _logger;
   26   final ProcessUtils _processUtils;
   27 
   28   static const String kCFBundleIdentifierKey = 'CFBundleIdentifier';
   29   static const String kCFBundleShortVersionStringKey = 'CFBundleShortVersionString';
   30   static const String kCFBundleExecutable = 'CFBundleExecutable';
   31 
   32   /// Parses the plist file located at [plistFilePath] and returns the
   33   /// associated map of key/value property list pairs.
   34   ///
   35   /// If [plistFilePath] points to a non-existent file or a file that's not a
   36   /// valid property list file, this will return an empty map.
   37   ///
   38   /// The [plistFilePath] argument must not be null.
   39   Map<String, dynamic> parseFile(String plistFilePath) {
   40     assert(plistFilePath != null);
   41     const String executable = '/usr/bin/plutil';
   42     if (!_fileSystem.isFileSync(executable)) {
   43       throw const FileNotFoundException(executable);
   44     }
   45     if (!_fileSystem.isFileSync(plistFilePath)) {
   46       return const <String, dynamic>{};
   47     }
   48 
   49     final String normalizedPlistPath = _fileSystem.path.absolute(plistFilePath);
   50 
   51     try {
   52       final List<String> args = <String>[
   53         executable, '-convert', 'json', '-o', '-', normalizedPlistPath,
   54       ];
   55       final String jsonContent = _processUtils.runSync(
   56         args,
   57         throwOnError: true,
   58       ).stdout.trim();
   59       return castStringKeyedMap(json.decode(jsonContent));
   60     } on ProcessException catch (error) {
   61       _logger.printTrace('$error');
   62       return const <String, dynamic>{};
   63     }
   64   }
   65 
   66   /// Parses the Plist file located at [plistFilePath] and returns the value
   67   /// that's associated with the specified [key] within the property list.
   68   ///
   69   /// If [plistFilePath] points to a non-existent file or a file that's not a
   70   /// valid property list file, this will return null.
   71   ///
   72   /// If [key] is not found in the property list, this will return null.
   73   ///
   74   /// The [plistFilePath] and [key] arguments must not be null.
   75   String getValueFromFile(String plistFilePath, String key) {
   76     assert(key != null);
   77     final Map<String, dynamic> parsed = parseFile(plistFilePath);
   78     return parsed[key] as String;
   79   }
   80 }