mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
LaunchBar - more tests and refactoring
Change-Id: I7ae632dd6c3c67881066589a721031fdea6ea5c0 Reviewed-on: https://git.eclipse.org/r/31217 Tested-by: Hudson CI Reviewed-by: Elena Laskavaia <elaskavaia.cdt@gmail.com>
This commit is contained in:
parent
4c8e2f3d91
commit
2a3246fa84
4 changed files with 392 additions and 106 deletions
|
@ -25,6 +25,9 @@ import java.util.HashSet;
|
|||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
|
||||
import org.eclipse.cdt.launchbar.core.AbstarctLaunchDescriptorType;
|
||||
import org.eclipse.cdt.launchbar.core.AbstractLaunchConfigurationProvider;
|
||||
import org.eclipse.cdt.launchbar.core.AbstractLaunchDescriptor;
|
||||
import org.eclipse.cdt.launchbar.core.AbstractLaunchTarget;
|
||||
import org.eclipse.cdt.launchbar.core.AbstractLaunchTargetType;
|
||||
import org.eclipse.cdt.launchbar.core.ConfigBasedLaunchConfigurationProvider;
|
||||
|
@ -48,6 +51,7 @@ import org.eclipse.core.runtime.IExtension;
|
|||
import org.eclipse.core.runtime.IExtensionPoint;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||
|
@ -105,6 +109,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
private ArrayList<ILaunchMode> globalmodes = new ArrayList<>();
|
||||
IExtensionPoint point;
|
||||
IEclipsePreferences store = new EclipsePreferences();
|
||||
private LocalTargetType localTargetType;
|
||||
|
||||
public class FixedLaunchBarManager extends LaunchBarManager {
|
||||
public FixedLaunchBarManager() throws CoreException {
|
||||
|
@ -195,7 +200,6 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
manager.addConfigProvider(descType.getId(), targetType.getId(), false, provider);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAddConfigProviderBad() throws CoreException {
|
||||
provider = spy(provider);
|
||||
|
@ -424,13 +428,13 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
|
||||
protected void userDeletesLC(ILaunchConfiguration lc2) {
|
||||
String string = lc2.getName();
|
||||
reset(lc2);
|
||||
reset(lc2);
|
||||
doReturn(string).when(lc2).getName();
|
||||
manager.launchConfigurationRemoved(lc2);
|
||||
}
|
||||
}
|
||||
|
||||
protected void projectMappingSetup() {
|
||||
descType = new ProjectBasedLaunchDescriptorType("desc2", lctype.getIdentifier()) {
|
||||
descType = new ProjectBasedLaunchDescriptorType("desc2", lctype.getIdentifier()) {
|
||||
protected IProject getProject(ILaunchConfiguration llc) {
|
||||
return getProjectByName(getProjectName(llc));
|
||||
}
|
||||
|
@ -450,7 +454,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
aaa = mockProject("aaa");
|
||||
mockLCProject(lc, aaa.getName());
|
||||
assertEquals(0, manager.getLaunchDescriptors().length);
|
||||
}
|
||||
}
|
||||
|
||||
public void testLaunchObjectAddedRemapping2() throws CoreException {
|
||||
projectMappingSetup();
|
||||
|
@ -548,7 +552,6 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
@Test
|
||||
public void testGetLaunchModesFew() throws CoreException {
|
||||
basicSetup();
|
||||
|
||||
ILaunchConfigurationType lctype2 = mockLCType("lctype2");
|
||||
mockLaunchModes(lctype2, "modex");
|
||||
mockLaunchModes(lctype, "run", "debug", "foo");
|
||||
|
@ -557,7 +560,6 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
assertEquals(3, launchModes.length);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSetActiveLaunchMode() {
|
||||
ILaunchMode mode = mock(ILaunchMode.class);
|
||||
|
@ -573,6 +575,14 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
assertEquals(null, manager.getActiveLaunchMode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetActiveLaunchModeNull2() {
|
||||
ILaunchMode modes[] = mockLaunchModes(lctype, "run", "debug", "foo");
|
||||
manager.setActiveLaunchMode(modes[0]);
|
||||
manager.setActiveLaunchMode(null);
|
||||
assertEquals(null, manager.getActiveLaunchMode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetActiveLaunchModeUnsupported() {
|
||||
basicSetup();
|
||||
|
@ -679,12 +689,101 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
|
||||
@Test
|
||||
public void testGetLaunchConfigurationType() throws CoreException {
|
||||
manager.getLaunchConfigurationType(desc, mytarget);
|
||||
assertNotNull(manager.getLaunchConfigurationType(desc, mytarget));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLaunchConfigurationTypeSet() throws CoreException {
|
||||
basicSetup();
|
||||
assertNotNull(manager.getLaunchConfigurationType(desc, mytarget));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLaunchConfigurationTypeSet2() throws CoreException {
|
||||
|
||||
descType = new AbstarctLaunchDescriptorType() {
|
||||
@Override
|
||||
public boolean ownsLaunchObject(Object element) throws CoreException {
|
||||
// TODO Auto-generated method stub
|
||||
return element.equals("bla");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchDescriptor getDescriptor(Object element) throws CoreException {
|
||||
return desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "bla";
|
||||
}
|
||||
};
|
||||
desc = new AbstractLaunchDescriptor() {
|
||||
@Override
|
||||
public ILaunchDescriptorType getType() {
|
||||
return descType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "bla";
|
||||
}
|
||||
};
|
||||
provider = new AbstractLaunchConfigurationProvider() {
|
||||
@Override
|
||||
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor) throws CoreException {
|
||||
return lc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor) throws CoreException {
|
||||
return lctype;
|
||||
}
|
||||
};
|
||||
manager.addTargetType(targetType);
|
||||
manager.addDescriptorType(descType, 5);
|
||||
assertEquals(null, manager.getLaunchConfigurationType(desc, null));
|
||||
manager.addConfigProvider(descType.getId(), targetType.getId(), false, provider);
|
||||
assertEquals(lctype, manager.getLaunchConfigurationType(desc, mytarget));
|
||||
assertEquals(lctype, manager.getLaunchConfigurationType(desc, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLaunchConfigurationNull() throws CoreException {
|
||||
assertNull(manager.getLaunchConfiguration(null, mytarget));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLaunchConfigurationNull2() throws CoreException {
|
||||
assertNull(manager.getLaunchConfiguration(desc, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLaunchConfigurationDummy() throws CoreException {
|
||||
assertNull(manager.getLaunchConfiguration(desc, mytarget));
|
||||
}
|
||||
|
||||
public void testGetLaunchConfigurationLocal() throws CoreException {
|
||||
basicSetup();
|
||||
addDefaultProvider();
|
||||
assertFalse(manager.supportsTargetType(desc, localTargetType));
|
||||
assertNull(manager.getLaunchConfiguration(desc, localTargetType.getTargets()[0]));
|
||||
}
|
||||
|
||||
public void testGetLaunchConfiguration() throws CoreException {
|
||||
manager.getLaunchConfiguration(desc, mytarget);
|
||||
basicSetup();
|
||||
assertTrue(manager.supportsTargetType(desc, targetType));
|
||||
assertNotNull(manager.getLaunchConfiguration(desc, mytarget));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -739,11 +838,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
provider = spy(provider);
|
||||
basicSetup();
|
||||
// emulate default type (if running not from plugin)
|
||||
LocalTargetType localType = new LocalTargetType();
|
||||
manager.addTargetType(localType);
|
||||
DefaultLaunchDescriptorType type = new DefaultLaunchDescriptorType();
|
||||
manager.addDescriptorType(type, 1);
|
||||
manager.addConfigProvider(type.getId(), localType.getId(), false, new DefaultLaunchConfigurationProvider());
|
||||
DefaultLaunchDescriptorType type = addDefaultProvider();
|
||||
// another lc not covered by provider
|
||||
ILaunchConfigurationType lctype2 = mockLCType("lctype2");
|
||||
ILaunchConfiguration lc2 = mockLC("lc2", lctype2);
|
||||
|
@ -754,7 +849,25 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
assertNotNull(launchDescriptors[0]);
|
||||
assertEquals(lc2.getName(), launchDescriptors[0].getName());
|
||||
manager.setActiveLaunchDescriptor(type.getDescriptor(lc2));
|
||||
assertEquals(localType.getTargets()[0], manager.getActiveLaunchTarget());
|
||||
assertEquals(localTargetType.getTargets()[0], manager.getActiveLaunchTarget());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLaunchConfigurationAddedBad() throws CoreException {
|
||||
provider = spy(provider);
|
||||
basicSetup();
|
||||
doThrow(new NullPointerException()).when(provider).launchConfigurationAdded(any(ILaunchConfiguration.class));
|
||||
manager.launchConfigurationAdded(lc);
|
||||
verify(provider).launchConfigurationAdded(lc);
|
||||
}
|
||||
|
||||
public DefaultLaunchDescriptorType addDefaultProvider() {
|
||||
localTargetType = new LocalTargetType();
|
||||
manager.addTargetType(localTargetType);
|
||||
DefaultLaunchDescriptorType type = new DefaultLaunchDescriptorType();
|
||||
manager.addDescriptorType(type, 1);
|
||||
manager.addConfigProvider(type.getId(), localTargetType.getId(), false, new DefaultLaunchConfigurationProvider());
|
||||
return type;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -765,6 +878,24 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
verify(provider).launchConfigurationRemoved(lc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLaunchConfigurationRemovedNoClaim() throws CoreException {
|
||||
manager = spy(manager);
|
||||
addDefaultProvider();
|
||||
manager.launchConfigurationAdded(lc);
|
||||
manager.launchConfigurationRemoved(lc);
|
||||
verify(manager).launchObjectRemoved(lc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLaunchConfigurationRemovedBad() throws CoreException {
|
||||
provider = spy(provider);
|
||||
basicSetup();
|
||||
doThrow(new NullPointerException()).when(provider).launchConfigurationRemoved(any(ILaunchConfiguration.class));
|
||||
manager.launchConfigurationRemoved(lc);
|
||||
verify(provider).launchConfigurationRemoved(lc);
|
||||
}
|
||||
|
||||
public void testExtensionConfigDefaultProvider() throws CoreException {
|
||||
IExtension extension = mock(IExtension.class);
|
||||
doReturn(new IExtension[] { extension }).when(point).getExtensions();
|
||||
|
@ -790,4 +921,132 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
doReturn(targetType.getId()).when(element).getAttribute("id");
|
||||
doReturn(targetType).when(element).createExecutableExtension("class");
|
||||
}
|
||||
|
||||
public void testExtensionDescriptorType() throws CoreException {
|
||||
IExtension extension = mock(IExtension.class);
|
||||
doReturn(new IExtension[] { extension }).when(point).getExtensions();
|
||||
IConfigurationElement element = mock(IConfigurationElement.class);
|
||||
doReturn(new IConfigurationElement[] { element }).when(extension).getConfigurationElements();
|
||||
descType = spy(descType);
|
||||
mockDescType(element, descType);
|
||||
doReturn(new ILaunchConfiguration[] { lc }).when(lman).getLaunchConfigurations();
|
||||
store.put("activeConfigDesc", desc.getId());
|
||||
manager = new FixedLaunchBarManager();
|
||||
verify(descType).getDescriptor(lc);
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
assertEquals(1, launchDescriptors.length);
|
||||
assertEquals(desc, launchDescriptors[0]);
|
||||
// assertEquals(desc, descriptor);
|
||||
}
|
||||
|
||||
protected void mockDescType(IConfigurationElement element, ILaunchDescriptorType descType) throws CoreException {
|
||||
doReturn("descriptorType").when(element).getName();
|
||||
doReturn(descType.getId()).when(element).getAttribute("id");
|
||||
doReturn("5").when(element).getAttribute("priority");
|
||||
doReturn(descType).when(element).createExecutableExtension("class");
|
||||
}
|
||||
|
||||
public void testExtensionDescriptorTypeBad() throws CoreException {
|
||||
IExtension extension = mock(IExtension.class);
|
||||
doReturn(new IExtension[] { extension }).when(point).getExtensions();
|
||||
IConfigurationElement element = mock(IConfigurationElement.class);
|
||||
doReturn(new IConfigurationElement[] { element }).when(extension).getConfigurationElements();
|
||||
descType = spy(descType);
|
||||
mockDescType(element, descType);
|
||||
doThrow(new CoreException(new Status(1, "a", "n"))).when(element).createExecutableExtension("class");
|
||||
doReturn(new ILaunchConfiguration[] { lc }).when(lman).getLaunchConfigurations();
|
||||
manager = new FixedLaunchBarManager();
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
assertEquals(0, launchDescriptors.length);
|
||||
}
|
||||
|
||||
public void testExtensionDescriptorTypeBadId() throws CoreException {
|
||||
IExtension extension = mock(IExtension.class);
|
||||
doReturn(new IExtension[] { extension }).when(point).getExtensions();
|
||||
IConfigurationElement element = mock(IConfigurationElement.class);
|
||||
doReturn(new IConfigurationElement[] { element }).when(extension).getConfigurationElements();
|
||||
descType = spy(descType);
|
||||
mockDescType(element, descType);
|
||||
doReturn(descType.getId() + "somestuff").when(element).getAttribute("id");
|
||||
doReturn(new ILaunchConfiguration[] { lc }).when(lman).getLaunchConfigurations();
|
||||
manager = new FixedLaunchBarManager();
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
assertEquals(0, launchDescriptors.length);
|
||||
}
|
||||
|
||||
public void testExtensionDescriptorTypeBadPrio() throws CoreException {
|
||||
IExtension extension = mock(IExtension.class);
|
||||
doReturn(new IExtension[] { extension }).when(point).getExtensions();
|
||||
IConfigurationElement element = mock(IConfigurationElement.class);
|
||||
doReturn(new IConfigurationElement[] { element }).when(extension).getConfigurationElements();
|
||||
descType = spy(descType);
|
||||
mockDescType(element, descType);
|
||||
|
||||
doReturn("5a").when(element).getAttribute("priority");
|
||||
doReturn(new ILaunchConfiguration[] { lc }).when(lman).getLaunchConfigurations();
|
||||
manager = new FixedLaunchBarManager();
|
||||
verify(descType).getDescriptor(lc);
|
||||
assertEquals(desc, manager.getLaunchDescriptors()[0]);
|
||||
}
|
||||
|
||||
public void testExtensionDescriptorTypeNoPrio() throws CoreException {
|
||||
IExtension extension = mock(IExtension.class);
|
||||
doReturn(new IExtension[] { extension }).when(point).getExtensions();
|
||||
IConfigurationElement element = mock(IConfigurationElement.class);
|
||||
doReturn(new IConfigurationElement[] { element }).when(extension).getConfigurationElements();
|
||||
descType = spy(descType);
|
||||
mockDescType(element, descType);
|
||||
doReturn(null).when(element).getAttribute("priority");
|
||||
doReturn(new ILaunchConfiguration[] { lc }).when(lman).getLaunchConfigurations();
|
||||
manager = new FixedLaunchBarManager();
|
||||
verify(descType).getDescriptor(lc);
|
||||
assertEquals(desc, manager.getLaunchDescriptors()[0]);
|
||||
}
|
||||
|
||||
public void testExtensionTargetType() throws CoreException {
|
||||
IExtension extension = mock(IExtension.class);
|
||||
doReturn(new IExtension[] { extension }).when(point).getExtensions();
|
||||
IConfigurationElement targetElement = mock(IConfigurationElement.class);
|
||||
mockTargetElement(targetElement, targetType);
|
||||
doReturn(new IConfigurationElement[] { targetElement }).when(extension).getConfigurationElements();
|
||||
manager = new FixedLaunchBarManager();
|
||||
targetType.targets.add(mytarget);
|
||||
ILaunchTarget launchTarget = manager.getLaunchTarget(mytarget.getId());
|
||||
assertEquals(mytarget, launchTarget);
|
||||
}
|
||||
|
||||
public void testExtensionTargetTypeBad() throws CoreException {
|
||||
IExtension extension = mock(IExtension.class);
|
||||
doReturn(new IExtension[] { extension }).when(point).getExtensions();
|
||||
IConfigurationElement targetElement = mock(IConfigurationElement.class);
|
||||
mockTargetElement(targetElement, targetType);
|
||||
doReturn(targetType.getId() + "some").when(targetElement).getAttribute("id");
|
||||
doReturn(new IConfigurationElement[] { targetElement }).when(extension).getConfigurationElements();
|
||||
manager = new FixedLaunchBarManager();
|
||||
targetType.targets.add(mytarget);
|
||||
ILaunchTarget launchTarget = manager.getLaunchTarget(mytarget.getId());
|
||||
assertNull(launchTarget);
|
||||
}
|
||||
|
||||
public void testExtensionConfigProvider() throws CoreException {
|
||||
IExtension extension = mock(IExtension.class);
|
||||
doReturn(new IExtension[] { extension }).when(point).getExtensions();
|
||||
IConfigurationElement element = mock(IConfigurationElement.class);
|
||||
IConfigurationElement targetElement = mock(IConfigurationElement.class);
|
||||
IConfigurationElement descElement = mock(IConfigurationElement.class);
|
||||
mockTargetElement(targetElement, targetType);
|
||||
mockDescType(descElement, descType);
|
||||
doReturn(new IConfigurationElement[] { element, targetElement, descElement }).when(extension).getConfigurationElements();
|
||||
doReturn("configProvider").when(element).getName();
|
||||
doReturn(targetType.getId()).when(element).getAttribute("targetType");
|
||||
doReturn(descType.getId()).when(element).getAttribute("descriptorType");
|
||||
doReturn(provider).when(element).createExecutableExtension("class");
|
||||
doReturn(new ILaunchConfiguration[] { lc }).when(lman).getLaunchConfigurations();
|
||||
targetType.targets.add(mytarget);
|
||||
manager = new FixedLaunchBarManager();
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
assertEquals(1, launchDescriptors.length);
|
||||
assertEquals(desc, launchDescriptors[0]);
|
||||
assertEquals(mytarget, manager.getActiveLaunchTarget());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public class ConfigBasedLaunchDescriptor extends AbstractLaunchDescriptor implem
|
|||
if (type instanceof ConfigBasedLaunchDescriptorType) {
|
||||
return ((ConfigBasedLaunchDescriptorType) type).getLaunchConfigurationType();
|
||||
}
|
||||
return null;
|
||||
throw new IllegalStateException("Cannot determine configuration type for " + this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,6 +24,8 @@ public interface ILaunchDescriptorConfigBased extends ILaunchDescriptor {
|
|||
|
||||
/**
|
||||
* Return launch configuration type on which it is based (cannot be null)
|
||||
*
|
||||
* @NonNull
|
||||
*/
|
||||
public ILaunchConfigurationType getLaunchConfigurationType();
|
||||
}
|
||||
|
|
|
@ -71,9 +71,30 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
IEclipsePreferences store = getPreferenceStore();
|
||||
String activeConfigDescId = store.get(PREF_ACTIVE_CONFIG_DESC, null);
|
||||
String configDescIds = store.get(PREF_CONFIG_DESC_ORDER, Collections.EMPTY_LIST.toString());
|
||||
IExtensionPoint point = getExtensionPoint();
|
||||
|
||||
|
||||
loadExtensions();
|
||||
|
||||
// Hook up the existing launch configurations and listen
|
||||
ILaunchManager launchManager = getLaunchManager();
|
||||
for (ILaunchConfiguration configuration : launchManager.getLaunchConfigurations()) {
|
||||
launchConfigurationAdded(configuration);
|
||||
}
|
||||
launchManager.addLaunchConfigurationListener(this);
|
||||
reorderDescriptors(configDescIds);
|
||||
// Now that all the descriptors are loaded, set the one
|
||||
ILaunchDescriptor configDesc = descriptors.get(activeConfigDescId);
|
||||
if (configDesc == null) {
|
||||
configDesc = getLastUsedDescriptor();
|
||||
}
|
||||
setActiveLaunchDescriptor(configDesc);
|
||||
}
|
||||
|
||||
|
||||
protected void loadExtensions() {
|
||||
IExtensionPoint point = getExtensionPoint();
|
||||
IExtension[] extensions = point.getExtensions();
|
||||
// first pass - target, descriptors and object providers
|
||||
// first pass - targets and descriptors
|
||||
for (IExtension extension : extensions) {
|
||||
for (IConfigurationElement element : extension.getConfigurationElements()) {
|
||||
try {
|
||||
|
@ -82,7 +103,9 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
String id = element.getAttribute("id");
|
||||
String priorityStr = element.getAttribute("priority");
|
||||
ILaunchDescriptorType type = (ILaunchDescriptorType) element.createExecutableExtension("class");
|
||||
assert id.equals(type.getId());
|
||||
if (!id.equals(type.getId()))
|
||||
throw new IllegalArgumentException("Descriptor Type id " + id
|
||||
+ " is mismatched with id defined in class " + type.getId());
|
||||
int priority = 1;
|
||||
if (priorityStr != null) {
|
||||
try {
|
||||
|
@ -96,11 +119,10 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
} else if (elementName.equals("targetType")) {
|
||||
String id = element.getAttribute("id");
|
||||
ILaunchTargetType targetType = (ILaunchTargetType) element.createExecutableExtension("class");
|
||||
assert id.equals(targetType.getId());
|
||||
if (!id.equals(targetType.getId()))
|
||||
throw new IllegalArgumentException("Target Type id " + id
|
||||
+ " is mismatched with id defined in class " + targetType.getId());
|
||||
addTargetType(targetType);
|
||||
} else if (elementName.equals("objectProvider")) {
|
||||
ILaunchObjectProvider objectProvider = (ILaunchObjectProvider) element.createExecutableExtension("class");
|
||||
objectProviders.add(objectProvider);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Activator.log(e); // exceptions during extension loading, log and move on
|
||||
|
@ -134,26 +156,25 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
Activator.log(e); // exceptions during extension loading, log and move on
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// third pass - object providers
|
||||
for (IExtension extension : extensions) {
|
||||
for (IConfigurationElement element : extension.getConfigurationElements()) {
|
||||
try {
|
||||
String elementName = element.getName();
|
||||
if (elementName.equals("objectProvider")) {
|
||||
ILaunchObjectProvider objectProvider = (ILaunchObjectProvider) element.createExecutableExtension("class");
|
||||
addObjectProvider(objectProvider);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Activator.log(e); // exceptions during extension loading, log and move on
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (ILaunchObjectProvider objectProvider : objectProviders) {
|
||||
objectProvider.init(this);
|
||||
}
|
||||
// Hook up the existing launch configurations and listen
|
||||
ILaunchManager launchManager = getLaunchManager();
|
||||
for (ILaunchConfiguration configuration : launchManager.getLaunchConfigurations()) {
|
||||
launchConfigurationAdded(configuration);
|
||||
}
|
||||
launchManager.addLaunchConfigurationListener(this);
|
||||
reorderDescriptors(configDescIds);
|
||||
// Now that all the descriptors are loaded, set the one
|
||||
ILaunchDescriptor configDesc = descriptors.get(activeConfigDescId);
|
||||
if (configDesc == null) {
|
||||
configDesc = getLastUsedDescriptor();
|
||||
}
|
||||
setActiveLaunchDescriptor(configDesc);
|
||||
}
|
||||
|
||||
private void reorderDescriptors(String configDescIds) {
|
||||
configDescIds = configDescIds.replaceAll("[\\]\\[]", "");
|
||||
|
@ -209,6 +230,15 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
Activator.trace("registered target " + targetType);
|
||||
}
|
||||
|
||||
public void addObjectProvider(ILaunchObjectProvider objectProvider) {
|
||||
objectProviders.add(objectProvider);
|
||||
try {
|
||||
objectProvider.init(this);
|
||||
} catch (Exception e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected ILaunchManager getLaunchManager() {
|
||||
return DebugPlugin.getDefault().getLaunchManager();
|
||||
}
|
||||
|
@ -226,12 +256,12 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
throw new IllegalStateException("Target type " + targetType + " is not registered");
|
||||
if (!descriptorTypes.containsKey(getDescriptorType(descriptorType)))
|
||||
throw new IllegalStateException("Descriptor type " + descriptorType + " is not registered");
|
||||
Map<String, ILaunchConfigurationProvider> targetTypes = configProviders.get(descriptorType);
|
||||
if (targetTypes == null) {
|
||||
targetTypes = new HashMap<>();
|
||||
configProviders.put(descriptorType, targetTypes);
|
||||
Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(descriptorType);
|
||||
if (targetMap == null) {
|
||||
targetMap = new HashMap<>();
|
||||
configProviders.put(descriptorType, targetMap);
|
||||
}
|
||||
targetTypes.put(targetType, configProvider);
|
||||
targetMap.put(targetType, configProvider);
|
||||
if (isDefaultB || defaultTargetTypes.get(descriptorType) == null) {
|
||||
defaultTargetTypes.put(descriptorType, targetType);
|
||||
}
|
||||
|
@ -252,7 +282,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
}
|
||||
|
||||
protected ILaunchDescriptor remapLaunchObject(Object element) {
|
||||
// remove old mapping. We have to do it anyway, no matter even nobody own it (and especially because of that)
|
||||
// remove old mapping. We have to do it anyway, no matter even nobody owns it (and especially because of that)
|
||||
ILaunchDescriptor old = objectDescriptorMap.get(element);
|
||||
if (old != null) { // old mapping is removed
|
||||
objectDescriptorMap.remove(element);
|
||||
|
@ -317,15 +347,13 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
public void launchObjectRemoved(Object element) {
|
||||
Activator.trace("launch object removed " + element);
|
||||
ILaunchDescriptor desc = objectDescriptorMap.get(element);
|
||||
objectDescriptorMap.remove(element);
|
||||
objectDescriptorMap.remove(element); // remove launch object unconditionally
|
||||
if (desc != null) {
|
||||
if (!objectDescriptorMap.values().contains(desc)) {
|
||||
if (!objectDescriptorMap.values().contains(desc)) { // can multiple elements maps to the equal descriptor?
|
||||
// if no one else is mapped to it
|
||||
descriptors.remove(getId(desc)); // can multiple elements maps to the same descriptor?
|
||||
descriptors.remove(getId(desc));
|
||||
if (desc.equals(activeLaunchDesc)) {
|
||||
// Roll back to the last one and make sure we don't come back
|
||||
ILaunchDescriptor nextDesc = getLastUsedDescriptor();
|
||||
setActiveLaunchDescriptor(nextDesc);
|
||||
setActiveLaunchDescriptor(getLastUsedDescriptor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -395,20 +423,19 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
setActiveLaunchTarget(null);
|
||||
return;
|
||||
}
|
||||
// checking active target
|
||||
if (activeLaunchTarget != null && supportsTargetType(activeLaunchDesc, activeLaunchTarget.getType()))
|
||||
return; // not changing target
|
||||
|
||||
// last stored target from persistent storage
|
||||
String activeTargetId = getPerDescriptorStore().get(PREF_ACTIVE_LAUNCH_TARGET, null);
|
||||
ILaunchTarget targets[] = new ILaunchTarget[] {
|
||||
activeLaunchTarget, // current active
|
||||
getLaunchTarget(activeTargetId), // last stored target from persistent storage
|
||||
getDeafultLaunchTarget() // default target for this desc
|
||||
};
|
||||
ILaunchTarget target = null;
|
||||
for (int i = 0; i < targets.length; i++) {
|
||||
target = targets[i];
|
||||
if (target != null && supportsTargetType(activeLaunchDesc, target.getType())) {
|
||||
break;
|
||||
}
|
||||
ILaunchTarget storedTarget = getLaunchTarget(activeTargetId);
|
||||
if (storedTarget != null && supportsTargetType(activeLaunchDesc, storedTarget.getType())) {
|
||||
setActiveLaunchTarget(storedTarget);
|
||||
return;
|
||||
}
|
||||
setActiveLaunchTarget(target);
|
||||
// default target for descriptor
|
||||
setActiveLaunchTarget(getDeafultLaunchTarget(activeLaunchDesc));
|
||||
}
|
||||
|
||||
protected void syncActiveMode() {
|
||||
|
@ -520,11 +547,10 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
if (activeLaunchDesc == null)
|
||||
if (mode == null)
|
||||
return;
|
||||
// store mode
|
||||
String modeId = mode == null ? null : mode.getIdentifier();
|
||||
setPreference(getPerDescriptorStore(), PREF_ACTIVE_LAUNCH_MODE, modeId); // per desc store
|
||||
setPreference(getPerDescriptorStore(), PREF_ACTIVE_LAUNCH_MODE, mode.getIdentifier()); // per desc store
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -560,7 +586,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
public void setActiveLaunchTarget(ILaunchTarget target) {
|
||||
if (target == null) {
|
||||
// try and select another target XXX this should not be an API
|
||||
target = getDeafultLaunchTarget();
|
||||
target = getDeafultLaunchTarget(activeLaunchDesc);
|
||||
}
|
||||
if (activeLaunchTarget == target)
|
||||
return;
|
||||
|
@ -589,13 +615,12 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
}
|
||||
}
|
||||
|
||||
protected ILaunchTarget getDeafultLaunchTarget() {
|
||||
ILaunchTarget target = null;
|
||||
ILaunchTarget[] targets = getLaunchTargets();
|
||||
protected ILaunchTarget getDeafultLaunchTarget(ILaunchDescriptor descriptor) {
|
||||
ILaunchTarget[] targets = getLaunchTargets(descriptor);
|
||||
if (targets.length > 0) {
|
||||
target = targets[0];
|
||||
return targets[0];
|
||||
}
|
||||
return target;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -617,20 +642,13 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
try {
|
||||
if (descriptor instanceof ILaunchDescriptorConfigBased) {
|
||||
// if descriptor is launch config based we don't need provider to determine the type
|
||||
ILaunchConfiguration config = ((ILaunchDescriptorConfigBased) descriptor).getLaunchConfiguration();
|
||||
if (config != null)
|
||||
return config.getType();
|
||||
return ((ILaunchDescriptorConfigBased) descriptor).getLaunchConfigurationType();
|
||||
}
|
||||
String descriptorTypeId = descriptor.getType().getId();
|
||||
Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(descriptorTypeId);
|
||||
if (targetMap != null) {
|
||||
String targetTypeId = target != null ? target.getType().getId() : defaultTargetTypes.get(descriptorTypeId);
|
||||
if (targetTypeId != null) {
|
||||
ILaunchConfigurationProvider configProvider = targetMap.get(targetTypeId);
|
||||
if (configProvider != null) {
|
||||
return configProvider.getLaunchConfigurationType(descriptor);
|
||||
}
|
||||
}
|
||||
String targetTypeId = target != null ? target.getType().getId() : defaultTargetTypes.get(descriptorTypeId);
|
||||
ILaunchConfigurationProvider configProvider = getConfigProvider(descriptorTypeId, targetTypeId);
|
||||
if (configProvider != null) {
|
||||
return configProvider.getLaunchConfigurationType(descriptor);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Activator.log(e); // we calling provider code inside try block, better be safe
|
||||
|
@ -639,25 +657,30 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
}
|
||||
|
||||
public boolean supportsTargetType(ILaunchDescriptor descriptor, ILaunchTargetType targetType) {
|
||||
if (descriptor == null || targetType == null)
|
||||
return false;
|
||||
Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(descriptor.getType().getId());
|
||||
if (targetMap != null) {
|
||||
return targetMap.get(targetType.getId()) != null;
|
||||
}
|
||||
return false;
|
||||
return getConfigProvider(descriptor, targetType) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException {
|
||||
if (descriptor == null || target == null)
|
||||
if (target == null)
|
||||
return null;
|
||||
Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(descriptor.getType().getId());
|
||||
ILaunchConfigurationProvider configProvider = getConfigProvider(descriptor, target.getType());
|
||||
if (configProvider != null) {
|
||||
return configProvider.getLaunchConfiguration(descriptor);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ILaunchConfigurationProvider getConfigProvider(ILaunchDescriptor descriptor, ILaunchTargetType targetType) {
|
||||
if (descriptor == null || targetType == null)
|
||||
return null;
|
||||
return getConfigProvider(descriptor.getType().getId(), targetType.getId());
|
||||
}
|
||||
|
||||
public ILaunchConfigurationProvider getConfigProvider(String descriptorTypeId, String targetTypeId) {
|
||||
Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(descriptorTypeId);
|
||||
if (targetMap != null) {
|
||||
ILaunchConfigurationProvider configProvider = targetMap.get(target.getType().getId());
|
||||
if (configProvider != null) {
|
||||
return configProvider.getLaunchConfiguration(descriptor);
|
||||
}
|
||||
return targetMap.get(targetTypeId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -678,14 +701,16 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
// TODO filter by launch configuration type to avoid loading plug-ins
|
||||
for (ILaunchDescriptorType descriptorType : descriptorTypes.keySet()) {
|
||||
Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(descriptorType.getId());
|
||||
for (ILaunchConfigurationProvider configProvider : targetMap.values()) {
|
||||
try {
|
||||
if (configProvider.launchConfigurationAdded(configuration)) {
|
||||
Activator.trace("launch config claimed by " + configProvider);
|
||||
return;
|
||||
if (targetMap != null) {
|
||||
for (ILaunchConfigurationProvider configProvider : targetMap.values()) {
|
||||
try {
|
||||
if (configProvider.launchConfigurationAdded(configuration)) {
|
||||
Activator.trace("launch config claimed by " + configProvider);
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Activator.log(e); // don't let one bad provider affect the rest
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Activator.log(e); // don't let one bad provider affect the rest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue