Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
618030e0
Commit
618030e0
authored
Nov 29, 2016
by
John McCutchan
Committed by
GitHub
Nov 29, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More AppContext cleanups (#7073)
parent
f1938c60
Changes
16
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
97 additions
and
99 deletions
+97
-99
fuchsia_builder.dart
packages/flutter_tools/bin/fuchsia_builder.dart
+11
-2
executable.dart
packages/flutter_tools/lib/executable.dart
+22
-12
config.dart
packages/flutter_tools/lib/src/base/config.dart
+1
-1
context.dart
packages/flutter_tools/lib/src/base/context.dart
+9
-1
os.dart
packages/flutter_tools/lib/src/base/os.dart
+1
-3
cache.dart
packages/flutter_tools/lib/src/cache.dart
+1
-1
daemon.dart
packages/flutter_tools/lib/src/commands/daemon.dart
+2
-2
mac.dart
packages/flutter_tools/lib/src/ios/mac.dart
+1
-1
simulators.dart
packages/flutter_tools/lib/src/ios/simulators.dart
+2
-4
flutter_command_runner.dart
.../flutter_tools/lib/src/runner/flutter_command_runner.dart
+5
-4
toolchain.dart
packages/flutter_tools/lib/src/toolchain.dart
+5
-12
usage.dart
packages/flutter_tools/lib/src/usage.dart
+1
-1
context_test.dart
packages/flutter_tools/test/context_test.dart
+3
-3
daemon_test.dart
packages/flutter_tools/test/daemon_test.dart
+4
-4
context.dart
packages/flutter_tools/test/src/context.dart
+23
-37
toolchain_test.dart
packages/flutter_tools/test/toolchain_test.dart
+6
-11
No files found.
packages/flutter_tools/bin/fuchsia_builder.dart
View file @
618030e0
...
@@ -8,11 +8,14 @@ import 'dart:io';
...
@@ -8,11 +8,14 @@ import 'dart:io';
import
'package:args/args.dart'
;
import
'package:args/args.dart'
;
import
'../lib/src/base/common.dart'
;
import
'../lib/src/base/common.dart'
;
import
'../lib/src/base/config.dart'
;
import
'../lib/src/base/context.dart'
;
import
'../lib/src/base/context.dart'
;
import
'../lib/src/base/logger.dart'
;
import
'../lib/src/base/logger.dart'
;
import
'../lib/src/base/os.dart'
;
import
'../lib/src/cache.dart'
;
import
'../lib/src/cache.dart'
;
import
'../lib/src/flx.dart'
;
import
'../lib/src/flx.dart'
;
import
'../lib/src/globals.dart'
;
import
'../lib/src/globals.dart'
;
import
'../lib/src/usage.dart'
;
const
String
_kOptionPackages
=
'packages'
;
const
String
_kOptionPackages
=
'packages'
;
const
String
_kOptionOutput
=
'output-file'
;
const
String
_kOptionOutput
=
'output-file'
;
...
@@ -28,10 +31,16 @@ const List<String> _kRequiredOptions = const <String>[
...
@@ -28,10 +31,16 @@ const List<String> _kRequiredOptions = const <String>[
_kOptionWorking
,
_kOptionWorking
,
];
];
void
main
(
List
<
String
>
args
)
async
{
Future
<
Null
>
main
(
List
<
String
>
args
)
async
{
AppContext
executableContext
=
new
AppContext
();
AppContext
executableContext
=
new
AppContext
();
executableContext
.
setVariable
(
Logger
,
new
StdoutLogger
());
executableContext
.
runInZone
(()
{
executableContext
.
runInZone
(()
{
context
[
Logger
]
=
new
StdoutLogger
();
// Initialize the context with some defaults.
context
.
putIfAbsent
(
Logger
,
()
=>
new
StdoutLogger
());
context
.
putIfAbsent
(
Cache
,
()
=>
new
Cache
());
context
.
putIfAbsent
(
Config
,
()
=>
new
Config
());
context
.
putIfAbsent
(
OperatingSystemUtils
,
()
=>
new
OperatingSystemUtils
());
context
.
putIfAbsent
(
Usage
,
()
=>
new
Usage
());
return
run
(
args
);
return
run
(
args
);
});
});
}
}
...
...
packages/flutter_tools/lib/executable.dart
View file @
618030e0
...
@@ -9,10 +9,13 @@ import 'package:args/command_runner.dart';
...
@@ -9,10 +9,13 @@ import 'package:args/command_runner.dart';
import
'package:stack_trace/stack_trace.dart'
;
import
'package:stack_trace/stack_trace.dart'
;
import
'src/base/common.dart'
;
import
'src/base/common.dart'
;
import
'src/base/config.dart'
;
import
'src/base/context.dart'
;
import
'src/base/context.dart'
;
import
'src/base/logger.dart'
;
import
'src/base/logger.dart'
;
import
'src/base/os.dart'
;
import
'src/base/process.dart'
;
import
'src/base/process.dart'
;
import
'src/base/utils.dart'
;
import
'src/base/utils.dart'
;
import
'src/cache.dart'
;
import
'src/commands/analyze.dart'
;
import
'src/commands/analyze.dart'
;
import
'src/commands/build.dart'
;
import
'src/commands/build.dart'
;
import
'src/commands/channel.dart'
;
import
'src/commands/channel.dart'
;
...
@@ -40,8 +43,12 @@ import 'src/device.dart';
...
@@ -40,8 +43,12 @@ import 'src/device.dart';
import
'src/doctor.dart'
;
import
'src/doctor.dart'
;
import
'src/globals.dart'
;
import
'src/globals.dart'
;
import
'src/hot.dart'
;
import
'src/hot.dart'
;
import
'src/usage.dart'
;
import
'src/ios/mac.dart'
;
import
'src/ios/simulators.dart'
;
import
'src/runner/flutter_command_runner.dart'
;
import
'src/runner/flutter_command_runner.dart'
;
import
'src/toolchain.dart'
;
import
'src/usage.dart'
;
/// Main entry point for commands.
/// Main entry point for commands.
///
///
...
@@ -88,16 +95,19 @@ Future<Null> main(List<String> args) async {
...
@@ -88,16 +95,19 @@ Future<Null> main(List<String> args) async {
// Make the context current.
// Make the context current.
_executableContext
.
runInZone
(()
{
_executableContext
.
runInZone
(()
{
// Initialize the context with some defaults.
// Initialize the context with some defaults.
if
(
context
[
Logger
]
==
null
)
context
.
putIfAbsent
(
Logger
,
()
=>
new
StdoutLogger
());
context
[
Logger
]
=
new
StdoutLogger
();
context
.
putIfAbsent
(
DeviceManager
,
()
=>
new
DeviceManager
());
if
(
context
[
DeviceManager
]
==
null
)
context
.
putIfAbsent
(
DevFSConfig
,
()
=>
new
DevFSConfig
());
context
[
DeviceManager
]
=
new
DeviceManager
();
context
.
putIfAbsent
(
Doctor
,
()
=>
new
Doctor
());
if
(
context
[
DevFSConfig
]
==
null
)
context
.
putIfAbsent
(
HotRunnerConfig
,
()
=>
new
HotRunnerConfig
());
context
[
DevFSConfig
]
=
new
DevFSConfig
();
context
.
putIfAbsent
(
Cache
,
()
=>
new
Cache
());
if
(
context
[
Doctor
]
==
null
)
context
.
putIfAbsent
(
ToolConfiguration
,
()
=>
new
ToolConfiguration
());
context
[
Doctor
]
=
new
Doctor
();
context
.
putIfAbsent
(
Config
,
()
=>
new
Config
());
if
(
context
[
HotRunnerConfig
]
==
null
)
context
.
putIfAbsent
(
OperatingSystemUtils
,
()
=>
new
OperatingSystemUtils
());
context
[
HotRunnerConfig
]
=
new
HotRunnerConfig
();
context
.
putIfAbsent
(
XCode
,
()
=>
new
XCode
());
context
.
putIfAbsent
(
IOSSimulatorUtils
,
()
=>
new
IOSSimulatorUtils
());
context
.
putIfAbsent
(
SimControl
,
()
=>
new
SimControl
());
context
.
putIfAbsent
(
Usage
,
()
=>
new
Usage
());
return
Chain
.
capture
/*<Future<Null>>*/
(()
async
{
return
Chain
.
capture
/*<Future<Null>>*/
(()
async
{
await
runner
.
run
(
args
);
await
runner
.
run
(
args
);
...
@@ -192,7 +202,7 @@ Future<String> _doctorText() async {
...
@@ -192,7 +202,7 @@ Future<String> _doctorText() async {
BufferLogger
logger
=
new
BufferLogger
();
BufferLogger
logger
=
new
BufferLogger
();
AppContext
appContext
=
new
AppContext
();
AppContext
appContext
=
new
AppContext
();
appContext
[
Logger
]
=
logger
;
appContext
.
setVariable
(
Logger
,
logger
)
;
await
appContext
.
runInZone
(()
=>
doctor
.
diagnose
());
await
appContext
.
runInZone
(()
=>
doctor
.
diagnose
());
...
...
packages/flutter_tools/lib/src/base/config.dart
View file @
618030e0
...
@@ -16,7 +16,7 @@ class Config {
...
@@ -16,7 +16,7 @@ class Config {
_values
=
JSON
.
decode
(
_configFile
.
readAsStringSync
());
_values
=
JSON
.
decode
(
_configFile
.
readAsStringSync
());
}
}
static
Config
get
instance
=>
context
[
Config
]
??
(
context
[
Config
]
=
new
Config
())
;
static
Config
get
instance
=>
context
[
Config
];
File
_configFile
;
File
_configFile
;
String
get
configPath
=>
_configFile
.
path
;
String
get
configPath
=>
_configFile
.
path
;
...
...
packages/flutter_tools/lib/src/base/context.dart
View file @
618030e0
...
@@ -36,7 +36,15 @@ class AppContext {
...
@@ -36,7 +36,15 @@ class AppContext {
dynamic
operator
[](
Type
type
)
=>
getVariable
(
type
);
dynamic
operator
[](
Type
type
)
=>
getVariable
(
type
);
void
operator
[]=(
Type
type
,
dynamic
instance
)
=>
setVariable
(
type
,
instance
);
dynamic
putIfAbsent
(
Type
type
,
dynamic
ifAbsent
())
{
dynamic
value
=
getVariable
(
type
);
if
(
value
!=
null
)
{
return
value
;
}
value
=
ifAbsent
();
setVariable
(
type
,
value
);
return
value
;
}
AppContext
_calcParent
(
Zone
zone
)
{
AppContext
_calcParent
(
Zone
zone
)
{
Zone
parentZone
=
zone
.
parent
;
Zone
parentZone
=
zone
.
parent
;
...
...
packages/flutter_tools/lib/src/base/os.dart
View file @
618030e0
...
@@ -12,9 +12,7 @@ import 'context.dart';
...
@@ -12,9 +12,7 @@ import 'context.dart';
import
'process.dart'
;
import
'process.dart'
;
/// Returns [OperatingSystemUtils] active in the current app context (i.e. zone).
/// Returns [OperatingSystemUtils] active in the current app context (i.e. zone).
OperatingSystemUtils
get
os
{
OperatingSystemUtils
get
os
=>
context
[
OperatingSystemUtils
];
return
context
[
OperatingSystemUtils
]
??
(
context
[
OperatingSystemUtils
]
=
new
OperatingSystemUtils
());
}
abstract
class
OperatingSystemUtils
{
abstract
class
OperatingSystemUtils
{
factory
OperatingSystemUtils
()
{
factory
OperatingSystemUtils
()
{
...
...
packages/flutter_tools/lib/src/cache.dart
View file @
618030e0
...
@@ -99,7 +99,7 @@ class Cache {
...
@@ -99,7 +99,7 @@ class Cache {
return
_engineRevision
;
return
_engineRevision
;
}
}
static
Cache
get
instance
=>
context
[
Cache
]
??
(
context
[
Cache
]
=
new
Cache
())
;
static
Cache
get
instance
=>
context
[
Cache
];
/// Return the top-level directory in the cache; this is `bin/cache`.
/// Return the top-level directory in the cache; this is `bin/cache`.
Directory
getRoot
()
{
Directory
getRoot
()
{
...
...
packages/flutter_tools/lib/src/commands/daemon.dart
View file @
618030e0
...
@@ -48,7 +48,7 @@ class DaemonCommand extends FlutterCommand {
...
@@ -48,7 +48,7 @@ class DaemonCommand extends FlutterCommand {
AppContext
appContext
=
new
AppContext
();
AppContext
appContext
=
new
AppContext
();
NotifyingLogger
notifyingLogger
=
new
NotifyingLogger
();
NotifyingLogger
notifyingLogger
=
new
NotifyingLogger
();
appContext
[
Logger
]
=
notifyingLogger
;
appContext
.
setVariable
(
Logger
,
notifyingLogger
)
;
Cache
.
releaseLockEarly
();
Cache
.
releaseLockEarly
();
...
@@ -674,7 +674,7 @@ class AppInstance {
...
@@ -674,7 +674,7 @@ class AppInstance {
_logger
=
new
_AppRunLogger
(
domain
,
this
);
_logger
=
new
_AppRunLogger
(
domain
,
this
);
AppContext
appContext
=
new
AppContext
();
AppContext
appContext
=
new
AppContext
();
appContext
[
Logger
]
=
_logger
;
appContext
.
setVariable
(
Logger
,
_logger
)
;
return
appContext
.
runInZone
(
method
);
return
appContext
.
runInZone
(
method
);
}
}
}
}
...
...
packages/flutter_tools/lib/src/ios/mac.dart
View file @
618030e0
...
@@ -56,7 +56,7 @@ class XCode {
...
@@ -56,7 +56,7 @@ class XCode {
}
}
/// Returns [XCode] active in the current app context.
/// Returns [XCode] active in the current app context.
static
XCode
get
instance
=>
context
[
XCode
]
??
(
context
[
XCode
]
=
new
XCode
())
;
static
XCode
get
instance
=>
context
[
XCode
];
bool
get
isInstalledAndMeetsVersionCheck
=>
isInstalled
&&
xcodeVersionSatisfactory
;
bool
get
isInstalledAndMeetsVersionCheck
=>
isInstalled
&&
xcodeVersionSatisfactory
;
...
...
packages/flutter_tools/lib/src/ios/simulators.dart
View file @
618030e0
...
@@ -37,9 +37,7 @@ class IOSSimulators extends PollingDeviceDiscovery {
...
@@ -37,9 +37,7 @@ class IOSSimulators extends PollingDeviceDiscovery {
class
IOSSimulatorUtils
{
class
IOSSimulatorUtils
{
/// Returns [IOSSimulatorUtils] active in the current app context (i.e. zone).
/// Returns [IOSSimulatorUtils] active in the current app context (i.e. zone).
static
IOSSimulatorUtils
get
instance
{
static
IOSSimulatorUtils
get
instance
=>
context
[
IOSSimulatorUtils
];
return
context
[
IOSSimulatorUtils
]
??
(
context
[
IOSSimulatorUtils
]
=
new
IOSSimulatorUtils
());
}
List
<
IOSSimulator
>
getAttachedDevices
()
{
List
<
IOSSimulator
>
getAttachedDevices
()
{
if
(!
XCode
.
instance
.
isInstalledAndMeetsVersionCheck
)
if
(!
XCode
.
instance
.
isInstalledAndMeetsVersionCheck
)
...
@@ -54,7 +52,7 @@ class IOSSimulatorUtils {
...
@@ -54,7 +52,7 @@ class IOSSimulatorUtils {
/// A wrapper around the `simctl` command line tool.
/// A wrapper around the `simctl` command line tool.
class
SimControl
{
class
SimControl
{
/// Returns [SimControl] active in the current app context (i.e. zone).
/// Returns [SimControl] active in the current app context (i.e. zone).
static
SimControl
get
instance
=>
context
[
SimControl
]
??
(
context
[
SimControl
]
=
new
SimControl
())
;
static
SimControl
get
instance
=>
context
[
SimControl
];
Future
<
bool
>
boot
({
String
deviceName
})
async
{
Future
<
bool
>
boot
({
String
deviceName
})
async
{
if
(
_isAnyConnected
())
if
(
_isAnyConnected
())
...
...
packages/flutter_tools/lib/src/runner/flutter_command_runner.dart
View file @
618030e0
...
@@ -137,8 +137,10 @@ class FlutterCommandRunner extends CommandRunner<Null> {
...
@@ -137,8 +137,10 @@ class FlutterCommandRunner extends CommandRunner<Null> {
@override
@override
Future
<
Null
>
runCommand
(
ArgResults
globalResults
)
async
{
Future
<
Null
>
runCommand
(
ArgResults
globalResults
)
async
{
// Check for verbose.
// Check for verbose.
if
(
globalResults
[
'verbose'
])
if
(
globalResults
[
'verbose'
])
{
context
[
Logger
]
=
new
VerboseLogger
();
// Override the logger.
context
.
setVariable
(
Logger
,
new
VerboseLogger
());
}
logger
.
quiet
=
globalResults
[
'quiet'
];
logger
.
quiet
=
globalResults
[
'quiet'
];
...
@@ -171,8 +173,7 @@ class FlutterCommandRunner extends CommandRunner<Null> {
...
@@ -171,8 +173,7 @@ class FlutterCommandRunner extends CommandRunner<Null> {
}
}
// The Android SDK could already have been set by tests.
// The Android SDK could already have been set by tests.
if
(!
context
.
isSet
(
AndroidSdk
))
context
.
putIfAbsent
(
AndroidSdk
,
()
=>
AndroidSdk
.
locateAndroidSdk
());
context
[
AndroidSdk
]
=
AndroidSdk
.
locateAndroidSdk
();
if
(
globalResults
[
'version'
])
{
if
(
globalResults
[
'version'
])
{
flutterUsage
.
sendCommand
(
'version'
);
flutterUsage
.
sendCommand
(
'version'
);
...
...
packages/flutter_tools/lib/src/toolchain.dart
View file @
618030e0
...
@@ -25,18 +25,11 @@ const Map<HostTool, String> _kHostToolFileName = const <HostTool, String>{
...
@@ -25,18 +25,11 @@ const Map<HostTool, String> _kHostToolFileName = const <HostTool, String>{
/// and the engine artifact directory for a given target platform. It is configurable
/// and the engine artifact directory for a given target platform. It is configurable
/// via command-line arguments in order to support local engine builds.
/// via command-line arguments in order to support local engine builds.
class
ToolConfiguration
{
class
ToolConfiguration
{
/// [overrideCache] is configurable for testing.
ToolConfiguration
();
ToolConfiguration
({
Cache
overrideCache
})
{
_cache
=
overrideCache
??
cache
;
}
Cache
_cache
;
Cache
get
cache
=>
context
[
Cache
]
;
static
ToolConfiguration
get
instance
{
static
ToolConfiguration
get
instance
=>
context
[
ToolConfiguration
];
if
(
context
[
ToolConfiguration
]
==
null
)
context
[
ToolConfiguration
]
=
new
ToolConfiguration
();
return
context
[
ToolConfiguration
];
}
/// Override using the artifacts from the cache directory (--engine-src-path).
/// Override using the artifacts from the cache directory (--engine-src-path).
String
engineSrcPath
;
String
engineSrcPath
;
...
@@ -63,14 +56,14 @@ class ToolConfiguration {
...
@@ -63,14 +56,14 @@ class ToolConfiguration {
// Create something like `android-arm` or `android-arm-release`.
// Create something like `android-arm` or `android-arm-release`.
String
dirName
=
getNameForTargetPlatform
(
platform
)
+
suffix
;
String
dirName
=
getNameForTargetPlatform
(
platform
)
+
suffix
;
Directory
engineDir
=
_
cache
.
getArtifactDirectory
(
'engine'
);
Directory
engineDir
=
cache
.
getArtifactDirectory
(
'engine'
);
return
new
Directory
(
path
.
join
(
engineDir
.
path
,
dirName
));
return
new
Directory
(
path
.
join
(
engineDir
.
path
,
dirName
));
}
}
}
}
String
getHostToolPath
(
HostTool
tool
)
{
String
getHostToolPath
(
HostTool
tool
)
{
if
(
engineBuildPath
==
null
)
{
if
(
engineBuildPath
==
null
)
{
return
path
.
join
(
_
cache
.
getArtifactDirectory
(
'engine'
).
path
,
return
path
.
join
(
cache
.
getArtifactDirectory
(
'engine'
).
path
,
getNameForHostPlatform
(
getCurrentHostPlatform
()),
getNameForHostPlatform
(
getCurrentHostPlatform
()),
_kHostToolFileName
[
tool
]);
_kHostToolFileName
[
tool
]);
}
}
...
...
packages/flutter_tools/lib/src/usage.dart
View file @
618030e0
...
@@ -39,7 +39,7 @@ class Usage {
...
@@ -39,7 +39,7 @@ class Usage {
}
}
/// Returns [Usage] active in the current app context.
/// Returns [Usage] active in the current app context.
static
Usage
get
instance
=>
context
[
Usage
]
??
(
context
[
Usage
]
=
new
Usage
())
;
static
Usage
get
instance
=>
context
[
Usage
];
Analytics
_analytics
;
Analytics
_analytics
;
...
...
packages/flutter_tools/test/context_test.dart
View file @
618030e0
...
@@ -12,7 +12,7 @@ void main() {
...
@@ -12,7 +12,7 @@ void main() {
test
(
'error'
,
()
async
{
test
(
'error'
,
()
async
{
AppContext
context
=
new
AppContext
();
AppContext
context
=
new
AppContext
();
BufferLogger
mockLogger
=
new
BufferLogger
();
BufferLogger
mockLogger
=
new
BufferLogger
();
context
[
Logger
]
=
mockLogger
;
context
.
setVariable
(
Logger
,
mockLogger
)
;
await
context
.
runInZone
(()
{
await
context
.
runInZone
(()
{
printError
(
'foo bar'
);
printError
(
'foo bar'
);
...
@@ -26,7 +26,7 @@ void main() {
...
@@ -26,7 +26,7 @@ void main() {
test
(
'status'
,
()
async
{
test
(
'status'
,
()
async
{
AppContext
context
=
new
AppContext
();
AppContext
context
=
new
AppContext
();
BufferLogger
mockLogger
=
new
BufferLogger
();
BufferLogger
mockLogger
=
new
BufferLogger
();
context
[
Logger
]
=
mockLogger
;
context
.
setVariable
(
Logger
,
mockLogger
)
;
await
context
.
runInZone
(()
{
await
context
.
runInZone
(()
{
printStatus
(
'foo bar'
);
printStatus
(
'foo bar'
);
...
@@ -40,7 +40,7 @@ void main() {
...
@@ -40,7 +40,7 @@ void main() {
test
(
'trace'
,
()
async
{
test
(
'trace'
,
()
async
{
AppContext
context
=
new
AppContext
();
AppContext
context
=
new
AppContext
();
BufferLogger
mockLogger
=
new
BufferLogger
();
BufferLogger
mockLogger
=
new
BufferLogger
();
context
[
Logger
]
=
mockLogger
;
context
.
setVariable
(
Logger
,
mockLogger
)
;
await
context
.
runInZone
(()
{
await
context
.
runInZone
(()
{
printTrace
(
'foo bar'
);
printTrace
(
'foo bar'
);
...
...
packages/flutter_tools/test/daemon_test.dart
View file @
618030e0
...
@@ -32,11 +32,11 @@ void main() {
...
@@ -32,11 +32,11 @@ void main() {
setUp
(()
{
setUp
(()
{
appContext
=
new
AppContext
();
appContext
=
new
AppContext
();
notifyingLogger
=
new
NotifyingLogger
();
notifyingLogger
=
new
NotifyingLogger
();
appContext
[
Logger
]
=
notifyingLogger
;
appContext
.
setVariable
(
Logger
,
notifyingLogger
)
;
appContext
[
Doctor
]
=
new
Doctor
(
);
appContext
.
setVariable
(
Doctor
,
new
Doctor
()
);
if
(
Platform
.
isMacOS
)
if
(
Platform
.
isMacOS
)
appContext
[
XCode
]
=
new
XCode
(
);
appContext
.
setVariable
(
XCode
,
new
XCode
()
);
appContext
[
DeviceManager
]
=
new
MockDeviceManager
(
);
appContext
.
setVariable
(
DeviceManager
,
new
MockDeviceManager
()
);
});
});
tearDown
(()
{
tearDown
(()
{
...
...
packages/flutter_tools/test/src/context.dart
View file @
618030e0
...
@@ -3,17 +3,19 @@
...
@@ -3,17 +3,19 @@
// found in the LICENSE file.
// found in the LICENSE file.
import
'dart:async'
;
import
'dart:async'
;
import
'dart:io'
;
import
'package:flutter_tools/src/base/config.dart'
;
import
'package:flutter_tools/src/base/context.dart'
;
import
'package:flutter_tools/src/base/context.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/os.dart'
;
import
'package:flutter_tools/src/base/os.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/device.dart'
;
import
'package:flutter_tools/src/device.dart'
;
import
'package:flutter_tools/src/devfs.dart'
;
import
'package:flutter_tools/src/devfs.dart'
;
import
'package:flutter_tools/src/doctor.dart'
;
import
'package:flutter_tools/src/doctor.dart'
;
import
'package:flutter_tools/src/hot.dart'
;
import
'package:flutter_tools/src/hot.dart'
;
import
'package:flutter_tools/src/ios/mac.dart'
;
import
'package:flutter_tools/src/ios/mac.dart'
;
import
'package:flutter_tools/src/ios/simulators.dart'
;
import
'package:flutter_tools/src/ios/simulators.dart'
;
import
'package:flutter_tools/src/toolchain.dart'
;
import
'package:flutter_tools/src/usage.dart'
;
import
'package:flutter_tools/src/usage.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:mockito/mockito.dart'
;
...
@@ -32,49 +34,33 @@ void testUsingContext(String description, dynamic testMethod(), {
...
@@ -32,49 +34,33 @@ void testUsingContext(String description, dynamic testMethod(), {
test
(
description
,
()
async
{
test
(
description
,
()
async
{
AppContext
testContext
=
new
AppContext
();
AppContext
testContext
=
new
AppContext
();
// Apply all overrides to the test context.
overrides
.
forEach
((
Type
type
,
dynamic
value
)
{
overrides
.
forEach
((
Type
type
,
dynamic
value
)
{
testContext
[
type
]
=
value
;
testContext
.
setVariable
(
type
,
value
)
;
});
});
if
(!
overrides
.
containsKey
(
Logger
))
// Initialize the test context with some default mocks.
testContext
[
Logger
]
=
new
BufferLogger
();
testContext
.
putIfAbsent
(
Logger
,
()
=>
new
BufferLogger
());
testContext
.
putIfAbsent
(
DeviceManager
,
()
=>
new
MockDeviceManager
());
if
(!
overrides
.
containsKey
(
DeviceManager
))
testContext
.
putIfAbsent
(
DevFSConfig
,
()
=>
new
DevFSConfig
());
testContext
[
DeviceManager
]
=
new
MockDeviceManager
();
testContext
.
putIfAbsent
(
Doctor
,
()
=>
new
MockDoctor
());
testContext
.
putIfAbsent
(
HotRunnerConfig
,
()
=>
new
HotRunnerConfig
());
if
(!
overrides
.
containsKey
(
Doctor
))
testContext
.
putIfAbsent
(
Cache
,
()
=>
new
Cache
());
testContext
[
Doctor
]
=
new
MockDoctor
();
testContext
.
putIfAbsent
(
ToolConfiguration
,
()
=>
new
ToolConfiguration
());
testContext
.
putIfAbsent
(
Config
,
()
=>
new
Config
());
if
(!
overrides
.
containsKey
(
SimControl
))
testContext
.
putIfAbsent
(
OperatingSystemUtils
,
()
{
testContext
[
SimControl
]
=
new
MockSimControl
();
if
(!
overrides
.
containsKey
(
Usage
))
testContext
[
Usage
]
=
new
MockUsage
();
if
(!
overrides
.
containsKey
(
OperatingSystemUtils
))
{
MockOperatingSystemUtils
os
=
new
MockOperatingSystemUtils
();
MockOperatingSystemUtils
os
=
new
MockOperatingSystemUtils
();
when
(
os
.
isWindows
).
thenReturn
(
false
);
when
(
os
.
isWindows
).
thenReturn
(
false
);
testContext
[
OperatingSystemUtils
]
=
os
;
return
os
;
}
});
testContext
.
putIfAbsent
(
XCode
,
()
=>
new
XCode
());
if
(!
overrides
.
containsKey
(
DevFSConfig
))
{
testContext
.
putIfAbsent
(
IOSSimulatorUtils
,
()
{
testContext
[
DevFSConfig
]
=
new
DevFSConfig
();
}
if
(!
overrides
.
containsKey
(
HotRunnerConfig
))
{
testContext
[
HotRunnerConfig
]
=
new
HotRunnerConfig
();
}
if
(!
overrides
.
containsKey
(
IOSSimulatorUtils
))
{
MockIOSSimulatorUtils
mock
=
new
MockIOSSimulatorUtils
();
MockIOSSimulatorUtils
mock
=
new
MockIOSSimulatorUtils
();
when
(
mock
.
getAttachedDevices
()).
thenReturn
(<
IOSSimulator
>[]);
when
(
mock
.
getAttachedDevices
()).
thenReturn
(<
IOSSimulator
>[]);
testContext
[
IOSSimulatorUtils
]
=
mock
;
return
mock
;
}
});
testContext
.
putIfAbsent
(
SimControl
,
()
=>
new
MockSimControl
());
if
(
Platform
.
isMacOS
)
{
testContext
.
putIfAbsent
(
Usage
,
()
=>
new
MockUsage
());
if
(!
overrides
.
containsKey
(
XCode
))
testContext
[
XCode
]
=
new
XCode
();
}
try
{
try
{
return
await
testContext
.
runInZone
(
testMethod
);
return
await
testContext
.
runInZone
(
testMethod
);
...
...
packages/flutter_tools/test/toolchain_test.dart
View file @
618030e0
...
@@ -14,19 +14,10 @@ import 'src/context.dart';
...
@@ -14,19 +14,10 @@ import 'src/context.dart';
void
main
(
)
{
void
main
(
)
{
group
(
'ToolConfiguration'
,
()
{
group
(
'ToolConfiguration'
,
()
{
Directory
tempDir
;
Directory
tempDir
;
setUp
(()
{
tempDir
=
Directory
.
systemTemp
.
createTempSync
(
'flutter_temp'
);
tempDir
=
Directory
.
systemTemp
.
createTempSync
(
'flutter_temp'
);
});
tearDown
(()
{
tempDir
.
deleteSync
(
recursive:
true
);
});
testUsingContext
(
'using cache'
,
()
{
testUsingContext
(
'using cache'
,
()
{
ToolConfiguration
toolConfig
=
new
ToolConfiguration
(
ToolConfiguration
toolConfig
=
new
ToolConfiguration
();
overrideCache:
new
Cache
(
rootOverride:
tempDir
)
);
expect
(
expect
(
toolConfig
.
getEngineArtifactsDirectory
(
TargetPlatform
.
android_arm
,
BuildMode
.
debug
).
path
,
toolConfig
.
getEngineArtifactsDirectory
(
TargetPlatform
.
android_arm
,
BuildMode
.
debug
).
path
,
...
@@ -36,6 +27,10 @@ void main() {
...
@@ -36,6 +27,10 @@ void main() {
toolConfig
.
getEngineArtifactsDirectory
(
TargetPlatform
.
android_arm
,
BuildMode
.
release
).
path
,
toolConfig
.
getEngineArtifactsDirectory
(
TargetPlatform
.
android_arm
,
BuildMode
.
release
).
path
,
endsWith
(
'cache/artifacts/engine/android-arm-release'
)
endsWith
(
'cache/artifacts/engine/android-arm-release'
)
);
);
expect
(
tempDir
,
isNotNull
);
tempDir
.
deleteSync
(
recursive:
true
);
},
overrides:
<
Type
,
dynamic
>
{
Cache:
new
Cache
(
rootOverride:
tempDir
)
});
});
testUsingContext
(
'using enginePath'
,
()
{
testUsingContext
(
'using enginePath'
,
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment