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

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

Issue 12079112: Make a bunch of stuff in pub synchronous. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix after merge. Created 7 years, 10 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/sdk_source.dart ('k') | utils/pub/system_cache.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 source; 5 library source;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'io.dart'; 8 import 'io.dart';
9 import 'package.dart'; 9 import 'package.dart';
10 import 'pubspec.dart'; 10 import 'pubspec.dart';
11 import 'system_cache.dart'; 11 import 'system_cache.dart';
12 import 'utils.dart';
12 import 'version.dart'; 13 import 'version.dart';
13 14
14 /// A source from which to install packages. 15 /// A source from which to install packages.
15 /// 16 ///
16 /// Each source has many packages that it looks up using [PackageId]s. The 17 /// Each source has many packages that it looks up using [PackageId]s. The
17 /// source is responsible for installing these packages to the package cache. 18 /// source is responsible for installing these packages to the package cache.
18 abstract class Source { 19 abstract class Source {
19 /// The name of the source. Should be lower-case, suitable for use in a 20 /// The name of the source. Should be lower-case, suitable for use in a
20 /// filename, and unique accross all sources. 21 /// filename, and unique accross all sources.
21 String get name; 22 String get name;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 Future<bool> install(PackageId id, String path) { 98 Future<bool> install(PackageId id, String path) {
98 throw "Either install or installToSystemCache must be implemented for " 99 throw "Either install or installToSystemCache must be implemented for "
99 "source $name."; 100 "source $name.";
100 } 101 }
101 102
102 /// Installs the package identified by [id] to the system cache. This is only 103 /// Installs the package identified by [id] to the system cache. This is only
103 /// called for sources with [shouldCache] set to true. 104 /// called for sources with [shouldCache] set to true.
104 /// 105 ///
105 /// By default, this uses [systemCacheDirectory] and [install]. 106 /// By default, this uses [systemCacheDirectory] and [install].
106 Future<Package> installToSystemCache(PackageId id) { 107 Future<Package> installToSystemCache(PackageId id) {
107 return systemCacheDirectory(id).then((path) { 108 var path;
108 return exists(path).then((exists) { 109 return systemCacheDirectory(id).then((p) {
109 if (exists) return new Future<bool>.immediate(true); 110 path = p;
110 return ensureDir(dirname(path)).then((_) => install(id, path)); 111 if (dirExists(path)) return true;
111 }).then((found) { 112 ensureDir(dirname(path));
112 if (!found) throw 'Package $id not found.'; 113 return install(id, path);
113 return Package.load(id.name, path, systemCache.sources); 114 }).then((found) {
114 }); 115 if (!found) throw 'Package $id not found.';
116 return new Package(id.name, path, systemCache.sources);
115 }); 117 });
116 } 118 }
117 119
118 /// Returns the directory in the system cache that the package identified by 120 /// Returns the directory in the system cache that the package identified by
119 /// [id] should be installed to. This should return a path to a subdirectory 121 /// [id] should be installed to. This should return a path to a subdirectory
120 /// of [systemCacheRoot]. 122 /// of [systemCacheRoot].
121 /// 123 ///
122 /// This doesn't need to be implemented if [shouldCache] is false. 124 /// This doesn't need to be implemented if [shouldCache] is false.
123 Future<String> systemCacheDirectory(PackageId id) { 125 Future<String> systemCacheDirectory(PackageId id) {
124 return new Future.immediateError( 126 return new Future.immediateError(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 /// according to [validateDescription], although it must still be serializable 163 /// according to [validateDescription], although it must still be serializable
162 /// to JSON and YAML. It must also be equal to [id] according to 164 /// to JSON and YAML. It must also be equal to [id] according to
163 /// [descriptionsEqual]. 165 /// [descriptionsEqual].
164 /// 166 ///
165 /// By default, this just returns [id]. 167 /// By default, this just returns [id].
166 Future<PackageId> resolveId(PackageId id) => new Future.immediate(id); 168 Future<PackageId> resolveId(PackageId id) => new Future.immediate(id);
167 169
168 /// Returns the source's name. 170 /// Returns the source's name.
169 String toString() => name; 171 String toString() => name;
170 } 172 }
OLDNEW
« no previous file with comments | « utils/pub/sdk_source.dart ('k') | utils/pub/system_cache.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698