| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:pub_semver/pub_semver.dart'; | 7 import 'package:pub_semver/pub_semver.dart'; |
| 8 | 8 |
| 9 import 'package.dart'; | 9 import 'package.dart'; |
| 10 import 'pubspec.dart'; | 10 import 'pubspec.dart'; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 /// [description2] for this source. | 117 /// [description2] for this source. |
| 118 /// | 118 /// |
| 119 /// This method should be light-weight. It doesn't need to validate that | 119 /// This method should be light-weight. It doesn't need to validate that |
| 120 /// either package exists. | 120 /// either package exists. |
| 121 /// | 121 /// |
| 122 /// Note that either description may be a reference description or an ID | 122 /// Note that either description may be a reference description or an ID |
| 123 /// description; they need not be the same type. ID descriptions should be | 123 /// description; they need not be the same type. ID descriptions should be |
| 124 /// considered equal to the reference descriptions that produced them. | 124 /// considered equal to the reference descriptions that produced them. |
| 125 bool descriptionsEqual(description1, description2); | 125 bool descriptionsEqual(description1, description2); |
| 126 | 126 |
| 127 /// Returns a hash code for [description]. |
| 128 /// |
| 129 /// Descriptions that compare equal using [descriptionsEqual] should return |
| 130 /// the same hash code. |
| 131 int hashDescription(description); |
| 132 |
| 127 /// Returns the source's name. | 133 /// Returns the source's name. |
| 128 String toString() => name; | 134 String toString() => name; |
| 129 } | 135 } |
| 130 | 136 |
| 131 /// A source bound to a [SystemCache]. | 137 /// A source bound to a [SystemCache]. |
| 132 abstract class BoundSource { | 138 abstract class BoundSource { |
| 133 /// The unbound source that produced [this]. | 139 /// The unbound source that produced [this]. |
| 134 Source get source; | 140 Source get source; |
| 135 | 141 |
| 136 /// The system cache to which [this] is bound. | 142 /// The system cache to which [this] is bound. |
| 137 SystemCache get systemCache; | 143 SystemCache get systemCache; |
| 138 | 144 |
| 139 /// Get the IDs of all versions that match [ref]. | 145 /// Get the IDs of all versions that match [ref]. |
| 140 /// | 146 /// |
| 141 /// Note that this does *not* require the packages to be downloaded locally, | 147 /// Note that this does *not* require the packages to be downloaded locally, |
| 142 /// which is the point. This is used during version resolution to determine | 148 /// which is the point. This is used during version resolution to determine |
| 143 /// which package versions are available to be downloaded (or already | 149 /// which package versions are available to be downloaded (or already |
| 144 /// downloaded). | 150 /// downloaded). |
| 145 /// | 151 /// |
| 146 /// By default, this assumes that each description has a single version and | 152 /// By default, this assumes that each description has a single version and |
| 147 /// uses [describe] to get that version. | 153 /// uses [describe] to get that version. |
| 148 /// | 154 /// |
| 149 /// Sources should not override this. Instead, they implement [doGetVersions]. | 155 /// Sources should not override this. Instead, they implement [doGetVersions]. |
| 150 Future<List<PackageId>> getVersions(PackageRef ref) { | 156 Future<List<PackageId>> getVersions(PackageRef ref) { |
| 151 if (ref.isRoot) { | 157 if (ref.isRoot) { |
| 152 throw new ArgumentError("Cannot get versions for the root package."); | 158 throw new ArgumentError("Cannot get versions for the root package."); |
| 153 } | 159 } |
| 154 if (ref.source != source.name) { | 160 if (ref.source != source) { |
| 155 throw new ArgumentError("Package $ref does not use source ${source.name}."
); | 161 throw new ArgumentError("Package $ref does not use source ${source.name}."
); |
| 156 } | 162 } |
| 157 | 163 |
| 158 return doGetVersions(ref); | 164 return doGetVersions(ref); |
| 159 } | 165 } |
| 160 | 166 |
| 161 /// Get the IDs of all versions that match [ref]. | 167 /// Get the IDs of all versions that match [ref]. |
| 162 /// | 168 /// |
| 163 /// Note that this does *not* require the packages to be downloaded locally, | 169 /// Note that this does *not* require the packages to be downloaded locally, |
| 164 /// which is the point. This is used during version resolution to determine | 170 /// which is the point. This is used during version resolution to determine |
| (...skipping 15 matching lines...) Expand all Loading... |
| 180 /// | 186 /// |
| 181 /// This may be called for packages that have not yet been downloaded during | 187 /// This may be called for packages that have not yet been downloaded during |
| 182 /// the version resolution process. Its results are automatically memoized. | 188 /// the version resolution process. Its results are automatically memoized. |
| 183 /// | 189 /// |
| 184 /// Throws a [DataException] if the pubspec's version doesn't match [id]'s | 190 /// Throws a [DataException] if the pubspec's version doesn't match [id]'s |
| 185 /// version. | 191 /// version. |
| 186 /// | 192 /// |
| 187 /// Sources should not override this. Instead, they implement [doDescribe]. | 193 /// Sources should not override this. Instead, they implement [doDescribe]. |
| 188 Future<Pubspec> describe(PackageId id) async { | 194 Future<Pubspec> describe(PackageId id) async { |
| 189 if (id.isRoot) throw new ArgumentError("Cannot describe the root package."); | 195 if (id.isRoot) throw new ArgumentError("Cannot describe the root package."); |
| 190 if (id.source != source.name) { | 196 if (id.source != source) { |
| 191 throw new ArgumentError("Package $id does not use source ${source.name}.")
; | 197 throw new ArgumentError( |
| 198 "Package $id does not use source ${source.name}."); |
| 192 } | 199 } |
| 193 | 200 |
| 194 var pubspec = _pubspecs[id]; | 201 var pubspec = _pubspecs[id]; |
| 195 if (pubspec != null) return pubspec; | 202 if (pubspec != null) return pubspec; |
| 196 | 203 |
| 197 // Delegate to the overridden one. | 204 // Delegate to the overridden one. |
| 198 pubspec = await doDescribe(id); | 205 pubspec = await doDescribe(id); |
| 199 if (pubspec.version != id.version) { | 206 if (pubspec.version != id.version) { |
| 200 dataError("The pubspec for $id has version ${pubspec.version}."); | 207 dataError("The pubspec for $id has version ${pubspec.version}."); |
| 201 } | 208 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 223 /// If the source is cached, this will be a path in the system cache. | 230 /// If the source is cached, this will be a path in the system cache. |
| 224 String getDirectory(PackageId id); | 231 String getDirectory(PackageId id); |
| 225 | 232 |
| 226 /// Stores [pubspec] so it's returned when [describe] is called with [id]. | 233 /// Stores [pubspec] so it's returned when [describe] is called with [id]. |
| 227 /// | 234 /// |
| 228 /// This is notionally protected; it should only be called by subclasses. | 235 /// This is notionally protected; it should only be called by subclasses. |
| 229 void memoizePubspec(PackageId id, Pubspec pubspec) { | 236 void memoizePubspec(PackageId id, Pubspec pubspec) { |
| 230 _pubspecs[id] = pubspec; | 237 _pubspecs[id] = pubspec; |
| 231 } | 238 } |
| 232 } | 239 } |
| OLD | NEW |