forked from firka/flutter
[flutter_tools] allow bypassing context for FlutterProject creation, remove fromPath (#76258)
This commit is contained in:
@@ -145,6 +145,6 @@ class BuildAarCommand extends BuildSubCommand {
|
||||
if (argResults.rest.isEmpty) {
|
||||
return FlutterProject.current();
|
||||
}
|
||||
return FlutterProject.fromPath(findProjectRoot(argResults.rest.first));
|
||||
return FlutterProject.fromDirectory(globals.fs.directory(findProjectRoot(argResults.rest.first)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ class BuildBundleCommand extends BuildSubCommand {
|
||||
@override
|
||||
Future<Map<CustomDimensions, String>> get usageValues async {
|
||||
final String projectDir = globals.fs.file(targetFile).parent.parent.path;
|
||||
final FlutterProject flutterProject = FlutterProject.fromPath(projectDir);
|
||||
final FlutterProject flutterProject = FlutterProject.fromDirectory(globals.fs.directory(projectDir));
|
||||
if (flutterProject == null) {
|
||||
return const <CustomDimensions, String>{};
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ class CreateCommand extends CreateBase {
|
||||
_printPluginAddPlatformMessage(relativePluginPath);
|
||||
} else {
|
||||
// Tell the user the next steps.
|
||||
final FlutterProject project = FlutterProject.fromPath(projectDirPath);
|
||||
final FlutterProject project = FlutterProject.fromDirectory(globals.fs.directory(projectDirPath));
|
||||
final FlutterProject app = project.hasExampleApp ? project.example : project;
|
||||
final String relativeAppPath = globals.fs.path.normalize(globals.fs.path.relative(app.directory.path));
|
||||
final String relativeAppMain = globals.fs.path.join(relativeAppPath, 'lib', 'main.dart');
|
||||
|
||||
@@ -88,7 +88,7 @@ class PackagesGetCommand extends FlutterCommand {
|
||||
if (target == null) {
|
||||
return usageValues;
|
||||
}
|
||||
final FlutterProject rootProject = FlutterProject.fromPath(target);
|
||||
final FlutterProject rootProject = FlutterProject.fromDirectory(globals.fs.directory(target));
|
||||
// Do not send plugin analytics if pub has not run before.
|
||||
final bool hasPlugins = rootProject.flutterPluginsDependenciesFile.existsSync()
|
||||
&& rootProject.packagesFile.existsSync()
|
||||
@@ -160,7 +160,7 @@ class PackagesGetCommand extends FlutterCommand {
|
||||
'${ workingDirectory ?? "current working directory" }.'
|
||||
);
|
||||
}
|
||||
final FlutterProject rootProject = FlutterProject.fromPath(target);
|
||||
final FlutterProject rootProject = FlutterProject.fromDirectory(globals.fs.directory(target));
|
||||
|
||||
await _runPubGet(target, rootProject);
|
||||
await rootProject.regeneratePlatformSpecificTooling();
|
||||
@@ -311,7 +311,7 @@ class PackagesInteractiveGetCommand extends FlutterCommand {
|
||||
throwToolExit('Expected to find project root in '
|
||||
'current working directory.');
|
||||
}
|
||||
final FlutterProject flutterProject = FlutterProject.fromPath(target);
|
||||
final FlutterProject flutterProject = FlutterProject.fromDirectory(globals.fs.directory(target));
|
||||
|
||||
if (flutterProject.manifest.generateSyntheticPackage) {
|
||||
final Environment environment = Environment(
|
||||
|
||||
@@ -86,9 +86,25 @@ class FlutterProject {
|
||||
/// if `pubspec.yaml` or `example/pubspec.yaml` is invalid.
|
||||
static FlutterProject current() => globals.projectFactory.fromDirectory(globals.fs.currentDirectory);
|
||||
|
||||
/// Returns a [FlutterProject] view of the given directory or a ToolExit error,
|
||||
/// if `pubspec.yaml` or `example/pubspec.yaml` is invalid.
|
||||
static FlutterProject fromPath(String path) => globals.projectFactory.fromDirectory(globals.fs.directory(path));
|
||||
/// Create a [FlutterProject] and bypass the project caching.
|
||||
@visibleForTesting
|
||||
static FlutterProject fromDirectoryTest(Directory directory, [Logger logger]) {
|
||||
final FileSystem fileSystem = directory.fileSystem;
|
||||
logger ??= BufferLogger.test();
|
||||
final FlutterManifest manifest = FlutterProject._readManifest(
|
||||
directory.childFile(bundle.defaultManifestPath).path,
|
||||
logger: logger,
|
||||
fileSystem: fileSystem,
|
||||
);
|
||||
final FlutterManifest exampleManifest = FlutterProject._readManifest(
|
||||
FlutterProject._exampleDirectory(directory)
|
||||
.childFile(bundle.defaultManifestPath)
|
||||
.path,
|
||||
logger: logger,
|
||||
fileSystem: fileSystem,
|
||||
);
|
||||
return FlutterProject(directory, manifest, exampleManifest);
|
||||
}
|
||||
|
||||
/// The location of this project.
|
||||
final Directory directory;
|
||||
|
||||
Reference in New Issue
Block a user