| 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 library barback.base_transform; | 5 library barback.base_transform; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'asset.dart'; | 10 import 'asset.dart'; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 /// This class provides the transformers with inputs, but its up to the | 22 /// This class provides the transformers with inputs, but its up to the |
| 23 /// subclasses to provide a means of emitting outputs. | 23 /// subclasses to provide a means of emitting outputs. |
| 24 abstract class BaseTransform { | 24 abstract class BaseTransform { |
| 25 final TransformNode _node; | 25 final TransformNode _node; |
| 26 | 26 |
| 27 /// Whether the primary input should be consumed. | 27 /// Whether the primary input should be consumed. |
| 28 /// | 28 /// |
| 29 /// This is exposed via [BaseTransformController]. | 29 /// This is exposed via [BaseTransformController]. |
| 30 bool _consumePrimary = false; | 30 bool _consumePrimary = false; |
| 31 | 31 |
| 32 /// Whether the transformer logged an error. |
| 33 /// |
| 34 /// This is exposed via [BaseTransformController]. |
| 35 bool _loggedError = false; |
| 36 |
| 32 /// The controller for the stream of log entries emitted by the transformer. | 37 /// The controller for the stream of log entries emitted by the transformer. |
| 33 /// | 38 /// |
| 34 /// This is exposed via [BaseTransformController]. | 39 /// This is exposed via [BaseTransformController]. |
| 35 /// | 40 /// |
| 36 /// This is synchronous because error logs can cause the transform to fail, so | 41 /// This is synchronous because error logs can cause the transform to fail, so |
| 37 /// we need to ensure that their processing isn't delayed until after the | 42 /// we need to ensure that their processing isn't delayed until after the |
| 38 /// transform or build has finished. | 43 /// transform or build has finished. |
| 39 final _onLogController = new StreamController<LogEntry>.broadcast(sync: true); | 44 final _onLogController = new StreamController<LogEntry>.broadcast(sync: true); |
| 40 | 45 |
| 41 /// A logger so that the [Transformer] can report build details. | 46 /// A logger so that the [Transformer] can report build details. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 60 Asset get primaryInput { | 65 Asset get primaryInput { |
| 61 if (_node.primary.state != AssetState.AVAILABLE) { | 66 if (_node.primary.state != AssetState.AVAILABLE) { |
| 62 throw new AssetNotFoundException(_node.primary.id); | 67 throw new AssetNotFoundException(_node.primary.id); |
| 63 } | 68 } |
| 64 | 69 |
| 65 return _node.primary.asset; | 70 return _node.primary.asset; |
| 66 } | 71 } |
| 67 | 72 |
| 68 BaseTransform(this._node) { | 73 BaseTransform(this._node) { |
| 69 _logger = new TransformLogger((asset, level, message, span) { | 74 _logger = new TransformLogger((asset, level, message, span) { |
| 75 if (level == LogLevel.ERROR) _loggedError = true; |
| 76 |
| 70 // If the log isn't already associated with an asset, use the primary. | 77 // If the log isn't already associated with an asset, use the primary. |
| 71 if (asset == null) asset = _node.primary.id; | 78 if (asset == null) asset = _node.primary.id; |
| 72 var entry = new LogEntry(_node.info, asset, level, message, span); | 79 var entry = new LogEntry(_node.info, asset, level, message, span); |
| 73 _onLogController.add(entry); | 80 _onLogController.add(entry); |
| 74 }); | 81 }); |
| 75 } | 82 } |
| 76 | 83 |
| 77 /// Gets the asset for an input [id]. | 84 /// Gets the asset for an input [id]. |
| 78 /// | 85 /// |
| 79 /// If an input with that ID cannot be found, throws an | 86 /// If an input with that ID cannot be found, throws an |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 /// | 123 /// |
| 117 /// Controllers are used so that [TransformNode]s can get values from a | 124 /// Controllers are used so that [TransformNode]s can get values from a |
| 118 /// [BaseTransform] without exposing getters in the public API. | 125 /// [BaseTransform] without exposing getters in the public API. |
| 119 abstract class BaseTransformController { | 126 abstract class BaseTransformController { |
| 120 /// The [BaseTransform] controlled by this controller. | 127 /// The [BaseTransform] controlled by this controller. |
| 121 final BaseTransform transform; | 128 final BaseTransform transform; |
| 122 | 129 |
| 123 /// Whether the primary input should be consumed. | 130 /// Whether the primary input should be consumed. |
| 124 bool get consumePrimary => transform._consumePrimary; | 131 bool get consumePrimary => transform._consumePrimary; |
| 125 | 132 |
| 133 /// Whether the transform logged an error. |
| 134 bool get loggedError => transform._loggedError; |
| 135 |
| 126 /// The stream of log entries emitted by the transformer during a run. | 136 /// The stream of log entries emitted by the transformer during a run. |
| 127 Stream<LogEntry> get onLog => transform._onLogController.stream; | 137 Stream<LogEntry> get onLog => transform._onLogController.stream; |
| 128 | 138 |
| 129 BaseTransformController(this.transform); | 139 BaseTransformController(this.transform); |
| 130 | 140 |
| 131 /// Notifies the [BaseTransform] that the transformation has finished being | 141 /// Notifies the [BaseTransform] that the transformation has finished being |
| 132 /// applied. | 142 /// applied. |
| 133 /// | 143 /// |
| 134 /// This will close any streams and release any resources that were allocated | 144 /// This will close any streams and release any resources that were allocated |
| 135 /// for the duration of the transformation. | 145 /// for the duration of the transformation. |
| 136 void close() { | 146 void close() { |
| 137 transform._onLogController.close(); | 147 transform._onLogController.close(); |
| 138 } | 148 } |
| 139 } | 149 } |
| OLD | NEW |