mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-08 11:03:28 +02:00
Remove the workspace runnable when doing
setPathEntryCotainer() it was causing deadlock when an autobuild was trigger.
This commit is contained in:
parent
64e41fec18
commit
c1b98bfe79
1 changed files with 96 additions and 88 deletions
|
@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.core.model;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Hashtable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
|
@ -39,7 +40,6 @@ import org.eclipse.cdt.core.resources.IPathEntryStoreListener;
|
||||||
import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent;
|
import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.resources.IWorkspaceRunnable;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IConfigurationElement;
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
import org.eclipse.core.runtime.IExtension;
|
import org.eclipse.core.runtime.IExtension;
|
||||||
|
@ -66,14 +66,17 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
static final String[] NO_PREREQUISITES = new String[0];
|
static final String[] NO_PREREQUISITES = new String[0];
|
||||||
/**
|
/**
|
||||||
* pathentry containers pool
|
* pathentry containers pool
|
||||||
|
* accessing the Container is done synch with the class
|
||||||
*/
|
*/
|
||||||
public static HashMap Containers = new HashMap(5);
|
private static HashMap Containers = new HashMap(5);
|
||||||
|
|
||||||
static final IPathEntry[] NO_PATHENTRIES = new IPathEntry[0];
|
static final IPathEntry[] NO_PATHENTRIES = new IPathEntry[0];
|
||||||
|
|
||||||
HashMap resolvedMap = new HashMap();
|
// Synchronized the access of the cache entries.
|
||||||
|
private Map resolvedMap = new Hashtable();
|
||||||
|
|
||||||
HashMap storeMap = new HashMap();
|
// Accessing the map is synch with the class
|
||||||
|
private Map storeMap = new HashMap();
|
||||||
|
|
||||||
private static PathEntryManager pathEntryManager;
|
private static PathEntryManager pathEntryManager;
|
||||||
private PathEntryManager() {
|
private PathEntryManager() {
|
||||||
|
@ -82,7 +85,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
/**
|
/**
|
||||||
* Return the singleton.
|
* Return the singleton.
|
||||||
*/
|
*/
|
||||||
public static PathEntryManager getDefault() {
|
public static synchronized PathEntryManager getDefault() {
|
||||||
if (pathEntryManager == null) {
|
if (pathEntryManager == null) {
|
||||||
pathEntryManager = new PathEntryManager();
|
pathEntryManager = new PathEntryManager();
|
||||||
CoreModel.getDefault().addElementChangedListener(pathEntryManager);
|
CoreModel.getDefault().addElementChangedListener(pathEntryManager);
|
||||||
|
@ -351,9 +354,9 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
// filter out this project - does not reference the container
|
// filter out this project - does not reference the container path
|
||||||
// path
|
|
||||||
modifiedProjects[i] = null;
|
modifiedProjects[i] = null;
|
||||||
|
// Still add it to the cache
|
||||||
containerPut(affectedProject, containerPath, newContainer);
|
containerPut(affectedProject, containerPath, newContainer);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -372,14 +375,10 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// trigger model refresh
|
// trigger model refresh
|
||||||
try {
|
|
||||||
CoreModel.run(new IWorkspaceRunnable() {
|
|
||||||
|
|
||||||
public void run(IProgressMonitor progressMonitor) throws CoreException {
|
|
||||||
boolean shouldFire = false;
|
boolean shouldFire = false;
|
||||||
CModelManager mgr = CModelManager.getDefault();
|
CModelManager mgr = CModelManager.getDefault();
|
||||||
for (int i = 0; i < projectLength; i++) {
|
for (int i = 0; i < projectLength; i++) {
|
||||||
if (progressMonitor != null && progressMonitor.isCanceled()) {
|
if (monitor != null && monitor.isCanceled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ICProject affectedProject = modifiedProjects[i];
|
ICProject affectedProject = modifiedProjects[i];
|
||||||
|
@ -394,22 +393,11 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
mgr.registerCModelDelta(deltas[j]);
|
mgr.registerCModelDelta(deltas[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//affectedProject.setRawPathEntries(affectedProject.getRawPathEntries(),
|
|
||||||
// progressMonitor);
|
|
||||||
}
|
}
|
||||||
if (shouldFire) {
|
if (shouldFire) {
|
||||||
mgr.fire(ElementChangedEvent.POST_CHANGE);
|
mgr.fire(ElementChangedEvent.POST_CHANGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, monitor);
|
|
||||||
} catch (CoreException e) {
|
|
||||||
if (e instanceof CModelException) {
|
|
||||||
throw (CModelException) e;
|
|
||||||
} else {
|
|
||||||
throw new CModelException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IPathEntryContainer getPathEntryContainer(IContainerEntry entry, ICProject cproject) throws CModelException {
|
public IPathEntryContainer getPathEntryContainer(IContainerEntry entry, ICProject cproject) throws CModelException {
|
||||||
return getPathEntryContainer(entry.getPath(), cproject);
|
return getPathEntryContainer(entry.getPath(), cproject);
|
||||||
|
@ -495,25 +483,29 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized IPathEntryContainer containerGet(ICProject project, IPath containerPath) {
|
private synchronized IPathEntryContainer containerGet(ICProject cproject, IPath containerPath) {
|
||||||
Map projectContainers = (Map) Containers.get(project);
|
Map projectContainers = (Map) Containers.get(cproject);
|
||||||
if (projectContainers == null) {
|
if (projectContainers == null) {
|
||||||
projectContainers = new HashMap();
|
projectContainers = new HashMap();
|
||||||
Containers.put(project, projectContainers);
|
Containers.put(cproject, projectContainers);
|
||||||
}
|
}
|
||||||
IPathEntryContainer container = (IPathEntryContainer) projectContainers.get(containerPath);
|
IPathEntryContainer container = (IPathEntryContainer) projectContainers.get(containerPath);
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void containerPut(ICProject project, IPath containerPath, IPathEntryContainer container) {
|
private synchronized void containerPut(ICProject cproject, IPath containerPath, IPathEntryContainer container) {
|
||||||
Map projectContainers = (Map) Containers.get(project);
|
Map projectContainers = (Map) Containers.get(cproject);
|
||||||
if (projectContainers == null) {
|
if (projectContainers == null) {
|
||||||
projectContainers = new HashMap();
|
projectContainers = new HashMap();
|
||||||
Containers.put(project, projectContainers);
|
Containers.put(cproject, projectContainers);
|
||||||
}
|
}
|
||||||
projectContainers.put(containerPath, container);
|
projectContainers.put(containerPath, container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized void containerRemove(ICProject cproject) {
|
||||||
|
Containers.remove(cproject);
|
||||||
|
}
|
||||||
|
|
||||||
public String[] projectPrerequisites(IPathEntry[] entries) throws CModelException {
|
public String[] projectPrerequisites(IPathEntry[] entries) throws CModelException {
|
||||||
if (entries != null) {
|
if (entries != null) {
|
||||||
ArrayList prerequisites = new ArrayList();
|
ArrayList prerequisites = new ArrayList();
|
||||||
|
@ -548,10 +540,10 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
|
|
||||||
// Sanity checks
|
// Sanity checks
|
||||||
if (oldEntries == null) {
|
if (oldEntries == null) {
|
||||||
oldEntries = new IPathEntry[0];
|
oldEntries = NO_PATHENTRIES;
|
||||||
}
|
}
|
||||||
if (newEntries == null) {
|
if (newEntries == null) {
|
||||||
newEntries = new IPathEntry[0];
|
newEntries = NO_PATHENTRIES;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the removed entries.
|
// Check the removed entries.
|
||||||
|
@ -689,7 +681,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
return containerIDs;
|
return containerIDs;
|
||||||
}
|
}
|
||||||
|
|
||||||
IPathEntryStore getPathEntryStore(IProject project) throws CoreException {
|
private synchronized IPathEntryStore getPathEntryStore(IProject project) throws CoreException {
|
||||||
IPathEntryStore store = (IPathEntryStore)storeMap.get(project);
|
IPathEntryStore store = (IPathEntryStore)storeMap.get(project);
|
||||||
if (store == null) {
|
if (store == null) {
|
||||||
store = CCorePlugin.getDefault().getPathEntryStore(project);
|
store = CCorePlugin.getDefault().getPathEntryStore(project);
|
||||||
|
@ -699,6 +691,10 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized Object removePathEntryStore(IProject project) {
|
||||||
|
return storeMap.remove(project);
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.resources.IPathEntryStoreListener#pathEntryStoreChanged(org.eclipse.cdt.core.resources.PathEntryChangedEvent)
|
* @see org.eclipse.cdt.core.resources.IPathEntryStoreListener#pathEntryStoreChanged(org.eclipse.cdt.core.resources.PathEntryChangedEvent)
|
||||||
*/
|
*/
|
||||||
|
@ -710,20 +706,24 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IPathEntryStore store = (IPathEntryStore)storeMap.get(project);
|
|
||||||
if (store != null) {
|
|
||||||
if (event.hasClosed()) {
|
|
||||||
storeMap.remove(project);
|
|
||||||
store.removePathEntryStoreListener(this);
|
|
||||||
Containers.remove(project);
|
|
||||||
}
|
|
||||||
CModelManager manager = CModelManager.getDefault();
|
CModelManager manager = CModelManager.getDefault();
|
||||||
ICProject cproject = manager.create(project);
|
ICProject cproject = manager.create(project);
|
||||||
|
try {
|
||||||
|
IPathEntryStore store = getPathEntryStore(project);
|
||||||
|
if (store != null) {
|
||||||
|
if (event.hasClosed()) {
|
||||||
|
removePathEntryStore(project);
|
||||||
|
store.removePathEntryStoreListener(this);
|
||||||
|
containerRemove(cproject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
if (project.isAccessible()) {
|
if (project.isAccessible()) {
|
||||||
try {
|
try {
|
||||||
IPathEntry[] oldResolvedEntries = getResolvedPathEntries(cproject);
|
|
||||||
// Clear the old cache entries.
|
// Clear the old cache entries.
|
||||||
resolvedMap.remove(cproject);
|
IPathEntry[] oldResolvedEntries = (IPathEntry[])resolvedMap.remove(cproject);
|
||||||
IPathEntry[] newResolvedEntries = getResolvedPathEntries(cproject);
|
IPathEntry[] newResolvedEntries = getResolvedPathEntries(cproject);
|
||||||
ICElementDelta[] deltas = generatePathEntryDeltas(cproject, oldResolvedEntries, newResolvedEntries);
|
ICElementDelta[] deltas = generatePathEntryDeltas(cproject, oldResolvedEntries, newResolvedEntries);
|
||||||
if (deltas.length > 0) {
|
if (deltas.length > 0) {
|
||||||
|
@ -734,10 +734,11 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
manager.fire(ElementChangedEvent.POST_CHANGE);
|
manager.fire(ElementChangedEvent.POST_CHANGE);
|
||||||
}
|
}
|
||||||
} catch (CModelException e) {
|
} catch (CModelException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resolvedMap.remove(cproject);
|
resolvedMap.remove(cproject);
|
||||||
}
|
containerRemove(cproject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -761,13 +762,21 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
// handle closing and removing of projects
|
// handle closing and removing of projects
|
||||||
if (((flags & ICElementDelta.F_CLOSED) != 0) || (kind == ICElementDelta.REMOVED)) {
|
if (((flags & ICElementDelta.F_CLOSED) != 0) || (kind == ICElementDelta.REMOVED)) {
|
||||||
if (element.getElementType() == ICElement.C_PROJECT) {
|
if (element.getElementType() == ICElement.C_PROJECT) {
|
||||||
IProject project = element.getCProject().getProject();
|
ICProject cproject = (ICProject)element;
|
||||||
IPathEntryStore store = (IPathEntryStore)storeMap.get(project);
|
IProject project = cproject.getProject();
|
||||||
|
IPathEntryStore store = null;
|
||||||
|
try {
|
||||||
|
store = getPathEntryStore(project);
|
||||||
if (store != null) {
|
if (store != null) {
|
||||||
store.fireClosedEvent(project);
|
store.fireClosedEvent(project);
|
||||||
} else {
|
}
|
||||||
resolvedMap.remove(element.getCProject());
|
} catch (CoreException e) {
|
||||||
Containers.remove(project);
|
throw new CModelException(e);
|
||||||
|
} finally {
|
||||||
|
if (store == null) {
|
||||||
|
resolvedMap.remove(cproject);
|
||||||
|
containerRemove(cproject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -815,5 +824,4 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue