diff --git a/lib/src/builder/build_step_impl.dart b/lib/src/builder/build_step_impl.dart index 34a04f388..be799b4d3 100644 --- a/lib/src/builder/build_step_impl.dart +++ b/lib/src/builder/build_step_impl.dart @@ -95,9 +95,9 @@ class BuildStepImpl implements BuildStep { Future resolve(AssetId id) async => new Resolver( await _resolvers.get(toBarbackTransform(this), [toBarbackAssetId(id)])); - /// Should be called after [build] has completed. This will wait until for + /// Should be called after `build` has completed. This will wait until for /// [_outputsCompleted] and will also close the [logger]. - Future finalize() async { + Future complete() async { await _outputsCompleted; await _logger?.clearListeners(); } diff --git a/lib/src/generate/build.dart b/lib/src/generate/build.dart index 21579c979..94dbbdd5f 100644 --- a/lib/src/generate/build.dart +++ b/lib/src/generate/build.dart @@ -135,7 +135,7 @@ Stream _runBuilder(Builder builder, List inputs) async* { var buildStep = new BuildStepImpl(inputAsset, expectedOutputs, _reader, _writer); await builder.build(buildStep); - await buildStep.finalize(); + await buildStep.complete(); for (var output in buildStep.outputs) { yield output; } diff --git a/lib/src/transformer/transformer.dart b/lib/src/transformer/transformer.dart index 492907388..f1a0d39dd 100644 --- a/lib/src/transformer/transformer.dart +++ b/lib/src/transformer/transformer.dart @@ -72,7 +72,7 @@ abstract class BuilderTransformer implements Transformer, DeclaringTransformer { // Run the build step. var buildStep = new BuildStepImpl(input, expected, reader, writer); await builder.build(buildStep); - await buildStep.finalize(); + await buildStep.complete(); })); } diff --git a/lib/src/util/barback.dart b/lib/src/util/barback.dart index 0153b163d..f35a89f4b 100644 --- a/lib/src/util/barback.dart +++ b/lib/src/util/barback.dart @@ -5,6 +5,7 @@ import 'dart:async'; import 'dart:convert'; import 'package:barback/barback.dart' as barback; +import 'package:logging/logging.dart'; import '../asset/asset.dart' as build; import '../asset/id.dart' as build; @@ -35,33 +36,7 @@ class BuildStepTransform implements barback.Transform { @override barback.TransformLogger get logger { - _logger ??= new barback.TransformLogger((asset, level, message, span) { - var buffer = new StringBuffer(); - if (asset != null) { - buffer.write('From $asset'); - if (span != null) { - buffer.write('()$span)'); - } - buffer.write(': '); - } - buffer.write(message); - switch (level) { - case barback.LogLevel.FINE: - buildStep.logger.fine(message); - break; - case barback.LogLevel.INFO: - buildStep.logger.info(message); - break; - case barback.LogLevel.WARNING: - buildStep.logger.warning(message); - break; - case barback.LogLevel.ERROR: - buildStep.logger.severe(message); - break; - default: - throw 'Unrecognized LogLevel $level.'; - } - }); + _logger ??= toTransformLogger(buildStep.logger); return _logger; } @@ -94,3 +69,28 @@ class BuildStepTransform implements barback.Transform { @override void consumePrimary() => throw new UnimplementedError(); } + + +const _barbackLevelToLoggingLevel = const { + barback.LogLevel.FINE: Level.FINE, + barback.LogLevel.INFO: Level.INFO, + barback.LogLevel.WARNING: Level.WARNING, + barback.LogLevel.ERROR: Level.SEVERE, +}; + +barback.TransformLogger toTransformLogger(Logger logger) { + return new barback.TransformLogger((asset, level, message, span) { + var buffer = new StringBuffer(); + if (asset != null) { + buffer.write('From $asset'); + if (span != null) { + buffer.write('()$span)'); + } + buffer.write(': '); + } + buffer.write(message); + var logLevel = _barbackLevelToLoggingLevel[level]; + if (logLevel == null) throw 'Unrecognized LogLevel $level.'; + logger.log(logLevel, buffer); + }); +} diff --git a/test/analyzer/resolver_test.dart b/test/analyzer/resolver_test.dart index da18955d1..42bcc8169 100644 --- a/test/analyzer/resolver_test.dart +++ b/test/analyzer/resolver_test.dart @@ -30,7 +30,7 @@ main() { buildStep.logger.onRecord.listen(logs.add); } await builder.build(buildStep); - await buildStep.finalize(); + await buildStep.complete(); if (messages != null) { expect(logs.map((l) => l.toString()), messages); } diff --git a/test/builder/build_step_impl_test.dart b/test/builder/build_step_impl_test.dart index ba9dad798..4560fc582 100644 --- a/test/builder/build_step_impl_test.dart +++ b/test/builder/build_step_impl_test.dart @@ -61,7 +61,7 @@ main() { buildStep.writeAsString(a2); expect(buildStep.outputs, [a1, a2]); - expect(buildStep.finalize(), completes); + expect(buildStep.complete(), completes); }); test('doesnt allow non-expected outputs', () { @@ -113,7 +113,7 @@ main() { inputs[new AssetId.parse(primary)], [outputId], reader, writer); await fileCombiner.build(buildStep); - await buildStep.finalize(); + await buildStep.complete(); // All the assets should be read and marked as deps, except [unUsed]. expect(buildStep.dependencies,