From e4fe32a7bc6c6e8651e90f458f78be4e8aff6e8f Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Fri, 2 Apr 2004 14:15:05 +0000 Subject: [PATCH] use the Job Manager for the BinaryRunner thread. --- core/org.eclipse.cdt.core/ChangeLog | 13 +++ .../cdt/core/model/ILibraryReference.java | 6 ++ .../cdt/internal/core/model/BinaryRunner.java | 99 +++++++++++++------ .../internal/core/model/CModelManager.java | 58 +++++++++++ .../cdt/internal/core/model/CProject.java | 12 +++ .../cdt/internal/core/model/CProjectInfo.java | 18 ++++ .../internal/core/model/LibraryReference.java | 7 ++ .../core/model/LibraryReferenceArchive.java | 14 +++ .../core/model/LibraryReferenceShared.java | 7 ++ 9 files changed, 204 insertions(+), 30 deletions(-) diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index b7e94702cef..ad96bc7cdd8 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -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. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILibraryReference.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILibraryReference.java index 43c12887f82..62664fa0f0f 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILibraryReference.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILibraryReference.java @@ -8,4 +8,10 @@ package org.eclipse.cdt.core.model; /** */ public interface ILibraryReference extends IParent, ICElement { + + /** + * Return the pathEntry. + * @return + */ + ILibraryEntry getLibraryEntry(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java index d93b8e1262b..059ee53c795 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java @@ -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,24 +16,35 @@ 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; cproject = CModelManager.getDefault().create(project); } 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; } - - }, CCorePlugin.getResourceString("CoreModel.BinaryRunner.Binary_Search_Thread")); //$NON-NLS-1$ - runner.start(); + }; + runner.schedule(); + } @@ -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) { - runner.addChildIfBinary((IFile)res); + 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) { + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java index 7b89b3491c0..b465de0f52c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java @@ -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. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java index fb35e2b7329..4ca36427355 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java @@ -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(); + } + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java index bc42794f8e5..28ab23c0afd 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java @@ -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) { + } + } + } + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReference.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReference.java index 4da3b8a8889..8c5ae7dcf8e 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReference.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReference.java @@ -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; + } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReferenceArchive.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReferenceArchive.java index eee120400b0..dd6afc41d45 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReferenceArchive.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReferenceArchive.java @@ -33,6 +33,7 @@ public class LibraryReferenceArchive extends Archive implements ILibraryReferenc return null; } + /* (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; + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReferenceShared.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReferenceShared.java index b52209e7be2..a80b22fd85d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReferenceShared.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReferenceShared.java @@ -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; + } + }