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

Unified Diff: packages/barback/test/transformer/aggregate_many_to_one.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: packages/barback/test/transformer/aggregate_many_to_one.dart
diff --git a/packages/barback/test/transformer/aggregate_many_to_one.dart b/packages/barback/test/transformer/aggregate_many_to_one.dart
new file mode 100644
index 0000000000000000000000000000000000000000..7bba89fc125e64e8c5a6627ccd127c8430d0617b
--- /dev/null
+++ b/packages/barback/test/transformer/aggregate_many_to_one.dart
@@ -0,0 +1,47 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library barback.test.transformer.aggregate_many_to_one;
+
+import 'dart:async';
+
+import 'package:barback/barback.dart';
+import 'package:path/path.dart' as path;
+
+import 'mock_aggregate.dart';
+
+/// An [AggregateTransformer] that applies to all assets with a given extension.
+/// For each directory containing any of these assets, it produces an output
+/// file that contains the concatenation of all matched assets in that
+/// directory in alphabetic order by name.
+class AggregateManyToOneTransformer extends MockAggregateTransformer {
+ /// The extension of assets to combine.
+ final String extension;
+
+ /// The basename of the output asset.
+ ///
+ /// The output asset's path will contain the directory name of the inputs as
+ /// well.
+ final String output;
+
+ AggregateManyToOneTransformer(this.extension, this.output);
+
+ String doClassifyPrimary(AssetId id) {
+ if (id.extension != ".$extension") return null;
+ return path.url.dirname(id.path);
+ }
+
+ Future doApply(AggregateTransform transform) {
+ return getPrimaryInputs(transform).toList().then((assets) {
+ assets.sort((asset1, asset2) => asset1.id.path.compareTo(asset2.id.path));
+ return Future.wait(assets.map((asset) => asset.readAsString()));
+ }).then((contents) {
+ var id = new AssetId(transform.package,
+ path.url.join(transform.key, output));
+ transform.addOutput(new Asset.fromString(id, contents.join('\n')));
+ });
+ }
+
+ String toString() => "aggregate $extension->$output";
+}
« no previous file with comments | « packages/barback/test/transformer/aggregate_many_to_many.dart ('k') | packages/barback/test/transformer/bad.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698