Unverified Commit 5398c34c authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate flutter_project_metadata to null safety (#78944)

parent 63d6ec56
...@@ -2,11 +2,8 @@ ...@@ -2,11 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:meta/meta.dart';
import 'package:package_config/package_config.dart'; import 'package:package_config/package_config.dart';
import '../base/common.dart'; import '../base/common.dart';
...@@ -19,14 +16,14 @@ import '../base/logger.dart'; ...@@ -19,14 +16,14 @@ import '../base/logger.dart';
/// If [throwOnError] is false, in the event of an error an empty package /// If [throwOnError] is false, in the event of an error an empty package
/// config is returned. /// config is returned.
Future<PackageConfig> loadPackageConfigWithLogging(File file, { Future<PackageConfig> loadPackageConfigWithLogging(File file, {
@required Logger logger, required Logger logger,
bool throwOnError = true, bool throwOnError = true,
}) async { }) async {
final FileSystem fileSystem = file.fileSystem; final FileSystem fileSystem = file.fileSystem;
bool didError = false; bool didError = false;
final PackageConfig result = await loadPackageConfigUri( final PackageConfig result = await loadPackageConfigUri(
file.absolute.uri, file.absolute.uri,
loader: (Uri uri) { loader: (Uri uri) async {
final File configFile = fileSystem.file(uri); final File configFile = fileSystem.file(uri);
if (!configFile.existsSync()) { if (!configFile.existsSync()) {
return null; return null;
...@@ -50,7 +47,7 @@ Future<PackageConfig> loadPackageConfigWithLogging(File file, { ...@@ -50,7 +47,7 @@ Future<PackageConfig> loadPackageConfigWithLogging(File file, {
} }
); );
if (didError) { if (didError) {
throwToolExit(null); throwToolExit('');
} }
return result; return result;
} }
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:yaml/yaml.dart'; import 'package:yaml/yaml.dart';
import 'base/file_system.dart'; import 'base/file_system.dart';
...@@ -29,8 +27,8 @@ String flutterProjectTypeToString(FlutterProjectType type) { ...@@ -29,8 +27,8 @@ String flutterProjectTypeToString(FlutterProjectType type) {
return getEnumName(type); return getEnumName(type);
} }
FlutterProjectType stringToProjectType(String value) { FlutterProjectType? stringToProjectType(String value) {
FlutterProjectType result; FlutterProjectType? result;
for (final FlutterProjectType type in FlutterProjectType.values) { for (final FlutterProjectType type in FlutterProjectType.values) {
if (value == flutterProjectTypeToString(type)) { if (value == flutterProjectTypeToString(type)) {
result = type; result = type;
...@@ -51,10 +49,10 @@ class FlutterProjectMetadata { ...@@ -51,10 +49,10 @@ class FlutterProjectMetadata {
final File _metadataFile; final File _metadataFile;
final Logger _logger; final Logger _logger;
String get versionChannel => _versionValue('channel'); String? get versionChannel => _versionValue('channel');
String get versionRevision => _versionValue('revision'); String? get versionRevision => _versionValue('revision');
FlutterProjectType get projectType { FlutterProjectType? get projectType {
final dynamic projectTypeYaml = _metadataValue('project_type'); final dynamic projectTypeYaml = _metadataValue('project_type');
if (projectTypeYaml is String) { if (projectTypeYaml is String) {
return stringToProjectType(projectTypeYaml); return stringToProjectType(projectTypeYaml);
...@@ -64,8 +62,8 @@ class FlutterProjectMetadata { ...@@ -64,8 +62,8 @@ class FlutterProjectMetadata {
} }
} }
YamlMap _versionYaml; YamlMap? _versionYaml;
String _versionValue(String key) { String? _versionValue(String key) {
if (_versionYaml == null) { if (_versionYaml == null) {
final dynamic versionYaml = _metadataValue('version'); final dynamic versionYaml = _metadataValue('version');
if (versionYaml is YamlMap) { if (versionYaml is YamlMap) {
...@@ -75,13 +73,13 @@ class FlutterProjectMetadata { ...@@ -75,13 +73,13 @@ class FlutterProjectMetadata {
return null; return null;
} }
} }
if (_versionYaml != null && _versionYaml.containsKey(key) && _versionYaml[key] is String) { if (_versionYaml != null && _versionYaml!.containsKey(key) && _versionYaml![key] is String) {
return _versionYaml[key] as String; return _versionYaml![key] as String;
} }
return null; return null;
} }
YamlMap _metadataYaml; YamlMap? _metadataYaml;
dynamic _metadataValue(String key) { dynamic _metadataValue(String key) {
if (_metadataYaml == null) { if (_metadataYaml == null) {
if (!_metadataFile.existsSync()) { if (!_metadataFile.existsSync()) {
...@@ -101,6 +99,6 @@ class FlutterProjectMetadata { ...@@ -101,6 +99,6 @@ class FlutterProjectMetadata {
} }
} }
return _metadataYaml[key]; return _metadataYaml![key];
} }
} }
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart';
import 'package:package_config/package_config.dart'; import 'package:package_config/package_config.dart';
import 'base/file_system.dart'; import 'base/file_system.dart';
...@@ -28,7 +25,7 @@ import 'base/file_system.dart'; ...@@ -28,7 +25,7 @@ import 'base/file_system.dart';
/// sources, and might need to include a license for each one. /// sources, and might need to include a license for each one.
class LicenseCollector { class LicenseCollector {
LicenseCollector({ LicenseCollector({
@required FileSystem fileSystem required FileSystem fileSystem
}) : _fileSystem = fileSystem; }) : _fileSystem = fileSystem;
final FileSystem _fileSystem; final FileSystem _fileSystem;
...@@ -67,8 +64,8 @@ class LicenseCollector { ...@@ -67,8 +64,8 @@ class LicenseCollector {
.readAsStringSync() .readAsStringSync()
.split(licenseSeparator); .split(licenseSeparator);
for (final String rawLicense in rawLicenses) { for (final String rawLicense in rawLicenses) {
List<String> packageNames; List<String> packageNames = <String>[];
String licenseText; String? licenseText;
if (rawLicenses.length > 1) { if (rawLicenses.length > 1) {
final int split = rawLicense.indexOf('\n\n'); final int split = rawLicense.indexOf('\n\n');
if (split >= 0) { if (split >= 0) {
...@@ -87,7 +84,7 @@ class LicenseCollector { ...@@ -87,7 +84,7 @@ class LicenseCollector {
final List<String> combinedLicensesList = packageLicenses.keys final List<String> combinedLicensesList = packageLicenses.keys
.map<String>((String license) { .map<String>((String license) {
final List<String> packageNames = packageLicenses[license].toList() final List<String> packageNames = packageLicenses[license]!.toList()
..sort(); ..sort();
return packageNames.join('\n') + '\n\n' + license; return packageNames.join('\n') + '\n\n' + license;
}).toList(); }).toList();
...@@ -97,7 +94,7 @@ class LicenseCollector { ...@@ -97,7 +94,7 @@ class LicenseCollector {
final List<String> additionalLicenseText = <String>[]; final List<String> additionalLicenseText = <String>[];
final List<String> errorMessages = <String>[]; final List<String> errorMessages = <String>[];
for (final String package in additionalLicenses.keys) { for (final String package in additionalLicenses.keys) {
for (final File license in additionalLicenses[package]) { for (final File license in additionalLicenses[package]!) {
if (!license.existsSync()) { if (!license.existsSync()) {
errorMessages.add( errorMessages.add(
'package $package specified an additional license at ${license.path}, but this file ' 'package $package specified an additional license at ${license.path}, but this file '
...@@ -146,9 +143,9 @@ class LicenseCollector { ...@@ -146,9 +143,9 @@ class LicenseCollector {
/// The result of processing licenses with a [LicenseCollector]. /// The result of processing licenses with a [LicenseCollector].
class LicenseResult { class LicenseResult {
const LicenseResult({ const LicenseResult({
@required this.combinedLicenses, required this.combinedLicenses,
@required this.dependencies, required this.dependencies,
@required this.errorMessages, required this.errorMessages,
}); });
/// The raw text of the consumed licenses. /// The raw text of the consumed licenses.
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:typed_data'; import 'dart:typed_data';
import '../base/file_system.dart'; import '../base/file_system.dart';
...@@ -20,8 +18,8 @@ class WebMemoryFS { ...@@ -20,8 +18,8 @@ class WebMemoryFS {
final Map<String, Uint8List> files = <String, Uint8List>{}; final Map<String, Uint8List> files = <String, Uint8List>{};
final Map<String, Uint8List> sourcemaps = <String, Uint8List>{}; final Map<String, Uint8List> sourcemaps = <String, Uint8List>{};
String get mergedMetadata => _mergedMetadata; String? get mergedMetadata => _mergedMetadata;
String _mergedMetadata; String? _mergedMetadata;
/// Update the filesystem with the provided source and manifest files. /// Update the filesystem with the provided source and manifest files.
/// ///
...@@ -37,13 +35,13 @@ class WebMemoryFS { ...@@ -37,13 +35,13 @@ class WebMemoryFS {
final Uint8List sourcemapBytes = sourcemapFile.readAsBytesSync(); final Uint8List sourcemapBytes = sourcemapFile.readAsBytesSync();
final Uint8List metadataBytes = metadataFile.readAsBytesSync(); final Uint8List metadataBytes = metadataFile.readAsBytesSync();
final Map<String, dynamic> manifest = final Map<String, dynamic> manifest =
castStringKeyedMap(json.decode(manifestFile.readAsStringSync())); castStringKeyedMap(json.decode(manifestFile.readAsStringSync()))!;
for (final String filePath in manifest.keys) { for (final String filePath in manifest.keys) {
if (filePath == null) { if (filePath == null) {
continue; continue;
} }
final Map<String, dynamic> offsets = final Map<String, dynamic> offsets =
castStringKeyedMap(manifest[filePath]); castStringKeyedMap(manifest[filePath])!;
final List<int> codeOffsets = final List<int> codeOffsets =
(offsets['code'] as List<dynamic>).cast<int>(); (offsets['code'] as List<dynamic>).cast<int>();
final List<int> sourcemapOffsets = final List<int> sourcemapOffsets =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment