@@ -39,7 +39,14 @@ class Doctor {
39
39
if (_iosWorkflow.appliesToHostPlatform)
40
40
_validators.add (_iosWorkflow);
41
41
42
- _validators.add (new AtomValidator ());
42
+ List <DoctorValidator > ideValidators = < DoctorValidator > [];
43
+ ideValidators.addAll (AtomValidator .installed);
44
+ ideValidators.addAll (IntellijValidator .installed);
45
+ if (ideValidators.isNotEmpty)
46
+ _validators.addAll (ideValidators);
47
+ else
48
+ _validators.add (new NoIdeValidator ());
49
+
43
50
_validators.add (new DeviceValidator ());
44
51
}
45
52
@@ -121,10 +128,11 @@ class Doctor {
121
128
final String separator = Platform .isWindows ? ' ' : '•' ;
122
129
123
130
for (ValidationMessage message in result.messages) {
131
+ String text = message.message.replaceAll ('\n ' , '\n ' );
124
132
if (message.isError) {
125
- printStatus (' x ${ message . message . replaceAll ( ' \n ' , ' \n ' )} ' , emphasis: true );
133
+ printStatus (' x $text ' , emphasis: true );
126
134
} else {
127
- printStatus (' $separator ${ message . message . replaceAll ( ' \n ' , ' \n ' )} ' );
135
+ printStatus (' $separator $text ' );
128
136
}
129
137
}
130
138
}
@@ -171,8 +179,6 @@ class ValidationResult {
171
179
final String statusInfo;
172
180
final List <ValidationMessage > messages;
173
181
174
- bool get isInstalled => type == ValidationType .installed;
175
-
176
182
String get leadingBox {
177
183
if (type == ValidationType .missing)
178
184
return '[x]' ;
@@ -226,9 +232,27 @@ class _FlutterValidator extends DoctorValidator {
226
232
}
227
233
}
228
234
235
+ class NoIdeValidator extends DoctorValidator {
236
+ NoIdeValidator () : super ('Flutter IDE Support' );
237
+
238
+ @override
239
+ Future <ValidationResult > validate () async {
240
+ // TODO(danrubel): do not show Atom once IntelliJ support is complete
241
+ return new ValidationResult (ValidationType .missing, < ValidationMessage > [
242
+ new ValidationMessage ('Atom - https://atom.io/' ),
243
+ new ValidationMessage ('IntelliJ - https://www.jetbrains.com/idea/' ),
244
+ ], statusInfo: 'No supported IDEs installed' );
245
+ }
246
+ }
247
+
229
248
class AtomValidator extends DoctorValidator {
230
249
AtomValidator () : super ('Atom - a lightweight development environment for Flutter' );
231
250
251
+ static Iterable <DoctorValidator > get installed {
252
+ AtomValidator atom = new AtomValidator ();
253
+ return atom.isInstalled ? < DoctorValidator > [atom] : < DoctorValidator > [];
254
+ }
255
+
232
256
static File getConfigFile () {
233
257
// ~/.atom/config.cson
234
258
return new File (path.join (_getAtomHomePath (), 'config.cson' ));
@@ -243,29 +267,22 @@ class AtomValidator extends DoctorValidator {
243
267
: path.join (env['HOME' ], '.atom' );
244
268
}
245
269
270
+ bool get isInstalled => FileSystemEntity .isDirectorySync (_getAtomHomePath ());
271
+
246
272
@override
247
273
Future <ValidationResult > validate () async {
248
274
List <ValidationMessage > messages = < ValidationMessage > [];
249
275
250
276
int installCount = 0 ;
251
277
252
- bool atomDirExists = FileSystemEntity .isDirectorySync (_getAtomHomePath ());
253
- if (! atomDirExists) {
254
- messages.add (new ValidationMessage .error ('Atom not installed; download at https://atom.io.' ));
255
- } else {
278
+ if (_validateHasPackage (messages, 'flutter' , 'Flutter' ))
256
279
installCount++ ;
257
280
258
- if (! _validateHasPackage (messages, 'flutter' , 'Flutter' ))
259
- installCount++ ;
260
-
261
- if (! _validateHasPackage (messages, 'dartlang' , 'Dart' ))
262
- installCount++ ;
263
- }
281
+ if (_validateHasPackage (messages, 'dartlang' , 'Dart' ))
282
+ installCount++ ;
264
283
265
284
return new ValidationResult (
266
- installCount == 3
267
- ? ValidationType .installed
268
- : installCount == 1 ? ValidationType .partial : ValidationType .missing,
285
+ installCount == 2 ? ValidationType .installed : ValidationType .partial,
269
286
messages
270
287
);
271
288
}
@@ -276,19 +293,18 @@ class AtomValidator extends DoctorValidator {
276
293
'$packageName plugin not installed; this adds $description specific functionality to Atom.\n '
277
294
'Install the plugin from Atom or run \' apm install $packageName \' .'
278
295
));
279
- return true ;
280
- } else {
281
- try {
282
- String flutterPluginPath = path.join (_getAtomHomePath (), 'packages' , packageName);
283
- File packageFile = new File (path.join (flutterPluginPath, 'package.json' ));
284
- Map <String , dynamic > packageInfo = JSON .decode (packageFile.readAsStringSync ());
285
- String version = packageInfo['version' ];
286
- messages.add (new ValidationMessage ('$packageName plugin version $version ' ));
287
- } catch (error) {
288
- printTrace ('Unable to read $packageName plugin version: $error ' );
289
- }
290
296
return false ;
291
297
}
298
+ try {
299
+ String flutterPluginPath = path.join (_getAtomHomePath (), 'packages' , packageName);
300
+ File packageFile = new File (path.join (flutterPluginPath, 'package.json' ));
301
+ Map <String , dynamic > packageInfo = JSON .decode (packageFile.readAsStringSync ());
302
+ String version = packageInfo['version' ];
303
+ messages.add (new ValidationMessage ('$packageName plugin version $version ' ));
304
+ } catch (error) {
305
+ printTrace ('Unable to read $packageName plugin version: $error ' );
306
+ }
307
+ return true ;
292
308
}
293
309
294
310
bool hasPackage (String packageName) {
@@ -297,6 +313,97 @@ class AtomValidator extends DoctorValidator {
297
313
}
298
314
}
299
315
316
+ class IntellijValidator extends DoctorValidator {
317
+ IntellijValidator (String title, {this .version, this .pluginsPath}) : super (title);
318
+
319
+ final String version;
320
+ final String pluginsPath;
321
+
322
+ static Iterable <DoctorValidator > get installed {
323
+ List <DoctorValidator > validators = < DoctorValidator > [];
324
+ Map <String , String > products = < String , String > {
325
+ 'IntelliJIdea' : 'IntelliJ IDEA Ultimate Edition' ,
326
+ 'IdeaIC' : 'IntelliJ IDEA Community Edition' ,
327
+ 'WebStorm' : 'IntelliJ WebStorm' ,
328
+ };
329
+ String homeDir = Platform .environment['HOME' ];
330
+
331
+ if (Platform .isLinux && homeDir != null ) {
332
+ for (FileSystemEntity dir in new Directory (homeDir).listSync ()) {
333
+ if (dir is Directory ) {
334
+ String name = path.basename (dir.path);
335
+ products.forEach ((String id, String title) {
336
+ if (name.startsWith ('.$id ' )) {
337
+ String version = name.substring (id.length + 1 );
338
+ String installPath;
339
+ try {
340
+ installPath = new File (path.join (dir.path, 'system' , '.home' )).readAsStringSync ();
341
+ } catch (e) {
342
+ // ignored
343
+ }
344
+ if (installPath != null && FileSystemEntity .isDirectorySync (installPath)) {
345
+ validators.add (new IntellijValidator (
346
+ title,
347
+ version: version,
348
+ pluginsPath: path.join (dir.path, 'config' , 'plugins' ),
349
+ ));
350
+ }
351
+ }
352
+ });
353
+ }
354
+ }
355
+ } else if (Platform .isMacOS) {
356
+ // TODO(danrubel): add support for Mac
357
+
358
+ } else {
359
+ // TODO(danrubel): add support for Windows
360
+ }
361
+ return validators;
362
+ }
363
+
364
+ @override
365
+ Future <ValidationResult > validate () async {
366
+ List <ValidationMessage > messages = < ValidationMessage > [];
367
+
368
+ int installCount = 0 ;
369
+
370
+ if (_validateHasPackage (messages, 'Dart' , 'Dart' ))
371
+ installCount++ ;
372
+
373
+ if (_validateHasPackage (messages, 'Flutter' , 'Flutter' ))
374
+ installCount++ ;
375
+
376
+ if (installCount < 2 ) {
377
+ messages.add (new ValidationMessage (
378
+ 'For information about managing plugins, see\n '
379
+ 'https://www.jetbrains.com/help/idea/2016.2/managing-plugins.html'
380
+ ));
381
+ }
382
+
383
+ return new ValidationResult (
384
+ installCount == 2 ? ValidationType .installed : ValidationType .partial,
385
+ messages,
386
+ statusInfo: 'version $version '
387
+ );
388
+ }
389
+
390
+ bool _validateHasPackage (List <ValidationMessage > messages, String packageName, String description) {
391
+ if (! hasPackage (packageName)) {
392
+ messages.add (new ValidationMessage (
393
+ '$packageName plugin not installed; this adds $description specific functionality.'
394
+ ));
395
+ return false ;
396
+ }
397
+ messages.add (new ValidationMessage ('$packageName plugin installed' ));
398
+ return true ;
399
+ }
400
+
401
+ bool hasPackage (String packageName) {
402
+ String packagePath = path.join (pluginsPath, packageName);
403
+ return FileSystemEntity .isDirectorySync (packagePath);
404
+ }
405
+ }
406
+
300
407
class DeviceValidator extends DoctorValidator {
301
408
DeviceValidator () : super ('Connected devices' );
302
409
0 commit comments