Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: utils/pub/package.dart

Issue 12047096: Get rid of RootSource. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/pub/entrypoint.dart ('k') | utils/pub/root_source.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import 'io.dart'; 8 import 'io.dart';
9 import 'pubspec.dart'; 9 import 'pubspec.dart';
10 import 'source.dart'; 10 import 'source.dart';
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 /// information to correctly install the package. 75 /// information to correctly install the package.
76 /// 76 ///
77 /// Note that it's possible for multiple distinct package IDs to point to 77 /// Note that it's possible for multiple distinct package IDs to point to
78 /// different directories that happen to contain identical packages. For 78 /// different directories that happen to contain identical packages. For
79 /// example, the same package may be available from multiple sources. As far as 79 /// example, the same package may be available from multiple sources. As far as
80 /// Pub is concerned, those packages are different. 80 /// Pub is concerned, those packages are different.
81 class PackageId implements Comparable { 81 class PackageId implements Comparable {
82 /// The name of the package being identified. 82 /// The name of the package being identified.
83 final String name; 83 final String name;
84 84
85 /// The [Source] used to look up this package given its [description]. 85 /// The [Source] used to look up this package given its [description]. If
86 /// this is a root package ID, this will be `null`.
Jennifer Messerly 2013/01/24 23:24:37 fwiw, I think Kathy suggested not using code font
Bob Nystrom 2013/01/25 18:22:50 I think you're remembering right, though I persona
86 final Source source; 87 final Source source;
87 88
88 /// The package's version. 89 /// The package's version.
89 final Version version; 90 final Version version;
90 91
91 /// The metadata used by the package's [source] to identify and locate it. It 92 /// The metadata used by the package's [source] to identify and locate it. It
92 /// contains whatever [Source]-specific data it needs to be able to install 93 /// contains whatever [Source]-specific data it needs to be able to install
93 /// the package. For example, the description of a git sourced package might 94 /// the package. For example, the description of a git sourced package might
94 /// by the URL "git://github.com/dart/uilib.git". 95 /// by the URL "git://github.com/dart/uilib.git".
95 final description; 96 final description;
96 97
97 PackageId(this.name, this.source, this.version, this.description); 98 PackageId(this.name, this.source, this.version, this.description);
98 99
100 /// Whether this ID identifies the root package.
101 bool get isRoot => source == null;
102
99 int get hashCode => name.hashCode ^ 103 int get hashCode => name.hashCode ^
100 source.name.hashCode ^ 104 (source != null ? source.name.hashCode : 0) ^
Jennifer Messerly 2013/01/24 23:24:37 Another idea here: you could make Source.hashCode
Bob Nystrom 2013/01/25 18:22:50 Great idea! Done.
101 version.hashCode; 105 version.hashCode;
102 106
103 bool operator ==(other) { 107 bool operator ==(other) {
104 if (other is! PackageId) return false; 108 if (other is! PackageId) return false;
105 // TODO(rnystrom): We're assuming here the name/version/source tuple is 109 // TODO(rnystrom): We're assuming here the name/version/source tuple is
106 // enough to uniquely identify the package and that we don't need to delve 110 // enough to uniquely identify the package and that we don't need to delve
107 // into the description. 111 // into the description.
108 return other.name == name && 112 return other.name == name &&
109 other.source.name == source.name && 113 other.source == source &&
Jennifer Messerly 2013/01/24 23:24:37 just checking, source already implements reasonabl
Bob Nystrom 2013/01/25 18:22:50 I'm relying on identity here. Sources are effectiv
110 other.version == version; 114 other.version == version;
111 } 115 }
112 116
113 String toString() { 117 String toString() {
118 if (isRoot) return "$name $version (root)";
114 if (source.isDefault) return "$name $version"; 119 if (source.isDefault) return "$name $version";
115 return "$name $version from $source"; 120 return "$name $version from $source";
116 } 121 }
117 122
118 int compareTo(Comparable other) { 123 int compareTo(Comparable other) {
119 if (other is! PackageId) throw new ArgumentError(other); 124 if (other is! PackageId) throw new ArgumentError(other);
120 125
121 var sourceComp = source.name.compareTo(other.source.name); 126 var sourceComp = source.name.compareTo(other.source.name);
122 if (sourceComp != 0) return sourceComp; 127 if (sourceComp != 0) return sourceComp;
123 128
(...skipping 10 matching lines...) Expand all
134 Future<PackageId> get resolved => source.resolveId(this); 139 Future<PackageId> get resolved => source.resolveId(this);
135 } 140 }
136 141
137 /// A reference to a package. Unlike a [PackageId], a PackageRef may not 142 /// A reference to a package. Unlike a [PackageId], a PackageRef may not
138 /// unambiguously refer to a single package. It may describe a range of allowed 143 /// unambiguously refer to a single package. It may describe a range of allowed
139 /// packages. 144 /// packages.
140 class PackageRef { 145 class PackageRef {
141 /// The name of the package being identified. 146 /// The name of the package being identified.
142 final String name; 147 final String name;
143 148
144 /// The [Source] used to look up the package. 149 /// The [Source] used to look up the package. If this refers to a root
150 /// package, this will be `null`.
145 final Source source; 151 final Source source;
146 152
147 /// The allowed package versions. 153 /// The allowed package versions.
148 final VersionConstraint constraint; 154 final VersionConstraint constraint;
149 155
150 /// The metadata used to identify the package being referenced. The 156 /// The metadata used to identify the package being referenced. The
151 /// interpretation of this will vary based on the [source]. 157 /// interpretation of this will vary based on the [source].
152 final description; 158 final description;
153 159
154 PackageRef(this.name, this.source, this.constraint, this.description); 160 PackageRef(this.name, this.source, this.constraint, this.description);
155 161
156 String toString() => "$name $constraint from $source ($description)"; 162 /// Creates a reference to the given root package.
163 PackageRef.root(Package package)
164 : name = package.name,
165 source = null,
166 constraint = package.version,
167 description = package.name;
168
169 /// Whether this refers to the root package.
170 bool get isRoot => source == null;
171
172 String toString() {
173 if (isRoot) return "$name $constraint (root)";
174 return "$name $constraint from $source ($description)";
175 }
157 176
158 /// Returns a [PackageId] generated from this [PackageRef] with the given 177 /// Returns a [PackageId] generated from this [PackageRef] with the given
159 /// concrete version. 178 /// concrete version.
160 PackageId atVersion(Version version) => 179 PackageId atVersion(Version version) =>
161 new PackageId(name, source, version, description); 180 new PackageId(name, source, version, description);
162 } 181 }
163 182
164 class PubspecNotFoundException implements Exception { 183 class PubspecNotFoundException implements Exception {
165 final String name; 184 final String name;
166 185
(...skipping 13 matching lines...) Expand all
180 199
181 class PubspecNameMismatchException implements Exception { 200 class PubspecNameMismatchException implements Exception {
182 final String expectedName; 201 final String expectedName;
183 final String actualName; 202 final String actualName;
184 203
185 PubspecNameMismatchException(this.expectedName, this.actualName); 204 PubspecNameMismatchException(this.expectedName, this.actualName);
186 205
187 String toString() => 'The name you specified for your dependency, ' 206 String toString() => 'The name you specified for your dependency, '
188 '"$expectedName", doesn\'t match the name "$actualName" in its pubspec.'; 207 '"$expectedName", doesn\'t match the name "$actualName" in its pubspec.';
189 } 208 }
OLDNEW
« no previous file with comments | « utils/pub/entrypoint.dart ('k') | utils/pub/root_source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698