From f9f2e2c22a16ba1f8e89f70162dcf1ed58e8f6bd Mon Sep 17 00:00:00 2001 From: BJ Hargrave Date: Thu, 11 Nov 2021 17:07:21 -0500 Subject: [PATCH] central: Refresh workspace inside bndLock for cnf change If a change to cnf was detected, we called workspace refresh without regard to any running builders. This caused issues where the workspace refresh closed repos while a builder was running. We now refresh the workspace while holding the bndLock. We use a job to handle this in case we need to wait for the lock and don't want to block the notification (which could be the main) thread. Signed-off-by: BJ Hargrave --- .../src/bndtools/central/Central.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/bndtools.core/src/bndtools/central/Central.java b/bndtools.core/src/bndtools/central/Central.java index 2ef00b6005..a3168cc848 100644 --- a/bndtools.core/src/bndtools/central/Central.java +++ b/bndtools.core/src/bndtools/central/Central.java @@ -43,6 +43,7 @@ import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jface.viewers.TreeViewer; @@ -429,8 +430,21 @@ private static void addCnfChangeListener(final Workspace workspace) { } IResourceDelta rootDelta = event.getDelta(); if (isCnfChanged(workspace, rootDelta)) { - logger.error("cnf changed; refreshing workspace"); - workspace.refresh(); + logger.info("cnf changed; refreshing workspace"); + // Move off notification thread + Job job = new Job("Refreshing workspace for cnf change") { + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + // Avoid race condition with BndtoolsBuilder + bndCall(after -> workspace.refresh(), monitor); + } catch (Exception e) { + return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, "error during workspace refresh", e); + } + return Status.OK_STATUS; + } + }; + job.schedule(); } }); }