|
Lines 53-63
Link Here
|
| 53 |
// key = indexLocation path, value = index state integer |
53 |
// key = indexLocation path, value = index state integer |
| 54 |
private SimpleLookupTable indexStates = null; |
54 |
private SimpleLookupTable indexStates = null; |
| 55 |
private File savedIndexNamesFile = new File(getSavedIndexesDirectory(), "savedIndexNames.txt"); //$NON-NLS-1$ |
55 |
private File savedIndexNamesFile = new File(getSavedIndexesDirectory(), "savedIndexNames.txt"); //$NON-NLS-1$ |
|
|
56 |
private File participantIndexNamesFile = new File(getSavedIndexesDirectory(), "participantsIndexNames.txt"); //$NON-NLS-1$ |
| 56 |
private boolean javaLikeNamesChanged = true; |
57 |
private boolean javaLikeNamesChanged = true; |
| 57 |
public static final Integer SAVED_STATE = new Integer(0); |
58 |
public static final Integer SAVED_STATE = new Integer(0); |
| 58 |
public static final Integer UPDATING_STATE = new Integer(1); |
59 |
public static final Integer UPDATING_STATE = new Integer(1); |
| 59 |
public static final Integer UNKNOWN_STATE = new Integer(2); |
60 |
public static final Integer UNKNOWN_STATE = new Integer(2); |
| 60 |
public static final Integer REBUILDING_STATE = new Integer(3); |
61 |
public static final Integer REBUILDING_STATE = new Integer(3); |
|
|
62 |
|
| 63 |
// search participants who register indexes with the index manager |
| 64 |
private SimpleLookupTable participantsContainers = null; |
| 65 |
private boolean participantUpdated = false; |
| 61 |
|
66 |
|
| 62 |
// Debug |
67 |
// Debug |
| 63 |
public static boolean DEBUG = false; |
68 |
public static boolean DEBUG = false; |
|
Lines 324-329
Link Here
|
| 324 |
rebuildIndex(indexLocation, containerPath); |
329 |
rebuildIndex(indexLocation, containerPath); |
| 325 |
index = null; |
330 |
index = null; |
| 326 |
} |
331 |
} |
|
|
332 |
} else { |
| 333 |
if (!getJavaPluginWorkingLocation().isPrefixOf(indexLocation)) { // the index belongs to non-jdt search participant |
| 334 |
if (indexLocation.toFile().exists()) { |
| 335 |
try { |
| 336 |
IPath container = getParticipantsContainer(indexLocation); |
| 337 |
if (container != null) { |
| 338 |
index = new Index(indexLocation.toOSString(), container.toOSString(), true /*reuse index file*/); |
| 339 |
this.indexes.put(indexLocation, index); |
| 340 |
} |
| 341 |
} catch (IOException e) { |
| 342 |
// ignore |
| 343 |
} |
| 344 |
} |
| 345 |
} |
| 327 |
} |
346 |
} |
| 328 |
} |
347 |
} |
| 329 |
if (index != null) |
348 |
if (index != null) |
|
Lines 370-375
Link Here
|
| 370 |
} |
389 |
} |
| 371 |
return this.indexStates; |
390 |
return this.indexStates; |
| 372 |
} |
391 |
} |
|
|
392 |
private IPath getParticipantsContainer(IPath indexLocation) { |
| 393 |
if (this.participantsContainers == null) { |
| 394 |
readParticipantsIndexNamesFile(); |
| 395 |
} |
| 396 |
return (IPath)this.participantsContainers.get(indexLocation); |
| 397 |
} |
| 373 |
private IPath getJavaPluginWorkingLocation() { |
398 |
private IPath getJavaPluginWorkingLocation() { |
| 374 |
if (this.javaPluginLocation != null) return this.javaPluginLocation; |
399 |
if (this.javaPluginLocation != null) return this.javaPluginLocation; |
| 375 |
|
400 |
|
|
Lines 661-666
Link Here
|
| 661 |
for (int i = 0; i < count; i++) |
686 |
for (int i = 0; i < count; i++) |
| 662 |
this.indexes.removeKey(locations[i]); |
687 |
this.indexes.removeKey(locations[i]); |
| 663 |
removeIndexesState(locations); |
688 |
removeIndexesState(locations); |
|
|
689 |
if (this.participantsContainers != null && this.participantsContainers.get(path.toOSString()) != null) { |
| 690 |
this.participantsContainers.removeKey(path.toOSString()); |
| 691 |
writeParticipantsIndexNamesFile(); |
| 692 |
} |
| 664 |
} |
693 |
} |
| 665 |
} |
694 |
} |
| 666 |
/** |
695 |
/** |
|
Lines 802-807
Link Here
|
| 802 |
monitor.exitRead(); |
831 |
monitor.exitRead(); |
| 803 |
} |
832 |
} |
| 804 |
} |
833 |
} |
|
|
834 |
if (this.participantsContainers != null && this.participantUpdated) { |
| 835 |
writeParticipantsIndexNamesFile(); |
| 836 |
this.participantUpdated = false; |
| 837 |
} |
| 805 |
this.needToSave = !allSaved; |
838 |
this.needToSave = !allSaved; |
| 806 |
} |
839 |
} |
| 807 |
public void scheduleDocumentIndexing(final SearchDocument searchDocument, IPath container, final IPath indexLocation, final SearchParticipant searchParticipant) { |
840 |
public void scheduleDocumentIndexing(final SearchDocument searchDocument, IPath container, final IPath indexLocation, final SearchParticipant searchParticipant) { |
|
Lines 861-866
Link Here
|
| 861 |
} |
894 |
} |
| 862 |
return null; |
895 |
return null; |
| 863 |
} |
896 |
} |
|
|
897 |
private void readParticipantsIndexNamesFile() { |
| 898 |
SimpleLookupTable containers = new SimpleLookupTable(3); |
| 899 |
try { |
| 900 |
char[] participantIndexNames = org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(this.participantIndexNamesFile, null); |
| 901 |
if (participantIndexNames.length > 0) { |
| 902 |
char[][] names = CharOperation.splitOn('\n', participantIndexNames); |
| 903 |
if (names.length >= 3) { |
| 904 |
// First line is DiskIndex signature (see writeParticipantsIndexNamesFile()) |
| 905 |
if (DiskIndex.SIGNATURE.equals(new String(names[0]))) { |
| 906 |
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]))); |
| 908 |
} |
| 909 |
} |
| 910 |
} |
| 911 |
} |
| 912 |
} catch (IOException ignored) { |
| 913 |
if (VERBOSE) |
| 914 |
Util.verbose("Failed to read participant index file names"); //$NON-NLS-1$ |
| 915 |
} |
| 916 |
this.participantsContainers = containers; |
| 917 |
return; |
| 918 |
} |
| 864 |
private synchronized void removeIndexesState(IPath[] locations) { |
919 |
private synchronized void removeIndexesState(IPath[] locations) { |
| 865 |
getIndexStates(); // ensure the states are initialized |
920 |
getIndexStates(); // ensure the states are initialized |
| 866 |
int length = locations.length; |
921 |
int length = locations.length; |
|
Lines 907-912
Link Here
|
| 907 |
} |
962 |
} |
| 908 |
|
963 |
|
| 909 |
} |
964 |
} |
|
|
965 |
public void updateParticipant(IPath indexLocation, IPath containerPath) { |
| 966 |
if (this.participantsContainers == null) { |
| 967 |
readParticipantsIndexNamesFile(); |
| 968 |
} |
| 969 |
if (this.participantsContainers.get(indexLocation) == null) { |
| 970 |
this.participantsContainers.put(indexLocation, containerPath); |
| 971 |
this.participantUpdated = true; |
| 972 |
} |
| 973 |
} |
| 910 |
private void writeJavaLikeNamesFile() { |
974 |
private void writeJavaLikeNamesFile() { |
| 911 |
BufferedWriter writer = null; |
975 |
BufferedWriter writer = null; |
| 912 |
String pathName = getJavaPluginWorkingLocation().toOSString(); |
976 |
String pathName = getJavaPluginWorkingLocation().toOSString(); |
|
Lines 941-946
Link Here
|
| 941 |
} |
1005 |
} |
| 942 |
} |
1006 |
} |
| 943 |
} |
1007 |
} |
|
|
1008 |
private void writeParticipantsIndexNamesFile() { |
| 1009 |
BufferedWriter writer = null; |
| 1010 |
try { |
| 1011 |
writer = new BufferedWriter(new FileWriter(this.participantIndexNamesFile)); |
| 1012 |
writer.write(DiskIndex.SIGNATURE); |
| 1013 |
writer.write('\n'); |
| 1014 |
Object[] indexFiles = this.participantsContainers.keyTable; |
| 1015 |
Object[] containers = this.participantsContainers.valueTable; |
| 1016 |
for (int i = 0, l = indexFiles.length; i < l; i++) { |
| 1017 |
IPath indexFile = (IPath)indexFiles[i]; |
| 1018 |
if (indexFile != null) { |
| 1019 |
writer.write(indexFile.toOSString()); |
| 1020 |
writer.write('\n'); |
| 1021 |
writer.write(((IPath)containers[i]).toOSString()); |
| 1022 |
writer.write('\n'); |
| 1023 |
} |
| 1024 |
} |
| 1025 |
} catch (IOException ignored) { |
| 1026 |
if (VERBOSE) |
| 1027 |
Util.verbose("Failed to write participant index file names", System.err); //$NON-NLS-1$ |
| 1028 |
} finally { |
| 1029 |
if (writer != null) { |
| 1030 |
try { |
| 1031 |
writer.close(); |
| 1032 |
} catch (IOException e) { |
| 1033 |
// ignore |
| 1034 |
} |
| 1035 |
} |
| 1036 |
} |
| 1037 |
} |
| 944 |
private void writeSavedIndexNamesFile() { |
1038 |
private void writeSavedIndexNamesFile() { |
| 945 |
BufferedWriter writer = null; |
1039 |
BufferedWriter writer = null; |
| 946 |
try { |
1040 |
try { |