1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

use the Job Manager for the BinaryRunner thread.

This commit is contained in:
Alain Magloire 2004-04-02 14:15:05 +00:00
parent 3683cff5a7
commit e4fe32a7bc
9 changed files with 204 additions and 30 deletions

View file

@ -1,3 +1,16 @@
2004-04-02 Alain Magloire
Use the the Job manager for the binary runner.
* model/org/eclipse/cdt/internal/core/model/BinaryRunner.java
* model/org/eclipse/cdt/internal/core/model/CModelManager.java
* model/org/eclipse/cdt/internal/core/model/CProject.java
* model/org/eclipse/cdt/internal/core/model/CProjectInfo.java
* model/org/eclipse/cdt/internal/core/model/LibraryReference.java
* model/org/eclipse/cdt/internal/core/model/LibraryReferenceArchive.java
* model/org/eclipse/cdt/internal/core/model/LibraryReferenceShared.java
* model/org/eclipse/cdt/core/model/ILibraryReference.java
2004-04-02 David Inglis
Fixed problem with .cdtproject not getting updated.

View file

@ -8,4 +8,10 @@ package org.eclipse.cdt.core.model;
/**
*/
public interface ILibraryReference extends IParent, ICElement {
/**
* Return the pathEntry.
* @return
*/
ILibraryEntry getLibraryEntry();
}

View file

