From cba84d5127c03fec1a6f90000510d4b89e341012 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Fri, 9 Oct 2020 13:05:42 -0700 Subject: [PATCH] [flutter_tools] remove globals from IntelliJ validator, refactor tests to remove dependency on JAR (#67240) Move the intellij validator to its own file, and split off the tests. Remove globals from each, and remove dependency on a real jar/filesystem by creating a minimal version of the manifest xml and setting it up in the memory file system. #47161 --- packages/flutter_tools/lib/src/doctor.dart | 277 +-------------- .../lib/src/intellij/intellij.dart | 10 +- .../lib/src/intellij/intellij_validator.dart | 332 ++++++++++++++++++ .../commands.shard/hermetic/doctor_test.dart | 96 ----- .../data/intellij/plugins/Dart/lib/Dart.jar | Bin 4138 -> 0 bytes .../intellij/plugins/flutter-intellij.jar | Bin 1822 -> 0 bytes .../intellij/intellij_validator_test.dart | 190 ++++++++++ 7 files changed, 538 insertions(+), 367 deletions(-) create mode 100644 packages/flutter_tools/lib/src/intellij/intellij_validator.dart delete mode 100644 packages/flutter_tools/test/data/intellij/plugins/Dart/lib/Dart.jar delete mode 100644 packages/flutter_tools/test/data/intellij/plugins/flutter-intellij.jar create mode 100644 packages/flutter_tools/test/general.shard/intellij/intellij_validator_test.dart diff --git a/packages/flutter_tools/lib/src/doctor.dart b/packages/flutter_tools/lib/src/doctor.dart index ee83be8763..aad6b9b17e 100644 --- a/packages/flutter_tools/lib/src/doctor.dart +++ b/packages/flutter_tools/lib/src/doctor.dart @@ -17,14 +17,12 @@ import 'base/platform.dart'; import 'base/terminal.dart'; import 'base/user_messages.dart'; import 'base/utils.dart'; -import 'base/version.dart'; import 'cache.dart'; import 'device.dart'; import 'features.dart'; import 'fuchsia/fuchsia_workflow.dart'; import 'globals.dart' as globals; -import 'intellij/intellij.dart'; -import 'ios/plist_parser.dart'; +import 'intellij/intellij_validator.dart'; import 'linux/linux_doctor.dart'; import 'linux/linux_workflow.dart'; import 'macos/macos_workflow.dart'; @@ -77,7 +75,12 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider { final List ideValidators = [ ...AndroidStudioValidator.allValidators(globals.config, globals.platform, globals.fs, globals.userMessages), - ...IntelliJValidator.installedValidators(globals.fs, globals.platform), + ...IntelliJValidator.installedValidators( + fileSystem: globals.fs, + platform: globals.platform, + userMessages: userMessages, + plistParser: globals.plistParser, + ), ...VsCodeValidator.installedValidators(globals.fs, globals.platform), ]; final ProxyValidator proxyValidator = ProxyValidator(platform: globals.platform); @@ -774,272 +777,6 @@ class NoIdeValidator extends DoctorValidator { } } -/// A doctor validator for both Intellij and Android Studio. -abstract class IntelliJValidator extends DoctorValidator { - IntelliJValidator(String title, this.installPath, { - @required FileSystem fileSystem, - }) : _fileSystem = fileSystem, - super(title); - - final String installPath; - final FileSystem _fileSystem; - - String get version; - String get pluginsPath; - - static final Map _idToTitle = { - 'IntelliJIdea': 'IntelliJ IDEA Ultimate Edition', - 'IdeaIC': 'IntelliJ IDEA Community Edition', - }; - - static final Version kMinIdeaVersion = Version(2017, 1, 0); - - static Iterable installedValidators(FileSystem fileSystem, Platform platform) { - if (platform.isLinux || platform.isWindows) { - return IntelliJValidatorOnLinuxAndWindows.installed(fileSystem); - } - if (platform.isMacOS) { - return IntelliJValidatorOnMac.installed(fileSystem); - } - return []; - } - - @override - Future validate() async { - final List messages = []; - - if (pluginsPath == null) { - messages.add(const ValidationMessage.error('Invalid IntelliJ version number.')); - } else { - messages.add(ValidationMessage(userMessages.intellijLocation(installPath))); - - final IntelliJPlugins plugins = IntelliJPlugins(pluginsPath, fileSystem: _fileSystem); - plugins.validatePackage( - messages, - ['flutter-intellij', 'flutter-intellij.jar'], - 'Flutter', - IntelliJPlugins.kIntellijFlutterPluginUrl, - minVersion: IntelliJPlugins.kMinFlutterPluginVersion, - ); - plugins.validatePackage( - messages, - ['Dart'], - 'Dart', - IntelliJPlugins.kIntellijDartPluginUrl, - ); - - if (_hasIssues(messages)) { - messages.add(ValidationMessage(userMessages.intellijPluginInfo)); - } - - _validateIntelliJVersion(messages, kMinIdeaVersion); - } - - return ValidationResult( - _hasIssues(messages) ? ValidationType.partial : ValidationType.installed, - messages, - statusInfo: userMessages.intellijStatusInfo(version), - ); - } - - bool _hasIssues(List messages) { - return messages.any((ValidationMessage message) => message.isError); - } - - void _validateIntelliJVersion(List messages, Version minVersion) { - // Ignore unknown versions. - if (minVersion == Version.unknown) { - return; - } - - final Version installedVersion = Version.parse(version); - if (installedVersion == null) { - return; - } - - if (installedVersion < minVersion) { - messages.add(ValidationMessage.error(userMessages.intellijMinimumVersion(minVersion.toString()))); - } - } -} - -/// A linux and windows specific implementation of the intellij validator. -class IntelliJValidatorOnLinuxAndWindows extends IntelliJValidator { - IntelliJValidatorOnLinuxAndWindows(String title, this.version, String installPath, this.pluginsPath, { - @required FileSystem fileSystem, - }) : super(title, installPath, fileSystem: fileSystem); - - @override - final String version; - - @override - final String pluginsPath; - - static Iterable installed(FileSystem fileSystem) { - final List validators = []; - if (globals.fsUtils.homeDirPath == null) { - return validators; - } - - void addValidator(String title, String version, String installPath, String pluginsPath) { - final IntelliJValidatorOnLinuxAndWindows validator = - IntelliJValidatorOnLinuxAndWindows(title, version, installPath, pluginsPath, fileSystem: fileSystem); - for (int index = 0; index < validators.length; ++index) { - final DoctorValidator other = validators[index]; - if (other is IntelliJValidatorOnLinuxAndWindows && validator.installPath == other.installPath) { - if (validator.version.compareTo(other.version) > 0) { - validators[index] = validator; - } - return; - } - } - validators.add(validator); - } - - final Directory homeDir = globals.fs.directory(globals.fsUtils.homeDirPath); - for (final Directory dir in homeDir.listSync().whereType()) { - final String name = globals.fs.path.basename(dir.path); - IntelliJValidator._idToTitle.forEach((String id, String title) { - if (name.startsWith('.$id')) { - final String version = name.substring(id.length + 1); - String installPath; - try { - installPath = globals.fs.file(globals.fs.path.join(dir.path, 'system', '.home')).readAsStringSync(); - } on Exception { - // ignored - } - if (installPath != null && globals.fs.isDirectorySync(installPath)) { - final String pluginsPath = globals.fs.path.join(dir.path, 'config', 'plugins'); - addValidator(title, version, installPath, pluginsPath); - } - } - }); - } - return validators; - } -} - -/// A macOS specific implementation of the intellij validator. -class IntelliJValidatorOnMac extends IntelliJValidator { - IntelliJValidatorOnMac(String title, this.id, String installPath, { - @required FileSystem fileSystem, - }) : super(title, installPath, fileSystem: fileSystem); - - final String id; - - static final Map _dirNameToId = { - 'IntelliJ IDEA.app': 'IntelliJIdea', - 'IntelliJ IDEA Ultimate.app': 'IntelliJIdea', - 'IntelliJ IDEA CE.app': 'IdeaIC', - }; - - static Iterable installed(FileSystem fileSystem) { - final List validators = []; - final List installPaths = [ - '/Applications', - fileSystem.path.join(globals.fsUtils.homeDirPath, 'Applications'), - ]; - - void checkForIntelliJ(Directory dir) { - final String name = fileSystem.path.basename(dir.path); - _dirNameToId.forEach((String dirName, String id) { - if (name == dirName) { - final String title = IntelliJValidator._idToTitle[id]; - validators.add(IntelliJValidatorOnMac(title, id, dir.path, fileSystem: fileSystem)); - } - }); - } - - try { - final Iterable installDirs = installPaths - .map(fileSystem.directory) - .map>((Directory dir) => dir.existsSync() ? dir.listSync() : []) - .expand((List mappedDirs) => mappedDirs) - .whereType(); - for (final Directory dir in installDirs) { - checkForIntelliJ(dir); - if (!dir.path.endsWith('.app')) { - for (final FileSystemEntity subdir in dir.listSync()) { - if (subdir is Directory) { - checkForIntelliJ(subdir); - } - } - } - } - } on FileSystemException catch (e) { - validators.add(ValidatorWithResult( - userMessages.intellijMacUnknownResult, - ValidationResult(ValidationType.missing, [ - ValidationMessage.error(e.message), - ]), - )); - } - return validators; - } - - @visibleForTesting - String get plistFile { - _plistFile ??= _fileSystem.path.join(installPath, 'Contents', 'Info.plist'); - return _plistFile; - } - String _plistFile; - - @override - String get version { - _version ??= globals.plistParser.getValueFromFile( - plistFile, - PlistParser.kCFBundleShortVersionStringKey, - ) ?? 'unknown'; - return _version; - } - String _version; - - @override - String get pluginsPath { - if (_pluginsPath != null) { - return _pluginsPath; - } - - final String altLocation = globals.plistParser - .getValueFromFile(plistFile, 'JetBrainsToolboxApp'); - - if (altLocation != null) { - _pluginsPath = altLocation + '.plugins'; - return _pluginsPath; - } - - final List split = version.split('.'); - if (split.length < 2) { - return null; - } - final String major = split[0]; - final String minor = split[1]; - - final String homeDirPath = globals.fsUtils.homeDirPath; - String pluginsPath = globals.fs.path.join( - homeDirPath, - 'Library', - 'Application Support', - 'JetBrains', - '$id$major.$minor', - 'plugins', - ); - // Fallback to legacy location from < 2020. - if (!globals.fs.isDirectorySync(pluginsPath)) { - pluginsPath = globals.fs.path.join( - homeDirPath, - 'Library', - 'Application Support', - '$id$major.$minor', - ); - } - _pluginsPath = pluginsPath; - - return _pluginsPath; - } - String _pluginsPath; -} - class DeviceValidator extends DoctorValidator { // TODO(jmagman): Make required once g3 rolls and is updated. DeviceValidator({ diff --git a/packages/flutter_tools/lib/src/intellij/intellij.dart b/packages/flutter_tools/lib/src/intellij/intellij.dart index 690b0dc315..2fbb3e1969 100644 --- a/packages/flutter_tools/lib/src/intellij/intellij.dart +++ b/packages/flutter_tools/lib/src/intellij/intellij.dart @@ -10,6 +10,14 @@ import '../base/version.dart'; import '../convert.dart'; import '../doctor.dart'; +/// A parser for the Intellij and Android Studio plugin JAR files. +/// +/// This searches on the provided plugin path for a JAR archive, then +/// unzips it to parse the META-INF/plugin.xml for version information. +/// +/// See also: +/// * [IntellijValidator], the validator base class that uses this to check +/// plugin versions. class IntelliJPlugins { IntelliJPlugins(this.pluginsPath, { @required FileSystem fileSystem @@ -74,7 +82,7 @@ class IntelliJPlugins { final int start = content.indexOf(versionStartTag); final int end = content.indexOf('', start); return content.substring(start + versionStartTag.length, end); - } on Exception { + } on ArchiveException { return null; } } diff --git a/packages/flutter_tools/lib/src/intellij/intellij_validator.dart b/packages/flutter_tools/lib/src/intellij/intellij_validator.dart new file mode 100644 index 0000000000..d27c4deb80 --- /dev/null +++ b/packages/flutter_tools/lib/src/intellij/intellij_validator.dart @@ -0,0 +1,332 @@ +// Copyright 2014 The Flutter 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:meta/meta.dart'; + +import '../base/file_system.dart'; +import '../base/platform.dart'; +import '../base/user_messages.dart' hide userMessages; +import '../base/version.dart'; +import '../doctor.dart'; +import '../ios/plist_parser.dart'; +import 'intellij.dart'; + +/// A doctor validator for both Intellij and Android Studio. +abstract class IntelliJValidator extends DoctorValidator { + IntelliJValidator(String title, this.installPath, { + @required FileSystem fileSystem, + @required UserMessages userMessages, + }) : _fileSystem = fileSystem, + _userMessages = userMessages, + super(title); + + final String installPath; + final FileSystem _fileSystem; + final UserMessages _userMessages; + + String get version; + + String get pluginsPath; + + static const Map _idToTitle = { + 'IntelliJIdea': 'IntelliJ IDEA Ultimate Edition', + 'IdeaIC': 'IntelliJ IDEA Community Edition', + }; + + static final Version kMinIdeaVersion = Version(2017, 1, 0); + + /// Create a [DoctorValidator] for each installation of Intellij. + /// + /// On platforms other than macOS, Linux, and Windows this returns an + /// empty list. + static Iterable installedValidators({ + @required FileSystem fileSystem, + @required Platform platform, + @required UserMessages userMessages, + @required PlistParser plistParser, + }) { + final FileSystemUtils fileSystemUtils = FileSystemUtils(fileSystem: fileSystem, platform: platform); + if (platform.isLinux || platform.isWindows) { + return IntelliJValidatorOnLinuxAndWindows.installed( + fileSystem: fileSystem, + fileSystemUtils: fileSystemUtils, + userMessages: userMessages, + ); + } + if (platform.isMacOS) { + return IntelliJValidatorOnMac.installed( + fileSystem: fileSystem, + fileSystemUtils: fileSystemUtils, + userMessages: userMessages, + plistParser: plistParser, + ); + } + return []; + } + + @override + Future validate() async { + final List messages = []; + + if (pluginsPath == null) { + messages.add(const ValidationMessage.error('Invalid IntelliJ version number.')); + } else { + messages.add(ValidationMessage(_userMessages.intellijLocation(installPath))); + + final IntelliJPlugins plugins = IntelliJPlugins(pluginsPath, fileSystem: _fileSystem); + plugins.validatePackage( + messages, + ['flutter-intellij', 'flutter-intellij.jar'], + 'Flutter', + IntelliJPlugins.kIntellijFlutterPluginUrl, + minVersion: IntelliJPlugins.kMinFlutterPluginVersion, + ); + plugins.validatePackage( + messages, + ['Dart'], + 'Dart', + IntelliJPlugins.kIntellijDartPluginUrl, + ); + + if (_hasIssues(messages)) { + messages.add(ValidationMessage(_userMessages.intellijPluginInfo)); + } + + _validateIntelliJVersion(messages, kMinIdeaVersion); + } + + return ValidationResult( + _hasIssues(messages) ? ValidationType.partial : ValidationType.installed, + messages, + statusInfo: _userMessages.intellijStatusInfo(version), + ); + } + + bool _hasIssues(List messages) { + return messages.any((ValidationMessage message) => message.isError); + } + + void _validateIntelliJVersion(List messages, Version minVersion) { + // Ignore unknown versions. + if (minVersion == Version.unknown) { + return; + } + + final Version installedVersion = Version.parse(version); + if (installedVersion == null) { + return; + } + + if (installedVersion < minVersion) { + messages.add(ValidationMessage.error(_userMessages.intellijMinimumVersion(minVersion.toString()))); + } + } +} + +/// A linux and windows specific implementation of the intellij validator. +class IntelliJValidatorOnLinuxAndWindows extends IntelliJValidator { + IntelliJValidatorOnLinuxAndWindows(String title, this.version, String installPath, this.pluginsPath, { + @required FileSystem fileSystem, + @required UserMessages userMessages, + }) : super(title, installPath, fileSystem: fileSystem, userMessages: userMessages); + + @override + final String version; + + @override + final String pluginsPath; + + static Iterable installed({ + @required FileSystem fileSystem, + @required FileSystemUtils fileSystemUtils, + @required UserMessages userMessages, + }) { + final List validators = []; + if (fileSystemUtils.homeDirPath == null) { + return validators; + } + + void addValidator(String title, String version, String installPath, String pluginsPath) { + final IntelliJValidatorOnLinuxAndWindows validator = IntelliJValidatorOnLinuxAndWindows( + title, + version, + installPath, + pluginsPath, + fileSystem: fileSystem, + userMessages: userMessages, + ); + for (int index = 0; index < validators.length; index += 1) { + final DoctorValidator other = validators[index]; + if (other is IntelliJValidatorOnLinuxAndWindows && validator.installPath == other.installPath) { + if (validator.version.compareTo(other.version) > 0) { + validators[index] = validator; + } + return; + } + } + validators.add(validator); + } + + final Directory homeDir = fileSystem.directory(fileSystemUtils.homeDirPath); + for (final Directory dir in homeDir.listSync().whereType()) { + final String name = fileSystem.path.basename(dir.path); + IntelliJValidator._idToTitle.forEach((String id, String title) { + if (name.startsWith('.$id')) { + final String version = name.substring(id.length + 1); + String installPath; + try { + installPath = fileSystem.file(fileSystem.path.join(dir.path, 'system', '.home')).readAsStringSync(); + } on FileSystemException { + // ignored + } + if (installPath != null && fileSystem.isDirectorySync(installPath)) { + final String pluginsPath = fileSystem.path.join(dir.path, 'config', 'plugins'); + addValidator(title, version, installPath, pluginsPath); + } + } + }); + } + return validators; + } +} + +/// A macOS specific implementation of the intellij validator. +class IntelliJValidatorOnMac extends IntelliJValidator { + IntelliJValidatorOnMac(String title, this.id, String installPath, { + @required FileSystem fileSystem, + @required UserMessages userMessages, + @required PlistParser plistParser, + @required String homeDirPath, + }) : _plistParser = plistParser, + _homeDirPath = homeDirPath, + super(title, installPath, fileSystem: fileSystem, userMessages: userMessages); + + final String id; + final PlistParser _plistParser; + final String _homeDirPath; + + static const Map _dirNameToId = { + 'IntelliJ IDEA.app': 'IntelliJIdea', + 'IntelliJ IDEA Ultimate.app': 'IntelliJIdea', + 'IntelliJ IDEA CE.app': 'IdeaIC', + }; + + static Iterable installed({ + @required FileSystem fileSystem, + @required FileSystemUtils fileSystemUtils, + @required UserMessages userMessages, + @required PlistParser plistParser, + }) { + final List validators = []; + final List installPaths = [ + '/Applications', + fileSystem.path.join(fileSystemUtils.homeDirPath, 'Applications'), + ]; + + void checkForIntelliJ(Directory dir) { + final String name = fileSystem.path.basename(dir.path); + _dirNameToId.forEach((String dirName, String id) { + if (name == dirName) { + final String title = IntelliJValidator._idToTitle[id]; + validators.add(IntelliJValidatorOnMac( + title, + id, + dir.path, + fileSystem: fileSystem, + userMessages: userMessages, + plistParser: plistParser, + homeDirPath: fileSystemUtils.homeDirPath, + )); + } + }); + } + + try { + final Iterable installDirs = installPaths + .map(fileSystem.directory) + .map>((Directory dir) => dir.existsSync() ? dir.listSync() : []) + .expand((List mappedDirs) => mappedDirs) + .whereType(); + for (final Directory dir in installDirs) { + checkForIntelliJ(dir); + if (!dir.path.endsWith('.app')) { + for (final FileSystemEntity subdir in dir.listSync()) { + if (subdir is Directory) { + checkForIntelliJ(subdir); + } + } + } + } + } on FileSystemException catch (e) { + validators.add(ValidatorWithResult( + userMessages.intellijMacUnknownResult, + ValidationResult(ValidationType.missing, [ + ValidationMessage.error(e.message), + ]), + )); + } + return validators; + } + + @visibleForTesting + String get plistFile { + _plistFile ??= _fileSystem.path.join(installPath, 'Contents', 'Info.plist'); + return _plistFile; + } + String _plistFile; + + @override + String get version { + return _version ??= _plistParser.getValueFromFile( + plistFile, + PlistParser.kCFBundleShortVersionStringKey, + ) ?? 'unknown'; + } + String _version; + + @override + String get pluginsPath { + if (_pluginsPath != null) { + return _pluginsPath; + } + + final String altLocation = _plistParser + .getValueFromFile(plistFile, 'JetBrainsToolboxApp'); + + if (altLocation != null) { + _pluginsPath = altLocation + '.plugins'; + return _pluginsPath; + } + + final List split = version.split('.'); + if (split.length < 2) { + return null; + } + final String major = split[0]; + final String minor = split[1]; + + final String homeDirPath = _homeDirPath; + String pluginsPath = _fileSystem.path.join( + homeDirPath, + 'Library', + 'Application Support', + 'JetBrains', + '$id$major.$minor', + 'plugins', + ); + // Fallback to legacy location from < 2020. + if (!_fileSystem.isDirectorySync(pluginsPath)) { + pluginsPath = _fileSystem.path.join( + homeDirPath, + 'Library', + 'Application Support', + '$id$major.$minor', + ); + } + _pluginsPath = pluginsPath; + + return _pluginsPath; + } + String _pluginsPath; +} diff --git a/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart index 75cee83641..78eb50b709 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart @@ -25,7 +25,6 @@ import 'package:flutter_tools/src/version.dart'; import 'package:flutter_tools/src/vscode/vscode.dart'; import 'package:flutter_tools/src/vscode/vscode_validator.dart'; import 'package:flutter_tools/src/web/workflow.dart'; -import 'package:meta/meta.dart'; import 'package:mockito/mockito.dart'; import 'package:process/process.dart'; import 'package:fake_async/fake_async.dart'; @@ -50,12 +49,10 @@ final Platform macPlatform = FakePlatform( ); void main() { - MockProcessManager mockProcessManager; MockFlutterVersion mockFlutterVersion; BufferLogger logger; setUp(() { - mockProcessManager = MockProcessManager(); mockFlutterVersion = MockFlutterVersion(); logger = BufferLogger.test(); }); @@ -71,87 +68,6 @@ void main() { }); group('doctor', () { - MockPlistParser mockPlistParser; - MemoryFileSystem fileSystem; - - setUp(() { - mockPlistParser = MockPlistParser(); - fileSystem = MemoryFileSystem.test(); - }); - - testUsingContext('intellij validator', () async { - const String installPath = '/path/to/intelliJ'; - // Uses real filesystem - final ValidationResult result = await IntelliJValidatorTestTarget('Test', installPath, fileSystem: globals.fs).validate(); - expect(result.type, ValidationType.partial); - expect(result.statusInfo, 'version test.test.test'); - expect(result.messages, hasLength(4)); - - ValidationMessage message = result.messages - .firstWhere((ValidationMessage m) => m.message.startsWith('IntelliJ ')); - expect(message.message, 'IntelliJ at $installPath'); - - 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, contains('Flutter plugin version 0.1.3')); - expect(message.message, contains('recommended minimum version')); - }, overrides: noColorTerminalOverride); - - testUsingContext('intellij plugins path checking on mac', () async { - when(mockPlistParser.getValueFromFile(any, PlistParser.kCFBundleShortVersionStringKey)).thenReturn('2020.10'); - - final Directory pluginsDirectory = fileSystem.directory('/foo/bar/Library/Application Support/JetBrains/TestID2020.10/plugins') - ..createSync(recursive: true); - final IntelliJValidatorOnMac validator = IntelliJValidatorOnMac('Test', 'TestID', '/path/to/app', fileSystem: fileSystem); - expect(validator.plistFile, '/path/to/app/Contents/Info.plist'); - expect(validator.pluginsPath, pluginsDirectory.path); - }, overrides: { - Platform: () => macPlatform, - PlistParser: () => mockPlistParser, - FileSystem: () => fileSystem, - ProcessManager: () => mockProcessManager, - FileSystemUtils: () => FileSystemUtils( - fileSystem: fileSystem, - platform: macPlatform, - ) - }); - - testUsingContext('legacy intellij plugins path checking on mac', () async { - when(mockPlistParser.getValueFromFile(any, PlistParser.kCFBundleShortVersionStringKey)).thenReturn('2020.10'); - - final IntelliJValidatorOnMac validator = IntelliJValidatorOnMac('Test', 'TestID', '/foo', fileSystem: fileSystem); - expect(validator.pluginsPath, '/foo/bar/Library/Application Support/TestID2020.10'); - }, overrides: { - Platform: () => macPlatform, - PlistParser: () => mockPlistParser, - FileSystem: () => fileSystem, - FileSystemUtils: () => FileSystemUtils( - fileSystem: fileSystem, - platform: macPlatform, - ), - ProcessManager: () => FakeProcessManager.any(), - }); - - testUsingContext('intellij plugins path checking on mac with override', () async { - when(mockPlistParser.getValueFromFile(any, 'JetBrainsToolboxApp')).thenReturn('/path/to/JetBrainsToolboxApp'); - - final IntelliJValidatorOnMac validator = IntelliJValidatorOnMac('Test', 'TestID', '/foo', fileSystem: fileSystem); - expect(validator.pluginsPath, '/path/to/JetBrainsToolboxApp.plugins'); - }, overrides: { - PlistParser: () => mockPlistParser, - Platform: () => macPlatform, - FileSystem: () => fileSystem, - FileSystemUtils: () => FileSystemUtils( - fileSystem: fileSystem, - platform: macPlatform, - ), - ProcessManager: () => FakeProcessManager.any(), - }); - testUsingContext('vs code validator when both installed', () async { final ValidationResult result = await VsCodeValidatorTestTargets.installedWithExtension.validate(); expect(result.type, ValidationType.installed); @@ -787,18 +703,6 @@ class NoOpDoctor implements Doctor { class MockUsage extends Mock implements Usage {} -class IntelliJValidatorTestTarget extends IntelliJValidator { - IntelliJValidatorTestTarget(String title, String installPath, {@required FileSystem fileSystem}) - : super(title, installPath, fileSystem: fileSystem); - - // Warning: requires real test data. - @override - String get pluginsPath => globals.fs.path.join('test', 'data', 'intellij', 'plugins'); - - @override - String get version => 'test.test.test'; -} - class PassingValidator extends DoctorValidator { PassingValidator(String name) : super(name); diff --git a/packages/flutter_tools/test/data/intellij/plugins/Dart/lib/Dart.jar b/packages/flutter_tools/test/data/intellij/plugins/Dart/lib/Dart.jar deleted file mode 100644 index 40d114086ef2ca89d1a8502238d2613b53c2b74c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4138 zcmWIWW@h1H0D--Ejh-MHhB+Bz7<^qr9CbbY-1I|3I2o9a6*@%RDRhV^t>9*0WSMh> zk%6T{n1KOgga`uz0|&$U$)TRRHdq|H!^gmICX9hW7}pB8Y}d=$r9NNd4@+IgO&KP)d7L+$2-7~)?sT%Zpn0qdIKJ;SAKyC$=g`Jno%~rAA}0jb zBu+VLkfu3t$%hy1@oLYPmoMLcBL0)7*xVcPAB-2NU*@eirF?UOh3Gu_b~%ZA(U;Ph z_A#vgyzcRy_v`n2tv%-IRr5sM(}h`nD@&*uXSZPZZ*76UZcSGz7e3v>&vQ`luFAwI zp3biO0_tY)t6F{K$Tf4SpRf6*)6q&Q+)1M5qr+tHW9Ls^IP)HL$hzhE`3H{$e_1|s6Wx45hF>5z;L*GVKVP#( zNZV+h+SBH&U*jg?zry zx~a|G+%jXe>dUR0o~tNn+pEU9zhv6D?4u?3x(uH!MSY6#-39ZCZY*0{Zy+aBXA=>m zcWF_gvcT(kzd1`7u3c@MyiVoJRJQqsin%!+U3x7!mnE(r7JJRD7dUAVOTyOM2OfFa z8&BNUwrmr#$wZdxsdHj}G`RMh_ng(V@+ePBhEHJ39JLN*zsDaY9rSB(IBFQRNrR=! znCAxH+;k~#-T$n2?#LFN=6ruJ{n>+_OG51HLPH~_JMIs-8{kNY2|veD96N@%?f8Ne)^pZ*54@6rNpzU zXbD$eP{@mIFU-8-7Hnx~oiTl~>O+=uXDlXK#-{AZeKMgV5oxmKEI&igwBYx<1>3=A)?UhK2n-%fppim&K`xvp0kncLRR*PJ6#x#8Y7 z^R3s}idtAI3!>9D6|vNb>|G_}v7qdk)-szT3NL51uGi{Z6wv5l8eMozz_sMW+rW16set*7S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$Irevxbk*m7C-9Dlu@*$U^!0|mTwr3B=G%3_6e{j^- zGFc$`-AMJ0Qpy_n3#})XH7(fwb3?!S`if&~_MQ3ib$Ls5^rHK)~hT_Q~@koEdpiAu5KRd;8FG`>wcA@X_i&o}v7 z9vrFnkXZAeJatz6p_SU!BUY-eJ8T zQ1m2RY~JVGUmqR5eoy+e#4i1K^Z5gEJbw&imgQ*FhE={3P-RPedNcLGLA$+a8yIy@ zOe#F^Or>dJwaN|ePL1gJqHTtm4!hU%)IQJIoID|V(c^D!&otOFwyn3xKNVdUm@joZ zD$-%Q{!PvN7W0jp7Ea(@dUQ?j`^%h4(m$@tIJtdJn-{ipq024Xi+h$Vd$TCTe6EeM zqvuWWS!S0)Qnj}0&b|4q%9A^^^0n>7lC|tUA4N<8DZ( zx&7BOcI|2EF<3F(Q*Ca2PRh=prPCRUH@xb7VX|stOJMk14Vl9da;ejvStYFy{-+1&{9-e!Y0(V49)BS2fSl?)i1^jt9mamJ#2d zUe{8u|8TSZwH?=GbEeB4sbZFu|Nmw4ml>uebFbuY$$b+db^n;yrSdC3jKmj-YZ~;IB)0!74_#ktB*9N|Nrt}<@0$nPe1>hR5SPJy?%uzcBMZr+Db%&(oS~$PW){l zwdB{bU11)p@0U!7=-%v~6=`wXH7(LOT5)5IomB5EPtBLHlB@^$jS~B_@zR~ldw8S@116bS`%YVyO=>tnjCH z;{L3)r&%PqBo>&QxTF{@$IoR^S=m#UX^H$Ra9KQa!*!MVUGe4Lwfp>j`e(k8oo|2k<&4Wm=0AFJ_u`Ca z^?ScPxm(W=;LXS+$Be7DEdlL#3oyKJ1Tm5N-mH+mH%7l3WE`%ZH^ewb1_p)&jm``V i3~=L+`{Aq%%%FZahQX|CAQvz(FfpuPU|`7M2k`(LXp$TN diff --git a/packages/flutter_tools/test/data/intellij/plugins/flutter-intellij.jar b/packages/flutter_tools/test/data/intellij/plugins/flutter-intellij.jar deleted file mode 100644 index 3a66e611f519f89421b1089e3416f4fd336d5859..0000000000000000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f#ZMS}TAm!ucMM$J6T2(=!q#l}u(g_(!|0)~r zz3iIyVZug1(;G6a-%n@%c^Nogq`mpVPn9#tYU{V_*68mN%-hc~=Y;^r-tV6-`5(G} z{tokvy+0cId+XO`Ha~w-?2y{PA+b=ItzWix&;OFz+OpEm4RD(v>Z=CnES-`u8IY_z$aTV@_{_T4Y0+OG4$2VWdvdGO$A=RbyJ z8y6jVbC22GT(Zyp46l8^NNByuD?8rPpA{^W{B9(yNHbqiJ!#K@Nx~nMwK#+K)~M(i z&JLc_epB&_QpkpQnSGA^x2Hw79AuPLx3V}=xc|2~XPxLtSB<{Y6Ruk{J!^dBUgm!N zuKM>6rEzEeF$Z`vGRZOHs$nFcm5l(y3r7$WslH)_)HfJ)4ahiLwGG5LMg|6k1&z)O i42bFrx$a?QU{'HOME': '/foo/bar'} +); + +void main() { + testWithoutContext('Intellij validator can parse plugin manifest from plugin JAR', () async { + final FileSystem fileSystem = MemoryFileSystem.test(); + // Create plugin JAR file for Flutter and Dart plugin. + final List flutterPluginBytes = utf8.encode(kIntellijFlutterPluginXml); + final Archive flutterPlugins = Archive(); + flutterPlugins.addFile(ArchiveFile('META-INF/plugin.xml', flutterPluginBytes.length, flutterPluginBytes)); + fileSystem.file('plugins/flutter-intellij.jar') + ..createSync(recursive: true) + ..writeAsBytesSync(ZipEncoder().encode(flutterPlugins)); + final List dartPluginBytes = utf8.encode(kIntellijDartPluginXml); + final Archive dartPlugins = Archive(); + dartPlugins.addFile(ArchiveFile('META-INF/plugin.xml', dartPluginBytes.length, dartPluginBytes)); + fileSystem.file('plugins/Dart/lib/Dart.jar') + ..createSync(recursive: true) + ..writeAsBytesSync(ZipEncoder().encode(dartPlugins)); + + final ValidationResult result = await IntelliJValidatorTestTarget('', 'path/to/intellij', fileSystem).validate(); + expect(result.type, ValidationType.partial); + expect(result.statusInfo, 'version test.test.test'); + expect(result.messages, const [ + ValidationMessage('IntelliJ at path/to/intellij'), + ValidationMessage.error('Flutter plugin version 0.1.3 - the recommended minimum version is 16.0.0'), + ValidationMessage('Dart plugin version 162.2485'), + ValidationMessage('For information about installing plugins, see\n' + 'https://flutter.dev/intellij-setup/#installing-the-plugins') + ]); + }); + + testWithoutContext('Intellij plugins path checking on mac', () async { + final FileSystem fileSystem = MemoryFileSystem.test(); + final Directory pluginsDirectory = fileSystem.directory('/foo/bar/Library/Application Support/JetBrains/TestID2020.10/plugins') + ..createSync(recursive: true); + final IntelliJValidatorOnMac validator = IntelliJValidatorOnMac( + 'Test', + 'TestID', + '/path/to/app', + fileSystem: fileSystem, + homeDirPath: '/foo/bar', + userMessages: UserMessages(), + plistParser: FakePlistParser({ + PlistParser.kCFBundleShortVersionStringKey: '2020.10', + }) + ); + + expect(validator.plistFile, '/path/to/app/Contents/Info.plist'); + expect(validator.pluginsPath, pluginsDirectory.path); + }); + + testWithoutContext('legacy Intellij plugins path checking on mac', () async { + final FileSystem fileSystem = MemoryFileSystem.test(); + final IntelliJValidatorOnMac validator = IntelliJValidatorOnMac( + 'Test', + 'TestID', + '/foo', + fileSystem: fileSystem, + homeDirPath: '/foo/bar', + userMessages: UserMessages(), + plistParser: FakePlistParser({ + PlistParser.kCFBundleShortVersionStringKey: '2020.10', + }) + ); + + expect(validator.pluginsPath, '/foo/bar/Library/Application Support/TestID2020.10'); + }); + + testWithoutContext('Intellij plugins path checking on mac with JetBrains toolbox override', () async { + final FileSystem fileSystem = MemoryFileSystem.test(); + final IntelliJValidatorOnMac validator = IntelliJValidatorOnMac( + 'Test', + 'TestID', + '/foo', + fileSystem: fileSystem, + homeDirPath: '/foo/bar', + userMessages: UserMessages(), + plistParser: FakePlistParser({ + 'JetBrainsToolboxApp': '/path/to/JetBrainsToolboxApp', + }) + ); + + expect(validator.pluginsPath, '/path/to/JetBrainsToolboxApp.plugins'); + }); +} + +class FakePlistParser extends Fake implements PlistParser { + FakePlistParser(this.values); + + final Map values; + + @override + String getValueFromFile(String plistFilePath, String key) { + return values[key]; + } +} + +class IntelliJValidatorTestTarget extends IntelliJValidator { + IntelliJValidatorTestTarget(String title, String installPath, FileSystem fileSystem) + : super(title, installPath, fileSystem: fileSystem, userMessages: UserMessages()); + + @override + String get pluginsPath => 'plugins'; + + @override + String get version => 'test.test.test'; +} + + +/// These file contents were derived from the META-INF/plugin.xml from an Intellij Flutter +/// plugin installation. +/// +/// The file is loacted in a plugin JAR, which can be located by looking at the plugin +/// path for the Intellij and Android Studio validators. +/// +/// If more XML contents are needed, prefer modifying these contents over checking +/// in another JAR. +const String kIntellijFlutterPluginXml = r''' + + io.flutter + Flutter + Support for developing Flutter applications. + flutter.io + + Custom Languages + + 0.1.3 + + + + + + Dart + 162.2485 + + + Support for Dart programming language + JetBrains + com.intellij.modules.xml + JavaScriptDebugger + org.jetbrains.plugins.yaml + com.intellij.copyright + com.intellij.modules.coverage + +'''; + +/// These file contents were derived from the META-INF/plugin.xml from an Intellij Dart +/// plugin installation. +/// +/// The file is loacted in a plugin JAR, which can be located by looking at the plugin +/// path for the Intellij and Android Studio validators. +/// +/// If more XML contents are needed, prefer modifying these contents over checking +/// in another JAR. +const String kIntellijDartPluginXml = r''' + + Dart + 162.2485 + + + Support for Dart programming language + JetBrains + com.intellij.modules.xml + JavaScriptDebugger + org.jetbrains.plugins.yaml + com.intellij.copyright + com.intellij.modules.coverage + +''';