| 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 'errors.dart'; | 11 import 'errors.dart'; |
| 12 import 'utils.dart'; | 12 import 'utils.dart'; |
| 13 | 13 |
| 14 /// An event indicating that the cascade has finished building all assets. | 14 /// An event indicating that the cascade has finished building all assets. |
| 15 /// | 15 /// |
| 16 /// A build can end either in success or failure. If there were no errors during | 16 /// A build can end either in success or failure. If there were no errors during |
| 17 /// the build, it's considered to be a success; any errors render it a failure, | 17 /// the build, it's considered to be a success; any errors render it a failure, |
| 18 /// although individual assets may still have built successfully. | 18 /// although individual assets may still have built successfully. |
| 19 class BuildResult { | 19 class BuildResult { |
| 20 /// All errors that occurred during the build. | 20 /// All errors that occurred during the build. |
| 21 final Set<BarbackException> errors; | 21 final Set<BarbackException> errors; |
| 22 | 22 |
| 23 /// `true` if the build succeeded. | 23 /// `true` if the build succeeded. |
| 24 bool get succeeded => errors.isEmpty; | 24 bool get succeeded => errors.isEmpty; |
| 25 | 25 |
| 26 BuildResult(Iterable<BarbackException> errors) | 26 BuildResult(Iterable<BarbackException> errors) |
| 27 : errors = errors.toSet(); | 27 : errors = flattenAggregateExceptions(errors).toSet(); |
| 28 | 28 |
| 29 /// Creates a build result indicating a successful build. | 29 /// Creates a build result indicating a successful build. |
| 30 /// | 30 /// |
| 31 /// This equivalent to a build result with no errors. | 31 /// This equivalent to a build result with no errors. |
| 32 BuildResult.success() | 32 BuildResult.success() |
| 33 : this([]); | 33 : this([]); |
| 34 | 34 |
| 35 String toString() { | 35 String toString() { |
| 36 if (succeeded) return "success"; | 36 if (succeeded) return "success"; |
| 37 | 37 |
| 38 return "errors:\n" + errors.map((error) { | 38 return "errors:\n" + errors.map((error) { |
| 39 var stackTrace = getAttachedStackTrace(error); | 39 var stackTrace = getAttachedStackTrace(error); |
| 40 if (stackTrace != null) stackTrace = new Trace.from(stackTrace); | 40 if (stackTrace != null) stackTrace = new Trace.from(stackTrace); |
| 41 | 41 |
| 42 var msg = new StringBuffer(); | 42 var msg = new StringBuffer(); |
| 43 msg.write(prefixLines(error.toString())); | 43 msg.write(prefixLines(error.toString())); |
| 44 if (stackTrace != null) { | 44 if (stackTrace != null) { |
| 45 msg.write("\n\n"); | 45 msg.write("\n\n"); |
| 46 msg.write("Stack trace:\n"); | 46 msg.write("Stack trace:\n"); |
| 47 msg.write(prefixLines(stackTrace.toString())); | 47 msg.write(prefixLines(stackTrace.toString())); |
| 48 } | 48 } |
| 49 return msg.toString(); | 49 return msg.toString(); |
| 50 }).join("\n\n"); | 50 }).join("\n\n"); |
| 51 } | 51 } |
| 52 } | 52 } |
| OLD | NEW |