@ -6,9 +6,7 @@ package org.eclipse.cdt.internal.core.model;
*/
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.core.model.ElementChangedEvent;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModel;
@ -18,13 +16,20 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
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;
public class BinaryRunner {
public class BinaryRunner implements IJobChangeListener {
IProject project;
ICProject cproject;
Thread runner;
Job runner;
ArchiveContainer vlib;
BinaryContainer vbin;
boolean done = false;
public BinaryRunner(IProject prj) {
project = prj;
@ -32,10 +37,14 @@ public class BinaryRunner {
}
public void start() {
runner = new Thread(new Runnable() {
public void run() {
String taskName = CCorePlugin.getResourceString("CoreModel.BinaryRunner.Binary_Search_Thread"); //$NON-NLS-1
Job runner = new Job(taskName) {
/* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
protected IStatus run(IProgressMonitor monitor) {
if (cproject == null || Thread.currentThread().isInterrupted()) {
return;
return Status.CANCEL_STATUS;
}
vbin = (BinaryContainer)cproject.getBinaryContainer();
vlib = (ArchiveContainer)cproject.getArchiveContainer();
@ -56,12 +65,13 @@ public class BinaryRunner {
// Tell the listeners we are done.
synchronized(BinaryRunner.this) {
BinaryRunner.this.notifyAll();
runner = null;
BinaryRunner.this.runner = null;
}
return Status.OK_STATUS;
}
};
runner.schedule();
}, CCorePlugin.getResourceString("CoreModel.BinaryRunner.Binary_Search_Thread")); //$NON-NLS-1$
runner.start();
}
@ -69,7 +79,7 @@ public class BinaryRunner {
* wrap the wait call and the interrupteException.
*/
public synchronized void waitIfRunning() {
while (runner != null && runner.isAlive()) {
while (runner != null && !done) {
try {
wait();
} catch (InterruptedException e) {
@ -78,8 +88,8 @@ public class BinaryRunner {
}
public void stop() {
if ( runner != null && runner.isAlive()) {
runner.interrupt();
if ( runner != null && !done) {
runner.cancel();
}
}
@ -107,20 +117,8 @@ public class BinaryRunner {
if (!factory.isTranslationUnit(file)) {
IBinaryFile bin = factory.createBinaryFile(file);
if (bin != null) {
ICElement parent = factory.create(file.getParent(), null);
if (bin.getType() == IBinaryFile.ARCHIVE) {
if (parent == null) {
parent = vlib;
}
Archive ar = new Archive(parent, file, (IBinaryArchive)bin);
vlib.addChild(ar);
} else {
if (parent == null) {
parent = vbin;
}
Binary binary = new Binary(parent, file, (IBinaryObject)bin);
vbin.addChild(binary);
}
// Create the file will add it to the {Archive,Binary}Containery.
factory.create(file, bin, null);
}
}
}
@ -138,11 +136,52 @@ public class BinaryRunner {
}
if (cproject.isOnOutputEntry(res)) {
if (res instanceof IFile) {
if (runner != null) {
runner.addChildIfBinary((IFile)res);
}
return false;
}
}
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) {
}
}

View file

@ -308,6 +308,64 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
return celement;
}
public ICElement create(IFile file, IBinaryFile bin, ICProject cproject) {
if (file == null) {
return null;
}
if (bin == null) {
return create(file, cproject);
}
if (cproject == null) {
cproject = create(file.getProject());
}
ICElement celement = null;
try {
ISourceRoot[] roots = cproject.getAllSourceRoots();
for (int i = 0; i < roots.length; ++i) {
ISourceRoot root = roots[i];
if (root.isOnSourceEntry(file)) {
IPath rootPath = root.getPath();
IPath resourcePath = file.getFullPath();
IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount());
String fileName = path.lastSegment();
path = path.removeLastSegments(1);
String[] segments = path.segments();
ICContainer cfolder = root;
for (int j = 0; j < segments.length; j++) {
cfolder = cfolder.getCContainer(segments[j]);
}
if (bin.getType() == IBinaryFile.ARCHIVE) {
celement = new Archive(cfolder, file, (IBinaryArchive)bin);
ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer();
vlib.addChild(celement);
} else {
celement = new Binary(cfolder, file, (IBinaryObject)bin);
BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer();
vbin.addChild(celement);
}
break;
}
}
// try in the outputEntry and save in the container
if (celement == null) {
if (bin.getType() == IBinaryFile.ARCHIVE) {
ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer();
ICElement archive = new Archive(vlib, file, (IBinaryArchive)bin);
vlib.addChild(archive);
} else {
BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer();
IBinary binary = new Binary(vbin, file, (IBinaryObject)bin);
vbin.addChild(binary);
}
}
} catch (CModelException e) {
//
}
return celement;
}
public void releaseCElement(ICElement celement) {
// Guard.

View file

@ -580,8 +580,20 @@ public class CProject extends Openable implements ICProject {
if (pinfo.vLib != null) {
pinfo.vLib.close();
}
pinfo.resetCaches();
CModelManager.getDefault().removeBinaryRunner(this);
}
super.closing(info);
}
/*
* Resets this project's caches
*/
public void resetCaches() {
CProjectInfo pinfo = (CProjectInfo) CModelManager.getDefault().peekAtInfo(this);
if (pinfo != null){
pinfo.resetCaches();
}
}
}

View file

@ -7,9 +7,11 @@ package org.eclipse.cdt.internal.core.model;
import java.util.ArrayList;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IArchiveContainer;
import org.eclipse.cdt.core.model.IBinaryContainer;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ILibraryReference;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
@ -24,6 +26,7 @@ class CProjectInfo extends OpenableInfo {
BinaryContainer vBin;
ArchiveContainer vLib;
ILibraryReference[] libReferences;
Object[] nonCResources = null;
/**
@ -117,4 +120,19 @@ class CProjectInfo extends OpenableInfo {
public void setNonCResources(Object[] resources) {
nonCResources = resources;
}
/*
* Reset the source roots and other caches
*/
public void resetCaches() {
if (libReferences != null) {
for (int i = 0; i < libReferences.length; i++) {
try {
((CElement)libReferences[i]).close();
} catch (CModelException e) {
}
}
}
}
}

View file

@ -45,4 +45,11 @@ public class LibraryReference extends Parent implements ILibraryReference {
return entry.getPath();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ILibraryReference#getLibraryEntry()
*/
public ILibraryEntry getLibraryEntry() {
return entry;
}
}

View file

@ -34,6 +34,7 @@ public class LibraryReferenceArchive extends Archive implements ILibraryReferenc
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ICElement#getPath()
*/
@ -41,4 +42,17 @@ public class LibraryReferenceArchive extends Archive implements ILibraryReferenc
return entry.getPath();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ICElement#exists()
*/
public boolean exists() {
return getPath().toFile().exists();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ILibraryReference#getLibraryEntry()
*/
public ILibraryEntry getLibraryEntry() {
return entry;
}
}

View file

@ -47,4 +47,11 @@ public class LibraryReferenceShared extends Binary implements ILibraryReference
return entry.getPath();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ILibraryReference#getLibraryEntry()
*/
public ILibraryEntry getLibraryEntry() {
return entry;
}
}