Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(584)

Unified Diff: utils/pub/package.dart

Issue 12079112: Make a bunch of stuff in pub synchronous. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix after merge. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/pub/oauth2.dart ('k') | utils/pub/pub.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/package.dart
diff --git a/utils/pub/package.dart b/utils/pub/package.dart
index 72c5c0e19c77476b616d4bcb8a48ed9034e95100..ac9cc39703353a377d922bc8d4dbcf6a23772981 100644
--- a/utils/pub/package.dart
+++ b/utils/pub/package.dart
@@ -15,31 +15,6 @@ final _README_REGEXP = new RegExp(r"^README($|\.)", caseSensitive: false);
/// A named, versioned, unit of code and resource reuse.
class Package {
- /// Loads the package whose root directory is [packageDir]. [name] is the
- /// expected name of that package (e.g. the name given in the dependency), or
- /// null if the package being loaded is the entrypoint package.
- static Future<Package> load(String name, String packageDir,
- SourceRegistry sources) {
- var pubspecPath = join(packageDir, 'pubspec.yaml');
-
- return fileExists(pubspecPath).then((exists) {
- if (!exists) throw new PubspecNotFoundException(name);
- return readTextFile(pubspecPath);
- }).then((contents) {
- try {
- var pubspec = new Pubspec.parse(contents, sources);
-
- if (pubspec.name == null) throw new PubspecHasNoNameException(name);
- if (name != null && pubspec.name != name) {
- throw new PubspecNameMismatchException(name, pubspec.name);
- }
- return new Package._(packageDir, pubspec);
- } on FormatException catch (ex) {
- throw 'Could not parse $pubspecPath:\n${ex.message}';
- }
- });
- }
-
/// The path to the directory containing the package.
final String dir;
@@ -80,6 +55,30 @@ class Package {
});
}
+ /// Loads the package whose root directory is [packageDir]. [name] is the
+ /// expected name of that package (e.g. the name given in the dependency), or
+ /// `null` if the package being loaded is the entrypoint package.
+ factory Package(String name, String packageDir, SourceRegistry sources) {
+ var pubspecPath = join(packageDir, 'pubspec.yaml');
+ if (!fileExists(pubspecPath)) throw new PubspecNotFoundException(name);
+
+ try {
+ var pubspec = new Pubspec.parse(readTextFile(pubspecPath), sources);
+
+ if (pubspec.name == null) {
+ throw new PubspecHasNoNameException(name);
+ }
+
+ if (name != null && pubspec.name != name) {
+ throw new PubspecNameMismatchException(name, pubspec.name);
+ }
+
+ return new Package._(packageDir, pubspec);
+ } on FormatException catch (ex) {
+ throw 'Could not parse $pubspecPath:\n${ex.message}';
+ }
+ }
+
/// Constructs a package with the given pubspec. The package will have no
/// directory associated with it.
Package.inMemory(this.pubspec)
« no previous file with comments | « utils/pub/oauth2.dart ('k') | utils/pub/pub.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698