1
0
Fork 0
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:
Doug Schaefer 2014-06-24 11:53:42 -04:00
parent 92aea028d9
commit 8686c2bfce
11 changed files with 284 additions and 33 deletions

View file

@ -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

View file

@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml

View 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>

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -1,7 +1,7 @@
Manifest-Version: 1.0 Manifest-Version: 1.0
Bundle-ManifestVersion: 2 Bundle-ManifestVersion: 2
Bundle-Name: LaunchBar Core 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-Version: 1.0.0.qualifier
Bundle-Activator: org.eclipse.cdt.launchbar.core.internal.Activator Bundle-Activator: org.eclipse.cdt.launchbar.core.internal.Activator
Bundle-Vendor: Eclipse CDT Bundle-Vendor: Eclipse CDT

View file

@ -1,4 +1,5 @@
source.. = src/ source.. = src/
output.. = bin/ output.. = bin/
bin.includes = META-INF/,\ bin.includes = META-INF/,\
. .,\
plugin.xml

View 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>

View file

@ -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>

View file

@ -13,25 +13,22 @@ package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager; import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceFactory; import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration; 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"; public static final String PLUGIN_ID = "org.eclipse.cdt.launchbar.core";
private static BundleContext context; private static Plugin plugin;
private LaunchBarManager launchBarManager; private LaunchBarManager launchBarManager;
static BundleContext getContext() {
return context;
}
public void start(BundleContext bundleContext) throws Exception { public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext; super.start(bundleContext);
plugin = this;
bundleContext.registerService(ILaunchBarManager.class, new ServiceFactory<ILaunchBarManager>() { bundleContext.registerService(ILaunchBarManager.class, new ServiceFactory<ILaunchBarManager>() {
@Override @Override
@ -56,7 +53,8 @@ public class Activator implements BundleActivator {
} }
public void stop(BundleContext bundleContext) throws Exception { public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null; super.stop(bundleContext);
plugin = null;
launchBarManager = null; launchBarManager = null;
} }
@ -64,4 +62,12 @@ public class Activator implements BundleActivator {
throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e)); 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));
}
} }

View file

@ -25,6 +25,8 @@ import org.eclipse.cdt.launchbar.core.ILaunchConfigurationsProvider;
import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.core.ILaunchTarget;
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.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IEclipsePreferences;
@ -74,22 +76,22 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
} }
public LaunchBarManager() throws CoreException { public LaunchBarManager() throws CoreException {
IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor( IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchConfigProvider");
Activator.PLUGIN_ID, IExtension[] extensions = point.getExtensions();
"launchConfigProvider"); for (IExtension extension : extensions) {
for (IConfigurationElement element : elements) { // provider is manditory
IConfigurationElement element = extension.getConfigurationElements()[0];
ILaunchConfigurationsProvider provider = (ILaunchConfigurationsProvider) element.createExecutableExtension("class"); ILaunchConfigurationsProvider provider = (ILaunchConfigurationsProvider) element.createExecutableExtension("class");
String priorityString = element.getAttribute("priority"); String priorityString = element.getAttribute("priority");
int priority = 1; // Default is 1 int priority = 100;
if (priorityString != null) { if (priorityString != null) {
try { try {
priority = Integer.parseInt(priorityString); priority = Integer.parseInt(priorityString);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Activator.throwCoreException(e); // Log it but keep going with the default
Activator.log(e);
} }
} }
providers.add(new ProviderExtensionDescriptor(provider, priority)); providers.add(new ProviderExtensionDescriptor(provider, priority));
} }