@@ -56,6 +56,19 @@ const Map<String, Object> macStudioInfoPlist2020_3 = <String, Object>{
5656 },
5757};
5858
59+ const Map <String , Object > macStudioInfoPlist2022_1 = < String , Object > {
60+ 'CFBundleGetInfoString' : 'Android Studio 2022.1, build AI-221.6008.13.2211.9477386. Copyright JetBrains s.r.o., (c) 2000-2023' ,
61+ 'CFBundleShortVersionString' : '2022.1' ,
62+ 'CFBundleVersion' : 'AI-221.6008.13.2211.9477386' ,
63+ 'JVMOptions' : < String , Object > {
64+ 'Properties' : < String , Object > {
65+ 'idea.vendor.name' : 'Google' ,
66+ 'idea.paths.selector' : 'AndroidStudio2022.1' ,
67+ 'idea.platform.prefix' : 'AndroidStudio' ,
68+ },
69+ },
70+ };
71+
5972const Map <String , Object > macStudioInfoPlistEAP = < String , Object > {
6073 'CFBundleGetInfoString' : 'Android Studio EAP AI-212.5712.43.2112.8233820, build AI-212.5712.43.2112.8233820. Copyright JetBrains s.r.o., (c) 2000-2022' ,
6174 'CFBundleShortVersionString' : 'EAP AI-212.5712.43.2112.8233820' ,
@@ -486,6 +499,84 @@ void main() {
486499 Platform : () => platform,
487500 PlistParser : () => plistUtils,
488501 });
502+
503+ testUsingContext ('Can find Android Studio 2020.3 bundled Java version on Mac' , () {
504+ final String studioInApplicationPlistFolder = globals.fs.path.join (
505+ '/' ,
506+ 'Application' ,
507+ 'Android Studio.app' ,
508+ 'Contents' ,
509+ );
510+ globals.fs.directory (studioInApplicationPlistFolder).createSync (recursive: true );
511+
512+ final String plistFilePath = globals.fs.path.join (studioInApplicationPlistFolder, 'Info.plist' );
513+ plistUtils.fileContents[plistFilePath] = macStudioInfoPlist2020_3;
514+ processManager.addCommand (FakeCommand (
515+ command: < String > [
516+ globals.fs.path.join (studioInApplicationPlistFolder, 'jre' , 'Contents' , 'Home' , 'bin' , 'java' ),
517+ '-version' ,
518+ ],
519+ stderr: '123' ,
520+ )
521+ );
522+ final AndroidStudio studio = AndroidStudio .fromMacOSBundle (
523+ globals.fs.directory (studioInApplicationPlistFolder).parent.path,
524+ )! ;
525+
526+ expect (studio.javaPath, equals (globals.fs.path.join (
527+ studioInApplicationPlistFolder,
528+ 'jre' ,
529+ 'Contents' ,
530+ 'Home' ,
531+ )));
532+ }, overrides: < Type , Generator > {
533+ FileSystem : () => fileSystem,
534+ FileSystemUtils : () => fsUtils,
535+ ProcessManager : () => processManager,
536+ // Custom home paths are not supported on macOS nor Windows yet,
537+ // so we force the platform to fake Linux here.
538+ Platform : () => platform,
539+ PlistParser : () => plistUtils,
540+ });
541+
542+ testUsingContext ('Can find Android Studio 2022.1 bundled Java version on Mac' , () {
543+ final String studioInApplicationPlistFolder = globals.fs.path.join (
544+ '/' ,
545+ 'Application' ,
546+ 'Android Studio.app' ,
547+ 'Contents' ,
548+ );
549+ globals.fs.directory (studioInApplicationPlistFolder).createSync (recursive: true );
550+
551+ final String plistFilePath = globals.fs.path.join (studioInApplicationPlistFolder, 'Info.plist' );
552+ plistUtils.fileContents[plistFilePath] = macStudioInfoPlist2022_1;
553+ processManager.addCommand (FakeCommand (
554+ command: < String > [
555+ globals.fs.path.join (studioInApplicationPlistFolder, 'jbr' , 'Contents' , 'Home' , 'bin' , 'java' ),
556+ '-version' ,
557+ ],
558+ stderr: '123' ,
559+ )
560+ );
561+ final AndroidStudio studio = AndroidStudio .fromMacOSBundle (
562+ globals.fs.directory (studioInApplicationPlistFolder).parent.path,
563+ )! ;
564+
565+ expect (studio.javaPath, equals (globals.fs.path.join (
566+ studioInApplicationPlistFolder,
567+ 'jbr' ,
568+ 'Contents' ,
569+ 'Home' ,
570+ )));
571+ }, overrides: < Type , Generator > {
572+ FileSystem : () => fileSystem,
573+ FileSystemUtils : () => fsUtils,
574+ ProcessManager : () => processManager,
575+ // Custom home paths are not supported on macOS nor Windows yet,
576+ // so we force the platform to fake Linux here.
577+ Platform : () => platform,
578+ PlistParser : () => plistUtils,
579+ });
489580 });
490581
491582 late FileSystem windowsFileSystem;
@@ -596,6 +687,38 @@ void main() {
596687 ProcessManager : () => FakeProcessManager .any (),
597688 });
598689
690+ testUsingContext ('Can find Android Studio 2020.3 bundled Java version on Windows' , () {
691+ windowsFileSystem.file (r'C:\Users\Dash\AppData\Local\Google\AndroidStudio2020.3\.home' )
692+ ..createSync (recursive: true )
693+ ..writeAsStringSync (r'C:\Program Files\AndroidStudio' );
694+ windowsFileSystem.directory (r'C:\Program Files\AndroidStudio' )
695+ .createSync (recursive: true );
696+
697+ final AndroidStudio studio = AndroidStudio .allInstalled ().single;
698+
699+ expect (studio.javaPath, equals (r'C:\Program Files\AndroidStudio\jre' ));
700+ }, overrides: < Type , Generator > {
701+ Platform : () => windowsPlatform,
702+ FileSystem : () => windowsFileSystem,
703+ ProcessManager : () => FakeProcessManager .any (),
704+ });
705+
706+ testUsingContext ('Can find Android Studio 2022.1 bundled Java version on Windows' , () {
707+ windowsFileSystem.file (r'C:\Users\Dash\AppData\Local\Google\AndroidStudio2022.1\.home' )
708+ ..createSync (recursive: true )
709+ ..writeAsStringSync (r'C:\Program Files\AndroidStudio' );
710+ windowsFileSystem.directory (r'C:\Program Files\AndroidStudio' )
711+ .createSync (recursive: true );
712+
713+ final AndroidStudio studio = AndroidStudio .allInstalled ().single;
714+
715+ expect (studio.javaPath, equals (r'C:\Program Files\AndroidStudio\jbr' ));
716+ }, overrides: < Type , Generator > {
717+ Platform : () => windowsPlatform,
718+ FileSystem : () => windowsFileSystem,
719+ ProcessManager : () => FakeProcessManager .any (),
720+ });
721+
599722 group ('Installation detection on Linux' , () {
600723 late FileSystemUtils fsUtils;
601724
@@ -686,6 +809,47 @@ void main() {
686809 Platform : () => linuxPlatform,
687810 ProcessManager : () => FakeProcessManager .any (),
688811 });
812+
813+ testUsingContext ('Can find Android Studio 2020.3 bundled Java version on Linux' , () {
814+ const String studioHomeFilePath = '$homeLinux /.cache/Google/AndroidStudio2020.3/.home' ;
815+ const String studioInstallPath = '$homeLinux /AndroidStudio' ;
816+
817+ globals.fs.file (studioHomeFilePath)
818+ ..createSync (recursive: true )
819+ ..writeAsStringSync (studioInstallPath);
820+
821+ globals.fs.directory (studioInstallPath).createSync ();
822+
823+ final AndroidStudio studio = AndroidStudio .allInstalled ().single;
824+
825+ expect (studio.javaPath, equals ('$studioInstallPath /jre' ));
826+ }, overrides: < Type , Generator > {
827+ FileSystem : () => fileSystem,
828+ FileSystemUtils : () => fsUtils,
829+ Platform : () => linuxPlatform,
830+ ProcessManager : () => FakeProcessManager .any (),
831+ });
832+
833+ testUsingContext ('Can find Android Studio 2022.1 bundled Java version on Linux' , () {
834+ const String studioHomeFilePath =
835+ '$homeLinux /.cache/Google/AndroidStudio2022.1/.home' ;
836+ const String studioInstallPath = '$homeLinux /AndroidStudio' ;
837+
838+ globals.fs.file (studioHomeFilePath)
839+ ..createSync (recursive: true )
840+ ..writeAsStringSync (studioInstallPath);
841+
842+ globals.fs.directory (studioInstallPath).createSync ();
843+
844+ final AndroidStudio studio = AndroidStudio .allInstalled ().single;
845+
846+ expect (studio.javaPath, equals ('$studioInstallPath /jbr' ));
847+ }, overrides: < Type , Generator > {
848+ FileSystem : () => fileSystem,
849+ FileSystemUtils : () => fsUtils,
850+ Platform : () => linuxPlatform,
851+ ProcessManager : () => FakeProcessManager .any (),
852+ });
689853 });
690854}
691855
0 commit comments