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

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

Issue 1042293003: Recognize nested pubspecs (issue 22907) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
« 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 9
10 import 'package:analysis_server/src/analysis_server.dart'; 10 import 'package:analysis_server/src/analysis_server.dart';
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 try { 328 try {
329 children = folder.getChildren(); 329 children = folder.getChildren();
330 } on FileSystemException { 330 } on FileSystemException {
331 // The directory either doesn't exist or cannot be read. Either way, there 331 // The directory either doesn't exist or cannot be read. Either way, there
332 // are no children that need to be added. 332 // are no children that need to be added.
333 return; 333 return;
334 } 334 }
335 for (Resource child in children) { 335 for (Resource child in children) {
336 String path = child.path; 336 String path = child.path;
337 // ignore excluded files or folders 337 // ignore excluded files or folders
338 if (_isExcluded(path)) { 338 if (_isExcluded(path) || info.excludes(path)) {
339 continue; 339 continue;
340 } 340 }
341 // add files, recurse into folders 341 // add files, recurse into folders
342 if (child is File) { 342 if (child is File) {
343 if (_shouldFileBeAnalyzed(child)) { 343 if (_shouldFileBeAnalyzed(child)) {
344 Source source = createSourceInContext(info.context, child); 344 Source source = createSourceInContext(info.context, child);
345 changeSet.addedSource(source); 345 changeSet.addedSource(source);
346 info.sources[path] = source; 346 info.sources[path] = source;
347 } 347 }
348 } else if (child is Folder) { 348 } else if (child is Folder) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 info.changeSubscription = folder.changes.listen((WatchEvent event) { 393 info.changeSubscription = folder.changes.listen((WatchEvent event) {
394 _handleWatchEvent(folder, info, event); 394 _handleWatchEvent(folder, info, event);
395 }); 395 });
396 UriResolver packageUriResolver = _computePackageUriResolver(folder, info); 396 UriResolver packageUriResolver = _computePackageUriResolver(folder, info);
397 info.context = addContext(folder, packageUriResolver); 397 info.context = addContext(folder, packageUriResolver);
398 info.context.name = folder.path; 398 info.context.name = folder.path;
399 return info; 399 return info;
400 } 400 }
401 401
402 /** 402 /**
403 * Creates a new context associated with [folder]. 403 * Potentially create a new context associated with the given [folder].
404 * 404 *
405 * If there are subfolders with 'pubspec.yaml' files, separate contexts 405 * If there are subfolders with 'pubspec.yaml' files, separate contexts are
406 * are created for them, and excluded from the context associated with 406 * created for them and excluded from the context associated with the
407 * [folder]. 407 * [folder].
408 * 408 *
409 * If [folder] itself contains a 'pubspec.yaml' file, subfolders are ignored.
410 *
411 * If [withPubspecOnly] is `true`, a context will be created only if there 409 * If [withPubspecOnly] is `true`, a context will be created only if there
412 * is a 'pubspec.yaml' file in [folder]. 410 * is a 'pubspec.yaml' file in the [folder].
413 * 411 *
414 * Returns create pubspec-based contexts. 412 * Returns create pubspec-based contexts.
415 */ 413 */
416 List<_ContextInfo> _createContexts(Folder folder, bool withPubspecOnly) { 414 List<_ContextInfo> _createContexts(Folder folder, bool withPubspecOnly) {
417 // check whether there is a pubspec in the folder
418 File pubspecFile = folder.getChild(PUBSPEC_NAME);
419 if (pubspecFile.exists) {
420 _ContextInfo info =
421 _createContextWithSources(folder, pubspecFile, <_ContextInfo>[]);
422 return [info];
423 }
424 // try to find subfolders with pubspec files 415 // try to find subfolders with pubspec files
425 List<_ContextInfo> children = <_ContextInfo>[]; 416 List<_ContextInfo> children = <_ContextInfo>[];
426 try { 417 try {
427 for (Resource child in folder.getChildren()) { 418 for (Resource child in folder.getChildren()) {
428 if (child is Folder) { 419 if (child is Folder) {
429 List<_ContextInfo> childContexts = _createContexts(child, true); 420 children.addAll(_createContexts(child, true));
430 children.addAll(childContexts);
431 } 421 }
432 } 422 }
433 } on FileSystemException { 423 } on FileSystemException {
434 // The directory either doesn't exist or cannot be read. Either way, there 424 // The directory either doesn't exist or cannot be read. Either way, there
435 // are no subfolders that need to be added. 425 // are no subfolders that need to be added.
436 } 426 }
427 // check whether there is a pubspec in the folder
428 File pubspecFile = folder.getChild(PUBSPEC_NAME);
429 if (pubspecFile.exists) {
430 return <_ContextInfo>[
431 _createContextWithSources(folder, pubspecFile, children)
432 ];
433 }
437 // no pubspec, done 434 // no pubspec, done
438 if (withPubspecOnly) { 435 if (withPubspecOnly) {
439 return children; 436 return children;
440 } 437 }
441 // OK, create a context without a pubspec 438 // OK, create a context without a pubspec
442 _createContextWithSources(folder, pubspecFile, children); 439 return <_ContextInfo>[
443 return children; 440 _createContextWithSources(folder, pubspecFile, children)
441 ];
444 } 442 }
445 443
446 /** 444 /**
447 * Create a new context associated with the given [folder]. The [pubspecFile] 445 * Create a new context associated with the given [folder]. The [pubspecFile]
448 * is the `pubspec.yaml` file contained in the folder. Add any sources that 446 * is the `pubspec.yaml` file contained in the folder. Add any sources that
449 * are not included in one of the [children] to the context. 447 * are not included in one of the [children] to the context.
450 */ 448 */
451 _ContextInfo _createContextWithSources( 449 _ContextInfo _createContextWithSources(
452 Folder folder, File pubspecFile, List<_ContextInfo> children) { 450 Folder folder, File pubspecFile, List<_ContextInfo> children) {
453 _ContextInfo info = _createContext(folder, pubspecFile, children); 451 _ContextInfo info = _createContext(folder, pubspecFile, children);
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 return excludes(resource.path); 751 return excludes(resource.path);
754 } 752 }
755 753
756 /** 754 /**
757 * Returns `true` if [path] is the pubspec file of this context. 755 * Returns `true` if [path] is the pubspec file of this context.
758 */ 756 */
759 bool isPubspec(String path) { 757 bool isPubspec(String path) {
760 return path == pubspecPath; 758 return path == pubspecPath;
761 } 759 }
762 } 760 }
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