Search in sources :

Example 21 with IndexLocation

use of org.eclipse.jdt.internal.core.index.IndexLocation in project che by eclipse.

the class IndexManager method computeIndexLocation.

public synchronized IndexLocation computeIndexLocation(IPath containerPath) {
    IndexLocation indexLocation = (IndexLocation) this.indexLocations.get(containerPath);
    if (indexLocation == null) {
        String pathString = containerPath.toOSString();
        CRC32 checksumCalculator = new CRC32();
        checksumCalculator.update(pathString.getBytes());
        //$NON-NLS-1$
        String fileName = Long.toString(checksumCalculator.getValue()) + ".index";
        if (JobManager.VERBOSE)
            //$NON-NLS-1$ //$NON-NLS-2$
            Util.verbose("-> index name for " + pathString + " is " + fileName);
        // to share the indexLocation between the indexLocations and indexStates tables, get the key from the indexStates table
        indexLocation = (IndexLocation) getIndexStates().getKey(new FileIndexLocation(new File(getSavedIndexesDirectory(), fileName)));
        this.indexLocations.put(containerPath, indexLocation);
    }
    return indexLocation;
}
Also used : CRC32(java.util.zip.CRC32) FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation) FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 22 with IndexLocation

use of org.eclipse.jdt.internal.core.index.IndexLocation in project che by eclipse.

the class IndexManager method resetIndex.

/**
     * Resets the index for a given path.
     * Returns true if the index was reset, false otherwise.
     */
public synchronized boolean resetIndex(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);
        if (JobManager.VERBOSE) {
            //$NON-NLS-1$ //$NON-NLS-2$
            Util.verbose("-> reseting index: " + indexLocation + " for path: " + containerPathString);
        }
        if (index == null) {
            // the index does not exist, try to recreate it
            return recreateIndex(containerPath) != null;
        }
        index.reset();
        return true;
    } 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 reset index for path: " + containerPathString);
            e.printStackTrace();
        }
        return false;
    }
}
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)

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