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 import 'source.dart'; | 5 import 'source.dart'; |
6 import 'source/git.dart'; | 6 import 'source/git.dart'; |
7 import 'source/hosted.dart'; | 7 import 'source/hosted.dart'; |
8 import 'source/path.dart'; | 8 import 'source/path.dart'; |
| 9 import 'source/sdk.dart'; |
9 import 'source/unknown.dart'; | 10 import 'source/unknown.dart'; |
10 | 11 |
11 /// A class that keeps track of [Source]s used for getting packages. | 12 /// A class that keeps track of [Source]s used for getting packages. |
12 class SourceRegistry { | 13 class SourceRegistry { |
13 /// The registered sources. | 14 /// The registered sources. |
14 /// | 15 /// |
15 /// This is initialized with the three built-in sources. | 16 /// This is initialized with the three built-in sources. |
16 final _sources = { | 17 final _sources = { |
17 "git": new GitSource(), | 18 "git": new GitSource(), |
18 "hosted": new HostedSource(), | 19 "hosted": new HostedSource(), |
19 "path": new PathSource() | 20 "path": new PathSource(), |
| 21 "sdk": new SdkSource() |
20 }; | 22 }; |
21 | 23 |
22 /// The default source, which is used when no source is specified. | 24 /// The default source, which is used when no source is specified. |
23 /// | 25 /// |
24 /// This defaults to [hosted]. | 26 /// This defaults to [hosted]. |
25 Source get defaultSource => _default; | 27 Source get defaultSource => _default; |
26 Source _default; | 28 Source _default; |
27 | 29 |
28 /// The registered sources, in name order. | 30 /// The registered sources, in name order. |
29 List<Source> get all { | 31 List<Source> get all { |
30 var sources = _sources.values.toList(); | 32 var sources = _sources.values.toList(); |
31 sources.sort((a, b) => a.name.compareTo(b.name)); | 33 sources.sort((a, b) => a.name.compareTo(b.name)); |
32 return sources; | 34 return sources; |
33 } | 35 } |
34 | 36 |
35 /// The built-in [GitSource]. | 37 /// The built-in [GitSource]. |
36 GitSource get git => _sources["git"] as GitSource; | 38 GitSource get git => _sources["git"] as GitSource; |
37 | 39 |
38 /// The built-in [HostedSource]. | 40 /// The built-in [HostedSource]. |
39 HostedSource get hosted => _sources["hosted"] as HostedSource; | 41 HostedSource get hosted => _sources["hosted"] as HostedSource; |
40 | 42 |
41 /// The built-in [PathSource]. | 43 /// The built-in [PathSource]. |
42 PathSource get path => _sources["path"] as PathSource; | 44 PathSource get path => _sources["path"] as PathSource; |
43 | 45 |
| 46 /// The built-in [SdkSource]. |
| 47 SdkSource get sdk => _sources["sdk"] as SdkSource; |
| 48 |
44 SourceRegistry() { | 49 SourceRegistry() { |
45 _default = hosted; | 50 _default = hosted; |
46 } | 51 } |
47 | 52 |
48 /// Sets the default source. | 53 /// Sets the default source. |
49 /// | 54 /// |
50 /// This takes a string, which must be the name of a registered source. | 55 /// This takes a string, which must be the name of a registered source. |
51 void setDefault(String name) { | 56 void setDefault(String name) { |
52 if (!_sources.containsKey(name)) { | 57 if (!_sources.containsKey(name)) { |
53 throw new StateError('Default source $name is not in the registry'); | 58 throw new StateError('Default source $name is not in the registry'); |
(...skipping 18 matching lines...) Expand all Loading... |
72 /// Returns the source named [name]. | 77 /// Returns the source named [name]. |
73 /// | 78 /// |
74 /// Returns an [UnknownSource] if no source with that name has been | 79 /// Returns an [UnknownSource] if no source with that name has been |
75 /// registered. If [name] is null, returns the default source. | 80 /// registered. If [name] is null, returns the default source. |
76 Source operator[](String name) { | 81 Source operator[](String name) { |
77 if (name == null) return _default; | 82 if (name == null) return _default; |
78 if (_sources.containsKey(name)) return _sources[name]; | 83 if (_sources.containsKey(name)) return _sources[name]; |
79 return new UnknownSource(name); | 84 return new UnknownSource(name); |
80 } | 85 } |
81 } | 86 } |
OLD | NEW |