[tools] Fix Android Studio duplicate detection (#88384)
This commit is contained in:
@@ -40,17 +40,13 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
_init(version: version);
|
||||
}
|
||||
|
||||
factory AndroidStudio.fromMacOSBundle(String bundlePath) {
|
||||
String studioPath = globals.fs.path.join(bundlePath, 'Contents');
|
||||
String plistFile = globals.fs.path.join(studioPath, 'Info.plist');
|
||||
Map<String, dynamic> plistValues = globals.plistParser.parseFile(plistFile);
|
||||
// As AndroidStudio managed by JetBrainsToolbox could have a wrapper pointing to the real Android Studio.
|
||||
// Check if we've found a JetBrainsToolbox wrapper and deal with it properly.
|
||||
final String? jetBrainsToolboxAppBundlePath = plistValues['JetBrainsToolboxApp'] as String?;
|
||||
if (jetBrainsToolboxAppBundlePath != null) {
|
||||
studioPath = globals.fs.path.join(jetBrainsToolboxAppBundlePath, 'Contents');
|
||||
plistFile = globals.fs.path.join(studioPath, 'Info.plist');
|
||||
plistValues = globals.plistParser.parseFile(plistFile);
|
||||
static AndroidStudio? fromMacOSBundle(String bundlePath) {
|
||||
final String studioPath = globals.fs.path.join(bundlePath, 'Contents');
|
||||
final String plistFile = globals.fs.path.join(studioPath, 'Info.plist');
|
||||
final Map<String, dynamic> plistValues = globals.plistParser.parseFile(plistFile);
|
||||
// If we've found a JetBrainsToolbox wrapper, ignore it.
|
||||
if (plistValues.containsKey('JetBrainsToolboxApp')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String versionString = plistValues[PlistParser.kCFBundleShortVersionStringKey] as String;
|
||||
@@ -317,7 +313,7 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
}
|
||||
|
||||
return candidatePaths
|
||||
.map<AndroidStudio>((FileSystemEntity e) => AndroidStudio.fromMacOSBundle(e.path))
|
||||
.map<AndroidStudio?>((FileSystemEntity e) => AndroidStudio.fromMacOSBundle(e.path))
|
||||
.whereType<AndroidStudio>()
|
||||
.toList();
|
||||
}
|
||||
|
||||
@@ -157,6 +157,7 @@ void main() {
|
||||
Platform: () => platform,
|
||||
PlistParser: () => plistUtils,
|
||||
});
|
||||
|
||||
testUsingContext('Can discover Android Studio >=2020.3 location on Mac', () {
|
||||
final String studioInApplicationPlistFolder = globals.fs.path.join(
|
||||
'/',
|
||||
@@ -222,6 +223,43 @@ void main() {
|
||||
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', () {
|
||||
// One in expected location.
|
||||
final String studioInApplication = fileSystem.path.join(
|
||||
@@ -370,64 +408,6 @@ void main() {
|
||||
Platform: () => platform,
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user