OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:pub_semver/pub_semver.dart'; | 7 import 'package:pub_semver/pub_semver.dart'; |
8 | 8 |
9 import '../package.dart'; | 9 import '../package.dart'; |
10 import '../pubspec.dart'; | 10 import '../pubspec.dart'; |
11 import '../source.dart'; | 11 import '../source.dart'; |
| 12 import '../system_cache.dart'; |
12 | 13 |
13 /// A [Null Object] that represents a source not recognized by pub. | 14 /// A [Null Object] that represents a source not recognized by pub. |
14 /// | 15 /// |
15 /// It provides some default behavior so that pub can work with sources it | 16 /// It provides some default behavior so that pub can work with sources it |
16 /// doesn't recognize. | 17 /// doesn't recognize. |
17 /// | 18 /// |
18 /// [null object]: http://en.wikipedia.org/wiki/Null_Object_pattern | 19 /// [null object]: http://en.wikipedia.org/wiki/Null_Object_pattern |
19 class UnknownSource extends Source { | 20 class UnknownSource extends Source { |
20 final String name; | 21 final String name; |
21 | 22 |
22 UnknownSource(this.name); | 23 UnknownSource(this.name); |
23 | 24 |
| 25 BoundSource bind(SystemCache systemCache) => |
| 26 new _BoundUnknownSource(this, systemCache); |
| 27 |
24 /// Two unknown sources are the same if their names are the same. | 28 /// Two unknown sources are the same if their names are the same. |
25 bool operator==(other) => | 29 bool operator==(other) => |
26 other is UnknownSource && | 30 other is UnknownSource && |
27 other.name == name; | 31 other.name == name; |
28 | 32 |
29 int get hashCode => name.hashCode; | 33 int get hashCode => name.hashCode; |
30 | 34 |
31 Future<List<PackageId>> doGetVersions(PackageRef ref) => | |
32 throw new UnsupportedError( | |
33 "Cannot get package versions from unknown source '$name'."); | |
34 | |
35 Future<Pubspec> doDescribe(PackageId id) => throw new UnsupportedError( | |
36 "Cannot describe a package from unknown source '$name'."); | |
37 | |
38 Future get(PackageId id, String symlink) => throw new UnsupportedError( | |
39 "Cannot get an unknown source '$name'."); | |
40 | |
41 /// Returns the directory where this package can be found locally. | |
42 String getDirectory(PackageId id) => throw new UnsupportedError( | |
43 "Cannot find a package from an unknown source '$name'."); | |
44 | |
45 bool descriptionsEqual(description1, description2) => | 35 bool descriptionsEqual(description1, description2) => |
46 description1 == description2; | 36 description1 == description2; |
47 | 37 |
48 PackageRef parseRef(String name, description, {String containingPath}) => | 38 PackageRef parseRef(String name, description, {String containingPath}) => |
49 new PackageRef(name, this.name, description); | 39 new PackageRef(name, this.name, description); |
50 | 40 |
51 PackageId parseId(String name, Version version, description) => | 41 PackageId parseId(String name, Version version, description) => |
52 new PackageId(name, this.name, version, description); | 42 new PackageId(name, this.name, version, description); |
53 } | 43 } |
| 44 |
| 45 class _BoundUnknownSource extends BoundSource { |
| 46 final UnknownSource source; |
| 47 |
| 48 final SystemCache systemCache; |
| 49 |
| 50 _BoundUnknownSource(this.source, this.systemCache); |
| 51 |
| 52 Future<List<PackageId>> doGetVersions(PackageRef ref) => |
| 53 throw new UnsupportedError( |
| 54 "Cannot get package versions from unknown source '${source.name}'."); |
| 55 |
| 56 Future<Pubspec> doDescribe(PackageId id) => throw new UnsupportedError( |
| 57 "Cannot describe a package from unknown source '${source.name}'."); |
| 58 |
| 59 Future get(PackageId id, String symlink) => throw new UnsupportedError( |
| 60 "Cannot get an unknown source '${source.name}'."); |
| 61 |
| 62 /// Returns the directory where this package can be found locally. |
| 63 String getDirectory(PackageId id) => throw new UnsupportedError( |
| 64 "Cannot find a package from an unknown source '${source.name}'."); |
| 65 } |
OLD | NEW |