diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java
index 3985932..e8143a5 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java
@@ -2249,7 +2249,19 @@
* @category CoreOptionID
*/
public static final String TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC = PLUGIN_ID + ".timeoutForParameterNameFromAttachedJavadoc"; //$NON-NLS-1$
-
+ /**
+ * Core option ID: The indexer will manage (update or delete) pre-built indexes
+ *
When enabled, the indexer will manage any pre-built index files
+ *
+ * - Option id:
"org.eclipse.jdt.core.index.manageProductIndexes"
+ * - Possible values:
{ "enabled", "disabled" }
+ * - Default:
"disabled"
+ *
+ * @since 3.9
+ * @category CoreOptionID
+ */
+ public static final String MANAGE_PREBUILT_INDEXES = PLUGIN_ID + ".index.manageProductIndexes"; //$NON-NLS-1$
+
/**
* @since 2.0
* @deprecated Use {@link org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants#FORMATTER_BRACE_POSITION_FOR_ANONYMOUS_TYPE_DECLARATION},
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java
index c36e288..172a809 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java
@@ -998,7 +998,7 @@
// first remove the index so that it is forced to be re-indexed
this.manager.indexManager.removeIndex(entryPath);
// then index the jar
- this.manager.indexManager.indexLibrary(entryPath, project.getProject(), ((ClasspathEntry)entries[j]).getLibraryIndexLocation());
+ this.manager.indexManager.indexLibrary(entryPath, project.getProject(), ((ClasspathEntry)entries[j]).getLibraryIndexLocation(), true);
} else {
URL indexLocation = ((ClasspathEntry)entries[j]).getLibraryIndexLocation();
if (indexLocation != null) { // force reindexing, this could be faster rather than maintaining the list
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java
index fb926c3..155ced6 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaCorePreferenceInitializer.java
@@ -94,7 +94,9 @@
// Time out for parameter names
defaultOptionsMap.put(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC, "50"); //$NON-NLS-1$
-
+ // update product index (default: disabled)
+ defaultOptionsMap.put(JavaCore.MANAGE_PREBUILT_INDEXES, JavaCore.DISABLED);
+
// Store default values to default preferences
IEclipsePreferences defaultPreferences = DefaultScope.INSTANCE.getNode(JavaCore.PLUGIN_ID);
for (Iterator iter = defaultOptionsMap.entrySet().iterator(); iter.hasNext();) {
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java
index 57aa94c..9def848 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java
@@ -2255,7 +2255,9 @@
// Time out for parameter names
defaultOptionsMap.put(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC, "50"); //$NON-NLS-1$
-
+ // update product index (default: disabled)
+ defaultOptionsMap.put(JavaCore.MANAGE_PREBUILT_INDEXES, JavaCore.DISABLED);
+
return new Hashtable(defaultOptionsMap);
}
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java
index 46dfe21..bc59f6d 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java
@@ -44,16 +44,25 @@
IFile resource;
Scanner scanner;
private IndexLocation indexFileURL;
-
+ private final boolean forceIndexUpdate;
+
public AddJarFileToIndex(IFile resource, IndexLocation indexFile, IndexManager manager) {
+ this(resource, indexFile, manager, false);
+ }
+ public AddJarFileToIndex(IFile resource, IndexLocation indexFile, IndexManager manager, final boolean updateIndex) {
super(resource.getFullPath(), manager);
this.resource = resource;
this.indexFileURL = indexFile;
+ this.forceIndexUpdate = updateIndex;
}
public AddJarFileToIndex(IPath jarPath, IndexLocation indexFile, IndexManager manager) {
+ this(jarPath, indexFile, manager, false);
+ }
+ public AddJarFileToIndex(IPath jarPath, IndexLocation indexFile, IndexManager manager, final boolean updateIndex) {
// external JAR scenario - no resource
super(jarPath, manager);
this.indexFileURL = indexFile;
+ this.forceIndexUpdate = updateIndex;
}
public boolean equals(Object o) {
if (o instanceof AddJarFileToIndex) {
@@ -75,7 +84,7 @@
if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true;
- if (this.indexFileURL != null) {
+ if (this.addPreBuiltIndex()) {
boolean added = this.manager.addIndex(this.containerPath, this.indexFileURL);
if (added) return true;
this.indexFileURL = null;
@@ -291,9 +300,23 @@
return false;
}
protected Integer updatedIndexState() {
- return IndexManager.REBUILDING_STATE;
+
+ Integer updateState = null;
+ if(this.addPreBuiltIndex()) {
+ updateState = IndexManager.REUSE_STATE;
+ }
+ else {
+ updateState = IndexManager.REBUILDING_STATE;
+ }
+ return updateState;
}
public String toString() {
return "indexing " + this.containerPath.toString(); //$NON-NLS-1$
}
-}
+
+ protected boolean addPreBuiltIndex() {
+
+ boolean addIndex = !this.forceIndexUpdate && ((this.indexFileURL != null) && this.indexFileURL.exists());
+ return addIndex;
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java
index d130e0f..9d31ca7 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java
@@ -67,10 +67,25 @@
private SimpleLookupTable participantsContainers = null;
private boolean participantUpdated = false;
+ // should JDT manage (update, delete as needed) pre-built indexes?
+ private Boolean manageUserIndexes = null;
+
// Debug
public static boolean DEBUG = false;
+
+private boolean isManagingPreBuiltIndexes() {
+ if (this.manageUserIndexes == null) {
+ String manageIndexPropertyValue = JavaCore.getOption(JavaCore.MANAGE_PREBUILT_INDEXES);
+ if (manageIndexPropertyValue != null) {
+ this.manageUserIndexes = Boolean.valueOf(JavaCore.ENABLED.equals(manageIndexPropertyValue));
+ } else {
+ this.manageUserIndexes = Boolean.FALSE;
+ }
+ }
+ return this.manageUserIndexes.booleanValue();
+ }
- public synchronized void aboutToUpdateIndex(IPath containerPath, Integer newIndexState) {
+public synchronized void aboutToUpdateIndex(IPath containerPath, Integer newIndexState) {
// newIndexState is either UPDATING_STATE or REBUILDING_STATE
// must tag the index as inconsistent, in case we exit before the update job is started
IndexLocation indexLocation = computeIndexLocation(containerPath);
@@ -136,6 +151,42 @@
removeIndexesState(locations);
}
deleteIndexFiles(knownPaths);
+}
+/**
+ * Compute the pre-built index location for a specified URL
+ */
+public synchronized IndexLocation computeIndexLocation(IPath containerPath, final URL newIndexURL) {
+ IndexLocation indexLocation = (IndexLocation) this.indexLocations.get(containerPath);
+ if (indexLocation == null) {
+ if(newIndexURL != null) {
+ indexLocation = IndexLocation.createIndexLocation(newIndexURL);
+ // update caches
+ indexLocation = (IndexLocation) getIndexStates().getKey(indexLocation);
+ this.indexLocations.put(containerPath, indexLocation);
+ }
+ else {
+ indexLocation = this.computeIndexLocation(containerPath);
+ // cache updating is done in #computeIndexLocation(path)
+ }
+ }
+ else {
+ // an existing index location exists - make sure it has not changed (i.e. the URL has not changed)
+ URL existingURL = indexLocation.getUrl();
+ if (newIndexURL != null) {
+ // if either URL is different then the index location has been updated so rebuild.
+ if(!newIndexURL.equals(existingURL)
+ || ((existingURL != null) && !existingURL.equals(newIndexURL))) {
+ // URL has changed so remove the old index and create a new one
+ this.removeIndex(containerPath);
+ // create a new one
+ indexLocation = IndexLocation.createIndexLocation(newIndexURL);
+ // update caches
+ indexLocation = (IndexLocation) getIndexStates().getKey(indexLocation);
+ this.indexLocations.put(containerPath, indexLocation);
+ }
+ }
+ }
+ return indexLocation;
}
public synchronized IndexLocation computeIndexLocation(IPath containerPath) {
IndexLocation indexLocation = (IndexLocation) this.indexLocations.get(containerPath);
@@ -493,20 +544,26 @@
if (!isJobWaiting(request))
request(request);
}
+public void indexLibrary(IPath path, IProject requestingProject, URL indexURL) {
+
+ this.indexLibrary(path, requestingProject, indexURL, false);
+}
+
/**
* Trigger addition of a library to an index
* Note: the actual operation is performed in background
*/
-public void indexLibrary(IPath path, IProject requestingProject, URL indexURL) {
+public void indexLibrary(IPath path, IProject requestingProject, URL indexURL, final boolean updateIndex) {
// requestingProject is no longer used to cancel jobs but leave it here just in case
- IndexLocation indexFile = indexURL != null ? IndexLocation.createIndexLocation(indexURL): null;
+ IndexLocation indexFile = computeIndexLocation(path, indexURL);
if (JavaCore.getPlugin() == null) return;
IndexRequest request = null;
+ boolean forceIndexUpdate = this.isManagingPreBuiltIndexes() && updateIndex;
Object target = JavaModel.getTarget(path, true);
if (target instanceof IFile) {
- request = new AddJarFileToIndex((IFile) target, indexFile, this);
+ request = new AddJarFileToIndex((IFile) target, indexFile, this, forceIndexUpdate);
} else if (target instanceof File) {
- request = new AddJarFileToIndex(path, indexFile, this);
+ request = new AddJarFileToIndex(path, indexFile, this, forceIndexUpdate);
} else if (target instanceof IContainer) {
request = new IndexBinaryFolder((IContainer) target, this);
} else {
@@ -1013,6 +1070,7 @@
else if (indexState == UPDATING_STATE) state = "UPDATING"; //$NON-NLS-1$
else if (indexState == UNKNOWN_STATE) state = "UNKNOWN"; //$NON-NLS-1$
else if (indexState == REBUILDING_STATE) state = "REBUILDING"; //$NON-NLS-1$
+ else if (indexState == REUSE_STATE) state = "REUSE"; //$NON-NLS-1$
Util.verbose("-> index state updated to: " + state + " for: "+indexLocation); //$NON-NLS-1$ //$NON-NLS-2$
}
}