OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Implementations of [Packages] that may be used in either server or browser | 5 /// Implementations of [Packages] that may be used in either server or browser |
6 /// based applications. For implementations that can only run in the browser, | 6 /// based applications. For implementations that can only run in the browser, |
7 /// see [package_config.packages_io_impl]. | 7 /// see [package_config.packages_io_impl]. |
8 library package_config.packages_impl; | 8 library package_config.packages_impl; |
9 | 9 |
10 import "dart:collection" show UnmodifiableMapView; | 10 import "dart:collection" show UnmodifiableMapView; |
11 import "../packages.dart"; | 11 import "../packages.dart"; |
12 import "util.dart" show checkValidPackageUri; | 12 import "util.dart" show checkValidPackageUri; |
13 | 13 |
14 /// A [Packages] null-object. | 14 /// A [Packages] null-object. |
15 class NoPackages implements Packages { | 15 class NoPackages implements Packages { |
16 const NoPackages(); | 16 const NoPackages(); |
17 | 17 |
18 Uri resolve(Uri packageUri, {Uri notFound(Uri packageUri)}) { | 18 Uri resolve(Uri packageUri, {Uri notFound(Uri packageUri)}) { |
19 String packageName = checkValidPackageUri(packageUri); | 19 String packageName = checkValidPackageUri(packageUri); |
20 if (notFound != null) return notFound(packageUri); | 20 if (notFound != null) return notFound(packageUri); |
21 throw new ArgumentError.value(packageUri, "packageUri", | 21 throw new ArgumentError.value( |
22 'No package named "$packageName"'); | 22 packageUri, "packageUri", 'No package named "$packageName"'); |
23 } | 23 } |
24 | 24 |
25 Iterable<String> get packages => new Iterable<String>.generate(0); | 25 Iterable<String> get packages => new Iterable<String>.generate(0); |
26 | 26 |
27 Map<String, Uri> asMap() => const<String,Uri>{}; | 27 Map<String, Uri> asMap() => const <String, Uri>{}; |
28 } | 28 } |
29 | 29 |
30 /// Base class for [Packages] implementations. | 30 /// Base class for [Packages] implementations. |
31 /// | 31 /// |
32 /// This class implements the [resolve] method in terms of a private | 32 /// This class implements the [resolve] method in terms of a private |
33 /// member | 33 /// member |
34 abstract class PackagesBase implements Packages { | 34 abstract class PackagesBase implements Packages { |
35 Uri resolve(Uri packageUri, {Uri notFound(Uri packageUri)}) { | 35 Uri resolve(Uri packageUri, {Uri notFound(Uri packageUri)}) { |
36 packageUri = _normalizePath(packageUri); | 36 packageUri = _normalizePath(packageUri); |
37 String packageName = checkValidPackageUri(packageUri); | 37 String packageName = checkValidPackageUri(packageUri); |
38 Uri packageBase = getBase(packageName); | 38 Uri packageBase = getBase(packageName); |
39 if (packageBase == null) { | 39 if (packageBase == null) { |
40 if (notFound != null) return notFound(packageUri); | 40 if (notFound != null) return notFound(packageUri); |
41 throw new ArgumentError.value(packageUri, "packageUri", | 41 throw new ArgumentError.value( |
42 'No package named "$packageName"'); | 42 packageUri, "packageUri", 'No package named "$packageName"'); |
43 } | 43 } |
44 String packagePath = packageUri.path.substring(packageName.length + 1); | 44 String packagePath = packageUri.path.substring(packageName.length + 1); |
45 return packageBase.resolve(packagePath); | 45 return packageBase.resolve(packagePath); |
46 } | 46 } |
47 | 47 |
48 /// Find a base location for a package name. | 48 /// Find a base location for a package name. |
49 /// | 49 /// |
50 /// Returns `null` if no package exists with that name, and that can be | 50 /// Returns `null` if no package exists with that name, and that can be |
51 /// determined. | 51 /// determined. |
52 Uri getBase(String packageName); | 52 Uri getBase(String packageName); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 85 } |
86 | 86 |
87 Iterable<String> get packages { | 87 Iterable<String> get packages { |
88 throw _failListingPackages(); | 88 throw _failListingPackages(); |
89 } | 89 } |
90 | 90 |
91 Map<String, Uri> asMap() { | 91 Map<String, Uri> asMap() { |
92 throw _failListingPackages(); | 92 throw _failListingPackages(); |
93 } | 93 } |
94 } | 94 } |
OLD | NEW |