Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJayaprakash Arthanareeswaran2013-04-01 10:38:56 +0000
committerJayaprakash Arthanareeswaran2013-04-01 10:38:56 +0000
commit5dfbbb5009633824065054fbfc5b3b4cdd22fb57 (patch)
treeadc864b37dc10d26e5ea3c95ff582995f094fbe8
parentc63d23b095650f643b81a4eef182f99fe93bbf9d (diff)
downloadeclipse.jdt.core-5dfbbb5009633824065054fbfc5b3b4cdd22fb57.tar.gz
eclipse.jdt.core-5dfbbb5009633824065054fbfc5b3b4cdd22fb57.tar.xz
eclipse.jdt.core-5dfbbb5009633824065054fbfc5b3b4cdd22fb57.zip
Fix for bug 395897 - INDEX_LOCATION_ATTRIBUTE_NAME attribute value isM20130401-1000
ignored when the index is rebuilt
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java4
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/FileIndexLocation.java7
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java29
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java65
4 files changed, 92 insertions, 13 deletions
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 c36e2885d8..8accbb6748 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -998,7 +998,7 @@ public class DeltaProcessor {
// 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/search/org/eclipse/jdt/internal/core/index/FileIndexLocation.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/FileIndexLocation.java
index 67fc9aea91..f0648dda81 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/FileIndexLocation.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/FileIndexLocation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation and others.
+ * Copyright (c) 2011, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -38,6 +38,11 @@ public class FileIndexLocation extends IndexLocation {
}
public boolean createNewFile() throws IOException {
+ File directory = this.indexFile.getParentFile();
+ if (directory != null && !directory.exists()) {
+ directory.mkdirs();
+ }
+ // always call File#createNewFile() so that the IOException is thrown if there is a failure
return this.indexFile.createNewFile();
}
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 46dfe2171c..42f0bb47cc 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -44,16 +44,25 @@ class AddJarFileToIndex extends IndexRequest {
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 @@ class AddJarFileToIndex extends IndexRequest {
if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true;
- if (this.indexFileURL != null) {
+ if (hasPreBuiltIndex()) {
boolean added = this.manager.addIndex(this.containerPath, this.indexFileURL);
if (added) return true;
this.indexFileURL = null;
@@ -291,9 +300,21 @@ class AddJarFileToIndex extends IndexRequest {
return false;
}
protected Integer updatedIndexState() {
- return IndexManager.REBUILDING_STATE;
+
+ Integer updateState = null;
+ if(hasPreBuiltIndex()) {
+ updateState = IndexManager.REUSE_STATE;
+ }
+ else {
+ updateState = IndexManager.REBUILDING_STATE;
+ }
+ return updateState;
}
public String toString() {
return "indexing " + this.containerPath.toString(); //$NON-NLS-1$
}
-}
+
+ protected boolean hasPreBuiltIndex() {
+ return !this.forceIndexUpdate && (this.indexFileURL != null && this.indexFileURL.exists());
+ }
+} \ 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 d130e0f42f..4834c3219e 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -67,10 +67,15 @@ public class IndexManager extends JobManager implements IIndexConstants {
private SimpleLookupTable participantsContainers = null;
private boolean participantUpdated = false;
+ // should JDT manage (update, delete as needed) pre-built indexes?
+ public static final String MANAGE_PRODUCT_INDEXES_PROPERTY = "jdt.core.manageProductIndexes"; //$NON-NLS-1$
+ private static final boolean IS_MANAGING_PRODUCT_INDEXES_PROPERTY = Boolean.getBoolean(MANAGE_PRODUCT_INDEXES_PROPERTY);
+
// Debug
public static boolean DEBUG = false;
- 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);
@@ -137,6 +142,37 @@ public void cleanUpIndexes() {
}
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 {
+ // 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)) {
+ // 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);
if (indexLocation == null) {
@@ -493,20 +529,33 @@ public void indexAll(IProject project) {
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 = null;
+ if(indexURL != null) {
+ if(IS_MANAGING_PRODUCT_INDEXES_PROPERTY) {
+ indexFile = computeIndexLocation(path, indexURL);
+ }
+ else {
+ indexFile = IndexLocation.createIndexLocation(indexURL);
+ }
+ }
if (JavaCore.getPlugin() == null) return;
IndexRequest request = null;
+ boolean forceIndexUpdate = IS_MANAGING_PRODUCT_INDEXES_PROPERTY && 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 {
@@ -675,6 +724,9 @@ public synchronized void removeIndex(IPath containerPath) {
indexFile.delete();
}
this.indexes.removeKey(indexLocation);
+ if (IS_MANAGING_PRODUCT_INDEXES_PROPERTY) {
+ this.indexLocations.removeKey(containerPath);
+ }
updateIndexState(indexLocation, null);
}
/**
@@ -1013,6 +1065,7 @@ private synchronized void updateIndexState(IndexLocation indexLocation, Integer
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$
}
}

Back to the top