diff options
author | Paul Pazderski | 2019-05-09 19:40:03 +0000 |
---|---|---|
committer | Paul Pazderski | 2019-08-12 14:04:47 +0000 |
commit | fbfee8d1413f408c644681303c5a4e844c700874 (patch) | |
tree | c864066f42ccdd9c41c5096f0a0ac39807201678 | |
parent | 36d4b6c1b9fd73256c3d5c3ee0a900fbc635a0eb (diff) | |
download | eclipse.platform.debug-fbfee8d1413f408c644681303c5a4e844c700874.tar.gz eclipse.platform.debug-fbfee8d1413f408c644681303c5a4e844c700874.tar.xz eclipse.platform.debug-fbfee8d1413f408c644681303c5a4e844c700874.zip |
Bug 549903 - Replace usage of deprecated SubProgressMonitor withI20190813-1800I20190812-1800
SubMonitor
Also replaced the anti-pattern:
if(doMore) {
doSomething(new SubProgressMonitor(monitor));
} else {
monitor.worked();
}
As consequence skipped optional work will not move the progress bar
anymore but leave the space for the remaining tasks.
Change-Id: Id58944194449f58f887e8969d7ba9d7c16939f9c
Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
3 files changed, 37 insertions, 70 deletions
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/core/model/LaunchConfigurationDelegate.java b/org.eclipse.debug.core/core/org/eclipse/debug/core/model/LaunchConfigurationDelegate.java index c5585dd4d..142c01828 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/core/model/LaunchConfigurationDelegate.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/core/model/LaunchConfigurationDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2018 IBM Corporation and others. + * Copyright (c) 2004, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -35,7 +35,6 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.IBreakpointManager; import org.eclipse.debug.core.ILaunch; @@ -117,21 +116,12 @@ public abstract class LaunchConfigurationDelegate implements ILaunchConfiguratio @Override public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException { - if (monitor != null) { - monitor.beginTask("", 1); //$NON-NLS-1$ - } - try { - IProject[] projects = getBuildOrder(configuration, mode); - if (projects == null) { - return true; - } - buildProjects(projects, new SubProgressMonitor(monitor, 1)); - return false; - } finally { - if (monitor != null) { - monitor.done(); - } + IProject[] projects = getBuildOrder(configuration, mode); + if (projects == null) { + return true; } + buildProjects(projects, SubMonitor.convert(monitor, 1)); + return false; } /** diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java index 0a10cb9cb..eece9bb85 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2018 IBM Corporation and others. + * Copyright (c) 2000, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -48,7 +48,6 @@ import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; @@ -730,7 +729,7 @@ public class LaunchConfiguration extends PlatformObject implements ILaunchConfig * - Final launch validation (1) * - Initialize source locator (1) * - Launch delegate (10) */ - SubMonitor lmonitor = SubMonitor.convert(monitor, DebugCoreMessages.LaunchConfiguration_9, build ? 23 : 13); + SubMonitor lmonitor = SubMonitor.convert(monitor, DebugCoreMessages.LaunchConfiguration_9, 23); try { // bug 28245 - force the delegate to load in case it is interested in launch notifications Set<String> modes = getModes(); @@ -821,42 +820,34 @@ public class LaunchConfiguration extends PlatformObject implements ILaunchConfig lmonitor.subTask(DebugCoreMessages.LaunchConfiguration_8); if (delegate2 != null) { - if (!(delegate2.preLaunchCheck(this, mode, new SubProgressMonitor(lmonitor, 1)))) { + if (!(delegate2.preLaunchCheck(this, mode, lmonitor.split(1)))) { getLaunchManager().removeLaunch(launch); return launch; } } - else { - lmonitor.worked(1); /* No pre-launch-check */ - } + lmonitor.setWorkRemaining(22); // perform pre-launch build if (build) { - IProgressMonitor buildMonitor = new SubProgressMonitor(lmonitor, 10, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK); - buildMonitor.beginTask(DebugCoreMessages.LaunchConfiguration_7, 10); - buildMonitor.subTask(DebugCoreMessages.LaunchConfiguration_6); + lmonitor.subTask(DebugCoreMessages.LaunchConfiguration_7 + DebugCoreMessages.LaunchConfiguration_6); boolean tempbuild = build; if (delegate2 != null) { - tempbuild = delegate2.buildForLaunch(this, mode, new SubProgressMonitor(buildMonitor, 7)); + tempbuild = delegate2.buildForLaunch(this, mode, lmonitor.split(7)); } if (tempbuild) { - buildMonitor.subTask(DebugCoreMessages.LaunchConfiguration_5); - ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new SubProgressMonitor(buildMonitor, 3)); - } - else { - buildMonitor.worked(3); /* No incremental build required */ + lmonitor.subTask(DebugCoreMessages.LaunchConfiguration_7 + DebugCoreMessages.LaunchConfiguration_5); + ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, lmonitor.split(3)); } } + lmonitor.setWorkRemaining(12); // final validation lmonitor.subTask(DebugCoreMessages.LaunchConfiguration_4); if (delegate2 != null) { - if (!(delegate2.finalLaunchCheck(this, mode, new SubProgressMonitor(lmonitor, 1)))) { + if (!(delegate2.finalLaunchCheck(this, mode, lmonitor.split(1)))) { getLaunchManager().removeLaunch(launch); return launch; } } - else { - lmonitor.worked(1); /* No validation */ - } + lmonitor.setWorkRemaining(11); try { //initialize the source locator @@ -866,7 +857,7 @@ public class LaunchConfiguration extends PlatformObject implements ILaunchConfig /* Launch the delegate */ lmonitor.subTask(DebugCoreMessages.LaunchConfiguration_2); - delegate.launch(this, mode, launch, new SubProgressMonitor(lmonitor, 10)); + delegate.launch(this, mode, launch, lmonitor.split(10)); } catch (CoreException e) { // if there was an exception, and the launch is empty, remove it if (!launch.hasChildren()) { diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java index 973c1dddd..d6910cfa9 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2018 IBM Corporation and others. + * Copyright (c) 2000, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -42,7 +42,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; import org.eclipse.core.runtime.jobs.IJobChangeEvent; import org.eclipse.core.runtime.jobs.IJobChangeListener; import org.eclipse.core.runtime.jobs.IJobManager; @@ -1014,18 +1014,7 @@ public class DebugUIPlugin extends AbstractUIPlugin implements ILaunchListener, public static ILaunch buildAndLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException { boolean buildBeforeLaunch = getDefault().getPreferenceStore().getBoolean(IDebugUIConstants.PREF_BUILD_BEFORE_LAUNCH); - monitor.beginTask(IInternalDebugCoreConstants.EMPTY_STRING, 1); - try - { - return configuration.launch( - mode, - new SubProgressMonitor(monitor, 1), - buildBeforeLaunch); - } - finally - { - monitor.done(); - } + return configuration.launch(mode, SubMonitor.convert(monitor, 1), buildBeforeLaunch); } /** @@ -1074,19 +1063,18 @@ public class DebugUIPlugin extends AbstractUIPlugin implements ILaunchListener, * Setup progress monitor - Waiting for jobs to finish (2) - * Build & launch (98) */ - monitor.beginTask(MessageFormat.format(DebugUIMessages.DebugUIPlugin_25, new Object[] { - configuration.getName() }), 100); - + final SubMonitor subMonitor = SubMonitor.convert(monitor, MessageFormat + .format(DebugUIMessages.DebugUIPlugin_25, new Object[] { configuration.getName() }), 100); try { - jobManager.join(ResourcesPlugin.FAMILY_MANUAL_BUILD, new SubProgressMonitor(monitor, 1)); - jobManager.join(ResourcesPlugin.FAMILY_AUTO_BUILD, new SubProgressMonitor(monitor, 1)); + jobManager.join(ResourcesPlugin.FAMILY_MANUAL_BUILD, subMonitor.split(1)); + jobManager.join(ResourcesPlugin.FAMILY_AUTO_BUILD, subMonitor.split(1)); } catch (InterruptedException e1) { - /* continue */} + /* continue */ + } if (!monitor.isCanceled()) { try { - buildAndLaunch(configuration, mode, new SubProgressMonitor(monitor, 98)); - } - catch (CoreException e2) { + buildAndLaunch(configuration, mode, subMonitor.split(98)); + } catch (CoreException e2) { throw new InvocationTargetException(e2); } } @@ -1103,10 +1091,10 @@ public class DebugUIPlugin extends AbstractUIPlugin implements ILaunchListener, /* * Setup progress monitor - Build & launch (1) */ - monitor.beginTask(MessageFormat.format(DebugUIMessages.DebugUIPlugin_25, new Object[] { - configuration.getName() }), 1); + final SubMonitor subMonitor = SubMonitor.convert(monitor, MessageFormat + .format(DebugUIMessages.DebugUIPlugin_25, new Object[] { configuration.getName() }), 1); try { - buildAndLaunch(configuration, mode, new SubProgressMonitor(monitor, 1)); + buildAndLaunch(configuration, mode, subMonitor); } catch (CoreException e) { throw new InvocationTargetException(e); } @@ -1190,7 +1178,7 @@ public class DebugUIPlugin extends AbstractUIPlugin implements ILaunchListener, /* Setup progress monitor * - Waiting for jobs to finish (2) * - Build & launch (98) */ - monitor.beginTask(DebugUIMessages.DebugUITools_3, 100); + final SubMonitor subMonitor = SubMonitor.convert(monitor, DebugUIMessages.DebugUITools_3, 100); try { if(waitInJob) { StringBuilder buffer = new StringBuilder(configuration.getName()); @@ -1221,17 +1209,15 @@ public class DebugUIPlugin extends AbstractUIPlugin implements ILaunchListener, }; addJobChangeListener(listener); try { - jobManager.join(ResourcesPlugin.FAMILY_MANUAL_BUILD, new SubProgressMonitor(monitor, 1)); - jobManager.join(ResourcesPlugin.FAMILY_AUTO_BUILD, new SubProgressMonitor(monitor, 1)); + jobManager.join(ResourcesPlugin.FAMILY_MANUAL_BUILD, subMonitor.split(1)); + jobManager.join(ResourcesPlugin.FAMILY_AUTO_BUILD, subMonitor.split(1)); } catch (InterruptedException e) {/*just continue.*/} DebugPlugin.getDefault().getLaunchManager().removeLaunch(pendingLaunch); } - else { - monitor.worked(2); /* don't wait for jobs to finish */ - } + subMonitor.setWorkRemaining(98); if (!monitor.isCanceled()) { - buildAndLaunch(configuration, mode, new SubProgressMonitor(monitor, 98)); + buildAndLaunch(configuration, mode, subMonitor.split(98)); } } catch (CoreException e) { final IStatus status = e.getStatus(); |