1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.internal;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.impl.DirectoryIndexExcludePolicy;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
import com.intellij.openapi.vfs.newvfs.persistent.FSRecords;
import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS;
import java.util.*;
/**
* @author nik
*/
@SuppressWarnings("UseOfSystemOutOrSystemErr")
public class DumpVfsInfoForExcludedFilesAction extends DumbAwareAction {
public DumpVfsInfoForExcludedFilesAction() {
super("Dump VFS content for files under excluded roots");
}
@Override
public void actionPerformed(AnActionEvent e) {
Project project = e.getProject();
if (project == null) return;
Set<String> excludeRoots = new HashSet<String>();
for (Module module : ModuleManager.getInstance(project).getModules()) {
Collections.addAll(excludeRoots, ModuleRootManager.getInstance(module).getExcludeRootUrls());
}
for (DirectoryIndexExcludePolicy policy : DirectoryIndexExcludePolicy.EP_NAME.getExtensions(project)) {
for (VirtualFile file : policy.getExcludeRootsForProject()) {
excludeRoots.add(file.getUrl());
}
}
if (excludeRoots.isEmpty()) {
System.out.println("No excluded roots found in project.");
}
for (String root : excludeRoots) {
VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(root);
if (file == null) {
System.out.println(root + " not in VFS");
continue;
}
dumpChildrenInDbRecursively(file, 0);
}
}
private static void dumpChildrenInDbRecursively(VirtualFile dir, int depth) {
if (!(dir instanceof NewVirtualFile)) {
System.out.println(dir.getPresentableUrl() + ": not in db (" + dir.getClass().getName() + ")");
return;
}
List<VirtualFile> dirs = new ArrayList<VirtualFile>();
int inDb = 0, contentInDb = 0, nullChildren = 0;
PersistentFS persistentFS = PersistentFS.getInstance();
if (persistentFS.wereChildrenAccessed(dir)) {
for (String name : persistentFS.listPersisted(dir)) {
inDb++;
NewVirtualFile child = ((NewVirtualFile)dir).refreshAndFindChild(name);
if (child == null) {
nullChildren++;
continue;
}
if (child.isDirectory()) {
dirs.add(child);
}
else if (FSRecords.getContentId(child.getId()) != 0) {
contentInDb++;
}
}
}
System.out.print(dir.getPresentableUrl() + ": " + inDb + " children in db");
if (contentInDb > 0) {
System.out.print(", content of " + contentInDb + " files in db");
}
if (nullChildren > 0) {
System.out.print(", " + nullChildren + " invalid files in db");
}
System.out.println();
if (depth > 10) {
System.out.println("too deep, skipping children");
}
else {
for (VirtualFile childDir : dirs) {
dumpChildrenInDbRecursively(childDir, depth+1);
}
}
}
}
|