Skip to content

Commit

Permalink
finalize -> completes, and refactor logger wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemac53 committed Feb 3, 2016
1 parent a7a69bd commit 3c3f7f7
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions lib/src/builder/build_step_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ class BuildStepImpl implements BuildStep {
Future<Resolver> 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();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/generate/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Stream<Asset> _runBuilder(Builder builder, List<AssetId> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/transformer/transformer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}));
}

Expand Down
54 changes: 27 additions & 27 deletions lib/src/util/barback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
});
}
2 changes: 1 addition & 1 deletion test/analyzer/resolver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions test/builder/build_step_impl_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3c3f7f7

Please sign in to comment.