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

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

Issue 10736015: Make the Git source install to the system cache. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor fixes 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
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('io.dart'); 7 #import('io.dart');
8 #import('package.dart'); 8 #import('package.dart');
9 #import('pubspec.dart'); 9 #import('pubspec.dart');
10 #import('system_cache.dart'); 10 #import('system_cache.dart');
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 88 }
89 89
90 /** 90 /**
91 * Installs the package identified by [id] to [path]. Returns a [Future] that 91 * Installs the package identified by [id] to [path]. Returns a [Future] that
92 * completes when the installation was finished. The [Future] should resolve 92 * completes when the installation was finished. The [Future] should resolve
93 * to true if the package was found in the source and false if it wasn't. For 93 * to true if the package was found in the source and false if it wasn't. For
94 * all other error conditions, it should complete with an exception. 94 * all other error conditions, it should complete with an exception.
95 * 95 *
96 * [path] is guaranteed not to exist, and its parent directory is guaranteed 96 * [path] is guaranteed not to exist, and its parent directory is guaranteed
97 * to exist. 97 * to exist.
98 *
99 * This doesn't need to be implemented if [installToSystemCache] is
100 * implemented.
98 */ 101 */
99 abstract Future<bool> install(PackageId id, String path); 102 Future<bool> install(PackageId id, String path) {
103 throw "Either install or installToSystemCache must be implemented for "
104 "source $name."
105 }
106
107 /**
108 * Installs the package identified by [id] to the system cache. This is only
109 * called for sources with [shouldCache] set to true.
110 *
111 * By default, this uses [systemCacheDirectory] and [install].
112 */
113 Future<Package> installToSystemCache(PackageId id) {
114 var path = systemCacheDirectory(id);
115 return exists(path).chain((exists) {
116 // TODO(nweiz): better error handling
117 if (exists) throw 'Package $id is already installed.';
118 return ensureDir(dirname(path));
119 }).chain((_) {
120 return install(id, path);
121 }).chain((found) {
122 if (!found) throw 'Package $id not found.';
123 return Package.load(path, systemCache.sources);
124 });
125 }
100 126
101 /** 127 /**
102 * Returns the directory in the system cache that the package identified by 128 * Returns the directory in the system cache that the package identified by
103 * [id] should be installed to. This should return a path to a subdirectory of 129 * [id] should be installed to. This should return a path to a subdirectory of
104 * [systemCacheRoot]. 130 * [systemCacheRoot].
105 * 131 *
106 * This doesn't need to be implemented if [shouldCache] is false. 132 * This doesn't need to be implemented if [shouldCache] is false, or if
133 * [installToSystemCache] is implemented.
107 */ 134 */
108 String systemCacheDirectory(PackageId id) => 135 String systemCacheDirectory(PackageId id) =>
109 join(systemCacheRoot, packageName(id.description)); 136 join(systemCacheRoot, packageName(id.description));
110 137
111 /** 138 /**
112 * When a [Pubspec] is parsed, it reads in the description for each 139 * When a [Pubspec] is parsed, it reads in the description for each
113 * dependency. It is up to the dependency's [Source] to determine how that 140 * dependency. It is up to the dependency's [Source] to determine how that
114 * should be interpreted. This will be called during parsing to validate that 141 * should be interpreted. This will be called during parsing to validate that
115 * the given [description] is well-formed according to this source. It should 142 * the given [description] is well-formed according to this source. It should
116 * return if the description is valid, or throw a [FormatException] if not. 143 * return if the description is valid, or throw a [FormatException] if not.
(...skipping 14 matching lines...) Expand all
131 * Returns whether or not [description1] describes the same package as 158 * Returns whether or not [description1] describes the same package as
132 * [description2] for this source. This method should be light-weight. It 159 * [description2] for this source. This method should be light-weight. It
133 * doesn't need to validate that either package exists. 160 * doesn't need to validate that either package exists.
134 * 161 *
135 * By default, this assumes both descriptions are strings and compares them 162 * By default, this assumes both descriptions are strings and compares them
136 * for equality. 163 * for equality.
137 */ 164 */
138 bool descriptionsEqual(description1, description2) => 165 bool descriptionsEqual(description1, description2) =>
139 description1 == description2; 166 description1 == description2;
140 } 167 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698