OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library barback.graph.static_asset_cascade; | |
6 | |
7 import 'dart:async'; | |
8 | |
9 import '../asset/asset_id.dart'; | |
10 import '../asset/asset_node.dart'; | |
11 import '../asset/asset_set.dart'; | |
12 import '../errors.dart'; | |
13 import '../log.dart'; | |
14 import '../package_provider.dart'; | |
15 import 'asset_cascade.dart'; | |
16 import 'node_status.dart'; | |
17 import 'package_graph.dart'; | |
18 | |
19 /// An asset cascade for a static package. | |
20 /// | |
21 /// A static package is known to have no transformers and no changes to its | |
22 /// assets. This allows this class to lazily and efficiently provide assets to | |
23 /// the rest of the package graph. | |
24 class StaticAssetCascade implements AssetCascade { | |
25 final String package; | |
26 | |
27 final PackageGraph graph; | |
28 | |
29 /// All sources that have been requested from the provider. | |
30 final _sources = new Map<AssetId, Future<AssetNode>>(); | |
31 | |
32 StaticAssetCascade(this.graph, this.package); | |
33 | |
34 Stream<BarbackException> get errors => _errorsController.stream; | |
35 final _errorsController = | |
36 new StreamController<BarbackException>.broadcast(sync: true); | |
37 | |
38 final status = NodeStatus.IDLE; | |
39 | |
40 final onLog = new StreamController<LogEntry>.broadcast().stream; | |
41 final onStatusChange = new StreamController<LogEntry>.broadcast().stream; | |
42 final onAsset = new StreamController<AssetNode>.broadcast().stream; | |
43 | |
44 Future<AssetSet> get availableOutputs { | |
45 var provider = graph.provider as StaticPackageProvider; | |
46 return provider.getAllAssetIds(package).asyncMap(provider.getAsset).toList() | |
47 .then((assets) => new AssetSet.from(assets)); | |
48 } | |
49 | |
50 Future<AssetNode> getAssetNode(AssetId id) { | |
51 return _sources.putIfAbsent(id, () { | |
52 return graph.provider.getAsset(id).then((asset) { | |
53 return new AssetNodeController.available(asset).node; | |
54 }).catchError((error, stackTrace) { | |
55 if (error is! AssetNotFoundException) { | |
56 reportError(new AssetLoadException(id, error, stackTrace)); | |
57 } | |
58 | |
59 // TODO(nweiz): propagate error information through asset nodes. | |
60 return null; | |
61 }); | |
62 }); | |
63 } | |
64 | |
65 void updateSources(Iterable<AssetId> sources) => | |
66 throw new UnsupportedError("Static package $package can't be explicitly " | |
67 "provided sources."); | |
68 | |
69 void removeSources(Iterable<AssetId> sources) => | |
70 throw new UnsupportedError("Static package $package can't be explicitly " | |
71 "provided sources."); | |
72 | |
73 void updateTransformers(Iterable<Iterable> transformersIterable) => | |
74 throw new UnsupportedError("Static package $package can't have " | |
75 "transformers."); | |
76 | |
77 void forceAllTransforms() {} | |
78 | |
79 void reportError(BarbackException error) => _errorsController.add(error); | |
80 | |
81 String toString() => "static cascade for $package"; | |
82 } | |
OLD | NEW |