Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: pkg/barback/lib/src/asset_cascade.dart

Issue 19402003: Rename several classes in barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/barback/lib/barback.dart ('k') | pkg/barback/lib/src/asset_graph.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.asset_graph; 5 library barback.asset_cascade;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'asset.dart'; 10 import 'asset.dart';
11 import 'asset_id.dart'; 11 import 'asset_id.dart';
12 import 'asset_graph_manager.dart';
13 import 'asset_provider.dart';
14 import 'asset_set.dart'; 12 import 'asset_set.dart';
15 import 'errors.dart'; 13 import 'errors.dart';
16 import 'change_batch.dart'; 14 import 'change_batch.dart';
15 import 'package_graph.dart';
17 import 'phase.dart'; 16 import 'phase.dart';
18 import 'transformer.dart'; 17 import 'transformer.dart';
19 import 'utils.dart'; 18 import 'utils.dart';
20 19
21 /// The asset manager for an individual package. 20 /// The asset cascade for an individual package.
22 /// 21 ///
23 /// This keeps track of which transformers are applied to which assets, and 22 /// This keeps track of which [Transformer]s are applied to which assets, and
24 /// re-runs those transformers when their dependencies change. The transformed 23 /// re-runs those transformers when their dependencies change. The transformed
25 /// assets are accessible via [getAssetById]. 24 /// assets are accessible via [getAssetById].
26 class AssetGraph { 25 ///
26 /// A cascade consists of one or more [Phases], each of which has one or more
27 /// [Transformer]s that run in parallel, potentially on the same inputs. The
28 /// inputs of the first phase are the static assets for this cascade's package
Bob Nystrom 2013/07/16 23:13:04 Instead of the parenthetical, I should just "stati
nweiz 2013/07/17 00:33:55 Done.
29 /// (the cascade's "sources"). The inputs of each successive phase are the
30 /// outputs of the previous phase, as well as any assets that haven't yet been
31 /// transformed.
32 class AssetCascade {
27 /// The name of the package whose assets are managed. 33 /// The name of the package whose assets are managed.
28 final String package; 34 final String package;
29 35
30 /// The [AssetGraphManager] that manages the [AssetGraph]s for all 36 /// The [PackageGraph] that tracks all [AssetCascade]s for all dependencies of
31 /// dependencies of the current app. 37 /// the current app.
32 final AssetGraphManager _manager; 38 final PackageGraph _graph;
33 39
34 final _phases = <Phase>[]; 40 final _phases = <Phase>[];
35 41
36 /// A stream that emits a [BuildResult] each time the build is completed, 42 /// A stream that emits a [BuildResult] each time the build is completed,
37 /// whether or not it succeeded. 43 /// whether or not it succeeded.
38 /// 44 ///
39 /// If an unexpected error in barback itself occurs, it will be emitted 45 /// If an unexpected error in barback itself occurs, it will be emitted
40 /// through this stream's error channel. 46 /// through this stream's error channel.
41 Stream<BuildResult> get results => _resultsController.stream; 47 Stream<BuildResult> get results => _resultsController.stream;
42 final _resultsController = new StreamController<BuildResult>.broadcast(); 48 final _resultsController = new StreamController<BuildResult>.broadcast();
43 49
44 /// A stream that emits any errors from the asset graph or the transformers. 50 /// A stream that emits any errors from the cascade or the transformers.
45 /// 51 ///
46 /// This emits errors as they're detected. If an error occurs in one part of 52 /// This emits errors as they're detected. If an error occurs in one part of
47 /// the asset graph, unrelated parts will continue building. 53 /// the cascade, unrelated parts will continue building.
48 /// 54 ///
49 /// This will not emit programming errors from barback itself. Those will be 55 /// This will not emit programming errors from barback itself. Those will be
50 /// emitted through the [results] stream's error channel. 56 /// emitted through the [results] stream's error channel.
51 Stream get errors => _errorsController.stream; 57 Stream get errors => _errorsController.stream;
52 final _errorsController = new StreamController.broadcast(); 58 final _errorsController = new StreamController.broadcast();
53 59
54 /// The errors that have occurred since the current build started. 60 /// The errors that have occurred since the current build started.
55 /// 61 ///
56 /// This will be empty if no build is occurring. 62 /// This will be empty if no build is occurring.
57 Queue _accumulatedErrors; 63 Queue _accumulatedErrors;
58 64
59 /// A future that completes when the currently running build process finishes. 65 /// A future that completes when the currently running build process finishes.
60 /// 66 ///
61 /// If no build it in progress, is `null`. 67 /// If no build it in progress, is `null`.
62 Future _processDone; 68 Future _processDone;
63 69
64 ChangeBatch _sourceChanges; 70 ChangeBatch _sourceChanges;
65 71
66 /// Creates a new [AssetGraph]. 72 /// Creates a new [AssetCascade].
67 /// 73 ///
68 /// It loads source assets within [package] using [provider] and then uses 74 /// It loads source assets within [package] using [provider] and then uses
69 /// [transformerPhases] to generate output files from them. 75 /// [transformerPhases] to generate output files from them.
70 //TODO(rnystrom): Better way of specifying transformers and their ordering. 76 //TODO(rnystrom): Better way of specifying transformers and their ordering.
71 AssetGraph(this._manager, this.package, 77 AssetCascade(this._graph, this.package,
72 Iterable<Iterable<Transformer>> transformerPhases) { 78 Iterable<Iterable<Transformer>> transformerPhases) {
73 // Flatten the phases to a list so we can traverse backwards to wire up 79 // Flatten the phases to a list so we can traverse backwards to wire up
74 // each phase to its next. 80 // each phase to its next.
75 var phases = transformerPhases.toList(); 81 var phases = transformerPhases.toList();
76 82
77 // Each phase writes its outputs as inputs to the next phase after it. 83 // Each phase writes its outputs as inputs to the next phase after it.
78 // Add a phase at the end for the final outputs of the last phase. 84 // Add a phase at the end for the final outputs of the last phase.
79 phases.add([]); 85 phases.add([]);
80 86
81 Phase nextPhase = null; 87 Phase nextPhase = null;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 229
224 // Take the current batch to ensure it doesn't get added to while we're 230 // Take the current batch to ensure it doesn't get added to while we're
225 // processing it. 231 // processing it.
226 var changes = _sourceChanges; 232 var changes = _sourceChanges;
227 _sourceChanges = null; 233 _sourceChanges = null;
228 234
229 var updated = new AssetSet(); 235 var updated = new AssetSet();
230 var futures = []; 236 var futures = [];
231 for (var id in changes.updated) { 237 for (var id in changes.updated) {
232 // TODO(rnystrom): Catch all errors from provider and route to results. 238 // TODO(rnystrom): Catch all errors from provider and route to results.
233 futures.add(_manager.provider.getAsset(id).then((asset) { 239 futures.add(_graph.provider.getAsset(id).then((asset) {
234 updated.add(asset); 240 updated.add(asset);
235 }).catchError((error) { 241 }).catchError((error) {
236 if (error is AssetNotFoundException) { 242 if (error is AssetNotFoundException) {
237 // Handle missing asset errors like regular missing assets. 243 // Handle missing asset errors like regular missing assets.
238 reportError(error); 244 reportError(error);
239 } else { 245 } else {
240 // It's an unexpected error, so rethrow it. 246 // It's an unexpected error, so rethrow it.
241 throw error; 247 throw error;
242 } 248 }
243 })); 249 }));
244 } 250 }
245 251
246 return Future.wait(futures).then((_) { 252 return Future.wait(futures).then((_) {
247 _phases.first.updateInputs(updated, changes.removed); 253 _phases.first.updateInputs(updated, changes.removed);
248 }); 254 });
249 }); 255 });
250 } 256 }
251 } 257 }
252 258
253 /// An event indicating that the asset graph has finished building. 259 /// An event indicating that the cascade has finished building all assets.
254 /// 260 ///
255 /// A build can end either in success or failure. If there were no errors during 261 /// A build can end either in success or failure. If there were no errors during
256 /// the build, it's considered to be a success; any errors render it a failure, 262 /// the build, it's considered to be a success; any errors render it a failure,
257 /// although individual assets may still have built successfully. 263 /// although individual assets may still have built successfully.
258 class BuildResult { 264 class BuildResult {
259 /// All errors that occurred during the build. 265 /// All errors that occurred during the build.
260 final List errors; 266 final List errors;
261 267
262 /// `true` if the build succeeded. 268 /// `true` if the build succeeded.
263 bool get succeeded => errors.isEmpty; 269 bool get succeeded => errors.isEmpty;
(...skipping 18 matching lines...) Expand all
282 msg.write(prefixLines(error.toString())); 288 msg.write(prefixLines(error.toString()));
283 if (stackTrace != null) { 289 if (stackTrace != null) {
284 msg.write("\n\n"); 290 msg.write("\n\n");
285 msg.write("Stack trace:\n"); 291 msg.write("Stack trace:\n");
286 msg.write(prefixLines(stackTrace.toString())); 292 msg.write(prefixLines(stackTrace.toString()));
287 } 293 }
288 return msg.toString(); 294 return msg.toString();
289 }).join("\n\n"); 295 }).join("\n\n");
290 } 296 }
291 } 297 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/barback.dart ('k') | pkg/barback/lib/src/asset_graph.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698