/** * Adds the given index entry (category and key) coming from this * document to the index. This method must be called from * {@link SearchParticipant#indexDocument(SearchDocument document, org.eclipse.core.runtime.IPath indexPath)}. * * @param category the category of the index entry * @param key the key of the index entry */ public void addIndexEntry(char[] category, char[] key) { if (this.index != null) this.index.addIndexEntry(category, key, getContainerRelativePath()); }
private String getContainerRelativePath() { if (this.containerRelativePath == null) this.containerRelativePath = this.index.containerRelativePath(getPath()); return this.containerRelativePath; }
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(); } 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); } } /**
/** * {@link #saveIndex(Index)} will only update the state if there are no other jobs running against the same * underlying resource for this index. Pre-built indexes must be in a {@link #REUSE_STATE} state even if * there is another job to run against it as the subsequent job will find the index and not save it in the * right state. * Refer to https://bugs.eclipse.org/bugs/show_bug.cgi?id=405932 */ public void savePreBuiltIndex(Index index) throws IOException { if (index.hasChanged()) { if (VERBOSE) Util.verbose("-> saving pre-build index " + index.getIndexLocation()); //$NON-NLS-1$ index.save(); } synchronized (this) { updateIndexState(index.getIndexLocation(), REUSE_STATE); } } public void saveIndex(Index index) throws IOException {
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()) { File indexFile = index.getIndexFile(); if (indexFile.exists()) { if (DEBUG) IPath container = getParticipantsContainer(indexLocation); if (container != null) { index = new Index(indexLocation.toOSString(), container.toOSString(), true /*reuse index file*/); this.indexes.put(indexLocation, index);
public void generateIndexForJar(String pathToJar, String pathToIndexFile) throws IOException { File f = new File(pathToJar); if (!f.exists()) { throw new FileNotFoundException(pathToJar + " not found"); //$NON-NLS-1$ } IndexLocation indexLocation = new FileIndexLocation(new File(pathToIndexFile)); Index index = new Index(indexLocation, pathToJar, false /*reuse index file*/); SearchParticipant participant = SearchEngine.getDefaultSearchParticipant(); index.separator = JAR_SEPARATOR; ZipFile zip = new ZipFile(pathToJar); try { for (Enumeration e = zip.entries(); e.hasMoreElements();) { // iterate each entry to index it ZipEntry ze = (ZipEntry) e.nextElement(); String zipEntryName = ze.getName(); if (Util.isClassFileName(zipEntryName)) { final byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip); JavaSearchDocument entryDocument = new JavaSearchDocument(ze, new Path(pathToJar), classFileBytes, participant); entryDocument.setIndex(index); new BinaryIndexer(entryDocument).indexDocument(); } } index.save(); } finally { zip.close(); } return; } }
String[] paths = index.queryDocumentNames(""); // all file names //$NON-NLS-1$ int max = paths == null ? 0 : paths.length; final SimpleLookupTable indexedFileNames = new SimpleLookupTable(max==0 ? 33 : max+11); indexedFileNames.put(paths[i], DELETED); final long indexLastModified = index.getIndexLastModified(); this.folder.accept( new IResourceProxyVisitor() {
@Override public EntryResult[] queryIn(Index index) throws IOException { return index.query(CATEGORIES, SECONDARY_PATTERN_KEY, R_PATTERN_MATCH | R_CASE_SENSITIVE); }
/** * Removes all index entries from the index for the given document. * This method must be called from * {@link SearchParticipant#indexDocument(SearchDocument document, org.eclipse.core.runtime.IPath indexPath)}. */ public void removeAllIndexEntries() { if (this.index != null) this.index.remove(getContainerRelativePath()); }
for (int j = 0, m = words.length; j < m; j++) { char[] word = words[j]; if (word != null && Index.isMatch(key, word, matchRule)) results = addQueryResult(results, word, values[j], memoryIndex, prevResults);
void saveIndexes() { IndexManager indexManager = JavaModelManager.getJavaModelManager().getIndexManager(); IPath jspModelWorkingLocation = JSPSearchSupport.getInstance().getModelJspPluginWorkingLocation(); File folder = new File(jspModelWorkingLocation.toOSString()); String[] files = folder.list(); String locay = ""; //$NON-NLS-1$ Index index = null; try { for (int i = 0; i < files.length; i++) { if (files[i].toLowerCase().endsWith(".index")) { //$NON-NLS-1$ locay = jspModelWorkingLocation.toString() + "/" + files[i]; //$NON-NLS-1$ // reuse index file index = new Index(locay, "Index for " + locay, true); //$NON-NLS-1$ indexManager.saveIndex(index); } } } catch (Exception e) { // we should be shutting down, want to shut down quietly if (DEBUG) e.printStackTrace(); } }
/** * 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 (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); } /**
public void save() throws IOException { // must own the write lock of the monitor if (!hasChanged()) return; int numberOfChanges = this.memoryIndex.docsToReferences.elementSize; this.diskIndex.separator = this.separator; this.diskIndex = this.diskIndex.mergeWith(this.memoryIndex); this.memoryIndex = new MemoryIndex(); if (numberOfChanges > 1000) System.gc(); // reclaim space if the MemoryIndex was very BIG } public void startQuery() {
String[] paths = index.queryDocumentNames(containerRelativePath);
String[] paths = index.queryDocumentNames(""); // all file names //$NON-NLS-1$ int max = paths == null ? 0 : paths.length; final SimpleLookupTable indexedFileNames = new SimpleLookupTable(max==0 ? 33 : max+11); indexedFileNames.put(paths[i], DELETED); final long indexLastModified = index.getIndexFile().lastModified(); this.folder.accept( new IResourceProxyVisitor() {
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()) { File indexFile = index.getIndexFile(); if (indexFile.exists()) { if (DEBUG) IPath container = getParticipantsContainer(indexLocation); if (container != null) { index = new Index(indexLocation, container.toOSString(), true /*reuse index file*/); this.indexes.put(indexLocation, index);
/** * {@link #saveIndex(Index)} will only update the state if there are no other jobs running against the same * underlying resource for this index. Pre-built indexes must be in a {@link #REUSE_STATE} state even if * there is another job to run against it as the subsequent job will find the index and not save it in the * right state. * Refer to https://bugs.eclipse.org/bugs/show_bug.cgi?id=405932 */ public void savePreBuiltIndex(Index index) throws IOException { if (index.hasChanged()) { if (VERBOSE) Util.verbose("-> saving pre-build index " + index.getIndexLocation()); //$NON-NLS-1$ index.save(); } synchronized (this) { updateIndexState(index.getIndexLocation(), REUSE_STATE); } } public void saveIndex(Index index) throws IOException {
public void generateIndexForJar(String pathToJar, String pathToIndexFile) throws IOException { File f = new File(pathToJar); if (!f.exists()) { throw new FileNotFoundException(pathToJar + " not found"); //$NON-NLS-1$ } IndexLocation indexLocation = new FileIndexLocation(new File(pathToIndexFile)); Index index = new Index(indexLocation, pathToJar, false /*reuse index file*/); SearchParticipant participant = SearchEngine.getDefaultSearchParticipant(); index.separator = JAR_SEPARATOR; ZipFile zip = new ZipFile(pathToJar); try { for (Enumeration e = zip.entries(); e.hasMoreElements();) { // iterate each entry to index it ZipEntry ze = (ZipEntry) e.nextElement(); String zipEntryName = ze.getName(); if (Util.isClassFileName(zipEntryName)) { final byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip); JavaSearchDocument entryDocument = new JavaSearchDocument(ze, new Path(pathToJar), classFileBytes, participant); entryDocument.setIndex(index); new BinaryIndexer(entryDocument).indexDocument(); } } index.save(); } finally { zip.close(); } return; } }
String[] paths = index.queryDocumentNames(""); // all file names //$NON-NLS-1$ int max = paths == null ? 0 : paths.length; final SimpleLookupTable indexedFileNames = new SimpleLookupTable(max==0 ? 33 : max+11); indexedFileNames.put(paths[i], DELETED); final long indexLastModified = index.getIndexLastModified(); this.folder.accept( new IResourceProxyVisitor() {
public EntryResult[] queryIn(Index index) throws IOException { return index.query(CATEGORIES, SECONDARY_PATTERN_KEY, R_PATTERN_MATCH | R_CASE_SENSITIVE); }