package org.eclipse.jdt.internal.core.search.indexing;
import java.io.IOException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.internal.core.index.Index;
import org.eclipse.jdt.internal.core.search.processing.JobManager;
import org.eclipse.jdt.internal.core.util.Util;
class RemoveFolderFromIndex extends IndexRequest {
IPath folderPath;
char[][] inclusionPatterns;
char[][] exclusionPatterns;
public RemoveFolderFromIndex(IPath folderPath, char[][] inclusionPatterns, char[][] exclusionPatterns, IProject project, IndexManager manager) {
super(project.getFullPath(), manager);
this.folderPath = folderPath;
this.inclusionPatterns = inclusionPatterns;
this.exclusionPatterns = exclusionPatterns;
}
@Override
public boolean execute(IProgressMonitor progressMonitor) {
if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true;
Index index = this.manager.getIndex(this.containerPath, true, false );
if (index == null) return true;
ReadWriteMonitor monitor = index.monitor;
if (monitor == null) return true;
try {
monitor.enterRead();
String containerRelativePath = Util.relativePath(this.folderPath, this.containerPath.segmentCount());
String[] paths = index.queryDocumentNames(containerRelativePath);
if (paths != null) {
if (this.exclusionPatterns == null && this.inclusionPatterns == null) {
for (int i = 0, max = paths.length; i < max; i++) {
this.manager.remove(paths[i], this.containerPath);
}
} else {
for (int i = 0, max = paths.length; i < max; i++) {
String documentPath = this.containerPath.toString() + '/' + paths[i];
if (!Util.isExcluded(new Path(documentPath), this.inclusionPatterns, this.exclusionPatterns, false))
this.manager.remove(paths[i], this.containerPath);
}
}
}
} catch (IOException e) {
if (JobManager.VERBOSE) {
Util.verbose("-> failed to remove " + this.folderPath + " from index because of the following exception:", System.err);
e.printStackTrace();
}
return false;
} finally {
monitor.exitRead();
}
return true;
}
@Override
public String toString() {
return "removing " + this.folderPath + " from index " + this.containerPath;
}
}