1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Improved halting of indexer when it hits too many erros. Increased max error count to 500.

This commit is contained in:
Markus Schorn 2006-11-15 16:36:25 +00:00
parent 3954755d03
commit 456f0c229c
4 changed files with 33 additions and 49 deletions

View file

@ -26,14 +26,13 @@ import org.eclipse.core.runtime.jobs.Job;
*/
public class PDOMIndexerJob extends Job {
private static final int TOTAL_MONITOR_WORK = 1000;
private final PDOMManager pdomManager;
private IPDOMIndexerTask currentTask;
private boolean cancelledByManager= false;
private Object taskMutex = new Object();
private IProgressMonitor monitor;
private Job fMonitorJob;
private IProgressMonitor fMonitor;
public PDOMIndexerJob(PDOMManager manager) {
super(CCorePlugin.getResourceString("pdom.indexer.name")); //$NON-NLS-1$
@ -42,10 +41,12 @@ public class PDOMIndexerJob extends Job {
}
protected IStatus run(IProgressMonitor monitor) {
this.monitor = monitor;
long start = System.currentTimeMillis();
startMonitorJob(monitor);
fMonitor = monitor;
String taskName = CCorePlugin.getResourceString("pdom.indexer.task"); //$NON-NLS-1$
monitor.beginTask(taskName, TOTAL_MONITOR_WORK);
Job monitorJob= startMonitorJob(monitor);
try {
do {
synchronized(taskMutex) {
@ -63,12 +64,7 @@ public class PDOMIndexerJob extends Job {
}
if (currentTask != null) {
try {
currentTask.run(monitor);
}
catch (Exception e) {
CCorePlugin.log(e);
}
currentTask.run(monitor);
}
}
while (currentTask != null);
@ -99,46 +95,35 @@ public class PDOMIndexerJob extends Job {
throw e;
}
finally {
stopMonitorJob();
monitorJob.cancel();
monitor.done();
}
}
private void stopMonitorJob() {
if (fMonitorJob != null) {
fMonitorJob.cancel();
}
}
private void startMonitorJob(final IProgressMonitor monitor) {
fMonitorJob= new Job(CCorePlugin.getResourceString("PDOMIndexerJob.updateMonitorJob")) { //$NON-NLS-1$
private Job startMonitorJob(final IProgressMonitor targetMonitor) {
Job monitorJob= new Job(CCorePlugin.getResourceString("PDOMIndexerJob.updateMonitorJob")) { //$NON-NLS-1$
protected IStatus run(IProgressMonitor m) {
String taskName = CCorePlugin.getResourceString("pdom.indexer.task"); //$NON-NLS-1$
monitor.beginTask(taskName, 1000);
try {
int currentTick= 0;
while(!m.isCanceled()) {
currentTick= pdomManager.getMonitorMessage(monitor, currentTick, 1000);
try {
Thread.sleep(350);
} catch (InterruptedException e) {
return Status.CANCEL_STATUS;
}
int currentTick= 0;
while(!m.isCanceled() && !targetMonitor.isCanceled()) {
currentTick= pdomManager.getMonitorMessage(targetMonitor, currentTick, TOTAL_MONITOR_WORK);
try {
Thread.sleep(350);
} catch (InterruptedException e) {
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
fMonitorJob.setSystem(true);
fMonitorJob.schedule();
monitorJob.setSystem(true);
monitorJob.schedule();
return monitorJob;
}
public void cancelJobs(IPDOMIndexer indexer) {
synchronized (taskMutex) {
if (currentTask != null && currentTask.getIndexer() == indexer) {
monitor.setCanceled(true);
fMonitor.setCanceled(true);
cancelledByManager = true;
while (currentTask != null && currentTask.getIndexer() == indexer) {
try {

View file

@ -18,6 +18,7 @@ public class Messages extends NLS {
public static String PDOMIndexerTask_collectingFilesTask;
public static String PDOMIndexerTask_errorWhileParsing;
public static String PDOMIndexerTask_parsingFileTask;
public static String PDOMIndexerTask_tooManyIndexProblems;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);

View file

@ -142,27 +142,24 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
doParseTU(tu, pm);
}
catch (CoreException e) {
if (!swallowError(path, e))
throw e;
swallowError(path, e);
}
catch (RuntimeException e) {
if (!swallowError(path, e))
throw e;
swallowError(path, e);
}
catch (Error e) {
if (!swallowError(path, e))
throw e;
swallowError(path, e);
}
}
private boolean swallowError(IPath file, Throwable e) {
if (++fErrorCount <= MAX_ERRORS) {
IStatus status= CCorePlugin.createStatus(
private void swallowError(IPath file, Throwable e) throws CoreException {
IStatus status= CCorePlugin.createStatus(
MessageFormat.format(Messages.PDOMIndexerTask_errorWhileParsing, new Object[]{file}), e);
CCorePlugin.log(status);
return true;
if (++fErrorCount > MAX_ERRORS) {
throw new CoreException(CCorePlugin.createStatus(
MessageFormat.format(Messages.PDOMIndexerTask_tooManyIndexProblems, new Object[]{getIndexer().getProject().getElementName()})));
}
return false;
}
abstract protected void doParseTU(ITranslationUnit tu, IProgressMonitor pm) throws CoreException, InterruptedException;

View file

@ -1,3 +1,4 @@
PDOMIndexerTask_collectingFilesTask=Collecting files to parse (project ''{0}'')
PDOMIndexerTask_tooManyIndexProblems=Too many problems while indexing project ''{0}'', stopping indexer.
PDOMIndexerTask_parsingFileTask=parsing {0} ({1})
PDOMIndexerTask_errorWhileParsing=Error while parsing {0}.