Refactoring to use ver command instead of systeminfo (#119304)
* refactoring to use `ver` command instead of `systeminfo` * fix tests to match new approach * adding another valid validator using brazil locale text * refactor tests to use generic fake class `ver` arg + showing output from `ver` if unsuccessful * update reason text in test * fix reason text to be hard coded
This commit is contained in:
@@ -2,9 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import '../base/io.dart';
|
||||
import '../base/os.dart';
|
||||
import '../doctor_validator.dart';
|
||||
|
||||
/// Flutter only supports development on Windows host machines version 10 and greater.
|
||||
@@ -16,49 +14,36 @@ const List<String> kUnsupportedVersions = <String>[
|
||||
|
||||
/// Regex pattern for identifying line from systeminfo stdout with windows version
|
||||
/// (ie. 10.5.4123)
|
||||
const String kWindowsOSVersionSemVerPattern =
|
||||
r'^(OS )([^:]*:\s*)([0-9]+\.[0-9]+\.[0-9]+)(.*)$';
|
||||
const String kWindowsOSVersionSemVerPattern = r'([0-9]+)\.([0-9]+)\.([0-9\.]+)';
|
||||
|
||||
/// Validator for supported Windows host machine operating system version.
|
||||
class WindowsVersionValidator extends DoctorValidator {
|
||||
const WindowsVersionValidator({required ProcessManager processManager})
|
||||
: _processManager = processManager,
|
||||
const WindowsVersionValidator({
|
||||
required OperatingSystemUtils operatingSystemUtils,
|
||||
}) : _operatingSystemUtils = operatingSystemUtils,
|
||||
super('Windows Version');
|
||||
|
||||
final ProcessManager _processManager;
|
||||
final OperatingSystemUtils _operatingSystemUtils;
|
||||
|
||||
@override
|
||||
Future<ValidationResult> validate() async {
|
||||
final ProcessResult result =
|
||||
await _processManager.run(<String>['systeminfo']);
|
||||
|
||||
if (result.exitCode != 0) {
|
||||
return const ValidationResult(
|
||||
ValidationType.missing,
|
||||
<ValidationMessage>[],
|
||||
statusInfo: 'Exit status from running `systeminfo` was unsuccessful',
|
||||
);
|
||||
}
|
||||
|
||||
final String resultStdout = result.stdout as String;
|
||||
|
||||
final RegExp regex =
|
||||
RegExp(kWindowsOSVersionSemVerPattern, multiLine: true);
|
||||
final Iterable<RegExpMatch> matches = regex.allMatches(resultStdout);
|
||||
final String commandResult = _operatingSystemUtils.name;
|
||||
final Iterable<RegExpMatch> matches = regex.allMatches(commandResult);
|
||||
|
||||
// Use the string split method to extract the major version
|
||||
// and check against the [kUnsupportedVersions] list
|
||||
final ValidationType windowsVersionStatus;
|
||||
final String statusInfo;
|
||||
if (matches.length == 1 &&
|
||||
!kUnsupportedVersions
|
||||
.contains(matches.elementAt(0).group(3)?.split('.').elementAt(0))) {
|
||||
!kUnsupportedVersions.contains(matches.elementAt(0).group(1))) {
|
||||
windowsVersionStatus = ValidationType.success;
|
||||
statusInfo = 'Installed version of Windows is version 10 or higher';
|
||||
} else {
|
||||
windowsVersionStatus = ValidationType.missing;
|
||||
statusInfo =
|
||||
'Unable to confirm if installed Windows version is 10 or greater';
|
||||
'Unable to determine Windows version (command `ver` returned $commandResult)';
|
||||
}
|
||||
|
||||
return ValidationResult(
|
||||
|
||||
Reference in New Issue
Block a user