4
4
5
5
import 'package:file/memory.dart' ;
6
6
import 'package:flutter_tools/src/android/android_sdk.dart' ;
7
+ import 'package:flutter_tools/src/base/config.dart' ;
7
8
import 'package:flutter_tools/src/base/file_system.dart' ;
8
9
import 'package:flutter_tools/src/base/io.dart' show ProcessResult;
10
+ import 'package:flutter_tools/src/base/logger.dart' ;
9
11
import 'package:flutter_tools/src/base/platform.dart' ;
10
- import 'package:flutter_tools/src/globals .dart' as globals ;
12
+ import 'package:meta/meta .dart' ;
11
13
import 'package:mockito/mockito.dart' ;
12
14
import 'package:process/process.dart' ;
13
15
@@ -18,12 +20,18 @@ import '../../src/mocks.dart';
18
20
class MockProcessManager extends Mock implements ProcessManager {}
19
21
20
22
void main () {
21
- MemoryFileSystem fs ;
23
+ MemoryFileSystem fileSystem ;
22
24
MockProcessManager processManager;
25
+ Config config;
23
26
24
27
setUp (() {
25
- fs = MemoryFileSystem ();
28
+ fileSystem = MemoryFileSystem . test ();
26
29
processManager = MockProcessManager ();
30
+ config = Config .test (
31
+ 'test' ,
32
+ directory: fileSystem.currentDirectory,
33
+ logger: BufferLogger .test (),
34
+ );
27
35
});
28
36
29
37
group ('android_sdk AndroidSdk' , () {
@@ -38,144 +46,154 @@ void main() {
38
46
39
47
testUsingContext ('parse sdk' , () {
40
48
sdkDir = MockAndroidSdk .createSdkDirectory ();
41
- globals. config.setValue ('android-sdk' , sdkDir.path);
49
+ config.setValue ('android-sdk' , sdkDir.path);
42
50
43
51
final AndroidSdk sdk = AndroidSdk .locateAndroidSdk ();
44
52
expect (sdk.latestVersion, isNotNull);
45
53
expect (sdk.latestVersion.sdkLevel, 23 );
46
54
}, overrides: < Type , Generator > {
47
- FileSystem : () => fs ,
55
+ FileSystem : () => fileSystem ,
48
56
ProcessManager : () => FakeProcessManager .any (),
57
+ Config : () => config,
49
58
});
50
59
51
60
testUsingContext ('parse sdk N' , () {
52
61
sdkDir = MockAndroidSdk .createSdkDirectory (withAndroidN: true );
53
- globals. config.setValue ('android-sdk' , sdkDir.path);
62
+ config.setValue ('android-sdk' , sdkDir.path);
54
63
55
64
final AndroidSdk sdk = AndroidSdk .locateAndroidSdk ();
56
65
expect (sdk.latestVersion, isNotNull);
57
66
expect (sdk.latestVersion.sdkLevel, 24 );
58
67
}, overrides: < Type , Generator > {
59
- FileSystem : () => fs ,
68
+ FileSystem : () => fileSystem ,
60
69
ProcessManager : () => FakeProcessManager .any (),
70
+ Config : () => config,
61
71
});
62
72
63
73
testUsingContext ('returns sdkmanager path under cmdline tools on Linux/macOS' , () {
64
74
sdkDir = MockAndroidSdk .createSdkDirectory ();
65
- globals. config.setValue ('android-sdk' , sdkDir.path);
75
+ config.setValue ('android-sdk' , sdkDir.path);
66
76
67
77
final AndroidSdk sdk = AndroidSdk .locateAndroidSdk ();
68
- globals.fs .file (
69
- globals.fs .path.join (sdk.directory, 'cmdline-tools' , 'latest' , 'bin' , 'sdkmanager' )
78
+ fileSystem .file (
79
+ fileSystem .path.join (sdk.directory, 'cmdline-tools' , 'latest' , 'bin' , 'sdkmanager' )
70
80
).createSync (recursive: true );
71
81
72
- expect (sdk.sdkManagerPath, globals.fs .path.join (sdk.directory, 'cmdline-tools' , 'latest' , 'bin' , 'sdkmanager' ));
82
+ expect (sdk.sdkManagerPath, fileSystem .path.join (sdk.directory, 'cmdline-tools' , 'latest' , 'bin' , 'sdkmanager' ));
73
83
}, overrides: < Type , Generator > {
74
- FileSystem : () => fs ,
84
+ FileSystem : () => fileSystem ,
75
85
ProcessManager : () => FakeProcessManager .any (),
76
86
Platform : () => FakePlatform (operatingSystem: 'linux' ),
87
+ Config : () => config,
77
88
});
78
89
79
90
testUsingContext ('returns sdkmanager.bat path under cmdline tools for windows' , () {
80
91
sdkDir = MockAndroidSdk .createSdkDirectory ();
81
- globals. config.setValue ('android-sdk' , sdkDir.path);
92
+ config.setValue ('android-sdk' , sdkDir.path);
82
93
83
94
final AndroidSdk sdk = AndroidSdk .locateAndroidSdk ();
84
- globals.fs .file (
85
- globals.fs .path.join (sdk.directory, 'cmdline-tools' , 'latest' , 'bin' , 'sdkmanager.bat' )
95
+ fileSystem .file (
96
+ fileSystem .path.join (sdk.directory, 'cmdline-tools' , 'latest' , 'bin' , 'sdkmanager.bat' )
86
97
).createSync (recursive: true );
87
98
88
99
expect (sdk.sdkManagerPath,
89
- globals.fs .path.join (sdk.directory, 'cmdline-tools' , 'latest' , 'bin' , 'sdkmanager.bat' ));
100
+ fileSystem .path.join (sdk.directory, 'cmdline-tools' , 'latest' , 'bin' , 'sdkmanager.bat' ));
90
101
}, overrides: < Type , Generator > {
91
- FileSystem : () => fs ,
102
+ FileSystem : () => fileSystem ,
92
103
ProcessManager : () => FakeProcessManager .any (),
93
104
Platform : () => FakePlatform (operatingSystem: 'windows' ),
105
+ Config : () => config,
94
106
});
95
107
96
108
testUsingContext ('returns sdkmanager path under tools if cmdline doesnt exist' , () {
97
109
sdkDir = MockAndroidSdk .createSdkDirectory ();
98
- globals. config.setValue ('android-sdk' , sdkDir.path);
110
+ config.setValue ('android-sdk' , sdkDir.path);
99
111
100
112
final AndroidSdk sdk = AndroidSdk .locateAndroidSdk ();
101
113
102
- expect (sdk.sdkManagerPath, globals.fs .path.join (sdk.directory, 'tools' , 'bin' , 'sdkmanager' ));
114
+ expect (sdk.sdkManagerPath, fileSystem .path.join (sdk.directory, 'tools' , 'bin' , 'sdkmanager' ));
103
115
}, overrides: < Type , Generator > {
104
- FileSystem : () => fs ,
116
+ FileSystem : () => fileSystem ,
105
117
ProcessManager : () => FakeProcessManager .any (),
118
+ Config : () => config,
106
119
});
107
120
108
121
testUsingContext ('returns sdkmanager version' , () {
109
122
sdkDir = MockAndroidSdk .createSdkDirectory ();
110
- globals. config.setValue ('android-sdk' , sdkDir.path);
123
+ config.setValue ('android-sdk' , sdkDir.path);
111
124
112
125
final AndroidSdk sdk = AndroidSdk .locateAndroidSdk ();
113
- when (globals. processManager.canRun (sdk.sdkManagerPath)).thenReturn (true );
114
- when (globals. processManager.runSync (< String > [sdk.sdkManagerPath, '--version' ],
126
+ when (processManager.canRun (sdk.sdkManagerPath)).thenReturn (true );
127
+ when (processManager.runSync (< String > [sdk.sdkManagerPath, '--version' ],
115
128
environment: argThat (isNotNull, named: 'environment' )))
116
129
.thenReturn (ProcessResult (1 , 0 , '26.1.1\n ' , '' ));
117
- if (globals.platform.isMacOS) {
118
- when (globals.processManager.runSync (
119
- < String > ['/usr/libexec/java_home' , '-v' , '1.8' ],
120
- workingDirectory: anyNamed ('workingDirectory' ),
121
- environment: anyNamed ('environment' ),
122
- )).thenReturn (ProcessResult (0 , 0 , '' , '' ));
123
- }
130
+ when (processManager.runSync (
131
+ < String > ['/usr/libexec/java_home' , '-v' , '1.8' ],
132
+ workingDirectory: anyNamed ('workingDirectory' ),
133
+ environment: anyNamed ('environment' ),
134
+ )).thenReturn (ProcessResult (0 , 0 , '' , '' ));
135
+
124
136
expect (sdk.sdkManagerVersion, '26.1.1' );
125
137
}, overrides: < Type , Generator > {
126
- FileSystem : () => fs ,
138
+ FileSystem : () => fileSystem ,
127
139
ProcessManager : () => processManager,
140
+ Config : () => config,
128
141
});
129
142
130
143
testUsingContext ('returns validate sdk is well formed' , () {
131
- sdkDir = MockBrokenAndroidSdk .createSdkDirectory ();
132
- globals.config.setValue ('android-sdk' , sdkDir.path);
144
+ sdkDir = MockBrokenAndroidSdk .createSdkDirectory (
145
+ fileSystem: fileSystem,
146
+ );
147
+ config.setValue ('android-sdk' , sdkDir.path);
133
148
134
149
final AndroidSdk sdk = AndroidSdk .locateAndroidSdk ();
135
- when (globals. processManager.canRun (sdk.adbPath)).thenReturn (true );
150
+ when (processManager.canRun (sdk.adbPath)).thenReturn (true );
136
151
137
152
final List <String > validationIssues = sdk.validateSdkWellFormed ();
138
153
expect (validationIssues.first, 'No valid Android SDK platforms found in'
139
154
' /.tmp_rand0/flutter_mock_android_sdk.rand0/platforms. Candidates were:\n '
140
155
' - android-22\n '
141
156
' - android-23' );
142
157
}, overrides: < Type , Generator > {
143
- FileSystem : () => fs ,
158
+ FileSystem : () => fileSystem ,
144
159
ProcessManager : () => processManager,
160
+ Config : () => config,
161
+ Platform : () => FakePlatform (operatingSystem: 'linux' ),
145
162
});
146
163
147
164
testUsingContext ('does not throw on sdkmanager version check failure' , () {
148
165
sdkDir = MockAndroidSdk .createSdkDirectory ();
149
- globals. config.setValue ('android-sdk' , sdkDir.path);
166
+ config.setValue ('android-sdk' , sdkDir.path);
150
167
151
168
final AndroidSdk sdk = AndroidSdk .locateAndroidSdk ();
152
- when (globals. processManager.canRun (sdk.sdkManagerPath)).thenReturn (true );
153
- when (globals. processManager.runSync (< String > [sdk.sdkManagerPath, '--version' ],
169
+ when (processManager.canRun (sdk.sdkManagerPath)).thenReturn (true );
170
+ when (processManager.runSync (< String > [sdk.sdkManagerPath, '--version' ],
154
171
environment: argThat (isNotNull, named: 'environment' )))
155
172
.thenReturn (ProcessResult (1 , 1 , '26.1.1\n ' , 'Mystery error' ));
156
- if (globals.platform.isMacOS) {
157
- when (globals.processManager.runSync (
158
- < String > ['/usr/libexec/java_home' , '-v' , '1.8' ],
159
- workingDirectory: anyNamed ('workingDirectory' ),
160
- environment: anyNamed ('environment' ),
161
- )).thenReturn (ProcessResult (0 , 0 , '' , '' ));
162
- }
173
+ when (processManager.runSync (
174
+ < String > ['/usr/libexec/java_home' , '-v' , '1.8' ],
175
+ workingDirectory: anyNamed ('workingDirectory' ),
176
+ environment: anyNamed ('environment' ),
177
+ )).thenReturn (ProcessResult (0 , 0 , '' , '' ));
178
+
163
179
expect (sdk.sdkManagerVersion, isNull);
164
180
}, overrides: < Type , Generator > {
165
- FileSystem : () => fs ,
181
+ FileSystem : () => fileSystem ,
166
182
ProcessManager : () => processManager,
183
+ Config : () => config,
167
184
});
168
185
169
186
testUsingContext ('throws on sdkmanager version check if sdkmanager not found' , () {
170
187
sdkDir = MockAndroidSdk .createSdkDirectory (withSdkManager: false );
171
- globals. config.setValue ('android-sdk' , sdkDir.path);
188
+ config.setValue ('android-sdk' , sdkDir.path);
172
189
173
190
final AndroidSdk sdk = AndroidSdk .locateAndroidSdk ();
174
- when (globals. processManager.canRun (sdk.sdkManagerPath)).thenReturn (false );
191
+ when (processManager.canRun (sdk.sdkManagerPath)).thenReturn (false );
175
192
expect (() => sdk.sdkManagerVersion, throwsToolExit ());
176
193
}, overrides: < Type , Generator > {
177
- FileSystem : () => fs ,
194
+ FileSystem : () => fileSystem ,
178
195
ProcessManager : () => processManager,
196
+ Config : () => config,
179
197
});
180
198
});
181
199
}
@@ -185,15 +203,15 @@ class MockBrokenAndroidSdk extends Mock implements AndroidSdk {
185
203
static Directory createSdkDirectory ({
186
204
bool withAndroidN = false ,
187
205
bool withSdkManager = true ,
206
+ @required FileSystem fileSystem,
188
207
}) {
189
- final Directory dir = globals.fs.systemTempDirectory.createTempSync ('flutter_mock_android_sdk.' );
190
- final String exe = globals.platform.isWindows ? '.exe' : '' ;
208
+ final Directory dir = fileSystem.systemTempDirectory.createTempSync ('flutter_mock_android_sdk.' );
191
209
_createSdkFile (dir, 'licenses/dummy' );
192
- _createSdkFile (dir, 'platform-tools/adb$ exe ' );
210
+ _createSdkFile (dir, 'platform-tools/adb' );
193
211
194
- _createSdkFile (dir, 'build-tools/sda/aapt$ exe ' );
195
- _createSdkFile (dir, 'build-tools/af/aapt$ exe ' );
196
- _createSdkFile (dir, 'build-tools/ljkasd/aapt$ exe ' );
212
+ _createSdkFile (dir, 'build-tools/sda/aapt' );
213
+ _createSdkFile (dir, 'build-tools/af/aapt' );
214
+ _createSdkFile (dir, 'build-tools/ljkasd/aapt' );
197
215
198
216
_createSdkFile (dir, 'platforms/android-22/android.jar' );
199
217
_createSdkFile (dir, 'platforms/android-23/android.jar' );
0 commit comments