Commit 31366204 authored by Dan Rubel's avatar Dan Rubel Committed by GitHub

Flutter doctor detect intellij on Linux (#6227)

parent c09a1101
...@@ -39,7 +39,14 @@ class Doctor { ...@@ -39,7 +39,14 @@ class Doctor {
if (_iosWorkflow.appliesToHostPlatform) if (_iosWorkflow.appliesToHostPlatform)
_validators.add(_iosWorkflow); _validators.add(_iosWorkflow);
_validators.add(new AtomValidator()); List<DoctorValidator> ideValidators = <DoctorValidator>[];
ideValidators.addAll(AtomValidator.installed);
ideValidators.addAll(IntellijValidator.installed);
if (ideValidators.isNotEmpty)
_validators.addAll(ideValidators);
else
_validators.add(new NoIdeValidator());
_validators.add(new DeviceValidator()); _validators.add(new DeviceValidator());
} }
...@@ -121,10 +128,11 @@ class Doctor { ...@@ -121,10 +128,11 @@ class Doctor {
final String separator = Platform.isWindows ? ' ' : '•'; final String separator = Platform.isWindows ? ' ' : '•';
for (ValidationMessage message in result.messages) { for (ValidationMessage message in result.messages) {
String text = message.message.replaceAll('\n', '\n ');
if (message.isError) { if (message.isError) {
printStatus(' x ${message.message.replaceAll('\n', '\n ')}', emphasis: true); printStatus(' x $text', emphasis: true);
} else { } else {
printStatus(' $separator ${message.message.replaceAll('\n', '\n ')}'); printStatus(' $separator $text');
} }
} }
} }
...@@ -171,8 +179,6 @@ class ValidationResult { ...@@ -171,8 +179,6 @@ class ValidationResult {
final String statusInfo; final String statusInfo;
final List<ValidationMessage> messages; final List<ValidationMessage> messages;
bool get isInstalled => type == ValidationType.installed;
String get leadingBox { String get leadingBox {
if (type == ValidationType.missing) if (type == ValidationType.missing)
return '[x]'; return '[x]';
...@@ -226,9 +232,27 @@ class _FlutterValidator extends DoctorValidator { ...@@ -226,9 +232,27 @@ class _FlutterValidator extends DoctorValidator {
} }
} }
class NoIdeValidator extends DoctorValidator {
NoIdeValidator() : super('Flutter IDE Support');
@override
Future<ValidationResult> validate() async {
// TODO(danrubel): do not show Atom once IntelliJ support is complete
return new ValidationResult(ValidationType.missing, <ValidationMessage>[
new ValidationMessage('Atom - https://atom.io/'),
new ValidationMessage('IntelliJ - https://www.jetbrains.com/idea/'),
], statusInfo: 'No supported IDEs installed');
}
}
class AtomValidator extends DoctorValidator { class AtomValidator extends DoctorValidator {
AtomValidator() : super('Atom - a lightweight development environment for Flutter'); AtomValidator() : super('Atom - a lightweight development environment for Flutter');
static Iterable<DoctorValidator> get installed {
AtomValidator atom = new AtomValidator();
return atom.isInstalled ? <DoctorValidator>[atom] : <DoctorValidator>[];
}
static File getConfigFile() { static File getConfigFile() {
// ~/.atom/config.cson // ~/.atom/config.cson
return new File(path.join(_getAtomHomePath(), 'config.cson')); return new File(path.join(_getAtomHomePath(), 'config.cson'));
...@@ -243,29 +267,22 @@ class AtomValidator extends DoctorValidator { ...@@ -243,29 +267,22 @@ class AtomValidator extends DoctorValidator {
: path.join(env['HOME'], '.atom'); : path.join(env['HOME'], '.atom');
} }
bool get isInstalled => FileSystemEntity.isDirectorySync(_getAtomHomePath());
@override @override
Future<ValidationResult> validate() async { Future<ValidationResult> validate() async {
List<ValidationMessage> messages = <ValidationMessage>[]; List<ValidationMessage> messages = <ValidationMessage>[];
int installCount = 0; int installCount = 0;
bool atomDirExists = FileSystemEntity.isDirectorySync(_getAtomHomePath()); if (_validateHasPackage(messages, 'flutter', 'Flutter'))
if (!atomDirExists) {
messages.add(new ValidationMessage.error('Atom not installed; download at https://atom.io.'));
} else {
installCount++; installCount++;
if (!_validateHasPackage(messages, 'flutter', 'Flutter')) if (_validateHasPackage(messages, 'dartlang', 'Dart'))
installCount++; installCount++;
if (!_validateHasPackage(messages, 'dartlang', 'Dart'))
installCount++;
}
return new ValidationResult( return new ValidationResult(
installCount == 3 installCount == 2 ? ValidationType.installed : ValidationType.partial,
? ValidationType.installed
: installCount == 1 ? ValidationType.partial : ValidationType.missing,
messages messages
); );
} }
...@@ -276,19 +293,18 @@ class AtomValidator extends DoctorValidator { ...@@ -276,19 +293,18 @@ class AtomValidator extends DoctorValidator {
'$packageName plugin not installed; this adds $description specific functionality to Atom.\n' '$packageName plugin not installed; this adds $description specific functionality to Atom.\n'
'Install the plugin from Atom or run \'apm install $packageName\'.' 'Install the plugin from Atom or run \'apm install $packageName\'.'
)); ));
return true;
} else {
try {
String flutterPluginPath = path.join(_getAtomHomePath(), 'packages', packageName);
File packageFile = new File(path.join(flutterPluginPath, 'package.json'));
Map<String, dynamic> packageInfo = JSON.decode(packageFile.readAsStringSync());
String version = packageInfo['version'];
messages.add(new ValidationMessage('$packageName plugin version $version'));
} catch (error) {
printTrace('Unable to read $packageName plugin version: $error');
}
return false; return false;
} }
try {
String flutterPluginPath = path.join(_getAtomHomePath(), 'packages', packageName);
File packageFile = new File(path.join(flutterPluginPath, 'package.json'));
Map<String, dynamic> packageInfo = JSON.decode(packageFile.readAsStringSync());
String version = packageInfo['version'];
messages.add(new ValidationMessage('$packageName plugin version $version'));
} catch (error) {
printTrace('Unable to read $packageName plugin version: $error');
}
return true;
} }
bool hasPackage(String packageName) { bool hasPackage(String packageName) {
...@@ -297,6 +313,97 @@ class AtomValidator extends DoctorValidator { ...@@ -297,6 +313,97 @@ class AtomValidator extends DoctorValidator {
} }
} }
class IntellijValidator extends DoctorValidator {
IntellijValidator(String title, {this.version, this.pluginsPath}) : super(title);
final String version;
final String pluginsPath;
static Iterable<DoctorValidator> get installed {
List<DoctorValidator> validators = <DoctorValidator>[];
Map<String, String> products = <String, String>{
'IntelliJIdea' : 'IntelliJ IDEA Ultimate Edition',
'IdeaIC' : 'IntelliJ IDEA Community Edition',
'WebStorm' : 'IntelliJ WebStorm',
};
String homeDir = Platform.environment['HOME'];
if (Platform.isLinux && homeDir != null) {
for (FileSystemEntity dir in new Directory(homeDir).listSync()) {
if (dir is Directory) {
String name = path.basename(dir.path);
products.forEach((String id, String title) {
if (name.startsWith('.$id')) {
String version = name.substring(id.length + 1);
String installPath;
try {
installPath = new File(path.join(dir.path, 'system', '.home')).readAsStringSync();
} catch (e) {
// ignored
}
if (installPath != null && FileSystemEntity.isDirectorySync(installPath)) {
validators.add(new IntellijValidator(
title,
version: version,
pluginsPath: path.join(dir.path, 'config', 'plugins'),
));
}
}
});
}
}
} else if (Platform.isMacOS) {
// TODO(danrubel): add support for Mac
} else {
// TODO(danrubel): add support for Windows
}
return validators;
}
@override
Future<ValidationResult> validate() async {
List<ValidationMessage> messages = <ValidationMessage>[];
int installCount = 0;
if (_validateHasPackage(messages, 'Dart', 'Dart'))
installCount++;
if (_validateHasPackage(messages, 'Flutter', 'Flutter'))
installCount++;
if (installCount < 2) {
messages.add(new ValidationMessage(
'For information about managing plugins, see\n'
'https://www.jetbrains.com/help/idea/2016.2/managing-plugins.html'
));
}
return new ValidationResult(
installCount == 2 ? ValidationType.installed : ValidationType.partial,
messages,
statusInfo: 'version $version'
);
}
bool _validateHasPackage(List<ValidationMessage> messages, String packageName, String description) {
if (!hasPackage(packageName)) {
messages.add(new ValidationMessage(
'$packageName plugin not installed; this adds $description specific functionality.'
));
return false;
}
messages.add(new ValidationMessage('$packageName plugin installed'));
return true;
}
bool hasPackage(String packageName) {
String packagePath = path.join(pluginsPath, packageName);
return FileSystemEntity.isDirectorySync(packagePath);
}
}
class DeviceValidator extends DoctorValidator { class DeviceValidator extends DoctorValidator {
DeviceValidator() : super('Connected devices'); DeviceValidator() : super('Connected devices');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment