From 72c4c919de45e6ff17097c19718da15474b1401d Mon Sep 17 00:00:00 2001 From: Joerg Kubitz Date: Tue, 19 Apr 2022 11:47:19 +0200 Subject: [PATCH] Bug 578871 - UndoableOperation2ChangeAdapter use ISchedulableOperation Give the caller of the UndoableOperation2ChangeAdapter.execute a hint that this operation aquires workspace.root as ISchedulingRule. It freezed the eclipse UI as long as any other Thread (for example autobuild) had any lock in the workspace. With the hint a UI can prevent to freeze while waiting for the rule. The original call to ResourcesPlugin.getWorkspace().run(runnable, pm); is equivalent to the call of Workspace.run(IWorkspaceRunnable, IProgressMonitor), which is implemented internally as run((ICoreRunnable) action, defaultRoot, IWorkspace.AVOID_UPDATE, monitor); - means, changing the original code to proposed one is safe and doesn't change any behavior because the executed code it is identical at the end. It only gives a hint about the lock that is used anyway. Workspace.run(IWorkspaceRunnable, IProgressMonitor) was inlined to give a uniform pattern where the lock is aquired. --- .../META-INF/MANIFEST.MF | 4 ++-- org.eclipse.ltk.core.refactoring/pom.xml | 2 +- .../refactoring/UndoableOperation2ChangeAdapter.java | 12 ++++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/org.eclipse.ltk.core.refactoring/META-INF/MANIFEST.MF b/org.eclipse.ltk.core.refactoring/META-INF/MANIFEST.MF index 83efcd6e007..c9e1308b10c 100644 --- a/org.eclipse.ltk.core.refactoring/META-INF/MANIFEST.MF +++ b/org.eclipse.ltk.core.refactoring/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.ltk.core.refactoring Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.ltk.core.refactoring; singleton:=true -Bundle-Version: 3.12.100.qualifier +Bundle-Version: 3.12.200.qualifier Bundle-Activator: org.eclipse.ltk.internal.core.refactoring.RefactoringCorePlugin Bundle-ActivationPolicy: lazy Bundle-Vendor: %providerName @@ -17,7 +17,7 @@ Export-Package: org.eclipse.ltk.core.refactoring, org.eclipse.ltk.internal.core.refactoring.history;x-friends:="org.eclipse.ltk.ui.refactoring,org.eclipse.ltk.core.refactoring.tests", org.eclipse.ltk.internal.core.refactoring.resource;x-friends:="org.eclipse.ltk.ui.refactoring,org.eclipse.ltk.core.refactoring.tests", org.eclipse.ltk.internal.core.refactoring.resource.undostates;x-internal:=true -Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.11.0,4.0.0)", +Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.25.0,4.0.0)", org.eclipse.core.expressions;bundle-version="[3.4.100,4.0.0)", org.eclipse.core.filesystem;bundle-version="[1.2.0,2.0.0)", org.eclipse.core.filebuffers;bundle-version="[3.5.0,4.0.0)", diff --git a/org.eclipse.ltk.core.refactoring/pom.xml b/org.eclipse.ltk.core.refactoring/pom.xml index 3d0f2f504b5..8b3b94e715e 100644 --- a/org.eclipse.ltk.core.refactoring/pom.xml +++ b/org.eclipse.ltk.core.refactoring/pom.xml @@ -18,6 +18,6 @@ org.eclipse.ltk org.eclipse.ltk.core.refactoring - 3.12.100-SNAPSHOT + 3.12.200-SNAPSHOT eclipse-plugin diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/UndoableOperation2ChangeAdapter.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/UndoableOperation2ChangeAdapter.java index 25cc14ca61d..c7921ce0e76 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/UndoableOperation2ChangeAdapter.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/UndoableOperation2ChangeAdapter.java @@ -29,7 +29,10 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.jobs.ISchedulableOperation; +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.ResourcesPlugin; @@ -40,7 +43,7 @@ import org.eclipse.ltk.core.refactoring.RefactoringStatus; -public class UndoableOperation2ChangeAdapter implements IUndoableOperation, IAdvancedUndoableOperation { +public class UndoableOperation2ChangeAdapter implements IUndoableOperation, IAdvancedUndoableOperation, ISchedulableOperation { private String fLabel; private String fDescription; @@ -348,7 +351,7 @@ private ExecuteResult executeChange(final IValidationCheckResultQuery query, IPr monitor.done(); } }; - ResourcesPlugin.getWorkspace().run(runnable, pm); + ResourcesPlugin.getWorkspace().run(runnable, getSchedulingRule(), IWorkspace.AVOID_UPDATE, pm); return result; } @@ -390,4 +393,9 @@ private void clearActiveChange() { fActiveChange.dispose(); fActiveChange= null; } + + @Override + public ISchedulingRule getSchedulingRule() { + return ResourcesPlugin.getWorkspace().getRoot(); + } }