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:convert' show JSON; | 9 import 'dart:convert' show JSON; |
10 | 10 |
11 import 'package:front_end/file_system.dart' | 11 import 'package:front_end/file_system.dart' |
12 show FileSystem, FileSystemException; | 12 show FileSystem, FileSystemException; |
13 | 13 |
14 import 'package:package_config/packages_file.dart' as packages_file show parse; | 14 import 'package:package_config/packages_file.dart' as packages_file show parse; |
15 | 15 |
16 import 'errors.dart' show inputError; | 16 import 'deprecated_problems.dart' show deprecated_inputError; |
17 | 17 |
18 class TranslateUri { | 18 class TranslateUri { |
19 final Map<String, Uri> packages; | 19 final Map<String, Uri> packages; |
20 final Map<String, Uri> dartLibraries; | 20 final Map<String, Uri> dartLibraries; |
21 | 21 |
22 // TODO(ahe): We probably want this to be `Map<String, Uri>`, that is, just | 22 // TODO(ahe): We probably want this to be `Map<String, Uri>`, that is, just |
23 // one patch library (with parts). | 23 // one patch library (with parts). |
24 final Map<String, List<Uri>> patches; | 24 final Map<String, List<Uri>> patches; |
25 | 25 |
26 TranslateUri(this.packages, this.dartLibraries, this.patches); | 26 TranslateUri(this.packages, this.dartLibraries, this.patches); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 // TODO(ahe): Provide a value for this file. | 69 // TODO(ahe): Provide a value for this file. |
70 Uri patches = null; | 70 Uri patches = null; |
71 | 71 |
72 packages ??= Uri.base.resolve(".packages"); | 72 packages ??= Uri.base.resolve(".packages"); |
73 | 73 |
74 List<int> bytes; | 74 List<int> bytes; |
75 try { | 75 try { |
76 bytes = await fileSystem.entityForUri(packages).readAsBytes(); | 76 bytes = await fileSystem.entityForUri(packages).readAsBytes(); |
77 } on FileSystemException catch (e) { | 77 } on FileSystemException catch (e) { |
78 inputError(packages, -1, e.message); | 78 deprecated_inputError(packages, -1, e.message); |
79 } | 79 } |
80 | 80 |
81 Map<String, Uri> parsedPackages; | 81 Map<String, Uri> parsedPackages; |
82 try { | 82 try { |
83 parsedPackages = packages_file.parse(bytes, packages); | 83 parsedPackages = packages_file.parse(bytes, packages); |
84 } on FormatException catch (e) { | 84 } on FormatException catch (e) { |
85 return inputError(packages, e.offset, e.message); | 85 return deprecated_inputError(packages, e.offset, e.message); |
86 } | 86 } |
87 return new TranslateUri( | 87 return new TranslateUri( |
88 parsedPackages, | 88 parsedPackages, |
89 await computeLibraries(fileSystem, librariesJson), | 89 await computeLibraries(fileSystem, librariesJson), |
90 await computePatches(fileSystem, patches)); | 90 await computePatches(fileSystem, patches)); |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 Future<Map<String, Uri>> computeLibraries( | 94 Future<Map<String, Uri>> computeLibraries( |
95 FileSystem fileSystem, Uri uri) async { | 95 FileSystem fileSystem, Uri uri) async { |
96 if (uri == null) return const <String, Uri>{}; | 96 if (uri == null) return const <String, Uri>{}; |
97 Map<String, String> libraries = JSON | 97 Map<String, String> libraries = JSON |
98 .decode(await fileSystem.entityForUri(uri).readAsString())["libraries"]; | 98 .decode(await fileSystem.entityForUri(uri).readAsString())["libraries"]; |
99 Map<String, Uri> result = <String, Uri>{}; | 99 Map<String, Uri> result = <String, Uri>{}; |
100 libraries.forEach((String name, String path) { | 100 libraries.forEach((String name, String path) { |
101 result[name] = uri.resolveUri(new Uri.file(path)); | 101 result[name] = uri.resolveUri(new Uri.file(path)); |
102 }); | 102 }); |
103 return result; | 103 return result; |
104 } | 104 } |
105 | 105 |
106 Future<Map<String, List<Uri>>> computePatches( | 106 Future<Map<String, List<Uri>>> computePatches( |
107 FileSystem fileSystem, Uri uri) async { | 107 FileSystem fileSystem, Uri uri) async { |
108 // TODO(ahe): Read patch information. | 108 // TODO(ahe): Read patch information. |
109 return const <String, List<Uri>>{}; | 109 return const <String, List<Uri>>{}; |
110 } | 110 } |
OLD | NEW |