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 package; | 5 library package; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:pathos/path.dart' as path; | 9 import 'package:pathos/path.dart' as path; |
10 | 10 |
(...skipping 85 matching lines...) Loading... |
96 final Version version; | 96 final Version version; |
97 | 97 |
98 /// The metadata used by the package's [source] to identify and locate it. It | 98 /// The metadata used by the package's [source] to identify and locate it. It |
99 /// contains whatever [Source]-specific data it needs to be able to install | 99 /// contains whatever [Source]-specific data it needs to be able to install |
100 /// the package. For example, the description of a git sourced package might | 100 /// the package. For example, the description of a git sourced package might |
101 /// by the URL "git://github.com/dart/uilib.git". | 101 /// by the URL "git://github.com/dart/uilib.git". |
102 final description; | 102 final description; |
103 | 103 |
104 PackageId(this.name, this.source, this.version, this.description); | 104 PackageId(this.name, this.source, this.version, this.description); |
105 | 105 |
| 106 /// Creates an ID for the given root package. |
| 107 PackageId.root(Package package) |
| 108 : name = package.name, |
| 109 source = null, |
| 110 version = package.version, |
| 111 description = package.name; |
| 112 |
106 /// Whether this ID identifies the root package. | 113 /// Whether this ID identifies the root package. |
107 bool get isRoot => source == null; | 114 bool get isRoot => source == null; |
108 | 115 |
109 int get hashCode => name.hashCode ^ source.hashCode ^ version.hashCode; | 116 int get hashCode => name.hashCode ^ source.hashCode ^ version.hashCode; |
110 | 117 |
111 /// Gets the directory where this package is or would be found in the | 118 /// Gets the directory where this package is or would be found in the |
112 /// [SystemCache]. | 119 /// [SystemCache]. |
113 Future<String> get systemCacheDirectory => source.systemCacheDirectory(this); | 120 Future<String> get systemCacheDirectory => source.systemCacheDirectory(this); |
114 | 121 |
115 bool operator ==(other) { | 122 bool operator ==(other) { |
(...skipping 20 matching lines...) Loading... |
136 if (nameComp != 0) return nameComp; | 143 if (nameComp != 0) return nameComp; |
137 | 144 |
138 return version.compareTo(other.version); | 145 return version.compareTo(other.version); |
139 } | 146 } |
140 | 147 |
141 /// Returns the pubspec for this package. | 148 /// Returns the pubspec for this package. |
142 Future<Pubspec> describe() => source.describe(this); | 149 Future<Pubspec> describe() => source.describe(this); |
143 | 150 |
144 /// Returns a future that completes to the resovled [PackageId] for this id. | 151 /// Returns a future that completes to the resovled [PackageId] for this id. |
145 Future<PackageId> get resolved => source.resolveId(this); | 152 Future<PackageId> get resolved => source.resolveId(this); |
| 153 |
| 154 /// Returns a [PackageRef] that references this package and constrains its |
| 155 /// version to exactly match [version]. |
| 156 PackageRef toRef() { |
| 157 return new PackageRef(name, source, version, description); |
| 158 } |
| 159 |
| 160 /// Returns `true` if this id's description matches [other]'s. |
| 161 bool descriptionEquals(PackageRef other) { |
| 162 return source.descriptionsEqual(description, other.description); |
| 163 } |
146 } | 164 } |
147 | 165 |
148 /// A reference to a package. Unlike a [PackageId], a PackageRef may not | 166 /// A reference to a package. Unlike a [PackageId], a PackageRef may not |
149 /// unambiguously refer to a single package. It may describe a range of allowed | 167 /// unambiguously refer to a single package. It may describe a range of allowed |
150 /// packages. | 168 /// packages. |
151 class PackageRef { | 169 class PackageRef { |
152 /// The name of the package being identified. | 170 /// The name of the package being identified. |
153 final String name; | 171 final String name; |
154 | 172 |
155 /// The [Source] used to look up the package. If this refers to a root | 173 /// The [Source] used to look up the package. If this refers to a root |
156 /// package, this will be `null`. | 174 /// package, this will be `null`. |
157 final Source source; | 175 final Source source; |
158 | 176 |
159 /// The allowed package versions. | 177 /// The allowed package versions. |
160 final VersionConstraint constraint; | 178 final VersionConstraint constraint; |
161 | 179 |
162 /// The metadata used to identify the package being referenced. The | 180 /// The metadata used to identify the package being referenced. The |
163 /// interpretation of this will vary based on the [source]. | 181 /// interpretation of this will vary based on the [source]. |
164 final description; | 182 final description; |
165 | 183 |
166 PackageRef(this.name, this.source, this.constraint, this.description); | 184 PackageRef(this.name, this.source, this.constraint, this.description); |
167 | 185 |
| 186 // TODO(rnystrom): Remove this if the old version solver is removed. |
168 /// Creates a reference to the given root package. | 187 /// Creates a reference to the given root package. |
169 PackageRef.root(Package package) | 188 PackageRef.root(Package package) |
170 : name = package.name, | 189 : name = package.name, |
171 source = null, | 190 source = null, |
172 constraint = package.version, | 191 constraint = package.version, |
173 description = package.name; | 192 description = package.name; |
174 | 193 |
175 /// Whether this refers to the root package. | 194 /// Whether this refers to the root package. |
176 bool get isRoot => source == null; | 195 bool get isRoot => source == null; |
177 | 196 |
178 String toString() { | 197 String toString() { |
179 if (isRoot) return "$name $constraint (root)"; | 198 if (isRoot) return "$name $constraint (root)"; |
180 return "$name $constraint from $source ($description)"; | 199 return "$name $constraint from $source ($description)"; |
181 } | 200 } |
182 | 201 |
183 /// Returns a [PackageId] generated from this [PackageRef] with the given | 202 /// Returns a [PackageId] generated from this [PackageRef] with the given |
184 /// concrete version. | 203 /// concrete version. |
185 PackageId atVersion(Version version) => | 204 PackageId atVersion(Version version) => |
186 new PackageId(name, source, version, description); | 205 new PackageId(name, source, version, description); |
| 206 |
| 207 /// Returns `true` if this reference's description matches [other]'s. |
| 208 bool descriptionEquals(PackageRef other) { |
| 209 return source.descriptionsEqual(description, other.description); |
| 210 } |
187 } | 211 } |
188 | 212 |
189 class PubspecNotFoundException implements Exception { | 213 class PubspecNotFoundException implements Exception { |
190 final String name; | 214 final String name; |
191 | 215 |
192 PubspecNotFoundException(this.name); | 216 PubspecNotFoundException(this.name); |
193 | 217 |
194 String toString() => 'Package "$name" doesn\'t have a pubspec.yaml file.'; | 218 String toString() => 'Package "$name" doesn\'t have a pubspec.yaml file.'; |
195 } | 219 } |
196 | 220 |
197 class PubspecHasNoNameException implements Exception { | 221 class PubspecHasNoNameException implements Exception { |
198 final String name; | 222 final String name; |
199 | 223 |
200 PubspecHasNoNameException(this.name); | 224 PubspecHasNoNameException(this.name); |
201 | 225 |
202 String toString() => 'Package "$name"\'s pubspec.yaml file is missing the ' | 226 String toString() => 'Package "$name"\'s pubspec.yaml file is missing the ' |
203 'required "name" field (e.g. "name: $name").'; | 227 'required "name" field (e.g. "name: $name").'; |
204 } | 228 } |
205 | 229 |
206 class PubspecNameMismatchException implements Exception { | 230 class PubspecNameMismatchException implements Exception { |
207 final String expectedName; | 231 final String expectedName; |
208 final String actualName; | 232 final String actualName; |
209 | 233 |
210 PubspecNameMismatchException(this.expectedName, this.actualName); | 234 PubspecNameMismatchException(this.expectedName, this.actualName); |
211 | 235 |
212 String toString() => 'The name you specified for your dependency, ' | 236 String toString() => 'The name you specified for your dependency, ' |
213 '"$expectedName", doesn\'t match the name "$actualName" in its pubspec.'; | 237 '"$expectedName", doesn\'t match the name "$actualName" in its pubspec.'; |
214 } | 238 } |
OLD | NEW |