Example usage for org.eclipse.jdt.internal.core.index Index getIndexFile

List of usage examples for org.eclipse.jdt.internal.core.index Index getIndexFile

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core.index Index getIndexFile.

Prototype

public File getIndexFile() 

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexManager.java

License:Open Source License

/**
 * Returns all the existing indexes for a list of index locations.
 * Note that this may trigger some indexes recreation work
 *
 * @param locations//www .j a  v a 2s .co  m
 *         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 /*do not create if none*/);
                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)
                            Util.verbose("Change in javaLikeNames - removing index file for " + containerPath); //$NON-NLS-1$
                        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 /*reuse index file*/);
                            this.indexes.put(indexLocation, index);
                        }
                    } catch (IOException e) {
                        // ignore
                    }
                }
            }
        }
        if (index != null)
            locatedIndexes[count++] = index; // only consider indexes which are ready
    }
    if (this.javaLikeNamesChanged) {
        writeJavaLikeNamesFile();
        this.javaLikeNamesChanged = false;
    }
    if (count < length) {
        System.arraycopy(locatedIndexes, 0, locatedIndexes = new Index[count], 0, count);
    }
    return locatedIndexes;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexManager.java

License:Open Source License

/**
 * Removes the index for a given path.//  ww  w .j  a va  2s . c om
 * This is a no-op if the index did not exist.
 */
public synchronized void removeIndex(IPath containerPath) {
    if (VERBOSE || DEBUG)
        Util.verbose("removing index " + containerPath); //$NON-NLS-1$
    IndexLocation indexLocation = computeIndexLocation(containerPath);
    Index index = getIndex(indexLocation);
    File indexFile = null;
    if (index != null) {
        index.monitor = null;
        indexFile = index.getIndexFile();
    }
    if (indexFile == null)
        indexFile = indexLocation.getIndexFile(); // index is not cached yet, but still want to delete the file
    if (this.indexStates.get(indexLocation) == REUSE_STATE) {
        indexLocation.close();
        this.indexLocations.put(containerPath, null);
    } else if (indexFile != null && indexFile.exists()) {
        if (DEBUG)
            Util.verbose("removing index file " + indexFile); //$NON-NLS-1$
        indexFile.delete();
    }
    this.indexes.removeKey(indexLocation);
    if (IS_MANAGING_PRODUCT_INDEXES_PROPERTY) {
        this.indexLocations.removeKey(containerPath);
    }
    updateIndexState(indexLocation, null);
}

From source file:org.eclipse.jdt.internal.core.search.indexing.IndexManager.java

License:Open Source License

/**
 * 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.
 *///  w  w w .  j a  v  a  2s .  c  o m
public Index[] getIndexes(IPath[] 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
        IPath 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 /*do not create if none*/);
                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)
                            Util.verbose("Change in javaLikeNames - removing index file for " + containerPath); //$NON-NLS-1$
                        indexFile.delete();
                    }
                    this.indexes.put(indexLocation, null);
                    rebuildIndex(indexLocation, containerPath);
                    index = null;
                }
            } else {
                if (!getJavaPluginWorkingLocation().isPrefixOf(indexLocation)) { // the index belongs to non-jdt search participant
                    if (indexLocation.toFile().exists()) {
                        try {
                            IPath container = getParticipantsContainer(indexLocation);
                            if (container != null) {
                                index = new Index(indexLocation.toOSString(), container.toOSString(),
                                        true /*reuse index file*/);
                                this.indexes.put(indexLocation, index);
                            }
                        } catch (IOException e) {
                            // ignore
                        }
                    }
                }
            }
        }
        if (index != null)
            locatedIndexes[count++] = index; // only consider indexes which are ready
    }
    if (this.javaLikeNamesChanged) {
        writeJavaLikeNamesFile();
        this.javaLikeNamesChanged = false;
    }
    if (count < length) {
        System.arraycopy(locatedIndexes, 0, locatedIndexes = new Index[count], 0, count);
    }
    return locatedIndexes;
}

From source file:org.eclipse.jdt.internal.core.search.indexing.IndexManager.java

License:Open Source License

/**
 * Removes the index for a given path./*from  w  w w .  j a  va 2  s.c  o m*/
 * This is a no-op if the index did not exist.
 */
public synchronized void removeIndex(IPath containerPath) {
    if (VERBOSE || DEBUG)
        Util.verbose("removing index " + containerPath); //$NON-NLS-1$
    IPath indexLocation = computeIndexLocation(containerPath);
    Index index = getIndex(indexLocation);
    File indexFile = null;
    if (index != null) {
        index.monitor = null;
        indexFile = index.getIndexFile();
    }
    if (indexFile == null)
        indexFile = new File(indexLocation.toOSString()); // index is not cached yet, but still want to delete the file
    if (indexFile.exists()) {
        if (DEBUG)
            Util.verbose("removing index file " + indexFile); //$NON-NLS-1$
        indexFile.delete();
    }
    this.indexes.removeKey(indexLocation);
    updateIndexState(indexLocation, null);
}

From source file:org.eclipse.jdt.internal.core.search.indexing.IndexManager.java

License:Open Source License

/**
 * Removes all indexes whose paths start with (or are equal to) the given path.
 *//*  w  ww  .j  a va  2 s .c o  m*/
public synchronized void removeIndexPath(IPath path) {
    if (VERBOSE || DEBUG)
        Util.verbose("removing index path " + path); //$NON-NLS-1$
    Object[] keyTable = this.indexes.keyTable;
    Object[] valueTable = this.indexes.valueTable;
    IPath[] locations = null;
    int max = this.indexes.elementSize;
    int count = 0;
    for (int i = 0, l = keyTable.length; i < l; i++) {
        IPath indexLocation = (IPath) keyTable[i];
        if (indexLocation == null)
            continue;
        if (path.isPrefixOf(indexLocation)) {
            Index index = (Index) valueTable[i];
            index.monitor = null;
            if (locations == null)
                locations = new IPath[max];
            locations[count++] = indexLocation;
            File indexFile = index.getIndexFile();
            if (indexFile.exists()) {
                if (DEBUG)
                    Util.verbose("removing index file " + indexFile); //$NON-NLS-1$
                indexFile.delete();
            }
        } else {
            max--;
        }
    }
    if (locations != null) {
        for (int i = 0; i < count; i++)
            this.indexes.removeKey(locations[i]);
        removeIndexesState(locations);
        if (this.participantsContainers != null && this.participantsContainers.get(path.toOSString()) != null) {
            this.participantsContainers.removeKey(path.toOSString());
            writeParticipantsIndexNamesFile();
        }
    }
}

From source file:org.eclipse.jdt.internal.core.search.indexing.IndexManager.java

License:Open Source License

public void saveIndex(Index index) throws IOException {
    // must have permission to write from the write monitor
    if (index.hasChanged()) {
        if (VERBOSE)
            Util.verbose("-> saving index " + index.getIndexFile()); //$NON-NLS-1$
        index.save();/*from  www  .  j ava2  s.  c  o  m*/
    }
    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;
            }
        }
        IPath indexLocation = computeIndexLocation(containerPath);
        updateIndexState(indexLocation, SAVED_STATE);
    }
}