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 'dart:async'; |
8 | 8 |
9 import '../../pkg/path/lib/path.dart' as path; | 9 import '../../pkg/path/lib/path.dart' as path; |
10 | 10 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 /// | 162 /// |
163 /// This doesn't need to be implemented if [shouldCache] is false. | 163 /// This doesn't need to be implemented if [shouldCache] is false. |
164 Future<String> systemCacheDirectory(PackageId id) { | 164 Future<String> systemCacheDirectory(PackageId id) { |
165 return new Future.immediateError( | 165 return new Future.immediateError( |
166 "systemCacheDirectory() must be implemented if shouldCache is true."); | 166 "systemCacheDirectory() must be implemented if shouldCache is true."); |
167 } | 167 } |
168 | 168 |
169 /// When a [Pubspec] or [LockFile] is parsed, it reads in the description for | 169 /// When a [Pubspec] or [LockFile] is parsed, it reads in the description for |
170 /// each dependency. It is up to the dependency's [Source] to determine how | 170 /// each dependency. It is up to the dependency's [Source] to determine how |
171 /// that should be interpreted. This will be called during parsing to validate | 171 /// that should be interpreted. This will be called during parsing to validate |
172 /// that the given [description] is well-formed according to this source, and | 172 /// that the given [description] is well-formed according to this source. It |
173 /// to give the source a chance to canonicalize the description. | 173 /// should return if the description is valid, or throw a [FormatException] if |
174 /// | 174 /// not. |
175 /// [containingPath] is the path to the local file (pubspec or lockfile) | |
176 /// where this description appears. It may be `null` if the description is | |
177 /// coming from some in-memory source (such as pulling down a pubspec from | |
178 /// pub.dartlang.org). | |
179 /// | |
180 /// It should return if a (possibly modified) valid description, or throw a | |
181 /// [FormatException] if not valid. | |
182 /// | 175 /// |
183 /// [fromLockFile] is true when the description comes from a [LockFile], to | 176 /// [fromLockFile] is true when the description comes from a [LockFile], to |
184 /// allow the source to use lockfile-specific descriptions via [resolveId]. | 177 /// allow the source to use lockfile-specific descriptions via [resolveId]. |
185 dynamic parseDescription(String containingPath, description, | 178 void validateDescription(description, {bool fromLockFile: false}) {} |
186 {bool fromLockFile: false}) { | |
187 return description; | |
188 } | |
189 | 179 |
190 /// Returns whether or not [description1] describes the same package as | 180 /// Returns whether or not [description1] describes the same package as |
191 /// [description2] for this source. This method should be light-weight. It | 181 /// [description2] for this source. This method should be light-weight. It |
192 /// doesn't need to validate that either package exists. | 182 /// doesn't need to validate that either package exists. |
193 /// | 183 /// |
194 /// By default, just uses regular equality. | 184 /// By default, just uses regular equality. |
195 bool descriptionsEqual(description1, description2) => | 185 bool descriptionsEqual(description1, description2) => |
196 description1 == description2; | 186 description1 == description2; |
197 | 187 |
198 /// For some sources, [PackageId]s can point to different chunks of code at | 188 /// For some sources, [PackageId]s can point to different chunks of code at |
199 /// different times. This takes such an [id] and returns a future that | 189 /// different times. This takes such an [id] and returns a future that |
200 /// completes to a [PackageId] that will uniquely specify a single chunk of | 190 /// completes to a [PackageId] that will uniquely specify a single chunk of |
201 /// code forever. | 191 /// code forever. |
202 /// | 192 /// |
203 /// For example, [GitSource] might take an [id] with description | 193 /// For example, [GitSource] might take an [id] with description |
204 /// `http://github.com/dart-lang/some-lib.git` and return an id with a | 194 /// `http://github.com/dart-lang/some-lib.git` and return an id with a |
205 /// description that includes the current commit of the Git repository. | 195 /// description that includes the current commit of the Git repository. |
206 /// | 196 /// |
207 /// This will be called after the package identified by [id] is installed, so | 197 /// This will be called after the package identified by [id] is installed, so |
208 /// the source can use the installed package to determine information about | 198 /// the source can use the installed package to determine information about |
209 /// the resolved id. | 199 /// the resolved id. |
210 /// | 200 /// |
211 /// The returned [PackageId] may have a description field that's invalid | 201 /// The returned [PackageId] may have a description field that's invalid |
212 /// according to [parseDescription], although it must still be serializable | 202 /// according to [validateDescription], although it must still be serializable |
213 /// to JSON and YAML. It must also be equal to [id] according to | 203 /// to JSON and YAML. It must also be equal to [id] according to |
214 /// [descriptionsEqual]. | 204 /// [descriptionsEqual]. |
215 /// | 205 /// |
216 /// By default, this just returns [id]. | 206 /// By default, this just returns [id]. |
217 Future<PackageId> resolveId(PackageId id) => new Future.immediate(id); | 207 Future<PackageId> resolveId(PackageId id) => new Future.immediate(id); |
218 | 208 |
219 /// Returns the source's name. | 209 /// Returns the source's name. |
220 String toString() => name; | 210 String toString() => name; |
221 } | 211 } |
OLD | NEW |