Search in sources :

Example 6 with IndexLocation

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

the class IndexManager method computeIndexLocation.

/**
     * Compute the pre-built index location for a specified URL
     */
public synchronized IndexLocation computeIndexLocation(IPath containerPath, final URL newIndexURL) {
    IndexLocation indexLocation = (IndexLocation) this.indexLocations.get(containerPath);
    if (indexLocation == null) {
        if (newIndexURL != null) {
            indexLocation = IndexLocation.createIndexLocation(newIndexURL);
            // update caches
            indexLocation = (IndexLocation) getIndexStates().getKey(indexLocation);
            this.indexLocations.put(containerPath, indexLocation);
        }
    } else {
        // an existing index location exists - make sure it has not changed (i.e. the URL has not changed)
        URL existingURL = indexLocation.getUrl();
        if (newIndexURL != null) {
            // if either URL is different then the index location has been updated so rebuild.
            if (!newIndexURL.equals(existingURL)) {
                // URL has changed so remove the old index and create a new one
                this.removeIndex(containerPath);
                // create a new one
                indexLocation = IndexLocation.createIndexLocation(newIndexURL);
                // update caches
                indexLocation = (IndexLocation) getIndexStates().getKey(indexLocation);
                this.indexLocations.put(containerPath, indexLocation);
            }
        }
    }
    return indexLocation;
}
Also used : FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation) URL(java.net.URL)

Example 7 with IndexLocation

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

the class IndexManager method indexLibrary.

/**
     * Trigger addition of a library to an index
     * Note: the actual operation is performed in background
     */
public void indexLibrary(IPath path, IProject requestingProject, URL indexURL, final boolean updateIndex) {
    // requestingProject is no longer used to cancel jobs but leave it here just in case
    IndexLocation indexFile = null;
    if (indexURL != null) {
        if (IS_MANAGING_PRODUCT_INDEXES_PROPERTY) {
            indexFile = computeIndexLocation(path, indexURL);
        } else {
            indexFile = IndexLocation.createIndexLocation(indexURL);
        }
    }
    //        if (JavaCore.getPlugin() == null) return;
    IndexRequest request = null;
    boolean forceIndexUpdate = IS_MANAGING_PRODUCT_INDEXES_PROPERTY && updateIndex;
    //        Object target = JavaModel.getTarget(path, true);
    //	if (target instanceof IFile) {
    //		request = new AddJarFileToIndex((IFile) target, indexFile, this, forceIndexUpdate);
    //	} else
    //        if (target instanceof File) {
    request = new AddJarFileToIndex(path, indexFile, this, forceIndexUpdate);
    // check if the same request is not already in the queue
    if (!isJobWaiting(request))
        request(request);
}
Also used : FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation)

Example 8 with IndexLocation

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

the class IndexManager method getIndexStates.

private SimpleLookupTable getIndexStates() {
    if (this.indexStates != null)
        return this.indexStates;
    this.indexStates = new SimpleLookupTable();
    File indexesDirectoryPath = getSavedIndexesDirectory();
    char[][] savedNames = readIndexState(getJavaPluginWorkingLocation().toOSString());
    if (savedNames != null) {
        for (int i = 1, l = savedNames.length; i < l; i++) {
            // first name is saved signature, see readIndexState()
            char[] savedName = savedNames[i];
            if (savedName.length > 0) {
                IndexLocation indexLocation = new FileIndexLocation(// shares indexesDirectoryPath's segments
                new File(indexesDirectoryPath, String.valueOf(savedName)));
                if (JobManager.VERBOSE)
                    //$NON-NLS-1$
                    Util.verbose("Reading saved index file " + indexLocation);
                this.indexStates.put(indexLocation, SAVED_STATE);
            }
        }
    } else {
        // All the index files are getting deleted and hence there is no need to
        // further check for change in javaLikeNames.
        writeJavaLikeNamesFile();
        this.javaLikeNamesChanged = false;
        deleteIndexFiles();
    }
    readIndexMap();
    return this.indexStates;
}
Also used : SimpleLookupTable(org.eclipse.jdt.internal.compiler.util.SimpleLookupTable) 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 9 with IndexLocation

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

the class IndexManager method updateParticipant.

public void updateParticipant(IPath indexPath, IPath containerPath) {
    if (this.participantsContainers == null) {
        readParticipantsIndexNamesFile();
    }
    IndexLocation indexLocation = new FileIndexLocation(indexPath.toFile(), true);
    if (this.participantsContainers.get(indexLocation) == null) {
        this.participantsContainers.put(indexLocation, containerPath);
        this.participantUpdated = true;
    }
}
Also used : FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation) FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation)

Example 10 with IndexLocation

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

the class IndexManager method removeIndexPath.

/**
     * Removes all indexes whose paths start with (or are equal to) the given path.
     */
public synchronized void removeIndexPath(IPath path) {
    if (JobManager.VERBOSE || DEBUG)
        //$NON-NLS-1$
        Util.verbose("removing index path " + path);
    Object[] keyTable = this.indexes.keyTable;
    Object[] valueTable = this.indexes.valueTable;
    IndexLocation[] locations = null;
    int max = this.indexes.elementSize;
    int count = 0;
    for (int i = 0, l = keyTable.length; i < l; i++) {
        IndexLocation indexLocation = (IndexLocation) keyTable[i];
        if (indexLocation == null)
            continue;
        if (indexLocation.startsWith(path)) {
            Index index = (Index) valueTable[i];
            index.monitor = null;
            if (locations == null)
                locations = new IndexLocation[max];
            locations[count++] = indexLocation;
            if (this.indexStates.get(indexLocation) == REUSE_STATE) {
                indexLocation.close();
            } else {
                if (DEBUG)
                    //$NON-NLS-1$
                    Util.verbose("removing index file " + indexLocation);
                indexLocation.delete();
            }
        } else {
            max--;
        }
    }
    if (locations != null) {
        for (int i = 0; i < count; i++) this.indexes.removeKey(locations[i]);
        removeIndexesState(locations);
        if (this.participantsContainers != null) {
            boolean update = false;
            for (int i = 0; i < count; i++) {
                if (this.participantsContainers.get(locations[i]) != null) {
                    update = true;
                    this.participantsContainers.removeKey(locations[i]);
                }
            }
            if (update)
                writeParticipantsIndexNamesFile();
        }
    }
}
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