use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class VcsDirtyScopeImpl method addDirtyDirRecursively.
/**
* Add dirty directory recursively. If there are already dirty entries
* that are descendants or ancestors for the added directory, the contained
* entries are dropped from scope.
*
* @param newcomer a new directory to add
*/
@Override
public void addDirtyDirRecursively(final FilePath newcomer) {
final VirtualFile vcsRoot = myVcsManager.getVcsRootFor(newcomer);
if (vcsRoot == null)
return;
myAffectedContentRoots.add(vcsRoot);
for (Map.Entry<VirtualFile, THashSet<FilePath>> entry : myDirtyFiles.entrySet()) {
final VirtualFile groupRoot = entry.getKey();
if (groupRoot != null && VfsUtilCore.isAncestor(vcsRoot, groupRoot, false)) {
final THashSet<FilePath> files = entry.getValue();
if (files != null) {
for (Iterator<FilePath> it = files.iterator(); it.hasNext(); ) {
FilePath oldBoy = it.next();
if (oldBoy.isUnder(newcomer, false)) {
it.remove();
}
}
}
}
}
THashSet<FilePath> dirsByRoot = myDirtyDirectoriesRecursively.get(vcsRoot);
if (dirsByRoot == null) {
dirsByRoot = newFilePathsSet();
myDirtyDirectoriesRecursively.put(vcsRoot, dirsByRoot);
} else {
for (Iterator<FilePath> it = dirsByRoot.iterator(); it.hasNext(); ) {
FilePath oldBoy = it.next();
if (newcomer.isUnder(oldBoy, false)) {
return;
}
if (oldBoy.isUnder(newcomer, false)) {
it.remove();
}
}
}
dirsByRoot.add(newcomer);
}
use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class VfsUtil method getCommonAncestors.
/**
* Gets the array of common ancestors for passed files.
*
* @param files array of files
* @return array of common ancestors for passed files
*/
@NotNull
public static VirtualFile[] getCommonAncestors(@NotNull VirtualFile[] files) {
// Separate files by first component in the path.
HashMap<VirtualFile, Set<VirtualFile>> map = new HashMap<>();
for (VirtualFile aFile : files) {
VirtualFile directory = aFile.isDirectory() ? aFile : aFile.getParent();
if (directory == null)
return VirtualFile.EMPTY_ARRAY;
VirtualFile[] path = getPathComponents(directory);
Set<VirtualFile> filesSet;
final VirtualFile firstPart = path[0];
if (map.containsKey(firstPart)) {
filesSet = map.get(firstPart);
} else {
filesSet = new THashSet<>();
map.put(firstPart, filesSet);
}
filesSet.add(directory);
}
// Find common ancestor for each set of files.
ArrayList<VirtualFile> ancestorsList = new ArrayList<>();
for (Set<VirtualFile> filesSet : map.values()) {
VirtualFile ancestor = null;
for (VirtualFile file : filesSet) {
if (ancestor == null) {
ancestor = file;
continue;
}
ancestor = getCommonAncestor(ancestor, file);
//assertTrue(ancestor != null);
}
ancestorsList.add(ancestor);
filesSet.clear();
}
return toVirtualFileArray(ancestorsList);
}
use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class CacheUpdateRunner method processFiles.
public static void processFiles(final ProgressIndicator indicator, boolean processInReadAction, Collection<VirtualFile> files, Project project, Consumer<FileContent> processor) {
indicator.checkCanceled();
final FileContentQueue queue = new FileContentQueue(files, indicator);
final double total = files.size();
queue.startLoading();
ProgressUpdater progressUpdater = new ProgressUpdater() {
final Set<VirtualFile> myFilesBeingProcessed = new THashSet<>();
final AtomicInteger myNumberOfFilesProcessed = new AtomicInteger();
@Override
public void processingStarted(VirtualFile virtualFile) {
indicator.checkCanceled();
synchronized (myFilesBeingProcessed) {
boolean added = myFilesBeingProcessed.add(virtualFile);
if (added) {
indicator.setFraction(myNumberOfFilesProcessed.incrementAndGet() / total);
}
if (added) {
VirtualFile parent = virtualFile.getParent();
if (parent != null)
indicator.setText2(parent.getPresentableUrl());
}
}
}
@Override
public void processingSuccessfullyFinished(VirtualFile virtualFile) {
synchronized (myFilesBeingProcessed) {
boolean removed = myFilesBeingProcessed.remove(virtualFile);
assert removed;
}
}
};
while (!project.isDisposed()) {
indicator.checkCanceled();
// todo wait for the user...
if (processSomeFilesWhileUserIsInactive(queue, progressUpdater, processInReadAction, project, processor)) {
break;
}
}
if (project.isDisposed()) {
indicator.cancel();
indicator.checkCanceled();
}
}
use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class LibraryImpl method disposeMyPointers.
private void disposeMyPointers() {
for (VirtualFilePointerContainer container : new THashSet<>(myRoots.values())) {
container.killAll();
}
if (myExcludedRoots != null) {
myExcludedRoots.killAll();
}
Disposer.dispose(myPointersDisposable);
Disposer.register(this, myPointersDisposable);
}
use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class ThreadTracker method checkLeak.
@TestOnly
public void checkLeak() throws AssertionError {
NettyUtil.awaitQuiescenceOfGlobalEventExecutor(100, TimeUnit.SECONDS);
ShutDownTracker.getInstance().waitFor(100, TimeUnit.SECONDS);
try {
if (myDefaultProjectInitialized != ((ProjectManagerImpl) ProjectManager.getInstance()).isDefaultProjectInitialized())
return;
Collection<Thread> after = new THashSet<>(getThreads());
after.removeAll(before);
for (final Thread thread : after) {
if (thread == Thread.currentThread())
continue;
ThreadGroup group = thread.getThreadGroup();
if (group != null && "system".equals(group.getName()))
continue;
if (isWellKnownOffender(thread))
continue;
if (!thread.isAlive())
continue;
if (thread.getStackTrace().length == 0) {
thread.interrupt();
if (new WaitFor(10000) {
@Override
protected boolean condition() {
return !thread.isAlive();
}
}.isConditionRealized()) {
continue;
}
}
StackTraceElement[] stackTrace = thread.getStackTrace();
if (stackTrace.length == 0) {
// ignore threads with empty stack traces for now. Seems they are zombies unwilling to die.
continue;
}
if (isIdleApplicationPoolThread(thread, stackTrace)) {
continue;
}
@SuppressWarnings("NonConstantStringShouldBeStringBuffer") String trace = "Thread leaked: " + thread + "; " + thread.getState() + " (" + thread.isAlive() + ")\n--- its stacktrace:\n";
for (final StackTraceElement stackTraceElement : stackTrace) {
trace += " at " + stackTraceElement + "\n";
}
trace += "---\n";
Assert.fail(trace);
}
} finally {
before.clear();
}
}
Aggregations