Make exclude list also exclude contexts

- Only create a context if the directory/.packages/pubspec.yaml is not excluded.
- Add tests.

Fixes: https://github.com/dart-lang/sdk/issues/23941

R=brianwilkerson@google.com, devoncarew@google.com, paulberry@google.com, pquitslund@google.com

Review URL: https://codereview.chromium.org//1263443005 .
This commit is contained in:
John McCutchan 2015-08-03 13:54:17 -07:00
parent 9d5154a1fd
commit dfc35faaf9
3 changed files with 110 additions and 5 deletions

View file

@ -844,9 +844,13 @@ class ContextManagerImpl implements ContextManager {
packageSpec = folder.getChild(PUBSPEC_NAME); packageSpec = folder.getChild(PUBSPEC_NAME);
} }
bool parentCreated = false; bool createContext = packageSpec.exists || !withPackageSpecOnly;
if (packageSpec.exists || !withPackageSpecOnly) { if (withPackageSpecOnly && packageSpec.exists &&
parentCreated = true; (parent != null) && parent.ignored(packageSpec.path)) {
// Don't create a context if the package spec is required and ignored.
createContext = false;
}
if (createContext) {
parent = _createContext(parent, folder, packageSpec); parent = _createContext(parent, folder, packageSpec);
} }
@ -854,7 +858,9 @@ class ContextManagerImpl implements ContextManager {
try { try {
for (Resource child in folder.getChildren()) { for (Resource child in folder.getChildren()) {
if (child is Folder) { if (child is Folder) {
_createContexts(parent, child, true); if (!parent.ignored(child.path)) {
_createContexts(parent, child, true);
}
} }
} }
} on FileSystemException { } on FileSystemException {
@ -862,7 +868,7 @@ class ContextManagerImpl implements ContextManager {
// are no subfolders that need to be added. // are no subfolders that need to be added.
} }
if (parentCreated) { if (createContext) {
// Now that the child contexts have been created, add the sources that // Now that the child contexts have been created, add the sources that
// don't belong to the children. // don't belong to the children.
ChangeSet changeSet = new ChangeSet(); ChangeSet changeSet = new ChangeSet();

View file

@ -231,6 +231,96 @@ analyzer:
expect(files[0], equals('/my/proj/lib/main.dart')); expect(files[0], equals('/my/proj/lib/main.dart'));
} }
test_path_filter_child_contexts_option() async {
// Create files.
String libPath = newFolder([projPath, LIB_NAME]);
newFile([libPath, 'main.dart']);
newFile([libPath, 'pubspec.yaml'], r'''
name: foobar
''');
String otherLibPath = newFolder([projPath, 'other_lib']);
newFile([otherLibPath, 'entry.dart']);
newFile([otherLibPath, 'pubspec.yaml'], r'''
name: other_lib
''');
// Setup analysis options file with ignore list that ignores the 'other_lib'
// directory by name.
newFile([projPath, '.analysis_options'], r'''
analyzer:
exclude:
- 'other_lib'
''');
// Setup context.
manager.setRoots(<String>[projPath], <String>[], <String, String>{});
// Verify that the context in other_lib wasn't created and that the
// context in lib was created.
var contexts = manager.contextsInAnalysisRoot(
resourceProvider.newFolder(projPath));
expect(contexts.length, 2);
expect(contexts[0].name, equals('/my/proj'));
expect(contexts[1].name, equals('/my/proj/lib'));
}
test_path_filter_wildcard_child_contexts_option() async {
// Create files.
String libPath = newFolder([projPath, LIB_NAME]);
newFile([libPath, 'main.dart']);
newFile([libPath, 'pubspec.yaml'], r'''
name: foobar
''');
String otherLibPath = newFolder([projPath, 'other_lib']);
newFile([otherLibPath, 'entry.dart']);
newFile([otherLibPath, 'pubspec.yaml'], r'''
name: other_lib
''');
// Setup analysis options file with ignore list that ignores 'other_lib'
// and all immediate children.
newFile([projPath, '.analysis_options'], r'''
analyzer:
exclude:
- 'other_lib/*'
''');
// Setup context.
manager.setRoots(<String>[projPath], <String>[], <String, String>{});
// Verify that the context in other_lib wasn't created and that the
// context in lib was created.
var contexts = manager.contextsInAnalysisRoot(
resourceProvider.newFolder(projPath));
expect(contexts.length, 2);
expect(contexts[0].name, equals('/my/proj'));
expect(contexts[1].name, equals('/my/proj/lib'));
}
test_path_filter_recursive_wildcard_child_contexts_option() async {
// Create files.
String libPath = newFolder([projPath, LIB_NAME]);
newFile([libPath, 'main.dart']);
newFile([libPath, 'pubspec.yaml'], r'''
name: foobar
''');
String otherLibPath = newFolder([projPath, 'other_lib']);
newFile([otherLibPath, 'entry.dart']);
newFile([otherLibPath, 'pubspec.yaml'], r'''
name: other_lib
''');
// Setup analysis options file with ignore list that ignores 'other_lib'
// and all descendants.
newFile([projPath, '.analysis_options'], r'''
analyzer:
exclude:
- 'other_lib/**'
''');
// Setup context.
manager.setRoots(<String>[projPath], <String>[], <String, String>{});
// Verify that the context in other_lib wasn't created and that the
// context in lib was created.
var contexts = manager.contextsInAnalysisRoot(
resourceProvider.newFolder(projPath));
expect(contexts.length, 2);
expect(contexts[0].name, equals('/my/proj'));
expect(contexts[1].name, equals('/my/proj/lib'));
}
test_refresh_folder_with_packagespec() { test_refresh_folder_with_packagespec() {
// create a context with a .packages file // create a context with a .packages file
String packagespecFile = posix.join(projPath, '.packages'); String packagespecFile = posix.join(projPath, '.packages');

View file

@ -62,4 +62,13 @@ class PathFilter {
/// Returns the relative portion of [path] from [root]. /// Returns the relative portion of [path] from [root].
String _relative(String path) => pathContext.relative(path, from: root); String _relative(String path) => pathContext.relative(path, from: root);
String toString() {
StringBuffer sb = new StringBuffer();
for (var pattern in _ignorePatterns) {
sb.write('$pattern ');
}
sb.writeln('');
return sb.toString();
}
} }