1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 04:45:38 +02:00

Bug 547831 Allow LC Providers to use the Null Target

The Null Target is half way to becoming a first class citizen. However
we don't provide it in the list of targets available for a launch
descriptor. This adds support for that by adding a boolean flag to
the launch configuration provider launch bar contribution extension.

To help with that, changed the handling of get launch config for the
default launch descriptors to grab the config directly from the
descriptor without going through the providers. It would be very weird
for the providers to return a different config, but that door is now
shut.

Also add some documentation to ILaunchBarManager. Was going to add
the support there but went for the extension instead. Might as well
check in the docs I wrote doing that.

Change-Id: Ia03002a661a3971df68f74b2c338fe538b8b376a
This commit is contained in:
Doug Schaefer 2019-05-31 16:24:07 -04:00
parent fb389bae6f
commit 890bca3466
4 changed files with 150 additions and 22 deletions

View file

@ -131,6 +131,13 @@ provider with priority 5. Priority 0 is reserved for default provider.
</appinfo>
</annotation>
</attribute>
<attribute name="supportsNullTarget" type="boolean">
<annotation>
<documentation>
Does the descriptor managed by this config provider support the null target.
</documentation>
</annotation>
</attribute>
</complexType>
</element>

View file

@ -25,20 +25,20 @@ import org.eclipse.launchbar.core.target.ILaunchTarget;
public interface ILaunchBarManager extends ILaunchConfigurationListener {
/**
* A launch object has been added. Create a matching launch descriptor if available.
* A launch object has been added. Create a matching launch descriptor if
* available.
*
* @param element
* launch object
* @param element launch object
* @return the launch descriptor that got created, null of none was
* @throws CoreException
*/
ILaunchDescriptor launchObjectAdded(Object launchObject) throws CoreException;
/**
* A launch object has been removed. Remove the associated launch descriptor if there is one.
* A launch object has been removed. Remove the associated launch descriptor if
* there is one.
*
* @param element
* launch object
* @param element launch object
* @throws CoreException
*/
void launchObjectRemoved(Object launchObject) throws CoreException;
@ -66,37 +66,118 @@ public interface ILaunchBarManager extends ILaunchConfigurationListener {
void removeListener(ILaunchBarListener listener);
/**
* Return the type id for the given launch descriptor type. This is defined in the extension
* point that defines the type.
* Return the type id for the given launch descriptor type. This is defined in
* the extension point that defines the type.
*
* @param descType
* descriptor type
* @param descType descriptor type
* @return the type id for the descriptor type
*/
String getDescriptorTypeId(ILaunchDescriptorType descType) throws CoreException;
/**
* Returns the active launch descriptor.
*
* @return active launch descriptor
* @throws CoreException
*/
ILaunchDescriptor getActiveLaunchDescriptor() throws CoreException;
/**
* Returns the active launch mode.
*
* @return active launch mode
* @throws CoreException
*/
ILaunchMode getActiveLaunchMode() throws CoreException;
/**
* Returns the active launch target.
*
* @return active launch target
* @throws CoreException
*/
ILaunchTarget getActiveLaunchTarget() throws CoreException;
/**
* Returns the active launch configuration as derived from the active descriptor
* and target.
*
* @return active launch configuration
* @throws CoreException
*/
ILaunchConfiguration getActiveLaunchConfiguration() throws CoreException;
/**
* Returns the launch configuration derived from the given launch descriptor and
* target.
*
* @param desc launch descriptor
* @param target launch target
* @return launch configuration
* @throws CoreException
*/
ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor desc, ILaunchTarget target) throws CoreException;
ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor desc, ILaunchTarget target) throws CoreException;
/**
* Returns the launch configuration type used for configurations that are
* derived from the given launch descriptor and launch target without creating a
* launch configuration.
*
* @param desc launch descriptor
* @param target launch target
* @return launch configuration type
* @throws CoreException
*/
ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor desc, ILaunchTarget target)
throws CoreException;
/**
* Returns all know launch descriptors.
*
* @return launch descriptors
* @throws CoreException
*/
ILaunchDescriptor[] getLaunchDescriptors() throws CoreException;
/**
* Set the active launch descriptor.
*
* @param desc launch descriptor
* @throws CoreException
*/
void setActiveLaunchDescriptor(ILaunchDescriptor desc) throws CoreException;
/**
* Return all launch modes for the active launch descriptor and active launch target.
*
* @return launch modes
* @throws CoreException
*/
ILaunchMode[] getLaunchModes() throws CoreException;
/**
* Set the active launch mode.
*
* @param mode launch mode
* @throws CoreException
*/
void setActiveLaunchMode(ILaunchMode mode) throws CoreException;
/**
* Return all launch targets supported by the given launch descriptor.
*
* @param desc launch descriptor
* @return launch targets
* @throws CoreException
*/
ILaunchTarget[] getLaunchTargets(ILaunchDescriptor desc) throws CoreException;
/**
* Set the active launch target.
*
* @param target launch target
* @throws CoreException
*/
void setActiveLaunchTarget(ILaunchTarget target) throws CoreException;
}

