| 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('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 Loading... |
| 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. | |
| 101 */ | 98 */ |
| 102 Future<bool> install(PackageId id, String path) { | 99 abstract 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 } | |
| 126 | 100 |
| 127 /** | 101 /** |
| 128 * 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 |
| 129 * [id] should be installed to. This should return a path to a subdirectory of | 103 * [id] should be installed to. This should return a path to a subdirectory of |
| 130 * [systemCacheRoot]. | 104 * [systemCacheRoot]. |
| 131 * | 105 * |
| 132 * This doesn't need to be implemented if [shouldCache] is false, or if | 106 * This doesn't need to be implemented if [shouldCache] is false. |
| 133 * [installToSystemCache] is implemented. | |
| 134 */ | 107 */ |
| 135 String systemCacheDirectory(PackageId id) => | 108 String systemCacheDirectory(PackageId id) => |
| 136 join(systemCacheRoot, packageName(id.description)); | 109 join(systemCacheRoot, packageName(id.description)); |
| 137 | 110 |
| 138 /** | 111 /** |
| 139 * 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 |
| 140 * 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 |
| 141 * 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 |
| 142 * 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 |
| 143 * 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. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 158 * Returns whether or not [description1] describes the same package as | 131 * Returns whether or not [description1] describes the same package as |
| 159 * [description2] for this source. This method should be light-weight. It | 132 * [description2] for this source. This method should be light-weight. It |
| 160 * doesn't need to validate that either package exists. | 133 * doesn't need to validate that either package exists. |
| 161 * | 134 * |
| 162 * By default, this assumes both descriptions are strings and compares them | 135 * By default, this assumes both descriptions are strings and compares them |
| 163 * for equality. | 136 * for equality. |
| 164 */ | 137 */ |
| 165 bool descriptionsEqual(description1, description2) => | 138 bool descriptionsEqual(description1, description2) => |
| 166 description1 == description2; | 139 description1 == description2; |
| 167 } | 140 } |
| OLD | NEW |