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 library context.directory.manager; | 5 library context.directory.manager; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:convert'; | 9 import 'dart:convert'; |
10 import 'dart:core' hide Resource; | 10 import 'dart:core' hide Resource; |
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 * | 953 * |
954 * TODO(paulberry): use [addDependency] for tracking all folder disposition | 954 * TODO(paulberry): use [addDependency] for tracking all folder disposition |
955 * dependencies (currently we only use it to track "pub list" dependencies). | 955 * dependencies (currently we only use it to track "pub list" dependencies). |
956 */ | 956 */ |
957 FolderDisposition _computeFolderDisposition( | 957 FolderDisposition _computeFolderDisposition( |
958 Folder folder, void addDependency(String path), File packagespecFile) { | 958 Folder folder, void addDependency(String path), File packagespecFile) { |
959 String packageRoot = normalizedPackageRoots[folder.path]; | 959 String packageRoot = normalizedPackageRoots[folder.path]; |
960 if (packageRoot != null) { | 960 if (packageRoot != null) { |
961 // TODO(paulberry): We shouldn't be using JavaFile here because it | 961 // TODO(paulberry): We shouldn't be using JavaFile here because it |
962 // makes the code untestable (see dartbug.com/23909). | 962 // makes the code untestable (see dartbug.com/23909). |
963 JavaFile packagesDir = new JavaFile(packageRoot); | 963 JavaFile packagesDirOrFile = new JavaFile(packageRoot); |
964 Map<String, List<Folder>> packageMap = new Map<String, List<Folder>>(); | 964 Map<String, List<Folder>> packageMap = new Map<String, List<Folder>>(); |
965 if (packagesDir.isDirectory()) { | 965 if (packagesDirOrFile.isDirectory()) { |
966 for (JavaFile file in packagesDir.listFiles()) { | 966 for (JavaFile file in packagesDirOrFile.listFiles()) { |
967 // Ensure symlinks in packages directory are canonicalized | 967 // Ensure symlinks in packages directory are canonicalized |
968 // to prevent 'type X cannot be assigned to type X' warnings | 968 // to prevent 'type X cannot be assigned to type X' warnings |
969 String path; | 969 String path; |
970 try { | 970 try { |
971 path = file.getCanonicalPath(); | 971 path = file.getCanonicalPath(); |
972 } catch (e, s) { | 972 } catch (e, s) { |
973 // Ignore packages that do not exist | 973 // Ignore packages that do not exist |
974 _instrumentationService.logException(e, s); | 974 _instrumentationService.logException(e, s); |
975 continue; | 975 continue; |
976 } | 976 } |
977 Resource res = resourceProvider.getResource(path); | 977 Resource res = resourceProvider.getResource(path); |
978 if (res is Folder) { | 978 if (res is Folder) { |
979 packageMap[file.getName()] = <Folder>[res]; | 979 packageMap[file.getName()] = <Folder>[res]; |
980 } | 980 } |
981 } | 981 } |
982 return new PackageMapDisposition(packageMap, packageRoot: packageRoot); | 982 return new PackageMapDisposition(packageMap, packageRoot: packageRoot); |
| 983 } else if (packagesDirOrFile.isFile()) { |
| 984 File packageSpecFile = resourceProvider.getFile(packageRoot); |
| 985 Packages packages = _readPackagespec(packageSpecFile); |
| 986 if (packages != null) { |
| 987 return new PackagesFileDisposition(packages); |
| 988 } |
983 } | 989 } |
984 // The package root does not exist (or is not a folder). Since | 990 // The package root does not exist (or is not a folder). Since |
985 // [setRoots] ignores any package roots that don't exist (or aren't | 991 // [setRoots] ignores any package roots that don't exist (or aren't |
986 // folders), the only way we should be able to get here is due to a race | 992 // folders), the only way we should be able to get here is due to a race |
987 // condition. In any case, the package root folder is gone, so we can't | 993 // condition. In any case, the package root folder is gone, so we can't |
988 // resolve packages. | 994 // resolve packages. |
989 return new NoPackageFolderDisposition(packageRoot: packageRoot); | 995 return new NoPackageFolderDisposition(packageRoot: packageRoot); |
990 } else { | 996 } else { |
991 PackageMapInfo packageMapInfo; | 997 PackageMapInfo packageMapInfo; |
992 callbacks.beginComputePackageMap(); | 998 callbacks.beginComputePackageMap(); |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1670 ResourceProvider resourceProvider) { | 1676 ResourceProvider resourceProvider) { |
1671 if (packages != null) { | 1677 if (packages != null) { |
1672 // Construct package map for the SdkExtUriResolver. | 1678 // Construct package map for the SdkExtUriResolver. |
1673 Map<String, List<Folder>> packageMap = buildPackageMap(resourceProvider); | 1679 Map<String, List<Folder>> packageMap = buildPackageMap(resourceProvider); |
1674 return <UriResolver>[new SdkExtUriResolver(packageMap)]; | 1680 return <UriResolver>[new SdkExtUriResolver(packageMap)]; |
1675 } else { | 1681 } else { |
1676 return const <UriResolver>[]; | 1682 return const <UriResolver>[]; |
1677 } | 1683 } |
1678 } | 1684 } |
1679 } | 1685 } |
OLD | NEW |