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

Side by Side Diff: pkg/analysis_server/lib/src/context_manager.dart

Issue 1411833002: Remove obsolete flag to enable package support (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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 | pkg/analysis_server/test/context_manager_test.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 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 * Class that maintains a mapping from included/excluded paths to a set of 310 * Class that maintains a mapping from included/excluded paths to a set of
311 * folders that should correspond to analysis contexts. 311 * folders that should correspond to analysis contexts.
312 */ 312 */
313 class ContextManagerImpl implements ContextManager { 313 class ContextManagerImpl implements ContextManager {
314 /** 314 /**
315 * File name of analysis options files. 315 * File name of analysis options files.
316 */ 316 */
317 static const String ANALYSIS_OPTIONS_FILE = '.analysis_options'; 317 static const String ANALYSIS_OPTIONS_FILE = '.analysis_options';
318 318
319 /** 319 /**
320 * Temporary flag to hide WIP .packages support (DEP 5).
321 */
322 static bool ENABLE_PACKAGESPEC_SUPPORT = serverOptions.isSet(
323 'ContextManagerImpl.ENABLE_PACKAGESPEC_SUPPORT',
324 defaultValue: true);
325
326 /**
327 * The name of the `lib` directory. 320 * The name of the `lib` directory.
328 */ 321 */
329 static const String LIB_DIR_NAME = 'lib'; 322 static const String LIB_DIR_NAME = 'lib';
330 323
331 /** 324 /**
332 * The name of `packages` folders. 325 * The name of `packages` folders.
333 */ 326 */
334 static const String PACKAGES_NAME = 'packages'; 327 static const String PACKAGES_NAME = 'packages';
335 328
336 /** 329 /**
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 // The package root does not exist (or is not a folder). Since 813 // The package root does not exist (or is not a folder). Since
821 // [setRoots] ignores any package roots that don't exist (or aren't 814 // [setRoots] ignores any package roots that don't exist (or aren't
822 // folders), the only way we should be able to get here is due to a race 815 // folders), the only way we should be able to get here is due to a race
823 // condition. In any case, the package root folder is gone, so we can't 816 // condition. In any case, the package root folder is gone, so we can't
824 // resolve packages. 817 // resolve packages.
825 return new NoPackageFolderDisposition(packageRoot: packageRoot); 818 return new NoPackageFolderDisposition(packageRoot: packageRoot);
826 } else { 819 } else {
827 PackageMapInfo packageMapInfo; 820 PackageMapInfo packageMapInfo;
828 callbacks.beginComputePackageMap(); 821 callbacks.beginComputePackageMap();
829 try { 822 try {
830 if (ENABLE_PACKAGESPEC_SUPPORT) { 823 // Try .packages first.
831 // Try .packages first. 824 if (pathContext.basename(packagespecFile.path) == PACKAGE_SPEC_NAME) {
832 if (pathContext.basename(packagespecFile.path) == PACKAGE_SPEC_NAME) { 825 Packages packages = _readPackagespec(packagespecFile);
833 Packages packages = _readPackagespec(packagespecFile); 826 return new PackagesFileDisposition(packages);
834 return new PackagesFileDisposition(packages);
835 }
836 } 827 }
837 if (packageResolverProvider != null) { 828 if (packageResolverProvider != null) {
838 UriResolver resolver = packageResolverProvider(folder); 829 UriResolver resolver = packageResolverProvider(folder);
839 if (resolver != null) { 830 if (resolver != null) {
840 return new CustomPackageResolverDisposition(resolver); 831 return new CustomPackageResolverDisposition(resolver);
841 } 832 }
842 } 833 }
843 ServerPerformanceStatistics.pub.makeCurrentWhile(() { 834 ServerPerformanceStatistics.pub.makeCurrentWhile(() {
844 packageMapInfo = _packageMapProvider.computePackageMap(folder); 835 packageMapInfo = _packageMapProvider.computePackageMap(folder);
845 }); 836 });
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 /** 977 /**
987 * Find the file that should be used to determine whether a context needs to 978 * Find the file that should be used to determine whether a context needs to
988 * be created here--this is either the ".packages" file or the "pubspec.yaml" 979 * be created here--this is either the ".packages" file or the "pubspec.yaml"
989 * file. 980 * file.
990 */ 981 */
991 File _findPackageSpecFile(Folder folder) { 982 File _findPackageSpecFile(Folder folder) {
992 // Decide whether a context needs to be created for [folder] here, and if 983 // Decide whether a context needs to be created for [folder] here, and if
993 // so, create it. 984 // so, create it.
994 File packageSpec; 985 File packageSpec;
995 986
996 if (ENABLE_PACKAGESPEC_SUPPORT) { 987 // Start by looking for .packages.
997 // Start by looking for .packages. 988 packageSpec = folder.getChild(PACKAGE_SPEC_NAME);
998 packageSpec = folder.getChild(PACKAGE_SPEC_NAME);
999 }
1000 989
1001 // Fall back to looking for a pubspec. 990 // Fall back to looking for a pubspec.
1002 if (packageSpec == null || !packageSpec.exists) { 991 if (packageSpec == null || !packageSpec.exists) {
1003 packageSpec = folder.getChild(PUBSPEC_NAME); 992 packageSpec = folder.getChild(PUBSPEC_NAME);
1004 } 993 }
1005 return packageSpec; 994 return packageSpec;
1006 } 995 }
1007 996
1008 /** 997 /**
1009 * Return the [ContextInfo] for the "innermost" context whose associated 998 * Return the [ContextInfo] for the "innermost" context whose associated
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 } 1052 }
1064 // handle the change 1053 // handle the change
1065 switch (event.type) { 1054 switch (event.type) {
1066 case ChangeType.ADD: 1055 case ChangeType.ADD:
1067 if (_isInPackagesDir(path, info.folder)) { 1056 if (_isInPackagesDir(path, info.folder)) {
1068 return; 1057 return;
1069 } 1058 }
1070 1059
1071 Resource resource = resourceProvider.getResource(path); 1060 Resource resource = resourceProvider.getResource(path);
1072 1061
1073 if (ENABLE_PACKAGESPEC_SUPPORT) { 1062 String directoryPath = pathContext.dirname(path);
1074 String directoryPath = pathContext.dirname(path);
1075 1063
1076 // Check to see if we need to create a new context. 1064 // Check to see if we need to create a new context.
1077 if (info.isTopLevel) { 1065 if (info.isTopLevel) {
1078 // Only create a new context if this is not the same directory 1066 // Only create a new context if this is not the same directory
1079 // described by our info object. 1067 // described by our info object.
1080 if (info.folder.path != directoryPath) { 1068 if (info.folder.path != directoryPath) {
1081 if (_isPubspec(path)) { 1069 if (_isPubspec(path)) {
1082 // Check for a sibling .packages file. 1070 // Check for a sibling .packages file.
1083 if (!resourceProvider 1071 if (!resourceProvider
1084 .getFile(pathContext.join(directoryPath, PACKAGE_SPEC_NAME)) 1072 .getFile(pathContext.join(directoryPath, PACKAGE_SPEC_NAME))
1085 .exists) { 1073 .exists) {
1086 _extractContext(info, resource); 1074 _extractContext(info, resource);
1087 return; 1075 return;
1088 }
1089 }
1090 if (_isPackagespec(path)) {
1091 // Check for a sibling pubspec.yaml file.
1092 if (!resourceProvider
1093 .getFile(pathContext.join(directoryPath, PUBSPEC_NAME))
1094 .exists) {
1095 _extractContext(info, resource);
1096 return;
1097 }
1098 } 1076 }
1099 } 1077 }
1100 } 1078 if (_isPackagespec(path)) {
1101 } else { 1079 // Check for a sibling pubspec.yaml file.
1102 // pubspec was added in a sub-folder, extract a new context 1080 if (!resourceProvider
1103 if (_isPubspec(path) && 1081 .getFile(pathContext.join(directoryPath, PUBSPEC_NAME))
1104 info.isTopLevel && 1082 .exists) {
1105 !info.isPathToPackageDescription(path)) { 1083 _extractContext(info, resource);
1106 _extractContext(info, resource); 1084 return;
1107 return; 1085 }
1086 }
1108 } 1087 }
1109 } 1088 }
1110 1089
1111 // If the file went away and was replaced by a folder before we 1090 // If the file went away and was replaced by a folder before we
1112 // had a chance to process the event, resource might be a Folder. In 1091 // had a chance to process the event, resource might be a Folder. In
1113 // that case don't add it. 1092 // that case don't add it.
1114 if (resource is File) { 1093 if (resource is File) {
1115 File file = resource; 1094 File file = resource;
1116 if (callbacks.shouldFileBeAnalyzed(file)) { 1095 if (callbacks.shouldFileBeAnalyzed(file)) {
1117 ChangeSet changeSet = new ChangeSet(); 1096 ChangeSet changeSet = new ChangeSet();
1118 Source source = createSourceInContext(info.context, file); 1097 Source source = createSourceInContext(info.context, file);
1119 changeSet.addedSource(source); 1098 changeSet.addedSource(source);
1120 callbacks.applyChangesToContext(info.folder, changeSet); 1099 callbacks.applyChangesToContext(info.folder, changeSet);
1121 info.sources[path] = source; 1100 info.sources[path] = source;
1122 } 1101 }
1123 } 1102 }
1124 break; 1103 break;
1125 case ChangeType.REMOVE: 1104 case ChangeType.REMOVE:
1126 1105
1127 // If package spec info is removed, check to see if we can merge context s. 1106 // If package spec info is removed, check to see if we can merge context s.
1128 // Note that it's important to verify that there is NEITHER a .packages nor a 1107 // Note that it's important to verify that there is NEITHER a .packages nor a
1129 // lingering pubspec.yaml before merging. 1108 // lingering pubspec.yaml before merging.
1130 if (!info.isTopLevel) { 1109 if (!info.isTopLevel) {
1131 if (ENABLE_PACKAGESPEC_SUPPORT) { 1110 String directoryPath = pathContext.dirname(path);
1132 String directoryPath = pathContext.dirname(path);
1133 1111
1134 // Only merge if this is the same directory described by our info ob ject. 1112 // Only merge if this is the same directory described by our info obje ct.
1135 if (info.folder.path == directoryPath) { 1113 if (info.folder.path == directoryPath) {
1136 if (_isPubspec(path)) { 1114 if (_isPubspec(path)) {
1137 // Check for a sibling .packages file. 1115 // Check for a sibling .packages file.
1138 if (!resourceProvider 1116 if (!resourceProvider
1139 .getFile(pathContext.join(directoryPath, PACKAGE_SPEC_NAME)) 1117 .getFile(pathContext.join(directoryPath, PACKAGE_SPEC_NAME))
1140 .exists) { 1118 .exists) {
1141 _mergeContext(info); 1119 _mergeContext(info);
1142 return; 1120 return;
1143 }
1144 }
1145 if (_isPackagespec(path)) {
1146 // Check for a sibling pubspec.yaml file.
1147 if (!resourceProvider
1148 .getFile(pathContext.join(directoryPath, PUBSPEC_NAME))
1149 .exists) {
1150 _mergeContext(info);
1151 return;
1152 }
1153 } 1121 }
1154 } 1122 }
1155 } else { 1123 if (_isPackagespec(path)) {
1156 if (info.isPathToPackageDescription(path)) { 1124 // Check for a sibling pubspec.yaml file.
1157 _mergeContext(info); 1125 if (!resourceProvider
1158 return; 1126 .getFile(pathContext.join(directoryPath, PUBSPEC_NAME))
1127 .exists) {
1128 _mergeContext(info);
1129 return;
1130 }
1159 } 1131 }
1160 } 1132 }
1161 } 1133 }
1162 1134
1163 List<Source> sources = info.context.getSourcesWithFullName(path); 1135 List<Source> sources = info.context.getSourcesWithFullName(path);
1164 if (!sources.isEmpty) { 1136 if (!sources.isEmpty) {
1165 ChangeSet changeSet = new ChangeSet(); 1137 ChangeSet changeSet = new ChangeSet();
1166 sources.forEach((Source source) { 1138 sources.forEach((Source source) {
1167 changeSet.removedSource(source); 1139 changeSet.removedSource(source);
1168 }); 1140 });
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 var path = resourceProvider.pathContext.fromUri(uri); 1446 var path = resourceProvider.pathContext.fromUri(uri);
1475 packageMap[name] = <Folder>[resourceProvider.getFolder(path)]; 1447 packageMap[name] = <Folder>[resourceProvider.getFolder(path)];
1476 } 1448 }
1477 }); 1449 });
1478 return <UriResolver>[new SdkExtUriResolver(packageMap)]; 1450 return <UriResolver>[new SdkExtUriResolver(packageMap)];
1479 } else { 1451 } else {
1480 return const <UriResolver>[]; 1452 return const <UriResolver>[];
1481 } 1453 }
1482 } 1454 }
1483 } 1455 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/context_manager_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698