| 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.asset_cascade; | 5 library barback.asset_cascade; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'asset.dart'; | 9 import 'asset.dart'; |
| 10 import 'asset_id.dart'; | 10 import 'asset_id.dart'; |
| 11 import 'asset_node.dart'; | 11 import 'asset_node.dart'; |
| 12 import 'asset_set.dart'; | 12 import 'asset_set.dart'; |
| 13 import 'log.dart'; | |
| 14 import 'cancelable_future.dart'; | 13 import 'cancelable_future.dart'; |
| 15 import 'errors.dart'; | 14 import 'errors.dart'; |
| 15 import 'log.dart'; |
| 16 import 'node_status.dart'; |
| 16 import 'node_streams.dart'; | 17 import 'node_streams.dart'; |
| 17 import 'package_graph.dart'; | 18 import 'package_graph.dart'; |
| 18 import 'phase.dart'; | 19 import 'phase.dart'; |
| 19 import 'transformer.dart'; | 20 import 'transformer.dart'; |
| 20 | 21 |
| 21 /// The asset cascade for an individual package. | 22 /// The asset cascade for an individual package. |
| 22 /// | 23 /// |
| 23 /// This keeps track of which [Transformer]s are applied to which assets, and | 24 /// This keeps track of which [Transformer]s are applied to which assets, and |
| 24 /// re-runs those transformers when their dependencies change. The transformed | 25 /// re-runs those transformers when their dependencies change. The transformed |
| 25 /// asset nodes are accessible via [getAssetNode]. | 26 /// asset nodes are accessible via [getAssetNode]. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 48 /// one. | 49 /// one. |
| 49 final _loadingSources = new Map<AssetId, CancelableFuture<Asset>>(); | 50 final _loadingSources = new Map<AssetId, CancelableFuture<Asset>>(); |
| 50 | 51 |
| 51 /// The list of phases in this cascade. | 52 /// The list of phases in this cascade. |
| 52 /// | 53 /// |
| 53 /// This will always contain at least one phase, and the first phase will | 54 /// This will always contain at least one phase, and the first phase will |
| 54 /// never have any transformers. This ensures that every transformer can | 55 /// never have any transformers. This ensures that every transformer can |
| 55 /// request inputs from a previous phase. | 56 /// request inputs from a previous phase. |
| 56 final _phases = <Phase>[]; | 57 final _phases = <Phase>[]; |
| 57 | 58 |
| 58 /// The subscription to the [Phase.onDone] stream of the last [Phase] in | 59 /// The subscription to the [Phase.onStatusChange] stream of the last [Phase] |
| 59 /// [_phases]. | 60 /// in [_phases]. |
| 60 StreamSubscription _phaseOnDoneSubscription; | 61 StreamSubscription _phaseStatusSubscription; |
| 61 | 62 |
| 62 /// A stream that emits any errors from the cascade or the transformers. | 63 /// A stream that emits any errors from the cascade or the transformers. |
| 63 /// | 64 /// |
| 64 /// This emits errors as they're detected. If an error occurs in one part of | 65 /// This emits errors as they're detected. If an error occurs in one part of |
| 65 /// the cascade, unrelated parts will continue building. | 66 /// the cascade, unrelated parts will continue building. |
| 66 Stream<BarbackException> get errors => _errorsController.stream; | 67 Stream<BarbackException> get errors => _errorsController.stream; |
| 67 final _errorsController = | 68 final _errorsController = |
| 68 new StreamController<BarbackException>.broadcast(sync: true); | 69 new StreamController<BarbackException>.broadcast(sync: true); |
| 69 | 70 |
| 70 /// Whether [this] is dirty and still has more processing to do. | 71 /// How far along [this] is in processing its assets. |
| 71 bool get isDirty { | 72 NodeStatus get status { |
| 72 // Just check the last phase, since it will check all the previous phases | 73 // Just check the last phase, since it will check all the previous phases |
| 73 // itself. | 74 // itself. |
| 74 return _phases.last.isDirty; | 75 return _phases.last.status; |
| 75 } | 76 } |
| 76 | 77 |
| 77 /// The streams exposed by this cascade. | 78 /// The streams exposed by this cascade. |
| 78 final _streams = new NodeStreams(); | 79 final _streams = new NodeStreams(); |
| 79 Stream<LogEntry> get onLog => _streams.onLog; | 80 Stream<LogEntry> get onLog => _streams.onLog; |
| 80 Stream get onDone => _streams.onDone; | 81 Stream<NodeStatus> get onStatusChange => _streams.onStatusChange; |
| 81 | 82 |
| 82 /// Returns all currently-available output assets from this cascade. | 83 /// Returns all currently-available output assets from this cascade. |
| 83 AssetSet get availableOutputs => | 84 AssetSet get availableOutputs => |
| 84 new AssetSet.from(_phases.last.availableOutputs.map((node) => node.asset)); | 85 new AssetSet.from(_phases.last.availableOutputs.map((node) => node.asset)); |
| 85 | 86 |
| 86 /// Creates a new [AssetCascade]. | 87 /// Creates a new [AssetCascade]. |
| 87 /// | 88 /// |
| 88 /// It loads source assets within [package] using [provider]. | 89 /// It loads source assets within [package] using [provider]. |
| 89 AssetCascade(this.graph, this.package) { | 90 AssetCascade(this.graph, this.package) { |
| 90 _addPhase(new Phase(this, package)); | 91 _addPhase(new Phase(this, package)); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 var phase = _phases.last.addPhase(); | 184 var phase = _phases.last.addPhase(); |
| 184 _addPhase(phase); | 185 _addPhase(phase); |
| 185 phase.updateTransformers(transformers[i]); | 186 phase.updateTransformers(transformers[i]); |
| 186 } | 187 } |
| 187 | 188 |
| 188 for (var i = transformers.length + 1; i < _phases.length; i++) { | 189 for (var i = transformers.length + 1; i < _phases.length; i++) { |
| 189 _phases[i].remove(); | 190 _phases[i].remove(); |
| 190 } | 191 } |
| 191 _phases.removeRange(transformers.length + 1, _phases.length); | 192 _phases.removeRange(transformers.length + 1, _phases.length); |
| 192 | 193 |
| 193 _phaseOnDoneSubscription.cancel(); | 194 _phaseStatusSubscription.cancel(); |
| 194 _phaseOnDoneSubscription = _phases.last.onDone | 195 _phaseStatusSubscription = _phases.last.onStatusChange |
| 195 .listen(_streams.onDoneController.add); | 196 .listen(_streams.changeStatus); |
| 196 } | 197 } |
| 197 | 198 |
| 198 /// Force all [LazyTransformer]s' transforms in this cascade to begin | 199 /// Force all [LazyTransformer]s' transforms in this cascade to begin |
| 199 /// producing concrete assets. | 200 /// producing concrete assets. |
| 200 void forceAllTransforms() { | 201 void forceAllTransforms() { |
| 201 for (var phase in _phases) { | 202 for (var phase in _phases) { |
| 202 phase.forceAllTransforms(); | 203 phase.forceAllTransforms(); |
| 203 } | 204 } |
| 204 } | 205 } |
| 205 | 206 |
| 206 void reportError(BarbackException error) { | 207 void reportError(BarbackException error) { |
| 207 _errorsController.add(error); | 208 _errorsController.add(error); |
| 208 } | 209 } |
| 209 | 210 |
| 210 /// Add [phase] to the end of [_phases] and watch its streams. | 211 /// Add [phase] to the end of [_phases] and watch its streams. |
| 211 void _addPhase(Phase phase) { | 212 void _addPhase(Phase phase) { |
| 212 _streams.onLogPool.add(phase.onLog); | 213 _streams.onLogPool.add(phase.onLog); |
| 213 if (_phaseOnDoneSubscription != null) _phaseOnDoneSubscription.cancel(); | 214 if (_phaseStatusSubscription != null) _phaseStatusSubscription.cancel(); |
| 214 _phaseOnDoneSubscription = | 215 _phaseStatusSubscription = |
| 215 phase.onDone.listen(_streams.onDoneController.add); | 216 phase.onStatusChange.listen(_streams.changeStatus); |
| 216 | 217 |
| 217 _phases.add(phase); | 218 _phases.add(phase); |
| 218 } | 219 } |
| 219 | 220 |
| 220 String toString() => "cascade for $package"; | 221 String toString() => "cascade for $package"; |
| 221 } | 222 } |
| OLD | NEW |