1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 09:15:38 +02:00

Handles closing of projects while indexing

This commit is contained in:
Markus Schorn 2006-12-01 13:15:59 +00:00
parent da9aa45994
commit 6480d32c60
6 changed files with 73 additions and 50 deletions

View file

@ -65,6 +65,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.content.IContentTypeManager.ContentTypeChangeEvent; import org.eclipse.core.runtime.content.IContentTypeManager.ContentTypeChangeEvent;
import org.eclipse.core.runtime.content.IContentTypeManager.IContentTypeChangeListener; import org.eclipse.core.runtime.content.IContentTypeManager.IContentTypeChangeListener;
@ -753,6 +754,16 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
} }
break; break;
case IResourceChangeEvent.PRE_CLOSE :
try {
if (resource.getType() == IResource.PROJECT &&
( ((IProject)resource).hasNature(CProjectNature.C_NATURE_ID) ||
((IProject)resource).hasNature(CCProjectNature.CC_NATURE_ID) )){
this.closing((IProject) resource, delta);}
} catch (CoreException e) {
}
break;
case IResourceChangeEvent.POST_CHANGE : case IResourceChangeEvent.POST_CHANGE :
try { try {
if (delta != null) { if (delta != null) {
@ -934,7 +945,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
start = System.currentTimeMillis(); start = System.currentTimeMillis();
} }
// wrap callbacks with Safe runnable for subsequent listeners to be called when some are causing grief // wrap callbacks with Safe runnable for subsequent listeners to be called when some are causing grief
Platform.run(new ISafeRunnable() { SafeRunner.run(new ISafeRunnable() {
public void handleException(Throwable exception) { public void handleException(Throwable exception) {
//CCorePlugin.log(exception, "Exception occurred in listener of C element change notification"); //$NON-NLS-1$ //CCorePlugin.log(exception, "Exception occurred in listener of C element change notification"); //$NON-NLS-1$
@ -1153,4 +1164,11 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
CCoreInternals.getPDOMManager().deleteProject(create(project), delta); CCoreInternals.getPDOMManager().deleteProject(create(project), delta);
} }
private void closing(IProject project, IResourceDelta delta) {
// stop the binary runner for this project
removeBinaryRunner(project);
// stop indexing jobs for this project
CCoreInternals.getPDOMManager().removeProject(create(project));
}
} }

View file

@ -93,7 +93,7 @@ public class DefaultPathEntryStore implements IPathEntryStore, ICDescriptorListe
NodeList list = element.getChildNodes(); NodeList list = element.getChildNodes();
for (int i = 0; i < list.getLength(); i++) { for (int i = 0; i < list.getLength(); i++) {
Node childNode = list.item(i); Node childNode = list.item(i);
if (childNode.getNodeType() == Node.ELEMENT_NODE) { if (childNode != null && childNode.getNodeType() == Node.ELEMENT_NODE) {
if (childNode.getNodeName().equals(PATH_ENTRY)) { if (childNode.getNodeName().equals(PATH_ENTRY)) {
pathEntries.add(decodePathEntry(fProject, (Element) childNode)); pathEntries.add(decodePathEntry(fProject, (Element) childNode));
} }

View file

@ -64,7 +64,7 @@ public class CModelListener implements IElementChangedListener {
fManager.changeProject(project, delta); fManager.changeProject(project, delta);
break; break;
case ICElementDelta.REMOVED: case ICElementDelta.REMOVED:
fManager.removeProject(project); // handled on pre-close and pre-delete
break; break;
} }
} }

View file

@ -76,7 +76,6 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
private static final QualifiedName indexerProperty= new QualifiedName(CCorePlugin.PLUGIN_ID, "pdomIndexer"); //$NON-NLS-1$ private static final QualifiedName indexerProperty= new QualifiedName(CCorePlugin.PLUGIN_ID, "pdomIndexer"); //$NON-NLS-1$
private static final QualifiedName dbNameProperty= new QualifiedName(CCorePlugin.PLUGIN_ID, "pdomName"); //$NON-NLS-1$ private static final QualifiedName dbNameProperty= new QualifiedName(CCorePlugin.PLUGIN_ID, "pdomName"); //$NON-NLS-1$
private static final QualifiedName pdomProperty= new QualifiedName(CCorePlugin.PLUGIN_ID, "pdom"); //$NON-NLS-1$
public static final String INDEXER_ID_KEY = "indexerId"; //$NON-NLS-1$ public static final String INDEXER_ID_KEY = "indexerId"; //$NON-NLS-1$
public static final String INDEX_ALL_FILES = "indexAllFiles"; //$NON-NLS-1$ public static final String INDEX_ALL_FILES = "indexAllFiles"; //$NON-NLS-1$
@ -102,7 +101,8 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
/** /**
* Stores mapping from pdom to project, used to serialize\ creation of new pdoms. * Stores mapping from pdom to project, used to serialize\ creation of new pdoms.
*/ */
private Map fPDOMs= new HashMap(); private Map fProjectToPDOM= new HashMap();
private Map fLocationToCProject= new HashMap();
private ListenerList fChangeListeners= new ListenerList(); private ListenerList fChangeListeners= new ListenerList();
private ListenerList fStateListeners= new ListenerList(); private ListenerList fStateListeners= new ListenerList();
@ -145,48 +145,44 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
} }
public IPDOM getPDOM(ICProject project) throws CoreException { public IPDOM getPDOM(ICProject project) throws CoreException {
synchronized (fPDOMs) { synchronized (fProjectToPDOM) {
IProject rproject = project.getProject(); IProject rproject = project.getProject();
WritablePDOM pdom = (WritablePDOM)rproject.getSessionProperty(pdomProperty); WritablePDOM pdom = (WritablePDOM) fProjectToPDOM.get(rproject);
if (pdom != null) { if (pdom != null) {
ICProject oldProject= (ICProject) fPDOMs.get(pdom);
if (project.equals(oldProject)) {
return pdom; return pdom;
} }
if (oldProject != null && oldProject.getProject().exists()) { String dbName= rproject.getPersistentProperty(dbNameProperty);
// old project exists, don't use pdom IPath dbPath= null;
String dbName= getDefaultName(project); if (dbName != null) {
rproject.setPersistentProperty(dbNameProperty, dbName); dbPath= CCorePlugin.getDefault().getStateLocation().append(dbName);
ICProject currentCOwner= (ICProject) fLocationToCProject.get(dbPath);
if (currentCOwner != null) {
IProject currentOwner= currentCOwner.getProject();
if (currentOwner.exists()) {
dbName= null;
dbPath= null;
} }
else { else {
// pdom can be reused, as the other project has gone pdom= (WritablePDOM) fProjectToPDOM.remove(currentOwner);
fPDOMs.put(pdom, project); fLocationToCProject.remove(dbPath);
return pdom;
}
}
// make sure we get a unique name.
String dbName= rproject.getPersistentProperty(dbNameProperty);
if (dbName != null) {
IPath dbPath= CCorePlugin.getDefault().getStateLocation().append(dbName);
for (Iterator iter = fPDOMs.keySet().iterator(); dbName != null && iter.hasNext();) {
PDOM existingPDOM = (PDOM) iter.next();
if (existingPDOM.getPath().equals(dbPath)) {
dbName= null;
} }
} }
} }
if (pdom == null) {
if (dbName == null) { if (dbName == null) {
dbName = getDefaultName(project); dbName= getDefaultName(project);
rproject.setPersistentProperty(dbNameProperty, dbName); rproject.setPersistentProperty(dbNameProperty, dbName);
dbPath= CCorePlugin.getDefault().getStateLocation().append(dbName);
} }
IPath dbPath = CCorePlugin.getDefault().getStateLocation().append(dbName);
pdom = new WritablePDOM(dbPath); pdom = new WritablePDOM(dbPath);
pdom.addListener(this); pdom.addListener(this);
rproject.setSessionProperty(pdomProperty, pdom); }
fPDOMs.put(pdom, project);
fLocationToCProject.put(dbPath, project);
fProjectToPDOM.put(rproject, pdom);
return pdom; return pdom;
} }
} }
@ -330,7 +326,7 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
} }
private void changeIndexer(ICProject cproject) throws CoreException { private void changeIndexer(ICProject cproject) throws CoreException {
assert !Thread.holdsLock(fPDOMs); assert !Thread.holdsLock(fProjectToPDOM);
IPDOMIndexer oldIndexer= null; IPDOMIndexer oldIndexer= null;
String newid= getIndexerId(cproject); String newid= getIndexerId(cproject);
boolean allFiles= getIndexAllFiles(cproject); boolean allFiles= getIndexAllFiles(cproject);
@ -351,7 +347,7 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
} }
public IPDOMIndexer getIndexer(ICProject project, boolean create) { public IPDOMIndexer getIndexer(ICProject project, boolean create) {
assert !Thread.holdsLock(fPDOMs); assert !Thread.holdsLock(fProjectToPDOM);
synchronized (fIndexerMutex) { synchronized (fIndexerMutex) {
IProject rproject = project.getProject(); IProject rproject = project.getProject();
if (!rproject.isOpen()) { if (!rproject.isOpen()) {
@ -500,7 +496,7 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
} }
public void removeProject(ICProject project) throws CoreException { public void removeProject(ICProject project) {
IPDOMIndexer indexer= getIndexer(project, false); IPDOMIndexer indexer= getIndexer(project, false);
if (indexer != null) { if (indexer != null) {
stopIndexer(indexer); stopIndexer(indexer);
@ -554,7 +550,7 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
} }
public void reindex(ICProject project) throws CoreException { public void reindex(ICProject project) throws CoreException {
assert !Thread.holdsLock(fPDOMs); assert !Thread.holdsLock(fProjectToPDOM);
IPDOMIndexer indexer= null; IPDOMIndexer indexer= null;
synchronized (fIndexerMutex) { synchronized (fIndexerMutex) {
indexer= getIndexer(project, false); indexer= getIndexer(project, false);
@ -627,8 +623,8 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
} }
ICProject project; ICProject project;
synchronized (fPDOMs) { synchronized (fProjectToPDOM) {
project = (ICProject) fPDOMs.get(pdom); project = (ICProject) fLocationToCProject.get(pdom.getPath());
} }
if (project != null) { if (project != null) {

View file

@ -148,7 +148,9 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
break; break;
case ICElement.C_CCONTAINER: case ICElement.C_CCONTAINER:
ICContainer folder= (ICContainer) element; ICContainer folder= (ICContainer) element;
if (delta.getKind() == ICElementDelta.ADDED) {
collectSources(folder, added, added, allFiles); collectSources(folder, added, added, allFiles);
}
break; break;
} }

View file

@ -185,7 +185,11 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
public Object[] getChildren(Object parentElement) { public Object[] getChildren(Object parentElement) {
try { try {
if (parentElement instanceof ICProject) { if (parentElement instanceof ICProject) {
PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM((ICProject)parentElement); ICProject cproject= (ICProject)parentElement;
if (!cproject.getProject().isOpen()) {
return new Object[0];
}
PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject);
PDOMLinkage[] linkages= pdom.getLinkages(); PDOMLinkage[] linkages= pdom.getLinkages();
if (linkages.length == 1) { if (linkages.length == 1) {
// Skip linkages in hierarchy if there is only one // Skip linkages in hierarchy if there is only one
@ -215,7 +219,11 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
public boolean hasChildren(Object element) { public boolean hasChildren(Object element) {
try { try {
if (element instanceof ICProject) { if (element instanceof ICProject) {
PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM((ICProject)element); ICProject cproject= (ICProject)element;
if (!cproject.getProject().isOpen()) {
return false;
}
PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject);
PDOMLinkage[] linkages = pdom.getLinkages(); PDOMLinkage[] linkages = pdom.getLinkages();
if (linkages.length == 0) if (linkages.length == 0)
return false; return false;
@ -328,7 +336,6 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(projects[i]); PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(projects[i]);
pdom.removeListener(this); pdom.removeListener(this);
} }
viewer.setChildCount(model, projects.length);
} catch (CoreException e) { } catch (CoreException e) {
CUIPlugin.getDefault().log(e); CUIPlugin.getDefault().log(e);
} }