-
Notifications
You must be signed in to change notification settings - Fork 26.7k
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
[flutter_tools] Remove Version.unknown
#124771
Merged
auto-submit
merged 16 commits into
flutter:master
from
andrewkolos:remove-version-unknown-null-object
Apr 15, 2023
Merged
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c9df6f1
remove Version.unknown
andrewkolos 8f667bd
document meaning of null in AndroidStudio
andrewkolos 0e5cb91
fix xcode, make major version required
andrewkolos 3bf8b19
oops
andrewkolos 8fec718
nits
andrewkolos 63fcb2c
nit
andrewkolos df60ac5
Update packages/flutter_tools/lib/src/android/android_studio.dart
andrewkolos 80d6da4
nits
andrewkolos f231e4b
refactor --android-studio-dir stuff
andrewkolos 968dc24
Merge remote-tracking branch 'upstream/master' into remove-version-un…
andrewkolos 91694eb
add some tests for findLatest ordering
andrewkolos f06b47e
reorder sorting if statements
andrewkolos 99aed0c
add equivalent version test
andrewkolos f288818
throw ToolExit when we configured Android Studio install does not exist
andrewkolos 30007eb
fix test
andrewkolos f25b771
Merge branch 'master' into remove-version-unknown-null-object
andrewkolos File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,15 +39,16 @@ final RegExp _dotHomeStudioVersionMatcher = | |
// See https://github.com/flutter/flutter/issues/124252. | ||
String? get javaPath => globals.androidStudio?.javaPath; | ||
|
||
class AndroidStudio implements Comparable<AndroidStudio> { | ||
class AndroidStudio { | ||
/// A [version] value of null represents an unknown version. | ||
AndroidStudio( | ||
this.directory, { | ||
Version? version, | ||
this.version, | ||
this.configured, | ||
this.studioAppName = 'AndroidStudio', | ||
this.presetPluginsPath, | ||
}) : version = version ?? Version.unknown { | ||
_init(version: version); | ||
}) { | ||
_init(); | ||
} | ||
|
||
static AndroidStudio? fromMacOSBundle(String bundlePath) { | ||
|
@@ -147,7 +148,12 @@ class AndroidStudio implements Comparable<AndroidStudio> { | |
|
||
final String directory; | ||
final String studioAppName; | ||
final Version version; | ||
|
||
/// The version of Android Studio. | ||
/// | ||
/// A null value represents an unknown version. | ||
final Version? version; | ||
|
||
final String? configured; | ||
final String? presetPluginsPath; | ||
|
||
|
@@ -163,8 +169,12 @@ class AndroidStudio implements Comparable<AndroidStudio> { | |
if (presetPluginsPath != null) { | ||
return presetPluginsPath!; | ||
} | ||
final int major = version.major; | ||
final int minor = version.minor; | ||
|
||
// TODO(andrewkolos): This is a bug. We shouldn't treat an unknown | ||
// version as the same 0.0. | ||
andrewkolos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// See https://github.com/flutter/flutter/issues/121468. | ||
final int major = version?.major ?? 0; | ||
final int minor = version?.minor ?? 0; | ||
final String? homeDirPath = globals.fsUtils.homeDirPath; | ||
if (homeDirPath == null) { | ||
return null; | ||
|
@@ -217,15 +227,6 @@ class AndroidStudio implements Comparable<AndroidStudio> { | |
|
||
List<String> get validationMessages => _validationMessages; | ||
|
||
@override | ||
int compareTo(AndroidStudio other) { | ||
final int result = version.compareTo(other.version); | ||
if (result == 0) { | ||
return directory.compareTo(other.directory); | ||
} | ||
return result; | ||
} | ||
|
||
/// Locates the newest, valid version of Android Studio. | ||
static AndroidStudio? latestValid() { | ||
final String? configuredStudio = globals.config.getValue('android-studio-dir') as String?; | ||
|
@@ -245,7 +246,17 @@ class AndroidStudio implements Comparable<AndroidStudio> { | |
} | ||
AndroidStudio? newest; | ||
for (final AndroidStudio studio in studios.where((AndroidStudio s) => s.isValid)) { | ||
if (newest == null || studio.compareTo(newest) > 0) { | ||
newest ??= studio; | ||
andrewkolos marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this functionality unit tested? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added some tests. I ran in my local master branch to (hopefully) verify that no behavior was changed. |
||
|
||
if (studio.version != null && newest.version == null) { | ||
newest = studio; | ||
} | ||
else if (studio.version == null && newest.version == null && | ||
andrewkolos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
studio.directory.compareTo(newest.directory) > 0 ) { | ||
christopherfujino marked this conversation as resolved.
Show resolved
Hide resolved
|
||
newest = studio; | ||
} | ||
else if (studio.version != null && newest.version != null && | ||
studio.version!.compareTo(newest.version!) > 0){ | ||
newest = studio; | ||
} | ||
} | ||
|
@@ -337,7 +348,10 @@ class AndroidStudio implements Comparable<AndroidStudio> { | |
return false; | ||
} | ||
if (newerThan != null) { | ||
return studio.version.compareTo(newerThan) >= 0; | ||
if (studio.version == null) { | ||
return false; | ||
} | ||
return studio.version!.compareTo(newerThan) >= 0; | ||
} | ||
return true; | ||
}); | ||
|
@@ -438,7 +452,7 @@ class AndroidStudio implements Comparable<AndroidStudio> { | |
return keyMatcher.stringMatch(plistValue)?.split('=').last.trim().replaceAll('"', ''); | ||
} | ||
|
||
void _init({Version? version}) { | ||
void _init() { | ||
christopherfujino marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_isValid = false; | ||
_validationMessages.clear(); | ||
|
||
|
@@ -453,15 +467,15 @@ class AndroidStudio implements Comparable<AndroidStudio> { | |
|
||
final String javaPath; | ||
if (globals.platform.isMacOS) { | ||
if (version != null && version.major < 2020) { | ||
if (version != null && version!.major < 2020) { | ||
javaPath = globals.fs.path.join(directory, 'jre', 'jdk', 'Contents', 'Home'); | ||
} else if (version != null && version.major == 2022) { | ||
} else if (version != null && version!.major == 2022) { | ||
javaPath = globals.fs.path.join(directory, 'jbr', 'Contents', 'Home'); | ||
} else { | ||
javaPath = globals.fs.path.join(directory, 'jre', 'Contents', 'Home'); | ||
} | ||
} else { | ||
if (version != null && version.major == 2022) { | ||
if (version != null && version!.major == 2022) { | ||
javaPath = globals.fs.path.join(directory, 'jbr'); | ||
} else { | ||
javaPath = globals.fs.path.join(directory, 'jre'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you move the comparison logic out of
AndroidStudio.compareTo
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My instinct is to never implement
Comparable
unless the semantics of comparison are immediately obvious (i.e. do not require reading documentation or code). This makes sense for things like numbers and dates. It makes less sense for things like software installs where the version (or lack of it) and the directory name are involved.I would consider consider the implementation if we had a need to compare AndroidStudio installs in multiple places in code, but we are only doing it in one place now.
I don't mind either way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh ok, if we were only comparing this once, this makes sense.