[flutter_tools] Move homeDirPath to FileSystemUtils (#49909)

This commit is contained in:
Zachary Anderson
2020-02-03 14:33:03 -08:00
committed by GitHub
parent 3bee190308
commit 390ed1cd81
10 changed files with 240 additions and 106 deletions

View File

@@ -307,16 +307,31 @@ class AndroidSdk {
} else if (globals.platform.environment.containsKey(kAndroidSdkRoot)) {
androidHomeDir = globals.platform.environment[kAndroidSdkRoot];
} else if (globals.platform.isLinux) {
if (homeDirPath != null) {
androidHomeDir = globals.fs.path.join(homeDirPath, 'Android', 'Sdk');
if (globals.fsUtils.homeDirPath != null) {
androidHomeDir = globals.fs.path.join(
globals.fsUtils.homeDirPath,
'Android',
'Sdk',
);
}
} else if (globals.platform.isMacOS) {
if (homeDirPath != null) {
androidHomeDir = globals.fs.path.join(homeDirPath, 'Library', 'Android', 'sdk');
if (globals.fsUtils.homeDirPath != null) {
androidHomeDir = globals.fs.path.join(
globals.fsUtils.homeDirPath,
'Library',
'Android',
'sdk',
);
}
} else if (globals.platform.isWindows) {
if (homeDirPath != null) {
androidHomeDir = globals.fs.path.join(homeDirPath, 'AppData', 'Local', 'Android', 'sdk');
if (globals.fsUtils.homeDirPath != null) {
androidHomeDir = globals.fs.path.join(
globals.fsUtils.homeDirPath,
'AppData',
'Local',
'Android',
'sdk',
);
}
}

View File

@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import '../base/common.dart';
import '../base/context.dart';
import '../base/file_system.dart';
import '../base/process.dart';
@@ -67,8 +66,13 @@ class AndroidStudio implements Comparable<AndroidStudio> {
}
}
final String presetPluginsPath = pathsSelectorValue == null
? null
: globals.fs.path.join(homeDirPath, 'Library', 'Application Support', pathsSelectorValue);
? null
: globals.fs.path.join(
globals.fsUtils.homeDirPath,
'Library',
'Application Support',
pathsSelectorValue,
);
return AndroidStudio(studioPath, version: version, presetPluginsPath: presetPluginsPath);
}
@@ -123,15 +127,18 @@ class AndroidStudio implements Comparable<AndroidStudio> {
final int minor = version?.minor;
if (globals.platform.isMacOS) {
return globals.fs.path.join(
homeDirPath,
'Library',
'Application Support',
'AndroidStudio$major.$minor');
globals.fsUtils.homeDirPath,
'Library',
'Application Support',
'AndroidStudio$major.$minor',
);
} else {
return globals.fs.path.join(homeDirPath,
'.$studioAppName$major.$minor',
'config',
'plugins');
return globals.fs.path.join(
globals.fsUtils.homeDirPath,
'.$studioAppName$major.$minor',
'config',
'plugins',
);
}
}
@@ -198,7 +205,10 @@ class AndroidStudio implements Comparable<AndroidStudio> {
}
_checkForStudio('/Applications');
_checkForStudio(globals.fs.path.join(homeDirPath, 'Applications'));
_checkForStudio(globals.fs.path.join(
globals.fsUtils.homeDirPath,
'Applications',
));
final String configuredStudioDir = globals.config.getValue('android-studio-dir') as String;
if (configuredStudioDir != null) {
@@ -235,14 +245,17 @@ class AndroidStudio implements Comparable<AndroidStudio> {
// Read all $HOME/.AndroidStudio*/system/.home files. There may be several
// pointing to the same installation, so we grab only the latest one.
if (homeDirPath != null && globals.fs.directory(homeDirPath).existsSync()) {
for (final FileSystemEntity entity in globals.fs.directory(homeDirPath).listSync(followLinks: false)) {
if (entity is Directory && entity.basename.startsWith('.AndroidStudio')) {
final AndroidStudio studio = AndroidStudio.fromHomeDot(entity);
if (studio != null && !_hasStudioAt(studio.directory, newerThan: studio.version)) {
studios.removeWhere((AndroidStudio other) => other.directory == studio.directory);
studios.add(studio);
}
if (globals.fsUtils.homeDirPath != null &&
globals.fs.directory(globals.fsUtils.homeDirPath).existsSync()) {
final Directory homeDir = globals.fs.directory(globals.fsUtils.homeDirPath);
for (final Directory entity in homeDir.listSync(followLinks: false).whereType<Directory>()) {
if (!entity.basename.startsWith('.AndroidStudio')) {
continue;
}
final AndroidStudio studio = AndroidStudio.fromHomeDot(entity);
if (studio != null && !_hasStudioAt(studio.directory, newerThan: studio.version)) {
studios.removeWhere((AndroidStudio other) => other.directory == studio.directory);
studios.add(studio);
}
}
}
@@ -262,7 +275,7 @@ class AndroidStudio implements Comparable<AndroidStudio> {
// Add /opt/android-studio and $HOME/android-studio, if they exist.
_checkWellKnownPath('/opt/android-studio');
_checkWellKnownPath('$homeDirPath/android-studio');
_checkWellKnownPath('${globals.fsUtils.homeDirPath}/android-studio');
}
return studios;
}