| 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 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'io.dart'; | 8 import 'io.dart'; |
| 9 import 'lock_file.dart'; | 9 import 'lock_file.dart'; |
| 10 import 'log.dart' as log; | 10 import 'log.dart' as log; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 versionSolver.useLatestVersion(dependency); | 123 versionSolver.useLatestVersion(dependency); |
| 124 } | 124 } |
| 125 return versionSolver.solve(); | 125 return versionSolver.solve(); |
| 126 }).then(_installDependencies); | 126 }).then(_installDependencies); |
| 127 } | 127 } |
| 128 | 128 |
| 129 /// Removes the old packages directory, installs all dependencies listed in | 129 /// Removes the old packages directory, installs all dependencies listed in |
| 130 /// [packageVersions], and writes a [LockFile]. | 130 /// [packageVersions], and writes a [LockFile]. |
| 131 Future _installDependencies(List<PackageId> packageVersions) { | 131 Future _installDependencies(List<PackageId> packageVersions) { |
| 132 return cleanDir(path).then((_) { | 132 return cleanDir(path).then((_) { |
| 133 return Future.wait(packageVersions.map((id) { | 133 return Future.wait(packageVersions.mappedBy((id) { |
| 134 if (id.isRoot) return new Future.immediate(id); | 134 if (id.isRoot) return new Future.immediate(id); |
| 135 return install(id); | 135 return install(id); |
| 136 })); | 136 })); |
| 137 }).then(_saveLockFile) | 137 }).then(_saveLockFile) |
| 138 .then(_installSelfReference) | 138 .then(_installSelfReference) |
| 139 .then(_linkSecondaryPackageDirs); | 139 .then(_linkSecondaryPackageDirs); |
| 140 } | 140 } |
| 141 | 141 |
| 142 /// Loads the list of concrete package versions from the `pubspec.lock`, if it | 142 /// Loads the list of concrete package versions from the `pubspec.lock`, if it |
| 143 /// exists. If it doesn't, this completes to an empty [LockFile]. | 143 /// exists. If it doesn't, this completes to an empty [LockFile]. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 } | 200 } |
| 201 | 201 |
| 202 /// Creates a symlink to the `packages` directory in [dir] and all its | 202 /// Creates a symlink to the `packages` directory in [dir] and all its |
| 203 /// subdirectories. | 203 /// subdirectories. |
| 204 Future _linkSecondaryPackageDirsRecursively(String dir) { | 204 Future _linkSecondaryPackageDirsRecursively(String dir) { |
| 205 return dirExists(dir).then((exists) { | 205 return dirExists(dir).then((exists) { |
| 206 if (!exists) return; | 206 if (!exists) return; |
| 207 return _linkSecondaryPackageDir(dir) | 207 return _linkSecondaryPackageDir(dir) |
| 208 .then((_) => _listDirWithoutPackages(dir)) | 208 .then((_) => _listDirWithoutPackages(dir)) |
| 209 .then((files) { | 209 .then((files) { |
| 210 return Future.wait(files.map((file) { | 210 return Future.wait(files.mappedBy((file) { |
| 211 return dirExists(file).then((isDir) { | 211 return dirExists(file).then((isDir) { |
| 212 if (!isDir) return; | 212 if (!isDir) return; |
| 213 return _linkSecondaryPackageDir(file); | 213 return _linkSecondaryPackageDir(file); |
| 214 }); | 214 }); |
| 215 })); | 215 })); |
| 216 }); | 216 }); |
| 217 }); | 217 }); |
| 218 } | 218 } |
| 219 | 219 |
| 220 // TODO(nweiz): roll this into [listDir] in io.dart once issue 4775 is fixed. | 220 // TODO(nweiz): roll this into [listDir] in io.dart once issue 4775 is fixed. |
| 221 /// Recursively lists the contents of [dir], excluding hidden `.DS_Store` | 221 /// Recursively lists the contents of [dir], excluding hidden `.DS_Store` |
| 222 /// files and `package` files. | 222 /// files and `package` files. |
| 223 Future<List<String>> _listDirWithoutPackages(dir) { | 223 Future<List<String>> _listDirWithoutPackages(dir) { |
| 224 return listDir(dir).then((files) { | 224 return listDir(dir).then((files) { |
| 225 return Future.wait(files.map((file) { | 225 return Future.wait(files.mappedBy((file) { |
| 226 if (basename(file) == 'packages') return new Future.immediate([]); | 226 if (basename(file) == 'packages') return new Future.immediate([]); |
| 227 return dirExists(file).then((isDir) { | 227 return dirExists(file).then((isDir) { |
| 228 if (!isDir) return []; | 228 if (!isDir) return []; |
| 229 return _listDirWithoutPackages(file); | 229 return _listDirWithoutPackages(file); |
| 230 }).then((subfiles) { | 230 }).then((subfiles) { |
| 231 var fileAndSubfiles = [file]; | 231 var fileAndSubfiles = [file]; |
| 232 fileAndSubfiles.addAll(subfiles); | 232 fileAndSubfiles.addAll(subfiles); |
| 233 return fileAndSubfiles; | 233 return fileAndSubfiles; |
| 234 }); | 234 }); |
| 235 })); | 235 })); |
| 236 }).then(flatten); | 236 }).then(flatten); |
| 237 } | 237 } |
| 238 | 238 |
| 239 /// Creates a symlink to the `packages` directory in [dir] if none exists. | 239 /// Creates a symlink to the `packages` directory in [dir] if none exists. |
| 240 Future _linkSecondaryPackageDir(String dir) { | 240 Future _linkSecondaryPackageDir(String dir) { |
| 241 var to = join(dir, 'packages'); | 241 var to = join(dir, 'packages'); |
| 242 return exists(to).then((exists) { | 242 return exists(to).then((exists) { |
| 243 if (exists) return; | 243 if (exists) return; |
| 244 return createSymlink(path, to); | 244 return createSymlink(path, to); |
| 245 }); | 245 }); |
| 246 } | 246 } |
| 247 } | 247 } |
| OLD | NEW |