List of usage examples for org.eclipse.jdt.internal.core.index Index Index
public Index(IndexLocation location, String containerPath, boolean reuseExistingFile) throws IOException
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexManager.java
License:Open Source License
/** * Returns the index for a given project, according to the following algorithm: * - if index is already in memory: answers this one back * - if (reuseExistingFile) then read it and return this index and record it in memory * - if (createIfMissing) then create a new empty index and record it in memory * <p/>/* www .j a va 2 s .c om*/ * Warning: Does not check whether index is consistent (not being used) */ public synchronized Index getIndex(IPath containerPath, IndexLocation indexLocation, boolean reuseExistingFile, boolean createIfMissing) { // Path is already canonical per construction Index index = getIndex(indexLocation); if (index == null) { Object state = getIndexStates().get(indexLocation); Integer currentIndexState = state == null ? UNKNOWN_STATE : (Integer) state; if (currentIndexState == UNKNOWN_STATE) { // should only be reachable for query jobs // IF you put an index in the cache, then AddJarFileToIndex fails because it thinks there is nothing to do rebuildIndex(indexLocation, containerPath); return null; } // index isn't cached, consider reusing an existing index file String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); if (reuseExistingFile) { if (indexLocation.exists()) { // check before creating index so as to avoid creating a new empty index if file is missing try { index = new Index(indexLocation, containerPathString, true /*reuse index file*/); this.indexes.put(indexLocation, index); return index; } catch (IOException e) { // failed to read the existing file or its no longer compatible if (currentIndexState != REBUILDING_STATE && currentIndexState != REUSE_STATE) { // rebuild index if existing file is // corrupt, unless the index is already being rebuilt if (VERBOSE) Util.verbose("-> cannot reuse existing index: " + indexLocation + " path: " + containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ rebuildIndex(indexLocation, containerPath); return null; } /*index = null;*/ // will fall thru to createIfMissing & create a empty index for the rebuild all job to populate } } if (currentIndexState == SAVED_STATE) { // rebuild index if existing file is missing rebuildIndex(indexLocation, containerPath); return null; } if (currentIndexState == REUSE_STATE) { // supposed to be in reuse state but error in the index file, so reindex. if (VERBOSE) Util.verbose( "-> cannot reuse given index: " + indexLocation + " path: " + containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ this.indexLocations.put(containerPath, null); indexLocation = computeIndexLocation(containerPath); rebuildIndex(indexLocation, containerPath); return null; } } // index wasn't found on disk, consider creating an empty new one if (createIfMissing) { try { if (VERBOSE) Util.verbose("-> create empty index: " + indexLocation + " path: " + containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ index = new Index(indexLocation, containerPathString, false /*do not reuse index file*/); this.indexes.put(indexLocation, index); return index; } catch (IOException e) { if (VERBOSE) Util.verbose("-> unable to create empty index: " + indexLocation + " path: " + containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ // The file could not be created. Possible reason: the project has been deleted. return null; } } } //System.out.println(" index name: " + path.toOSString() + " <----> " + index.getIndexFile().getName()); return index; }
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//from w ww . j a va 2 s .c om * 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
/** * 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) *///from w w w . j a v a2 s. c o m 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 (VERBOSE) Util.verbose("-> recreating index: " + indexLocation + " for path: " + containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ index = new Index(indexLocation, containerPathString, false /*do not reuse index file*/); 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 (VERBOSE) { Util.verbose("-> failed to recreate index for path: " + containerPathString); //$NON-NLS-1$ e.printStackTrace(); } return null; } }
From source file:org.eclipse.jdt.internal.core.search.indexing.IndexManager.java
License:Open Source License
/** * Returns the index for a given project, according to the following algorithm: * - if index is already in memory: answers this one back * - if (reuseExistingFile) then read it and return this index and record it in memory * - if (createIfMissing) then create a new empty index and record it in memory * * Warning: Does not check whether index is consistent (not being used) *///from w ww . j a va 2 s . co m public synchronized Index getIndex(IPath containerPath, IPath indexLocation, boolean reuseExistingFile, boolean createIfMissing) { // Path is already canonical per construction Index index = getIndex(indexLocation); if (index == null) { Object state = getIndexStates().get(indexLocation); Integer currentIndexState = state == null ? UNKNOWN_STATE : (Integer) state; if (currentIndexState == UNKNOWN_STATE) { // should only be reachable for query jobs // IF you put an index in the cache, then AddJarFileToIndex fails because it thinks there is nothing to do rebuildIndex(indexLocation, containerPath); return null; } // index isn't cached, consider reusing an existing index file String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); String indexLocationString = indexLocation.toOSString(); if (reuseExistingFile) { File indexFile = new File(indexLocationString); if (indexFile.exists()) { // check before creating index so as to avoid creating a new empty index if file is missing try { index = new Index(indexLocationString, containerPathString, true /*reuse index file*/); this.indexes.put(indexLocation, index); return index; } catch (IOException e) { // failed to read the existing file or its no longer compatible if (currentIndexState != REBUILDING_STATE) { // rebuild index if existing file is corrupt, unless the index is already being rebuilt if (VERBOSE) Util.verbose("-> cannot reuse existing index: " + indexLocationString + " path: " //$NON-NLS-1$//$NON-NLS-2$ + containerPathString); rebuildIndex(indexLocation, containerPath); return null; } /*index = null;*/ // will fall thru to createIfMissing & create a empty index for the rebuild all job to populate } } if (currentIndexState == SAVED_STATE) { // rebuild index if existing file is missing rebuildIndex(indexLocation, containerPath); return null; } } // index wasn't found on disk, consider creating an empty new one if (createIfMissing) { try { if (VERBOSE) Util.verbose( "-> create empty index: " + indexLocationString + " path: " + containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ index = new Index(indexLocationString, containerPathString, false /*do not reuse index file*/); this.indexes.put(indexLocation, index); return index; } catch (IOException e) { if (VERBOSE) Util.verbose("-> unable to create empty index: " + indexLocationString + " path: " //$NON-NLS-1$//$NON-NLS-2$ + containerPathString); // The file could not be created. Possible reason: the project has been deleted. return null; } } } //System.out.println(" index name: " + path.toOSString() + " <----> " + index.getIndexFile().getName()); return index; }
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. *//*from ww w . ja va 2 s . c om*/ 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
/** * 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) *//*from w ww.j a va 2 s. c o m*/ 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 IPath indexLocation = computeIndexLocation(containerPath); Index index = getIndex(indexLocation); ReadWriteMonitor monitor = index == null ? null : index.monitor; if (VERBOSE) Util.verbose("-> recreating index: " + indexLocation + " for path: " + containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ index = new Index(indexLocation.toOSString(), containerPathString, false /*do not reuse index file*/); 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 (VERBOSE) { Util.verbose("-> failed to recreate index for path: " + containerPathString); //$NON-NLS-1$ e.printStackTrace(); } return null; } }