From 428ce0815bcf27b552d6d27c39c9ae79eaf58f8a Mon Sep 17 00:00:00 2001 From: Neevash Ramdial Date: Wed, 27 May 2020 13:07:28 -0400 Subject: [PATCH] [flutter_tools] Support latest IntelliJ via Jetbrain toolbox (#57963) --- packages/flutter_tools/lib/src/doctor.dart | 21 +++++++-- .../commands.shard/hermetic/doctor_test.dart | 47 ++++++++++++++++--- .../mac_not_via_toolbox/Contents/Info.plist | 38 --------------- .../mac_via_toolbox/Contents/Info.plist | 40 ---------------- 4 files changed, 58 insertions(+), 88 deletions(-) delete mode 100644 packages/flutter_tools/test/data/intellij/mac_not_via_toolbox/Contents/Info.plist delete mode 100644 packages/flutter_tools/test/data/intellij/mac_via_toolbox/Contents/Info.plist diff --git a/packages/flutter_tools/lib/src/doctor.dart b/packages/flutter_tools/lib/src/doctor.dart index f492045677..a0f3bb3b93 100644 --- a/packages/flutter_tools/lib/src/doctor.dart +++ b/packages/flutter_tools/lib/src/doctor.dart @@ -915,19 +915,32 @@ class IntelliJValidatorOnMac extends IntelliJValidator { } final List split = version.split('.'); - if (split.length < 2) { return null; } - final String major = split[0]; final String minor = split[1]; - _pluginsPath = globals.fs.path.join( - globals.fsUtils.homeDirPath, + + 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; 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 1d1eb0d38a..2f4a42e84a 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart @@ -19,6 +19,7 @@ import 'package:flutter_tools/src/commands/doctor.dart'; import 'package:flutter_tools/src/doctor.dart'; import 'package:flutter_tools/src/features.dart'; import 'package:flutter_tools/src/globals.dart' as globals; +import 'package:flutter_tools/src/ios/plist_parser.dart'; import 'package:flutter_tools/src/proxy_validator.dart'; import 'package:flutter_tools/src/reporting/reporting.dart'; import 'package:flutter_tools/src/version.dart'; @@ -55,6 +56,14 @@ void main() { }); group('doctor', () { + MockPlistParser mockPlistParser; + MemoryFileSystem fileSystem; + + setUp(() { + mockPlistParser = MockPlistParser(); + fileSystem = MemoryFileSystem.test(); + }); + testUsingContext('intellij validator', () async { const String installPath = '/path/to/intelliJ'; final ValidationResult result = await IntelliJValidatorTestTarget('Test', installPath).validate(); @@ -77,14 +86,39 @@ void main() { }, overrides: noColorTerminalOverride); testUsingContext('intellij plugins path checking on mac', () async { - final String pathViaToolbox = globals.fs.path.join('test', 'data', 'intellij', 'mac_via_toolbox'); - final String pathNotViaToolbox = globals.fs.path.join('test', 'data', 'intellij', 'mac_not_via_toolbox'); + when(mockPlistParser.getValueFromFile(any, PlistParser.kCFBundleShortVersionStringKey)).thenReturn('2020.10'); - final IntelliJValidatorOnMac validatorViaToolbox = IntelliJValidatorOnMac('Test', 'Test', pathViaToolbox); - expect(validatorViaToolbox.plistFile, 'test/data/intellij/mac_via_toolbox/Contents/Info.plist'); + 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'); + expect(validator.plistFile, '/path/to/app/Contents/Info.plist'); + expect(validator.pluginsPath, pluginsDirectory.path); + }, overrides: { + Platform: () => FakePlatform() + ..environment = {'HOME': '/foo/bar'}, + PlistParser: () => mockPlistParser, + FileSystem: () => fileSystem, + ProcessManager: () => mockProcessManager, + }); - final IntelliJValidatorOnMac validatorNotViaToolbox = IntelliJValidatorOnMac('Test', 'Test', pathNotViaToolbox); - expect(validatorNotViaToolbox.plistFile, 'test/data/intellij/mac_not_via_toolbox/Contents/Info.plist'); + 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'); + expect(validator.pluginsPath, '/foo/bar/Library/Application Support/TestID2020.10'); + }, overrides: { + Platform: () => FakePlatform() + ..environment = {'HOME': '/foo/bar'}, + PlistParser: () => mockPlistParser, + }); + + 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'); + expect(validator.pluginsPath, '/path/to/JetBrainsToolboxApp.plugins'); + }, overrides: { + PlistParser: () => mockPlistParser, }); testUsingContext('vs code validator when both installed', () async { @@ -1185,3 +1219,4 @@ class VsCodeValidatorTestTargets extends VsCodeValidator { class MockProcessManager extends Mock implements ProcessManager {} class MockArtifacts extends Mock implements Artifacts {} +class MockPlistParser extends Mock implements PlistParser {} diff --git a/packages/flutter_tools/test/data/intellij/mac_not_via_toolbox/Contents/Info.plist b/packages/flutter_tools/test/data/intellij/mac_not_via_toolbox/Contents/Info.plist deleted file mode 100644 index 087127f913..0000000000 --- a/packages/flutter_tools/test/data/intellij/mac_not_via_toolbox/Contents/Info.plist +++ /dev/null @@ -1,38 +0,0 @@ - - - - - CFBundleDevelopmentRegion - English - CFBundleExecutable - jetbrains-toolbox-launcher - CFBundleGetInfoString - - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - APPL - CFBundleSignature - ???? - NSHumanReadableCopyright - Copyright (c) JetBrains s.r.o. - NSHighResolutionCapable - - NSUIElement - - LSUIElement - - CFBundleName - IntelliJ IDEA Ultimate 2019.3.3 - CFBundleIdentifier - com.jetbrains.apps.activator.linkapp.pcom.jetbrains.apps.activator__ntelli_ltimate_2019_3_3 - CFBundleVersion - 2019.3.3 - CFBundleLongVersionString - 2019.3.3 - CFBundleShortVersionString - 2019.3.3 - CFBundleIconFile - icon.icns - - diff --git a/packages/flutter_tools/test/data/intellij/mac_via_toolbox/Contents/Info.plist b/packages/flutter_tools/test/data/intellij/mac_via_toolbox/Contents/Info.plist deleted file mode 100644 index 0700e061cd..0000000000 --- a/packages/flutter_tools/test/data/intellij/mac_via_toolbox/Contents/Info.plist +++ /dev/null @@ -1,40 +0,0 @@ - - - - - CFBundleDevelopmentRegion - English - CFBundleExecutable - jetbrains-toolbox-launcher - CFBundleGetInfoString - - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - APPL - CFBundleSignature - ???? - NSHumanReadableCopyright - Copyright (c) JetBrains s.r.o. - NSHighResolutionCapable - - NSUIElement - - LSUIElement - - CFBundleName - IntelliJ IDEA Ultimate 2019.3.3 - CFBundleIdentifier - com.jetbrains.apps.activator.linkapp.pcom.jetbrains.apps.activator__ntelli_ltimate_2019_3_3 - CFBundleVersion - 2019.3.3 - CFBundleLongVersionString - 2019.3.3 - CFBundleShortVersionString - 2019.3.3 - CFBundleIconFile - icon.icns - JetBrainsToolboxApp - /Users/lynn/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/193.6494.35/IntelliJ IDEA.app - -