Unverified Commit 69c98bd9 authored by Andrew Kolos's avatar Andrew Kolos Committed by GitHub

Remove duplicate global declaration of `UserMessages` (#142281)

Fixes https://github.com/flutter/flutter/issues/142286

This is a refactor. No code behavior changes should be observed.
parent 6d436dfa
...@@ -11,7 +11,7 @@ import '../base/context.dart'; ...@@ -11,7 +11,7 @@ import '../base/context.dart';
import '../base/io.dart'; import '../base/io.dart';
import '../base/logger.dart'; import '../base/logger.dart';
import '../base/platform.dart'; import '../base/platform.dart';
import '../base/user_messages.dart' hide userMessages; import '../base/user_messages.dart';
import '../base/version.dart'; import '../base/version.dart';
import '../convert.dart'; import '../convert.dart';
import '../doctor_validator.dart'; import '../doctor_validator.dart';
......
...@@ -2,18 +2,14 @@ ...@@ -2,18 +2,14 @@
// 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.
import 'context.dart';
import 'platform.dart'; import 'platform.dart';
/// Contains messages produced by Flutter tools. /// Class containing some message strings that can be produced by Flutter tools.
// //
// This allows partial reimplementations of the flutter tool to override // This allows partial reimplementations of the flutter tool to override
// certain messages. // certain messages.
// TODO(andrewkolos): It is unclear if this is worth keeping. See // TODO(andrewkolos): It is unclear if this is worth keeping. See
// https://github.com/flutter/flutter/issues/125155. // https://github.com/flutter/flutter/issues/125155.
UserMessages get userMessages => context.get<UserMessages>()!;
/// Class containing message strings that can be produced by Flutter tools.
class UserMessages { class UserMessages {
// Messages used in multiple components. // Messages used in multiple components.
String get flutterToolBugInstructions => String get flutterToolBugInstructions =>
...@@ -211,11 +207,6 @@ class UserMessages { ...@@ -211,11 +207,6 @@ class UserMessages {
'$consequence\n' '$consequence\n'
'To re-install $reinstallInstructions'; 'To re-install $reinstallInstructions';
// Messages used in VsCodeValidator
String vsCodeVersion(String version) => 'version $version';
String vsCodeLocation(String location) => 'VS Code at $location';
String vsCodeFlutterExtensionMissing(String url) => 'Flutter extension not installed; install from\n$url';
// Messages used in VisualStudioValidator // Messages used in VisualStudioValidator
String visualStudioVersion(String name, String version) => '$name version $version'; String visualStudioVersion(String name, String version) => '$name version $version';
String visualStudioLocation(String location) => 'Visual Studio at $location'; String visualStudioLocation(String location) => 'Visual Studio at $location';
......
...@@ -278,7 +278,7 @@ Future<T> runInContext<T>( ...@@ -278,7 +278,7 @@ Future<T> runInContext<T>(
processManager: globals.processManager processManager: globals.processManager
), ),
LocalEngineLocator: () => LocalEngineLocator( LocalEngineLocator: () => LocalEngineLocator(
userMessages: userMessages, userMessages: globals.userMessages,
logger: globals.logger, logger: globals.logger,
platform: globals.platform, platform: globals.platform,
fileSystem: globals.fs, fileSystem: globals.fs,
......
...@@ -119,7 +119,7 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider { ...@@ -119,7 +119,7 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
...IntelliJValidator.installedValidators( ...IntelliJValidator.installedValidators(
fileSystem: globals.fs, fileSystem: globals.fs,
platform: platform, platform: platform,
userMessages: userMessages, userMessages: globals.userMessages,
plistParser: globals.plistParser, plistParser: globals.plistParser,
processManager: globals.processManager, processManager: globals.processManager,
logger: _logger, logger: _logger,
...@@ -134,7 +134,7 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider { ...@@ -134,7 +134,7 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
flutterVersion: () => globals.flutterVersion.fetchTagsAndGetVersion(clock: globals.systemClock), flutterVersion: () => globals.flutterVersion.fetchTagsAndGetVersion(clock: globals.systemClock),
devToolsVersion: () => globals.cache.devToolsVersion, devToolsVersion: () => globals.cache.devToolsVersion,
processManager: globals.processManager, processManager: globals.processManager,
userMessages: userMessages, userMessages: globals.userMessages,
artifacts: globals.artifacts!, artifacts: globals.artifacts!,
flutterRoot: () => Cache.flutterRoot!, flutterRoot: () => Cache.flutterRoot!,
operatingSystemUtils: globals.os, operatingSystemUtils: globals.os,
...@@ -150,7 +150,7 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider { ...@@ -150,7 +150,7 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
GroupedValidator(<DoctorValidator>[ GroupedValidator(<DoctorValidator>[
XcodeValidator( XcodeValidator(
xcode: globals.xcode!, xcode: globals.xcode!,
userMessages: userMessages, userMessages: globals.userMessages,
iosSimulatorUtils: globals.iosSimulatorUtils!, iosSimulatorUtils: globals.iosSimulatorUtils!,
), ),
globals.cocoapodsValidator!, globals.cocoapodsValidator!,
...@@ -170,7 +170,7 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider { ...@@ -170,7 +170,7 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
if (linuxWorkflow.appliesToHostPlatform) if (linuxWorkflow.appliesToHostPlatform)
LinuxDoctorValidator( LinuxDoctorValidator(
processManager: globals.processManager, processManager: globals.processManager,
userMessages: userMessages, userMessages: globals.userMessages,
), ),
if (windowsWorkflow!.appliesToHostPlatform) if (windowsWorkflow!.appliesToHostPlatform)
visualStudioValidator!, visualStudioValidator!,
......
...@@ -9,8 +9,8 @@ import 'package:yaml/yaml.dart'; ...@@ -9,8 +9,8 @@ import 'package:yaml/yaml.dart';
import 'base/deferred_component.dart'; import 'base/deferred_component.dart';
import 'base/file_system.dart'; import 'base/file_system.dart';
import 'base/logger.dart'; import 'base/logger.dart';
import 'base/user_messages.dart';
import 'base/utils.dart'; import 'base/utils.dart';
import 'globals.dart' as globals;
import 'plugins.dart'; import 'plugins.dart';
/// Whether or not Impeller Scene 3D model import is enabled. /// Whether or not Impeller Scene 3D model import is enabled.
...@@ -103,7 +103,7 @@ class FlutterManifest { ...@@ -103,7 +103,7 @@ class FlutterManifest {
version = Version.parse(verStr); version = Version.parse(verStr);
} on Exception { } on Exception {
if (!_hasShowInvalidVersionMsg) { if (!_hasShowInvalidVersionMsg) {
_logger.printStatus(userMessages.invalidVersionSettingHintMessage(verStr), emphasis: true); _logger.printStatus(globals.userMessages.invalidVersionSettingHintMessage(verStr), emphasis: true);
_hasShowInvalidVersionMsg = true; _hasShowInvalidVersionMsg = true;
} }
} }
......
...@@ -9,7 +9,7 @@ import '../base/file_system.dart'; ...@@ -9,7 +9,7 @@ import '../base/file_system.dart';
import '../base/io.dart'; import '../base/io.dart';
import '../base/logger.dart'; import '../base/logger.dart';
import '../base/platform.dart'; import '../base/platform.dart';
import '../base/user_messages.dart' hide userMessages; import '../base/user_messages.dart';
import '../base/version.dart'; import '../base/version.dart';
import '../convert.dart'; import '../convert.dart';
import '../doctor_validator.dart'; import '../doctor_validator.dart';
......
...@@ -15,7 +15,6 @@ import '../base/context.dart'; ...@@ -15,7 +15,6 @@ import '../base/context.dart';
import '../base/io.dart' as io; import '../base/io.dart' as io;
import '../base/io.dart'; import '../base/io.dart';
import '../base/os.dart'; import '../base/os.dart';
import '../base/user_messages.dart';
import '../base/utils.dart'; import '../base/utils.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../build_system/build_system.dart'; import '../build_system/build_system.dart';
...@@ -1398,7 +1397,7 @@ abstract class FlutterCommand extends Command<void> { ...@@ -1398,7 +1397,7 @@ abstract class FlutterCommand extends Command<void> {
commandResult = await verifyThenRunCommand(commandPath); commandResult = await verifyThenRunCommand(commandPath);
} finally { } finally {
final DateTime endTime = globals.systemClock.now(); final DateTime endTime = globals.systemClock.now();
globals.printTrace(userMessages.flutterElapsedTime(name, getElapsedAsMilliseconds(endTime.difference(startTime)))); globals.printTrace(globals.userMessages.flutterElapsedTime(name, getElapsedAsMilliseconds(endTime.difference(startTime))));
if (commandPath != null) { if (commandPath != null) {
_sendPostUsage( _sendPostUsage(
commandPath, commandPath,
...@@ -1825,7 +1824,7 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and ...@@ -1825,7 +1824,7 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and
return null; return null;
} }
if (deviceList.length > 1) { if (deviceList.length > 1) {
globals.printStatus(userMessages.flutterSpecifyDevice); globals.printStatus(globals.userMessages.flutterSpecifyDevice);
deviceList = await globals.deviceManager!.getAllDevices(); deviceList = await globals.deviceManager!.getAllDevices();
globals.printStatus(''); globals.printStatus('');
await Device.printDevices(deviceList, globals.logger); await Device.printDevices(deviceList, globals.logger);
...@@ -1844,7 +1843,7 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and ...@@ -1844,7 +1843,7 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and
// until one can be found. // until one can be found.
final String? path = findProjectRoot(globals.fs, globals.fs.currentDirectory.path); final String? path = findProjectRoot(globals.fs, globals.fs.currentDirectory.path);
if (path == null) { if (path == null) {
throwToolExit(userMessages.flutterNoPubspec); throwToolExit(globals.userMessages.flutterNoPubspec);
} }
if (path != globals.fs.currentDirectory.path) { if (path != globals.fs.currentDirectory.path) {
globals.fs.currentDirectory = path; globals.fs.currentDirectory = path;
...@@ -1855,7 +1854,7 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and ...@@ -1855,7 +1854,7 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and
if (_usesTargetOption) { if (_usesTargetOption) {
final String targetPath = targetFile; final String targetPath = targetFile;
if (!globals.fs.isFileSync(targetPath)) { if (!globals.fs.isFileSync(targetPath)) {
throw ToolExit(userMessages.flutterTargetFileMissing(targetPath)); throw ToolExit(globals.userMessages.flutterTargetFileMissing(targetPath));
} }
} }
} }
......
...@@ -13,7 +13,6 @@ import '../base/common.dart'; ...@@ -13,7 +13,6 @@ import '../base/common.dart';
import '../base/context.dart'; import '../base/context.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/terminal.dart'; import '../base/terminal.dart';
import '../base/user_messages.dart';
import '../base/utils.dart'; import '../base/utils.dart';
import '../cache.dart'; import '../cache.dart';
import '../convert.dart'; import '../convert.dart';
...@@ -251,10 +250,10 @@ class FlutterCommandRunner extends CommandRunner<void> { ...@@ -251,10 +250,10 @@ class FlutterCommandRunner extends CommandRunner<void> {
try { try {
wrapColumn = int.parse(topLevelResults[FlutterGlobalOptions.kWrapColumnOption] as String); wrapColumn = int.parse(topLevelResults[FlutterGlobalOptions.kWrapColumnOption] as String);
if (wrapColumn < 0) { if (wrapColumn < 0) {
throwToolExit(userMessages.runnerWrapColumnInvalid(topLevelResults[FlutterGlobalOptions.kWrapColumnOption])); throwToolExit(globals.userMessages.runnerWrapColumnInvalid(topLevelResults[FlutterGlobalOptions.kWrapColumnOption]));
} }
} on FormatException { } on FormatException {
throwToolExit(userMessages.runnerWrapColumnParseError(topLevelResults[FlutterGlobalOptions.kWrapColumnOption])); throwToolExit(globals.userMessages.runnerWrapColumnParseError(topLevelResults[FlutterGlobalOptions.kWrapColumnOption]));
} }
} }
......
...@@ -9,7 +9,7 @@ import '../base/common.dart'; ...@@ -9,7 +9,7 @@ import '../base/common.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/logger.dart'; import '../base/logger.dart';
import '../base/platform.dart'; import '../base/platform.dart';
import '../base/user_messages.dart' hide userMessages; import '../base/user_messages.dart';
import '../cache.dart'; import '../cache.dart';
import '../dart/package_map.dart'; import '../dart/package_map.dart';
......
...@@ -8,7 +8,6 @@ import '../base/common.dart'; ...@@ -8,7 +8,6 @@ import '../base/common.dart';
import '../base/logger.dart'; import '../base/logger.dart';
import '../base/platform.dart'; import '../base/platform.dart';
import '../base/terminal.dart'; import '../base/terminal.dart';
import '../base/user_messages.dart';
import '../device.dart'; import '../device.dart';
import '../globals.dart' as globals; import '../globals.dart' as globals;
import '../ios/devices.dart'; import '../ios/devices.dart';
...@@ -151,7 +150,7 @@ class TargetDevices { ...@@ -151,7 +150,7 @@ class TargetDevices {
bool includeDevicesUnsupportedByProject = false, bool includeDevicesUnsupportedByProject = false,
}) async { }) async {
if (!globals.doctor!.canLaunchAnything) { if (!globals.doctor!.canLaunchAnything) {
_logger.printError(userMessages.flutterNoDevelopmentDevice); _logger.printError(globals.userMessages.flutterNoDevelopmentDevice);
return null; return null;
} }
...@@ -215,7 +214,7 @@ class TargetDevices { ...@@ -215,7 +214,7 @@ class TargetDevices {
_logger.printStatus(_deviceManager.hasSpecifiedAllDevices _logger.printStatus(_deviceManager.hasSpecifiedAllDevices
? _noDevicesFoundMessage ? _noDevicesFoundMessage
: userMessages.flutterNoSupportedDevices); : globals.userMessages.flutterNoSupportedDevices);
await _printUnsupportedDevice(unsupportedDevices); await _printUnsupportedDevice(unsupportedDevices);
return null; return null;
} }
...@@ -272,7 +271,7 @@ class TargetDevices { ...@@ -272,7 +271,7 @@ class TargetDevices {
supportFilter: DeviceDiscoverySupportFilter.excludeDevicesUnsupportedByFlutter(), supportFilter: DeviceDiscoverySupportFilter.excludeDevicesUnsupportedByFlutter(),
); );
_logger.printStatus(userMessages.flutterSpecifyDeviceWithAllOption); _logger.printStatus(globals.userMessages.flutterSpecifyDeviceWithAllOption);
_logger.printStatus(''); _logger.printStatus('');
} }
...@@ -336,7 +335,7 @@ class TargetDevices { ...@@ -336,7 +335,7 @@ class TargetDevices {
'\n', '\n',
); );
result.writeln(); result.writeln();
result.writeln(userMessages.flutterMissPlatformProjects( result.writeln(globals.userMessages.flutterMissPlatformProjects(
Device.devicesPlatformTypes(unsupportedDevices), Device.devicesPlatformTypes(unsupportedDevices),
)); ));
_logger.printStatus(result.toString(), newline: false); _logger.printStatus(result.toString(), newline: false);
...@@ -461,7 +460,7 @@ class TargetDevicesWithExtendedWirelessDeviceDiscovery extends TargetDevices { ...@@ -461,7 +460,7 @@ class TargetDevicesWithExtendedWirelessDeviceDiscovery extends TargetDevices {
bool includeDevicesUnsupportedByProject = false, bool includeDevicesUnsupportedByProject = false,
}) async { }) async {
if (!globals.doctor!.canLaunchAnything) { if (!globals.doctor!.canLaunchAnything) {
_logger.printError(userMessages.flutterNoDevelopmentDevice); _logger.printError(globals.userMessages.flutterNoDevelopmentDevice);
return null; return null;
} }
......
...@@ -6,7 +6,6 @@ import 'package:process/process.dart'; ...@@ -6,7 +6,6 @@ import 'package:process/process.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/platform.dart'; import '../base/platform.dart';
import '../base/user_messages.dart';
import '../doctor_validator.dart'; import '../doctor_validator.dart';
import 'vscode.dart'; import 'vscode.dart';
...@@ -27,8 +26,8 @@ class VsCodeValidator extends DoctorValidator { ...@@ -27,8 +26,8 @@ class VsCodeValidator extends DoctorValidator {
List<ValidationMessage>.from(_vsCode.validationMessages); List<ValidationMessage>.from(_vsCode.validationMessages);
final String vsCodeVersionText = _vsCode.version == null final String vsCodeVersionText = _vsCode.version == null
? userMessages.vsCodeVersion('unknown') ? 'version unknown'
: userMessages.vsCodeVersion(_vsCode.version.toString()); : 'version ${_vsCode.version}';
if (_vsCode.version == null) { if (_vsCode.version == null) {
validationMessages.add(const ValidationMessage.error('Unable to determine VS Code version.')); validationMessages.add(const ValidationMessage.error('Unable to determine VS Code version.'));
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import '../base/context.dart'; import '../base/context.dart';
import '../base/user_messages.dart' hide userMessages; import '../base/user_messages.dart';
import '../doctor_validator.dart'; import '../doctor_validator.dart';
import 'visual_studio.dart'; import 'visual_studio.dart';
......
...@@ -17,7 +17,6 @@ import 'package:flutter_tools/src/base/io.dart'; ...@@ -17,7 +17,6 @@ import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/terminal.dart'; import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/base/user_messages.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/daemon.dart'; import 'package:flutter_tools/src/commands/daemon.dart';
...@@ -419,7 +418,7 @@ void main() { ...@@ -419,7 +418,7 @@ void main() {
expect( expect(
testLogger.statusText, testLogger.statusText,
containsIgnoringWhitespace( containsIgnoringWhitespace(
userMessages.flutterMissPlatformProjects( globals.userMessages.flutterMissPlatformProjects(
Device.devicesPlatformTypes(<Device>[mockDevice]), Device.devicesPlatformTypes(<Device>[mockDevice]),
), ),
), ),
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// 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.
import 'package:flutter_tools/src/base/user_messages.dart' hide userMessages; import 'package:flutter_tools/src/base/user_messages.dart';
import 'package:flutter_tools/src/doctor_validator.dart'; import 'package:flutter_tools/src/doctor_validator.dart';
import 'package:flutter_tools/src/windows/visual_studio.dart'; import 'package:flutter_tools/src/windows/visual_studio.dart';
import 'package:flutter_tools/src/windows/visual_studio_validator.dart'; import 'package:flutter_tools/src/windows/visual_studio_validator.dart';
...@@ -10,11 +10,11 @@ import 'package:test/fake.dart'; ...@@ -10,11 +10,11 @@ import 'package:test/fake.dart';
import '../../src/common.dart'; import '../../src/common.dart';
final UserMessages userMessages = UserMessages();
void main() { void main() {
group('Visual Studio validation', () { group('Visual Studio validation', () {
late FakeVisualStudio fakeVisualStudio; late FakeVisualStudio fakeVisualStudio;
final UserMessages userMessages = UserMessages();
setUp(() { setUp(() {
fakeVisualStudio = FakeVisualStudio(); fakeVisualStudio = FakeVisualStudio();
......
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