Unverified Commit 6269abb7 authored by Mokusesei's avatar Mokusesei Committed by GitHub

Reland: fix android studio 4.1 plugin path for mac (#69954)

parent 5ba2d79a
...@@ -66,14 +66,28 @@ class AndroidStudio implements Comparable<AndroidStudio> { ...@@ -66,14 +66,28 @@ class AndroidStudio implements Comparable<AndroidStudio> {
pathsSelectorValue = jvmProperties['idea.paths.selector'] as String; pathsSelectorValue = jvmProperties['idea.paths.selector'] as String;
} }
} }
final String presetPluginsPath = pathsSelectorValue == null
? null final int major = version?.major;
: globals.fs.path.join( final int minor = version?.minor;
globals.fsUtils.homeDirPath, String presetPluginsPath;
'Library', if (pathsSelectorValue != null) {
'Application Support', if (major != null && major >= 4 && minor != null && minor >= 1) {
pathsSelectorValue, presetPluginsPath = globals.fs.path.join(
); globals.fsUtils.homeDirPath,
'Library',
'Application Support',
'Google',
pathsSelectorValue,
);
} else {
presetPluginsPath = globals.fs.path.join(
globals.fsUtils.homeDirPath,
'Library',
'Application Support',
pathsSelectorValue,
);
}
}
return AndroidStudio(studioPath, version: version, presetPluginsPath: presetPluginsPath); return AndroidStudio(studioPath, version: version, presetPluginsPath: presetPluginsPath);
} }
...@@ -127,12 +141,23 @@ class AndroidStudio implements Comparable<AndroidStudio> { ...@@ -127,12 +141,23 @@ class AndroidStudio implements Comparable<AndroidStudio> {
final int major = version?.major; final int major = version?.major;
final int minor = version?.minor; final int minor = version?.minor;
if (globals.platform.isMacOS) { if (globals.platform.isMacOS) {
return globals.fs.path.join( /// plugin path of Android Studio has been changed after version 4.1.
globals.fsUtils.homeDirPath, if (major != null && major >= 4 && minor != null && minor >= 1) {
'Library', return globals.fs.path.join(
'Application Support', globals.fsUtils.homeDirPath,
'AndroidStudio$major.$minor', 'Library',
); 'Application Support',
'Google',
'AndroidStudio$major.$minor',
);
} else {
return globals.fs.path.join(
globals.fsUtils.homeDirPath,
'Library',
'Application Support',
'AndroidStudio$major.$minor',
);
}
} else { } else {
return globals.fs.path.join( return globals.fs.path.join(
globals.fsUtils.homeDirPath, globals.fsUtils.homeDirPath,
......
...@@ -29,6 +29,19 @@ const Map<String, dynamic> macStudioInfoPlist = <String, dynamic>{ ...@@ -29,6 +29,19 @@ const Map<String, dynamic> macStudioInfoPlist = <String, dynamic>{
}, },
}; };
const Map<String, dynamic> macStudioInfoPlist4_1 = <String, dynamic>{
'CFBundleGetInfoString': 'Android Studio 4.1, build AI-201.8743.12.41.6858069. Copyright JetBrains s.r.o., (c) 2000-2020',
'CFBundleShortVersionString': '4.1',
'CFBundleVersion': 'AI-201.8743.12.41.6858069',
'JVMOptions': <String, dynamic>{
'Properties': <String, dynamic>{
'idea.vendor.name' : 'Google',
'idea.paths.selector': 'AndroidStudio4.1',
'idea.platform.prefix': 'AndroidStudio',
},
},
};
final Platform linuxPlatform = FakePlatform( final Platform linuxPlatform = FakePlatform(
operatingSystem: 'linux', operatingSystem: 'linux',
environment: <String, String>{'HOME': homeLinux}, environment: <String, String>{'HOME': homeLinux},
...@@ -96,6 +109,71 @@ void main() { ...@@ -96,6 +109,71 @@ void main() {
); );
}); });
testUsingContext('Can discover Android Studio >=4.1 location on Mac', () {
final String studioInApplicationPlistFolder = globals.fs.path.join(
'/',
'Application',
'Android Studio.app',
'Contents',
);
globals.fs.directory(studioInApplicationPlistFolder).createSync(recursive: true);
final String plistFilePath = globals.fs.path.join(studioInApplicationPlistFolder, 'Info.plist');
when(plistUtils.parseFile(plistFilePath)).thenReturn(macStudioInfoPlist4_1);
final AndroidStudio studio = AndroidStudio.fromMacOSBundle(
globals.fs.directory(studioInApplicationPlistFolder)?.parent?.path,
);
expect(studio, isNotNull);
expect(studio.pluginsPath, equals(globals.fs.path.join(
homeMac,
'Library',
'Application Support',
'Google',
'AndroidStudio4.1',
)));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
FileSystemUtils: () => fsUtils,
ProcessManager: () => FakeProcessManager.any(),
// Custom home paths are not supported on macOS nor Windows yet,
// so we force the platform to fake Linux here.
Platform: () => platform,
PlistParser: () => plistUtils,
});
testUsingContext('Can discover Android Studio <4.1 location on Mac', () {
final String studioInApplicationPlistFolder = globals.fs.path.join(
'/',
'Application',
'Android Studio.app',
'Contents',
);
globals.fs.directory(studioInApplicationPlistFolder).createSync(recursive: true);
final String plistFilePath = globals.fs.path.join(studioInApplicationPlistFolder, 'Info.plist');
when(plistUtils.parseFile(plistFilePath)).thenReturn(macStudioInfoPlist);
final AndroidStudio studio = AndroidStudio.fromMacOSBundle(
globals.fs.directory(studioInApplicationPlistFolder)?.parent?.path,
);
expect(studio, isNotNull);
expect(studio.pluginsPath, equals(globals.fs.path.join(
homeMac,
'Library',
'Application Support',
'AndroidStudio3.3',
)));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
FileSystemUtils: () => fsUtils,
ProcessManager: () => FakeProcessManager.any(),
// Custom home paths are not supported on macOS nor Windows yet,
// so we force the platform to fake Linux here.
Platform: () => platform,
PlistParser: () => plistUtils,
});
testUsingContext('extracts custom paths for directly downloaded Android Studio on Mac', () { testUsingContext('extracts custom paths for directly downloaded Android Studio on Mac', () {
final String studioInApplicationPlistFolder = globals.fs.path.join( final String studioInApplicationPlistFolder = globals.fs.path.join(
'/', '/',
......
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