Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: utils/pub/repo_source.dart

Issue 10704172: Hook in the version solver to pub install. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/pub/pubspec.dart ('k') | utils/pub/sdk_source.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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('dartlang_source'); 5 #library('dartlang_source');
6 6
7 #import('dart:io'); 7 #import('dart:io');
8 #import('dart:json');
8 #import('dart:uri'); 9 #import('dart:uri');
9 #import('io.dart'); 10 #import('io.dart');
10 #import('package.dart'); 11 #import('package.dart');
12 #import('pubspec.dart');
11 #import('source.dart'); 13 #import('source.dart');
14 #import('source_registry.dart');
12 #import('utils.dart'); 15 #import('utils.dart');
16 #import('version.dart');
13 17
14 /** 18 /**
15 * A package source that installs packages from a package repository that uses 19 * A package source that installs packages from a package repository that uses
16 * the same API as pub.dartlang.org. 20 * the same API as pub.dartlang.org.
17 */ 21 */
18 class RepoSource extends Source { 22 class RepoSource extends Source {
19 final String name = "repo"; 23 final String name = "repo";
20 24
21 final bool shouldCache = true; 25 final bool shouldCache = true;
22 26
23 // TODO(nweiz): update this comment once pub.dartlang.org is online 27 // TODO(nweiz): update this comment once pub.dartlang.org is online
24 /** 28 /**
25 * The URL of the default package repository. 29 * The URL of the default package repository.
26 * 30 *
27 * At time of writing, pub.dartlang.org is not yet online, but it should be 31 * At time of writing, pub.dartlang.org is not yet online, but it should be
28 * soon. 32 * soon.
29 */ 33 */
30 static final String defaultUrl = "http://pub.dartlang.org"; 34 static final String defaultUrl = "http://pub.dartlang.org";
31 35
32 RepoSource(); 36 RepoSource();
33 37
34 /** 38 /**
39 * Downloads a list of all versions of a package that have been uploaded to
40 * pub.dartlang.org.
41 */
42 Future<List<Version>> getVersions(description) {
43 var parsed = _parseDescription(description);
44 var fullUrl = "${parsed.last}/packages/${parsed.first}.json";
45 return consumeInputStream(httpGet(fullUrl)).transform((data) {
46 var doc = JSON.parse(new String.fromCharCodes(data));
47 return doc['versions'].map((version) => new Version.parse(version));
48 });
49 }
50
51 /**
52 * Downloads and parses the pubspec for a specific version of a package that
53 * has been uploaded to pub.dartlang.org.
54 */
55 Future<Pubspec> describe(PackageId id) {
56 var parsed = _parseDescription(id.description);
57 var fullUrl = "${parsed.last}/packages/${parsed.first}/versions/"
58 "${id.version}.yaml";
59 return consumeInputStream(httpGet(fullUrl)).transform((data) {
60 return new Pubspec.parse(
61 new String.fromCharCodes(data), systemCache.sources);
62 });
63 }
64
65 /**
35 * Downloads a package from a package repository and unpacks it. 66 * Downloads a package from a package repository and unpacks it.
36 */ 67 */
37 Future<bool> install(PackageId id, String destPath) { 68 Future<bool> install(PackageId id, String destPath) {
38 var parsedDescription = _parseDescription(id.description); 69 var parsedDescription = _parseDescription(id.description);
39 var name = parsedDescription.first; 70 var name = parsedDescription.first;
40 var url = parsedDescription.last; 71 var url = parsedDescription.last;
41 72
42 return ensureDir(destPath).chain((destDir) { 73 return ensureDir(destPath).chain((destDir) {
43 var fullUrl = "$url/packages/$name/versions/${id.version}.tar.gz"; 74 var fullUrl = "$url/packages/$name/versions/${id.version}.tar.gz";
44 return extractTarGz(httpGet(fullUrl), destDir); 75 return extractTarGz(httpGet(fullUrl), destDir);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 131
101 var name = description["name"]; 132 var name = description["name"];
102 if (name is! String) { 133 if (name is! String) {
103 throw new FormatException("The 'name' key must have a string value."); 134 throw new FormatException("The 'name' key must have a string value.");
104 } 135 }
105 136
106 var url = description.containsKey("url") ? description["url"] : defaultUrl; 137 var url = description.containsKey("url") ? description["url"] : defaultUrl;
107 return new Pair<String, String>(name, url); 138 return new Pair<String, String>(name, url);
108 } 139 }
109 } 140 }
OLDNEW
« no previous file with comments | « utils/pub/pubspec.dart ('k') | utils/pub/sdk_source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698