| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 barback.graph.phase; | 5 library barback.graph.phase; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:collection/collection.dart'; |
| 10 |
| 9 import '../asset/asset_id.dart'; | 11 import '../asset/asset_id.dart'; |
| 10 import '../asset/asset_node.dart'; | 12 import '../asset/asset_node.dart'; |
| 11 import '../asset/asset_node_set.dart'; | 13 import '../asset/asset_node_set.dart'; |
| 12 import '../errors.dart'; | 14 import '../errors.dart'; |
| 13 import '../log.dart'; | 15 import '../log.dart'; |
| 14 import '../transformer/aggregate_transformer.dart'; | 16 import '../transformer/aggregate_transformer.dart'; |
| 15 import '../transformer/transformer.dart'; | 17 import '../transformer/transformer.dart'; |
| 16 import '../transformer/transformer_group.dart'; | 18 import '../transformer/transformer_group.dart'; |
| 17 import '../utils.dart'; | |
| 18 import '../utils/multiset.dart'; | 19 import '../utils/multiset.dart'; |
| 19 import 'asset_cascade.dart'; | 20 import 'asset_cascade.dart'; |
| 20 import 'group_runner.dart'; | 21 import 'group_runner.dart'; |
| 21 import 'node_status.dart'; | 22 import 'node_status.dart'; |
| 22 import 'node_streams.dart'; | 23 import 'node_streams.dart'; |
| 23 import 'phase_forwarder.dart'; | 24 import 'phase_forwarder.dart'; |
| 24 import 'phase_output.dart'; | 25 import 'phase_output.dart'; |
| 25 import 'transformer_classifier.dart'; | 26 import 'transformer_classifier.dart'; |
| 26 | 27 |
| 27 /// One phase in the ordered series of transformations in an [AssetCascade]. | 28 /// One phase in the ordered series of transformations in an [AssetCascade]. |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 // avoid this, we should have this and the methods it calls take explicit | 199 // avoid this, we should have this and the methods it calls take explicit |
| 199 // callbacks, as in [AssetNode.whenAvailable]. | 200 // callbacks, as in [AssetNode.whenAvailable]. |
| 200 /// Gets the asset node for an output [id]. | 201 /// Gets the asset node for an output [id]. |
| 201 /// | 202 /// |
| 202 /// If [id] is for a generated or transformed asset, this will wait until it | 203 /// If [id] is for a generated or transformed asset, this will wait until it |
| 203 /// has been created and return it. This means that the returned asset will | 204 /// has been created and return it. This means that the returned asset will |
| 204 /// always be [AssetState.AVAILABLE]. | 205 /// always be [AssetState.AVAILABLE]. |
| 205 /// | 206 /// |
| 206 /// If the output cannot be found, returns null. | 207 /// If the output cannot be found, returns null. |
| 207 Future<AssetNode> getOutput(AssetId id) { | 208 Future<AssetNode> getOutput(AssetId id) { |
| 208 return syncFuture(() { | 209 return new Future.sync(() { |
| 209 if (id.package != cascade.package) return cascade.graph.getAssetNode(id); | 210 if (id.package != cascade.package) return cascade.graph.getAssetNode(id); |
| 210 if (_outputs.containsKey(id)) { | 211 if (_outputs.containsKey(id)) { |
| 211 var output = _outputs[id].output; | 212 var output = _outputs[id].output; |
| 212 // If the requested output is available, we can just return it. | 213 // If the requested output is available, we can just return it. |
| 213 if (output.state.isAvailable) return output; | 214 if (output.state.isAvailable) return output; |
| 214 | 215 |
| 215 // If the requested output exists but isn't yet available, wait to see | 216 // If the requested output exists but isn't yet available, wait to see |
| 216 // if it becomes available. If it's removed before becoming available, | 217 // if it becomes available. If it's removed before becoming available, |
| 217 // try again, since it could be generated again. | 218 // try again, since it could be generated again. |
| 218 output.force(); | 219 output.force(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 this, transformer, "$_location.$_index"); | 252 this, transformer, "$_location.$_index"); |
| 252 _classifiers[transformer] = classifier; | 253 _classifiers[transformer] = classifier; |
| 253 classifier.onAsset.listen(_handleOutput); | 254 classifier.onAsset.listen(_handleOutput); |
| 254 _streams.onLogPool.add(classifier.onLog); | 255 _streams.onLogPool.add(classifier.onLog); |
| 255 classifier.onStatusChange.listen((_) => _streams.changeStatus(status)); | 256 classifier.onStatusChange.listen((_) => _streams.changeStatus(status)); |
| 256 for (var input in _inputs) { | 257 for (var input in _inputs) { |
| 257 classifier.addInput(input); | 258 classifier.addInput(input); |
| 258 } | 259 } |
| 259 } | 260 } |
| 260 | 261 |
| 261 var newGroups = transformers.where((op) => op is TransformerGroup) | 262 var newGroups = DelegatingSet.typed/*<TransformerGroup>*/( |
| 262 .toSet(); | 263 transformers.where((op) => op is TransformerGroup).toSet()); |
| 263 var oldGroups = _groups.keys.toSet(); | 264 var oldGroups = _groups.keys.toSet(); |
| 264 for (var removed in oldGroups.difference(newGroups)) { | 265 for (var removed in oldGroups.difference(newGroups)) { |
| 265 _groups.remove(removed).remove(); | 266 _groups.remove(removed).remove(); |
| 266 } | 267 } |
| 267 | 268 |
| 268 for (var added in newGroups.difference(oldGroups)) { | 269 for (var added in newGroups.difference(oldGroups)) { |
| 269 var runner = new GroupRunner(previous, added, "$_location.$_index"); | 270 var runner = new GroupRunner(previous, added, "$_location.$_index"); |
| 270 _groups[added] = runner; | 271 _groups[added] = runner; |
| 271 runner.onAsset.listen(_handleOutput); | 272 runner.onAsset.listen(_handleOutput); |
| 272 _streams.onLogPool.add(runner.onLog); | 273 _streams.onLogPool.add(runner.onLog); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 return; | 383 return; |
| 383 } | 384 } |
| 384 | 385 |
| 385 // A lazy asset may be emitted while still dirty. If so, we wait until it's | 386 // A lazy asset may be emitted while still dirty. If so, we wait until it's |
| 386 // either available or removed before trying again to access it. | 387 // either available or removed before trying again to access it. |
| 387 assert(asset.state.isDirty); | 388 assert(asset.state.isDirty); |
| 388 asset.force(); | 389 asset.force(); |
| 389 asset.whenStateChanges().then((state) { | 390 asset.whenStateChanges().then((state) { |
| 390 if (state.isRemoved) return getOutput(asset.id); | 391 if (state.isRemoved) return getOutput(asset.id); |
| 391 return asset; | 392 return asset; |
| 392 }).then(request.complete).catchError(request.completeError); | 393 }) |
| 394 .then((asset) => request.complete(asset)) |
| 395 .catchError(request.completeError); |
| 393 } | 396 } |
| 394 | 397 |
| 395 String toString() => "phase $_location.$_index"; | 398 String toString() => "phase $_location.$_index"; |
| 396 } | 399 } |
| OLD | NEW |