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

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

Issue 18650004: Make Assets know their ID. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Don't make AssetSet implement Set<T>. 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
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.transform; 5 library barback.transform;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'asset.dart'; 9 import 'asset.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 'errors.dart'; 13 import 'errors.dart';
13 import 'transform_node.dart'; 14 import 'transform_node.dart';
14 15
15 /// Creates a [Transform] by forwarding to the private constructor. 16 /// Creates a [Transform] by forwarding to the private constructor.
16 /// 17 ///
17 /// Lets [TransformNode] create [Transforms] without giving a [Transform] 18 /// Lets [TransformNode] create [Transforms] without giving a [Transform]
18 /// itself a public constructor, which would be visible to external users. 19 /// itself a public constructor, which would be visible to external users.
19 /// Unlike the [Transform] class, this function is not exported by barback.dart. 20 /// Unlike the [Transform] class, this function is not exported by barback.dart.
20 Transform createTransform(TransformNode node, Set<AssetNode> inputs, 21 Transform createTransform(TransformNode node, Set<AssetNode> inputs,
21 Map<AssetId, Asset> outputs) => 22 Set<Asset> outputs) =>
22 new Transform._(node, inputs, outputs); 23 new Transform._(node, inputs, outputs);
23 24
24 /// While a [Transformer] represents a *kind* of transformation, this defines 25 /// While a [Transformer] represents a *kind* of transformation, this defines
25 /// one specific usage of it on a set of files. 26 /// one specific usage of it on a set of files.
26 /// 27 ///
27 /// This ephemeral object exists only during an actual transform application to 28 /// This ephemeral object exists only during an actual transform application to
28 /// facilitate communication between the [Transformer] and the code hosting 29 /// facilitate communication between the [Transformer] and the code hosting
29 /// the transformation. It lets the [Transformer] access inputs and generate 30 /// the transformation. It lets the [Transformer] access inputs and generate
30 /// outputs. 31 /// outputs.
31 class Transform { 32 class Transform {
32 final TransformNode _node; 33 final TransformNode _node;
33 34
34 final Set<AssetNode> _inputs; 35 final Set<AssetNode> _inputs;
35 final Map<AssetId, Asset> _outputs; 36 final AssetSet _outputs;
36 37
37 /// Gets the ID of the primary input for this transformation. 38 /// Gets the ID of the primary input for this transformation.
38 /// 39 ///
39 /// While a transformation can use multiple input assets, one must be a 40 /// While a transformation can use multiple input assets, one must be a
40 /// special "primary" asset. This will be the "entrypoint" or "main" input 41 /// special "primary" asset. This will be the "entrypoint" or "main" input
41 /// file for a transformation. 42 /// file for a transformation.
42 /// 43 ///
43 /// For example, with a dart2js transform, the primary input would be the 44 /// For example, with a dart2js transform, the primary input would be the
44 /// entrypoint Dart file. All of the other Dart files that that imports 45 /// entrypoint Dart file. All of the other Dart files that that imports
45 /// would be secondary inputs. 46 /// would be secondary inputs.
(...skipping 18 matching lines...) Expand all
64 // is exited. We'll then catch this and report it through the proper 65 // is exited. We'll then catch this and report it through the proper
65 // results stream. 66 // results stream.
66 if (node == null) throw new MissingInputException(id); 67 if (node == null) throw new MissingInputException(id);
67 68
68 // Keep track of which assets this transform depends on. 69 // Keep track of which assets this transform depends on.
69 _inputs.add(node); 70 _inputs.add(node);
70 return node.asset; 71 return node.asset;
71 }); 72 });
72 } 73 }
73 74
74 /// Stores [output] as the output created by this transformation for asset 75 /// Stores [output] as the output created by this transformation.
75 /// [id]. A transformation can output as many assets as it wants. 76 ///
76 void addOutput(AssetId id, Asset output) { 77 /// A transformation can output as many assets as it wants.
77 _outputs[id] = output; 78 void addOutput(Asset output) {
79 // TODO(rnystrom): This should immediately throw if an output with that ID
80 // has already been created by this transformer.
81 _outputs.add(output);
78 } 82 }
79 } 83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698