Chromium Code Reviews| 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 | 9 |
| 10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 * The [ResourceProvider] using which paths are converted into [Resource]s. | 42 * The [ResourceProvider] using which paths are converted into [Resource]s. |
| 43 */ | 43 */ |
| 44 final ResourceProvider resourceProvider; | 44 final ResourceProvider resourceProvider; |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * The context used to work with file system paths. | 47 * The context used to work with file system paths. |
| 48 */ | 48 */ |
| 49 pathos.Context pathContext; | 49 pathos.Context pathContext; |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * A list of excluded paths - folders and files. | 52 * The list of excluded paths (folders and files) most recently passed to |
| 53 * [setRoots]. | |
| 53 */ | 54 */ |
| 54 List<String> excludedPaths = <String>[]; | 55 List<String> excludedPaths = <String>[]; |
| 55 | 56 |
| 56 /** | 57 /** |
| 58 * The list of included paths (folders and files) most recently passed to | |
| 59 * [setRoots]. | |
| 60 */ | |
| 61 List<String> includedPaths = <String>[]; | |
|
scheglov
2014/09/10 18:37:50
I'd put "included" before "exclude", as we do in s
| |
| 62 | |
| 63 /** | |
| 57 * Provider which is used to determine the mapping from package name to | 64 * Provider which is used to determine the mapping from package name to |
| 58 * package folder. | 65 * package folder. |
| 59 */ | 66 */ |
| 60 final PackageMapProvider packageMapProvider; | 67 final PackageMapProvider packageMapProvider; |
| 61 | 68 |
| 62 ContextManager(this.resourceProvider, this.packageMapProvider) { | 69 ContextManager(this.resourceProvider, this.packageMapProvider) { |
| 63 pathContext = resourceProvider.pathContext; | 70 pathContext = resourceProvider.pathContext; |
| 64 } | 71 } |
| 65 | 72 |
| 66 /** | 73 /** |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 93 // no | 100 // no |
| 94 return false; | 101 return false; |
| 95 } | 102 } |
| 96 | 103 |
| 97 /** | 104 /** |
| 98 * Remove the context associated with the given [folder]. | 105 * Remove the context associated with the given [folder]. |
| 99 */ | 106 */ |
| 100 void removeContext(Folder folder); | 107 void removeContext(Folder folder); |
| 101 | 108 |
| 102 /** | 109 /** |
| 110 * Rebuild the set of contexts from scratch based on the data last sent to | |
| 111 * setRoots(). | |
| 112 */ | |
| 113 void refresh() { | |
| 114 // Destroy old contexts | |
| 115 List<Folder> contextFolders = _contexts.keys.toList(); | |
| 116 contextFolders.forEach(_destroyContext); | |
| 117 | |
| 118 // Rebuild contexts based on the data last sent to setRoots(). | |
| 119 setRoots(includedPaths, excludedPaths); | |
| 120 } | |
| 121 | |
| 122 /** | |
| 103 * Change the set of paths which should be used as starting points to | 123 * Change the set of paths which should be used as starting points to |
| 104 * determine the context directories. | 124 * determine the context directories. |
| 105 */ | 125 */ |
| 106 void setRoots(List<String> includedPaths, List<String> excludedPaths) { | 126 void setRoots(List<String> includedPaths, List<String> excludedPaths) { |
| 107 List<Folder> contextFolders = _contexts.keys.toList(); | 127 List<Folder> contextFolders = _contexts.keys.toList(); |
| 108 // included | 128 // included |
| 109 Set<Folder> includedFolders = new HashSet<Folder>(); | 129 Set<Folder> includedFolders = new HashSet<Folder>(); |
| 110 for (int i = 0; i < includedPaths.length; i++) { | 130 for (int i = 0; i < includedPaths.length; i++) { |
| 111 String path = includedPaths[i]; | 131 String path = includedPaths[i]; |
| 112 Resource resource = resourceProvider.getResource(path); | 132 Resource resource = resourceProvider.getResource(path); |
| 113 if (resource is Folder) { | 133 if (resource is Folder) { |
| 114 includedFolders.add(resource); | 134 includedFolders.add(resource); |
| 115 } else { | 135 } else { |
| 116 // TODO(scheglov) implemented separate files analysis | 136 // TODO(scheglov) implemented separate files analysis |
| 117 throw new UnimplementedError( | 137 throw new UnimplementedError( |
| 118 '$path is not a folder. ' | 138 '$path is not a folder. ' |
| 119 'Only support for folder analysis is implemented currently.'); | 139 'Only support for folder analysis is implemented currently.'); |
| 120 } | 140 } |
| 121 } | 141 } |
| 142 this.includedPaths = includedPaths; | |
| 122 // excluded | 143 // excluded |
| 123 List<String> oldExcludedPaths = this.excludedPaths; | 144 List<String> oldExcludedPaths = this.excludedPaths; |
| 124 this.excludedPaths = excludedPaths; | 145 this.excludedPaths = excludedPaths; |
| 125 // destroy old contexts | 146 // destroy old contexts |
| 126 for (Folder contextFolder in contextFolders) { | 147 for (Folder contextFolder in contextFolders) { |
| 127 bool isIncluded = includedFolders.any((folder) { | 148 bool isIncluded = includedFolders.any((folder) { |
| 128 return folder.isOrContains(contextFolder.path); | 149 return folder.isOrContains(contextFolder.path); |
| 129 }); | 150 }); |
| 130 if (!isIncluded) { | 151 if (!isIncluded) { |
| 131 _destroyContext(contextFolder); | 152 _destroyContext(contextFolder); |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 return excludes(resource.path); | 581 return excludes(resource.path); |
| 561 } | 582 } |
| 562 | 583 |
| 563 /** | 584 /** |
| 564 * Returns `true` if [path] is the pubspec file of this context. | 585 * Returns `true` if [path] is the pubspec file of this context. |
| 565 */ | 586 */ |
| 566 bool isPubspec(String path) { | 587 bool isPubspec(String path) { |
| 567 return path == pubspecPath; | 588 return path == pubspecPath; |
| 568 } | 589 } |
| 569 } | 590 } |
| OLD | NEW |