From 1d58ba3e70ca0550d1bc1a58642913f6ca253510 Mon Sep 17 00:00:00 2001 From: Martin Jobst Date: Thu, 17 Oct 2024 14:08:20 +0200 Subject: [PATCH] Update markers in current thread if holding resource lock Also remove unused marker helpers. --- .../errormarker/FordiacMarkerHelper.java | 136 +++++++----------- 1 file changed, 55 insertions(+), 81 deletions(-) diff --git a/plugins/org.eclipse.fordiac.ide.model/src/org/eclipse/fordiac/ide/model/errormarker/FordiacMarkerHelper.java b/plugins/org.eclipse.fordiac.ide.model/src/org/eclipse/fordiac/ide/model/errormarker/FordiacMarkerHelper.java index 6b39ad27d3..528ed3884a 100644 --- a/plugins/org.eclipse.fordiac.ide.model/src/org/eclipse/fordiac/ide/model/errormarker/FordiacMarkerHelper.java +++ b/plugins/org.eclipse.fordiac.ide.model/src/org/eclipse/fordiac/ide/model/errormarker/FordiacMarkerHelper.java @@ -18,10 +18,8 @@ *******************************************************************************/ package org.eclipse.fordiac.ide.model.errormarker; -import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.function.BiConsumer; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -34,6 +32,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.JobGroup; import org.eclipse.emf.common.util.Diagnostic; @@ -243,71 +242,36 @@ public static Map getDiagnosticAttributes(final Diagnostic diagn ); } - public static List findMarkers(final EObject target) { - return findMarkers(target, FordiacErrorMarker.IEC61499_MARKER); - } - - public static List findMarkers(final EObject target, final String type) { - final IResource resource = getResource(target); - return findMarkers(resource, target, type); - } - - public static List findMarkers(final IResource resource, final EObject target, final String type) { - final List result = new ArrayList<>(); - if (resource != null && resource.isAccessible() && target != null) { - final String targetUriString = getTargetUri(resource, target).toString(); - try { - final IMarker[] markers = resource.findMarkers(type, true, IResource.DEPTH_INFINITE); - for (final var marker : markers) { - if (marker.getAttribute(FordiacErrorMarker.TARGET_URI, "").equals(targetUriString)) { //$NON-NLS-1$ - result.add(marker); + public static void createMarkers(final IResource resource, final List builders) { + if (resource != null && resource.isAccessible()) { + final ISchedulingRule currentRule = Job.getJobManager().currentRule(); + if (currentRule != null && currentRule.contains(resource)) { + createMarkersInWorkspace(resource, builders); + } else { + final WorkspaceJob job = new WorkspaceJob("Create error markers on resource: " + resource.getName()) { //$NON-NLS-1$ + @Override + public IStatus runInWorkspace(final IProgressMonitor monitor) { + createMarkersInWorkspace(resource, builders); + return Status.OK_STATUS; } - } - } catch (final CoreException e) { - FordiacLogHelper.logError("Could not find error markers", e); //$NON-NLS-1$ + }; + job.setUser(false); + job.setSystem(true); + job.setPriority(Job.DECORATE); + job.setRule(resource); + job.setJobGroup(JOB_GROUP); + job.schedule(); } } - return result; } - public static void findAllMarkers(final IResource resource, final EObject root, final String type, - final BiConsumer consumer) { - if (resource != null && resource.isAccessible() && root != null) { - try { - final IMarker[] markers = resource.findMarkers(type, true, IResource.DEPTH_INFINITE); - for (final var marker : markers) { - final EObject target = FordiacErrorMarker.getTargetRelative(marker, root); - if (target != null) { - consumer.accept(target, marker); - } - } - } catch (final CoreException e) { - FordiacLogHelper.logError("Could not find all error markers", e); //$NON-NLS-1$ + private static void createMarkersInWorkspace(final IResource resource, final List builders) { + try { + for (final var builder : builders) { + builder.createMarker(resource); } - } - } - - public static void createMarkers(final IResource resource, final List builders) { - if (resource != null && resource.isAccessible()) { - final WorkspaceJob job = new WorkspaceJob("Create error markers on resource: " + resource.getName()) { //$NON-NLS-1$ - @Override - public IStatus runInWorkspace(final IProgressMonitor monitor) { - try { - for (final var builder : builders) { - builder.createMarker(resource); - } - } catch (final CoreException e) { - FordiacLogHelper.logError("Could not create error markers", e); //$NON-NLS-1$ - } - return Status.OK_STATUS; - } - }; - job.setUser(false); - job.setSystem(true); - job.setPriority(Job.DECORATE); - job.setRule(resource); - job.setJobGroup(JOB_GROUP); - job.schedule(); + } catch (final CoreException e) { + FordiacLogHelper.logError("Could not create error markers", e); //$NON-NLS-1$ } } @@ -324,27 +288,37 @@ public static void updateMarkers(final IResource resource, final String type, final List builders, final boolean force) { if (resource != null && resource.isAccessible() && (force || errorMarkersNeedsUpdate(resource, type, builders))) { - final WorkspaceJob job = new WorkspaceJob("Update error markers on resource: " + resource.getName()) { //$NON-NLS-1$ - @Override - public IStatus runInWorkspace(final IProgressMonitor monitor) { - try { - resource.deleteMarkers(type, true, IResource.DEPTH_INFINITE); - for (final var builder : builders) { - builder.createMarker(resource); - } - } catch (final CoreException e) { - FordiacLogHelper.logError("Could not update error markers on resource: " + resource.getName(), //$NON-NLS-1$ - e); + final ISchedulingRule currentRule = Job.getJobManager().currentRule(); + if (currentRule != null && currentRule.contains(resource)) { + createMarkersInWorkspace(resource, builders); + } else { + final WorkspaceJob job = new WorkspaceJob("Update error markers on resource: " + resource.getName()) { //$NON-NLS-1$ + @Override + public IStatus runInWorkspace(final IProgressMonitor monitor) { + updateMarkersInWorkspace(resource, type, builders); + return Status.OK_STATUS; } - return Status.OK_STATUS; - } - }; - job.setUser(false); - job.setSystem(true); - job.setPriority(Job.DECORATE); - job.setRule(resource); - job.setJobGroup(JOB_GROUP); - job.schedule(); + }; + job.setUser(false); + job.setSystem(true); + job.setPriority(Job.DECORATE); + job.setRule(resource); + job.setJobGroup(JOB_GROUP); + job.schedule(); + } + } + } + + private static void updateMarkersInWorkspace(final IResource resource, final String type, + final List builders) { + try { + resource.deleteMarkers(type, true, IResource.DEPTH_INFINITE); + for (final var builder : builders) { + builder.createMarker(resource); + } + } catch (final CoreException e) { + FordiacLogHelper.logError("Could not update error markers on resource: " + resource.getName(), //$NON-NLS-1$ + e); } }