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('io.dart'); | 7 #import('io.dart'); |
| 8 #import('pubspec.dart'); | 8 #import('pubspec.dart'); |
| 9 #import('source.dart'); | 9 #import('source.dart'); |
| 10 #import('source_registry.dart'); | 10 #import('source_registry.dart'); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 * by the URL "git://github.com/dart/uilib.git". | 109 * by the URL "git://github.com/dart/uilib.git". |
| 110 */ | 110 */ |
| 111 final description; | 111 final description; |
| 112 | 112 |
| 113 PackageId(this.source, this.version, this.description); | 113 PackageId(this.source, this.version, this.description); |
| 114 | 114 |
| 115 /** | 115 /** |
| 116 * The name of the package being identified. This will be the human-friendly | 116 * The name of the package being identified. This will be the human-friendly |
| 117 * name like "uilib". | 117 * name like "uilib". |
| 118 */ | 118 */ |
| 119 String get name() => source.packageName(this); | 119 String get name() => source.packageName(description); |
| 120 | 120 |
| 121 int hashCode() => name.hashCode() ^ | 121 int hashCode() => name.hashCode() ^ |
| 122 source.name.hashCode() ^ | 122 source.name.hashCode() ^ |
| 123 version.hashCode(); | 123 version.hashCode(); |
| 124 | 124 |
| 125 bool operator ==(other) { | 125 bool operator ==(other) { |
| 126 if (other is! PackageId) return false; | 126 if (other is! PackageId) return false; |
| 127 // TODO(rnystrom): We're assuming here the name/version/source tuple is | 127 // TODO(rnystrom): We're assuming here the name/version/source tuple is |
| 128 // enough to uniquely identify the package and that we don't need to delve | 128 // enough to uniquely identify the package and that we don't need to delve |
| 129 // into the description. | 129 // into the description. |
| 130 return other.name == name && | 130 return other.name == name && |
| 131 other.source.name == source.name && | 131 other.source.name == source.name && |
| 132 other.version == version; | 132 other.version == version; |
| 133 } | 133 } |
| 134 | 134 |
| 135 String toString() => "$name $version from ${source.name}"; | 135 String toString() => "$name $version from ${source.name}"; |
| 136 | 136 |
| 137 int compareTo(Comparable other) { | 137 int compareTo(Comparable other) { |
| 138 if (other is! PackageId) throw new IllegalArgumentException(other); | 138 if (other is! PackageId) throw new IllegalArgumentException(other); |
| 139 | 139 |
| 140 var sourceComp = source.name.compareTo(other.source.name); | 140 var sourceComp = source.name.compareTo(other.source.name); |
| 141 if (sourceComp != 0) return sourceComp; | 141 if (sourceComp != 0) return sourceComp; |
| 142 | 142 |
| 143 var nameComp = name.compareTo(other.name); | 143 var nameComp = name.compareTo(other.name); |
| 144 if (nameComp != 0) return nameComp; | 144 if (nameComp != 0) return nameComp; |
| 145 | 145 |
| 146 return version.compareTo(other.version); | 146 return version.compareTo(other.version); |
| 147 } | 147 } |
| 148 | |
| 149 /** | |
| 150 * Returns the pubspec for this package. | |
| 151 */ | |
| 152 Future<Pubspec> describe() => source.describe(this); | |
| 148 } | 153 } |
| 149 | 154 |
| 150 /** | 155 /** |
| 151 * A reference to a package. Unlike a [PackageId], a PackageRef may not | 156 * A reference to a package. Unlike a [PackageId], a PackageRef may not |
| 152 * unambiguously refer to a single package. It may describe a range of allowed | 157 * unambiguously refer to a single package. It may describe a range of allowed |
| 153 * packages. | 158 * packages. |
| 154 */ | 159 */ |
| 155 class PackageRef { | 160 class PackageRef { |
| 156 /** | 161 /** |
| 157 * The name of the package being referenced. | |
| 158 */ | |
| 159 final String name; | |
| 160 | |
| 161 /** | |
| 162 * The [Source] used to look up the package. | 162 * The [Source] used to look up the package. |
| 163 */ | 163 */ |
| 164 final Source source; | 164 final Source source; |
| 165 | 165 |
| 166 /** | 166 /** |
| 167 * The allowed package versions. | 167 * The allowed package versions. |
| 168 */ | 168 */ |
| 169 final VersionConstraint constraint; | 169 final VersionConstraint constraint; |
| 170 | 170 |
| 171 /** | 171 /** |
| 172 * The metadata used to identify the package being referenced. The | 172 * The metadata used to identify the package being referenced. The |
| 173 * interpretation of this will vary based on the [source]. | 173 * interpretation of this will vary based on the [source]. |
| 174 */ | 174 */ |
| 175 final description; | 175 final description; |
| 176 | 176 |
| 177 PackageRef(this.name, this.source, this.constraint, this.description); | 177 /** |
| 178 * The name of the package being referenced. | |
| 179 */ | |
| 180 String get name() => source.packageName(description); | |
| 181 | |
| 182 PackageRef(this.source, this.constraint, this.description); | |
| 178 | 183 |
| 179 String toString() => "$name $constraint from $source ($description)"; | 184 String toString() => "$name $constraint from $source ($description)"; |
| 185 | |
| 186 /** | |
| 187 * Returns a [PackageId] generated from this [PackageRef] with the given | |
| 188 * concrete version. | |
| 189 */ | |
| 190 PackageId withVersion(Version version) => | |
|
Bob Nystrom
2012/06/29 17:24:40
"with" is a bit confusing here. Maybe "atVersion"
nweiz
2012/06/29 18:45:08
Done.
| |
| 191 new PackageId(source, version, description); | |
| 180 } | 192 } |
| OLD | NEW |