Unverified Commit cfe4d0d7 authored by Lau Ching Jun's avatar Lau Ching Jun Committed by GitHub

Add FlutterProjectFactory so that it can be overridden internally. (#35092)

Also update the comments since we don't return Future<FlutterProject>
anymore.
parent 6d8a59c8
...@@ -9,6 +9,7 @@ import 'package:yaml/yaml.dart'; ...@@ -9,6 +9,7 @@ import 'package:yaml/yaml.dart';
import 'android/gradle.dart' as gradle; import 'android/gradle.dart' as gradle;
import 'base/common.dart'; import 'base/common.dart';
import 'base/context.dart';
import 'base/file_system.dart'; import 'base/file_system.dart';
import 'build_info.dart'; import 'build_info.dart';
import 'bundle.dart' as bundle; import 'bundle.dart' as bundle;
...@@ -22,6 +23,27 @@ import 'plugins.dart'; ...@@ -22,6 +23,27 @@ import 'plugins.dart';
import 'template.dart'; import 'template.dart';
import 'web/workflow.dart'; import 'web/workflow.dart';
FlutterProjectFactory get projectFactory => context.get<FlutterProjectFactory>() ?? const FlutterProjectFactory();
class FlutterProjectFactory {
const FlutterProjectFactory();
/// Returns a [FlutterProject] view of the given directory or a ToolExit error,
/// if `pubspec.yaml` or `example/pubspec.yaml` is invalid.
FlutterProject fromDirectory(Directory directory) {
assert(directory != null);
final FlutterManifest manifest = FlutterProject._readManifest(
directory.childFile(bundle.defaultManifestPath).path,
);
final FlutterManifest exampleManifest = FlutterProject._readManifest(
FlutterProject._exampleDirectory(directory)
.childFile(bundle.defaultManifestPath)
.path,
);
return FlutterProject(directory, manifest, exampleManifest);
}
}
/// Represents the contents of a Flutter project at the specified [directory]. /// Represents the contents of a Flutter project at the specified [directory].
/// ///
/// [FlutterManifest] information is read from `pubspec.yaml` and /// [FlutterManifest] information is read from `pubspec.yaml` and
...@@ -38,25 +60,16 @@ class FlutterProject { ...@@ -38,25 +60,16 @@ class FlutterProject {
assert(manifest != null), assert(manifest != null),
assert(_exampleManifest != null); assert(_exampleManifest != null);
/// Returns a future that completes with a [FlutterProject] view of the given directory /// Returns a [FlutterProject] view of the given directory or a ToolExit error,
/// or a ToolExit error, if `pubspec.yaml` or `example/pubspec.yaml` is invalid. /// if `pubspec.yaml` or `example/pubspec.yaml` is invalid.
static FlutterProject fromDirectory(Directory directory) { static FlutterProject fromDirectory(Directory directory) => projectFactory.fromDirectory(directory);
assert(directory != null);
final FlutterManifest manifest = _readManifest(
directory.childFile(bundle.defaultManifestPath).path,
);
final FlutterManifest exampleManifest = _readManifest(
_exampleDirectory(directory).childFile(bundle.defaultManifestPath).path,
);
return FlutterProject(directory, manifest, exampleManifest);
}
/// Returns a future that completes with a [FlutterProject] view of the current directory. /// Returns a [FlutterProject] view of the current directory or a ToolExit error,
/// or a ToolExit error, if `pubspec.yaml` or `example/pubspec.yaml` is invalid. /// if `pubspec.yaml` or `example/pubspec.yaml` is invalid.
static FlutterProject current() => fromDirectory(fs.currentDirectory); static FlutterProject current() => fromDirectory(fs.currentDirectory);
/// Returns a future that completes with a [FlutterProject] view of the given directory. /// Returns a [FlutterProject] view of the given directory or a ToolExit error,
/// or a ToolExit error, if `pubspec.yaml` or `example/pubspec.yaml` is invalid. /// if `pubspec.yaml` or `example/pubspec.yaml` is invalid.
static FlutterProject fromPath(String path) => fromDirectory(fs.directory(path)); static FlutterProject fromPath(String path) => fromDirectory(fs.directory(path));
/// The location of this project. /// The location of this project.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment