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

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

Issue 1534093002: Improve the detection lockfile freshness. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Created 5 years 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
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 pub.source_registry; 5 library pub.source_registry;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package.dart'; 9 import 'package.dart';
10 import 'source.dart'; 10 import 'source.dart';
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 /// registered. 58 /// registered.
59 void register(Source source) { 59 void register(Source source) {
60 if (_sources.containsKey(source.name)) { 60 if (_sources.containsKey(source.name)) {
61 throw new StateError('Source registry already has a source named ' 61 throw new StateError('Source registry already has a source named '
62 '${source.name}'); 62 '${source.name}');
63 } 63 }
64 64
65 _sources[source.name] = source; 65 _sources[source.name] = source;
66 } 66 }
67 67
68 /// Loads the package identified by [id].
69 ///
70 /// Throws an [ArgumentError] if [id] has an invalid source.
71 Package load(PackageId id) {
72 var source = this[id.source];
73 if (source == null) throw new ArgumentError("Unknown source ${id.source}.");
74
75 var dir = source.getDirectory(id);
76 return new Package.load(id.name, dir, this);
77 }
78
68 /// Returns the source named [name]. 79 /// Returns the source named [name].
69 /// 80 ///
70 /// Returns an [UnknownSource] if no source with that name has been 81 /// Returns an [UnknownSource] if no source with that name has been
71 /// registered. If [name] is null, returns the default source. 82 /// registered. If [name] is null, returns the default source.
72 Source operator[](String name) { 83 Source operator[](String name) {
73 if (name == null) { 84 if (name == null) {
74 if (defaultSource != null) return defaultSource; 85 if (defaultSource != null) return defaultSource;
75 throw new StateError('No default source has been registered'); 86 throw new StateError('No default source has been registered');
76 } 87 }
77 88
78 if (_sources.containsKey(name)) return _sources[name]; 89 if (_sources.containsKey(name)) return _sources[name];
79 return new UnknownSource(name); 90 return new UnknownSource(name);
80 } 91 }
81 } 92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698