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 53-64
Link Here
|
53 |
// key = indexLocation path, value = index state integer |
54 |
// key = indexLocation path, value = index state integer |
54 |
private SimpleLookupTable indexStates = null; |
55 |
private SimpleLookupTable indexStates = null; |
55 |
private File savedIndexNamesFile = new File(getSavedIndexesDirectory(), "savedIndexNames.txt"); //$NON-NLS-1$ |
56 |
private File savedIndexNamesFile = new File(getSavedIndexesDirectory(), "savedIndexNames.txt"); //$NON-NLS-1$ |
|
|
57 |
private File indexNamesMapFile = new File(getSavedIndexesDirectory(), "indexNamesMap.txt"); //$NON-NLS-1$ |
56 |
private File participantIndexNamesFile = new File(getSavedIndexesDirectory(), "participantsIndexNames.txt"); //$NON-NLS-1$ |
58 |
private File participantIndexNamesFile = new File(getSavedIndexesDirectory(), "participantsIndexNames.txt"); //$NON-NLS-1$ |
57 |
private boolean javaLikeNamesChanged = true; |
59 |
private boolean javaLikeNamesChanged = true; |
58 |
public static final Integer SAVED_STATE = new Integer(0); |
60 |
public static final Integer SAVED_STATE = new Integer(0); |
59 |
public static final Integer UPDATING_STATE = new Integer(1); |
61 |
public static final Integer UPDATING_STATE = new Integer(1); |
60 |
public static final Integer UNKNOWN_STATE = new Integer(2); |
62 |
public static final Integer UNKNOWN_STATE = new Integer(2); |
61 |
public static final Integer REBUILDING_STATE = new Integer(3); |
63 |
public static final Integer REBUILDING_STATE = new Integer(3); |
|
|
64 |
public static final Integer REUSE_STATE = new Integer(4); |
62 |
|
65 |
|
63 |
// search participants who register indexes with the index manager |
66 |
// search participants who register indexes with the index manager |
64 |
private SimpleLookupTable participantsContainers = null; |
67 |
private SimpleLookupTable participantsContainers = null; |
Lines 255-260
Link Here
|
255 |
return index; |
258 |
return index; |
256 |
} catch (IOException e) { |
259 |
} catch (IOException e) { |
257 |
// failed to read the existing file or its no longer compatible |
260 |
// failed to read the existing file or its no longer compatible |
|
|
261 |
if (currentIndexState == REUSE_STATE) { |
262 |
// supposed to be in reuse state but error in the index file, so reindex. |
263 |
if (VERBOSE) |
264 |
Util.verbose("-> cannot reuse given index: "+indexLocationString+" path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ |
265 |
this.indexLocations.put(containerPath, null); |
266 |
indexLocation = computeIndexLocation(containerPath); |
267 |
rebuildIndex(indexLocation, containerPath); |
268 |
return null; |
269 |
} |
258 |
if (currentIndexState != REBUILDING_STATE) { // rebuild index if existing file is corrupt, unless the index is already being rebuilt |
270 |
if (currentIndexState != REBUILDING_STATE) { // rebuild index if existing file is corrupt, unless the index is already being rebuilt |
259 |
if (VERBOSE) |
271 |
if (VERBOSE) |
260 |
Util.verbose("-> cannot reuse existing index: "+indexLocationString+" path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ |
272 |
Util.verbose("-> cannot reuse existing index: "+indexLocationString+" path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ |
Lines 268-273
Link Here
|
268 |
rebuildIndex(indexLocation, containerPath); |
280 |
rebuildIndex(indexLocation, containerPath); |
269 |
return null; |
281 |
return null; |
270 |
} |
282 |
} |
|
|
283 |
//TODO SATYAM: should do something if in reuse state |
271 |
} |
284 |
} |
272 |
// index wasn't found on disk, consider creating an empty new one |
285 |
// index wasn't found on disk, consider creating an empty new one |
273 |
if (createIfMissing) { |
286 |
if (createIfMissing) { |
Lines 315-321
Link Here
|
315 |
IPath containerPath = (IPath) this.indexLocations.keyForValue(indexLocation); |
328 |
IPath containerPath = (IPath) this.indexLocations.keyForValue(indexLocation); |
316 |
if (containerPath != null) {// sanity check |
329 |
if (containerPath != null) {// sanity check |
317 |
index = getIndex(containerPath, indexLocation, true /*reuse index file*/, false /*do not create if none*/); |
330 |
index = getIndex(containerPath, indexLocation, true /*reuse index file*/, false /*do not create if none*/); |
318 |
if (index != null && this.javaLikeNamesChanged && !index.isIndexForJar()) { |
331 |
if (index != null && this.javaLikeNamesChanged && !index.isIndexForJar()) { //TODO SATYAM: shouldn't delete the pre-index files |
319 |
// When a change in java like names extension has been detected, all |
332 |
// When a change in java like names extension has been detected, all |
320 |
// non jar files indexes (i.e. containing sources) need to be rebuilt. |
333 |
// non jar files indexes (i.e. containing sources) need to be rebuilt. |
321 |
// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=286379 |
334 |
// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=286379 |
Lines 387-392
Link Here
|
387 |
this.javaLikeNamesChanged = false; |
400 |
this.javaLikeNamesChanged = false; |
388 |
deleteIndexFiles(); |
401 |
deleteIndexFiles(); |
389 |
} |
402 |
} |
|
|
403 |
readIndexMap(indexesDirectoryPath.toOSString()); |
390 |
return this.indexStates; |
404 |
return this.indexStates; |
391 |
} |
405 |
} |
392 |
private IPath getParticipantsContainer(IPath indexLocation) { |
406 |
private IPath getParticipantsContainer(IPath indexLocation) { |
Lines 474-480
Link Here
|
474 |
for (int i = 0; i < entries.length; i++) { |
488 |
for (int i = 0; i < entries.length; i++) { |
475 |
IClasspathEntry entry= entries[i]; |
489 |
IClasspathEntry entry= entries[i]; |
476 |
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) |
490 |
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) |
477 |
indexLibrary(entry.getPath(), project); |
491 |
indexLibrary(entry.getPath(), project, ((ClasspathEntry)entry).getLibraryIndexLocation()); |
478 |
} |
492 |
} |
479 |
} catch(JavaModelException e){ // cannot retrieve classpath info |
493 |
} catch(JavaModelException e){ // cannot retrieve classpath info |
480 |
} |
494 |
} |
Lines 488-503
Link Here
|
488 |
* Trigger addition of a library to an index |
502 |
* Trigger addition of a library to an index |
489 |
* Note: the actual operation is performed in background |
503 |
* Note: the actual operation is performed in background |
490 |
*/ |
504 |
*/ |
491 |
public void indexLibrary(IPath path, IProject requestingProject) { |
505 |
public void indexLibrary(IPath path, IProject requestingProject, URL indexFile) { |
492 |
// requestingProject is no longer used to cancel jobs but leave it here just in case |
506 |
// requestingProject is no longer used to cancel jobs but leave it here just in case |
493 |
if (JavaCore.getPlugin() == null) return; |
507 |
if (JavaCore.getPlugin() == null) return; |
494 |
|
|
|
495 |
Object target = JavaModel.getTarget(path, true); |
496 |
IndexRequest request = null; |
508 |
IndexRequest request = null; |
|
|
509 |
Object target = JavaModel.getTarget(path, true); |
497 |
if (target instanceof IFile) { |
510 |
if (target instanceof IFile) { |
498 |
request = new AddJarFileToIndex((IFile) target, this); |
511 |
request = new AddJarFileToIndex((IFile) target, indexFile, this); |
499 |
} else if (target instanceof File) { |
512 |
} else if (target instanceof File) { |
500 |
request = new AddJarFileToIndex(path, this); |
513 |
request = new AddJarFileToIndex(path, indexFile, this); |
501 |
} else if (target instanceof IContainer) { |
514 |
} else if (target instanceof IContainer) { |
502 |
request = new IndexBinaryFolder((IContainer) target, this); |
515 |
request = new IndexBinaryFolder((IContainer) target, this); |
503 |
} else { |
516 |
} else { |
Lines 508-513
Link Here
|
508 |
if (!isJobWaiting(request)) |
521 |
if (!isJobWaiting(request)) |
509 |
request(request); |
522 |
request(request); |
510 |
} |
523 |
} |
|
|
524 |
|
525 |
synchronized boolean addIndex(IPath containerPath, IPath indexFile) { |
526 |
this.indexStates.put(indexFile, REUSE_STATE); |
527 |
this.indexLocations.put(containerPath, indexFile); |
528 |
Index index = getIndex(containerPath, indexFile, true, false); |
529 |
if (index == null) { |
530 |
this.indexLocations.put(containerPath, null); |
531 |
return false; |
532 |
} |
533 |
writeIndexMapFile(); |
534 |
return true; |
535 |
} |
536 |
|
511 |
/** |
537 |
/** |
512 |
* Index the content of the given source folder. |
538 |
* Index the content of the given source folder. |
513 |
*/ |
539 |
*/ |
Lines 584-592
Link Here
|
584 |
} else if (target instanceof IFolder) { |
610 |
} else if (target instanceof IFolder) { |
585 |
request = new IndexBinaryFolder((IFolder) target, this); |
611 |
request = new IndexBinaryFolder((IFolder) target, this); |
586 |
} else if (target instanceof IFile) { |
612 |
} else if (target instanceof IFile) { |
587 |
request = new AddJarFileToIndex((IFile) target, this); |
613 |
request = new AddJarFileToIndex((IFile) target, null, this); |
588 |
} else if (target instanceof File) { |
614 |
} else if (target instanceof File) { |
589 |
request = new AddJarFileToIndex(containerPath, this); |
615 |
request = new AddJarFileToIndex(containerPath, null, this); |
590 |
} |
616 |
} |
591 |
if (request != null) |
617 |
if (request != null) |
592 |
request(request); |
618 |
request(request); |
Lines 643-649
Link Here
|
643 |
} |
669 |
} |
644 |
if (indexFile == null) |
670 |
if (indexFile == null) |
645 |
indexFile = new File(indexLocation.toOSString()); // index is not cached yet, but still want to delete the file |
671 |
indexFile = new File(indexLocation.toOSString()); // index is not cached yet, but still want to delete the file |
646 |
if (indexFile.exists()) { |
672 |
if (this.indexStates.get(indexLocation) == REUSE_STATE) { |
|
|
673 |
this.indexLocations.put(containerPath, null); |
674 |
} else if (indexFile.exists()) { |
647 |
if (DEBUG) |
675 |
if (DEBUG) |
648 |
Util.verbose("removing index file " + indexFile); //$NON-NLS-1$ |
676 |
Util.verbose("removing index file " + indexFile); //$NON-NLS-1$ |
649 |
indexFile.delete(); |
677 |
indexFile.delete(); |
Lines 673-679
Link Here
|
673 |
locations = new IPath[max]; |
701 |
locations = new IPath[max]; |
674 |
locations[count++] = indexLocation; |
702 |
locations[count++] = indexLocation; |
675 |
File indexFile = index.getIndexFile(); |
703 |
File indexFile = index.getIndexFile(); |
676 |
if (indexFile.exists()) { |
704 |
if (indexFile.exists() && this.indexStates.get(indexLocation) != REUSE_STATE) { |
677 |
if (DEBUG) |
705 |
if (DEBUG) |
678 |
Util.verbose("removing index file " + indexFile); //$NON-NLS-1$ |
706 |
Util.verbose("removing index file " + indexFile); //$NON-NLS-1$ |
679 |
indexFile.delete(); |
707 |
indexFile.delete(); |
Lines 894-899
Link Here
|
894 |
} |
922 |
} |
895 |
return null; |
923 |
return null; |
896 |
} |
924 |
} |
|
|
925 |
|
926 |
private char[][] readIndexMap(String dirOSString) { |
927 |
try { |
928 |
char[] indexMaps = org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(this.indexNamesMapFile, null); |
929 |
if (indexMaps.length > 0) { |
930 |
char[][] names = CharOperation.splitOn('\n', indexMaps); |
931 |
if (names.length >= 3) { |
932 |
// First line is DiskIndex signature + saved plugin working location (see writeSavedIndexNamesFile()) |
933 |
String savedSignature = DiskIndex.SIGNATURE + "+" + dirOSString; //$NON-NLS-1$ //TODO SATYAM Should dirOSString need to be stored |
934 |
if (savedSignature.equals(new String(names[0]))) { |
935 |
for (int i = 1, l = names.length-1 ; i < l ; i+=2) { |
936 |
IPath indexPath = new Path(new String(names[i])); |
937 |
this.indexLocations.put(new Path(new String(names[i+1])), indexPath ); |
938 |
this.indexStates.put(indexPath, REUSE_STATE); |
939 |
//TODO SATYAM: Is this good enough |
940 |
} |
941 |
} |
942 |
|
943 |
} |
944 |
} |
945 |
} catch (IOException ignored) { |
946 |
if (VERBOSE) |
947 |
Util.verbose("Failed to read saved index file names"); //$NON-NLS-1$ |
948 |
} |
949 |
return null; |
950 |
} |
897 |
private void readParticipantsIndexNamesFile() { |
951 |
private void readParticipantsIndexNamesFile() { |
898 |
SimpleLookupTable containers = new SimpleLookupTable(3); |
952 |
SimpleLookupTable containers = new SimpleLookupTable(3); |
899 |
try { |
953 |
try { |
Lines 947-952
Link Here
|
947 |
} |
1001 |
} |
948 |
|
1002 |
|
949 |
writeSavedIndexNamesFile(); |
1003 |
writeSavedIndexNamesFile(); |
|
|
1004 |
writeIndexMapFile(); |
950 |
|
1005 |
|
951 |
if (VERBOSE) { |
1006 |
if (VERBOSE) { |
952 |
if (indexState == null) { |
1007 |
if (indexState == null) { |
Lines 1065-1068
Link Here
|
1065 |
} |
1120 |
} |
1066 |
} |
1121 |
} |
1067 |
} |
1122 |
} |
|
|
1123 |
|
1124 |
private void writeIndexMapFile() { |
1125 |
BufferedWriter writer = null; |
1126 |
try { |
1127 |
writer = new BufferedWriter(new FileWriter(this.indexNamesMapFile)); |
1128 |
writer.write(DiskIndex.SIGNATURE); |
1129 |
writer.write('+'); |
1130 |
writer.write(getJavaPluginWorkingLocation().toOSString()); |
1131 |
writer.write('\n'); |
1132 |
Object[] keys = this.indexStates.keyTable; |
1133 |
Object[] states = this.indexStates.valueTable; |
1134 |
for (int i = 0, l = states.length; i < l; i++) { |
1135 |
IPath key = (IPath) keys[i]; |
1136 |
if (key != null && !key.isEmpty() && states[i] == REUSE_STATE) { |
1137 |
IPath value = (IPath)this.indexLocations.keyForValue(key); |
1138 |
if (value != null) { |
1139 |
writer.write(key.toOSString()); |
1140 |
writer.write('\n'); |
1141 |
writer.write(value.toOSString()); |
1142 |
writer.write('\n'); |
1143 |
} |
1144 |
} |
1145 |
} |
1146 |
} catch (IOException ignored) { |
1147 |
if (VERBOSE) |
1148 |
Util.verbose("Failed to write saved index file names", System.err); //$NON-NLS-1$ |
1149 |
} finally { |
1150 |
if (writer != null) { |
1151 |
try { |
1152 |
writer.close(); |
1153 |
} catch (IOException e) { |
1154 |
// ignore |
1155 |
} |
1156 |
} |
1157 |
} |
1158 |
} |
1068 |
} |
1159 |
} |