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 library hosted_source; | 5 library hosted_source; |
6 | 6 |
7 import 'dart:io' as io; | 7 import 'dart:io' as io; |
8 import 'dart:json'; | 8 import 'dart:json'; |
9 import 'dart:uri'; | 9 import 'dart:uri'; |
10 | 10 |
11 // TODO(nweiz): Make this import better. | 11 // TODO(nweiz): Make this import better. |
12 import '../../pkg/http/lib/http.dart' as http; | 12 import '../../pkg/http/lib/http.dart' as http; |
13 import 'io.dart'; | 13 import 'io.dart'; |
14 import 'log.dart' as log; | |
15 import 'package.dart'; | 14 import 'package.dart'; |
16 import 'pubspec.dart'; | 15 import 'pubspec.dart'; |
17 import 'source.dart'; | 16 import 'source.dart'; |
18 import 'source_registry.dart'; | 17 import 'source_registry.dart'; |
19 import 'utils.dart'; | 18 import 'utils.dart'; |
20 import 'version.dart'; | 19 import 'version.dart'; |
21 | 20 |
22 /** | 21 /** |
23 * A package source that installs packages from a package hosting site that | 22 * A package source that installs packages from a package hosting site that |
24 * uses the same API as pub.dartlang.org. | 23 * uses the same API as pub.dartlang.org. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 /** | 66 /** |
68 * Downloads a package from the site and unpacks it. | 67 * Downloads a package from the site and unpacks it. |
69 */ | 68 */ |
70 Future<bool> install(PackageId id, String destPath) { | 69 Future<bool> install(PackageId id, String destPath) { |
71 var parsedDescription = _parseDescription(id.description); | 70 var parsedDescription = _parseDescription(id.description); |
72 var name = parsedDescription.first; | 71 var name = parsedDescription.first; |
73 var url = parsedDescription.last; | 72 var url = parsedDescription.last; |
74 | 73 |
75 var fullUrl = "$url/packages/$name/versions/${id.version}.tar.gz"; | 74 var fullUrl = "$url/packages/$name/versions/${id.version}.tar.gz"; |
76 | 75 |
77 log.message('Downloading $id...'); | 76 print('Downloading $id...'); |
78 | 77 |
79 // Download and extract the archive to a temp directory. | 78 // Download and extract the archive to a temp directory. |
80 var tempDir; | 79 var tempDir; |
81 return Futures.wait([ | 80 return Futures.wait([ |
82 httpClient.send(new http.Request("GET", new Uri.fromString(fullUrl))) | 81 httpClient.send(new http.Request("GET", new Uri.fromString(fullUrl))) |
83 .transform((response) => response.stream), | 82 .transform((response) => response.stream), |
84 systemCache.createTempDir() | 83 systemCache.createTempDir() |
85 ]).chain((args) { | 84 ]).chain((args) { |
86 tempDir = args[1]; | 85 tempDir = args[1]; |
87 return timeout(extractTarGz(args[0], tempDir), HTTP_TIMEOUT, | 86 return timeout(extractTarGz(args[0], tempDir), HTTP_TIMEOUT, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 | 168 |
170 var name = description["name"]; | 169 var name = description["name"]; |
171 if (name is! String) { | 170 if (name is! String) { |
172 throw new FormatException("The 'name' key must have a string value."); | 171 throw new FormatException("The 'name' key must have a string value."); |
173 } | 172 } |
174 | 173 |
175 var url = description.containsKey("url") ? description["url"] : defaultUrl; | 174 var url = description.containsKey("url") ? description["url"] : defaultUrl; |
176 return new Pair<String, String>(name, url); | 175 return new Pair<String, String>(name, url); |
177 } | 176 } |
178 } | 177 } |
OLD | NEW |