Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(527)

Side by Side Diff: lib/src/checker/multi_package_resolver.dart

Issue 1001563003: Fix in multi-package-resolver to support files that will be created later (graph (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | lib/src/dependency_graph.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 library dev_compiler.src.checker.multi_package_resolver; 5 library dev_compiler.src.checker.multi_package_resolver;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:analyzer/src/generated/java_io.dart'; 9 import 'package:analyzer/src/generated/java_io.dart';
10 import 'package:analyzer/src/generated/source.dart'; 10 import 'package:analyzer/src/generated/source.dart';
11 import 'package:analyzer/src/generated/source_io.dart'; 11 import 'package:analyzer/src/generated/source_io.dart';
12 import 'package:path/path.dart' show join; 12 import 'package:path/path.dart' show join;
13 13
14 /// A package resolver that supports a non-standard package layout, where 14 /// A package resolver that supports a non-standard package layout, where
15 /// packages with dotted names are expanded to a hierarchy of directories, and 15 /// packages with dotted names are expanded to a hierarchy of directories, and
16 /// packages can be found on one or more locations. 16 /// packages can be found on one or more locations.
17 class MultiPackageResolver extends UriResolver { 17 class MultiPackageResolver extends UriResolver {
18 final List<String> searchPaths; 18 final List<String> searchPaths;
19 MultiPackageResolver(this.searchPaths); 19 MultiPackageResolver(this.searchPaths);
20 20
21 @override 21 @override
22 Source resolveAbsolute(Uri uri) { 22 Source resolveAbsolute(Uri uri) {
23 var path = _expandPath(uri); 23 var path = _expandPath(uri);
24 if (path == null) return null; 24 if (path == null) return null;
25 25
26 var resolvedPath = _resolve(path); 26 var resolvedPath = _resolve(path);
27 if (resolvedPath == null) return null; 27 if (resolvedPath == null) {
28 // If we can't resolve it, we default to use the path with the first
29 // prefix. The returned source will have that `source.exists()` is false.
vsm 2015/03/11 20:07:50 Does this mean that the directory for generated co
Siggi Cherem (dart-lang) 2015/03/12 18:26:40 After this and our discussion offline, I decided t
30 var prefix = searchPaths.isEmpty ? '' : searchPaths[0];
31 resolvedPath = join(prefix, path);
32 }
28 33
29 return new FileBasedSource.con2(uri, new JavaFile(resolvedPath)); 34 return new FileBasedSource.con2(uri, new JavaFile(resolvedPath));
30 } 35 }
31 36
32 /// Resolve [path] by looking at each prefix in [searchPaths] and returning 37 /// Resolve [path] by looking at each prefix in [searchPaths] and returning
33 /// the first location where `prefix + path` exists. 38 /// the first location where `prefix + path` exists.
34 String _resolve(String path) { 39 String _resolve(String path) {
35 for (var prefix in searchPaths) { 40 for (var prefix in searchPaths) {
36 var resolvedPath = join(prefix, path); 41 var resolvedPath = join(prefix, path);
37 if (new File(resolvedPath).existsSync()) return resolvedPath; 42 if (new File(resolvedPath).existsSync()) return resolvedPath;
38 } 43 }
39 return null; 44 return null;
40 } 45 }
41 46
42 /// Expand `uri.path`, replacing dots in the package name with slashes. 47 /// Expand `uri.path`, replacing dots in the package name with slashes.
43 String _expandPath(Uri uri) { 48 String _expandPath(Uri uri) {
44 if (uri.scheme != 'package') return null; 49 if (uri.scheme != 'package') return null;
45 var path = uri.path; 50 var path = uri.path;
46 var slashPos = path.indexOf('/'); 51 var slashPos = path.indexOf('/');
47 var packagePath = path.substring(0, slashPos).replaceAll(".", "/"); 52 var packagePath = path.substring(0, slashPos).replaceAll(".", "/");
48 var filePath = path.substring(slashPos + 1); 53 var filePath = path.substring(slashPos + 1);
49 return '${packagePath}/lib/${filePath}'; 54 return '${packagePath}/lib/${filePath}';
50 } 55 }
51 } 56 }
OLDNEW
« no previous file with comments | « no previous file | lib/src/dependency_graph.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698