mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
First go at putting in source folder indexing. Index All events will index
source folders (still need to put in includes indexing).
This commit is contained in:
parent
4abe159ab8
commit
191dd913bd
3 changed files with 30 additions and 100 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2004-05-18 Bogdan Gheorghe
|
||||||
|
First go at putting in source folder indexing. Index All events will index
|
||||||
|
source folders (still need to put in includes indexing). DeltaProcessor only
|
||||||
|
forwards events for source files so individual indexing doesn't need to be
|
||||||
|
altered.
|
||||||
|
|
||||||
2004-05-16 Bogdan Gheorghe
|
2004-05-16 Bogdan Gheorghe
|
||||||
Fix for bug 61332 - make sure that the timer is ready to go before starting
|
Fix for bug 61332 - make sure that the timer is ready to go before starting
|
||||||
a new index
|
a new index
|
||||||
|
|
|
@ -14,10 +14,18 @@ package org.eclipse.cdt.internal.core.search.indexing;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
import org.eclipse.cdt.core.model.IPathEntry;
|
||||||
|
import org.eclipse.cdt.core.model.ISourceEntry;
|
||||||
|
import org.eclipse.cdt.core.model.ISourceRoot;
|
||||||
import org.eclipse.cdt.internal.core.Util;
|
import org.eclipse.cdt.internal.core.Util;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndex;
|
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||||
import org.eclipse.cdt.internal.core.index.IQueryResult;
|
import org.eclipse.cdt.internal.core.index.IQueryResult;
|
||||||
import org.eclipse.cdt.internal.core.index.impl.IFileDocument;
|
import org.eclipse.cdt.internal.core.index.impl.IFileDocument;
|
||||||
|
import org.eclipse.cdt.internal.core.model.CModel;
|
||||||
|
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||||
|
import org.eclipse.cdt.internal.core.model.SourceEntry;
|
||||||
|
import org.eclipse.cdt.internal.core.model.SourceRoot;
|
||||||
import org.eclipse.cdt.internal.core.search.SimpleLookupTable;
|
import org.eclipse.cdt.internal.core.search.SimpleLookupTable;
|
||||||
import org.eclipse.cdt.internal.core.search.processing.JobManager;
|
import org.eclipse.cdt.internal.core.search.processing.JobManager;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
|
@ -72,109 +80,25 @@ public class IndexAllProject extends IndexRequest {
|
||||||
indexedFileNames.put(results[i].getPath(), DELETED);
|
indexedFileNames.put(results[i].getPath(), DELETED);
|
||||||
final long indexLastModified = max == 0 ? 0L : index.getIndexFile().lastModified();
|
final long indexLastModified = max == 0 ? 0L : index.getIndexFile().lastModified();
|
||||||
|
|
||||||
// CModel model = (CModel) CModelManager.getDefault().getCModel();
|
CModel model = (CModel) CModelManager.getDefault().getCModel();
|
||||||
// ICProject cProject = model.getCProject(project.getName());
|
|
||||||
// ICElement[] kids = cProject.getChildren();
|
if (model == null)
|
||||||
IPath cProjectPath = project.getFullPath();
|
return false;
|
||||||
|
|
||||||
IWorkspaceRoot root = this.project.getWorkspace().getRoot();
|
ICProject cProject = model.getCProject(project.getName());
|
||||||
IResource sourceFolder = root.findMember(cProjectPath);
|
|
||||||
|
|
||||||
if (this.isCancelled) return false;
|
if (cProject == null)
|
||||||
|
return false;
|
||||||
if (sourceFolder != null) {
|
|
||||||
|
|
||||||
// collect output locations if source is project (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32041)
|
|
||||||
final HashSet outputs = new HashSet();
|
|
||||||
|
|
||||||
final boolean hasOutputs = !outputs.isEmpty();
|
//Get the source roots for this project
|
||||||
|
ISourceRoot[] sourceRoot = cProject.getSourceRoots();
|
||||||
final char[][] patterns = null;
|
for (int i=0;i<sourceRoot.length;i++){
|
||||||
if (max == 0) {
|
if (sourceRoot[i] instanceof SourceRoot){
|
||||||
sourceFolder.accept(
|
ISourceEntry tempEntry = ((SourceRoot) sourceRoot[i]).getSourceEntry();
|
||||||
new IResourceProxyVisitor() {
|
this.manager.request(new AddFolderToIndex(sourceRoot[i].getPath(), project, tempEntry.fullExclusionPatternChars(), this.manager));
|
||||||
public boolean visit(IResourceProxy proxy) {
|
|
||||||
if (isCancelled) return false;
|
|
||||||
switch(proxy.getType()) {
|
|
||||||
case IResource.FILE :
|
|
||||||
if (Util.isCCFileName(proxy.getName())) {
|
|
||||||
IResource resource = proxy.requestResource();
|
|
||||||
if (resource.getLocation() != null && (patterns == null || !Util.isExcluded(resource, patterns))) {
|
|
||||||
String name = new IFileDocument((IFile) resource).getName();
|
|
||||||
indexedFileNames.put(name, resource);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
|
|
||||||
case IResource.FOLDER :
|
|
||||||
if (patterns != null && Util.isExcluded(proxy.requestResource(), patterns))
|
|
||||||
return false;
|
|
||||||
if (hasOutputs && outputs.contains(proxy.requestFullPath())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
IResource.NONE
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
sourceFolder.accept(
|
|
||||||
new IResourceProxyVisitor() {
|
|
||||||
public boolean visit(IResourceProxy proxy) {
|
|
||||||
if (isCancelled) return false;
|
|
||||||
switch(proxy.getType()) {
|
|
||||||
case IResource.FILE :
|
|
||||||
if (Util.isCCFileName(proxy.getName())) {
|
|
||||||
IResource resource = proxy.requestResource();
|
|
||||||
IPath path = resource.getLocation();
|
|
||||||
if (path != null && (patterns == null || !Util.isExcluded(resource, patterns))) {
|
|
||||||
String name = new IFileDocument((IFile) resource).getName();
|
|
||||||
indexedFileNames.put(name,
|
|
||||||
indexedFileNames.get(name) == null || indexLastModified < path.toFile().lastModified()
|
|
||||||
? (Object) resource
|
|
||||||
: (Object) OK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
case IResource.FOLDER :
|
|
||||||
if (patterns != null && Util.isExcluded(proxy.requestResource(), patterns))
|
|
||||||
return false;
|
|
||||||
if (hasOutputs && outputs.contains(proxy.requestFullPath())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
IResource.NONE
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Object[] names = indexedFileNames.keyTable;
|
|
||||||
Object[] values = indexedFileNames.valueTable;
|
|
||||||
boolean shouldSave = false;
|
|
||||||
for (int i = 0, length = names.length; i < length; i++) {
|
|
||||||
String name = (String) names[i];
|
|
||||||
if (name != null) {
|
|
||||||
if (this.isCancelled) return false;
|
|
||||||
|
|
||||||
Object value = values[i];
|
|
||||||
if (value != OK) {
|
|
||||||
shouldSave = true;
|
|
||||||
if (value == DELETED)
|
|
||||||
this.manager.remove(name, this.indexPath);
|
|
||||||
else
|
|
||||||
this.manager.addSource((IFile) value, this.indexPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// request to save index when all cus have been indexed
|
|
||||||
if (shouldSave)
|
|
||||||
this.manager.request(new SaveIndex(this.indexPath, this.manager));
|
|
||||||
|
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
if (IndexManager.VERBOSE) {
|
if (IndexManager.VERBOSE) {
|
||||||
JobManager.verbose("-> failed to index " + this.project + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
|
JobManager.verbose("-> failed to index " + this.project + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
|
@ -143,6 +143,7 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
||||||
// reduces the chance that the file is open later on, preventing it from being deleted
|
// reduces the chance that the file is open later on, preventing it from being deleted
|
||||||
if (!job.initializeContents()) return;
|
if (!job.initializeContents()) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
request(job);
|
request(job);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,9 +332,8 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
||||||
/**
|
/**
|
||||||
* Index the content of the given source folder.
|
* Index the content of the given source folder.
|
||||||
*/
|
*/
|
||||||
public void indexSourceFolder(CProject javaProject, IPath sourceFolder, final char[][] exclusionPattern) {
|
public void indexSourceFolder(IProject project, IPath sourceFolder, final char[][] exclusionPattern) {
|
||||||
IProject project = javaProject.getProject();
|
|
||||||
|
|
||||||
if (this.jobEnd > this.jobStart) {
|
if (this.jobEnd > this.jobStart) {
|
||||||
// check if a job to index the project is not already in the queue
|
// check if a job to index the project is not already in the queue
|
||||||
IndexRequest request = new IndexAllProject(project, this);
|
IndexRequest request = new IndexAllProject(project, this);
|
||||||
|
|
Loading…
Add table
Reference in a new issue