1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

Fix for 45835 also changed binary runner control to stop running when project closes/open/deleted

This commit is contained in:
David Inglis 2003-11-06 19:52:40 +00:00
parent 39f8ff8c86
commit 436e271263
3 changed files with 89 additions and 45 deletions

View file

@ -1,4 +1,11 @@
2003-10-29 David Inglis
2003-11-06 David Inglis
Fix for 45835 also changed binary runner control to stop running when project closes/open/deleted
* model/org/eclipse/cdt/internal/core/CModelManager.java
* model/org/eclipse/cdt/internal/core/BinaryRunner.java
2003-11-06 David Inglis
Futher changes for 45736

View file

@ -10,59 +10,72 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;
public class BinaryRunner extends Thread {
ArchiveContainer clib;
BinaryContainer cbin;
ICProject cproject;
CModelManager factory;
public class BinaryRunner {
IProject project;
Thread runner;
public BinaryRunner(IProject prj) {
project = prj;
}
public void start() {
runner = new Thread(new Runnable() {
public void run() {
ICProject cproject = CModelManager.getDefault().create(project);
ArchiveContainer clib;
BinaryContainer cbin;
cbin = (BinaryContainer)cproject.getBinaryContainer();
clib = (ArchiveContainer)cproject.getArchiveContainer();
clib.removeChildren();
cbin.removeChildren();
try {
cproject.getProject().accept(new Visitor(BinaryRunner.this));
} catch (CoreException e) {
//e.printStackTrace();
} catch (Exception e) {
// What is wrong ?
e.printStackTrace();
}
if (!Thread.currentThread().isInterrupted()) {
fireEvents(cproject, cbin);
fireEvents(cproject, clib);
}
// Tell the listeners we are done.
synchronized(BinaryRunner.this) {
BinaryRunner.this.notifyAll();
runner = null;
}
}
public BinaryRunner(ICProject cprj) {
super("Binary Search Thread");
cproject = cprj;
cbin = (BinaryContainer)cprj.getBinaryContainer();
clib = (ArchiveContainer)cprj.getArchiveContainer();
factory = CModelManager.getDefault();
start();
}, "Binary Search Thread");
runner.start();
}
public void run() {
clib.removeChildren();
cbin.removeChildren();
try {
cproject.getProject().accept(new Visitor(this));
} catch (CoreException e) {
//e.printStackTrace();
} catch (Exception e) {
// What is wrong ?
e.printStackTrace();
}
if (!isInterrupted()) {
fireEvents(cbin);
fireEvents(clib);
}
// Tell the listeners we are done.
synchronized(this) {
notifyAll();
}
}
/**
* wrap the wait call and the interrupteException.
*/
public synchronized void waitIfRunning() {
while (isAlive()) {
while (runner != null && runner.isAlive()) {
try {
wait();
} catch (InterruptedException e) {
}
}
}
public void stop() {
if ( runner != null && runner.isAlive()) {
runner.interrupt();
}
}
public void fireEvents(Parent container) {
void fireEvents(ICProject cproject, Parent container) {
// Fired the event.
ICElement[] children = container.getChildren();
if (children.length > 0) {
@ -80,6 +93,7 @@ public class BinaryRunner extends Thread {
}
void addChildIfBinary(IFile file) {
CModelManager factory = CModelManager.getDefault();
// Attempt to speed things up by rejecting up front
// Things we know should not be Binary files.
if (!factory.isTranslationUnit(file)) {

View file

@ -188,7 +188,7 @@ public class CModelManager implements IResourceChangeListener {
case IResource.FOLDER :
return create(parent, (IFolder)resource);
case IResource.ROOT :
return create(parent, (IWorkspaceRoot)resource);
return create((IWorkspaceRoot)resource);
default :
return null;
}
@ -373,6 +373,10 @@ public class CModelManager implements IResourceChangeListener {
// so we have to recall create again.
releaseCElement(celement);
celement = create(project);
Parent parent = (Parent)celement.getParent();
CElementInfo info = (CElementInfo)parent.getElementInfo();
info.addChild(celement);
// Fired and ICElementDelta.PARSER_CHANGED
CElementDelta delta = new CElementDelta(getCModel());
delta.binaryParserChanged(celement);
@ -500,13 +504,14 @@ public class CModelManager implements IResourceChangeListener {
return ok;
}
public BinaryRunner getBinaryRunner(ICProject cProject) {
public BinaryRunner getBinaryRunner(ICProject project) {
BinaryRunner runner = null;
synchronized(binaryRunners) {
runner = (BinaryRunner)binaryRunners.get(cProject);
runner = (BinaryRunner)binaryRunners.get(project.getProject());
if (runner == null) {
runner = new BinaryRunner(cProject);
binaryRunners.put(cProject, runner);
runner = new BinaryRunner(project.getProject());
binaryRunners.put(project.getProject(), runner);
runner.start();
}
}
return runner;
@ -725,8 +730,24 @@ public class CModelManager implements IResourceChangeListener {
}
break;
case IResource.PROJECT :
// TO BE COMPLETED ...
break;
if (0 != (delta.getFlags() & IResourceDelta.OPEN)) {
IProject project = (IProject) resource;
if (!project.isOpen()) {
// project closing... stop the runner.
BinaryRunner runner = (BinaryRunner)binaryRunners.get(project);
if (runner != null ) {
runner.stop();
}
} else {
if ( binaryRunners.get(project) == null ) {
// project opening... lets add the runner to the
// map but no need to start it since the deltas
// will populate containers
binaryRunners.put(project, new BinaryRunner(project));
}
}
}
break;
}
}
/**
@ -784,9 +805,7 @@ public class CModelManager implements IResourceChangeListener {
BinaryRunner[] runners = (BinaryRunner[])binaryRunners.values().toArray(new BinaryRunner[0]);
for (int i = 0; i < runners.length; i++) {
if (runners[i].isAlive()) {
runners[i].interrupt();
}
runners[i].stop();
}
}
@ -797,5 +816,9 @@ public class CModelManager implements IResourceChangeListener {
public void deleting(IProject project){
// discard all indexing jobs for this project
this.getIndexManager().discardJobs(project.getName());
BinaryRunner runner = (BinaryRunner) binaryRunners.remove(project);
if (runner != null) {
runner.stop();
}
}
}