OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// An enum of all operating systems supported by Dart. | 5 /// An enum of all operating systems supported by Dart. |
6 /// | 6 /// |
7 /// This is used for selecting which operating systems a test can run on. Even | 7 /// This is used for selecting which operating systems a test can run on. Even |
8 /// for browser tests, this indicates the operating system of the machine | 8 /// for browser tests, this indicates the operating system of the machine |
9 /// running the test runner. | 9 /// running the test runner. |
10 class OperatingSystem { | 10 class OperatingSystem { |
11 /// Microsoft Windows. | 11 /// Microsoft Windows. |
12 static const windows = const OperatingSystem._("windows"); | 12 static const windows = const OperatingSystem._("Windows", "windows"); |
13 | 13 |
14 /// Mac OS X. | 14 /// Mac OS X. |
15 static const macOS = const OperatingSystem._("mac-os"); | 15 static const macOS = const OperatingSystem._("OS X", "mac-os"); |
kevmoo
2016/02/19 02:08:47
ios was added in 1.14 – fyi
nweiz
2016/02/23 22:02:38
I'll add that in a separate CL.
| |
16 | 16 |
17 /// GNU/Linux. | 17 /// GNU/Linux. |
18 static const linux = const OperatingSystem._("linux"); | 18 static const linux = const OperatingSystem._("Linux", "linux"); |
19 | 19 |
20 /// Android. | 20 /// Android. |
21 /// | 21 /// |
22 /// Since this is the operating system the test runner is running on, this | 22 /// Since this is the operating system the test runner is running on, this |
23 /// won't be true when testing remotely on an Android browser. | 23 /// won't be true when testing remotely on an Android browser. |
24 static const android = const OperatingSystem._("android"); | 24 static const android = const OperatingSystem._("Android", "android"); |
25 | 25 |
26 /// No operating system. | 26 /// No operating system. |
27 /// | 27 /// |
28 /// This is used when running in the browser, or if an unrecognized operating | 28 /// This is used when running in the browser, or if an unrecognized operating |
29 /// system is used. It can't be referenced by name in platform selectors. | 29 /// system is used. It can't be referenced by name in platform selectors. |
30 static const none = const OperatingSystem._("none"); | 30 static const none = const OperatingSystem._("none", "none"); |
31 | 31 |
32 /// A list of all instances of [OperatingSystem] other than [none]. | 32 /// A list of all instances of [OperatingSystem] other than [none]. |
33 static const all = const [windows, macOS, linux, android]; | 33 static const all = const [windows, macOS, linux, android]; |
34 | 34 |
35 /// Finds an operating system by its name. | 35 /// Finds an operating system by its name. |
36 /// | 36 /// |
37 /// If no operating system is found, returns [none]. | 37 /// If no operating system is found, returns [none]. |
38 static OperatingSystem find(String name) => | 38 static OperatingSystem find(String name) => |
39 all.firstWhere((platform) => platform.name == name, orElse: () => null); | 39 all.firstWhere((platform) => platform.name == name, orElse: () => null); |
40 | 40 |
41 /// Finds an operating system by the return value from `dart:io`'s | 41 /// Finds an operating system by the return value from `dart:io`'s |
42 /// `Platform.operatingSystem`. | 42 /// `Platform.operatingSystem`. |
43 /// | 43 /// |
44 /// If no operating system is found, returns [none]. | 44 /// If no operating system is found, returns [none]. |
45 static OperatingSystem findByIoName(String name) { | 45 static OperatingSystem findByIoName(String name) { |
46 switch (name) { | 46 switch (name) { |
47 case "windows": return windows; | 47 case "windows": return windows; |
48 case "macos": return macOS; | 48 case "macos": return macOS; |
49 case "linux": return linux; | 49 case "linux": return linux; |
50 case "android": return android; | 50 case "android": return android; |
51 default: return none; | 51 default: return none; |
52 } | 52 } |
53 } | 53 } |
54 | 54 |
55 /// The name of the operating system. | 55 /// The human-friendly of the operating system. |
56 final String name; | 56 final String name; |
57 | 57 |
58 /// The identifier used to look up the operating system. | |
59 final String identifier; | |
60 | |
58 /// Whether this is a POSIX-ish operating system. | 61 /// Whether this is a POSIX-ish operating system. |
59 bool get isPosix => this != windows && this != none; | 62 bool get isPosix => this != windows && this != none; |
60 | 63 |
61 const OperatingSystem._(this.name); | 64 const OperatingSystem._(this.name, this.identifier); |
62 | 65 |
63 String toString() => name; | 66 String toString() => name; |
64 } | 67 } |
OLD | NEW |