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/core/JavaCore.java (-1 / +13 lines)
Lines 2249-2255 Link Here
2249
	 * @category CoreOptionID
2249
	 * @category CoreOptionID
2250
	 */
2250
	 */
2251
	public static final String TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC = PLUGIN_ID + ".timeoutForParameterNameFromAttachedJavadoc"; //$NON-NLS-1$
2251
	public static final String TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC = PLUGIN_ID + ".timeoutForParameterNameFromAttachedJavadoc"; //$NON-NLS-1$
2252
2252
	/**
2253
	 * Core option ID: The indexer will manage (update or delete) pre-built indexes
2254
	 * <p>When enabled, the indexer will manage any pre-built index files</p>
2255
	 * <dl>
2256
	 * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.index.manageProductIndexes"</code></dd>
2257
	 * <dt>Possible values:</dt><dd><code>{ "enabled", "disabled" }</code></dd>
2258
	 * <dt>Default:</dt><dd><code>"disabled"</code></dd>
2259
	 * </dl>
2260
	 * @since 3.9
2261
	 * @category CoreOptionID
2262
	 */
2263
	public static final String MANAGE_PREBUILT_INDEXES = PLUGIN_ID + ".index.manageProductIndexes"; //$NON-NLS-1$
2264
	
2253
	/**
2265
	/**
2254
	 * @since 2.0
2266
	 * @since 2.0
2255
	 * @deprecated Use {@link org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants#FORMATTER_BRACE_POSITION_FOR_ANONYMOUS_TYPE_DECLARATION},
2267
	 * @deprecated Use {@link org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants#FORMATTER_BRACE_POSITION_FOR_ANONYMOUS_TYPE_DECLARATION},
(-)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/model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java (-1 / +3 lines)
Lines 94-100 Link Here
94
94
95
		// Time out for parameter names
95
		// Time out for parameter names
96
		defaultOptionsMap.put(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC, "50"); //$NON-NLS-1$
96
		defaultOptionsMap.put(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC, "50"); //$NON-NLS-1$
97
97
		// update product index (default: disabled)
98
		defaultOptionsMap.put(JavaCore.MANAGE_PREBUILT_INDEXES, JavaCore.DISABLED);
99
		
98
		// Store default values to default preferences
100
		// Store default values to default preferences
99
	 	IEclipsePreferences defaultPreferences = DefaultScope.INSTANCE.getNode(JavaCore.PLUGIN_ID);
101
	 	IEclipsePreferences defaultPreferences = DefaultScope.INSTANCE.getNode(JavaCore.PLUGIN_ID);
100
		for (Iterator iter = defaultOptionsMap.entrySet().iterator(); iter.hasNext();) {
102
		for (Iterator iter = defaultOptionsMap.entrySet().iterator(); iter.hasNext();) {
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java (-1 / +3 lines)
Lines 2255-2261 Link Here
2255
2255
2256
		// Time out for parameter names
2256
		// Time out for parameter names
2257
		defaultOptionsMap.put(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC, "50"); //$NON-NLS-1$
2257
		defaultOptionsMap.put(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC, "50"); //$NON-NLS-1$
2258
2258
		// update product index (default: disabled)
2259
		defaultOptionsMap.put(JavaCore.MANAGE_PREBUILT_INDEXES, JavaCore.DISABLED);
2260
		
2259
		return new Hashtable(defaultOptionsMap);
2261
		return new Hashtable(defaultOptionsMap);
2260
	}
2262
	}
2261
2263
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java (-4 / +27 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 forceIndexUpdate;
48
	
48
	public AddJarFileToIndex(IFile resource, IndexLocation indexFile, IndexManager manager) {
49
	public AddJarFileToIndex(IFile resource, IndexLocation indexFile, IndexManager manager) {
50
		this(resource, indexFile, manager, false);
51
	}
52
	public AddJarFileToIndex(IFile resource, IndexLocation indexFile, IndexManager manager, final boolean updateIndex) {
49
		super(resource.getFullPath(), manager);
53
		super(resource.getFullPath(), manager);
50
		this.resource = resource;
54
		this.resource = resource;
51
		this.indexFileURL = indexFile;
55
		this.indexFileURL = indexFile;
56
		this.forceIndexUpdate = updateIndex;
52
	}
57
	}
53
	public AddJarFileToIndex(IPath jarPath, IndexLocation indexFile, IndexManager manager) {
58
	public AddJarFileToIndex(IPath jarPath, IndexLocation indexFile, IndexManager manager) {
59
		this(jarPath, indexFile, manager, false);
60
	}
61
	public AddJarFileToIndex(IPath jarPath, IndexLocation indexFile, IndexManager manager, final boolean updateIndex) {
54
		// external JAR scenario - no resource
62
		// external JAR scenario - no resource
55
		super(jarPath, manager);
63
		super(jarPath, manager);
56
		this.indexFileURL = indexFile;
64
		this.indexFileURL = indexFile;
65
		this.forceIndexUpdate = updateIndex;
57
	}
66
	}
58
	public boolean equals(Object o) {
67
	public boolean equals(Object o) {
59
		if (o instanceof AddJarFileToIndex) {
68
		if (o instanceof AddJarFileToIndex) {
Lines 75-81 Link Here
75
84
76
		if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true;
85
		if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true;
77
86
78
		if (this.indexFileURL != null) {
87
		if (this.addPreBuiltIndex()) {
79
			boolean added = this.manager.addIndex(this.containerPath, this.indexFileURL);
88
			boolean added = this.manager.addIndex(this.containerPath, this.indexFileURL);
80
			if (added) return true;	
89
			if (added) return true;	
81
			this.indexFileURL = null;
90
			this.indexFileURL = null;
Lines 291-299 Link Here
291
		return false;
300
		return false;
292
	}
301
	}
293
	protected Integer updatedIndexState() {
302
	protected Integer updatedIndexState() {
294
		return IndexManager.REBUILDING_STATE;
303
304
		Integer updateState = null;
305
		if(this.addPreBuiltIndex()) {
306
			updateState = IndexManager.REUSE_STATE;
307
		}
308
		else {
309
			updateState = IndexManager.REBUILDING_STATE;
310
		}
311
		return updateState;
295
	}
312
	}
296
	public String toString() {
313
	public String toString() {
297
		return "indexing " + this.containerPath.toString(); //$NON-NLS-1$
314
		return "indexing " + this.containerPath.toString(); //$NON-NLS-1$
298
	}
315
	}
299
}
316
317
	protected boolean addPreBuiltIndex() {
318
		
319
		boolean addIndex = !this.forceIndexUpdate && ((this.indexFileURL != null) && this.indexFileURL.exists());
320
		return addIndex;
321
	}
322
}
(-)a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java (-13 / +76 lines)
Lines 67-76 Link Here
67
	private SimpleLookupTable participantsContainers = null;
67
	private SimpleLookupTable participantsContainers = null;
68
	private boolean participantUpdated = false;
68
	private boolean participantUpdated = false;
69
69
70
	// should JDT manage (update, delete as needed) pre-built indexes?
71
	private Boolean manageUserIndexes = null;
72
	
70
	// Debug
73
	// Debug
71
	public static boolean DEBUG = false;
74
	public static boolean DEBUG = false;
75
	
76
private boolean isManagingPreBuiltIndexes() {
77
	if (this.manageUserIndexes == null) {
78
			String manageIndexPropertyValue = JavaCore.getOption(JavaCore.MANAGE_PREBUILT_INDEXES);
79
			if (manageIndexPropertyValue != null) {
80
				this.manageUserIndexes = Boolean.valueOf(JavaCore.ENABLED.equals(manageIndexPropertyValue));
81
			} else {
82
				this.manageUserIndexes = Boolean.FALSE;
83
			}
84
		}
85
		return this.manageUserIndexes.booleanValue();
86
	}
72
87
73
	public synchronized void aboutToUpdateIndex(IPath containerPath, Integer newIndexState) {
88
public synchronized void aboutToUpdateIndex(IPath containerPath, Integer newIndexState) {
74
	// newIndexState is either UPDATING_STATE or REBUILDING_STATE
89
	// 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
90
	// must tag the index as inconsistent, in case we exit before the update job is started
76
	IndexLocation indexLocation = computeIndexLocation(containerPath);
91
	IndexLocation indexLocation = computeIndexLocation(containerPath);
Lines 136-141 Link Here
136
			removeIndexesState(locations);
151
			removeIndexesState(locations);
137
	}
152
	}
138
	deleteIndexFiles(knownPaths);
153
	deleteIndexFiles(knownPaths);
154
}
155
/**
156
 * Compute the pre-built index location for a specified URL
157
 */
