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 'dart:io' show File; | 9 import 'package:package_config/packages_file.dart' as packages_file show parse; |
10 | 10 |
11 import 'package:package_config/packages_file.dart' as packages_file show parse; | 11 import 'errors.dart' show inputError; |
| 12 |
| 13 import 'io.dart' show readBytesFromFile; |
| 14 |
| 15 import 'scanner/characters.dart' show $LF; |
12 | 16 |
13 class TranslateUri { | 17 class TranslateUri { |
14 final Map<String, Uri> packages; | 18 final Map<String, Uri> packages; |
15 final Map<String, Uri> dartLibraries; | 19 final Map<String, Uri> dartLibraries; |
16 | 20 |
17 TranslateUri(this.packages, this.dartLibraries); | 21 TranslateUri(this.packages, this.dartLibraries); |
18 | 22 |
19 Uri translate(Uri uri) { | 23 Uri translate(Uri uri) { |
20 if (uri.scheme == "dart") return translateDartUri(uri); | 24 if (uri.scheme == "dart") return translateDartUri(uri); |
21 if (uri.scheme == "package") return translatePackageUri(uri); | 25 if (uri.scheme == "package") return translatePackageUri(uri); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 "web_gl": sdk.resolve("lib/web_gl/dartium/web_gl_dartium.dart"), | 71 "web_gl": sdk.resolve("lib/web_gl/dartium/web_gl_dartium.dart"), |
68 "web_sql": sdk.resolve("lib/web_sql/dartium/web_sql_dartium.dart"), | 72 "web_sql": sdk.resolve("lib/web_sql/dartium/web_sql_dartium.dart"), |
69 "_internal": sdk.resolve("lib/internal/internal.dart"), | 73 "_internal": sdk.resolve("lib/internal/internal.dart"), |
70 "profiler": sdk.resolve("lib/profiler/profiler.dart"), | 74 "profiler": sdk.resolve("lib/profiler/profiler.dart"), |
71 "vmservice_io": sdk.resolve("lib/vmservice_io/vmservice_io.dart"), | 75 "vmservice_io": sdk.resolve("lib/vmservice_io/vmservice_io.dart"), |
72 "_vmservice": sdk.resolve("lib/vmservice/vmservice.dart"), | 76 "_vmservice": sdk.resolve("lib/vmservice/vmservice.dart"), |
73 "_builtin": sdk.resolve("lib/_builtin/_builtin.dart"), | 77 "_builtin": sdk.resolve("lib/_builtin/_builtin.dart"), |
74 }; | 78 }; |
75 } | 79 } |
76 uri ??= Uri.base.resolve(".packages"); | 80 uri ??= Uri.base.resolve(".packages"); |
77 File file = new File.fromUri(uri); | 81 List<int> bytes = await readBytesFromFile(uri); |
78 List<int> bytes = await file.readAsBytes(); | 82 Map<String, Uri> packages = const <String, Uri>{}; |
79 Map<String, Uri> packages = packages_file.parse(bytes, uri); | 83 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); |
| 88 } on FormatException catch (e) { |
| 89 return inputError(uri, e.offset, e.message); |
| 90 } |
80 return new TranslateUri(packages, dartLibraries); | 91 return new TranslateUri(packages, dartLibraries); |
81 } | 92 } |
82 } | 93 } |
OLD | NEW |