1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 17:25:38 +02:00

Bug 467153 - Step one of making configs per target.

WTP needs a new config for every target. That breaks our architecture
of one config per target type. But that's actually already broken
since we can't really get the proper target to the launch config.
Depending on active, we always hoped the target didn't change, but
it can. So one config per target is correct anyway.

Change-Id: I14ba8413b9494a13f3496eed5535debbc330a56c
This commit is contained in:
Doug Schaefer 2015-05-17 23:22:09 -04:00
parent 899208ac28
commit 86c73092fa
25 changed files with 901 additions and 1096 deletions

View file

@ -12,4 +12,5 @@ Require-Bundle: org.eclipse.core.runtime,
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.launchbar.core,
org.eclipse.launchbar.core.internal;x-friends:="org.eclipse.launchbar.core.tests,org.eclipse.launchbar.ui"
org.eclipse.launchbar.core.internal;x-friends:="org.eclipse.launchbar.core.tests,org.eclipse.launchbar.ui",
org.eclipse.launchbar.core.launch

View file

@ -4,14 +4,20 @@
<extension-point id="launchBarContributions" name="Launch Bar Contributions" schema="schema/launchBarContributions.exsd"/>
<extension
point="org.eclipse.launchbar.core.launchBarContributions">
<targetType
connectionTypeId="ca.cdtdoug.wascana.arduino.core.connectionType"
id="org.eclipse.launchbar.core.targetType.local">
</targetType>
<objectProvider
class="org.eclipse.launchbar.core.internal.ProjectLaunchObjectProvider"
id="org.eclipse.launchbar.core.objectProvider.project">
</objectProvider>
<descriptorType
class="org.eclipse.launchbar.core.internal.DefaultLaunchDescriptorType"
id="org.eclipse.launchbar.core.descriptorType.default"
priority="0">
</descriptorType>
<configProvider
class="org.eclipse.launchbar.core.DefaultLaunchConfigProvider"
descriptorType="org.eclipse.launchbar.core.descriptorType.default"
priority="0">
</configProvider>
</extension>
</plugin>

View file

@ -19,11 +19,8 @@
<complexType>
<sequence minOccurs="0" maxOccurs="unbounded">
<element ref="descriptorType"/>
<element ref="targetType"/>
<element ref="configType"/>
<element ref="configProvider"/>
<element ref="objectProvider"/>
<element ref="defaultConfigTarget"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
@ -86,48 +83,7 @@
</complexType>
</element>
<element name="targetType">
<annotation>
<documentation>
A target is the machine you launch on. Typical examples include the local machine we are running on, or remote embedded or server targets.
</documentation>
</annotation>
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="connectionTypeId" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<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>
<element name="configType">
<element name="configProvider">
<annotation>
<documentation>
Descriptor types and target types map to a launch configuration type. Configurations of that type knows how to launch for the desciptor on targets of that type.
@ -144,51 +100,11 @@
</appinfo>
</annotation>
</attribute>
<attribute name="targetType" type="string" use="required">
<attribute name="priority" 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="launchConfigurationType" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="identifier" basedOn="org.eclipse.debug.core.launchConfigurationTypes/launchConfigurationType/@id"/>
</appinfo>
</annotation>
</attribute>
<attribute name="isDefault" type="boolean">
<annotation>
<documentation>
Is this the default target type for this descriptor type.
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="configProvider">
<annotation>
<documentation>
The config provider knows how to create launch configurations from descriptors. It tracks which configs it has created so that they don&apos;t show up as descriptors on their own.
</documentation>
</annotation>
<complexType>
<attribute name="launchConfigurationType" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="identifier" basedOn="org.eclipse.debug.core.launchConfigurationTypes/launchConfigurationType/@id"/>
</appinfo>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
@ -204,43 +120,6 @@
</complexType>
</element>
<element name="defaultConfigTarget">
<annotation>
<documentation>
The default config provider is brought in when no other config providers claim a given launch configuration. This entry associates a target type with the launch configuration so that it can be launched on targets of that type.
</documentation>
</annotation>
<complexType>
<attribute name="launchConfigurationType" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="identifier" basedOn="org.eclipse.debug.core.launchConfigurationTypes/launchConfigurationType/@id"/>
</appinfo>
</annotation>
</attribute>
<attribute name="targetType" 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="isDefault" type="boolean">
<annotation>
<documentation>
Is this the default target type for this descriptor type.
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="objectProvider">
<annotation>
<documentation>

View file

@ -0,0 +1,43 @@
package org.eclipse.launchbar.core;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.launchbar.core.internal.Activator;
import org.eclipse.remote.core.IRemoteConnection;
/**
* Common launch config provider. Manages creating launch configurations and ensuring
* duplicates are managed properly.
*/
public abstract class AbstractLaunchConfigProvider implements ILaunchConfigurationProvider {
private static final String ORIGINAL_NAME = Activator.PLUGIN_ID + ".originalName"; //$NON-NLS-1$
protected ILaunchConfiguration createLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
String name = launchManager.generateLaunchConfigurationName(descriptor.getName());
ILaunchConfigurationWorkingCopy workingCopy = getLaunchConfigurationType(descriptor, target).newInstance(null, name);
populateLaunchConfiguration(descriptor, workingCopy);
return workingCopy.doSave();
}
protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchConfigurationWorkingCopy workingCopy)
throws CoreException {
// Leave our breadcrumb
workingCopy.setAttribute(ORIGINAL_NAME, workingCopy.getName());
}
@Override
public boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
// We created it if it has the same name we created it with.
// This covers the case when the config was duplicated.
// We can own only one, the original one.
return configuration.getAttribute(ORIGINAL_NAME, "").equals(configuration.getName()); //$NON-NLS-1$
}
}

View file

@ -0,0 +1,59 @@
package org.eclipse.launchbar.core;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.remote.core.IRemoteConnection;
/**
* The launch config provider for the default descriptor which is the launch config itself.
*
* Override this class and register an extension if you want to support targets other than the local connection.
*/
public class DefaultLaunchConfigProvider implements ILaunchConfigurationProvider {
@Override
public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
// Only supports Local connection
return target.getConnectionType().getId().equals("org.eclipse.remote.LocalServices"); //$NON-NLS-1$
}
@Override
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, IRemoteConnection target)
throws CoreException {
return descriptor.getAdapter(ILaunchConfiguration.class).getType();
}
@Override
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target)
throws CoreException {
return descriptor.getAdapter(ILaunchConfiguration.class);
}
@Override
public boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
// If I get here, I own it
return true;
}
@Override
public Object launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
return configuration;
}
@Override
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
return true;
}
@Override
public void launchDescriptorRemoved(ILaunchDescriptor descriptor) throws CoreException {
// nothing to do
}
@Override
public void launchTargetRemoved(IRemoteConnection target) throws CoreException {
// nothing to do
}
}

View file

@ -1,44 +1,89 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems and others.
* Copyright (c) 2014, 2015 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
* QNX Software Systems - initial
*******************************************************************************/
package org.eclipse.launchbar.core;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.remote.core.IRemoteConnection;
/**
* The provider of launch configurations of a given type for a given descriptor type
* and a given target type.
*
* It is recommended to extend {@link LaunchConfigurationProvider}
* instead of implementing this directly.
* It is recommended to extend {@link AbstractLaunchConfigProvider} or one of it's
* subclasses instead of implementing this directly.
*/
public interface ILaunchConfigurationProvider {
/**
* Does this provider own this launch configuration. If so, make sure the launch descriptor
* is properly constructed by sending in a launch object to the launch manager.
* And return that object.
* Does this config provider provide launch configurations for the combination
* of descriptor and target.
*
* Note: this is called when filtering targets for a descriptor. Processing
* should be minimal.
*
* @param descriptor
* @param target
* @return
*/
boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException;
/**
* Return the launch configuation type for the descriptor and target.
*
* @param descriptor
* @param target launch configuration type or null if not supported
* @return
* @throws CoreException
*/
ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor,
IRemoteConnection target) throws CoreException;
/**
* Create a launch configuration for the descriptor to launch on the target.
*
* @param descriptor the descriptor to create the config for
* @param target the target to launch the config on
* @return launch configuration
* @throws CoreException
*/
ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target)
throws CoreException;
/**
* Does this provider own the launch configuration.
*
* @param configuration launch configuration
* @return true if this provider owns the launch configuration
* @throws CoreException
*/
boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException;
/**
* A launch configuration has been added.
* Return the launch object associated with this configuration and the launch bar manager
* will ensure the descriptor is created for it.
*
* @param configuration
* @return launch object that relates to this config or null it does not own it.
* @return whether this provider owns this launch configuration
* @throws CoreException
*/
Object launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException;
/**
* A launch configuration has been removed.
* It it fired after launch configuration has been removed from file system, so accessing its attributes won't work.
* This notification can be used to purge internal cache for example.
* This method is called after launch configuration has been removed from file system,
* so accessing its attributes won't work.
* If provider cannot determine if it owns it it should return false.
*
* @param configuration
@ -48,21 +93,21 @@ public interface ILaunchConfigurationProvider {
boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException;
/**
* Returns the launch configuration type for configurations created by this provider.
*
* @return launch configuration type
* @throws CoreException
*/
ILaunchConfigurationType getLaunchConfigurationType() throws CoreException;
/**
* Create a launch configuration for the descriptor to launch on the target.
* A launch descriptor has been removed. Remove any launch configurations that were
* created for it.
*
* @param descriptor
* @param target
* @return launch configuration
* @throws CoreException
* @throws CoreException
*/
ILaunchConfiguration createLaunchConfiguration(ILaunchManager launchManager, ILaunchDescriptor descriptor) throws CoreException;
void launchDescriptorRemoved(ILaunchDescriptor descriptor) throws CoreException;
/**
* A launch target has been removed. Remove any launch configurations that were created
* for it.
*
* @param target
* @throws CoreException
*/
void launchTargetRemoved(IRemoteConnection target) throws CoreException;
}

View file

@ -1,77 +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;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.launchbar.core.internal.Activator;
/**
* A root class for launch configuration providers. Provides the ability to detect launch
* configurations that it has created.
*/
public abstract class LaunchConfigurationProvider implements ILaunchConfigurationProvider {
// Used to make sure this is the config we've created
protected static final String ORIGINAL_NAME = Activator.PLUGIN_ID + ".originalName"; //$NON-NLS-1$
@Override
public ILaunchConfiguration createLaunchConfiguration(ILaunchManager launchManager, ILaunchDescriptor descriptor) throws CoreException {
String name = launchManager.generateLaunchConfigurationName(getConfigurationName(descriptor));
ILaunchConfigurationWorkingCopy wc = getLaunchConfigurationType().newInstance(null, name);
wc.setAttribute(ORIGINAL_NAME, name);
populateConfiguration(wc, descriptor);
return wc.doSave();
}
/**
* Potential name for new configurations. Names are still put through the launch manager
* to ensure they are unique.
*
* @param descriptor the launch descriptor triggering the configuration creation
* @return candidate configuration name
*/
protected String getConfigurationName(ILaunchDescriptor descriptor) {
// by default, use the descriptor name
return descriptor.getName();
}
/**
* Populate the new configuration with attributes and resources.
*
* @param workingCopy working copy for the new configuration
* @param descriptor the launch descriptor that triggered the new configuration
* @throws CoreException
*/
protected void populateConfiguration(ILaunchConfigurationWorkingCopy workingCopy, ILaunchDescriptor descriptor) throws CoreException {
// by default, nothing to add
}
/**
* Determines if we created this launch configuration. Generally used by the launch configuration
* add handler to determine if the incoming launch configuration is ours.
*
* @param configuration
* @return do we own this launch configuration
* @throws CoreException
*/
protected boolean ownsConfiguration(ILaunchConfiguration configuration) throws CoreException {
// must be the same config type
if (!configuration.getType().equals(getLaunchConfigurationType()))
return false;
// we created it if it has the same name we created it with
return configuration.getAttribute(ORIGINAL_NAME, "").equals(configuration.getName()); //$NON-NLS-1$
}
}

