Unverified Commit 422a97d1 authored by Mokusesei's avatar Mokusesei Committed by GitHub

Fix: fix android studio 4.1 plugin path for macOS (#69364)

parent ada6b7e5
......@@ -66,14 +66,28 @@ class AndroidStudio implements Comparable<AndroidStudio> {
pathsSelectorValue = jvmProperties['idea.paths.selector'] as String;
}
}
final String presetPluginsPath = pathsSelectorValue == null
? null
: globals.fs.path.join(
globals.fsUtils.homeDirPath,
'Library',
'Application Support',
pathsSelectorValue,
);
final int major = version?.major;
final int minor = version?.minor;
String presetPluginsPath;
if (pathsSelectorValue != null) {
if (major >= 4 && minor >= 1) {
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);
}
......@@ -127,12 +141,23 @@ class AndroidStudio implements Comparable<AndroidStudio> {
final int major = version?.major;
final int minor = version?.minor;
if (globals.platform.isMacOS) {
return globals.fs.path.join(
globals.fsUtils.homeDirPath,
'Library',
'Application Support',
'AndroidStudio$major.$minor',
);
/// plugin path of Android Studio has been changed after version 4.1.
if (major >= 4 && minor >= 1) {
return globals.fs.path.join(
globals.fsUtils.homeDirPath,
'Library',
'Application Support',
'Google',
'AndroidStudio$major.$minor',
);
} else {
return globals.fs.path.join(
globals.fsUtils.homeDirPath,
'Library',
'Application Support',
'AndroidStudio$major.$minor',
);
}
} else {
return globals.fs.path.join(
globals.fsUtils.homeDirPath,
......
......@@ -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(
operatingSystem: 'linux',
environment: <String, String>{'HOME': homeLinux},
......@@ -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', () {
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