Relax Android Studio version check. (#8389)
It's not just $HOME/.AndroidStudio2.2, it might also be .AndroidStudioPreview2.3, or .AndroidStudioFooBar1.7, or whatever. Made the Version parser less throw-happy, and relaxed the directory name checks to allow for the above. Fixes #8353.
This commit is contained in:
@@ -28,6 +28,9 @@ AndroidStudio get androidStudio =>
|
||||
|
||||
final Version minGradleVersion = new Version(2, 14, 1);
|
||||
|
||||
final RegExp _dotHomeStudioVersionMatcher =
|
||||
new RegExp(r'^\.AndroidStudio([^\d]*)([\d.]+)');
|
||||
|
||||
/// Locate Gradle.
|
||||
String get gradleExecutable {
|
||||
// See if the user has explicitly configured gradle-dir.
|
||||
@@ -66,15 +69,22 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
}
|
||||
|
||||
factory AndroidStudio.fromHomeDot(Directory homeDotDir) {
|
||||
Version version = new Version.parse(
|
||||
homeDotDir.basename.substring('.AndroidStudio'.length));
|
||||
Match versionMatch =
|
||||
_dotHomeStudioVersionMatcher.firstMatch(homeDotDir.basename);
|
||||
if (versionMatch?.groupCount != 2) {
|
||||
return null;
|
||||
}
|
||||
Version version = new Version.parse(versionMatch[2]);
|
||||
if (version == null) {
|
||||
return null;
|
||||
}
|
||||
String installPath;
|
||||
try {
|
||||
installPath = fs
|
||||
.file(fs.path.join(homeDotDir.path, 'system', '.home'))
|
||||
.readAsStringSync();
|
||||
} catch (e) {
|
||||
// ignored
|
||||
// ignored, installPath will be null, which is handled below
|
||||
}
|
||||
if (installPath != null && fs.isDirectorySync(installPath)) {
|
||||
return new AndroidStudio(installPath, version: version);
|
||||
@@ -176,7 +186,7 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
});
|
||||
}
|
||||
|
||||
// Read all $HOME/AndroidStudio*/system/.home files. There may be several
|
||||
// Read all $HOME/.AndroidStudio*/system/.home files. There may be several
|
||||
// pointing to the same installation, so we grab only the latest one.
|
||||
for (FileSystemEntity entity in fs.directory(homeDirPath).listSync()) {
|
||||
if (entity is Directory && entity.basename.startsWith('.AndroidStudio')) {
|
||||
@@ -231,7 +241,8 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
for (FileSystemEntity entry in gradlePaths.where((FileSystemEntity e) =>
|
||||
e.basename.startsWith('gradle-') && e is Directory)) {
|
||||
Version version =
|
||||
new Version.parse(entry.basename.substring('gradle-'.length));
|
||||
new Version.parse(entry.basename.substring('gradle-'.length)) ??
|
||||
Version.unknown;
|
||||
if (latestGradleVersion == null || version > latestGradleVersion) {
|
||||
latestGradleVersion = version;
|
||||
if (version >= minGradleVersion) {
|
||||
|
||||
@@ -100,22 +100,23 @@ class ConfiguredGradleValidator extends DoctorValidator {
|
||||
gradleExecutable = fs.path.join(
|
||||
cfgGradleDir, 'bin', platform.isWindows ? 'gradle.bat' : 'gradle');
|
||||
}
|
||||
String version;
|
||||
String versionString;
|
||||
if (processManager.canRun(gradleExecutable)) {
|
||||
type = ValidationType.partial;
|
||||
ProcessResult result =
|
||||
processManager.runSync(<String>[gradleExecutable, '--version']);
|
||||
if (result.exitCode == 0) {
|
||||
version = result.stdout
|
||||
versionString = result.stdout
|
||||
.toString()
|
||||
.split('\n')
|
||||
.firstWhere((String s) => s.startsWith('Gradle '))
|
||||
.substring('Gradle '.length);
|
||||
if (new Version.parse(version) >= minGradleVersion) {
|
||||
Version version = new Version.parse(versionString) ?? Version.unknown;
|
||||
if (version >= minGradleVersion) {
|
||||
type = ValidationType.installed;
|
||||
} else {
|
||||
messages.add(new ValidationMessage.error(
|
||||
'Gradle version $minGradleVersion required. Found version $version.'));
|
||||
'Gradle version $minGradleVersion required. Found version $versionString.'));
|
||||
}
|
||||
} else {
|
||||
messages
|
||||
@@ -128,6 +129,6 @@ class ConfiguredGradleValidator extends DoctorValidator {
|
||||
|
||||
messages.add(new ValidationMessage(
|
||||
'Consider removing the gradle-dir setting to use Gradle from Android Studio.'));
|
||||
return new ValidationResult(type, messages, statusInfo: version);
|
||||
return new ValidationResult(type, messages, statusInfo: versionString);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class Version implements Comparable<Version> {
|
||||
factory Version.parse(String text) {
|
||||
Match match = versionPattern.firstMatch(text);
|
||||
if (match == null) {
|
||||
throw new FormatException('Could not parse "$text".');
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -54,7 +54,7 @@ class Version implements Comparable<Version> {
|
||||
int patch = int.parse(match[5] ?? '0');
|
||||
return new Version._(major, minor, patch, text);
|
||||
} on FormatException {
|
||||
throw new FormatException('Could not parse "$text".');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -111,6 +111,8 @@ baz=qux
|
||||
|
||||
Version v5 = new Version(1, 2, 0, text: 'foo');
|
||||
expect(v5, equals(v2));
|
||||
|
||||
expect(new Version.parse('Preview2.2'), isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user