Lines 16-22
Link Here
|
16 |
import java.util.zip.CRC32; |
16 |
import java.util.zip.CRC32; |
17 |
|
17 |
|
18 |
import org.eclipse.core.resources.*; |
18 |
import org.eclipse.core.resources.*; |
19 |
import org.eclipse.core.runtime.FileLocator; |
|
|
20 |
import org.eclipse.core.runtime.IPath; |
19 |
import org.eclipse.core.runtime.IPath; |
21 |
import org.eclipse.core.runtime.IProgressMonitor; |
20 |
import org.eclipse.core.runtime.IProgressMonitor; |
22 |
import org.eclipse.core.runtime.OperationCanceledException; |
21 |
import org.eclipse.core.runtime.OperationCanceledException; |
Lines 73-79
Link Here
|
73 |
public synchronized void aboutToUpdateIndex(IPath containerPath, Integer newIndexState) { |
72 |
public synchronized void aboutToUpdateIndex(IPath containerPath, Integer newIndexState) { |
74 |
// newIndexState is either UPDATING_STATE or REBUILDING_STATE |
73 |
// newIndexState is either UPDATING_STATE or REBUILDING_STATE |
75 |
// must tag the index as inconsistent, in case we exit before the update job is started |
74 |
// must tag the index as inconsistent, in case we exit before the update job is started |
76 |
IPath indexLocation = computeIndexLocation(containerPath); |
75 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
77 |
Object state = getIndexStates().get(indexLocation); |
76 |
Object state = getIndexStates().get(indexLocation); |
78 |
Integer currentIndexState = state == null ? UNKNOWN_STATE : (Integer) state; |
77 |
Integer currentIndexState = state == null ? UNKNOWN_STATE : (Integer) state; |
79 |
if (currentIndexState.compareTo(REBUILDING_STATE) >= 0) return; // already rebuilding the index |
78 |
if (currentIndexState.compareTo(REBUILDING_STATE) >= 0) return; // already rebuilding the index |
Lines 95-101
Link Here
|
95 |
if (JavaCore.getPlugin() == null) return; |
94 |
if (JavaCore.getPlugin() == null) return; |
96 |
SearchParticipant participant = SearchEngine.getDefaultSearchParticipant(); |
95 |
SearchParticipant participant = SearchEngine.getDefaultSearchParticipant(); |
97 |
SearchDocument document = participant.getDocument(resource.getFullPath().toString()); |
96 |
SearchDocument document = participant.getDocument(resource.getFullPath().toString()); |
98 |
IPath indexLocation = computeIndexLocation(containerPath); |
97 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
99 |
scheduleDocumentIndexing(document, containerPath, indexLocation, participant); |
98 |
scheduleDocumentIndexing(document, containerPath, indexLocation, participant); |
100 |
} |
99 |
} |
101 |
/** |
100 |
/** |
Lines 107-113
Link Here
|
107 |
SearchParticipant participant = SearchEngine.getDefaultSearchParticipant(); |
106 |
SearchParticipant participant = SearchEngine.getDefaultSearchParticipant(); |
108 |
SearchDocument document = participant.getDocument(resource.getFullPath().toString()); |
107 |
SearchDocument document = participant.getDocument(resource.getFullPath().toString()); |
109 |
document.setParser(parser); |
108 |
document.setParser(parser); |
110 |
IPath indexLocation = computeIndexLocation(containerPath); |
109 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
111 |
scheduleDocumentIndexing(document, containerPath, indexLocation, participant); |
110 |
scheduleDocumentIndexing(document, containerPath, indexLocation, participant); |
112 |
} |
111 |
} |
113 |
/* |
112 |
/* |
Lines 119-135
Link Here
|
119 |
PatternSearchJob job = new PatternSearchJob(null, SearchEngine.getDefaultSearchParticipant(), scope, null); |
118 |
PatternSearchJob job = new PatternSearchJob(null, SearchEngine.getDefaultSearchParticipant(), scope, null); |
120 |
Index[] selectedIndexes = job.getIndexes(null); |
119 |
Index[] selectedIndexes = job.getIndexes(null); |
121 |
for (int i = 0, l = selectedIndexes.length; i < l; i++) { |
120 |
for (int i = 0, l = selectedIndexes.length; i < l; i++) { |
122 |
String path = selectedIndexes[i].getIndexFile().getAbsolutePath(); |
121 |
IndexLocation IndexLocation = selectedIndexes[i].getIndexLocation(); |
123 |
knownPaths.add(path); |
122 |
knownPaths.add(IndexLocation); |
124 |
} |
123 |
} |
125 |
|
124 |
|
126 |
if (this.indexStates != null) { |
125 |
if (this.indexStates != null) { |
127 |
Object[] keys = this.indexStates.keyTable; |
126 |
Object[] keys = this.indexStates.keyTable; |
128 |
IPath[] locations = new IPath[this.indexStates.elementSize]; |
127 |
IndexLocation[] locations = new IndexLocation[this.indexStates.elementSize]; |
129 |
int count = 0; |
128 |
int count = 0; |
130 |
for (int i = 0, l = keys.length; i < l; i++) { |
129 |
for (int i = 0, l = keys.length; i < l; i++) { |
131 |
IPath key = (IPath) keys[i]; |
130 |
IndexLocation key = (IndexLocation) keys[i]; |
132 |
if (key != null && !knownPaths.includes(key.toOSString())) |
131 |
if (key != null && !knownPaths.includes(key)) |
133 |
locations[count++] = key; |
132 |
locations[count++] = key; |
134 |
} |
133 |
} |
135 |
if (count > 0) |
134 |
if (count > 0) |
Lines 137-144
Link Here
|
137 |
} |
136 |
} |
138 |
deleteIndexFiles(knownPaths); |
137 |
deleteIndexFiles(knownPaths); |
139 |
} |
138 |
} |
140 |
public synchronized IPath computeIndexLocation(IPath containerPath) { |
139 |
public synchronized IndexLocation computeIndexLocation(IPath containerPath) { |
141 |
IPath indexLocation = (IPath) this.indexLocations.get(containerPath); |
140 |
IndexLocation indexLocation = (IndexLocation) this.indexLocations.get(containerPath); |
142 |
if (indexLocation == null) { |
141 |
if (indexLocation == null) { |
143 |
String pathString = containerPath.toOSString(); |
142 |
String pathString = containerPath.toOSString(); |
144 |
CRC32 checksumCalculator = new CRC32(); |
143 |
CRC32 checksumCalculator = new CRC32(); |
Lines 147-153
Link Here
|
147 |
if (VERBOSE) |
146 |
if (VERBOSE) |
148 |
Util.verbose("-> index name for " + pathString + " is " + fileName); //$NON-NLS-1$ //$NON-NLS-2$ |
147 |
Util.verbose("-> index name for " + pathString + " is " + fileName); //$NON-NLS-1$ //$NON-NLS-2$ |
149 |
// to share the indexLocation between the indexLocations and indexStates tables, get the key from the indexStates table |
148 |
// to share the indexLocation between the indexLocations and indexStates tables, get the key from the indexStates table |
150 |
indexLocation = (IPath) getIndexStates().getKey(getJavaPluginWorkingLocation().append(fileName)); |
149 |
indexLocation = (IndexLocation) getIndexStates().getKey(new FileIndexLocation(new File(getSavedIndexesDirectory(), fileName))); |
151 |
this.indexLocations.put(containerPath, indexLocation); |
150 |
this.indexLocations.put(containerPath, indexLocation); |
152 |
} |
151 |
} |
153 |
return indexLocation; |
152 |
return indexLocation; |
Lines 164-170
Link Here
|
164 |
|
163 |
|
165 |
for (int i = 0, l = indexesFiles.length; i < l; i++) { |
164 |
for (int i = 0, l = indexesFiles.length; i < l; i++) { |
166 |
String fileName = indexesFiles[i].getAbsolutePath(); |
165 |
String fileName = indexesFiles[i].getAbsolutePath(); |
167 |
if (pathsToKeep != null && pathsToKeep.includes(fileName)) continue; |
166 |
if (pathsToKeep != null && pathsToKeep.includes(new FileIndexLocation(indexesFiles[i]))) continue; |
168 |
String suffix = ".index"; //$NON-NLS-1$ |
167 |
String suffix = ".index"; //$NON-NLS-1$ |
169 |
if (fileName.regionMatches(true, fileName.length() - suffix.length(), suffix, 0, suffix.length())) { |
168 |
if (fileName.regionMatches(true, fileName.length() - suffix.length(), suffix, 0, suffix.length())) { |
170 |
if (VERBOSE || DEBUG) |
169 |
if (VERBOSE || DEBUG) |
Lines 176-182
Link Here
|
176 |
/* |
175 |
/* |
177 |
* Creates an empty index at the given location, for the given container path, if none exist. |
176 |
* Creates an empty index at the given location, for the given container path, if none exist. |
178 |
*/ |
177 |
*/ |
179 |
public synchronized void ensureIndexExists(IPath indexLocation, IPath containerPath) { |
178 |
public synchronized void ensureIndexExists(IndexLocation indexLocation, IPath containerPath) { |
180 |
SimpleLookupTable states = getIndexStates(); |
179 |
SimpleLookupTable states = getIndexStates(); |
181 |
Object state = states.get(indexLocation); |
180 |
Object state = states.get(indexLocation); |
182 |
if (state == null) { |
181 |
if (state == null) { |
Lines 210-216
Link Here
|
210 |
* @param indexLocation The path of the index file |
209 |
* @param indexLocation The path of the index file |
211 |
* @return The corresponding index or <code>null</code> if not found |
210 |
* @return The corresponding index or <code>null</code> if not found |
212 |
*/ |
211 |
*/ |
213 |
public synchronized Index getIndex(IPath indexLocation) { |
212 |
public synchronized Index getIndex(IndexLocation indexLocation) { |
214 |
return (Index) this.indexes.get(indexLocation); // is null if unknown, call if the containerPath must be computed |
213 |
return (Index) this.indexes.get(indexLocation); // is null if unknown, call if the containerPath must be computed |
215 |
} |
214 |
} |
216 |
/** |
215 |
/** |
Lines 222-228
Link Here
|
222 |
* Warning: Does not check whether index is consistent (not being used) |
221 |
* Warning: Does not check whether index is consistent (not being used) |
223 |
*/ |
222 |
*/ |
224 |
public synchronized Index getIndex(IPath containerPath, boolean reuseExistingFile, boolean createIfMissing) { |
223 |
public synchronized Index getIndex(IPath containerPath, boolean reuseExistingFile, boolean createIfMissing) { |
225 |
IPath indexLocation = computeIndexLocation(containerPath); |
224 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
226 |
return getIndex(containerPath, indexLocation, reuseExistingFile, createIfMissing); |
225 |
return getIndex(containerPath, indexLocation, reuseExistingFile, createIfMissing); |
227 |
} |
226 |
} |
228 |
/** |
227 |
/** |
Lines 233-239
Link Here
|
233 |
* |
232 |
* |
234 |
* Warning: Does not check whether index is consistent (not being used) |
233 |
* Warning: Does not check whether index is consistent (not being used) |
235 |
*/ |
234 |
*/ |
236 |
public synchronized Index getIndex(IPath containerPath, IPath indexLocation, boolean reuseExistingFile, boolean createIfMissing) { |
235 |
public synchronized Index getIndex(IPath containerPath, IndexLocation indexLocation, boolean reuseExistingFile, boolean createIfMissing) { |
237 |
// Path is already canonical per construction |
236 |
// Path is already canonical per construction |
238 |
Index index = getIndex(indexLocation); |
237 |
Index index = getIndex(indexLocation); |
239 |
if (index == null) { |
238 |
if (index == null) { |
Lines 248-266
Link Here
|
248 |
|
247 |
|
249 |
// index isn't cached, consider reusing an existing index file |
248 |
// index isn't cached, consider reusing an existing index file |
250 |
String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
249 |
String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
251 |
String indexLocationString = indexLocation.toOSString(); |
|
|
252 |
if (reuseExistingFile) { |
250 |
if (reuseExistingFile) { |
253 |
File indexFile = new File(indexLocationString); |
251 |
if (indexLocation.exists()) { // check before creating index so as to avoid creating a new empty index if file is missing |
254 |
if (indexFile.exists()) { // check before creating index so as to avoid creating a new empty index if file is missing |
|
|
255 |
try { |
252 |
try { |
256 |
index = new Index(indexLocationString, containerPathString, true /*reuse index file*/); |
253 |
index = new Index(indexLocation, containerPathString, true /*reuse index file*/); |
257 |
this.indexes.put(indexLocation, index); |
254 |
this.indexes.put(indexLocation, index); |
258 |
return index; |
255 |
return index; |
259 |
} catch (IOException e) { |
256 |
} catch (IOException e) { |
260 |
// failed to read the existing file or its no longer compatible |
257 |
// failed to read the existing file or its no longer compatible |
261 |
if (currentIndexState != REBUILDING_STATE && currentIndexState != REUSE_STATE) { // rebuild index if existing file is corrupt, unless the index is already being rebuilt |
258 |
if (currentIndexState != REBUILDING_STATE && currentIndexState != REUSE_STATE) { // rebuild index if existing file is corrupt, unless the index is already being rebuilt |
262 |
if (VERBOSE) |
259 |
if (VERBOSE) |
263 |
Util.verbose("-> cannot reuse existing index: "+indexLocationString+" path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ |
260 |
Util.verbose("-> cannot reuse existing index: "+indexLocation+" path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ |
264 |
rebuildIndex(indexLocation, containerPath); |
261 |
rebuildIndex(indexLocation, containerPath); |
265 |
return null; |
262 |
return null; |
266 |
} |
263 |
} |
Lines 285-297
Link Here
|
285 |
if (createIfMissing) { |
282 |
if (createIfMissing) { |
286 |
try { |
283 |
try { |
287 |
if (VERBOSE) |
284 |
if (VERBOSE) |
288 |
Util.verbose("-> create empty index: "+indexLocationString+" path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ |
285 |
Util.verbose("-> create empty index: "+indexLocation+" path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ |
289 |
index = new Index(indexLocationString, containerPathString, false /*do not reuse index file*/); |
286 |
index = new Index(indexLocation, containerPathString, false /*do not reuse index file*/); |
290 |
this.indexes.put(indexLocation, index); |
287 |
this.indexes.put(indexLocation, index); |
291 |
return index; |
288 |
return index; |
292 |
} catch (IOException e) { |
289 |
} catch (IOException e) { |
293 |
if (VERBOSE) |
290 |
if (VERBOSE) |
294 |
Util.verbose("-> unable to create empty index: "+indexLocationString+" path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ |
291 |
Util.verbose("-> unable to create empty index: "+indexLocation+" path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ |
295 |
// The file could not be created. Possible reason: the project has been deleted. |
292 |
// The file could not be created. Possible reason: the project has been deleted. |
296 |
return null; |
293 |
return null; |
297 |
} |
294 |
} |
Lines 307-313
Link Here
|
307 |
* @param locations The list of of the index files path |
304 |
* @param locations The list of of the index files path |
308 |
* @return The corresponding indexes list. |
305 |
* @return The corresponding indexes list. |
309 |
*/ |
306 |
*/ |
310 |
public Index[] getIndexes(IPath[] locations, IProgressMonitor progressMonitor) { |
307 |
public Index[] getIndexes(IndexLocation[] locations, IProgressMonitor progressMonitor) { |
311 |
// acquire the in-memory indexes on the fly |
308 |
// acquire the in-memory indexes on the fly |
312 |
int length = locations.length; |
309 |
int length = locations.length; |
313 |
Index[] locatedIndexes = new Index[length]; |
310 |
Index[] locatedIndexes = new Index[length]; |
Lines 320-326
Link Here
|
320 |
throw new OperationCanceledException(); |
317 |
throw new OperationCanceledException(); |
321 |
} |
318 |
} |
322 |
// may trigger some index recreation work |
319 |
// may trigger some index recreation work |
323 |
IPath indexLocation = locations[i]; |
320 |
IndexLocation indexLocation = locations[i]; |
324 |
Index index = getIndex(indexLocation); |
321 |
Index index = getIndex(indexLocation); |
325 |
if (index == null) { |
322 |
if (index == null) { |
326 |
// only need containerPath if the index must be built |
323 |
// only need containerPath if the index must be built |
Lines 342-359
Link Here
|
342 |
index = null; |
339 |
index = null; |
343 |
} |
340 |
} |
344 |
} else { |
341 |
} else { |
345 |
if (!getJavaPluginWorkingLocation().isPrefixOf(indexLocation)) { // the index belongs to non-jdt search participant |
342 |
if (indexLocation.isParticipantIndex() && indexLocation.exists()) { // the index belongs to non-jdt search participant |
346 |
if (indexLocation.toFile().exists()) { |
343 |
try { |
347 |
try { |
344 |
IPath container = getParticipantsContainer(indexLocation); |
348 |
IPath container = getParticipantsContainer(indexLocation); |
345 |
if (container != null) { |
349 |
if (container != null) { |
346 |
index = new Index(indexLocation, container.toOSString(), true /*reuse index file*/); |
350 |
index = new Index(indexLocation.toOSString(), container.toOSString(), true /*reuse index file*/); |
347 |
this.indexes.put(indexLocation, index); |
351 |
this.indexes.put(indexLocation, index); |
|
|
352 |
} |
353 |
} catch (IOException e) { |
354 |
// ignore |
355 |
} |
348 |
} |
356 |
} |
349 |
} catch (IOException e) { |
|
|
350 |
// ignore |
351 |
} |
357 |
} |
352 |
} |
358 |
} |
353 |
} |
359 |
} |
354 |
} |
Lines 370-376
Link Here
|
370 |
return locatedIndexes; |
365 |
return locatedIndexes; |
371 |
} |
366 |
} |
372 |
public synchronized Index getIndexForUpdate(IPath containerPath, boolean reuseExistingFile, boolean createIfMissing) { |
367 |
public synchronized Index getIndexForUpdate(IPath containerPath, boolean reuseExistingFile, boolean createIfMissing) { |
373 |
IPath indexLocation = computeIndexLocation(containerPath); |
368 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
374 |
if (getIndexStates().get(indexLocation) == REBUILDING_STATE) |
369 |
if (getIndexStates().get(indexLocation) == REBUILDING_STATE) |
375 |
return getIndex(containerPath, indexLocation, reuseExistingFile, createIfMissing); |
370 |
return getIndex(containerPath, indexLocation, reuseExistingFile, createIfMissing); |
376 |
|
371 |
|
Lines 380-392
Link Here
|
380 |
if (this.indexStates != null) return this.indexStates; |
375 |
if (this.indexStates != null) return this.indexStates; |
381 |
|
376 |
|
382 |
this.indexStates = new SimpleLookupTable(); |
377 |
this.indexStates = new SimpleLookupTable(); |
383 |
IPath indexesDirectoryPath = getJavaPluginWorkingLocation(); |
378 |
File indexesDirectoryPath = getSavedIndexesDirectory(); |
384 |
char[][] savedNames = readIndexState(indexesDirectoryPath.toOSString()); |
379 |
char[][] savedNames = readIndexState(getJavaPluginWorkingLocation().toOSString()); |
385 |
if (savedNames != null) { |
380 |
if (savedNames != null) { |
386 |
for (int i = 1, l = savedNames.length; i < l; i++) { // first name is saved signature, see readIndexState() |
381 |
for (int i = 1, l = savedNames.length; i < l; i++) { // first name is saved signature, see readIndexState() |
387 |
char[] savedName = savedNames[i]; |
382 |
char[] savedName = savedNames[i]; |
388 |
if (savedName.length > 0) { |
383 |
if (savedName.length > 0) { |
389 |
IPath indexLocation = indexesDirectoryPath.append(new String(savedName)); // shares indexesDirectoryPath's segments |
384 |
IndexLocation indexLocation = new FileIndexLocation(new File(indexesDirectoryPath, String.valueOf(savedName))); // shares indexesDirectoryPath's segments |
390 |
if (VERBOSE) |
385 |
if (VERBOSE) |
391 |
Util.verbose("Reading saved index file " + indexLocation); //$NON-NLS-1$ |
386 |
Util.verbose("Reading saved index file " + indexLocation); //$NON-NLS-1$ |
392 |
this.indexStates.put(indexLocation, SAVED_STATE); |
387 |
this.indexStates.put(indexLocation, SAVED_STATE); |
Lines 401-407
Link Here
|
401 |
} |
396 |
} |
402 |
return this.indexStates; |
397 |
return this.indexStates; |
403 |
} |
398 |
} |
404 |
private IPath getParticipantsContainer(IPath indexLocation) { |
399 |
private IPath getParticipantsContainer(IndexLocation indexLocation) { |
405 |
if (this.participantsContainers == null) { |
400 |
if (this.participantsContainers == null) { |
406 |
readParticipantsIndexNamesFile(); |
401 |
readParticipantsIndexNamesFile(); |
407 |
} |
402 |
} |
Lines 502-516
Link Here
|
502 |
*/ |
497 |
*/ |
503 |
public void indexLibrary(IPath path, IProject requestingProject, URL indexURL) { |
498 |
public void indexLibrary(IPath path, IProject requestingProject, URL indexURL) { |
504 |
// requestingProject is no longer used to cancel jobs but leave it here just in case |
499 |
// requestingProject is no longer used to cancel jobs but leave it here just in case |
505 |
IPath indexFile = null; |
500 |
IndexLocation indexFile = indexURL != null ? IndexLocation.createIndexLocation(indexURL): null; |
506 |
if (indexURL != null) { |
|
|
507 |
try { |
508 |
indexFile = new Path(FileLocator.resolve(indexURL).getPath()); |
509 |
} catch (IOException e) { |
510 |
if (VERBOSE) |
511 |
Util.verbose("-> cannot resolve the url : "+ indexURL + " specified for " + path); //$NON-NLS-1$ //$NON-NLS-2$ |
512 |
} |
513 |
} |
514 |
if (JavaCore.getPlugin() == null) return; |
501 |
if (JavaCore.getPlugin() == null) return; |
515 |
IndexRequest request = null; |
502 |
IndexRequest request = null; |
516 |
Object target = JavaModel.getTarget(path, true); |
503 |
Object target = JavaModel.getTarget(path, true); |
Lines 529-539
Link Here
|
529 |
request(request); |
516 |
request(request); |
530 |
} |
517 |
} |
531 |
|
518 |
|
532 |
synchronized boolean addIndex(IPath containerPath, IPath indexFile) { |
519 |
synchronized boolean addIndex(IPath containerPath, IndexLocation indexFile) { |
533 |
this.indexStates.put(indexFile, REUSE_STATE); |
520 |
this.indexStates.put(indexFile, REUSE_STATE); |
534 |
this.indexLocations.put(containerPath, indexFile); |
521 |
this.indexLocations.put(containerPath, indexFile); |
535 |
Index index = getIndex(containerPath, indexFile, true, false); |
522 |
Index index = getIndex(containerPath, indexFile, true, false); |
536 |
if (index == null) { |
523 |
if (index == null) { |
|
|
524 |
indexFile.close(); |
537 |
this.indexLocations.put(containerPath, null); |
525 |
this.indexLocations.put(containerPath, null); |
538 |
return false; |
526 |
return false; |
539 |
} |
527 |
} |
Lines 554-560
Link Here
|
554 |
request(new AddFolderToIndex(sourceFolder, project, inclusionPatterns, exclusionPatterns, this)); |
542 |
request(new AddFolderToIndex(sourceFolder, project, inclusionPatterns, exclusionPatterns, this)); |
555 |
} |
543 |
} |
556 |
public synchronized void jobWasCancelled(IPath containerPath) { |
544 |
public synchronized void jobWasCancelled(IPath containerPath) { |
557 |
IPath indexLocation = computeIndexLocation(containerPath); |
545 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
558 |
Index index = getIndex(indexLocation); |
546 |
Index index = getIndex(indexLocation); |
559 |
if (index != null) { |
547 |
if (index != null) { |
560 |
index.monitor = null; |
548 |
index.monitor = null; |
Lines 600-606
Link Here
|
600 |
} |
588 |
} |
601 |
return null; |
589 |
return null; |
602 |
} |
590 |
} |
603 |
private void rebuildIndex(IPath indexLocation, IPath containerPath) { |
591 |
private void rebuildIndex(IndexLocation indexLocation, IPath containerPath) { |
604 |
Object target = JavaModel.getTarget(containerPath, true); |
592 |
Object target = JavaModel.getTarget(containerPath, true); |
605 |
if (target == null) return; |
593 |
if (target == null) return; |
606 |
|
594 |
|
Lines 633-645
Link Here
|
633 |
String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
621 |
String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
634 |
try { |
622 |
try { |
635 |
// Path is already canonical |
623 |
// Path is already canonical |
636 |
IPath indexLocation = computeIndexLocation(containerPath); |
624 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
637 |
Index index = getIndex(indexLocation); |
625 |
Index index = getIndex(indexLocation); |
638 |
ReadWriteMonitor monitor = index == null ? null : index.monitor; |
626 |
ReadWriteMonitor monitor = index == null ? null : index.monitor; |
639 |
|
627 |
|
640 |
if (VERBOSE) |
628 |
if (VERBOSE) |
641 |
Util.verbose("-> recreating index: "+indexLocation+" for path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ |
629 |
Util.verbose("-> recreating index: "+indexLocation+" for path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ |
642 |
index = new Index(indexLocation.toOSString(), containerPathString, false /*do not reuse index file*/); |
630 |
index = new Index(indexLocation, containerPathString, false /*do not reuse index file*/); |
643 |
this.indexes.put(indexLocation, index); |
631 |
this.indexes.put(indexLocation, index); |
644 |
index.monitor = monitor; |
632 |
index.monitor = monitor; |
645 |
return index; |
633 |
return index; |
Lines 666-672
Link Here
|
666 |
public synchronized void removeIndex(IPath containerPath) { |
654 |
public synchronized void removeIndex(IPath containerPath) { |
667 |
if (VERBOSE || DEBUG) |
655 |
if (VERBOSE || DEBUG) |
668 |
Util.verbose("removing index " + containerPath); //$NON-NLS-1$ |
656 |
Util.verbose("removing index " + containerPath); //$NON-NLS-1$ |
669 |
IPath indexLocation = computeIndexLocation(containerPath); |
657 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
670 |
Index index = getIndex(indexLocation); |
658 |
Index index = getIndex(indexLocation); |
671 |
File indexFile = null; |
659 |
File indexFile = null; |
672 |
if (index != null) { |
660 |
if (index != null) { |
Lines 674-683
Link Here
|
674 |
indexFile = index.getIndexFile(); |
662 |
indexFile = index.getIndexFile(); |
675 |
} |
663 |
} |
676 |
if (indexFile == null) |
664 |
if (indexFile == null) |
677 |
indexFile = new File(indexLocation.toOSString()); // index is not cached yet, but still want to delete the file |
665 |
indexFile = indexLocation.getIndexFile(); // index is not cached yet, but still want to delete the file |
678 |
if (this.indexStates.get(indexLocation) == REUSE_STATE) { |
666 |
if (this.indexStates.get(indexLocation) == REUSE_STATE) { |
|
|
667 |
indexLocation.close(); |
679 |
this.indexLocations.put(containerPath, null); |
668 |
this.indexLocations.put(containerPath, null); |
680 |
} else if (indexFile.exists()) { |
669 |
} else if (indexFile != null && indexFile.exists()) { |
681 |
if (DEBUG) |
670 |
if (DEBUG) |
682 |
Util.verbose("removing index file " + indexFile); //$NON-NLS-1$ |
671 |
Util.verbose("removing index file " + indexFile); //$NON-NLS-1$ |
683 |
indexFile.delete(); |
672 |
indexFile.delete(); |
Lines 693-716
Link Here
|
693 |
Util.verbose("removing index path " + path); //$NON-NLS-1$ |
682 |
Util.verbose("removing index path " + path); //$NON-NLS-1$ |
694 |
Object[] keyTable = this.indexes.keyTable; |
683 |
Object[] keyTable = this.indexes.keyTable; |
695 |
Object[] valueTable = this.indexes.valueTable; |
684 |
Object[] valueTable = this.indexes.valueTable; |
696 |
IPath[] locations = null; |
685 |
IndexLocation[] locations = null; |
697 |
int max = this.indexes.elementSize; |
686 |
int max = this.indexes.elementSize; |
698 |
int count = 0; |
687 |
int count = 0; |
699 |
for (int i = 0, l = keyTable.length; i < l; i++) { |
688 |
for (int i = 0, l = keyTable.length; i < l; i++) { |
700 |
IPath indexLocation = (IPath) keyTable[i]; |
689 |
IndexLocation indexLocation = (IndexLocation) keyTable[i]; |
701 |
if (indexLocation == null) |
690 |
if (indexLocation == null) |
702 |
continue; |
691 |
continue; |
703 |
if (path.isPrefixOf(indexLocation)) { |
692 |
if (indexLocation.startsWith(path)) { |
704 |
Index index = (Index) valueTable[i]; |
693 |
Index index = (Index) valueTable[i]; |
705 |
index.monitor = null; |
694 |
index.monitor = null; |
706 |
if (locations == null) |
695 |
if (locations == null) |
707 |
locations = new IPath[max]; |
696 |
locations = new IndexLocation[max]; |
708 |
locations[count++] = indexLocation; |
697 |
locations[count++] = indexLocation; |
709 |
File indexFile = index.getIndexFile(); |
698 |
if (this.indexStates.get(indexLocation) == REUSE_STATE) { |
710 |
if (indexFile.exists()) { |
699 |
indexLocation.close(); |
|
|
700 |
} else { |
711 |
if (DEBUG) |
701 |
if (DEBUG) |
712 |
Util.verbose("removing index file " + indexFile); //$NON-NLS-1$ |
702 |
Util.verbose("removing index file " + indexLocation); //$NON-NLS-1$ |
713 |
indexFile.delete(); |
703 |
indexLocation.delete(); |
714 |
} |
704 |
} |
715 |
} else { |
705 |
} else { |
716 |
max--; |
706 |
max--; |
Lines 786-792
Link Here
|
786 |
String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
776 |
String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
787 |
try { |
777 |
try { |
788 |
// Path is already canonical |
778 |
// Path is already canonical |
789 |
IPath indexLocation = computeIndexLocation(containerPath); |
779 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
790 |
Index index = getIndex(indexLocation); |
780 |
Index index = getIndex(indexLocation); |
791 |
if (VERBOSE) { |
781 |
if (VERBOSE) { |
792 |
Util.verbose("-> reseting index: "+indexLocation+" for path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ |
782 |
Util.verbose("-> reseting index: "+indexLocation+" for path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ |
Lines 810-816
Link Here
|
810 |
// must have permission to write from the write monitor |
800 |
// must have permission to write from the write monitor |
811 |
if (index.hasChanged()) { |
801 |
if (index.hasChanged()) { |
812 |
if (VERBOSE) |
802 |
if (VERBOSE) |
813 |
Util.verbose("-> saving index " + index.getIndexFile()); //$NON-NLS-1$ |
803 |
Util.verbose("-> saving index " + index.getIndexLocation()); //$NON-NLS-1$ |
814 |
index.save(); |
804 |
index.save(); |
815 |
} |
805 |
} |
816 |
synchronized (this) { |
806 |
synchronized (this) { |
Lines 822-828
Link Here
|
822 |
if (((IndexRequest) job).containerPath.equals(containerPath)) return; |
812 |
if (((IndexRequest) job).containerPath.equals(containerPath)) return; |
823 |
} |
813 |
} |
824 |
} |
814 |
} |
825 |
IPath indexLocation = computeIndexLocation(containerPath); |
815 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
826 |
updateIndexState(indexLocation, SAVED_STATE); |
816 |
updateIndexState(indexLocation, SAVED_STATE); |
827 |
} |
817 |
} |
828 |
} |
818 |
} |
Lines 877-883
Link Here
|
877 |
} |
867 |
} |
878 |
this.needToSave = !allSaved; |
868 |
this.needToSave = !allSaved; |
879 |
} |
869 |
} |
880 |
public void scheduleDocumentIndexing(final SearchDocument searchDocument, IPath container, final IPath indexLocation, final SearchParticipant searchParticipant) { |
870 |
public void scheduleDocumentIndexing(final SearchDocument searchDocument, IPath container, final IndexLocation indexLocation, final SearchParticipant searchParticipant) { |
881 |
request(new IndexRequest(container, this) { |
871 |
request(new IndexRequest(container, this) { |
882 |
public boolean execute(IProgressMonitor progressMonitor) { |
872 |
public boolean execute(IProgressMonitor progressMonitor) { |
883 |
if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true; |
873 |
if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true; |
Lines 890-896
Link Here
|
890 |
|
880 |
|
891 |
try { |
881 |
try { |
892 |
monitor.enterWrite(); // ask permission to write |
882 |
monitor.enterWrite(); // ask permission to write |
893 |
indexDocument(searchDocument, searchParticipant, index, indexLocation); |
883 |
indexDocument(searchDocument, searchParticipant, index, new Path(indexLocation.getCanonicalFilePath())); |
894 |
} finally { |
884 |
} finally { |
895 |
monitor.exitWrite(); // free write lock |
885 |
monitor.exitWrite(); // free write lock |
896 |
} |
886 |
} |
Lines 944-950
Link Here
|
944 |
// First line is DiskIndex signature (see writeParticipantsIndexNamesFile()) |
934 |
// First line is DiskIndex signature (see writeParticipantsIndexNamesFile()) |
945 |
if (DiskIndex.SIGNATURE.equals(new String(names[0]))) { |
935 |
if (DiskIndex.SIGNATURE.equals(new String(names[0]))) { |
946 |
for (int i = 1, l = names.length-1 ; i < l ; i+=2) { |
936 |
for (int i = 1, l = names.length-1 ; i < l ; i+=2) { |
947 |
containers.put(new Path(new String(names[i])), new Path(new String(names[i+1]))); |
937 |
IndexLocation indexLocation = new FileIndexLocation(new File(new String(names[i])), true); |
|
|
938 |
containers.put(indexLocation, new Path(new String(names[i+1]))); |
948 |
} |
939 |
} |
949 |
} |
940 |
} |
950 |
} |
941 |
} |
Lines 956-962
Link Here
|
956 |
this.participantsContainers = containers; |
947 |
this.participantsContainers = containers; |
957 |
return; |
948 |
return; |
958 |
} |
949 |
} |
959 |
private synchronized void removeIndexesState(IPath[] locations) { |
950 |
private synchronized void removeIndexesState(IndexLocation[] locations) { |
960 |
getIndexStates(); // ensure the states are initialized |
951 |
getIndexStates(); // ensure the states are initialized |
961 |
int length = locations.length; |
952 |
int length = locations.length; |
962 |
boolean changed = false; |
953 |
boolean changed = false; |
Lines 973-980
Link Here
|
973 |
|
964 |
|
974 |
writeSavedIndexNamesFile(); |
965 |
writeSavedIndexNamesFile(); |
975 |
} |
966 |
} |
976 |
private synchronized void updateIndexState(IPath indexLocation, Integer indexState) { |
967 |
private synchronized void updateIndexState(IndexLocation indexLocation, Integer indexState) { |
977 |
if (indexLocation.isEmpty()) |
968 |
if (indexLocation == null) |
978 |
throw new IllegalArgumentException(); |
969 |
throw new IllegalArgumentException(); |
979 |
|
970 |
|
980 |
getIndexStates(); // ensure the states are initialized |
971 |
getIndexStates(); // ensure the states are initialized |
Lines 1002-1011
Link Here
|
1002 |
} |
993 |
} |
1003 |
|
994 |
|
1004 |
} |
995 |
} |
1005 |
public void updateParticipant(IPath indexLocation, IPath containerPath) { |
996 |
public void updateParticipant(IPath indexPath, IPath containerPath) { |
1006 |
if (this.participantsContainers == null) { |
997 |
if (this.participantsContainers == null) { |
1007 |
readParticipantsIndexNamesFile(); |
998 |
readParticipantsIndexNamesFile(); |
1008 |
} |
999 |
} |
|
|
1000 |
IndexLocation indexLocation = new FileIndexLocation(indexPath.toFile(), true); |
1009 |
if (this.participantsContainers.get(indexLocation) == null) { |
1001 |
if (this.participantsContainers.get(indexLocation) == null) { |
1010 |
this.participantsContainers.put(indexLocation, containerPath); |
1002 |
this.participantsContainers.put(indexLocation, containerPath); |
1011 |
this.participantUpdated = true; |
1003 |
this.participantUpdated = true; |
Lines 1054-1062
Link Here
|
1054 |
Object[] indexFiles = this.participantsContainers.keyTable; |
1046 |
Object[] indexFiles = this.participantsContainers.keyTable; |
1055 |
Object[] containers = this.participantsContainers.valueTable; |
1047 |
Object[] containers = this.participantsContainers.valueTable; |
1056 |
for (int i = 0, l = indexFiles.length; i < l; i++) { |
1048 |
for (int i = 0, l = indexFiles.length; i < l; i++) { |
1057 |
IPath indexFile = (IPath)indexFiles[i]; |
1049 |
IndexLocation indexFile = (IndexLocation)indexFiles[i]; |
1058 |
if (indexFile != null) { |
1050 |
if (indexFile != null) { |
1059 |
writer.write(indexFile.toOSString()); |
1051 |
writer.write(indexFile.getIndexFile().getPath()); |
1060 |
writer.write('\n'); |
1052 |
writer.write('\n'); |
1061 |
writer.write(((IPath)containers[i]).toOSString()); |
1053 |
writer.write(((IPath)containers[i]).toOSString()); |
1062 |
writer.write('\n'); |
1054 |
writer.write('\n'); |
Lines 1086-1094
Link Here
|
1086 |
Object[] keys = this.indexStates.keyTable; |
1078 |
Object[] keys = this.indexStates.keyTable; |
1087 |
Object[] states = this.indexStates.valueTable; |
1079 |
Object[] states = this.indexStates.valueTable; |
1088 |
for (int i = 0, l = states.length; i < l; i++) { |
1080 |
for (int i = 0, l = states.length; i < l; i++) { |
1089 |
IPath key = (IPath) keys[i]; |
1081 |
IndexLocation key = (IndexLocation) keys[i]; |
1090 |
if (key != null && !key.isEmpty() && states[i] == SAVED_STATE) { |
1082 |
if (key != null && states[i] == SAVED_STATE) { |
1091 |
writer.write(key.lastSegment()); |
1083 |
writer.write(key.fileName()); |
1092 |
writer.write('\n'); |
1084 |
writer.write('\n'); |
1093 |
} |
1085 |
} |
1094 |
} |
1086 |
} |