| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // Note: this explicitly avoids using a library tag because pub will add | 5 library pub.transformer_isolate; |
| 6 // additional imports at the top of the file. | |
| 7 | 6 |
| 8 import 'dart:async'; | 7 import 'dart:async'; |
| 9 import 'dart:isolate'; | 8 import 'dart:isolate'; |
| 10 import 'dart:convert'; | 9 import 'dart:convert'; |
| 11 import 'dart:mirrors'; | 10 import 'dart:mirrors'; |
| 12 | 11 |
| 13 import '<<URL_BASE>>/packages/source_maps/span.dart'; | 12 import 'package:source_maps/span.dart'; |
| 14 import '<<URL_BASE>>/packages/stack_trace/stack_trace.dart'; | 13 import 'package:stack_trace/stack_trace.dart'; |
| 15 import '<<URL_BASE>>/packages/barback/barback.dart'; | 14 import 'package:barback/barback.dart'; |
| 16 // TODO(nweiz): don't import from "src" once issue 14966 is fixed. | 15 // TODO(nweiz): don't import from "src" once issue 14966 is fixed. |
| 17 import '<<URL_BASE>>/packages/barback/src/internal_asset.dart'; | 16 import 'package:barback/src/internal_asset.dart'; |
| 18 | 17 |
| 19 /// Sets up the initial communication with the host isolate. | 18 /// Sets up the initial communication with the host isolate. |
| 20 void main(_, SendPort replyTo) { | 19 void loadTransformers(SendPort replyTo) { |
| 21 var port = new ReceivePort(); | 20 var port = new ReceivePort(); |
| 22 replyTo.send(port.sendPort); | 21 replyTo.send(port.sendPort); |
| 23 port.first.then((wrappedMessage) { | 22 port.first.then((wrappedMessage) { |
| 24 _respond(wrappedMessage, (message) { | 23 _respond(wrappedMessage, (message) { |
| 25 var library = Uri.parse(message['library']); | 24 var library = Uri.parse(message['library']); |
| 26 var configuration = JSON.decode(message['configuration']); | 25 var configuration = JSON.decode(message['configuration']); |
| 27 var mode = new BarbackMode(message['mode']); | 26 var mode = new BarbackMode(message['mode']); |
| 28 return initialize(library, configuration, mode). | 27 return _initialize(library, configuration, mode). |
| 29 map(_serializeTransformerOrGroup).toList(); | 28 map(_serializeTransformerOrGroup).toList(); |
| 30 }); | 29 }); |
| 31 }); | 30 }); |
| 32 } | 31 } |
| 33 | 32 |
| 34 /// Loads all the transformers and groups defined in [uri]. | 33 /// Loads all the transformers and groups defined in [uri]. |
| 35 /// | 34 /// |
| 36 /// Loads the library, finds any Transformer or TransformerGroup subclasses in | 35 /// Loads the library, finds any Transformer or TransformerGroup subclasses in |
| 37 /// it, instantiates them with [configuration] and [mode], and returns them. | 36 /// it, instantiates them with [configuration] and [mode], and returns them. |
| 38 Iterable initialize(Uri uri, Map configuration, BarbackMode mode) { | 37 Iterable _initialize(Uri uri, Map configuration, BarbackMode mode) { |
| 39 var mirrors = currentMirrorSystem(); | 38 var mirrors = currentMirrorSystem(); |
| 40 var transformerClass = reflectClass(Transformer); | 39 var transformerClass = reflectClass(Transformer); |
| 41 var groupClass = reflectClass(TransformerGroup); | 40 var groupClass = reflectClass(TransformerGroup); |
| 42 | 41 |
| 43 // TODO(nweiz): if no valid transformers are found, throw an error message | 42 // TODO(nweiz): if no valid transformers are found, throw an error message |
| 44 // describing candidates and why they were rejected. | 43 // describing candidates and why they were rejected. |
| 45 return mirrors.libraries[uri].declarations.values.map((declaration) { | 44 return mirrors.libraries[uri].declarations.values.map((declaration) { |
| 46 if (declaration is! ClassMirror) return null; | 45 if (declaration is! ClassMirror) return null; |
| 47 var classMirror = declaration; | 46 var classMirror = declaration; |
| 48 if (classMirror.isPrivate) return null; | 47 if (classMirror.isPrivate) return null; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 101 } |
| 103 | 102 |
| 104 Future<String> readInputAsString(AssetId id, {Encoding encoding}) { | 103 Future<String> readInputAsString(AssetId id, {Encoding encoding}) { |
| 105 if (encoding == null) encoding = UTF8; | 104 if (encoding == null) encoding = UTF8; |
| 106 return getInput(id).then((input) => input.readAsString(encoding: encoding)); | 105 return getInput(id).then((input) => input.readAsString(encoding: encoding)); |
| 107 } | 106 } |
| 108 | 107 |
| 109 Stream<List<int>> readInput(AssetId id) => | 108 Stream<List<int>> readInput(AssetId id) => |
| 110 _futureStream(getInput(id).then((input) => input.read())); | 109 _futureStream(getInput(id).then((input) => input.read())); |
| 111 | 110 |
| 111 Future<bool> hasInput(AssetId id) { |
| 112 return getInput(id).then((_) => true).catchError((error) { |
| 113 if (error is AssetNotFoundException && error.id == id) return false; |
| 114 throw error; |
| 115 }); |
| 116 } |
| 117 |
| 112 void addOutput(Asset output) { | 118 void addOutput(Asset output) { |
| 113 _call(_port, { | 119 _call(_port, { |
| 114 'type': 'addOutput', | 120 'type': 'addOutput', |
| 115 'output': serializeAsset(output) | 121 'output': serializeAsset(output) |
| 116 }); | 122 }); |
| 117 } | 123 } |
| 124 |
| 125 void consumePrimary() { |
| 126 _call(_port, {'type': 'consumePrimary'}); |
| 127 } |
| 118 } | 128 } |
| 119 | 129 |
| 120 /// Returns the mirror for the root Object type. | 130 /// Returns the mirror for the root Object type. |
| 121 ClassMirror get objectMirror => reflectClass(Object); | 131 ClassMirror get objectMirror => reflectClass(Object); |
| 122 | 132 |
| 123 // TODO(nweiz): clean this up when issue 13248 is fixed. | 133 // TODO(nweiz): clean this up when issue 13248 is fixed. |
| 124 MethodMirror getConstructor(ClassMirror classMirror, String constructor) { | 134 MethodMirror getConstructor(ClassMirror classMirror, String constructor) { |
| 125 var name = new Symbol("${MirrorSystem.getName(classMirror.simpleName)}" | 135 var name = new Symbol("${MirrorSystem.getName(classMirror.simpleName)}" |
| 126 ".$constructor"); | 136 ".$constructor"); |
| 127 var candidate = classMirror.declarations[name]; | 137 var candidate = classMirror.declarations[name]; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 subscription = callback().listen(controller.add, | 391 subscription = callback().listen(controller.add, |
| 382 onError: controller.addError, | 392 onError: controller.addError, |
| 383 onDone: controller.close); | 393 onDone: controller.close); |
| 384 }, | 394 }, |
| 385 onCancel: () => subscription.cancel(), | 395 onCancel: () => subscription.cancel(), |
| 386 onPause: () => subscription.pause(), | 396 onPause: () => subscription.pause(), |
| 387 onResume: () => subscription.resume(), | 397 onResume: () => subscription.resume(), |
| 388 sync: true); | 398 sync: true); |
| 389 return controller.stream; | 399 return controller.stream; |
| 390 } | 400 } |
| OLD | NEW |