Search in sources :

Example 16 with IndexLocation

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

the class IndexManager method readParticipantsIndexNamesFile.

private void readParticipantsIndexNamesFile() {
    SimpleLookupTable containers = new SimpleLookupTable(3);
    try {
        char[] participantIndexNames = org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(this.participantIndexNamesFile, null);
        if (participantIndexNames.length > 0) {
            char[][] names = CharOperation.splitOn('\n', participantIndexNames);
            if (names.length >= 3) {
                // First line is DiskIndex signature  (see writeParticipantsIndexNamesFile())
                if (DiskIndex.SIGNATURE.equals(new String(names[0]))) {
                    for (int i = 1, l = names.length - 1; i < l; i += 2) {
                        IndexLocation indexLocation = new FileIndexLocation(new File(new String(names[i])), true);
                        containers.put(indexLocation, new Path(new String(names[i + 1])));
                    }
                }
            }
        }
    } catch (IOException ignored) {
        if (JobManager.VERBOSE)
            //$NON-NLS-1$
            Util.verbose("Failed to read participant index file names");
    }
    this.participantsContainers = containers;
    return;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) SimpleLookupTable(org.eclipse.jdt.internal.compiler.util.SimpleLookupTable) FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation) IOException(java.io.IOException) FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 17 with IndexLocation

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

the class IndexManager method removeIndex.

/**
     * Removes the index for a given path.
     * This is a no-op if the index did not exist.
     */
public synchronized void removeIndex(IPath containerPath) {
    if (JobManager.VERBOSE || DEBUG)
        //$NON-NLS-1$
        Util.verbose("removing index " + containerPath);
    IndexLocation indexLocation = computeIndexLocation(containerPath);
    Index index = getIndex(indexLocation);
    File indexFile = null;
    if (index != null) {
        index.monitor = null;
        indexFile = index.getIndexFile();
    }
    if (indexFile == null)
        // index is not cached yet, but still want to delete the file
        indexFile = indexLocation.getIndexFile();
    if (this.indexStates.get(indexLocation) == REUSE_STATE) {
        indexLocation.close();
        this.indexLocations.put(containerPath, null);
    } else if (indexFile != null && indexFile.exists()) {
        if (DEBUG)
            //$NON-NLS-1$
            Util.verbose("removing index file " + indexFile);
        indexFile.delete();
    }
    this.indexes.removeKey(indexLocation);
    if (IS_MANAGING_PRODUCT_INDEXES_PROPERTY) {
        this.indexLocations.removeKey(containerPath);
    }
    updateIndexState(indexLocation, 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) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 18 with IndexLocation

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

the class IndexManager method addBinary.

/**
     * Trigger addition of a resource to an index
     * Note: the actual operation is performed in background
     */
public void addBinary(IFile resource, IPath containerPath) {
    //        if (JavaCore.getPlugin() == null) return;
    SearchParticipant participant = SearchEngine.getDefaultSearchParticipant();
    SearchDocument document = participant.getDocument(resource.getFullPath().toString());
    IndexLocation indexLocation = computeIndexLocation(containerPath);
    scheduleDocumentIndexing(document, containerPath, indexLocation, participant);
}
Also used : FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation) SearchParticipant(org.eclipse.jdt.core.search.SearchParticipant) SearchDocument(org.eclipse.jdt.core.search.SearchDocument)

Example 19 with IndexLocation

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

the class IndexManager method saveIndex.

public void saveIndex(Index index) throws IOException {
    // must have permission to write from the write monitor
    if (index.hasChanged()) {
        if (JobManager.VERBOSE)
            //$NON-NLS-1$
            Util.verbose("-> saving index " + index.getIndexLocation());
        index.save();
    }
    synchronized (this) {
        IPath containerPath = new Path(index.containerPath);
        if (this.jobEnd > this.jobStart) {
            for (int i = this.jobEnd; i > this.jobStart; i--) {
                // skip the current job
                IJob job = this.awaitingJobs[i];
                if (job instanceof IndexRequest)
                    if (((IndexRequest) job).containerPath.equals(containerPath))
                        return;
            }
        }
        IndexLocation indexLocation = computeIndexLocation(containerPath);
        updateIndexState(indexLocation, SAVED_STATE);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IJob(org.eclipse.jdt.internal.core.search.processing.IJob) FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation)

Example 20 with IndexLocation

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

the class IndexManager method getIndexes.

/**
     * Returns all the existing indexes for a list of index locations.
     * Note that this may trigger some indexes recreation work
     *
     * @param locations
     *         The list of of the index files path
     * @return The corresponding indexes list.
     */
public Index[] getIndexes(IndexLocation[] locations, IProgressMonitor progressMonitor) {
    // acquire the in-memory indexes on the fly
    int length = locations.length;
    Index[] locatedIndexes = new Index[length];
    int count = 0;
    if (this.javaLikeNamesChanged) {
        this.javaLikeNamesChanged = hasJavaLikeNamesChanged();
    }
    for (int i = 0; i < length; i++) {
        if (progressMonitor != null && progressMonitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        // may trigger some index recreation work
        IndexLocation indexLocation = locations[i];
        Index index = getIndex(indexLocation);
        if (index == null) {
            // only need containerPath if the index must be built
            IPath containerPath = (IPath) this.indexLocations.keyForValue(indexLocation);
            if (containerPath != null) {
                // sanity check
                index = getIndex(containerPath, indexLocation, true, /*reuse index file*/
                false);
                if (index != null && this.javaLikeNamesChanged && !index.isIndexForJar()) {
                    // When a change in java like names extension has been detected, all
                    // non jar files indexes (i.e. containing sources) need to be rebuilt.
                    // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=286379
                    File indexFile = index.getIndexFile();
                    if (indexFile.exists()) {
                        if (DEBUG)
                            //$NON-NLS-1$
                            Util.verbose("Change in javaLikeNames - removing index file for " + containerPath);
                        indexFile.delete();
                    }
                    this.indexes.put(indexLocation, null);
                    rebuildIndex(indexLocation, containerPath);
                    index = null;
                }
            } else {
                if (indexLocation.isParticipantIndex() && indexLocation.exists()) {
                    // the index belongs to non-jdt search participant
                    try {
                        IPath container = getParticipantsContainer(indexLocation);
                        if (container != null) {
                            index = new Index(indexLocation, container.toOSString(), true);
                            this.indexes.put(indexLocation, index);
                        }
                    } catch (IOException e) {
                    // ignore
                    }
                }
            }
        }
        if (index != null)
            // only consider indexes which are ready
            locatedIndexes[count++] = index;
    }
    if (this.javaLikeNamesChanged) {
        writeJavaLikeNamesFile();
        this.javaLikeNamesChanged = false;
    }
    if (count < length) {
        System.arraycopy(locatedIndexes, 0, locatedIndexes = new Index[count], 0, count);
    }
    return locatedIndexes;
}
Also used : IPath(org.eclipse.core.runtime.IPath) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) 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) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

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