mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
Patch for Bogdan Gheorghe
Put in Indexer shut down which cleans up the .metadata directory of any suspicious looking index files Put in CSearchScope changes (in both UI and core) to enable working set searches
This commit is contained in:
parent
b1ebabea9a
commit
e1a20e1a7d
10 changed files with 209 additions and 44 deletions
|
@ -10,7 +10,10 @@
|
|||
*/
|
||||
package org.eclipse.cdt.core.indexer.tests;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
|
@ -85,7 +88,7 @@ public class IndexManagerTests extends TestCase {
|
|||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite();
|
||||
suite.addTest(new IndexManagerTests("testRefs"));
|
||||
suite.addTest(new IndexManagerTests("testIndexShutdown"));
|
||||
return suite;
|
||||
//return new TestSuite(IndexManagerTests.class);
|
||||
}
|
||||
|
@ -420,6 +423,45 @@ public class IndexManagerTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testIndexShutdown() throws Exception{
|
||||
//Add a new file to the project, give it some time to index
|
||||
importFile("reftest.cpp","resources/indexer/reftest.cpp");
|
||||
//Enable indexing on the created project
|
||||
//By doing this, we force the Index Manager to indexAll()
|
||||
indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
|
||||
indexManager.setEnabled(testProject,true);
|
||||
Thread.sleep(TIMEOUT);
|
||||
//Make sure project got added to index
|
||||
IPath testProjectPath = testProject.getFullPath();
|
||||
IIndex ind = indexManager.getIndex(testProjectPath,true,true);
|
||||
assertTrue("Index exists for project",ind != null);
|
||||
|
||||
//Create an empty index file
|
||||
String badIndexFile = CCorePlugin.getDefault().getStateLocation().append("badIndex.index").toOSString();
|
||||
FileWriter writer = null;
|
||||
try {
|
||||
writer = new FileWriter(badIndexFile);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
catch (IOException e){}
|
||||
|
||||
File indexesDirectory = new File(CCorePlugin.getDefault().getStateLocation().toOSString());
|
||||
|
||||
//This should get rid of the empty index file from the metadata and
|
||||
//remove the index from the indexes (since its .index file is missing)
|
||||
indexManager.shutdown();
|
||||
|
||||
File[] indexesFiles = indexesDirectory.listFiles();
|
||||
if (indexesFiles != null) {
|
||||
for (int i = 0, indexesFilesLength = indexesFiles.length; i < indexesFilesLength; i++) {
|
||||
if(indexesFiles[i].getName().equals("badIndex.index")){
|
||||
fail("Shutdown did not delete .index file");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testDependencyTree() throws Exception{
|
||||
//Add a file to the project
|
||||
IFile depTest = importFile("DepTest.cpp","resources/dependency/DepTest.cpp");
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
2003-08-07 Bogdan Gheorghe
|
||||
- Added shutdown cleanup routine in IndexManager
|
||||
|
||||
2003-07-28 Andrew Niefer
|
||||
- added support for '?' wildcards in AbstractIndexer.bestPrefix
|
||||
|
||||
|
|
|
@ -318,12 +318,6 @@ public class Util {
|
|||
} else if (existingExternalFiles.contains(externalFile)) {
|
||||
return externalFile;
|
||||
} else {
|
||||
//TODO: BOG do we need to add something here? ANSWER YES!
|
||||
/*
|
||||
if (JavaModelManager.ZIP_ACCESS_VERBOSE) {
|
||||
System.out.println("(" + Thread.currentThread() + ") [JavaModel.getTarget(...)] Checking existence of " + path.toString()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
*/
|
||||
if (externalFile.exists()) {
|
||||
// cache external file
|
||||
existingExternalFiles.add(externalFile);
|
||||
|
|
|
@ -30,6 +30,8 @@ import org.eclipse.core.runtime.IPath;
|
|||
import org.eclipse.core.runtime.QualifiedName;
|
||||
import org.eclipse.cdt.internal.core.search.processing.JobManager;
|
||||
import org.eclipse.cdt.internal.core.search.processing.IJob;
|
||||
import org.eclipse.cdt.internal.core.search.CWorkspaceScope;
|
||||
import org.eclipse.cdt.internal.core.search.IndexSelector;
|
||||
import org.eclipse.cdt.internal.core.search.SimpleLookupTable;
|
||||
import org.eclipse.cdt.internal.core.search.CharOperation;
|
||||
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||
|
@ -51,12 +53,12 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
/* need to save ? */
|
||||
private boolean needToSave = false;
|
||||
private static final CRC32 checksumCalculator = new CRC32();
|
||||
private IPath javaPluginLocation = null;
|
||||
private IPath cCorePluginLocation = null;
|
||||
|
||||
/* can only replace a current state if its less than the new one */
|
||||
private SimpleLookupTable indexStates = null;
|
||||
private File savedIndexNamesFile =
|
||||
new File(getJavaPluginWorkingLocation().append("savedIndexNames.txt").toOSString()); //$NON-NLS-1$
|
||||
new File(getCCorePluginWorkingLocation().append("savedIndexNames.txt").toOSString()); //$NON-NLS-1$
|
||||
public static Integer SAVED_STATE = new Integer(0);
|
||||
public static Integer UPDATING_STATE = new Integer(1);
|
||||
public static Integer UNKNOWN_STATE = new Integer(2);
|
||||
|
@ -126,7 +128,7 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
String fileName = Long.toString(checksumCalculator.getValue()) + ".index"; //$NON-NLS-1$
|
||||
if (VERBOSE)
|
||||
JobManager.verbose("-> index name for " + pathString + " is " + fileName); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
name = getJavaPluginWorkingLocation().append(fileName).toOSString();
|
||||
name = getCCorePluginWorkingLocation().append(fileName).toOSString();
|
||||
indexNames.put(path, name);
|
||||
}
|
||||
return name;
|
||||
|
@ -216,10 +218,10 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
return this.indexStates;
|
||||
}
|
||||
|
||||
private IPath getJavaPluginWorkingLocation() {
|
||||
if (this.javaPluginLocation != null) return this.javaPluginLocation;
|
||||
private IPath getCCorePluginWorkingLocation() {
|
||||
if (this.cCorePluginLocation != null) return this.cCorePluginLocation;
|
||||
|
||||
return this.javaPluginLocation = CCorePlugin.getDefault().getStateLocation();
|
||||
return this.cCorePluginLocation = CCorePlugin.getDefault().getStateLocation();
|
||||
}
|
||||
/**
|
||||
* Index access is controlled through a read-write monitor so as
|
||||
|
@ -430,7 +432,7 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
this.indexStates = null;
|
||||
}
|
||||
this.indexNames = new SimpleLookupTable();
|
||||
this.javaPluginLocation = null;
|
||||
this.cCorePluginLocation = null;
|
||||
}
|
||||
|
||||
public void saveIndex(IIndex index) throws IOException {
|
||||
|
@ -492,26 +494,28 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
public void shutdown() {
|
||||
if (VERBOSE)
|
||||
JobManager.verbose("Shutdown"); //$NON-NLS-1$
|
||||
//TODO: BOG Put in Shutdown
|
||||
/*
|
||||
IndexSelector indexSelector = new IndexSelector(new JavaWorkspaceScope(), null, false, this);
|
||||
//Get index entries for all projects in the workspace, store their absolute paths
|
||||
IndexSelector indexSelector = new IndexSelector(new CWorkspaceScope(), null, false, this);
|
||||
IIndex[] selectedIndexes = indexSelector.getIndexes();
|
||||
SimpleLookupTable knownPaths = new SimpleLookupTable();
|
||||
for (int i = 0, max = selectedIndexes.length; i < max; i++) {
|
||||
String path = selectedIndexes[i].getIndexFile().getAbsolutePath();
|
||||
knownPaths.put(path, path);
|
||||
}
|
||||
|
||||
//Any index entries that are in the index state must have a corresponding
|
||||
//path entry - if not they are removed from the saved indexes file
|
||||
if (indexStates != null) {
|
||||
Object[] indexNames = indexStates.keyTable;
|
||||
for (int i = 0, l = indexNames.length; i < l; i++) {
|
||||
String key = (String) indexNames[i];
|
||||
if (key != null && !knownPaths.containsKey(key))
|
||||
if (key != null && !knownPaths.containsKey(key)) //here is an index that is in t
|
||||
updateIndexState(key, null);
|
||||
}
|
||||
}
|
||||
|
||||
File indexesDirectory = new File(getJavaPluginWorkingLocation().toOSString());
|
||||
//Clean up the .metadata folder - if there are any files in the directory that
|
||||
//are not associated to an index we delete them
|
||||
File indexesDirectory = new File(getCCorePluginWorkingLocation().toOSString());
|
||||
if (indexesDirectory.isDirectory()) {
|
||||
File[] indexesFiles = indexesDirectory.listFiles();
|
||||
if (indexesFiles != null) {
|
||||
|
@ -525,7 +529,7 @@ public class IndexManager extends JobManager implements IIndexConstants {
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
super.shutdown();
|
||||
}
|
||||
|
||||
|
|
|
@ -758,6 +758,10 @@ public class CModelManager implements IResourceChangeListener {
|
|||
*
|
||||
*/
|
||||
public void shutdown() {
|
||||
if (this.fDeltaProcessor.indexManager != null){ // no more indexing
|
||||
this.fDeltaProcessor.indexManager.shutdown();
|
||||
}
|
||||
|
||||
// Do any shutdown of services.
|
||||
ResourcesPlugin.getWorkspace().removeResourceChangeListener(factory);
|
||||
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
2003-08-08 Bogdan Gheorghe
|
||||
- Added CreateSearchScope to create a search scope out of
|
||||
CElements
|
||||
- Filled out CSearchScope to enable:
|
||||
- adding a project to scope, include referenced projects
|
||||
- adding individual CElements to scope
|
||||
|
||||
2003-08-06 Andrew Niefer
|
||||
- Create OrPattern which matches for search if any of its constituent patterns matches
|
||||
- modified MatchLocator to support the OrPattern
|
||||
|
|
|
@ -13,9 +13,13 @@
|
|||
*/
|
||||
package org.eclipse.cdt.core.search;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.internal.core.search.CSearchScope;
|
||||
import org.eclipse.cdt.internal.core.search.CWorkspaceScope;
|
||||
import org.eclipse.cdt.internal.core.search.PathCollector;
|
||||
import org.eclipse.cdt.internal.core.search.PatternSearchJob;
|
||||
|
@ -64,13 +68,31 @@ public class SearchEngine implements ICSearchConstants{
|
|||
return new CWorkspaceScope();
|
||||
}
|
||||
|
||||
public static ICSearchScope createCSearchScope(ICElement[] elements) {
|
||||
return createCSearchScope(elements, true);
|
||||
}
|
||||
/**
|
||||
* @param objects
|
||||
* @return
|
||||
*/
|
||||
public static ICSearchScope createCSearchScope(Object[] objects) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public static ICSearchScope createCSearchScope(ICElement[] elements, boolean includeReferencedProjects) {
|
||||
CSearchScope scope = new CSearchScope();
|
||||
HashSet visitedProjects = new HashSet(2);
|
||||
for (int i = 0, length = elements.length; i < length; i++) {
|
||||
ICElement element = elements[i];
|
||||
if (element != null) {
|
||||
try {
|
||||
if (element instanceof ICProject) {
|
||||
scope.add((ICProject)element, includeReferencedProjects, visitedProjects);
|
||||
} else {
|
||||
scope.add(element);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
return scope;
|
||||
}
|
||||
|
||||
public static ICSearchPattern createSearchPattern( String stringPattern, SearchFor searchFor, LimitTo limitTo, boolean isCaseSensitive){
|
||||
|
|
|
@ -16,15 +16,16 @@ import java.util.HashSet;
|
|||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.IMember;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
public class CSearchScope implements ICSearchScope {
|
||||
|
||||
private ArrayList elements;
|
||||
|
||||
/* The paths of the resources in this search scope*/
|
||||
private IPath[] paths;
|
||||
private boolean[] pathWithSubFolders;
|
||||
|
@ -63,6 +64,24 @@ public class CSearchScope implements ICSearchScope {
|
|||
if (!project.isAccessible() || !visitedProjects.add(project)) return;
|
||||
|
||||
this.addEnclosingProject(project.getFullPath());
|
||||
ICElement[] projChildren = cProject.getChildren();
|
||||
for (int i=0; i< projChildren.length; i++){
|
||||
this.add(projChildren[i]);
|
||||
}
|
||||
|
||||
if (includesPrereqProjects){
|
||||
IProject[] refProjects=null;
|
||||
try {
|
||||
refProjects = project.getReferencedProjects();
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
for (int i=0; i<refProjects.length; i++){
|
||||
ICProject cProj= (ICProject)refProjects[i].getAdapter(ICElement.class);
|
||||
if (cProj != null){
|
||||
this.add(cProj, true, visitedProjects);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Adds the given path to this search scope. Remember if subfolders need to be included as well.
|
||||
|
@ -87,18 +106,9 @@ public class CSearchScope implements ICSearchScope {
|
|||
}
|
||||
|
||||
public boolean encloses(String resourcePathString) {
|
||||
IPath resourcePath;
|
||||
int separatorIndex = -1; //resourcePathString.indexOf(JAR_FILE_ENTRY_SEPARATOR);
|
||||
if (separatorIndex != -1) {
|
||||
resourcePath =
|
||||
new Path(resourcePathString.substring(0, separatorIndex)).
|
||||
append(new Path(resourcePathString.substring(separatorIndex+1)));
|
||||
} else {
|
||||
resourcePath = new Path(resourcePathString);
|
||||
}
|
||||
IPath resourcePath = new Path(resourcePathString);
|
||||
return this.encloses(resourcePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this search scope encloses the given path.
|
||||
*/
|
||||
|
@ -110,8 +120,8 @@ public class CSearchScope implements ICSearchScope {
|
|||
}
|
||||
} else {
|
||||
// if not looking at subfolders, this scope encloses the given path
|
||||
// if this path is a direct child of the scope's ressource
|
||||
// or if this path is the scope's resource (see bug 13919 Declaration for package not found if scope is not project)
|
||||
// if this path is a direct child of the scope's resource
|
||||
// or if this path is the scope's resource
|
||||
IPath scopePath = this.paths[i];
|
||||
if (scopePath.isPrefixOf(path)
|
||||
&& ((scopePath.segmentCount() == path.segmentCount() - 1)
|
||||
|
@ -147,6 +157,31 @@ public class CSearchScope implements ICSearchScope {
|
|||
}
|
||||
|
||||
private IPath fullPath(ICElement element) {
|
||||
return null;
|
||||
return element.getPath();
|
||||
}
|
||||
|
||||
public void add(ICElement element) {
|
||||
switch (element.getElementType()) {
|
||||
case ICElement.C_PROJECT:
|
||||
// a workspace scope should be used
|
||||
break;
|
||||
default:
|
||||
if (element instanceof IMember) {
|
||||
if (this.elements == null) {
|
||||
this.elements = new ArrayList();
|
||||
}
|
||||
this.elements.add(element);
|
||||
}
|
||||
//Add the element to paths
|
||||
this.add(this.fullPath(element), true);
|
||||
|
||||
ICElement parent = element.getParent();
|
||||
while (parent != null && !(parent instanceof ICProject)) {
|
||||
parent = parent.getParent();
|
||||
}
|
||||
if (parent instanceof ICProject) {
|
||||
this.addEnclosingProject(parent.getCProject().getProject().getFullPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
2003-08-08 Bogdan Gheorghe
|
||||
- Filled out CSearchScopeFactory to translate working sets
|
||||
into CElements
|
||||
|
||||
2003-08-01 Andrew Niefer
|
||||
- Modified CSearchResultCollector to reflect changes in BasicSearchResultCollector,
|
||||
acceptMatch will return false if the match was not accepted because it has already
|
||||
|
|
|
@ -13,8 +13,13 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.cdt.core.search.SearchEngine;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
|
||||
|
@ -26,8 +31,7 @@ import org.eclipse.ui.IWorkingSet;
|
|||
*/
|
||||
public class CSearchScopeFactory {
|
||||
private static CSearchScopeFactory fgInstance;
|
||||
private static ICSearchScope EMPTY_SCOPE= SearchEngine.createCSearchScope(new Object[] {});
|
||||
|
||||
private static ICSearchScope EMPTY_SCOPE= SearchEngine.createCSearchScope(new ICElement[]{});
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -40,14 +44,60 @@ public class CSearchScopeFactory {
|
|||
fgInstance = new CSearchScopeFactory();
|
||||
return fgInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sets
|
||||
* @return
|
||||
*/
|
||||
public ICSearchScope createCSearchScope(IWorkingSet[] sets) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
if (sets == null || sets.length < 1)
|
||||
return EMPTY_SCOPE;
|
||||
|
||||
Set cElements= new HashSet(sets.length * 10);
|
||||
for (int i= 0; i < sets.length; i++)
|
||||
addCElements(cElements, sets[i]);
|
||||
return createCSearchScope(cElements);
|
||||
}
|
||||
/**
|
||||
* @param cElements
|
||||
* @return
|
||||
*/
|
||||
private ICSearchScope createCSearchScope(Set cElements) {
|
||||
return SearchEngine.createCSearchScope((ICElement[])cElements.toArray(new ICElement[cElements.size()]));
|
||||
}
|
||||
/**
|
||||
* @param cElements
|
||||
* @param set
|
||||
*/
|
||||
private void addCElements(Set cElements, IWorkingSet set) {
|
||||
if (set == null)
|
||||
return;
|
||||
|
||||
IAdaptable[] elements= set.getElements();
|
||||
for (int i= 0; i < elements.length; i++) {
|
||||
if (elements[i] instanceof ICElement)
|
||||
addCElements(cElements, (ICElement)elements[i]);
|
||||
else
|
||||
addCElements(cElements, elements[i]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param cElements
|
||||
* @param adaptable
|
||||
*/
|
||||
private void addCElements(Set cElements, IAdaptable resource) {
|
||||
ICElement cElement= (ICElement)resource.getAdapter(ICElement.class);
|
||||
if (cElement == null)
|
||||
// not an ICElement resource
|
||||
return;
|
||||
|
||||
addCElements(cElements, cElement);
|
||||
}
|
||||
/**
|
||||
* @param cElements
|
||||
* @param element
|
||||
*/
|
||||
private void addCElements(Set cElements, ICElement element) {
|
||||
cElements.add(element);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,5 +108,5 @@ public class CSearchScopeFactory {
|
|||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue