Search in sources :

Example 11 with IndexLocation

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);
}
Also used : SimpleSet(org.eclipse.jdt.internal.compiler.util.SimpleSet) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) PatternSearchJob(org.eclipse.jdt.internal.core.search.PatternSearchJob) FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation) DiskIndex(org.eclipse.jdt.internal.core.index.DiskIndex) Index(org.eclipse.jdt.internal.core.index.Index)

Example 12 with IndexLocation

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);
    }
}
Also used : FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation)

Example 13 with IndexLocation

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
            }
        }
    }
}
Also used : FileWriter(java.io.FileWriter) FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 14 with IndexLocation

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;
    }
}
Also used : FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation) DiskIndex(org.eclipse.jdt.internal.core.index.DiskIndex) Index(org.eclipse.jdt.internal.core.index.Index) IOException(java.io.IOException)

Example 15 with IndexLocation

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);
}
Also used : FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation) DiskIndex(org.eclipse.jdt.internal.core.index.DiskIndex) Index(org.eclipse.jdt.internal.core.index.Index)

Aggregations

IndexLocation (org.eclipse.jdt.internal.core.index.IndexLocation)22 FileIndexLocation (org.eclipse.jdt.internal.core.index.FileIndexLocation)21 IOException (java.io.IOException)8 DiskIndex (org.eclipse.jdt.internal.core.index.DiskIndex)7 Index (org.eclipse.jdt.internal.core.index.Index)7 IPath (org.eclipse.core.runtime.IPath)6 File (java.io.File)5 IFile (org.eclipse.core.resources.IFile)5 BufferedWriter (java.io.BufferedWriter)3 FileWriter (java.io.FileWriter)3 Path (org.eclipse.core.runtime.Path)3 URL (java.net.URL)2 SearchDocument (org.eclipse.jdt.core.search.SearchDocument)2 SearchParticipant (org.eclipse.jdt.core.search.SearchParticipant)2 SimpleLookupTable (org.eclipse.jdt.internal.compiler.util.SimpleLookupTable)2 SimpleSet (org.eclipse.jdt.internal.compiler.util.SimpleSet)2 LinkedHashSet (java.util.LinkedHashSet)1 CRC32 (java.util.zip.CRC32)1 IFolder (org.eclipse.core.resources.IFolder)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1