mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-03 07:05:24 +02:00
Final LaunchBar 1.0 API. Lots of clean up and simplification.
launchConfigAdded becomes pretty important. Requires providers to be able to find descriptor and target from the incoming configuration if they own it. Also added handing for a default when the target is null. removed ownsConfiguration in providers since the launchConfigAdd does that by returning false. Added enablement for config providers, but that will need work and some default property testers for it to be useful. For the correct way to add in a config provider, check out the Arduino change for this API at: https://git.eclipse.org/r/#/c/49029/ Change-Id: I46b194a933c846d7d3e4eea8a0213c4ec324816f
This commit is contained in:
parent
f4944e5e27
commit
e1ac2000de
19 changed files with 596 additions and 506 deletions
|
@ -12,7 +12,10 @@
|
|||
class="org.eclipse.launchbar.core.internal.DefaultLaunchDescriptorType"
|
||||
id="org.eclipse.launchbar.core.descriptorType.default"
|
||||
priority="0">
|
||||
<enablement></enablement>
|
||||
<enablement>
|
||||
<instanceof
|
||||
value="org.eclipse.debug.core.ILaunchConfiguration">
|
||||
</instanceof></enablement>
|
||||
</descriptorType>
|
||||
<configProvider
|
||||
class="org.eclipse.launchbar.core.DefaultLaunchConfigProvider"
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
</annotation>
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element ref="enablement"/>
|
||||
<element ref="enablement" minOccurs="0" maxOccurs="1"/>
|
||||
</sequence>
|
||||
<attribute name="id" type="string" use="required">
|
||||
<annotation>
|
||||
|
@ -98,6 +98,9 @@ descriptor with priority 5. Priority 0 is reserved for default descriptor.
|
|||
</documentation>
|
||||
</annotation>
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element ref="enablement" minOccurs="0" maxOccurs="1"/>
|
||||
</sequence>
|
||||
<attribute name="descriptorType" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
|
|
@ -3,30 +3,33 @@ 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.ILaunchConfigurationType;
|
||||
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.
|
||||
* Common launch config provider. Manages creating launch configurations and
|
||||
* ensuring duplicates are managed properly.
|
||||
*/
|
||||
public abstract class AbstractLaunchConfigProvider implements ILaunchConfigurationProvider {
|
||||
|
||||
private static final String ATTR_ORIGINAL_NAME = Activator.PLUGIN_ID + ".originalName"; //$NON-NLS-1$
|
||||
private static final String ATTR_PROVIDER_CLASS = Activator.PLUGIN_ID + ".providerClass"; //$NON-NLS-1$
|
||||
|
||||
protected ILaunchConfiguration createLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
||||
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);
|
||||
ILaunchConfigurationType type = getLaunchConfigurationType(descriptor, target);
|
||||
ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, name);
|
||||
|
||||
populateLaunchConfiguration(descriptor, target, workingCopy);
|
||||
|
||||
return workingCopy.doSave();
|
||||
}
|
||||
|
||||
|
||||
protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target,
|
||||
ILaunchConfigurationWorkingCopy workingCopy) throws CoreException {
|
||||
// Leave our breadcrumb
|
||||
|
@ -34,14 +37,18 @@ public abstract class AbstractLaunchConfigProvider implements ILaunchConfigurati
|
|||
workingCopy.setAttribute(ATTR_PROVIDER_CLASS, getClass().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
|
||||
protected boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
|
||||
if (!configuration.exists()) {
|
||||
// can't own it if it doesn't exist
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for our class name but also that the config name
|
||||
// matches what we originally set it to.
|
||||
// This covers the case when the config was duplicated.
|
||||
// We can own only one, the original one.
|
||||
return configuration.getAttribute(ATTR_PROVIDER_CLASS, "").equals(getClass().getName()) //$NON-NLS-1$
|
||||
&& configuration.getAttribute(ATTR_ORIGINAL_NAME, "").equals(configuration.getName()); //$NON-NLS-1$
|
||||
&& configuration.getAttribute(ATTR_ORIGINAL_NAME, "").equals(configuration.getName()); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,15 +6,14 @@ 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.
|
||||
* 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.
|
||||
* Override this class and register an extension if you want to support targets
|
||||
* other than the local connection.
|
||||
*/
|
||||
public class DefaultLaunchConfigProvider implements ILaunchConfigurationProvider {
|
||||
|
||||
/**
|
||||
* Only support local connection. Override to support different types of connection.
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
||||
// Only supports Local connection
|
||||
|
@ -37,20 +36,20 @@ public class DefaultLaunchConfigProvider implements ILaunchConfigurationProvider
|
|||
return descriptor.getAdapter(ILaunchConfiguration.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* If you do override this method and return true you would have to make sure you add launch object which matches
|
||||
* this configuration, otherwise it will not be visible
|
||||
*/
|
||||
@Override
|
||||
public boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
|
||||
// return false so that the config is added as a launch object
|
||||
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
|
||||
// return false so that the configuration can become a launch object
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
|
||||
// by contract we return true if we own or use to own configuration
|
||||
return ownsLaunchConfiguration(configuration);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,15 +62,4 @@ public class DefaultLaunchConfigProvider implements ILaunchConfigurationProvider
|
|||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
|
||||
// by contract we return true if we own configuration
|
||||
return ownsLaunchConfiguration(configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException {
|
||||
// by contract we return true if we own configuration
|
||||
return ownsLaunchConfiguration(configuration);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,22 +11,32 @@
|
|||
package org.eclipse.launchbar.core;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.debug.core.ILaunchConfigurationListener;
|
||||
|
||||
public interface ILaunchBarManager {
|
||||
/**
|
||||
* Interface to the Launch Bar Manager.
|
||||
*
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface ILaunchBarManager extends ILaunchConfigurationListener {
|
||||
|
||||
/**
|
||||
* A launch object has been added. Create a matching launch descriptor if available.
|
||||
* A launch object has been added. Create a matching launch descriptor if
|
||||
* available.
|
||||
*
|
||||
* @param element launch object
|
||||
* @param element
|
||||
* launch object
|
||||
* @return the launch descriptor that got created, null of none was
|
||||
* @throws CoreException
|
||||
*/
|
||||
ILaunchDescriptor launchObjectAdded(Object launchObject) throws CoreException;
|
||||
|
||||
/**
|
||||
* A launch object has been removed. Remove the associated launch descriptor if there is one.
|
||||
* A launch object has been removed. Remove the associated launch descriptor
|
||||
* if there is one.
|
||||
*
|
||||
* @param element launch object
|
||||
* @param element
|
||||
* launch object
|
||||
* @throws CoreException
|
||||
*/
|
||||
void launchObjectRemoved(Object launchObject) throws CoreException;
|
||||
|
@ -39,6 +49,4 @@ public interface ILaunchBarManager {
|
|||
*/
|
||||
void launchObjectChanged(Object launchObject) throws CoreException;
|
||||
|
||||
// TODO API for adding and removing types.
|
||||
|
||||
}
|
||||
|
|
|
@ -16,23 +16,23 @@ import org.eclipse.debug.core.ILaunchConfigurationType;
|
|||
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.
|
||||
* 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 AbstractLaunchConfigProvider} or one of it's
|
||||
* subclasses 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 config provider provide launch configurations for the combination
|
||||
* of descriptor and target.
|
||||
* 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 true if target is supported, false otherwise.
|
||||
* @return true if target is supported, false otherwise.
|
||||
*/
|
||||
boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException;
|
||||
|
||||
|
@ -40,39 +40,42 @@ public interface ILaunchConfigurationProvider {
|
|||
* Return the launch configuation type for the descriptor and target.
|
||||
*
|
||||
* @param descriptor
|
||||
* @param target launch configuration type or null if not supported
|
||||
* @param target
|
||||
* launch configuration type or null if not supported
|
||||
* @return
|
||||
* @throws CoreException
|
||||
*/
|
||||
ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor,
|
||||
IRemoteConnection target) 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
|
||||
* @param descriptor
|
||||
* the descriptor to create the config for
|
||||
* @param target
|
||||
* the target to launch the config on
|
||||
* @return launch configuration
|
||||
* @throws CoreException
|
||||
* @throws CoreException
|
||||
*/
|
||||
ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target)
|
||||
throws CoreException;
|
||||
|
||||
/**
|
||||
* Does this provider own the launch configuration.
|
||||
* A launch configuration has been added. Provider can inspect it and
|
||||
* associate with internal map. Provider should make sure it owns this
|
||||
* launch configuration or it can modify it to take over.
|
||||
*
|
||||
* @param configuration launch configuration
|
||||
* @return true if this provider owns the launch configuration
|
||||
* @throws CoreException
|
||||
* @return true of provider owns this launch configuration
|
||||
*/
|
||||
boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException;
|
||||
boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException;
|
||||
|
||||
/**
|
||||
* A launch configuration has been removed.
|
||||
* 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.
|
||||
* A launch configuration has been removed. 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
|
||||
* @return true if provider owns this launch configuration
|
||||
|
@ -81,23 +84,17 @@ public interface ILaunchConfigurationProvider {
|
|||
boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException;
|
||||
|
||||
/**
|
||||
* A launch configuration has been added. Provider can inspect it and associate with internal map.
|
||||
* Provider should make sure it owns this launch configuration or it can modify it to take over.
|
||||
*
|
||||
* @return true of provider owns this launch configuration
|
||||
*/
|
||||
boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException;
|
||||
|
||||
/**
|
||||
* A launch configuration has been changed. Provider can inspect it to re-evaluate its internal map.
|
||||
* Provider should make sure it owns this launch configuration or it can modify it to take over.
|
||||
* A launch configuration has been changed. Provider can inspect it to
|
||||
* re-evaluate its internal map. Provider should make sure it owns this
|
||||
* launch configuration or it can modify it to take over.
|
||||
*
|
||||
* @return true of provider owns this launch configuration
|
||||
*/
|
||||
boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException;
|
||||
|
||||
/**
|
||||
* A launch descriptor has been removed. Remove any launch configurations that were
|
||||
* created for it.
|
||||
* A launch descriptor has been removed. Remove any launch configurations
|
||||
* that were created for it.
|
||||
*
|
||||
* @param descriptor
|
||||
* @throws CoreException
|
||||
|
@ -105,13 +102,12 @@ public interface ILaunchConfigurationProvider {
|
|||
void launchDescriptorRemoved(ILaunchDescriptor descriptor) throws CoreException;
|
||||
|
||||
/**
|
||||
* A launch target has been removed. Remove any launch configurations that were created
|
||||
* for it.
|
||||
* 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;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,17 +12,15 @@ package org.eclipse.launchbar.core;
|
|||
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a thing that can be launched.
|
||||
* It is good practice that the descriptor is adaptable to the launch object
|
||||
* it is representing.
|
||||
* Represents a thing that can be launched. It is good practice that the
|
||||
* descriptor is adaptable to the launch object it is representing.
|
||||
*/
|
||||
public interface ILaunchDescriptor extends IAdaptable {
|
||||
|
||||
/**
|
||||
* Name to show in the launch descriptor selector.
|
||||
* Names must be unique for all descriptors of a given type.
|
||||
* Name to show in the launch descriptor selector. Names must be unique for
|
||||
* all descriptors of a given type.
|
||||
*
|
||||
* @return name of the launch descriptor
|
||||
*/
|
||||
|
|
|
@ -14,33 +14,22 @@ import org.eclipse.core.runtime.CoreException;
|
|||
|
||||
/**
|
||||
* Provides mapping between launch objects and launch descriptors.
|
||||
*
|
||||
* It is strongly recommended to extend AbstarctLaunchDescriptorType instead of implementing this directly
|
||||
*/
|
||||
public interface ILaunchDescriptorType {
|
||||
/**
|
||||
* Does this type own this launch object?
|
||||
*
|
||||
* The main checking should be done in enablement expression of extension declaring the type,
|
||||
* if enablement expression if defined this method can return true.
|
||||
* This also can used for fine-tuning of ownership
|
||||
* which is hard to declared in xml.
|
||||
*
|
||||
* @param element
|
||||
* @return owns element
|
||||
* @throws CoreException
|
||||
*/
|
||||
boolean ownsLaunchObject(Object launchObject) throws CoreException;
|
||||
|
||||
/**
|
||||
* Return a descriptor for the given launch object.
|
||||
*
|
||||
* May return null to essentially eat the element so no other types
|
||||
* create a descriptor for it.
|
||||
* May return null to essentially eat the element so no other types create a
|
||||
* descriptor for it.
|
||||
*
|
||||
* @param descriptor launch object for descriptor
|
||||
* The enablement expression for a given launch object must pass for this
|
||||
* clause to be executed.
|
||||
*
|
||||
* @param descriptor
|
||||
* launch object for descriptor
|
||||
* @return the best descriptor
|
||||
* @throws CoreException
|
||||
* @throws CoreException
|
||||
*/
|
||||
ILaunchDescriptor getDescriptor(Object launchObject) throws CoreException;
|
||||
|
||||
|
|
|
@ -9,201 +9,146 @@ import java.util.Map.Entry;
|
|||
|
||||
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;
|
||||
import org.eclipse.remote.core.IRemoteConnectionType;
|
||||
import org.eclipse.remote.core.IRemoteServicesManager;
|
||||
|
||||
public abstract class PerTargetLaunchConfigProvider extends AbstractLaunchConfigProvider {
|
||||
public final String ATTR_CONNECTION_TYPE = getConnectionTypeAttribute();
|
||||
public final String ATTR_CONNECTION_NAME = getConnectionNameAttribute();
|
||||
|
||||
private final Map<ILaunchDescriptor, Map<IRemoteConnection, ILaunchConfiguration>> configMap = new HashMap<>();
|
||||
private final Map<ILaunchDescriptor, ILaunchConfiguration> defaultConfigs = new HashMap<>();
|
||||
private final Collection<ILaunchConfiguration> ownedConfigs = new LinkedHashSet<>();
|
||||
|
||||
protected String getConnectionNameAttribute() {
|
||||
return "org.eclipse.launchbar.core.connectionName";//$NON-NLS-1$
|
||||
}
|
||||
|
||||
protected String getConnectionTypeAttribute() {
|
||||
return "org.eclipse.launchbar.core.connectionType";//$NON-NLS-1$
|
||||
protected ILaunchBarManager getManager() {
|
||||
return Activator.getService(ILaunchBarManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target)
|
||||
throws CoreException {
|
||||
Map<IRemoteConnection, ILaunchConfiguration> targetMap = getTargetMap(descriptor);
|
||||
ILaunchConfiguration config = targetMap.get(target);
|
||||
if (config != null) {
|
||||
return config;
|
||||
}
|
||||
// first search for owned configurations, to see if any match to descriptor
|
||||
config = findLaunchConfiguration(descriptor, target);
|
||||
if (config == null) {
|
||||
config = createLaunchConfiguration(descriptor, target);
|
||||
launchConfigurationAdded(config);
|
||||
}
|
||||
targetMap.put(target, config);
|
||||
return config;
|
||||
}
|
||||
|
||||
protected Map<IRemoteConnection, ILaunchConfiguration> getTargetMap(ILaunchDescriptor descriptor) {
|
||||
Map<IRemoteConnection, ILaunchConfiguration> targetMap = configMap.get(descriptor);
|
||||
if (targetMap == null) {
|
||||
targetMap = new HashMap<>();
|
||||
configMap.put(descriptor, targetMap);
|
||||
}
|
||||
return targetMap;
|
||||
}
|
||||
|
||||
protected ILaunchConfiguration findLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target)
|
||||
throws CoreException {
|
||||
for (ILaunchConfiguration configuration : ownedConfigs) {
|
||||
if (descriptorAndTargetMatchesConfiguration(descriptor, target, configuration)) {
|
||||
return configuration;
|
||||
if (target != null) {
|
||||
Map<IRemoteConnection, ILaunchConfiguration> targetMap = configMap.get(descriptor);
|
||||
if (targetMap != null) {
|
||||
ILaunchConfiguration config = targetMap.get(target);
|
||||
if (config != null) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ILaunchConfiguration config = defaultConfigs.get(descriptor);
|
||||
if (config != null) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
// The config will get added to the cache when launchConfigurationAdded
|
||||
// is called when the new config is saved.
|
||||
return createLaunchConfiguration(descriptor, target);
|
||||
}
|
||||
|
||||
protected boolean descriptorAndTargetMatchesConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target,
|
||||
ILaunchConfiguration configuration) {
|
||||
if (targetMatchesConfiguration(target, configuration) == false)
|
||||
return false;
|
||||
if (descriptorMatchesConfiguration(descriptor, configuration) == false)
|
||||
protected abstract ILaunchDescriptor getLaunchDescriptor(ILaunchConfiguration configuration) throws CoreException;
|
||||
|
||||
protected abstract IRemoteConnection getLaunchTarget(ILaunchConfiguration configuration) throws CoreException;
|
||||
|
||||
protected boolean providesForNullTarget() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean addLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
|
||||
ILaunchDescriptor desc = getLaunchDescriptor(configuration);
|
||||
if (desc == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IRemoteConnection target = getLaunchTarget(configuration);
|
||||
if (target == null) {
|
||||
if (providesForNullTarget()) {
|
||||
defaultConfigs.put(desc, configuration);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
Map<IRemoteConnection, ILaunchConfiguration> targetMap = configMap.get(desc);
|
||||
if (targetMap == null) {
|
||||
targetMap = new HashMap<>();
|
||||
configMap.put(desc, targetMap);
|
||||
}
|
||||
targetMap.put(target, configuration);
|
||||
}
|
||||
|
||||
ownedConfigs.add(configuration);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method should be overridden to check that configuration does actually represent the descriptor.
|
||||
* You don't need to check ownership since this method will be only called on owned configurations
|
||||
*/
|
||||
protected boolean descriptorMatchesConfiguration(ILaunchDescriptor descriptor, ILaunchConfiguration configuration) {
|
||||
// we using startsWith instead of equals because new configuration using "generateLaunchConfigurationName" method which
|
||||
// means only prefix guaranteed to be matching, and the prefix is the descriptor name
|
||||
return configuration.getName().startsWith(descriptor.getName());
|
||||
@Override
|
||||
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
|
||||
if (ownsLaunchConfiguration(configuration)) {
|
||||
return addLaunchConfiguration(configuration);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean targetMatchesConfiguration(IRemoteConnection target, ILaunchConfiguration configuration) {
|
||||
String targetName;
|
||||
try {
|
||||
targetName = configuration.getAttribute(ATTR_CONNECTION_NAME, "");
|
||||
} catch (CoreException e) {
|
||||
return false;
|
||||
}
|
||||
if (target != null && target.getName().equals(targetName)) {
|
||||
return true;
|
||||
} else if (target == null && (targetName == null || targetName.isEmpty())) {
|
||||
@Override
|
||||
public boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException {
|
||||
if (ownsLaunchConfiguration(configuration)) {
|
||||
// clear cache, target could have changed
|
||||
launchConfigurationRemoved(configuration);
|
||||
return addLaunchConfiguration(configuration);
|
||||
} else if (ownedConfigs.contains(configuration)) {
|
||||
// something changed that will cause us to loose ownership of this
|
||||
// configuration. Remove and add it back in.
|
||||
ILaunchBarManager manager = getManager();
|
||||
manager.launchConfigurationRemoved(configuration);
|
||||
manager.launchConfigurationAdded(configuration);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target,
|
||||
ILaunchConfigurationWorkingCopy workingCopy) throws CoreException {
|
||||
super.populateLaunchConfiguration(descriptor, target, workingCopy);
|
||||
workingCopy.setAttribute(ATTR_CONNECTION_TYPE, target.getConnectionType().getId());
|
||||
workingCopy.setAttribute(ATTR_CONNECTION_NAME, target.getName());
|
||||
}
|
||||
|
||||
public IRemoteConnection getTarget(ILaunchConfiguration configuration) throws CoreException {
|
||||
IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
|
||||
String connectionTypeId = configuration.getAttribute(ATTR_CONNECTION_TYPE, ""); //$NON-NLS-1$
|
||||
if (connectionTypeId.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
IRemoteConnectionType connectionType = remoteManager.getConnectionType(connectionTypeId);
|
||||
if (connectionType == null) {
|
||||
return null;
|
||||
}
|
||||
String connectionName = configuration.getAttribute(ATTR_CONNECTION_NAME, ""); //$NON-NLS-1$
|
||||
if (connectionName.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return connectionType.getConnection(connectionName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
|
||||
return ownedConfigs.contains(configuration);
|
||||
}
|
||||
|
||||
public boolean ownsLaunchConfigurationByAttributes(ILaunchConfiguration configuration) {
|
||||
try {
|
||||
return super.ownsLaunchConfiguration(configuration);
|
||||
} catch (CoreException e) {
|
||||
// will happened if called after LC is deleted
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
|
||||
boolean owned = ownsLaunchConfiguration(configuration);
|
||||
if (owned) {
|
||||
ownedConfigs.remove(configuration);
|
||||
for (Entry<ILaunchDescriptor, Map<IRemoteConnection, ILaunchConfiguration>> descEntry : configMap.entrySet()) {
|
||||
for (Entry<IRemoteConnection, ILaunchConfiguration> targetEntry : descEntry.getValue().entrySet()) {
|
||||
if (targetEntry.getValue().equals(configuration)) {
|
||||
descEntry.getValue().remove(targetEntry.getKey());
|
||||
if (descEntry.getValue().isEmpty()) {
|
||||
configMap.remove(descEntry.getKey());
|
||||
}
|
||||
return true;
|
||||
ownedConfigs.remove(configuration);
|
||||
for (Entry<ILaunchDescriptor, Map<IRemoteConnection, ILaunchConfiguration>> descEntry : configMap.entrySet()) {
|
||||
for (Entry<IRemoteConnection, ILaunchConfiguration> targetEntry : descEntry.getValue().entrySet()) {
|
||||
if (targetEntry.getValue().equals(configuration)) {
|
||||
descEntry.getValue().remove(targetEntry.getKey());
|
||||
if (descEntry.getValue().isEmpty()) {
|
||||
configMap.remove(descEntry.getKey());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return owned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
|
||||
if (ownsLaunchConfigurationByAttributes(configuration)) {
|
||||
ownedConfigs.add(configuration);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException {
|
||||
if (ownsLaunchConfigurationByAttributes(configuration)) {
|
||||
// clear cache, target could have changed
|
||||
launchConfigurationRemoved(configuration);
|
||||
ownedConfigs.add(configuration);
|
||||
return true;
|
||||
} else if (ownedConfigs.contains(configuration)) {
|
||||
// user did something that will cause us to loose ownership of this configuration
|
||||
launchConfigurationRemoved(configuration);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launchDescriptorRemoved(ILaunchDescriptor descriptor) throws CoreException {
|
||||
Map<IRemoteConnection, ILaunchConfiguration> map = configMap.remove(descriptor);
|
||||
if (map == null)
|
||||
return;
|
||||
for (ILaunchConfiguration config : map.values()) {
|
||||
if (map != null) {
|
||||
for (ILaunchConfiguration config : map.values()) {
|
||||
ownedConfigs.remove(config);
|
||||
// remove all auto-configs associated with descriptor
|
||||
config.delete();
|
||||
}
|
||||
}
|
||||
|
||||
ILaunchConfiguration config = defaultConfigs.remove(descriptor);
|
||||
if (config != null) {
|
||||
ownedConfigs.remove(config);
|
||||
config.delete(); // remove all auto-configs associated with descriptor
|
||||
config.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launchTargetRemoved(IRemoteConnection target) throws CoreException {
|
||||
for (Iterator<Entry<ILaunchDescriptor, Map<IRemoteConnection, ILaunchConfiguration>>> iterator = configMap.entrySet()
|
||||
.iterator(); iterator.hasNext();) {
|
||||
for (Iterator<Entry<ILaunchDescriptor, Map<IRemoteConnection, ILaunchConfiguration>>> iterator = configMap
|
||||
.entrySet().iterator(); iterator.hasNext();) {
|
||||
Entry<ILaunchDescriptor, Map<IRemoteConnection, ILaunchConfiguration>> descEntry = iterator.next();
|
||||
Map<IRemoteConnection, ILaunchConfiguration> map = descEntry.getValue();
|
||||
ILaunchConfiguration config = map.remove(target);
|
||||
if (config != null) {
|
||||
config.delete(); // remove all auto-configs associated with target
|
||||
// remove all auto-configs associated with target
|
||||
config.delete();
|
||||
}
|
||||
if (map.isEmpty()) {
|
||||
iterator.remove();
|
||||
|
|
|
@ -14,8 +14,8 @@ import org.eclipse.core.resources.IProject;
|
|||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
/**
|
||||
* A reusable descriptor for wrapping projects that can be used by descriptor types
|
||||
* that map to projects.
|
||||
* A reusable descriptor for wrapping projects that can be used by descriptor
|
||||
* types that map to projects.
|
||||
*/
|
||||
public class ProjectLaunchDescriptor extends PlatformObject implements ILaunchDescriptor {
|
||||
|
||||
|
@ -49,4 +49,36 @@ public class ProjectLaunchDescriptor extends PlatformObject implements ILaunchDe
|
|||
public String toString() {
|
||||
return getName(); // for debugging purposes
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((project == null) ? 0 : project.hashCode());
|
||||
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ProjectLaunchDescriptor other = (ProjectLaunchDescriptor) obj;
|
||||
if (project == null) {
|
||||
if (other.project != null)
|
||||
return false;
|
||||
} else if (!project.equals(other.project))
|
||||
return false;
|
||||
if (type == null) {
|
||||
if (other.type != null)
|
||||
return false;
|
||||
} else if (!type.equals(other.type))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,42 +15,21 @@ 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;
|
||||
|
||||
public abstract class ProjectPerTargetLaunchConfigProvider extends PerTargetLaunchConfigProvider {
|
||||
|
||||
@Override
|
||||
public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
||||
return (descriptor.getAdapter(IProject.class) != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean descriptorMatchesConfiguration(ILaunchDescriptor descriptor, ILaunchConfiguration configuration) {
|
||||
IProject project = descriptor.getAdapter(IProject.class);
|
||||
if (project == null || configuration == null)
|
||||
return false;
|
||||
return (project.equals(getProject(configuration)));
|
||||
}
|
||||
|
||||
protected IProject getProject(ILaunchConfiguration configuration) {
|
||||
IResource[] mappedResources = null;
|
||||
try {
|
||||
mappedResources = configuration.getMappedResources();
|
||||
} catch (CoreException e) {
|
||||
return null;
|
||||
}
|
||||
if (mappedResources == null)
|
||||
return null;
|
||||
for (IResource resource : mappedResources) {
|
||||
if (resource instanceof IProject)
|
||||
return (IProject) resource;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target,
|
||||
ILaunchConfigurationWorkingCopy workingCopy) throws CoreException {
|
||||
super.populateLaunchConfiguration(descriptor, target, workingCopy);
|
||||
|
||||
// Add our project to the mapped resources
|
||||
IProject project = descriptor.getAdapter(IProject.class);
|
||||
IResource[] mappedResources = workingCopy.getMappedResources();
|
||||
|
@ -63,4 +42,25 @@ public abstract class ProjectPerTargetLaunchConfigProvider extends PerTargetLaun
|
|||
workingCopy.setMappedResources(newResources);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ILaunchDescriptor getLaunchDescriptor(ILaunchConfiguration configuration) throws CoreException {
|
||||
IResource[] mappedResources = configuration.getMappedResources();
|
||||
if (mappedResources == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IProject project = null;
|
||||
for (IResource resource : mappedResources) {
|
||||
if (resource instanceof IProject)
|
||||
project = (IProject) resource;
|
||||
}
|
||||
if (project == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ILaunchBarManager manager = Activator.getService(ILaunchBarManager.class);
|
||||
return manager.launchObjectAdded(project);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ import org.eclipse.launchbar.core.ILaunchDescriptor;
|
|||
import org.eclipse.launchbar.core.ILaunchDescriptorType;
|
||||
|
||||
/**
|
||||
* A special descriptor type that managed configurations that aren't owned
|
||||
* by other descriptor types.
|
||||
* A special descriptor type that managed configurations that aren't owned by
|
||||
* other descriptor types.
|
||||
*/
|
||||
public class DefaultLaunchDescriptorType implements ILaunchDescriptorType {
|
||||
|
||||
|
@ -20,16 +20,11 @@ public class DefaultLaunchDescriptorType implements ILaunchDescriptorType {
|
|||
private Map<ILaunchConfiguration, DefaultLaunchDescriptor> descriptors = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean ownsLaunchObject(Object element) {
|
||||
return element instanceof ILaunchConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchDescriptor getDescriptor(Object element) {
|
||||
if (element instanceof ILaunchConfiguration) {
|
||||
ILaunchConfiguration config = (ILaunchConfiguration) element;
|
||||
public ILaunchDescriptor getDescriptor(Object launchObject) {
|
||||
if (launchObject instanceof ILaunchConfiguration) {
|
||||
ILaunchConfiguration config = (ILaunchConfiguration) launchObject;
|
||||
try {
|
||||
if( config.getType() != null && config.getType().isPublic()
|
||||
if (config.getType() != null && config.getType().isPublic()
|
||||
&& !(config.getAttribute(ILaunchManager.ATTR_PRIVATE, false))) {
|
||||
|
||||
DefaultLaunchDescriptor descriptor = descriptors.get(config);
|
||||
|
@ -39,9 +34,9 @@ public class DefaultLaunchDescriptorType implements ILaunchDescriptorType {
|
|||
}
|
||||
return descriptor;
|
||||
}
|
||||
} catch(CoreException ce) {
|
||||
} catch (CoreException ce) {
|
||||
Activator.log(ce.getStatus());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
|||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.eclipse.debug.core.DebugPlugin;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
import org.eclipse.debug.core.ILaunchConfigurationListener;
|
||||
import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||
import org.eclipse.debug.core.ILaunchManager;
|
||||
import org.eclipse.debug.core.ILaunchMode;
|
||||
|
@ -52,14 +51,19 @@ import org.osgi.service.prefs.Preferences;
|
|||
/**
|
||||
* The brains of the launch bar.
|
||||
*/
|
||||
public class LaunchBarManager implements ILaunchBarManager, ILaunchConfigurationListener, IRemoteConnectionChangeListener {
|
||||
public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionChangeListener {
|
||||
|
||||
// TODO make these more fine grained or break them into more focused listeners
|
||||
// TODO make these more fine grained or break them into more focused
|
||||
// listeners
|
||||
public interface Listener {
|
||||
void activeLaunchDescriptorChanged();
|
||||
|
||||
void activeLaunchModeChanged();
|
||||
|
||||
void activeLaunchTargetChanged();
|
||||
|
||||
void launchDescriptorRemoved(ILaunchDescriptor descriptor);
|
||||
|
||||
void launchTargetsChanged();
|
||||
}
|
||||
|
||||
|
@ -90,7 +94,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
private ILaunchMode activeLaunchMode;
|
||||
private IRemoteConnection activeLaunchTarget;
|
||||
|
||||
// private static final String PREF_ACTIVE_CONFIG_DESC = "activeConfigDesc";
|
||||
// private static final String PREF_ACTIVE_CONFIG_DESC = "activeConfigDesc";
|
||||
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$
|
||||
|
@ -194,7 +198,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
|
||||
descriptorTypes.put(typeInfo.getId(), typeInfo);
|
||||
|
||||
|
||||
if (configProviders.get(typeInfo.getId()) == null) {
|
||||
// Make sure we initialize the list
|
||||
configProviders.put(typeInfo.getId(), new ArrayList<LaunchConfigProviderInfo>());
|
||||
|
@ -249,18 +252,21 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
|
||||
}
|
||||
|
||||
// Now that all the types are loaded, the object providers which now populate the descriptors
|
||||
// Now that all the types are loaded, the object providers which now
|
||||
// populate the descriptors
|
||||
for (IExtension extension : extensions) {
|
||||
for (IConfigurationElement element : extension.getConfigurationElements()) {
|
||||
try {
|
||||
String elementName = element.getName();
|
||||
if (elementName.equals("objectProvider")) { //$NON-NLS-1$
|
||||
ILaunchObjectProvider objectProvider = (ILaunchObjectProvider) element.createExecutableExtension("class"); //$NON-NLS-1$
|
||||
ILaunchObjectProvider objectProvider = (ILaunchObjectProvider) element
|
||||
.createExecutableExtension("class"); //$NON-NLS-1$
|
||||
objectProviders.add(objectProvider);
|
||||
objectProvider.init(this);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Activator.log(e); // exceptions during extension loading, log and move on
|
||||
// exceptions during extension loading, log and move on
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -297,48 +303,21 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
||||
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, IRemoteConnection target)
|
||||
throws CoreException {
|
||||
if (descriptor == null)
|
||||
return null;
|
||||
|
||||
for (LaunchConfigProviderInfo provider : configProviders.get(getDescriptorTypeId(descriptor.getType()))) {
|
||||
ILaunchConfigurationType type = provider.getProvider().getLaunchConfigurationType(descriptor, target);
|
||||
if (type != null) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private ILaunchDescriptorType ownsLaunchObject(Object launchObject) throws CoreException {
|
||||
for (LaunchDescriptorTypeInfo descriptorInfo : orderedDescriptorTypes) {
|
||||
try {
|
||||
if (descriptorInfo.ownsLaunchObject(launchObject)) {
|
||||
ILaunchDescriptorType type = descriptorInfo.getType();
|
||||
descriptorTypeInfo.put(type, descriptorInfo);
|
||||
if (type.ownsLaunchObject(launchObject)) {
|
||||
return type;
|
||||
}
|
||||
for (LaunchConfigProviderInfo providerInfo : configProviders.get(getDescriptorTypeId(descriptor.getType()))) {
|
||||
if (providerInfo.enabled(descriptor) && providerInfo.enabled(target)) {
|
||||
ILaunchConfigurationType type = providerInfo.getProvider().getLaunchConfigurationType(descriptor,
|
||||
target);
|
||||
if (type != null) {
|
||||
return type;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Activator.log(e); // one of used defined launch types is misbehaving
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -346,51 +325,77 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
public ILaunchDescriptor launchObjectAdded(Object launchObject) {
|
||||
Activator.trace("launch object added " + launchObject); //$NON-NLS-1$
|
||||
ILaunchDescriptor desc = objectDescriptorMap.get(launchObject);
|
||||
if (desc != null)
|
||||
if (desc != null) {
|
||||
return desc;
|
||||
|
||||
try {
|
||||
ILaunchDescriptorType type = ownsLaunchObject(launchObject);
|
||||
if (type != null) {
|
||||
desc = type.getDescriptor(launchObject);
|
||||
if (desc != null) {
|
||||
addDescriptor(launchObject, desc);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
|
||||
return desc;
|
||||
for (LaunchDescriptorTypeInfo descriptorInfo : orderedDescriptorTypes) {
|
||||
try {
|
||||
if (descriptorInfo.enabled(launchObject)) {
|
||||
ILaunchDescriptorType type = descriptorInfo.getType();
|
||||
// For newly loaded types, this is the first time we see
|
||||
// them
|
||||
// Add it to the info map.
|
||||
descriptorTypeInfo.put(type, descriptorInfo);
|
||||
desc = type.getDescriptor(launchObject);
|
||||
if (desc != null) {
|
||||
addDescriptor(launchObject, desc);
|
||||
return desc;
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launchObjectRemoved(Object launchObject) throws CoreException {
|
||||
Activator.trace("launch object removed " + launchObject); //$NON-NLS-1$
|
||||
ILaunchDescriptor desc = objectDescriptorMap.get(launchObject);
|
||||
removeDescriptor(launchObject, desc);
|
||||
ILaunchDescriptor descriptor = objectDescriptorMap.remove(launchObject);
|
||||
if (descriptor != null) {
|
||||
descriptors.remove(getDescriptorId(descriptor));
|
||||
if (descriptor.equals(activeLaunchDesc)) {
|
||||
setActiveLaunchDescriptor(getLastUsedDescriptor());
|
||||
}
|
||||
|
||||
for (LaunchConfigProviderInfo providerInfo : configProviders
|
||||
.get(getDescriptorTypeId(descriptor.getType()))) {
|
||||
if (providerInfo.enabled(descriptor)) {
|
||||
providerInfo.getProvider().launchDescriptorRemoved(descriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launchObjectChanged(Object launchObject) throws CoreException {
|
||||
// TODO deal with object renames here, somehow
|
||||
|
||||
// check if a new descriptor wants to take over
|
||||
ILaunchDescriptor origDesc = objectDescriptorMap.get(launchObject);
|
||||
ILaunchDescriptorType newDescType = ownsLaunchObject(launchObject);
|
||||
if (origDesc == null) {
|
||||
// See if anyone wants it now
|
||||
launchObjectAdded(launchObject);
|
||||
return;
|
||||
}
|
||||
|
||||
if (newDescType != null) {
|
||||
if (origDesc == null || !origDesc.getType().equals(newDescType)) {
|
||||
// we have a take over
|
||||
if (origDesc != null) {
|
||||
removeDescriptor(launchObject, origDesc);
|
||||
}
|
||||
|
||||
ILaunchDescriptor newDesc = newDescType.getDescriptor(launchObject);
|
||||
if (newDesc != null) {
|
||||
addDescriptor(launchObject, newDesc);
|
||||
}
|
||||
// check if descriptor still wants it
|
||||
ILaunchDescriptorType origDescType = origDesc.getType();
|
||||
try {
|
||||
ILaunchDescriptor newDesc = origDescType.getDescriptor(launchObject);
|
||||
if (newDesc == null) {
|
||||
// nope, give it back to the pool
|
||||
objectDescriptorMap.remove(launchObject);
|
||||
launchObjectAdded(launchObject);
|
||||
} else if (!newDesc.equals(origDesc)) {
|
||||
// record the new descriptor
|
||||
objectDescriptorMap.put(launchObject, newDesc);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -402,7 +407,8 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
}
|
||||
|
||||
public ILaunchDescriptor[] getLaunchDescriptors() {
|
||||
// return descriptor in usage order (most used first). UI can sort them later as it wishes
|
||||
// return descriptor in usage order (most used first). UI can sort them
|
||||
// later as it wishes
|
||||
ArrayList<ILaunchDescriptor> values = new ArrayList<>(descriptors.values());
|
||||
Collections.reverse(values);
|
||||
return values.toArray(new ILaunchDescriptor[values.size()]);
|
||||
|
@ -415,18 +421,23 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
public void setActiveLaunchDescriptor(ILaunchDescriptor descriptor) throws CoreException {
|
||||
Activator.trace("set active descriptor " + descriptor); //$NON-NLS-1$
|
||||
if (activeLaunchDesc == descriptor) {
|
||||
// Sync since targets could be changed since last time (and modes theoretically too)
|
||||
// Sync since targets could be changed since last time (and modes
|
||||
// theoretically too)
|
||||
syncActiveTarget();
|
||||
syncActiveMode();
|
||||
Activator.trace("resync for " + descriptor); //$NON-NLS-1$
|
||||
return;
|
||||
}
|
||||
if (descriptor != null && !descriptors.containsValue(descriptor))
|
||||
if (descriptor != null && !descriptors.containsValue(descriptor)) {
|
||||
throw new IllegalStateException(Messages.LaunchBarManager_1);
|
||||
if (descriptor == null)
|
||||
descriptor = getLastUsedDescriptor(); // do not set to null unless no descriptors
|
||||
}
|
||||
if (descriptor == null) {
|
||||
// do not set to null unless no descriptors
|
||||
descriptor = getLastUsedDescriptor();
|
||||
}
|
||||
activeLaunchDesc = descriptor;
|
||||
if (descriptor != null) { // keeps most used descriptor last
|
||||
if (descriptor != null) {
|
||||
// keeps most used descriptor last
|
||||
Pair<String, String> id = getDescriptorId(descriptor);
|
||||
descriptors.remove(id);
|
||||
descriptors.put(id, descriptor);
|
||||
|
@ -447,7 +458,8 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
|
||||
// Store the desc order, active one is the last one
|
||||
StringBuffer buff = new StringBuffer();
|
||||
for (Pair<String, String> key : descriptors.keySet()) {// TODO: this can be very long string
|
||||
// TODO: this can be very long string
|
||||
for (Pair<String, String> key : descriptors.keySet()) {
|
||||
if (buff.length() > 0) {
|
||||
buff.append(',');
|
||||
}
|
||||
|
@ -485,17 +497,15 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
return;
|
||||
}
|
||||
ILaunchMode foundMode = null;
|
||||
String storedModeId = getPerDescriptorStore().get(PREF_ACTIVE_LAUNCH_MODE, null); // last desc mode id
|
||||
// last desc mode id
|
||||
String storedModeId = getPerDescriptorStore().get(PREF_ACTIVE_LAUNCH_MODE, null);
|
||||
String lastActiveModeId = activeLaunchMode == null ? null : activeLaunchMode.getIdentifier();
|
||||
ILaunchMode[] supportedModes = getLaunchModes(); // this is based on active desc and target which are already set
|
||||
// this is based on active desc and target which are already set
|
||||
ILaunchMode[] supportedModes = getLaunchModes();
|
||||
if (supportedModes.length > 0) { // mna, what if no modes are supported?
|
||||
String modeNames[] = new String[] {
|
||||
storedModeId,
|
||||
lastActiveModeId,
|
||||
"run", //$NON-NLS-1$
|
||||
String modeNames[] = new String[] { storedModeId, lastActiveModeId, "run", //$NON-NLS-1$
|
||||
"debug", //$NON-NLS-1$
|
||||
supportedModes[0].getIdentifier()
|
||||
};
|
||||
supportedModes[0].getIdentifier() };
|
||||
for (int i = 0; i < modeNames.length; i++) {
|
||||
foundMode = getLaunchManager().getLaunchMode(modeNames[i]);
|
||||
if (supportsMode(foundMode))
|
||||
|
@ -554,7 +564,8 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
}
|
||||
|
||||
private void fireActiveLaunchDescriptorChanged() {
|
||||
if (!initialized) return;
|
||||
if (!initialized)
|
||||
return;
|
||||
for (Listener listener : listeners) {
|
||||
try {
|
||||
listener.activeLaunchDescriptorChanged();
|
||||
|
@ -612,7 +623,8 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
}
|
||||
|
||||
private void fireActiveLaunchModeChanged() {
|
||||
if (!initialized) return;
|
||||
if (!initialized)
|
||||
return;
|
||||
for (Listener listener : listeners) {
|
||||
try {
|
||||
listener.activeLaunchModeChanged();
|
||||
|
@ -622,7 +634,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void storeLaunchMode(ILaunchDescriptor desc, ILaunchMode mode) {
|
||||
if (mode != null) {
|
||||
// per desc store, desc can null if will be stored globally
|
||||
|
@ -646,10 +657,12 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
|
||||
boolean supportsTarget(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
||||
String descriptorTypeId = getDescriptorTypeId(descriptor.getType());
|
||||
for (LaunchConfigProviderInfo provider : configProviders.get(descriptorTypeId)) {
|
||||
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descriptorTypeId)) {
|
||||
try {
|
||||
if (provider.getProvider().supports(descriptor, target)) {
|
||||
return true;
|
||||
if (providerInfo.enabled(descriptor) && providerInfo.enabled(target)) {
|
||||
if (providerInfo.getProvider().supports(descriptor, target)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Activator.log(e);
|
||||
|
@ -664,6 +677,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
|
||||
/**
|
||||
* Sets preferred target for launch descriptor
|
||||
*
|
||||
* @param desc
|
||||
* @param target
|
||||
* @throws CoreException
|
||||
|
@ -682,19 +696,23 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
}
|
||||
activeLaunchTarget = target;
|
||||
storeLaunchTarget(activeLaunchDesc, target);
|
||||
syncActiveMode();
|
||||
fireActiveLaunchTargetChanged(); // notify listeners
|
||||
}
|
||||
|
||||
private void storeLaunchTarget(ILaunchDescriptor desc, IRemoteConnection target) {
|
||||
if (target == null) {
|
||||
return; // no point storing null, if stored id is invalid it won't be used anyway
|
||||
// no point storing null, if stored id is invalid it won't be used
|
||||
// anyway
|
||||
return;
|
||||
}
|
||||
// per desc store, desc can be null means it store globally
|
||||
setPreference(getPerDescriptorStore(desc), PREF_ACTIVE_LAUNCH_TARGET, toString(getTargetId(target)));
|
||||
}
|
||||
|
||||
private void fireActiveLaunchTargetChanged() {
|
||||
if (!initialized) return;
|
||||
if (!initialized)
|
||||
return;
|
||||
for (Listener listener : listeners) {
|
||||
try {
|
||||
listener.activeLaunchTargetChanged();
|
||||
|
@ -713,7 +731,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
return getLaunchConfiguration(activeLaunchDesc, activeLaunchTarget);
|
||||
}
|
||||
|
||||
|
||||
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target)
|
||||
throws CoreException {
|
||||
if (descriptor == null) {
|
||||
|
@ -723,13 +740,15 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
String descTypeId = getDescriptorTypeId(descriptor.getType());
|
||||
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeId)) {
|
||||
try {
|
||||
ILaunchConfigurationProvider provider = providerInfo.getProvider();
|
||||
// between multiple provider who support this descriptor we need to find one
|
||||
// that supports this target
|
||||
if (provider.supports(descriptor, target)) {
|
||||
ILaunchConfiguration config = provider.getLaunchConfiguration(descriptor, target);
|
||||
if (config != null) {
|
||||
return config;
|
||||
if (providerInfo.enabled(descriptor) && providerInfo.enabled(target)) {
|
||||
ILaunchConfigurationProvider provider = providerInfo.getProvider();
|
||||
// between multiple provider who support this descriptor we
|
||||
// need to find one that supports this target
|
||||
if (provider.supports(descriptor, target)) {
|
||||
ILaunchConfiguration config = provider.getLaunchConfiguration(descriptor, target);
|
||||
if (config != null) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
|
@ -757,9 +776,10 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
for (LaunchDescriptorTypeInfo descTypeInfo : orderedDescriptorTypes) {
|
||||
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeInfo.getId())) {
|
||||
try {
|
||||
providerInfo.getProvider().launchConfigurationAdded(configuration);
|
||||
if (providerInfo.getProvider().ownsLaunchConfiguration(configuration)) {
|
||||
return;
|
||||
if (providerInfo.enabled(configuration)) {
|
||||
if (providerInfo.getProvider().launchConfigurationAdded(configuration)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Activator.log(e);
|
||||
|
@ -778,12 +798,13 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
Activator.log(e);
|
||||
}
|
||||
|
||||
// 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;
|
||||
if (providerInfo.enabled(configuration)) {
|
||||
if (providerInfo.getProvider().launchConfigurationRemoved(configuration)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Activator.log(e);
|
||||
|
@ -797,7 +818,11 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
for (LaunchDescriptorTypeInfo descTypeInfo : orderedDescriptorTypes) {
|
||||
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeInfo.getId())) {
|
||||
try {
|
||||
providerInfo.getProvider().launchConfigurationChanged(configuration);
|
||||
if (providerInfo.enabled(configuration)) {
|
||||
if (providerInfo.getProvider().launchConfigurationChanged(configuration)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
package org.eclipse.launchbar.core.internal;
|
||||
|
||||
import org.eclipse.core.expressions.EvaluationContext;
|
||||
import org.eclipse.core.expressions.EvaluationResult;
|
||||
import org.eclipse.core.expressions.Expression;
|
||||
import org.eclipse.core.expressions.ExpressionConverter;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.launchbar.core.ILaunchConfigurationProvider;
|
||||
|
||||
public class LaunchConfigProviderInfo {
|
||||
|
@ -9,6 +14,7 @@ public class LaunchConfigProviderInfo {
|
|||
private final int priority;
|
||||
private IConfigurationElement element;
|
||||
private ILaunchConfigurationProvider provider;
|
||||
private Expression expression;
|
||||
|
||||
public LaunchConfigProviderInfo(IConfigurationElement element) {
|
||||
this.descriptorTypeId = element.getAttribute("descriptorType"); //$NON-NLS-1$
|
||||
|
@ -23,6 +29,27 @@ public class LaunchConfigProviderInfo {
|
|||
priority = priorityNum;
|
||||
|
||||
this.element = element;
|
||||
|
||||
IConfigurationElement[] enabledExpressions = element.getChildren("enablement");//$NON-NLS-1$
|
||||
if (enabledExpressions == null || enabledExpressions.length == 0) {
|
||||
Activator.log(new Status(Status.WARNING, Activator.PLUGIN_ID,
|
||||
"Enablement expression is missing for config provider for " + descriptorTypeId)); //$NON-NLS-1$
|
||||
} else if (enabledExpressions.length > 1) {
|
||||
Activator.log(new Status(Status.WARNING, Activator.PLUGIN_ID,
|
||||
"Multiple enablement expressions are detected for config provider for "//$NON-NLS-1$
|
||||
+ descriptorTypeId));
|
||||
} else {
|
||||
try {
|
||||
expression = ExpressionConverter.getDefault().perform(enabledExpressions[0]);
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
if (expression == null) {
|
||||
Activator.log(new Status(Status.ERROR, Activator.PLUGIN_ID,
|
||||
"Cannot parse enablement expression defined in config provider for " + descriptorTypeId)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getDescriptorTypeId() {
|
||||
|
@ -40,4 +67,12 @@ public class LaunchConfigProviderInfo {
|
|||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
public boolean enabled(Object element) throws CoreException {
|
||||
if (expression == null)
|
||||
return true;
|
||||
EvaluationResult result = expression.evaluate(new EvaluationContext(null, element));
|
||||
return (result == EvaluationResult.TRUE);
|
||||
}
|
||||
|
||||
}
|
|
@ -28,7 +28,9 @@ public class LaunchDescriptorTypeInfo {
|
|||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
this.element = element;
|
||||
|
||||
IConfigurationElement[] enabledExpressions = element.getChildren("enablement");//$NON-NLS-1$
|
||||
if (enabledExpressions == null || enabledExpressions.length == 0) {
|
||||
Activator.log(new Status(Status.WARNING, Activator.PLUGIN_ID,
|
||||
|
@ -36,7 +38,7 @@ public class LaunchDescriptorTypeInfo {
|
|||
} else if (enabledExpressions.length > 1) {
|
||||
Activator.log(new Status(Status.WARNING, Activator.PLUGIN_ID,
|
||||
"Multiple enablement expressions are detected for descriptor type "//$NON-NLS-1$
|
||||
+ id));
|
||||
+ id));
|
||||
} else {
|
||||
try {
|
||||
expression = ExpressionConverter.getDefault().perform(enabledExpressions[0]);
|
||||
|
@ -51,7 +53,7 @@ public class LaunchDescriptorTypeInfo {
|
|||
}
|
||||
|
||||
// Used for testing
|
||||
public LaunchDescriptorTypeInfo(String id, int priority, ILaunchDescriptorType type) {
|
||||
LaunchDescriptorTypeInfo(String id, int priority, ILaunchDescriptorType type) {
|
||||
this.id = id;
|
||||
this.priority = priority;
|
||||
this.type = type;
|
||||
|
@ -73,10 +75,10 @@ public class LaunchDescriptorTypeInfo {
|
|||
return type;
|
||||
}
|
||||
|
||||
public boolean ownsLaunchObject(Object object) throws CoreException {
|
||||
public boolean enabled(Object launchObject) throws CoreException {
|
||||
if (expression == null)
|
||||
return true;
|
||||
EvaluationResult result = expression.evaluate(new EvaluationContext(null, object));
|
||||
EvaluationResult result = expression.evaluate(new EvaluationContext(null, launchObject));
|
||||
return (result == EvaluationResult.TRUE);
|
||||
}
|
||||
}
|
|
@ -25,8 +25,8 @@ import org.eclipse.launchbar.core.ILaunchBarManager;
|
|||
import org.eclipse.launchbar.core.ILaunchObjectProvider;
|
||||
|
||||
/**
|
||||
* Injects IProject objects from platform resources into the launch bar model for potential
|
||||
* project descriptors.
|
||||
* Injects IProject objects from platform resources into the launch bar model
|
||||
* for potential project descriptors.
|
||||
*/
|
||||
public class ProjectLaunchObjectProvider implements ILaunchObjectProvider, IResourceChangeListener {
|
||||
private ILaunchBarManager manager;
|
||||
|
@ -60,8 +60,11 @@ public class ProjectLaunchObjectProvider implements ILaunchObjectProvider, IReso
|
|||
} else if ((kind & IResourceDelta.REMOVED) != 0) {
|
||||
manager.launchObjectRemoved(project);
|
||||
} else if ((kind & IResourceDelta.CHANGED) != 0) {
|
||||
// TODO may need to be more concise as to what changes we're looking for
|
||||
manager.launchObjectChanged(project);
|
||||
int flags = delta.getFlags();
|
||||
// Right now, only care about nature changes
|
||||
if ((flags & IResourceDelta.DESCRIPTION) != 0) {
|
||||
manager.launchObjectChanged(project);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} else if (res instanceof IFile || res instanceof IFolder) {
|
||||
|
|
|
@ -16,10 +16,10 @@ import static org.junit.Assert.assertNotEquals;
|
|||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.debug.core.DebugPlugin;
|
||||
|
@ -38,6 +38,7 @@ import org.junit.FixMethodOrder;
|
|||
import org.junit.Test;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
@FixMethodOrder(MethodSorters.JVM)
|
||||
public class PerTargetLaunchConfigProviderTest {
|
||||
private IRemoteServicesManager remoteServiceManager;
|
||||
|
@ -85,16 +86,62 @@ public class PerTargetLaunchConfigProviderTest {
|
|||
}
|
||||
|
||||
public class PerTargetLaunchConfigProvider1 extends PerTargetLaunchConfigProvider {
|
||||
public static final String CONNECTION_NAME_ATTR = "connectionName";
|
||||
private ILaunchBarManager manager;
|
||||
|
||||
@Override
|
||||
public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, IRemoteConnection target)
|
||||
throws CoreException {
|
||||
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor,
|
||||
IRemoteConnection target) throws CoreException {
|
||||
return launchConfigType;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target,
|
||||
ILaunchConfigurationWorkingCopy workingCopy) throws CoreException {
|
||||
super.populateLaunchConfiguration(descriptor, target, workingCopy);
|
||||
workingCopy.setAttribute(CONNECTION_NAME_ATTR, target.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ILaunchDescriptor getLaunchDescriptor(ILaunchConfiguration configuration) throws CoreException {
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IRemoteConnection getLaunchTarget(ILaunchConfiguration configuration) throws CoreException {
|
||||
String name = configuration.getAttribute(CONNECTION_NAME_ATTR, "");
|
||||
if (localTarget.getName().equals(name)) {
|
||||
return localTarget;
|
||||
} else if (otherTarget.getName().equals(name)) {
|
||||
return otherTarget;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ILaunchBarManager getManager() {
|
||||
if (manager == null) {
|
||||
manager = mock(ILaunchBarManager.class);
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target)
|
||||
throws CoreException {
|
||||
ILaunchConfiguration config = super.getLaunchConfiguration(descriptor, target);
|
||||
// Since this provider isn't hooked in properly, need to manually
|
||||
// add in the config
|
||||
launchConfigurationAdded(config);
|
||||
return config;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@Test
|
||||
|
@ -102,9 +149,7 @@ public class PerTargetLaunchConfigProviderTest {
|
|||
ILaunchConfiguration launchConfig = launchConfigType.newInstance(null, launchName).doSave();
|
||||
ILaunchConfigurationWorkingCopy launchConfigWC = launchConfig.getWorkingCopy();
|
||||
provider.populateLaunchConfiguration(descriptor, localTarget, launchConfigWC);
|
||||
//assertEquals(launchConfig.getName(), launchConfigWC.getAttribute(LaunchBarManager2Test.ATTR_ORIGINAL_NAME, ""));
|
||||
//assertEquals(provider.getClass().getName(), launchConfigWC.getAttribute(LaunchBarManager2Test.ATTR_PROVIDER_CLASS, ""));
|
||||
assertTrue(provider.ownsLaunchConfigurationByAttributes(launchConfigWC));
|
||||
assertTrue(provider.ownsLaunchConfiguration(launchConfigWC));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -139,7 +184,8 @@ public class PerTargetLaunchConfigProviderTest {
|
|||
assertNotNull(launchConfiguration1);
|
||||
// reset provider
|
||||
provider = new PerTargetLaunchConfigProvider1();
|
||||
provider.launchConfigurationAdded(launchConfiguration1); // simulate provider initialization on startup
|
||||
// simulate provider initialization on startup
|
||||
provider.launchConfigurationAdded(launchConfiguration1);
|
||||
ILaunchConfiguration launchConfiguration2 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||
assertNotNull(launchConfiguration2);
|
||||
assertEquals(launchConfiguration1, launchConfiguration2);
|
||||
|
@ -149,7 +195,7 @@ public class PerTargetLaunchConfigProviderTest {
|
|||
public void testGetTarget() throws CoreException {
|
||||
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||
assertNotNull(launchConfiguration1);
|
||||
assertSame(localTarget, provider.getTarget(launchConfiguration1));
|
||||
assertSame(localTarget, provider.getLaunchTarget(launchConfiguration1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -177,10 +223,10 @@ public class PerTargetLaunchConfigProviderTest {
|
|||
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||
assertNotNull(launchConfiguration1);
|
||||
ILaunchConfigurationWorkingCopy wc = launchConfiguration1.getWorkingCopy();
|
||||
wc.setAttribute(provider.getConnectionNameAttribute(), otherTarget.getName());
|
||||
wc.setAttribute(PerTargetLaunchConfigProvider1.CONNECTION_NAME_ATTR, otherTarget.getName());
|
||||
wc.doSave();
|
||||
provider.launchConfigurationChanged(launchConfiguration1);
|
||||
//provider.launchConfigurationChanged(lc3);
|
||||
// provider.launchConfigurationChanged(lc3);
|
||||
ILaunchConfiguration launchConfiguration2 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||
assertNotNull(launchConfiguration2);
|
||||
assertNotEquals(launchConfiguration1, launchConfiguration2);
|
||||
|
@ -192,10 +238,14 @@ public class PerTargetLaunchConfigProviderTest {
|
|||
assertNotNull(launchConfiguration1);
|
||||
ILaunchConfigurationWorkingCopy wc = launchConfiguration1.getWorkingCopy();
|
||||
wc.setAttribute(LaunchBarManager2Test.ATTR_ORIGINAL_NAME, "bla");
|
||||
wc.doSave();
|
||||
launchConfiguration1 = wc.doSave();
|
||||
provider.launchConfigurationChanged(launchConfiguration1);
|
||||
// we should have lost ownership
|
||||
assertFalse(provider.ownsLaunchConfiguration(launchConfiguration1));
|
||||
verify(provider.manager).launchConfigurationRemoved(launchConfiguration1);
|
||||
verify(provider.manager).launchConfigurationAdded(launchConfiguration1);
|
||||
// have to fake out the remove
|
||||
provider.launchConfigurationRemoved(launchConfiguration1);
|
||||
ILaunchConfiguration launchConfiguration2 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||
assertNotNull(launchConfiguration2);
|
||||
assertNotEquals(launchConfiguration1, launchConfiguration2);
|
||||
|
@ -206,7 +256,6 @@ public class PerTargetLaunchConfigProviderTest {
|
|||
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||
assertNotNull(launchConfiguration1);
|
||||
provider.launchDescriptorRemoved(descriptor);
|
||||
assertEquals(0, provider.getTargetMap(descriptor).size());
|
||||
assertFalse(provider.ownsLaunchConfiguration(launchConfiguration1));
|
||||
assertFalse(launchConfiguration1.exists());
|
||||
}
|
||||
|
@ -214,7 +263,6 @@ public class PerTargetLaunchConfigProviderTest {
|
|||
@Test
|
||||
public void testLaunchDescriptorRemoved2() throws CoreException {
|
||||
provider.launchDescriptorRemoved(descriptor);
|
||||
assertEquals(0, provider.getTargetMap(descriptor).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -222,7 +270,6 @@ public class PerTargetLaunchConfigProviderTest {
|
|||
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, otherTarget);
|
||||
assertNotNull(launchConfiguration1);
|
||||
provider.launchTargetRemoved(otherTarget);
|
||||
assertEquals(0, provider.getTargetMap(descriptor).size());
|
||||
assertFalse(launchConfiguration1.exists());
|
||||
}
|
||||
|
||||
|
@ -233,7 +280,6 @@ public class PerTargetLaunchConfigProviderTest {
|
|||
ILaunchConfiguration launchConfiguration2 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||
assertNotNull(launchConfiguration2);
|
||||
provider.launchTargetRemoved(otherTarget);
|
||||
assertEquals(1, provider.getTargetMap(descriptor).size());
|
||||
assertFalse(launchConfiguration1.exists());
|
||||
assertTrue(launchConfiguration2.exists());
|
||||
}
|
||||
|
@ -243,7 +289,6 @@ public class PerTargetLaunchConfigProviderTest {
|
|||
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, otherTarget);
|
||||
assertNotNull(launchConfiguration1);
|
||||
provider.launchTargetRemoved(localTarget);
|
||||
assertEquals(1, provider.getTargetMap(descriptor).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -252,7 +297,6 @@ public class PerTargetLaunchConfigProviderTest {
|
|||
assertNotNull(launchConfiguration1);
|
||||
assertTrue(provider.ownsLaunchConfiguration(launchConfiguration1));
|
||||
launchConfiguration1.delete();
|
||||
assertTrue(provider.ownsLaunchConfiguration(launchConfiguration1));
|
||||
provider.launchConfigurationRemoved(launchConfiguration1);
|
||||
assertFalse(provider.ownsLaunchConfiguration(launchConfiguration1));
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ 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;
|
||||
|
@ -129,26 +128,26 @@ public class LaunchBarManager2Test {
|
|||
doReturn(provider).when(element).createExecutableExtension("class");
|
||||
}
|
||||
|
||||
protected ILaunchConfigurationProvider mockProviderElement(String descriptorTypeId, int priority, ILaunchDescriptor descriptor,
|
||||
IRemoteConnection target,
|
||||
ILaunchConfiguration config, Object launchObj) throws CoreException {
|
||||
protected ILaunchConfigurationProvider mockConfigProviderElement(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(true).when(provider).launchConfigurationAdded(config);
|
||||
return provider;
|
||||
}
|
||||
|
||||
protected IConfigurationElement mockDescriptorTypeElement(String descriptorTypeId, int priority,
|
||||
ILaunchDescriptorType descriptorType)
|
||||
throws CoreException {
|
||||
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");
|
||||
mockEnablementElement(element);
|
||||
// TODO need a real enablement here, not an empty one
|
||||
// mockEnablementElement(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
|
@ -179,7 +178,6 @@ public class LaunchBarManager2Test {
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -297,7 +295,7 @@ public class LaunchBarManager2Test {
|
|||
doReturn(descriptorType).when(descriptor).getType();
|
||||
doReturn(descriptor).when(descriptorType).getDescriptor(launchObject);
|
||||
// configProvider
|
||||
provider = mockProviderElement(descriptorTypeId, 10, descriptor, otherTarget, launchConfig, launchObject);
|
||||
provider = mockConfigProviderElement(descriptorTypeId, 10, descriptor, otherTarget, launchConfig, launchObject);
|
||||
mockLaunchObjectOnDescriptor(launchObject);
|
||||
// default descriptor
|
||||
String defaultDescTypeId = "defaultDescType";
|
||||
|
@ -309,7 +307,8 @@ public class LaunchBarManager2Test {
|
|||
@Test
|
||||
public void testDescriptor() throws Exception {
|
||||
// Create a descriptor type and inject an associated object
|
||||
// Make sure the descriptor is active with the local target and proper mode
|
||||
// Make sure the descriptor is active with the local target and proper
|
||||
// mode
|
||||
// Make sure the associated launch config is active too
|
||||
// Mocking
|
||||
manager.launchObjectAdded(launchObject);
|
||||
|
@ -327,26 +326,20 @@ public class LaunchBarManager2Test {
|
|||
assertNull(manager.getActiveLaunchMode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddDescriptorTypeBad() throws CoreException {
|
||||
doThrow(new NullPointerException()).when(descriptorType).ownsLaunchObject(any());
|
||||
manager.launchObjectAdded("aaa");
|
||||
verify(descriptorType).ownsLaunchObject(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddConfigMappingTwo() throws CoreException {
|
||||
basicSetupOnly();
|
||||
IRemoteConnection target = mockRemoteConnection("t2");
|
||||
mockProviderElement(descriptorTypeId, 10, descriptor, target, launchConfig, launchObject);
|
||||
mockConfigProviderElement(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);
|
||||
mockConfigProviderElement(descriptorTypeId, 10, desc2, target, lc2, lc2);
|
||||
init();
|
||||
manager.launchObjectAdded(launchObject);
|
||||
// it return original lctype because we did not associate this dynmaically
|
||||
// it return original lctype because we did not associate this
|
||||
// dynmaically
|
||||
assertEquals(launchConfigType, manager.getLaunchConfigurationType(descriptor, target));
|
||||
}
|
||||
|
||||
|
@ -354,10 +347,10 @@ public class LaunchBarManager2Test {
|
|||
public void testAddConfigProviderTwo2() throws CoreException {
|
||||
basicSetupOnly();
|
||||
IRemoteConnection target = mockRemoteConnection("t2");
|
||||
mockProviderElement(descriptorTypeId, 15, descriptor, target, launchConfig, launchObject);
|
||||
mockConfigProviderElement(descriptorTypeId, 15, descriptor, target, launchConfig, launchObject);
|
||||
ILaunchConfigurationType lctype2 = mockLCType("lctypeid2");
|
||||
ILaunchConfiguration lc2 = mockLC("lc2", lctype2);
|
||||
mockProviderElement(descriptorTypeId, 20, descriptor, target, lc2, launchObject);
|
||||
mockConfigProviderElement(descriptorTypeId, 20, descriptor, target, lc2, launchObject);
|
||||
init();
|
||||
manager.launchObjectAdded(launchObject);
|
||||
assertEquals(lctype2, manager.getLaunchConfigurationType(descriptor, target));
|
||||
|
@ -390,7 +383,7 @@ public class LaunchBarManager2Test {
|
|||
basicSetupOnly();
|
||||
elements.clear();
|
||||
mockDescriptorTypeElement(descriptorTypeId, 10, descriptorType);
|
||||
mockProviderElement(descriptorTypeId, 10, descriptor, localTarget, launchConfig, launchObject);
|
||||
mockConfigProviderElement(descriptorTypeId, 10, descriptor, localTarget, launchConfig, launchObject);
|
||||
init();
|
||||
manager.launchObjectAdded(launchObject);
|
||||
ILaunchDescriptor desc = manager.getActiveLaunchDescriptor();
|
||||
|
@ -420,30 +413,36 @@ public class LaunchBarManager2Test {
|
|||
}
|
||||
|
||||
//
|
||||
// public void testGetLaunchDescriptorsSort() {
|
||||
// final ILaunchDescriptor res[] = new ILaunchDescriptor[1];
|
||||
// manager.addTargetType(targetType);
|
||||
// ConfigBasedLaunchDescriptorType descType1 = new ConfigBasedLaunchDescriptorType("id1", lctype.getIdentifier());
|
||||
// ConfigBasedLaunchDescriptorType descType2 = new ConfigBasedLaunchDescriptorType("id2", lctype.getIdentifier()) {
|
||||
// @Override
|
||||
// public ILaunchDescriptor getDescriptor(Object element) {
|
||||
// return res[0] = super.getDescriptor(element);
|
||||
// }
|
||||
// };
|
||||
// ConfigBasedLaunchDescriptorType descType3 = new ConfigBasedLaunchDescriptorType("id3", lctype.getIdentifier());
|
||||
// manager.addDescriptorType(descType1, 3);
|
||||
// manager.addDescriptorType(descType2, 5);
|
||||
// manager.addDescriptorType(descType3, 1);
|
||||
// manager.addConfigProvider(descType1.getId(), targetType.getId(), true, provider);
|
||||
// manager.addConfigProvider(descType2.getId(), targetType.getId(), true, provider);
|
||||
// manager.addConfigProvider(descType3.getId(), targetType.getId(), true, provider);
|
||||
// targetType.targets.add(mytarget);
|
||||
// manager.launchObjectAdded(launchObject);
|
||||
// ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
// assertEquals(1, launchDescriptors.length);
|
||||
// assertNotNull(launchDescriptors[0]);
|
||||
// assertSame(res[0], launchDescriptors[0]);
|
||||
// }
|
||||
// public void testGetLaunchDescriptorsSort() {
|
||||
// final ILaunchDescriptor res[] = new ILaunchDescriptor[1];
|
||||
// manager.addTargetType(targetType);
|
||||
// ConfigBasedLaunchDescriptorType descType1 = new
|
||||
// ConfigBasedLaunchDescriptorType("id1", lctype.getIdentifier());
|
||||
// ConfigBasedLaunchDescriptorType descType2 = new
|
||||
// ConfigBasedLaunchDescriptorType("id2", lctype.getIdentifier()) {
|
||||
// @Override
|
||||
// public ILaunchDescriptor getDescriptor(Object element) {
|
||||
// return res[0] = super.getDescriptor(element);
|
||||
// }
|
||||
// };
|
||||
// ConfigBasedLaunchDescriptorType descType3 = new
|
||||
// ConfigBasedLaunchDescriptorType("id3", lctype.getIdentifier());
|
||||
// manager.addDescriptorType(descType1, 3);
|
||||
// manager.addDescriptorType(descType2, 5);
|
||||
// manager.addDescriptorType(descType3, 1);
|
||||
// manager.addConfigProvider(descType1.getId(), targetType.getId(), true,
|
||||
// provider);
|
||||
// manager.addConfigProvider(descType2.getId(), targetType.getId(), true,
|
||||
// provider);
|
||||
// manager.addConfigProvider(descType3.getId(), targetType.getId(), true,
|
||||
// provider);
|
||||
// targetType.targets.add(mytarget);
|
||||
// manager.launchObjectAdded(launchObject);
|
||||
// ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
// assertEquals(1, launchDescriptors.length);
|
||||
// assertNotNull(launchDescriptors[0]);
|
||||
// assertSame(res[0], launchDescriptors[0]);
|
||||
// }
|
||||
//
|
||||
@Test
|
||||
public void testLaunchObjectAdded() throws CoreException {
|
||||
|
@ -481,6 +480,7 @@ public class LaunchBarManager2Test {
|
|||
when(project.getType()).thenReturn(IResource.PROJECT);
|
||||
return project;
|
||||
}
|
||||
|
||||
public static final String ATTR_PROJECT_NAME = "org.eclipse.cdt.launch" + ".PROJECT_ATTR";
|
||||
public static final String ATTR_PROGRAM_NAME = "org.eclipse.cdt.launch" + ".PROGRAM_NAME";
|
||||
|
||||
|
@ -547,11 +547,6 @@ public class LaunchBarManager2Test {
|
|||
}
|
||||
|
||||
public class ProjectBasedLaunchDescriptorType implements ILaunchDescriptorType {
|
||||
@Override
|
||||
public boolean ownsLaunchObject(Object launchObject) throws CoreException {
|
||||
return launchObject instanceof IProject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchDescriptor getDescriptor(Object launchObject) throws CoreException {
|
||||
return new ProjectLaunchDescriptor(this, (IProject) launchObject);
|
||||
|
@ -561,8 +556,11 @@ public class LaunchBarManager2Test {
|
|||
return "pbtype";
|
||||
}
|
||||
}
|
||||
public static final String ATTR_ORIGINAL_NAME = org.eclipse.launchbar.core.internal.Activator.PLUGIN_ID + ".originalName"; //$NON-NLS-1$
|
||||
public static final String ATTR_PROVIDER_CLASS = org.eclipse.launchbar.core.internal.Activator.PLUGIN_ID + ".providerClass"; //$NON-NLS-1$
|
||||
|
||||
public static final String ATTR_ORIGINAL_NAME = org.eclipse.launchbar.core.internal.Activator.PLUGIN_ID
|
||||
+ ".originalName"; //$NON-NLS-1$
|
||||
public static final String ATTR_PROVIDER_CLASS = org.eclipse.launchbar.core.internal.Activator.PLUGIN_ID
|
||||
+ ".providerClass"; //$NON-NLS-1$
|
||||
|
||||
protected void projectMappingSetup() throws CoreException {
|
||||
descriptorType = new ProjectBasedLaunchDescriptorType();
|
||||
|
@ -571,7 +569,8 @@ public class LaunchBarManager2Test {
|
|||
descriptor = new ProjectLaunchDescriptor(descriptorType, aaa);
|
||||
// setup some stuff
|
||||
mockDescriptorTypeElement(descriptorTypeId, 10, descriptorType);
|
||||
//lc = provider.createLaunchConfiguration(lman, descType.getDescriptor(aaa));
|
||||
// lc = provider.createLaunchConfiguration(lman,
|
||||
// descType.getDescriptor(aaa));
|
||||
mockLCProject(launchConfig, aaa);
|
||||
mockLCAttribute(launchConfig, ATTR_ORIGINAL_NAME, aaa.getName());
|
||||
assertEquals(0, manager.getLaunchDescriptors().length);
|
||||
|
@ -586,6 +585,16 @@ public class LaunchBarManager2Test {
|
|||
public boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
|
||||
return configuration == launchConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ILaunchDescriptor getLaunchDescriptor(ILaunchConfiguration configuration) throws CoreException {
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IRemoteConnection getLaunchTarget(ILaunchConfiguration configuration) throws CoreException {
|
||||
return localTarget;
|
||||
}
|
||||
};
|
||||
mockProviderElement(descriptorTypeId, 10, provider);
|
||||
mockLCAttribute(launchConfig, ATTR_PROVIDER_CLASS, provider.getClass().getName());
|
||||
|
@ -635,10 +644,10 @@ public class LaunchBarManager2Test {
|
|||
|
||||
@Test
|
||||
public void testLaunchObjectAddedBadDescriptor() throws CoreException {
|
||||
doThrow(new NullPointerException()).when(descriptorType).ownsLaunchObject(any());
|
||||
doThrow(new NullPointerException()).when(descriptorType).getDescriptor(any());
|
||||
// check events
|
||||
manager.launchObjectAdded(launchObject);
|
||||
verify(descriptorType).ownsLaunchObject(launchObject);
|
||||
verify(descriptorType).getDescriptor(launchObject);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -651,7 +660,7 @@ public class LaunchBarManager2Test {
|
|||
|
||||
@Test
|
||||
public void testLaunchObjectRemoveBadDescriptor() throws CoreException {
|
||||
doThrow(new NullPointerException()).when(descriptorType).ownsLaunchObject(any());
|
||||
doThrow(new NullPointerException()).when(descriptorType).getDescriptor(any());
|
||||
// check events
|
||||
manager.launchObjectRemoved(launchObject);
|
||||
}
|
||||
|
@ -894,7 +903,7 @@ public class LaunchBarManager2Test {
|
|||
ILaunchMode mode = mockLaunchModes(launchConfigType, "foo")[0];
|
||||
manager.launchObjectAdded(launchObject);
|
||||
manager.launchConfigurationAdded(launchConfig);
|
||||
verify(provider).ownsLaunchConfiguration(launchConfig);
|
||||
verify(provider).launchConfigurationAdded(launchConfig);
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
assertEquals(1, launchDescriptors.length);
|
||||
assertNotNull(launchDescriptors[0]);
|
||||
|
@ -910,7 +919,7 @@ public class LaunchBarManager2Test {
|
|||
ILaunchConfigurationType lctype2 = mockLCType("lctype2");
|
||||
ILaunchConfiguration lc2 = mockLC("lc2", lctype2);
|
||||
manager.launchConfigurationAdded(lc2);
|
||||
//verify(provider).launchConfigurationAdded(lc2);
|
||||
// verify(provider).launchConfigurationAdded(lc2);
|
||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||
assertEquals(1, launchDescriptors.length);
|
||||
assertNotNull(launchDescriptors[0]);
|
||||
|
@ -921,10 +930,9 @@ public class LaunchBarManager2Test {
|
|||
|
||||
@Test
|
||||
public void testLaunchConfigurationAddedBad() throws CoreException {
|
||||
doThrow(new NullPointerException()).when(provider).ownsLaunchConfiguration(any(ILaunchConfiguration.class));
|
||||
doThrow(new NullPointerException()).when(provider).launchConfigurationAdded(any(ILaunchConfiguration.class));
|
||||
manager.launchConfigurationAdded(launchConfig);
|
||||
verify(provider).launchConfigurationAdded(launchConfig);
|
||||
verify(provider).ownsLaunchConfiguration(launchConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -958,10 +966,13 @@ public class LaunchBarManager2Test {
|
|||
mockSubElement(enablement, new IConfigurationElement[] { instance });
|
||||
doReturn("java.lang.Integer").when(instance).getAttribute("value");
|
||||
init();
|
||||
assertNull(manager.launchObjectAdded(launchObject)); // this will be refused by enablement expression
|
||||
assertNull(manager.launchObjectAdded(1)); // we programmatically refuse this
|
||||
// this will be refused by enablement expression
|
||||
assertNull(manager.launchObjectAdded(launchObject));
|
||||
// we programmatically refuse this
|
||||
assertNull(manager.launchObjectAdded(1));
|
||||
mockLaunchObjectOnDescriptor(1);
|
||||
assertNotNull(manager.launchObjectAdded(1)); // now we both good programmatically and in expression in extension
|
||||
// now we both good programmatically and in expression in extension
|
||||
assertNotNull(manager.launchObjectAdded(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ 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;
|
||||
|
@ -46,15 +45,17 @@ public class LaunchBarManagerTest {
|
|||
|
||||
@Test
|
||||
public void defaultTest() throws Exception {
|
||||
// Create a launch config, make sure default mode and local target are active
|
||||
// Create a launch config, make sure default mode and local target are
|
||||
// active
|
||||
// And that that config is the active config.
|
||||
|
||||
|
||||
// Mocking
|
||||
ILaunchConfigurationType launchConfigType = mock(ILaunchConfigurationType.class);
|
||||
ILaunchConfiguration launchConfig = mock(ILaunchConfiguration.class);
|
||||
String launchConfigName = "launchConfig";
|
||||
doReturn(launchConfigName).when(launchConfig).getName();
|
||||
doReturn(launchConfigName).when(launchConfig).getAttribute(eq("org.eclipse.launchbar.core.originalName"), anyString());
|
||||
doReturn(launchConfigName).when(launchConfig).getAttribute(eq("org.eclipse.launchbar.core.originalName"),
|
||||
anyString());
|
||||
doReturn("").when(launchConfig).getAttribute(eq("org.eclipse.launchbar.core.providerClass"), anyString());
|
||||
doReturn(true).when(launchConfigType).isPublic();
|
||||
doReturn(launchConfigType).when(launchConfig).getType();
|
||||
|
@ -80,25 +81,25 @@ public class LaunchBarManagerTest {
|
|||
|
||||
assertNotNull(manager.getActiveLaunchMode());
|
||||
assertEquals("run", manager.getActiveLaunchMode().getIdentifier());
|
||||
|
||||
|
||||
assertEquals(launchConfig, manager.getActiveLaunchConfiguration());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void descriptorTest() throws Exception {
|
||||
// Create a descriptor type and inject an associated object
|
||||
// Make sure the descriptor is active with the local target and proper mode
|
||||
// Make sure the descriptor is active with the local target and proper
|
||||
// mode
|
||||
// Make sure the associated launch config is active too
|
||||
|
||||
// Mocking
|
||||
final IExtensionPoint extensionPoint = mock(IExtensionPoint.class);
|
||||
IExtension extension = mock(IExtension.class);
|
||||
doReturn(new IExtension[] { extension }).when(extensionPoint).getExtensions();
|
||||
|
||||
|
||||
List<IConfigurationElement> elements = new ArrayList<>();
|
||||
IConfigurationElement element;
|
||||
|
||||
|
||||
// fake launch object
|
||||
String launchObject = "fakeObject";
|
||||
|
||||
|
@ -110,7 +111,6 @@ public class LaunchBarManagerTest {
|
|||
doReturn(descriptorTypeId).when(element).getAttribute("id");
|
||||
ILaunchDescriptorType descriptorType = mock(ILaunchDescriptorType.class);
|
||||
doReturn(descriptorType).when(element).createExecutableExtension("class");
|
||||
doReturn(true).when(descriptorType).ownsLaunchObject(launchObject);
|
||||
ILaunchDescriptor descriptor = mock(ILaunchDescriptor.class);
|
||||
doReturn(descriptor).when(descriptorType).getDescriptor(launchObject);
|
||||
doReturn(descriptorType).when(descriptor).getType();
|
||||
|
@ -142,13 +142,15 @@ public class LaunchBarManagerTest {
|
|||
doReturn("configProvider").when(element).getName();
|
||||
doReturn(descriptorTypeId).when(element).getAttribute("descriptorType");
|
||||
doReturn("10").when(element).getAttribute("priority");
|
||||
|
||||
|
||||
ILaunchConfigurationProvider configProvider = mock(ILaunchConfigurationProvider.class);
|
||||
doReturn(configProvider).when(element).createExecutableExtension("class");
|
||||
|
||||
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));
|
||||
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 {
|
||||
|
@ -158,13 +160,14 @@ public class LaunchBarManagerTest {
|
|||
}).when(configProvider).supports(eq(descriptor), any(IRemoteConnection.class));
|
||||
|
||||
doReturn(elements.toArray(new IConfigurationElement[0])).when(extension).getConfigurationElements();
|
||||
|
||||
|
||||
// Now inject the launch object
|
||||
LaunchBarManager manager = new LaunchBarManager(false) {
|
||||
@Override
|
||||
IExtensionPoint getExtensionPoint() throws CoreException {
|
||||
return extensionPoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
ILaunchManager getLaunchManager() {
|
||||
return launchManager;
|
||||
|
@ -183,10 +186,13 @@ public class LaunchBarManagerTest {
|
|||
assertEquals(launchConfig, manager.getActiveLaunchConfiguration());
|
||||
}
|
||||
|
||||
// TODO - test that changing active target type produces a different launch config type
|
||||
// TODO - test that changing active target type produces a different launch
|
||||
// config type
|
||||
// TODO - test that settings are maintained after a restart
|
||||
// TODO - test that two target types that map to the same desc type and config type share configs
|
||||
// TODO - test duplicating a config. make sure it's default desc and same targets
|
||||
// TODO - test that two target types that map to the same desc type and
|
||||
// config type share configs
|
||||
// TODO - test duplicating a config. make sure it's default desc and same
|
||||
// targets
|
||||
// TODO - test project descriptors and stuff
|
||||
// TODO - test descriptor takeovers (new descriptors on launchObjectChange
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue