Unverified Commit f2004b8f authored by KyleWong's avatar KyleWong Committed by GitHub

Add android studio process logic for JetBrainsToolbox (#27687)

* Make plugin path search logic use version check as a fallback.

* In JetBrainsToolbox, Info.plist would be just some kind of wrapper, we need a double check before get the real one.

* Use Regex to get content instead of `default command` to avoid error output as there could be no JetBrainsToolboxApp key/value for a normal Info.plist(Android Studio.)
parent 199ebaa6
...@@ -26,21 +26,37 @@ AndroidStudio get androidStudio => context[AndroidStudio]; ...@@ -26,21 +26,37 @@ AndroidStudio get androidStudio => context[AndroidStudio];
final RegExp _dotHomeStudioVersionMatcher = final RegExp _dotHomeStudioVersionMatcher =
RegExp(r'^\.(AndroidStudio[^\d]*)([\d.]+)'); RegExp(r'^\.(AndroidStudio[^\d]*)([\d.]+)');
final RegExp _pathsSelectorMatcher =
RegExp(r'"idea.paths.selector" = "AndroidStudio[^;]+"');
String get javaPath => androidStudio?.javaPath; String get javaPath => androidStudio?.javaPath;
class AndroidStudio implements Comparable<AndroidStudio> { class AndroidStudio implements Comparable<AndroidStudio> {
AndroidStudio(this.directory, AndroidStudio(this.directory,
{Version version, this.configured, this.studioAppName = 'AndroidStudio', this.pathsSelectorPath}) {Version version, this.configured, this.studioAppName = 'AndroidStudio', this.presetPluginsPath})
: version = version ?? Version.unknown { : version = version ?? Version.unknown {
_init(); _init();
} }
factory AndroidStudio.fromMacOSBundle(String bundlePath) { factory AndroidStudio.fromMacOSBundle(String bundlePath) {
final String studioPath = fs.path.join(bundlePath, 'Contents'); String studioPath = fs.path.join(bundlePath, 'Contents');
final String plistFile = fs.path.join(studioPath, 'Info.plist'); String plistFile = fs.path.join(studioPath, 'Info.plist');
String plistValue = iosWorkflow.getPlistValueFromFile(
plistFile,
null,
);
final RegExp _pathsSelectorMatcher = RegExp(r'"idea.paths.selector" = "[^;]+"');
final RegExp _jetBrainsToolboxAppMatcher = RegExp(r'JetBrainsToolboxApp = "[^;]+"');
// 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 = extractStudioPlistValueWithMatcher(plistValue, _jetBrainsToolboxAppMatcher);
if (jetBrainsToolboxAppBundlePath != null) {
studioPath = fs.path.join(jetBrainsToolboxAppBundlePath, 'Contents');
plistFile = fs.path.join(studioPath, 'Info.plist');
plistValue = iosWorkflow.getPlistValueFromFile(
plistFile,
null,
);
}
final String versionString = iosWorkflow.getPlistValueFromFile( final String versionString = iosWorkflow.getPlistValueFromFile(
plistFile, plistFile,
plist.kCFBundleShortVersionStringKey, plist.kCFBundleShortVersionStringKey,
...@@ -50,12 +66,11 @@ class AndroidStudio implements Comparable<AndroidStudio> { ...@@ -50,12 +66,11 @@ class AndroidStudio implements Comparable<AndroidStudio> {
if (versionString != null) if (versionString != null)
version = Version.parse(versionString); version = Version.parse(versionString);
final String plistValue = iosWorkflow.getPlistValueFromFile( final String pathsSelectorValue = extractStudioPlistValueWithMatcher(plistValue, _pathsSelectorMatcher);
plistFile, final String presetPluginsPath = pathsSelectorValue == null
null, ? null
); : fs.path.join(homeDirPath, 'Library', 'Application Support', '$pathsSelectorValue');
final String pathsSelectorValue = _pathsSelectorMatcher.stringMatch(plistValue).split('=').last.trim().replaceAll('"', ''); return AndroidStudio(studioPath, version: version, presetPluginsPath: presetPluginsPath);
return AndroidStudio(studioPath, version: version, pathsSelectorPath: pathsSelectorValue);
} }
factory AndroidStudio.fromHomeDot(Directory homeDotDir) { factory AndroidStudio.fromHomeDot(Directory homeDotDir) {
...@@ -91,9 +106,8 @@ class AndroidStudio implements Comparable<AndroidStudio> { ...@@ -91,9 +106,8 @@ class AndroidStudio implements Comparable<AndroidStudio> {
final String studioAppName; final String studioAppName;
final Version version; final Version version;
final String configured; final String configured;
final String pathsSelectorPath; final String presetPluginsPath;
String _pluginsPath;
String _javaPath; String _javaPath;
bool _isValid = false; bool _isValid = false;
final List<String> _validationMessages = <String>[]; final List<String> _validationMessages = <String>[];
...@@ -103,23 +117,23 @@ class AndroidStudio implements Comparable<AndroidStudio> { ...@@ -103,23 +117,23 @@ class AndroidStudio implements Comparable<AndroidStudio> {
bool get isValid => _isValid; bool get isValid => _isValid;
String get pluginsPath { String get pluginsPath {
if (_pluginsPath == null) { if (presetPluginsPath != null) {
final int major = version.major; return presetPluginsPath;
final int minor = version.minor; }
if (platform.isMacOS) { final int major = version?.major;
_pluginsPath = fs.path.join( final int minor = version?.minor;
homeDirPath, if (platform.isMacOS) {
'Library', return fs.path.join(
'Application Support', homeDirPath,
'$pathsSelectorPath'); 'Library',
} else { 'Application Support',
_pluginsPath = fs.path.join(homeDirPath, 'AndroidStudio$major.$minor');
'.$studioAppName$major.$minor', } else {
'config', return fs.path.join(homeDirPath,
'plugins'); '.$studioAppName$major.$minor',
} 'config',
'plugins');
} }
return _pluginsPath;
} }
List<String> get validationMessages => _validationMessages; List<String> get validationMessages => _validationMessages;
...@@ -250,6 +264,13 @@ class AndroidStudio implements Comparable<AndroidStudio> { ...@@ -250,6 +264,13 @@ class AndroidStudio implements Comparable<AndroidStudio> {
return studios; return studios;
} }
static String extractStudioPlistValueWithMatcher(String plistValue, RegExp keyMatcher) {
if (plistValue == null || keyMatcher == null) {
return null;
}
return keyMatcher?.stringMatch(plistValue)?.split('=')?.last?.trim()?.replaceAll('"', '');
}
void _init() { void _init() {
_isValid = false; _isValid = false;
_validationMessages.clear(); _validationMessages.clear();
......
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