Check for AndroidStudio plugins in the right .dot dir. (#20619)
This fixes issues 11940 and 18155.
This commit is contained in:
committed by
Mehmet Fidanboylu
parent
d02e67e76e
commit
66e5422375
@@ -25,17 +25,19 @@ AndroidStudio get androidStudio => context[AndroidStudio];
|
||||
// $HOME/Applications/Android Studio.app/Contents/
|
||||
|
||||
final RegExp _dotHomeStudioVersionMatcher =
|
||||
RegExp(r'^\.AndroidStudio([^\d]*)([\d.]+)');
|
||||
RegExp(r'^\.(AndroidStudio[^\d]*)([\d.]+)');
|
||||
|
||||
String get javaPath => androidStudio?.javaPath;
|
||||
|
||||
class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
AndroidStudio(this.directory, {Version version, this.configured})
|
||||
AndroidStudio(this.directory,
|
||||
{Version version, this.configured, this.studioAppName = 'AndroidStudio'})
|
||||
: this.version = version ?? Version.unknown {
|
||||
_init();
|
||||
}
|
||||
|
||||
final String directory;
|
||||
final String studioAppName;
|
||||
final Version version;
|
||||
final String configured;
|
||||
|
||||
@@ -65,7 +67,8 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
return null;
|
||||
}
|
||||
final Version version = Version.parse(versionMatch[2]);
|
||||
if (version == null) {
|
||||
final String studioAppName = versionMatch[1];
|
||||
if (studioAppName == null || version == null) {
|
||||
return null;
|
||||
}
|
||||
String installPath;
|
||||
@@ -77,7 +80,11 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
// ignored, installPath will be null, which is handled below
|
||||
}
|
||||
if (installPath != null && fs.isDirectorySync(installPath)) {
|
||||
return AndroidStudio(installPath, version: version);
|
||||
return AndroidStudio(
|
||||
installPath,
|
||||
version: version,
|
||||
studioAppName: studioAppName,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -98,7 +105,7 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
'AndroidStudio$major.$minor');
|
||||
} else {
|
||||
_pluginsPath = fs.path.join(homeDirPath,
|
||||
'.AndroidStudio$major.$minor',
|
||||
'.$studioAppName$major.$minor',
|
||||
'config',
|
||||
'plugins');
|
||||
}
|
||||
|
||||
44
packages/flutter_tools/test/android/android_studio_test.dart
Normal file
44
packages/flutter_tools/test/android/android_studio_test.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/android/android_studio.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
|
||||
const String home = '/home/me';
|
||||
|
||||
Platform linuxPlatform() {
|
||||
return FakePlatform.fromPlatform(const LocalPlatform())
|
||||
..operatingSystem = 'linux'
|
||||
..environment = <String, String>{'HOME': home};
|
||||
}
|
||||
|
||||
void main() {
|
||||
const String installPath = '/opt/android-studio-with-cheese-5.0';
|
||||
const String studioHome = '$home/.AndroidStudioWithCheese5.0';
|
||||
const String homeFile = '$studioHome/system/.home';
|
||||
|
||||
MemoryFileSystem fs;
|
||||
|
||||
setUp(() {
|
||||
fs = MemoryFileSystem();
|
||||
fs.directory(installPath).createSync(recursive: true);
|
||||
fs.file(homeFile).createSync(recursive: true);
|
||||
fs.file(homeFile).writeAsStringSync(installPath);
|
||||
});
|
||||
|
||||
group('pluginsPath', () {
|
||||
testUsingContext('extracts custom paths from home dir', () {
|
||||
final AndroidStudio studio =
|
||||
AndroidStudio.fromHomeDot(fs.directory(studioHome));
|
||||
expect(studio, isNotNull);
|
||||
expect(studio.pluginsPath,
|
||||
equals('/home/me/.AndroidStudioWithCheese5.0/config/plugins'));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
// Note that custom home paths are not supported on macOS nor Windows yet:
|
||||
Platform: () => linuxPlatform(),
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user