| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 fasta.translate_uri; | 5 library fasta.translate_uri; |
| 6 | 6 |
| 7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
| 8 | 8 |
| 9 import 'package:package_config/packages_file.dart' as packages_file show parse; | 9 import 'package:package_config/packages_file.dart' as packages_file show parse; |
| 10 | 10 |
| 11 import 'errors.dart' show inputError; | 11 import 'errors.dart' show inputError; |
| 12 | 12 |
| 13 import 'io.dart' show readBytesFromFile; | 13 import 'io.dart' show readBytesFromFile; |
| 14 | 14 |
| 15 import 'scanner/characters.dart' show $LF; | |
| 16 | |
| 17 class TranslateUri { | 15 class TranslateUri { |
| 18 final Map<String, Uri> packages; | 16 final Map<String, Uri> packages; |
| 19 final Map<String, Uri> dartLibraries; | 17 final Map<String, Uri> dartLibraries; |
| 20 | 18 |
| 21 TranslateUri(this.packages, this.dartLibraries); | 19 TranslateUri(this.packages, this.dartLibraries); |
| 22 | 20 |
| 23 Uri translate(Uri uri) { | 21 Uri translate(Uri uri) { |
| 24 if (uri.scheme == "dart") return translateDartUri(uri); | 22 if (uri.scheme == "dart") return translateDartUri(uri); |
| 25 if (uri.scheme == "package") return translatePackageUri(uri); | 23 if (uri.scheme == "package") return translatePackageUri(uri); |
| 26 return null; | 24 return null; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 "web_gl": sdk.resolve("lib/web_gl/dartium/web_gl_dartium.dart"), | 69 "web_gl": sdk.resolve("lib/web_gl/dartium/web_gl_dartium.dart"), |
| 72 "web_sql": sdk.resolve("lib/web_sql/dartium/web_sql_dartium.dart"), | 70 "web_sql": sdk.resolve("lib/web_sql/dartium/web_sql_dartium.dart"), |
| 73 "_internal": sdk.resolve("lib/internal/internal.dart"), | 71 "_internal": sdk.resolve("lib/internal/internal.dart"), |
| 74 "profiler": sdk.resolve("lib/profiler/profiler.dart"), | 72 "profiler": sdk.resolve("lib/profiler/profiler.dart"), |
| 75 "vmservice_io": sdk.resolve("lib/vmservice_io/vmservice_io.dart"), | 73 "vmservice_io": sdk.resolve("lib/vmservice_io/vmservice_io.dart"), |
| 76 "_vmservice": sdk.resolve("lib/vmservice/vmservice.dart"), | 74 "_vmservice": sdk.resolve("lib/vmservice/vmservice.dart"), |
| 77 "_builtin": sdk.resolve("lib/_builtin/_builtin.dart"), | 75 "_builtin": sdk.resolve("lib/_builtin/_builtin.dart"), |
| 78 }; | 76 }; |
| 79 } | 77 } |
| 80 uri ??= Uri.base.resolve(".packages"); | 78 uri ??= Uri.base.resolve(".packages"); |
| 81 List<int> bytes = await readBytesFromFile(uri); | 79 List<int> bytes = |
| 80 await readBytesFromFile(uri, ensureZeroTermination: false); |
| 82 Map<String, Uri> packages = const <String, Uri>{}; | 81 Map<String, Uri> packages = const <String, Uri>{}; |
| 83 try { | 82 try { |
| 84 // We always add an extra zero byte at the end of files. We change that | |
| 85 // to a newline to avoid a format error from `packages_file.parse`. | |
| 86 bytes[bytes.length - 1] = $LF; | |
| 87 packages = packages_file.parse(bytes, uri); | 83 packages = packages_file.parse(bytes, uri); |
| 88 } on FormatException catch (e) { | 84 } on FormatException catch (e) { |
| 89 return inputError(uri, e.offset, e.message); | 85 return inputError(uri, e.offset, e.message); |
| 90 } | 86 } |
| 91 return new TranslateUri(packages, dartLibraries); | 87 return new TranslateUri(packages, dartLibraries); |
| 92 } | 88 } |
| 93 } | 89 } |
| OLD | NEW |