View file

@ -0,0 +1,115 @@
/*******************************************************************************
* Copyright (c) 2015 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
*******************************************************************************/
package org.eclipse.launchbar.core;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.remote.core.IRemoteConnection;
/**
* Common launch configuration provider for cases where it provides for a single
* connection type and a single launch configuration type.
*/
public abstract class PerTypeLaunchConfigProvider extends AbstractLaunchConfigProvider {
// Map from launch object to launch configuration
private Map<Object, ILaunchConfiguration> configMap = new HashMap<>();
protected abstract String getRemoteConnectionTypeId();
protected abstract String getLaunchConfigurationTypeId();
protected abstract Object getLaunchObject(ILaunchDescriptor descriptor);
protected abstract Object getLaunchObject(ILaunchConfiguration configuration) throws CoreException;
protected ILaunchConfigurationType getLaunchConfigurationType() {
return DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(getLaunchConfigurationTypeId());
}
@Override
public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
// If target is null, assume we support it.
return target == null || target.getConnectionType().getId().equals(getRemoteConnectionTypeId());
}
@Override
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
if (supports(descriptor, target)) {
return getLaunchConfigurationType();
}
return null;
}
@Override
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
if (supports(descriptor, target)) {
Object launchObject = getLaunchObject(descriptor);
ILaunchConfiguration config = configMap.get(launchObject);
if (config == null) {
config = createLaunchConfiguration(descriptor, target);
configMap.put(launchObject, config);
}
return config;
} else {
return null;
}
}
@Override
public boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
if (!super.ownsLaunchConfiguration(configuration)) {
return false;
}
// Must be of our type
return configuration.getType().equals(getLaunchConfigurationType());
}
@Override
public Object launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
if (ownsLaunchConfiguration(configuration)) {
Object launchObject = getLaunchObject(configuration);
configMap.put(launchObject, configuration);
return launchObject;
}
return null;
}
@Override
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
if (ownsLaunchConfiguration(configuration)) {
Object launchObject = getLaunchObject(configuration);
configMap.remove(launchObject);
return true;
}
return false;
}
@Override
public void launchDescriptorRemoved(ILaunchDescriptor descriptor) throws CoreException {
Object launchObject = getLaunchObject(descriptor);
if (launchObject != null) {
configMap.remove(launchObject);
}
}
@Override
public void launchTargetRemoved(IRemoteConnection target) throws CoreException {
// nothing to do per target
}
}

View file

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems and others.
* Copyright (c) 2015 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
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.launchbar.core;
@ -15,19 +15,44 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.launchbar.core.internal.Activator;
import org.eclipse.remote.core.IRemoteConnection;
/**
* A root launch configuration provider that can be used with project launch descriptors.
* Takes ownership of configurations we've created that map to the the project.
*/
public abstract class ProjectLaunchConfigurationProvider extends LaunchConfigurationProvider {
public abstract class ProjectPerTypeLaunchConfigProvider extends PerTypeLaunchConfigProvider {
private static final String PROJECT_CONFIG = Activator.PLUGIN_ID + ".projectConfig"; //$NON-NLS-1$
@Override
protected void populateConfiguration(ILaunchConfigurationWorkingCopy workingCopy, ILaunchDescriptor descriptor) throws CoreException {
super.populateConfiguration(workingCopy, descriptor);
protected Object getLaunchObject(ILaunchDescriptor descriptor) {
return descriptor.getAdapter(IProject.class);
}
@Override
protected Object getLaunchObject(ILaunchConfiguration configuration) throws CoreException {
for (IResource resource : configuration.getMappedResources()) {
if (resource instanceof IProject) {
return (IProject) resource;
}
}
return null;
}
@Override
public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
if (!super.supports(descriptor, target)) {
return false;
}
return descriptor.getAdapter(IProject.class) != null;
}
@Override
protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchConfigurationWorkingCopy workingCopy)
throws CoreException {
super.populateLaunchConfiguration(descriptor, workingCopy);
// Add our project to the mapped resources
IProject project = (IProject) descriptor.getAdapter(IProject.class);
IProject project = descriptor.getAdapter(IProject.class);
IResource[] mappedResources = workingCopy.getMappedResources();
if (mappedResources == null || mappedResources.length == 0) {
workingCopy.setMappedResources(new IResource[] { project });
@ -37,44 +62,16 @@ public abstract class ProjectLaunchConfigurationProvider extends LaunchConfigura
newResources[mappedResources.length] = project;
workingCopy.setMappedResources(newResources);
}
}
/**
* Extract the project from the launch configuration. Used when checking if we own it.
*
* @param configuration
* @return project for launch configuration.
* @throws CoreException
*/
protected IProject getProject(ILaunchConfiguration configuration) throws CoreException {
// by default return the first project in the mapped resources
for (IResource resource : configuration.getMappedResources()) {
if (resource instanceof IProject) {
return (IProject) resource;
}
}
return null;
workingCopy.setAttribute(PROJECT_CONFIG, true);
}
@Override
public Object launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
if (!ownsConfiguration(configuration)) {
return null;
public boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
if (!super.ownsLaunchConfiguration(configuration)) {
return false;
}
IProject project = getProject(configuration);
if (project == null) {
// The user must have changed project. We don't own it any more in that case.
return null;
}
return project;
}
@Override
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
return ownsConfiguration(configuration);
return configuration.getAttribute(PROJECT_CONFIG, false);
}
}

View file

@ -21,8 +21,7 @@ public class DefaultLaunchDescriptorType implements ILaunchDescriptorType {
@Override
public boolean ownsLaunchObject(Object element) {
// This descriptor type doesn't own any launch objects
return false;
return element instanceof ILaunchConfiguration;
}
@Override

View file

@ -12,13 +12,12 @@ package org.eclipse.launchbar.core.internal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
@ -38,7 +37,6 @@ import org.eclipse.debug.core.ILaunchConfigurationType;
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;
@ -47,7 +45,6 @@ import org.eclipse.remote.core.IRemoteConnectionChangeListener;
import org.eclipse.remote.core.IRemoteConnectionType;
import org.eclipse.remote.core.IRemoteServicesManager;
import org.eclipse.remote.core.RemoteConnectionChangeEvent;
import org.eclipse.remote.core.launch.IRemoteLaunchConfigService;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
@ -73,35 +70,13 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
// The descriptor types
private final Map<String, LaunchDescriptorTypeInfo> descriptorTypes = new HashMap<>();
// Descriptor types ordered from highest priority to lowest
private List<LaunchDescriptorTypeInfo> orderedDescriptorTypes;
// the extended info for loaded descriptor types
private final Map<ILaunchDescriptorType, LaunchDescriptorTypeInfo> descriptorTypeInfo = new HashMap<>();
// Descriptor types ordered from highest priority to lowest
private final List<LaunchDescriptorTypeInfo> orderedDescriptorTypes = new LinkedList<>();
// The target types by id
private final Map<String, LaunchTargetTypeInfo> targetTypes = new HashMap<>();
// The list of target types for a given descriptor type
private final Map<String, List<String>> descriptorTargets = new HashMap<>();
// The mapping from descriptor type to target type to launch config type
private final Map<String, Map<String, String>> configTypes = new HashMap<>();
// Map descriptor type to target type so we can build when no targets have been added
private final Map<String, String> defaultTargetTypes = new HashMap<>();
// Map from launch config type id to target type ids for default descriptors
private final Map<String, List<String>> configTargetTypes = new HashMap<>();
// Map from launch config type Id to target type id for default descriptor for null target
private final Map<String, String> defaultConfigTargetTypes = new HashMap<>();
// The launch config providers
private final Map<String, LaunchConfigProviderInfo> configProviders = new HashMap<>();
// The default launch descriptor type used to wrap unclaimed launch configs
private DefaultLaunchDescriptorType defaultDescriptorType = new DefaultLaunchDescriptorType();
private final Map<String, List<LaunchConfigProviderInfo>> configProviders = new HashMap<>();
// Descriptors in MRU order, key is desc type id and desc name.
private final Map<Pair<String, String>, ILaunchDescriptor> descriptors = new LinkedHashMap<>();
@ -109,11 +84,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
// Map of launch objects to launch descriptors
private final Map<Object, ILaunchDescriptor> objectDescriptorMap = new HashMap<>();
// The created launch configurations
private final Map<ILaunchDescriptor, Map<ILaunchConfigurationProvider, ILaunchConfiguration>> configs = new HashMap<>();
private final IRemoteServicesManager remoteServicesManager = getRemoteServicesManager();
private final IRemoteLaunchConfigService remoteLaunchConfigService = getRemoteLaunchConfigService();
private ILaunchDescriptor activeLaunchDesc;
private ILaunchMode activeLaunchMode;
@ -123,7 +94,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
private static final String PREF_ACTIVE_LAUNCH_MODE = "activeLaunchMode"; //$NON-NLS-1$
private static final String PREF_ACTIVE_LAUNCH_TARGET = "activeLaunchTarget"; //$NON-NLS-1$
private static final String PREF_CONFIG_DESC_ORDER = "configDescList"; //$NON-NLS-1$
boolean initialized = false;
public LaunchBarManager() {
@ -154,10 +125,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
return Activator.getService(IRemoteServicesManager.class);
}
IRemoteLaunchConfigService getRemoteLaunchConfigService() {
return Activator.getService(IRemoteLaunchConfigService.class);
}
// To allow override by tests
IExtensionPoint getExtensionPoint() throws CoreException {
return Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchBarContributions"); //$NON-NLS-1$
@ -174,18 +141,17 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
// Fetch the desc order before the init messes it up
IEclipsePreferences store = getPreferenceStore();
String configDescIds = store.get(PREF_CONFIG_DESC_ORDER, ""); //$NON-NLS-1$
// Load up the types
loadExtensions();
// Add in the default descriptor type
LaunchDescriptorTypeInfo defaultInfo = new LaunchDescriptorTypeInfo(DefaultLaunchDescriptorType.ID,
0, defaultDescriptorType);
addDescriptorType(defaultInfo);
// Hook up the existing launch configurations and listen
ILaunchManager launchManager = getLaunchManager();
for (ILaunchConfiguration configuration : launchManager.getLaunchConfigurations()) {
launchConfigurationAdded(configuration);
}
launchManager.addLaunchConfigurationListener(this);
// Reorder the descriptors based on the preference
if (!configDescIds.isEmpty()) {
String[] split = configDescIds.split(","); //$NON-NLS-1$
@ -199,6 +165,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
last = desc;
}
}
// Set the active desc, with MRU, it should be the last one
if (last != null) {
setActiveLaunchDescriptor(last);
@ -224,49 +191,24 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
String elementName = element.getName();
if (elementName.equals("descriptorType")) { //$NON-NLS-1$
LaunchDescriptorTypeInfo typeInfo = new LaunchDescriptorTypeInfo(element);
addDescriptorType(typeInfo);
} else if (elementName.equals("targetType")) { //$NON-NLS-1$
LaunchTargetTypeInfo info = new LaunchTargetTypeInfo(element);
targetTypes.put(info.getId(), info);
} else if (elementName.equals("configType")) { //$NON-NLS-1$
String descriptorTypeId = element.getAttribute("descriptorType"); //$NON-NLS-1$
String targetTypeId = element.getAttribute("targetType"); //$NON-NLS-1$
String launchConfigTypeId = element.getAttribute("launchConfigurationType"); //$NON-NLS-1$
String isDefaultStr = element.getAttribute("isDefault"); //$NON-NLS-1$
boolean isDefault = isDefaultStr != null ? Boolean.parseBoolean(isDefaultStr) : false;
// add to desc type -> target type mapping
List<String> targetTypes = descriptorTargets.get(descriptorTypeId);
if (targetTypes == null) {
targetTypes = new ArrayList<>();
descriptorTargets.put(descriptorTypeId, targetTypes);
descriptorTypes.put(typeInfo.getId(), typeInfo);
// TODO figure out a better place to set the id so we don't load the type object
// until needed
descriptorTypeInfo.put(typeInfo.getType(), typeInfo);
if (configProviders.get(typeInfo.getId()) == null) {
// Make sure we initialize the list
configProviders.put(typeInfo.getId(), new ArrayList<LaunchConfigProviderInfo>());
}
targetTypes.add(targetTypeId);
// Add to desc type -> target type -> config type mapping
Map<String, String> targetConfigMap = configTypes.get(descriptorTypeId);
if (targetConfigMap == null) {
targetConfigMap = new HashMap<>();
configTypes.put(descriptorTypeId, targetConfigMap);
}
targetConfigMap.put(targetTypeId, launchConfigTypeId);
// If default, add to defaults list
if (isDefault) {
defaultTargetTypes.put(descriptorTypeId, targetTypeId);
}
// also assume that the target type works for the config type
addDefaultConfigTargetType(launchConfigTypeId, targetTypeId, isDefault);
} else if (elementName.equals("configProvider")) { //$NON-NLS-1$
LaunchConfigProviderInfo info = new LaunchConfigProviderInfo(element);
configProviders.put(info.getLaunchConfigTypeId(), info);
} else if (elementName.equals("defaultConfigTarget")) { //$NON-NLS-1$
String configTypeId = element.getAttribute("launchConfigurationType"); //$NON-NLS-1$
String targetTypeId = element.getAttribute("targetType"); //$NON-NLS-1$
String isDefaultStr = element.getAttribute("isDefault"); //$NON-NLS-1$
boolean isDefault = isDefaultStr != null ? Boolean.parseBoolean(isDefaultStr) : false;
addDefaultConfigTargetType(configTypeId, targetTypeId, isDefault);
List<LaunchConfigProviderInfo> providers = configProviders.get(info.getDescriptorTypeId());
if (providers == null) {
providers = new ArrayList<>();
configProviders.put(info.getDescriptorTypeId(), providers);
}
providers.add(info);
}
} catch (CoreException e) {
Activator.log(e.getStatus());
@ -274,6 +216,41 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
}
}
// Sort things
orderedDescriptorTypes = new ArrayList<>(descriptorTypes.values());
Collections.sort(orderedDescriptorTypes, new Comparator<LaunchDescriptorTypeInfo>() {
@Override
public int compare(LaunchDescriptorTypeInfo o1, LaunchDescriptorTypeInfo o2) {
int p1 = o1.getPriority();
int p2 = o2.getPriority();
if (p1 < p2) {
return 1;
} else if (p1 > p2) {
return -1;
} else {
return 0;
}
}
});
for (List<LaunchConfigProviderInfo> providers : configProviders.values()) {
Collections.sort(providers, new Comparator<LaunchConfigProviderInfo>() {
@Override
public int compare(LaunchConfigProviderInfo o1, LaunchConfigProviderInfo o2) {
int p1 = o1.getPriority();
int p2 = o2.getPriority();
if (p1 < p2) {
return 1;
} else if (p1 > p2) {
return -1;
} else {
return 0;
}
}
});
}
// Now that all the types are loaded, the object providers which now populate the descriptors
for (IExtension extension : extensions) {
for (IConfigurationElement element : extension.getConfigurationElements()) {
@ -281,7 +258,8 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
String elementName = element.getName();
if (elementName.equals("objectProvider")) { //$NON-NLS-1$
ILaunchObjectProvider objectProvider = (ILaunchObjectProvider) element.createExecutableExtension("class"); //$NON-NLS-1$
addObjectProvider(objectProvider);
objectProviders.add(objectProvider);
objectProvider.init(this);
}
} catch (Exception e) {
Activator.log(e); // exceptions during extension loading, log and move on
@ -290,86 +268,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
}
}
private void addDescriptorType(LaunchDescriptorTypeInfo typeInfo) throws CoreException {
descriptorTypes.put(typeInfo.getId(), typeInfo);
// TODO figure out a better place to set the id so we don't load the type object until needed
descriptorTypeInfo.put(typeInfo.getType(), typeInfo);
Iterator<LaunchDescriptorTypeInfo> iterator = orderedDescriptorTypes.iterator();
boolean inserted = false;
for (int i = 0; i < orderedDescriptorTypes.size(); ++i) {
if (iterator.next().getPriority() < typeInfo.getPriority()) {
orderedDescriptorTypes.add(i, typeInfo);
inserted = true;
break;
}
}
if (!inserted) {
orderedDescriptorTypes.add(typeInfo);
}
Activator.trace("registered descriptor type " + typeInfo.getId()); //$NON-NLS-1$
}
private void addDefaultConfigTargetType(String configTypeId, String targetTypeId, boolean isDefault) {
List<String> targetTypes = configTargetTypes.get(configTypeId);
if (targetTypes == null) {
targetTypes = new ArrayList<>();
configTargetTypes.put(configTypeId, targetTypes);
}
targetTypes.add(targetTypeId);
if (isDefault) {
defaultConfigTargetTypes.put(configTypeId, targetTypeId);
}
}
private void addObjectProvider(ILaunchObjectProvider objectProvider) {
objectProviders.add(objectProvider);
try {
objectProvider.init(this);
} catch (Exception e) {
Activator.log(e);
}
}
private void addDescriptor(Object launchObject, ILaunchDescriptor descriptor) throws CoreException {
descriptors.put(getDescriptorId(descriptor), descriptor);
objectDescriptorMap.put(launchObject, descriptor);
setActiveLaunchDescriptor(descriptor);
}
private void removeDescriptor(Object launchObject, ILaunchDescriptor descriptor) throws CoreException {
objectDescriptorMap.remove(launchObject); // remove launch object unconditionally
if (descriptor != null) {
descriptors.remove(getDescriptorId(descriptor));
if (descriptor.equals(activeLaunchDesc)) {
setActiveLaunchDescriptor(getLastUsedDescriptor());
}
// Also delete any configs created for this descriptor
Map<ILaunchConfigurationProvider, ILaunchConfiguration> configMap = configs.get(descriptor);
if (configMap != null) {
configs.remove(descriptor);
for (ILaunchConfiguration config : configMap.values()) {
config.delete();
}
}
}
}
public String getDescriptorTypeId(ILaunchDescriptorType type) {
return descriptorTypeInfo.get(type).getId();
}
private Pair<String, String> getDescriptorId(ILaunchDescriptor descriptor) {
return new Pair<String, String>(getDescriptorTypeId(descriptor.getType()), descriptor.getName());
}
private Pair<String, String> getTargetId(IRemoteConnection target) {
return new Pair<String, String>(target.getConnectionType().getId(), target.getName());
}
private String toString(Pair<String, String> key) {
return key.getFirst() + ":" + key.getSecond(); //$NON-NLS-1$
}
@ -383,78 +281,49 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
return new Pair<String, String>(key.substring(0, i), key.substring(i + 1));
}
private LaunchTargetTypeInfo getTargetTypeInfo(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
// Figure out what our target type is.
// Any target types registered with this descriptor type?
List<String> targetTypeIds = descriptorTargets.get(getDescriptorTypeId(descriptor.getType()));
if (targetTypeIds == null) {
// Nope, how about with the config type
ILaunchConfiguration config = (ILaunchConfiguration) descriptor.getAdapter(ILaunchConfiguration.class);
if (config != null) {
targetTypeIds = configTargetTypes.get(config.getType().getIdentifier());
}
}
LaunchTargetTypeInfo targetTypeInfo = null;
if (targetTypeIds != null) {
for (String targetTypeId : targetTypeIds) {
LaunchTargetTypeInfo info = targetTypes.get(targetTypeId);
if (info != null && info.matches(target)) {
if (targetTypeInfo == null) {
targetTypeInfo = info;
} else {
// Is it a better match? i.e. doesn't rely on wild cards
if ((targetTypeInfo.getOsName().isEmpty() && !info.getOsName().isEmpty())
|| (targetTypeInfo.getOsArch().isEmpty() && !info.getOsArch().isEmpty())) {
targetTypeInfo = info;
}
}
}
}
}
return targetTypeInfo;
public String getDescriptorTypeId(ILaunchDescriptorType type) {
return descriptorTypeInfo.get(type).getId();
}
private ILaunchConfigurationProvider getConfigProvider(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
if (descriptor == null || target==null) {
return null;
}
private Pair<String, String> getDescriptorId(ILaunchDescriptor descriptor) {
return new Pair<String, String>(getDescriptorTypeId(descriptor.getType()), descriptor.getName());
}
LaunchTargetTypeInfo targetTypeInfo = getTargetTypeInfo(descriptor, target);
if (targetTypeInfo == null) {
return null;
}
private Pair<String, String> getTargetId(IRemoteConnection target) {
return new Pair<String, String>(target.getConnectionType().getId(), target.getName());
}
Map<String, String> targetMap = configTypes.get(getDescriptorTypeId(descriptor.getType()));
if (targetMap != null) {
String configProviderId = targetMap.get(targetTypeInfo.getId());
LaunchConfigProviderInfo providerInfo = configProviders.get(configProviderId);
if (providerInfo != null) {
return providerInfo.getProvider();
private void addDescriptor(Object launchObject, ILaunchDescriptor descriptor) throws CoreException {
descriptors.put(getDescriptorId(descriptor), descriptor);
objectDescriptorMap.put(launchObject, descriptor);
setActiveLaunchDescriptor(descriptor);
}
private void removeDescriptor(Object launchObject, ILaunchDescriptor descriptor) throws CoreException {
objectDescriptorMap.remove(launchObject); // remove launch object unconditionally
if (descriptor != null) {
descriptors.remove(getDescriptorId(descriptor));
if (descriptor.equals(activeLaunchDesc)) {
setActiveLaunchDescriptor(getLastUsedDescriptor());
}
for (LaunchConfigProviderInfo provider : configProviders.get(getDescriptorTypeId(descriptor.getType()))) {
provider.getProvider().launchDescriptorRemoved(descriptor);
}
}
return null;
}
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
if (descriptor == null)
return null;
LaunchTargetTypeInfo targetTypeInfo = getTargetTypeInfo(descriptor, target);
if (targetTypeInfo != null) {
Map<String, String> targetMap = configTypes.get(getDescriptorTypeId(descriptor.getType()));
if (targetMap != null) {
String configTypeId = targetMap.get(targetTypeInfo.getId());
return getLaunchManager().getLaunchConfigurationType(configTypeId);
for (LaunchConfigProviderInfo provider : configProviders.get(getDescriptorTypeId(descriptor.getType()))) {
ILaunchConfigurationType type = provider.getProvider().getLaunchConfigurationType(descriptor, target);
if (type != null) {
return type;
}
}
ILaunchConfiguration config = (ILaunchConfiguration) descriptor.getAdapter(ILaunchConfiguration.class);
if (config != null)
return config.getType();
return null;
}
@ -526,7 +395,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
}
}
protected ILaunchDescriptor getLastUsedDescriptor() {
private ILaunchDescriptor getLastUsedDescriptor() {
if (descriptors.size() == 0)
return null;
ILaunchDescriptor[] descs = descriptors.values().toArray(new ILaunchDescriptor[descriptors.size()]);
@ -601,7 +470,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
IRemoteConnectionType remoteServices = remoteServicesManager.getConnectionType(id.getFirst());
if (remoteServices != null) {
IRemoteConnection storedTarget = remoteServices.getConnection(id.getSecond());
if (storedTarget != null && supportsTargetType(activeLaunchDesc, storedTarget)) {
if (storedTarget != null && supportsTarget(activeLaunchDesc, storedTarget)) {
setActiveLaunchTarget(storedTarget);
return;
}
@ -662,7 +531,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
Activator.log(e);
}
}
private Preferences getPerDescriptorStore() {
return getPerDescriptorStore(activeLaunchDesc);
}
@ -753,7 +622,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
}
}
}
private void storeLaunchMode(ILaunchDescriptor desc, ILaunchMode mode) {
if (mode != null) {
@ -766,42 +635,30 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
if (descriptor == null)
return Collections.emptyList();
// Any target types registered with this descriptor type?
List<String> targetTypeIds = descriptorTargets.get(getDescriptorTypeId(descriptor.getType()));
if (targetTypeIds == null) {
// Nope, how about with the config type
ILaunchConfiguration config = (ILaunchConfiguration) descriptor.getAdapter(ILaunchConfiguration.class);
if (config != null) {
targetTypeIds = configTargetTypes.get(config.getType().getIdentifier());
}
List<IRemoteConnection> targets = new ArrayList<>();
for (IRemoteConnection target : remoteServicesManager.getAllRemoteConnections()) {
if (supportsTarget(descriptor, target)) {
targets.add(target);
}
}
return getLaunchTargets(targetTypeIds);
return targets;
}
List<IRemoteConnection> getLaunchTargets(List<String> targetTypeIds) {
if (targetTypeIds != null && targetTypeIds.size() > 0) {
List<IRemoteConnection> targetList = new ArrayList<>();
for (IRemoteConnection connection : remoteServicesManager.getAllRemoteConnections()) {
for (String targetTypeId : targetTypeIds) {
LaunchTargetTypeInfo info = targetTypes.get(targetTypeId);
if (info != null && info.matches(connection)) {
targetList.add(connection);
break;
}
}
boolean supportsTarget(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
String descriptorTypeId = getDescriptorTypeId(descriptor.getType());
for (LaunchConfigProviderInfo provider : configProviders.get(descriptorTypeId)) {
if (provider.getProvider().supports(descriptor, target)) {
return true;
}
return targetList;
}
// Nope, return the local target, the default default
IRemoteConnectionType localServices = remoteServicesManager.getLocalConnectionType();
return localServices.getConnections();
return false;
}
public IRemoteConnection getActiveLaunchTarget() {
return activeLaunchTarget;
}
/**
* Sets preferred target for launch descriptor
* @param desc
@ -831,15 +688,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
}
// per desc store, desc can be null means it store globally
setPreference(getPerDescriptorStore(desc), PREF_ACTIVE_LAUNCH_TARGET, toString(getTargetId(target)));
// Also we have to store this in remote connection service
try {
ILaunchConfiguration config = getLaunchConfiguration(desc, target, false);
if (config != null) {
remoteLaunchConfigService.setActiveConnection(config, target);
}
} catch (CoreException e) {
Activator.log(e);
}
}
private void fireActiveLaunchTargetChanged() {
@ -858,52 +706,26 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
return targets.isEmpty() ? null : targets.get(0);
}
boolean supportsTargetType(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
return getConfigProvider(descriptor, target) != null;
}
public ILaunchConfiguration getActiveLaunchConfiguration() throws CoreException {
return getLaunchConfiguration(activeLaunchDesc, activeLaunchTarget);
}
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
return getLaunchConfiguration(descriptor, target, true);
}
private ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target,
boolean create) throws CoreException {
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target)
throws CoreException {
if (descriptor == null) {
return null;
}
ILaunchConfigurationProvider configProvider = getConfigProvider(descriptor, target);
if (configProvider != null) {
// First see if it exists yet
Map<ILaunchConfigurationProvider, ILaunchConfiguration> configMap = configs.get(descriptor);
if (configMap != null) {
ILaunchConfiguration config = configMap.get(configProvider);
if (config != null) {
return config;
}
} else {
// we'll need this in a minute
configMap = new HashMap<>();
configs.put(descriptor, configMap);
}
if (create == false)
return null;
// Not found, create, store and return it
ILaunchConfiguration config = configProvider.createLaunchConfiguration(getLaunchManager(), descriptor);
String descTypeId = getDescriptorTypeId(descriptor.getType());
for (LaunchConfigProviderInfo provider : configProviders.get(descTypeId)) {
ILaunchConfiguration config = provider.getProvider().getLaunchConfiguration(descriptor, target);
if (config != null) {
configMap.put(configProvider, config);
// since new LC is created we need to associate it with remote target
storeLaunchTarget(descriptor, target);
return config;
}
}
return (ILaunchConfiguration) descriptor.getAdapter(ILaunchConfiguration.class);
return null;
}
public void addListener(Listener listener) {
@ -920,108 +742,45 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
@Override
public void launchConfigurationAdded(ILaunchConfiguration configuration) {
Activator.trace("launch config added " + configuration); //$NON-NLS-1$
try {
LaunchConfigProviderInfo info = configProviders.get(configuration.getType().getIdentifier());
if (info != null) {
ILaunchConfigurationProvider provider = info.getProvider();
Object launchObject = provider.launchConfigurationAdded(configuration);
if (launchObject != null) {
ILaunchDescriptor descriptor = objectDescriptorMap.get(launchObject);
if (descriptor != null) {
Map<ILaunchConfigurationProvider, ILaunchConfiguration> configMap = configs.get(descriptor);
if (configMap == null) {
configMap = new HashMap<>();
configs.put(descriptor, configMap);
for (LaunchDescriptorTypeInfo descTypeInfo : orderedDescriptorTypes) {
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeInfo.getId())) {
try {
Object launchObject = providerInfo.getProvider().launchConfigurationAdded(configuration);
if (launchObject != null) {
ILaunchDescriptor descriptor = objectDescriptorMap.get(launchObject);
if (descriptor != null) {
setActiveLaunchDescriptor(descriptor);
} else {
launchObjectAdded(configuration);
}
configMap.put(provider, configuration);
return;
}
Activator.trace("launch config claimed by " + provider); //$NON-NLS-1$
return;
} catch (Throwable e) {
Activator.log(e);
}
}
} catch (Throwable e) {
// catching throwable here because provider is user class and it can do nasty things :)
Activator.log(e);
}
Activator.trace("launch config not claimed"); //$NON-NLS-1$
try {
ILaunchDescriptor desc = defaultDescriptorType.getDescriptor(configuration);
if( desc != null ) {
addDescriptor(configuration, desc);
}
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
@Override
public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
Activator.trace("launch config removed " + configuration); //$NON-NLS-1$
try {
launchObjectRemoved(configuration);
} catch (Throwable e) {
Activator.log(e);
}
// Is there any way this method is called when a LC still exists??? This may be dead code.
// configuration.getType() will fail when !configuration.exists()
if (configuration.exists()) {
try {
LaunchConfigProviderInfo info = configProviders.get(configuration.getType().getIdentifier());
if (info != null) {
ILaunchConfigurationProvider provider = info.getProvider();
if (provider.launchConfigurationRemoved(configuration)) {
Activator.trace("launch config removed by " + provider); //$NON-NLS-1$
// TODO do I need to do this if configs are launch objects?
for (LaunchDescriptorTypeInfo descTypeInfo : orderedDescriptorTypes) {
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeInfo.getId())) {
try {
if (providerInfo.getProvider().launchConfigurationRemoved(configuration)) {
return;
}
}
} catch (Throwable e) {
Activator.log(e);
}
}
Activator.trace("launch config not claimed"); //$NON-NLS-1$
ILaunchDescriptor desc = objectDescriptorMap.get(configuration);
if (desc == null) {
/* WARNING: This is slow. Call only as a last resort */
Iterator<Entry<ILaunchDescriptor, Map<ILaunchConfigurationProvider, ILaunchConfiguration>>> iter = configs.entrySet().iterator();
while (iter.hasNext()) {
Entry<ILaunchDescriptor, Map<ILaunchConfigurationProvider, ILaunchConfiguration>> e1 = iter.next();
if (e1.getValue().containsValue(configuration)) {
Iterator<Entry<ILaunchConfigurationProvider, ILaunchConfiguration>> iter2 = e1.getValue().entrySet().iterator();
while (iter2.hasNext()) {
Entry<ILaunchConfigurationProvider, ILaunchConfiguration> e2 = iter2.next();
if (e2.getValue().equals(configuration)) {
final ILaunchConfigurationProvider provider = e2.getKey();
try {
provider.launchConfigurationRemoved(e2.getValue());
Activator.trace("launch config removed by " + provider); //$NON-NLS-1$
} catch (Throwable e) {
Activator.log(e);
}
e1.getValue().remove((ILaunchConfigurationProvider) provider);
return;
}
}
break;
} catch (Throwable e) {
Activator.log(e);
}
}
} else {
Map<ILaunchConfigurationProvider, ILaunchConfiguration> configMap = configs.get(desc);
if (configMap != null) {
for (ILaunchConfigurationProvider provider : configMap.keySet()) {
try {
if (provider.launchConfigurationRemoved(configuration)) {
Activator.trace("launch config removed by " + provider); //$NON-NLS-1$
return;
}
} catch (Throwable e) {
Activator.log(e);
}
}
}
}
try {
removeDescriptor(configuration, desc);
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
@ -1066,9 +825,10 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
break;
}
}
private void fireLaunchTargetsChanged() {
if (!initialized) return;
if (!initialized)
return;
for (Listener listener : listeners) {
try {
listener.launchTargetsChanged();
@ -1083,7 +843,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
return;
fireLaunchTargetsChanged();
// if we added new target we probably want to use it
if (activeLaunchDesc != null && supportsTargetType(activeLaunchDesc, target)) {
if (activeLaunchDesc != null && supportsTarget(activeLaunchDesc, target)) {
setActiveLaunchTarget(target);
}
}
@ -1097,7 +857,4 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
}
}
public DefaultLaunchDescriptorType getDefaultDescriptorType(){
return defaultDescriptorType;
}
}

View file

@ -5,17 +5,32 @@ import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.launchbar.core.ILaunchConfigurationProvider;
public class LaunchConfigProviderInfo {
private final String launchConfigTypeId;
private final String descriptorTypeId;
private final int priority;
private IConfigurationElement element;
private ILaunchConfigurationProvider provider;
public LaunchConfigProviderInfo(IConfigurationElement element) {
this.launchConfigTypeId = element.getAttribute("launchConfigurationType"); //$NON-NLS-1$
this.descriptorTypeId = element.getAttribute("descriptorType"); //$NON-NLS-1$
String priorityStr = element.getAttribute("priority"); //$NON-NLS-1$
int priorityNum;
try {
priorityNum = Integer.parseInt(priorityStr);
} catch (NumberFormatException e) {
priorityNum = 0;
}
priority = priorityNum;
this.element = element;
}
public String getLaunchConfigTypeId() {
return launchConfigTypeId;
public String getDescriptorTypeId() {
return descriptorTypeId;
}
public int getPriority() {
return priority;
}
public ILaunchConfigurationProvider getProvider() throws CoreException {

View file

@ -1,27 +0,0 @@
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"); //$NON-NLS-1$
this.targetTypeId = element.getAttribute("targetType"); //$NON-NLS-1$
this.launchConfigTypeId = element.getAttribute("launchConfigurationType"); //$NON-NLS-1$
}
public String getDescriptorTypeId() {
return descriptorTypeId;
}
public String getTargetTypeId() {
return targetTypeId;
}
public String getLaunchConfigTypeId() {
return launchConfigTypeId;
}
}

View file

@ -1,67 +0,0 @@
/*******************************************************************************
* Copyright (c) 2014,2015 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
* Elena Laskavaia
*******************************************************************************/
package org.eclipse.launchbar.core.internal;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.remote.core.IRemoteConnection;
class LaunchTargetTypeInfo {
private static final String ANY = ""; //$NON-NLS-1$
private final String id;
private final String connectionTypeId;
private String osname;
private String osarch;
public LaunchTargetTypeInfo(IConfigurationElement ce) {
id = ce.getAttribute("id"); //$NON-NLS-1$
connectionTypeId = ce.getAttribute("connectionTypeId"); //$NON-NLS-1$
if (id == null || connectionTypeId == null)
throw new NullPointerException();
osname = ce.getAttribute("osname"); //$NON-NLS-1$
if (osname == null) {
osname = ANY;
}
osarch = ce.getAttribute("osarch"); //$NON-NLS-1$
if (osarch == null) {
osarch = ANY;
}
}
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.isEmpty() && !osname.equals(connection.getProperty(IRemoteConnection.OS_NAME_PROPERTY))) {
return false;
}
if (!osarch.isEmpty() && !osarch.equals(connection.getProperty(IRemoteConnection.OS_ARCH_PROPERTY))) {
return false;
}
return true;
}
}

View file

@ -0,0 +1,131 @@
/*******************************************************************************
* Copyright (c) 2015 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
* IBM and others who contributed to ILaunchConfigurationDelegate2
* and ILaunchConfigurationDelegate
*******************************************************************************/
package org.eclipse.launchbar.core.launch;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate2;
import org.eclipse.remote.core.IRemoteConnection;
/**
* A launch configuration delegate that accepts a IRemoteConnection as an additional
* parameter to the launch functions. Delegates who want to receive this parameter from
* the LaunchBar launch actions need to implement this interface.
*/
public interface IRemoteLaunchConfigurationDelegate extends ILaunchConfigurationDelegate2 {
/**
* Returns a launch object to use when launching the given launch
* configuration in the given mode, or <code>null</code> if a new default
* launch object should be created by the debug platform. If a launch object
* is returned, its launch mode must match that of the mode specified in
* this method call.
*
* @param configuration the configuration being launched
* @param mode the mode the configuration is being launched in
* @param target the remote connection to launch on
* @return a launch object or <code>null</code>
* @throws CoreException if unable to launch
*/
public ILaunch getLaunch(ILaunchConfiguration configuration, String mode, IRemoteConnection target) throws CoreException;
/**
* Optionally performs any required building before launching the given
* configuration in the specified mode, and returns whether the debug platform
* should perform an incremental workspace build before the launch continues.
* If <code>false</code> is returned the launch will proceed without further
* building, and if <code>true</code> is returned an incremental build will
* be performed on the workspace before launching.
* <p>
* This method is only called if the launch is invoked with flag indicating
* building should take place before the launch. This is done via the
* method
* <code>ILaunchConfiguration.launch(String mode, IProgressMonitor monitor, boolean build)</code>.
* </p>
* @param configuration the configuration being launched
* @param mode the mode the configuration is being launched in
* @param target the remote connection the configuration is being launched on
* @param monitor progress monitor, or <code>null</code>. A cancelable progress monitor is provided by the Job
* framework. It should be noted that the setCanceled(boolean) method should never be called on the provided
* monitor or the monitor passed to any delegates from this method; due to a limitation in the progress monitor
* framework using the setCanceled method can cause entire workspace batch jobs to be canceled, as the canceled flag
* is propagated up the top-level parent monitor. The provided monitor is not guaranteed to have been started.
* @return whether the debug platform should perform an incremental workspace
* build before the launch
* @throws CoreException if an exception occurs while building
*/
public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IRemoteConnection target, IProgressMonitor monitor) throws CoreException;
/**
* Returns whether a launch should proceed. This method is called after
* <code>preLaunchCheck()</code> and <code>buildForLaunch()</code> providing
* a final chance for this launch delegate to abort a launch if required.
* For example, a delegate could cancel a launch if it discovered compilation
* errors that would prevent the launch from succeeding.
*
* @param configuration the configuration being launched
* @param mode launch mode
* @param target the remote connection the configuration is being launched on
* @param monitor progress monitor, or <code>null</code>. A cancelable progress monitor is provided by the Job
* framework. It should be noted that the setCanceled(boolean) method should never be called on the provided
* monitor or the monitor passed to any delegates from this method; due to a limitation in the progress monitor
* framework using the setCanceled method can cause entire workspace batch jobs to be canceled, as the canceled flag
* is propagated up the top-level parent monitor. The provided monitor is not guaranteed to have been started.
* @return whether the launch should proceed
* @throws CoreException if an exception occurs during final checks
*/
public boolean finalLaunchCheck(ILaunchConfiguration configuration, String mode, IRemoteConnection target, IProgressMonitor monitor) throws CoreException;
/**
* Returns whether a launch should proceed. This method is called first
* in the launch sequence providing an opportunity for this launch delegate
* to abort the launch.
*
* @param configuration configuration being launched
* @param mode launch mode
* @param target the remote connection the configuration is being launched on
* @param monitor progress monitor, or <code>null</code>. A cancelable progress monitor is provided by the Job
* framework. It should be noted that the setCanceled(boolean) method should never be called on the provided
* monitor or the monitor passed to any delegates from this method; due to a limitation in the progress monitor
* framework using the setCanceled method can cause entire workspace batch jobs to be canceled, as the canceled flag
* is propagated up the top-level parent monitor. The provided monitor is not guaranteed to have been started.
* @return whether the launch should proceed
* @throws CoreException if an exception occurs while performing pre-launch checks
*/
public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IRemoteConnection target, IProgressMonitor monitor) throws CoreException;
/**
* Launches the given configuration in the specified mode, contributing
* debug targets and/or processes to the given launch object. The
* launch object has already been registered with the launch manager.
*
* @param configuration the configuration to launch
* @param mode the mode in which to launch, one of the mode constants
* defined by <code>ILaunchManager</code> -
* <code>RUN_MODE</code> or <code>DEBUG_MODE</code>.
* @param target the remote connection the configuration to launched on
* @param monitor progress monitor, or <code>null</code> progress monitor, or <code>null</code>. A cancelable progress
* monitor is provided by the Job framework. It should be noted that the setCanceled(boolean) method should
* never be called on the provided monitor or the monitor passed to any delegates from this method; due to a
* limitation in the progress monitor framework using the setCanceled method can cause entire workspace batch
* jobs to be canceled, as the canceled flag is propagated up the top-level parent monitor.
* The provided monitor is not guaranteed to have been started.
* @param launch the launch object to contribute processes and debug
* targets to
* @exception CoreException if launching fails
*/
public void launch(ILaunchConfiguration configuration, String mode, IRemoteConnection target, ILaunch launch, IProgressMonitor monitor) throws CoreException;
}

View file

@ -0,0 +1,59 @@
/*******************************************************************************
* Copyright (c) 2015 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
*******************************************************************************/
package org.eclipse.launchbar.core.launch;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
import org.eclipse.remote.core.IRemoteConnection;
public abstract class RemoteLaunchConfigurationDelegate extends LaunchConfigurationDelegate
implements IRemoteLaunchConfigurationDelegate {
@Override
public ILaunch getLaunch(ILaunchConfiguration configuration, String mode, IRemoteConnection target)
throws CoreException {
return getLaunch(configuration, mode);
}
@Override
public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IRemoteConnection target,
IProgressMonitor monitor) throws CoreException {
return buildForLaunch(configuration, mode, monitor);
}
@Override
public boolean finalLaunchCheck(ILaunchConfiguration configuration, String mode, IRemoteConnection target,
IProgressMonitor monitor) throws CoreException {
return finalLaunchCheck(configuration, mode, monitor);
}
@Override
public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IRemoteConnection target,
IProgressMonitor monitor) throws CoreException {
return preLaunchCheck(configuration, mode, monitor);
}
@Override
public void launch(ILaunchConfiguration configuration, String mode, IRemoteConnection target, ILaunch launch,
IProgressMonitor monitor) throws CoreException {
launch(configuration, mode, launch, monitor);
}
@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
throws CoreException {
// do nothing by default assuming the subclass has implemented a proper remote launch() method.
}
}

View file

@ -14,6 +14,8 @@ import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.launchbar.ui.internal.messages"; //$NON-NLS-1$
public static String BuildActiveCommandHandler_0;
public static String BuildActiveCommandHandler_1;
public static String ConfigSelector_0;
public static String ConfigSelector_1;
public static String ConfigSelector_2;

View file

@ -35,7 +35,10 @@ import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate2;
import org.eclipse.launchbar.core.internal.LaunchBarManager;
import org.eclipse.launchbar.core.launch.IRemoteLaunchConfigurationDelegate;
import org.eclipse.launchbar.ui.internal.Activator;
import org.eclipse.launchbar.ui.internal.Messages;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
@ -52,23 +55,25 @@ public class BuildActiveCommandHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
new UIJob(Display.getDefault(), "Building Active Configuration") {
@Override
public boolean belongsTo(Object family) {
return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family);
}
try {
LaunchBarManager launchBarManager = Activator.getDefault().getLaunchBarUIManager().getManager();
final ILaunchConfiguration config = launchBarManager.getActiveLaunchConfiguration();
final ILaunchMode launchMode = launchBarManager.getActiveLaunchMode();
final IRemoteConnection target = launchBarManager.getActiveLaunchTarget();
public IStatus runInUIThread(IProgressMonitor monitor) {
try {
final LaunchBarManager launchBarManager = Activator.getDefault().getLaunchBarUIManager().getManager();
final ILaunchConfiguration config = launchBarManager.getActiveLaunchConfiguration();
new UIJob(Display.getDefault(), Messages.BuildActiveCommandHandler_0) {
@Override
public boolean belongsTo(Object family) {
return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family);
}
public IStatus runInUIThread(IProgressMonitor monitor) {
final Collection<IProject> projects = getProjects(config);
if (BuildAction.isSaveAllSet()) {
saveEditors(projects);
}
new Job("Building Active Configuration") {
new Job(Messages.BuildActiveCommandHandler_1) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
@ -77,25 +82,36 @@ public class BuildActiveCommandHandler extends AbstractHandler {
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
return Status.OK_STATUS;
}
ILaunchMode launchMode = launchBarManager.getActiveLaunchMode();
String mode = launchMode.getIdentifier();
String mode = launchMode != null ? launchMode.getIdentifier() : "run"; //$NON-NLS-1$
Set<String> modes = new HashSet<>();
modes.add(mode);
ILaunchDelegate delegate = config.getType().getPreferredDelegate(modes);
if (delegate == null)
delegate = config.getType().getDelegates(modes)[0];
ILaunchConfigurationDelegate configDel = delegate.getDelegate();
if (configDel instanceof ILaunchConfigurationDelegate2) {
if (configDel instanceof IRemoteLaunchConfigurationDelegate) {
IRemoteLaunchConfigurationDelegate configDel2 = (IRemoteLaunchConfigurationDelegate)configDel;
boolean ret;
ret = configDel2.preLaunchCheck(config, mode, target, monitor);
if (!ret) {
return Status.CANCEL_STATUS;
}
if (!configDel2.buildForLaunch(config, mode, target, monitor)) {
return Status.OK_STATUS;
}
} else if (configDel instanceof ILaunchConfigurationDelegate2) {
ILaunchConfigurationDelegate2 configDel2 = (ILaunchConfigurationDelegate2)configDel;
boolean ret;
ret = configDel2.preLaunchCheck(config, mode, monitor);
if (!ret)
if (!ret) {
return Status.CANCEL_STATUS;
if (!configDel2.buildForLaunch(config, mode, monitor))
}
if (!configDel2.buildForLaunch(config, mode, monitor)) {
return Status.OK_STATUS;
}
}
// Fall through, do a normal build
if (projects.isEmpty()) {
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
@ -111,14 +127,14 @@ public class BuildActiveCommandHandler extends AbstractHandler {
}
}
}.schedule();
} catch (CoreException e) {
return e.getStatus();
}
return Status.OK_STATUS;
};
}.schedule();
return Status.OK_STATUS;
};
}.schedule();
} catch (CoreException e) {
return e.getStatus();
}
return Status.OK_STATUS;
}

View file

@ -17,7 +17,6 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
@ -188,23 +187,6 @@ public abstract class CSelector extends Composite {
}
};
private ICellModifier modifier = new ICellModifier() {
@Override
public void modify(Object element, String property, Object value) {
handleEdit(element);
}
@Override
public Object getValue(Object element, String property) {
return null;
}
@Override
public boolean canModify(Object element, String property) {
return isEditable(element);
}
};
public CSelector(Composite parent, int style) {
super(parent, style);
@ -439,7 +421,6 @@ public abstract class CSelector extends Composite {
protected void initializeListViewer(LaunchBarListViewer listViewer) {
listViewer.setContentProvider(contentProvider);
listViewer.setLabelProvider(labelProvider);
listViewer.setCellModifier(modifier);
listViewer.setComparator(sorter);
listViewer.setHistoryComparator(sorterTop);
}

View file

@ -24,7 +24,6 @@ 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.internal.LaunchBarManager;
import org.eclipse.launchbar.ui.internal.Activator;
import org.eclipse.launchbar.ui.internal.DefaultDescriptorLabelProvider;
import org.eclipse.launchbar.ui.internal.LaunchBarUIManager;
@ -198,12 +197,7 @@ public class ConfigSelector extends CSelector {
new Job(Messages.ConfigSelector_3) {
protected IStatus run(IProgressMonitor monitor) {
try {
final LaunchBarManager barManager = uiManager.getManager();
final ILaunchDescriptor desc = barManager.getDefaultDescriptorType().getDescriptor(wizard.getWorkingCopy());
if (desc != null) {
barManager.setLaunchMode(desc, wizard.getLaunchMode());
}
wizard.getWorkingCopy().doSave();// that would trigger active config change
wizard.getWorkingCopy().doSave();
return Status.OK_STATUS;
} catch (CoreException e) {
return e.getStatus();

View file

@ -6,7 +6,6 @@ import java.util.List;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.IFontProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
@ -31,8 +30,6 @@ import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.graphics.Color;
@ -61,7 +58,6 @@ public class LaunchBarListViewer extends StructuredViewer {
private final int maxScrollBucket = 6;
private int separatorIndex = -1;
private boolean historySupported = true;
private ICellModifier modifier;
private ViewerComparator historyComparator;
private boolean finalSelection = false;
private FilterControl filterControl;
@ -169,19 +165,16 @@ public class LaunchBarListViewer extends StructuredViewer {
private Color outlineColor = getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
private Color highlightColor = getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
private ILabelProvider labelProvider;
private ICellModifier modifer;
@Override
public String toString() {
return "[" + index + "] " + labelProvider.getText(element); //$NON-NLS-1$ //$NON-NLS-2$
}
public ListItem(Composite parent, int style, Object element, int index, ILabelProvider labelProvider,
ICellModifier modifier) {
public ListItem(Composite parent, int style, Object element, int index, ILabelProvider labelProvider) {
super(parent, style);
this.element = element;
this.index = index;
this.labelProvider = labelProvider;
this.modifer = modifier;
setData(element);
addPaintListener(new PaintListener() {
@Override
@ -199,12 +192,9 @@ public class LaunchBarListViewer extends StructuredViewer {
protected void lazyInit() {
Image image = labelProvider.getImage(element);
boolean editable = isEditable(element);
int columns = 1;
if (image != null)
columns++;
if (editable)
columns++;
GridLayout layout = new GridLayout(columns, false);
layout.marginWidth = layout.marginHeight = 7;
setLayout(layout);
@ -235,31 +225,9 @@ public class LaunchBarListViewer extends StructuredViewer {
label = createLabel(this, element);
label.addMouseListener(listItemMouseListener);
label.addMouseTrackListener(listItemMouseTrackListener);
if (editable) {
editButton = new EditButton(this, SWT.NONE);
editButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// Need to run this after the current event storm
// Or we get a disposed error.
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (editButton.isSelected())
handleEdit(element);
}
});
}
});
editButton.setBackground(backgroundColor);
editButton.addMouseTrackListener(listItemMouseTrackListener);
editButton.addTraverseListener(listItemTraverseListener);
editButton.addKeyListener(lisItemKeyListener);
} else {
// add traverse listnener to control which will have keyboard focus
addTraverseListener(listItemTraverseListener);
addKeyListener(lisItemKeyListener);
}
// add traverse listnener to control which will have keyboard focus
addTraverseListener(listItemTraverseListener);
addKeyListener(lisItemKeyListener);
setBackground(backgroundColor);
layout(true);
@ -286,19 +254,6 @@ public class LaunchBarListViewer extends StructuredViewer {
}
}
protected boolean isEditable(Object element) {
if (modifer != null) {
return modifer.canModify(element, null);
}
return false;
}
protected void handleEdit(Object element) {
if (modifer != null) {
modifer.modify(element, null, null);
}
}
@Override
public void setBackground(Color color) {
super.setBackground(color);
@ -470,7 +425,7 @@ public class LaunchBarListViewer extends StructuredViewer {
}
private ListItem createListItem(Object[] elements, int i) {
ListItem item = new ListItem(listComposite, SWT.NONE, elements[i], i, (ILabelProvider) getLabelProvider(), modifier);
ListItem item = new ListItem(listComposite, SWT.NONE, elements[i], i, (ILabelProvider) getLabelProvider());
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
item.setLayoutData(gd);
if (i <= maxScrollBucket) { // this is how many visible by default
@ -601,10 +556,6 @@ public class LaunchBarListViewer extends StructuredViewer {
return historyPref;
}
public void setCellModifier(ICellModifier modifier) {
this.modifier = modifier;
}
public int getItemCount() {
return listItems.length;
}

View file

@ -21,13 +21,14 @@ import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.Viewer;
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.Messages;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.ui.IRemoteUIConnectionService;
import org.eclipse.remote.ui.RemoteConnectionsLabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
@ -37,7 +38,6 @@ import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@ -79,29 +79,7 @@ public class TargetSelector extends CSelector {
}
});
setLabelProvider(new LabelProvider() {
@Override
public Image getImage(Object element) {
if (element instanceof IRemoteConnection) {
IRemoteConnection target = (IRemoteConnection) element;
if (target.isOpen()) {
return Activator.getDefault().getImage("icons/connected.png");
} else {
return Activator.getDefault().getImage("icons/disconnected.png");
}
}
return super.getImage(element);
}
@Override
public String getText(Object element) {
if (element instanceof IRemoteConnection) {
IRemoteConnection target = (IRemoteConnection) element;
return target.getName();
}
return super.getText(element);
}
});
setLabelProvider(new RemoteConnectionsLabelProvider());
setSorter(new Comparator<Object>() {
@Override
@ -163,8 +141,7 @@ public class TargetSelector extends CSelector {
public void mouseUp(org.eclipse.swt.events.MouseEvent event) {
try {
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
// TODO the command id should be in a remote ui interface
Command newConnectionCmd = commandService.getCommand("org.eclipse.remote.ui.command.newConnection"); //$NON-NLS-1$
Command newConnectionCmd = commandService.getCommand(IRemoteUIConnectionService.NEW_CONNECTION_COMMAND);
newConnectionCmd.executeWithChecks(new ExecutionEvent());
} catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
Activator.log(e);

View file

@ -1,3 +1,5 @@
BuildActiveCommandHandler_0=Building Active Configuration
BuildActiveCommandHandler_1=Building Active Configuration
ConfigSelector_0=No Launch Configurations
ConfigSelector_1=Launch configuration
ConfigSelector_2=Create New Configuration...

View file

@ -10,14 +10,27 @@
*******************************************************************************/
package org.eclipse.launchbar.core.internal;
import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@ -38,22 +51,22 @@ import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.launchbar.core.DefaultLaunchConfigProvider;
import org.eclipse.launchbar.core.ILaunchConfigurationProvider;
import org.eclipse.launchbar.core.ILaunchDescriptor;
import org.eclipse.launchbar.core.ILaunchDescriptorType;
import org.eclipse.launchbar.core.ProjectLaunchConfigurationProvider;
import org.eclipse.launchbar.core.ProjectLaunchDescriptor;
import org.eclipse.launchbar.core.ProjectPerTypeLaunchConfigProvider;
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.eclipse.remote.core.launch.IRemoteLaunchConfigService;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
@SuppressWarnings("restriction")
@SuppressWarnings({"restriction", "nls"})
@FixMethodOrder(MethodSorters.JVM)
public class LaunchBarManager2Test {
private LaunchBarManager manager;
@ -69,13 +82,12 @@ public class LaunchBarManager2Test {
IEclipsePreferences store = new EclipsePreferences();
private ArrayList<Object> elements;
private IExtension extension;
private String localTargetTypeId;
private static final String localTargetTypeId = "org.eclipse.remote.LocalServices";
private String descriptorTypeId;
private IRemoteConnection localTarget;
private String launchObject;
private IRemoteServicesManager remoteServiceManager;
private IRemoteConnection otherTarget;
private String otherTargetTypeId;
private List<IRemoteConnection> targets;
public class FixedLaunchBarManager extends LaunchBarManager {
@ -98,11 +110,6 @@ public class LaunchBarManager2Test {
return store;
}
@Override
IRemoteLaunchConfigService getRemoteLaunchConfigService() {
return mock(IRemoteLaunchConfigService.class);
}
@Override
IRemoteServicesManager getRemoteServicesManager() {
return remoteServiceManager;
@ -114,30 +121,31 @@ public class LaunchBarManager2Test {
basicSetup();
}
protected IConfigurationElement mockConfigTypeElement(String targetTypeId, String descriptorTypeId, String launchConfigTypeId) {
IConfigurationElement element = mockElementAndAdd("configType");
doReturn(descriptorTypeId).when(element).getAttribute("descriptorType");
doReturn(targetTypeId).when(element).getAttribute("targetType");
doReturn(launchConfigTypeId).when(element).getAttribute("launchConfigurationType");
return element;
}
protected ILaunchConfigurationProvider mockProviderTypes(ILaunchConfigurationProvider provider)
throws CoreException {
doReturn(launchConfigType).when(provider).getLaunchConfigurationType();
doReturn(launchConfig).when(provider).createLaunchConfiguration(lman, descriptor);
return provider;
}
protected void mockProviderElement(ILaunchConfigurationProvider provider) throws CoreException {
protected void mockProviderElement(String descriptorTypeId, int priority, ILaunchConfigurationProvider provider) throws CoreException {
IConfigurationElement element = mockElementAndAdd("configProvider");
doReturn(launchConfigType.getIdentifier()).when(element).getAttribute("launchConfigurationType");
doReturn(descriptorTypeId).when(element).getAttribute("descriptorType");
doReturn(Integer.toString(priority)).when(element).getAttribute("priority");
doReturn(provider).when(element).createExecutableExtension("class");
}
protected IConfigurationElement mockDescriptorTypeElement(String descriptorTypeId) {
protected ILaunchConfigurationProvider mockProviderElement(String descriptorTypeId, int priority, ILaunchDescriptor descriptor, IRemoteConnection target,
ILaunchConfiguration config, Object launchObj) throws CoreException {
ILaunchConfigurationProvider provider = mock(ILaunchConfigurationProvider.class);
mockProviderElement(descriptorTypeId, priority, provider);
doReturn(config.getType()).when(provider).getLaunchConfigurationType(descriptor, target);
doReturn(config).when(provider).getLaunchConfiguration(descriptor, target);
doReturn(true).when(provider).supports(descriptor, target);
doReturn(true).when(provider).ownsLaunchConfiguration(config);
doReturn(launchObj).when(provider).launchConfigurationAdded(config);
return provider;
}
protected IConfigurationElement mockDescriptorTypeElement(String descriptorTypeId, int priority, ILaunchDescriptorType descriptorType)
throws CoreException {
IConfigurationElement element = mockElementAndAdd("descriptorType");
doReturn(descriptorTypeId).when(element).getAttribute("id");
doReturn(Integer.toString(priority)).when(element).getAttribute("priority");
doReturn(descriptorType).when(element).createExecutableExtension("class");
return element;
}
@ -154,34 +162,12 @@ public class LaunchBarManager2Test {
return element;
}
protected String mockLocalTargetElement() {
IConfigurationElement element = mockElementAndAdd("targetType");
String targetTypeId = "org.eclipse.launchbar.core.targetType.local";
doReturn(targetTypeId).when(element).getAttribute("id");
doReturn("org.eclipse.remote.LocalServices").when(element).getAttribute("connectionTypeId");
return targetTypeId;
}
protected IConfigurationElement mockTargetElement(String id) {
IConfigurationElement element = mockElementAndAdd("targetType");
doReturn(id).when(element).getAttribute("id");
doReturn(id).when(element).getAttribute("connectionTypeId");
return element;
}
protected void mockLaunchObjectOnDescriptor(Object launchObject) throws CoreException {
doReturn(true).when(descriptorType).ownsLaunchObject(launchObject);
doReturn(descriptor).when(descriptorType).getDescriptor(launchObject);
doReturn(launchObject.toString()).when(descriptor).getName();
}
protected IConfigurationElement mockDescriptorTypeElement(String descriptorTypeId, ILaunchDescriptorType descriptorType)
throws CoreException {
IConfigurationElement element = mockDescriptorTypeElement(descriptorTypeId);
doReturn(descriptorType).when(element).createExecutableExtension("class");
return element;
}
private ILaunchConfiguration mockLC(String string, ILaunchConfigurationType lctype2) throws CoreException {
ILaunchConfiguration lc = mock(ILaunchConfiguration.class);
doReturn(string).when(lc).getName();
@ -238,9 +224,9 @@ public class LaunchBarManager2Test {
}
@Override
public Object getAdapter(Class adapter) {
public <T> T getAdapter(Class<T> adapter) {
if (adapter.isInstance(conf))
return conf;
return adapter.cast(conf);
return super.getAdapter(adapter);
}
@ -271,37 +257,38 @@ public class LaunchBarManager2Test {
doReturn(new ILaunchConfiguration[] {}).when(lman).getLaunchConfigurations();
remoteServiceManager = spy(Activator.getService(IRemoteServicesManager.class));
manager = new FixedLaunchBarManager();
// mock
// lc
launchConfigType = mockLCType("lctype1");
launchConfig = mockLC("bla", launchConfigType);
// launch config type
mockLaunchModes(launchConfigType, "run", "debug");
// target
localTargetTypeId = mockLocalTargetElement();
// launch descriptor and type
descriptorType = mock(ILaunchDescriptorType.class);
descriptorTypeId = "descType";
mockDescriptorTypeElement(descriptorTypeId, descriptorType);
descriptor = mock(ILaunchDescriptor.class);
doReturn(descriptorType).when(descriptor).getType();
// configProvider
provider = mock(ILaunchConfigurationProvider.class);
mockProviderElement(provider);
mockProviderTypes(provider);
launchObject = "test";
mockLaunchObjectOnDescriptor(launchObject);
localTarget = manager.getRemoteServicesManager().getLocalConnectionType().getConnections().get(0);
otherTargetTypeId = "target2";
mockTargetElement(otherTargetTypeId);
// mock
launchObject = "test";
// remote connections
otherTarget = mock(IRemoteConnection.class);
IRemoteConnectionType rtype = mock(IRemoteConnectionType.class);
doReturn(rtype).when(otherTarget).getConnectionType();
doReturn(otherTargetTypeId).when(rtype).getId();
doReturn("otherTargetType").when(rtype).getId();
targets = Arrays.asList(new IRemoteConnection[] { otherTarget, localTarget });
// configType
mockConfigTypeElement(otherTargetTypeId, descriptorTypeId, launchConfigType.getIdentifier());
// lc
String launchConfigTypeId = "lctype1";
launchConfigType = mockLCType(launchConfigTypeId);
launchConfig = mockLC(launchObject, launchConfigType);
// launch config type
mockLaunchModes(launchConfigType, "run", "debug");
// launch descriptor and type
descriptorType = mock(ILaunchDescriptorType.class);
descriptorTypeId = "descType";
mockDescriptorTypeElement(descriptorTypeId, 10, descriptorType);
descriptor = mock(ILaunchDescriptor.class);
doReturn(descriptorType).when(descriptor).getType();
doReturn(descriptor).when(descriptorType).getDescriptor(launchObject);
// configProvider
provider = mockProviderElement(descriptorTypeId, 10, descriptor, otherTarget, launchConfig, launchObject);
mockLaunchObjectOnDescriptor(launchObject);
// default descriptor
String defaultDescTypeId = "defaultDescType";
mockDescriptorTypeElement(defaultDescTypeId, 0, new DefaultLaunchDescriptorType());
ILaunchConfigurationProvider defaultProvider = new DefaultLaunchConfigProvider();
mockProviderElement(defaultDescTypeId, 0, defaultProvider);
}
@Test
@ -339,58 +326,29 @@ public class LaunchBarManager2Test {
verify(descriptorType).ownsLaunchObject(any());
}
@Test
public void testAddConfigProviderNoTarget_failing() {
// here target type is not defined
try {
basicSetupOnly();
// configType
mockConfigTypeElement("xxx", descriptorTypeId, launchConfigType.getIdentifier());
init();
//fail("Expecting exctpion because target is not registered");
} catch (Exception e) {
// pass
fail();// fail for now when this is fixed - fix the test
}
}
//
// @Test
// public void testAddConfigProviderNoDesc() {
// try {
// manager.addTargetType(targetType);
// manager.addConfigProvider(descType.getId(), targetType.getId(), false, provider);
// fail("Expecting exctpion because target is not registered");
// } catch (Exception e) {
// // pass
// }
// }
//
@Test
public void testAddConfigMappingTwo() throws CoreException {
basicSetupOnly();
String t2 = "t2";
mockTargetElement(t2);
IRemoteConnection target = mockRemoteConnection(t2);
mockConfigTypeElement(t2, descriptorTypeId, launchConfigType.getIdentifier());
init();
IRemoteConnection target = mockRemoteConnection("t2");
mockProviderElement(descriptorTypeId, 10, descriptor, target, launchConfig, launchObject);
// now create another lc type, which is not registered in config type
ILaunchConfigurationType lctype2 = mockLCType("lctypeid2");
ILaunchConfiguration lc2 = mockLC("bla2", lctype2);
ConfigBasedLaunchDescriptor desc2 = new ConfigBasedLaunchDescriptor(descriptorType, lc2);
mockProviderElement(descriptorTypeId, 10, desc2, target, lc2, lc2);
init();
// it return original lctype because we did not associate this dynmaically
assertEquals(launchConfigType, manager.getLaunchConfigurationType(desc2, target));
assertEquals(launchConfigType, manager.getLaunchConfigurationType(descriptor, target));
}
@Test
public void testAddConfigProviderTwo2() throws CoreException {
basicSetupOnly();
String t2 = "t2";
mockTargetElement(t2);
IRemoteConnection target = mockRemoteConnection(t2);
mockConfigTypeElement(t2, descriptorTypeId, launchConfigType.getIdentifier());
IRemoteConnection target = mockRemoteConnection("t2");
mockProviderElement(descriptorTypeId, 15, descriptor, target, launchConfig, launchObject);
ILaunchConfigurationType lctype2 = mockLCType("lctypeid2");
mockConfigTypeElement(t2, descriptorTypeId, lctype2.getIdentifier());
ILaunchConfiguration lc2 = mockLC("lc2", lctype2);
mockProviderElement(descriptorTypeId, 20, descriptor, target, lc2, launchObject);
init();
assertEquals(lctype2, manager.getLaunchConfigurationType(descriptor, target));
}
@ -408,8 +366,8 @@ public class LaunchBarManager2Test {
public void testGetLaunchTargetsNoConfigMapping() throws CoreException {
basicSetupOnly();
elements.clear();
mockLocalTargetElement();
mockDescriptorTypeElement(descriptorTypeId, descriptorType);
mockDescriptorTypeElement(descriptorTypeId, 10, descriptorType);
mockProviderElement(descriptorTypeId, 10, new DefaultLaunchConfigProvider());
init();
manager.launchObjectAdded(launchObject);
ILaunchDescriptor desc = manager.getActiveLaunchDescriptor();
@ -421,9 +379,8 @@ public class LaunchBarManager2Test {
public void testGetLaunchTargetsConfigMapping() throws CoreException {
basicSetupOnly();
elements.clear();
mockLocalTargetElement();
mockDescriptorTypeElement(descriptorTypeId, descriptorType);
mockConfigTypeElement(localTargetTypeId, descriptorTypeId, launchConfigType.getIdentifier());
mockDescriptorTypeElement(descriptorTypeId, 10, descriptorType);
mockProviderElement(descriptorTypeId, 10, descriptor, localTarget, launchConfig, launchObject);
init();
manager.launchObjectAdded(launchObject);
ILaunchDescriptor desc = manager.getActiveLaunchDescriptor();
@ -539,7 +496,16 @@ public class LaunchBarManager2Test {
public ILaunchConfiguration mockLCAttribute(ILaunchConfiguration lc, String attr, String value) {
try {
when(lc.getAttribute(eq(attr), anyString())).thenReturn(value);
doReturn(value).when(lc).getAttribute(eq(attr), anyString());
} catch (CoreException e) {
throw new RuntimeException(e);
}
return lc;
}
public ILaunchConfiguration mockLCAttribute(ILaunchConfiguration lc, String attr, boolean value) {
try {
doReturn(value).when(lc).getAttribute(attr, false);
} catch (CoreException e) {
throw new RuntimeException(e);
}
@ -583,29 +549,53 @@ public class LaunchBarManager2Test {
return "pbtype";
}
}
String ORIGINAL_NAME = org.eclipse.launchbar.core.internal.Activator.PLUGIN_ID + ".originalName";
String PROJECT_CONFIG = org.eclipse.launchbar.core.internal.Activator.PLUGIN_ID + ".projectConfig";
protected void projectMappingSetup() throws CoreException {
descriptorType = new ProjectBasedLaunchDescriptorType();
descriptorTypeId = ((ProjectBasedLaunchDescriptorType) descriptorType).getId();
provider = new ProjectLaunchConfigurationProvider() {
@Override
public ILaunchConfigurationType getLaunchConfigurationType() throws CoreException {
return launchConfigType;
}
};
aaa = mockProject("aaa");
descriptor = new ProjectLaunchDescriptor(descriptorType, aaa);
// setup some stuff
localTargetTypeId = mockLocalTargetElement();
IConfigurationElement element = mockDescriptorTypeElement(descriptorTypeId, descriptorType);
// configType
mockConfigTypeElement(localTargetTypeId, descriptorTypeId, launchConfigType.getIdentifier());
mockDescriptorTypeElement(descriptorTypeId, 10, descriptorType);
//lc = provider.createLaunchConfiguration(lman, descType.getDescriptor(aaa));
mockLCProject(launchConfig, aaa);
mockLCAttribute(launchConfig, ORIGINAL_NAME, aaa.getName());
mockProviderElement(provider);
mockLCAttribute(launchConfig, PROJECT_CONFIG, true);
assertEquals(0, manager.getLaunchDescriptors().length);
provider = new ProjectPerTypeLaunchConfigProvider() {
@Override
protected String getRemoteConnectionTypeId() {
return localTargetTypeId;
}
@Override
protected String getLaunchConfigurationTypeId() {
return launchConfigType.getIdentifier();
}
@Override
public boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
return configuration == launchConfig;
}
@Override
protected Object getLaunchObject(ILaunchConfiguration configuration) throws CoreException {
if (configuration == launchConfig)
return aaa;
return null;
}
@Override
protected Object getLaunchObject(ILaunchDescriptor d) {
if (descriptor == d) {
return aaa;
}
return null;
}
};
mockProviderElement(descriptorTypeId, 10, provider);
init();
}
@ -621,6 +611,7 @@ public class LaunchBarManager2Test {
assertTrue(manager.getLaunchDescriptors()[0].getName().startsWith(aaa.getName()));
// user clicked on descriptor gear to edit lc, new lc is created
manager.launchConfigurationAdded(launchConfig);
// the project launch config should have caught this
assertEquals(1, manager.getLaunchDescriptors().length);
assertEquals(launchConfig.getName(), manager.getLaunchDescriptors()[0].getName());
// user cloned lc and changed some settings
@ -841,17 +832,12 @@ public class LaunchBarManager2Test {
@Test
public void testGetLaunchTarget() throws CoreException {
final List<IRemoteConnection> list = manager.getLaunchTargets(Collections.singletonList(localTargetTypeId));
IRemoteConnectionType targetType = remoteServiceManager.getConnectionType(localTargetTypeId);
final List<IRemoteConnection> list = targetType.getConnections();
assertEquals(1, list.size());
assertEquals(localTarget, list.get(0));
}
@Test
public void testGetLaunchTargetNone() throws CoreException {
final List<IRemoteConnection> list = manager.getLaunchTargets(Collections.singletonList("xxx"));
assertEquals(0, list.size());
}
@Test
public void testGetLaunchConfigurationType() throws CoreException {
assertNotNull(manager.getLaunchConfigurationType(descriptor, otherTarget));
@ -870,7 +856,7 @@ public class LaunchBarManager2Test {
@Test
public void testGetLaunchConfiguration() throws CoreException {
basicSetup();
assertTrue(manager.supportsTargetType(descriptor, otherTarget));
assertTrue(manager.supportsTarget(descriptor, otherTarget));
assertNotNull(manager.getLaunchConfiguration(descriptor, otherTarget));
}
@ -907,8 +893,7 @@ public class LaunchBarManager2Test {
public void testLaunchConfigurationAdded2() throws CoreException {
globalmodes.clear();
ILaunchMode mode = mockLaunchModes(launchConfigType, "foo")[0];
// XXX if provider returns object not known by launch bar bad things happen
//doReturn(launchObject).when(provider).launchConfigurationAdded(lc);
manager.launchObjectAdded(launchObject);
manager.launchConfigurationAdded(launchConfig);
verify(provider).launchConfigurationAdded(launchConfig);
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
@ -926,7 +911,6 @@ public class LaunchBarManager2Test {
ILaunchConfigurationType lctype2 = mockLCType("lctype2");
ILaunchConfiguration lc2 = mockLC("lc2", lctype2);
manager.launchConfigurationAdded(lc2);
verifyZeroInteractions(provider);
//verify(provider).launchConfigurationAdded(lc2);
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
assertEquals(1, launchDescriptors.length);
@ -966,34 +950,4 @@ public class LaunchBarManager2Test {
}
}
@Test
public void testExtensionConfigDefaultProvider() throws CoreException {
basicSetupOnly();
elements.clear();
IConfigurationElement element = mockElementAndAdd("defaultConfigTarget");
doReturn(launchConfigType.getIdentifier()).when(element).getAttribute("launchConfigurationType");
localTargetTypeId = "x2";
mockTargetElement(localTargetTypeId);
doReturn(localTargetTypeId).when(element).getAttribute("targetType");
init();
manager.launchConfigurationAdded(launchConfig);
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
assertEquals(1, launchDescriptors.length);
assertNotNull(launchDescriptors[0]);
assertEquals(launchConfig.getName(), launchDescriptors[0].getName());
assertEquals(null, manager.getActiveLaunchTarget());
}
@Test
public void testExtensionDescriptorTypeBad() throws CoreException {
basicSetupOnly();
elements.clear();
IConfigurationElement element = mockDescriptorTypeElement("d1", descriptorType = mock(ILaunchDescriptorType.class));
doThrow(new CoreException(new Status(1, "a", "n"))).when(element).createExecutableExtension("class");
doReturn(new ILaunchConfiguration[] { launchConfig }).when(lman).getLaunchConfigurations();
mockConfigTypeElement(localTargetTypeId, "d1", launchConfigType.getIdentifier());
init();
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
assertEquals(1, launchDescriptors.length); // XXX should be 0
}
}

View file

@ -3,7 +3,10 @@ package org.eclipse.launchbar.core.internal;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@ -24,8 +27,9 @@ import org.eclipse.launchbar.core.ILaunchDescriptorType;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteConnectionType;
import org.eclipse.remote.core.IRemoteServicesManager;
import org.eclipse.remote.core.launch.IRemoteLaunchConfigService;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@SuppressWarnings("nls")
public class LaunchBarManagerTest {
@ -48,17 +52,17 @@ public class LaunchBarManagerTest {
// Mocking
ILaunchConfigurationType launchConfigType = mock(ILaunchConfigurationType.class);
ILaunchConfiguration launchConfig = mock(ILaunchConfiguration.class);
String launchConfigName = "launchConfig";
doReturn(launchConfigName).when(launchConfig).getName();
doReturn(launchConfigName).when(launchConfig).getAttribute(eq("org.eclipse.launchbar.core.originalName"), anyString());
doReturn(true).when(launchConfigType).isPublic();
doReturn(launchConfigType).when(launchConfig).getType();
doReturn("dummy").when(launchConfigType).getIdentifier();
doReturn("launchConfigType").when(launchConfigType).getIdentifier();
doReturn(true).when(launchConfigType).supportsMode("run");
doReturn(true).when(launchConfigType).supportsMode("debug");
// Inject the launch config
LaunchBarManager manager = new LaunchBarManager(false) {
IRemoteLaunchConfigService getRemoteLaunchConfigService() {
return mock(IRemoteLaunchConfigService.class);
}
};
manager.init();
manager.launchConfigurationAdded(launchConfig);
@ -94,14 +98,6 @@ public class LaunchBarManagerTest {
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("connectionTypeId");
// fake launch object
String launchObject = "fakeObject";
@ -143,22 +139,23 @@ public class LaunchBarManagerTest {
element = mock(IConfigurationElement.class);
elements.add(element);
doReturn("configProvider").when(element).getName();
doReturn(launchConfigTypeId).when(element).getAttribute("launchConfigurationType");
doReturn(descriptorTypeId).when(element).getAttribute("descriptorType");
doReturn("10").when(element).getAttribute("priority");
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");
ILaunchConfiguration launchConfig = mock(ILaunchConfiguration.class);
doReturn(launchConfig).when(configProvider).getLaunchConfiguration(eq(descriptor), any(IRemoteConnection.class));
doReturn(launchConfigType).when(configProvider).getLaunchConfigurationType(any(ILaunchDescriptor.class), any(IRemoteConnection.class));
doAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
IRemoteConnection target = (IRemoteConnection) invocation.getArguments()[1];
return target.getConnectionType().getId().equals("org.eclipse.remote.LocalServices");
}
}).when(configProvider).supports(eq(descriptor), any(IRemoteConnection.class));
doReturn(elements.toArray(new IConfigurationElement[0])).when(extension).getConfigurationElements();
// Now inject the launch object
@ -171,10 +168,6 @@ public class LaunchBarManagerTest {
ILaunchManager getLaunchManager() {
return launchManager;
}
@Override
IRemoteLaunchConfigService getRemoteLaunchConfigService() {
return mock(IRemoteLaunchConfigService.class);
}
};
manager.init();
manager.launchObjectAdded(launchObject);