use of org.eclipse.jdt.internal.core.index.IndexLocation in project che by eclipse.
the class IndexManager method cleanUpIndexes.
/*
* Removes unused indexes from disk.
*/
public void cleanUpIndexes() {
SimpleSet knownPaths = new SimpleSet();
IJavaSearchScope scope = BasicSearchEngine.createWorkspaceScope();
PatternSearchJob job = new PatternSearchJob(null, SearchEngine.getDefaultSearchParticipant(), scope, null);
Index[] selectedIndexes = job.getIndexes(null);
for (int i = 0, l = selectedIndexes.length; i < l; i++) {
IndexLocation IndexLocation = selectedIndexes[i].getIndexLocation();
knownPaths.add(IndexLocation);
}
if (this.indexStates != null) {
Object[] keys = this.indexStates.keyTable;
IndexLocation[] locations = new IndexLocation[this.indexStates.elementSize];
int count = 0;
for (int i = 0, l = keys.length; i < l; i++) {
IndexLocation key = (IndexLocation) keys[i];
if (key != null && !knownPaths.includes(key))
locations[count++] = key;
}
if (count > 0)
removeIndexesState(locations);
}
deleteIndexFiles(knownPaths);
}
use of org.eclipse.jdt.internal.core.index.IndexLocation in project che by eclipse.
the class IndexManager method aboutToUpdateIndex.
public synchronized void aboutToUpdateIndex(IPath containerPath, Integer newIndexState) {
// newIndexState is either UPDATING_STATE or REBUILDING_STATE
// must tag the index as inconsistent, in case we exit before the update job is started
IndexLocation indexLocation = computeIndexLocation(containerPath);
Object state = getIndexStates().get(indexLocation);
Integer currentIndexState = state == null ? UNKNOWN_STATE : (Integer) state;
// already rebuilding the index
if (currentIndexState.compareTo(REBUILDING_STATE) >= 0)
return;
int compare = newIndexState.compareTo(currentIndexState);
if (compare > 0) {
// so UPDATING_STATE replaces SAVED_STATE and REBUILDING_STATE replaces everything
updateIndexState(indexLocation, newIndexState);
} else if (compare < 0 && this.indexes.get(indexLocation) == null) {
// if already cached index then there is nothing more to do
rebuildIndex(indexLocation, containerPath);
}
}
use of org.eclipse.jdt.internal.core.index.IndexLocation in project che by eclipse.
the class IndexManager method writeSavedIndexNamesFile.
private void writeSavedIndexNamesFile() {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(this.savedIndexNamesFile));
writer.write(DiskIndex.SIGNATURE);
writer.write('+');
writer.write(getJavaPluginWorkingLocation().toOSString());
writer.write('\n');
Object[] keys = this.indexStates.keyTable;
Object[] states = this.indexStates.valueTable;
for (int i = 0, l = states.length; i < l; i++) {
IndexLocation key = (IndexLocation) keys[i];
if (key != null && states[i] == SAVED_STATE) {
writer.write(key.fileName());
writer.write('\n');
}
}
} catch (IOException ignored) {
if (JobManager.VERBOSE)
//$NON-NLS-1$
Util.verbose("Failed to write saved index file names", System.err);
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
// ignore
}
}
}
}
use of org.eclipse.jdt.internal.core.index.IndexLocation in project che by eclipse.
the class IndexManager method recreateIndex.
/**
* Recreates the index for a given path, keeping the same read-write monitor.
* Returns the new empty index or null if it didn't exist before.
* Warning: Does not check whether index is consistent (not being used)
*/
public synchronized Index recreateIndex(IPath containerPath) {
// only called to over write an existing cached index...
String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
try {
// Path is already canonical
IndexLocation indexLocation = computeIndexLocation(containerPath);
Index index = getIndex(indexLocation);
ReadWriteMonitor monitor = index == null ? null : index.monitor;
if (JobManager.VERBOSE)
//$NON-NLS-1$ //$NON-NLS-2$
Util.verbose("-> recreating index: " + indexLocation + " for path: " + containerPathString);
index = new Index(indexLocation, containerPathString, false);
this.indexes.put(indexLocation, index);
index.monitor = monitor;
return index;
} catch (IOException e) {
// The file could not be created. Possible reason: the project has been deleted.
if (JobManager.VERBOSE) {
//$NON-NLS-1$
Util.verbose("-> failed to recreate index for path: " + containerPathString);
e.printStackTrace();
}
return null;
}
}
use of org.eclipse.jdt.internal.core.index.IndexLocation in project che by eclipse.
the class IndexManager method jobWasCancelled.
public synchronized void jobWasCancelled(IPath containerPath) {
IndexLocation indexLocation = computeIndexLocation(containerPath);
Index index = getIndex(indexLocation);
if (index != null) {
index.monitor = null;
this.indexes.removeKey(indexLocation);
}
updateIndexState(indexLocation, UNKNOWN_STATE);
}
Aggregations