mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-11 18:25:40 +02:00
LaunchBar - junits - more tweaks and refactoring
Change-Id: Ia786fd63c07b3240c1535036b443675dd4931eca Signed-off-by: Alena Laskavaia <elaskavaia.cdt@gmail.com> Reviewed-on: https://git.eclipse.org/r/30732 Tested-by: Hudson CI
This commit is contained in:
parent
05795e449e
commit
86864c02fe
9 changed files with 648 additions and 206 deletions
|
@ -8,6 +8,8 @@ Require-Bundle: org.eclipse.core.runtime,
|
|||
org.junit;bundle-version="4.11.0",
|
||||
org.mockito,
|
||||
org.eclipse.cdt.launchbar.core;bundle-version="1.0.0",
|
||||
org.eclipse.debug.core
|
||||
org.eclipse.debug.core,
|
||||
org.eclipse.cdt.debug.core,
|
||||
org.eclipse.core.filesystem
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Bundle-ActivationPolicy: lazy
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.launchbar.core.internal;
|
||||
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -22,6 +24,7 @@ import java.util.HashSet;
|
|||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
|
||||
import org.eclipse.cdt.launchbar.core.AbstractLaunchTarget;
|
||||
import org.eclipse.cdt.launchbar.core.AbstractLaunchTargetType;
|
||||
import org.eclipse.cdt.launchbar.core.ConfigBasedLaunchConfigurationProvider;
|
||||
|
@ -33,10 +36,17 @@ import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
|
|||
import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType;
|
||||
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
|
||||
import org.eclipse.cdt.launchbar.core.ILaunchTargetType;
|
||||
import org.eclipse.cdt.launchbar.core.ProjectBasedLaunchConfigurationProvider;
|
||||
import org.eclipse.cdt.launchbar.core.ProjectBasedLaunchDescriptorType;
|
||||
import org.eclipse.core.internal.preferences.EclipsePreferences;
|
||||
import org.eclipse.core.internal.resources.Project;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
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.preferences.IEclipsePreferences;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||
|
@ -52,11 +62,11 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
private LaunchBarManager manager;
|
||||
private ILaunchConfigurationProvider provider;
|
||||
private ILaunchDescriptor desc;
|
||||
private ILaunchDescriptorType descType;
|
||||
ILaunchDescriptorType descType;
|
||||
private ILaunchConfigurationType lctype;
|
||||
private ILaunchConfiguration lc;
|
||||
|
||||
class TargetType extends AbstractLaunchTargetType {
|
||||
public class TargetType extends AbstractLaunchTargetType {
|
||||
private String id;
|
||||
ArrayList<ILaunchTarget> targets = new ArrayList<>();
|
||||
|
||||
|
@ -90,6 +100,8 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
}
|
||||
private ILaunchTarget mytarget = new LaunchTarget("target_1", targetType);
|
||||
private ILaunchManager lman;
|
||||
private IProject aaa;
|
||||
private ArrayList<ILaunchMode> globalmodes = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
|
@ -97,6 +109,8 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
doReturn(new IExtension[] {}).when(point).getExtensions();
|
||||
lman = mock(ILaunchManager.class);
|
||||
doReturn(new ILaunchConfiguration[] {}).when(lman).getLaunchConfigurations();
|
||||
doReturn(globalmodes.toArray(new ILaunchMode[globalmodes.size()])).when(lman).getLaunchModes();
|
||||
|
||||
final IEclipsePreferences store = new EclipsePreferences();
|
||||
manager = new LaunchBarManager() {
|
||||
@Override
|
||||
|
@ -119,7 +133,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
lctype = mockLCType("lctype1");
|
||||
lc = mockLC("bla", lctype);
|
||||
// other init
|
||||
provider = spy(new ConfigBasedLaunchConfigurationProvider(lctype.getIdentifier()));
|
||||
provider = new ConfigBasedLaunchConfigurationProvider(lctype.getIdentifier());
|
||||
descType = new ConfigBasedLaunchDescriptorType("desctype1", lctype.getIdentifier());
|
||||
desc = new ConfigBasedLaunchDescriptor(descType, lc);
|
||||
}
|
||||
|
@ -145,7 +159,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
return lctype;
|
||||
}
|
||||
|
||||
protected ILaunchMode[] mockLaunchMode(ILaunchConfigurationType type, String... modes) {
|
||||
protected ILaunchMode[] mockLaunchModes(ILaunchConfigurationType type, String... modes) {
|
||||
ILaunchMode res[] = new ILaunchMode[modes.length];
|
||||
for (int i = 0; i < modes.length; i++) {
|
||||
String modeId = modes[i];
|
||||
|
@ -154,8 +168,10 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
res[i] = mode;
|
||||
doReturn(modeId).when(mode).getIdentifier();
|
||||
doReturn(mode).when(lman).getLaunchMode(modeId);
|
||||
globalmodes.add(mode);
|
||||
}
|
||||
doReturn(new HashSet<>(Arrays.asList(modes))).when(type).getSupportedModes();
|
||||
doReturn(globalmodes.toArray(new ILaunchMode[globalmodes.size()])).when(lman).getLaunchModes();
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -172,6 +188,25 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
manager.addConfigProvider(descType.getId(), targetType.getId(), false, provider);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAddConfigProviderBad() throws CoreException {
|
||||
provider = spy(provider);
|
||||
doThrow(new NullPointerException()).when(provider).init(manager);
|
||||
manager.addTargetType(targetType);
|
||||
manager.addDescriptorType(descType, 5);
|
||||
manager.addConfigProvider(descType.getId(), targetType.getId(), false, provider);
|
||||
verify(provider).init(manager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddDescriptorTypeBad() throws CoreException {
|
||||
descType = spy(descType);
|
||||
doThrow(new NullPointerException()).when(descType).init(manager);
|
||||
manager.addDescriptorType(descType, 5);
|
||||
verify(descType).init(manager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddConfigProviderNoTarget() {
|
||||
try {
|
||||
|
@ -211,12 +246,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
public void testAddConfigProviderTwo2() throws CoreException {
|
||||
manager.addTargetType(targetType);
|
||||
manager.addDescriptorType(descType, 5);
|
||||
ILaunchConfigurationProvider provider2 = new ConfigBasedLaunchConfigurationProvider("type2") {
|
||||
@Override
|
||||
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor) throws CoreException {
|
||||
return lctype;
|
||||
}
|
||||
};
|
||||
ILaunchConfigurationProvider provider2 = new ConfigBasedLaunchConfigurationProvider("type2");
|
||||
manager.addConfigProvider(descType.getId(), targetType.getId(), true, provider2);
|
||||
TargetType targetType2 = new TargetType("t2");
|
||||
manager.addTargetType(targetType2);
|
||||
|
@ -224,18 +254,29 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
ILaunchConfigurationType lctype2 = mockLCType("lctypeid2");
|
||||
ILaunchConfiguration lc2 = mockLC("bla2", lctype2);
|
||||
ConfigBasedLaunchDescriptor desc2 = new ConfigBasedLaunchDescriptor(descType, lc2);
|
||||
assertEquals(lctype, manager.getLaunchConfigurationType(desc2, null));
|
||||
assertEquals(lctype2, manager.getLaunchConfigurationType(desc2, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLaunchTargets() throws CoreException {
|
||||
basicSetup();
|
||||
manager.launchObjectAdded(lc);
|
||||
manager.setActiveLaunchDescriptor(desc);
|
||||
ILaunchTarget[] launchTargets = manager.getLaunchTargets();
|
||||
assertEquals(1, launchTargets.length);
|
||||
assertEquals(mytarget, launchTargets[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLaunchTargetsNoProvider() throws CoreException {
|
||||
manager.addTargetType(targetType);
|
||||
targetType.targets.add(mytarget);
|
||||
manager.addDescriptorType(descType, 5);
|
||||
manager.launchObjectAdded(lc);
|
||||
ILaunchTarget[] launchTargets = manager.getLaunchTargets();
|
||||
assertEquals(0, launchTargets.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLaunchDescriptorsNull() {
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
|
@ -274,7 +315,6 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
assertSame(res[0], launchDescriptors[0]);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLaunchObjectAdded() throws CoreException {
|
||||
basicSetup();
|
||||
|
@ -294,6 +334,131 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
assertEquals(2, manager.getLaunchDescriptors().length);
|
||||
}
|
||||
|
||||
public IProject mockProject(String projectName) {
|
||||
IProject project = mock(Project.class);
|
||||
when(project.getAdapter(IResource.class)).thenReturn(project);
|
||||
when(project.getProject()).thenReturn(project);
|
||||
when(project.getName()).thenReturn(projectName);
|
||||
IPath path = new Path(projectName);
|
||||
when(project.getFullPath()).thenReturn(path);
|
||||
when(project.getType()).thenReturn(IResource.PROJECT);
|
||||
return project;
|
||||
}
|
||||
|
||||
public ILaunchConfiguration mockLCProject(ILaunchConfiguration lc, String projectName) {
|
||||
mockLCAttribute(lc, ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
|
||||
return lc;
|
||||
}
|
||||
|
||||
public ILaunchConfiguration mockLCBinary(ILaunchConfiguration lc, String binname) {
|
||||
mockLCAttribute(lc, ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, binname);
|
||||
return lc;
|
||||
}
|
||||
|
||||
public ILaunchConfiguration mockLCAttribute(ILaunchConfiguration lc, String attr, String value) {
|
||||
try {
|
||||
when(lc.getAttribute(eq(attr), anyString())).thenReturn(value);
|
||||
} catch (CoreException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return lc;
|
||||
}
|
||||
|
||||
protected String getProjectName(ILaunchConfiguration llc) {
|
||||
try {
|
||||
return llc.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");
|
||||
} catch (CoreException e) {
|
||||
//
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
IProject getProjectByName(String p) {
|
||||
if (p.equals("aaa"))
|
||||
return aaa;
|
||||
return mockProject(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* This scenario when provider will change mapping element->descriptor, depending on other objects involved
|
||||
*/
|
||||
@Test
|
||||
public void testLaunchObjectAddedRemapping() throws CoreException {
|
||||
projectMappingSetup();
|
||||
// user created a project
|
||||
manager.launchObjectAdded(aaa);
|
||||
assertEquals(1, manager.getLaunchDescriptors().length);
|
||||
assertEquals(aaa.getName(), manager.getLaunchDescriptors()[0].getName());
|
||||
// user clicked on descriptor geer to edit lc, new lc is created
|
||||
manager.launchConfigurationAdded(lc);
|
||||
assertEquals(1, manager.getLaunchDescriptors().length);
|
||||
assertEquals(lc.getName(), manager.getLaunchDescriptors()[0].getName());
|
||||
// user cloned lc and changed some settings
|
||||
ILaunchConfiguration lc2 = mockLC("lc2", lctype);
|
||||
mockLCProject(lc2, aaa.getName());
|
||||
manager.launchConfigurationAdded(lc2);
|
||||
assertEquals(2, manager.getLaunchDescriptors().length);
|
||||
// user deleted lc
|
||||
manager.launchConfigurationRemoved(lc2);
|
||||
assertEquals(1, manager.getLaunchDescriptors().length);
|
||||
// user deleted last lc, now we back to project default
|
||||
manager.launchConfigurationRemoved(lc);
|
||||
assertEquals(1, manager.getLaunchDescriptors().length);
|
||||
}
|
||||
|
||||
protected void projectMappingSetup() {
|
||||
descType = new ProjectBasedLaunchDescriptorType("desc2", lctype.getIdentifier()) {
|
||||
protected IProject getProject(ILaunchConfiguration llc) {
|
||||
return getProjectByName(getProjectName(llc));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean ownsProject(IProject element) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
provider = new ProjectBasedLaunchConfigurationProvider(lctype.getIdentifier()) {
|
||||
protected IProject getProject(ILaunchConfiguration llc) {
|
||||
return getProjectByName(getProjectName(llc));
|
||||
}
|
||||
};
|
||||
desc = null;
|
||||
basicSetup();
|
||||
aaa = mockProject("aaa");
|
||||
mockLCProject(lc, aaa.getName());
|
||||
assertEquals(0, manager.getLaunchDescriptors().length);
|
||||
}
|
||||
|
||||
public void testLaunchObjectAddedRemapping2() throws CoreException {
|
||||
projectMappingSetup();
|
||||
// test unmapping
|
||||
manager.launchObjectAdded(aaa);
|
||||
manager.launchObjectAdded(lc);
|
||||
assertEquals(2, manager.getLaunchDescriptors().length);
|
||||
manager.launchObjectAdded(aaa); // that would remove aaa mapping since lc is already there
|
||||
assertEquals(1, manager.getLaunchDescriptors().length);
|
||||
assertEquals(lc.getName(), manager.getLaunchDescriptors()[0].getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLaunchObjectAddedBadDescriptor() throws CoreException {
|
||||
descType = spy(descType);
|
||||
basicSetup();
|
||||
doThrow(new NullPointerException()).when(descType).ownsLaunchObject(any());
|
||||
// check events
|
||||
manager.launchObjectAdded(lc);
|
||||
verify(descType).ownsLaunchObject(lc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLaunchObjectRemoveBadDescriptor() throws CoreException {
|
||||
descType = spy(descType);
|
||||
basicSetup();
|
||||
doThrow(new NullPointerException()).when(descType).ownsLaunchObject(any());
|
||||
// check events
|
||||
manager.launchObjectRemoved(lc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLaunchObjectRemoved() throws CoreException {
|
||||
basicSetup();
|
||||
|
@ -305,14 +470,52 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
|
||||
@Test
|
||||
public void testGetActiveLaunchDescriptor() throws CoreException {
|
||||
basicSetup();
|
||||
Listener lis = mock(Listener.class);
|
||||
manager.addListener(lis);
|
||||
|
||||
manager.setActiveLaunchDescriptor(desc);
|
||||
manager.launchObjectAdded(lc);
|
||||
// manager.setActiveLaunchDescriptor(desc);
|
||||
assertEquals(desc, manager.getActiveLaunchDescriptor());
|
||||
verify(lis).activeConfigurationDescriptorChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetActiveLaunchDescriptorUnkn() throws CoreException {
|
||||
basicSetup();
|
||||
try {
|
||||
manager.setActiveLaunchDescriptor(desc);
|
||||
fail();
|
||||
} catch (Exception e) {
|
||||
// pass
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetActiveLaunchDescriptorNullBad() throws CoreException {
|
||||
basicSetup();
|
||||
manager.launchObjectAdded(lc);
|
||||
manager.setActiveLaunchDescriptor(null);
|
||||
assertEquals(desc, manager.getActiveLaunchDescriptor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetActiveLaunchDescriptorLisBad() throws CoreException {
|
||||
basicSetup();
|
||||
Listener lis = mock(Listener.class);
|
||||
manager.addListener(lis);
|
||||
doThrow(new NullPointerException()).when(lis).activeConfigurationDescriptorChanged();
|
||||
manager.launchConfigurationAdded(lc);
|
||||
verify(lis).activeConfigurationDescriptorChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetActiveLaunchDescriptorNull() throws CoreException {
|
||||
basicSetup();
|
||||
manager.launchObjectAdded(lc);
|
||||
manager.launchObjectRemoved(lc);
|
||||
manager.setActiveLaunchDescriptor(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLaunchModes() throws CoreException {
|
||||
ILaunchMode[] launchModes = manager.getLaunchModes();
|
||||
|
@ -320,7 +523,20 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetActiveLaunchMode() {
|
||||
public void testGetLaunchModesFew() throws CoreException {
|
||||
basicSetup();
|
||||
|
||||
ILaunchConfigurationType lctype2 = mockLCType("lctype2");
|
||||
mockLaunchModes(lctype2, "modex");
|
||||
mockLaunchModes(lctype, "run", "debug", "foo");
|
||||
manager.launchConfigurationAdded(lc);
|
||||
ILaunchMode[] launchModes = manager.getLaunchModes();
|
||||
assertEquals(3, launchModes.length);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSetActiveLaunchMode() {
|
||||
ILaunchMode mode = mock(ILaunchMode.class);
|
||||
doReturn("bla").when(mode).getIdentifier();
|
||||
doReturn("Bla").when(mode).getLabel();
|
||||
|
@ -328,10 +544,55 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
assertEquals(mode, manager.getActiveLaunchMode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetActiveLaunchModeNull() {
|
||||
manager.setActiveLaunchMode(null);
|
||||
assertEquals(null, manager.getActiveLaunchMode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetActiveLaunchModeUnsupported() {
|
||||
basicSetup();
|
||||
ILaunchConfigurationType lctype2 = mockLCType("lctype2");
|
||||
ILaunchMode mode = mockLaunchModes(lctype2, "modex")[0];
|
||||
mockLaunchModes(lctype, "run", "debug", "foo");
|
||||
manager.launchConfigurationAdded(lc);
|
||||
try {
|
||||
manager.setActiveLaunchMode(mode);
|
||||
fail();
|
||||
} catch (Exception e) {
|
||||
// works
|
||||
assertNotEquals(mode, manager.getActiveLaunchMode());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetActiveLaunchModeLis() {
|
||||
ILaunchMode mode = mock(ILaunchMode.class);
|
||||
doReturn("bla").when(mode).getIdentifier();
|
||||
Listener lis = mock(Listener.class);
|
||||
manager.addListener(lis);
|
||||
manager.setActiveLaunchMode(mode);
|
||||
manager.setActiveLaunchMode(null);
|
||||
verify(lis, times(2)).activeLaunchModeChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetActiveLaunchModeLisBad() {
|
||||
ILaunchMode mode = mock(ILaunchMode.class);
|
||||
doReturn("bla").when(mode).getIdentifier();
|
||||
Listener lis = mock(Listener.class);
|
||||
manager.addListener(lis);
|
||||
doThrow(new NullPointerException()).when(lis).activeLaunchModeChanged();
|
||||
manager.setActiveLaunchMode(mode);
|
||||
verify(lis).activeLaunchModeChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetActiveLaunchModeFromDesc() throws CoreException {
|
||||
basicSetup();
|
||||
mockLaunchMode(lctype, "run");
|
||||
mockLaunchModes(lctype, "run");
|
||||
manager.launchObjectAdded(lc);
|
||||
manager.setActiveLaunchDescriptor(desc);
|
||||
ILaunchMode resmode = manager.getActiveLaunchMode();
|
||||
assertNotNull(resmode);
|
||||
|
@ -341,7 +602,8 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
@Test
|
||||
public void testGetActiveLaunchModeFromDescDebug() throws CoreException {
|
||||
basicSetup();
|
||||
mockLaunchMode(lctype, "run", "debug");
|
||||
mockLaunchModes(lctype, "run", "debug");
|
||||
manager.launchObjectAdded(lc);
|
||||
manager.setActiveLaunchDescriptor(desc);
|
||||
ILaunchMode resmode = manager.getActiveLaunchMode();
|
||||
assertNotNull(resmode);
|
||||
|
@ -351,8 +613,9 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
@Test
|
||||
public void testGetActiveLaunchModeFromDescActive() throws CoreException {
|
||||
basicSetup();
|
||||
mockLaunchMode(lctype, "run");
|
||||
ILaunchMode mode = mockLaunchMode(lctype, "foo")[0];
|
||||
mockLaunchModes(lctype, "run");
|
||||
ILaunchMode mode = mockLaunchModes(lctype, "foo")[0];
|
||||
manager.launchObjectAdded(lc);
|
||||
manager.setActiveLaunchMode(mode);
|
||||
manager.setActiveLaunchDescriptor(desc);
|
||||
ILaunchMode resmode = manager.getActiveLaunchMode();
|
||||
|
@ -368,6 +631,16 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
assertEquals(mytarget, manager.getActiveLaunchTarget());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddTargetTypeBad() {
|
||||
targetType = spy(targetType);
|
||||
doThrow(new NullPointerException()).when(targetType).init(manager);
|
||||
manager.addTargetType(targetType);
|
||||
targetType.targets.add(mytarget);
|
||||
assertEquals(mytarget, manager.getLaunchTarget(mytarget.getId()));
|
||||
verify(targetType).init(manager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLaunchTarget() {
|
||||
manager.addTargetType(targetType);
|
||||
|
@ -397,9 +670,11 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
manager.addListener(lis);
|
||||
basicSetup();
|
||||
// check events
|
||||
manager.launchObjectAdded(lc);
|
||||
manager.setActiveLaunchDescriptor(desc);
|
||||
verify(lis).activeLaunchTargetChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddListenerBad() throws CoreException {
|
||||
Listener lis = mock(Listener.class);
|
||||
|
@ -407,6 +682,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
doThrow(new NullPointerException()).when(lis).activeLaunchTargetChanged();
|
||||
basicSetup();
|
||||
// check events
|
||||
manager.launchObjectAdded(lc);
|
||||
manager.setActiveLaunchDescriptor(desc);
|
||||
verify(lis).activeLaunchTargetChanged();
|
||||
}
|
||||
|
@ -422,8 +698,9 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
|
||||
@Test
|
||||
public void testLaunchConfigurationAdded() throws CoreException {
|
||||
provider = spy(provider);
|
||||
basicSetup();
|
||||
ILaunchMode mode = mockLaunchMode(lctype, "foo")[0];
|
||||
ILaunchMode mode = mockLaunchModes(lctype, "foo")[0];
|
||||
manager.launchConfigurationAdded(lc);
|
||||
verify(provider).launchConfigurationAdded(lc);
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
|
@ -436,6 +713,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testLaunchConfigurationAddedDefault() throws CoreException {
|
||||
provider = spy(provider);
|
||||
basicSetup();
|
||||
// emulate default type (if running not from plugin)
|
||||
LocalTargetType localType = new LocalTargetType();
|
||||
|
@ -458,6 +736,7 @@ public class LaunchBarManagerTest extends TestCase {
|
|||
|
||||
@Test
|
||||
public void testLaunchConfigurationRemoved() throws CoreException {
|
||||
provider = spy(provider);
|
||||
basicSetup();
|
||||
manager.launchConfigurationRemoved(lc);
|
||||
verify(provider).launchConfigurationRemoved(lc);
|
||||
|
|
|
@ -49,4 +49,9 @@ public abstract class AbstarctLaunchDescriptorType implements ILaunchDescriptorT
|
|||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getId();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import org.eclipse.debug.core.ILaunchConfiguration;
|
|||
import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||
|
||||
/**
|
||||
* Abstract provider can work with any ITypeBaseLaunchDescriptor to provide launch configurations
|
||||
* Abstract provider can work with any ILaunchDescriptorConfigBased to provide launch configurations
|
||||
*/
|
||||
public abstract class AbstractLaunchConfigurationProvider implements ILaunchConfigurationProvider {
|
||||
protected ILaunchBarManager manager;
|
||||
|
|
|
@ -12,6 +12,12 @@ package org.eclipse.cdt.launchbar.core;
|
|||
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
|
||||
/**
|
||||
* Interface for descriptors which are based on launch configurations
|
||||
*/
|
||||
public interface ILaunchDescriptorConfigBased extends ILaunchDescriptor {
|
||||
/**
|
||||
* Return launch configuration on which it is based
|
||||
*/
|
||||
public ILaunchConfiguration getConfig();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 QNX Software Systems. All Rights Reserved.
|
||||
*
|
||||
* You must obtain a written license from and pay applicable license fees to QNX
|
||||
* Software Systems before you may reproduce, modify or distribute this software,
|
||||
* or any work that includes all or part of this software. Free development
|
||||
* licenses are available for evaluation and non-commercial purposes. For more
|
||||
* information visit [http://licensing.qnx.com] or email licensing@qnx.com.
|
||||
*
|
||||
* This file may contain contributions from others. Please review this entire
|
||||
* file for other proprietary rights or license notices, as well as the QNX
|
||||
* Development Suite License Guide at [http://licensing.qnx.com/license-guide/]
|
||||
* for other information.
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.launchbar.core;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
|
||||
public abstract class ProjectBasedLaunchConfigurationProvider extends ConfigBasedLaunchConfigurationProvider {
|
||||
public ProjectBasedLaunchConfigurationProvider(String launchConfigurationTypeId) {
|
||||
super(launchConfigurationTypeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
|
||||
boolean res = super.launchConfigurationAdded(configuration);
|
||||
IProject project = getProject(configuration);
|
||||
getManager().launchObjectRemoved(project);
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
|
||||
boolean res = super.launchConfigurationRemoved(configuration);
|
||||
IProject project = getProject(configuration);
|
||||
getManager().launchObjectAdded(project);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected abstract IProject getProject(ILaunchConfiguration llc);
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 QNX Software Systems. All Rights Reserved.
|
||||
*
|
||||
* You must obtain a written license from and pay applicable license fees to QNX
|
||||
* Software Systems before you may reproduce, modify or distribute this software,
|
||||
* or any work that includes all or part of this software. Free development
|
||||
* licenses are available for evaluation and non-commercial purposes. For more
|
||||
* information visit [http://licensing.qnx.com] or email licensing@qnx.com.
|
||||
*
|
||||
* This file may contain contributions from others. Please review this entire
|
||||
* file for other proprietary rights or license notices, as well as the QNX
|
||||
* Development Suite License Guide at [http://licensing.qnx.com/license-guide/]
|
||||
* for other information.
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.launchbar.core;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
|
||||
public class ProjectBasedLaunchDescriptor extends ConfigBasedLaunchDescriptor {
|
||||
private IProject project;
|
||||
|
||||
public ProjectBasedLaunchDescriptor(ILaunchDescriptorType type, IProject p, ILaunchConfiguration lc) {
|
||||
super(type, lc);
|
||||
this.project = p;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
if (getConfig() == null)
|
||||
return project.getName();
|
||||
else
|
||||
return getConfig().getName();
|
||||
}
|
||||
|
||||
public IProject getProject() {
|
||||
return project;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 QNX Software Systems. All Rights Reserved.
|
||||
*
|
||||
* You must obtain a written license from and pay applicable license fees to QNX
|
||||
* Software Systems before you may reproduce, modify or distribute this software,
|
||||
* or any work that includes all or part of this software. Free development
|
||||
* licenses are available for evaluation and non-commercial purposes. For more
|
||||
* information visit [http://licensing.qnx.com] or email licensing@qnx.com.
|
||||
*
|
||||
* This file may contain contributions from others. Please review this entire
|
||||
* file for other proprietary rights or license notices, as well as the QNX
|
||||
* Development Suite License Guide at [http://licensing.qnx.com/license-guide/]
|
||||
* for other information.
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.launchbar.core;
|
||||
|
||||
import org.eclipse.cdt.launchbar.core.internal.Activator;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
|
||||
public abstract class ProjectBasedLaunchDescriptorType extends ConfigBasedLaunchDescriptorType {
|
||||
public ProjectBasedLaunchDescriptorType(String descTypeId, String launchConfigTypeId) {
|
||||
super(descTypeId, launchConfigTypeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ownsLaunchObject(Object element) {
|
||||
if (super.ownsLaunchObject(element))
|
||||
return true;
|
||||
if (element instanceof IProject && ownsProject((IProject) element))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract boolean ownsProject(IProject element);
|
||||
|
||||
@Override
|
||||
public ILaunchDescriptor getDescriptor(Object element) {
|
||||
if (element instanceof ILaunchConfiguration) {
|
||||
ILaunchConfiguration llc = (ILaunchConfiguration) element;
|
||||
IProject project = getProject(llc);
|
||||
return new ProjectBasedLaunchDescriptor(this, project, llc);
|
||||
} else if (element instanceof IProject) {
|
||||
try {
|
||||
ILaunchDescriptor[] lds = getManager().getLaunchDescriptors();
|
||||
for (int i = 0; i < lds.length; i++) {
|
||||
ILaunchDescriptor ld = lds[i];
|
||||
if (ld instanceof ProjectBasedLaunchDescriptor
|
||||
&& element.equals(((ProjectBasedLaunchDescriptor) ld).getProject())) {
|
||||
return null; // somebody else has it
|
||||
}
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
return new ProjectBasedLaunchDescriptor(this, (IProject) element, null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected abstract IProject getProject(ILaunchConfiguration llc);
|
||||
}
|
|
@ -19,7 +19,6 @@ import java.util.LinkedHashMap;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.launchbar.core.ConfigBasedLaunchConfigurationProvider;
|
||||
import org.eclipse.cdt.launchbar.core.ConfigBasedLaunchDescriptorType;
|
||||
|
@ -49,30 +48,28 @@ import org.osgi.service.prefs.BackingStoreException;
|
|||
import org.osgi.service.prefs.Preferences;
|
||||
|
||||
public class LaunchBarManager extends PlatformObject implements ILaunchBarManager, ILaunchConfigurationListener {
|
||||
|
||||
private List<Listener> listeners = new LinkedList<>();
|
||||
private Map<String, ILaunchTargetType> targetTypes = new HashMap<>();
|
||||
private LinkedHashMap<ILaunchDescriptorType, Integer> descriptorTypes = new LinkedHashMap<>();
|
||||
private Map<String, ILaunchDescriptor> descriptors = new HashMap<>();
|
||||
private final Map<String, ILaunchDescriptor> descriptors = new LinkedHashMap<>();
|
||||
private List<ILaunchObjectProvider> objectProviders = new ArrayList<>();
|
||||
// Map descriptor type to target type to provider
|
||||
private Map<String, Map<String, ILaunchConfigurationProvider>> configProviders = new HashMap<>();
|
||||
// Map descriptor type to target type
|
||||
private Map<String, String> defaultTargetTypes = new HashMap<>();
|
||||
private Map<Object, ILaunchDescriptor> objectDescriptorMap = new HashMap<>();
|
||||
|
||||
private ILaunchDescriptor activeLaunchDesc;
|
||||
private ILaunchMode activeLaunchMode;
|
||||
private ILaunchTarget activeLaunchTarget;
|
||||
|
||||
private ILaunchDescriptor lastLaunchDesc;
|
||||
|
||||
private static final String PREF_ACTIVE_CONFIG_DESC = "activeConfigDesc";
|
||||
private static final String PREF_ACTIVE_LAUNCH_MODE = "activeLaunchMode";
|
||||
private static final String PREF_ACTIVE_LAUNCH_TARGET = "activeLaunchTarget";
|
||||
|
||||
|
||||
public LaunchBarManager() throws CoreException {
|
||||
// Load up the active from the preferences before loading the descriptors
|
||||
IEclipsePreferences store = getPreferenceStore();
|
||||
String activeConfigDescId = store.get(PREF_ACTIVE_CONFIG_DESC, null);
|
||||
IExtensionPoint point = getExtensionPoint();
|
||||
IExtension[] extensions = point.getExtensions();
|
||||
// first pass - target, descriptors and object providers
|
||||
|
@ -85,7 +82,6 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
String priorityStr = element.getAttribute("priority");
|
||||
ILaunchDescriptorType type = (ILaunchDescriptorType) element.createExecutableExtension("class");
|
||||
assert id.equals(type.getId());
|
||||
|
||||
int priority = 1;
|
||||
if (priorityStr != null) {
|
||||
try {
|
||||
|
@ -140,41 +136,22 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
}
|
||||
|
||||
|
||||
// Load up the active from the preferences before loading the descriptors
|
||||
IEclipsePreferences store = getPreferenceStore();
|
||||
String activeConfigDescId = store.get(PREF_ACTIVE_CONFIG_DESC, null);
|
||||
|
||||
for (ILaunchDescriptorType descriptorType : descriptorTypes.keySet()) {
|
||||
descriptorType.init(this);
|
||||
}
|
||||
|
||||
for (ILaunchTargetType targetType : targetTypes.values()) {
|
||||
targetType.init(this);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// Now that all the descriptors are loaded, set the one
|
||||
if (activeConfigDescId == null && !descriptors.isEmpty()) {
|
||||
activeConfigDescId = getId(descriptors.values().iterator().next());
|
||||
}
|
||||
|
||||
if (activeConfigDescId != null) {
|
||||
ILaunchDescriptor configDesc = descriptors.get(activeConfigDescId);
|
||||
if (configDesc != null) {
|
||||
if (configDesc == null) {
|
||||
configDesc = getLastUsedDescriptor();
|
||||
}
|
||||
setActiveLaunchDescriptor(configDesc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static void sortMapByValue(LinkedHashMap<ILaunchDescriptorType, Integer> map) {
|
||||
List<Map.Entry<ILaunchDescriptorType, Integer>> entries =
|
||||
|
@ -195,6 +172,11 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
public void addDescriptorType(ILaunchDescriptorType type, int priority) {
|
||||
descriptorTypes.put(type, priority);
|
||||
sortMapByValue(descriptorTypes);
|
||||
try {
|
||||
type.init(this);
|
||||
} catch (Exception e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -202,6 +184,11 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
*/
|
||||
public void addTargetType(ILaunchTargetType targetType) {
|
||||
targetTypes.put(targetType.getId(), targetType);
|
||||
try {
|
||||
targetType.init(this);
|
||||
} catch (Exception e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected ILaunchManager getLaunchManager() {
|
||||
|
@ -232,7 +219,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
}
|
||||
try {
|
||||
configProvider.init(this);
|
||||
} catch (CoreException e) {
|
||||
} catch (Exception e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
|
@ -247,33 +234,31 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
|
||||
@Override
|
||||
public ILaunchDescriptor launchObjectAdded(Object element) {
|
||||
ILaunchDescriptor desc = objectDescriptorMap.get(element);
|
||||
if (desc != null)
|
||||
return desc;
|
||||
|
||||
ILaunchDescriptor desc = null;
|
||||
// don't use objectDescriptorMap as cache - provider may decide to remap objects
|
||||
for (ILaunchDescriptorType descriptorType : descriptorTypes.keySet()) {
|
||||
try {
|
||||
if (descriptorType.ownsLaunchObject(element)) {
|
||||
desc = descriptorType.getDescriptor(element);
|
||||
if (desc != null) { // own the object but do not create descriptor to ignore it
|
||||
String id = getId(desc);
|
||||
ILaunchDescriptor old = descriptors.get(id);
|
||||
if (old != null && !desc.equals(old))
|
||||
Activator.log(new IllegalStateException(
|
||||
"Id of descriptor must be unique within same type "
|
||||
+ "(or descriptors with same id must be equal)"));
|
||||
descriptors.put(id, desc);
|
||||
ILaunchDescriptor old = objectDescriptorMap.get(element);
|
||||
if (old != null) { // old mapping is removed
|
||||
objectDescriptorMap.remove(element);
|
||||
descriptors.remove(getId(old));
|
||||
}
|
||||
if (desc != null) { // null if we own the object but do not create descriptor to ignore it
|
||||
descriptors.put(getId(desc), desc);
|
||||
objectDescriptorMap.put(element, desc);
|
||||
setActiveLaunchDescriptor(desc);
|
||||
return desc;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
} catch (Exception e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
if (desc != null)
|
||||
setActiveLaunchDescriptor(desc);
|
||||
return desc;
|
||||
}
|
||||
|
||||
private String getId(ILaunchDescriptor desc) {
|
||||
|
@ -283,20 +268,26 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
}
|
||||
|
||||
@Override
|
||||
public void launchObjectRemoved(Object element) throws CoreException {
|
||||
public void launchObjectRemoved(Object element) {
|
||||
ILaunchDescriptor desc = objectDescriptorMap.get(element);
|
||||
if (desc != null) {
|
||||
descriptors.remove(getId(desc));
|
||||
objectDescriptorMap.remove(element);
|
||||
descriptors.remove(getId(desc)); // can multiple elements maps to the same descriptor?
|
||||
if (desc.equals(activeLaunchDesc)) {
|
||||
// Roll back to the last one and make sure we don't come back
|
||||
ILaunchDescriptor nextDesc = lastLaunchDesc;
|
||||
activeLaunchDesc = null;
|
||||
ILaunchDescriptor nextDesc = getLastUsedDescriptor();
|
||||
setActiveLaunchDescriptor(nextDesc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected ILaunchDescriptor getLastUsedDescriptor() {
|
||||
if (descriptors.size() == 0)
|
||||
return null;
|
||||
ILaunchDescriptor[] descs = descriptors.values().toArray(new ILaunchDescriptor[descriptors.size()]);
|
||||
return descs[descs.length - 1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchDescriptor[] getLaunchDescriptors() {
|
||||
ILaunchDescriptor[] descs = descriptors.values().toArray(new ILaunchDescriptor[descriptors.size()]);
|
||||
|
@ -315,64 +306,89 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setActiveLaunchDescriptor(ILaunchDescriptor configDesc) throws CoreException {
|
||||
if (activeLaunchDesc == configDesc)
|
||||
public void setActiveLaunchDescriptor(ILaunchDescriptor configDesc) {
|
||||
if (activeLaunchDesc == configDesc) {
|
||||
// Sync since targets could be changed since last time (and modes theoretically too)
|
||||
syncActiveTarget();
|
||||
syncActiveMode();
|
||||
return;
|
||||
lastLaunchDesc = activeLaunchDesc;
|
||||
}
|
||||
if (configDesc != null && !descriptors.containsValue(configDesc))
|
||||
throw new IllegalStateException("Active descriptor must be in the map of descriptors");
|
||||
if (configDesc == null)
|
||||
configDesc = getLastUsedDescriptor(); // do not set to null unless no descriptors
|
||||
activeLaunchDesc = configDesc;
|
||||
|
||||
IEclipsePreferences store = getPreferenceStore();
|
||||
setPreference(store, PREF_ACTIVE_CONFIG_DESC, getId(activeLaunchDesc));
|
||||
if (configDesc != null) { // keeps most used descriptor last
|
||||
descriptors.remove(configDesc.getId());
|
||||
descriptors.put(configDesc.getId(), configDesc);
|
||||
}
|
||||
// store in persistent storage
|
||||
setPreference(getPreferenceStore(), PREF_ACTIVE_CONFIG_DESC, getId(activeLaunchDesc));
|
||||
|
||||
// Send notifications
|
||||
for (Listener listener : listeners) {
|
||||
try {
|
||||
listener.activeConfigurationDescriptorChanged();
|
||||
} catch (Exception e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
updateLaunchDescriptor(activeLaunchDesc);
|
||||
// Set active target
|
||||
syncActiveTarget();
|
||||
// Set active mode
|
||||
syncActiveMode();
|
||||
}
|
||||
|
||||
protected void syncActiveTarget() {
|
||||
if (activeLaunchDesc == null) {
|
||||
setActiveLaunchMode(null);
|
||||
setActiveLaunchTarget(null);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set active target
|
||||
String activeTargetId = store.node(activeLaunchDesc.getId()).get(PREF_ACTIVE_LAUNCH_TARGET, null);
|
||||
String lastTargetId = store.get(PREF_ACTIVE_LAUNCH_TARGET, null);
|
||||
String targetIds[] = new String[] { activeTargetId, lastTargetId };
|
||||
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 < targetIds.length; i++) {
|
||||
String targetId = targetIds[i];
|
||||
target = getLaunchTarget(targetId);
|
||||
for (int i = 0; i < targets.length; i++) {
|
||||
target = targets[i];
|
||||
if (target != null && supportsTargetType(activeLaunchDesc, target.getType())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
setActiveLaunchTarget(target); // if target is null this will pick default
|
||||
setActiveLaunchTarget(target);
|
||||
}
|
||||
|
||||
// Set active mode
|
||||
ILaunchConfigurationType configType = getLaunchConfigurationType(activeLaunchDesc, activeLaunchTarget);
|
||||
protected void syncActiveMode() {
|
||||
if (activeLaunchDesc == null) {
|
||||
setActiveLaunchMode(null);
|
||||
return;
|
||||
}
|
||||
ILaunchMode foundMode = null;
|
||||
if (configType != null) {
|
||||
String activeModeName = store.node(activeLaunchDesc.getId()).get(PREF_ACTIVE_LAUNCH_MODE, null); // last desc mode name
|
||||
String lastModeName = store.get(PREF_ACTIVE_LAUNCH_MODE, null); // last global mode name
|
||||
Set<String> supportedModes = configType.getSupportedModes();
|
||||
if (supportedModes.size() > 0) { // mna, what if no modes are supported?
|
||||
ILaunchManager launchManager = getLaunchManager();
|
||||
String modeNames[] = new String[] { activeModeName, lastModeName, "debug", "run", supportedModes.iterator().next() };
|
||||
String storedModeId = getPerDescriptorStore().get(PREF_ACTIVE_LAUNCH_MODE, null); // last desc mode id
|
||||
String lastActiveModeId = activeLaunchMode == null ? null : activeLaunchMode.getIdentifier();
|
||||
ILaunchMode[] supportedModes = getLaunchModes(); // this is based on active desc and target which are already set
|
||||
if (supportedModes.length > 0) { // mna, what if no modes are supported?
|
||||
String modeNames[] = new String[] {
|
||||
storedModeId, lastActiveModeId,
|
||||
"debug", "run",
|
||||
supportedModes[0].getIdentifier()
|
||||
};
|
||||
for (int i = 0; i < modeNames.length && foundMode == null; i++) {
|
||||
String mode = modeNames[i];
|
||||
if (mode != null && supportedModes.contains(mode)) {
|
||||
foundMode = launchManager.getLaunchMode(mode);
|
||||
}
|
||||
}
|
||||
foundMode = getLaunchModeByName(modeNames[i], supportedModes);
|
||||
}
|
||||
}
|
||||
setActiveLaunchMode(foundMode);
|
||||
}
|
||||
|
||||
private ILaunchMode getLaunchModeByName(String mode, ILaunchMode[] supportedModes) {
|
||||
if (mode == null)
|
||||
return null;
|
||||
for (int j = 0; j < supportedModes.length; j++) {
|
||||
ILaunchMode lm = supportedModes[j];
|
||||
if (lm.getIdentifier().equals(mode)) {
|
||||
return lm;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void setPreference(Preferences store, String prefId, String value) {
|
||||
if (value != null) {
|
||||
store.put(prefId, value);
|
||||
|
@ -386,6 +402,12 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
}
|
||||
}
|
||||
|
||||
protected Preferences getPerDescriptorStore() {
|
||||
if (activeLaunchDesc == null)
|
||||
return getPreferenceStore();
|
||||
return getPreferenceStore().node(activeLaunchDesc.getId());
|
||||
}
|
||||
|
||||
protected IEclipsePreferences getPreferenceStore() {
|
||||
return InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
|
||||
}
|
||||
|
@ -393,16 +415,19 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
@Override
|
||||
public void updateLaunchDescriptor(ILaunchDescriptor configDesc) {
|
||||
for (Listener listener : listeners) {
|
||||
try {
|
||||
listener.activeConfigurationDescriptorChanged();
|
||||
} catch (Exception e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchMode[] getLaunchModes() throws CoreException {
|
||||
public ILaunchMode[] getLaunchModes() {
|
||||
ILaunchConfigurationType configType = getLaunchConfigurationType(activeLaunchDesc, activeLaunchTarget);
|
||||
if (configType == null)
|
||||
return new ILaunchMode[0];
|
||||
|
||||
List<ILaunchMode> modeList = new ArrayList<>();
|
||||
ILaunchMode[] modes = getLaunchManager().getLaunchModes();
|
||||
for (ILaunchMode mode : modes) {
|
||||
|
@ -410,7 +435,6 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
modeList.add(mode);
|
||||
}
|
||||
}
|
||||
|
||||
return modeList.toArray(new ILaunchMode[modeList.size()]);
|
||||
}
|
||||
|
||||
|
@ -423,17 +447,11 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
public void setActiveLaunchMode(ILaunchMode mode) {
|
||||
if (activeLaunchMode == mode)
|
||||
return;
|
||||
try {
|
||||
ILaunchConfigurationType configType = getLaunchConfigurationType(activeLaunchDesc, activeLaunchTarget);
|
||||
if (!(activeLaunchDesc == null || mode == null || (configType != null && configType.supportsMode(mode.getIdentifier()))))
|
||||
throw new IllegalStateException("Mode is not supported by descriptor");
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e);
|
||||
return;
|
||||
}
|
||||
// change mode
|
||||
activeLaunchMode = mode;
|
||||
|
||||
// notify listeners
|
||||
for (Listener listener : listeners) {
|
||||
try {
|
||||
|
@ -442,12 +460,11 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
// store mode
|
||||
String modeId = mode == null ? null : mode.getIdentifier();
|
||||
setPreference(getPreferenceStore(), PREF_ACTIVE_LAUNCH_MODE, modeId); // global store
|
||||
if (activeLaunchDesc == null)
|
||||
return;
|
||||
setPreference(getPreferenceStore().node(activeLaunchDesc.getId()), PREF_ACTIVE_LAUNCH_MODE, modeId); // per desc store
|
||||
// store mode
|
||||
String modeId = mode == null ? null : mode.getIdentifier();
|
||||
setPreference(getPerDescriptorStore(), PREF_ACTIVE_LAUNCH_MODE, modeId); // per desc store
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -458,7 +475,6 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
public ILaunchTarget[] getLaunchTargets(ILaunchDescriptor desc) {
|
||||
if (desc == null)
|
||||
return new ILaunchTarget[0];
|
||||
|
||||
List<ILaunchTarget> targetList = new ArrayList<>();
|
||||
Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(desc.getType().getId());
|
||||
if (targetMap != null) {
|
||||
|
@ -483,12 +499,27 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
@Override
|
||||
public void setActiveLaunchTarget(ILaunchTarget target) {
|
||||
if (target == null) {
|
||||
// try and select another target
|
||||
// try and select another target XXX this should not be an API
|
||||
target = getDeafultLaunchTarget();
|
||||
}
|
||||
if (activeLaunchTarget == target)
|
||||
return;
|
||||
activeLaunchTarget = target;
|
||||
updateLaunchTarget(activeLaunchTarget);
|
||||
if (target == null) {
|
||||
return; // no point storing null, if stored id is invalid it won't be used anyway
|
||||
}
|
||||
target.setActive();
|
||||
if (activeLaunchDesc == null)
|
||||
return;
|
||||
// per desc store
|
||||
if (supportsTargetType(activeLaunchDesc, target.getType()))
|
||||
setPreference(getPerDescriptorStore(),
|
||||
PREF_ACTIVE_LAUNCH_TARGET, target.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLaunchTarget(ILaunchTarget target) {
|
||||
for (Listener listener : listeners) {
|
||||
try {
|
||||
listener.activeLaunchTargetChanged();
|
||||
|
@ -496,24 +527,6 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
if (target == null) {
|
||||
return; // no point storing null, if stored id is invalid it won't be used anyway
|
||||
}
|
||||
target.setActive();
|
||||
// global store
|
||||
setPreference(getPreferenceStore(), PREF_ACTIVE_LAUNCH_TARGET, target.getId());
|
||||
if (activeLaunchDesc == null)
|
||||
return;
|
||||
// per desc store
|
||||
if (supportsTargetType(activeLaunchDesc, target.getType()))
|
||||
setPreference(getPreferenceStore().node(activeLaunchDesc.getName()),
|
||||
PREF_ACTIVE_LAUNCH_TARGET, target.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLaunchTarget(ILaunchTarget target) {
|
||||
for (Listener listener : listeners)
|
||||
listener.activeLaunchTargetChanged();
|
||||
}
|
||||
|
||||
protected ILaunchTarget getDeafultLaunchTarget() {
|
||||
|
@ -538,10 +551,14 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
}
|
||||
|
||||
@Override
|
||||
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException {
|
||||
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) {
|
||||
if (descriptor == null)
|
||||
return null;
|
||||
|
||||
try {
|
||||
if (descriptor instanceof ILaunchDescriptorConfigBased) {
|
||||
// if descriptor is launch config based we don't need provider to determine the type
|
||||
return ((ILaunchDescriptorConfigBased) descriptor).getConfig().getType();
|
||||
}
|
||||
String descriptorTypeId = descriptor.getType().getId();
|
||||
Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(descriptorTypeId);
|
||||
if (targetMap != null) {
|
||||
|
@ -553,8 +570,8 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
}
|
||||
}
|
||||
}
|
||||
if (descriptor instanceof ILaunchDescriptorConfigBased) {
|
||||
return ((ILaunchDescriptorConfigBased) descriptor).getConfig().getType();
|
||||
} catch (Exception e) {
|
||||
Activator.log(e); // we calling provider code inside try block, better be safe
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -562,25 +579,17 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
public boolean supportsTargetType(ILaunchDescriptor descriptor, ILaunchTargetType targetType) {
|
||||
if (descriptor == null || targetType == null)
|
||||
return false;
|
||||
|
||||
String descriptorTypeId = descriptor.getType().getId();
|
||||
Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(descriptorTypeId);
|
||||
Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(descriptor.getType().getId());
|
||||
if (targetMap != null) {
|
||||
String targetTypeId = targetType.getId();
|
||||
ILaunchConfigurationProvider configProvider = targetMap.get(targetTypeId);
|
||||
if (configProvider != null) {
|
||||
return true;
|
||||
return targetMap.get(targetType.getId()) != null;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException {
|
||||
if (activeLaunchDesc == null || target == null)
|
||||
if (descriptor == null || target == null)
|
||||
return null;
|
||||
|
||||
Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(descriptor.getType().getId());
|
||||
if (targetMap != null) {
|
||||
ILaunchConfigurationProvider configProvider = targetMap.get(target.getType().getId());
|
||||
|
@ -603,46 +612,43 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
|
||||
@Override
|
||||
public void launchConfigurationAdded(ILaunchConfiguration configuration) {
|
||||
try {
|
||||
// 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)) {
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Activator.log(e); // don't let one bad provider affect the rest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No one claimed it, send it through the descriptorTypes
|
||||
launchObjectAdded(configuration);
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
|
||||
try {
|
||||
// TODO filter by launch configuration type
|
||||
for (ILaunchDescriptorType descriptorType : descriptorTypes.keySet()) {
|
||||
Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(descriptorType.getId());
|
||||
for (ILaunchConfigurationProvider configProvider : targetMap.values()) {
|
||||
try {
|
||||
if (configProvider.launchConfigurationRemoved(configuration)) {
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Activator.log(e); // don't let one bad provider affect the rest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
launchObjectRemoved(configuration);
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launchConfigurationChanged(ILaunchConfiguration configuration) {
|
||||
// Nothing to do on changes
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue