### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core diff --git model/org/eclipse/jdt/internal/core/DeltaProcessor.java model/org/eclipse/jdt/internal/core/DeltaProcessor.java index c36e288..8accbb6 100644 --- model/org/eclipse/jdt/internal/core/DeltaProcessor.java +++ 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 @@ // 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 search/org/eclipse/jdt/internal/core/index/FileIndexLocation.java search/org/eclipse/jdt/internal/core/index/FileIndexLocation.java index 67fc9ae..f0648dd 100644 --- search/org/eclipse/jdt/internal/core/index/FileIndexLocation.java +++ 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 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 search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java index 46dfe21..42f0bb4 100644 --- search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java +++ 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 @@ 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 (hasPreBuiltIndex()) { boolean added = this.manager.addIndex(this.containerPath, this.indexFileURL); if (added) return true; this.indexFileURL = null; @@ -291,9 +300,21 @@ 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 search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java index d130e0f..4834c32 100644 --- search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java +++ 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 @@ 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); @@ -136,6 +141,37 @@ 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 { + // 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); @@ -493,20 +529,33 @@ 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 @@ indexFile.delete(); } this.indexes.removeKey(indexLocation); + if (IS_MANAGING_PRODUCT_INDEXES_PROPERTY) { + this.indexLocations.removeKey(containerPath); + } updateIndexState(indexLocation, null); } /** @@ -1013,6 +1065,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$ } }