Unverified Commit 458b298f authored by Elias Yishak's avatar Elias Yishak Committed by GitHub

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
parent 59d80dc8
...@@ -132,7 +132,7 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider { ...@@ -132,7 +132,7 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
), ),
if (platform.isWindows) if (platform.isWindows)
WindowsVersionValidator( WindowsVersionValidator(
processManager: globals.processManager, operatingSystemUtils: globals.os,
), ),
if (androidWorkflow!.appliesToHostPlatform) if (androidWorkflow!.appliesToHostPlatform)
GroupedValidator(<DoctorValidator>[androidValidator!, androidLicenseValidator!]), GroupedValidator(<DoctorValidator>[androidValidator!, androidLicenseValidator!]),
......
...@@ -2,9 +2,7 @@ ...@@ -2,9 +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:process/process.dart'; import '../base/os.dart';
import '../base/io.dart';
import '../doctor_validator.dart'; import '../doctor_validator.dart';
/// Flutter only supports development on Windows host machines version 10 and greater. /// Flutter only supports development on Windows host machines version 10 and greater.
...@@ -16,49 +14,36 @@ const List<String> kUnsupportedVersions = <String>[ ...@@ -16,49 +14,36 @@ const List<String> kUnsupportedVersions = <String>[
/// Regex pattern for identifying line from systeminfo stdout with windows version /// Regex pattern for identifying line from systeminfo stdout with windows version
/// (ie. 10.5.4123) /// (ie. 10.5.4123)
const String kWindowsOSVersionSemVerPattern = const String kWindowsOSVersionSemVerPattern = r'([0-9]+)\.([0-9]+)\.([0-9\.]+)';
r'^(OS )([^:]*:\s*)([0-9]+\.[0-9]+\.[0-9]+)(.*)$';
/// Validator for supported Windows host machine operating system version. /// Validator for supported Windows host machine operating system version.
class WindowsVersionValidator extends DoctorValidator { class WindowsVersionValidator extends DoctorValidator {
const WindowsVersionValidator({required ProcessManager processManager}) const WindowsVersionValidator({
: _processManager = processManager, required OperatingSystemUtils operatingSystemUtils,
}) : _operatingSystemUtils = operatingSystemUtils,
super('Windows Version'); super('Windows Version');
final ProcessManager _processManager; final OperatingSystemUtils _operatingSystemUtils;
@override @override
Future<ValidationResult> validate() async { 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 = final RegExp regex =
RegExp(kWindowsOSVersionSemVerPattern, multiLine: true); 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 // Use the string split method to extract the major version
// and check against the [kUnsupportedVersions] list // and check against the [kUnsupportedVersions] list
final ValidationType windowsVersionStatus; final ValidationType windowsVersionStatus;
final String statusInfo; final String statusInfo;
if (matches.length == 1 && if (matches.length == 1 &&
!kUnsupportedVersions !kUnsupportedVersions.contains(matches.elementAt(0).group(1))) {
.contains(matches.elementAt(0).group(3)?.split('.').elementAt(0))) {
windowsVersionStatus = ValidationType.success; windowsVersionStatus = ValidationType.success;
statusInfo = 'Installed version of Windows is version 10 or higher'; statusInfo = 'Installed version of Windows is version 10 or higher';
} else { } else {
windowsVersionStatus = ValidationType.missing; windowsVersionStatus = ValidationType.missing;
statusInfo = statusInfo =
'Unable to confirm if installed Windows version is 10 or greater'; 'Unable to determine Windows version (command `ver` returned $commandResult)';
} }
return ValidationResult( return ValidationResult(
......
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