158
public synchronized IndexLocation computeIndexLocation(IPath containerPath, final URL newIndexURL) {
159
	IndexLocation indexLocation = (IndexLocation) this.indexLocations.get(containerPath);
160
	if (indexLocation == null) {
161
		if(newIndexURL != null) {
162
			indexLocation = IndexLocation.createIndexLocation(newIndexURL);
163
			// update caches
164
			indexLocation = (IndexLocation) getIndexStates().getKey(indexLocation);
165
			this.indexLocations.put(containerPath, indexLocation);
166
		}
167
		else {
168
			indexLocation = this.computeIndexLocation(containerPath);
169
			// cache updating is done in #computeIndexLocation(path)
170
		}
171
	}
172
	else {
173
		// an existing index location exists - make sure it has not changed (i.e. the URL has not changed)
174
		URL existingURL = indexLocation.getUrl();
175
		if (newIndexURL != null) {
176
			// if either URL is different then the index location has been updated so rebuild.
177
			if(!newIndexURL.equals(existingURL)
178
				|| ((existingURL != null) && !existingURL.equals(newIndexURL))) {
179
				// URL has changed so remove the old index and create a new one
180
				this.removeIndex(containerPath);
181
				// create a new one
182
				indexLocation = IndexLocation.createIndexLocation(newIndexURL);
183
				// update caches
184
				indexLocation = (IndexLocation) getIndexStates().getKey(indexLocation);
185
				this.indexLocations.put(containerPath, indexLocation);
186
			}
187
		}
188
	}
189
	return indexLocation;
139
}
190
}
140
public synchronized IndexLocation computeIndexLocation(IPath containerPath) {
191
public synchronized IndexLocation computeIndexLocation(IPath containerPath) {
141
	IndexLocation indexLocation = (IndexLocation) this.indexLocations.get(containerPath);
192
	IndexLocation indexLocation = (IndexLocation) this.indexLocations.get(containerPath);
Lines 493-512 Link Here
493
	if (!isJobWaiting(request))
544
	if (!isJobWaiting(request))
494
		request(request);
545
		request(request);
495
}
546
}
547
public void indexLibrary(IPath path, IProject requestingProject, URL indexURL) {
548
	
549
	this.indexLibrary(path, requestingProject, indexURL, false);
550
}
551
496
/**
552
/**
497
 * Trigger addition of a library to an index
553
 * Trigger addition of a library to an index
498
 * Note: the actual operation is performed in background
554
 * Note: the actual operation is performed in background
499
 */
