View | Details | Raw Unified | Return to bug 395897 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java (-1 / +1 lines)
Lines 998-1004 Link Here
998
									// first remove the index so that it is forced to be re-indexed
998
									// first remove the index so that it is forced to be re-indexed
999
									this.manager.indexManager.removeIndex(entryPath);
999
									this.manager.indexManager.removeIndex(entryPath);
1000
									// then index the jar
1000
									// then index the jar
1001
									this.manager.indexManager.indexLibrary(entryPath, project.getProject(), ((ClasspathEntry)entries[j]).getLibraryIndexLocation());
1001
									this.manager.indexManager.indexLibrary(entryPath, project.getProject(), ((ClasspathEntry)entries[j]).getLibraryIndexLocation(), true);
1002
								} else {
1002
								} else {
1003
									URL indexLocation = ((ClasspathEntry)entries[j]).getLibraryIndexLocation();
1003
									URL indexLocation = ((ClasspathEntry)entries[j]).getLibraryIndexLocation();
1004
									if (indexLocation != null) { // force reindexing, this could be faster rather than maintaining the list
1004
									if (indexLocation != null) { // force reindexing, this could be faster rather than maintaining the list
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java (-149 / +214 lines)
Lines 44-59 Link Here
44
	IFile resource;
44
	IFile resource;
45
	Scanner scanner;
45
	Scanner scanner;
46
	private IndexLocation indexFileURL;
46
	private IndexLocation indexFileURL;
47
47
	private final boolean updateIndexIfNecessary;
48
	
48
	public AddJarFileToIndex(IFile resource, IndexLocation indexFile, IndexManager manager) {
49
	public AddJarFileToIndex(IFile resource, IndexLocation indexFile, IndexManager manager) {
50
51
		this(resource, indexFile, manager, false);
52
	}
53
	
54
	public AddJarFileToIndex(IPath jarPath, IndexLocation indexFile, IndexManager manager) {
55
56
		this(jarPath, indexFile, manager, false);
57
	}
58
	
59
	public AddJarFileToIndex(IFile resource, IndexLocation indexFile, IndexManager manager, final boolean updateIndex) {
60
49
		super(resource.getFullPath(), manager);
61
		super(resource.getFullPath(), manager);
50
		this.resource = resource;
62
		this.resource = resource;
51
		this.indexFileURL = indexFile;
63
		this.indexFileURL = indexFile;
64
		this.updateIndexIfNecessary = updateIndex;
52
	}
65
	}
53
	public AddJarFileToIndex(IPath jarPath, IndexLocation indexFile, IndexManager manager) {
66
	public AddJarFileToIndex(IPath jarPath, IndexLocation indexFile, IndexManager manager, final boolean updateIndex) {
67
54
		// external JAR scenario - no resource
68
		// external JAR scenario - no resource
55
		super(jarPath, manager);
69
		super(jarPath, manager);
56
		this.indexFileURL = indexFile;
70
		this.indexFileURL = indexFile;
71
		this.updateIndexIfNecessary = updateIndex;
57
	}
72
	}
58
	public boolean equals(Object o) {
73
	public boolean equals(Object o) {
59
		if (o instanceof AddJarFileToIndex) {
74
		if (o instanceof AddJarFileToIndex) {
Lines 76-86 Link Here
76
		if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true;
91
		if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true;
77
92
78
		if (this.indexFileURL != null) {
93
		if (this.indexFileURL != null) {
79
			boolean added = this.manager.addIndex(this.containerPath, this.indexFileURL);
94
			try {
80
			if (added) return true;	
95
				boolean added = this.createOrUpdatePreBuiltIndex(progressMonitor);
81
			this.indexFileURL = null;
96
				if(added) return true;
97
				this.indexFileURL = null;
98
			}
99
			catch (IOException e) {
100
				if (JobManager.VERBOSE) {
101
					org.eclipse.jdt.internal.core.util.Util.verbose("-> failed to index " + this.containerPath + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
102
					e.printStackTrace();
103
				}
104
				this.manager.removeIndex(this.containerPath);
105
			}
82
		}
106
		}
83
107
		
108
		boolean result = false;
84
		try {
109
		try {
85
			// if index is already cached, then do not perform any check
110
			// if index is already cached, then do not perform any check
86
			// MUST reset the IndexManager if a jar file is changed
111
			// MUST reset the IndexManager if a jar file is changed
Lines 97-258 Link Here
97
					org.eclipse.jdt.internal.core.util.Util.verbose("-> index could not be created for " + this.containerPath); //$NON-NLS-1$
122
					org.eclipse.jdt.internal.core.util.Util.verbose("-> index could not be created for " + this.containerPath); //$NON-NLS-1$
98
				return true;
123
				return true;
99
			}
124
			}
100
			ReadWriteMonitor monitor = index.monitor;
125
			result = this.populateIndex(index, progressMonitor);
101
			if (monitor == null) {
102
				if (JobManager.VERBOSE)
103
					org.eclipse.jdt.internal.core.util.Util.verbose("-> index for " + this.containerPath + " just got deleted"); //$NON-NLS-1$//$NON-NLS-2$
104
				return true; // index got deleted since acquired
105
			}
106
			index.separator = JAR_SEPARATOR;
107
			ZipFile zip = null;
108
			try {
109
				// this path will be a relative path to the workspace in case the zipfile in the workspace otherwise it will be a path in the
110
				// local file system
111
				Path zipFilePath = null;
112
113
				monitor.enterWrite(); // ask permission to write
114
				if (this.resource != null) {
115
					URI location = this.resource.getLocationURI();
116
					if (location == null) return false;
117
					if (JavaModelManager.ZIP_ACCESS_VERBOSE)
118
						System.out.println("(" + Thread.currentThread() + ") [AddJarFileToIndex.execute()] Creating ZipFile on " + location.getPath()); //$NON-NLS-1$	//$NON-NLS-2$
119
					File file = null;
120
					try {
121
						file = org.eclipse.jdt.internal.core.util.Util.toLocalFile(location, progressMonitor);
122
					} catch (CoreException e) {
123
						if (JobManager.VERBOSE) {
124
							org.eclipse.jdt.internal.core.util.Util.verbose("-> failed to index " + location.getPath() + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
125
							e.printStackTrace();
126
						}
127
					}
128
					if (file == null) {
129
						if (JobManager.VERBOSE)
130
							org.eclipse.jdt.internal.core.util.Util.verbose("-> failed to index " + location.getPath() + " because the file could not be fetched"); //$NON-NLS-1$ //$NON-NLS-2$
131
						return false;
132
					}
133
					zip = new ZipFile(file);
134
					zipFilePath = (Path) this.resource.getFullPath().makeRelative();
135
					// absolute path relative to the workspace
136
				} else {
137
					if (JavaModelManager.ZIP_ACCESS_VERBOSE)
138
						System.out.println("(" + Thread.currentThread() + ") [AddJarFileToIndex.execute()] Creating ZipFile on " + this.containerPath); //$NON-NLS-1$	//$NON-NLS-2$
139
					// external file -> it is ok to use toFile()
140
					zip = new ZipFile(this.containerPath.toFile());
141
					zipFilePath = (Path) this.containerPath;
142
					// path is already canonical since coming from a library classpath entry
143
				}
144
145
				if (this.isCancelled) {
146
					if (JobManager.VERBOSE)
147
						org.eclipse.jdt.internal.core.util.Util.verbose("-> indexing of " + zip.getName() + " has been cancelled"); //$NON-NLS-1$ //$NON-NLS-2$
148
					return false;
149
				}
150
151
				if (JobManager.VERBOSE)
152
					org.eclipse.jdt.internal.core.util.Util.verbose("-> indexing " + zip.getName()); //$NON-NLS-1$
153
				long initialTime = System.currentTimeMillis();
154
155
				String[] paths = index.queryDocumentNames(""); // all file names //$NON-NLS-1$
156
				if (paths != null) {
157
					int max = paths.length;
158
					/* check integrity of the existing index file
159
					 * if the length is equal to 0, we want to index the whole jar again
160
					 * If not, then we want to check that there is no missing entry, if
161
					 * one entry is missing then we recreate the index
162
					 */
163
					String EXISTS = "OK"; //$NON-NLS-1$
164
					String DELETED = "DELETED"; //$NON-NLS-1$
165
					SimpleLookupTable indexedFileNames = new SimpleLookupTable(max == 0 ? 33 : max + 11);
166
					for (int i = 0; i < max; i++)
167
						indexedFileNames.put(paths[i], DELETED);
168
					for (Enumeration e = zip.entries(); e.hasMoreElements();) {
169
						// iterate each entry to index it
170
						ZipEntry ze = (ZipEntry) e.nextElement();
171
						String zipEntryName = ze.getName();
172
						if (Util.isClassFileName(zipEntryName) && isValidPackageNameForClass(zipEntryName))
173
								// the class file may not be there if the package name is not valid
174
							indexedFileNames.put(zipEntryName, EXISTS);
175
					}
176
					boolean needToReindex = indexedFileNames.elementSize != max; // a new file was added
177
					if (!needToReindex) {
178
						Object[] valueTable = indexedFileNames.valueTable;
179
						for (int i = 0, l = valueTable.length; i < l; i++) {
180
							if (valueTable[i] == DELETED) {
181
								needToReindex = true; // a file was deleted so re-index
182
								break;
183
							}
184
						}
185
						if (!needToReindex) {
186
							if (JobManager.VERBOSE)
187
								org.eclipse.jdt.internal.core.util.Util.verbose("-> no indexing required (index is consistent with library) for " //$NON-NLS-1$
188
								+ zip.getName() + " (" //$NON-NLS-1$
189
								+ (System.currentTimeMillis() - initialTime) + "ms)"); //$NON-NLS-1$
190
							this.manager.saveIndex(index); // to ensure its placed into the saved state
191
							return true;
192
						}
193
					}
194
				}
195
196
				// Index the jar for the first time or reindex the jar in case the previous index file has been corrupted
197
				// index already existed: recreate it so that we forget about previous entries
198
				SearchParticipant participant = SearchEngine.getDefaultSearchParticipant();
199
				if (!this.manager.resetIndex(this.containerPath)) {
200
					// failed to recreate index, see 73330
201
					this.manager.removeIndex(this.containerPath);
202
					return false;
203
				}
204
				index.separator = JAR_SEPARATOR;
205
				IPath indexPath = null;
206
				IndexLocation indexLocation;
207
				if ((indexLocation = index.getIndexLocation()) != null) {
208
					indexPath = new Path(indexLocation.getCanonicalFilePath());
209
				}
210
				for (Enumeration e = zip.entries(); e.hasMoreElements();) {
211
					if (this.isCancelled) {
212
						if (JobManager.VERBOSE)
213
							org.eclipse.jdt.internal.core.util.Util.verbose("-> indexing of " + zip.getName() + " has been cancelled"); //$NON-NLS-1$ //$NON-NLS-2$
214
						return false;
215
					}
216
217
					// iterate each entry to index it
218
					ZipEntry ze = (ZipEntry) e.nextElement();
219
					String zipEntryName = ze.getName();
220
					if (Util.isClassFileName(zipEntryName) && 
221
							isValidPackageNameForClass(zipEntryName)) {
222
						// index only classes coming from valid packages - https://bugs.eclipse.org/bugs/show_bug.cgi?id=293861
223
						final byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip);
224
						JavaSearchDocument entryDocument = new JavaSearchDocument(ze, zipFilePath, classFileBytes, participant);
225
						this.manager.indexDocument(entryDocument, participant, index, indexPath);
226
					}
227
				}
228
				this.manager.saveIndex(index);
229
				if (JobManager.VERBOSE)
230
					org.eclipse.jdt.internal.core.util.Util.verbose("-> done indexing of " //$NON-NLS-1$
231
						+ zip.getName() + " (" //$NON-NLS-1$
232
						+ (System.currentTimeMillis() - initialTime) + "ms)"); //$NON-NLS-1$
233
			} finally {
234
				if (zip != null) {
235
					if (JavaModelManager.ZIP_ACCESS_VERBOSE)
236
						System.out.println("(" + Thread.currentThread() + ") [AddJarFileToIndex.execute()] Closing ZipFile " + zip); //$NON-NLS-1$	//$NON-NLS-2$
237
					zip.close();
238
				}
239
				monitor.exitWrite(); // free write lock
240
			}
241
		} catch (IOException e) {
126
		} catch (IOException e) {
242
			if (JobManager.VERBOSE) {
127
			if (JobManager.VERBOSE) {
243
				org.eclipse.jdt.internal.core.util.Util.verbose("-> failed to index " + this.containerPath + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
128
				org.eclipse.jdt.internal.core.util.Util.verbose("-> failed to index " + this.containerPath + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
244
				e.printStackTrace();
129
				e.printStackTrace();
245
			}
130
			}
246
			this.manager.removeIndex(this.containerPath);
131
			this.manager.removeIndex(this.containerPath);
247
			return false;
248
		}
132
		}
249
		return true;
133
		return result;
250
	}
134
	}
135
251
	public String getJobFamily() {
136
	public String getJobFamily() {
252
		if (this.resource != null)
137
		if (this.resource != null)
253
			return super.getJobFamily();
138
			return super.getJobFamily();
254
		return this.containerPath.toOSString(); // external jar
139
		return this.containerPath.toOSString(); // external jar
255
	}	
140
	}	
141
142
	private boolean createOrUpdatePreBuiltIndex(final IProgressMonitor progressMonitor) throws IOException {
143
		
144
		boolean success = false;
145
		if(this.updateIndexIfNecessary || !this.indexFileURL.getIndexFile().exists()) {
146
			// construct a new index and populate the contents
147
			String containerPathString = this.containerPath.getDevice() == null ? this.containerPath.toString()
148
					: this.containerPath.toOSString();
149
			Index newIndex = null;
150
			try {
151
				newIndex = new Index(this.indexFileURL, containerPathString, false);
152
				this.populateIndex(newIndex, progressMonitor);
153
			} catch (IOException e) {
154
				if (JobManager.VERBOSE) {
155
					org.eclipse.jdt.internal.core.util.Util.verbose("-> failed to create index for " + this.containerPath + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
156
					e.printStackTrace();
157
				}
158
				this.manager.removeIndex(this.containerPath);
159
			}
160
			// add this index to the indexmanager
161
			if(newIndex != null) {
162
				success = this.manager.addIndex(this.containerPath, newIndex);
163
			}
164
		}
165
		else {
166
			// add the index as-is to the manager
167
			success = this.manager.addIndex(this.containerPath, this.indexFileURL);
168
		}
169
		if(!success && JobManager.VERBOSE) {
170
			org.eclipse.jdt.internal.core.util.Util.verbose("-> pre-build index could not be updated for " + this.containerPath); //$NON-NLS-1$
171
		}
172
		return success;
173
	}
174
	
175
	private boolean populateIndex(final Index index, final IProgressMonitor progressMonitor) throws IOException {
176
177
		ReadWriteMonitor monitor = index.monitor;
178
		if (monitor == null) {
179
			if (JobManager.VERBOSE)
180
				org.eclipse.jdt.internal.core.util.Util.verbose("-> index for " + this.containerPath + " just got deleted"); //$NON-NLS-1$//$NON-NLS-2$
181
			return true; // index got deleted since acquired
182
		}
183
		index.separator = JAR_SEPARATOR;
184
		ZipFile zip = null;
185
		try {
186
			// this path will be a relative path to the workspace in case the zipfile in the workspace otherwise it will be a path in the
187
			// local file system
188
			Path zipFilePath = null;
189
190
			monitor.enterWrite(); // ask permission to write
191
			if (this.resource != null) {
192
				URI location = this.resource.getLocationURI();
193
				if (location == null) return false;
194
				if (JavaModelManager.ZIP_ACCESS_VERBOSE)
195
					System.out.println("(" + Thread.currentThread() + ") [AddJarFileToIndex.execute()] Creating ZipFile on " + location.getPath()); //$NON-NLS-1$	//$NON-NLS-2$
196
				File file = null;
197
				try {
198
					file = org.eclipse.jdt.internal.core.util.Util.toLocalFile(location, progressMonitor);
199
				} catch (CoreException e) {
200
					if (JobManager.VERBOSE) {
201
						org.eclipse.jdt.internal.core.util.Util.verbose("-> failed to index " + location.getPath() + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
202
						e.printStackTrace();
203
					}
204
				}
205
				if (file == null) {
206
					if (JobManager.VERBOSE)
207
						org.eclipse.jdt.internal.core.util.Util.verbose("-> failed to index " + location.getPath() + " because the file could not be fetched"); //$NON-NLS-1$ //$NON-NLS-2$
208
					return false;
209
				}
210
				zip = new ZipFile(file);
211
				zipFilePath = (Path) this.resource.getFullPath().makeRelative();
212
				// absolute path relative to the workspace
213
			} else {
214
				if (JavaModelManager.ZIP_ACCESS_VERBOSE)
215
					System.out.println("(" + Thread.currentThread() + ") [AddJarFileToIndex.execute()] Creating ZipFile on " + this.containerPath); //$NON-NLS-1$	//$NON-NLS-2$
216
				// external file -> it is ok to use toFile()
217
				zip = new ZipFile(this.containerPath.toFile());
218
				zipFilePath = (Path) this.containerPath;
219
				// path is already canonical since coming from a library classpath entry
220
			}
221
222
			if (this.isCancelled) {
223
				if (JobManager.VERBOSE)
224
					org.eclipse.jdt.internal.core.util.Util.verbose("-> indexing of " + zip.getName() + " has been cancelled"); //$NON-NLS-1$ //$NON-NLS-2$
225
				return false;
226
			}
227
228
			if (JobManager.VERBOSE)
229
				org.eclipse.jdt.internal.core.util.Util.verbose("-> indexing " + zip.getName()); //$NON-NLS-1$
230
			long initialTime = System.currentTimeMillis();
231
232
			String[] paths = index.queryDocumentNames(""); // all file names //$NON-NLS-1$
233
			if (paths != null) {
234
				int max = paths.length;
235
				/* check integrity of the existing index file
236
				 * if the length is equal to 0, we want to index the whole jar again
237
				 * If not, then we want to check that there is no missing entry, if
238
				 * one entry is missing then we recreate the index
239
				 */
240
				String EXISTS = "OK"; //$NON-NLS-1$
241
				String DELETED = "DELETED"; //$NON-NLS-1$
242
				SimpleLookupTable indexedFileNames = new SimpleLookupTable(max == 0 ? 33 : max + 11);
243
				for (int i = 0; i < max; i++)
244
					indexedFileNames.put(paths[i], DELETED);
245
				for (Enumeration e = zip.entries(); e.hasMoreElements();) {
246
					// iterate each entry to index it
247
					ZipEntry ze = (ZipEntry) e.nextElement();
248
					String zipEntryName = ze.getName();
249
					if (Util.isClassFileName(zipEntryName) && isValidPackageNameForClass(zipEntryName))
250
							// the class file may not be there if the package name is not valid
251
						indexedFileNames.put(zipEntryName, EXISTS);
252
				}
253
				boolean needToReindex = indexedFileNames.elementSize != max; // a new file was added
254
				if (!needToReindex) {
255
					Object[] valueTable = indexedFileNames.valueTable;
256
					for (int i = 0, l = valueTable.length; i < l; i++) {
257
						if (valueTable[i] == DELETED) {
258
							needToReindex = true; // a file was deleted so re-index
259
							break;
260
						}
261
					}
262
					if (!needToReindex) {
263
						if (JobManager.VERBOSE)
264
							org.eclipse.jdt.internal.core.util.Util.verbose("-> no indexing required (index is consistent with library) for " //$NON-NLS-1$
265
							+ zip.getName() + " (" //$NON-NLS-1$
266
							+ (System.currentTimeMillis() - initialTime) + "ms)"); //$NON-NLS-1$
267
						this.manager.saveIndex(index); // to ensure its placed into the saved state
268
						return true;
269
					}
270
				}
271
			}
272
273
			// Index the jar for the first time or reindex the jar in case the previous index file has been corrupted
274
			// index already existed: recreate it so that we forget about previous entries
275
			SearchParticipant participant = SearchEngine.getDefaultSearchParticipant();
276
			if (!this.manager.resetIndex(this.containerPath)) {
277
				// failed to recreate index, see 73330
278
				this.manager.removeIndex(this.containerPath);
279
				return false;
280
			}
281
			index.separator = JAR_SEPARATOR;
282
			IPath indexPath = null;
283
			IndexLocation indexLocation;
284
			if ((indexLocation = index.getIndexLocation()) != null) {
285
				indexPath = new Path(indexLocation.getCanonicalFilePath());
286
			}
287
			for (Enumeration e = zip.entries(); e.hasMoreElements();) {
288
				if (this.isCancelled) {
289
					if (JobManager.VERBOSE)
290
						org.eclipse.jdt.internal.core.util.Util.verbose("-> indexing of " + zip.getName() + " has been cancelled"); //$NON-NLS-1$ //$NON-NLS-2$
291
					return false;
292
				}
293
294
				// iterate each entry to index it
295
				ZipEntry ze = (ZipEntry) e.nextElement();
296
				String zipEntryName = ze.getName();
297
				if (Util.isClassFileName(zipEntryName) && 
298
						isValidPackageNameForClass(zipEntryName)) {
299
					// index only classes coming from valid packages - https://bugs.eclipse.org/bugs/show_bug.cgi?id=293861
300
					final byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip);
301
					JavaSearchDocument entryDocument = new JavaSearchDocument(ze, zipFilePath, classFileBytes, participant);
302
					this.manager.indexDocument(entryDocument, participant, index, indexPath);
303
				}
304
			}
305
			this.manager.saveIndex(index);
306
			if (JobManager.VERBOSE)
307
				org.eclipse.jdt.internal.core.util.Util.verbose("-> done indexing of " //$NON-NLS-1$
308
					+ zip.getName() + " (" //$NON-NLS-1$
309
					+ (System.currentTimeMillis() - initialTime) + "ms)"); //$NON-NLS-1$
310
		} finally {
311
			if (zip != null) {
312
				if (JavaModelManager.ZIP_ACCESS_VERBOSE)
313
					System.out.println("(" + Thread.currentThread() + ") [AddJarFileToIndex.execute()] Closing ZipFile " + zip); //$NON-NLS-1$	//$NON-NLS-2$
314
				zip.close();
315
			}
316
			monitor.exitWrite(); // free write lock
317
		}
318
		return true;
319
	}
320
	
256
	private boolean isIdentifier() throws InvalidInputException {
321
	private boolean isIdentifier() throws InvalidInputException {
257
		switch(this.scanner.scanIdentifier()) {
322
		switch(this.scanner.scanIdentifier()) {
258
			// assert and enum will not be recognized as java identifiers 
323
			// assert and enum will not be recognized as java identifiers 
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java (-2 / +37 lines)
Lines 70-75 Link Here
70
	// Debug
70
	// Debug
71
	public static boolean DEBUG = false;
71
	public static boolean DEBUG = false;
72
72
73
	private Boolean updateProductIndexes = null;
74
75
	public synchronized boolean updateProductIndexes() {
76
77
		if (this.updateProductIndexes == null) {
78
			boolean manageIndexPropertyValue = Boolean.getBoolean("JDT_UPDATE_PRODUCT_INDEXES"); //$NON-NLS-1$
79
			this.updateProductIndexes = Boolean.valueOf(manageIndexPropertyValue);
80
		}
81
		return this.updateProductIndexes.booleanValue();
82
	}
83
	
73
	public synchronized void aboutToUpdateIndex(IPath containerPath, Integer newIndexState) {
84
	public synchronized void aboutToUpdateIndex(IPath containerPath, Integer newIndexState) {
74
	// newIndexState is either UPDATING_STATE or REBUILDING_STATE
85
	// 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
86
	// must tag the index as inconsistent, in case we exit before the update job is started
Lines 493-512 Link Here
493
	if (!isJobWaiting(request))
504
	if (!isJobWaiting(request))
494
		request(request);
505
		request(request);
495
}
506
}
507
496
/**
508
/**
497
 * Trigger addition of a library to an index
509
 * Trigger addition of a library to an index
498
 * Note: the actual operation is performed in background
510
 * Note: the actual operation is performed in background
499
 */
511
 */
500
public void indexLibrary(IPath path, IProject requestingProject, URL indexURL) {
512
public void indexLibrary(IPath path, IProject requestingProject, URL indexURL) {
513
514
	this.indexLibrary(path, requestingProject, indexURL, false);
515
}
516
	
517
/**
518
 * Trigger addition of a library to an index
519
 * Note: the actual operation is performed in background
520
 */
521
public void indexLibrary(IPath path, IProject requestingProject, URL indexURL, final boolean forceUpdate) {
501
	// requestingProject is no longer used to cancel jobs but leave it here just in case
522
	// requestingProject is no longer used to cancel jobs but leave it here just in case
502
	IndexLocation indexFile = indexURL != null ? IndexLocation.createIndexLocation(indexURL): null;
523
	IndexLocation indexFile = indexURL != null ? IndexLocation.createIndexLocation(indexURL): null;
503
	if (JavaCore.getPlugin() == null) return;
524
	if (JavaCore.getPlugin() == null) return;
504
	IndexRequest request = null;
525
	IndexRequest request = null;
505
	Object target = JavaModel.getTarget(path, true);
526
	Object target = JavaModel.getTarget(path, true);
527
	// bug395897: work-around to enable any pre-built indexes to be regenerated
528
	boolean updateIndex = this.updateProductIndexes() && forceUpdate;
506
	if (target instanceof IFile) {
529
	if (target instanceof IFile) {
507
		request = new AddJarFileToIndex((IFile) target, indexFile, this);
530
		request = new AddJarFileToIndex((IFile) target, indexFile, this, updateIndex);
508
	} else if (target instanceof File) {
531
	} else if (target instanceof File) {
509
		request = new AddJarFileToIndex(path, indexFile, this);
532
		request = new AddJarFileToIndex(path, indexFile, this, updateIndex);
510
	} else if (target instanceof IContainer) {
533
	} else if (target instanceof IContainer) {
511
		request = new IndexBinaryFolder((IContainer) target, this);
534
		request = new IndexBinaryFolder((IContainer) target, this);
512
	} else {
535
	} else {
Lines 518-523 Link Here
518
		request(request);
541
		request(request);
519
}
542
}
520
543
544
synchronized boolean addIndex(final IPath containerPath, final Index index) {
545
546
	boolean result = false;
547
	if((index != null) && (containerPath != null)) {
548
		getIndexStates().put(index.getIndexLocation(), REUSE_STATE);
549
		this.indexLocations.put(containerPath, index.getIndexLocation());
550
		result = true;
551
	}
552
	writeIndexMapFile();
553
	return result;
554
}
555
521
synchronized boolean addIndex(IPath containerPath, IndexLocation indexFile) {
556
synchronized boolean addIndex(IPath containerPath, IndexLocation indexFile) {
522
	getIndexStates().put(indexFile, REUSE_STATE);
557
	getIndexStates().put(indexFile, REUSE_STATE);
523
	this.indexLocations.put(containerPath, indexFile);
558
	this.indexLocations.put(containerPath, indexFile);

Return to bug 395897