| 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.package_graph; | 5 library barback.package_graph; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
| 10 | 10 |
| 11 import 'asset.dart'; | 11 import 'asset.dart'; |
| 12 import 'asset_cascade.dart'; | 12 import 'asset_cascade.dart'; |
| 13 import 'asset_id.dart'; | 13 import 'asset_id.dart'; |
| 14 import 'asset_node.dart'; |
| 15 import 'build_result.dart'; |
| 14 import 'errors.dart'; | 16 import 'errors.dart'; |
| 15 import 'package_provider.dart'; | 17 import 'package_provider.dart'; |
| 16 import 'utils.dart'; | 18 import 'utils.dart'; |
| 17 | 19 |
| 18 /// The collection of [AssetCascade]s for an entire application. | 20 /// The collection of [AssetCascade]s for an entire application. |
| 19 /// | 21 /// |
| 20 /// This tracks each package's [AssetCascade] and routes asset requests between | 22 /// This tracks each package's [AssetCascade] and routes asset requests between |
| 21 /// them. | 23 /// them. |
| 22 class PackageGraph { | 24 class PackageGraph { |
| 23 /// The provider that exposes asset and package information. | 25 /// The provider that exposes asset and package information. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // Include all build errors for all cascades. If no cascades have | 75 // Include all build errors for all cascades. If no cascades have |
| 74 // errors, the result will automatically be considered a success. | 76 // errors, the result will automatically be considered a success. |
| 75 _resultsController.add(new BuildResult(flatten( | 77 _resultsController.add(new BuildResult(flatten( |
| 76 _cascadeResults.values.map((result) => result.errors)))); | 78 _cascadeResults.values.map((result) => result.errors)))); |
| 77 }, onError: _resultsController.addError); | 79 }, onError: _resultsController.addError); |
| 78 } | 80 } |
| 79 | 81 |
| 80 _errors = mergeStreams(_cascades.values.map((cascade) => cascade.errors)); | 82 _errors = mergeStreams(_cascades.values.map((cascade) => cascade.errors)); |
| 81 } | 83 } |
| 82 | 84 |
| 83 /// Gets the asset identified by [id]. | 85 /// Gets the asset node identified by [id]. |
| 84 /// | 86 /// |
| 85 /// If [id] is for a generated or transformed asset, this will wait until | 87 /// If [id] is for a generated or transformed asset, this will wait until |
| 86 /// it has been created and return it. If the asset cannot be found, throws | 88 /// it has been created and return it. If the asset cannot be found, throws |
| 87 /// [AssetNotFoundException]. | 89 /// [AssetNotFoundException]. |
| 88 Future<Asset> getAssetById(AssetId id) { | 90 Future<AssetNode> getAssetNode(AssetId id) { |
| 89 var cascade = _cascades[id.package]; | 91 var cascade = _cascades[id.package]; |
| 90 if (cascade != null) return cascade.getAssetById(id); | 92 if (cascade != null) return cascade.getAssetNode(id); |
| 91 return new Future.error( | 93 return new Future.error( |
| 92 new AssetNotFoundException(id), | 94 new AssetNotFoundException(id), |
| 93 new Trace.current().vmTrace); | 95 new Trace.current().vmTrace); |
| 94 } | 96 } |
| 95 | 97 |
| 96 /// Adds [sources] to the graph's known set of source assets. | 98 /// Adds [sources] to the graph's known set of source assets. |
| 97 /// | 99 /// |
| 98 /// Begins applying any transforms that can consume any of the sources. If a | 100 /// Begins applying any transforms that can consume any of the sources. If a |
| 99 /// given source is already known, it is considered modified and all | 101 /// given source is already known, it is considered modified and all |
| 100 /// transforms that use it will be re-applied. | 102 /// transforms that use it will be re-applied. |
| 101 void updateSources(Iterable<AssetId> sources) { | 103 void updateSources(Iterable<AssetId> sources) { |
| 102 groupBy(sources, (id) => id.package).forEach((package, ids) { | 104 groupBy(sources, (id) => id.package).forEach((package, ids) { |
| 103 var cascade = _cascades[package]; | 105 var cascade = _cascades[package]; |
| 104 if (cascade == null) throw new ArgumentError("Unknown package $package."); | 106 if (cascade == null) throw new ArgumentError("Unknown package $package."); |
| 105 _cascadeResults[package] = null; | 107 _cascadeResults[package] = null; |
| 106 cascade.updateSources(ids); | 108 cascade.updateSources(ids); |
| 107 }); | 109 }); |
| 108 } | 110 } |
| 109 | 111 |
| 110 /// Removes [removed] from the graph's known set of source assets. | 112 /// Removes [removed] from the graph's known set of source assets. |
| 111 void removeSources(Iterable<AssetId> sources) { | 113 void removeSources(Iterable<AssetId> sources) { |
| 112 groupBy(sources, (id) => id.package).forEach((package, ids) { | 114 groupBy(sources, (id) => id.package).forEach((package, ids) { |
| 113 var cascade = _cascades[package]; | 115 var cascade = _cascades[package]; |
| 114 if (cascade == null) throw new ArgumentError("Unknown package $package."); | 116 if (cascade == null) throw new ArgumentError("Unknown package $package."); |
| 115 _cascadeResults[package] = null; | 117 _cascadeResults[package] = null; |
| 116 cascade.removeSources(ids); | 118 cascade.removeSources(ids); |
| 117 }); | 119 }); |
| 118 } | 120 } |
| 119 } | 121 } |
| OLD | NEW |