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('package.dart'); | 7 #import('package.dart'); |
8 #import('pubspec.dart'); | 8 #import('pubspec.dart'); |
9 #import('version.dart'); | 9 #import('version.dart'); |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 * Whether this source's packages should be cached in Pub's global cache | 25 * Whether this source's packages should be cached in Pub's global cache |
26 * directory. | 26 * directory. |
27 * | 27 * |
28 * A source should be cached if it requires network access to retrieve | 28 * A source should be cached if it requires network access to retrieve |
29 * packages. It doesn't need to be cached if all packages are available | 29 * packages. It doesn't need to be cached if all packages are available |
30 * locally. | 30 * locally. |
31 */ | 31 */ |
32 abstract bool get shouldCache(); | 32 abstract bool get shouldCache(); |
33 | 33 |
34 /** | 34 /** |
35 * Get the list of all versions that exist for package [name]. | 35 * Get the list of all versions that exist for the package described by |
| 36 * [description]. |
36 * | 37 * |
37 * Note that this does *not* require the packages to be installed, which is | 38 * Note that this does *not* require the packages to be installed, which is |
38 * the point. This is used during version resolution to determine which | 39 * the point. This is used during version resolution to determine which |
39 * package versions are available to be installed (or already installed). | 40 * package versions are available to be installed (or already installed). |
40 */ | 41 */ |
41 Future<List<Version>> getVersions(String name) { | 42 Future<List<Version>> getVersions(description) { |
42 // TODO(rnystrom): Do something better here. | 43 // TODO(rnystrom): Do something better here. |
43 throw "Source $name doesn't support versioning."; | 44 throw "Source $name doesn't support versioning."; |
44 } | 45 } |
45 | 46 |
46 /** | 47 /** |
47 * Loads the (possibly remote) pubspec for the desired [version] of the named | 48 * Loads the (possibly remote) pubspec for the package version identified by |
48 * [package]. This will be called for packages that have not yet been | 49 * [id]. This will be called for packages that have not yet been installed |
49 * installed during the version resolution process. | 50 * during the version resolution process. |
50 */ | 51 */ |
51 Future<Pubspec> describe(String package, Version version) { | 52 Future<Pubspec> describe(PackageId id) { |
52 // TODO(rnystrom): Figure out how non-default sources should handle this. | 53 // TODO(rnystrom): Figure out how non-default sources should handle this. |
53 throw "Source $name doesn't support versioning."; | 54 throw "Source $name doesn't support versioning."; |
54 } | 55 } |
55 | 56 |
56 /** | 57 /** |
57 * Installs the package identified by [id] to [path]. Returns a [Future] that | 58 * Installs the package identified by [id] to [path]. Returns a [Future] that |
58 * completes when the installation was finished. The [Future] should resolve | 59 * completes when the installation was finished. The [Future] should resolve |
59 * to true if the package was found in the source and false if it wasn't. For | 60 * to true if the package was found in the source and false if it wasn't. For |
60 * all other error conditions, it should complete with an exception. | 61 * all other error conditions, it should complete with an exception. |
61 * | 62 * |
62 * [path] is guaranteed not to exist, and its parent directory is guaranteed | 63 * [path] is guaranteed not to exist, and its parent directory is guaranteed |
63 * to exist. | 64 * to exist. |
64 */ | 65 */ |
65 abstract Future<bool> install(PackageId id, String path); | 66 abstract Future<bool> install(PackageId id, String path); |
66 | 67 |
67 /** | 68 /** |
68 * Returns the directory in the system cache that the package identified by | 69 * Returns the directory in the system cache that the package identified by |
69 * [id] should be installed to. [parent] is this source's subdirectory in the | 70 * [id] should be installed to. [parent] is this source's subdirectory in the |
70 * system cache directory. | 71 * system cache directory. |
71 * | 72 * |
72 * This doesn't need to be implemented if [shouldCache] is false. | 73 * This doesn't need to be implemented if [shouldCache] is false. |
73 */ | 74 */ |
74 String systemCacheDirectory(PackageId id, String parent) => | 75 String systemCacheDirectory(PackageId id, String parent) => |
75 join(parent, packageName(id)); | 76 join(parent, packageName(id.description)); |
76 | 77 |
77 /** | 78 /** |
78 * When a [Pubspec] is parsed, it reads in the description for each | 79 * When a [Pubspec] is parsed, it reads in the description for each |
79 * dependency. It is up to the dependency's [Source] to determine how that | 80 * dependency. It is up to the dependency's [Source] to determine how that |
80 * should be interpreted. This will be called during parsing to validate that | 81 * should be interpreted. This will be called during parsing to validate that |
81 * the given [description] is well-formed according to this source. It should | 82 * the given [description] is well-formed according to this source. It should |
82 * return if the description is valid, or throw a [FormatException] if not. | 83 * return if the description is valid, or throw a [FormatException] if not. |
83 */ | 84 */ |
84 void validateDescription(description) {} | 85 void validateDescription(description) {} |
85 | 86 |
86 /** | 87 /** |
87 * Returns a human-friendly name for the package identified by [id]. This | 88 * Returns a human-friendly name for the package described by [description]. |
88 * method should be light-weight. It doesn't need to validate that the given | 89 * This method should be light-weight. It doesn't need to validate that the |
89 * package exists. | 90 * given package exists. |
90 * | 91 * |
91 * The package name should be lower-case and suitable for use in a filename. | 92 * The package name should be lower-case and suitable for use in a filename. |
92 * It may contain forward slashes. | 93 * It may contain forward slashes. |
93 */ | 94 */ |
94 String packageName(PackageId id) => id.description; | 95 String packageName(description) => description; |
| 96 |
| 97 /** |
| 98 * Returns whether or not [description1] describes the same package as |
| 99 * [description2] for this source. This method should be light-weight. It |
| 100 * doesn't need to validate that either package exists. |
| 101 * |
| 102 * By default, this assumes both descriptions are strings and compares them |
| 103 * for equality. |
| 104 */ |
| 105 bool descriptionsEqual(description1, description2) => |
| 106 description1 == description2; |
95 } | 107 } |
OLD | NEW |