OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import 'dart:collection'; | 5 import 'dart:collection'; |
6 | 6 |
7 import '../ascii_tree.dart' as tree; | 7 import '../ascii_tree.dart' as tree; |
8 import '../command.dart'; | 8 import '../command.dart'; |
9 import '../log.dart' as log; | 9 import '../log.dart' as log; |
10 import '../package.dart'; | 10 import '../package.dart'; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 /// Generates a dependency tree for the root package. | 137 /// Generates a dependency tree for the root package. |
138 /// | 138 /// |
139 /// If a package is encountered more than once (i.e. a shared or circular | 139 /// If a package is encountered more than once (i.e. a shared or circular |
140 /// dependency), later ones are not traversed. This is done in breadth-first | 140 /// dependency), later ones are not traversed. This is done in breadth-first |
141 /// fashion so that a package will always be expanded at the shallowest | 141 /// fashion so that a package will always be expanded at the shallowest |
142 /// depth that it appears at. | 142 /// depth that it appears at. |
143 void _outputTree() { | 143 void _outputTree() { |
144 // The work list for the breadth-first traversal. It contains the package | 144 // The work list for the breadth-first traversal. It contains the package |
145 // being added to the tree, and the parent map that will receive that | 145 // being added to the tree, and the parent map that will receive that |
146 // package. | 146 // package. |
147 var toWalk = new Queue<Pair<Package, Map>>(); | 147 var toWalk = new Queue<Pair<Package, Map<String, Map>>>(); |
148 var visited = new Set<String>.from([entrypoint.root.name]); | 148 var visited = new Set<String>.from([entrypoint.root.name]); |
149 | 149 |
150 // Start with the root dependencies. | 150 // Start with the root dependencies. |
151 var packageTree = {}; | 151 var packageTree = <String, Map>{}; |
152 var immediateDependencies = entrypoint.root.immediateDependencies.toSet(); | 152 var immediateDependencies = entrypoint.root.immediateDependencies.toSet(); |
153 if (!_includeDev) { | 153 if (!_includeDev) { |
154 immediateDependencies.removeAll(entrypoint.root.devDependencies); | 154 immediateDependencies.removeAll(entrypoint.root.devDependencies); |
155 } | 155 } |
156 for (var dep in immediateDependencies) { | 156 for (var dep in immediateDependencies) { |
157 toWalk.add(new Pair(_getPackage(dep.name), packageTree)); | 157 toWalk.add(new Pair(_getPackage(dep.name), packageTree)); |
158 } | 158 } |
159 | 159 |
160 // Do a breadth-first walk to the dependency graph. | 160 // Do a breadth-first walk to the dependency graph. |
161 while (toWalk.isNotEmpty) { | 161 while (toWalk.isNotEmpty) { |
162 var pair = toWalk.removeFirst(); | 162 var pair = toWalk.removeFirst(); |
163 var package = pair.first; | 163 var package = pair.first; |
164 var map = pair.last; | 164 var map = pair.last; |
165 | 165 |
166 if (visited.contains(package.name)) { | 166 if (visited.contains(package.name)) { |
167 map[log.gray('${package.name}...')] = {}; | 167 map[log.gray('${package.name}...')] = {}; |
168 continue; | 168 continue; |
169 } | 169 } |
170 | 170 |
171 visited.add(package.name); | 171 visited.add(package.name); |
172 | 172 |
173 // Populate the map with this package's dependencies. | 173 // Populate the map with this package's dependencies. |
174 var childMap = {}; | 174 var childMap = <String, Map>{}; |
175 map[_labelPackage(package)] = childMap; | 175 map[_labelPackage(package)] = childMap; |
176 | 176 |
177 for (var dep in package.dependencies) { | 177 for (var dep in package.dependencies) { |
178 toWalk.add(new Pair(_getPackage(dep.name), childMap)); | 178 toWalk.add(new Pair(_getPackage(dep.name), childMap)); |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 _buffer.write(tree.fromMap(packageTree, showAllChildren: true)); | 182 _buffer.write(tree.fromMap(packageTree, showAllChildren: true)); |
183 } | 183 } |
184 | 184 |
(...skipping 29 matching lines...) Expand all Loading... |
214 /// available. | 214 /// available. |
215 /// | 215 /// |
216 /// It's very unlikely that the lockfile won't be up-to-date with the pubspec, | 216 /// It's very unlikely that the lockfile won't be up-to-date with the pubspec, |
217 /// but it's possible, since [Entrypoint.assertUpToDate]'s modification time | 217 /// but it's possible, since [Entrypoint.assertUpToDate]'s modification time |
218 /// check can return a false negative. This fails gracefully if that happens. | 218 /// check can return a false negative. This fails gracefully if that happens. |
219 Package _getPackage(String name) { | 219 Package _getPackage(String name) { |
220 var package = entrypoint.packageGraph.packages[name]; | 220 var package = entrypoint.packageGraph.packages[name]; |
221 if (package != null) return package; | 221 if (package != null) return package; |
222 dataError('The pubspec.yaml file has changed since the pubspec.lock file ' | 222 dataError('The pubspec.yaml file has changed since the pubspec.lock file ' |
223 'was generated, please run "pub get" again.'); | 223 'was generated, please run "pub get" again.'); |
| 224 return null; |
224 } | 225 } |
225 } | 226 } |
OLD | NEW |