| 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.package_graph; | 5 library barback.graph.package_graph; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import '../asset/asset_id.dart'; | 10 import '../asset/asset_id.dart'; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 120 } |
| 121 | 121 |
| 122 /// Gets the asset node identified by [id]. | 122 /// Gets the asset node identified by [id]. |
| 123 /// | 123 /// |
| 124 /// If [id] is for a generated or transformed asset, this will wait until it | 124 /// If [id] is for a generated or transformed asset, this will wait until it |
| 125 /// has been created and return it. This means that the returned asset will | 125 /// has been created and return it. This means that the returned asset will |
| 126 /// always be [AssetState.AVAILABLE]. | 126 /// always be [AssetState.AVAILABLE]. |
| 127 /// | 127 /// |
| 128 /// If the asset cannot be found, returns null. | 128 /// If the asset cannot be found, returns null. |
| 129 Future<AssetNode> getAssetNode(AssetId id) { | 129 Future<AssetNode> getAssetNode(AssetId id) { |
| 130 return _inErrorZone(() { | 130 return _inErrorZone/*<Future<AssetNode>>*/(() { |
| 131 var cascade = _cascades[id.package]; | 131 var cascade = _cascades[id.package]; |
| 132 if (cascade != null) return cascade.getAssetNode(id); | 132 if (cascade != null) return cascade.getAssetNode(id); |
| 133 return new Future.value(null); | 133 return new Future.value(null); |
| 134 }); | 134 }); |
| 135 } | 135 } |
| 136 | 136 |
| 137 /// Returns the stream of newly-emitted assets for the given package's | 137 /// Returns the stream of newly-emitted assets for the given package's |
| 138 /// cascade. | 138 /// cascade. |
| 139 /// | 139 /// |
| 140 /// If there's no cascade for [package], returns `null`. | 140 /// If there's no cascade for [package], returns `null`. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 151 /// | 151 /// |
| 152 /// Any transforms using [LazyTransformer]s will be forced to generate | 152 /// Any transforms using [LazyTransformer]s will be forced to generate |
| 153 /// concrete outputs, and those outputs will be returned. | 153 /// concrete outputs, and those outputs will be returned. |
| 154 Future<AssetSet> getAllAssets() { | 154 Future<AssetSet> getAllAssets() { |
| 155 for (var cascade in _cascades.values) { | 155 for (var cascade in _cascades.values) { |
| 156 _inErrorZone(() => cascade.forceAllTransforms()); | 156 _inErrorZone(() => cascade.forceAllTransforms()); |
| 157 } | 157 } |
| 158 | 158 |
| 159 if (_status != NodeStatus.IDLE) { | 159 if (_status != NodeStatus.IDLE) { |
| 160 // A build is still ongoing, so wait for it to complete and try again. | 160 // A build is still ongoing, so wait for it to complete and try again. |
| 161 return results.first.then((_) => getAllAssets()); | 161 return results.first.then/*<Future<AssetSet>>*/((_) => getAllAssets()); |
| 162 } | 162 } |
| 163 | 163 |
| 164 // If an unexpected error occurred, complete with that. | 164 // If an unexpected error occurred, complete with that. |
| 165 if (_lastUnexpectedError != null) { | 165 if (_lastUnexpectedError != null) { |
| 166 var error = _lastUnexpectedError; | 166 var error = _lastUnexpectedError; |
| 167 _lastUnexpectedError = null; | 167 _lastUnexpectedError = null; |
| 168 return new Future.error(error, _lastUnexpectedErrorTrace); | 168 return new Future.error(error, _lastUnexpectedErrorTrace); |
| 169 } | 169 } |
| 170 | 170 |
| 171 // If the last build completed with an error, complete the future with it. | 171 // If the last build completed with an error, complete the future with it. |
| 172 if (!_lastResult.succeeded) { | 172 if (!_lastResult.succeeded) { |
| 173 return new Future.error(BarbackException.aggregate(_lastResult.errors)); | 173 return new Future.error(BarbackException.aggregate(_lastResult.errors)); |
| 174 } | 174 } |
| 175 | 175 |
| 176 // Otherwise, return all of the final output assets. | 176 // Otherwise, return all of the final output assets. |
| 177 return Future.wait(_cascades.values.map( | 177 return Future.wait(_cascades.values.map( |
| 178 (cascade) => cascade.availableOutputs)) | 178 (cascade) => cascade.availableOutputs)) |
| 179 .then((assetSets) { | 179 .then((assetSets) { |
| 180 var assets = unionAll(assetSets.map((assetSet) => assetSet.toSet())); | 180 var assets = unionAll(assetSets.map((assetSet) => assetSet.toSet())); |
| 181 return new Future.value(new AssetSet.from(assets)); | 181 return new AssetSet.from(assets); |
| 182 }); | 182 }); |
| 183 } | 183 } |
| 184 | 184 |
| 185 /// Adds [sources] to the graph's known set of source assets. | 185 /// Adds [sources] to the graph's known set of source assets. |
| 186 /// | 186 /// |
| 187 /// Begins applying any transforms that can consume any of the sources. If a | 187 /// Begins applying any transforms that can consume any of the sources. If a |
| 188 /// given source is already known, it is considered modified and all | 188 /// given source is already known, it is considered modified and all |
| 189 /// transforms that use it will be re-applied. | 189 /// transforms that use it will be re-applied. |
| 190 void updateSources(Iterable<AssetId> sources) { | 190 void updateSources(Iterable<AssetId> sources) { |
| 191 groupBy(sources, (id) => id.package).forEach((package, ids) { | 191 groupBy(sources, (id) => id.package).forEach((package, ids) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 }); | 267 }); |
| 268 } | 268 } |
| 269 | 269 |
| 270 /// Run [body] in an error-handling [Zone] and pipe any unexpected errors to | 270 /// Run [body] in an error-handling [Zone] and pipe any unexpected errors to |
| 271 /// the error channel of [results]. | 271 /// the error channel of [results]. |
| 272 /// | 272 /// |
| 273 /// [body] can return a value or a [Future] that will be piped to the returned | 273 /// [body] can return a value or a [Future] that will be piped to the returned |
| 274 /// [Future]. If it throws a [BarbackException], that exception will be piped | 274 /// [Future]. If it throws a [BarbackException], that exception will be piped |
| 275 /// to the returned [Future] as well. Any other exceptions will be piped to | 275 /// to the returned [Future] as well. Any other exceptions will be piped to |
| 276 /// [results]. | 276 /// [results]. |
| 277 Future _inErrorZone(body()) { | 277 Future/*<T>*/ _inErrorZone/*<T>*/(/*=T*/ body()) { |
| 278 var completer = new Completer.sync(); | 278 var completer = new Completer/*<T>*/.sync(); |
| 279 runZoned(() { | 279 runZoned(() { |
| 280 syncFuture(body).then(completer.complete).catchError((error, stackTrace) { | 280 new Future.sync(body).then(completer.complete) |
| 281 .catchError((error, stackTrace) { |
| 281 if (error is! BarbackException) throw error; | 282 if (error is! BarbackException) throw error; |
| 282 completer.completeError(error, stackTrace); | 283 completer.completeError(error, stackTrace); |
| 283 }); | 284 }); |
| 284 }, onError: (error, stackTrace) { | 285 }, onError: (error, stackTrace) { |
| 285 _lastUnexpectedError = error; | 286 _lastUnexpectedError = error; |
| 286 _lastUnexpectedErrorTrace = stackTrace; | 287 _lastUnexpectedErrorTrace = stackTrace; |
| 287 _resultsController.addError(error, stackTrace); | 288 _resultsController.addError(error, stackTrace); |
| 288 }); | 289 }); |
| 289 return completer.future; | 290 return completer.future; |
| 290 } | 291 } |
| 291 } | 292 } |
| OLD | NEW |