1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 17:26:01 +02:00

fixed syncing of binary runner and getBinaries()

This commit is contained in:
David Inglis 2004-04-06 17:57:10 +00:00
parent b06853641e
commit 84c89baed2
2 changed files with 40 additions and 83 deletions

View file

@ -1,3 +1,9 @@
2004-04-06 David Inglis
Fixed up syncing of binary runner and ::getBinaries()
* model/org/eclipse/cdt/internal/core/model/BinaryRunner.java
2004-04-04 Alain Magloire 2004-04-04 Alain Magloire
More support for external headers. More support for external headers.

View file

@ -1,8 +1,7 @@
package org.eclipse.cdt.internal.core.model; package org.eclipse.cdt.internal.core.model;
/* /*
* (c) Copyright QNX Software Systems Ltd. 2002. * (c) Copyright QNX Software Systems Ltd. 2002. All Rights Reserved.
* All Rights Reserved.
*/ */
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
@ -19,76 +18,64 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
public class BinaryRunner implements IJobChangeListener { public class BinaryRunner {
IProject project;
ICProject cproject; ICProject cproject;
Job runner; Job runner;
ArchiveContainer vlib;
BinaryContainer vbin;
boolean done = false;
public BinaryRunner(IProject prj) { public BinaryRunner(IProject prj) {
project = prj; cproject = CModelManager.getDefault().create(prj);
cproject = CModelManager.getDefault().create(project);
} }
public void start() { public void start() {
String taskName = CCorePlugin.getResourceString("CoreModel.BinaryRunner.Binary_Search_Thread"); //$NON-NLS-1 String taskName = CCorePlugin.getResourceString("CoreModel.BinaryRunner.Binary_Search_Thread"); //$NON-NLS-1$
Job runner = new Job(taskName) { runner = new Job(taskName) {
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/ */
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
if (cproject == null || Thread.currentThread().isInterrupted()) { if (cproject == null || monitor.isCanceled()) {
return Status.CANCEL_STATUS; return Status.CANCEL_STATUS;
} }
vbin = (BinaryContainer)cproject.getBinaryContainer(); BinaryContainer vbin = (BinaryContainer) cproject.getBinaryContainer();
vlib = (ArchiveContainer)cproject.getArchiveContainer(); ArchiveContainer vlib = (ArchiveContainer) cproject.getArchiveContainer();
vlib.removeChildren(); vlib.removeChildren();
vbin.removeChildren(); vbin.removeChildren();
try { try {
project.accept(new Visitor(BinaryRunner.this)); cproject.getProject().accept(new Visitor(BinaryRunner.this, monitor));
} catch (CoreException e) { } catch (CoreException e) {
//e.printStackTrace(); return e.getStatus();
} catch (Exception e) {
// What is wrong ?
e.printStackTrace();
} }
if (!Thread.currentThread().isInterrupted()) { if (monitor.isCanceled()) {
fireEvents(cproject, vbin); fireEvents(cproject, vbin);
fireEvents(cproject, vlib); fireEvents(cproject, vlib);
} }
// Tell the listeners we are done.
synchronized(BinaryRunner.this) {
BinaryRunner.this.notifyAll();
BinaryRunner.this.runner = null;
}
return Status.OK_STATUS; return Status.OK_STATUS;
} }
}; };
runner.schedule(); runner.schedule();
}
}
/** /**
* wrap the wait call and the interrupteException. * wrap the wait call and the interrupteException.
*/ */
public synchronized void waitIfRunning() { public void waitIfRunning() {
while (runner != null && !done) { if (runner != null) {
try { try {
wait(); runner.join();
} catch (InterruptedException e) { } catch (InterruptedException e) {
} }
} }
} }
public void stop() { public void stop() {
if ( runner != null && !done) { if (runner != null && runner.getState() == Job.RUNNING) {
runner.cancel(); runner.cancel();
} }
} }
@ -98,7 +85,7 @@ public class BinaryRunner implements IJobChangeListener {
ICElement[] children = container.getChildren(); ICElement[] children = container.getChildren();
if (children.length > 0) { if (children.length > 0) {
CModelManager factory = CModelManager.getDefault(); CModelManager factory = CModelManager.getDefault();
ICElement root = (ICModel)factory.getCModel(); ICElement root = (ICModel) factory.getCModel();
CElementDelta cdelta = new CElementDelta(root); CElementDelta cdelta = new CElementDelta(root);
cdelta.added(cproject); cdelta.added(cproject);
cdelta.added(container); cdelta.added(container);
@ -124,20 +111,23 @@ public class BinaryRunner implements IJobChangeListener {
} }
class Visitor implements IResourceVisitor { class Visitor implements IResourceVisitor {
BinaryRunner runner;
public Visitor (BinaryRunner r) { private BinaryRunner vRunner;
runner = r; private IProgressMonitor vMonitor;
public Visitor(BinaryRunner r, IProgressMonitor monitor) {
vRunner = r;
vMonitor = monitor;
} }
public boolean visit(IResource res) throws CoreException { public boolean visit(IResource res) throws CoreException {
if (Thread.currentThread().isInterrupted()) { if (vMonitor.isCanceled()) {
return false; return false;
} }
if (cproject.isOnOutputEntry(res)) { if (cproject.isOnOutputEntry(res)) {
if (res instanceof IFile) { if (res instanceof IFile) {
if (runner != null) { if (vRunner != null) {
runner.addChildIfBinary((IFile)res); vRunner.addChildIfBinary((IFile) res);
} }
return false; return false;
} }
@ -145,43 +135,4 @@ public class BinaryRunner implements IJobChangeListener {
return true; return true;
} }
} }
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.IJobChangeListener#aboutToRun(org.eclipse.core.runtime.jobs.IJobChangeEvent)
*/
public void aboutToRun(IJobChangeEvent event) {
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.IJobChangeListener#awake(org.eclipse.core.runtime.jobs.IJobChangeEvent)
*/
public void awake(IJobChangeEvent event) {
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.IJobChangeListener#done(org.eclipse.core.runtime.jobs.IJobChangeEvent)
*/
public void done(IJobChangeEvent event) {
done = true;
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.IJobChangeListener#running(org.eclipse.core.runtime.jobs.IJobChangeEvent)
*/
public void running(IJobChangeEvent event) {
done = false;
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.IJobChangeListener#scheduled(org.eclipse.core.runtime.jobs.IJobChangeEvent)
*/
public void scheduled(IJobChangeEvent event) {
done = false;
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.IJobChangeListener#sleeping(org.eclipse.core.runtime.jobs.IJobChangeEvent)
*/
public void sleeping(IJobChangeEvent event) {
}
}