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 path; | 10 import 'package:path/path.dart' as path; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } catch (error, stackTrace) { | 73 } catch (error, stackTrace) { |
74 var parsed = _parseDescription(ref.description); | 74 var parsed = _parseDescription(ref.description); |
75 _throwFriendlyError(error, stackTrace, parsed.first, parsed.last); | 75 _throwFriendlyError(error, stackTrace, parsed.first, parsed.last); |
76 } | 76 } |
77 | 77 |
78 var doc = JSON.decode(body); | 78 var doc = JSON.decode(body); |
79 return doc['versions'].map((map) { | 79 return doc['versions'].map((map) { |
80 var pubspec = new Pubspec.fromMap( | 80 var pubspec = new Pubspec.fromMap( |
81 map['pubspec'], systemCache.sources, | 81 map['pubspec'], systemCache.sources, |
82 expectedName: ref.name, location: url); | 82 expectedName: ref.name, location: url); |
83 var id = idFor(ref.name, pubspec.version); | 83 var id = idFor(ref.name, pubspec.version, |
| 84 url: _serverFor(ref.description)); |
84 memoizePubspec(id, pubspec); | 85 memoizePubspec(id, pubspec); |
85 | 86 |
86 return id; | 87 return id; |
87 }).toList(); | 88 }).toList(); |
88 } | 89 } |
89 | 90 |
90 /// Downloads and parses the pubspec for a specific version of a package that | 91 /// Downloads and parses the pubspec for a specific version of a package that |
91 /// is available from the site. | 92 /// is available from the site. |
92 Future<Pubspec> describeUncached(PackageId id) async { | 93 Future<Pubspec> describeUncached(PackageId id) async { |
93 // Request it from the server. | 94 // Request it from the server. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 160 |
160 var successes = []; | 161 var successes = []; |
161 var failures = []; | 162 var failures = []; |
162 | 163 |
163 for (var serverDir in listDir(systemCacheRoot)) { | 164 for (var serverDir in listDir(systemCacheRoot)) { |
164 var url = _directoryToUrl(path.basename(serverDir)); | 165 var url = _directoryToUrl(path.basename(serverDir)); |
165 var packages = _getCachedPackagesInDirectory(path.basename(serverDir)); | 166 var packages = _getCachedPackagesInDirectory(path.basename(serverDir)); |
166 packages.sort(Package.orderByNameAndVersion); | 167 packages.sort(Package.orderByNameAndVersion); |
167 | 168 |
168 for (var package in packages) { | 169 for (var package in packages) { |
169 var id = idFor(package.name, package.version); | 170 var id = idFor(package.name, package.version, url: url); |
170 | 171 |
171 try { | 172 try { |
172 await _download(url, package.name, package.version, package.dir); | 173 await _download(url, package.name, package.version, package.dir); |
173 successes.add(id); | 174 successes.add(id); |
174 } catch (error, stackTrace) { | 175 } catch (error, stackTrace) { |
175 failures.add(id); | 176 failures.add(id); |
176 var message = "Failed to repair ${log.bold(package.name)} " | 177 var message = "Failed to repair ${log.bold(package.name)} " |
177 "${package.version}"; | 178 "${package.version}"; |
178 if (url != defaultUrl) message += " from $url"; | 179 if (url != defaultUrl) message += " from $url"; |
179 log.error("$message. Error:\n$error"); | 180 log.error("$message. Error:\n$error"); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 log.io("Finding versions of ${ref.name} in " | 263 log.io("Finding versions of ${ref.name} in " |
263 "$systemCacheRoot/${_urlToDirectory(server)}"); | 264 "$systemCacheRoot/${_urlToDirectory(server)}"); |
264 | 265 |
265 var dir = path.join(systemCacheRoot, _urlToDirectory(server)); | 266 var dir = path.join(systemCacheRoot, _urlToDirectory(server)); |
266 | 267 |
267 var versions; | 268 var versions; |
268 if (dirExists(dir)) { | 269 if (dirExists(dir)) { |
269 versions = await listDir(dir).map((entry) { | 270 versions = await listDir(dir).map((entry) { |
270 var components = path.basename(entry).split("-"); | 271 var components = path.basename(entry).split("-"); |
271 if (components.first != ref.name) return null; | 272 if (components.first != ref.name) return null; |
272 return HostedSource.idFor(ref.name, new Version.parse(components.last)); | 273 return HostedSource.idFor( |
| 274 ref.name, new Version.parse(components.last), |
| 275 url: _serverFor(ref.description)); |
273 }).where((id) => id != null).toList(); | 276 }).where((id) => id != null).toList(); |
274 } else { | 277 } else { |
275 versions = []; | 278 versions = []; |
276 } | 279 } |
277 | 280 |
278 // If there are no versions in the cache, report a clearer error. | 281 // If there are no versions in the cache, report a clearer error. |
279 if (versions.isEmpty) { | 282 if (versions.isEmpty) { |
280 throw new PackageNotFoundException( | 283 throw new PackageNotFoundException( |
281 "Could not find package ${ref.name} in cache."); | 284 "Could not find package ${ref.name} in cache."); |
282 } | 285 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 /// converts that to a Uri given [pattern]. | 348 /// converts that to a Uri given [pattern]. |
346 /// | 349 /// |
347 /// Ensures the package name is properly URL encoded. | 350 /// Ensures the package name is properly URL encoded. |
348 Uri _makeUrl(description, String pattern(String server, String package)) { | 351 Uri _makeUrl(description, String pattern(String server, String package)) { |
349 var parsed = _parseDescription(description); | 352 var parsed = _parseDescription(description); |
350 var server = parsed.last; | 353 var server = parsed.last; |
351 var package = Uri.encodeComponent(parsed.first); | 354 var package = Uri.encodeComponent(parsed.first); |
352 return Uri.parse(pattern(server, package)); | 355 return Uri.parse(pattern(server, package)); |
353 } | 356 } |
354 | 357 |
| 358 /// Returns the server URL for [description]. |
| 359 Uri _serverFor(description) => Uri.parse(_parseDescription(description).last); |
| 360 |
355 /// Parses [id] into its server, package name, and version components, then | 361 /// Parses [id] into its server, package name, and version components, then |
356 /// converts that to a Uri given [pattern]. | 362 /// converts that to a Uri given [pattern]. |
357 /// | 363 /// |
358 /// Ensures the package name is properly URL encoded. | 364 /// Ensures the package name is properly URL encoded. |
359 Uri _makeVersionUrl(PackageId id, | 365 Uri _makeVersionUrl(PackageId id, |
360 String pattern(String server, String package, String version)) { | 366 String pattern(String server, String package, String version)) { |
361 var parsed = _parseDescription(id.description); | 367 var parsed = _parseDescription(id.description); |
362 var server = parsed.last; | 368 var server = parsed.last; |
363 var package = Uri.encodeComponent(parsed.first); | 369 var package = Uri.encodeComponent(parsed.first); |
364 var version = Uri.encodeComponent(id.version.toString()); | 370 var version = Uri.encodeComponent(id.version.toString()); |
(...skipping 22 matching lines...) Expand all Loading... |
387 var name = description["name"]; | 393 var name = description["name"]; |
388 if (name is! String) { | 394 if (name is! String) { |
389 throw new FormatException("The 'name' key must have a string value."); | 395 throw new FormatException("The 'name' key must have a string value."); |
390 } | 396 } |
391 | 397 |
392 var url = description["url"]; | 398 var url = description["url"]; |
393 if (url == null) url = HostedSource.defaultUrl; | 399 if (url == null) url = HostedSource.defaultUrl; |
394 | 400 |
395 return new Pair<String, String>(name, url); | 401 return new Pair<String, String>(name, url); |
396 } | 402 } |
OLD | NEW |