Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/launch
diff options
context:
space:
mode:
authorAlena Laskavaia2014-07-24 20:50:54 +0000
committerElena Laskavaia2014-07-28 20:43:44 +0000
commite26e8a60c064b7eeb52b2029ad91ee35e03e2b5f (patch)
tree1e49ebe5b07751f929625f42e4a8bf5183f6f0ec /launch
parent668242634ac5d538c8e4da46236135a04ff2448b (diff)
downloadorg.eclipse.cdt-e26e8a60c064b7eeb52b2029ad91ee35e03e2b5f.tar.gz
org.eclipse.cdt-e26e8a60c064b7eeb52b2029ad91ee35e03e2b5f.tar.xz
org.eclipse.cdt-e26e8a60c064b7eeb52b2029ad91ee35e03e2b5f.zip
LaunchBar - added test plugin and refactoring
Initial tests and refactoring to support tests Change-Id: Ia14961b4a13ad7e8f2e1d75be264243f7432fe2d Signed-off-by: Alena Laskavaia <elaskavaia.cdt@gmail.com> Reviewed-on: https://git.eclipse.org/r/30462
Diffstat (limited to 'launch')
-rw-r--r--launch/org.eclipse.cdt.launchbar.core.tests/.classpath7
-rw-r--r--launch/org.eclipse.cdt.launchbar.core.tests/.project28
-rw-r--r--launch/org.eclipse.cdt.launchbar.core.tests/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--launch/org.eclipse.cdt.launchbar.core.tests/META-INF/MANIFEST.MF13
-rw-r--r--launch/org.eclipse.cdt.launchbar.core.tests/about.html24
-rw-r--r--launch/org.eclipse.cdt.launchbar.core.tests/build.properties4
-rw-r--r--launch/org.eclipse.cdt.launchbar.core.tests/pom.xml45
-rw-r--r--launch/org.eclipse.cdt.launchbar.core.tests/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManagerTest.java465
-rw-r--r--launch/org.eclipse.cdt.launchbar.core.tests/src/org/eclipse/cdt/launchbar/core/tests/Activator.java30
-rw-r--r--launch/org.eclipse.cdt.launchbar.core.tests/src/org/eclipse/cdt/launchbar/core/tests/AutomatedIntegrationSuite.java42
-rw-r--r--launch/org.eclipse.cdt.launchbar.core/META-INF/MANIFEST.MF2
-rw-r--r--launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstarctLaunchDescriptorType.java52
-rw-r--r--launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchConfigurationProvider.java48
-rw-r--r--launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchDescriptor.java49
-rw-r--r--launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchTarget.java59
-rw-r--r--launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchTargetType.java62
-rw-r--r--launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchConfigurationProvider.java (renamed from launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/TypeBasedLaunchConfigurationProvider.java)37
-rw-r--r--launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchDescriptor.java42
-rw-r--r--launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchDescriptorType.java (renamed from launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/TypeBasedLaunchDescriptorType.java)39
-rw-r--r--launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/DefaultLaunchDescriptor.java45
-rw-r--r--launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorConfigBased.java17
-rw-r--r--launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorType.java5
-rw-r--r--launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/Activator.java5
-rw-r--r--launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchConfigurationProvider.java30
-rw-r--r--launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptorType.java21
-rw-r--r--launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManager.java419
26 files changed, 1293 insertions, 304 deletions
diff --git a/launch/org.eclipse.cdt.launchbar.core.tests/.classpath b/launch/org.eclipse.cdt.launchbar.core.tests/.classpath
new file mode 100644
index 00000000000..098194ca4b7
--- /dev/null
+++ b/launch/org.eclipse.cdt.launchbar.core.tests/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/launch/org.eclipse.cdt.launchbar.core.tests/.project b/launch/org.eclipse.cdt.launchbar.core.tests/.project
new file mode 100644
index 00000000000..dcc91f96735
--- /dev/null
+++ b/launch/org.eclipse.cdt.launchbar.core.tests/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.cdt.launchbar.core.tests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/launch/org.eclipse.cdt.launchbar.core.tests/.settings/org.eclipse.jdt.core.prefs b/launch/org.eclipse.cdt.launchbar.core.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..f42de363afa
--- /dev/null
+++ b/launch/org.eclipse.cdt.launchbar.core.tests/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/launch/org.eclipse.cdt.launchbar.core.tests/META-INF/MANIFEST.MF b/launch/org.eclipse.cdt.launchbar.core.tests/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..bfe846fde74
--- /dev/null
+++ b/launch/org.eclipse.cdt.launchbar.core.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,13 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Launch Bar Core Tests
+Bundle-SymbolicName: org.eclipse.cdt.launchbar.core.tests
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.eclipse.cdt.launchbar.core.tests.Activator
+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
+Bundle-RequiredExecutionEnvironment: JavaSE-1.7
+Bundle-ActivationPolicy: lazy
diff --git a/launch/org.eclipse.cdt.launchbar.core.tests/about.html b/launch/org.eclipse.cdt.launchbar.core.tests/about.html
new file mode 100644
index 00000000000..d7c511887d6
--- /dev/null
+++ b/launch/org.eclipse.cdt.launchbar.core.tests/about.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"><head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head>
+
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 22, 2007</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body></html> \ No newline at end of file
diff --git a/launch/org.eclipse.cdt.launchbar.core.tests/build.properties b/launch/org.eclipse.cdt.launchbar.core.tests/build.properties
new file mode 100644
index 00000000000..34d2e4d2dad
--- /dev/null
+++ b/launch/org.eclipse.cdt.launchbar.core.tests/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/launch/org.eclipse.cdt.launchbar.core.tests/pom.xml b/launch/org.eclipse.cdt.launchbar.core.tests/pom.xml
new file mode 100644
index 00000000000..5046c5f1fbf
--- /dev/null
+++ b/launch/org.eclipse.cdt.launchbar.core.tests/pom.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.eclipse.cdt</groupId>
+ <artifactId>cdt-parent</artifactId>
+ <version>8.5.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <version>1.0.0-SNAPSHOT</version>
+ <artifactId>org.eclipse.cdt.launchbar.core.tests</artifactId>
+ <packaging>eclipse-plugin</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-surefire-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <configuration>
+ <argLine>${base.ui.test.vmargs} -ea -Xms256m -Xmx512m -XX:MaxPermSize=256M</argLine>
+ <includes>
+ <include>**/AutomatedIntegrationSuite.*</include>
+ </includes>
+ <testFailureIgnore>true</testFailureIgnore>
+ <dependencies>
+ <dependency>
+ <artifactId>org.eclipse.platform.feature.group</artifactId>
+ <type>p2-installable-unit</type>
+ </dependency>
+ <dependency>
+ <artifactId>org.eclipse.cdt.feature.group</artifactId>
+ <version>8.2.0.${buildQualifier}</version>
+ <type>p2-installable-unit</type>
+ </dependency>
+ </dependencies>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/launch/org.eclipse.cdt.launchbar.core.tests/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManagerTest.java b/launch/org.eclipse.cdt.launchbar.core.tests/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManagerTest.java
new file mode 100644
index 00000000000..327fb6b1967
--- /dev/null
+++ b/launch/org.eclipse.cdt.launchbar.core.tests/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManagerTest.java
@@ -0,0 +1,465 @@
+/*******************************************************************************
+ * 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.internal;
+
+import static org.mockito.Mockito.*;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+
+import junit.framework.TestCase;
+
+import org.eclipse.cdt.launchbar.core.AbstractLaunchTarget;
+import org.eclipse.cdt.launchbar.core.AbstractLaunchTargetType;
+import org.eclipse.cdt.launchbar.core.ConfigBasedLaunchConfigurationProvider;
+import org.eclipse.cdt.launchbar.core.ConfigBasedLaunchDescriptor;
+import org.eclipse.cdt.launchbar.core.ConfigBasedLaunchDescriptorType;
+import org.eclipse.cdt.launchbar.core.ILaunchBarManager.Listener;
+import org.eclipse.cdt.launchbar.core.ILaunchConfigurationProvider;
+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.core.internal.preferences.EclipsePreferences;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+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.junit.Test;
+
+/**
+ * @author elaskavaia
+ *
+ */
+public class LaunchBarManagerTest extends TestCase {
+ private LaunchBarManager manager;
+ private ILaunchConfigurationProvider provider;
+ private ILaunchDescriptor desc;
+ private ILaunchDescriptorType descType;
+ private ILaunchConfigurationType lctype;
+ private ILaunchConfiguration lc;
+
+ class TargetType extends AbstractLaunchTargetType {
+ private String id;
+ ArrayList<ILaunchTarget> targets = new ArrayList<>();
+
+ public TargetType(String id) {
+ this.id = id;
+ }
+
+ @Override
+ public ILaunchTarget[] getTargets() {
+ return targets.toArray(new ILaunchTarget[targets.size()]);
+ }
+
+ @Override
+ public String getId() {
+ return id;
+ }
+ }
+ private TargetType targetType = new TargetType("target_type1");
+
+ class LaunchTarget extends AbstractLaunchTarget {
+ private ILaunchTargetType type;
+
+ public LaunchTarget(String id, ILaunchTargetType type) {
+ super(id);
+ this.type = type;
+ }
+
+ public ILaunchTargetType getType() {
+ return type;
+ }
+ }
+ private ILaunchTarget mytarget = new LaunchTarget("target_1", targetType);
+ private ILaunchManager lman;
+
+ @Override
+ protected void setUp() throws Exception {
+ final IExtensionPoint point = mock(IExtensionPoint.class);
+ doReturn(new IExtension[] {}).when(point).getExtensions();
+ lman = mock(ILaunchManager.class);
+ doReturn(new ILaunchConfiguration[] {}).when(lman).getLaunchConfigurations();
+ final IEclipsePreferences store = new EclipsePreferences();
+ manager = new LaunchBarManager() {
+ @Override
+ public IExtensionPoint getExtensionPoint() {
+ return point;
+ }
+
+ @Override
+ protected ILaunchManager getLaunchManager() {
+ return lman;
+ }
+
+ @Override
+ protected IEclipsePreferences getPreferenceStore() {
+ return store;
+ }
+ };
+ // mock
+ // lc
+ lctype = mockLCType("lctype1");
+ lc = mockLC("bla", lctype);
+ // other init
+ provider = spy(new ConfigBasedLaunchConfigurationProvider(lctype.getIdentifier()));
+ descType = new ConfigBasedLaunchDescriptorType("desctype1", lctype.getIdentifier());
+ desc = new ConfigBasedLaunchDescriptor(descType, lc);
+ }
+
+ protected void basicSetup() {
+ // setup some stuff
+ manager.addTargetType(targetType);
+ targetType.targets.add(mytarget);
+ manager.addDescriptorType(descType, 5);
+ manager.addConfigProvider(descType.getId(), targetType.getId(), false, provider);
+ }
+
+ private ILaunchConfiguration mockLC(String string, ILaunchConfigurationType lctype2) throws CoreException {
+ ILaunchConfiguration lc = mock(ILaunchConfiguration.class);
+ doReturn(string).when(lc).getName();
+ doReturn(lctype2).when(lc).getType();
+ return lc;
+ }
+
+ protected ILaunchConfigurationType mockLCType(String id) {
+ ILaunchConfigurationType lctype = mock(ILaunchConfigurationType.class);
+ doReturn(id).when(lctype).getIdentifier();
+ return lctype;
+ }
+
+ protected ILaunchMode[] mockLaunchMode(ILaunchConfigurationType type, String... modes) {
+ ILaunchMode res[] = new ILaunchMode[modes.length];
+ for (int i = 0; i < modes.length; i++) {
+ String modeId = modes[i];
+ doReturn(true).when(type).supportsMode(modeId);
+ ILaunchMode mode = mock(ILaunchMode.class);
+ res[i] = mode;
+ doReturn(modeId).when(mode).getIdentifier();
+ doReturn(mode).when(lman).getLaunchMode(modeId);
+ }
+ doReturn(new HashSet<>(Arrays.asList(modes))).when(type).getSupportedModes();
+ return res;
+ }
+
+ public void testLaunchBarManager() {
+ assertNull(manager.getActiveLaunchDescriptor());
+ assertNull(manager.getActiveLaunchTarget());
+ assertNull(manager.getActiveLaunchMode());
+ }
+
+ @Test
+ public void testAddConfigProvider() {
+ manager.addTargetType(targetType);
+ manager.addDescriptorType(descType, 5);
+ manager.addConfigProvider(descType.getId(), targetType.getId(), false, provider);
+ }
+
+ @Test
+ public void testAddConfigProviderNoTarget() {
+ try {
+ manager.addDescriptorType(descType, 5);
+ manager.addConfigProvider(descType.getId(), targetType.getId(), false, provider);
+ fail("Expecting exctpion because target is not registered");
+ } catch (Exception e) {
+ // pass
+ }
+ }
+
+ @Test
+ public void testAddConfigProviderNoDesc() {
+ try {
+ manager.addTargetType(targetType);
+ manager.addConfigProvider(descType.getId(), targetType.getId(), false, provider);
+ fail("Expecting exctpion because target is not registered");
+ } catch (Exception e) {
+ // pass
+ }
+ }
+
+ @Test
+ public void testAddConfigProviderTwo() throws CoreException {
+ basicSetup();
+ TargetType targetType2 = new TargetType("t2");
+ manager.addTargetType(targetType2);
+ ILaunchConfigurationProvider provider2 = new ConfigBasedLaunchConfigurationProvider("type2");
+ manager.addConfigProvider(descType.getId(), targetType2.getId(), true, provider2);
+ ILaunchConfigurationType lctype2 = mockLCType("lctypeid2");
+ ILaunchConfiguration lc2 = mockLC("bla2", lctype2);
+ ConfigBasedLaunchDescriptor desc2 = new ConfigBasedLaunchDescriptor(descType, lc2);
+ assertEquals(lctype2, manager.getLaunchConfigurationType(desc2, null));
+ }
+
+ @Test
+ 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;
+ }
+ };
+ manager.addConfigProvider(descType.getId(), targetType.getId(), true, provider2);
+ TargetType targetType2 = new TargetType("t2");
+ manager.addTargetType(targetType2);
+ manager.addConfigProvider(descType.getId(), targetType2.getId(), false, provider);
+ ILaunchConfigurationType lctype2 = mockLCType("lctypeid2");
+ ILaunchConfiguration lc2 = mockLC("bla2", lctype2);
+ ConfigBasedLaunchDescriptor desc2 = new ConfigBasedLaunchDescriptor(descType, lc2);
+ assertEquals(lctype, manager.getLaunchConfigurationType(desc2, null));
+ }
+
+ @Test
+ public void testGetLaunchTargets() throws CoreException {
+ basicSetup();
+ manager.setActiveLaunchDescriptor(desc);
+ ILaunchTarget[] launchTargets = manager.getLaunchTargets();
+ assertEquals(1, launchTargets.length);
+ assertEquals(mytarget, launchTargets[0]);
+ }
+
+ @Test
+ public void testGetLaunchDescriptorsNull() {
+ ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
+ assertEquals(0, launchDescriptors.length);
+ }
+
+ public void testGetLaunchDescriptors() {
+ basicSetup();
+ manager.launchObjectAdded(lc);
+ ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
+ assertEquals(1, launchDescriptors.length);
+ }
+
+ public void testGetLaunchDescriptorsSort() {
+ final ILaunchDescriptor res[] = new ILaunchDescriptor[1];
+ manager.addTargetType(targetType);
+ ConfigBasedLaunchDescriptorType descType1 = new ConfigBasedLaunchDescriptorType("id1", lctype.getIdentifier());
+ ConfigBasedLaunchDescriptorType descType2 = new ConfigBasedLaunchDescriptorType("id2", lctype.getIdentifier()) {
+ @Override
+ public ILaunchDescriptor getDescriptor(Object element) {
+ return res[0] = super.getDescriptor(element);
+ }
+ };
+ ConfigBasedLaunchDescriptorType descType3 = new ConfigBasedLaunchDescriptorType("id3", lctype.getIdentifier());
+ manager.addDescriptorType(descType1, 3);
+ manager.addDescriptorType(descType2, 5);
+ manager.addDescriptorType(descType3, 1);
+ manager.addConfigProvider(descType1.getId(), targetType.getId(), true, provider);
+ manager.addConfigProvider(descType2.getId(), targetType.getId(), true, provider);
+ manager.addConfigProvider(descType3.getId(), targetType.getId(), true, provider);
+ targetType.targets.add(mytarget);
+ manager.launchObjectAdded(lc);
+ ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
+ assertEquals(1, launchDescriptors.length);
+ assertNotNull(launchDescriptors[0]);
+ assertSame(res[0], launchDescriptors[0]);
+ }
+
+
+ @Test
+ public void testLaunchObjectAdded() throws CoreException {
+ basicSetup();
+ manager.launchObjectAdded(lc);
+ ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
+ assertEquals(1, launchDescriptors.length);
+ assertNotNull(launchDescriptors[0]);
+ assertEquals(lc.getName(), launchDescriptors[0].getName());
+ }
+
+ @Test
+ public void testLaunchObjectAdded2() throws CoreException {
+ basicSetup();
+ manager.launchObjectAdded(lc);
+ ILaunchConfiguration lc2 = mockLC("lc2", lctype);
+ manager.launchObjectAdded(lc2);
+ assertEquals(2, manager.getLaunchDescriptors().length);
+ }
+
+ @Test
+ public void testLaunchObjectRemoved() throws CoreException {
+ basicSetup();
+ manager.launchObjectAdded(lc);
+ assertEquals(1, manager.getLaunchDescriptors().length);
+ manager.launchObjectRemoved(lc);
+ assertEquals(0, manager.getLaunchDescriptors().length);
+ }
+
+ @Test
+ public void testGetActiveLaunchDescriptor() throws CoreException {
+ Listener lis = mock(Listener.class);
+ manager.addListener(lis);
+
+ manager.setActiveLaunchDescriptor(desc);
+ assertEquals(desc, manager.getActiveLaunchDescriptor());
+ verify(lis).activeConfigurationDescriptorChanged();
+ }
+
+ @Test
+ public void testGetLaunchModes() throws CoreException {
+ ILaunchMode[] launchModes = manager.getLaunchModes();
+ assertEquals(0, launchModes.length);
+ }
+
+ @Test
+ public void testGetActiveLaunchMode() {
+ ILaunchMode mode = mock(ILaunchMode.class);
+ doReturn("bla").when(mode).getIdentifier();
+ doReturn("Bla").when(mode).getLabel();
+ manager.setActiveLaunchMode(mode);
+ assertEquals(mode, manager.getActiveLaunchMode());
+ }
+
+ @Test
+ public void testGetActiveLaunchModeFromDesc() throws CoreException {
+ basicSetup();
+ mockLaunchMode(lctype, "run");
+ manager.setActiveLaunchDescriptor(desc);
+ ILaunchMode resmode = manager.getActiveLaunchMode();
+ assertNotNull(resmode);
+ assertEquals("run", resmode.getIdentifier());
+ }
+
+ @Test
+ public void testGetActiveLaunchModeFromDescDebug() throws CoreException {
+ basicSetup();
+ mockLaunchMode(lctype, "run", "debug");
+ manager.setActiveLaunchDescriptor(desc);
+ ILaunchMode resmode = manager.getActiveLaunchMode();
+ assertNotNull(resmode);
+ assertEquals("debug", resmode.getIdentifier());
+ }
+
+ @Test
+ public void testGetActiveLaunchModeFromDescActive() throws CoreException {
+ basicSetup();
+ mockLaunchMode(lctype, "run");
+ ILaunchMode mode = mockLaunchMode(lctype, "foo")[0];
+ manager.setActiveLaunchMode(mode);
+ manager.setActiveLaunchDescriptor(desc);
+ ILaunchMode resmode = manager.getActiveLaunchMode();
+ assertNotNull(resmode);
+ assertEquals("foo", resmode.getIdentifier());
+ }
+
+ @Test
+ public void testGetActiveLaunchTarget() {
+ manager.addTargetType(targetType);
+ targetType.targets.add(mytarget);
+ manager.setActiveLaunchTarget(mytarget);
+ assertEquals(mytarget, manager.getActiveLaunchTarget());
+ }
+
+ @Test
+ public void testGetLaunchTarget() {
+ manager.addTargetType(targetType);
+ targetType.targets.add(mytarget);
+ assertEquals(mytarget, manager.getLaunchTarget(mytarget.getId()));
+ }
+
+ @Test
+ public void testGetLaunchTargetNone() {
+ manager.addTargetType(targetType);
+ assertNull(manager.getLaunchTarget(mytarget.getId()));
+ }
+
+ @Test
+ public void testGetLaunchConfigurationType() throws CoreException {
+ manager.getLaunchConfigurationType(desc, mytarget);
+ }
+
+ @Test
+ public void testGetLaunchConfiguration() throws CoreException {
+ manager.getLaunchConfiguration(desc, mytarget);
+ }
+
+ @Test
+ public void testAddListener() throws CoreException {
+ Listener lis = mock(Listener.class);
+ manager.addListener(lis);
+ basicSetup();
+ // check events
+ manager.setActiveLaunchDescriptor(desc);
+ verify(lis).activeLaunchTargetChanged();
+ }
+ @Test
+ public void testAddListenerBad() throws CoreException {
+ Listener lis = mock(Listener.class);
+ manager.addListener(lis);
+ doThrow(new NullPointerException()).when(lis).activeLaunchTargetChanged();
+ basicSetup();
+ // check events
+ manager.setActiveLaunchDescriptor(desc);
+ verify(lis).activeLaunchTargetChanged();
+ }
+
+ @Test
+ public void testRemoveListener() {
+ basicSetup();
+ Listener lis = mock(Listener.class);
+ manager.addListener(lis);
+ manager.removeListener(lis);
+ verifyZeroInteractions(lis);
+ }
+
+ @Test
+ public void testLaunchConfigurationAdded() throws CoreException {
+ basicSetup();
+ ILaunchMode mode = mockLaunchMode(lctype, "foo")[0];
+ manager.launchConfigurationAdded(lc);
+ verify(provider).launchConfigurationAdded(lc);
+ ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
+ assertEquals(1, launchDescriptors.length);
+ assertNotNull(launchDescriptors[0]);
+ assertEquals(lc.getName(), launchDescriptors[0].getName());
+ manager.setActiveLaunchDescriptor(desc);
+ assertEquals(mytarget, manager.getActiveLaunchTarget());
+ assertEquals(mode, manager.getActiveLaunchMode());
+ }
+
+ public void testLaunchConfigurationAddedDefault() throws CoreException {
+ 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());
+ // another lc not covered by provider
+ ILaunchConfigurationType lctype2 = mockLCType("lctype2");
+ ILaunchConfiguration lc2 = mockLC("lc2", lctype2);
+ manager.launchConfigurationAdded(lc2);
+ verify(provider).launchConfigurationAdded(lc2);
+ ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
+ assertEquals(1, launchDescriptors.length);
+ assertNotNull(launchDescriptors[0]);
+ assertEquals(lc2.getName(), launchDescriptors[0].getName());
+ manager.setActiveLaunchDescriptor(type.getDescriptor(lc2));
+ assertEquals(localType.getTargets()[0], manager.getActiveLaunchTarget());
+ }
+
+ @Test
+ public void testLaunchConfigurationRemoved() throws CoreException {
+ basicSetup();
+ manager.launchConfigurationRemoved(lc);
+ verify(provider).launchConfigurationRemoved(lc);
+ }
+}
diff --git a/launch/org.eclipse.cdt.launchbar.core.tests/src/org/eclipse/cdt/launchbar/core/tests/Activator.java b/launch/org.eclipse.cdt.launchbar.core.tests/src/org/eclipse/cdt/launchbar/core/tests/Activator.java
new file mode 100644
index 00000000000..8a30e30181d
--- /dev/null
+++ b/launch/org.eclipse.cdt.launchbar.core.tests/src/org/eclipse/cdt/launchbar/core/tests/Activator.java
@@ -0,0 +1,30 @@
+package org.eclipse.cdt.launchbar.core.tests;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator {
+
+ private static BundleContext context;
+
+ static BundleContext getContext() {
+ return context;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext bundleContext) throws Exception {
+ Activator.context = bundleContext;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext bundleContext) throws Exception {
+ Activator.context = null;
+ }
+
+}
diff --git a/launch/org.eclipse.cdt.launchbar.core.tests/src/org/eclipse/cdt/launchbar/core/tests/AutomatedIntegrationSuite.java b/launch/org.eclipse.cdt.launchbar.core.tests/src/org/eclipse/cdt/launchbar/core/tests/AutomatedIntegrationSuite.java
new file mode 100644
index 00000000000..96b3c92ae4f
--- /dev/null
+++ b/launch/org.eclipse.cdt.launchbar.core.tests/src/org/eclipse/cdt/launchbar/core/tests/AutomatedIntegrationSuite.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2011 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * QNX Software Systems - initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ *******************************************************************************/
+package org.eclipse.cdt.launchbar.core.tests;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.launchbar.core.internal.LaunchBarManagerTest;
+
+public class AutomatedIntegrationSuite extends TestSuite {
+ public AutomatedIntegrationSuite() {
+ }
+
+ public AutomatedIntegrationSuite(Class<? extends TestCase> theClass, String name) {
+ super(theClass, name);
+ }
+
+ public AutomatedIntegrationSuite(Class<? extends TestCase> theClass) {
+ super(theClass);
+ }
+
+ public AutomatedIntegrationSuite(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ final AutomatedIntegrationSuite suite = new AutomatedIntegrationSuite();
+ // tests
+ suite.addTestSuite(LaunchBarManagerTest.class);
+ return suite;
+ }
+}
diff --git a/launch/org.eclipse.cdt.launchbar.core/META-INF/MANIFEST.MF b/launch/org.eclipse.cdt.launchbar.core/META-INF/MANIFEST.MF
index 9edbf2c22fe..21f8f4e111a 100644
--- a/launch/org.eclipse.cdt.launchbar.core/META-INF/MANIFEST.MF
+++ b/launch/org.eclipse.cdt.launchbar.core/META-INF/MANIFEST.MF
@@ -10,4 +10,4 @@ Require-Bundle: org.eclipse.core.runtime,
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.cdt.launchbar.core,
- org.eclipse.cdt.launchbar.core.internal;x-friends:="org.eclipse.cdt.launchbar.ui"
+ org.eclipse.cdt.launchbar.core.internal;x-friends:="org.eclipse.cdt.launchbar.ui,org.eclipse.cdt.launchbar.core.tests"
diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstarctLaunchDescriptorType.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstarctLaunchDescriptorType.java
new file mode 100644
index 00000000000..659992c1058
--- /dev/null
+++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstarctLaunchDescriptorType.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2014 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Elena Laskavaia - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.launchbar.core;
+
+/**
+ * Abstract launch descriptor type provide convenience methods to implement hashcode, equals and store lanch bar manager object. It
+ * is recommended to use this method instead of implementing interface
+ */
+public abstract class AbstarctLaunchDescriptorType implements ILaunchDescriptorType {
+ private ILaunchBarManager manager;
+
+ @Override
+ public abstract String getId();
+
+
+ @Override
+ public void init(ILaunchBarManager barmanager) {
+ this.manager = barmanager;
+ }
+
+ @Override
+ public ILaunchBarManager getManager() {
+ return manager;
+ }
+
+ @Override
+ public int hashCode() {
+ return 37 + getId().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj.getClass().equals(getClass())))
+ return false;
+ ILaunchDescriptorType other = (ILaunchDescriptorType) obj;
+ if (!getId().equals(other.getId()))
+ return false;
+ return true;
+ }
+}
diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchConfigurationProvider.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchConfigurationProvider.java
new file mode 100644
index 00000000000..da445c108db
--- /dev/null
+++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchConfigurationProvider.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2014 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Elena Laskavaia - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.launchbar.core;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+
+/**
+ * Abstract provider can work with any ITypeBaseLaunchDescriptor to provide launch configurations
+ */
+public abstract class AbstractLaunchConfigurationProvider implements ILaunchConfigurationProvider {
+ protected ILaunchBarManager manager;
+
+ @Override
+ public void init(ILaunchBarManager manager) throws CoreException {
+ this.manager = manager;
+ }
+
+ public ILaunchBarManager getManager() {
+ return manager;
+ }
+
+ @Override
+ public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor) throws CoreException {
+ if (descriptor instanceof ILaunchDescriptorConfigBased) {
+ return ((ILaunchDescriptorConfigBased) descriptor).getConfig();
+ }
+ return null;
+ }
+
+ @Override
+ public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor) throws CoreException {
+ ILaunchConfiguration config = getLaunchConfiguration(descriptor);
+ if (config != null) {
+ return config.getType();
+ }
+ return null;
+ }
+}
diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchDescriptor.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchDescriptor.java
new file mode 100644
index 00000000000..8676ca9f719
--- /dev/null
+++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchDescriptor.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2014 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Elena Laskavaia - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.launchbar.core;
+
+/**
+ * Convenience implementation of ILaunchDescriptor
+ *
+ * @author elaskavaia
+ *
+ */
+public abstract class AbstractLaunchDescriptor implements ILaunchDescriptor {
+
+ @Override
+ public abstract String getName();
+
+ @Override
+ public abstract ILaunchDescriptorType getType();
+
+ public String getId() {
+ return getName() + "." + getType().getId();
+ }
+
+ @Override
+ public int hashCode() {
+ return 17 + getId().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof AbstractLaunchDescriptor))
+ return false;
+ AbstractLaunchDescriptor other = (AbstractLaunchDescriptor) obj;
+ if (!getId().equals(other.getId()))
+ return false;
+ return true;
+ }
+}
diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchTarget.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchTarget.java
new file mode 100644
index 00000000000..4046199d25c
--- /dev/null
+++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchTarget.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2014 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Elena Laskavaia - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.launchbar.core;
+
+/**
+ * Convenience implementation of ILaunchTarget, provides hooks for id, and equals and hashcode methods based on id.
+ */
+public abstract class AbstractLaunchTarget implements ILaunchTarget {
+ private final String id;
+
+ public AbstractLaunchTarget(String id) {
+ this.id = id;
+ }
+
+ @Override
+ public String getId() {
+ return id;
+ }
+
+ @Override
+ public String getName() {
+ return id;
+ }
+
+ @Override
+ public abstract ILaunchTargetType getType();
+
+ @Override
+ public void setActive() {
+ // nothing to do
+ }
+
+ @Override
+ public int hashCode() {
+ return 7 + getId().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj.getClass().equals(getClass())))
+ return false;
+ ILaunchDescriptorType other = (ILaunchDescriptorType) obj;
+ if (!getId().equals(other.getId()))
+ return false;
+ return true;
+ }
+}
diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchTargetType.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchTargetType.java
new file mode 100644
index 00000000000..e2a75132f72
--- /dev/null
+++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchTargetType.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2014 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Elena Laskavaia - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.launchbar.core;
+
+/**
+ * Convenience implementation of ILaunchTargetType, provides equals and hashcode methods based on id.
+ */
+public abstract class AbstractLaunchTargetType implements ILaunchTargetType {
+ private ILaunchBarManager manager;
+
+ @Override
+ public void init(ILaunchBarManager barmanager) {
+ this.manager = barmanager;
+ }
+
+ public ILaunchBarManager getManager() {
+ return manager;
+ }
+
+ @Override
+ public abstract String getId();
+
+ @Override
+ public int hashCode() {
+ return 7 + getId().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj.getClass().equals(getClass())))
+ return false;
+ ILaunchDescriptorType other = (ILaunchDescriptorType) obj;
+ if (!getId().equals(other.getId()))
+ return false;
+ return true;
+ }
+
+ @Override
+ public ILaunchTarget getTarget(String id) {
+ if (id == null)
+ return null;
+ ILaunchTarget[] targets = getTargets();
+ for (int i = 0; i < targets.length; i++) {
+ ILaunchTarget target = targets[i];
+ if (target.getId().equals(id))
+ return target;
+ }
+ return null;
+ }
+}
diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/TypeBasedLaunchConfigurationProvider.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchConfigurationProvider.java
index 49e708ae74f..aacfdd568f7 100644
--- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/TypeBasedLaunchConfigurationProvider.java
+++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchConfigurationProvider.java
@@ -1,4 +1,3 @@
-
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
@@ -7,32 +6,21 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX Software Systems (Elena Laskavaia) - Initial API and implementation
+ * Elena Laskavaia - Initial API and implementation
*******************************************************************************/
+package org.eclipse.cdt.launchbar.core;
-package org.eclipse.cdt.launchbar.core.internal;
-
-import org.eclipse.cdt.launchbar.core.DefaultLaunchDescriptor;
-import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
-import org.eclipse.cdt.launchbar.core.ILaunchConfigurationProvider;
-import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationType;
-public class TypeBasedLaunchConfigurationProvider implements ILaunchConfigurationProvider {
- protected ILaunchBarManager manager;
+public class ConfigBasedLaunchConfigurationProvider extends AbstractLaunchConfigurationProvider implements
+ ILaunchConfigurationProvider {
private String typeId;
- public TypeBasedLaunchConfigurationProvider(String launchConfigurationTypeId) {
+ public ConfigBasedLaunchConfigurationProvider(String launchConfigurationTypeId) {
this.typeId = launchConfigurationTypeId;
}
- @Override
- public void init(ILaunchBarManager manager) throws CoreException {
- this.manager = manager;
- }
-
public boolean ownsConfiguration(ILaunchConfiguration element) {
try {
return element.getType().getIdentifier().equals(typeId);
@@ -60,18 +48,7 @@ public class TypeBasedLaunchConfigurationProvider implements ILaunchConfiguratio
}
@Override
- public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor) throws CoreException {
- if (descriptor instanceof DefaultLaunchDescriptor) {
- return ((DefaultLaunchDescriptor) descriptor).getConfig();
- }
- return null;
- }
-
- @Override
- public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor) throws CoreException {
- if (descriptor instanceof DefaultLaunchDescriptor) {
- return ((DefaultLaunchDescriptor) descriptor).getConfig().getType();
- }
- return null;
+ public String toString() {
+ return "Provider for " + typeId;
}
}
diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchDescriptor.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchDescriptor.java
new file mode 100644
index 00000000000..b8723d37c60
--- /dev/null
+++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchDescriptor.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2014 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Doug Schaefer
+ *******************************************************************************/
+package org.eclipse.cdt.launchbar.core;
+
+import org.eclipse.debug.core.ILaunchConfiguration;
+
+public class ConfigBasedLaunchDescriptor extends AbstractLaunchDescriptor implements ILaunchDescriptorConfigBased {
+ private final ILaunchDescriptorType type;
+ private final ILaunchConfiguration config;
+
+ public ConfigBasedLaunchDescriptor(ILaunchDescriptorType type, ILaunchConfiguration config) {
+ this.type = type;
+ this.config = config;
+ }
+
+ @Override
+ public String getName() {
+ return config.getName();
+ }
+
+ @Override
+ public ILaunchDescriptorType getType() {
+ return type;
+ }
+
+ public ILaunchConfiguration getConfig() {
+ return config;
+ }
+
+ @Override
+ public String toString() {
+ return getId();
+ }
+}
diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/TypeBasedLaunchDescriptorType.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchDescriptorType.java
index d8be527eb2f..f4f559ecebb 100644
--- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/TypeBasedLaunchDescriptorType.java
+++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchDescriptorType.java
@@ -6,32 +6,26 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX Software Systems (Elena Laskavaia) - Initial API and implementation
+ * Elena Laskavaia - Initial API and implementation
*******************************************************************************/
-package org.eclipse.cdt.launchbar.core.internal;
+package org.eclipse.cdt.launchbar.core;
-import org.eclipse.cdt.launchbar.core.DefaultLaunchDescriptor;
-import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
-import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
-import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
-public class TypeBasedLaunchDescriptorType implements ILaunchDescriptorType {
- protected ILaunchBarManager manager;
- private String typeId;
+public class ConfigBasedLaunchDescriptorType extends AbstarctLaunchDescriptorType implements ILaunchDescriptorType {
private String id;
+ private String typeId;
- public TypeBasedLaunchDescriptorType(String descId, String launchConfigurationTypeId) {
+ public ConfigBasedLaunchDescriptorType(String descTypeId, String launchConfigurationTypeId) {
if (launchConfigurationTypeId == null)
throw new NullPointerException();
this.typeId = launchConfigurationTypeId;
- this.id = descId != null ? descId : typeId + ".desc";
+ this.id = descTypeId != null ? descTypeId : launchConfigurationTypeId;
}
- @Override
- public String getId() {
- return id;
+ public ConfigBasedLaunchDescriptorType(String launchConfigurationTypeId) {
+ this(null, launchConfigurationTypeId);
}
public boolean ownsConfiguration(ILaunchConfiguration element) {
@@ -43,18 +37,8 @@ public class TypeBasedLaunchDescriptorType implements ILaunchDescriptorType {
}
@Override
- public void init(ILaunchBarManager manager) {
- this.manager = manager;
- }
-
- @Override
public ILaunchDescriptor getDescriptor(Object element) {
- return new DefaultLaunchDescriptor(this, (ILaunchConfiguration) element);
- }
-
- @Override
- public ILaunchBarManager getManager() {
- return manager;
+ return new ConfigBasedLaunchDescriptor(this, (ILaunchConfiguration) element);
}
@Override
@@ -62,4 +46,9 @@ public class TypeBasedLaunchDescriptorType implements ILaunchDescriptorType {
return element instanceof ILaunchConfiguration
&& ownsConfiguration((ILaunchConfiguration) element);
}
+
+ @Override
+ public String getId() {
+ return id;
+ }
}
diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/DefaultLaunchDescriptor.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/DefaultLaunchDescriptor.java
index dc1073e1947..c4c4b82ecb9 100644
--- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/DefaultLaunchDescriptor.java
+++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/DefaultLaunchDescriptor.java
@@ -12,49 +12,10 @@ package org.eclipse.cdt.launchbar.core;
import org.eclipse.debug.core.ILaunchConfiguration;
-public class DefaultLaunchDescriptor implements ILaunchDescriptor {
- private final ILaunchDescriptorType type;
- private final ILaunchConfiguration config;
-
- public DefaultLaunchDescriptor(ILaunchDescriptorType type, ILaunchConfiguration config) {
- this.type = type;
- this.config = config;
- }
-
- @Override
- public String getName() {
- return config.getName();
- }
-
- @Override
- public ILaunchDescriptorType getType() {
- return type;
- }
- public ILaunchConfiguration getConfig() {
- return config;
- }
-
- public String getId() {
- return config.getName() + "." + type.getId();
- }
+public class DefaultLaunchDescriptor extends ConfigBasedLaunchDescriptor {
- @Override
- public int hashCode() {
- return 17 + getId().hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof DefaultLaunchDescriptor))
- return false;
- DefaultLaunchDescriptor other = (DefaultLaunchDescriptor) obj;
- if (!getId().equals(other.getId()))
- return false;
- return true;
+ public DefaultLaunchDescriptor(ILaunchDescriptorType type, ILaunchConfiguration config) {
+ super(type, config);
}
}
diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorConfigBased.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorConfigBased.java
new file mode 100644
index 00000000000..eefa5f8d4db
--- /dev/null
+++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorConfigBased.java
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2014 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Doug Schaefer
+ *******************************************************************************/
+package org.eclipse.cdt.launchbar.core;
+
+import org.eclipse.debug.core.ILaunchConfiguration;
+
+public interface ILaunchDescriptorConfigBased extends ILaunchDescriptor {
+ public ILaunchConfiguration getConfig();
+}
diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorType.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorType.java
index 11b3fc5feeb..98e1f9b2cd5 100644
--- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorType.java
+++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorType.java
@@ -13,8 +13,9 @@ package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.runtime.CoreException;
/**
- * Provides the list of launch configurations
- *
+ * Provides mapping between launch objects and launch descriptors.
+ *
+ * It is strongly recommended to extend AbstarctLaunchDescriptorType instead of implementing this directly
*/
public interface ILaunchDescriptorType {
diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/Activator.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/Activator.java
index e93db208261..14418a6cc0a 100644
--- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/Activator.java
+++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/Activator.java
@@ -63,7 +63,10 @@ public class Activator extends Plugin {
}
public static void log(IStatus status) {
- plugin.getLog().log(status);
+ if (plugin != null)
+ plugin.getLog().log(status);
+ else
+ System.err.println(status.getMessage());
}
public static void log(Exception exception) {
diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchConfigurationProvider.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchConfigurationProvider.java
index 748ba16652b..01a7d827282 100644
--- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchConfigurationProvider.java
+++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchConfigurationProvider.java
@@ -1,45 +1,19 @@
package org.eclipse.cdt.launchbar.core.internal;
-import org.eclipse.cdt.launchbar.core.DefaultLaunchDescriptor;
-import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
+import org.eclipse.cdt.launchbar.core.AbstractLaunchConfigurationProvider;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationProvider;
-import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationType;
-
-public class DefaultLaunchConfigurationProvider implements ILaunchConfigurationProvider {
-
- @Override
- public void init(ILaunchBarManager manager) throws CoreException {
- // nothing to do
- }
+public class DefaultLaunchConfigurationProvider extends AbstractLaunchConfigurationProvider implements ILaunchConfigurationProvider {
@Override
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
// We may own it but return false to let it percolate through to the descriptor type.
return false;
}
-
- @Override
- public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor) throws CoreException {
- if (descriptor instanceof DefaultLaunchDescriptor) {
- return ((DefaultLaunchDescriptor) descriptor).getConfig();
- }
- return null;
- }
-
- @Override
- public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor) throws CoreException {
- if (descriptor instanceof DefaultLaunchDescriptor) {
- return ((DefaultLaunchDescriptor) descriptor).getConfig().getType();
- }
- return null;
- }
@Override
public boolean launchConfigurationRemoved(ILaunchConfiguration configation) throws CoreException {
return false;
}
-
}
diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptorType.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptorType.java
index 8cee52fbf74..3210b873ed7 100644
--- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptorType.java
+++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptorType.java
@@ -1,40 +1,25 @@
package org.eclipse.cdt.launchbar.core.internal;
+import org.eclipse.cdt.launchbar.core.AbstarctLaunchDescriptorType;
import org.eclipse.cdt.launchbar.core.DefaultLaunchDescriptor;
-import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType;
import org.eclipse.debug.core.ILaunchConfiguration;
-public class DefaultLaunchDescriptorType implements ILaunchDescriptorType {
-
+public class DefaultLaunchDescriptorType extends AbstarctLaunchDescriptorType implements ILaunchDescriptorType {
public static final String ID = "org.eclipse.cdt.launchbar.core.descriptor.default";
- private ILaunchBarManager manager;
-
@Override
public String getId() {
return ID;
}
-
- @Override
- public void init(ILaunchBarManager manager) {
- this.manager = manager;
- }
-
@Override
public boolean ownsLaunchObject(Object element) {
return element instanceof ILaunchConfiguration;
}
-
+
@Override
public ILaunchDescriptor getDescriptor(Object element) {
return new DefaultLaunchDescriptor(this, (ILaunchConfiguration) element);
}
-
- @Override
- public ILaunchBarManager getManager() {
- return manager;
- }
-
}
diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManager.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManager.java
index 080646ee7e4..c0ae5290052 100644
--- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManager.java
+++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManager.java
@@ -15,13 +15,18 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
+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;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationProvider;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
+import org.eclipse.cdt.launchbar.core.ILaunchDescriptorConfigBased;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType;
import org.eclipse.cdt.launchbar.core.ILaunchObjectProvider;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
@@ -47,7 +52,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
private List<Listener> listeners = new LinkedList<>();
private Map<String, ILaunchTargetType> targetTypes = new HashMap<>();
- private List<ILaunchDescriptorType> descriptorTypes = new ArrayList<>();
+ private LinkedHashMap<ILaunchDescriptorType, Integer> descriptorTypes = new LinkedHashMap<>();
private Map<String, ILaunchDescriptor> descriptors = new HashMap<>();
private List<ILaunchObjectProvider> objectProviders = new ArrayList<>();
// Map descriptor type to target type to provider
@@ -66,83 +71,80 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
private static final String PREF_ACTIVE_LAUNCH_MODE = "activeLaunchMode";
private static final String PREF_ACTIVE_LAUNCH_TARGET = "activeLaunchTarget";
- public LaunchBarManager() throws CoreException {
- final Map<ILaunchDescriptorType, Integer> typePriorities = new HashMap<>();
- IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchBarContributions");
+ public LaunchBarManager() throws CoreException {
+ IExtensionPoint point = getExtensionPoint();
IExtension[] extensions = point.getExtensions();
+ // first pass - target, descriptors and object providers
for (IExtension extension : extensions) {
for (IConfigurationElement element : extension.getConfigurationElements()) {
- String elementName = element.getName();
- if (elementName.equals("descriptorType")) {
- String id = element.getAttribute("id");
- String priorityStr = element.getAttribute("priority");
- ILaunchDescriptorType type = (ILaunchDescriptorType) element.createExecutableExtension("class");
-
- assert id.equals(type.getId());
- descriptorTypes.add(type);
-
- int priority = 1;
- if (priorityStr != null) {
- try {
- priority = Integer.parseInt(priorityStr);
- } catch (NumberFormatException e) {
- // Log it but keep going with the default
- Activator.log(e);
+ try {
+ String elementName = element.getName();
+ if (elementName.equals("descriptorType")) {
+ String id = element.getAttribute("id");
+ String priorityStr = element.getAttribute("priority");
+ ILaunchDescriptorType type = (ILaunchDescriptorType) element.createExecutableExtension("class");
+ assert id.equals(type.getId());
+
+ int priority = 1;
+ if (priorityStr != null) {
+ try {
+ priority = Integer.parseInt(priorityStr);
+ } catch (NumberFormatException e) {
+ // Log it but keep going with the default
+ Activator.log(e);
+ }
}
+ addDescriptorType(type, priority);
+ } else if (elementName.equals("targetType")) {
+ String id = element.getAttribute("id");
+ ILaunchTargetType targetType = (ILaunchTargetType) element.createExecutableExtension("class");
+ assert id.equals(targetType.getId());
+ addTargetType(targetType);
+ } else if (elementName.equals("objectProvider")) {
+ ILaunchObjectProvider objectProvider = (ILaunchObjectProvider) element.createExecutableExtension("class");
+ objectProviders.add(objectProvider);
}
- typePriorities.put(type, priority);
- } else if (elementName.equals("targetType")) {
- String id = element.getAttribute("id");
- ILaunchTargetType targetType = (ILaunchTargetType) element.createExecutableExtension("class");
-
- assert id.equals(targetType.getId());
- targetTypes.put(id, targetType);
- } else if (elementName.equals("objectProvider")) {
- ILaunchObjectProvider objectProvider = (ILaunchObjectProvider) element.createExecutableExtension("class");
- objectProviders.add(objectProvider);
- } else if (elementName.equals("configProvider")) {
- String descriptorType = element.getAttribute("descriptorType");
- String targetType = element.getAttribute("targetType");
- String isDefault = element.getAttribute("isDefault");
- // TODO don't instantiate this until we need it
- ILaunchConfigurationProvider configProvider = (ILaunchConfigurationProvider) element.createExecutableExtension("class");
- addConfigProvider(descriptorType, targetType, Boolean.valueOf(isDefault), configProvider);
- } else if (elementName.equals("defaultConfigProvider")) {
- String descriptorType = element.getAttribute("descriptorType");
- String targetType = element.getAttribute("targetType");
- String launchType = element.getAttribute("launchConfigurationType");
- String isDefault = element.getAttribute("isDefault");
- ILaunchConfigurationProvider configProvider = new TypeBasedLaunchConfigurationProvider(launchType);
- addConfigProvider(descriptorType, targetType, Boolean.valueOf(isDefault), configProvider);
-
- ILaunchDescriptorType type = new TypeBasedLaunchDescriptorType(descriptorType, launchType);
- descriptorTypes.add(type);
- typePriorities.put(type, 2); // TODO: fix priority
+ } catch (Exception e) {
+ Activator.log(e); // exceptions during extension loading, log and move on
}
}
}
-
- Collections.sort(descriptorTypes, new Comparator<ILaunchDescriptorType>() {
- @Override
- public int compare(ILaunchDescriptorType o1, ILaunchDescriptorType o2) {
- int p1 = typePriorities.get(o1);
- int p2 = typePriorities.get(o2);
- // Reverse order, highest priority first
- if (p1 < p2)
- return 1;
- else if (p1 > p2)
- return -1;
- else
- return 0;
+ // second pass config providers that has references to targets and descriptors
+ for (IExtension extension : extensions) {
+ for (IConfigurationElement element : extension.getConfigurationElements()) {
+ try {
+ String elementName = element.getName();
+ if (elementName.equals("configProvider")) {
+ String descriptorType = element.getAttribute("descriptorType");
+ String targetType = element.getAttribute("targetType");
+ String isDefault = element.getAttribute("isDefault");
+ // TODO don't instantiate this until we need it
+ ILaunchConfigurationProvider configProvider = (ILaunchConfigurationProvider) element
+ .createExecutableExtension("class");
+ addConfigProvider(descriptorType, targetType, Boolean.valueOf(isDefault), configProvider);
+ } else if (elementName.equals("defaultConfigProvider")) {
+ String descriptorType = element.getAttribute("descriptorType");
+ String targetType = element.getAttribute("targetType");
+ String launchType = element.getAttribute("launchConfigurationType");
+ String isDefault = element.getAttribute("isDefault");
+ ILaunchConfigurationProvider configProvider = new ConfigBasedLaunchConfigurationProvider(launchType);
+ addConfigProvider(descriptorType, targetType, Boolean.valueOf(isDefault), configProvider);
+ ILaunchDescriptorType type = new ConfigBasedLaunchDescriptorType(descriptorType, launchType);
+ addDescriptorType(type, 2);// TODO: fix priority
+ }
+ } catch (Exception e) {
+ Activator.log(e); // exceptions during extension loading, log and move on
+ }
}
- });
+ }
+
// Load up the active from the preferences before loading the descriptors
- IEclipsePreferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
+ IEclipsePreferences store = getPreferenceStore();
String activeConfigDescId = store.get(PREF_ACTIVE_CONFIG_DESC, null);
- for (ILaunchDescriptorType descriptorType : descriptorTypes) {
+ for (ILaunchDescriptorType descriptorType : descriptorTypes.keySet()) {
descriptorType.init(this);
}
@@ -154,14 +156,8 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
objectProvider.init(this);
}
- for (Map<String, ILaunchConfigurationProvider> targetMap : configProviders.values()) {
- for (ILaunchConfigurationProvider configProvider : targetMap.values()) {
- configProvider.init(this);
- }
- }
-
// Hook up the existing launch configurations and listen
- ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchManager launchManager = getLaunchManager();
for (ILaunchConfiguration configuration : launchManager.getLaunchConfigurations()) {
launchConfigurationAdded(configuration);
}
@@ -180,17 +176,73 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
}
}
- protected void addConfigProvider(String descriptorType, String targetType, boolean isDefaultB,
+ protected static void sortMapByValue(LinkedHashMap<ILaunchDescriptorType, Integer> map) {
+ List<Map.Entry<ILaunchDescriptorType, Integer>> entries =
+ new ArrayList<Map.Entry<ILaunchDescriptorType, Integer>>(map.entrySet());
+ Collections.sort(entries, new Comparator<Map.Entry<ILaunchDescriptorType, Integer>>() {
+ public int compare(Map.Entry<ILaunchDescriptorType, Integer> a, Map.Entry<ILaunchDescriptorType, Integer> b) {
+ return b.getValue().compareTo(a.getValue()); // reverse order 3 2 1
+ }
+ });
+ LinkedHashMap<ILaunchDescriptorType, Integer> sortedMap = new LinkedHashMap<ILaunchDescriptorType, Integer>();
+ for (Map.Entry<ILaunchDescriptorType, Integer> entry : entries) {
+ sortedMap.put(entry.getKey(), entry.getValue());
+ }
+ map.clear();
+ map.putAll(sortedMap);
+ }
+
+ public void addDescriptorType(ILaunchDescriptorType type, int priority) {
+ descriptorTypes.put(type, priority);
+ sortMapByValue(descriptorTypes);
+ }
+
+ /**
+ * Programmatically add target type
+ */
+ public void addTargetType(ILaunchTargetType targetType) {
+ targetTypes.put(targetType.getId(), targetType);
+ }
+
+ protected ILaunchManager getLaunchManager() {
+ return DebugPlugin.getDefault().getLaunchManager();
+ }
+
+ protected IExtensionPoint getExtensionPoint() {
+ return Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchBarContributions");
+ }
+
+ /**
+ * Programmatically add launch configuration provider
+ */
+ public void addConfigProvider(String descriptorType, String targetType, boolean isDefaultB,
ILaunchConfigurationProvider configProvider) {
+ if (targetTypes.get(targetType) == null)
+ 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);
}
targetTypes.put(targetType, configProvider);
- if (isDefaultB) {
+ if (isDefaultB || defaultTargetTypes.get(descriptorType) == null) {
defaultTargetTypes.put(descriptorType, targetType);
}
+ try {
+ configProvider.init(this);
+ } catch (CoreException e) {
+ Activator.log(e);
+ }
+ }
+
+ public ILaunchDescriptorType getDescriptorType(String descriptorTypeId) {
+ for (ILaunchDescriptorType descriptorType : descriptorTypes.keySet()) {
+ if (descriptorType.getId().equals(descriptorTypeId))
+ return descriptorType;
+ }
+ return null;
}
@Override
@@ -199,7 +251,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
if (desc != null)
return desc;
- for (ILaunchDescriptorType descriptorType : descriptorTypes) {
+ for (ILaunchDescriptorType descriptorType : descriptorTypes.keySet()) {
try {
if (descriptorType.ownsLaunchObject(element)) {
desc = descriptorType.getDescriptor(element);
@@ -208,8 +260,8 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
ILaunchDescriptor old = descriptors.get(id);
if (old != null && !desc.equals(old))
Activator.log(new IllegalStateException(
- "Name of descriptor must be unique within same type "
- + "(or descriptors with same name must be equal)"));
+ "Id of descriptor must be unique within same type "
+ + "(or descriptors with same id must be equal)"));
descriptors.put(id, desc);
objectDescriptorMap.put(element, desc);
setActiveLaunchDescriptor(desc);
@@ -225,6 +277,8 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
}
private String getId(ILaunchDescriptor desc) {
+ if (desc == null)
+ return null;
return desc.getId();
}
@@ -262,28 +316,22 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
@Override
public void setActiveLaunchDescriptor(ILaunchDescriptor configDesc) throws CoreException {
- if (activeLaunchDesc != null && activeLaunchDesc == configDesc)
+ if (activeLaunchDesc == configDesc)
return;
lastLaunchDesc = activeLaunchDesc;
activeLaunchDesc = configDesc;
- IEclipsePreferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
- if (activeLaunchDesc != null) {
- store.put(PREF_ACTIVE_CONFIG_DESC, getId(activeLaunchDesc));
- } else {
- store.remove(PREF_ACTIVE_CONFIG_DESC);
- }
- try {
- store.flush();
- } catch (BackingStoreException e) {
- Activator.log(e);
- }
+ IEclipsePreferences store = getPreferenceStore();
+ setPreference(store, PREF_ACTIVE_CONFIG_DESC, getId(activeLaunchDesc));
// Send notifications
for (Listener listener : listeners) {
- listener.activeConfigurationDescriptorChanged();
+ try {
+ listener.activeConfigurationDescriptorChanged();
+ } catch (Exception e) {
+ Activator.log(e);
+ }
}
-
if (activeLaunchDesc == null) {
setActiveLaunchMode(null);
setActiveLaunchTarget(null);
@@ -291,36 +339,57 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
}
// Set active target
- String activeTargetId = store.node(activeLaunchDesc.getName()).get(PREF_ACTIVE_LAUNCH_TARGET, null);
+ 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 };
ILaunchTarget target = null;
- if (activeTargetId != null) {
- target = getLaunchTarget(activeTargetId);
- }
- if (target == null) {
- ILaunchTarget[] targets = getLaunchTargets();
- if (targets.length > 0) {
- target = targets[0];
+ for (int i = 0; i < targetIds.length; i++) {
+ String targetId = targetIds[i];
+ target = getLaunchTarget(targetId);
+ if (target != null && supportsTargetType(activeLaunchDesc, target.getType())) {
+ break;
}
}
- setActiveLaunchTarget(target);
+ setActiveLaunchTarget(target); // if target is null this will pick default
// Set active mode
- String activeModeName = store.node(activeLaunchDesc.getName()).get(PREF_ACTIVE_LAUNCH_MODE, null);
ILaunchConfigurationType configType = getLaunchConfigurationType(activeLaunchDesc, activeLaunchTarget);
- ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
ILaunchMode foundMode = null;
- if (activeModeName != null && configType.supportsMode(activeModeName)) {
- foundMode = launchManager.getLaunchMode(activeModeName);
+ 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() };
+ for (int i = 0; i < modeNames.length && foundMode == null; i++) {
+ String mode = modeNames[i];
+ if (mode != null && supportedModes.contains(mode)) {
+ foundMode = launchManager.getLaunchMode(mode);
+ }
+ }
+ }
}
- if (foundMode == null && configType.supportsMode("debug")) {
- foundMode = launchManager.getLaunchMode("debug");
+ setActiveLaunchMode(foundMode);
+ }
+
+ protected void setPreference(Preferences store, String prefId, String value) {
+ if (value != null) {
+ store.put(prefId, value);
+ } else {
+ store.remove(prefId);
}
- if (foundMode == null && configType.supportsMode("run")) {
- foundMode = launchManager.getLaunchMode("run");
+ try {
+ store.flush();
+ } catch (BackingStoreException e) {
+ Activator.log(e);
}
- setActiveLaunchMode(foundMode);
}
+ protected IEclipsePreferences getPreferenceStore() {
+ return InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
+ }
+
@Override
public ILaunchMode[] getLaunchModes() throws CoreException {
ILaunchConfigurationType configType = getLaunchConfigurationType(activeLaunchDesc, activeLaunchTarget);
@@ -328,7 +397,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
return new ILaunchMode[0];
List<ILaunchMode> modeList = new ArrayList<>();
- ILaunchMode[] modes = DebugPlugin.getDefault().getLaunchManager().getLaunchModes();
+ ILaunchMode[] modes = getLaunchManager().getLaunchModes();
for (ILaunchMode mode : modes) {
if (configType.supportsMode(mode.getIdentifier())) {
modeList.add(mode);
@@ -347,38 +416,47 @@ 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;
- for (Listener listener : listeners)
- listener.activeLaunchModeChanged();
-
+ // notify listeners
+ for (Listener listener : listeners) {
+ try {
+ listener.activeLaunchModeChanged();
+ } catch (Exception e) {
+ 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;
-
- Preferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).node(activeLaunchDesc.getName());
- if (mode != null) {
- store.put(PREF_ACTIVE_LAUNCH_MODE, mode.getIdentifier());
- } else {
- store.remove(PREF_ACTIVE_LAUNCH_MODE);
- }
- try {
- store.flush();
- } catch (BackingStoreException e) {
- // TODO log
- e.printStackTrace();
- }
+ setPreference(getPreferenceStore().node(activeLaunchDesc.getId()), PREF_ACTIVE_LAUNCH_MODE, modeId); // per desc store
}
@Override
public ILaunchTarget[] getLaunchTargets() {
- if (activeLaunchDesc == null)
+ return getLaunchTargets(activeLaunchDesc);
+ }
+
+ public ILaunchTarget[] getLaunchTargets(ILaunchDescriptor desc) {
+ if (desc == null)
return new ILaunchTarget[0];
List<ILaunchTarget> targetList = new ArrayList<>();
- Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(activeLaunchDesc.getType().getId());
+ Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(desc.getType().getId());
if (targetMap != null) {
- for (String id : targetMap.keySet()) {
- ILaunchTargetType type = targetTypes.get(id);
+ for (String targetTypeId : targetMap.keySet()) {
+ ILaunchTargetType type = targetTypes.get(targetTypeId);
if (type != null) {
ILaunchTarget[] targets = type.getTargets();
for (ILaunchTarget target : targets) {
@@ -397,42 +475,49 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
@Override
public void setActiveLaunchTarget(ILaunchTarget target) {
- if (activeLaunchTarget == target) return;
-
if (target == null) {
// try and select another target
- ILaunchTarget[] targets = getLaunchTargets();
- if (targets.length > 0) {
- target = targets[0];
- }
+ target = getDeafultLaunchTarget();
}
- activeLaunchTarget = target;
-
- for (Listener listener : listeners)
- listener.activeLaunchTargetChanged();
-
- if (activeLaunchDesc == null)
+ if (activeLaunchTarget == target)
return;
-
- Preferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).node(activeLaunchDesc.getName());
- if (target != null) {
- target.setActive();
- store.put(PREF_ACTIVE_LAUNCH_TARGET, target.getId());
- } else {
- store.remove(PREF_ACTIVE_LAUNCH_TARGET);
+ activeLaunchTarget = target;
+ for (Listener listener : listeners) {
+ try {
+ listener.activeLaunchTargetChanged();
+ } catch (Exception e) {
+ Activator.log(e);
+ }
}
- try {
- store.flush();
- } catch (BackingStoreException e) {
- // TODO log
- e.printStackTrace();
+ 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());
}
+ protected ILaunchTarget getDeafultLaunchTarget() {
+ ILaunchTarget target = null;
+ ILaunchTarget[] targets = getLaunchTargets();
+ if (targets.length > 0) {
+ target = targets[0];
+ }
+ return target;
+ }
+
@Override
- public ILaunchTarget getLaunchTarget(String id) {
+ public ILaunchTarget getLaunchTarget(String targetId) {
+ if (targetId == null)
+ return null;
for (ILaunchTargetType type : targetTypes.values()) {
- ILaunchTarget target = type.getTarget(id);
+ ILaunchTarget target = type.getTarget(targetId);
if (target != null)
return target;
}
@@ -455,9 +540,29 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
}
}
}
+ if (descriptor instanceof ILaunchDescriptorConfigBased) {
+ return ((ILaunchDescriptorConfigBased) descriptor).getConfig().getType();
+ }
return null;
}
+ 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);
+ if (targetMap != null) {
+ String targetTypeId = targetType.getId();
+ ILaunchConfigurationProvider configProvider = targetMap.get(targetTypeId);
+ if (configProvider != null) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
@Override
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException {
if (activeLaunchDesc == null || target == null)
@@ -487,7 +592,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
public void launchConfigurationAdded(ILaunchConfiguration configuration) {
try {
// TODO filter by launch configuration type to avoid loading plug-ins
- for (ILaunchDescriptorType descriptorType : descriptorTypes) {
+ for (ILaunchDescriptorType descriptorType : descriptorTypes.keySet()) {
Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(descriptorType.getId());
for (ILaunchConfigurationProvider configProvider : targetMap.values()) {
if (configProvider.launchConfigurationAdded(configuration)) {
@@ -507,7 +612,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
try {
// TODO filter by launch configuration type
- for (ILaunchDescriptorType descriptorType : descriptorTypes) {
+ for (ILaunchDescriptorType descriptorType : descriptorTypes.keySet()) {
Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(descriptorType.getId());
for (ILaunchConfigurationProvider configProvider : targetMap.values()) {
if (configProvider.launchConfigurationRemoved(configuration)) {

Back to the top