Chromium Code Reviews| Index: utils/pub/package.dart |
| diff --git a/utils/pub/package.dart b/utils/pub/package.dart |
| index f62e2becd0ffbda4ff69ee4a14c900e1a78a3cde..a53bcee40d737e26f6f76d04754038c179bc8eca 100644 |
| --- a/utils/pub/package.dart |
| +++ b/utils/pub/package.dart |
| @@ -13,31 +13,6 @@ import 'version.dart'; |
| /// 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; |
| @@ -58,6 +33,30 @@ class Package { |
| /// specified in the pubspec when this package depends on another. |
| Collection<PackageRef> get dependencies => pubspec.dependencies; |
| + /// 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) { |
|
nweiz
2013/02/01 02:05:55
It may still be correct to call this "Package.load
Bob Nystrom
2013/02/01 23:17:21
I'm personally OK with that being implied by the f
|
| + 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) |