mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
update flutter doctor to display versions for installed IntelliJ plugins (#7125)
This commit is contained in:
parent
5eada49b05
commit
a3caafe83c
@ -5,6 +5,8 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:archive/archive.dart';
|
||||
import 'dart:convert' show UTF8;
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'android/android_workflow.dart';
|
||||
@ -292,10 +294,31 @@ abstract class IntelliJValidator extends DoctorValidator {
|
||||
));
|
||||
return false;
|
||||
}
|
||||
messages.add(new ValidationMessage('$title plugin installed'));
|
||||
String version = _readPackageVersion(packageName);
|
||||
messages.add(new ValidationMessage('$title plugin '
|
||||
'${version != null ? "version $version" : "installed"}'));
|
||||
return true;
|
||||
}
|
||||
|
||||
String _readPackageVersion(String packageName) {
|
||||
String jarPath = packageName.endsWith('.jar')
|
||||
? path.join(pluginsPath, packageName)
|
||||
: path.join(pluginsPath, packageName, 'lib', '$packageName.jar');
|
||||
// TODO(danrubel) look for a better way to extract a single 2K file from the zip
|
||||
// rather than reading the entire file into memory.
|
||||
try {
|
||||
Archive archive = new ZipDecoder().decodeBytes(new File(jarPath).readAsBytesSync());
|
||||
ArchiveFile file = archive.findFile('META-INF/plugin.xml');
|
||||
String content = UTF8.decode(file.content);
|
||||
String versionStartTag = '<version>';
|
||||
int start = content.indexOf(versionStartTag);
|
||||
int end = content.indexOf('</version>', start);
|
||||
return content.substring(start + versionStartTag.length, end);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
bool hasPackage(String packageName) {
|
||||
String packagePath = path.join(pluginsPath, packageName);
|
||||
if (packageName.endsWith('.jar'))
|
||||
|
@ -26,6 +26,7 @@ import 'daemon_test.dart' as daemon_test;
|
||||
import 'devfs_test.dart' as devfs_test;
|
||||
import 'device_test.dart' as device_test;
|
||||
import 'devices_test.dart' as devices_test;
|
||||
import 'doctor_test.dart' as doctor_test;
|
||||
import 'drive_test.dart' as drive_test;
|
||||
import 'format_test.dart' as format_test;
|
||||
import 'install_test.dart' as install_test;
|
||||
@ -60,6 +61,7 @@ void main() {
|
||||
devfs_test.main();
|
||||
device_test.main();
|
||||
devices_test.main();
|
||||
doctor_test.main();
|
||||
drive_test.main();
|
||||
format_test.main();
|
||||
install_test.main();
|
||||
|
Binary file not shown.
Binary file not shown.
38
packages/flutter_tools/test/doctor_test.dart
Normal file
38
packages/flutter_tools/test/doctor_test.dart
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:flutter_tools/src/doctor.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'src/context.dart';
|
||||
|
||||
void main() {
|
||||
group('doctor', () {
|
||||
testUsingContext('intellij validator', () async {
|
||||
ValidationResult result = await new IntelliJValidatorTestTarget('Test').validate();
|
||||
expect(result.type, ValidationType.installed);
|
||||
expect(result.statusInfo, 'version test.test.test');
|
||||
expect(result.messages, hasLength(2));
|
||||
|
||||
ValidationMessage message = result.messages
|
||||
.firstWhere((ValidationMessage m) => m.message.startsWith('Dart '));
|
||||
expect(message.message, 'Dart plugin version 162.2485');
|
||||
|
||||
message = result.messages
|
||||
.firstWhere((ValidationMessage m) => m.message.startsWith('Flutter '));
|
||||
expect(message.message, 'Flutter plugin version 0.1.3');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class IntelliJValidatorTestTarget extends IntelliJValidator {
|
||||
IntelliJValidatorTestTarget(String title) : super(title);
|
||||
|
||||
@override
|
||||
String get pluginsPath => path.join('test', 'data', 'intellij', 'plugins');
|
||||
|
||||
@override
|
||||
String get version => 'test.test.test';
|
||||
}
|
Loading…
Reference in New Issue
Block a user