| 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('io.dart'); | 7 #import('io.dart'); |
| 8 #import('package.dart'); | 8 #import('package.dart'); |
| 9 #import('pubspec.dart'); | 9 #import('pubspec.dart'); |
| 10 #import('system_cache.dart'); | 10 #import('system_cache.dart'); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 * This should only be called once for each source, by [SystemCache.register]. | 59 * This should only be called once for each source, by [SystemCache.register]. |
| 60 * It should not be overridden by base classes. | 60 * It should not be overridden by base classes. |
| 61 */ | 61 */ |
| 62 void bind(SystemCache systemCache) { | 62 void bind(SystemCache systemCache) { |
| 63 assert(_systemCache == null); | 63 assert(_systemCache == null); |
| 64 this._systemCache = systemCache; | 64 this._systemCache = systemCache; |
| 65 } | 65 } |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * Get the list of all versions that exist for the package described by | 68 * Get the list of all versions that exist for the package described by |
| 69 * [description]. | 69 * [description]. [name] is the expected name of the package. |
| 70 * | 70 * |
| 71 * Note that this does *not* require the packages to be installed, which is | 71 * Note that this does *not* require the packages to be installed, which is |
| 72 * the point. This is used during version resolution to determine which | 72 * the point. This is used during version resolution to determine which |
| 73 * package versions are available to be installed (or already installed). | 73 * package versions are available to be installed (or already installed). |
| 74 * | 74 * |
| 75 * By default, this assumes that each description has a single version and | 75 * By default, this assumes that each description has a single version and |
| 76 * uses [describe] to get that version. | 76 * uses [describe] to get that version. |
| 77 */ | 77 */ |
| 78 Future<List<Version>> getVersions(description) { | 78 Future<List<Version>> getVersions(String name, description) { |
| 79 return describe(new PackageId(this, Version.none, description)) | 79 return describe(new PackageId(name, this, Version.none, description)) |
| 80 .transform((pubspec) => [pubspec.version]); | 80 .transform((pubspec) => [pubspec.version]); |
| 81 } | 81 } |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * Loads the (possibly remote) pubspec for the package version identified by | 84 * Loads the (possibly remote) pubspec for the package version identified by |
| 85 * [id]. This may be called for packages that have not yet been installed | 85 * [id]. This may be called for packages that have not yet been installed |
| 86 * during the version resolution process. | 86 * during the version resolution process. |
| 87 * | 87 * |
| 88 * For cached sources, by default this uses [installToSystemCache] to get the | 88 * For cached sources, by default this uses [installToSystemCache] to get the |
| 89 * pubspec. There is no default implementation for non-cached sources; they | 89 * pubspec. There is no default implementation for non-cached sources; they |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 * | 121 * |
| 122 * By default, this uses [systemCacheDirectory] and [install]. | 122 * By default, this uses [systemCacheDirectory] and [install]. |
| 123 */ | 123 */ |
| 124 Future<Package> installToSystemCache(PackageId id) { | 124 Future<Package> installToSystemCache(PackageId id) { |
| 125 var path = systemCacheDirectory(id); | 125 var path = systemCacheDirectory(id); |
| 126 return exists(path).chain((exists) { | 126 return exists(path).chain((exists) { |
| 127 if (exists) return new Future<bool>.immediate(true); | 127 if (exists) return new Future<bool>.immediate(true); |
| 128 return ensureDir(dirname(path)).chain((_) => install(id, path)); | 128 return ensureDir(dirname(path)).chain((_) => install(id, path)); |
| 129 }).chain((found) { | 129 }).chain((found) { |
| 130 if (!found) throw 'Package $id not found.'; | 130 if (!found) throw 'Package $id not found.'; |
| 131 return Package.load(path, systemCache.sources); | 131 return Package.load(id.name, path, systemCache.sources); |
| 132 }); | 132 }); |
| 133 } | 133 } |
| 134 | 134 |
| 135 /** | 135 /** |
| 136 * Returns the directory in the system cache that the package identified by | 136 * Returns the directory in the system cache that the package identified by |
| 137 * [id] should be installed to. This should return a path to a subdirectory of | 137 * [id] should be installed to. This should return a path to a subdirectory of |
| 138 * [systemCacheRoot]. | 138 * [systemCacheRoot]. |
| 139 * | 139 * |
| 140 * This doesn't need to be implemented if [shouldCache] is false, or if | 140 * This doesn't need to be implemented if [shouldCache] is false, or if |
| 141 * [installToSystemCache] is implemented. | 141 * [installToSystemCache] is implemented. |
| 142 */ | 142 */ |
| 143 String systemCacheDirectory(PackageId id) => | 143 String systemCacheDirectory(PackageId id) => |
| 144 join(systemCacheRoot, packageName(id.description)); | 144 join(systemCacheRoot, packageName(id.description)); |
| 145 | 145 |
| 146 /** | 146 /** |
| 147 * When a [Pubspec] or [LockFile] is parsed, it reads in the description for | 147 * When a [Pubspec] or [LockFile] is parsed, it reads in the description for |
| 148 * each dependency. It is up to the dependency's [Source] to determine how | 148 * each dependency. It is up to the dependency's [Source] to determine how |
| 149 * that should be interpreted. This will be called during parsing to validate | 149 * that should be interpreted. This will be called during parsing to validate |
| 150 * that the given [description] is well-formed according to this source. It | 150 * that the given [description] is well-formed according to this source. It |
| 151 * should return if the description is valid, or throw a [FormatException] if | 151 * should return if the description is valid, or throw a [FormatException] if |
| 152 * not. | 152 * not. |
| 153 * | 153 * |
| 154 * [fromLockFile] is true when the description comes from a [LockFile], to | 154 * [fromLockFile] is true when the description comes from a [LockFile], to |
| 155 * allow the source to use lockfile-specific descriptions via [resolveId]. | 155 * allow the source to use lockfile-specific descriptions via [resolveId]. |
| 156 */ | 156 */ |
| 157 void validateDescription(description, [bool fromLockFile=false]) {} | 157 void validateDescription(description, [bool fromLockFile=false]) {} |
| 158 | 158 |
| 159 /** | 159 /** |
| 160 * Returns a human-friendly name for the package described by [description]. | |
| 161 * This method should be light-weight. It doesn't need to validate that the | |
| 162 * given package exists. | |
| 163 * | |
| 164 * The package name should be lower-case and suitable for use in a filename. | |
| 165 * It may contain forward slashes. | |
| 166 */ | |
| 167 String packageName(description) => description; | |
| 168 | |
| 169 /** | |
| 170 * Returns whether or not [description1] describes the same package as | 160 * Returns whether or not [description1] describes the same package as |
| 171 * [description2] for this source. This method should be light-weight. It | 161 * [description2] for this source. This method should be light-weight. It |
| 172 * doesn't need to validate that either package exists. | 162 * doesn't need to validate that either package exists. |
| 173 * | 163 * |
| 174 * By default, this assumes both descriptions are strings and compares them | 164 * By default, this assumes both descriptions are strings and compares them |
| 175 * for equality. | 165 * for equality. |
| 176 */ | 166 */ |
| 177 bool descriptionsEqual(description1, description2) => | 167 bool descriptionsEqual(description1, description2) => |
| 178 description1 == description2; | 168 description1 == description2; |
| 179 | 169 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 193 * | 183 * |
| 194 * The returned [PackageId] may have a description field that's invalid | 184 * The returned [PackageId] may have a description field that's invalid |
| 195 * according to [validateDescription], although it must still be serializable | 185 * according to [validateDescription], although it must still be serializable |
| 196 * to JSON and YAML. It must also be equal to [id] according to | 186 * to JSON and YAML. It must also be equal to [id] according to |
| 197 * [descriptionsEqual]. | 187 * [descriptionsEqual]. |
| 198 * | 188 * |
| 199 * By default, this just returns [id]. | 189 * By default, this just returns [id]. |
| 200 */ | 190 */ |
| 201 Future<PackageId> resolveId(PackageId id) => new Future.immediate(id); | 191 Future<PackageId> resolveId(PackageId id) => new Future.immediate(id); |
| 202 } | 192 } |
| OLD | NEW |