View file

@ -37,6 +37,7 @@ import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchListener;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.launchbar.core.DefaultLaunchDescriptor;
import org.eclipse.launchbar.core.ILaunchBarListener;
import org.eclipse.launchbar.core.ILaunchBarManager;
import org.eclipse.launchbar.core.ILaunchConfigurationProvider;
@ -310,6 +311,14 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
throws CoreException {
if (descriptor == null)
return null;
if (descriptor instanceof DefaultLaunchDescriptor) {
// With the default descriptor, we already have the config, just return the type
// Doesn't matter what the target is, that's dealt with at launch time
ILaunchConfiguration config = descriptor.getAdapter(ILaunchConfiguration.class);
return config.getType();
}
for (LaunchConfigProviderInfo providerInfo : configProviders.get(getDescriptorTypeId(descriptor.getType()))) {
if (providerInfo.enabled(descriptor) && providerInfo.enabled(target)) {
ILaunchConfigurationProvider provider = providerInfo.getProvider();
@ -321,6 +330,8 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
}
}
}
// not found
return null;
}
@ -708,6 +719,9 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
targets.add(target);
}
}
if (supportsNullTarget(descriptor)) {
targets.add(ILaunchTarget.NULL_TARGET);
}
return targets.toArray(new ILaunchTarget[targets.size()]);
}
@ -727,6 +741,16 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
return false;
}
boolean supportsNullTarget(ILaunchDescriptor descriptor) {
String descriptorTypeId = getDescriptorTypeId(descriptor.getType());
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descriptorTypeId)) {
if (providerInfo.enabled(descriptor) && providerInfo.supportsNullTarget()) {
return true;
}
}
return false;
}
@Override
public ILaunchTarget getActiveLaunchTarget() {
return activeLaunchTarget;
@ -761,9 +785,8 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
}
private void storeLaunchTarget(ILaunchDescriptor desc, ILaunchTarget target) {
if (target == null || target == ILaunchTarget.NULL_TARGET) {
// no point storing null, if stored id is invalid it won't be used
// anyway
if (target == null) {
// Don't store if it's null. Not sure we're null any more anyway.
return;
}
// per desc store, desc can be null means it store globally
@ -807,6 +830,11 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
if (descriptor == null) {
return null;
}
if (descriptor instanceof DefaultLaunchDescriptor) {
return descriptor.getAdapter(ILaunchConfiguration.class);
}
String descTypeId = getDescriptorTypeId(descriptor.getType());
for (LaunchConfigProviderInfo providerInfo : configProviders.get(descTypeId)) {
try {

View file

@ -22,6 +22,7 @@ import org.eclipse.launchbar.core.ILaunchConfigurationProvider;
public class LaunchConfigProviderInfo {
private final String descriptorTypeId;
private final int priority;
private final boolean supportsNullTarget;
private IConfigurationElement element;
private ILaunchConfigurationProvider provider;
private Expression expression;
@ -38,6 +39,13 @@ public class LaunchConfigProviderInfo {
}
priority = priorityNum;
String nullTargetString = element.getAttribute("supportsNullTarget"); //$NON-NLS-1$
if (nullTargetString != null) {
supportsNullTarget = Boolean.parseBoolean(nullTargetString);
} else {
supportsNullTarget = false;
}
this.element = element;
IConfigurationElement[] enabledExpressions = element.getChildren("enablement");//$NON-NLS-1$
@ -70,6 +78,10 @@ public class LaunchConfigProviderInfo {
return priority;
}
public boolean supportsNullTarget() {
return supportsNullTarget;
}
public ILaunchConfigurationProvider getProvider() {
if (provider == null) {
try {