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

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

Issue 199443003: Asset load failures in Barback should produce AssetNotFoundExceptions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 | « no previous file | pkg/barback/lib/src/transform_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) 2014, the Dart project authors. Please see the AUTHORS file 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 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.base_transform; 5 library barback.base_transform;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'asset.dart'; 10 import 'asset.dart';
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 /// Gets the primary input asset. 45 /// Gets the primary input asset.
46 /// 46 ///
47 /// While a transformation can use multiple input assets, one must be a 47 /// While a transformation can use multiple input assets, one must be a
48 /// special "primary" asset. This will be the "entrypoint" or "main" input 48 /// special "primary" asset. This will be the "entrypoint" or "main" input
49 /// file for a transformation. 49 /// file for a transformation.
50 /// 50 ///
51 /// For example, with a dart2js transform, the primary input would be the 51 /// For example, with a dart2js transform, the primary input would be the
52 /// entrypoint Dart file. All of the other Dart files that that imports 52 /// entrypoint Dart file. All of the other Dart files that that imports
53 /// would be secondary inputs. 53 /// would be secondary inputs.
54 /// 54 ///
55 /// This method may fail at runtime if called asynchronously after the 55 /// This method may fail at runtime with an [AssetNotFoundException] if called
56 /// transform begins running. The primary input may become unavailable while 56 /// asynchronously after the transform begins running. The primary input may
57 /// this transformer is running due to asset changes earlier in the graph. 57 /// become unavailable while this transformer is running due to asset changes
58 /// You can ignore the error if this happens: the transformer will be re-run 58 /// earlier in the graph. You can ignore the error if this happens: the
59 /// automatically for you. 59 /// transformer will be re-run automatically for you.
60 Asset get primaryInput { 60 Asset get primaryInput {
61 if (_node.primary.state != AssetState.AVAILABLE) { 61 if (_node.primary.state != AssetState.AVAILABLE) {
62 throw new AssetNotFoundException(_node.primary.id); 62 throw new AssetNotFoundException(_node.primary.id);
63 } 63 }
64 64
65 return _node.primary.asset; 65 return _node.primary.asset;
66 } 66 }
67 67
68 BaseTransform(this._node) { 68 BaseTransform(this._node) {
69 _logger = new TransformLogger((asset, level, message, span) { 69 _logger = new TransformLogger((asset, level, message, span) {
70 // If the log isn't already associated with an asset, use the primary. 70 // If the log isn't already associated with an asset, use the primary.
71 if (asset == null) asset = _node.primary.id; 71 if (asset == null) asset = _node.primary.id;
72 var entry = new LogEntry(_node.info, asset, level, message, span); 72 var entry = new LogEntry(_node.info, asset, level, message, span);
73 _onLogController.add(entry); 73 _onLogController.add(entry);
74 }); 74 });
75 } 75 }
76 76
77 /// Gets the asset for an input [id]. 77 /// Gets the asset for an input [id].
78 /// 78 ///
79 /// If an input with that ID cannot be found, throws an 79 /// If an input with [id] cannot be found, throws an [AssetNotFoundException].
80 /// [AssetNotFoundException].
81 Future<Asset> getInput(AssetId id) => _node.getInput(id); 80 Future<Asset> getInput(AssetId id) => _node.getInput(id);
82 81
83 /// A convenience method to the contents of the input with [id] as a string. 82 /// A convenience method to the contents of the input with [id] as a string.
84 /// 83 ///
85 /// This is equivalent to calling `getInput()` followed by `readAsString()`. 84 /// This is equivalent to calling [getInput] followed by [Asset.readAsString].
86 /// 85 ///
87 /// If the asset was created from a [String] the original string is always 86 /// If the asset was created from a [String] the original string is always
88 /// returned and [encoding] is ignored. Otherwise, the binary data of the 87 /// returned and [encoding] is ignored. Otherwise, the binary data of the
89 /// asset is decoded using [encoding], which defaults to [UTF8]. 88 /// asset is decoded using [encoding], which defaults to [UTF8].
89 ///
90 /// If an input with [id] cannot be found, throws an [AssetNotFoundException].
90 Future<String> readInputAsString(AssetId id, {Encoding encoding}) { 91 Future<String> readInputAsString(AssetId id, {Encoding encoding}) {
91 if (encoding == null) encoding = UTF8; 92 if (encoding == null) encoding = UTF8;
92 return getInput(id).then((input) => input.readAsString(encoding: encoding)); 93 return getInput(id).then((input) => input.readAsString(encoding: encoding));
93 } 94 }
94 95
95 /// A convenience method to the contents of the input with [id]. 96 /// A convenience method to the contents of the input with [id].
96 /// 97 ///
97 /// This is equivalent to calling `getInput()` followed by `read()`. 98 /// This is equivalent to calling [getInput] followed by [Asset.read].
98 /// 99 ///
99 /// If the asset was created from a [String], this returns its UTF-8 encoding. 100 /// If the asset was created from a [String], this returns its UTF-8 encoding.
101 ///
102 /// If an input with [id] cannot be found, throws an [AssetNotFoundException].
100 Stream<List<int>> readInput(AssetId id) => 103 Stream<List<int>> readInput(AssetId id) =>
101 futureStream(getInput(id).then((input) => input.read())); 104 futureStream(getInput(id).then((input) => input.read()));
102 105
103 /// Consume the primary input so that it doesn't get processed by future 106 /// Consume the primary input so that it doesn't get processed by future
104 /// phases or emitted once processing has finished. 107 /// phases or emitted once processing has finished.
105 /// 108 ///
106 /// Normally the primary input will automatically be forwarded unless the 109 /// Normally the primary input will automatically be forwarded unless the
107 /// transformer overwrites it by emitting an input with the same id. This 110 /// transformer overwrites it by emitting an input with the same id. This
108 /// allows the transformer to tell barback not to forward the primary input 111 /// allows the transformer to tell barback not to forward the primary input
109 /// even if it's not overwritten. 112 /// even if it's not overwritten.
(...skipping 20 matching lines...) Expand all
130 133
131 /// Notifies the [BaseTransform] that the transformation has finished being 134 /// Notifies the [BaseTransform] that the transformation has finished being
132 /// applied. 135 /// applied.
133 /// 136 ///
134 /// This will close any streams and release any resources that were allocated 137 /// This will close any streams and release any resources that were allocated
135 /// for the duration of the transformation. 138 /// for the duration of the transformation.
136 void close() { 139 void close() {
137 transform._onLogController.close(); 140 transform._onLogController.close();
138 } 141 }
139 } 142 }
OLDNEW
« no previous file with comments | « no previous file | pkg/barback/lib/src/transform_node.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698