diff options
author | Paul Pazderski | 2019-07-03 11:11:08 +0000 |
---|---|---|
committer | Paul Pazderski | 2019-07-05 10:39:01 +0000 |
commit | e2276c506a466c6b90fbec847bee5464b0b84f5c (patch) | |
tree | e232de457de204d46fd8bc0d686a2fab4f58ece5 | |
parent | 324f7342257c184b49912010121da919ef076060 (diff) | |
download | eclipse.platform.debug-e2276c506a466c6b90fbec847bee5464b0b84f5c.tar.gz eclipse.platform.debug-e2276c506a466c6b90fbec847bee5464b0b84f5c.tar.xz eclipse.platform.debug-e2276c506a466c6b90fbec847bee5464b0b84f5c.zip |
Bug 529651 - Add unit test for 'no build before group launch'
Change-Id: Ifeb288c9088b9d7ea0b37a78ef86465e0ee75424
Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
-rw-r--r-- | org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java | 51 | ||||
-rw-r--r-- | org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/TestLaunchDelegate.java | 44 |
2 files changed, 91 insertions, 4 deletions
diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java index e6f195c61..0b64fda8b 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2017 SSI Schaefer IT Solutions GmbH and others. + * Copyright (c) 2016, 2019 SSI Schaefer IT Solutions GmbH and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -23,21 +23,28 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.ILaunchDelegate; import org.eclipse.debug.core.ILaunchListener; import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.IStreamListener; import org.eclipse.debug.core.model.IDisconnect; +import org.eclipse.debug.core.model.ILaunchConfigurationDelegate2; import org.eclipse.debug.core.model.IProcess; import org.eclipse.debug.core.model.IStreamMonitor; import org.eclipse.debug.core.model.IStreamsProxy; +import org.eclipse.debug.core.model.LaunchConfigurationDelegate; +import org.eclipse.debug.internal.core.LaunchManager; import org.eclipse.debug.internal.core.groups.GroupLaunchConfigurationDelegate; import org.eclipse.debug.internal.core.groups.GroupLaunchElement; import org.eclipse.debug.internal.core.groups.GroupLaunchElement.GroupElementPostLaunchAction; +import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchHistory; import org.eclipse.debug.tests.TestUtil; import org.eclipse.debug.ui.IDebugUIConstants; @@ -329,6 +336,48 @@ public class LaunchGroupTests extends AbstractLaunchTest { assertTrue("group element should be updated", elements.get(0).name.equals("AnotherTest")); //$NON-NLS-1$//$NON-NLS-2$ } + /** + * Test for Bug 529651. Build before launch was not invoked for launches started as part of group launch. + */ + public void testBuildBeforeLaunch() throws CoreException { + final AtomicInteger launched = new AtomicInteger(0); + final AtomicInteger buildRequested = new AtomicInteger(0); + final ILaunchConfigurationDelegate2 customLaunchDelegate = new LaunchConfigurationDelegate() { + @Override + public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { + launched.incrementAndGet(); + } + + @Override + public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException { + buildRequested.incrementAndGet(); + return false; + } + }; + final ILaunchDelegate launchDelegate = ((LaunchManager) DebugPlugin.getDefault().getLaunchManager()).getLaunchDelegate(LaunchConfigurationTests.ID_TEST_LAUNCH_TYPE); + final TestLaunchDelegate testLaunchDelegate = (TestLaunchDelegate) launchDelegate.getDelegate(); + testLaunchDelegate.setDelegate(customLaunchDelegate); + final boolean oldBuildBeforePref = DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IDebugUIConstants.PREF_BUILD_BEFORE_LAUNCH); + try { + ILaunchConfigurationWorkingCopy lc = getLaunchConfiguration("Test1").getWorkingCopy(); //$NON-NLS-1$ + GroupLaunchElement ge = createLaunchGroupElement(lc, GroupElementPostLaunchAction.NONE, null, false); + ILaunchConfiguration group = createLaunchGroup(DEF_GRP_NAME, ge); + + DebugUIPlugin.getDefault().getPreferenceStore().setValue(IDebugUIConstants.PREF_BUILD_BEFORE_LAUNCH, false); + group.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor(), false); + assertEquals("Element not launched.", 1, launched.get()); //$NON-NLS-1$ + assertEquals("Build even though it was disabled.", 0, buildRequested.get()); //$NON-NLS-1$ + + DebugUIPlugin.getDefault().getPreferenceStore().setValue(IDebugUIConstants.PREF_BUILD_BEFORE_LAUNCH, true); + group.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor(), true); + assertEquals("Element not launched.", 2, launched.get()); //$NON-NLS-1$ + assertEquals("Requested build was ignored.", 1, buildRequested.get()); //$NON-NLS-1$ + } finally { + testLaunchDelegate.setDelegate(null); + DebugUIPlugin.getDefault().getPreferenceStore().setValue(IDebugUIConstants.PREF_BUILD_BEFORE_LAUNCH, oldBuildBeforePref); + } + } + private static DummyStream attachDummyProcess(final ILaunch l) { final DummyStream dummy = new DummyStream(); final InvocationHandler streamProxyHandler = new InvocationHandler() { diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/TestLaunchDelegate.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/TestLaunchDelegate.java index fa8c3c0b2..478eeaf2b 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/TestLaunchDelegate.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/TestLaunchDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2014 IBM Corporation and others. + * Copyright (c) 2009, 2019 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -17,15 +17,53 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.model.ILaunchConfigurationDelegate2; import org.eclipse.debug.core.model.LaunchConfigurationDelegate; /** - * An empty launch delegate + * A launch delegate for testing which does nothing or delegate method + * invocations to a delegate if a delegate was set to delegate. */ public class TestLaunchDelegate extends LaunchConfigurationDelegate { + private ILaunchConfigurationDelegate2 delegate = null; + @Override public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { - // do nothing + if (delegate != null) { + delegate.launch(configuration, mode, launch, monitor); + } + } + + @Override + public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException { + if (delegate != null) { + return delegate.buildForLaunch(configuration, mode, monitor); + } + return super.buildForLaunch(configuration, mode, monitor); + } + + @Override + public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException { + if (delegate != null) { + return delegate.preLaunchCheck(configuration, mode, monitor); + } + return super.preLaunchCheck(configuration, mode, monitor); + } + + @Override + public boolean finalLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException { + if (delegate != null) { + delegate.finalLaunchCheck(configuration, mode, monitor); + } + return super.finalLaunchCheck(configuration, mode, monitor); + } + + public ILaunchConfigurationDelegate2 getDelegate() { + return delegate; + } + + public void setDelegate(ILaunchConfigurationDelegate2 delegate) { + this.delegate = delegate; } } |