mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 17:35:35 +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,7 +63,11 @@ public class Activator extends Plugin {
|
|||
}
|
||||
|
||||
public static void log(Exception exception) {
|
||||
log(new Status(IStatus.ERROR, PLUGIN_ID, exception.getLocalizedMessage(), 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 =
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -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,16 +32,14 @@ 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();
|
||||
|
||||
ILaunchMode activeLaunchMode = launchBarManager.getActiveLaunchMode();
|
||||
ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(launchConfiguration.getType(), activeLaunchMode.getIdentifier());
|
||||
|
||||
|
||||
if (DebugUITools.openLaunchConfigurationPropertiesDialog(HandlerUtil.getActiveShell(event), wc, group.getIdentifier()) == Window.OK)
|
||||
wc.doSave();
|
||||
} catch (CoreException e) {
|
||||
|
|
|
@ -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";
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws CoreException {
|
||||
super.init();
|
||||
synchronized (this) {
|
||||
done = true;
|
||||
notify();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IExtensionPoint getExtensionPoint() throws CoreException {
|
||||
// default things
|
||||
IExtensionPoint point = mock(IExtensionPoint.class);
|
||||
|
||||
IExtension extension = mock(IExtension.class);
|
||||
doReturn(new IExtension[] { extension }).when(point).getExtensions();
|
||||
|
||||
List<IConfigurationElement> elements = new ArrayList<>();
|
||||
|
||||
IConfigurationElement element;
|
||||
|
||||
// The local target
|
||||
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");
|
||||
|
||||
// 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");
|
||||
}
|
||||
|
||||
// Test descriptors
|
||||
for (TestLaunchDescriptorType descType : getTestDescriptorTypes()) {
|
||||
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");
|
||||
}
|
||||
|
||||
// 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");
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
// test object providers
|
||||
for (TestLaunchObjectProvider objectProvider : getTestObjectProviders()) {
|
||||
element = mock(IConfigurationElement.class);
|
||||
elements.add(element);
|
||||
doReturn("objectProvider").when(element).getName();
|
||||
doReturn(objectProvider).when(element).createExecutableExtension("class");
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected 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();
|
||||
}
|
||||
public class LaunchBarManagerTest {
|
||||
|
||||
@Test
|
||||
public void testLaunchBarManager() throws Exception {
|
||||
TestLaunchBarManager manager = new TestLaunchBarManager();
|
||||
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.getActiveLaunchTarget());
|
||||
assertNull(manager.getActiveLaunchMode());
|
||||
assertNull(manager.getActiveLaunchTarget());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccessPath() throws Exception {
|
||||
TestLaunchBarManager manager = new TestLaunchBarManager();
|
||||
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");
|
||||
|
||||
// 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);
|
||||
// Inject the launch config
|
||||
LaunchBarManager manager = new LaunchBarManager(false);
|
||||
manager.init();
|
||||
manager.launchConfigurationAdded(launchConfig);
|
||||
|
||||
// fire in launch object and target
|
||||
ILaunchDescriptorType descType = manager.getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID);
|
||||
assertNotNull(descType);
|
||||
TestLaunchObject launchObject = new TestLaunchObject(name, descType);
|
||||
// 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());
|
||||
}
|
||||
|
||||
@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(extensionPoint).getExtensions();
|
||||
|
||||
List<IConfigurationElement> elements = new ArrayList<>();
|
||||
IConfigurationElement element;
|
||||
|
||||
// local target type
|
||||
element = mock(IConfigurationElement.class);
|
||||
elements.add(element);
|
||||
doReturn("targetType").when(element).getName();
|
||||
String targetTypeId = "org.eclipse.launchbar.core.targetType.local";
|
||||
doReturn(targetTypeId).when(element).getAttribute("id");
|
||||
doReturn("org.eclipse.remote.LocalServices").when(element).getAttribute("remoteServicesId");
|
||||
|
||||
// fake launch object
|
||||
String launchObject = "fakeObject";
|
||||
|
||||
// launch descriptor for that object
|
||||
element = mock(IConfigurationElement.class);
|
||||
elements.add(element);
|
||||
doReturn("descriptorType").when(element).getName();
|
||||
String descriptorTypeId = "fakeDescriptorType";
|
||||
doReturn(descriptorTypeId).when(element).getAttribute("id");
|
||||
ILaunchDescriptorType descriptorType = mock(ILaunchDescriptorType.class);
|
||||
doReturn(descriptorType).when(element).createExecutableExtension("class");
|
||||
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();
|
||||
|
||||
// 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(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);
|
||||
|
||||
// configType
|
||||
element = mock(IConfigurationElement.class);
|
||||
elements.add(element);
|
||||
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();
|
||||
|
||||
// Now inject the launch object
|
||||
LaunchBarManager manager = new LaunchBarManager(false) {
|
||||
@Override
|
||||
IExtensionPoint getExtensionPoint() throws CoreException {
|
||||
return extensionPoint;
|
||||
}
|
||||
@Override
|
||||
ILaunchManager getLaunchManager() {
|
||||
return launchManager;
|
||||
}
|
||||
};
|
||||
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