| 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 entrypoint; | 5 library entrypoint; |
| 6 | 6 |
| 7 import 'io.dart'; | 7 import 'io.dart'; |
| 8 import 'lock_file.dart'; | 8 import 'lock_file.dart'; |
| 9 import 'log.dart' as log; | 9 import 'log.dart' as log; |
| 10 import 'package.dart'; | 10 import 'package.dart'; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 107 |
| 108 return future; | 108 return future; |
| 109 } | 109 } |
| 110 | 110 |
| 111 /** | 111 /** |
| 112 * Installs all dependencies of the [root] package to its "packages" | 112 * Installs all dependencies of the [root] package to its "packages" |
| 113 * directory, respecting the [LockFile] if present. Returns a [Future] that | 113 * directory, respecting the [LockFile] if present. Returns a [Future] that |
| 114 * completes when all dependencies are installed. | 114 * completes when all dependencies are installed. |
| 115 */ | 115 */ |
| 116 Future installDependencies() { | 116 Future installDependencies() { |
| 117 return _loadLockFile() | 117 return loadLockFile() |
| 118 .chain((lockFile) => resolveVersions(cache.sources, root, lockFile)) | 118 .chain((lockFile) => resolveVersions(cache.sources, root, lockFile)) |
| 119 .chain(_installDependencies); | 119 .chain(_installDependencies); |
| 120 } | 120 } |
| 121 | 121 |
| 122 /** | 122 /** |
| 123 * Installs the latest available versions of all dependencies of the [root] | 123 * Installs the latest available versions of all dependencies of the [root] |
| 124 * package to its "package" directory, writing a new [LockFile]. Returns a | 124 * package to its "package" directory, writing a new [LockFile]. Returns a |
| 125 * [Future] that completes when all dependencies are installed. | 125 * [Future] that completes when all dependencies are installed. |
| 126 */ | 126 */ |
| 127 Future updateAllDependencies() { | 127 Future updateAllDependencies() { |
| 128 return resolveVersions(cache.sources, root, new LockFile.empty()) | 128 return resolveVersions(cache.sources, root, new LockFile.empty()) |
| 129 .chain(_installDependencies); | 129 .chain(_installDependencies); |
| 130 } | 130 } |
| 131 | 131 |
| 132 /** | 132 /** |
| 133 * Installs the latest available versions of [dependencies], while leaving | 133 * Installs the latest available versions of [dependencies], while leaving |
| 134 * other dependencies as specified by the [LockFile] if possible. Returns a | 134 * other dependencies as specified by the [LockFile] if possible. Returns a |
| 135 * [Future] that completes when all dependencies are installed. | 135 * [Future] that completes when all dependencies are installed. |
| 136 */ | 136 */ |
| 137 Future updateDependencies(List<String> dependencies) { | 137 Future updateDependencies(List<String> dependencies) { |
| 138 return _loadLockFile().chain((lockFile) { | 138 return loadLockFile().chain((lockFile) { |
| 139 var versionSolver = new VersionSolver(cache.sources, root, lockFile); | 139 var versionSolver = new VersionSolver(cache.sources, root, lockFile); |
| 140 for (var dependency in dependencies) { | 140 for (var dependency in dependencies) { |
| 141 versionSolver.useLatestVersion(dependency); | 141 versionSolver.useLatestVersion(dependency); |
| 142 } | 142 } |
| 143 return versionSolver.solve(); | 143 return versionSolver.solve(); |
| 144 }).chain(_installDependencies); | 144 }).chain(_installDependencies); |
| 145 } | 145 } |
| 146 | 146 |
| 147 /** | 147 /** |
| 148 * Removes the old packages directory, installs all dependencies listed in | 148 * Removes the old packages directory, installs all dependencies listed in |
| 149 * [packageVersions], and writes a [LockFile]. | 149 * [packageVersions], and writes a [LockFile]. |
| 150 */ | 150 */ |
| 151 Future _installDependencies(List<PackageId> packageVersions) { | 151 Future _installDependencies(List<PackageId> packageVersions) { |
| 152 return cleanDir(path).chain((_) { | 152 return cleanDir(path).chain((_) { |
| 153 return Futures.wait(packageVersions.map((id) { | 153 return Futures.wait(packageVersions.map((id) { |
| 154 if (id.source is RootSource) return new Future.immediate(id); | 154 if (id.source is RootSource) return new Future.immediate(id); |
| 155 return install(id); | 155 return install(id); |
| 156 })); | 156 })); |
| 157 }).chain(_saveLockFile) | 157 }).chain(_saveLockFile) |
| 158 .chain(_installSelfReference) | 158 .chain(_installSelfReference) |
| 159 .chain(_linkSecondaryPackageDirs); | 159 .chain(_linkSecondaryPackageDirs); |
| 160 } | 160 } |
| 161 | 161 |
| 162 /** | 162 /// Loads the list of concrete package versions from the `pubspec.lock`, if it |
| 163 * Loads the list of concrete package versions from the `pubspec.lock`, if it | 163 /// exists. If it doesn't, this completes to an empty [LockFile]. |
| 164 * exists. If it doesn't, this completes to an empty [LockFile]. | 164 Future<LockFile> loadLockFile() { |
| 165 * | |
| 166 * If there's an error reading the `pubspec.lock` file, this will print a | |
| 167 * warning message and act as though the file doesn't exist. | |
| 168 */ | |
| 169 Future<LockFile> _loadLockFile() { | |
| 170 var lockFilePath = join(root.dir, 'pubspec.lock'); | 165 var lockFilePath = join(root.dir, 'pubspec.lock'); |
| 171 | 166 |
| 172 log.fine("Loading lockfile."); | 167 log.fine("Loading lockfile."); |
| 173 return fileExists(lockFilePath).chain((exists) { | 168 return fileExists(lockFilePath).chain((exists) { |
| 174 if (!exists) { | 169 if (!exists) { |
| 175 log.fine("No lock file at $lockFilePath, creating empty one."); | 170 log.fine("No lock file at $lockFilePath, creating empty one."); |
| 176 return new Future<LockFile>.immediate(new LockFile.empty()); | 171 return new Future<LockFile>.immediate(new LockFile.empty()); |
| 177 } | 172 } |
| 178 | 173 |
| 179 return readTextFile(lockFilePath).transform((text) => | 174 return readTextFile(lockFilePath).transform((text) => |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 * Creates a symlink to the `packages` directory in [dir] if none exists. | 270 * Creates a symlink to the `packages` directory in [dir] if none exists. |
| 276 */ | 271 */ |
| 277 Future _linkSecondaryPackageDir(String dir) { | 272 Future _linkSecondaryPackageDir(String dir) { |
| 278 var to = join(dir, 'packages'); | 273 var to = join(dir, 'packages'); |
| 279 return exists(to).chain((exists) { | 274 return exists(to).chain((exists) { |
| 280 if (exists) return new Future.immediate(null); | 275 if (exists) return new Future.immediate(null); |
| 281 return createSymlink(path, to); | 276 return createSymlink(path, to); |
| 282 }); | 277 }); |
| 283 } | 278 } |
| 284 } | 279 } |
| OLD | NEW |