Extract checking IntelliJ packages into a helper and use for Android Studio. (#16198)
This commit is contained in:
parent
48478b5952
commit
4658ec0f9c
@ -38,6 +38,7 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
|||||||
final Version version;
|
final Version version;
|
||||||
final String configured;
|
final String configured;
|
||||||
|
|
||||||
|
String _pluginsPath;
|
||||||
String _javaPath;
|
String _javaPath;
|
||||||
bool _isValid = false;
|
bool _isValid = false;
|
||||||
final List<String> _validationMessages = <String>[];
|
final List<String> _validationMessages = <String>[];
|
||||||
@ -81,6 +82,26 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
|||||||
|
|
||||||
bool get isValid => _isValid;
|
bool get isValid => _isValid;
|
||||||
|
|
||||||
|
String get pluginsPath {
|
||||||
|
if (_pluginsPath == null) {
|
||||||
|
final int major = version.major;
|
||||||
|
final int minor = version.minor;
|
||||||
|
if (platform.isMacOS) {
|
||||||
|
_pluginsPath = fs.path.join(
|
||||||
|
homeDirPath,
|
||||||
|
'Library',
|
||||||
|
'Application Support',
|
||||||
|
'AndroidStudio$major.$minor');
|
||||||
|
} else {
|
||||||
|
_pluginsPath = fs.path.join(homeDirPath,
|
||||||
|
'.AndroidStudio$major.$minor',
|
||||||
|
'config',
|
||||||
|
'plugins');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _pluginsPath;
|
||||||
|
}
|
||||||
|
|
||||||
List<String> get validationMessages => _validationMessages;
|
List<String> get validationMessages => _validationMessages;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -7,6 +7,7 @@ import 'dart:async';
|
|||||||
import '../base/version.dart';
|
import '../base/version.dart';
|
||||||
import '../doctor.dart';
|
import '../doctor.dart';
|
||||||
import '../globals.dart';
|
import '../globals.dart';
|
||||||
|
import '../intellij/intellij.dart';
|
||||||
import 'android_studio.dart';
|
import 'android_studio.dart';
|
||||||
|
|
||||||
class AndroidStudioValidator extends DoctorValidator {
|
class AndroidStudioValidator extends DoctorValidator {
|
||||||
@ -30,11 +31,18 @@ class AndroidStudioValidator extends DoctorValidator {
|
|||||||
Future<ValidationResult> validate() async {
|
Future<ValidationResult> validate() async {
|
||||||
final List<ValidationMessage> messages = <ValidationMessage>[];
|
final List<ValidationMessage> messages = <ValidationMessage>[];
|
||||||
ValidationType type = ValidationType.missing;
|
ValidationType type = ValidationType.missing;
|
||||||
|
|
||||||
final String studioVersionText = _studio.version == Version.unknown
|
final String studioVersionText = _studio.version == Version.unknown
|
||||||
? null
|
? null
|
||||||
: 'version ${_studio.version}';
|
: 'version ${_studio.version}';
|
||||||
messages
|
messages
|
||||||
.add(new ValidationMessage('Android Studio at ${_studio.directory}'));
|
.add(new ValidationMessage('Android Studio at ${_studio.directory}'));
|
||||||
|
|
||||||
|
final IntelliJPlugins plugins = new IntelliJPlugins(_studio.pluginsPath);
|
||||||
|
plugins.validatePackage(messages, <String>['flutter-intellij', 'flutter-intellij.jar'],
|
||||||
|
'Flutter', minVersion: IntelliJPlugins.kMinFlutterPluginVersion);
|
||||||
|
plugins.validatePackage(messages, <String>['Dart'], 'Dart');
|
||||||
|
|
||||||
if (_studio.isValid) {
|
if (_studio.isValid) {
|
||||||
type = ValidationType.installed;
|
type = ValidationType.installed;
|
||||||
messages.addAll(_studio.validationMessages
|
messages.addAll(_studio.validationMessages
|
||||||
|
@ -3,9 +3,6 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert' show utf8;
|
|
||||||
|
|
||||||
import 'package:archive/archive.dart';
|
|
||||||
|
|
||||||
import 'android/android_studio_validator.dart';
|
import 'android/android_studio_validator.dart';
|
||||||
import 'android/android_workflow.dart';
|
import 'android/android_workflow.dart';
|
||||||
@ -21,6 +18,7 @@ import 'base/version.dart';
|
|||||||
import 'cache.dart';
|
import 'cache.dart';
|
||||||
import 'device.dart';
|
import 'device.dart';
|
||||||
import 'globals.dart';
|
import 'globals.dart';
|
||||||
|
import 'intellij/intellij.dart';
|
||||||
import 'ios/ios_workflow.dart';
|
import 'ios/ios_workflow.dart';
|
||||||
import 'ios/plist_utils.dart';
|
import 'ios/plist_utils.dart';
|
||||||
import 'version.dart';
|
import 'version.dart';
|
||||||
@ -316,7 +314,6 @@ abstract class IntelliJValidator extends DoctorValidator {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static final Version kMinIdeaVersion = new Version(2017, 1, 0);
|
static final Version kMinIdeaVersion = new Version(2017, 1, 0);
|
||||||
static final Version kMinFlutterPluginVersion = new Version(16, 0, 0);
|
|
||||||
|
|
||||||
static Iterable<DoctorValidator> get installedValidators {
|
static Iterable<DoctorValidator> get installedValidators {
|
||||||
if (platform.isLinux || platform.isWindows)
|
if (platform.isLinux || platform.isWindows)
|
||||||
@ -332,9 +329,10 @@ abstract class IntelliJValidator extends DoctorValidator {
|
|||||||
|
|
||||||
messages.add(new ValidationMessage('IntelliJ at $installPath'));
|
messages.add(new ValidationMessage('IntelliJ at $installPath'));
|
||||||
|
|
||||||
_validatePackage(messages, <String>['flutter-intellij', 'flutter-intellij.jar'],
|
final IntelliJPlugins plugins = new IntelliJPlugins(pluginsPath);
|
||||||
'Flutter', minVersion: kMinFlutterPluginVersion);
|
plugins.validatePackage(messages, <String>['flutter-intellij', 'flutter-intellij.jar'],
|
||||||
_validatePackage(messages, <String>['Dart'], 'Dart');
|
'Flutter', minVersion: IntelliJPlugins.kMinFlutterPluginVersion);
|
||||||
|
plugins.validatePackage(messages, <String>['Dart'], 'Dart');
|
||||||
|
|
||||||
if (_hasIssues(messages)) {
|
if (_hasIssues(messages)) {
|
||||||
messages.add(new ValidationMessage(
|
messages.add(new ValidationMessage(
|
||||||
@ -371,70 +369,16 @@ abstract class IntelliJValidator extends DoctorValidator {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _validatePackage(List<ValidationMessage> messages, List<String> packageNames, String title, {
|
|
||||||
Version minVersion
|
|
||||||
}) {
|
|
||||||
for (String packageName in packageNames) {
|
|
||||||
if (!hasPackage(packageName)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String versionText = _readPackageVersion(packageName);
|
|
||||||
final Version version = new Version.parse(versionText);
|
|
||||||
if (version != null && minVersion != null && version < minVersion) {
|
|
||||||
messages.add(new ValidationMessage.error(
|
|
||||||
'$title plugin version $versionText - the recommended minimum version is $minVersion'
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
messages.add(new ValidationMessage(
|
|
||||||
'$title plugin ${version != null ? "version $version" : "installed"}'
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
messages.add(new ValidationMessage.error(
|
|
||||||
'$title plugin not installed; this adds $title specific functionality.'
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
String _readPackageVersion(String packageName) {
|
|
||||||
final String jarPath = packageName.endsWith('.jar')
|
|
||||||
? fs.path.join(pluginsPath, packageName)
|
|
||||||
: fs.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 {
|
|
||||||
final Archive archive = new ZipDecoder().decodeBytes(fs.file(jarPath).readAsBytesSync());
|
|
||||||
final ArchiveFile file = archive.findFile('META-INF/plugin.xml');
|
|
||||||
final String content = utf8.decode(file.content);
|
|
||||||
const String versionStartTag = '<version>';
|
|
||||||
final int start = content.indexOf(versionStartTag);
|
|
||||||
final int end = content.indexOf('</version>', start);
|
|
||||||
return content.substring(start + versionStartTag.length, end);
|
|
||||||
} catch (_) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasPackage(String packageName) {
|
|
||||||
final String packagePath = fs.path.join(pluginsPath, packageName);
|
|
||||||
if (packageName.endsWith('.jar'))
|
|
||||||
return fs.isFileSync(packagePath);
|
|
||||||
return fs.isDirectorySync(packagePath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class IntelliJValidatorOnLinuxAndWindows extends IntelliJValidator {
|
class IntelliJValidatorOnLinuxAndWindows extends IntelliJValidator {
|
||||||
IntelliJValidatorOnLinuxAndWindows(String title, this.version, String installPath, this.pluginsPath) : super(title, installPath);
|
IntelliJValidatorOnLinuxAndWindows(String title, this.version, String installPath, this.pluginsPath) : super(title, installPath);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String version;
|
final String version;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String pluginsPath;
|
final String pluginsPath;
|
||||||
|
|
||||||
static Iterable<DoctorValidator> get installed {
|
static Iterable<DoctorValidator> get installed {
|
||||||
final List<DoctorValidator> validators = <DoctorValidator>[];
|
final List<DoctorValidator> validators = <DoctorValidator>[];
|
||||||
|
71
packages/flutter_tools/lib/src/intellij/intellij.dart
Normal file
71
packages/flutter_tools/lib/src/intellij/intellij.dart
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
// Copyright 2018 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 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:archive/archive.dart';
|
||||||
|
|
||||||
|
import '../base/file_system.dart';
|
||||||
|
import '../base/version.dart';
|
||||||
|
import '../doctor.dart';
|
||||||
|
|
||||||
|
class IntelliJPlugins {
|
||||||
|
static final Version kMinFlutterPluginVersion = new Version(16, 0, 0);
|
||||||
|
|
||||||
|
final String pluginsPath;
|
||||||
|
|
||||||
|
IntelliJPlugins(this.pluginsPath);
|
||||||
|
|
||||||
|
void validatePackage(
|
||||||
|
List<ValidationMessage> messages, List<String> packageNames, String title,
|
||||||
|
{Version minVersion}) {
|
||||||
|
for (String packageName in packageNames) {
|
||||||
|
if (!_hasPackage(packageName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String versionText = _readPackageVersion(packageName);
|
||||||
|
final Version version = new Version.parse(versionText);
|
||||||
|
if (version != null && minVersion != null && version < minVersion) {
|
||||||
|
messages.add(new ValidationMessage.error(
|
||||||
|
'$title plugin version $versionText - the recommended minimum version is $minVersion'));
|
||||||
|
} else {
|
||||||
|
messages.add(new ValidationMessage(
|
||||||
|
'$title plugin ${version != null ? "version $version" : "installed"}'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
messages.add(new ValidationMessage.error(
|
||||||
|
'$title plugin not installed; this adds $title specific functionality.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _hasPackage(String packageName) {
|
||||||
|
final String packagePath = fs.path.join(pluginsPath, packageName);
|
||||||
|
if (packageName.endsWith('.jar'))
|
||||||
|
return fs.isFileSync(packagePath);
|
||||||
|
return fs.isDirectorySync(packagePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
String _readPackageVersion(String packageName) {
|
||||||
|
final String jarPath = packageName.endsWith('.jar')
|
||||||
|
? fs.path.join(pluginsPath, packageName)
|
||||||
|
: fs.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 {
|
||||||
|
final Archive archive =
|
||||||
|
new ZipDecoder().decodeBytes(fs.file(jarPath).readAsBytesSync());
|
||||||
|
final ArchiveFile file = archive.findFile('META-INF/plugin.xml');
|
||||||
|
final String content = utf8.decode(file.content);
|
||||||
|
const String versionStartTag = '<version>';
|
||||||
|
final int start = content.indexOf(versionStartTag);
|
||||||
|
final int end = content.indexOf('</version>', start);
|
||||||
|
return content.substring(start + versionStartTag.length, end);
|
||||||
|
} catch (_) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
57
packages/flutter_tools/test/intellij/intellij_test.dart
Normal file
57
packages/flutter_tools/test/intellij/intellij_test.dart
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
// Copyright 2018 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:flutter_tools/src/base/file_system.dart';
|
||||||
|
import 'package:flutter_tools/src/doctor.dart';
|
||||||
|
import 'package:flutter_tools/src/intellij/intellij.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
import '../src/context.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('IntelliJ', () {
|
||||||
|
group('plugins', () {
|
||||||
|
testUsingContext('found', () async {
|
||||||
|
final String pluginsPath =
|
||||||
|
fs.path.join('test', 'data', 'intellij', 'plugins');
|
||||||
|
final IntelliJPlugins plugins = new IntelliJPlugins(pluginsPath);
|
||||||
|
|
||||||
|
final List<ValidationMessage> messages = <ValidationMessage>[];
|
||||||
|
plugins.validatePackage(messages,
|
||||||
|
<String>['flutter-intellij', 'flutter-intellij.jar'], 'Flutter',
|
||||||
|
minVersion: IntelliJPlugins.kMinFlutterPluginVersion);
|
||||||
|
plugins.validatePackage(messages, <String>['Dart'], 'Dart');
|
||||||
|
|
||||||
|
ValidationMessage message = messages
|
||||||
|
.firstWhere((ValidationMessage m) => m.message.startsWith('Dart '));
|
||||||
|
expect(message.message, 'Dart plugin version 162.2485');
|
||||||
|
|
||||||
|
message = messages.firstWhere(
|
||||||
|
(ValidationMessage m) => m.message.startsWith('Flutter '));
|
||||||
|
expect(message.message, contains('Flutter plugin version 0.1.3'));
|
||||||
|
expect(message.message, contains('recommended minimum version'));
|
||||||
|
});
|
||||||
|
|
||||||
|
testUsingContext('not found', () async {
|
||||||
|
final String pluginsPath =
|
||||||
|
fs.path.join('test', 'data', 'intellij', 'no_plugins');
|
||||||
|
final IntelliJPlugins plugins = new IntelliJPlugins(pluginsPath);
|
||||||
|
|
||||||
|
final List<ValidationMessage> messages = <ValidationMessage>[];
|
||||||
|
plugins.validatePackage(messages,
|
||||||
|
<String>['flutter-intellij', 'flutter-intellij.jar'], 'Flutter',
|
||||||
|
minVersion: IntelliJPlugins.kMinFlutterPluginVersion);
|
||||||
|
plugins.validatePackage(messages, <String>['Dart'], 'Dart');
|
||||||
|
|
||||||
|
ValidationMessage message = messages
|
||||||
|
.firstWhere((ValidationMessage m) => m.message.startsWith('Dart '));
|
||||||
|
expect(message.message, contains('Dart plugin not installed'));
|
||||||
|
|
||||||
|
message = messages.firstWhere(
|
||||||
|
(ValidationMessage m) => m.message.startsWith('Flutter '));
|
||||||
|
expect(message.message, contains('Flutter plugin not installed'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user