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