| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012, the Dart project authors.  Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors.  Please see the AUTHORS file | 
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a | 
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. | 
| 4 | 4 | 
| 5 library source; | 5 library source; | 
| 6 | 6 | 
|  | 7 import 'dart:async'; | 
| 7 import 'io.dart'; | 8 import 'io.dart'; | 
| 8 import 'package.dart'; | 9 import 'package.dart'; | 
| 9 import 'pubspec.dart'; | 10 import 'pubspec.dart'; | 
| 10 import 'system_cache.dart'; | 11 import 'system_cache.dart'; | 
| 11 import 'version.dart'; | 12 import 'version.dart'; | 
| 12 | 13 | 
| 13 /// A source from which to install packages. | 14 /// A source from which to install packages. | 
| 14 /// | 15 /// | 
| 15 /// Each source has many packages that it looks up using [PackageId]s. The | 16 /// Each source has many packages that it looks up using [PackageId]s. The | 
| 16 /// source is responsible for installing these packages to the package cache. | 17 /// source is responsible for installing these packages to the package cache. | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 57   /// [description]. [name] is the expected name of the package. | 58   /// [description]. [name] is the expected name of the package. | 
| 58   /// | 59   /// | 
| 59   /// Note that this does *not* require the packages to be installed, which is | 60   /// Note that this does *not* require the packages to be installed, which is | 
| 60   /// the point. This is used during version resolution to determine which | 61   /// the point. This is used during version resolution to determine which | 
| 61   /// package versions are available to be installed (or already installed). | 62   /// package versions are available to be installed (or already installed). | 
| 62   /// | 63   /// | 
| 63   /// By default, this assumes that each description has a single version and | 64   /// By default, this assumes that each description has a single version and | 
| 64   /// uses [describe] to get that version. | 65   /// uses [describe] to get that version. | 
| 65   Future<List<Version>> getVersions(String name, description) { | 66   Future<List<Version>> getVersions(String name, description) { | 
| 66     return describe(new PackageId(name, this, Version.none, description)) | 67     return describe(new PackageId(name, this, Version.none, description)) | 
| 67       .transform((pubspec) => [pubspec.version]); | 68       .then((pubspec) => [pubspec.version]); | 
| 68   } | 69   } | 
| 69 | 70 | 
| 70   /// Loads the (possibly remote) pubspec for the package version identified by | 71   /// Loads the (possibly remote) pubspec for the package version identified by | 
| 71   /// [id]. This may be called for packages that have not yet been installed | 72   /// [id]. This may be called for packages that have not yet been installed | 
| 72   /// during the version resolution process. | 73   /// during the version resolution process. | 
| 73   /// | 74   /// | 
| 74   /// For cached sources, by default this uses [installToSystemCache] to get the | 75   /// For cached sources, by default this uses [installToSystemCache] to get the | 
| 75   /// pubspec. There is no default implementation for non-cached sources; they | 76   /// pubspec. There is no default implementation for non-cached sources; they | 
| 76   /// must implement it manually. | 77   /// must implement it manually. | 
| 77   Future<Pubspec> describe(PackageId id) { | 78   Future<Pubspec> describe(PackageId id) { | 
| 78     if (!shouldCache) throw "Source $name must implement describe(id)."; | 79     if (!shouldCache) throw "Source $name must implement describe(id)."; | 
| 79     return installToSystemCache(id).transform((package) => package.pubspec); | 80     return installToSystemCache(id).then((package) => package.pubspec); | 
| 80   } | 81   } | 
| 81 | 82 | 
| 82   /// Installs the package identified by [id] to [path]. Returns a [Future] that | 83   /// Installs the package identified by [id] to [path]. Returns a [Future] that | 
| 83   /// completes when the installation was finished. The [Future] should resolve | 84   /// completes when the installation was finished. The [Future] should resolve | 
| 84   /// to true if the package was found in the source and false if it wasn't. For | 85   /// to true if the package was found in the source and false if it wasn't. For | 
| 85   /// all other error conditions, it should complete with an exception. | 86   /// all other error conditions, it should complete with an exception. | 
| 86   /// | 87   /// | 
| 87   /// [path] is guaranteed not to exist, and its parent directory is guaranteed | 88   /// [path] is guaranteed not to exist, and its parent directory is guaranteed | 
| 88   /// to exist. | 89   /// to exist. | 
| 89   /// | 90   /// | 
| 90   /// Note that [path] may be deleted. If re-installing a package that has | 91   /// Note that [path] may be deleted. If re-installing a package that has | 
| 91   /// already been installed would be costly or impossible, | 92   /// already been installed would be costly or impossible, | 
| 92   /// [installToSystemCache] should be implemented instead of [install]. | 93   /// [installToSystemCache] should be implemented instead of [install]. | 
| 93   /// | 94   /// | 
| 94   /// This doesn't need to be implemented if [installToSystemCache] is | 95   /// This doesn't need to be implemented if [installToSystemCache] is | 
| 95   /// implemented. | 96   /// implemented. | 
| 96   Future<bool> install(PackageId id, String path) { | 97   Future<bool> install(PackageId id, String path) { | 
| 97     throw "Either install or installToSystemCache must be implemented for " | 98     throw "Either install or installToSystemCache must be implemented for " | 
| 98         "source $name."; | 99         "source $name."; | 
| 99   } | 100   } | 
| 100 | 101 | 
| 101   /// Installs the package identified by [id] to the system cache. This is only | 102   /// Installs the package identified by [id] to the system cache. This is only | 
| 102   /// called for sources with [shouldCache] set to true. | 103   /// called for sources with [shouldCache] set to true. | 
| 103   /// | 104   /// | 
| 104   /// By default, this uses [systemCacheDirectory] and [install]. | 105   /// By default, this uses [systemCacheDirectory] and [install]. | 
| 105   Future<Package> installToSystemCache(PackageId id) { | 106   Future<Package> installToSystemCache(PackageId id) { | 
| 106     var path = systemCacheDirectory(id); | 107     var path = systemCacheDirectory(id); | 
| 107     return exists(path).chain((exists) { | 108     return exists(path).then((exists) { | 
| 108       if (exists) return new Future<bool>.immediate(true); | 109       if (exists) return new Future<bool>.immediate(true); | 
| 109       return ensureDir(dirname(path)).chain((_) => install(id, path)); | 110       return ensureDir(dirname(path)).then((_) => install(id, path)); | 
| 110     }).chain((found) { | 111     }).then((found) { | 
| 111       if (!found) throw 'Package $id not found.'; | 112       if (!found) throw 'Package $id not found.'; | 
| 112       return Package.load(id.name, path, systemCache.sources); | 113       return Package.load(id.name, path, systemCache.sources); | 
| 113     }); | 114     }); | 
| 114   } | 115   } | 
| 115 | 116 | 
| 116   /// Returns the directory in the system cache that the package identified by | 117   /// Returns the directory in the system cache that the package identified by | 
| 117   /// [id] should be installed to. This should return a path to a subdirectory | 118   /// [id] should be installed to. This should return a path to a subdirectory | 
| 118   /// of [systemCacheRoot]. | 119   /// of [systemCacheRoot]. | 
| 119   /// | 120   /// | 
| 120   /// This doesn't need to be implemented if [shouldCache] is false, or if | 121   /// This doesn't need to be implemented if [shouldCache] is false, or if | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 160   /// according to [validateDescription], although it must still be serializable | 161   /// according to [validateDescription], although it must still be serializable | 
| 161   /// to JSON and YAML. It must also be equal to [id] according to | 162   /// to JSON and YAML. It must also be equal to [id] according to | 
| 162   /// [descriptionsEqual]. | 163   /// [descriptionsEqual]. | 
| 163   /// | 164   /// | 
| 164   /// By default, this just returns [id]. | 165   /// By default, this just returns [id]. | 
| 165   Future<PackageId> resolveId(PackageId id) => new Future.immediate(id); | 166   Future<PackageId> resolveId(PackageId id) => new Future.immediate(id); | 
| 166 | 167 | 
| 167   /// Returns the source's name. | 168   /// Returns the source's name. | 
| 168   String toString() => name; | 169   String toString() => name; | 
| 169 } | 170 } | 
| OLD | NEW | 
|---|