mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
Start adding CDT launchbar provider.
This commit is contained in:
parent
92aea028d9
commit
8686c2bfce
11 changed files with 284 additions and 33 deletions
|
@ -0,0 +1,13 @@
|
|||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: LaunchBar for CDT Core
|
||||
Bundle-SymbolicName: org.eclipse.cdt.launchbar.cdt.core;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Activator: org.eclipse.cdt.launchbar.cdt.core.Activator
|
||||
Bundle-Vendor: Eclipse CDT
|
||||
Require-Bundle: org.eclipse.core.runtime,
|
||||
org.eclipse.cdt.launchbar.core,
|
||||
org.eclipse.debug.core,
|
||||
org.eclipse.cdt.debug.core
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Bundle-ActivationPolicy: lazy
|
|
@ -0,0 +1,5 @@
|
|||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
plugin.xml
|
13
launch/org.eclipse.cdt.launchbar.cdt.core/plugin.xml
Normal file
13
launch/org.eclipse.cdt.launchbar.cdt.core/plugin.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
<extension
|
||||
id="cdtLaunchConfigProvider"
|
||||
name="CDT Launch Config Provider"
|
||||
point="org.eclipse.cdt.launchbar.core.launchConfigProvider">
|
||||
<provider
|
||||
class="org.eclipse.cdt.launchbar.cdt.core.internal.CDTLaunchConfigProvider"
|
||||
priority="5"></provider>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
|
@ -0,0 +1,72 @@
|
|||
package org.eclipse.cdt.launchbar.cdt.core.internal;
|
||||
|
||||
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
|
||||
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
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;
|
||||
|
||||
public class CDTLaunchConfigDescriptor implements ILaunchConfigurationDescriptor {
|
||||
|
||||
private String projectName;
|
||||
private ILaunchConfiguration config;
|
||||
|
||||
public CDTLaunchConfigDescriptor(IProject project) {
|
||||
projectName = project.getName();
|
||||
}
|
||||
|
||||
public CDTLaunchConfigDescriptor(ILaunchConfiguration config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (config != null)
|
||||
return config.getName();
|
||||
else
|
||||
return projectName;
|
||||
}
|
||||
|
||||
private ILaunchManager getLaunchManager() {
|
||||
return DebugPlugin.getDefault().getLaunchManager();
|
||||
}
|
||||
|
||||
private IProject getProject() {
|
||||
return ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchConfigurationType getLaunchConfigurationType() throws CoreException {
|
||||
return getLaunchManager().getLaunchConfigurationType(ICDTLaunchConfigurationConstants.ID_LAUNCH_C_APP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchConfiguration getLaunchConfiguration() throws CoreException {
|
||||
if (config == null) {
|
||||
ILaunchConfigurationType configType = getLaunchConfigurationType();
|
||||
ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateLaunchConfigurationName(projectName));
|
||||
wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
|
||||
wc.setMappedResources(new IResource[] { getProject() });
|
||||
|
||||
// TODO finish this off
|
||||
|
||||
config = wc.doSave();
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ILaunchConfiguration launchConfiguration) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
// matches if it's the same project
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package org.eclipse.cdt.launchbar.cdt.core.internal;
|
||||
|
||||
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
|
||||
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
|
||||
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationsProvider;
|
||||
|
||||
public class CDTLaunchConfigProvider implements ILaunchConfigurationsProvider {
|
||||
|
||||
public CDTLaunchConfigProvider() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(ILaunchBarManager manager) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchConfigurationDescriptor filterDescriptor(ILaunchConfigurationDescriptor descriptor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: LaunchBar Core
|
||||
Bundle-SymbolicName: org.eclipse.cdt.launchbar.core
|
||||
Bundle-SymbolicName: org.eclipse.cdt.launchbar.core;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Activator: org.eclipse.cdt.launchbar.core.internal.Activator
|
||||
Bundle-Vendor: Eclipse CDT
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
||||
.,\
|
||||
plugin.xml
|
||||
|
|
6
launch/org.eclipse.cdt.launchbar.core/plugin.xml
Normal file
6
launch/org.eclipse.cdt.launchbar.core/plugin.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
<extension-point id="launchConfigProvider" name="Launch Configuration Descriptor Provider" schema="schema/launchConfigProvider.exsd"/>
|
||||
|
||||
</plugin>
|
|
@ -0,0 +1,109 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Schema file written by PDE -->
|
||||
<schema targetNamespace="org.eclipse.cdt.launchbar.core" xmlns="http://www.w3.org/2001/XMLSchema">
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.schema plugin="org.eclipse.cdt.launchbar.core" id="launchConfigProvider" name="Launch Configuration Descriptor Provider"/>
|
||||
</appinfo>
|
||||
<documentation>
|
||||
[Enter description of this extension point.]
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<element name="extension">
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.element />
|
||||
</appinfo>
|
||||
</annotation>
|
||||
<complexType>
|
||||
<sequence>
|
||||
<element ref="provider"/>
|
||||
</sequence>
|
||||
<attribute name="point" type="string" use="required">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="id" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="name" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute translatable="true"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<element name="provider">
|
||||
<complexType>
|
||||
<attribute name="class" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
<appinfo>
|
||||
<meta.attribute kind="java" basedOn=":org.eclipse.cdt.launchbar.core.ILaunchConfigurationsProvider"/>
|
||||
</appinfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="priority" type="string">
|
||||
<annotation>
|
||||
<documentation>
|
||||
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.section type="since"/>
|
||||
</appinfo>
|
||||
<documentation>
|
||||
[Enter the first release in which this extension point appears.]
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.section type="examples"/>
|
||||
</appinfo>
|
||||
<documentation>
|
||||
[Enter extension point usage example here.]
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.section type="apiinfo"/>
|
||||
</appinfo>
|
||||
<documentation>
|
||||
[Enter API information here.]
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
<annotation>
|
||||
<appinfo>
|
||||
<meta.section type="implementation"/>
|
||||
</appinfo>
|
||||
<documentation>
|
||||
[Enter information about supplied implementation of this extension point.]
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
|
||||
</schema>
|
|
@ -13,25 +13,22 @@ package org.eclipse.cdt.launchbar.core.internal;
|
|||
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Plugin;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleActivator;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceFactory;
|
||||
import org.osgi.framework.ServiceRegistration;
|
||||
|
||||
public class Activator implements BundleActivator {
|
||||
public class Activator extends Plugin {
|
||||
|
||||
public static final String PLUGIN_ID = "org.eclipse.cdt.launchbar.core";
|
||||
private static BundleContext context;
|
||||
private static Plugin plugin;
|
||||
private LaunchBarManager launchBarManager;
|
||||
|
||||
static BundleContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public void start(BundleContext bundleContext) throws Exception {
|
||||
Activator.context = bundleContext;
|
||||
super.start(bundleContext);
|
||||
plugin = this;
|
||||
|
||||
bundleContext.registerService(ILaunchBarManager.class, new ServiceFactory<ILaunchBarManager>() {
|
||||
@Override
|
||||
|
@ -56,7 +53,8 @@ public class Activator implements BundleActivator {
|
|||
}
|
||||
|
||||
public void stop(BundleContext bundleContext) throws Exception {
|
||||
Activator.context = null;
|
||||
super.stop(bundleContext);
|
||||
plugin = null;
|
||||
launchBarManager = null;
|
||||
}
|
||||
|
||||
|
@ -64,4 +62,12 @@ public class Activator implements BundleActivator {
|
|||
throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e));
|
||||
}
|
||||
|
||||
public static void log(IStatus status) {
|
||||
plugin.getLog().log(status);
|
||||
}
|
||||
|
||||
public static void log(Exception exception) {
|
||||
log(new Status(IStatus.ERROR, PLUGIN_ID, exception.getLocalizedMessage(), exception));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ import org.eclipse.cdt.launchbar.core.ILaunchConfigurationsProvider;
|
|||
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IExtension;
|
||||
import org.eclipse.core.runtime.IExtensionPoint;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
|
@ -48,7 +50,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
private ILaunchMode activeLaunchMode;
|
||||
|
||||
private final LocalTargetType localTargetType = new LocalTargetType();
|
||||
|
||||
|
||||
private static final String PREF_ACTIVE_CONFIG_DESC = "activeConfigDesc";
|
||||
private static final String PREF_ACTIVE_LAUNCH_MODE = "activeLaunchMode";
|
||||
private static final String PREF_ACTIVE_LAUNCH_TARGET = "activeLaunchTarget";
|
||||
|
@ -74,22 +76,22 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
}
|
||||
|
||||
public LaunchBarManager() throws CoreException {
|
||||
IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(
|
||||
Activator.PLUGIN_ID,
|
||||
"launchConfigProvider");
|
||||
for (IConfigurationElement element : elements) {
|
||||
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchConfigProvider");
|
||||
IExtension[] extensions = point.getExtensions();
|
||||
for (IExtension extension : extensions) {
|
||||
// provider is manditory
|
||||
IConfigurationElement element = extension.getConfigurationElements()[0];
|
||||
ILaunchConfigurationsProvider provider = (ILaunchConfigurationsProvider) element.createExecutableExtension("class");
|
||||
String priorityString = element.getAttribute("priority");
|
||||
int priority = 1; // Default is 1
|
||||
|
||||
int priority = 100;
|
||||
if (priorityString != null) {
|
||||
try {
|
||||
priority = Integer.parseInt(priorityString);
|
||||
} catch (NumberFormatException e) {
|
||||
Activator.throwCoreException(e);
|
||||
// Log it but keep going with the default
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
providers.add(new ProviderExtensionDescriptor(provider, priority));
|
||||
}
|
||||
|
||||
|
@ -106,7 +108,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
|
||||
for (ILaunchConfiguration configuration : launchManager.getLaunchConfigurations()) {
|
||||
ILaunchConfigurationDescriptor configDesc = new DefaultLaunchConfigurationDescriptor(configuration);
|
||||
|
@ -115,20 +117,20 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
}
|
||||
configDescs.put(configDesc.getName(), configDesc);
|
||||
}
|
||||
|
||||
|
||||
for (ProviderExtensionDescriptor providerDesc : providers) {
|
||||
providerDesc.getProvider().init(this);
|
||||
}
|
||||
|
||||
launchManager.addLaunchConfigurationListener(this);
|
||||
|
||||
|
||||
// Load up the active from the preferences or pick reasonable defaults
|
||||
IEclipsePreferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
|
||||
String activeConfigDescName = store.get(PREF_ACTIVE_CONFIG_DESC, null);
|
||||
if (activeConfigDescName == null && !configDescs.isEmpty()) {
|
||||
activeConfigDescName = configDescs.values().iterator().next().getName();
|
||||
}
|
||||
|
||||
|
||||
if (activeConfigDescName != null) {
|
||||
ILaunchConfigurationDescriptor configDesc = configDescs.get(activeConfigDescName);
|
||||
if (configDesc != null) {
|
||||
|
@ -155,14 +157,14 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
public void launchConfigurationChanged(ILaunchConfiguration configuration) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
|
||||
ILaunchConfigurationDescriptor configDesc = getLaunchConfigurationDescriptor(configuration);
|
||||
if (configDesc != null)
|
||||
removeLaunchConfigurationDescriptor(configDesc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ILaunchConfigurationDescriptor[] getLaunchConfigurationDescriptors() {
|
||||
ILaunchConfigurationDescriptor[] descs = configDescs.values().toArray(new ILaunchConfigurationDescriptor[configDescs.size()]);
|
||||
|
@ -186,13 +188,13 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
ILaunchConfigurationDescriptor configDesc = configDescs.get(configuration.getName());
|
||||
if (configDesc.matches(configuration))
|
||||
return configDesc;
|
||||
|
||||
|
||||
// Nope, try all descs
|
||||
for (ILaunchConfigurationDescriptor cd : configDescs.values()) {
|
||||
if (cd.matches(configuration))
|
||||
return cd;
|
||||
}
|
||||
|
||||
|
||||
// nothing, weird
|
||||
return null;
|
||||
}
|
||||
|
@ -203,7 +205,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
return;
|
||||
lastConfigDesc = activeConfigDesc;
|
||||
activeConfigDesc = configDesc;
|
||||
|
||||
|
||||
IEclipsePreferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
|
||||
if (activeConfigDesc != null) {
|
||||
store.put(PREF_ACTIVE_CONFIG_DESC, activeConfigDesc.getName());
|
||||
|
@ -280,7 +282,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
@Override
|
||||
public void removeLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc) {
|
||||
configDescs.remove(configDesc.getName());
|
||||
|
||||
|
||||
// Fix up the active config if this one was it
|
||||
if (activeConfigDesc.equals(configDesc)) {
|
||||
try {
|
||||
|
@ -355,19 +357,19 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
@Override
|
||||
public void setActiveLaunchTarget(ILaunchTarget target) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLaunchTarget(ILaunchTarget target) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLaunchTarget(ILaunchTarget target) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue