| 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 'asset_cascade.dart'; | 9 import 'asset_cascade.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 'build_result.dart'; | 13 import 'build_result.dart'; |
| 13 import 'errors.dart'; | 14 import 'errors.dart'; |
| 14 import 'package_provider.dart'; | 15 import 'package_provider.dart'; |
| 15 import 'utils.dart'; | 16 import 'utils.dart'; |
| 16 | 17 |
| 17 /// The collection of [AssetCascade]s for an entire application. | 18 /// The collection of [AssetCascade]s for an entire application. |
| 18 /// | 19 /// |
| 19 /// This tracks each package's [AssetCascade] and routes asset requests between | 20 /// This tracks each package's [AssetCascade] and routes asset requests between |
| 20 /// them. | 21 /// them. |
| 21 class PackageGraph { | 22 class PackageGraph { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 /// has been created and return it. This means that the returned asset will | 86 /// has been created and return it. This means that the returned asset will |
| 86 /// always be [AssetState.AVAILABLE]. | 87 /// always be [AssetState.AVAILABLE]. |
| 87 /// | 88 /// |
| 88 /// If the asset cannot be found, returns null. | 89 /// If the asset cannot be found, returns null. |
| 89 Future<AssetNode> getAssetNode(AssetId id) { | 90 Future<AssetNode> getAssetNode(AssetId id) { |
| 90 var cascade = _cascades[id.package]; | 91 var cascade = _cascades[id.package]; |
| 91 if (cascade != null) return cascade.getAssetNode(id); | 92 if (cascade != null) return cascade.getAssetNode(id); |
| 92 return new Future.value(null); | 93 return new Future.value(null); |
| 93 } | 94 } |
| 94 | 95 |
| 96 /// Gets all output assets. |
| 97 /// |
| 98 /// If a build is currently in progress, waits until it completes. The |
| 99 /// returned future will complete with an error if the build is not |
| 100 /// successful. |
| 101 Future<AssetSet> getAllAssets() { |
| 102 if (_cascadeResults.values.contains(null)) { |
| 103 // A build is still ongoing, so wait for it to complete and try again. |
| 104 return results.first.then((_) => getAllAssets()); |
| 105 } |
| 106 |
| 107 // If the build completed with an error, complete the future with it. |
| 108 var errors = unionAll( |
| 109 _cascadeResults.values.map((result) => result.errors)); |
| 110 if (errors.isNotEmpty) { |
| 111 return new Future.error(BarbackException.aggregate(errors)); |
| 112 } |
| 113 |
| 114 // Otherwise, return all of the final output assets. |
| 115 var assets = unionAll(_cascades.values.map( |
| 116 (cascade) => cascade.availableOutputs.toSet())); |
| 117 |
| 118 return new Future.value(new AssetSet.from(assets)); |
| 119 } |
| 120 |
| 95 /// Adds [sources] to the graph's known set of source assets. | 121 /// Adds [sources] to the graph's known set of source assets. |
| 96 /// | 122 /// |
| 97 /// Begins applying any transforms that can consume any of the sources. If a | 123 /// Begins applying any transforms that can consume any of the sources. If a |
| 98 /// given source is already known, it is considered modified and all | 124 /// given source is already known, it is considered modified and all |
| 99 /// transforms that use it will be re-applied. | 125 /// transforms that use it will be re-applied. |
| 100 void updateSources(Iterable<AssetId> sources) { | 126 void updateSources(Iterable<AssetId> sources) { |
| 101 groupBy(sources, (id) => id.package).forEach((package, ids) { | 127 groupBy(sources, (id) => id.package).forEach((package, ids) { |
| 102 var cascade = _cascades[package]; | 128 var cascade = _cascades[package]; |
| 103 if (cascade == null) throw new ArgumentError("Unknown package $package."); | 129 if (cascade == null) throw new ArgumentError("Unknown package $package."); |
| 104 _cascadeResults[package] = null; | 130 _cascadeResults[package] = null; |
| 105 cascade.updateSources(ids); | 131 cascade.updateSources(ids); |
| 106 }); | 132 }); |
| 107 } | 133 } |
| 108 | 134 |
| 109 /// Removes [removed] from the graph's known set of source assets. | 135 /// Removes [removed] from the graph's known set of source assets. |
| 110 void removeSources(Iterable<AssetId> sources) { | 136 void removeSources(Iterable<AssetId> sources) { |
| 111 groupBy(sources, (id) => id.package).forEach((package, ids) { | 137 groupBy(sources, (id) => id.package).forEach((package, ids) { |
| 112 var cascade = _cascades[package]; | 138 var cascade = _cascades[package]; |
| 113 if (cascade == null) throw new ArgumentError("Unknown package $package."); | 139 if (cascade == null) throw new ArgumentError("Unknown package $package."); |
| 114 _cascadeResults[package] = null; | 140 _cascadeResults[package] = null; |
| 115 cascade.removeSources(ids); | 141 cascade.removeSources(ids); |
| 116 }); | 142 }); |
| 117 } | 143 } |
| 118 } | 144 } |
| OLD | NEW |