| 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('source_registry'); | 5 #library('source_registry'); |
| 6 | 6 |
| 7 #import('source.dart'); | 7 #import('source.dart'); |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * A class that keeps track of [Source]s used for installing packages. | 10 * A class that keeps track of [Source]s used for installing packages. |
| 11 */ | 11 */ |
| 12 class SourceRegistry { | 12 class SourceRegistry { |
| 13 final Map<String, Source> _map; | 13 final Map<String, Source> _map; |
| 14 Source _default; | 14 Source _default; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * Creates a new registry with no packages registered. | 17 * Creates a new registry with no packages registered. |
| 18 */ | 18 */ |
| 19 SourceRegistry() : _map = <String, Source>{}; | 19 SourceRegistry() : _map = <String, Source>{}; |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * Returns the default source, which is used when no source is specified. | 22 * Returns the default source, which is used when no source is specified. |
| 23 */ | 23 */ |
| 24 Source get defaultSource() => _default; | 24 Source get defaultSource => _default; |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * Sets the default source. This takes a string, which must be the name of a | 27 * Sets the default source. This takes a string, which must be the name of a |
| 28 * registered source. | 28 * registered source. |
| 29 */ | 29 */ |
| 30 void setDefault(String name) { | 30 void setDefault(String name) { |
| 31 if (!_map.containsKey(name)) { | 31 if (!_map.containsKey(name)) { |
| 32 // TODO(nweiz): Real error-handling system | 32 // TODO(nweiz): Real error-handling system |
| 33 throw 'Default source $name is not in the registry'; | 33 throw 'Default source $name is not in the registry'; |
| 34 } | 34 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 61 Source operator[](String name) { | 61 Source operator[](String name) { |
| 62 if (name == null) { | 62 if (name == null) { |
| 63 if (defaultSource != null) return defaultSource; | 63 if (defaultSource != null) return defaultSource; |
| 64 // TODO(nweiz): Real error-handling system | 64 // TODO(nweiz): Real error-handling system |
| 65 throw 'No default source has been registered'; | 65 throw 'No default source has been registered'; |
| 66 } | 66 } |
| 67 if (_map.containsKey(name)) return _map[name]; | 67 if (_map.containsKey(name)) return _map[name]; |
| 68 throw 'No source named $name is registered'; | 68 throw 'No source named $name is registered'; |
| 69 } | 69 } |
| 70 } | 70 } |
| OLD | NEW |