diff --git a/packages/flutter_tools/lib/runner.dart b/packages/flutter_tools/lib/runner.dart index 152e94006b6..7eb1be4b025 100644 --- a/packages/flutter_tools/lib/runner.dart +++ b/packages/flutter_tools/lib/runner.dart @@ -7,7 +7,6 @@ import 'dart:async'; import 'package:args/command_runner.dart'; -import 'package:http/http.dart' as http; import 'package:intl/intl.dart' as intl; import 'package:intl/intl_standalone.dart' as intl_standalone; @@ -136,7 +135,6 @@ Future _handleToolError( globals.flutterUsage.sendException(error); await asyncGuard(() async { final CrashReportSender crashReportSender = CrashReportSender( - client: http.Client(), usage: globals.flutterUsage, platform: globals.platform, logger: globals.logger, diff --git a/packages/flutter_tools/lib/src/reporting/crash_reporting.dart b/packages/flutter_tools/lib/src/reporting/crash_reporting.dart index 1f59b36f266..1b0f6560988 100644 --- a/packages/flutter_tools/lib/src/reporting/crash_reporting.dart +++ b/packages/flutter_tools/lib/src/reporting/crash_reporting.dart @@ -97,12 +97,12 @@ class CrashReporter { /// wish to use your own server for collecting crash reports from Flutter Tools. class CrashReportSender { CrashReportSender({ - @required http.Client client, + http.Client client, @required Usage usage, @required Platform platform, @required Logger logger, @required OperatingSystemUtils operatingSystemUtils, - }) : _client = client, + }) : _client = client ?? http.Client(), _usage = usage, _platform = platform, _logger = logger, diff --git a/packages/flutter_tools/test/integration.shard/forbidden_imports_test.dart b/packages/flutter_tools/test/integration.shard/forbidden_imports_test.dart index 2c14356d862..3faae826dd6 100644 --- a/packages/flutter_tools/test/integration.shard/forbidden_imports_test.dart +++ b/packages/flutter_tools/test/integration.shard/forbidden_imports_test.dart @@ -86,6 +86,31 @@ void main() { } }); + test('no unauthorized imports of package:http', () { + final List allowedPaths = [ + // Used only for multi-part file uploads, which are non-trivial to reimplement. + fileSystem.path.join(flutterTools, 'lib', 'src', 'reporting', 'reporting.dart'), + ]; + bool _isNotAllowed(FileSystemEntity entity) => allowedPaths.every((String path) => path != entity.path); + + for (final String dirName in ['lib', 'bin']) { + final Iterable files = fileSystem.directory(fileSystem.path.join(flutterTools, dirName)) + .listSync(recursive: true) + .where(_isDartFile) + .where(_isNotAllowed) + .map(_asFile); + for (final File file in files) { + for (final String line in file.readAsLinesSync()) { + if (line.startsWith(RegExp(r'import.*package:http/')) && + !line.contains('ignore: package_http_import')) { + final String relativePath = fileSystem.path.relative(file.path, from:flutterTools); + fail("$relativePath imports 'package:http'; import 'lib/src/base/io.dart' instead"); + } + } + } + } + }); + test('no unauthorized imports of test_api', () { final List allowedPaths = [ fileSystem.path.join(flutterTools, 'lib', 'src', 'test', 'flutter_platform.dart'),