Commit 7765dd4c authored by KyleWong's avatar KyleWong Committed by xster

Refactor logic to get plugins path for android studio in mac (#26964)

parent 704814c6
......@@ -26,12 +26,14 @@ AndroidStudio get androidStudio => context[AndroidStudio];
final RegExp _dotHomeStudioVersionMatcher =
RegExp(r'^\.(AndroidStudio[^\d]*)([\d.]+)');
final RegExp _pathsSelectorMatcher =
RegExp(r'"idea.paths.selector" = "AndroidStudio[^;]+"');
String get javaPath => androidStudio?.javaPath;
class AndroidStudio implements Comparable<AndroidStudio> {
AndroidStudio(this.directory,
{Version version, this.configured, this.studioAppName = 'AndroidStudio'})
{Version version, this.configured, this.studioAppName = 'AndroidStudio', this.pathsSelectorPath})
: version = version ?? Version.unknown {
_init();
}
......@@ -47,7 +49,13 @@ class AndroidStudio implements Comparable<AndroidStudio> {
Version version;
if (versionString != null)
version = Version.parse(versionString);
return AndroidStudio(studioPath, version: version);
final String plistValue = iosWorkflow.getPlistValueFromFile(
plistFile,
null,
);
final String pathsSelectorValue = _pathsSelectorMatcher.stringMatch(plistValue).split('=').last.trim().replaceAll('"', '');
return AndroidStudio(studioPath, version: version, pathsSelectorPath: pathsSelectorValue);
}
factory AndroidStudio.fromHomeDot(Directory homeDotDir) {
......@@ -83,6 +91,7 @@ class AndroidStudio implements Comparable<AndroidStudio> {
final String studioAppName;
final Version version;
final String configured;
final String pathsSelectorPath;
String _pluginsPath;
String _javaPath;
......@@ -102,7 +111,7 @@ class AndroidStudio implements Comparable<AndroidStudio> {
homeDirPath,
'Library',
'Application Support',
'AndroidStudio$major.$minor');
'$pathsSelectorPath');
} else {
_pluginsPath = fs.path.join(homeDirPath,
'.$studioAppName$major.$minor',
......
......@@ -26,9 +26,13 @@ String getValueFromFile(String plistFilePath, String key) {
final String normalizedPlistPath = fs.path.withoutExtension(fs.path.absolute(plistFilePath));
try {
final String value = runCheckedSync(<String>[
executable, 'read', normalizedPlistPath, key
]);
final List<String> args = <String>[
executable, 'read', normalizedPlistPath
];
if (key != null && key.isNotEmpty){
args.add(key);
}
final String value = runCheckedSync(args);
return value.isEmpty ? null : value;
} catch (error) {
return null;
......
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