Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When searching for the JDK bundled with an unrecognized version of Android Studio, assume the version to be the latest #125247

Merged
merged 10 commits into from
Apr 21, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -550,12 +550,11 @@ void main() {
plistWithoutVersion['CFBundleShortVersionString'] = '';
plistUtils.fileContents[plistFilePath] = plistWithoutVersion;

final String javaBinaryPath = fileSystem.path.join(studioInApplicationPlistFolder, 'jbr', 'Contents', 'Home', 'bin', 'java');
fileSystem.file(javaBinaryPath).createSync(recursive: true);
final String jdkPath = fileSystem.path.join(studioInApplicationPlistFolder, 'jbr', 'Contents', 'Home');

processManager.addCommand(FakeCommand(
command: <String>[
javaBinaryPath,
fileSystem.path.join(jdkPath, 'bin', 'java'),
'-version',
],
stderr: '123',
Expand All @@ -566,12 +565,45 @@ void main() {
)!;

expect(studio.version, null);
expect(studio.javaPath, equals(fileSystem.path.join(
studioInApplicationPlistFolder,
'jbr',
expect(studio.javaPath, jdkPath);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
FileSystemUtils: () => fsUtils,
ProcessManager: () => processManager,
Platform: () => platform,
PlistParser: () => plistUtils,
});

testUsingContext('when given an Android Studio newer than any known version, finds Java version by assuming latest known Android Studio version', () {
final String studioInApplicationPlistFolder = fileSystem.path.join(
'/',
'Application',
'Android Studio.app',
'Contents',
'Home',
)));
);
fileSystem.directory(studioInApplicationPlistFolder).createSync(recursive: true);

final String plistFilePath = fileSystem.path.join(studioInApplicationPlistFolder, 'Info.plist');
final Map<String, Object> plistWithoutVersion = Map<String, Object>.from(macStudioInfoPlist2022_1);
plistWithoutVersion['CFBundleShortVersionString'] = '99999.99.99';
plistUtils.fileContents[plistFilePath] = plistWithoutVersion;

final String jdkPathFor2022 = fileSystem.path.join(studioInApplicationPlistFolder, 'jbr', 'Contents', 'Home');

processManager.addCommand(FakeCommand(
command: <String>[
fileSystem.path.join(jdkPathFor2022, 'bin', 'java'),
'-version',
],
stderr: '123',
)
);
final AndroidStudio studio = AndroidStudio.fromMacOSBundle(
fileSystem.directory(studioInApplicationPlistFolder).parent.path,
)!;

expect(studio.version, greaterThanOrEqualTo(Version(99999, null, null)));
expect(studio.javaPath, jdkPathFor2022);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
FileSystemUtils: () => fsUtils,
Expand Down Expand Up @@ -748,6 +780,27 @@ void main() {
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
});

testUsingContext('when given an Android Studio newer than any known version, finds Java version by assuming latest known Android Studio version', () {
fileSystem.file(r'C:\Users\Dash\AppData\Local\Google\AndroidStudio99999.99.99\.home')
..createSync(recursive: true)
..writeAsStringSync(r'C:\Program Files\AndroidStudio');
fileSystem.directory(r'C:\Program Files\AndroidStudio')
.createSync(recursive: true);

fileSystem.file(r'C:\Program Files\AndroidStudio\jbr\bin\java').createSync(recursive: true);

final AndroidStudio studio = AndroidStudio.allInstalled().single;

const String expectedJdkLocationFor2022 = r'C:\Program Files\AndroidStudio\jbr';
expect(studio.version, greaterThanOrEqualTo(Version(99999, null, null)));
expect(studio.javaPath, equals(expectedJdkLocationFor2022));
}, overrides: <Type, Generator>{
Platform: () => platform,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
});

andrewkolos marked this conversation as resolved.
Show resolved Hide resolved
});

group('installation detection on Linux', () {
Expand Down Expand Up @@ -914,6 +967,31 @@ void main() {
ProcessManager: () => FakeProcessManager.any(),
});

testUsingContext('when given an Android Studio newer than any known version, finds Java version by assuming latest known Android Studio version', () {
const String studioHomeFilePath =
'$homeLinux/.cache/Google/AndroidStudio99999.99.99/.home';
const String studioInstallPath = '$homeLinux/AndroidStudio';

fileSystem.file(studioHomeFilePath)
..createSync(recursive: true)
..writeAsStringSync(studioInstallPath);

fileSystem.directory(studioInstallPath).createSync();

final String expectedJdkLocationFor2022 = fileSystem.path.join(studioInstallPath, 'jbr', 'bin', 'java');
fileSystem.file(expectedJdkLocationFor2022).createSync(recursive: true);

final AndroidStudio studio = AndroidStudio.allInstalled().single;

expect(studio.version, greaterThanOrEqualTo(Version(99999, null, null)));
andrewkolos marked this conversation as resolved.
Show resolved Hide resolved
expect(studio.javaPath, equals('$studioInstallPath/jbr'));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
FileSystemUtils: () => fsUtils,
Platform: () => platform,
ProcessManager: () => FakeProcessManager.any(),
});

andrewkolos marked this conversation as resolved.
Show resolved Hide resolved
testUsingContext('pluginsPath extracts custom paths from home dir', () {
const String installPath = '/opt/android-studio-with-cheese-5.0';
const String studioHome = '$homeLinux/.AndroidStudioWithCheese5.0';
Expand Down