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