mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-20 15:35:24 +02:00
launch bar: per target provider and test fixes
- fixed tests and added tests for previous API changes - fixed unsafe call of provider methods without catching exceptions - added description of priority attribute in the extension point API - fixed default return values in DefaultLaunchConfigProvider, in case it is extended - removed unused import - fixed per target provider to support persistance - added test for per target provider Change-Id: If08b18b939e86757108a800d1092a62621a8c7d0
This commit is contained in:
parent
652500b200
commit
b46cc02560
13 changed files with 515 additions and 90 deletions
|
@ -59,21 +59,24 @@
|
||||||
<attribute name="id" type="string" use="required">
|
<attribute name="id" type="string" use="required">
|
||||||
<annotation>
|
<annotation>
|
||||||
<documentation>
|
<documentation>
|
||||||
|
Global descriptor type id. I.e. com.example.mytype
|
||||||
</documentation>
|
</documentation>
|
||||||
</annotation>
|
</annotation>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute name="priority" type="string" use="required">
|
<attribute name="priority" type="string" use="required">
|
||||||
<annotation>
|
<annotation>
|
||||||
<documentation>
|
<documentation>
|
||||||
|
Priority of the descriptor, values from 1 to 100.
|
||||||
|
Lower values represent lower priority.
|
||||||
|
I.e. descriptor with priority 10 will override
|
||||||
|
descriptor with priority 5. Priority 0 is reserved for default descriptor.
|
||||||
</documentation>
|
</documentation>
|
||||||
</annotation>
|
</annotation>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute name="class" type="string" use="required">
|
<attribute name="class" type="string" use="required">
|
||||||
<annotation>
|
<annotation>
|
||||||
<documentation>
|
<documentation>
|
||||||
|
Class that implements ILaunchDescriptorType
|
||||||
</documentation>
|
</documentation>
|
||||||
<appinfo>
|
<appinfo>
|
||||||
<meta.attribute kind="java" basedOn=":org.eclipse.launchbar.core.ILaunchDescriptorType"/>
|
<meta.attribute kind="java" basedOn=":org.eclipse.launchbar.core.ILaunchDescriptorType"/>
|
||||||
|
@ -93,7 +96,7 @@
|
||||||
<attribute name="descriptorType" type="string" use="required">
|
<attribute name="descriptorType" type="string" use="required">
|
||||||
<annotation>
|
<annotation>
|
||||||
<documentation>
|
<documentation>
|
||||||
|
Id of the descriptor type defined in descriptorType element (can be from another extension)
|
||||||
</documentation>
|
</documentation>
|
||||||
<appinfo>
|
<appinfo>
|
||||||
<meta.attribute kind="identifier" basedOn="org.eclipse.launchbar.core.launchBarContributions/descriptorType/@id"/>
|
<meta.attribute kind="identifier" basedOn="org.eclipse.launchbar.core.launchBarContributions/descriptorType/@id"/>
|
||||||
|
@ -103,14 +106,17 @@
|
||||||
<attribute name="priority" type="string" use="required">
|
<attribute name="priority" type="string" use="required">
|
||||||
<annotation>
|
<annotation>
|
||||||
<documentation>
|
<documentation>
|
||||||
|
Priority of the provider, values from 1 to 100.
|
||||||
|
Lower values represent lower priority.
|
||||||
|
I.e. provider with priority 10 will be checked before
|
||||||
|
provider with priority 5. Priority 0 is reserved for default provider.
|
||||||
</documentation>
|
</documentation>
|
||||||
</annotation>
|
</annotation>
|
||||||
</attribute>
|
</attribute>
|
||||||
<attribute name="class" type="string" use="required">
|
<attribute name="class" type="string" use="required">
|
||||||
<annotation>
|
<annotation>
|
||||||
<documentation>
|
<documentation>
|
||||||
|
Class that implements ILaunchConfigurationProvider
|
||||||
</documentation>
|
</documentation>
|
||||||
<appinfo>
|
<appinfo>
|
||||||
<meta.attribute kind="java" basedOn=":org.eclipse.launchbar.core.ILaunchConfigurationProvider"/>
|
<meta.attribute kind="java" basedOn=":org.eclipse.launchbar.core.ILaunchConfigurationProvider"/>
|
||||||
|
|
|
@ -12,10 +12,17 @@ import org.eclipse.remote.core.IRemoteConnection;
|
||||||
*/
|
*/
|
||||||
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
|
||||||
return target.getConnectionType().getId().equals("org.eclipse.remote.LocalServices"); //$NON-NLS-1$
|
if (target != null && target.getConnectionType().getId().equals("org.eclipse.remote.LocalServices")) { //$NON-NLS-1$
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -30,6 +37,10 @@ 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 ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
|
||||||
// return false so that the config is added as a launch object
|
// return false so that the config is added as a launch object
|
||||||
|
@ -38,8 +49,8 @@ public class DefaultLaunchConfigProvider implements ILaunchConfigurationProvider
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
|
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
|
||||||
// catch any left over configs
|
// by contract we return true if we own or use to own configuration
|
||||||
return true;
|
return ownsLaunchConfiguration(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,13 +65,13 @@ public class DefaultLaunchConfigProvider implements ILaunchConfigurationProvider
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
|
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
|
||||||
// catch any left over configs
|
// by contract we return true if we own configuration
|
||||||
return true;
|
return ownsLaunchConfiguration(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException {
|
public boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException {
|
||||||
// catch any left over configs
|
// by contract we return true if we own configuration
|
||||||
return true;
|
return ownsLaunchConfiguration(configuration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import org.eclipse.remote.core.IRemoteConnection;
|
||||||
* subclasses instead of implementing this directly.
|
* 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 combination
|
||||||
* of descriptor and target.
|
* of descriptor and target.
|
||||||
|
@ -33,7 +32,7 @@ public interface ILaunchConfigurationProvider {
|
||||||
*
|
*
|
||||||
* @param descriptor
|
* @param descriptor
|
||||||
* @param target
|
* @param target
|
||||||
* @return
|
* @return true if target is supported, false otherwise.
|
||||||
*/
|
*/
|
||||||
boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException;
|
boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package org.eclipse.launchbar.core;
|
package org.eclipse.launchbar.core;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
@ -13,30 +16,90 @@ import org.eclipse.remote.core.IRemoteConnectionType;
|
||||||
import org.eclipse.remote.core.IRemoteServicesManager;
|
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 static final String ATTR_CONNECTION_TYPE = "connectionType"; //$NON-NLS-1$
|
public final String ATTR_CONNECTION_NAME = getConnectionNameAttribute();
|
||||||
public static final String ATTR_CONNECTION_NAME = "connectionName"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
private final Map<ILaunchDescriptor, Map<IRemoteConnection, ILaunchConfiguration>> configMap = new HashMap<>();
|
private final Map<ILaunchDescriptor, Map<IRemoteConnection, ILaunchConfiguration>> configMap = new HashMap<>();
|
||||||
|
private final Collection<ILaunchConfiguration> ownedConfigs = new LinkedHashSet<>();
|
||||||
|
|
||||||
|
protected String getConnectionNameAttribute() {
|
||||||
|
return "org.eclipse.launchbar.core.connectionName";//$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getConnectionTypeAttribute() {
|
||||||
|
return "org.eclipse.launchbar.core.connectionType";//$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target)
|
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
Map<IRemoteConnection, ILaunchConfiguration> targetMap = configMap.get(descriptor);
|
Map<IRemoteConnection, ILaunchConfiguration> targetMap = getTargetMap(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);
|
||||||
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
ILaunchConfiguration config = createLaunchConfiguration(descriptor, target);
|
protected Map<IRemoteConnection, ILaunchConfiguration> getTargetMap(ILaunchDescriptor descriptor) {
|
||||||
|
Map<IRemoteConnection, ILaunchConfiguration> targetMap = configMap.get(descriptor);
|
||||||
if (targetMap == null) {
|
if (targetMap == null) {
|
||||||
targetMap = new HashMap<>();
|
targetMap = new HashMap<>();
|
||||||
configMap.put(descriptor, targetMap);
|
configMap.put(descriptor, targetMap);
|
||||||
}
|
}
|
||||||
targetMap.put(target, config);
|
return targetMap;
|
||||||
return config;
|
}
|
||||||
|
|
||||||
|
protected ILaunchConfiguration findLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target)
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method should be overridden to check that configuration does actually represent the descriptor.
|
||||||
|
* You don't need to check ownership since this method will be only called on owned configurations
|
||||||
|
*/
|
||||||
|
protected boolean descriptorMatchesConfiguration(ILaunchDescriptor descriptor, ILaunchConfiguration configuration) {
|
||||||
|
// we using startsWith instead of equals because new configuration using "generateLaunchConfigurationName" method which
|
||||||
|
// means only prefix guaranteed to be matching, and the prefix is the descriptor name
|
||||||
|
return configuration.getName().startsWith(descriptor.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean targetMatchesConfiguration(IRemoteConnection target, ILaunchConfiguration configuration) {
|
||||||
|
String targetName;
|
||||||
|
try {
|
||||||
|
targetName = configuration.getAttribute(ATTR_CONNECTION_NAME, "");
|
||||||
|
} catch (CoreException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (target != null && target.getName().equals(targetName)) {
|
||||||
|
return true;
|
||||||
|
} else if (target == null && (targetName == null || targetName.isEmpty())) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -47,28 +110,42 @@ public abstract class PerTargetLaunchConfigProvider extends AbstractLaunchConfig
|
||||||
workingCopy.setAttribute(ATTR_CONNECTION_NAME, target.getName());
|
workingCopy.setAttribute(ATTR_CONNECTION_NAME, target.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IRemoteConnection getTarget(ILaunchConfiguration configuration) throws CoreException {
|
public IRemoteConnection getTarget(ILaunchConfiguration configuration) throws CoreException {
|
||||||
IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
|
IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
|
||||||
String connectionTypeId = configuration.getAttribute(ATTR_CONNECTION_TYPE, ""); //$NON-NLS-1$
|
String connectionTypeId = configuration.getAttribute(ATTR_CONNECTION_TYPE, ""); //$NON-NLS-1$
|
||||||
if (connectionTypeId.isEmpty()) {
|
if (connectionTypeId.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
IRemoteConnectionType connectionType = remoteManager.getConnectionType(connectionTypeId);
|
IRemoteConnectionType connectionType = remoteManager.getConnectionType(connectionTypeId);
|
||||||
if (connectionType == null) {
|
if (connectionType == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String connectionName = configuration.getAttribute(ATTR_CONNECTION_NAME, ""); //$NON-NLS-1$
|
String connectionName = configuration.getAttribute(ATTR_CONNECTION_NAME, ""); //$NON-NLS-1$
|
||||||
if (connectionName.isEmpty()) {
|
if (connectionName.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return connectionType.getConnection(connectionName);
|
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);
|
||||||
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()) {
|
||||||
if (targetEntry.getValue().equals(configuration)) {
|
if (targetEntry.getValue().equals(configuration)) {
|
||||||
|
@ -80,33 +157,57 @@ public abstract class PerTargetLaunchConfigProvider extends AbstractLaunchConfig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
|
return owned;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
|
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
|
||||||
// TODO re-create map
|
if (ownsLaunchConfigurationByAttributes(configuration)) {
|
||||||
|
ownedConfigs.add(configuration);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException {
|
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 {
|
||||||
configMap.remove(descriptor);
|
Map<IRemoteConnection, ILaunchConfiguration> map = configMap.remove(descriptor);
|
||||||
|
if (map == null)
|
||||||
|
return;
|
||||||
|
for (ILaunchConfiguration config : map.values()) {
|
||||||
|
ownedConfigs.remove(config);
|
||||||
|
config.delete(); // remove all auto-configs associated with descriptor
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void launchTargetRemoved(IRemoteConnection target) throws CoreException {
|
public void launchTargetRemoved(IRemoteConnection target) throws CoreException {
|
||||||
for (Entry<ILaunchDescriptor, Map<IRemoteConnection, ILaunchConfiguration>> descEntry : configMap.entrySet()) {
|
for (Iterator<Entry<ILaunchDescriptor, Map<IRemoteConnection, ILaunchConfiguration>>> iterator = configMap.entrySet()
|
||||||
descEntry.getValue().remove(target);
|
.iterator(); iterator.hasNext();) {
|
||||||
if (descEntry.getValue().isEmpty()) {
|
Entry<ILaunchDescriptor, Map<IRemoteConnection, ILaunchConfiguration>> descEntry = iterator.next();
|
||||||
configMap.remove(descEntry.getKey());
|
Map<IRemoteConnection, ILaunchConfiguration> map = descEntry.getValue();
|
||||||
|
ILaunchConfiguration config = map.remove(target);
|
||||||
|
if (config != null) {
|
||||||
|
config.delete(); // remove all auto-configs associated with target
|
||||||
|
}
|
||||||
|
if (map.isEmpty()) {
|
||||||
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,21 +13,44 @@ package org.eclipse.launchbar.core;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
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.ILaunchConfigurationWorkingCopy;
|
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
||||||
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();
|
||||||
|
@ -40,5 +63,4 @@ public abstract class ProjectPerTargetLaunchConfigProvider extends PerTargetLaun
|
||||||
workingCopy.setMappedResources(newResources);
|
workingCopy.setMappedResources(newResources);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ 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;
|
||||||
import org.eclipse.launchbar.core.ILaunchBarManager;
|
import org.eclipse.launchbar.core.ILaunchBarManager;
|
||||||
|
import org.eclipse.launchbar.core.ILaunchConfigurationProvider;
|
||||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||||
import org.eclipse.launchbar.core.ILaunchDescriptorType;
|
import org.eclipse.launchbar.core.ILaunchDescriptorType;
|
||||||
import org.eclipse.launchbar.core.ILaunchObjectProvider;
|
import org.eclipse.launchbar.core.ILaunchObjectProvider;
|
||||||
|
@ -648,9 +649,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 provider : configProviders.get(descriptorTypeId)) {
|
||||||
|
try {
|
||||||
if (provider.getProvider().supports(descriptor, target)) {
|
if (provider.getProvider().supports(descriptor, target)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Activator.log(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -718,12 +723,21 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
String descTypeId = getDescriptorTypeId(descriptor.getType());
|
String descTypeId = getDescriptorTypeId(descriptor.getType());
|
||||||
for (LaunchConfigProviderInfo provider : configProviders.get(descTypeId)) {
|
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeId)) {
|
||||||
ILaunchConfiguration config = provider.getProvider().getLaunchConfiguration(descriptor, target);
|
try {
|
||||||
|
ILaunchConfigurationProvider provider = providerInfo.getProvider();
|
||||||
|
// between multiple provider who support this descriptor we need to find one
|
||||||
|
// that supports this target
|
||||||
|
if (provider.supports(descriptor, target)) {
|
||||||
|
ILaunchConfiguration config = provider.getLaunchConfiguration(descriptor, target);
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Activator.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ import org.eclipse.swt.events.KeyListener;
|
||||||
import org.eclipse.swt.events.MouseAdapter;
|
import org.eclipse.swt.events.MouseAdapter;
|
||||||
import org.eclipse.swt.events.MouseEvent;
|
import org.eclipse.swt.events.MouseEvent;
|
||||||
import org.eclipse.swt.events.MouseListener;
|
import org.eclipse.swt.events.MouseListener;
|
||||||
import org.eclipse.swt.events.MouseMoveListener;
|
|
||||||
import org.eclipse.swt.events.MouseTrackAdapter;
|
import org.eclipse.swt.events.MouseTrackAdapter;
|
||||||
import org.eclipse.swt.events.MouseTrackListener;
|
import org.eclipse.swt.events.MouseTrackListener;
|
||||||
import org.eclipse.swt.events.PaintEvent;
|
import org.eclipse.swt.events.PaintEvent;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
Manifest-Version: 1.0
|
Manifest-Version: 1.0
|
||||||
Bundle-ManifestVersion: 2
|
Bundle-ManifestVersion: 2
|
||||||
Bundle-Name: Launch Bar Core Tests
|
Bundle-Name: Launch Bar Core Tests
|
||||||
Bundle-SymbolicName: org.eclipse.launchbar.core.tests
|
Bundle-SymbolicName: org.eclipse.launchbar.core.tests;singleton:=true
|
||||||
Bundle-Version: 1.0.0.qualifier
|
Bundle-Version: 1.0.0.qualifier
|
||||||
Fragment-Host: org.eclipse.launchbar.core;bundle-version="1.0.0"
|
Fragment-Host: org.eclipse.launchbar.core;bundle-version="1.0.0"
|
||||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
source.. = src/
|
source.. = src/
|
||||||
output.. = bin/
|
output.. = bin/
|
||||||
bin.includes = META-INF/,\
|
bin.includes = META-INF/,\
|
||||||
.
|
.,\
|
||||||
|
fragment.xml
|
||||||
|
|
14
tests/org.eclipse.launchbar.core.tests/fragment.xml
Normal file
14
tests/org.eclipse.launchbar.core.tests/fragment.xml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<?eclipse version="3.4"?>
|
||||||
|
<fragment>
|
||||||
|
<extension
|
||||||
|
point="org.eclipse.debug.core.launchConfigurationTypes">
|
||||||
|
<launchConfigurationType
|
||||||
|
id="org.eclipse.launchbar.core.tests.lctype1"
|
||||||
|
modes="run, debug, xxx"
|
||||||
|
name="Launch Bar Test Launch Configuration"
|
||||||
|
public="true">
|
||||||
|
</launchConfigurationType>
|
||||||
|
</extension>
|
||||||
|
|
||||||
|
</fragment>
|
|
@ -0,0 +1,259 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2015 QNX Software Systems and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Elena Laskavaia
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.launchbar.core;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertSame;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.debug.core.DebugPlugin;
|
||||||
|
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||||
|
import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||||
|
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
||||||
|
import org.eclipse.debug.core.ILaunchManager;
|
||||||
|
import org.eclipse.launchbar.core.internal.Activator;
|
||||||
|
import org.eclipse.launchbar.core.internal.LaunchBarManager2Test;
|
||||||
|
import org.eclipse.remote.core.IRemoteConnection;
|
||||||
|
import org.eclipse.remote.core.IRemoteConnectionType;
|
||||||
|
import org.eclipse.remote.core.IRemoteServicesManager;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.FixMethodOrder;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runners.MethodSorters;
|
||||||
|
|
||||||
|
@FixMethodOrder(MethodSorters.JVM)
|
||||||
|
public class PerTargetLaunchConfigProviderTest {
|
||||||
|
private IRemoteServicesManager remoteServiceManager;
|
||||||
|
private IRemoteConnection localTarget;
|
||||||
|
private String launchName;
|
||||||
|
private IRemoteConnection otherTarget;
|
||||||
|
private ILaunchConfigurationType launchConfigType;
|
||||||
|
private ILaunchDescriptorType descriptorType;
|
||||||
|
private ILaunchDescriptor descriptor;
|
||||||
|
private PerTargetLaunchConfigProvider1 provider;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void basicSetupOnly() throws CoreException {
|
||||||
|
remoteServiceManager = spy(Activator.getService(IRemoteServicesManager.class));
|
||||||
|
localTarget = remoteServiceManager.getLocalConnectionType().getConnections().get(0);
|
||||||
|
// other mocked remote connections
|
||||||
|
otherTarget = mock(IRemoteConnection.class);
|
||||||
|
IRemoteConnectionType rtype = mock(IRemoteConnectionType.class);
|
||||||
|
doReturn(rtype).when(otherTarget).getConnectionType();
|
||||||
|
doReturn("otherTargetType").when(rtype).getId();
|
||||||
|
doReturn("otherTarget").when(otherTarget).getName();
|
||||||
|
// launch stuff
|
||||||
|
launchName = "test";
|
||||||
|
// launch config type
|
||||||
|
launchConfigType = getLaunchManager().getLaunchConfigurationType("org.eclipse.launchbar.core.tests.lctype1");
|
||||||
|
// launch descriptor and type
|
||||||
|
descriptorType = mock(ILaunchDescriptorType.class);
|
||||||
|
descriptor = mock(ILaunchDescriptor.class);
|
||||||
|
doReturn(descriptorType).when(descriptor).getType();
|
||||||
|
doReturn(launchName).when(descriptor).getName();
|
||||||
|
// configProvider
|
||||||
|
provider = new PerTargetLaunchConfigProvider1();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ILaunchManager getLaunchManager() {
|
||||||
|
return DebugPlugin.getDefault().getLaunchManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void after() throws CoreException {
|
||||||
|
ILaunchConfiguration[] launchConfigurations = getLaunchManager().getLaunchConfigurations();
|
||||||
|
for (ILaunchConfiguration lc : launchConfigurations) {
|
||||||
|
lc.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PerTargetLaunchConfigProvider1 extends PerTargetLaunchConfigProvider {
|
||||||
|
@Override
|
||||||
|
public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, IRemoteConnection target)
|
||||||
|
throws CoreException {
|
||||||
|
return launchConfigType;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPopulateLaunchConfiguration() throws CoreException {
|
||||||
|
ILaunchConfiguration launchConfig = launchConfigType.newInstance(null, launchName).doSave();
|
||||||
|
ILaunchConfigurationWorkingCopy launchConfigWC = launchConfig.getWorkingCopy();
|
||||||
|
provider.populateLaunchConfiguration(descriptor, localTarget, launchConfigWC);
|
||||||
|
//assertEquals(launchConfig.getName(), launchConfigWC.getAttribute(LaunchBarManager2Test.ATTR_ORIGINAL_NAME, ""));
|
||||||
|
//assertEquals(provider.getClass().getName(), launchConfigWC.getAttribute(LaunchBarManager2Test.ATTR_PROVIDER_CLASS, ""));
|
||||||
|
assertTrue(provider.ownsLaunchConfigurationByAttributes(launchConfigWC));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOwnsLaunchConfiguration() throws CoreException {
|
||||||
|
ILaunchConfiguration launchConfig = launchConfigType.newInstance(null, launchName).doSave();
|
||||||
|
assertFalse(provider.ownsLaunchConfiguration(launchConfig));
|
||||||
|
ILaunchConfiguration launchConfiguration = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
|
assertTrue(provider.ownsLaunchConfiguration(launchConfiguration));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetLaunchConfiguration() throws CoreException {
|
||||||
|
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
|
ILaunchConfiguration launchConfiguration2 = provider.getLaunchConfiguration(descriptor, otherTarget);
|
||||||
|
assertNotNull(launchConfiguration1);
|
||||||
|
assertNotNull(launchConfiguration2);
|
||||||
|
assertNotEquals(launchConfiguration1, launchConfiguration2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetLaunchConfigurationReuse() throws CoreException {
|
||||||
|
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
|
assertNotNull(launchConfiguration1);
|
||||||
|
ILaunchConfiguration launchConfiguration2 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
|
assertNotNull(launchConfiguration2);
|
||||||
|
assertSame(launchConfiguration1, launchConfiguration2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetLaunchConfigurationPersistance() throws CoreException {
|
||||||
|
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
|
assertNotNull(launchConfiguration1);
|
||||||
|
// reset provider
|
||||||
|
provider = new PerTargetLaunchConfigProvider1();
|
||||||
|
provider.launchConfigurationAdded(launchConfiguration1); // simulate provider initialization on startup
|
||||||
|
ILaunchConfiguration launchConfiguration2 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
|
assertNotNull(launchConfiguration2);
|
||||||
|
assertEquals(launchConfiguration1, launchConfiguration2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetTarget() throws CoreException {
|
||||||
|
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
|
assertNotNull(launchConfiguration1);
|
||||||
|
assertSame(localTarget, provider.getTarget(launchConfiguration1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLaunchConfigurationRemoved() throws CoreException {
|
||||||
|
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
|
assertNotNull(launchConfiguration1);
|
||||||
|
provider.launchConfigurationRemoved(launchConfiguration1);
|
||||||
|
ILaunchConfiguration launchConfiguration2 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
|
assertNotNull(launchConfiguration2);
|
||||||
|
assertNotEquals(launchConfiguration1, launchConfiguration2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLaunchConfigurationChanged_NotReallyChanged() throws CoreException {
|
||||||
|
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
|
assertNotNull(launchConfiguration1);
|
||||||
|
provider.launchConfigurationChanged(launchConfiguration1);
|
||||||
|
ILaunchConfiguration launchConfiguration2 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
|
assertNotNull(launchConfiguration2);
|
||||||
|
assertSame(launchConfiguration1, launchConfiguration2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLaunchConfigurationChanged_Target() throws CoreException {
|
||||||
|
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
|
assertNotNull(launchConfiguration1);
|
||||||
|
ILaunchConfigurationWorkingCopy wc = launchConfiguration1.getWorkingCopy();
|
||||||
|
wc.setAttribute(provider.getConnectionNameAttribute(), otherTarget.getName());
|
||||||
|
wc.doSave();
|
||||||
|
provider.launchConfigurationChanged(launchConfiguration1);
|
||||||
|
//provider.launchConfigurationChanged(lc3);
|
||||||
|
ILaunchConfiguration launchConfiguration2 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
|
assertNotNull(launchConfiguration2);
|
||||||
|
assertNotEquals(launchConfiguration1, launchConfiguration2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLaunchConfigurationChanged_OrgName() throws CoreException {
|
||||||
|
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
|
assertNotNull(launchConfiguration1);
|
||||||
|
ILaunchConfigurationWorkingCopy wc = launchConfiguration1.getWorkingCopy();
|
||||||
|
wc.setAttribute(LaunchBarManager2Test.ATTR_ORIGINAL_NAME, "bla");
|
||||||
|
wc.doSave();
|
||||||
|
provider.launchConfigurationChanged(launchConfiguration1);
|
||||||
|
// we should have lost ownership
|
||||||
|
assertFalse(provider.ownsLaunchConfiguration(launchConfiguration1));
|
||||||
|
ILaunchConfiguration launchConfiguration2 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
|
assertNotNull(launchConfiguration2);
|
||||||
|
assertNotEquals(launchConfiguration1, launchConfiguration2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLaunchDescriptorRemoved() throws CoreException {
|
||||||
|
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
|
assertNotNull(launchConfiguration1);
|
||||||
|
provider.launchDescriptorRemoved(descriptor);
|
||||||
|
assertEquals(0, provider.getTargetMap(descriptor).size());
|
||||||
|
assertFalse(provider.ownsLaunchConfiguration(launchConfiguration1));
|
||||||
|
assertFalse(launchConfiguration1.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLaunchDescriptorRemoved2() throws CoreException {
|
||||||
|
provider.launchDescriptorRemoved(descriptor);
|
||||||
|
assertEquals(0, provider.getTargetMap(descriptor).size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLaunchTargetRemoved() throws CoreException {
|
||||||
|
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, otherTarget);
|
||||||
|
assertNotNull(launchConfiguration1);
|
||||||
|
provider.launchTargetRemoved(otherTarget);
|
||||||
|
assertEquals(0, provider.getTargetMap(descriptor).size());
|
||||||
|
assertFalse(launchConfiguration1.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLaunchTargetRemoved2() throws CoreException {
|
||||||
|
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, otherTarget);
|
||||||
|
assertNotNull(launchConfiguration1);
|
||||||
|
ILaunchConfiguration launchConfiguration2 = provider.getLaunchConfiguration(descriptor, localTarget);
|
||||||
|
assertNotNull(launchConfiguration2);
|
||||||
|
provider.launchTargetRemoved(otherTarget);
|
||||||
|
assertEquals(1, provider.getTargetMap(descriptor).size());
|
||||||
|
assertFalse(launchConfiguration1.exists());
|
||||||
|
assertTrue(launchConfiguration2.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLaunchTargetRemoved3() throws CoreException {
|
||||||
|
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, otherTarget);
|
||||||
|
assertNotNull(launchConfiguration1);
|
||||||
|
provider.launchTargetRemoved(localTarget);
|
||||||
|
assertEquals(1, provider.getTargetMap(descriptor).size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLCRemoved() throws CoreException {
|
||||||
|
ILaunchConfiguration launchConfiguration1 = provider.getLaunchConfiguration(descriptor, otherTarget);
|
||||||
|
assertNotNull(launchConfiguration1);
|
||||||
|
assertTrue(provider.ownsLaunchConfiguration(launchConfiguration1));
|
||||||
|
launchConfiguration1.delete();
|
||||||
|
assertTrue(provider.ownsLaunchConfiguration(launchConfiguration1));
|
||||||
|
provider.launchConfigurationRemoved(launchConfiguration1);
|
||||||
|
assertFalse(provider.ownsLaunchConfiguration(launchConfiguration1));
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,7 @@ 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;
|
||||||
|
@ -45,7 +46,6 @@ import org.eclipse.core.runtime.IExtensionPoint;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.PlatformObject;
|
import org.eclipse.core.runtime.PlatformObject;
|
||||||
import org.eclipse.core.runtime.Status;
|
|
||||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||||
import org.eclipse.debug.core.ILaunchConfigurationType;
|
import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||||
|
@ -121,14 +121,16 @@ public class LaunchBarManager2Test {
|
||||||
basicSetup();
|
basicSetup();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void mockProviderElement(String descriptorTypeId, int priority, ILaunchConfigurationProvider provider) throws CoreException {
|
protected void mockProviderElement(String descriptorTypeId, int priority, ILaunchConfigurationProvider provider)
|
||||||
|
throws CoreException {
|
||||||
IConfigurationElement element = mockElementAndAdd("configProvider");
|
IConfigurationElement element = mockElementAndAdd("configProvider");
|
||||||
doReturn(descriptorTypeId).when(element).getAttribute("descriptorType");
|
doReturn(descriptorTypeId).when(element).getAttribute("descriptorType");
|
||||||
doReturn(Integer.toString(priority)).when(element).getAttribute("priority");
|
doReturn(Integer.toString(priority)).when(element).getAttribute("priority");
|
||||||
doReturn(provider).when(element).createExecutableExtension("class");
|
doReturn(provider).when(element).createExecutableExtension("class");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ILaunchConfigurationProvider mockProviderElement(String descriptorTypeId, int priority, ILaunchDescriptor descriptor, IRemoteConnection target,
|
protected ILaunchConfigurationProvider mockProviderElement(String descriptorTypeId, int priority, ILaunchDescriptor descriptor,
|
||||||
|
IRemoteConnection target,
|
||||||
ILaunchConfiguration config, Object launchObj) throws CoreException {
|
ILaunchConfiguration config, Object launchObj) throws CoreException {
|
||||||
ILaunchConfigurationProvider provider = mock(ILaunchConfigurationProvider.class);
|
ILaunchConfigurationProvider provider = mock(ILaunchConfigurationProvider.class);
|
||||||
mockProviderElement(descriptorTypeId, priority, provider);
|
mockProviderElement(descriptorTypeId, priority, provider);
|
||||||
|
@ -139,7 +141,8 @@ public class LaunchBarManager2Test {
|
||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IConfigurationElement mockDescriptorTypeElement(String descriptorTypeId, int priority, ILaunchDescriptorType descriptorType)
|
protected IConfigurationElement mockDescriptorTypeElement(String descriptorTypeId, int priority,
|
||||||
|
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");
|
||||||
|
@ -171,7 +174,8 @@ public class LaunchBarManager2Test {
|
||||||
ILaunchConfiguration lc = mock(ILaunchConfiguration.class);
|
ILaunchConfiguration lc = mock(ILaunchConfiguration.class);
|
||||||
doReturn(string).when(lc).getName();
|
doReturn(string).when(lc).getName();
|
||||||
doReturn(lctype2).when(lc).getType();
|
doReturn(lctype2).when(lc).getType();
|
||||||
doReturn("").when(lc).getAttribute(eq(ORIGINAL_NAME), eq(""));
|
doReturn("").when(lc).getAttribute(eq(ATTR_ORIGINAL_NAME), eq(""));
|
||||||
|
doReturn("").when(lc).getAttribute(eq(ATTR_PROVIDER_CLASS), eq(""));
|
||||||
return lc;
|
return lc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,9 +284,7 @@ public class LaunchBarManager2Test {
|
||||||
doReturn(descriptor).when(descriptorType).getDescriptor(launchObject);
|
doReturn(descriptor).when(descriptorType).getDescriptor(launchObject);
|
||||||
// configProvider
|
// configProvider
|
||||||
provider = mockProviderElement(descriptorTypeId, 10, descriptor, otherTarget, launchConfig, launchObject);
|
provider = mockProviderElement(descriptorTypeId, 10, descriptor, otherTarget, launchConfig, launchObject);
|
||||||
|
|
||||||
mockLaunchObjectOnDescriptor(launchObject);
|
mockLaunchObjectOnDescriptor(launchObject);
|
||||||
|
|
||||||
// default descriptor
|
// default descriptor
|
||||||
String defaultDescTypeId = "defaultDescType";
|
String defaultDescTypeId = "defaultDescType";
|
||||||
mockDescriptorTypeElement(defaultDescTypeId, 0, new DefaultLaunchDescriptorType());
|
mockDescriptorTypeElement(defaultDescTypeId, 0, new DefaultLaunchDescriptorType());
|
||||||
|
@ -543,9 +545,9 @@ 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$
|
||||||
|
|
||||||
String ORIGINAL_NAME = org.eclipse.launchbar.core.internal.Activator.PLUGIN_ID + ".originalName";
|
|
||||||
String PROJECT_CONFIG = org.eclipse.launchbar.core.internal.Activator.PLUGIN_ID + ".projectConfig";
|
|
||||||
protected void projectMappingSetup() throws CoreException {
|
protected void projectMappingSetup() throws CoreException {
|
||||||
descriptorType = new ProjectBasedLaunchDescriptorType();
|
descriptorType = new ProjectBasedLaunchDescriptorType();
|
||||||
descriptorTypeId = ((ProjectBasedLaunchDescriptorType) descriptorType).getId();
|
descriptorTypeId = ((ProjectBasedLaunchDescriptorType) descriptorType).getId();
|
||||||
|
@ -555,8 +557,7 @@ public class LaunchBarManager2Test {
|
||||||
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, ORIGINAL_NAME, aaa.getName());
|
mockLCAttribute(launchConfig, ATTR_ORIGINAL_NAME, aaa.getName());
|
||||||
mockLCAttribute(launchConfig, PROJECT_CONFIG, true);
|
|
||||||
assertEquals(0, manager.getLaunchDescriptors().length);
|
assertEquals(0, manager.getLaunchDescriptors().length);
|
||||||
provider = new ProjectPerTargetLaunchConfigProvider() {
|
provider = new ProjectPerTargetLaunchConfigProvider() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -571,6 +572,7 @@ public class LaunchBarManager2Test {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mockProviderElement(descriptorTypeId, 10, provider);
|
mockProviderElement(descriptorTypeId, 10, provider);
|
||||||
|
mockLCAttribute(launchConfig, ATTR_PROVIDER_CLASS, provider.getClass().getName());
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -902,30 +904,26 @@ public class LaunchBarManager2Test {
|
||||||
public void testLaunchConfigurationAddedBad() throws CoreException {
|
public void testLaunchConfigurationAddedBad() throws CoreException {
|
||||||
doThrow(new NullPointerException()).when(provider).ownsLaunchConfiguration(any(ILaunchConfiguration.class));
|
doThrow(new NullPointerException()).when(provider).ownsLaunchConfiguration(any(ILaunchConfiguration.class));
|
||||||
manager.launchConfigurationAdded(launchConfig);
|
manager.launchConfigurationAdded(launchConfig);
|
||||||
|
verify(provider).launchConfigurationAdded(launchConfig);
|
||||||
verify(provider).ownsLaunchConfiguration(launchConfig);
|
verify(provider).ownsLaunchConfiguration(launchConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLaunchConfigurationRemoved_fails() throws CoreException {
|
public void testLaunchConfigurationChanged() throws CoreException {
|
||||||
manager.launchConfigurationRemoved(launchConfig);
|
manager.launchConfigurationChanged(launchConfig);
|
||||||
try {
|
verify(provider).launchConfigurationChanged(launchConfig);
|
||||||
verify(provider).launchConfigurationRemoved(launchConfig);
|
|
||||||
fail();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
// temp fail test
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLaunchConfigurationRemovedBad_fails() throws CoreException {
|
public void testLaunchConfigurationRemoved() throws CoreException {
|
||||||
doThrow(new NullPointerException()).when(provider).launchConfigurationRemoved(any(ILaunchConfiguration.class));
|
|
||||||
manager.launchConfigurationRemoved(launchConfig);
|
manager.launchConfigurationRemoved(launchConfig);
|
||||||
try {
|
|
||||||
verify(provider).launchConfigurationRemoved(launchConfig);
|
verify(provider).launchConfigurationRemoved(launchConfig);
|
||||||
fail();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
// temp fail test
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLaunchConfigurationRemovedBad() throws CoreException {
|
||||||
|
doThrow(new NullPointerException()).when(provider).launchConfigurationRemoved(any(ILaunchConfiguration.class));
|
||||||
|
manager.launchConfigurationRemoved(launchConfig);
|
||||||
|
verify(provider).launchConfigurationRemoved(launchConfig);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ 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;
|
||||||
|
@ -33,7 +34,6 @@ import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
@SuppressWarnings("nls")
|
@SuppressWarnings("nls")
|
||||||
public class LaunchBarManagerTest {
|
public class LaunchBarManagerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void startupTest() throws Exception {
|
public void startupTest() throws Exception {
|
||||||
// Make sure the manager starts up and defaults everything to null
|
// Make sure the manager starts up and defaults everything to null
|
||||||
|
@ -55,6 +55,7 @@ public class LaunchBarManagerTest {
|
||||||
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(true).when(launchConfigType).isPublic();
|
doReturn(true).when(launchConfigType).isPublic();
|
||||||
doReturn(launchConfigType).when(launchConfig).getType();
|
doReturn(launchConfigType).when(launchConfig).getType();
|
||||||
doReturn("launchConfigType").when(launchConfigType).getIdentifier();
|
doReturn("launchConfigType").when(launchConfigType).getIdentifier();
|
||||||
|
|
Loading…
Add table
Reference in a new issue