Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2010 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2011 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 11-16
Link Here
|
11 |
package org.eclipse.jdt.internal.core.search.indexing; |
11 |
package org.eclipse.jdt.internal.core.search.indexing; |
12 |
|
12 |
|
13 |
import java.io.*; |
13 |
import java.io.*; |
|
|
14 |
import java.net.URL; |
14 |
import java.util.*; |
15 |
import java.util.*; |
15 |
import java.util.zip.CRC32; |
16 |
import java.util.zip.CRC32; |
16 |
|
17 |
|
Lines 59-64
Link Here
|
59 |
public static final Integer UPDATING_STATE = new Integer(1); |
60 |
public static final Integer UPDATING_STATE = new Integer(1); |
60 |
public static final Integer UNKNOWN_STATE = new Integer(2); |
61 |
public static final Integer UNKNOWN_STATE = new Integer(2); |
61 |
public static final Integer REBUILDING_STATE = new Integer(3); |
62 |
public static final Integer REBUILDING_STATE = new Integer(3); |
|
|
63 |
public static final Integer REUSE_STATE = new Integer(4); |
62 |
|
64 |
|
63 |
// search participants who register indexes with the index manager |
65 |
// search participants who register indexes with the index manager |
64 |
private SimpleLookupTable participantsContainers = null; |
66 |
private SimpleLookupTable participantsContainers = null; |
Lines 70-79
Link Here
|
70 |
public synchronized void aboutToUpdateIndex(IPath containerPath, Integer newIndexState) { |
72 |
public synchronized void aboutToUpdateIndex(IPath containerPath, Integer newIndexState) { |
71 |
// newIndexState is either UPDATING_STATE or REBUILDING_STATE |
73 |
// newIndexState is either UPDATING_STATE or REBUILDING_STATE |
72 |
// 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 |
73 |
IPath indexLocation = computeIndexLocation(containerPath); |
75 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
74 |
Object state = getIndexStates().get(indexLocation); |
76 |
Object state = getIndexStates().get(indexLocation); |
75 |
Integer currentIndexState = state == null ? UNKNOWN_STATE : (Integer) state; |
77 |
Integer currentIndexState = state == null ? UNKNOWN_STATE : (Integer) state; |
76 |
if (currentIndexState.equals(REBUILDING_STATE)) return; // already rebuilding the index |
78 |
if (currentIndexState.compareTo(REBUILDING_STATE) >= 0) return; // already rebuilding the index |
77 |
|
79 |
|
78 |
int compare = newIndexState.compareTo(currentIndexState); |
80 |
int compare = newIndexState.compareTo(currentIndexState); |
79 |
if (compare > 0) { |
81 |
if (compare > 0) { |
Lines 92-98
Link Here
|
92 |
if (JavaCore.getPlugin() == null) return; |
94 |
if (JavaCore.getPlugin() == null) return; |
93 |
SearchParticipant participant = SearchEngine.getDefaultSearchParticipant(); |
95 |
SearchParticipant participant = SearchEngine.getDefaultSearchParticipant(); |
94 |
SearchDocument document = participant.getDocument(resource.getFullPath().toString()); |
96 |
SearchDocument document = participant.getDocument(resource.getFullPath().toString()); |
95 |
IPath indexLocation = computeIndexLocation(containerPath); |
97 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
96 |
scheduleDocumentIndexing(document, containerPath, indexLocation, participant); |
98 |
scheduleDocumentIndexing(document, containerPath, indexLocation, participant); |
97 |
} |
99 |
} |
98 |
/** |
100 |
/** |
Lines 104-110
Link Here
|
104 |
SearchParticipant participant = SearchEngine.getDefaultSearchParticipant(); |
106 |
SearchParticipant participant = SearchEngine.getDefaultSearchParticipant(); |
105 |
SearchDocument document = participant.getDocument(resource.getFullPath().toString()); |
107 |
SearchDocument document = participant.getDocument(resource.getFullPath().toString()); |
106 |
document.setParser(parser); |
108 |
document.setParser(parser); |
107 |
IPath indexLocation = computeIndexLocation(containerPath); |
109 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
108 |
scheduleDocumentIndexing(document, containerPath, indexLocation, participant); |
110 |
scheduleDocumentIndexing(document, containerPath, indexLocation, participant); |
109 |
} |
111 |
} |
110 |
/* |
112 |
/* |
Lines 116-132
Link Here
|
116 |
PatternSearchJob job = new PatternSearchJob(null, SearchEngine.getDefaultSearchParticipant(), scope, null); |
118 |
PatternSearchJob job = new PatternSearchJob(null, SearchEngine.getDefaultSearchParticipant(), scope, null); |
117 |
Index[] selectedIndexes = job.getIndexes(null); |
119 |
Index[] selectedIndexes = job.getIndexes(null); |
118 |
for (int i = 0, l = selectedIndexes.length; i < l; i++) { |
120 |
for (int i = 0, l = selectedIndexes.length; i < l; i++) { |
119 |
String path = selectedIndexes[i].getIndexFile().getAbsolutePath(); |
121 |
IndexLocation IndexLocation = selectedIndexes[i].getIndexLocation(); |
120 |
knownPaths.add(path); |
122 |
knownPaths.add(IndexLocation); |
121 |
} |
123 |
} |
122 |
|
124 |
|
123 |
if (this.indexStates != null) { |
125 |
if (this.indexStates != null) { |
124 |
Object[] keys = this.indexStates.keyTable; |
126 |
Object[] keys = this.indexStates.keyTable; |
125 |
IPath[] locations = new IPath[this.indexStates.elementSize]; |
127 |
IndexLocation[] locations = new IndexLocation[this.indexStates.elementSize]; |
126 |
int count = 0; |
128 |
int count = 0; |
127 |
for (int i = 0, l = keys.length; i < l; i++) { |
129 |
for (int i = 0, l = keys.length; i < l; i++) { |
128 |
IPath key = (IPath) keys[i]; |
130 |
IndexLocation key = (IndexLocation) keys[i]; |
129 |
if (key != null && !knownPaths.includes(key.toOSString())) |
131 |
if (key != null && !knownPaths.includes(key)) |
130 |
locations[count++] = key; |
132 |
locations[count++] = key; |
131 |
} |
133 |
} |
132 |
if (count > 0) |
134 |
if (count > 0) |
Lines 134-141
Link Here
|
134 |
} |
136 |
} |
135 |
deleteIndexFiles(knownPaths); |
137 |
deleteIndexFiles(knownPaths); |
136 |
} |
138 |
} |
137 |
public synchronized IPath computeIndexLocation(IPath containerPath) { |
139 |
public synchronized IndexLocation computeIndexLocation(IPath containerPath) { |
138 |
IPath indexLocation = (IPath) this.indexLocations.get(containerPath); |
140 |
IndexLocation indexLocation = (IndexLocation) this.indexLocations.get(containerPath); |
139 |
if (indexLocation == null) { |
141 |
if (indexLocation == null) { |
140 |
String pathString = containerPath.toOSString(); |
142 |
String pathString = containerPath.toOSString(); |
141 |
CRC32 checksumCalculator = new CRC32(); |
143 |
CRC32 checksumCalculator = new CRC32(); |
Lines 144-150
Link Here
|
144 |
if (VERBOSE) |
146 |
if (VERBOSE) |
145 |
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$ |
146 |
// 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 |
147 |
indexLocation = (IPath) getIndexStates().getKey(getJavaPluginWorkingLocation().append(fileName)); |
149 |
indexLocation = (IndexLocation) getIndexStates().getKey(new FlatFileIndex(new File(getSavedIndexesDirectory(), fileName))); |
148 |
this.indexLocations.put(containerPath, indexLocation); |
150 |
this.indexLocations.put(containerPath, indexLocation); |
149 |
} |
151 |
} |
150 |
return indexLocation; |
152 |
return indexLocation; |
Lines 161-167
Link Here
|
161 |
|
163 |
|
162 |
for (int i = 0, l = indexesFiles.length; i < l; i++) { |
164 |
for (int i = 0, l = indexesFiles.length; i < l; i++) { |
163 |
String fileName = indexesFiles[i].getAbsolutePath(); |
165 |
String fileName = indexesFiles[i].getAbsolutePath(); |
164 |
if (pathsToKeep != null && pathsToKeep.includes(fileName)) continue; |
166 |
if (pathsToKeep != null && pathsToKeep.includes(new FlatFileIndex(indexesFiles[i]))) continue; |
165 |
String suffix = ".index"; //$NON-NLS-1$ |
167 |
String suffix = ".index"; //$NON-NLS-1$ |
166 |
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())) { |
167 |
if (VERBOSE || DEBUG) |
169 |
if (VERBOSE || DEBUG) |
Lines 173-179
Link Here
|
173 |
/* |
175 |
/* |
174 |
* 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. |
175 |
*/ |
177 |
*/ |
176 |
public synchronized void ensureIndexExists(IPath indexLocation, IPath containerPath) { |
178 |
public synchronized void ensureIndexExists(IndexLocation indexLocation, IPath containerPath) { |
177 |
SimpleLookupTable states = getIndexStates(); |
179 |
SimpleLookupTable states = getIndexStates(); |
178 |
Object state = states.get(indexLocation); |
180 |
Object state = states.get(indexLocation); |
179 |
if (state == null) { |
181 |
if (state == null) { |
Lines 207-213
Link Here
|
207 |
* @param indexLocation The path of the index file |
209 |
* @param indexLocation The path of the index file |
208 |
* @return The corresponding index or <code>null</code> if not found |
210 |
* @return The corresponding index or <code>null</code> if not found |
209 |
*/ |
211 |
*/ |
210 |
public synchronized Index getIndex(IPath indexLocation) { |
212 |
public synchronized Index getIndex(IndexLocation indexLocation) { |
211 |
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 |
212 |
} |
214 |
} |
213 |
/** |
215 |
/** |
Lines 219-225
Link Here
|
219 |
* Warning: Does not check whether index is consistent (not being used) |
221 |
* Warning: Does not check whether index is consistent (not being used) |
220 |
*/ |
222 |
*/ |
221 |
public synchronized Index getIndex(IPath containerPath, boolean reuseExistingFile, boolean createIfMissing) { |
223 |
public synchronized Index getIndex(IPath containerPath, boolean reuseExistingFile, boolean createIfMissing) { |
222 |
IPath indexLocation = computeIndexLocation(containerPath); |
224 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
223 |
return getIndex(containerPath, indexLocation, reuseExistingFile, createIfMissing); |
225 |
return getIndex(containerPath, indexLocation, reuseExistingFile, createIfMissing); |
224 |
} |
226 |
} |
225 |
/** |
227 |
/** |
Lines 230-236
Link Here
|
230 |
* |
232 |
* |
231 |
* Warning: Does not check whether index is consistent (not being used) |
233 |
* Warning: Does not check whether index is consistent (not being used) |
232 |
*/ |
234 |
*/ |
233 |
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) { |
234 |
// Path is already canonical per construction |
236 |
// Path is already canonical per construction |
235 |
Index index = getIndex(indexLocation); |
237 |
Index index = getIndex(indexLocation); |
236 |
if (index == null) { |
238 |
if (index == null) { |
Lines 245-263
Link Here
|
245 |
|
247 |
|
246 |
// index isn't cached, consider reusing an existing index file |
248 |
// index isn't cached, consider reusing an existing index file |
247 |
String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
249 |
String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
248 |
String indexLocationString = indexLocation.toOSString(); |
|
|
249 |
if (reuseExistingFile) { |
250 |
if (reuseExistingFile) { |
250 |
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 |
251 |
if (indexFile.exists()) { // check before creating index so as to avoid creating a new empty index if file is missing |
|
|
252 |
try { |
252 |
try { |
253 |
index = new Index(indexLocationString, containerPathString, true /*reuse index file*/); |
253 |
index = new Index(indexLocation, containerPathString, true /*reuse index file*/); |
254 |
this.indexes.put(indexLocation, index); |
254 |
this.indexes.put(indexLocation, index); |
255 |
return index; |
255 |
return index; |
256 |
} catch (IOException e) { |
256 |
} catch (IOException e) { |
257 |
// failed to read the existing file or its no longer compatible |
257 |
// failed to read the existing file or its no longer compatible |
258 |
if (currentIndexState != REBUILDING_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 |
259 |
if (VERBOSE) |
259 |
if (VERBOSE) |
260 |
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$ |
261 |
rebuildIndex(indexLocation, containerPath); |
261 |
rebuildIndex(indexLocation, containerPath); |
262 |
return null; |
262 |
return null; |
263 |
} |
263 |
} |
Lines 268-285
Link Here
|
268 |
rebuildIndex(indexLocation, containerPath); |
268 |
rebuildIndex(indexLocation, containerPath); |
269 |
return null; |
269 |
return null; |
270 |
} |
270 |
} |
|
|
271 |
if (currentIndexState == REUSE_STATE) { |
272 |
// supposed to be in reuse state but error in the index file, so reindex. |
273 |
if (VERBOSE) |
274 |
Util.verbose("-> cannot reuse given index: "+indexLocation+" path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ |
275 |
this.indexLocations.put(containerPath, null); |
276 |
indexLocation = computeIndexLocation(containerPath); |
277 |
rebuildIndex(indexLocation, containerPath); |
278 |
return null; |
279 |
} |
271 |
} |
280 |
} |
272 |
// index wasn't found on disk, consider creating an empty new one |
281 |
// index wasn't found on disk, consider creating an empty new one |
273 |
if (createIfMissing) { |
282 |
if (createIfMissing) { |
274 |
try { |
283 |
try { |
275 |
if (VERBOSE) |
284 |
if (VERBOSE) |
276 |
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$ |
277 |
index = new Index(indexLocationString, containerPathString, false /*do not reuse index file*/); |
286 |
index = new Index(indexLocation, containerPathString, false /*do not reuse index file*/); |
278 |
this.indexes.put(indexLocation, index); |
287 |
this.indexes.put(indexLocation, index); |
279 |
return index; |
288 |
return index; |
280 |
} catch (IOException e) { |
289 |
} catch (IOException e) { |
281 |
if (VERBOSE) |
290 |
if (VERBOSE) |
282 |
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$ |
283 |
// 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. |
284 |
return null; |
293 |
return null; |
285 |
} |
294 |
} |
Lines 295-301
Link Here
|
295 |
* @param locations The list of of the index files path |
304 |
* @param locations The list of of the index files path |
296 |
* @return The corresponding indexes list. |
305 |
* @return The corresponding indexes list. |
297 |
*/ |
306 |
*/ |
298 |
public Index[] getIndexes(IPath[] locations, IProgressMonitor progressMonitor) { |
307 |
public Index[] getIndexes(IndexLocation[] locations, IProgressMonitor progressMonitor) { |
299 |
// acquire the in-memory indexes on the fly |
308 |
// acquire the in-memory indexes on the fly |
300 |
int length = locations.length; |
309 |
int length = locations.length; |
301 |
Index[] locatedIndexes = new Index[length]; |
310 |
Index[] locatedIndexes = new Index[length]; |
Lines 308-314
Link Here
|
308 |
throw new OperationCanceledException(); |
317 |
throw new OperationCanceledException(); |
309 |
} |
318 |
} |
310 |
// may trigger some index recreation work |
319 |
// may trigger some index recreation work |
311 |
IPath indexLocation = locations[i]; |
320 |
IndexLocation indexLocation = locations[i]; |
312 |
Index index = getIndex(indexLocation); |
321 |
Index index = getIndex(indexLocation); |
313 |
if (index == null) { |
322 |
if (index == null) { |
314 |
// only need containerPath if the index must be built |
323 |
// only need containerPath if the index must be built |
Lines 330-347
Link Here
|
330 |
index = null; |
339 |
index = null; |
331 |
} |
340 |
} |
332 |
} else { |
341 |
} else { |
333 |
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 |
334 |
if (indexLocation.toFile().exists()) { |
343 |
try { |
335 |
try { |
344 |
IPath container = getParticipantsContainer(indexLocation); |
336 |
IPath container = getParticipantsContainer(indexLocation); |
345 |
if (container != null) { |
337 |
if (container != null) { |
346 |
index = new Index(indexLocation, container.toOSString(), true /*reuse index file*/); |
338 |
index = new Index(indexLocation.toOSString(), container.toOSString(), true /*reuse index file*/); |
347 |
this.indexes.put(indexLocation, index); |
339 |
this.indexes.put(indexLocation, index); |
|
|
340 |
} |
341 |
} catch (IOException e) { |
342 |
// ignore |
343 |
} |
348 |
} |
344 |
} |
349 |
} catch (IOException e) { |
|
|
350 |
// ignore |
351 |
} |
345 |
} |
352 |
} |
346 |
} |
353 |
} |
347 |
} |
354 |
} |
Lines 358-364
Link Here
|
358 |
return locatedIndexes; |
365 |
return locatedIndexes; |
359 |
} |
366 |
} |
360 |
public synchronized Index getIndexForUpdate(IPath containerPath, boolean reuseExistingFile, boolean createIfMissing) { |
367 |
public synchronized Index getIndexForUpdate(IPath containerPath, boolean reuseExistingFile, boolean createIfMissing) { |
361 |
IPath indexLocation = computeIndexLocation(containerPath); |
368 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
362 |
if (getIndexStates().get(indexLocation) == REBUILDING_STATE) |
369 |
if (getIndexStates().get(indexLocation) == REBUILDING_STATE) |
363 |
return getIndex(containerPath, indexLocation, reuseExistingFile, createIfMissing); |
370 |
return getIndex(containerPath, indexLocation, reuseExistingFile, createIfMissing); |
364 |
|
371 |
|
Lines 368-380
Link Here
|
368 |
if (this.indexStates != null) return this.indexStates; |
375 |
if (this.indexStates != null) return this.indexStates; |
369 |
|
376 |
|
370 |
this.indexStates = new SimpleLookupTable(); |
377 |
this.indexStates = new SimpleLookupTable(); |
371 |
IPath indexesDirectoryPath = getJavaPluginWorkingLocation(); |
378 |
File indexesDirectoryPath = getSavedIndexesDirectory(); |
372 |
char[][] savedNames = readIndexState(indexesDirectoryPath.toOSString()); |
379 |
char[][] savedNames = readIndexState(getJavaPluginWorkingLocation().toOSString()); |
373 |
if (savedNames != null) { |
380 |
if (savedNames != null) { |
374 |
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() |
375 |
char[] savedName = savedNames[i]; |
382 |
char[] savedName = savedNames[i]; |
376 |
if (savedName.length > 0) { |
383 |
if (savedName.length > 0) { |
377 |
IPath indexLocation = indexesDirectoryPath.append(new String(savedName)); // shares indexesDirectoryPath's segments |
384 |
IndexLocation indexLocation = new FlatFileIndex(new File(indexesDirectoryPath, String.valueOf(savedName))); // shares indexesDirectoryPath's segments |
378 |
if (VERBOSE) |
385 |
if (VERBOSE) |
379 |
Util.verbose("Reading saved index file " + indexLocation); //$NON-NLS-1$ |
386 |
Util.verbose("Reading saved index file " + indexLocation); //$NON-NLS-1$ |
380 |
this.indexStates.put(indexLocation, SAVED_STATE); |
387 |
this.indexStates.put(indexLocation, SAVED_STATE); |
Lines 389-395
Link Here
|
389 |
} |
396 |
} |
390 |
return this.indexStates; |
397 |
return this.indexStates; |
391 |
} |
398 |
} |
392 |
private IPath getParticipantsContainer(IPath indexLocation) { |
399 |
private IPath getParticipantsContainer(IndexLocation indexLocation) { |
393 |
if (this.participantsContainers == null) { |
400 |
if (this.participantsContainers == null) { |
394 |
readParticipantsIndexNamesFile(); |
401 |
readParticipantsIndexNamesFile(); |
395 |
} |
402 |
} |
Lines 474-480
Link Here
|
474 |
for (int i = 0; i < entries.length; i++) { |
481 |
for (int i = 0; i < entries.length; i++) { |
475 |
IClasspathEntry entry= entries[i]; |
482 |
IClasspathEntry entry= entries[i]; |
476 |
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) |
483 |
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) |
477 |
indexLibrary(entry.getPath(), project); |
484 |
indexLibrary(entry.getPath(), project, ((ClasspathEntry)entry).getLibraryIndexLocation()); |
478 |
} |
485 |
} |
479 |
} catch(JavaModelException e){ // cannot retrieve classpath info |
486 |
} catch(JavaModelException e){ // cannot retrieve classpath info |
480 |
} |
487 |
} |
Lines 488-503
Link Here
|
488 |
* Trigger addition of a library to an index |
495 |
* Trigger addition of a library to an index |
489 |
* Note: the actual operation is performed in background |
496 |
* Note: the actual operation is performed in background |
490 |
*/ |
497 |
*/ |
491 |
public void indexLibrary(IPath path, IProject requestingProject) { |
498 |
public void indexLibrary(IPath path, IProject requestingProject, URL indexURL) { |
492 |
// 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 |
|
|
500 |
IndexLocation indexFile = indexURL != null ? IndexLocation.createIndexLocation(indexURL): null; |
493 |
if (JavaCore.getPlugin() == null) return; |
501 |
if (JavaCore.getPlugin() == null) return; |
494 |
|
|
|
495 |
Object target = JavaModel.getTarget(path, true); |
496 |
IndexRequest request = null; |
502 |
IndexRequest request = null; |
|
|
503 |
Object target = JavaModel.getTarget(path, true); |
497 |
if (target instanceof IFile) { |
504 |
if (target instanceof IFile) { |
498 |
request = new AddJarFileToIndex((IFile) target, this); |
505 |
request = new AddJarFileToIndex((IFile) target, indexFile, this); |
499 |
} else if (target instanceof File) { |
506 |
} else if (target instanceof File) { |
500 |
request = new AddJarFileToIndex(path, this); |
507 |
request = new AddJarFileToIndex(path, indexFile, this); |
501 |
} else if (target instanceof IContainer) { |
508 |
} else if (target instanceof IContainer) { |
502 |
request = new IndexBinaryFolder((IContainer) target, this); |
509 |
request = new IndexBinaryFolder((IContainer) target, this); |
503 |
} else { |
510 |
} else { |
Lines 508-513
Link Here
|
508 |
if (!isJobWaiting(request)) |
515 |
if (!isJobWaiting(request)) |
509 |
request(request); |
516 |
request(request); |
510 |
} |
517 |
} |
|
|
518 |
|
519 |
synchronized boolean addIndex(IPath containerPath, IndexLocation indexFile) { |
520 |
this.indexStates.put(indexFile, REUSE_STATE); |
521 |
this.indexLocations.put(containerPath, indexFile); |
522 |
Index index = getIndex(containerPath, indexFile, true, false); |
523 |
if (index == null) { |
524 |
indexFile.close(); |
525 |
this.indexLocations.put(containerPath, null); |
526 |
return false; |
527 |
} |
528 |
return true; |
529 |
} |
530 |
|
511 |
/** |
531 |
/** |
512 |
* Index the content of the given source folder. |
532 |
* Index the content of the given source folder. |
513 |
*/ |
533 |
*/ |
Lines 522-528
Link Here
|
522 |
request(new AddFolderToIndex(sourceFolder, project, inclusionPatterns, exclusionPatterns, this)); |
542 |
request(new AddFolderToIndex(sourceFolder, project, inclusionPatterns, exclusionPatterns, this)); |
523 |
} |
543 |
} |
524 |
public synchronized void jobWasCancelled(IPath containerPath) { |
544 |
public synchronized void jobWasCancelled(IPath containerPath) { |
525 |
IPath indexLocation = computeIndexLocation(containerPath); |
545 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
526 |
Index index = getIndex(indexLocation); |
546 |
Index index = getIndex(indexLocation); |
527 |
if (index != null) { |
547 |
if (index != null) { |
528 |
index.monitor = null; |
548 |
index.monitor = null; |
Lines 568-574
Link Here
|
568 |
} |
588 |
} |
569 |
return null; |
589 |
return null; |
570 |
} |
590 |
} |
571 |
private void rebuildIndex(IPath indexLocation, IPath containerPath) { |
591 |
private void rebuildIndex(IndexLocation indexLocation, IPath containerPath) { |
572 |
Object target = JavaModel.getTarget(containerPath, true); |
592 |
Object target = JavaModel.getTarget(containerPath, true); |
573 |
if (target == null) return; |
593 |
if (target == null) return; |
574 |
|
594 |
|
Lines 584-592
Link Here
|
584 |
} else if (target instanceof IFolder) { |
604 |
} else if (target instanceof IFolder) { |
585 |
request = new IndexBinaryFolder((IFolder) target, this); |
605 |
request = new IndexBinaryFolder((IFolder) target, this); |
586 |
} else if (target instanceof IFile) { |
606 |
} else if (target instanceof IFile) { |
587 |
request = new AddJarFileToIndex((IFile) target, this); |
607 |
request = new AddJarFileToIndex((IFile) target, null, this); |
588 |
} else if (target instanceof File) { |
608 |
} else if (target instanceof File) { |
589 |
request = new AddJarFileToIndex(containerPath, this); |
609 |
request = new AddJarFileToIndex(containerPath, null, this); |
590 |
} |
610 |
} |
591 |
if (request != null) |
611 |
if (request != null) |
592 |
request(request); |
612 |
request(request); |
Lines 601-613
Link Here
|
601 |
String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
621 |
String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
602 |
try { |
622 |
try { |
603 |
// Path is already canonical |
623 |
// Path is already canonical |
604 |
IPath indexLocation = computeIndexLocation(containerPath); |
624 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
605 |
Index index = getIndex(indexLocation); |
625 |
Index index = getIndex(indexLocation); |
606 |
ReadWriteMonitor monitor = index == null ? null : index.monitor; |
626 |
ReadWriteMonitor monitor = index == null ? null : index.monitor; |
607 |
|
627 |
|
608 |
if (VERBOSE) |
628 |
if (VERBOSE) |
609 |
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$ |
610 |
index = new Index(indexLocation.toOSString(), containerPathString, false /*do not reuse index file*/); |
630 |
index = new Index(indexLocation, containerPathString, false /*do not reuse index file*/); |
611 |
this.indexes.put(indexLocation, index); |
631 |
this.indexes.put(indexLocation, index); |
612 |
index.monitor = monitor; |
632 |
index.monitor = monitor; |
613 |
return index; |
633 |
return index; |
Lines 634-640
Link Here
|
634 |
public synchronized void removeIndex(IPath containerPath) { |
654 |
public synchronized void removeIndex(IPath containerPath) { |
635 |
if (VERBOSE || DEBUG) |
655 |
if (VERBOSE || DEBUG) |
636 |
Util.verbose("removing index " + containerPath); //$NON-NLS-1$ |
656 |
Util.verbose("removing index " + containerPath); //$NON-NLS-1$ |
637 |
IPath indexLocation = computeIndexLocation(containerPath); |
657 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
638 |
Index index = getIndex(indexLocation); |
658 |
Index index = getIndex(indexLocation); |
639 |
File indexFile = null; |
659 |
File indexFile = null; |
640 |
if (index != null) { |
660 |
if (index != null) { |
Lines 642-649
Link Here
|
642 |
indexFile = index.getIndexFile(); |
662 |
indexFile = index.getIndexFile(); |
643 |
} |
663 |
} |
644 |
if (indexFile == null) |
664 |
if (indexFile == null) |
645 |
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 |
646 |
if (indexFile.exists()) { |
666 |
if (this.indexStates.get(indexLocation) == REUSE_STATE) { |
|
|
667 |
indexLocation.close(); |
668 |
this.indexLocations.put(containerPath, null); |
669 |
} else if (indexFile != null && indexFile.exists()) { |
647 |
if (DEBUG) |
670 |
if (DEBUG) |
648 |
Util.verbose("removing index file " + indexFile); //$NON-NLS-1$ |
671 |
Util.verbose("removing index file " + indexFile); //$NON-NLS-1$ |
649 |
indexFile.delete(); |
672 |
indexFile.delete(); |
Lines 659-682
Link Here
|
659 |
Util.verbose("removing index path " + path); //$NON-NLS-1$ |
682 |
Util.verbose("removing index path " + path); //$NON-NLS-1$ |
660 |
Object[] keyTable = this.indexes.keyTable; |
683 |
Object[] keyTable = this.indexes.keyTable; |
661 |
Object[] valueTable = this.indexes.valueTable; |
684 |
Object[] valueTable = this.indexes.valueTable; |
662 |
IPath[] locations = null; |
685 |
IndexLocation[] locations = null; |
663 |
int max = this.indexes.elementSize; |
686 |
int max = this.indexes.elementSize; |
664 |
int count = 0; |
687 |
int count = 0; |
665 |
for (int i = 0, l = keyTable.length; i < l; i++) { |
688 |
for (int i = 0, l = keyTable.length; i < l; i++) { |
666 |
IPath indexLocation = (IPath) keyTable[i]; |
689 |
IndexLocation indexLocation = (IndexLocation) keyTable[i]; |
667 |
if (indexLocation == null) |
690 |
if (indexLocation == null) |
668 |
continue; |
691 |
continue; |
669 |
if (path.isPrefixOf(indexLocation)) { |
692 |
if (path.isPrefixOf(new Path(indexLocation.getFilePath()))) { |
670 |
Index index = (Index) valueTable[i]; |
693 |
Index index = (Index) valueTable[i]; |
671 |
index.monitor = null; |
694 |
index.monitor = null; |
672 |
if (locations == null) |
695 |
if (locations == null) |
673 |
locations = new IPath[max]; |
696 |
locations = new IndexLocation[max]; |
674 |
locations[count++] = indexLocation; |
697 |
locations[count++] = indexLocation; |
675 |
File indexFile = index.getIndexFile(); |
698 |
if (this.indexStates.get(indexLocation) == REUSE_STATE) { |
676 |
if (indexFile.exists()) { |
699 |
indexLocation.close(); |
|
|
700 |
} else { |
677 |
if (DEBUG) |
701 |
if (DEBUG) |
678 |
Util.verbose("removing index file " + indexFile); //$NON-NLS-1$ |
702 |
Util.verbose("removing index file " + indexLocation); //$NON-NLS-1$ |
679 |
indexFile.delete(); |
703 |
indexLocation.delete(); |
680 |
} |
704 |
} |
681 |
} else { |
705 |
} else { |
682 |
max--; |
706 |
max--; |
Lines 686-694
Link Here
|
686 |
for (int i = 0; i < count; i++) |
710 |
for (int i = 0; i < count; i++) |
687 |
this.indexes.removeKey(locations[i]); |
711 |
this.indexes.removeKey(locations[i]); |
688 |
removeIndexesState(locations); |
712 |
removeIndexesState(locations); |
689 |
if (this.participantsContainers != null && this.participantsContainers.get(path.toOSString()) != null) { |
713 |
if (this.participantsContainers != null) { |
690 |
this.participantsContainers.removeKey(path.toOSString()); |
714 |
boolean update = false; |
691 |
writeParticipantsIndexNamesFile(); |
715 |
for (int i = 0; i < count; i++) { |
|
|
716 |
if (this.participantsContainers.get(locations[i]) != null) { |
717 |
update = true; |
718 |
this.participantsContainers.removeKey(locations[i]); |
719 |
} |
720 |
} |
721 |
if (update) writeParticipantsIndexNamesFile(); |
692 |
} |
722 |
} |
693 |
} |
723 |
} |
694 |
} |
724 |
} |
Lines 746-752
Link Here
|
746 |
String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
776 |
String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); |
747 |
try { |
777 |
try { |
748 |
// Path is already canonical |
778 |
// Path is already canonical |
749 |
IPath indexLocation = computeIndexLocation(containerPath); |
779 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
750 |
Index index = getIndex(indexLocation); |
780 |
Index index = getIndex(indexLocation); |
751 |
if (VERBOSE) { |
781 |
if (VERBOSE) { |
752 |
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 770-776
Link Here
|
770 |
// must have permission to write from the write monitor |
800 |
// must have permission to write from the write monitor |
771 |
if (index.hasChanged()) { |
801 |
if (index.hasChanged()) { |
772 |
if (VERBOSE) |
802 |
if (VERBOSE) |
773 |
Util.verbose("-> saving index " + index.getIndexFile()); //$NON-NLS-1$ |
803 |
Util.verbose("-> saving index " + index.getIndexLocation()); //$NON-NLS-1$ |
774 |
index.save(); |
804 |
index.save(); |
775 |
} |
805 |
} |
776 |
synchronized (this) { |
806 |
synchronized (this) { |
Lines 782-788
Link Here
|
782 |
if (((IndexRequest) job).containerPath.equals(containerPath)) return; |
812 |
if (((IndexRequest) job).containerPath.equals(containerPath)) return; |
783 |
} |
813 |
} |
784 |
} |
814 |
} |
785 |
IPath indexLocation = computeIndexLocation(containerPath); |
815 |
IndexLocation indexLocation = computeIndexLocation(containerPath); |
786 |
updateIndexState(indexLocation, SAVED_STATE); |
816 |
updateIndexState(indexLocation, SAVED_STATE); |
787 |
} |
817 |
} |
788 |
} |
818 |
} |
Lines 837-856
Link Here
|
837 |
} |
867 |
} |
838 |
this.needToSave = !allSaved; |
868 |
this.needToSave = !allSaved; |
839 |
} |
869 |
} |
840 |
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) { |
841 |
request(new IndexRequest(container, this) { |
871 |
request(new IndexRequest(container, this) { |
842 |
public boolean execute(IProgressMonitor progressMonitor) { |
872 |
public boolean execute(IProgressMonitor progressMonitor) { |
843 |
if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true; |
873 |
if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true; |
844 |
|
874 |
|
845 |
/* ensure no concurrent write access to index */ |
875 |
/* ensure no concurrent write access to index */ |
846 |
Index index = getIndex(this.containerPath, indexLocation, true, /*reuse index file*/ true /*create if none*/); |
876 |
Index index; |
|
|
877 |
index = getIndex(this.containerPath, indexLocation, true, /*reuse index file*/ true /*create if none*/); |
847 |
if (index == null) return true; |
878 |
if (index == null) return true; |
848 |
ReadWriteMonitor monitor = index.monitor; |
879 |
ReadWriteMonitor monitor = index.monitor; |
849 |
if (monitor == null) return true; // index got deleted since acquired |
880 |
if (monitor == null) return true; // index got deleted since acquired |
850 |
|
881 |
|
851 |
try { |
882 |
try { |
852 |
monitor.enterWrite(); // ask permission to write |
883 |
monitor.enterWrite(); // ask permission to write |
853 |
indexDocument(searchDocument, searchParticipant, index, indexLocation); |
884 |
indexDocument(searchDocument, searchParticipant, index, new Path(indexLocation.getFilePath())); |
854 |
} finally { |
885 |
} finally { |
855 |
monitor.exitWrite(); // free write lock |
886 |
monitor.exitWrite(); // free write lock |
856 |
} |
887 |
} |
Lines 904-910
Link Here
|
904 |
// First line is DiskIndex signature (see writeParticipantsIndexNamesFile()) |
935 |
// First line is DiskIndex signature (see writeParticipantsIndexNamesFile()) |
905 |
if (DiskIndex.SIGNATURE.equals(new String(names[0]))) { |
936 |
if (DiskIndex.SIGNATURE.equals(new String(names[0]))) { |
906 |
for (int i = 1, l = names.length-1 ; i < l ; i+=2) { |
937 |
for (int i = 1, l = names.length-1 ; i < l ; i+=2) { |
907 |
containers.put(new Path(new String(names[i])), new Path(new String(names[i+1]))); |
938 |
IndexLocation indexLocation = new FlatFileIndex(new File(new String(names[i]))); |
|
|
939 |
indexLocation.setParticipantIndex(); |
940 |
containers.put(indexLocation, new Path(new String(names[i+1]))); |
908 |
} |
941 |
} |
909 |
} |
942 |
} |
910 |
} |
943 |
} |
Lines 916-922
Link Here
|
916 |
this.participantsContainers = containers; |
949 |
this.participantsContainers = containers; |
917 |
return; |
950 |
return; |
918 |
} |
951 |
} |
919 |
private synchronized void removeIndexesState(IPath[] locations) { |
952 |
private synchronized void removeIndexesState(IndexLocation[] locations) { |
920 |
getIndexStates(); // ensure the states are initialized |
953 |
getIndexStates(); // ensure the states are initialized |
921 |
int length = locations.length; |
954 |
int length = locations.length; |
922 |
boolean changed = false; |
955 |
boolean changed = false; |
Lines 933-940
Link Here
|
933 |
|
966 |
|
934 |
writeSavedIndexNamesFile(); |
967 |
writeSavedIndexNamesFile(); |
935 |
} |
968 |
} |
936 |
private synchronized void updateIndexState(IPath indexLocation, Integer indexState) { |
969 |
private synchronized void updateIndexState(IndexLocation indexLocation, Integer indexState) { |
937 |
if (indexLocation.isEmpty()) |
970 |
if (indexLocation == null) |
938 |
throw new IllegalArgumentException(); |
971 |
throw new IllegalArgumentException(); |
939 |
|
972 |
|
940 |
getIndexStates(); // ensure the states are initialized |
973 |
getIndexStates(); // ensure the states are initialized |
Lines 962-973
Link Here
|
962 |
} |
995 |
} |
963 |
|
996 |
|
964 |
} |
997 |
} |
965 |
public void updateParticipant(IPath indexLocation, IPath containerPath) { |
998 |
public void updateParticipant(IPath indexPath, IPath containerPath) { |
966 |
if (this.participantsContainers == null) { |
999 |
if (this.participantsContainers == null) { |
967 |
readParticipantsIndexNamesFile(); |
1000 |
readParticipantsIndexNamesFile(); |
968 |
} |
1001 |
} |
|
|
1002 |
IndexLocation indexLocation = new FlatFileIndex(indexPath.toFile()); |
969 |
if (this.participantsContainers.get(indexLocation) == null) { |
1003 |
if (this.participantsContainers.get(indexLocation) == null) { |
970 |
this.participantsContainers.put(indexLocation, containerPath); |
1004 |
this.participantsContainers.put(indexLocation, containerPath); |
|
|
1005 |
indexLocation.setParticipantIndex(); |
971 |
this.participantUpdated = true; |
1006 |
this.participantUpdated = true; |
972 |
} |
1007 |
} |
973 |
} |
1008 |
} |
Lines 1014-1022
Link Here
|
1014 |
Object[] indexFiles = this.participantsContainers.keyTable; |
1049 |
Object[] indexFiles = this.participantsContainers.keyTable; |
1015 |
Object[] containers = this.participantsContainers.valueTable; |
1050 |
Object[] containers = this.participantsContainers.valueTable; |
1016 |
for (int i = 0, l = indexFiles.length; i < l; i++) { |
1051 |
for (int i = 0, l = indexFiles.length; i < l; i++) { |
1017 |
IPath indexFile = (IPath)indexFiles[i]; |
1052 |
IndexLocation indexFile = (IndexLocation)indexFiles[i]; |
1018 |
if (indexFile != null) { |
1053 |
if (indexFile != null) { |
1019 |
writer.write(indexFile.toOSString()); |
1054 |
writer.write(indexFile.getIndexFile().getPath()); |
1020 |
writer.write('\n'); |
1055 |
writer.write('\n'); |
1021 |
writer.write(((IPath)containers[i]).toOSString()); |
1056 |
writer.write(((IPath)containers[i]).toOSString()); |
1022 |
writer.write('\n'); |
1057 |
writer.write('\n'); |
Lines 1046-1054
Link Here
|
1046 |
Object[] keys = this.indexStates.keyTable; |
1081 |
Object[] keys = this.indexStates.keyTable; |
1047 |
Object[] states = this.indexStates.valueTable; |
1082 |
Object[] states = this.indexStates.valueTable; |
1048 |
for (int i = 0, l = states.length; i < l; i++) { |
1083 |
for (int i = 0, l = states.length; i < l; i++) { |
1049 |
IPath key = (IPath) keys[i]; |
1084 |
IndexLocation key = (IndexLocation) keys[i]; |
1050 |
if (key != null && !key.isEmpty() && states[i] == SAVED_STATE) { |
1085 |
if (key != null && states[i] == SAVED_STATE) { |
1051 |
writer.write(key.lastSegment()); |
1086 |
writer.write(key.fileName()); |
1052 |
writer.write('\n'); |
1087 |
writer.write('\n'); |
1053 |
} |
1088 |
} |
1054 |
} |
1089 |
} |