555
 */
500
public void indexLibrary(IPath path, IProject requestingProject, URL indexURL) {
556
public void indexLibrary(IPath path, IProject requestingProject, URL indexURL, final boolean updateIndex) {
501
	// requestingProject is no longer used to cancel jobs but leave it here just in case
557
	// requestingProject is no longer used to cancel jobs but leave it here just in case
502
	IndexLocation indexFile = indexURL != null ? IndexLocation.createIndexLocation(indexURL): null;
558
	IndexLocation indexFile = computeIndexLocation(path, indexURL);
503
	if (JavaCore.getPlugin() == null) return;
559
	if (JavaCore.getPlugin() == null) return;
504
	IndexRequest request = null;
560
	IndexRequest request = null;
561
	boolean forceIndexUpdate = this.isManagingPreBuiltIndexes() && updateIndex;
505
	Object target = JavaModel.getTarget(path, true);
562
	Object target = JavaModel.getTarget(path, true);
506
	if (target instanceof IFile) {
563
	if (target instanceof IFile) {
507
		request = new AddJarFileToIndex((IFile) target, indexFile, this);
564
		request = new AddJarFileToIndex((IFile) target, indexFile, this, forceIndexUpdate);
508
	} else if (target instanceof File) {
565
	} else if (target instanceof File) {
509
		request = new AddJarFileToIndex(path, indexFile, this);
566
		request = new AddJarFileToIndex(path, indexFile, this, forceIndexUpdate);
510
	} else if (target instanceof IContainer) {
567
	} else if (target instanceof IContainer) {
511
		request = new IndexBinaryFolder((IContainer) target, this);
568
		request = new IndexBinaryFolder((IContainer) target, this);
512
	} else {
569
	} else {
Lines 519-533 Link Here
519
}
576
}
520
577
521
synchronized boolean addIndex(IPath containerPath, IndexLocation indexFile) {
578
synchronized boolean addIndex(IPath containerPath, IndexLocation indexFile) {
522
	getIndexStates().put(indexFile, REUSE_STATE);
579
	// do not re-add a pre-built index if it is already in the index list
523
	this.indexLocations.put(containerPath, indexFile);
580
	if(getIndex(indexFile) == null) {
524
	Index index = getIndex(containerPath, indexFile, true, false);
581
		getIndexStates().put(indexFile, REUSE_STATE);
525
	if (index == null) {
582
		this.indexLocations.put(containerPath, indexFile);
526
		indexFile.close();
583
		Index index = getIndex(containerPath, indexFile, true, false);
527
		this.indexLocations.put(containerPath, null);
584
		if (index == null) {
528
		return false;
585
			indexFile.close();
586
			this.indexLocations.put(containerPath, null);
587
			return false;
588
		}
589
		writeIndexMapFile();
529
	}
590
	}
530
	writeIndexMapFile();
531
	return true;
591
	return true;
532
}
592
}
533
593
Lines 675-680 Link Here
675
		indexFile.delete();
735
		indexFile.delete();
676
	}
736
	}
