mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-09 01:05:38 +02:00
Handles closing of projects while indexing
This commit is contained in:
parent
da9aa45994
commit
6480d32c60
6 changed files with 73 additions and 50 deletions
|
@ -65,6 +65,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.ISafeRunnable;
|
||||
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.IContentTypeChangeListener;
|
||||
|
||||
|
@ -745,10 +746,20 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
|||
switch (event.getType()) {
|
||||
case IResourceChangeEvent.PRE_DELETE :
|
||||
try {
|
||||
if (resource.getType() == IResource.PROJECT &&
|
||||
( ((IProject)resource).hasNature(CProjectNature.C_NATURE_ID) ||
|
||||
((IProject)resource).hasNature(CCProjectNature.CC_NATURE_ID) )){
|
||||
this.deleting((IProject) resource, delta);}
|
||||
if (resource.getType() == IResource.PROJECT &&
|
||||
( ((IProject)resource).hasNature(CProjectNature.C_NATURE_ID) ||
|
||||
((IProject)resource).hasNature(CCProjectNature.CC_NATURE_ID) )){
|
||||
this.deleting((IProject) resource, delta);}
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
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;
|
||||
|
@ -934,7 +945,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
|||
start = System.currentTimeMillis();
|
||||
}
|
||||
// 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) {
|
||||
//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);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ public class DefaultPathEntryStore implements IPathEntryStore, ICDescriptorListe
|
|||
NodeList list = element.getChildNodes();
|
||||
for (int i = 0; i < list.getLength(); 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)) {
|
||||
pathEntries.add(decodePathEntry(fProject, (Element) childNode));
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public class CModelListener implements IElementChangedListener {
|
|||
fManager.changeProject(project, delta);
|
||||
break;
|
||||
case ICElementDelta.REMOVED:
|
||||
fManager.removeProject(project);
|
||||
// handled on pre-close and pre-delete
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 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 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.
|
||||
*/
|
||||
private Map fPDOMs= new HashMap();
|
||||
private Map fProjectToPDOM= new HashMap();
|
||||
private Map fLocationToCProject= new HashMap();
|
||||
private ListenerList fChangeListeners= 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 {
|
||||
synchronized (fPDOMs) {
|
||||
synchronized (fProjectToPDOM) {
|
||||
IProject rproject = project.getProject();
|
||||
WritablePDOM pdom = (WritablePDOM)rproject.getSessionProperty(pdomProperty);
|
||||
WritablePDOM pdom = (WritablePDOM) fProjectToPDOM.get(rproject);
|
||||
if (pdom != null) {
|
||||
ICProject oldProject= (ICProject) fPDOMs.get(pdom);
|
||||
if (project.equals(oldProject)) {
|
||||
return pdom;
|
||||
}
|
||||
return pdom;
|
||||
}
|
||||
|
||||
if (oldProject != null && oldProject.getProject().exists()) {
|
||||
// old project exists, don't use pdom
|
||||
String dbName= getDefaultName(project);
|
||||
rproject.setPersistentProperty(dbNameProperty, dbName);
|
||||
}
|
||||
else {
|
||||
// pdom can be reused, as the other project has gone
|
||||
fPDOMs.put(pdom, project);
|
||||
return pdom;
|
||||
}
|
||||
}
|
||||
|
||||
// make sure we get a unique name.
|
||||
String dbName= rproject.getPersistentProperty(dbNameProperty);
|
||||
IPath dbPath= null;
|
||||
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)) {
|
||||
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 {
|
||||
pdom= (WritablePDOM) fProjectToPDOM.remove(currentOwner);
|
||||
fLocationToCProject.remove(dbPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pdom == null) {
|
||||
if (dbName == null) {
|
||||
dbName= getDefaultName(project);
|
||||
rproject.setPersistentProperty(dbNameProperty, dbName);
|
||||
dbPath= CCorePlugin.getDefault().getStateLocation().append(dbName);
|
||||
}
|
||||
|
||||
if (dbName == null) {
|
||||
dbName = getDefaultName(project);
|
||||
rproject.setPersistentProperty(dbNameProperty, dbName);
|
||||
pdom = new WritablePDOM(dbPath);
|
||||
pdom.addListener(this);
|
||||
}
|
||||
IPath dbPath = CCorePlugin.getDefault().getStateLocation().append(dbName);
|
||||
pdom = new WritablePDOM(dbPath);
|
||||
pdom.addListener(this);
|
||||
rproject.setSessionProperty(pdomProperty, pdom);
|
||||
fPDOMs.put(pdom, project);
|
||||
|
||||
fLocationToCProject.put(dbPath, project);
|
||||
fProjectToPDOM.put(rproject, pdom);
|
||||
return pdom;
|
||||
}
|
||||
}
|
||||
|
@ -330,7 +326,7 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
|
|||
}
|
||||
|
||||
private void changeIndexer(ICProject cproject) throws CoreException {
|
||||
assert !Thread.holdsLock(fPDOMs);
|
||||
assert !Thread.holdsLock(fProjectToPDOM);
|
||||
IPDOMIndexer oldIndexer= null;
|
||||
String newid= getIndexerId(cproject);
|
||||
boolean allFiles= getIndexAllFiles(cproject);
|
||||
|
@ -351,7 +347,7 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
|
|||
}
|
||||
|
||||
public IPDOMIndexer getIndexer(ICProject project, boolean create) {
|
||||
assert !Thread.holdsLock(fPDOMs);
|
||||
assert !Thread.holdsLock(fProjectToPDOM);
|
||||
synchronized (fIndexerMutex) {
|
||||
IProject rproject = project.getProject();
|
||||
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);
|
||||
if (indexer != null) {
|
||||
stopIndexer(indexer);
|
||||
|
@ -554,7 +550,7 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
|
|||
}
|
||||
|
||||
public void reindex(ICProject project) throws CoreException {
|
||||
assert !Thread.holdsLock(fPDOMs);
|
||||
assert !Thread.holdsLock(fProjectToPDOM);
|
||||
IPDOMIndexer indexer= null;
|
||||
synchronized (fIndexerMutex) {
|
||||
indexer= getIndexer(project, false);
|
||||
|
@ -627,8 +623,8 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
|
|||
}
|
||||
|
||||
ICProject project;
|
||||
synchronized (fPDOMs) {
|
||||
project = (ICProject) fPDOMs.get(pdom);
|
||||
synchronized (fProjectToPDOM) {
|
||||
project = (ICProject) fLocationToCProject.get(pdom.getPath());
|
||||
}
|
||||
|
||||
if (project != null) {
|
||||
|
|
|
@ -148,7 +148,9 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
|
|||
break;
|
||||
case ICElement.C_CCONTAINER:
|
||||
ICContainer folder= (ICContainer) element;
|
||||
collectSources(folder, added, added, allFiles);
|
||||
if (delta.getKind() == ICElementDelta.ADDED) {
|
||||
collectSources(folder, added, added, allFiles);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -185,7 +185,11 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
|
|||
public Object[] getChildren(Object parentElement) {
|
||||
try {
|
||||
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();
|
||||
if (linkages.length == 1) {
|
||||
// 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) {
|
||||
try {
|
||||
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();
|
||||
if (linkages.length == 0)
|
||||
return false;
|
||||
|
@ -328,7 +336,6 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
|
|||
PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(projects[i]);
|
||||
pdom.removeListener(this);
|
||||
}
|
||||
viewer.setChildCount(model, projects.length);
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue