| 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 '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'; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 Future<bool> install(PackageId id, String path) { | 97 Future<bool> install(PackageId id, String path) { |
| 98 throw "Either install or installToSystemCache must be implemented for " | 98 throw "Either install or installToSystemCache must be implemented for " |
| 99 "source $name."; | 99 "source $name."; |
| 100 } | 100 } |
| 101 | 101 |
| 102 /// Installs the package identified by [id] to the system cache. This is only | 102 /// Installs the package identified by [id] to the system cache. This is only |
| 103 /// called for sources with [shouldCache] set to true. | 103 /// called for sources with [shouldCache] set to true. |
| 104 /// | 104 /// |
| 105 /// By default, this uses [systemCacheDirectory] and [install]. | 105 /// By default, this uses [systemCacheDirectory] and [install]. |
| 106 Future<Package> installToSystemCache(PackageId id) { | 106 Future<Package> installToSystemCache(PackageId id) { |
| 107 var path = systemCacheDirectory(id); | 107 return systemCacheDirectory(id).then((path) { |
| 108 return exists(path).then((exists) { | 108 return exists(path).then((exists) { |
| 109 if (exists) return new Future<bool>.immediate(true); | 109 if (exists) return new Future<bool>.immediate(true); |
| 110 return ensureDir(dirname(path)).then((_) => install(id, path)); | 110 return ensureDir(dirname(path)).then((_) => install(id, path)); |
| 111 }).then((found) { | 111 }).then((found) { |
| 112 if (!found) throw 'Package $id not found.'; | 112 if (!found) throw 'Package $id not found.'; |
| 113 return Package.load(id.name, path, systemCache.sources); | 113 return Package.load(id.name, path, systemCache.sources); |
| 114 }); |
| 114 }); | 115 }); |
| 115 } | 116 } |
| 116 | 117 |
| 117 /// Returns the directory in the system cache that the package identified by | 118 /// Returns the directory in the system cache that the package identified by |
| 118 /// [id] should be installed to. This should return a path to a subdirectory | 119 /// [id] should be installed to. This should return a path to a subdirectory |
| 119 /// of [systemCacheRoot]. | 120 /// of [systemCacheRoot]. |
| 120 /// | 121 /// |
| 121 /// This doesn't need to be implemented if [shouldCache] is false, or if | 122 /// This doesn't need to be implemented if [shouldCache] is false. |
| 122 /// [installToSystemCache] is implemented. | 123 Future<String> systemCacheDirectory(PackageId id) { |
| 123 String systemCacheDirectory(PackageId id) { | 124 return new Future.immediateError( |
| 124 throw 'Source.systemCacheDirectory must be implemented if shouldCache is ' | 125 "systemCacheDirectory() must be implemented if shouldCache is true."); |
| 125 'true and installToSystemCache is not implemented.'; | |
| 126 } | 126 } |
| 127 | 127 |
| 128 /// When a [Pubspec] or [LockFile] is parsed, it reads in the description for | 128 /// When a [Pubspec] or [LockFile] is parsed, it reads in the description for |
| 129 /// each dependency. It is up to the dependency's [Source] to determine how | 129 /// each dependency. It is up to the dependency's [Source] to determine how |
| 130 /// that should be interpreted. This will be called during parsing to validate | 130 /// that should be interpreted. This will be called during parsing to validate |
| 131 /// that the given [description] is well-formed according to this source. It | 131 /// that the given [description] is well-formed according to this source. It |
| 132 /// should return if the description is valid, or throw a [FormatException] if | 132 /// should return if the description is valid, or throw a [FormatException] if |
| 133 /// not. | 133 /// not. |
| 134 /// | 134 /// |
| 135 /// [fromLockFile] is true when the description comes from a [LockFile], to | 135 /// [fromLockFile] is true when the description comes from a [LockFile], to |
| (...skipping 25 matching lines...) Expand all Loading... |
| 161 /// according to [validateDescription], although it must still be serializable | 161 /// according to [validateDescription], although it must still be serializable |
| 162 /// to JSON and YAML. It must also be equal to [id] according to | 162 /// to JSON and YAML. It must also be equal to [id] according to |
| 163 /// [descriptionsEqual]. | 163 /// [descriptionsEqual]. |
| 164 /// | 164 /// |
| 165 /// By default, this just returns [id]. | 165 /// By default, this just returns [id]. |
| 166 Future<PackageId> resolveId(PackageId id) => new Future.immediate(id); | 166 Future<PackageId> resolveId(PackageId id) => new Future.immediate(id); |
| 167 | 167 |
| 168 /// Returns the source's name. | 168 /// Returns the source's name. |
| 169 String toString() => name; | 169 String toString() => name; |
| 170 } | 170 } |
| OLD | NEW |