677
	this.indexes.removeKey(indexLocation);
737
	this.indexes.removeKey(indexLocation);
738
	this.indexLocations.removeKey(containerPath);
678
	updateIndexState(indexLocation, null);
739
	updateIndexState(indexLocation, null);
679
}
740
}
680
/**
741
/**
Lines 769-774 Link Here
769
	}
830
	}
770
	this.indexLocations = new SimpleLookupTable();
831
	this.indexLocations = new SimpleLookupTable();
771
	this.javaPluginLocation = null;
832
	this.javaPluginLocation = null;
833
	this.manageUserIndexes = null;
772
}
834
}
773
/**
835
/**
774
 * Resets the index for a given path.
836
 * Resets the index for a given path.
Lines 1013-1018 Link Here
1013
			else if (indexState == UPDATING_STATE) state = "UPDATING"; //$NON-NLS-1$
1075
			else if (indexState == UPDATING_STATE) state = "UPDATING"; //$NON-NLS-1$
1014
			else if (indexState == UNKNOWN_STATE) state = "UNKNOWN"; //$NON-NLS-1$
1076
			else if (indexState == UNKNOWN_STATE) state = "UNKNOWN"; //$NON-NLS-1$
1015
			else if (indexState == REBUILDING_STATE) state = "REBUILDING"; //$NON-NLS-1$
1077
			else if (indexState == REBUILDING_STATE) state = "REBUILDING"; //$NON-NLS-1$
1078
			else if (indexState == REUSE_STATE) state = "REUSE"; //$NON-NLS-1$
1016
			Util.verbose("-> index state updated to: " + state + " for: "+indexLocation); //$NON-NLS-1$ //$NON-NLS-2$
1079
			Util.verbose("-> index state updated to: " + state + " for: "+indexLocation); //$NON-NLS-1$ //$NON-NLS-2$
1017
		}
1080
		}
1018
	}
1081
	}

Return to bug 395897