mirror of
https://github.com/dart-lang/sdk
synced 2024-09-22 09:32:59 +00:00
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:
parent
9d5154a1fd
commit
dfc35faaf9
|
@ -844,9 +844,13 @@ class ContextManagerImpl implements ContextManager {
|
|||
packageSpec = folder.getChild(PUBSPEC_NAME);
|
||||
}
|
||||
|
||||
bool parentCreated = false;
|
||||
if (packageSpec.exists || !withPackageSpecOnly) {
|
||||
parentCreated = true;
|
||||
bool createContext = packageSpec.exists || !withPackageSpecOnly;
|
||||
if (withPackageSpecOnly && packageSpec.exists &&
|
||||
(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);
|
||||
}
|
||||
|
||||
|
@ -854,7 +858,9 @@ class ContextManagerImpl implements ContextManager {
|
|||
try {
|
||||
for (Resource child in folder.getChildren()) {
|
||||
if (child is Folder) {
|
||||
_createContexts(parent, child, true);
|
||||
if (!parent.ignored(child.path)) {
|
||||
_createContexts(parent, child, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} on FileSystemException {
|
||||
|
@ -862,7 +868,7 @@ class ContextManagerImpl implements ContextManager {
|
|||
// are no subfolders that need to be added.
|
||||
}
|
||||
|
||||
if (parentCreated) {
|
||||
if (createContext) {
|
||||
// Now that the child contexts have been created, add the sources that
|
||||
// don't belong to the children.
|
||||
ChangeSet changeSet = new ChangeSet();
|
||||
|
|
|
@ -231,6 +231,96 @@ analyzer:
|
|||
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() {
|
||||
// create a context with a .packages file
|
||||
String packagespecFile = posix.join(projPath, '.packages');
|
||||
|
|
|
@ -62,4 +62,13 @@ class PathFilter {
|
|||
|
||||
/// Returns the relative portion of [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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue