mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-03-28 14:56:28 +01:00
Bug 560554. Launch target not populated into defaultdescriptors.
Make explicit the decisions to push down to providers to populate configuration by checking if descriptor supports target. Make explicit the delete/reset logic by a new method on the interface, as opposed to checking if the descriptor is an instanceof DefaultDescriptor. This enables descriptors which support targets, and can be deleted. Change-Id: Id4e3126a70d8cb091d4520acf5d21c5205e0c745 Signed-off-by: Tad Adams <tadams@blackberry.com>
This commit is contained in:
parent
f4f9785b87
commit
bcd1b5b71b
6 changed files with 119 additions and 7 deletions
|
@ -34,6 +34,7 @@ import org.eclipse.debug.core.ILaunchConfiguration;
|
|||
import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||
import org.eclipse.debug.core.ILaunchManager;
|
||||
import org.eclipse.debug.core.ILaunchMode;
|
||||
import org.eclipse.launchbar.core.DefaultLaunchDescriptor;
|
||||
import org.eclipse.launchbar.core.ILaunchConfigurationProvider;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptorType;
|
||||
|
@ -208,6 +209,107 @@ public class LaunchBarManagerTest {
|
|||
assertEquals(launchConfig, manager.getActiveLaunchConfiguration());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void descriptorWithTargetsTest() throws Exception {
|
||||
// Create a descriptor derived from DefaultLaunchDescriptor whose type
|
||||
// supports targets.
|
||||
// Check the active config after adding the launchObject and make sure it came from the provider
|
||||
|
||||
// Mocking
|
||||
final IExtensionPoint extensionPoint = mock(IExtensionPoint.class);
|
||||
IExtension extension = mock(IExtension.class);
|
||||
doReturn(new IExtension[] { extension }).when(extensionPoint).getExtensions();
|
||||
|
||||
List<IConfigurationElement> elements = new ArrayList<>();
|
||||
IConfigurationElement element;
|
||||
|
||||
// fake launch object
|
||||
String launchObject = "fakeObject";
|
||||
|
||||
// launch descriptor for that object
|
||||
element = mock(IConfigurationElement.class);
|
||||
elements.add(element);
|
||||
doReturn("descriptorType").when(element).getName();
|
||||
String descriptorTypeId = "fakeDescriptorType";
|
||||
doReturn(descriptorTypeId).when(element).getAttribute("id");
|
||||
ILaunchDescriptorType descriptorType = mock(ILaunchDescriptorType.class);
|
||||
doReturn(descriptorType).when(element).createExecutableExtension("class");
|
||||
ILaunchDescriptor descriptor = mock(DefaultLaunchDescriptor.class);
|
||||
doReturn(true).when(descriptorType).supportsTargets();
|
||||
doReturn(descriptor).when(descriptorType).getDescriptor(launchObject);
|
||||
doReturn(descriptorType).when(descriptor).getType();
|
||||
doReturn(launchObject).when(descriptor).getName();
|
||||
|
||||
// launch config type
|
||||
final ILaunchManager launchManager = mock(ILaunchManager.class);
|
||||
ILaunchMode runMode = mock(ILaunchMode.class);
|
||||
String run = "run";
|
||||
doReturn(run).when(runMode).getIdentifier();
|
||||
doReturn(runMode).when(launchManager).getLaunchMode(run);
|
||||
ILaunchMode debugMode = mock(ILaunchMode.class);
|
||||
String debug = "debug";
|
||||
doReturn(debug).when(debugMode).getIdentifier();
|
||||
doReturn(debugMode).when(launchManager).getLaunchMode(debug);
|
||||
doReturn(new ILaunchMode[] { runMode, debugMode }).when(launchManager).getLaunchModes();
|
||||
ILaunchConfigurationType launchConfigType = mock(ILaunchConfigurationType.class);
|
||||
String launchConfigTypeId = "fakeLaunchConfigType";
|
||||
doReturn(launchConfigTypeId).when(launchConfigType).getIdentifier();
|
||||
doReturn(true).when(launchConfigType).supportsMode(run);
|
||||
doReturn(true).when(launchConfigType).supportsMode(debug);
|
||||
doReturn(launchConfigType).when(launchManager).getLaunchConfigurationType(launchConfigTypeId);
|
||||
doReturn(new ILaunchConfiguration[0]).when(launchManager).getLaunchConfigurations();
|
||||
|
||||
// configProvider
|
||||
element = mock(IConfigurationElement.class);
|
||||
elements.add(element);
|
||||
doReturn("configProvider").when(element).getName();
|
||||
doReturn(descriptorTypeId).when(element).getAttribute("descriptorType");
|
||||
doReturn("10").when(element).getAttribute("priority");
|
||||
|
||||
ILaunchConfigurationProvider configProvider = mock(ILaunchConfigurationProvider.class);
|
||||
doReturn(configProvider).when(element).createExecutableExtension("class");
|
||||
|
||||
final ILaunchTargetManager targetManager = mock(ILaunchTargetManager.class);
|
||||
ILaunchTarget localTarget = mock(ILaunchTarget.class);
|
||||
doReturn(ILaunchTargetManager.localLaunchTargetTypeId).when(localTarget).getTypeId();
|
||||
doReturn("Local").when(localTarget).getId();
|
||||
doReturn(new ILaunchTarget[] { localTarget }).when(targetManager).getLaunchTargets();
|
||||
|
||||
ILaunchConfiguration launchConfig = mock(ILaunchConfiguration.class);
|
||||
doReturn(launchConfig).when(configProvider).getLaunchConfiguration(eq(descriptor), any(ILaunchTarget.class));
|
||||
doReturn(launchConfigType).when(configProvider).getLaunchConfigurationType(any(ILaunchDescriptor.class),
|
||||
any(ILaunchTarget.class));
|
||||
doAnswer(invocation -> {
|
||||
ILaunchTarget target = (ILaunchTarget) invocation.getArguments()[1];
|
||||
return target.getTypeId().equals(ILaunchTargetManager.localLaunchTargetTypeId);
|
||||
}).when(configProvider).supports(eq(descriptor), any(ILaunchTarget.class));
|
||||
|
||||
doReturn(elements.toArray(new IConfigurationElement[0])).when(extension).getConfigurationElements();
|
||||
|
||||
// Now inject the launch object
|
||||
LaunchBarManager manager = new LaunchBarManager(false) {
|
||||
@Override
|
||||
IExtensionPoint getExtensionPoint() throws CoreException {
|
||||
return extensionPoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
ILaunchManager getLaunchManager() {
|
||||
return launchManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
ILaunchTargetManager getLaunchTargetManager() {
|
||||
return targetManager;
|
||||
}
|
||||
|
||||
};
|
||||
manager.init();
|
||||
manager.launchObjectAdded(launchObject);
|
||||
|
||||
assertEquals(launchConfig, manager.getActiveLaunchConfiguration());
|
||||
}
|
||||
|
||||
// TODO - test that changing active target type produces a different launch
|
||||
// config type
|
||||
// TODO - test that settings are maintained after a restart
|
||||
|
|
|
@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
|||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: LaunchBar Core
|
||||
Bundle-SymbolicName: org.eclipse.launchbar.core;singleton:=true
|
||||
Bundle-Version: 2.3.100.qualifier
|
||||
Bundle-Version: 2.4.0.qualifier
|
||||
Bundle-Activator: org.eclipse.launchbar.core.internal.Activator
|
||||
Bundle-Vendor: Eclipse CDT
|
||||
Require-Bundle: org.eclipse.core.runtime,
|
||||
|
|
|
@ -47,4 +47,13 @@ public interface ILaunchDescriptorType {
|
|||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Do the launch configurations of this type support being deleted.
|
||||
*
|
||||
* @return true if can be deleted
|
||||
* @since 2.4
|
||||
*/
|
||||
default boolean canDelete() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -835,7 +835,9 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
|||
}
|
||||
|
||||
if (descriptor instanceof DefaultLaunchDescriptor) {
|
||||
return descriptor.getAdapter(ILaunchConfiguration.class);
|
||||
if (!descriptor.getType().supportsTargets()) {
|
||||
return descriptor.getAdapter(ILaunchConfiguration.class);
|
||||
}
|
||||
}
|
||||
|
||||
String descTypeId = getDescriptorTypeId(descriptor.getType());
|
||||
|
|
|
@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
|||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: LaunchBar UI
|
||||
Bundle-SymbolicName: org.eclipse.launchbar.ui;singleton:=true
|
||||
Bundle-Version: 2.3.100.qualifier
|
||||
Bundle-Version: 2.3.200.qualifier
|
||||
Bundle-Activator: org.eclipse.launchbar.ui.internal.Activator
|
||||
Bundle-Vendor: Eclipse CDT
|
||||
Require-Bundle: org.eclipse.core.runtime,
|
||||
|
|
|
@ -18,7 +18,6 @@ import org.eclipse.jface.operation.IRunnableWithProgress;
|
|||
import org.eclipse.jface.operation.ModalContext;
|
||||
import org.eclipse.jface.viewers.ILabelProvider;
|
||||
import org.eclipse.jface.wizard.ProgressMonitorPart;
|
||||
import org.eclipse.launchbar.core.DefaultLaunchDescriptor;
|
||||
import org.eclipse.launchbar.core.DefaultLaunchDescriptorType;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||
|
@ -249,7 +248,7 @@ public class LaunchBarLaunchConfigDialog extends TitleAreaDialog implements ILau
|
|||
}
|
||||
|
||||
String deleteText;
|
||||
if (descriptor instanceof DefaultLaunchDescriptor) {
|
||||
if (descriptor.getType().canDelete()) {
|
||||
deleteText = Messages.LaunchBarLaunchConfigDialog_Delete;
|
||||
} else {
|
||||
deleteText = Messages.LaunchBarLaunchConfigDialog_Reset;
|
||||
|
@ -274,7 +273,7 @@ public class LaunchBarLaunchConfigDialog extends TitleAreaDialog implements ILau
|
|||
|
||||
protected void deletePressed() {
|
||||
String title, message;
|
||||
if (descriptor instanceof DefaultLaunchDescriptor) {
|
||||
if (descriptor.getType().canDelete()) {
|
||||
title = Messages.LaunchBarLaunchConfigDialog_DeleteTitle;
|
||||
message = Messages.LaunchBarLaunchConfigDialog_DeleteConfirm;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue