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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:io' as io; | 6 import 'dart:io' as io; |
7 import "dart:convert"; | 7 import "dart:convert"; |
8 | 8 |
9 import 'package:http/http.dart' as http; | 9 import 'package:http/http.dart' as http; |
10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
(...skipping 27 matching lines...) Expand all Loading... |
38 if (url != null) return url; | 38 if (url != null) return url; |
39 | 39 |
40 return "https://pub.dartlang.org"; | 40 return "https://pub.dartlang.org"; |
41 } | 41 } |
42 | 42 |
43 /// Returns a reference to a hosted package named [name]. | 43 /// Returns a reference to a hosted package named [name]. |
44 /// | 44 /// |
45 /// If [url] is passed, it's the URL of the pub server from which the package | 45 /// If [url] is passed, it's the URL of the pub server from which the package |
46 /// should be downloaded. It can be a [Uri] or a [String]. | 46 /// should be downloaded. It can be a [Uri] or a [String]. |
47 PackageRef refFor(String name, {url}) => | 47 PackageRef refFor(String name, {url}) => |
48 new PackageRef(name, 'hosted', _descriptionFor(name, url)); | 48 new PackageRef(name, this, _descriptionFor(name, url)); |
49 | 49 |
50 /// Returns an ID for a hosted package named [name] at [version]. | 50 /// Returns an ID for a hosted package named [name] at [version]. |
51 /// | 51 /// |
52 /// If [url] is passed, it's the URL of the pub server from which the package | 52 /// If [url] is passed, it's the URL of the pub server from which the package |
53 /// should be downloaded. It can be a [Uri] or a [String]. | 53 /// should be downloaded. It can be a [Uri] or a [String]. |
54 PackageId idFor(String name, Version version, {url}) => | 54 PackageId idFor(String name, Version version, {url}) => |
55 new PackageId(name, 'hosted', version, _descriptionFor(name, url)); | 55 new PackageId(name, this, version, _descriptionFor(name, url)); |
56 | 56 |
57 /// Returns the description for a hosted package named [name] with the | 57 /// Returns the description for a hosted package named [name] with the |
58 /// given package server [url]. | 58 /// given package server [url]. |
59 _descriptionFor(String name, [url]) { | 59 _descriptionFor(String name, [url]) { |
60 if (url == null) return name; | 60 if (url == null) return name; |
61 | 61 |
62 if (url is! String && url is! Uri) { | 62 if (url is! String && url is! Uri) { |
63 throw new ArgumentError.value(url, 'url', 'must be a Uri or a String.'); | 63 throw new ArgumentError.value(url, 'url', 'must be a Uri or a String.'); |
64 } | 64 } |
65 | 65 |
66 return {'name': name, 'url': url.toString()}; | 66 return {'name': name, 'url': url.toString()}; |
67 } | 67 } |
68 | 68 |
69 bool descriptionsEqual(description1, description2) => | 69 bool descriptionsEqual(description1, description2) => |
70 _parseDescription(description1) == _parseDescription(description2); | 70 _parseDescription(description1) == _parseDescription(description2); |
71 | 71 |
| 72 int hashDescription(description) => _parseDescription.hashCode; |
| 73 |
72 /// Ensures that [description] is a valid hosted package description. | 74 /// Ensures that [description] is a valid hosted package description. |
73 /// | 75 /// |
74 /// There are two valid formats. A plain string refers to a package with the | 76 /// There are two valid formats. A plain string refers to a package with the |
75 /// given name from the default host, while a map with keys "name" and "url" | 77 /// given name from the default host, while a map with keys "name" and "url" |
76 /// refers to a package with the given name from the host at the given URL. | 78 /// refers to a package with the given name from the host at the given URL. |
77 PackageRef parseRef(String name, description, {String containingPath}) { | 79 PackageRef parseRef(String name, description, {String containingPath}) { |
78 _parseDescription(description); | 80 _parseDescription(description); |
79 return new PackageRef(name, this.name, description); | 81 return new PackageRef(name, this, description); |
80 } | 82 } |
81 | 83 |
82 PackageId parseId(String name, Version version, description) { | 84 PackageId parseId(String name, Version version, description) { |
83 _parseDescription(description); | 85 _parseDescription(description); |
84 return new PackageId(name, this.name, version, description); | 86 return new PackageId(name, this, version, description); |
85 } | 87 } |
86 | 88 |
87 /// Parses the description for a package. | 89 /// Parses the description for a package. |
88 /// | 90 /// |
89 /// If the package parses correctly, this returns a (name, url) pair. If not, | 91 /// If the package parses correctly, this returns a (name, url) pair. If not, |
90 /// this throws a descriptive FormatException. | 92 /// this throws a descriptive FormatException. |
91 Pair<String, String> _parseDescription(description) { | 93 Pair<String, String> _parseDescription(description) { |
92 if (description is String) { | 94 if (description is String) { |
93 return new Pair<String, String>(description, defaultUrl); | 95 return new Pair<String, String>(description, defaultUrl); |
94 } | 96 } |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 // Since HostedSource is cached, this will only be called for uncached | 419 // Since HostedSource is cached, this will only be called for uncached |
418 // packages. | 420 // packages. |
419 throw new UnsupportedError("Cannot download packages when offline."); | 421 throw new UnsupportedError("Cannot download packages when offline."); |
420 } | 422 } |
421 | 423 |
422 Future<Pubspec> describeUncached(PackageId id) { | 424 Future<Pubspec> describeUncached(PackageId id) { |
423 throw new PackageNotFoundException( | 425 throw new PackageNotFoundException( |
424 "${id.name} ${id.version} is not available in your system cache."); | 426 "${id.name} ${id.version} is not available in your system cache."); |
425 } | 427 } |
426 } | 428 } |
OLD | NEW |