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

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

Issue 18650004: Make Assets know their ID. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweak doc. 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/src/asset.dart ('k') | pkg/barback/lib/src/asset_node.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_graph;
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_provider.dart'; 12 import 'asset_provider.dart';
13 import 'asset_set.dart';
13 import 'errors.dart'; 14 import 'errors.dart';
14 import 'change_batch.dart'; 15 import 'change_batch.dart';
15 import 'phase.dart'; 16 import 'phase.dart';
16 import 'transformer.dart'; 17 import 'transformer.dart';
17 18
18 /// The main build dependency manager. 19 /// The main build dependency manager.
19 /// 20 ///
20 /// For any given input file, it can tell which output files are affected by 21 /// For any given input file, it can tell which output files are affected by
21 /// it, and vice versa. 22 /// it, and vice versa.
22 class AssetGraph { 23 class AssetGraph {
(...skipping 13 matching lines...) Expand all
36 37
37 /// Creates a new [AssetGraph]. 38 /// Creates a new [AssetGraph].
38 /// 39 ///
39 /// It loads source assets using [provider] and then uses [transformerPhases] 40 /// It loads source assets using [provider] and then uses [transformerPhases]
40 /// to generate output files from them. 41 /// to generate output files from them.
41 //TODO(rnystrom): Better way of specifying transformers and their ordering. 42 //TODO(rnystrom): Better way of specifying transformers and their ordering.
42 AssetGraph(this._provider, 43 AssetGraph(this._provider,
43 Iterable<Iterable<Transformer>> transformerPhases) { 44 Iterable<Iterable<Transformer>> transformerPhases) {
44 // Flatten the phases to a list so we can traverse backwards to wire up 45 // Flatten the phases to a list so we can traverse backwards to wire up
45 // each phase to its next. 46 // each phase to its next.
46 transformerPhases = transformerPhases.toList(); 47 var phases = transformerPhases.toList();
47 48
48 // Each phase writes its outputs as inputs to the next phase after it. 49 // Each phase writes its outputs as inputs to the next phase after it.
49 // Add a phase at the end for the final outputs of the last phase. 50 // Add a phase at the end for the final outputs of the last phase.
50 transformerPhases.add([]); 51 phases.add([]);
51 52
52 Phase nextPhase = null; 53 Phase nextPhase = null;
53 for (var transformers in transformerPhases.reversed) { 54 for (var transformers in phases.reversed) {
54 nextPhase = new Phase(this, _phases.length, transformers.toList(), 55 nextPhase = new Phase(this, _phases.length, transformers.toList(),
55 nextPhase); 56 nextPhase);
56 _phases.insert(0, nextPhase); 57 _phases.insert(0, nextPhase);
57 } 58 }
58 } 59 }
59 60
60 /// Gets the asset identified by [id]. 61 /// Gets the asset identified by [id].
61 /// 62 ///
62 /// If [id] is for a generated or transformed asset, this will wait until 63 /// If [id] is for a generated or transformed asset, this will wait until
63 /// it has been created and return it. If the asset cannot be found, throws 64 /// it has been created and return it. If the asset cannot be found, throws
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 // changes are processed in a single batch even when the first one starts 184 // changes are processed in a single batch even when the first one starts
184 // the build process. 185 // the build process.
185 return new Future(() { 186 return new Future(() {
186 if (_sourceChanges == null) return null; 187 if (_sourceChanges == null) return null;
187 188
188 // Take the current batch to ensure it doesn't get added to while we're 189 // Take the current batch to ensure it doesn't get added to while we're
189 // processing it. 190 // processing it.
190 var changes = _sourceChanges; 191 var changes = _sourceChanges;
191 _sourceChanges = null; 192 _sourceChanges = null;
192 193
193 var updated = new Map<AssetId, Asset>(); 194 var updated = new AssetSet();
194 var futures = []; 195 var futures = [];
195 for (var id in changes.updated) { 196 for (var id in changes.updated) {
196 // TODO(rnystrom): Catch all errors from provider and route to results. 197 // TODO(rnystrom): Catch all errors from provider and route to results.
197 futures.add(_provider.getAsset(id).then((asset) { 198 futures.add(_provider.getAsset(id).then((asset) {
198 updated[id] = asset; 199 updated.add(asset);
199 }).catchError((error) { 200 }).catchError((error) {
200 if (error is AssetNotFoundException) { 201 if (error is AssetNotFoundException) {
201 // Handle missing asset errors like regular missing assets. 202 // Handle missing asset errors like regular missing assets.
202 reportError(error); 203 reportError(error);
203 } else { 204 } else {
204 // It's an unexpected error, so rethrow it. 205 // It's an unexpected error, so rethrow it.
205 throw error; 206 throw error;
206 } 207 }
207 })); 208 }));
208 } 209 }
209 210
210 return Future.wait(futures).then((_) { 211 return Future.wait(futures).then((_) {
211 _phases.first.updateInputs(updated, changes.removed); 212 _phases.first.updateInputs(updated, changes.removed);
212 }); 213 });
213 }); 214 });
214 } 215 }
215 } 216 }
216 217
217 /// Used to report build results back from the asynchronous build process 218 /// Used to report build results back from the asynchronous build process
218 /// running in the background. 219 /// running in the background.
219 class BuildResult { 220 class BuildResult {
220 /// The error that occurred, or `null` if the result is not an error. 221 /// The error that occurred, or `null` if the result is not an error.
221 final error; 222 final error;
222 223
223 /// `true` if this result is for a successful build. 224 /// `true` if this result is for a successful build.
224 bool get succeeded => error == null; 225 bool get succeeded => error == null;
225 226
226 BuildResult([this.error]); 227 BuildResult([this.error]);
227 } 228 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/src/asset.dart ('k') | pkg/barback/lib/src/asset_node.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698