mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-21 07:55: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"
|
class="org.eclipse.launchbar.core.internal.DefaultLaunchDescriptorType"
|
||||||
id="org.eclipse.launchbar.core.descriptorType.default"
|
id="org.eclipse.launchbar.core.descriptorType.default"
|
||||||
priority="0">
|
priority="0">
|
||||||
<enablement></enablement>
|
<enablement>
|
||||||
|
<instanceof
|
||||||
|
value="org.eclipse.debug.core.ILaunchConfiguration">
|
||||||
|
</instanceof></enablement>
|
||||||
</descriptorType>
|
</descriptorType>
|
||||||
<configProvider
|
<configProvider
|
||||||
class="org.eclipse.launchbar.core.DefaultLaunchConfigProvider"
|
class="org.eclipse.launchbar.core.DefaultLaunchConfigProvider"
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
</annotation>
|
</annotation>
|
||||||
<complexType>
|
<complexType>
|
||||||
<sequence>
|
<sequence>
|
||||||
<element ref="enablement"/>
|
<element ref="enablement" minOccurs="0" maxOccurs="1"/>
|
||||||
</sequence>
|
</sequence>
|
||||||
<attribute name="id" type="string" use="required">
|
<attribute name="id" type="string" use="required">
|
||||||
<annotation>
|
<annotation>
|
||||||
|
@ -98,6 +98,9 @@ descriptor with priority 5. Priority 0 is reserved for default descriptor.
|
||||||
</documentation>
|
</documentation>
|
||||||
</annotation>
|
</annotation>
|
||||||
<complexType>
|
<complexType>
|
||||||
|
<sequence>
|
||||||
|
<element ref="enablement" minOccurs="0" maxOccurs="1"/>
|
||||||
|
</sequence>
|
||||||
<attribute name="descriptorType" type="string" use="required">
|
<attribute name="descriptorType" type="string" use="required">
|
||||||
<annotation>
|
<annotation>
|
||||||
<documentation>
|
<documentation>
|
||||||
|
|
|
@ -3,24 +3,27 @@ package org.eclipse.launchbar.core;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.debug.core.DebugPlugin;
|
import org.eclipse.debug.core.DebugPlugin;
|
||||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||||
|
import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||||
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
||||||
import org.eclipse.debug.core.ILaunchManager;
|
import org.eclipse.debug.core.ILaunchManager;
|
||||||
import org.eclipse.launchbar.core.internal.Activator;
|
import org.eclipse.launchbar.core.internal.Activator;
|
||||||
import org.eclipse.remote.core.IRemoteConnection;
|
import org.eclipse.remote.core.IRemoteConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common launch config provider. Manages creating launch configurations and ensuring
|
* Common launch config provider. Manages creating launch configurations and
|
||||||
* duplicates are managed properly.
|
* ensuring duplicates are managed properly.
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractLaunchConfigProvider implements ILaunchConfigurationProvider {
|
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_ORIGINAL_NAME = Activator.PLUGIN_ID + ".originalName"; //$NON-NLS-1$
|
||||||
private static final String ATTR_PROVIDER_CLASS = Activator.PLUGIN_ID + ".providerClass"; //$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();
|
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
|
||||||
String name = launchManager.generateLaunchConfigurationName(descriptor.getName());
|
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);
|
populateLaunchConfiguration(descriptor, target, workingCopy);
|
||||||
|
|
||||||
|
@ -34,8 +37,12 @@ public abstract class AbstractLaunchConfigProvider implements ILaunchConfigurati
|
||||||
workingCopy.setAttribute(ATTR_PROVIDER_CLASS, getClass().getName());
|
workingCopy.setAttribute(ATTR_PROVIDER_CLASS, getClass().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
|
||||||
public 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
|
// Check for our class name but also that the config name
|
||||||
// matches what we originally set it to.
|
// matches what we originally set it to.
|
||||||
// This covers the case when the config was duplicated.
|
// This covers the case when the config was duplicated.
|
||||||
|
|
|
@ -6,15 +6,14 @@ import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||||
import org.eclipse.remote.core.IRemoteConnection;
|
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 {
|
public class DefaultLaunchConfigProvider implements ILaunchConfigurationProvider {
|
||||||
|
|
||||||
/**
|
|
||||||
* Only support local connection. Override to support different types of connection.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
||||||
// Only supports Local connection
|
// Only supports Local connection
|
||||||
|
@ -37,20 +36,20 @@ public class DefaultLaunchConfigProvider implements ILaunchConfigurationProvider
|
||||||
return descriptor.getAdapter(ILaunchConfiguration.class);
|
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
|
@Override
|
||||||
public boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
|
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
|
||||||
// return false so that the config is added as a launch object
|
// return false so that the configuration can become a launch object
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
|
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
|
||||||
// by contract we return true if we own or use to own configuration
|
return false;
|
||||||
return ownsLaunchConfiguration(configuration);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -63,15 +62,4 @@ public class DefaultLaunchConfigProvider implements ILaunchConfigurationProvider
|
||||||
// nothing to do
|
// 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;
|
package org.eclipse.launchbar.core;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.debug.core.ILaunchConfigurationListener;
|
||||||
public interface ILaunchBarManager {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A launch object has been added. Create a matching launch descriptor if available.
|
* Interface to the Launch Bar Manager.
|
||||||
*
|
*
|
||||||
* @param element launch object
|
* @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.
|
||||||
|
*
|
||||||
|
* @param element
|
||||||
|
* launch object
|
||||||
* @return the launch descriptor that got created, null of none was
|
* @return the launch descriptor that got created, null of none was
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
ILaunchDescriptor launchObjectAdded(Object launchObject) 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
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
void launchObjectRemoved(Object launchObject) throws CoreException;
|
void launchObjectRemoved(Object launchObject) throws CoreException;
|
||||||
|
@ -39,6 +49,4 @@ public interface ILaunchBarManager {
|
||||||
*/
|
*/
|
||||||
void launchObjectChanged(Object launchObject) throws CoreException;
|
void launchObjectChanged(Object launchObject) throws CoreException;
|
||||||
|
|
||||||
// TODO API for adding and removing types.
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,16 +16,16 @@ import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||||
import org.eclipse.remote.core.IRemoteConnection;
|
import org.eclipse.remote.core.IRemoteConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The provider of launch configurations of a given type for a given descriptor type
|
* The provider of launch configurations of a given type for a given descriptor
|
||||||
* and a given target type.
|
* type and a given target type.
|
||||||
*
|
*
|
||||||
* It is recommended to extend {@link AbstractLaunchConfigProvider} or one of it's
|
* It is recommended to extend {@link AbstractLaunchConfigProvider} or one of
|
||||||
* subclasses instead of implementing this directly.
|
* it's subclasses instead of implementing this directly.
|
||||||
*/
|
*/
|
||||||
public interface ILaunchConfigurationProvider {
|
public interface ILaunchConfigurationProvider {
|
||||||
/**
|
/**
|
||||||
* Does this config provider provide launch configurations for the combination
|
* Does this config provider provide launch configurations for the
|
||||||
* of descriptor and target.
|
* combination of descriptor and target.
|
||||||
*
|
*
|
||||||
* Note: this is called when filtering targets for a descriptor. Processing
|
* Note: this is called when filtering targets for a descriptor. Processing
|
||||||
* should be minimal.
|
* should be minimal.
|
||||||
|
@ -40,18 +40,21 @@ public interface ILaunchConfigurationProvider {
|
||||||
* Return the launch configuation type for the descriptor and target.
|
* Return the launch configuation type for the descriptor and target.
|
||||||
*
|
*
|
||||||
* @param descriptor
|
* @param descriptor
|
||||||
* @param target launch configuration type or null if not supported
|
* @param target
|
||||||
|
* launch configuration type or null if not supported
|
||||||
* @return
|
* @return
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor,
|
ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, IRemoteConnection target)
|
||||||
IRemoteConnection target) throws CoreException;
|
throws CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a launch configuration for the descriptor to launch on the target.
|
* Create a launch configuration for the descriptor to launch on the target.
|
||||||
*
|
*
|
||||||
* @param descriptor the descriptor to create the config for
|
* @param descriptor
|
||||||
* @param target the target to launch the config on
|
* the descriptor to create the config for
|
||||||
|
* @param target
|
||||||
|
* the target to launch the config on
|
||||||
* @return launch configuration
|
* @return launch configuration
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
|
@ -59,20 +62,20 @@ public interface ILaunchConfigurationProvider {
|
||||||
throws CoreException;
|
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 of provider owns this launch configuration
|
||||||
* @return true if this provider owns the launch configuration
|
|
||||||
* @throws CoreException
|
|
||||||
*/
|
*/
|
||||||
boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException;
|
boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A launch configuration has been removed.
|
* A launch configuration has been removed. This notification can be used to
|
||||||
* This notification can be used to purge internal cache for example.
|
* purge internal cache for example. This method is called after launch
|
||||||
* This method is called after launch configuration has been removed from file system,
|
* configuration has been removed from file system, so accessing its
|
||||||
* so accessing its attributes won't work.
|
* attributes won't work. If provider cannot determine if it owns it it
|
||||||
* If provider cannot determine if it owns it it should return false.
|
* should return false.
|
||||||
*
|
*
|
||||||
* @param configuration
|
* @param configuration
|
||||||
* @return true if provider owns this launch configuration
|
* @return true if provider owns this launch configuration
|
||||||
|
@ -81,23 +84,17 @@ public interface ILaunchConfigurationProvider {
|
||||||
boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException;
|
boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A launch configuration has been added. Provider can inspect it and associate with internal map.
|
* A launch configuration has been changed. Provider can inspect it to
|
||||||
* Provider should make sure it owns this launch configuration or it can modify it to take over.
|
* 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 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.
|
|
||||||
*
|
*
|
||||||
* @return true of provider owns this launch configuration
|
* @return true of provider owns this launch configuration
|
||||||
*/
|
*/
|
||||||
boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException;
|
boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A launch descriptor has been removed. Remove any launch configurations that were
|
* A launch descriptor has been removed. Remove any launch configurations
|
||||||
* created for it.
|
* that were created for it.
|
||||||
*
|
*
|
||||||
* @param descriptor
|
* @param descriptor
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
|
@ -105,13 +102,12 @@ public interface ILaunchConfigurationProvider {
|
||||||
void launchDescriptorRemoved(ILaunchDescriptor descriptor) throws CoreException;
|
void launchDescriptorRemoved(ILaunchDescriptor descriptor) throws CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A launch target has been removed. Remove any launch configurations that were created
|
* A launch target has been removed. Remove any launch configurations that
|
||||||
* for it.
|
* were created for it.
|
||||||
*
|
*
|
||||||
* @param target
|
* @param target
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
void launchTargetRemoved(IRemoteConnection target) throws CoreException;
|
void launchTargetRemoved(IRemoteConnection target) throws CoreException;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,17 +12,15 @@ package org.eclipse.launchbar.core;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.IAdaptable;
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a thing that can be launched.
|
* Represents a thing that can be launched. It is good practice that the
|
||||||
* It is good practice that the descriptor is adaptable to the launch object
|
* descriptor is adaptable to the launch object it is representing.
|
||||||
* it is representing.
|
|
||||||
*/
|
*/
|
||||||
public interface ILaunchDescriptor extends IAdaptable {
|
public interface ILaunchDescriptor extends IAdaptable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name to show in the launch descriptor selector.
|
* Name to show in the launch descriptor selector. Names must be unique for
|
||||||
* Names must be unique for all descriptors of a given type.
|
* all descriptors of a given type.
|
||||||
*
|
*
|
||||||
* @return name of the launch descriptor
|
* @return name of the launch descriptor
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -14,31 +14,20 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides mapping between launch objects and launch descriptors.
|
* Provides mapping between launch objects and launch descriptors.
|
||||||
*
|
|
||||||
* It is strongly recommended to extend AbstarctLaunchDescriptorType instead of implementing this directly
|
|
||||||
*/
|
*/
|
||||||
public interface ILaunchDescriptorType {
|
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.
|
* Return a descriptor for the given launch object.
|
||||||
*
|
*
|
||||||
* May return null to essentially eat the element so no other types
|
* May return null to essentially eat the element so no other types create a
|
||||||
* create a descriptor for it.
|
* 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
|
* @return the best descriptor
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -9,142 +9,103 @@ import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||||
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
|
||||||
import org.eclipse.launchbar.core.internal.Activator;
|
import org.eclipse.launchbar.core.internal.Activator;
|
||||||
import org.eclipse.remote.core.IRemoteConnection;
|
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 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, Map<IRemoteConnection, ILaunchConfiguration>> configMap = new HashMap<>();
|
||||||
|
private final Map<ILaunchDescriptor, ILaunchConfiguration> defaultConfigs = new HashMap<>();
|
||||||
private final Collection<ILaunchConfiguration> ownedConfigs = new LinkedHashSet<>();
|
private final Collection<ILaunchConfiguration> ownedConfigs = new LinkedHashSet<>();
|
||||||
|
|
||||||
protected String getConnectionNameAttribute() {
|
protected ILaunchBarManager getManager() {
|
||||||
return "org.eclipse.launchbar.core.connectionName";//$NON-NLS-1$
|
return Activator.getService(ILaunchBarManager.class);
|
||||||
}
|
|
||||||
|
|
||||||
protected String getConnectionTypeAttribute() {
|
|
||||||
return "org.eclipse.launchbar.core.connectionType";//$NON-NLS-1$
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target)
|
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
Map<IRemoteConnection, ILaunchConfiguration> targetMap = getTargetMap(descriptor);
|
if (target != null) {
|
||||||
|
Map<IRemoteConnection, ILaunchConfiguration> targetMap = configMap.get(descriptor);
|
||||||
|
if (targetMap != null) {
|
||||||
ILaunchConfiguration config = targetMap.get(target);
|
ILaunchConfiguration config = targetMap.get(target);
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
return config;
|
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);
|
} else {
|
||||||
|
ILaunchConfiguration config = defaultConfigs.get(descriptor);
|
||||||
|
if (config != null) {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected Map<IRemoteConnection, ILaunchConfiguration> getTargetMap(ILaunchDescriptor descriptor) {
|
// The config will get added to the cache when launchConfigurationAdded
|
||||||
Map<IRemoteConnection, ILaunchConfiguration> targetMap = configMap.get(descriptor);
|
// is called when the new config is saved.
|
||||||
|
return createLaunchConfiguration(descriptor, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
if (targetMap == null) {
|
||||||
targetMap = new HashMap<>();
|
targetMap = new HashMap<>();
|
||||||
configMap.put(descriptor, targetMap);
|
configMap.put(desc, targetMap);
|
||||||
}
|
}
|
||||||
return targetMap;
|
targetMap.put(target, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ILaunchConfiguration findLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target)
|
ownedConfigs.add(configuration);
|
||||||
throws CoreException {
|
|
||||||
for (ILaunchConfiguration configuration : ownedConfigs) {
|
|
||||||
if (descriptorAndTargetMatchesConfiguration(descriptor, target, configuration)) {
|
|
||||||
return configuration;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean descriptorAndTargetMatchesConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target,
|
|
||||||
ILaunchConfiguration configuration) {
|
|
||||||
if (targetMatchesConfiguration(target, configuration) == false)
|
|
||||||
return false;
|
|
||||||
if (descriptorMatchesConfiguration(descriptor, configuration) == false)
|
|
||||||
return false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* This method should be overridden to check that configuration does actually represent the descriptor.
|
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
|
||||||
* You don't need to check ownership since this method will be only called on owned configurations
|
if (ownsLaunchConfiguration(configuration)) {
|
||||||
*/
|
return addLaunchConfiguration(configuration);
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean targetMatchesConfiguration(IRemoteConnection target, ILaunchConfiguration configuration) {
|
|
||||||
String targetName;
|
|
||||||
try {
|
|
||||||
targetName = configuration.getAttribute(ATTR_CONNECTION_NAME, "");
|
|
||||||
} catch (CoreException e) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (target != null && target.getName().equals(targetName)) {
|
|
||||||
return true;
|
@Override
|
||||||
} else if (target == null && (targetName == null || targetName.isEmpty())) {
|
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;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
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
|
@Override
|
||||||
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
|
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
|
||||||
boolean owned = ownsLaunchConfiguration(configuration);
|
|
||||||
if (owned) {
|
|
||||||
ownedConfigs.remove(configuration);
|
ownedConfigs.remove(configuration);
|
||||||
for (Entry<ILaunchDescriptor, Map<IRemoteConnection, ILaunchConfiguration>> descEntry : configMap.entrySet()) {
|
for (Entry<ILaunchDescriptor, Map<IRemoteConnection, ILaunchConfiguration>> descEntry : configMap.entrySet()) {
|
||||||
for (Entry<IRemoteConnection, ILaunchConfiguration> targetEntry : descEntry.getValue().entrySet()) {
|
for (Entry<IRemoteConnection, ILaunchConfiguration> targetEntry : descEntry.getValue().entrySet()) {
|
||||||
|
@ -157,53 +118,37 @@ public abstract class PerTargetLaunchConfigProvider extends AbstractLaunchConfig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void launchDescriptorRemoved(ILaunchDescriptor descriptor) throws CoreException {
|
public void launchDescriptorRemoved(ILaunchDescriptor descriptor) throws CoreException {
|
||||||
Map<IRemoteConnection, ILaunchConfiguration> map = configMap.remove(descriptor);
|
Map<IRemoteConnection, ILaunchConfiguration> map = configMap.remove(descriptor);
|
||||||
if (map == null)
|
if (map != null) {
|
||||||
return;
|
|
||||||
for (ILaunchConfiguration config : map.values()) {
|
for (ILaunchConfiguration config : map.values()) {
|
||||||
ownedConfigs.remove(config);
|
ownedConfigs.remove(config);
|
||||||
config.delete(); // remove all auto-configs associated with descriptor
|
// remove all auto-configs associated with descriptor
|
||||||
|
config.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ILaunchConfiguration config = defaultConfigs.remove(descriptor);
|
||||||
|
if (config != null) {
|
||||||
|
ownedConfigs.remove(config);
|
||||||
|
config.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void launchTargetRemoved(IRemoteConnection target) throws CoreException {
|
public void launchTargetRemoved(IRemoteConnection target) throws CoreException {
|
||||||
for (Iterator<Entry<ILaunchDescriptor, Map<IRemoteConnection, ILaunchConfiguration>>> iterator = configMap.entrySet()
|
for (Iterator<Entry<ILaunchDescriptor, Map<IRemoteConnection, ILaunchConfiguration>>> iterator = configMap
|
||||||
.iterator(); iterator.hasNext();) {
|
.entrySet().iterator(); iterator.hasNext();) {
|
||||||
Entry<ILaunchDescriptor, Map<IRemoteConnection, ILaunchConfiguration>> descEntry = iterator.next();
|
Entry<ILaunchDescriptor, Map<IRemoteConnection, ILaunchConfiguration>> descEntry = iterator.next();
|
||||||
Map<IRemoteConnection, ILaunchConfiguration> map = descEntry.getValue();
|
Map<IRemoteConnection, ILaunchConfiguration> map = descEntry.getValue();
|
||||||
ILaunchConfiguration config = map.remove(target);
|
ILaunchConfiguration config = map.remove(target);
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
config.delete(); // remove all auto-configs associated with target
|
// remove all auto-configs associated with target
|
||||||
|
config.delete();
|
||||||
}
|
}
|
||||||
if (map.isEmpty()) {
|
if (map.isEmpty()) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
|
|
|
@ -14,8 +14,8 @@ import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.runtime.PlatformObject;
|
import org.eclipse.core.runtime.PlatformObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A reusable descriptor for wrapping projects that can be used by descriptor types
|
* A reusable descriptor for wrapping projects that can be used by descriptor
|
||||||
* that map to projects.
|
* types that map to projects.
|
||||||
*/
|
*/
|
||||||
public class ProjectLaunchDescriptor extends PlatformObject implements ILaunchDescriptor {
|
public class ProjectLaunchDescriptor extends PlatformObject implements ILaunchDescriptor {
|
||||||
|
|
||||||
|
@ -49,4 +49,36 @@ public class ProjectLaunchDescriptor extends PlatformObject implements ILaunchDe
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getName(); // for debugging purposes
|
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.core.runtime.CoreException;
|
||||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||||
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
||||||
|
import org.eclipse.launchbar.core.internal.Activator;
|
||||||
import org.eclipse.remote.core.IRemoteConnection;
|
import org.eclipse.remote.core.IRemoteConnection;
|
||||||
|
|
||||||
public abstract class ProjectPerTargetLaunchConfigProvider extends PerTargetLaunchConfigProvider {
|
public abstract class ProjectPerTargetLaunchConfigProvider extends PerTargetLaunchConfigProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
||||||
return (descriptor.getAdapter(IProject.class) != null);
|
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
|
@Override
|
||||||
protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target,
|
protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target,
|
||||||
ILaunchConfigurationWorkingCopy workingCopy) throws CoreException {
|
ILaunchConfigurationWorkingCopy workingCopy) throws CoreException {
|
||||||
super.populateLaunchConfiguration(descriptor, target, workingCopy);
|
super.populateLaunchConfiguration(descriptor, target, workingCopy);
|
||||||
|
|
||||||
// Add our project to the mapped resources
|
// Add our project to the mapped resources
|
||||||
IProject project = descriptor.getAdapter(IProject.class);
|
IProject project = descriptor.getAdapter(IProject.class);
|
||||||
IResource[] mappedResources = workingCopy.getMappedResources();
|
IResource[] mappedResources = workingCopy.getMappedResources();
|
||||||
|
@ -63,4 +42,25 @@ public abstract class ProjectPerTargetLaunchConfigProvider extends PerTargetLaun
|
||||||
workingCopy.setMappedResources(newResources);
|
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;
|
import org.eclipse.launchbar.core.ILaunchDescriptorType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A special descriptor type that managed configurations that aren't owned
|
* A special descriptor type that managed configurations that aren't owned by
|
||||||
* by other descriptor types.
|
* other descriptor types.
|
||||||
*/
|
*/
|
||||||
public class DefaultLaunchDescriptorType implements ILaunchDescriptorType {
|
public class DefaultLaunchDescriptorType implements ILaunchDescriptorType {
|
||||||
|
|
||||||
|
@ -20,14 +20,9 @@ public class DefaultLaunchDescriptorType implements ILaunchDescriptorType {
|
||||||
private Map<ILaunchConfiguration, DefaultLaunchDescriptor> descriptors = new HashMap<>();
|
private Map<ILaunchConfiguration, DefaultLaunchDescriptor> descriptors = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean ownsLaunchObject(Object element) {
|
public ILaunchDescriptor getDescriptor(Object launchObject) {
|
||||||
return element instanceof ILaunchConfiguration;
|
if (launchObject instanceof ILaunchConfiguration) {
|
||||||
}
|
ILaunchConfiguration config = (ILaunchConfiguration) launchObject;
|
||||||
|
|
||||||
@Override
|
|
||||||
public ILaunchDescriptor getDescriptor(Object element) {
|
|
||||||
if (element instanceof ILaunchConfiguration) {
|
|
||||||
ILaunchConfiguration config = (ILaunchConfiguration) element;
|
|
||||||
try {
|
try {
|
||||||
if (config.getType() != null && config.getType().isPublic()
|
if (config.getType() != null && config.getType().isPublic()
|
||||||
&& !(config.getAttribute(ILaunchManager.ATTR_PRIVATE, false))) {
|
&& !(config.getAttribute(ILaunchManager.ATTR_PRIVATE, false))) {
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||||
import org.eclipse.debug.core.DebugPlugin;
|
import org.eclipse.debug.core.DebugPlugin;
|
||||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||||
import org.eclipse.debug.core.ILaunchConfigurationListener;
|
|
||||||
import org.eclipse.debug.core.ILaunchConfigurationType;
|
import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||||
import org.eclipse.debug.core.ILaunchManager;
|
import org.eclipse.debug.core.ILaunchManager;
|
||||||
import org.eclipse.debug.core.ILaunchMode;
|
import org.eclipse.debug.core.ILaunchMode;
|
||||||
|
@ -52,14 +51,19 @@ import org.osgi.service.prefs.Preferences;
|
||||||
/**
|
/**
|
||||||
* The brains of the launch bar.
|
* 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 {
|
public interface Listener {
|
||||||
void activeLaunchDescriptorChanged();
|
void activeLaunchDescriptorChanged();
|
||||||
|
|
||||||
void activeLaunchModeChanged();
|
void activeLaunchModeChanged();
|
||||||
|
|
||||||
void activeLaunchTargetChanged();
|
void activeLaunchTargetChanged();
|
||||||
|
|
||||||
void launchDescriptorRemoved(ILaunchDescriptor descriptor);
|
void launchDescriptorRemoved(ILaunchDescriptor descriptor);
|
||||||
|
|
||||||
void launchTargetsChanged();
|
void launchTargetsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +198,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
|
|
||||||
descriptorTypes.put(typeInfo.getId(), typeInfo);
|
descriptorTypes.put(typeInfo.getId(), typeInfo);
|
||||||
|
|
||||||
|
|
||||||
if (configProviders.get(typeInfo.getId()) == null) {
|
if (configProviders.get(typeInfo.getId()) == null) {
|
||||||
// Make sure we initialize the list
|
// Make sure we initialize the list
|
||||||
configProviders.put(typeInfo.getId(), new ArrayList<LaunchConfigProviderInfo>());
|
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 (IExtension extension : extensions) {
|
||||||
for (IConfigurationElement element : extension.getConfigurationElements()) {
|
for (IConfigurationElement element : extension.getConfigurationElements()) {
|
||||||
try {
|
try {
|
||||||
String elementName = element.getName();
|
String elementName = element.getName();
|
||||||
if (elementName.equals("objectProvider")) { //$NON-NLS-1$
|
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);
|
objectProviders.add(objectProvider);
|
||||||
objectProvider.init(this);
|
objectProvider.init(this);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} 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);
|
setActiveLaunchDescriptor(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeDescriptor(Object launchObject, ILaunchDescriptor descriptor) throws CoreException {
|
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, IRemoteConnection target)
|
||||||
objectDescriptorMap.remove(launchObject); // remove launch object unconditionally
|
throws CoreException {
|
||||||
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 {
|
|
||||||
if (descriptor == null)
|
if (descriptor == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
for (LaunchConfigProviderInfo provider : configProviders.get(getDescriptorTypeId(descriptor.getType()))) {
|
for (LaunchConfigProviderInfo providerInfo : configProviders.get(getDescriptorTypeId(descriptor.getType()))) {
|
||||||
ILaunchConfigurationType type = provider.getProvider().getLaunchConfigurationType(descriptor, target);
|
if (providerInfo.enabled(descriptor) && providerInfo.enabled(target)) {
|
||||||
|
ILaunchConfigurationType type = providerInfo.getProvider().getLaunchConfigurationType(descriptor,
|
||||||
|
target);
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
return type;
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Throwable e) {
|
|
||||||
Activator.log(e); // one of used defined launch types is misbehaving
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,51 +325,77 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
public ILaunchDescriptor launchObjectAdded(Object launchObject) {
|
public ILaunchDescriptor launchObjectAdded(Object launchObject) {
|
||||||
Activator.trace("launch object added " + launchObject); //$NON-NLS-1$
|
Activator.trace("launch object added " + launchObject); //$NON-NLS-1$
|
||||||
ILaunchDescriptor desc = objectDescriptorMap.get(launchObject);
|
ILaunchDescriptor desc = objectDescriptorMap.get(launchObject);
|
||||||
if (desc != null)
|
if (desc != null) {
|
||||||
return desc;
|
return desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (LaunchDescriptorTypeInfo descriptorInfo : orderedDescriptorTypes) {
|
||||||
try {
|
try {
|
||||||
ILaunchDescriptorType type = ownsLaunchObject(launchObject);
|
if (descriptorInfo.enabled(launchObject)) {
|
||||||
if (type != null) {
|
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);
|
desc = type.getDescriptor(launchObject);
|
||||||
if (desc != null) {
|
if (desc != null) {
|
||||||
addDescriptor(launchObject, desc);
|
addDescriptor(launchObject, desc);
|
||||||
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return desc;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void launchObjectRemoved(Object launchObject) throws CoreException {
|
public void launchObjectRemoved(Object launchObject) throws CoreException {
|
||||||
Activator.trace("launch object removed " + launchObject); //$NON-NLS-1$
|
Activator.trace("launch object removed " + launchObject); //$NON-NLS-1$
|
||||||
ILaunchDescriptor desc = objectDescriptorMap.get(launchObject);
|
ILaunchDescriptor descriptor = objectDescriptorMap.remove(launchObject);
|
||||||
removeDescriptor(launchObject, desc);
|
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
|
@Override
|
||||||
public void launchObjectChanged(Object launchObject) throws CoreException {
|
public void launchObjectChanged(Object launchObject) throws CoreException {
|
||||||
// TODO deal with object renames here, somehow
|
// TODO deal with object renames here, somehow
|
||||||
|
|
||||||
// check if a new descriptor wants to take over
|
|
||||||
ILaunchDescriptor origDesc = objectDescriptorMap.get(launchObject);
|
ILaunchDescriptor origDesc = objectDescriptorMap.get(launchObject);
|
||||||
ILaunchDescriptorType newDescType = ownsLaunchObject(launchObject);
|
if (origDesc == null) {
|
||||||
|
// See if anyone wants it now
|
||||||
if (newDescType != null) {
|
launchObjectAdded(launchObject);
|
||||||
if (origDesc == null || !origDesc.getType().equals(newDescType)) {
|
return;
|
||||||
// we have a take over
|
|
||||||
if (origDesc != null) {
|
|
||||||
removeDescriptor(launchObject, origDesc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ILaunchDescriptor newDesc = newDescType.getDescriptor(launchObject);
|
// check if descriptor still wants it
|
||||||
if (newDesc != null) {
|
ILaunchDescriptorType origDescType = origDesc.getType();
|
||||||
addDescriptor(launchObject, newDesc);
|
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() {
|
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());
|
ArrayList<ILaunchDescriptor> values = new ArrayList<>(descriptors.values());
|
||||||
Collections.reverse(values);
|
Collections.reverse(values);
|
||||||
return values.toArray(new ILaunchDescriptor[values.size()]);
|
return values.toArray(new ILaunchDescriptor[values.size()]);
|
||||||
|
@ -415,18 +421,23 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
public void setActiveLaunchDescriptor(ILaunchDescriptor descriptor) throws CoreException {
|
public void setActiveLaunchDescriptor(ILaunchDescriptor descriptor) throws CoreException {
|
||||||
Activator.trace("set active descriptor " + descriptor); //$NON-NLS-1$
|
Activator.trace("set active descriptor " + descriptor); //$NON-NLS-1$
|
||||||
if (activeLaunchDesc == descriptor) {
|
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();
|
syncActiveTarget();
|
||||||
syncActiveMode();
|
syncActiveMode();
|
||||||
Activator.trace("resync for " + descriptor); //$NON-NLS-1$
|
Activator.trace("resync for " + descriptor); //$NON-NLS-1$
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (descriptor != null && !descriptors.containsValue(descriptor))
|
if (descriptor != null && !descriptors.containsValue(descriptor)) {
|
||||||
throw new IllegalStateException(Messages.LaunchBarManager_1);
|
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;
|
activeLaunchDesc = descriptor;
|
||||||
if (descriptor != null) { // keeps most used descriptor last
|
if (descriptor != null) {
|
||||||
|
// keeps most used descriptor last
|
||||||
Pair<String, String> id = getDescriptorId(descriptor);
|
Pair<String, String> id = getDescriptorId(descriptor);
|
||||||
descriptors.remove(id);
|
descriptors.remove(id);
|
||||||
descriptors.put(id, descriptor);
|
descriptors.put(id, descriptor);
|
||||||
|
@ -447,7 +458,8 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
|
|
||||||
// Store the desc order, active one is the last one
|
// Store the desc order, active one is the last one
|
||||||
StringBuffer buff = new StringBuffer();
|
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) {
|
if (buff.length() > 0) {
|
||||||
buff.append(',');
|
buff.append(',');
|
||||||
}
|
}
|
||||||
|
@ -485,17 +497,15 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ILaunchMode foundMode = null;
|
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();
|
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?
|
if (supportedModes.length > 0) { // mna, what if no modes are supported?
|
||||||
String modeNames[] = new String[] {
|
String modeNames[] = new String[] { storedModeId, lastActiveModeId, "run", //$NON-NLS-1$
|
||||||
storedModeId,
|
|
||||||
lastActiveModeId,
|
|
||||||
"run", //$NON-NLS-1$
|
|
||||||
"debug", //$NON-NLS-1$
|
"debug", //$NON-NLS-1$
|
||||||
supportedModes[0].getIdentifier()
|
supportedModes[0].getIdentifier() };
|
||||||
};
|
|
||||||
for (int i = 0; i < modeNames.length; i++) {
|
for (int i = 0; i < modeNames.length; i++) {
|
||||||
foundMode = getLaunchManager().getLaunchMode(modeNames[i]);
|
foundMode = getLaunchManager().getLaunchMode(modeNames[i]);
|
||||||
if (supportsMode(foundMode))
|
if (supportsMode(foundMode))
|
||||||
|
@ -554,7 +564,8 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireActiveLaunchDescriptorChanged() {
|
private void fireActiveLaunchDescriptorChanged() {
|
||||||
if (!initialized) return;
|
if (!initialized)
|
||||||
|
return;
|
||||||
for (Listener listener : listeners) {
|
for (Listener listener : listeners) {
|
||||||
try {
|
try {
|
||||||
listener.activeLaunchDescriptorChanged();
|
listener.activeLaunchDescriptorChanged();
|
||||||
|
@ -612,7 +623,8 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireActiveLaunchModeChanged() {
|
private void fireActiveLaunchModeChanged() {
|
||||||
if (!initialized) return;
|
if (!initialized)
|
||||||
|
return;
|
||||||
for (Listener listener : listeners) {
|
for (Listener listener : listeners) {
|
||||||
try {
|
try {
|
||||||
listener.activeLaunchModeChanged();
|
listener.activeLaunchModeChanged();
|
||||||
|
@ -622,7 +634,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void storeLaunchMode(ILaunchDescriptor desc, ILaunchMode mode) {
|
private void storeLaunchMode(ILaunchDescriptor desc, ILaunchMode mode) {
|
||||||
if (mode != null) {
|
if (mode != null) {
|
||||||
// per desc store, desc can null if will be stored globally
|
// per desc store, desc can null if will be stored globally
|
||||||
|
@ -646,11 +657,13 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
|
|
||||||
boolean supportsTarget(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
boolean supportsTarget(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
||||||
String descriptorTypeId = getDescriptorTypeId(descriptor.getType());
|
String descriptorTypeId = getDescriptorTypeId(descriptor.getType());
|
||||||
for (LaunchConfigProviderInfo provider : configProviders.get(descriptorTypeId)) {
|
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descriptorTypeId)) {
|
||||||
try {
|
try {
|
||||||
if (provider.getProvider().supports(descriptor, target)) {
|
if (providerInfo.enabled(descriptor) && providerInfo.enabled(target)) {
|
||||||
|
if (providerInfo.getProvider().supports(descriptor, target)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
|
@ -664,6 +677,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets preferred target for launch descriptor
|
* Sets preferred target for launch descriptor
|
||||||
|
*
|
||||||
* @param desc
|
* @param desc
|
||||||
* @param target
|
* @param target
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
|
@ -682,19 +696,23 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
}
|
}
|
||||||
activeLaunchTarget = target;
|
activeLaunchTarget = target;
|
||||||
storeLaunchTarget(activeLaunchDesc, target);
|
storeLaunchTarget(activeLaunchDesc, target);
|
||||||
|
syncActiveMode();
|
||||||
fireActiveLaunchTargetChanged(); // notify listeners
|
fireActiveLaunchTargetChanged(); // notify listeners
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeLaunchTarget(ILaunchDescriptor desc, IRemoteConnection target) {
|
private void storeLaunchTarget(ILaunchDescriptor desc, IRemoteConnection target) {
|
||||||
if (target == null) {
|
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
|
// per desc store, desc can be null means it store globally
|
||||||
setPreference(getPerDescriptorStore(desc), PREF_ACTIVE_LAUNCH_TARGET, toString(getTargetId(target)));
|
setPreference(getPerDescriptorStore(desc), PREF_ACTIVE_LAUNCH_TARGET, toString(getTargetId(target)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireActiveLaunchTargetChanged() {
|
private void fireActiveLaunchTargetChanged() {
|
||||||
if (!initialized) return;
|
if (!initialized)
|
||||||
|
return;
|
||||||
for (Listener listener : listeners) {
|
for (Listener listener : listeners) {
|
||||||
try {
|
try {
|
||||||
listener.activeLaunchTargetChanged();
|
listener.activeLaunchTargetChanged();
|
||||||
|
@ -713,7 +731,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
return getLaunchConfiguration(activeLaunchDesc, activeLaunchTarget);
|
return getLaunchConfiguration(activeLaunchDesc, activeLaunchTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target)
|
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
if (descriptor == null) {
|
if (descriptor == null) {
|
||||||
|
@ -723,15 +740,17 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
String descTypeId = getDescriptorTypeId(descriptor.getType());
|
String descTypeId = getDescriptorTypeId(descriptor.getType());
|
||||||
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeId)) {
|
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeId)) {
|
||||||
try {
|
try {
|
||||||
|
if (providerInfo.enabled(descriptor) && providerInfo.enabled(target)) {
|
||||||
ILaunchConfigurationProvider provider = providerInfo.getProvider();
|
ILaunchConfigurationProvider provider = providerInfo.getProvider();
|
||||||
// between multiple provider who support this descriptor we need to find one
|
// between multiple provider who support this descriptor we
|
||||||
// that supports this target
|
// need to find one that supports this target
|
||||||
if (provider.supports(descriptor, target)) {
|
if (provider.supports(descriptor, target)) {
|
||||||
ILaunchConfiguration config = provider.getLaunchConfiguration(descriptor, target);
|
ILaunchConfiguration config = provider.getLaunchConfiguration(descriptor, target);
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
|
@ -757,10 +776,11 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
for (LaunchDescriptorTypeInfo descTypeInfo : orderedDescriptorTypes) {
|
for (LaunchDescriptorTypeInfo descTypeInfo : orderedDescriptorTypes) {
|
||||||
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeInfo.getId())) {
|
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeInfo.getId())) {
|
||||||
try {
|
try {
|
||||||
providerInfo.getProvider().launchConfigurationAdded(configuration);
|
if (providerInfo.enabled(configuration)) {
|
||||||
if (providerInfo.getProvider().ownsLaunchConfiguration(configuration)) {
|
if (providerInfo.getProvider().launchConfigurationAdded(configuration)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
|
@ -778,13 +798,14 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO do I need to do this if configs are launch objects?
|
|
||||||
for (LaunchDescriptorTypeInfo descTypeInfo : orderedDescriptorTypes) {
|
for (LaunchDescriptorTypeInfo descTypeInfo : orderedDescriptorTypes) {
|
||||||
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeInfo.getId())) {
|
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeInfo.getId())) {
|
||||||
try {
|
try {
|
||||||
|
if (providerInfo.enabled(configuration)) {
|
||||||
if (providerInfo.getProvider().launchConfigurationRemoved(configuration)) {
|
if (providerInfo.getProvider().launchConfigurationRemoved(configuration)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
|
@ -797,7 +818,11 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
for (LaunchDescriptorTypeInfo descTypeInfo : orderedDescriptorTypes) {
|
for (LaunchDescriptorTypeInfo descTypeInfo : orderedDescriptorTypes) {
|
||||||
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeInfo.getId())) {
|
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeInfo.getId())) {
|
||||||
try {
|
try {
|
||||||
providerInfo.getProvider().launchConfigurationChanged(configuration);
|
if (providerInfo.enabled(configuration)) {
|
||||||
|
if (providerInfo.getProvider().launchConfigurationChanged(configuration)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
package org.eclipse.launchbar.core.internal;
|
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.CoreException;
|
||||||
import org.eclipse.core.runtime.IConfigurationElement;
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.launchbar.core.ILaunchConfigurationProvider;
|
import org.eclipse.launchbar.core.ILaunchConfigurationProvider;
|
||||||
|
|
||||||
public class LaunchConfigProviderInfo {
|
public class LaunchConfigProviderInfo {
|
||||||
|
@ -9,6 +14,7 @@ public class LaunchConfigProviderInfo {
|
||||||
private final int priority;
|
private final int priority;
|
||||||
private IConfigurationElement element;
|
private IConfigurationElement element;
|
||||||
private ILaunchConfigurationProvider provider;
|
private ILaunchConfigurationProvider provider;
|
||||||
|
private Expression expression;
|
||||||
|
|
||||||
public LaunchConfigProviderInfo(IConfigurationElement element) {
|
public LaunchConfigProviderInfo(IConfigurationElement element) {
|
||||||
this.descriptorTypeId = element.getAttribute("descriptorType"); //$NON-NLS-1$
|
this.descriptorTypeId = element.getAttribute("descriptorType"); //$NON-NLS-1$
|
||||||
|
@ -23,6 +29,27 @@ public class LaunchConfigProviderInfo {
|
||||||
priority = priorityNum;
|
priority = priorityNum;
|
||||||
|
|
||||||
this.element = element;
|
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() {
|
public String getDescriptorTypeId() {
|
||||||
|
@ -40,4 +67,12 @@ public class LaunchConfigProviderInfo {
|
||||||
}
|
}
|
||||||
return provider;
|
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);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.element = element;
|
this.element = element;
|
||||||
|
|
||||||
IConfigurationElement[] enabledExpressions = element.getChildren("enablement");//$NON-NLS-1$
|
IConfigurationElement[] enabledExpressions = element.getChildren("enablement");//$NON-NLS-1$
|
||||||
if (enabledExpressions == null || enabledExpressions.length == 0) {
|
if (enabledExpressions == null || enabledExpressions.length == 0) {
|
||||||
Activator.log(new Status(Status.WARNING, Activator.PLUGIN_ID,
|
Activator.log(new Status(Status.WARNING, Activator.PLUGIN_ID,
|
||||||
|
@ -51,7 +53,7 @@ public class LaunchDescriptorTypeInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used for testing
|
// Used for testing
|
||||||
public LaunchDescriptorTypeInfo(String id, int priority, ILaunchDescriptorType type) {
|
LaunchDescriptorTypeInfo(String id, int priority, ILaunchDescriptorType type) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
@ -73,10 +75,10 @@ public class LaunchDescriptorTypeInfo {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean ownsLaunchObject(Object object) throws CoreException {
|
public boolean enabled(Object launchObject) throws CoreException {
|
||||||
if (expression == null)
|
if (expression == null)
|
||||||
return true;
|
return true;
|
||||||
EvaluationResult result = expression.evaluate(new EvaluationContext(null, object));
|
EvaluationResult result = expression.evaluate(new EvaluationContext(null, launchObject));
|
||||||
return (result == EvaluationResult.TRUE);
|
return (result == EvaluationResult.TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -25,8 +25,8 @@ import org.eclipse.launchbar.core.ILaunchBarManager;
|
||||||
import org.eclipse.launchbar.core.ILaunchObjectProvider;
|
import org.eclipse.launchbar.core.ILaunchObjectProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Injects IProject objects from platform resources into the launch bar model for potential
|
* Injects IProject objects from platform resources into the launch bar model
|
||||||
* project descriptors.
|
* for potential project descriptors.
|
||||||
*/
|
*/
|
||||||
public class ProjectLaunchObjectProvider implements ILaunchObjectProvider, IResourceChangeListener {
|
public class ProjectLaunchObjectProvider implements ILaunchObjectProvider, IResourceChangeListener {
|
||||||
private ILaunchBarManager manager;
|
private ILaunchBarManager manager;
|
||||||
|
@ -60,9 +60,12 @@ public class ProjectLaunchObjectProvider implements ILaunchObjectProvider, IReso
|
||||||
} else if ((kind & IResourceDelta.REMOVED) != 0) {
|
} else if ((kind & IResourceDelta.REMOVED) != 0) {
|
||||||
manager.launchObjectRemoved(project);
|
manager.launchObjectRemoved(project);
|
||||||
} else if ((kind & IResourceDelta.CHANGED) != 0) {
|
} else if ((kind & IResourceDelta.CHANGED) != 0) {
|
||||||
// TODO may need to be more concise as to what changes we're looking for
|
int flags = delta.getFlags();
|
||||||
|
// Right now, only care about nature changes
|
||||||
|
if ((flags & IResourceDelta.DESCRIPTION) != 0) {
|
||||||
manager.launchObjectChanged(project);
|
manager.launchObjectChanged(project);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
} else if (res instanceof IFile || res instanceof IFolder) {
|
} else if (res instanceof IFile || res instanceof IFolder) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -16,10 +16,10 @@ import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.debug.core.DebugPlugin;
|
import org.eclipse.debug.core.DebugPlugin;
|
||||||
|
@ -38,6 +38,7 @@ import org.junit.FixMethodOrder;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runners.MethodSorters;
|
import org.junit.runners.MethodSorters;
|
||||||
|
|
||||||
|
@SuppressWarnings("nls")
|
||||||
@FixMethodOrder(MethodSorters.JVM)
|
@FixMethodOrder(MethodSorters.JVM)
|
||||||
public class PerTargetLaunchConfigProviderTest {
|
public class PerTargetLaunchConfigProviderTest {
|
||||||
private IRemoteServicesManager remoteServiceManager;
|
private IRemoteServicesManager remoteServiceManager;
|
||||||
|
@ -85,16 +86,62 @@ public class PerTargetLaunchConfigProviderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PerTargetLaunchConfigProvider1 extends PerTargetLaunchConfigProvider {
|
public class PerTargetLaunchConfigProvider1 extends PerTargetLaunchConfigProvider {
|
||||||
|
public static final String CONNECTION_NAME_ATTR = "connectionName";
|
||||||
|
private ILaunchBarManager manager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, IRemoteConnection target)
|
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor,
|
||||||
throws CoreException {
|
IRemoteConnection target) throws CoreException {
|
||||||
return launchConfigType;
|
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
|
@Test
|
||||||
|
@ -102,9 +149,7 @@ public class PerTargetLaunchConfigProviderTest {
|
||||||
ILaunchConfiguration launchConfig = launchConfigType.newInstance(null, launchName).doSave();
|
ILaunchConfiguration launchConfig = launchConfigType.newInstance(null, launchName).doSave();
|
||||||
ILaunchConfigurationWorkingCopy launchConfigWC = launchConfig.getWorkingCopy();
|
ILaunchConfigurationWorkingCopy launchConfigWC = launchConfig.getWorkingCopy();
|
||||||
provider.populateLaunchConfiguration(descriptor, localTarget, launchConfigWC);
|
provider.populateLaunchConfiguration(descriptor, localTarget, launchConfigWC);
|
||||||
//assertEquals(launchConfig.getName(), launchConfigWC.getAttribute(LaunchBarManager2Test.ATTR_ORIGINAL_NAME, ""));
|
assertTrue(provider.ownsLaunchConfiguration(launchConfigWC));
|
||||||
//assertEquals(provider.getClass().getName(), launchConfigWC.getAttribute(LaunchBarManager2Test.ATTR_PROVIDER_CLASS, ""));
|
|
||||||
assertTrue(provider.ownsLaunchConfigurationByAttributes(launchConfigWC));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -139,7 +184,8 @@ public class PerTargetLaunchConfigProviderTest {
|
||||||
assertNotNull(launchConfiguration1);
|
assertNotNull(launchConfiguration1);
|
||||||
// reset provider
|
// reset provider
|
||||||
provider = new PerTargetLaunchConfigProvider1();
|
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);
|
ILaunchConfiguration launchConfiguration2 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
assertNotNull(launchConfiguration2);
|
assertNotNull(launchConfiguration2);
|
||||||
assertEquals(launchConfiguration1, launchConfiguration2);
|
assertEquals(launchConfiguration1, launchConfiguration2);
|
||||||
|
@ -149,7 +195,7 @@ public class PerTargetLaunchConfigProviderTest {
|
||||||
public void testGetTarget() throws CoreException {
|
public void testGetTarget() throws CoreException {
|
||||||
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, localTarget);
|
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
assertNotNull(launchConfiguration1);
|
assertNotNull(launchConfiguration1);
|
||||||
assertSame(localTarget, provider.getTarget(launchConfiguration1));
|
assertSame(localTarget, provider.getLaunchTarget(launchConfiguration1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -177,7 +223,7 @@ public class PerTargetLaunchConfigProviderTest {
|
||||||
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, localTarget);
|
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
assertNotNull(launchConfiguration1);
|
assertNotNull(launchConfiguration1);
|
||||||
ILaunchConfigurationWorkingCopy wc = launchConfiguration1.getWorkingCopy();
|
ILaunchConfigurationWorkingCopy wc = launchConfiguration1.getWorkingCopy();
|
||||||
wc.setAttribute(provider.getConnectionNameAttribute(), otherTarget.getName());
|
wc.setAttribute(PerTargetLaunchConfigProvider1.CONNECTION_NAME_ATTR, otherTarget.getName());
|
||||||
wc.doSave();
|
wc.doSave();
|
||||||
provider.launchConfigurationChanged(launchConfiguration1);
|
provider.launchConfigurationChanged(launchConfiguration1);
|
||||||
// provider.launchConfigurationChanged(lc3);
|
// provider.launchConfigurationChanged(lc3);
|
||||||
|
@ -192,10 +238,14 @@ public class PerTargetLaunchConfigProviderTest {
|
||||||
assertNotNull(launchConfiguration1);
|
assertNotNull(launchConfiguration1);
|
||||||
ILaunchConfigurationWorkingCopy wc = launchConfiguration1.getWorkingCopy();
|
ILaunchConfigurationWorkingCopy wc = launchConfiguration1.getWorkingCopy();
|
||||||
wc.setAttribute(LaunchBarManager2Test.ATTR_ORIGINAL_NAME, "bla");
|
wc.setAttribute(LaunchBarManager2Test.ATTR_ORIGINAL_NAME, "bla");
|
||||||
wc.doSave();
|
launchConfiguration1 = wc.doSave();
|
||||||
provider.launchConfigurationChanged(launchConfiguration1);
|
provider.launchConfigurationChanged(launchConfiguration1);
|
||||||
// we should have lost ownership
|
// we should have lost ownership
|
||||||
assertFalse(provider.ownsLaunchConfiguration(launchConfiguration1));
|
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);
|
ILaunchConfiguration launchConfiguration2 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
assertNotNull(launchConfiguration2);
|
assertNotNull(launchConfiguration2);
|
||||||
assertNotEquals(launchConfiguration1, launchConfiguration2);
|
assertNotEquals(launchConfiguration1, launchConfiguration2);
|
||||||
|
@ -206,7 +256,6 @@ public class PerTargetLaunchConfigProviderTest {
|
||||||
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, localTarget);
|
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
assertNotNull(launchConfiguration1);
|
assertNotNull(launchConfiguration1);
|
||||||
provider.launchDescriptorRemoved(descriptor);
|
provider.launchDescriptorRemoved(descriptor);
|
||||||
assertEquals(0, provider.getTargetMap(descriptor).size());
|
|
||||||
assertFalse(provider.ownsLaunchConfiguration(launchConfiguration1));
|
assertFalse(provider.ownsLaunchConfiguration(launchConfiguration1));
|
||||||
assertFalse(launchConfiguration1.exists());
|
assertFalse(launchConfiguration1.exists());
|
||||||
}
|
}
|
||||||
|
@ -214,7 +263,6 @@ public class PerTargetLaunchConfigProviderTest {
|
||||||
@Test
|
@Test
|
||||||
public void testLaunchDescriptorRemoved2() throws CoreException {
|
public void testLaunchDescriptorRemoved2() throws CoreException {
|
||||||
provider.launchDescriptorRemoved(descriptor);
|
provider.launchDescriptorRemoved(descriptor);
|
||||||
assertEquals(0, provider.getTargetMap(descriptor).size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -222,7 +270,6 @@ public class PerTargetLaunchConfigProviderTest {
|
||||||
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, otherTarget);
|
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, otherTarget);
|
||||||
assertNotNull(launchConfiguration1);
|
assertNotNull(launchConfiguration1);
|
||||||
provider.launchTargetRemoved(otherTarget);
|
provider.launchTargetRemoved(otherTarget);
|
||||||
assertEquals(0, provider.getTargetMap(descriptor).size());
|
|
||||||
assertFalse(launchConfiguration1.exists());
|
assertFalse(launchConfiguration1.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +280,6 @@ public class PerTargetLaunchConfigProviderTest {
|
||||||
ILaunchConfiguration launchConfiguration2 = provider.getLaunchConfiguration(descriptor, localTarget);
|
ILaunchConfiguration launchConfiguration2 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
assertNotNull(launchConfiguration2);
|
assertNotNull(launchConfiguration2);
|
||||||
provider.launchTargetRemoved(otherTarget);
|
provider.launchTargetRemoved(otherTarget);
|
||||||
assertEquals(1, provider.getTargetMap(descriptor).size());
|
|
||||||
assertFalse(launchConfiguration1.exists());
|
assertFalse(launchConfiguration1.exists());
|
||||||
assertTrue(launchConfiguration2.exists());
|
assertTrue(launchConfiguration2.exists());
|
||||||
}
|
}
|
||||||
|
@ -243,7 +289,6 @@ public class PerTargetLaunchConfigProviderTest {
|
||||||
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, otherTarget);
|
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, otherTarget);
|
||||||
assertNotNull(launchConfiguration1);
|
assertNotNull(launchConfiguration1);
|
||||||
provider.launchTargetRemoved(localTarget);
|
provider.launchTargetRemoved(localTarget);
|
||||||
assertEquals(1, provider.getTargetMap(descriptor).size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -252,7 +297,6 @@ public class PerTargetLaunchConfigProviderTest {
|
||||||
assertNotNull(launchConfiguration1);
|
assertNotNull(launchConfiguration1);
|
||||||
assertTrue(provider.ownsLaunchConfiguration(launchConfiguration1));
|
assertTrue(provider.ownsLaunchConfiguration(launchConfiguration1));
|
||||||
launchConfiguration1.delete();
|
launchConfiguration1.delete();
|
||||||
assertTrue(provider.ownsLaunchConfiguration(launchConfiguration1));
|
|
||||||
provider.launchConfigurationRemoved(launchConfiguration1);
|
provider.launchConfigurationRemoved(launchConfiguration1);
|
||||||
assertFalse(provider.ownsLaunchConfiguration(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.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
|
@ -129,26 +128,26 @@ public class LaunchBarManager2Test {
|
||||||
doReturn(provider).when(element).createExecutableExtension("class");
|
doReturn(provider).when(element).createExecutableExtension("class");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ILaunchConfigurationProvider mockProviderElement(String descriptorTypeId, int priority, ILaunchDescriptor descriptor,
|
protected ILaunchConfigurationProvider mockConfigProviderElement(String descriptorTypeId, int priority,
|
||||||
IRemoteConnection target,
|
ILaunchDescriptor descriptor, IRemoteConnection target, ILaunchConfiguration config, Object launchObj)
|
||||||
ILaunchConfiguration config, Object launchObj) throws CoreException {
|
throws CoreException {
|
||||||
ILaunchConfigurationProvider provider = mock(ILaunchConfigurationProvider.class);
|
ILaunchConfigurationProvider provider = mock(ILaunchConfigurationProvider.class);
|
||||||
mockProviderElement(descriptorTypeId, priority, provider);
|
mockProviderElement(descriptorTypeId, priority, provider);
|
||||||
doReturn(config.getType()).when(provider).getLaunchConfigurationType(descriptor, target);
|
doReturn(config.getType()).when(provider).getLaunchConfigurationType(descriptor, target);
|
||||||
doReturn(config).when(provider).getLaunchConfiguration(descriptor, target);
|
doReturn(config).when(provider).getLaunchConfiguration(descriptor, target);
|
||||||
doReturn(true).when(provider).supports(descriptor, target);
|
doReturn(true).when(provider).supports(descriptor, target);
|
||||||
doReturn(true).when(provider).ownsLaunchConfiguration(config);
|
doReturn(true).when(provider).launchConfigurationAdded(config);
|
||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IConfigurationElement mockDescriptorTypeElement(String descriptorTypeId, int priority,
|
protected IConfigurationElement mockDescriptorTypeElement(String descriptorTypeId, int priority,
|
||||||
ILaunchDescriptorType descriptorType)
|
ILaunchDescriptorType descriptorType) throws CoreException {
|
||||||
throws CoreException {
|
|
||||||
IConfigurationElement element = mockElementAndAdd("descriptorType");
|
IConfigurationElement element = mockElementAndAdd("descriptorType");
|
||||||
doReturn(descriptorTypeId).when(element).getAttribute("id");
|
doReturn(descriptorTypeId).when(element).getAttribute("id");
|
||||||
doReturn(Integer.toString(priority)).when(element).getAttribute("priority");
|
doReturn(Integer.toString(priority)).when(element).getAttribute("priority");
|
||||||
doReturn(descriptorType).when(element).createExecutableExtension("class");
|
doReturn(descriptorType).when(element).createExecutableExtension("class");
|
||||||
mockEnablementElement(element);
|
// TODO need a real enablement here, not an empty one
|
||||||
|
// mockEnablementElement(element);
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +178,6 @@ public class LaunchBarManager2Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void mockLaunchObjectOnDescriptor(Object launchObject) throws CoreException {
|
protected void mockLaunchObjectOnDescriptor(Object launchObject) throws CoreException {
|
||||||
doReturn(true).when(descriptorType).ownsLaunchObject(launchObject);
|
|
||||||
doReturn(descriptor).when(descriptorType).getDescriptor(launchObject);
|
doReturn(descriptor).when(descriptorType).getDescriptor(launchObject);
|
||||||
doReturn(launchObject.toString()).when(descriptor).getName();
|
doReturn(launchObject.toString()).when(descriptor).getName();
|
||||||
}
|
}
|
||||||
|
@ -297,7 +295,7 @@ public class LaunchBarManager2Test {
|
||||||
doReturn(descriptorType).when(descriptor).getType();
|
doReturn(descriptorType).when(descriptor).getType();
|
||||||
doReturn(descriptor).when(descriptorType).getDescriptor(launchObject);
|
doReturn(descriptor).when(descriptorType).getDescriptor(launchObject);
|
||||||
// configProvider
|
// configProvider
|
||||||
provider = mockProviderElement(descriptorTypeId, 10, descriptor, otherTarget, launchConfig, launchObject);
|
provider = mockConfigProviderElement(descriptorTypeId, 10, descriptor, otherTarget, launchConfig, launchObject);
|
||||||
mockLaunchObjectOnDescriptor(launchObject);
|
mockLaunchObjectOnDescriptor(launchObject);
|
||||||
// default descriptor
|
// default descriptor
|
||||||
String defaultDescTypeId = "defaultDescType";
|
String defaultDescTypeId = "defaultDescType";
|
||||||
|
@ -309,7 +307,8 @@ public class LaunchBarManager2Test {
|
||||||
@Test
|
@Test
|
||||||
public void testDescriptor() throws Exception {
|
public void testDescriptor() throws Exception {
|
||||||
// Create a descriptor type and inject an associated object
|
// 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
|
// Make sure the associated launch config is active too
|
||||||
// Mocking
|
// Mocking
|
||||||
manager.launchObjectAdded(launchObject);
|
manager.launchObjectAdded(launchObject);
|
||||||
|
@ -327,26 +326,20 @@ public class LaunchBarManager2Test {
|
||||||
assertNull(manager.getActiveLaunchMode());
|
assertNull(manager.getActiveLaunchMode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAddDescriptorTypeBad() throws CoreException {
|
|
||||||
doThrow(new NullPointerException()).when(descriptorType).ownsLaunchObject(any());
|
|
||||||
manager.launchObjectAdded("aaa");
|
|
||||||
verify(descriptorType).ownsLaunchObject(any());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddConfigMappingTwo() throws CoreException {
|
public void testAddConfigMappingTwo() throws CoreException {
|
||||||
basicSetupOnly();
|
basicSetupOnly();
|
||||||
IRemoteConnection target = mockRemoteConnection("t2");
|
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
|
// now create another lc type, which is not registered in config type
|
||||||
ILaunchConfigurationType lctype2 = mockLCType("lctypeid2");
|
ILaunchConfigurationType lctype2 = mockLCType("lctypeid2");
|
||||||
ILaunchConfiguration lc2 = mockLC("bla2", lctype2);
|
ILaunchConfiguration lc2 = mockLC("bla2", lctype2);
|
||||||
ConfigBasedLaunchDescriptor desc2 = new ConfigBasedLaunchDescriptor(descriptorType, lc2);
|
ConfigBasedLaunchDescriptor desc2 = new ConfigBasedLaunchDescriptor(descriptorType, lc2);
|
||||||
mockProviderElement(descriptorTypeId, 10, desc2, target, lc2, lc2);
|
mockConfigProviderElement(descriptorTypeId, 10, desc2, target, lc2, lc2);
|
||||||
init();
|
init();
|
||||||
manager.launchObjectAdded(launchObject);
|
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));
|
assertEquals(launchConfigType, manager.getLaunchConfigurationType(descriptor, target));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,10 +347,10 @@ public class LaunchBarManager2Test {
|
||||||
public void testAddConfigProviderTwo2() throws CoreException {
|
public void testAddConfigProviderTwo2() throws CoreException {
|
||||||
basicSetupOnly();
|
basicSetupOnly();
|
||||||
IRemoteConnection target = mockRemoteConnection("t2");
|
IRemoteConnection target = mockRemoteConnection("t2");
|
||||||
mockProviderElement(descriptorTypeId, 15, descriptor, target, launchConfig, launchObject);
|
mockConfigProviderElement(descriptorTypeId, 15, descriptor, target, launchConfig, launchObject);
|
||||||
ILaunchConfigurationType lctype2 = mockLCType("lctypeid2");
|
ILaunchConfigurationType lctype2 = mockLCType("lctypeid2");
|
||||||
ILaunchConfiguration lc2 = mockLC("lc2", lctype2);
|
ILaunchConfiguration lc2 = mockLC("lc2", lctype2);
|
||||||
mockProviderElement(descriptorTypeId, 20, descriptor, target, lc2, launchObject);
|
mockConfigProviderElement(descriptorTypeId, 20, descriptor, target, lc2, launchObject);
|
||||||
init();
|
init();
|
||||||
manager.launchObjectAdded(launchObject);
|
manager.launchObjectAdded(launchObject);
|
||||||
assertEquals(lctype2, manager.getLaunchConfigurationType(descriptor, target));
|
assertEquals(lctype2, manager.getLaunchConfigurationType(descriptor, target));
|
||||||
|
@ -390,7 +383,7 @@ public class LaunchBarManager2Test {
|
||||||
basicSetupOnly();
|
basicSetupOnly();
|
||||||
elements.clear();
|
elements.clear();
|
||||||
mockDescriptorTypeElement(descriptorTypeId, 10, descriptorType);
|
mockDescriptorTypeElement(descriptorTypeId, 10, descriptorType);
|
||||||
mockProviderElement(descriptorTypeId, 10, descriptor, localTarget, launchConfig, launchObject);
|
mockConfigProviderElement(descriptorTypeId, 10, descriptor, localTarget, launchConfig, launchObject);
|
||||||
init();
|
init();
|
||||||
manager.launchObjectAdded(launchObject);
|
manager.launchObjectAdded(launchObject);
|
||||||
ILaunchDescriptor desc = manager.getActiveLaunchDescriptor();
|
ILaunchDescriptor desc = manager.getActiveLaunchDescriptor();
|
||||||
|
@ -423,20 +416,26 @@ public class LaunchBarManager2Test {
|
||||||
// public void testGetLaunchDescriptorsSort() {
|
// public void testGetLaunchDescriptorsSort() {
|
||||||
// final ILaunchDescriptor res[] = new ILaunchDescriptor[1];
|
// final ILaunchDescriptor res[] = new ILaunchDescriptor[1];
|
||||||
// manager.addTargetType(targetType);
|
// manager.addTargetType(targetType);
|
||||||
// ConfigBasedLaunchDescriptorType descType1 = new ConfigBasedLaunchDescriptorType("id1", lctype.getIdentifier());
|
// ConfigBasedLaunchDescriptorType descType1 = new
|
||||||
// ConfigBasedLaunchDescriptorType descType2 = new ConfigBasedLaunchDescriptorType("id2", lctype.getIdentifier()) {
|
// ConfigBasedLaunchDescriptorType("id1", lctype.getIdentifier());
|
||||||
|
// ConfigBasedLaunchDescriptorType descType2 = new
|
||||||
|
// ConfigBasedLaunchDescriptorType("id2", lctype.getIdentifier()) {
|
||||||
// @Override
|
// @Override
|
||||||
// public ILaunchDescriptor getDescriptor(Object element) {
|
// public ILaunchDescriptor getDescriptor(Object element) {
|
||||||
// return res[0] = super.getDescriptor(element);
|
// return res[0] = super.getDescriptor(element);
|
||||||
// }
|
// }
|
||||||
// };
|
// };
|
||||||
// ConfigBasedLaunchDescriptorType descType3 = new ConfigBasedLaunchDescriptorType("id3", lctype.getIdentifier());
|
// ConfigBasedLaunchDescriptorType descType3 = new
|
||||||
|
// ConfigBasedLaunchDescriptorType("id3", lctype.getIdentifier());
|
||||||
// manager.addDescriptorType(descType1, 3);
|
// manager.addDescriptorType(descType1, 3);
|
||||||
// manager.addDescriptorType(descType2, 5);
|
// manager.addDescriptorType(descType2, 5);
|
||||||
// manager.addDescriptorType(descType3, 1);
|
// manager.addDescriptorType(descType3, 1);
|
||||||
// manager.addConfigProvider(descType1.getId(), targetType.getId(), true, provider);
|
// manager.addConfigProvider(descType1.getId(), targetType.getId(), true,
|
||||||
// manager.addConfigProvider(descType2.getId(), targetType.getId(), true, provider);
|
// provider);
|
||||||
// manager.addConfigProvider(descType3.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);
|
// targetType.targets.add(mytarget);
|
||||||
// manager.launchObjectAdded(launchObject);
|
// manager.launchObjectAdded(launchObject);
|
||||||
// ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
// ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||||
|
@ -481,6 +480,7 @@ public class LaunchBarManager2Test {
|
||||||
when(project.getType()).thenReturn(IResource.PROJECT);
|
when(project.getType()).thenReturn(IResource.PROJECT);
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String ATTR_PROJECT_NAME = "org.eclipse.cdt.launch" + ".PROJECT_ATTR";
|
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";
|
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 {
|
public class ProjectBasedLaunchDescriptorType implements ILaunchDescriptorType {
|
||||||
@Override
|
|
||||||
public boolean ownsLaunchObject(Object launchObject) throws CoreException {
|
|
||||||
return launchObject instanceof IProject;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ILaunchDescriptor getDescriptor(Object launchObject) throws CoreException {
|
public ILaunchDescriptor getDescriptor(Object launchObject) throws CoreException {
|
||||||
return new ProjectLaunchDescriptor(this, (IProject) launchObject);
|
return new ProjectLaunchDescriptor(this, (IProject) launchObject);
|
||||||
|
@ -561,8 +556,11 @@ public class LaunchBarManager2Test {
|
||||||
return "pbtype";
|
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 {
|
protected void projectMappingSetup() throws CoreException {
|
||||||
descriptorType = new ProjectBasedLaunchDescriptorType();
|
descriptorType = new ProjectBasedLaunchDescriptorType();
|
||||||
|
@ -571,7 +569,8 @@ public class LaunchBarManager2Test {
|
||||||
descriptor = new ProjectLaunchDescriptor(descriptorType, aaa);
|
descriptor = new ProjectLaunchDescriptor(descriptorType, aaa);
|
||||||
// setup some stuff
|
// setup some stuff
|
||||||
mockDescriptorTypeElement(descriptorTypeId, 10, descriptorType);
|
mockDescriptorTypeElement(descriptorTypeId, 10, descriptorType);
|
||||||
//lc = provider.createLaunchConfiguration(lman, descType.getDescriptor(aaa));
|
// lc = provider.createLaunchConfiguration(lman,
|
||||||
|
// descType.getDescriptor(aaa));
|
||||||
mockLCProject(launchConfig, aaa);
|
mockLCProject(launchConfig, aaa);
|
||||||
mockLCAttribute(launchConfig, ATTR_ORIGINAL_NAME, aaa.getName());
|
mockLCAttribute(launchConfig, ATTR_ORIGINAL_NAME, aaa.getName());
|
||||||
assertEquals(0, manager.getLaunchDescriptors().length);
|
assertEquals(0, manager.getLaunchDescriptors().length);
|
||||||
|
@ -586,6 +585,16 @@ public class LaunchBarManager2Test {
|
||||||
public boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
|
public boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
|
||||||
return configuration == launchConfig;
|
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);
|
mockProviderElement(descriptorTypeId, 10, provider);
|
||||||
mockLCAttribute(launchConfig, ATTR_PROVIDER_CLASS, provider.getClass().getName());
|
mockLCAttribute(launchConfig, ATTR_PROVIDER_CLASS, provider.getClass().getName());
|
||||||
|
@ -635,10 +644,10 @@ public class LaunchBarManager2Test {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLaunchObjectAddedBadDescriptor() throws CoreException {
|
public void testLaunchObjectAddedBadDescriptor() throws CoreException {
|
||||||
doThrow(new NullPointerException()).when(descriptorType).ownsLaunchObject(any());
|
doThrow(new NullPointerException()).when(descriptorType).getDescriptor(any());
|
||||||
// check events
|
// check events
|
||||||
manager.launchObjectAdded(launchObject);
|
manager.launchObjectAdded(launchObject);
|
||||||
verify(descriptorType).ownsLaunchObject(launchObject);
|
verify(descriptorType).getDescriptor(launchObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -651,7 +660,7 @@ public class LaunchBarManager2Test {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLaunchObjectRemoveBadDescriptor() throws CoreException {
|
public void testLaunchObjectRemoveBadDescriptor() throws CoreException {
|
||||||
doThrow(new NullPointerException()).when(descriptorType).ownsLaunchObject(any());
|
doThrow(new NullPointerException()).when(descriptorType).getDescriptor(any());
|
||||||
// check events
|
// check events
|
||||||
manager.launchObjectRemoved(launchObject);
|
manager.launchObjectRemoved(launchObject);
|
||||||
}
|
}
|
||||||
|
@ -894,7 +903,7 @@ public class LaunchBarManager2Test {
|
||||||
ILaunchMode mode = mockLaunchModes(launchConfigType, "foo")[0];
|
ILaunchMode mode = mockLaunchModes(launchConfigType, "foo")[0];
|
||||||
manager.launchObjectAdded(launchObject);
|
manager.launchObjectAdded(launchObject);
|
||||||
manager.launchConfigurationAdded(launchConfig);
|
manager.launchConfigurationAdded(launchConfig);
|
||||||
verify(provider).ownsLaunchConfiguration(launchConfig);
|
verify(provider).launchConfigurationAdded(launchConfig);
|
||||||
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
|
||||||
assertEquals(1, launchDescriptors.length);
|
assertEquals(1, launchDescriptors.length);
|
||||||
assertNotNull(launchDescriptors[0]);
|
assertNotNull(launchDescriptors[0]);
|
||||||
|
@ -921,10 +930,9 @@ public class LaunchBarManager2Test {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLaunchConfigurationAddedBad() throws CoreException {
|
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);
|
manager.launchConfigurationAdded(launchConfig);
|
||||||
verify(provider).launchConfigurationAdded(launchConfig);
|
verify(provider).launchConfigurationAdded(launchConfig);
|
||||||
verify(provider).ownsLaunchConfiguration(launchConfig);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -958,10 +966,13 @@ public class LaunchBarManager2Test {
|
||||||
mockSubElement(enablement, new IConfigurationElement[] { instance });
|
mockSubElement(enablement, new IConfigurationElement[] { instance });
|
||||||
doReturn("java.lang.Integer").when(instance).getAttribute("value");
|
doReturn("java.lang.Integer").when(instance).getAttribute("value");
|
||||||
init();
|
init();
|
||||||
assertNull(manager.launchObjectAdded(launchObject)); // this will be refused by enablement expression
|
// this will be refused by enablement expression
|
||||||
assertNull(manager.launchObjectAdded(1)); // we programmatically refuse this
|
assertNull(manager.launchObjectAdded(launchObject));
|
||||||
|
// we programmatically refuse this
|
||||||
|
assertNull(manager.launchObjectAdded(1));
|
||||||
mockLaunchObjectOnDescriptor(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.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
|
@ -46,7 +45,8 @@ public class LaunchBarManagerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultTest() throws Exception {
|
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.
|
// And that that config is the active config.
|
||||||
|
|
||||||
// Mocking
|
// Mocking
|
||||||
|
@ -54,7 +54,8 @@ public class LaunchBarManagerTest {
|
||||||
ILaunchConfiguration launchConfig = mock(ILaunchConfiguration.class);
|
ILaunchConfiguration launchConfig = mock(ILaunchConfiguration.class);
|
||||||
String launchConfigName = "launchConfig";
|
String launchConfigName = "launchConfig";
|
||||||
doReturn(launchConfigName).when(launchConfig).getName();
|
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("").when(launchConfig).getAttribute(eq("org.eclipse.launchbar.core.providerClass"), anyString());
|
||||||
doReturn(true).when(launchConfigType).isPublic();
|
doReturn(true).when(launchConfigType).isPublic();
|
||||||
doReturn(launchConfigType).when(launchConfig).getType();
|
doReturn(launchConfigType).when(launchConfig).getType();
|
||||||
|
@ -85,10 +86,10 @@ public class LaunchBarManagerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public void descriptorTest() throws Exception {
|
public void descriptorTest() throws Exception {
|
||||||
// Create a descriptor type and inject an associated object
|
// 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
|
// Make sure the associated launch config is active too
|
||||||
|
|
||||||
// Mocking
|
// Mocking
|
||||||
|
@ -110,7 +111,6 @@ public class LaunchBarManagerTest {
|
||||||
doReturn(descriptorTypeId).when(element).getAttribute("id");
|
doReturn(descriptorTypeId).when(element).getAttribute("id");
|
||||||
ILaunchDescriptorType descriptorType = mock(ILaunchDescriptorType.class);
|
ILaunchDescriptorType descriptorType = mock(ILaunchDescriptorType.class);
|
||||||
doReturn(descriptorType).when(element).createExecutableExtension("class");
|
doReturn(descriptorType).when(element).createExecutableExtension("class");
|
||||||
doReturn(true).when(descriptorType).ownsLaunchObject(launchObject);
|
|
||||||
ILaunchDescriptor descriptor = mock(ILaunchDescriptor.class);
|
ILaunchDescriptor descriptor = mock(ILaunchDescriptor.class);
|
||||||
doReturn(descriptor).when(descriptorType).getDescriptor(launchObject);
|
doReturn(descriptor).when(descriptorType).getDescriptor(launchObject);
|
||||||
doReturn(descriptorType).when(descriptor).getType();
|
doReturn(descriptorType).when(descriptor).getType();
|
||||||
|
@ -147,8 +147,10 @@ public class LaunchBarManagerTest {
|
||||||
doReturn(configProvider).when(element).createExecutableExtension("class");
|
doReturn(configProvider).when(element).createExecutableExtension("class");
|
||||||
|
|
||||||
ILaunchConfiguration launchConfig = mock(ILaunchConfiguration.class);
|
ILaunchConfiguration launchConfig = mock(ILaunchConfiguration.class);
|
||||||
doReturn(launchConfig).when(configProvider).getLaunchConfiguration(eq(descriptor), any(IRemoteConnection.class));
|
doReturn(launchConfig).when(configProvider).getLaunchConfiguration(eq(descriptor),
|
||||||
doReturn(launchConfigType).when(configProvider).getLaunchConfigurationType(any(ILaunchDescriptor.class), any(IRemoteConnection.class));
|
any(IRemoteConnection.class));
|
||||||
|
doReturn(launchConfigType).when(configProvider).getLaunchConfigurationType(any(ILaunchDescriptor.class),
|
||||||
|
any(IRemoteConnection.class));
|
||||||
doAnswer(new Answer<Boolean>() {
|
doAnswer(new Answer<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
@ -165,6 +167,7 @@ public class LaunchBarManagerTest {
|
||||||
IExtensionPoint getExtensionPoint() throws CoreException {
|
IExtensionPoint getExtensionPoint() throws CoreException {
|
||||||
return extensionPoint;
|
return extensionPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
ILaunchManager getLaunchManager() {
|
ILaunchManager getLaunchManager() {
|
||||||
return launchManager;
|
return launchManager;
|
||||||
|
@ -183,10 +186,13 @@ public class LaunchBarManagerTest {
|
||||||
assertEquals(launchConfig, manager.getActiveLaunchConfiguration());
|
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 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 that two target types that map to the same desc type and
|
||||||
// TODO - test duplicating a config. make sure it's default desc and same targets
|
// 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 project descriptors and stuff
|
||||||
// TODO - test descriptor takeovers (new descriptors on launchObjectChange
|
// TODO - test descriptor takeovers (new descriptors on launchObjectChange
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue