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

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

Issue 10749014: Refactor Source to take the system cache as a parameter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge 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('package.dart'); 8 #import('package.dart');
8 #import('pubspec.dart'); 9 #import('pubspec.dart');
10 #import('system_cache.dart');
9 #import('version.dart'); 11 #import('version.dart');
10 12
11 /** 13 /**
12 * A source from which to install packages. 14 * A source from which to install packages.
13 * 15 *
14 * Each source has many packages that it looks up using [PackageId]s. The source 16 * Each source has many packages that it looks up using [PackageId]s. The source
15 * is responsible for installing these packages to the package cache. 17 * is responsible for installing these packages to the package cache.
16 */ 18 */
17 class Source { 19 class Source {
18 /** 20 /**
19 * The name of the source. Should be lower-case, suitable for use in a 21 * The name of the source. Should be lower-case, suitable for use in a
20 * filename, and unique accross all sources. 22 * filename, and unique accross all sources.
21 */ 23 */
22 abstract String get name(); 24 abstract String get name();
23 25
24 /** 26 /**
25 * Whether this source's packages should be cached in Pub's global cache 27 * Whether this source's packages should be cached in Pub's global cache
26 * directory. 28 * directory.
27 * 29 *
28 * A source should be cached if it requires network access to retrieve 30 * A source should be cached if it requires network access to retrieve
29 * packages. It doesn't need to be cached if all packages are available 31 * packages. It doesn't need to be cached if all packages are available
30 * locally. 32 * locally.
31 */ 33 */
32 abstract bool get shouldCache(); 34 abstract bool get shouldCache();
33 35
34 /** 36 /**
37 * The system cache with which this source is registered.
38 */
39 SystemCache get systemCache() {
40 assert(_systemCache != null);
41 return _systemCache;
42 }
43
44 /**
45 * The system cache variable. Set by [_bind].
46 */
47 SystemCache _systemCache;
48
49 /**
50 * The root directory of this source's cache within the system cache.
51 *
52 * This shouldn't be overridden by subclasses.
53 */
54 String get systemCacheRoot() => join(systemCache.rootDir, name);
55
56 /**
57 * Records the system cache to which this source belongs.
58 *
59 * This should only be called once for each source, by [SystemCache.register].
60 * It should not be overridden by base classes.
61 */
62 void bind(SystemCache systemCache) {
63 assert(_systemCache == null);
64 this._systemCache = systemCache;
65 }
66
67 /**
35 * Get the list of all versions that exist for the package described by 68 * Get the list of all versions that exist for the package described by
36 * [description]. 69 * [description].
37 * 70 *
38 * Note that this does *not* require the packages to be installed, which is 71 * Note that this does *not* require the packages to be installed, which is
39 * the point. This is used during version resolution to determine which 72 * the point. This is used during version resolution to determine which
40 * package versions are available to be installed (or already installed). 73 * package versions are available to be installed (or already installed).
41 */ 74 */
42 Future<List<Version>> getVersions(description) { 75 Future<List<Version>> getVersions(description) {
43 // TODO(rnystrom): Do something better here. 76 // TODO(rnystrom): Do something better here.
44 throw "Source $name doesn't support versioning."; 77 throw "Source $name doesn't support versioning.";
(...skipping 15 matching lines...) Expand all
60 * 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
61 * all other error conditions, it should complete with an exception. 94 * all other error conditions, it should complete with an exception.
62 * 95 *
63 * [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
64 * to exist. 97 * to exist.
65 */ 98 */
66 abstract Future<bool> install(PackageId id, String path); 99 abstract Future<bool> install(PackageId id, String path);
67 100
68 /** 101 /**
69 * Returns the directory in the system cache that the package identified by 102 * Returns the directory in the system cache that the package identified by
70 * [id] should be installed to. [parent] is this source's subdirectory in the 103 * [id] should be installed to. This should return a path to a subdirectory of
71 * system cache directory. 104 * [systemCacheRoot].
72 * 105 *
73 * This doesn't need to be implemented if [shouldCache] is false. 106 * This doesn't need to be implemented if [shouldCache] is false.
74 */ 107 */
75 String systemCacheDirectory(PackageId id, String parent) => 108 String systemCacheDirectory(PackageId id) =>
76 join(parent, packageName(id.description)); 109 join(systemCacheRoot, packageName(id.description));
77 110
78 /** 111 /**
79 * When a [Pubspec] is parsed, it reads in the description for each 112 * When a [Pubspec] is parsed, it reads in the description for each
80 * dependency. It is up to the dependency's [Source] to determine how that 113 * dependency. It is up to the dependency's [Source] to determine how that
81 * should be interpreted. This will be called during parsing to validate that 114 * should be interpreted. This will be called during parsing to validate that
82 * the given [description] is well-formed according to this source. It should 115 * the given [description] is well-formed according to this source. It should
83 * return if the description is valid, or throw a [FormatException] if not. 116 * return if the description is valid, or throw a [FormatException] if not.
84 */ 117 */
85 void validateDescription(description) {} 118 void validateDescription(description) {}
86 119
(...skipping 11 matching lines...) Expand all
98 * Returns whether or not [description1] describes the same package as 131 * Returns whether or not [description1] describes the same package as
99 * [description2] for this source. This method should be light-weight. It 132 * [description2] for this source. This method should be light-weight. It
100 * doesn't need to validate that either package exists. 133 * doesn't need to validate that either package exists.
101 * 134 *
102 * By default, this assumes both descriptions are strings and compares them 135 * By default, this assumes both descriptions are strings and compares them
103 * for equality. 136 * for equality.
104 */ 137 */
105 bool descriptionsEqual(description1, description2) => 138 bool descriptionsEqual(description1, description2) =>
106 description1 == description2; 139 description1 == description2;
107 } 140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698