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

Side by Side Diff: lib/src/source_registry.dart

Issue 2079303003: Track Source objects in PackageNames. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Code review changes Created 4 years, 5 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
« no previous file with comments | « lib/src/source/unknown.dart ('k') | lib/src/system_cache.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 import 'package.dart';
6 import 'source.dart'; 5 import 'source.dart';
7 import 'source/git.dart'; 6 import 'source/git.dart';
8 import 'source/hosted.dart'; 7 import 'source/hosted.dart';
9 import 'source/path.dart'; 8 import 'source/path.dart';
10 import 'source/unknown.dart'; 9 import 'source/unknown.dart';
11 10
12 /// A class that keeps track of [Source]s used for getting packages. 11 /// A class that keeps track of [Source]s used for getting packages.
13 class SourceRegistry { 12 class SourceRegistry {
14 /// The registered sources. 13 /// The registered sources.
15 /// 14 ///
(...skipping 23 matching lines...) Expand all
39 /// The built-in [HostedSource]. 38 /// The built-in [HostedSource].
40 HostedSource get hosted => _sources["hosted"] as HostedSource; 39 HostedSource get hosted => _sources["hosted"] as HostedSource;
41 40
42 /// The built-in [PathSource]. 41 /// The built-in [PathSource].
43 PathSource get path => _sources["path"] as PathSource; 42 PathSource get path => _sources["path"] as PathSource;
44 43
45 SourceRegistry() { 44 SourceRegistry() {
46 _default = hosted; 45 _default = hosted;
47 } 46 }
48 47
49 /// Returns whether [id1] and [id2] refer to the same package, including
50 /// validating that their descriptions are equivalent.
51 bool idsEqual(PackageId id1, PackageId id2) {
52 if (id1 != id2) return false;
53 if (id1 == null && id2 == null) return true;
54 return idDescriptionsEqual(id1, id2);
55 }
56
57 /// Returns whether [id1] and [id2] have the same source and description.
58 ///
59 /// This doesn't check whether the name or versions are equal.
60 bool idDescriptionsEqual(PackageId id1, PackageId id2) {
61 if (id1.source != id2.source) return false;
62 return this[id1.source].descriptionsEqual(id1.description, id2.description);
63 }
64
65 /// Sets the default source. 48 /// Sets the default source.
66 /// 49 ///
67 /// This takes a string, which must be the name of a registered source. 50 /// This takes a string, which must be the name of a registered source.
68 void setDefault(String name) { 51 void setDefault(String name) {
69 if (!_sources.containsKey(name)) { 52 if (!_sources.containsKey(name)) {
70 throw new StateError('Default source $name is not in the registry'); 53 throw new StateError('Default source $name is not in the registry');
71 } 54 }
72 55
73 _default = _sources[name]; 56 _default = _sources[name];
74 } 57 }
(...skipping 14 matching lines...) Expand all
89 /// Returns the source named [name]. 72 /// Returns the source named [name].
90 /// 73 ///
91 /// Returns an [UnknownSource] if no source with that name has been 74 /// Returns an [UnknownSource] if no source with that name has been
92 /// registered. If [name] is null, returns the default source. 75 /// registered. If [name] is null, returns the default source.
93 Source operator[](String name) { 76 Source operator[](String name) {
94 if (name == null) return _default; 77 if (name == null) return _default;
95 if (_sources.containsKey(name)) return _sources[name]; 78 if (_sources.containsKey(name)) return _sources[name];
96 return new UnknownSource(name); 79 return new UnknownSource(name);
97 } 80 }
98 } 81 }
OLDNEW
« no previous file with comments | « lib/src/source/unknown.dart ('k') | lib/src/system_cache.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698