|
Lines 58-63
Link Here
|
| 58 |
public static final Integer UPDATING_STATE = new Integer(1); |
58 |
public static final Integer UPDATING_STATE = new Integer(1); |
| 59 |
public static final Integer UNKNOWN_STATE = new Integer(2); |
59 |
public static final Integer UNKNOWN_STATE = new Integer(2); |
| 60 |
public static final Integer REBUILDING_STATE = new Integer(3); |
60 |
public static final Integer REBUILDING_STATE = new Integer(3); |
|
|
61 |
|
| 62 |
// search participants who register indexes with the index manager |
| 63 |
private SimpleLookupTable participantsContainers = null; |
| 64 |
private boolean participantUpdated = false; |
| 65 |
private static final String PARTICIPANTS_INDEX_NAMES = "participantsIndexNames.txt"; //$NON-NLS-1$ |
| 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 |
if (this.participantsContainers == null) return null; |
| 396 |
} |
| 397 |
return (IPath)this.participantsContainers.get(indexLocation); |
| 398 |
} |
| 373 |
private IPath getJavaPluginWorkingLocation() { |
399 |
private IPath getJavaPluginWorkingLocation() { |
| 374 |
if (this.javaPluginLocation != null) return this.javaPluginLocation; |
400 |
if (this.javaPluginLocation != null) return this.javaPluginLocation; |
| 375 |
|
401 |
|
|
Lines 662-667
Link Here
|
| 662 |
this.indexes.removeKey(locations[i]); |
688 |
this.indexes.removeKey(locations[i]); |
| 663 |
removeIndexesState(locations); |
689 |
removeIndexesState(locations); |
| 664 |
} |
690 |
} |
|
|
691 |
if (this.participantsContainers != null && this.participantsContainers.get(path.toOSString()) != null) { |
| 692 |
this.participantsContainers.removeKey(path.toOSString()); |
| 693 |
} |
| 665 |
} |
694 |
} |
| 666 |
/** |
695 |
/** |
| 667 |
* Removes all indexes whose paths start with (or are equal to) the given path. |
696 |
* Removes all indexes whose paths start with (or are equal to) the given path. |
|
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 |
try { |
| 899 |
File participantsIndexNamesFile = new File(getSavedIndexesDirectory(), PARTICIPANTS_INDEX_NAMES); |
| 900 |
char[] savedIndexNames = org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(participantsIndexNamesFile, null); |
| 901 |
if (savedIndexNames.length > 0) { |
| 902 |
char[][] names = CharOperation.splitOn('\n', savedIndexNames); |
| 903 |
if (names.length >= 3) { |
| 904 |
// First line is DiskIndex signature (see writeParticipantsIndexNamesFile()) |
| 905 |
String savedSignature = DiskIndex.SIGNATURE; |
| 906 |
if (savedSignature.equals(new String(names[0]))) { |
| 907 |
SimpleLookupTable containers = new SimpleLookupTable(3); |
| 908 |
for (int i = 1, l = names.length-1 ; i < l ; i+=2) { |
| 909 |
containers.put(new Path(new String(names[i])), new Path(new String(names[i+1]))); |
| 910 |
} |
| 911 |
this.participantsContainers = containers; |
| 912 |
} |
| 913 |
} |
| 914 |
} |
| 915 |
} catch (IOException ignored) { |
| 916 |
if (VERBOSE) |
| 917 |
Util.verbose("Failed to read saved index file names"); //$NON-NLS-1$ |
| 918 |
} |
| 919 |
return; |
| 920 |
} |
| 864 |
private synchronized void removeIndexesState(IPath[] locations) { |
921 |
private synchronized void removeIndexesState(IPath[] locations) { |
| 865 |
getIndexStates(); // ensure the states are initialized |
922 |
getIndexStates(); // ensure the states are initialized |
| 866 |
int length = locations.length; |
923 |
int length = locations.length; |
|
Lines 907-912
Link Here
|
| 907 |
} |
964 |
} |
| 908 |
|
965 |
|
| 909 |
} |
966 |
} |
|
|
967 |
public void updateParticipant(IPath indexLocation, IPath containerPath) { |
| 968 |
if (this.participantsContainers == null) { |
| 969 |
readParticipantsIndexNamesFile(); |
| 970 |
if (this.participantsContainers == null) |
| 971 |
this.participantsContainers = new SimpleLookupTable(3); |
| 972 |
} |
| 973 |
if (this.participantsContainers.get(indexLocation) == null) { |
| 974 |
this.participantsContainers.put(indexLocation, containerPath); |
| 975 |
this.participantUpdated = true; |
| 976 |
} |
| 977 |
} |
| 910 |
private void writeJavaLikeNamesFile() { |
978 |
private void writeJavaLikeNamesFile() { |
| 911 |
BufferedWriter writer = null; |
979 |
BufferedWriter writer = null; |
| 912 |
String pathName = getJavaPluginWorkingLocation().toOSString(); |
980 |
String pathName = getJavaPluginWorkingLocation().toOSString(); |
|
Lines 941-946
Link Here
|
| 941 |
} |
1009 |
} |
| 942 |
} |
1010 |
} |
| 943 |
} |
1011 |
} |
|
|
1012 |
private void writeParticipantsIndexNamesFile() { |
| 1013 |
BufferedWriter writer = null; |
| 1014 |
try { |
| 1015 |
File participantsIndexNamesFile = new File(getSavedIndexesDirectory(), PARTICIPANTS_INDEX_NAMES); |
| 1016 |
writer = new BufferedWriter(new FileWriter(participantsIndexNamesFile)); |
| 1017 |
writer.write(DiskIndex.SIGNATURE); |
| 1018 |
writer.write('\n'); |
| 1019 |
Object[] indexFiles = this.participantsContainers.keyTable; |
| 1020 |
Object[] containers = this.participantsContainers.valueTable; |
| 1021 |
for (int i = 0, l = indexFiles.length; i < l; i++) { |
| 1022 |
IPath indexFile = (IPath)indexFiles[i]; |
| 1023 |
if (indexFile != null) { |
| 1024 |
writer.write(indexFile.toOSString()); |
| 1025 |
writer.write('\n'); |
| 1026 |
writer.write(((IPath)containers[i]).toOSString()); |
| 1027 |
writer.write('\n'); |
| 1028 |
} |
| 1029 |
} |
| 1030 |
} catch (IOException ignored) { |
| 1031 |
if (VERBOSE) |
| 1032 |
Util.verbose("Failed to write participant index file names", System.err); //$NON-NLS-1$ |
| 1033 |
} finally { |
| 1034 |
if (writer != null) { |
| 1035 |
try { |
| 1036 |
writer.close(); |
| 1037 |
} catch (IOException e) { |
| 1038 |
// ignore |
| 1039 |
} |
| 1040 |
} |
| 1041 |
} |
| 1042 |
} |
| 944 |
private void writeSavedIndexNamesFile() { |
1043 |
private void writeSavedIndexNamesFile() { |
| 945 |
BufferedWriter writer = null; |
1044 |
BufferedWriter writer = null; |
| 946 |
try { |
1045 |
try { |