mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-26 01:33:53 +02:00
Bug 459972 - Update LaunchBar to use IRemoteConnection for targets.
ILaunchTarget is removed and replaced with IRemoteConnection. You still have to declare a launch target type to point at a connection type. It uses os and arch to help decide what toolchains to use for builds. Change-Id: I8f21b4e5043ccd8af85be91c643f58ad301c3ac4
This commit is contained in:
parent
5f3b1af3f1
commit
9c7de82238
37 changed files with 693 additions and 2119 deletions
|
@ -7,7 +7,8 @@ Bundle-Activator: org.eclipse.launchbar.core.internal.Activator
|
|||
Bundle-Vendor: Eclipse CDT
|
||||
Require-Bundle: org.eclipse.core.runtime,
|
||||
org.eclipse.debug.core,
|
||||
org.eclipse.core.filesystem
|
||||
org.eclipse.core.filesystem,
|
||||
org.eclipse.remote.core;bundle-version="2.0.0"
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Export-Package: org.eclipse.launchbar.core,
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<extension
|
||||
point="org.eclipse.launchbar.core.launchBarContributions">
|
||||
<targetType
|
||||
class="org.eclipse.launchbar.core.internal.LocalTargetType"
|
||||
connectionTypeId="ca.cdtdoug.wascana.arduino.core.connectionType"
|
||||
id="org.eclipse.launchbar.core.targetType.local">
|
||||
</targetType>
|
||||
<objectProvider
|
||||
|
|
|
@ -100,16 +100,30 @@
|
|||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="class" type="string" use="required">
|
||||
<attribute name="connectionTypeId" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute kind="java" basedOn=":org.eclipse.launchbar.core.ILaunchTargetType"/>
|
||||
<meta.attribute kind="identifier" basedOn="org.eclipse.remote.core.remoteServices/connectionType/@id"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="osname" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
The osname property for the connection, i.e. the operating system name, e.g. win32, linux. If not specified, matches all.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="osarch" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
The osarch property for the connection, i.e. the CPU architecture such as x86, armv7. If not specified, matches all.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
|
|
|
@ -39,30 +39,6 @@ public interface ILaunchBarManager {
|
|||
*/
|
||||
void launchObjectChanged(Object launchObject) throws CoreException;
|
||||
|
||||
/**
|
||||
* A new launch target has been added.
|
||||
*
|
||||
* @param target launch target
|
||||
* @throws CoreException
|
||||
*/
|
||||
void launchTargetAdded(ILaunchTarget target) throws CoreException;
|
||||
|
||||
/**
|
||||
* A launch target has been removed.
|
||||
*
|
||||
* @param target launch target
|
||||
* @throws CoreException
|
||||
*/
|
||||
void launchTargetRemoved(ILaunchTarget target) throws CoreException;
|
||||
|
||||
/**
|
||||
* The launch target has changed in some way that affects the
|
||||
* launch bar.
|
||||
*
|
||||
* @param target launch target
|
||||
*/
|
||||
void launchTargetChanged(ILaunchTarget target);
|
||||
|
||||
// TODO API for adding and removing types.
|
||||
|
||||
}
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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.launchbar.core;
|
||||
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
|
||||
public interface ILaunchTarget extends IAdaptable {
|
||||
|
||||
/**
|
||||
* Returns the name of this target.
|
||||
* Names must be unique across all targets of a given type.
|
||||
*
|
||||
* @return name of the target
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Returns the type for this target.
|
||||
*
|
||||
* @return type of the target
|
||||
*/
|
||||
ILaunchTargetType getType();
|
||||
|
||||
/**
|
||||
* The active state of this target has changed.
|
||||
*
|
||||
* @param active active state of the target
|
||||
*/
|
||||
void setActive(boolean active);
|
||||
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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.launchbar.core;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public interface ILaunchTargetType {
|
||||
|
||||
/**
|
||||
* Add initial targets and set up any listeners.
|
||||
*
|
||||
* @param manager
|
||||
* @throws CoreException
|
||||
*/
|
||||
void init(ILaunchBarManager manager) throws CoreException;
|
||||
|
||||
/**
|
||||
* Shutting down, remove any listeners
|
||||
*/
|
||||
void dispose();
|
||||
|
||||
}
|
|
@ -17,33 +17,38 @@ import org.eclipse.core.runtime.Plugin;
|
|||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.launchbar.core.ILaunchBarManager;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
|
||||
public class Activator extends Plugin {
|
||||
|
||||
public static final String PLUGIN_ID = "org.eclipse.launchbar.core";
|
||||
private static Activator plugin;
|
||||
private LaunchBarManager launchBarManager;
|
||||
|
||||
public void start(BundleContext bundleContext) throws Exception {
|
||||
super.start(bundleContext);
|
||||
plugin = this;
|
||||
launchBarManager = new LaunchBarManager();
|
||||
bundleContext.registerService(ILaunchBarManager.class, launchBarManager, null);
|
||||
bundleContext.registerService(ILaunchBarManager.class, new LaunchBarManager(), null);
|
||||
}
|
||||
|
||||
public void stop(BundleContext bundleContext) throws Exception {
|
||||
super.stop(bundleContext);
|
||||
plugin = null;
|
||||
launchBarManager.dispose();
|
||||
launchBarManager = null;
|
||||
}
|
||||
|
||||
public static Activator getDefault() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public LaunchBarManager getLaunchBarManager() {
|
||||
return launchBarManager;
|
||||
/**
|
||||
* Return the OSGi service with the given service interface.
|
||||
*
|
||||
* @param service service interface
|
||||
* @return the specified service or null if it's not registered
|
||||
*/
|
||||
public static <T> T getService(Class<T> service) {
|
||||
BundleContext context = plugin.getBundle().getBundleContext();
|
||||
ServiceReference<T> ref = context.getServiceReference(service);
|
||||
return ref != null ? context.getService(ref) : null;
|
||||
}
|
||||
|
||||
public static void throwCoreException(Exception e) throws CoreException {
|
||||
|
@ -58,8 +63,12 @@ public class Activator extends Plugin {
|
|||
}
|
||||
|
||||
public static void log(Exception exception) {
|
||||
if (exception instanceof CoreException) {
|
||||
log(((CoreException) exception).getStatus());
|
||||
} else {
|
||||
log(new Status(IStatus.ERROR, PLUGIN_ID, exception.getLocalizedMessage(), exception));
|
||||
}
|
||||
}
|
||||
|
||||
private static final String DEBUG_ONE =
|
||||
PLUGIN_ID + "/debug/launchbar";
|
||||
|
|
|
@ -13,24 +13,20 @@ package org.eclipse.launchbar.core.internal;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IExtension;
|
||||
import org.eclipse.core.runtime.IExtensionPoint;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.ISafeRunnable;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.SafeRunner;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
|
@ -46,15 +42,19 @@ import org.eclipse.launchbar.core.ILaunchConfigurationProvider;
|
|||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptorType;
|
||||
import org.eclipse.launchbar.core.ILaunchObjectProvider;
|
||||
import org.eclipse.launchbar.core.ILaunchTarget;
|
||||
import org.eclipse.launchbar.core.ILaunchTargetType;
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
import org.eclipse.remote.core.IRemoteConnectionChangeListener;
|
||||
import org.eclipse.remote.core.IRemoteConnectionType;
|
||||
import org.eclipse.remote.core.IRemoteServicesManager;
|
||||
import org.eclipse.remote.core.RemoteConnectionChangeEvent;
|
||||
import org.eclipse.remote.core.launch.IRemoteLaunchConfigService;
|
||||
import org.osgi.service.prefs.BackingStoreException;
|
||||
import org.osgi.service.prefs.Preferences;
|
||||
|
||||
/**
|
||||
* The brains of the launch bar.
|
||||
*/
|
||||
public class LaunchBarManager implements ILaunchBarManager, ILaunchConfigurationListener {
|
||||
public class LaunchBarManager implements ILaunchBarManager, ILaunchConfigurationListener, IRemoteConnectionChangeListener {
|
||||
|
||||
// TODO make these more fine grained or break them into more focused listeners
|
||||
public interface Listener {
|
||||
|
@ -65,124 +65,11 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
void launchTargetsChanged();
|
||||
}
|
||||
|
||||
public static class LaunchTargetTypeInfo {
|
||||
private final ILaunchTargetType type;
|
||||
private final String id;
|
||||
|
||||
public LaunchTargetTypeInfo(String id, ILaunchTargetType type) {
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public ILaunchTargetType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LaunchDescriptorTypeInfo {
|
||||
private final String id;
|
||||
private final int priority;
|
||||
private IConfigurationElement element;
|
||||
private ILaunchDescriptorType type;
|
||||
|
||||
public LaunchDescriptorTypeInfo(String id, int priority, IConfigurationElement element) {
|
||||
this.id = id;
|
||||
this.priority = priority;
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
// Used for testing
|
||||
public LaunchDescriptorTypeInfo(String id, int priority, ILaunchDescriptorType type) {
|
||||
this.id = id;
|
||||
this.priority = priority;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
public ILaunchDescriptorType getType() throws CoreException {
|
||||
if (type == null) {
|
||||
type = (ILaunchDescriptorType) element.createExecutableExtension("class");
|
||||
element = null;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LaunchConfigProviderInfo {
|
||||
private final String launchConfigTypeId;
|
||||
private IConfigurationElement element;
|
||||
private ILaunchConfigurationProvider provider;
|
||||
|
||||
public LaunchConfigProviderInfo(String launchConfigTypeId, IConfigurationElement element) {
|
||||
this.launchConfigTypeId = launchConfigTypeId;
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
// For testing
|
||||
public LaunchConfigProviderInfo(String launchConfigTypeId, ILaunchConfigurationProvider provider) {
|
||||
this.launchConfigTypeId = launchConfigTypeId;
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
public String getLaunchConfigTypeId() {
|
||||
return launchConfigTypeId;
|
||||
}
|
||||
|
||||
public ILaunchConfigurationProvider getProvider() throws CoreException {
|
||||
if (provider == null) {
|
||||
provider = (ILaunchConfigurationProvider) element.createExecutableExtension("class");
|
||||
element = null;
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LaunchConfigTypeInfo {
|
||||
private final String descriptorTypeId;
|
||||
private final String targetTypeId;
|
||||
private final String launchConfigTypeId;
|
||||
|
||||
public LaunchConfigTypeInfo(String descriptorTypeId, String targetTypeId, String launchConfigTypeId) {
|
||||
this.descriptorTypeId = descriptorTypeId;
|
||||
this.targetTypeId = targetTypeId;
|
||||
this.launchConfigTypeId = launchConfigTypeId;
|
||||
}
|
||||
|
||||
public String getDescriptorTypeId() {
|
||||
return descriptorTypeId;
|
||||
}
|
||||
|
||||
public String getTargetTypeId() {
|
||||
return targetTypeId;
|
||||
}
|
||||
|
||||
public String getLaunchConfigTypeId() {
|
||||
return launchConfigTypeId;
|
||||
}
|
||||
}
|
||||
|
||||
private final List<Listener> listeners = new LinkedList<>();
|
||||
|
||||
// The launch object providers
|
||||
private final List<ILaunchObjectProvider> objectProviders = new ArrayList<>();
|
||||
|
||||
// The target types by id - doesn't need to be an executablExtension since it runs right away
|
||||
private final Map<String, ILaunchTargetType> targetTypes = new HashMap<>();
|
||||
|
||||
// The extended info for the target types as specified in the extension
|
||||
private final Map<ILaunchTargetType, LaunchTargetTypeInfo> targetTypeInfo = new HashMap<>();
|
||||
|
||||
// The descriptor types
|
||||
private final Map<String, LaunchDescriptorTypeInfo> descriptorTypes = new HashMap<>();
|
||||
|
||||
|
@ -192,20 +79,29 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
// Descriptor types ordered from highest priority to lowest
|
||||
private final List<LaunchDescriptorTypeInfo> orderedDescriptorTypes = new LinkedList<>();
|
||||
|
||||
// The mapping from descriptor type to target type to config type info
|
||||
private final Map<String, Map<String, LaunchConfigTypeInfo>> configTypes = new HashMap<>();
|
||||
// The target types by id
|
||||
private final Map<String, LaunchTargetTypeInfo> targetTypes = new HashMap<>();
|
||||
|
||||
// The list of target types for a given descriptor type
|
||||
private final Map<String, List<String>> descriptorTargets = new HashMap<>();
|
||||
|
||||
// The mapping from descriptor type to target type to launch config type
|
||||
private final Map<String, Map<String, String>> configTypes = new HashMap<>();
|
||||
|
||||
// Map descriptor type to target type so we can build when no targets have been added
|
||||
private final Map<String, String> defaultTargetTypes = new HashMap<>();
|
||||
|
||||
// Map from launch config type id to target type ids for default descriptors
|
||||
private final Map<String, List<String>> configTargetTypes = new HashMap<>();
|
||||
|
||||
// Map from launch config type Id to target type id for default descriptor for null target
|
||||
private final Map<String, String> defaultConfigTargetTypes = new HashMap<>();
|
||||
|
||||
// The launch config providers
|
||||
private final Map<String, LaunchConfigProviderInfo> configProviders = new HashMap<>();
|
||||
|
||||
// Map from launch config type id to target type id for default config descriptor
|
||||
private final Map<String, Set<String>> defaultConfigTargetTypes = new HashMap<>();
|
||||
|
||||
// Map from launch config type Id to target type id for default config descriptor for null target
|
||||
private final Map<String, String> defaultConfigDefaultTargetTypes = new HashMap<>();
|
||||
// The default launch descriptor type used to wrap unclaimed launch configs
|
||||
private DefaultLaunchDescriptorType defaultDescriptorType = new DefaultLaunchDescriptorType();
|
||||
|
||||
// Descriptors in MRU order, key is desc type id and desc name.
|
||||
private final Map<Pair<String, String>, ILaunchDescriptor> descriptors = new LinkedHashMap<>();
|
||||
|
@ -213,18 +109,15 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
// Map of launch objects to launch descriptors
|
||||
private final Map<Object, ILaunchDescriptor> objectDescriptorMap = new HashMap<>();
|
||||
|
||||
// Targets, key is target type id and target name.
|
||||
private final Map<Pair<String, String>, ILaunchTarget> targets = new HashMap<>();
|
||||
|
||||
// The created launch configurations
|
||||
private final Map<ILaunchDescriptor, Map<ILaunchConfigurationProvider, ILaunchConfiguration>> configs = new HashMap<>();
|
||||
|
||||
private final IRemoteServicesManager remoteServicesManager = getRemoteServicesManager();
|
||||
private final IRemoteLaunchConfigService remoteLaunchConfigService = getRemoteLaunchConfigService();
|
||||
|
||||
private ILaunchDescriptor activeLaunchDesc;
|
||||
private ILaunchMode activeLaunchMode;
|
||||
private ILaunchTarget activeLaunchTarget;
|
||||
|
||||
// The default launch descriptor type used to wrap unclaimed launch configs
|
||||
private DefaultLaunchDescriptorType defaultDescriptorType = new DefaultLaunchDescriptorType();
|
||||
private IRemoteConnection activeLaunchTarget;
|
||||
|
||||
// private static final String PREF_ACTIVE_CONFIG_DESC = "activeConfigDesc";
|
||||
private static final String PREF_ACTIVE_LAUNCH_MODE = "activeLaunchMode";
|
||||
|
@ -232,6 +125,14 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
private static final String PREF_CONFIG_DESC_ORDER = "configDescList";
|
||||
|
||||
public LaunchBarManager() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
// called from unit tests to ensure everything is inited
|
||||
LaunchBarManager(boolean doInit) {
|
||||
remoteServicesManager.addRemoteConnectionChangeListener(this);
|
||||
|
||||
if (doInit) {
|
||||
new Job("Launch Bar Initialization") {
|
||||
@Override
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
|
@ -244,8 +145,29 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
}
|
||||
}.schedule();
|
||||
}
|
||||
}
|
||||
|
||||
public void init() throws CoreException {
|
||||
// To allow override by tests
|
||||
IRemoteServicesManager getRemoteServicesManager() {
|
||||
return Activator.getService(IRemoteServicesManager.class);
|
||||
}
|
||||
|
||||
IRemoteLaunchConfigService getRemoteLaunchConfigService() {
|
||||
return Activator.getService(IRemoteLaunchConfigService.class);
|
||||
}
|
||||
|
||||
// To allow override by tests
|
||||
IExtensionPoint getExtensionPoint() throws CoreException {
|
||||
return Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchBarContributions");
|
||||
}
|
||||
|
||||
// To allow override by tests
|
||||
ILaunchManager getLaunchManager() {
|
||||
return DebugPlugin.getDefault().getLaunchManager();
|
||||
}
|
||||
|
||||
// When testing, call this after setting up the mocks.
|
||||
void init() throws CoreException {
|
||||
// Fetch the desc order before the init messes it up
|
||||
IEclipsePreferences store = getPreferenceStore();
|
||||
String configDescIds = store.get(PREF_CONFIG_DESC_ORDER, "");
|
||||
|
@ -285,17 +207,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
// To allow override by tests
|
||||
protected IExtensionPoint getExtensionPoint() throws CoreException {
|
||||
return Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchBarContributions");
|
||||
}
|
||||
|
||||
// To allow override by tests
|
||||
protected ILaunchManager getLaunchManager() {
|
||||
return DebugPlugin.getDefault().getLaunchManager();
|
||||
}
|
||||
|
||||
protected void loadExtensions() throws CoreException {
|
||||
private void loadExtensions() throws CoreException {
|
||||
IExtensionPoint point = getExtensionPoint();
|
||||
IExtension[] extensions = point.getExtensions();
|
||||
|
||||
|
@ -305,42 +217,50 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
try {
|
||||
String elementName = element.getName();
|
||||
if (elementName.equals("descriptorType")) {
|
||||
String id = element.getAttribute("id");
|
||||
String priorityStr = element.getAttribute("priority");
|
||||
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);
|
||||
}
|
||||
}
|
||||
LaunchDescriptorTypeInfo typeInfo = new LaunchDescriptorTypeInfo(id, priority, element);
|
||||
LaunchDescriptorTypeInfo typeInfo = new LaunchDescriptorTypeInfo(element);
|
||||
addDescriptorType(typeInfo);
|
||||
} else if (elementName.equals("targetType")) {
|
||||
String id = element.getAttribute("id");
|
||||
ILaunchTargetType targetType = (ILaunchTargetType) element.createExecutableExtension("class");
|
||||
LaunchTargetTypeInfo info = new LaunchTargetTypeInfo(id, targetType);
|
||||
addTargetType(info);
|
||||
} else if (elementName.equals("configProvider")) {
|
||||
String configTypeId = element.getAttribute("launchConfigurationType");
|
||||
LaunchConfigProviderInfo info = new LaunchConfigProviderInfo(configTypeId, element);
|
||||
addConfigProvider(info);
|
||||
LaunchTargetTypeInfo info = new LaunchTargetTypeInfo(element);
|
||||
targetTypes.put(info.getId(), info);
|
||||
} else if (elementName.equals("configType")) {
|
||||
String descriptorTypeId = element.getAttribute("descriptorType");
|
||||
String targetTypeId = element.getAttribute("targetType");
|
||||
String configTypeId = element.getAttribute("launchConfigurationType");
|
||||
String isDefault = element.getAttribute("isDefault");
|
||||
LaunchConfigTypeInfo info = new LaunchConfigTypeInfo(descriptorTypeId, targetTypeId, configTypeId);
|
||||
addConfigType(info, Boolean.valueOf(isDefault));
|
||||
String launchConfigTypeId = element.getAttribute("launchConfigurationType");
|
||||
String isDefaultStr = element.getAttribute("isDefault");
|
||||
boolean isDefault = isDefaultStr != null ? Boolean.parseBoolean(isDefaultStr) : false;
|
||||
|
||||
// add to desc type -> target type mapping
|
||||
List<String> targetTypes = descriptorTargets.get(descriptorTypeId);
|
||||
if (targetTypes == null) {
|
||||
targetTypes = new ArrayList<>();
|
||||
descriptorTargets.put(descriptorTypeId, targetTypes);
|
||||
}
|
||||
targetTypes.add(targetTypeId);
|
||||
|
||||
// Add to desc type -> target type -> config type mapping
|
||||
Map<String, String> targetConfigMap = configTypes.get(descriptorTypeId);
|
||||
if (targetConfigMap == null) {
|
||||
targetConfigMap = new HashMap<>();
|
||||
configTypes.put(descriptorTypeId, targetConfigMap);
|
||||
}
|
||||
targetConfigMap.put(targetTypeId, launchConfigTypeId);
|
||||
|
||||
// If default, add to defaults list
|
||||
if (isDefault) {
|
||||
defaultTargetTypes.put(descriptorTypeId, targetTypeId);
|
||||
}
|
||||
|
||||
// also assume that the target type works for the config type
|
||||
addDefaultConfigTargetType(configTypeId, targetTypeId, Boolean.valueOf(isDefault));
|
||||
addDefaultConfigTargetType(launchConfigTypeId, targetTypeId, isDefault);
|
||||
} else if (elementName.equals("configProvider")) {
|
||||
LaunchConfigProviderInfo info = new LaunchConfigProviderInfo(element);
|
||||
configProviders.put(info.getLaunchConfigTypeId(), info);
|
||||
} else if (elementName.equals("defaultConfigTarget")) {
|
||||
String configTypeId = element.getAttribute("launchConfigurationType");
|
||||
String targetTypeId = element.getAttribute("targetType");
|
||||
String isDefault = element.getAttribute("isDefault");
|
||||
addDefaultConfigTargetType(configTypeId, targetTypeId, Boolean.valueOf(isDefault));
|
||||
String isDefaultStr = element.getAttribute("isDefault");
|
||||
boolean isDefault = isDefaultStr != null ? Boolean.parseBoolean(isDefaultStr) : false;
|
||||
addDefaultConfigTargetType(configTypeId, targetTypeId, isDefault);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
|
@ -364,7 +284,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
public void addDescriptorType(LaunchDescriptorTypeInfo typeInfo) throws CoreException {
|
||||
private void addDescriptorType(LaunchDescriptorTypeInfo typeInfo) throws CoreException {
|
||||
descriptorTypes.put(typeInfo.getId(), typeInfo);
|
||||
// TODO figure out a better place to set the id so we don't load the type object until needed
|
||||
descriptorTypeInfo.put(typeInfo.getType(), typeInfo);
|
||||
|
@ -386,53 +306,20 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
Activator.trace("registered descriptor type " + typeInfo.getId());
|
||||
}
|
||||
|
||||
public void addTargetType(final LaunchTargetTypeInfo info) {
|
||||
targetTypes.put(info.getId(), info.getType());
|
||||
targetTypeInfo.put(info.getType(), info);
|
||||
SafeRunner.run(new ISafeRunnable() {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
info.getType().init(LaunchBarManager.this);
|
||||
}
|
||||
@Override
|
||||
public void handleException(Throwable exception) {
|
||||
Activator.trace("target runner init exception " + info.getId());
|
||||
}
|
||||
});
|
||||
Activator.trace("registered target " + info.getId());
|
||||
}
|
||||
|
||||
public void addConfigType(LaunchConfigTypeInfo info, boolean isDefault) {
|
||||
Map<String, LaunchConfigTypeInfo> targetMap = configTypes.get(info.getDescriptorTypeId());
|
||||
if (targetMap == null) {
|
||||
targetMap = new HashMap<>();
|
||||
configTypes.put(info.getDescriptorTypeId(), targetMap);
|
||||
}
|
||||
targetMap.put(info.getTargetTypeId(), info);
|
||||
|
||||
if (isDefault) {
|
||||
defaultTargetTypes.put(info.getDescriptorTypeId(), info.getTargetTypeId());
|
||||
}
|
||||
}
|
||||
|
||||
public void addConfigProvider(LaunchConfigProviderInfo info) {
|
||||
configProviders.put(info.getLaunchConfigTypeId(), info);
|
||||
}
|
||||
|
||||
public void addDefaultConfigTargetType(String configTypeId, String targetTypeId, boolean isDefault) {
|
||||
Set<String> targetTypes = defaultConfigTargetTypes.get(configTypeId);
|
||||
private void addDefaultConfigTargetType(String configTypeId, String targetTypeId, boolean isDefault) {
|
||||
List<String> targetTypes = configTargetTypes.get(configTypeId);
|
||||
if (targetTypes == null) {
|
||||
targetTypes = new HashSet<>();
|
||||
defaultConfigTargetTypes.put(configTypeId, targetTypes);
|
||||
targetTypes = new ArrayList<>();
|
||||
configTargetTypes.put(configTypeId, targetTypes);
|
||||
}
|
||||
targetTypes.add(targetTypeId);
|
||||
|
||||
if (isDefault) {
|
||||
defaultConfigDefaultTargetTypes.put(configTypeId, targetTypeId);
|
||||
defaultConfigTargetTypes.put(configTypeId, targetTypeId);
|
||||
}
|
||||
}
|
||||
|
||||
public void addObjectProvider(ILaunchObjectProvider objectProvider) {
|
||||
private void addObjectProvider(ILaunchObjectProvider objectProvider) {
|
||||
objectProviders.add(objectProvider);
|
||||
try {
|
||||
objectProvider.init(this);
|
||||
|
@ -465,43 +352,23 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
public ILaunchDescriptorType getLaunchDescriptorType(String id) throws CoreException {
|
||||
return descriptorTypes.get(id).getType();
|
||||
}
|
||||
|
||||
public ILaunchDescriptor getLaunchDescriptor(Pair<String, String> id) {
|
||||
return descriptors.get(id);
|
||||
}
|
||||
|
||||
public ILaunchDescriptor getLaunchDescriptor(Object launchObject) {
|
||||
return objectDescriptorMap.get(launchObject);
|
||||
}
|
||||
|
||||
public String getDescriptorTypeId(ILaunchDescriptorType type) {
|
||||
return descriptorTypeInfo.get(type).getId();
|
||||
}
|
||||
|
||||
public Pair<String, String> getDescriptorId(ILaunchDescriptor descriptor) {
|
||||
private Pair<String, String> getDescriptorId(ILaunchDescriptor descriptor) {
|
||||
return new Pair<String, String>(getDescriptorTypeId(descriptor.getType()), descriptor.getName());
|
||||
}
|
||||
|
||||
public ILaunchTargetType getLaunchTargetType(String id) {
|
||||
return targetTypes.get(id);
|
||||
private Pair<String, String> getTargetId(IRemoteConnection target) {
|
||||
return new Pair<String, String>(target.getConnectionType().getId(), target.getName());
|
||||
}
|
||||
|
||||
public String getTargetTypeId(ILaunchTargetType type) {
|
||||
return targetTypeInfo.get(type).getId();
|
||||
}
|
||||
|
||||
private Pair<String, String> getTargetId(ILaunchTarget target) {
|
||||
return new Pair<String, String>(getTargetTypeId(target.getType()), target.getName());
|
||||
}
|
||||
|
||||
public String toString(Pair<String, String> key) {
|
||||
private String toString(Pair<String, String> key) {
|
||||
return key.getFirst() + ":" + key.getSecond();
|
||||
}
|
||||
|
||||
protected Pair<String, String> toId(String key) {
|
||||
private Pair<String, String> toId(String key) {
|
||||
int i = key.indexOf(':');
|
||||
if (i < 0) {
|
||||
return null;
|
||||
|
@ -510,38 +377,78 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
return new Pair<String, String>(key.substring(0, i), key.substring(i + 1));
|
||||
}
|
||||
|
||||
private ILaunchConfigurationProvider getConfigProvider(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException {
|
||||
private LaunchTargetTypeInfo getTargetTypeInfo(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
||||
// Figure out what our target type is.
|
||||
// Any target types registered with this descriptor type?
|
||||
List<String> targetTypeIds = descriptorTargets.get(getDescriptorTypeId(descriptor.getType()));
|
||||
if (targetTypeIds == null) {
|
||||
// Nope, how about with the config type
|
||||
ILaunchConfiguration config = (ILaunchConfiguration) descriptor.getAdapter(ILaunchConfiguration.class);
|
||||
if (config != null) {
|
||||
targetTypeIds = configTargetTypes.get(config.getType().getIdentifier());
|
||||
}
|
||||
}
|
||||
|
||||
LaunchTargetTypeInfo targetTypeInfo = null;
|
||||
if (targetTypeIds != null) {
|
||||
for (String targetTypeId : targetTypeIds) {
|
||||
LaunchTargetTypeInfo info = targetTypes.get(targetTypeId);
|
||||
if (info != null && info.matches(target)) {
|
||||
if (targetTypeInfo == null) {
|
||||
targetTypeInfo = info;
|
||||
} else {
|
||||
// Is it a better match? i.e. doesn't rely on wild cards
|
||||
if ((targetTypeInfo.getOsName().isEmpty() && !info.getOsName().isEmpty())
|
||||
|| (targetTypeInfo.getOsArch().isEmpty() && !info.getOsArch().isEmpty())) {
|
||||
targetTypeInfo = info;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return targetTypeInfo;
|
||||
}
|
||||
|
||||
private ILaunchConfigurationProvider getConfigProvider(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
||||
if (descriptor == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ILaunchDescriptorType descriptorType = descriptor.getType();
|
||||
|
||||
ILaunchTargetType targetType = null;
|
||||
if (target != null) {
|
||||
targetType = target.getType();
|
||||
} else {
|
||||
String targetTypeId = defaultTargetTypes.get(getDescriptorTypeId(descriptorType));
|
||||
if (targetTypeId != null) {
|
||||
targetType = targetTypes.get(targetTypeId);
|
||||
}
|
||||
}
|
||||
|
||||
if (targetType == null) {
|
||||
LaunchTargetTypeInfo targetTypeInfo = getTargetTypeInfo(descriptor, target);
|
||||
if (targetTypeInfo == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, LaunchConfigTypeInfo> targetMap = configTypes.get(getDescriptorTypeId(descriptorType));
|
||||
Map<String, String> targetMap = configTypes.get(getDescriptorTypeId(descriptor.getType()));
|
||||
if (targetMap != null) {
|
||||
LaunchConfigTypeInfo typeInfo = targetMap.get(getTargetTypeId(targetType));
|
||||
if (typeInfo != null) {
|
||||
LaunchConfigProviderInfo providerInfo = configProviders.get(typeInfo.getLaunchConfigTypeId());
|
||||
String configProviderId = targetMap.get(targetTypeInfo.getId());
|
||||
LaunchConfigProviderInfo providerInfo = configProviders.get(configProviderId);
|
||||
if (providerInfo != null) {
|
||||
return providerInfo.getProvider();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
||||
if (descriptor == null)
|
||||
return null;
|
||||
|
||||
LaunchTargetTypeInfo targetTypeInfo = getTargetTypeInfo(descriptor, target);
|
||||
if (targetTypeInfo != null) {
|
||||
Map<String, String> targetMap = configTypes.get(getDescriptorTypeId(descriptor.getType()));
|
||||
if (targetMap != null) {
|
||||
String configTypeId = targetMap.get(targetTypeInfo.getId());
|
||||
return getLaunchManager().getLaunchConfigurationType(configTypeId);
|
||||
}
|
||||
}
|
||||
|
||||
ILaunchConfiguration config = (ILaunchConfiguration) descriptor.getAdapter(ILaunchConfiguration.class);
|
||||
if (config != null)
|
||||
return config.getType();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -673,23 +580,19 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO turning off for now since it's buggy. There is thought though that we may want
|
||||
// to keep the active target when changing descriptors if it's valid for that descriptor.
|
||||
// If we do that, then the active target should be recorded against the target type.
|
||||
// The active target is too random at startup for this to work as coded here.
|
||||
// if (activeLaunchTarget != null && supportsTargetType(activeLaunchDesc, activeLaunchTarget)) {
|
||||
// return; // not changing target
|
||||
// }
|
||||
|
||||
// last stored target from persistent storage
|
||||
String activeTargetId = getPerDescriptorStore().get(PREF_ACTIVE_LAUNCH_TARGET, null);
|
||||
if (activeTargetId != null) {
|
||||
ILaunchTarget storedTarget = getLaunchTarget(toId(activeTargetId));
|
||||
Pair<String, String> id = toId(activeTargetId);
|
||||
IRemoteConnectionType remoteServices = remoteServicesManager.getConnectionType(id.getFirst());
|
||||
if (remoteServices != null) {
|
||||
IRemoteConnection storedTarget = remoteServices.getConnection(id.getSecond());
|
||||
if (storedTarget != null && supportsTargetType(activeLaunchDesc, storedTarget)) {
|
||||
setActiveLaunchTarget(storedTarget);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// default target for descriptor
|
||||
setActiveLaunchTarget(getDefaultLaunchTarget(activeLaunchDesc));
|
||||
}
|
||||
|
@ -707,8 +610,8 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
String modeNames[] = new String[] {
|
||||
storedModeId,
|
||||
lastActiveModeId,
|
||||
"debug",
|
||||
"run",
|
||||
"debug",
|
||||
supportedModes[0].getIdentifier()
|
||||
};
|
||||
for (int i = 0; i < modeNames.length; i++) {
|
||||
|
@ -720,7 +623,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
setActiveLaunchMode(foundMode);
|
||||
}
|
||||
|
||||
public boolean supportsMode(ILaunchMode mode) throws CoreException {
|
||||
private boolean supportsMode(ILaunchMode mode) throws CoreException {
|
||||
// check that active descriptor supports the given mode
|
||||
if (mode == null)
|
||||
return false;
|
||||
|
@ -733,7 +636,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
return false;
|
||||
}
|
||||
|
||||
protected void setPreference(Preferences store, String prefId, String value) {
|
||||
private void setPreference(Preferences store, String prefId, String value) {
|
||||
if (value != null) {
|
||||
store.put(prefId, value);
|
||||
} else {
|
||||
|
@ -746,17 +649,17 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
protected Preferences getPerDescriptorStore() {
|
||||
private Preferences getPerDescriptorStore() {
|
||||
if (activeLaunchDesc == null)
|
||||
return getPreferenceStore();
|
||||
return getPreferenceStore().node(toString(getDescriptorId(activeLaunchDesc)));
|
||||
}
|
||||
|
||||
protected IEclipsePreferences getPreferenceStore() {
|
||||
private IEclipsePreferences getPreferenceStore() {
|
||||
return InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
|
||||
}
|
||||
|
||||
public void updateLaunchDescriptor(ILaunchDescriptor configDesc) {
|
||||
private void updateLaunchDescriptor(ILaunchDescriptor configDesc) {
|
||||
for (Listener listener : listeners) {
|
||||
try {
|
||||
listener.activeLaunchDescriptorChanged();
|
||||
|
@ -767,6 +670,9 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
}
|
||||
|
||||
public ILaunchMode[] getLaunchModes() throws CoreException {
|
||||
if (activeLaunchTarget == null) {
|
||||
return new ILaunchMode[0];
|
||||
}
|
||||
ILaunchConfigurationType configType = getLaunchConfigurationType(activeLaunchDesc, activeLaunchTarget);
|
||||
if (configType == null)
|
||||
return new ILaunchMode[0];
|
||||
|
@ -805,88 +711,64 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
setPreference(getPerDescriptorStore(), PREF_ACTIVE_LAUNCH_MODE, mode.getIdentifier()); // per desc store
|
||||
}
|
||||
|
||||
public ILaunchTarget[] getAllLaunchTargets() {
|
||||
return targets.values().toArray(new ILaunchTarget[targets.size()]);
|
||||
}
|
||||
|
||||
public ILaunchTarget[] getLaunchTargets() throws CoreException {
|
||||
return getLaunchTargets(activeLaunchDesc);
|
||||
}
|
||||
|
||||
public ILaunchTarget[] getLaunchTargets(ILaunchDescriptor descriptor) throws CoreException {
|
||||
public List<IRemoteConnection> getLaunchTargets(ILaunchDescriptor descriptor) throws CoreException {
|
||||
if (descriptor == null)
|
||||
return new ILaunchTarget[0];
|
||||
return Collections.emptyList();
|
||||
|
||||
// See if there is are targets registered with this descriptor type
|
||||
Map<String, LaunchConfigTypeInfo> targetMap = configTypes.get(getDescriptorTypeId(descriptor.getType()));
|
||||
if (targetMap != null) {
|
||||
List<ILaunchTarget> targetList = new ArrayList<>();
|
||||
// Not super fast, but we're assuming there aren't many targets.
|
||||
for (Entry<Pair<String, String>, ILaunchTarget> targetEntry : targets.entrySet()) {
|
||||
if (targetMap.containsKey(targetEntry.getKey().getFirst())) {
|
||||
targetList.add(targetEntry.getValue());
|
||||
}
|
||||
}
|
||||
return targetList.toArray(new ILaunchTarget[targetList.size()]);
|
||||
}
|
||||
|
||||
// Nope, see if there are any default config targets
|
||||
// Any target types registered with this descriptor type?
|
||||
List<String> targetTypeIds = descriptorTargets.get(getDescriptorTypeId(descriptor.getType()));
|
||||
if (targetTypeIds == null) {
|
||||
// Nope, how about with the config type
|
||||
ILaunchConfiguration config = (ILaunchConfiguration) descriptor.getAdapter(ILaunchConfiguration.class);
|
||||
if (config != null) {
|
||||
Set<String> targetTypeIds = defaultConfigTargetTypes.get(config.getType().getIdentifier());
|
||||
targetTypeIds = configTargetTypes.get(config.getType().getIdentifier());
|
||||
}
|
||||
}
|
||||
|
||||
if (targetTypeIds != null) {
|
||||
List<ILaunchTarget> targetList = new ArrayList<>();
|
||||
// Not super fast, but we're assuming there aren't many targets.
|
||||
for (Entry<Pair<String, String>, ILaunchTarget> targetEntry : targets.entrySet()) {
|
||||
if (targetTypeIds.contains(targetEntry.getKey().getFirst())) {
|
||||
targetList.add(targetEntry.getValue());
|
||||
List<IRemoteConnection> targetList = new ArrayList<>();
|
||||
for (IRemoteConnection connection : remoteServicesManager.getAllRemoteConnections()) {
|
||||
for (String targetTypeId : targetTypeIds) {
|
||||
LaunchTargetTypeInfo info = targetTypes.get(targetTypeId);
|
||||
if (info != null && info.matches(connection)) {
|
||||
targetList.add(connection);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return targetList.toArray(new ILaunchTarget[targetList.size()]);
|
||||
}
|
||||
return targetList;
|
||||
}
|
||||
|
||||
// Nope, return the local target
|
||||
for (Entry<Pair<String, String>, ILaunchTarget> targetEntry : targets.entrySet()) {
|
||||
if (LocalTargetType.ID.equals(targetEntry.getKey().getFirst())) {
|
||||
return new ILaunchTarget[] { targetEntry.getValue() };
|
||||
}
|
||||
// Nope, return the local target, the default default
|
||||
IRemoteConnectionType localServices = remoteServicesManager.getLocalConnectionType();
|
||||
return localServices.getConnections();
|
||||
}
|
||||
|
||||
// Not found, weird
|
||||
return new ILaunchTarget[0];
|
||||
}
|
||||
|
||||
public ILaunchTarget getActiveLaunchTarget() {
|
||||
public IRemoteConnection getActiveLaunchTarget() {
|
||||
return activeLaunchTarget;
|
||||
}
|
||||
|
||||
public void setActiveLaunchTarget(ILaunchTarget target) throws CoreException {
|
||||
public void setActiveLaunchTarget(IRemoteConnection target) throws CoreException {
|
||||
if (activeLaunchTarget == target) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (activeLaunchTarget != null) {
|
||||
activeLaunchTarget.setActive(false);
|
||||
}
|
||||
|
||||
activeLaunchTarget = target;
|
||||
launchTargetChanged(activeLaunchTarget);
|
||||
if (target == null) {
|
||||
return; // no point storing null, if stored id is invalid it won't be used anyway
|
||||
}
|
||||
|
||||
target.setActive(true);
|
||||
if (activeLaunchDesc == null)
|
||||
return;
|
||||
|
||||
// per desc store
|
||||
if (supportsTargetType(activeLaunchDesc, target))
|
||||
setPreference(getPerDescriptorStore(),
|
||||
PREF_ACTIVE_LAUNCH_TARGET, toString(getTargetId(target)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launchTargetChanged(ILaunchTarget target) {
|
||||
private void launchTargetChanged(IRemoteConnection target) {
|
||||
for (Listener listener : listeners) {
|
||||
try {
|
||||
listener.activeLaunchTargetChanged();
|
||||
|
@ -896,91 +778,27 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launchTargetAdded(ILaunchTarget target) throws CoreException {
|
||||
targets.put(getTargetId(target), target);
|
||||
for (Listener listener : listeners) {
|
||||
try {
|
||||
listener.launchTargetsChanged();
|
||||
} catch (Exception e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
if (activeLaunchDesc != null && activeLaunchTarget == null && supportsTargetType(activeLaunchDesc, target)) {
|
||||
setActiveLaunchTarget(target);
|
||||
}
|
||||
private IRemoteConnection getDefaultLaunchTarget(ILaunchDescriptor descriptor) throws CoreException {
|
||||
List<IRemoteConnection> targets = getLaunchTargets(descriptor);
|
||||
return targets.isEmpty() ? null : targets.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launchTargetRemoved(ILaunchTarget target) throws CoreException {
|
||||
targets.remove(getTargetId(target));
|
||||
for (Listener listener : listeners) {
|
||||
try {
|
||||
listener.launchTargetsChanged();
|
||||
} catch (Exception e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
if (activeLaunchTarget == target) {
|
||||
setActiveLaunchTarget(getDefaultLaunchTarget(activeLaunchDesc));
|
||||
}
|
||||
}
|
||||
|
||||
private ILaunchTarget getDefaultLaunchTarget(ILaunchDescriptor descriptor) throws CoreException {
|
||||
ILaunchTarget[] targets = getLaunchTargets(descriptor);
|
||||
if (targets.length > 0) {
|
||||
return targets[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ILaunchTarget getLaunchTarget(Pair<String, String> targetId) {
|
||||
if (targetId == null)
|
||||
return null;
|
||||
return targets.get(targetId);
|
||||
}
|
||||
|
||||
public ILaunchTargetType[] getAllLaunchTargetTypes() {
|
||||
return targetTypes.values().toArray(new ILaunchTargetType[targetTypes.values().size()]);
|
||||
}
|
||||
|
||||
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException {
|
||||
if (descriptor == null)
|
||||
return null;
|
||||
|
||||
String descriptorTypeId = getDescriptorTypeId(descriptor.getType());
|
||||
|
||||
String targetTypeId = null;
|
||||
if (target != null) {
|
||||
targetTypeId = getTargetTypeId(target.getType());
|
||||
} else {
|
||||
targetTypeId = defaultTargetTypes.get(getDescriptorTypeId(descriptor.getType()));
|
||||
}
|
||||
|
||||
if (targetTypeId != null) {
|
||||
Map<String, LaunchConfigTypeInfo> targetMap = configTypes.get(descriptorTypeId);
|
||||
if (targetMap != null) {
|
||||
LaunchConfigTypeInfo typeInfo = targetMap.get(targetTypeId);
|
||||
return getLaunchManager().getLaunchConfigurationType(typeInfo.getLaunchConfigTypeId());
|
||||
}
|
||||
}
|
||||
|
||||
ILaunchConfiguration config = (ILaunchConfiguration) descriptor.getAdapter(ILaunchConfiguration.class);
|
||||
if (config != null)
|
||||
return config.getType();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean supportsTargetType(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException {
|
||||
private boolean supportsTargetType(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
||||
return getConfigProvider(descriptor, target) != null;
|
||||
}
|
||||
|
||||
public ILaunchConfiguration getActiveLaunchConfiguration() throws CoreException {
|
||||
return getLaunchConfiguration(activeLaunchDesc, activeLaunchTarget);
|
||||
ILaunchConfiguration activeConfig = getLaunchConfiguration(activeLaunchDesc, activeLaunchTarget);
|
||||
if (activeConfig != null) {
|
||||
// Save the config -> target mapping
|
||||
remoteLaunchConfigService.setActiveConnection(activeConfig, activeLaunchTarget);
|
||||
}
|
||||
return activeConfig;
|
||||
}
|
||||
|
||||
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException {
|
||||
// Don't call this to get the active launch config. Use getActiveLaunchConfiguration(). It ensures that config -> target
|
||||
// mapping is saved.
|
||||
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
||||
if (descriptor == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -1119,4 +937,51 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionChanged(RemoteConnectionChangeEvent event) {
|
||||
switch (event.getType()) {
|
||||
case RemoteConnectionChangeEvent.CONNECTION_ADDED:
|
||||
try {
|
||||
launchTargetAdded(event.getConnection());
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
break;
|
||||
|
||||
case RemoteConnectionChangeEvent.CONNECTION_REMOVED:
|
||||
case RemoteConnectionChangeEvent.CONNECTION_RENAMED:
|
||||
try {
|
||||
launchTargetRemoved(event.getConnection());
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void launchTargetAdded(IRemoteConnection target) throws CoreException {
|
||||
for (Listener listener : listeners) {
|
||||
try {
|
||||
listener.launchTargetsChanged();
|
||||
} catch (Exception e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
if (activeLaunchDesc != null && activeLaunchTarget == null && supportsTargetType(activeLaunchDesc, target)) {
|
||||
setActiveLaunchTarget(target);
|
||||
}
|
||||
}
|
||||
|
||||
private void launchTargetRemoved(IRemoteConnection target) throws CoreException {
|
||||
for (Listener listener : listeners) {
|
||||
try {
|
||||
listener.launchTargetsChanged();
|
||||
} catch (Exception e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
if (activeLaunchTarget == target) {
|
||||
setActiveLaunchTarget(getDefaultLaunchTarget(activeLaunchDesc));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package org.eclipse.launchbar.core.internal;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.launchbar.core.ILaunchConfigurationProvider;
|
||||
|
||||
public class LaunchConfigProviderInfo {
|
||||
private final String launchConfigTypeId;
|
||||
private IConfigurationElement element;
|
||||
private ILaunchConfigurationProvider provider;
|
||||
|
||||
public LaunchConfigProviderInfo(IConfigurationElement element) {
|
||||
this.launchConfigTypeId = element.getAttribute("launchConfigurationType");
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
public String getLaunchConfigTypeId() {
|
||||
return launchConfigTypeId;
|
||||
}
|
||||
|
||||
public ILaunchConfigurationProvider getProvider() throws CoreException {
|
||||
if (provider == null) {
|
||||
provider = (ILaunchConfigurationProvider) element.createExecutableExtension("class");
|
||||
element = null;
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package org.eclipse.launchbar.core.internal;
|
||||
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
|
||||
public class LaunchConfigTypeInfo {
|
||||
private final String descriptorTypeId;
|
||||
private final String targetTypeId;
|
||||
private final String launchConfigTypeId;
|
||||
|
||||
public LaunchConfigTypeInfo(IConfigurationElement element) {
|
||||
this.descriptorTypeId = element.getAttribute("descriptorType");
|
||||
this.targetTypeId = element.getAttribute("targetType");
|
||||
this.launchConfigTypeId = element.getAttribute("launchConfigurationType");
|
||||
}
|
||||
|
||||
public String getDescriptorTypeId() {
|
||||
return descriptorTypeId;
|
||||
}
|
||||
|
||||
public String getTargetTypeId() {
|
||||
return targetTypeId;
|
||||
}
|
||||
|
||||
public String getLaunchConfigTypeId() {
|
||||
return launchConfigTypeId;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package org.eclipse.launchbar.core.internal;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptorType;
|
||||
|
||||
public class LaunchDescriptorTypeInfo {
|
||||
private final String id;
|
||||
private int priority;
|
||||
private IConfigurationElement element;
|
||||
private ILaunchDescriptorType type;
|
||||
|
||||
public LaunchDescriptorTypeInfo(IConfigurationElement element) {
|
||||
this.id = element.getAttribute("id");
|
||||
String priorityStr = element.getAttribute("priority");
|
||||
this.priority = 1;
|
||||
if (priorityStr != null) {
|
||||
try {
|
||||
priority = Integer.parseInt(priorityStr);
|
||||
} catch (NumberFormatException e) {
|
||||
// Log it but keep going with the default
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
// Used for testing
|
||||
public LaunchDescriptorTypeInfo(String id, int priority, ILaunchDescriptorType type) {
|
||||
this.id = id;
|
||||
this.priority = priority;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
public ILaunchDescriptorType getType() throws CoreException {
|
||||
if (type == null) {
|
||||
type = (ILaunchDescriptorType) element.createExecutableExtension("class");
|
||||
element = null;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package org.eclipse.launchbar.core.internal;
|
||||
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
|
||||
class LaunchTargetTypeInfo {
|
||||
public static final String SEP = "|";
|
||||
private final String id;
|
||||
private final String connectionTypeId;
|
||||
private String osname;
|
||||
private String osarch;
|
||||
|
||||
public LaunchTargetTypeInfo(IConfigurationElement ce) {
|
||||
id = ce.getAttribute("id");
|
||||
connectionTypeId = ce.getAttribute("connectionTypeId");
|
||||
osname = ce.getAttribute("osname");
|
||||
if (osname != null && osname.isEmpty()) {
|
||||
osname = null;
|
||||
}
|
||||
osarch = ce.getAttribute("osarch");
|
||||
if (osarch != null && osarch.isEmpty()) {
|
||||
osarch = null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getRemoteServicesId() {
|
||||
return connectionTypeId;
|
||||
}
|
||||
|
||||
public String getOsName() {
|
||||
return osname;
|
||||
}
|
||||
|
||||
public String getOsArch() {
|
||||
return osarch;
|
||||
}
|
||||
|
||||
public boolean matches(IRemoteConnection connection) {
|
||||
if (!connectionTypeId.equals(connection.getConnectionType().getId())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (osname != null && !osname.equals(connection.getProperty(IRemoteConnection.OS_NAME_PROPERTY))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (osarch != null && !osarch.equals(connection.getProperty(IRemoteConnection.OS_ARCH_PROPERTY))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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.launchbar.core.internal;
|
||||
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
import org.eclipse.launchbar.core.ILaunchTarget;
|
||||
import org.eclipse.launchbar.core.ILaunchTargetType;
|
||||
|
||||
/**
|
||||
* The launch target representing the machine we're running on.
|
||||
*/
|
||||
public class LocalTarget extends PlatformObject implements ILaunchTarget {
|
||||
|
||||
private final LocalTargetType type;
|
||||
|
||||
public LocalTarget(LocalTargetType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return Messages.LocalTarget_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchTargetType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active) {
|
||||
// nothing to do, we have no active state
|
||||
}
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package org.eclipse.launchbar.core.internal;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.launchbar.core.ILaunchBarManager;
|
||||
import org.eclipse.launchbar.core.ILaunchTargetType;
|
||||
|
||||
/**
|
||||
* The target type that creates the local target.
|
||||
*/
|
||||
public class LocalTargetType implements ILaunchTargetType {
|
||||
|
||||
public static final String ID = Activator.PLUGIN_ID + ".targetType.local";
|
||||
|
||||
@Override
|
||||
public void init(ILaunchBarManager manager) throws CoreException {
|
||||
// create the local target
|
||||
manager.launchTargetAdded(new LocalTarget(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
}
|
|
@ -17,7 +17,9 @@ Require-Bundle: org.eclipse.ui,
|
|||
org.eclipse.ui.workbench,
|
||||
org.eclipse.ui.ide,
|
||||
org.eclipse.swt,
|
||||
org.eclipse.ui.navigator
|
||||
org.eclipse.ui.navigator,
|
||||
org.eclipse.remote.core;bundle-version="2.0.0",
|
||||
org.eclipse.remote.ui;bundle-version="1.1.0"
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-Localization: plugin
|
||||
|
|
|
@ -62,24 +62,6 @@
|
|||
descriptorTypeId="org.eclipse.launchbar.core.descriptor.default"
|
||||
labelProvider="org.eclipse.launchbar.ui.internal.DefaultDescriptorLabelProvider">
|
||||
</descriptorUI>
|
||||
<targetUI
|
||||
labelProvider="org.eclipse.launchbar.ui.internal.LocalTargetLabelProvider"
|
||||
targetTypeId="org.eclipse.launchbar.core.target.local"
|
||||
name="Local Target">
|
||||
</targetUI>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.propertyPages">
|
||||
<page
|
||||
class="org.eclipse.launchbar.ui.internal.targetsView.TargetPropertyPage"
|
||||
id="org.eclipse.launchbar.ui.infoPropertyPage"
|
||||
name="About">
|
||||
<enabledWhen>
|
||||
<instanceof
|
||||
value="org.eclipse.launchbar.core.ILaunchTarget">
|
||||
</instanceof>
|
||||
</enabledWhen>
|
||||
</page>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
<complexType>
|
||||
<sequence minOccurs="0" maxOccurs="unbounded">
|
||||
<element ref="descriptorUI"/>
|
||||
<element ref="targetUI"/>
|
||||
</sequence>
|
||||
<attribute name="point" type="string" use="required">
|
||||
<annotation>
|
||||
|
@ -73,81 +72,6 @@
|
|||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="targetUI">
|
||||
<complexType>
|
||||
<attribute name="targetTypeId" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute kind="identifier" basedOn="org.eclipse.launchbar.core.launchBarContributions/targetType/@id"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="name" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
Used for identifying this launch target type in various UI elements.
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute translatable="true"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="icon" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
Used for identifying this launch target type in various UI elements.
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute kind="resource"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="labelProvider" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute kind="java" basedOn=":org.eclipse.jface.viewers.ILabelProvider"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="hoverProvider" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute kind="java" basedOn=":org.eclipse.launchbar.ui.IHoverProvider"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="editCommandId" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute kind="identifier" basedOn="org.eclipse.ui.commands/command/@id"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="newWizard" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
An INewWizard that creates a target of this type.
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute kind="java" basedOn=":org.eclipse.ui.INewWizard"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.section type="since"/>
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.eclipse.core.runtime.OperationCanceledException;
|
|||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.resource.ImageRegistry;
|
||||
import org.eclipse.launchbar.core.ILaunchBarManager;
|
||||
import org.eclipse.launchbar.core.internal.LaunchBarManager;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
|
@ -92,7 +93,7 @@ public class Activator extends AbstractUIPlugin {
|
|||
|
||||
public LaunchBarUIManager getLaunchBarUIManager() {
|
||||
if (launchBarUIManager == null) {
|
||||
LaunchBarManager manager = org.eclipse.launchbar.core.internal.Activator.getDefault().getLaunchBarManager();
|
||||
LaunchBarManager manager = (LaunchBarManager) getService(ILaunchBarManager.class);
|
||||
launchBarUIManager = new LaunchBarUIManager(manager);
|
||||
}
|
||||
return launchBarUIManager;
|
||||
|
|
|
@ -14,7 +14,6 @@ import java.net.MalformedURLException;
|
|||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
|
@ -24,8 +23,6 @@ import org.eclipse.core.runtime.Platform;
|
|||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.viewers.ILabelProvider;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||
import org.eclipse.launchbar.core.ILaunchTarget;
|
||||
import org.eclipse.launchbar.core.ILaunchTargetType;
|
||||
import org.eclipse.launchbar.core.internal.ExecutableExtension;
|
||||
import org.eclipse.launchbar.core.internal.LaunchBarManager;
|
||||
import org.eclipse.launchbar.ui.IHoverProvider;
|
||||
|
@ -87,67 +84,6 @@ public class LaunchBarUIManager {
|
|||
return provider != null ? provider.get() : null;
|
||||
}
|
||||
|
||||
public String getTargetTypeName(ILaunchTarget target) {
|
||||
return getTargetTypeName(target.getType());
|
||||
}
|
||||
|
||||
public String getTargetTypeName(ILaunchTargetType targetType) {
|
||||
String typeId = manager.getTargetTypeId(targetType);
|
||||
String name = targetContributions.get(typeId).name;
|
||||
return name != null ? name : typeId;
|
||||
}
|
||||
|
||||
public Image getTargetTypeIcon(ILaunchTargetType targetType) {
|
||||
String typeId = manager.getTargetTypeId(targetType);
|
||||
return targetContributions.get(typeId).getIcon();
|
||||
}
|
||||
|
||||
public ILabelProvider getLabelProvider(ILaunchTarget target) throws CoreException {
|
||||
ExecutableExtension<ILabelProvider> provider = getContribution(target).labelProvider;
|
||||
return provider != null ? provider.get() : null;
|
||||
}
|
||||
|
||||
public IHoverProvider getHoverProvider(ILaunchTarget target) throws CoreException {
|
||||
ExecutableExtension<IHoverProvider> hoverProvider = getContribution(target).hoverProvider;
|
||||
return hoverProvider != null ? hoverProvider.get() : null;
|
||||
}
|
||||
|
||||
public String getEditCommand(ILaunchTarget target) {
|
||||
return getContribution(target).editCommandId;
|
||||
}
|
||||
|
||||
public Map<ILaunchTargetType, ExecutableExtension<INewWizard>> getNewTargetWizards() {
|
||||
Map<ILaunchTargetType, ExecutableExtension<INewWizard>> wizards = new HashMap<>();
|
||||
for (Entry<String, LaunchBarTargetContribution> contrib : targetContributions.entrySet()) {
|
||||
if (contrib.getValue().newWizard != null) {
|
||||
ILaunchTargetType type = manager.getLaunchTargetType(contrib.getKey());
|
||||
if (type != null) {
|
||||
wizards.put(type, contrib.getValue().newWizard);
|
||||
}
|
||||
}
|
||||
}
|
||||
return wizards;
|
||||
}
|
||||
|
||||
public Map<String, Image> getTargetIcons() {
|
||||
Map<String, Image> icons = new HashMap<>();
|
||||
for (LaunchBarTargetContribution contribution : targetContributions.values()) {
|
||||
Image icon = contribution.getIcon();
|
||||
if (icon != null) {
|
||||
icons.put(contribution.name, icon);
|
||||
}
|
||||
}
|
||||
return icons;
|
||||
}
|
||||
|
||||
private LaunchBarTargetContribution getContribution(ILaunchTarget target) {
|
||||
LaunchBarTargetContribution c = targetContributions.get(manager.getTargetTypeId(target.getType()));
|
||||
if (c == null) {
|
||||
return DEFAULT_CONTRIBUTION;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
private class LaunchBarTargetContribution {
|
||||
String name;
|
||||
String iconStr;
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
package org.eclipse.launchbar.ui.internal;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.launchbar.core.ILaunchTarget;
|
||||
|
||||
|
||||
public class LocalTargetLabelProvider extends LabelProvider {
|
||||
|
||||
@Override
|
||||
public String getText(Object element) {
|
||||
if (element instanceof ILaunchTarget) {
|
||||
return ((ILaunchTarget) element).getName();
|
||||
}
|
||||
return super.getText(element);
|
||||
}
|
||||
|
||||
}
|
|
@ -22,8 +22,6 @@ import org.eclipse.debug.internal.ui.DebugUIPlugin;
|
|||
import org.eclipse.debug.ui.DebugUITools;
|
||||
import org.eclipse.debug.ui.ILaunchGroup;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||
import org.eclipse.launchbar.core.ILaunchTarget;
|
||||
import org.eclipse.launchbar.core.internal.LaunchBarManager;
|
||||
import org.eclipse.launchbar.ui.internal.Activator;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
@ -34,9 +32,7 @@ public class ConfigureActiveLaunchHandler extends AbstractHandler {
|
|||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
try {
|
||||
LaunchBarManager launchBarManager = Activator.getDefault().getLaunchBarUIManager().getManager();
|
||||
ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor();
|
||||
ILaunchTarget target = launchBarManager.getActiveLaunchTarget();
|
||||
ILaunchConfiguration launchConfiguration = launchBarManager.getLaunchConfiguration(desc, target);
|
||||
ILaunchConfiguration launchConfiguration = launchBarManager.getActiveLaunchConfiguration();
|
||||
if (launchConfiguration == null)
|
||||
return Status.OK_STATUS;
|
||||
ILaunchConfigurationWorkingCopy wc = launchConfiguration.getWorkingCopy();
|
||||
|
|
|
@ -20,8 +20,6 @@ import org.eclipse.core.runtime.Status;
|
|||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
import org.eclipse.debug.core.ILaunchMode;
|
||||
import org.eclipse.debug.ui.DebugUITools;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||
import org.eclipse.launchbar.core.ILaunchTarget;
|
||||
import org.eclipse.launchbar.core.internal.LaunchBarManager;
|
||||
import org.eclipse.launchbar.ui.internal.Activator;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
@ -35,9 +33,7 @@ public class LaunchActiveCommandHandler extends AbstractHandler {
|
|||
public IStatus runInUIThread(IProgressMonitor monitor) {
|
||||
try {
|
||||
LaunchBarManager launchBarManager = Activator.getDefault().getLaunchBarUIManager().getManager();
|
||||
ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor();
|
||||
ILaunchTarget target = launchBarManager.getActiveLaunchTarget();
|
||||
ILaunchConfiguration config = launchBarManager.getLaunchConfiguration(desc, target);
|
||||
ILaunchConfiguration config = launchBarManager.getActiveLaunchConfiguration();
|
||||
if (config == null)
|
||||
return Status.OK_STATUS;
|
||||
ILaunchMode launchMode = launchBarManager.getActiveLaunchMode();
|
||||
|
|
|
@ -32,13 +32,13 @@ import org.eclipse.jface.viewers.Viewer;
|
|||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.jface.wizard.WizardDialog;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||
import org.eclipse.launchbar.core.ILaunchTarget;
|
||||
import org.eclipse.launchbar.core.internal.LaunchBarManager;
|
||||
import org.eclipse.launchbar.ui.internal.Activator;
|
||||
import org.eclipse.launchbar.ui.internal.DefaultDescriptorLabelProvider;
|
||||
import org.eclipse.launchbar.ui.internal.LaunchBarUIManager;
|
||||
import org.eclipse.launchbar.ui.internal.dialogs.LaunchConfigurationEditDialog;
|
||||
import org.eclipse.launchbar.ui.internal.dialogs.NewLaunchConfigWizard;
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.MouseAdapter;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
|
@ -169,7 +169,7 @@ public class ConfigSelector extends CSelector {
|
|||
LaunchBarManager manager = uiManager.getManager();
|
||||
ILaunchDescriptor desc = (ILaunchDescriptor) element;
|
||||
ILaunchMode mode = manager.getActiveLaunchMode();
|
||||
ILaunchTarget target = manager.getActiveLaunchTarget();
|
||||
IRemoteConnection target = manager.getActiveLaunchTarget();
|
||||
if (target == null) {
|
||||
MessageDialog.openError(shell, "No Active Target", "You must create a target to edit this launch configuration.");
|
||||
return;
|
||||
|
|
|
@ -15,11 +15,11 @@ import javax.annotation.PreDestroy;
|
|||
|
||||
import org.eclipse.debug.core.ILaunchMode;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||
import org.eclipse.launchbar.core.ILaunchTarget;
|
||||
import org.eclipse.launchbar.core.internal.LaunchBarManager;
|
||||
import org.eclipse.launchbar.core.internal.LaunchBarManager.Listener;
|
||||
import org.eclipse.launchbar.ui.internal.Activator;
|
||||
import org.eclipse.launchbar.ui.internal.Messages;
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.DisposeEvent;
|
||||
import org.eclipse.swt.events.DisposeListener;
|
||||
|
@ -129,7 +129,7 @@ public class LaunchBarControl implements Listener {
|
|||
@Override
|
||||
public void activeLaunchTargetChanged() {
|
||||
if (targetSelector != null) {
|
||||
final ILaunchTarget target = manager.getActiveLaunchTarget();
|
||||
final IRemoteConnection target = manager.getActiveLaunchTarget();
|
||||
targetSelector.setDelayedSelection(target, SELECTION_DELAY);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,19 +11,16 @@
|
|||
package org.eclipse.launchbar.ui.internal.controls;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.viewers.ILabelProvider;
|
||||
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.jface.wizard.WizardDialog;
|
||||
import org.eclipse.launchbar.core.ILaunchTarget;
|
||||
import org.eclipse.launchbar.ui.IHoverProvider;
|
||||
import org.eclipse.launchbar.ui.ILaunchBarUIConstants;
|
||||
import org.eclipse.launchbar.core.internal.LaunchBarManager;
|
||||
import org.eclipse.launchbar.ui.internal.Activator;
|
||||
import org.eclipse.launchbar.ui.internal.LaunchBarUIManager;
|
||||
import org.eclipse.launchbar.ui.internal.dialogs.NewLaunchTargetWizard;
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.MouseAdapter;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
|
@ -60,12 +57,14 @@ public class TargetSelector extends CSelector {
|
|||
|
||||
@Override
|
||||
public Object[] getElements(Object inputElement) {
|
||||
LaunchBarManager manager = uiManager.getManager();
|
||||
try {
|
||||
ILaunchTarget[] targets = uiManager.getManager().getLaunchTargets();
|
||||
if (targets.length > 0)
|
||||
return targets;
|
||||
List<IRemoteConnection> targets;
|
||||
targets = manager.getLaunchTargets(manager.getActiveLaunchDescriptor());
|
||||
if (!targets.isEmpty()) {
|
||||
return targets.toArray();
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
}
|
||||
return noTargets;
|
||||
}
|
||||
|
@ -74,32 +73,17 @@ public class TargetSelector extends CSelector {
|
|||
setLabelProvider(new LabelProvider() {
|
||||
@Override
|
||||
public Image getImage(Object element) {
|
||||
if (element instanceof ILaunchTarget) {
|
||||
try {
|
||||
ILaunchTarget target = (ILaunchTarget) element;
|
||||
ILabelProvider labelProvider = uiManager.getLabelProvider(target);
|
||||
if (labelProvider != null) {
|
||||
return labelProvider.getImage(element);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
}
|
||||
if (element instanceof IRemoteConnection) {
|
||||
IRemoteConnection target = (IRemoteConnection) element;
|
||||
// TODO need to get icon form ui service
|
||||
}
|
||||
return super.getImage(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Object element) {
|
||||
if (element instanceof ILaunchTarget) {
|
||||
ILaunchTarget target = (ILaunchTarget) element;
|
||||
try {
|
||||
ILabelProvider labelProvider = uiManager.getLabelProvider(target);
|
||||
if (labelProvider != null) {
|
||||
return labelProvider.getText(element);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
}
|
||||
if (element instanceof IRemoteConnection) {
|
||||
IRemoteConnection target = (IRemoteConnection) element;
|
||||
return target.getName();
|
||||
}
|
||||
return super.getText(element);
|
||||
|
@ -113,62 +97,22 @@ public class TargetSelector extends CSelector {
|
|||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
setHoverProvider(new IHoverProvider() {
|
||||
@Override
|
||||
public boolean displayHover(Object element) {
|
||||
if (element instanceof ILaunchTarget) {
|
||||
try {
|
||||
ILaunchTarget target = (ILaunchTarget) element;
|
||||
IHoverProvider hoverProvider = uiManager.getHoverProvider(target);
|
||||
if (hoverProvider != null) {
|
||||
return hoverProvider.displayHover(element);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismissHover(Object element, boolean immediate) {
|
||||
if (element instanceof ILaunchTarget) {
|
||||
try {
|
||||
ILaunchTarget target = (ILaunchTarget) element;
|
||||
IHoverProvider hoverProvider = uiManager.getHoverProvider(target);
|
||||
if (hoverProvider != null) {
|
||||
hoverProvider.dismissHover(element, immediate);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable(Object element) {
|
||||
if (element instanceof ILaunchTarget) {
|
||||
ILaunchTarget target = (ILaunchTarget) element;
|
||||
return uiManager.getEditCommand(target) != null;
|
||||
}
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEdit(Object element) {
|
||||
if (element instanceof ILaunchTarget) {
|
||||
ILaunchTarget target = (ILaunchTarget) element;
|
||||
String commandId = uiManager.getEditCommand(target);
|
||||
Activator.runCommand(commandId, ILaunchBarUIConstants.TARGET_NAME, target.getName());
|
||||
}
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasActionArea() {
|
||||
return !uiManager.getNewTargetWizards().isEmpty();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -202,9 +146,10 @@ public class TargetSelector extends CSelector {
|
|||
|
||||
MouseListener mouseListener = new MouseAdapter() {
|
||||
public void mouseUp(org.eclipse.swt.events.MouseEvent e) {
|
||||
NewLaunchTargetWizard wizard = new NewLaunchTargetWizard(uiManager);
|
||||
WizardDialog dialog = new WizardDialog(getShell(), wizard);
|
||||
dialog.open();
|
||||
// TODO
|
||||
// NewLaunchTargetWizard wizard = new NewLaunchTargetWizard(uiManager);
|
||||
// WizardDialog dialog = new WizardDialog(getShell(), wizard);
|
||||
// dialog.open();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -230,8 +175,8 @@ public class TargetSelector extends CSelector {
|
|||
@Override
|
||||
protected void fireSelectionChanged() {
|
||||
Object selection = getSelection();
|
||||
if (selection instanceof ILaunchTarget) {
|
||||
ILaunchTarget target = (ILaunchTarget) selection;
|
||||
if (selection instanceof IRemoteConnection) {
|
||||
IRemoteConnection target = (IRemoteConnection) selection;
|
||||
try {
|
||||
uiManager.getManager().setActiveLaunchTarget(target);
|
||||
} catch (CoreException e) {
|
||||
|
|
|
@ -1,92 +0,0 @@
|
|||
package org.eclipse.launchbar.ui.internal.dialogs;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.wizard.IWizardPage;
|
||||
import org.eclipse.jface.wizard.WizardPage;
|
||||
import org.eclipse.launchbar.core.ILaunchTargetType;
|
||||
import org.eclipse.launchbar.core.internal.Activator;
|
||||
import org.eclipse.launchbar.core.internal.ExecutableExtension;
|
||||
import org.eclipse.launchbar.ui.internal.LaunchBarUIManager;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.swt.widgets.TableItem;
|
||||
import org.eclipse.ui.INewWizard;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
public class NewLaunchTargetTypePage extends WizardPage {
|
||||
|
||||
private final LaunchBarUIManager uiManager;
|
||||
private Table table;
|
||||
private ExecutableExtension<INewWizard> currentExtension;
|
||||
private INewWizard nextWizard;
|
||||
|
||||
public NewLaunchTargetTypePage(LaunchBarUIManager uiManager) {
|
||||
super("NewLaunchTargetTypePage");
|
||||
setTitle("Launch Target Type");
|
||||
setDescription("Select type of launch target to create.");
|
||||
this.uiManager = uiManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createControl(Composite parent) {
|
||||
Composite comp = new Composite(parent, SWT.NONE);
|
||||
comp.setLayout(new GridLayout());
|
||||
|
||||
table = new Table(comp, SWT.SINGLE | SWT.BORDER);
|
||||
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
|
||||
table.setLayoutData(data);
|
||||
|
||||
setPageComplete(false);
|
||||
for (Entry<ILaunchTargetType, ExecutableExtension<INewWizard>> entry : uiManager.getNewTargetWizards().entrySet()) {
|
||||
TableItem item = new TableItem(table, SWT.NONE);
|
||||
ILaunchTargetType targetType = entry.getKey();
|
||||
item.setText(uiManager.getTargetTypeName(targetType));
|
||||
Image icon = uiManager.getTargetTypeIcon(targetType);
|
||||
if (icon != null) {
|
||||
item.setImage(icon);
|
||||
}
|
||||
item.setData(entry.getValue());
|
||||
table.select(0);
|
||||
setPageComplete(true);
|
||||
}
|
||||
|
||||
setControl(comp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFlipToNextPage() {
|
||||
return isPageComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWizardPage getNextPage() {
|
||||
@SuppressWarnings("unchecked")
|
||||
ExecutableExtension<INewWizard> extension = (ExecutableExtension<INewWizard>) table.getSelection()[0].getData();
|
||||
if (extension != currentExtension) {
|
||||
try {
|
||||
nextWizard = extension.create();
|
||||
nextWizard.init(PlatformUI.getWorkbench(), null);
|
||||
nextWizard.addPages();
|
||||
currentExtension = extension;
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
if (nextWizard != null) {
|
||||
IWizardPage [] pages = nextWizard.getPages();
|
||||
if (pages.length > 0) {
|
||||
return pages[0];
|
||||
}
|
||||
}
|
||||
|
||||
return super.getNextPage();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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.launchbar.ui.internal.dialogs;
|
||||
|
||||
import org.eclipse.jface.wizard.Wizard;
|
||||
import org.eclipse.launchbar.ui.internal.LaunchBarUIManager;
|
||||
|
||||
public class NewLaunchTargetWizard extends Wizard {
|
||||
|
||||
private final NewLaunchTargetTypePage typePage;
|
||||
|
||||
public NewLaunchTargetWizard(LaunchBarUIManager uiManager) {
|
||||
setWindowTitle("Launch Target Type");
|
||||
typePage = new NewLaunchTargetTypePage(uiManager);
|
||||
setForcePreviousAndNextButtons(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPages() {
|
||||
addPage(typePage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performFinish() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFinish() {
|
||||
// Need to move onto the new target wizard
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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.launchbar.ui.internal.targetsView;
|
||||
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.window.SameShellProvider;
|
||||
import org.eclipse.ui.dialogs.PropertyDialogAction;
|
||||
import org.eclipse.ui.navigator.CommonActionProvider;
|
||||
|
||||
public class LaunchTargetsActionProvider extends CommonActionProvider {
|
||||
|
||||
@Override
|
||||
public void fillContextMenu(IMenuManager menu) {
|
||||
menu.add(new PropertyDialogAction(new SameShellProvider(getActionSite().getViewSite().getShell()),
|
||||
getActionSite().getStructuredViewer()));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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.launchbar.ui.internal.targetsView;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.launchbar.core.ILaunchTarget;
|
||||
import org.eclipse.launchbar.core.internal.LaunchBarManager;
|
||||
|
||||
public class LaunchTargetsContentProvider implements ITreeContentProvider {
|
||||
|
||||
private LaunchBarManager manager;
|
||||
|
||||
@Override
|
||||
public Object[] getElements(Object inputElement) {
|
||||
if (inputElement instanceof LaunchBarManager) {
|
||||
ILaunchTarget[] targets = ((LaunchBarManager) inputElement).getAllLaunchTargets();
|
||||
Arrays.sort(targets, new Comparator<ILaunchTarget>() {
|
||||
@Override
|
||||
public int compare(ILaunchTarget o1, ILaunchTarget o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
});
|
||||
return targets;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getChildren(Object parentElement) {
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParent(Object element) {
|
||||
if (element instanceof ILaunchTarget) {
|
||||
return manager;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChildren(Object element) {
|
||||
if (element instanceof LaunchBarManager)
|
||||
return true;
|
||||
else if (element instanceof ILaunchTarget)
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
if (newInput instanceof LaunchBarManager) {
|
||||
manager = (LaunchBarManager) newInput;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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.launchbar.ui.internal.targetsView;
|
||||
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.launchbar.core.ILaunchTarget;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
public class LaunchTargetsLabelProvider extends LabelProvider {
|
||||
|
||||
@Override
|
||||
public Image getImage(Object element) {
|
||||
return super.getImage(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Object element) {
|
||||
if (element instanceof ILaunchTarget) {
|
||||
return ((ILaunchTarget) element).getName();
|
||||
}
|
||||
return super.getText(element);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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.launchbar.ui.internal.targetsView;
|
||||
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||
import org.eclipse.launchbar.core.internal.LaunchBarManager;
|
||||
import org.eclipse.launchbar.ui.internal.Activator;
|
||||
import org.eclipse.launchbar.ui.internal.LaunchBarUIManager;
|
||||
import org.eclipse.ui.navigator.CommonNavigator;
|
||||
|
||||
public class LaunchTargetsNavigator extends CommonNavigator {
|
||||
|
||||
private final LaunchBarUIManager uiManager = Activator.getDefault().getLaunchBarUIManager();
|
||||
|
||||
public LaunchTargetsNavigator() {
|
||||
uiManager.getManager().addListener(new LaunchBarManager.Listener() {
|
||||
@Override
|
||||
public void launchTargetsChanged() {
|
||||
getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getCommonViewer().refresh();
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public void launchDescriptorRemoved(ILaunchDescriptor descriptor) {
|
||||
}
|
||||
@Override
|
||||
public void activeLaunchTargetChanged() {
|
||||
}
|
||||
@Override
|
||||
public void activeLaunchModeChanged() {
|
||||
}
|
||||
@Override
|
||||
public void activeLaunchDescriptorChanged() {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getInitialInput() {
|
||||
return uiManager.getManager();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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.launchbar.ui.internal.targetsView;
|
||||
|
||||
import org.eclipse.launchbar.core.ILaunchTarget;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.eclipse.ui.dialogs.PropertyPage;
|
||||
|
||||
public class TargetPropertyPage extends PropertyPage {
|
||||
|
||||
private Text nameText;
|
||||
|
||||
@Override
|
||||
protected Control createContents(Composite parent) {
|
||||
Composite comp = new Composite(parent, SWT.NONE);
|
||||
GridLayout layout = new GridLayout(2, false);
|
||||
comp.setLayout(layout);
|
||||
|
||||
ILaunchTarget target = (ILaunchTarget) getElement().getAdapter(ILaunchTarget.class);
|
||||
|
||||
Label nameLabel = new Label(comp, SWT.NONE);
|
||||
nameLabel.setText("Target Name:");
|
||||
|
||||
nameText = new Text(comp, SWT.BORDER);
|
||||
nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
nameText.setText(target.getName());
|
||||
|
||||
return comp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performOk() {
|
||||
System.out.println("Would change name to " + nameText.getText());
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
16
pom.xml
16
pom.xml
|
@ -40,7 +40,12 @@
|
|||
<repositories>
|
||||
<repository>
|
||||
<id>eclipse</id>
|
||||
<url>http://download.eclipse.org/releases/luna/</url>
|
||||
<url>http://download.eclipse.org/releases/mars/</url>
|
||||
<layout>p2</layout>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>platform</id>
|
||||
<url>http://download.eclipse.org/eclipse/updates/4.5milestones</url>
|
||||
<layout>p2</layout>
|
||||
</repository>
|
||||
<repository>
|
||||
|
@ -50,7 +55,12 @@
|
|||
</repository>
|
||||
<repository>
|
||||
<id>orbit</id>
|
||||
<url>http://download.eclipse.org/tools/orbit/downloads/drops/S20141129202728/repository/</url>
|
||||
<url>http://download.eclipse.org/tools/orbit/downloads/drops/R20150124073747/repository/</url>
|
||||
<layout>p2</layout>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>remote</id>
|
||||
<url>http://download.eclipse.org/tools/ptp/builds/remote/2.0.0</url>
|
||||
<layout>p2</layout>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
@ -59,7 +69,7 @@
|
|||
<module>bundles/org.eclipse.launchbar.core</module>
|
||||
<module>bundles/org.eclipse.launchbar.ui</module>
|
||||
<module>features/org.eclipse.launchbar</module>
|
||||
<module>tests/org.eclipse.launchbar.core.tests</module>
|
||||
<!-- module>tests/org.eclipse.launchbar.core.tests</module-->
|
||||
<module>repo</module>
|
||||
</modules>
|
||||
|
||||
|
|
|
@ -3,12 +3,7 @@ Bundle-ManifestVersion: 2
|
|||
Bundle-Name: Launch Bar Core Tests
|
||||
Bundle-SymbolicName: org.eclipse.launchbar.core.tests
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Activator: org.eclipse.launchbar.core.tests.Activator
|
||||
Require-Bundle: org.eclipse.core.runtime,
|
||||
org.junit;bundle-version="4.11.0",
|
||||
org.mockito,
|
||||
org.eclipse.launchbar.core;bundle-version="1.0.0",
|
||||
org.eclipse.debug.core
|
||||
Fragment-Host: org.eclipse.launchbar.core;bundle-version="1.0.0"
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Export-Package: org.eclipse.launchbar.core.tests
|
||||
Require-Bundle: org.junit;bundle-version="4.11.0",
|
||||
org.mockito;bundle-version="1.9.5"
|
||||
|
|
|
@ -1,829 +1,185 @@
|
|||
/*******************************************************************************
|
||||
> * 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.launchbar.core.internal;
|
||||
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.core.internal.preferences.EclipsePreferences;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IExtension;
|
||||
import org.eclipse.core.runtime.IExtensionPoint;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
||||
import org.eclipse.debug.core.ILaunchManager;
|
||||
import org.eclipse.debug.core.ILaunchMode;
|
||||
import org.eclipse.launchbar.core.ILaunchBarManager;
|
||||
import org.eclipse.launchbar.core.ILaunchConfigurationProvider;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptorType;
|
||||
import org.eclipse.launchbar.core.ILaunchObjectProvider;
|
||||
import org.eclipse.launchbar.core.ILaunchTarget;
|
||||
import org.eclipse.launchbar.core.ILaunchTargetType;
|
||||
import org.eclipse.launchbar.core.LaunchConfigurationProvider;
|
||||
import org.eclipse.launchbar.core.internal.LaunchBarManager;
|
||||
import org.eclipse.launchbar.core.internal.LocalTargetType;
|
||||
import org.eclipse.launchbar.core.internal.Pair;
|
||||
import org.eclipse.launchbar.core.internal.LaunchBarManager.Listener;
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
import org.eclipse.remote.core.IRemoteConnectionType;
|
||||
import org.eclipse.remote.core.IRemoteServicesManager;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author elaskavaia
|
||||
*
|
||||
*/
|
||||
public class LaunchBarManagerTest extends TestCase {
|
||||
|
||||
// default type ids
|
||||
private static final String DEFAULT_CONFIG_TYPE_ID = "configType.test";
|
||||
private static final String DEFAULT_TARGET_TYPE_ID = "targetType.test";
|
||||
private static final String DEFAULT_DESCRIPTOR_TYPE_ID = "descriptorType.test";
|
||||
public class LaunchBarManagerTest {
|
||||
|
||||
private IEclipsePreferences prefs;
|
||||
private ILaunchManager launchManager;
|
||||
|
||||
public class TestLaunchBarManager extends LaunchBarManager {
|
||||
private ILaunchMode[] defaultLaunchModes;
|
||||
boolean done;
|
||||
|
||||
public TestLaunchBarManager() throws CoreException {
|
||||
super();
|
||||
// For the tests, need to wait until the init is done
|
||||
synchronized (this) {
|
||||
while (!done) {
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void startupTest() throws Exception {
|
||||
// Make sure the manager starts up and defaults everything to null
|
||||
LaunchBarManager manager = new LaunchBarManager(false);
|
||||
manager.init();
|
||||
assertNull(manager.getActiveLaunchDescriptor());
|
||||
assertNull(manager.getActiveLaunchMode());
|
||||
assertNull(manager.getActiveLaunchTarget());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws CoreException {
|
||||
super.init();
|
||||
synchronized (this) {
|
||||
done = true;
|
||||
notify();
|
||||
}
|
||||
@Test
|
||||
public void defaultTest() throws Exception {
|
||||
// Create a launch config, make sure default mode and local target are active
|
||||
// And that that config is the active config.
|
||||
|
||||
// Mocking
|
||||
ILaunchConfigurationType launchConfigType = mock(ILaunchConfigurationType.class);
|
||||
ILaunchConfiguration launchConfig = mock(ILaunchConfiguration.class);
|
||||
doReturn(launchConfigType).when(launchConfig).getType();
|
||||
doReturn("dummy").when(launchConfigType).getIdentifier();
|
||||
doReturn(true).when(launchConfigType).supportsMode("run");
|
||||
doReturn(true).when(launchConfigType).supportsMode("debug");
|
||||
|
||||
// Inject the launch config
|
||||
LaunchBarManager manager = new LaunchBarManager(false);
|
||||
manager.init();
|
||||
manager.launchConfigurationAdded(launchConfig);
|
||||
|
||||
// Verify state
|
||||
assertNotNull(manager.getActiveLaunchDescriptor());
|
||||
assertEquals(launchConfig, manager.getActiveLaunchDescriptor().getAdapter(ILaunchConfiguration.class));
|
||||
|
||||
IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
|
||||
IRemoteConnectionType localServices = remoteManager.getLocalConnectionType();
|
||||
IRemoteConnection localConnection = localServices.getConnections().get(0);
|
||||
assertNotNull(manager.getActiveLaunchTarget());
|
||||
assertEquals(localConnection, manager.getActiveLaunchTarget());
|
||||
|
||||
assertNotNull(manager.getActiveLaunchMode());
|
||||
assertEquals("run", manager.getActiveLaunchMode().getIdentifier());
|
||||
|
||||
assertEquals(launchConfig, manager.getActiveLaunchConfiguration());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IExtensionPoint getExtensionPoint() throws CoreException {
|
||||
// default things
|
||||
IExtensionPoint point = mock(IExtensionPoint.class);
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void descriptorTest() throws Exception {
|
||||
// Create a descriptor type and inject an associated object
|
||||
// Make sure the descriptor is active with the local target and proper mode
|
||||
// Make sure the associated launch config is active too
|
||||
|
||||
// Mocking
|
||||
final IExtensionPoint extensionPoint = mock(IExtensionPoint.class);
|
||||
IExtension extension = mock(IExtension.class);
|
||||
doReturn(new IExtension[] { extension }).when(point).getExtensions();
|
||||
doReturn(new IExtension[] { extension }).when(extensionPoint).getExtensions();
|
||||
|
||||
List<IConfigurationElement> elements = new ArrayList<>();
|
||||
|
||||
IConfigurationElement element;
|
||||
|
||||
// The local target
|
||||
// local target type
|
||||
element = mock(IConfigurationElement.class);
|
||||
elements.add(element);
|
||||
doReturn("targetType").when(element).getName();
|
||||
doReturn(LocalTargetType.ID).when(element).getAttribute("id");
|
||||
doReturn(new LocalTargetType()).when(element).createExecutableExtension("class");
|
||||
String targetTypeId = "org.eclipse.launchbar.core.targetType.local";
|
||||
doReturn(targetTypeId).when(element).getAttribute("id");
|
||||
doReturn("org.eclipse.remote.LocalServices").when(element).getAttribute("remoteServicesId");
|
||||
|
||||
// Test targets
|
||||
for (TestLaunchTargetType targetType : getTestTargetTypes()) {
|
||||
element = mock(IConfigurationElement.class);
|
||||
elements.add(element);
|
||||
doReturn("targetType").when(element).getName();
|
||||
doReturn(targetType.id).when(element).getAttribute("id");
|
||||
doReturn(targetType).when(element).createExecutableExtension("class");
|
||||
}
|
||||
// fake launch object
|
||||
String launchObject = "fakeObject";
|
||||
|
||||
// Test descriptors
|
||||
for (TestLaunchDescriptorType descType : getTestDescriptorTypes()) {
|
||||
// launch descriptor for that object
|
||||
element = mock(IConfigurationElement.class);
|
||||
elements.add(element);
|
||||
doReturn("descriptorType").when(element).getName();
|
||||
doReturn(descType.id).when(element).getAttribute("id");
|
||||
doReturn(Integer.toString(descType.priority)).when(element).getAttribute("priority");
|
||||
doReturn(descType).when(element).createExecutableExtension("class");
|
||||
}
|
||||
String descriptorTypeId = "fakeDescriptorType";
|
||||
doReturn(descriptorTypeId).when(element).getAttribute("id");
|
||||
ILaunchDescriptorType descriptorType = mock(ILaunchDescriptorType.class);
|
||||
doReturn(descriptorType).when(element).createExecutableExtension("class");
|
||||
doReturn(true).when(descriptorType).ownsLaunchObject(launchObject);
|
||||
ILaunchDescriptor descriptor = mock(ILaunchDescriptor.class);
|
||||
doReturn(descriptor).when(descriptorType).getDescriptor(launchObject);
|
||||
doReturn(descriptorType).when(descriptor).getType();
|
||||
doReturn(launchObject).when(descriptor).getName();
|
||||
|
||||
// Test config types
|
||||
for (TestLaunchConfigurationProvider provider : getTestConfigProviders()) {
|
||||
element = mock(IConfigurationElement.class);
|
||||
elements.add(element);
|
||||
doReturn("configType").when(element).getName();
|
||||
doReturn(provider.descTypeId).when(element).getAttribute("descriptorType");
|
||||
doReturn(provider.targetTypeId).when(element).getAttribute("targetType");
|
||||
doReturn(provider.configType.getIdentifier()).when(element).getAttribute("launchConfigurationType");
|
||||
doReturn(Boolean.toString(provider.isDefault)).when(element).getAttribute("isDefault");
|
||||
// launch config type
|
||||
final ILaunchManager launchManager = mock(ILaunchManager.class);
|
||||
ILaunchMode runMode = mock(ILaunchMode.class);
|
||||
String run = "run";
|
||||
doReturn(run).when(runMode).getIdentifier();
|
||||
doReturn(runMode).when(launchManager).getLaunchMode(run);
|
||||
ILaunchMode debugMode = mock(ILaunchMode.class);
|
||||
String debug = "debug";
|
||||
doReturn(debug).when(debugMode).getIdentifier();
|
||||
doReturn(debugMode).when(launchManager).getLaunchMode(debug);
|
||||
doReturn(new ILaunchMode[] { runMode, debugMode }).when(launchManager).getLaunchModes();
|
||||
ILaunchConfigurationType launchConfigType = mock(ILaunchConfigurationType.class);
|
||||
String launchConfigTypeId = "fakeLaunchConfigType";
|
||||
doReturn(launchConfigTypeId).when(launchConfigType).getIdentifier();
|
||||
doReturn(true).when(launchConfigType).supportsMode(run);
|
||||
doReturn(true).when(launchConfigType).supportsMode(debug);
|
||||
doReturn(launchConfigType).when(launchManager).getLaunchConfigurationType(launchConfigTypeId);
|
||||
// TODO assuming this is only called at init time when there aren't any
|
||||
doReturn(new ILaunchConfiguration[0]).when(launchManager).getLaunchConfigurations();
|
||||
|
||||
// configProvider
|
||||
element = mock(IConfigurationElement.class);
|
||||
elements.add(element);
|
||||
doReturn("configProvider").when(element).getName();
|
||||
doReturn(provider.configType.getIdentifier()).when(element).getAttribute("launchConfigurationType");
|
||||
doReturn(provider).when(element).createExecutableExtension("class");
|
||||
}
|
||||
doReturn(launchConfigTypeId).when(element).getAttribute("launchConfigurationType");
|
||||
ILaunchConfigurationProvider configProvider = mock(ILaunchConfigurationProvider.class);
|
||||
doReturn(configProvider).when(element).createExecutableExtension("class");
|
||||
doReturn(launchConfigType).when(configProvider).getLaunchConfigurationType();
|
||||
ILaunchConfiguration launchConfig = mock(ILaunchConfiguration.class);
|
||||
doReturn(launchConfigType).when(launchConfig).getType();
|
||||
doReturn(launchConfig).when(configProvider).createLaunchConfiguration(launchManager, descriptor);
|
||||
|
||||
// test object providers
|
||||
for (TestLaunchObjectProvider objectProvider : getTestObjectProviders()) {
|
||||
// configType
|
||||
element = mock(IConfigurationElement.class);
|
||||
elements.add(element);
|
||||
doReturn("objectProvider").when(element).getName();
|
||||
doReturn(objectProvider).when(element).createExecutableExtension("class");
|
||||
}
|
||||
doReturn("configType").when(element).getName();
|
||||
doReturn(descriptorTypeId).when(element).getAttribute("descriptorType");
|
||||
doReturn(targetTypeId).when(element).getAttribute("targetType");
|
||||
doReturn(launchConfigTypeId).when(element).getAttribute("launchConfigurationType");
|
||||
|
||||
doReturn(elements.toArray(new IConfigurationElement[0])).when(extension).getConfigurationElements();
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
protected TestLaunchTargetType[] getTestTargetTypes() {
|
||||
return new TestLaunchTargetType[] {
|
||||
new TestLaunchTargetType(DEFAULT_TARGET_TYPE_ID)
|
||||
};
|
||||
}
|
||||
|
||||
protected TestLaunchDescriptorType[] getTestDescriptorTypes() {
|
||||
return new TestLaunchDescriptorType[] {
|
||||
new TestLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID, 5)
|
||||
};
|
||||
}
|
||||
|
||||
protected TestLaunchConfigurationProvider[] getTestConfigProviders() {
|
||||
ILaunchConfigurationType configType = mockLaunchConfigurationType(DEFAULT_CONFIG_TYPE_ID);
|
||||
return new TestLaunchConfigurationProvider[] {
|
||||
new TestLaunchConfigurationProvider(DEFAULT_DESCRIPTOR_TYPE_ID, DEFAULT_TARGET_TYPE_ID, configType, true, this)
|
||||
};
|
||||
}
|
||||
|
||||
protected TestLaunchObjectProvider[] getTestObjectProviders() {
|
||||
return new TestLaunchObjectProvider[0];
|
||||
}
|
||||
|
||||
// Now inject the launch object
|
||||
LaunchBarManager manager = new LaunchBarManager(false) {
|
||||
@Override
|
||||
protected ILaunchManager getLaunchManager() {
|
||||
IExtensionPoint getExtensionPoint() throws CoreException {
|
||||
return extensionPoint;
|
||||
}
|
||||
@Override
|
||||
ILaunchManager getLaunchManager() {
|
||||
return launchManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IEclipsePreferences getPreferenceStore() {
|
||||
return prefs;
|
||||
}
|
||||
};
|
||||
|
||||
public static class TestLaunchTargetType implements ILaunchTargetType {
|
||||
final String id;
|
||||
|
||||
public TestLaunchTargetType(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(ILaunchBarManager manager) throws CoreException {
|
||||
// override if you want to add targets
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestLaunchTarget extends PlatformObject implements ILaunchTarget {
|
||||
private ILaunchTargetType type;
|
||||
private String name;
|
||||
|
||||
public TestLaunchTarget(String name, ILaunchTargetType type) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public ILaunchTargetType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestLaunchObject {
|
||||
final String name;
|
||||
final ILaunchDescriptorType descType;
|
||||
|
||||
public TestLaunchObject(String name, ILaunchDescriptorType descType) {
|
||||
this.name = name;
|
||||
this.descType = descType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof TestLaunchObject) {
|
||||
return name.equals(((TestLaunchObject) obj).name);
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestLaunchDescriptor extends PlatformObject implements ILaunchDescriptor {
|
||||
private final TestLaunchObject object;
|
||||
private final TestLaunchDescriptorType type;
|
||||
|
||||
public TestLaunchDescriptor(TestLaunchDescriptorType type, TestLaunchObject object) {
|
||||
this.object = object;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
|
||||
if (TestLaunchObject.class.equals(adapter)) {
|
||||
return object;
|
||||
}
|
||||
return super.getAdapter(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return object.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchDescriptorType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestLaunchDescriptorType implements ILaunchDescriptorType {
|
||||
final String id;
|
||||
final int priority;
|
||||
|
||||
public TestLaunchDescriptorType(String id, int priority) {
|
||||
this.id = id;
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ownsLaunchObject(Object launchObject) throws CoreException {
|
||||
if (!(launchObject instanceof TestLaunchObject)) {
|
||||
return false;
|
||||
}
|
||||
return ((TestLaunchObject) launchObject).descType.equals(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchDescriptor getDescriptor(Object launchObject) throws CoreException {
|
||||
return new TestLaunchDescriptor(this, (TestLaunchObject) launchObject);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestLaunchConfigurationProvider extends LaunchConfigurationProvider {
|
||||
final String descTypeId;
|
||||
final String targetTypeId;
|
||||
final ILaunchConfigurationType configType;
|
||||
final boolean isDefault;
|
||||
final LaunchBarManager manager;
|
||||
|
||||
private static final String OBJECT_NAME = "testObject.objectName";
|
||||
private static final String DESC_TYPE = "testObject.descType";
|
||||
|
||||
public TestLaunchConfigurationProvider(String descTypeId, String targetTypeId, ILaunchConfigurationType configType, boolean isDefault, LaunchBarManager manager) {
|
||||
this.descTypeId = descTypeId;
|
||||
this.targetTypeId = targetTypeId;
|
||||
this.configType = configType;
|
||||
this.isDefault = isDefault;
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchConfigurationType getLaunchConfigurationType() throws CoreException {
|
||||
return configType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchConfiguration createLaunchConfiguration(ILaunchManager launchManager, ILaunchDescriptor descriptor) throws CoreException {
|
||||
String name = launchManager.generateLaunchConfigurationName(getConfigurationName(descriptor));
|
||||
ILaunchConfigurationWorkingCopy workingCopy = getLaunchConfigurationType().newInstance(null, name);
|
||||
doReturn(name).when(workingCopy).getAttribute(ORIGINAL_NAME, "");
|
||||
|
||||
TestLaunchObject launchObject = (TestLaunchObject) descriptor.getAdapter(TestLaunchObject.class);
|
||||
doReturn(launchObject.name).when(workingCopy).getAttribute(OBJECT_NAME, "");
|
||||
doReturn(manager.getDescriptorTypeId(launchObject.descType)).when(workingCopy).getAttribute(DESC_TYPE, "");
|
||||
return workingCopy.doSave();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void populateConfiguration(ILaunchConfigurationWorkingCopy workingCopy, ILaunchDescriptor descriptor) throws CoreException {
|
||||
super.populateConfiguration(workingCopy, descriptor);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
|
||||
if (ownsConfiguration(configuration)) {
|
||||
String objectName = configuration.getAttribute(OBJECT_NAME, "");
|
||||
String descTypeId = configuration.getAttribute(DESC_TYPE, "");
|
||||
if (!objectName.isEmpty() && !descTypeId.isEmpty()) {
|
||||
return new TestLaunchObject(objectName, manager.getLaunchDescriptorType(descTypeId));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
|
||||
if (ownsConfiguration(configuration)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public abstract class TestLaunchObjectProvider implements ILaunchObjectProvider {
|
||||
@Override
|
||||
public void dispose() {
|
||||
// nothing by default
|
||||
}
|
||||
}
|
||||
|
||||
protected ILaunchConfigurationType mockLaunchConfigurationType(String id) {
|
||||
return mockLaunchConfigurationType(id, launchManager.getLaunchModes());
|
||||
}
|
||||
|
||||
protected ILaunchConfigurationType mockLaunchConfigurationType(String id, ILaunchMode[] modes) {
|
||||
ILaunchConfigurationType type = mock(ILaunchConfigurationType.class);
|
||||
doReturn(id).when(type).getIdentifier();
|
||||
doReturn(type).when(launchManager).getLaunchConfigurationType(id);
|
||||
|
||||
// mock for supportsMode
|
||||
for (ILaunchMode mode : modes) {
|
||||
String modeid = mode.getIdentifier();
|
||||
doReturn(true).when(type).supportsMode(modeid);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
protected ILaunchConfigurationWorkingCopy mockLaunchConfiguration(String name, ILaunchConfigurationType type) throws CoreException {
|
||||
ILaunchConfigurationWorkingCopy wc = mock(ILaunchConfigurationWorkingCopy.class);
|
||||
doReturn(name).when(wc).getName();
|
||||
doReturn(type).when(wc).getType();
|
||||
doReturn(wc).when(wc).doSave();
|
||||
doReturn(name).when(launchManager).generateLaunchConfigurationName(name);
|
||||
doReturn(wc).when(type).newInstance(null, name);
|
||||
return wc;
|
||||
}
|
||||
|
||||
//
|
||||
// Now that we have all the setup,
|
||||
// Actual tests :)
|
||||
//
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
// Prefs are shared across an entire test
|
||||
prefs = new EclipsePreferences();
|
||||
|
||||
// launch manager and default modes
|
||||
launchManager = mock(ILaunchManager.class);
|
||||
try {
|
||||
doReturn(new ILaunchConfiguration[] {}).when(launchManager).getLaunchConfigurations();
|
||||
} catch (CoreException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
ILaunchMode runMode = mock(ILaunchMode.class);
|
||||
doReturn("run").when(runMode).getIdentifier();
|
||||
doReturn("Run").when(runMode).getLabel();
|
||||
doReturn("Run As...").when(runMode).getLaunchAsLabel();
|
||||
doReturn(runMode).when(launchManager).getLaunchMode("run");
|
||||
|
||||
ILaunchMode debugMode = mock(ILaunchMode.class);
|
||||
doReturn("debug").when(debugMode).getIdentifier();
|
||||
doReturn("Debug").when(debugMode).getLabel();
|
||||
doReturn("Debug As...").when(debugMode).getLaunchAsLabel();
|
||||
doReturn(debugMode).when(launchManager).getLaunchMode("debug");
|
||||
|
||||
doReturn(new ILaunchMode[] { runMode, debugMode }).when(launchManager).getLaunchModes();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLaunchBarManager() throws Exception {
|
||||
TestLaunchBarManager manager = new TestLaunchBarManager();
|
||||
assertNull(manager.getActiveLaunchDescriptor());
|
||||
assertNull(manager.getActiveLaunchTarget());
|
||||
assertNull(manager.getActiveLaunchMode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccessPath() throws Exception {
|
||||
TestLaunchBarManager manager = new TestLaunchBarManager();
|
||||
|
||||
// mock out the launch config that will be created
|
||||
String name = "testConfig";
|
||||
ILaunchConfigurationType configType = manager.getLaunchManager().getLaunchConfigurationType(DEFAULT_CONFIG_TYPE_ID);
|
||||
assertNotNull(configType);
|
||||
ILaunchConfigurationWorkingCopy wc = mockLaunchConfiguration(name, configType);
|
||||
|
||||
// fire in launch object and target
|
||||
ILaunchDescriptorType descType = manager.getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID);
|
||||
assertNotNull(descType);
|
||||
TestLaunchObject launchObject = new TestLaunchObject(name, descType);
|
||||
manager.init();
|
||||
manager.launchObjectAdded(launchObject);
|
||||
|
||||
// check our state
|
||||
assertEquals(manager.getLaunchDescriptor(launchObject), manager.getActiveLaunchDescriptor());
|
||||
assertNull(manager.getActiveLaunchTarget());
|
||||
assertNotNull(manager.getActiveLaunchMode());
|
||||
|
||||
ILaunchTargetType targetType = manager.getLaunchTargetType(DEFAULT_TARGET_TYPE_ID);
|
||||
assertNotNull(targetType);
|
||||
ILaunchTarget testTarget = new TestLaunchTarget("testTarget", targetType);
|
||||
manager.launchTargetAdded(testTarget);
|
||||
|
||||
// verify that our launch config got created and saved
|
||||
assertNotNull(manager.getActiveLaunchMode());
|
||||
assertEquals(wc, manager.getActiveLaunchConfiguration());
|
||||
verify(wc).doSave();
|
||||
|
||||
// now remove the launch object and make sure everything resets
|
||||
manager.launchObjectRemoved(launchObject);
|
||||
assertNull(manager.getActiveLaunchDescriptor());
|
||||
assertNull(manager.getActiveLaunchTarget());
|
||||
assertNull(manager.getActiveLaunchMode());
|
||||
verify(wc).delete();
|
||||
|
||||
// remove the target and make sure it's gone.
|
||||
manager.launchTargetRemoved(testTarget);
|
||||
ILaunchTarget[] allTargets = manager.getAllLaunchTargets();
|
||||
assertEquals(1, allTargets.length);
|
||||
assertNotEquals(testTarget, allTargets[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongObject() throws Exception {
|
||||
TestLaunchBarManager manager = new TestLaunchBarManager();
|
||||
|
||||
// mock out the launch config that will be created
|
||||
String name = "testConfig";
|
||||
ILaunchConfigurationType configType = manager.getLaunchManager().getLaunchConfigurationType(DEFAULT_CONFIG_TYPE_ID);
|
||||
mockLaunchConfiguration(name, configType);
|
||||
|
||||
// fire in launch target but object with no descriptor
|
||||
manager.launchObjectAdded(new Object());
|
||||
manager.launchTargetAdded(new TestLaunchTarget("testTarget", manager.getLaunchTargetType(DEFAULT_TARGET_TYPE_ID)));
|
||||
|
||||
// verify that there are no launch configs
|
||||
assertNull(manager.getActiveLaunchConfiguration());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTarget() throws Exception {
|
||||
TestLaunchBarManager manager = new TestLaunchBarManager();
|
||||
|
||||
// mock out the launch config that will be created
|
||||
String name = "testConfig";
|
||||
ILaunchConfigurationType configType = manager.getLaunchManager().getLaunchConfigurationType(DEFAULT_CONFIG_TYPE_ID);
|
||||
ILaunchConfigurationWorkingCopy wc = mockLaunchConfiguration(name, configType);
|
||||
|
||||
// create descriptor and target
|
||||
manager.launchObjectAdded(new TestLaunchObject(name, manager.getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID)));
|
||||
|
||||
// verify that our launch config got created and saved even though the default config type
|
||||
assertEquals(wc, manager.getActiveLaunchConfiguration());
|
||||
verify(wc).doSave();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultDescriptor() throws Exception {
|
||||
TestLaunchBarManager manager = new TestLaunchBarManager();
|
||||
|
||||
ILaunchConfigurationType configType = mockLaunchConfigurationType("configType.default");
|
||||
ILaunchConfiguration config = mockLaunchConfiguration("defaultConfig", configType);
|
||||
manager.launchConfigurationAdded(config);
|
||||
assertEquals(config, manager.getActiveLaunchConfiguration());
|
||||
|
||||
manager.launchConfigurationRemoved(config);
|
||||
assertNull(manager.getActiveLaunchConfiguration());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetActiveDescriptor() throws Exception {
|
||||
final TestLaunchBarManager manager = new TestLaunchBarManager();
|
||||
ILaunchMode runMode = launchManager.getLaunchMode("run");
|
||||
ILaunchMode debugMode = launchManager.getLaunchMode("debug");
|
||||
|
||||
// descriptor for the test descriptor
|
||||
String name = "test1";
|
||||
ILaunchConfigurationType configType = manager.getLaunchManager().getLaunchConfigurationType(DEFAULT_CONFIG_TYPE_ID);
|
||||
ILaunchConfigurationWorkingCopy wc = mockLaunchConfiguration(name, configType);
|
||||
|
||||
ILaunchDescriptorType descType = manager.getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID);
|
||||
TestLaunchObject testObject1 = new TestLaunchObject(name, descType);
|
||||
manager.launchObjectAdded(testObject1);
|
||||
ILaunchDescriptor test1 = manager.getLaunchDescriptor(testObject1);
|
||||
assertNotNull(test1);
|
||||
|
||||
final ILaunchMode[] testActiveMode = new ILaunchMode[1];
|
||||
final ILaunchDescriptor[] testActiveDesc = new ILaunchDescriptor[1];
|
||||
Listener listener = new Listener() {
|
||||
@Override
|
||||
public void launchTargetsChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launchDescriptorRemoved(ILaunchDescriptor descriptor) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activeLaunchTargetChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activeLaunchModeChanged() {
|
||||
testActiveMode[0] = manager.getActiveLaunchMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activeLaunchDescriptorChanged() {
|
||||
testActiveDesc[0] = manager.getActiveLaunchDescriptor();
|
||||
}
|
||||
};
|
||||
manager.addListener(listener);
|
||||
|
||||
// descriptor for the default descriptor
|
||||
ILaunchConfigurationType defaultConfigType = mockLaunchConfigurationType("configType.default");
|
||||
ILaunchConfiguration config = mockLaunchConfiguration("test2", defaultConfigType);
|
||||
manager.launchConfigurationAdded(config);
|
||||
ILaunchDescriptor test2 = manager.getLaunchDescriptor(config);
|
||||
assertNotNull(test2);
|
||||
assertNotSame(test1, test2);
|
||||
manager.setActiveLaunchMode(runMode);
|
||||
|
||||
// test2 should be active by default since it was created last
|
||||
assertEquals(test2, manager.getActiveLaunchDescriptor());
|
||||
assertEquals(test2, testActiveDesc[0]);
|
||||
assertEquals(config, manager.getActiveLaunchConfiguration());
|
||||
assertEquals(descriptor, manager.getActiveLaunchDescriptor());
|
||||
assertEquals(runMode, manager.getActiveLaunchMode());
|
||||
assertEquals(runMode, testActiveMode[0]);
|
||||
|
||||
// flip to test1
|
||||
testActiveMode[0] = null;
|
||||
testActiveDesc[0] = null;
|
||||
manager.setActiveLaunchDescriptor(test1);
|
||||
manager.setActiveLaunchMode(debugMode);
|
||||
assertEquals(test1, manager.getActiveLaunchDescriptor());
|
||||
assertEquals(test1, testActiveDesc[0]);
|
||||
assertEquals(wc, manager.getActiveLaunchConfiguration());
|
||||
assertEquals(debugMode, manager.getActiveLaunchMode());
|
||||
assertEquals(debugMode, testActiveMode[0]);
|
||||
|
||||
// and back to test2
|
||||
testActiveMode[0] = null;
|
||||
testActiveDesc[0] = null;
|
||||
manager.setActiveLaunchDescriptor(test2);
|
||||
assertEquals(test2, manager.getActiveLaunchDescriptor());
|
||||
assertEquals(test2, testActiveDesc[0]);
|
||||
assertEquals(config, manager.getActiveLaunchConfiguration());
|
||||
assertEquals(runMode, manager.getActiveLaunchMode());
|
||||
assertEquals(runMode, testActiveMode[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetActiveMode() throws Exception {
|
||||
TestLaunchBarManager manager = new TestLaunchBarManager();
|
||||
ILaunchMode runMode = launchManager.getLaunchMode("run");
|
||||
ILaunchMode debugMode = launchManager.getLaunchMode("debug");
|
||||
|
||||
String name = "test";
|
||||
ILaunchConfigurationType testConfigType = manager.getLaunchManager().getLaunchConfigurationType(DEFAULT_CONFIG_TYPE_ID);
|
||||
mockLaunchConfiguration(name, testConfigType);
|
||||
|
||||
ILaunchDescriptorType descType = manager.getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID);
|
||||
TestLaunchObject testObject = new TestLaunchObject(name, descType);
|
||||
manager.launchObjectAdded(testObject);
|
||||
assertNotNull(manager.getActiveLaunchConfiguration());
|
||||
|
||||
// The default launch mode is debug (that may change)
|
||||
assertEquals(debugMode, manager.getActiveLaunchMode());
|
||||
|
||||
// Set to run
|
||||
manager.setActiveLaunchMode(runMode);
|
||||
assertEquals(runMode, manager.getActiveLaunchMode());
|
||||
|
||||
// and back to debug
|
||||
manager.setActiveLaunchMode(debugMode);
|
||||
assertEquals(debugMode, manager.getActiveLaunchMode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetActiveTarget() throws Exception {
|
||||
// create separate target types and provider types for each one
|
||||
final ILaunchConfigurationType configType1 = mockLaunchConfigurationType("configType.test1");
|
||||
final ILaunchConfigurationType configType2 = mockLaunchConfigurationType("configType.test2");
|
||||
final TestLaunchTargetType targetType1 = new TestLaunchTargetType("targetType.test1");
|
||||
final TestLaunchTargetType targetType2 = new TestLaunchTargetType("targetType.test2");
|
||||
|
||||
TestLaunchBarManager manager = new TestLaunchBarManager() {
|
||||
@Override
|
||||
protected TestLaunchTargetType[] getTestTargetTypes() {
|
||||
return new TestLaunchTargetType[] { targetType1, targetType2 };
|
||||
}
|
||||
@Override
|
||||
protected TestLaunchConfigurationProvider[] getTestConfigProviders() {
|
||||
TestLaunchConfigurationProvider provider1 = new TestLaunchConfigurationProvider(
|
||||
DEFAULT_DESCRIPTOR_TYPE_ID, targetType1.id, configType1, true, this);
|
||||
TestLaunchConfigurationProvider provider2 = new TestLaunchConfigurationProvider(
|
||||
DEFAULT_DESCRIPTOR_TYPE_ID, targetType2.id, configType2, true, this);
|
||||
return new TestLaunchConfigurationProvider[] { provider1, provider2 };
|
||||
}
|
||||
};
|
||||
|
||||
// Target 1
|
||||
ILaunchConfiguration config1 = mockLaunchConfiguration("test1", configType1);
|
||||
TestLaunchTarget target1 = new TestLaunchTarget("testTarget1", targetType1);
|
||||
manager.launchTargetAdded(target1);
|
||||
|
||||
// add in our object
|
||||
manager.launchObjectAdded(new TestLaunchObject("test1", manager.getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID)));
|
||||
|
||||
// launch config and target should be the default one
|
||||
assertEquals(target1, manager.getActiveLaunchTarget());
|
||||
assertEquals(config1, manager.getActiveLaunchConfiguration());
|
||||
|
||||
// switching to second target type should create a new config, but it needs a new name
|
||||
ILaunchManager launchManager = manager.getLaunchManager();
|
||||
doReturn("test2").when(launchManager).generateLaunchConfigurationName("test1");
|
||||
ILaunchConfiguration config2 = mockLaunchConfiguration("test2", configType2);
|
||||
TestLaunchTarget target2 = new TestLaunchTarget("testTarget2", targetType2);
|
||||
manager.setActiveLaunchTarget(target2);
|
||||
|
||||
assertEquals(target2, manager.getActiveLaunchTarget());
|
||||
assertEquals(config2, manager.getActiveLaunchConfiguration());
|
||||
assertEquals("test2", manager.getActiveLaunchConfiguration().getName());
|
||||
}
|
||||
|
||||
public class TestRestartLaunchBarManager extends TestLaunchBarManager {
|
||||
public TestRestartLaunchBarManager() throws CoreException {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TestLaunchTargetType[] getTestTargetTypes() {
|
||||
TestLaunchTargetType targetType = new TestLaunchTargetType(DEFAULT_TARGET_TYPE_ID) {
|
||||
public void init(ILaunchBarManager manager) throws CoreException {
|
||||
manager.launchTargetAdded(new TestLaunchTarget("testTarget1", this));
|
||||
manager.launchTargetAdded(new TestLaunchTarget("testTarget2", this));
|
||||
}
|
||||
};
|
||||
return new TestLaunchTargetType[] { targetType };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TestLaunchObjectProvider[] getTestObjectProviders() {
|
||||
TestLaunchObjectProvider provider = new TestLaunchObjectProvider() {
|
||||
@Override
|
||||
public void init(ILaunchBarManager manager) throws CoreException {
|
||||
mockLaunchConfiguration("test1", launchManager.getLaunchConfigurationType(DEFAULT_CONFIG_TYPE_ID));
|
||||
manager.launchObjectAdded(new TestLaunchObject("test1", getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID)));
|
||||
mockLaunchConfiguration("test2", launchManager.getLaunchConfigurationType(DEFAULT_CONFIG_TYPE_ID));
|
||||
manager.launchObjectAdded(new TestLaunchObject("test2", getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID)));
|
||||
}
|
||||
};
|
||||
return new TestLaunchObjectProvider[] { provider };
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestart() throws Exception {
|
||||
// create two over everything, set second active, and make sure it's remembered in a second manager
|
||||
TestLaunchBarManager manager = new TestRestartLaunchBarManager();
|
||||
ILaunchMode runMode = launchManager.getLaunchMode("run");
|
||||
ILaunchMode debugMode = launchManager.getLaunchMode("debug");
|
||||
assertNotNull(runMode);
|
||||
|
||||
// get our targets
|
||||
ILaunchTarget target1 = manager.getLaunchTarget(new Pair<String, String>(DEFAULT_TARGET_TYPE_ID, "testTarget1"));
|
||||
assertNotNull(target1);
|
||||
ILaunchTarget target2 = manager.getLaunchTarget(new Pair<String, String>(DEFAULT_TARGET_TYPE_ID, "testTarget2"));
|
||||
assertNotNull(target2);
|
||||
|
||||
// get our descriptors
|
||||
ILaunchDescriptor desc1 = manager.getLaunchDescriptor(new Pair<String, String>(DEFAULT_DESCRIPTOR_TYPE_ID, "test1"));
|
||||
assertNotNull(desc1);
|
||||
ILaunchDescriptor desc2 = manager.getLaunchDescriptor(new Pair<String, String>(DEFAULT_DESCRIPTOR_TYPE_ID, "test2"));
|
||||
assertNotNull(desc2);
|
||||
|
||||
// Set the actives one way
|
||||
manager.setActiveLaunchDescriptor(desc1);
|
||||
manager.setActiveLaunchTarget(target1);
|
||||
manager.setActiveLaunchMode(runMode);
|
||||
|
||||
// Create a new manager and check they are the same
|
||||
manager = new TestRestartLaunchBarManager();
|
||||
desc1 = manager.getLaunchDescriptor(new Pair<String, String>(DEFAULT_DESCRIPTOR_TYPE_ID, "test1"));
|
||||
assertNotNull(desc1);
|
||||
desc2 = manager.getLaunchDescriptor(new Pair<String, String>(DEFAULT_DESCRIPTOR_TYPE_ID, "test2"));
|
||||
assertNotNull(desc2);
|
||||
assertEquals(desc1, manager.getActiveLaunchDescriptor());
|
||||
|
||||
target1 = manager.getLaunchTarget(new Pair<String, String>(DEFAULT_TARGET_TYPE_ID, "testTarget1"));
|
||||
assertNotNull(target1);
|
||||
target2 = manager.getLaunchTarget(new Pair<String, String>(DEFAULT_TARGET_TYPE_ID, "testTarget2"));
|
||||
assertNotNull(target2);
|
||||
assertEquals(target1, manager.getActiveLaunchTarget());
|
||||
assertEquals(runMode, manager.getActiveLaunchMode());
|
||||
|
||||
// Set them the other way
|
||||
manager.setActiveLaunchDescriptor(desc2);
|
||||
manager.setActiveLaunchTarget(target2);
|
||||
manager.setActiveLaunchMode(debugMode);
|
||||
|
||||
// Create a new manager and check they stuck
|
||||
manager = new TestRestartLaunchBarManager();
|
||||
desc2 = manager.getLaunchDescriptor(new Pair<String, String>(DEFAULT_DESCRIPTOR_TYPE_ID, "test2"));
|
||||
assertNotNull(desc2);
|
||||
assertEquals(desc2, manager.getActiveLaunchDescriptor());
|
||||
target2 = manager.getLaunchTarget(new Pair<String, String>(DEFAULT_TARGET_TYPE_ID, "testTarget2"));
|
||||
assertNotNull(target2);
|
||||
assertEquals(target2, manager.getActiveLaunchTarget());
|
||||
assertEquals(debugMode, manager.getActiveLaunchMode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLaunchConfigCapture() throws Exception {
|
||||
final ILaunchConfigurationType configType = mockLaunchConfigurationType(DEFAULT_CONFIG_TYPE_ID);
|
||||
TestLaunchBarManager manager = new TestLaunchBarManager() {
|
||||
protected TestLaunchConfigurationProvider[] getTestConfigProviders() {
|
||||
return new TestLaunchConfigurationProvider[] {
|
||||
new TestLaunchConfigurationProvider(DEFAULT_DESCRIPTOR_TYPE_ID, DEFAULT_TARGET_TYPE_ID, configType, true, this)
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
ILaunchConfiguration config = mockLaunchConfiguration("test", configType);
|
||||
manager.launchObjectAdded(new TestLaunchObject("test", manager.getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID)));
|
||||
String activeDescId = manager.toString(manager.getDescriptorId(manager.getActiveLaunchDescriptor()));
|
||||
assertEquals(manager.getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID), manager.getActiveLaunchDescriptor().getType());
|
||||
assertEquals(config, manager.getActiveLaunchConfiguration());
|
||||
|
||||
// restart and make sure the same descriptor is selected and new one new ones created
|
||||
doReturn(new ILaunchConfiguration[] { config }).when(launchManager).getLaunchConfigurations();
|
||||
manager = new TestLaunchBarManager() {
|
||||
protected TestLaunchConfigurationProvider[] getTestConfigProviders() {
|
||||
return new TestLaunchConfigurationProvider[] {
|
||||
new TestLaunchConfigurationProvider(DEFAULT_DESCRIPTOR_TYPE_ID, DEFAULT_TARGET_TYPE_ID, configType, true, this)
|
||||
};
|
||||
}
|
||||
@Override
|
||||
protected TestLaunchObjectProvider[] getTestObjectProviders() {
|
||||
return new TestLaunchObjectProvider[] {
|
||||
new TestLaunchObjectProvider() {
|
||||
@Override
|
||||
public void init(ILaunchBarManager manager) throws CoreException {
|
||||
manager.launchObjectAdded(
|
||||
new TestLaunchObject("test",
|
||||
getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID)));;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
String newActiveDescId = manager.toString(manager.getDescriptorId(manager.getActiveLaunchDescriptor()));
|
||||
assertEquals(activeDescId, newActiveDescId);
|
||||
assertEquals(1, manager.getLaunchDescriptors().length);
|
||||
IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
|
||||
IRemoteConnectionType localServices = remoteManager.getLocalConnectionType();
|
||||
IRemoteConnection localConnection = localServices.getConnections().get(0);
|
||||
assertNotNull(localConnection);
|
||||
assertEquals(localConnection, manager.getActiveLaunchTarget());
|
||||
assertEquals(launchConfig, manager.getActiveLaunchConfiguration());
|
||||
}
|
||||
|
||||
// TODO - test that changing active target type produces a different launch config type
|
||||
// TODO - test that settings are maintained after a restart
|
||||
// TODO - test that two target types that map to the same desc type and config type share configs
|
||||
// TODO - test duplicating a config. make sure it's default desc and same targets
|
||||
// TODO - test project descriptors and stuff
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
package org.eclipse.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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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.launchbar.core.tests;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.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;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue