Unverified Commit d7228752 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

[tools] Fix Android Studio duplicate detection (#88384)

parent 061dff8c
...@@ -40,17 +40,13 @@ class AndroidStudio implements Comparable<AndroidStudio> { ...@@ -40,17 +40,13 @@ class AndroidStudio implements Comparable<AndroidStudio> {
_init(version: version); _init(version: version);
} }
factory AndroidStudio.fromMacOSBundle(String bundlePath) { static AndroidStudio? fromMacOSBundle(String bundlePath) {
String studioPath = globals.fs.path.join(bundlePath, 'Contents'); final String studioPath = globals.fs.path.join(bundlePath, 'Contents');
String plistFile = globals.fs.path.join(studioPath, 'Info.plist'); final String plistFile = globals.fs.path.join(studioPath, 'Info.plist');
Map<String, dynamic> plistValues = globals.plistParser.parseFile(plistFile); final Map<String, dynamic> plistValues = globals.plistParser.parseFile(plistFile);
// As AndroidStudio managed by JetBrainsToolbox could have a wrapper pointing to the real Android Studio. // If we've found a JetBrainsToolbox wrapper, ignore it.
// Check if we've found a JetBrainsToolbox wrapper and deal with it properly. if (plistValues.containsKey('JetBrainsToolboxApp')) {
final String? jetBrainsToolboxAppBundlePath = plistValues['JetBrainsToolboxApp'] as String?; return null;
if (jetBrainsToolboxAppBundlePath != null) {
studioPath = globals.fs.path.join(jetBrainsToolboxAppBundlePath, 'Contents');
plistFile = globals.fs.path.join(studioPath, 'Info.plist');
plistValues = globals.plistParser.parseFile(plistFile);
} }
final String versionString = plistValues[PlistParser.kCFBundleShortVersionStringKey] as String; final String versionString = plistValues[PlistParser.kCFBundleShortVersionStringKey] as String;
...@@ -317,7 +313,7 @@ class AndroidStudio implements Comparable<AndroidStudio> { ...@@ -317,7 +313,7 @@ class AndroidStudio implements Comparable<AndroidStudio> {
} }
return candidatePaths return candidatePaths
.map<AndroidStudio>((FileSystemEntity e) => AndroidStudio.fromMacOSBundle(e.path)) .map<AndroidStudio?>((FileSystemEntity e) => AndroidStudio.fromMacOSBundle(e.path))
.whereType<AndroidStudio>() .whereType<AndroidStudio>()
.toList(); .toList();
} }
......
...@@ -157,6 +157,7 @@ void main() { ...@@ -157,6 +157,7 @@ void main() {
Platform: () => platform, Platform: () => platform,
PlistParser: () => plistUtils, PlistParser: () => plistUtils,
}); });
testUsingContext('Can discover Android Studio >=2020.3 location on Mac', () { testUsingContext('Can discover Android Studio >=2020.3 location on Mac', () {
final String studioInApplicationPlistFolder = globals.fs.path.join( final String studioInApplicationPlistFolder = globals.fs.path.join(
'/', '/',
...@@ -222,6 +223,43 @@ void main() { ...@@ -222,6 +223,43 @@ void main() {
PlistParser: () => plistUtils, PlistParser: () => plistUtils,
}); });
testUsingContext('Does not discover Android Studio with JetBrainsToolboxApp wrapper', () {
final String applicationPlistFolder = globals.fs.path.join(
'/',
'Applications',
'Android Studio.app',
'Contents',
);
globals.fs.directory(applicationPlistFolder).createSync(recursive: true);
final String applicationsPlistFilePath = globals.fs.path.join(applicationPlistFolder, 'Info.plist');
const Map<String, dynamic> jetbrainsInfoPlist = <String, dynamic>{
'JetBrainsToolboxApp': 'ignored',
};
plistUtils.fileContents[applicationsPlistFilePath] = jetbrainsInfoPlist;
final String homeDirectoryPlistFolder = globals.fs.path.join(
globals.fsUtils.homeDirPath,
'Applications',
'Android Studio.app',
'Contents',
);
globals.fs.directory(homeDirectoryPlistFolder).createSync(recursive: true);
final String homeDirectoryPlistFilePath = globals.fs.path.join(homeDirectoryPlistFolder, 'Info.plist');
plistUtils.fileContents[homeDirectoryPlistFilePath] = macStudioInfoPlist2020_3;
expect(AndroidStudio.allInstalled().length, 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 installation from Spotlight query', () { testUsingContext('Can discover installation from Spotlight query', () {
// One in expected location. // One in expected location.
final String studioInApplication = fileSystem.path.join( final String studioInApplication = fileSystem.path.join(
...@@ -370,64 +408,6 @@ void main() { ...@@ -370,64 +408,6 @@ void main() {
Platform: () => platform, Platform: () => platform,
PlistParser: () => plistUtils, PlistParser: () => plistUtils,
}); });
testUsingContext('extracts custom paths for Android Studio downloaded by JetBrainsToolbox on Mac', () {
final String jetbrainsStudioInApplicationPlistFolder = globals.fs.path.join(
homeMac,
'Application',
'JetBrains Toolbox',
'Android Studio.app',
'Contents',
);
globals.fs.directory(jetbrainsStudioInApplicationPlistFolder).createSync(recursive: true);
const Map<String, dynamic> jetbrainsInfoPlist = <String, dynamic>{
'CFBundleLongVersionString': '3.3',
'CFBundleShortVersionString': '3.3',
'CFBundleVersion': '3.3',
'JetBrainsToolboxApp': '$homeMac/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/183.5256920/Android Studio 3.3.app',
};
final String jetbrainsPlistFilePath = globals.fs.path.join(
jetbrainsStudioInApplicationPlistFolder,
'Info.plist',
);
plistUtils.fileContents[jetbrainsPlistFilePath] = jetbrainsInfoPlist;
final String studioInApplicationPlistFolder = globals.fs.path.join(
globals.fs.path.join(homeMac,'Library','Application Support'),
'JetBrains',
'Toolbox',
'apps',
'AndroidStudio',
'ch-0',
'183.5256920',
globals.fs.path.join('Android Studio 3.3.app', 'Contents'),
);
globals.fs.directory(studioInApplicationPlistFolder).createSync(recursive: true);
final String studioPlistFilePath = globals.fs.path.join(
studioInApplicationPlistFolder,
'Info.plist',
);
plistUtils.fileContents[studioPlistFilePath] = macStudioInfoPlist;
final AndroidStudio studio = AndroidStudio.fromMacOSBundle(
globals.fs.directory(jetbrainsStudioInApplicationPlistFolder)?.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,
});
}); });
FileSystem windowsFileSystem; FileSystem windowsFileSystem;
......
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