Skip to content

Commit

Permalink
feat: adding Jetbrains Toolbox Android Studio detection for Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
erickzanardo committed Jun 28, 2024
1 parent 7b35a8a commit 08fe109
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 10 deletions.
11 changes: 11 additions & 0 deletions packages/shorebird_cli/lib/src/android_studio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ class AndroidStudio {
p.join('/', 'opt', 'android-studio'),
p.join(home, '.AndroidStudio'),
p.join(home, '.cache', 'Google', 'AndroidStudio'),
// Reference:
// https://blog.jetbrains.com/toolbox-app/2023/08/toolbox-app-2-0-overhauls-installations-and-updates/#install-and-update-reworked-from-the-ground-up
p.join(
home,
'.local',
'share',
'JetBrains',
'Toolbox',
'apps',
'AndroidStudio',
),
];
return candidateLocations.firstWhereOrNull((location) {
return Directory(location).existsSync();
Expand Down
74 changes: 64 additions & 10 deletions packages/shorebird_cli/test/src/android_studio_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,76 @@ void main() {
});

group('on Linux', () {
late Directory mockedHome;

setUp(() {
when(() => platform.isWindows).thenReturn(false);
when(() => platform.isMacOS).thenReturn(false);
when(() => platform.isLinux).thenReturn(true);

mockedHome = Directory.systemTemp.createTempSync();
when(() => platform.environment).thenReturn({
'HOME': mockedHome.path,
});
});

test('returns correct path', () async {
final tempDir = setUpAppTempDir();
final androidStudioDir = Directory(
p.join(tempDir.path, '.AndroidStudio'),
)..createSync(recursive: true);
when(() => platform.environment).thenReturn({'HOME': tempDir.path});
await expectLater(
runWithOverrides(() => androidStudio.path),
equals(androidStudioDir.path),
);
group('when installed directly on home', () {
late Directory androidStudioDir;

setUp(() {
androidStudioDir = Directory(
p.join(mockedHome.path, '.AndroidStudio'),
)..createSync(recursive: true);
});

test('returns correct path', () async {
await expectLater(
runWithOverrides(() => androidStudio.path),
equals(androidStudioDir.path),
);
});
});

group('when installed on the home cache', () {
late Directory androidStudioDir;

setUp(() {
androidStudioDir = Directory(
p.join(mockedHome.path, '.cache', 'Google', 'AndroidStudio'),
)..createSync(recursive: true);
});

test('returns correct path', () async {
await expectLater(
runWithOverrides(() => androidStudio.path),
equals(androidStudioDir.path),
);
});
});

group('when installed via the jetbrains toolbox app', () {
late Directory androidStudioDir;

setUp(() {
androidStudioDir = Directory(
p.join(
mockedHome.path,
'.local',
'share',
'JetBrains',
'Toolbox',
'apps',
'AndroidStudio',
),
)..createSync(recursive: true);
});

test('returns correct path', () async {
await expectLater(
runWithOverrides(() => androidStudio.path),
equals(androidStudioDir.path),
);
});
});
});
});
Expand Down

0 comments on commit 08fe109

Please sign in to comment.