1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
---|---|
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | import 'package:process/process.dart'; |
6 | import 'package:unified_analytics/unified_analytics.dart'; |
7 | |
8 | import 'android/android_sdk.dart'; |
9 | import 'android/android_studio.dart'; |
10 | import 'android/gradle_utils.dart'; |
11 | import 'android/java.dart'; |
12 | import 'artifacts.dart'; |
13 | import 'base/bot_detector.dart'; |
14 | import 'base/config.dart'; |
15 | import 'base/context.dart'; |
16 | import 'base/error_handling_io.dart'; |
17 | import 'base/file_system.dart'; |
18 | import 'base/io.dart'; |
19 | import 'base/logger.dart'; |
20 | import 'base/net.dart'; |
21 | import 'base/os.dart'; |
22 | import 'base/platform.dart'; |
23 | import 'base/process.dart'; |
24 | import 'base/signals.dart'; |
25 | import 'base/template.dart'; |
26 | import 'base/terminal.dart'; |
27 | import 'base/time.dart'; |
28 | import 'base/user_messages.dart'; |
29 | import 'build_system/build_system.dart'; |
30 | import 'build_system/build_targets.dart'; |
31 | import 'cache.dart'; |
32 | import 'custom_devices/custom_devices_config.dart'; |
33 | import 'device.dart'; |
34 | import 'doctor.dart'; |
35 | import 'ios/ios_workflow.dart'; |
36 | import 'ios/plist_parser.dart'; |
37 | import 'ios/simulators.dart'; |
38 | import 'ios/xcodeproj.dart'; |
39 | import 'macos/cocoapods.dart'; |
40 | import 'macos/cocoapods_validator.dart'; |
41 | import 'macos/xcdevice.dart'; |
42 | import 'macos/xcode.dart'; |
43 | import 'native_assets.dart'; |
44 | import 'persistent_tool_state.dart'; |
45 | import 'pre_run_validator.dart'; |
46 | import 'project.dart'; |
47 | import 'reporting/crash_reporting.dart'; |
48 | import 'reporting/reporting.dart'; |
49 | import 'runner/local_engine.dart'; |
50 | import 'version.dart'; |
51 | |
52 | // TODO(ianh): We should remove all the global variables and replace them with |
53 | // arguments (to constructors, methods, etc, as appropriate). |
54 | |
55 | Artifacts? get artifacts => context.get<Artifacts>(); |
56 | BuildSystem get buildSystem => context.get<BuildSystem>()!; |
57 | BuildTargets get buildTargets => context.get<BuildTargets>()!; |
58 | Cache get cache => context.get<Cache>()!; |
59 | CocoaPodsValidator? get cocoapodsValidator => context.get<CocoaPodsValidator>(); |
60 | Config get config => context.get<Config>()!; |
61 | CrashReporter? get crashReporter => context.get<CrashReporter>(); |
62 | DeviceManager? get deviceManager => context.get<DeviceManager>(); |
63 | Doctor? get doctor => context.get<Doctor>(); |
64 | HttpClientFactory? get httpClientFactory => context.get<HttpClientFactory>(); |
65 | IOSSimulatorUtils? get iosSimulatorUtils => context.get<IOSSimulatorUtils>(); |
66 | Logger get logger => context.get<Logger>()!; |
67 | OperatingSystemUtils get os => context.get<OperatingSystemUtils>()!; |
68 | Signals get signals => context.get<Signals>() ?? LocalSignals.instance; |
69 | AndroidStudio? get androidStudio => context.get<AndroidStudio>(); |
70 | AndroidSdk? get androidSdk => context.get<AndroidSdk>(); |
71 | FlutterVersion get flutterVersion => context.get<FlutterVersion>()!; |
72 | Usage get flutterUsage => context.get<Usage>()!; |
73 | XcodeProjectInterpreter? get xcodeProjectInterpreter => context.get<XcodeProjectInterpreter>(); |
74 | XCDevice? get xcdevice => context.get<XCDevice>(); |
75 | Xcode? get xcode => context.get<Xcode>(); |
76 | IOSWorkflow? get iosWorkflow => context.get<IOSWorkflow>(); |
77 | LocalEngineLocator? get localEngineLocator => context.get<LocalEngineLocator>(); |
78 | |
79 | PersistentToolState? get persistentToolState => PersistentToolState.instance; |
80 | |
81 | BotDetector get botDetector => context.get<BotDetector>() ?? _defaultBotDetector; |
82 | final BotDetector _defaultBotDetector = BotDetector( |
83 | httpClientFactory: context.get<HttpClientFactory>() ?? () => HttpClient(), |
84 | platform: platform, |
85 | persistentToolState: |
86 | persistentToolState ?? |
87 | PersistentToolState(fileSystem: fs, logger: logger, platform: platform), |
88 | ); |
89 | Future<bool> get isRunningOnBot => botDetector.isRunningOnBot; |
90 | |
91 | // Analytics instance for package:unified_analytics for analytics |
92 | // reporting for all Flutter and Dart related tooling |
93 | Analytics get analytics => context.get<Analytics>()!; |
94 | |
95 | /// Currently active implementation of the file system. |
96 | /// |
97 | /// By default it uses local disk-based implementation. Override this in tests |
98 | /// with [MemoryFileSystem]. |
99 | FileSystem get fs => ErrorHandlingFileSystem( |
100 | delegate: context.get<FileSystem>() ?? localFileSystem, |
101 | platform: platform, |
102 | ); |
103 | |
104 | FileSystemUtils get fsUtils => |
105 | context.get<FileSystemUtils>() ?? FileSystemUtils(fileSystem: fs, platform: platform); |
106 | |
107 | const ProcessManager _kLocalProcessManager = LocalProcessManager(); |
108 | |
109 | /// The active process manager. |
110 | ProcessManager get processManager => context.get<ProcessManager>() ?? _kLocalProcessManager; |
111 | ProcessUtils get processUtils => context.get<ProcessUtils>()!; |
112 | |
113 | const Platform _kLocalPlatform = LocalPlatform(); |
114 | Platform get platform => context.get<Platform>() ?? _kLocalPlatform; |
115 | |
116 | UserMessages get userMessages => context.get<UserMessages>()!; |
117 | |
118 | final OutputPreferences _default = OutputPreferences( |
119 | wrapText: stdio.hasTerminal, |
120 | showColor: platform.stdoutSupportsAnsi, |
121 | stdio: stdio, |
122 | ); |
123 | OutputPreferences get outputPreferences => context.get<OutputPreferences>() ?? _default; |
124 | |
125 | /// The current system clock instance. |
126 | SystemClock get systemClock => context.get<SystemClock>() ?? _systemClock; |
127 | SystemClock _systemClock = const SystemClock(); |
128 | |
129 | ProcessInfo get processInfo => context.get<ProcessInfo>()!; |
130 | |
131 | /// Display an error level message to the user. Commands should use this if they |
132 | /// fail in some way. |
133 | /// |
134 | /// Set [emphasis] to true to make the output bold if it's supported. |
135 | /// Set [color] to a [TerminalColor] to color the output, if the logger |
136 | /// supports it. The [color] defaults to [TerminalColor.red]. |
137 | void printError( |
138 | String message, { |
139 | StackTrace? stackTrace, |
140 | bool? emphasis, |
141 | TerminalColor? color, |
142 | int? indent, |
143 | int? hangingIndent, |
144 | bool? wrap, |
145 | }) { |
146 | logger.printError( |
147 | message, |
148 | stackTrace: stackTrace, |
149 | emphasis: emphasis ?? false, |
150 | color: color, |
151 | indent: indent, |
152 | hangingIndent: hangingIndent, |
153 | wrap: wrap, |
154 | ); |
155 | } |
156 | |
157 | /// Display a warning level message to the user. Commands should use this if they |
158 | /// have important warnings to convey that aren't fatal. |
159 | /// |
160 | /// Set [emphasis] to true to make the output bold if it's supported. |
161 | /// Set [color] to a [TerminalColor] to color the output, if the logger |
162 | /// supports it. The [color] defaults to [TerminalColor.cyan]. |
163 | void printWarning( |
164 | String message, { |
165 | bool? emphasis, |
166 | TerminalColor? color, |
167 | int? indent, |
168 | int? hangingIndent, |
169 | bool? wrap, |
170 | }) { |
171 | logger.printWarning( |
172 | message, |
173 | emphasis: emphasis ?? false, |
174 | color: color, |
175 | indent: indent, |
176 | hangingIndent: hangingIndent, |
177 | wrap: wrap, |
178 | ); |
179 | } |
180 | |
181 | /// Display normal output of the command. This should be used for things like |
182 | /// progress messages, success messages, or just normal command output. |
183 | /// |
184 | /// Set `emphasis` to true to make the output bold if it's supported. |
185 | /// |
186 | /// Set `newline` to false to skip the trailing linefeed. |
187 | /// |
188 | /// If `indent` is provided, each line of the message will be prepended by the |
189 | /// specified number of whitespaces. |
190 | void printStatus( |
191 | String message, { |
192 | bool? emphasis, |
193 | bool? newline, |
194 | TerminalColor? color, |
195 | int? indent, |
196 | int? hangingIndent, |
197 | bool? wrap, |
198 | }) { |
199 | logger.printStatus( |
200 | message, |
201 | emphasis: emphasis ?? false, |
202 | color: color, |
203 | newline: newline ?? true, |
204 | indent: indent, |
205 | hangingIndent: hangingIndent, |
206 | wrap: wrap, |
207 | ); |
208 | } |
209 | |
210 | /// Display the [message] inside a box. |
211 | /// |
212 | /// For example, this is the generated output: |
213 | /// |
214 | /// ┌─ [title] ─┐ |
215 | /// │ [message] │ |
216 | /// └───────────┘ |
217 | /// |
218 | /// If a terminal is attached, the lines in [message] are automatically wrapped based on |
219 | /// the available columns. |
220 | void printBox(String message, {String? title}) { |
221 | logger.printBox(message, title: title); |
222 | } |
223 | |
224 | /// Use this for verbose tracing output. Users can turn this output on in order |
225 | /// to help diagnose issues with the toolchain or with their setup. |
226 | void printTrace(String message) => logger.printTrace(message); |
227 | |
228 | AnsiTerminal get terminal { |
229 | return context.get<AnsiTerminal>() ?? _defaultAnsiTerminal; |
230 | } |
231 | |
232 | final AnsiTerminal _defaultAnsiTerminal = AnsiTerminal( |
233 | stdio: stdio, |
234 | platform: platform, |
235 | now: DateTime.now(), |
236 | shutdownHooks: shutdownHooks, |
237 | ); |
238 | |
239 | /// The global Stdio wrapper. |
240 | Stdio get stdio => context.get<Stdio>() ?? (_stdioInstance ??= Stdio()); |
241 | Stdio? _stdioInstance; |
242 | |
243 | PlistParser get plistParser => |
244 | context.get<PlistParser>() ?? |
245 | (_plistInstance ??= PlistParser( |
246 | fileSystem: fs, |
247 | processManager: processManager, |
248 | logger: logger, |
249 | )); |
250 | PlistParser? _plistInstance; |
251 | |
252 | /// The global template renderer. |
253 | TemplateRenderer get templateRenderer => context.get<TemplateRenderer>()!; |
254 | |
255 | /// Global [ShutdownHooks] that should be run before the tool process exits. |
256 | /// |
257 | /// This is depended on by [localFileSystem] which is called before any |
258 | /// [Context] is set up, and thus this cannot be a Context getter. |
259 | final ShutdownHooks shutdownHooks = ShutdownHooks(); |
260 | |
261 | // Unless we're in a test of this class's signal handling features, we must |
262 | // have only one instance created with the singleton LocalSignals instance |
263 | // and the catchable signals it considers to be fatal. |
264 | LocalFileSystem? _instance; |
265 | LocalFileSystem get localFileSystem => |
266 | _instance ??= LocalFileSystem(LocalSignals.instance, Signals.defaultExitSignals, shutdownHooks); |
267 | |
268 | /// Gradle utils in the current [AppContext]. |
269 | GradleUtils? get gradleUtils => context.get<GradleUtils>(); |
270 | |
271 | CocoaPods? get cocoaPods => context.get<CocoaPods>(); |
272 | |
273 | FlutterProjectFactory get projectFactory { |
274 | return context.get<FlutterProjectFactory>() ?? |
275 | FlutterProjectFactory(logger: logger, fileSystem: fs); |
276 | } |
277 | |
278 | CustomDevicesConfig get customDevicesConfig => context.get<CustomDevicesConfig>()!; |
279 | |
280 | PreRunValidator get preRunValidator => |
281 | context.get<PreRunValidator>() ?? const NoOpPreRunValidator(); |
282 | |
283 | // Used to build RegExp instances which can detect the VM service message. |
284 | final RegExp kVMServiceMessageRegExp = RegExp( |
285 | r'The Dart VM service is listening on ((http|//)[a-zA-Z0-9:/=_\-\.\[\]]+)', |
286 | ); |
287 | |
288 | /// Contains information about the JRE/JDK to use for Java-dependent operations. |
289 | /// |
290 | /// A value of [null] indicates that no installation of java could be found on |
291 | /// the host machine. |
292 | Java? get java => context.get<Java>(); |
293 | |
294 | TestCompilerNativeAssetsBuilder? get nativeAssetsBuilder => |
295 | context.get<TestCompilerNativeAssetsBuilder>(); |
296 |
Definitions
- artifacts
- buildSystem
- buildTargets
- cache
- cocoapodsValidator
- config
- crashReporter
- deviceManager
- doctor
- httpClientFactory
- iosSimulatorUtils
- logger
- os
- signals
- androidStudio
- androidSdk
- flutterVersion
- flutterUsage
- xcodeProjectInterpreter
- xcdevice
- xcode
- iosWorkflow
- localEngineLocator
- persistentToolState
- botDetector
- _defaultBotDetector
- isRunningOnBot
- analytics
- fs
- fsUtils
- _kLocalProcessManager
- processManager
- processUtils
- _kLocalPlatform
- platform
- userMessages
- _default
- outputPreferences
- systemClock
- _systemClock
- processInfo
- printError
- printWarning
- printStatus
- printBox
- printTrace
- terminal
- _defaultAnsiTerminal
- stdio
- _stdioInstance
- plistParser
- _plistInstance
- templateRenderer
- shutdownHooks
- _instance
- localFileSystem
- gradleUtils
- cocoaPods
- projectFactory
- customDevicesConfig
- preRunValidator
- kVMServiceMessageRegExp
- java
Learn more about Flutter for embedded and desktop on industrialflutter.com