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