[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Indexer/Search Patch
|
- 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
Bogdan
Index: indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java,v
retrieving revision 1.7
diff -u -r1.7 IndexManagerTests.java
--- indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java 25 Jul 2003 15:21:49 -0000 1.7
+++ indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java 8 Aug 2003 15:40:35 -0000
@@ -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 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 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");
Index: index/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/index/ChangeLog,v
retrieving revision 1.8
diff -u -r1.8 ChangeLog
--- index/ChangeLog 29 Jul 2003 12:40:17 -0000 1.8
+++ index/ChangeLog 8 Aug 2003 15:38:22 -0000
@@ -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
Index: index/org/eclipse/cdt/internal/core/search/Util.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/Util.java,v
retrieving revision 1.4
diff -u -r1.4 Util.java
--- index/org/eclipse/cdt/internal/core/search/Util.java 30 Jul 2003 01:31:14 -0000 1.4
+++ index/org/eclipse/cdt/internal/core/search/Util.java 8 Aug 2003 15:38:22 -0000
@@ -318,12 +318,6 @@
} 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);
Index: index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java,v
retrieving revision 1.3
diff -u -r1.3 IndexManager.java
--- index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java 21 Jul 2003 21:14:06 -0000 1.3
+++ index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java 8 Aug 2003 15:38:22 -0000
@@ -30,6 +30,8 @@
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 @@
/* 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 @@
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 @@
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 @@
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 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 @@
}
}
}
-*/
+
super.shutdown();
}
Index: model/org/eclipse/cdt/internal/core/model/CModelManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java,v
retrieving revision 1.30
diff -u -r1.30 CModelManager.java
--- model/org/eclipse/cdt/internal/core/model/CModelManager.java 24 Jul 2003 14:15:06 -0000 1.30
+++ model/org/eclipse/cdt/internal/core/model/CModelManager.java 8 Aug 2003 15:38:23 -0000
@@ -758,6 +758,10 @@
*
*/
public void shutdown() {
+ if (this.fDeltaProcessor.indexManager != null){ // no more indexing
+ this.fDeltaProcessor.indexManager.shutdown();
+ }
+
// Do any shutdown of services.
ResourcesPlugin.getWorkspace().removeResourceChangeListener(factory);
Index: search/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/ChangeLog,v
retrieving revision 1.13
diff -u -r1.13 ChangeLog
--- search/ChangeLog 7 Aug 2003 14:52:18 -0000 1.13
+++ search/ChangeLog 8 Aug 2003 15:38:23 -0000
@@ -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
Index: search/org/eclipse/cdt/core/search/SearchEngine.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/SearchEngine.java,v
retrieving revision 1.4
diff -u -r1.4 SearchEngine.java
--- search/org/eclipse/cdt/core/search/SearchEngine.java 11 Jul 2003 22:12:35 -0000 1.4
+++ search/org/eclipse/cdt/core/search/SearchEngine.java 8 Aug 2003 15:38:23 -0000
@@ -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 @@
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){
Index: search/org/eclipse/cdt/internal/core/search/CSearchScope.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/search/org/eclipse/cdt/internal/core/search/CSearchScope.java,v
retrieving revision 1.2
diff -u -r1.2 CSearchScope.java
--- search/org/eclipse/cdt/internal/core/search/CSearchScope.java 11 Jul 2003 22:12:35 -0000 1.2
+++ search/org/eclipse/cdt/internal/core/search/CSearchScope.java 8 Aug 2003 15:38:23 -0000
@@ -16,15 +16,16 @@
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 @@
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 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 @@
}
} 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 @@
}
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());
+ }
+ }
+ }
}
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/ChangeLog,v
retrieving revision 1.133
diff -u -r1.133 ChangeLog
--- ChangeLog 1 Aug 2003 19:26:58 -0000 1.133
+++ ChangeLog 8 Aug 2003 15:41:26 -0000
@@ -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
Index: src/org/eclipse/cdt/internal/ui/search/CSearchScopeFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchScopeFactory.java,v
retrieving revision 1.1
diff -u -r1.1 CSearchScopeFactory.java
--- src/org/eclipse/cdt/internal/ui/search/CSearchScopeFactory.java 16 Jun 2003 17:35:44 -0000 1.1
+++ src/org/eclipse/cdt/internal/ui/search/CSearchScopeFactory.java 8 Aug 2003 15:41:27 -0000
@@ -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 @@
*/
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 @@
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 @@
// TODO Auto-generated method stub
return null;
}
-
+
}