| OLD | NEW |
| 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.build_result; | 5 library barback.build_result; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
| 10 | 10 |
| 11 import 'barback_logger.dart'; | 11 import 'barback_logger.dart'; |
| 12 import 'errors.dart'; | 12 import 'errors.dart'; |
| 13 import 'utils.dart'; | 13 import 'utils.dart'; |
| 14 | 14 |
| 15 /// An event indicating that the cascade has finished building all assets. | 15 /// An event indicating that the cascade has finished building all assets. |
| 16 /// | 16 /// |
| 17 /// A build can end either in success or failure. If there were no errors during | 17 /// A build can end either in success or failure. If there were no errors during |
| 18 /// the build, it's considered to be a success; any errors render it a failure, | 18 /// the build, it's considered to be a success; any errors render it a failure, |
| 19 /// although individual assets may still have built successfully. | 19 /// although individual assets may still have built successfully. |
| 20 class BuildResult { | 20 class BuildResult { |
| 21 // TODO(rnystrom): Revise how to track error results. Errors can come from | 21 // TODO(rnystrom): Revise how to track error results. Errors can come from |
| 22 // both logs and exceptions. Accumulating them is likely slow and a waste of | 22 // both logs and exceptions. Accumulating them is likely slow and a waste of |
| 23 // memory. If we do want to accumulate them, we should at least unify them | 23 // memory. If we do want to accumulate them, we should at least unify them |
| 24 // in a single collection (probably of log entries). | 24 // in a single collection (probably of log entries). |
| 25 /// All errors that were thrown during the build. | 25 /// All errors that were thrown during the build. |
| 26 final Set<BarbackException> errors; | 26 final Set<BarbackException> errors; |
| 27 | 27 |
| 28 /// The number of error log entries that occurred during this build. | 28 /// `true` if the build succeeded. |
| 29 final int _numErrorLogs; | 29 bool get succeeded => errors.isEmpty; |
| 30 | 30 |
| 31 /// `true` if the build succeeded. | 31 BuildResult(Iterable<BarbackException> errors) |
| 32 bool get succeeded => errors.isEmpty && _numErrorLogs == 0; | |
| 33 | |
| 34 /// Gets the number of error exceptions and log entries. | |
| 35 int get numErrors => errors.length + _numErrorLogs; | |
| 36 | |
| 37 BuildResult(Iterable<BarbackException> errors, this._numErrorLogs) | |
| 38 : errors = flattenAggregateExceptions(errors).toSet(); | 32 : errors = flattenAggregateExceptions(errors).toSet(); |
| 39 | 33 |
| 40 /// Creates a build result indicating a successful build. | 34 /// Creates a build result indicating a successful build. |
| 41 /// | 35 /// |
| 42 /// This equivalent to a build result with no errors. | 36 /// This equivalent to a build result with no errors. |
| 43 BuildResult.success() | 37 BuildResult.success() |
| 44 : this([], 0); | 38 : this([]); |
| 39 |
| 40 /// Creates a single [BuildResult] that contains all of the errors of |
| 41 /// [results]. |
| 42 factory BuildResult.aggregate(Iterable<BuildResult> results) { |
| 43 var errors = unionAll(results.map((result) => result.errors)); |
| 44 return new BuildResult(errors); |
| 45 } |
| 45 | 46 |
| 46 String toString() { | 47 String toString() { |
| 47 if (succeeded) return "success"; | 48 if (succeeded) return "success"; |
| 48 | 49 |
| 49 return "errors:\n" + errors.map((error) { | 50 return "errors:\n" + errors.map((error) { |
| 50 var stackTrace = getAttachedStackTrace(error); | 51 var stackTrace = getAttachedStackTrace(error); |
| 51 if (stackTrace != null) stackTrace = new Trace.from(stackTrace); | 52 if (stackTrace != null) stackTrace = new Trace.from(stackTrace); |
| 52 | 53 |
| 53 var msg = new StringBuffer(); | 54 var msg = new StringBuffer(); |
| 54 msg.write(prefixLines(error.toString())); | 55 msg.write(prefixLines(error.toString())); |
| 55 if (stackTrace != null) { | 56 if (stackTrace != null) { |
| 56 msg.write("\n\n"); | 57 msg.write("\n\n"); |
| 57 msg.write("Stack trace:\n"); | 58 msg.write("Stack trace:\n"); |
| 58 msg.write(prefixLines(stackTrace.toString())); | 59 msg.write(prefixLines(stackTrace.toString())); |
| 59 } | 60 } |
| 60 return msg.toString(); | 61 return msg.toString(); |
| 61 }).join("\n\n"); | 62 }).join("\n\n"); |
| 62 } | 63 } |
| 63 } | 64 } |
| OLD | NEW |