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