1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 16:56:04 +02:00

Adapt Arduino plug-ins to final LaunchBar API.

Change-Id: Ib5d7738ad137566b7cf6f9b8c177f72c747b2d2b
This commit is contained in:
Doug Schaefer 2015-05-30 22:51:14 -04:00
parent 8282a1767e
commit 76267c7aa9
4 changed files with 48 additions and 28 deletions

View file

@ -112,6 +112,16 @@
class="org.eclipse.cdt.arduino.core.internal.launch.ArduinoLaunchDescriptorType" class="org.eclipse.cdt.arduino.core.internal.launch.ArduinoLaunchDescriptorType"
id="org.eclipse.cdt.arduino.core.descriptorType" id="org.eclipse.cdt.arduino.core.descriptorType"
priority="5"> priority="5">
<enablement>
<instanceof
value="org.eclipse.core.resources.IProject">
</instanceof>
<test
forcePluginActivation="true"
property="org.eclipse.core.resources.projectNature"
value="org.eclipse.cdt.arduino.core.arduinoNature">
</test>
</enablement>
</descriptorType> </descriptorType>
<configProvider <configProvider
class="org.eclipse.cdt.arduino.core.internal.launch.ArduinoLaunchConfigurationProvider" class="org.eclipse.cdt.arduino.core.internal.launch.ArduinoLaunchConfigurationProvider"

View file

@ -26,9 +26,7 @@ import org.eclipse.cdt.arduino.core.internal.Activator;
import org.eclipse.cdt.arduino.core.internal.ArduinoProjectNature; import org.eclipse.cdt.arduino.core.internal.ArduinoProjectNature;
import org.eclipse.cdt.arduino.core.internal.Messages; import org.eclipse.cdt.arduino.core.internal.Messages;
import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection; import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection;
import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
@ -73,26 +71,23 @@ public class ArduinoProjectGenerator {
} }
public void setupArduinoProject(IProgressMonitor monitor) throws CoreException { public void setupArduinoProject(IProgressMonitor monitor) throws CoreException {
// create the CDT-ness of the project // Add Arduino nature
IProjectDescription projDesc = project.getDescription(); IProjectDescription projDesc = project.getDescription();
CCorePlugin.getDefault().createCDTProject(projDesc, project, monitor);
String[] oldIds = projDesc.getNatureIds(); String[] oldIds = projDesc.getNatureIds();
String[] newIds = new String[oldIds.length + 3]; String[] newIds = new String[oldIds.length + 1];
System.arraycopy(oldIds, 0, newIds, 0, oldIds.length); System.arraycopy(oldIds, 0, newIds, 0, oldIds.length);
newIds[newIds.length - 1] = ArduinoProjectNature.ID; newIds[newIds.length - 1] = ArduinoProjectNature.ID;
newIds[newIds.length - 2] = CCProjectNature.CC_NATURE_ID;
newIds[newIds.length - 3] = CProjectNature.C_NATURE_ID;
projDesc.setNatureIds(newIds); projDesc.setNatureIds(newIds);
project.setDescription(projDesc, monitor); project.setDescription(projDesc, monitor);
// create the CDT natures and build setup
CCorePlugin.getDefault().createCDTProject(projDesc, project, monitor);
ICProjectDescription cprojDesc = CCorePlugin.getDefault().createProjectDescription(project, false); ICProjectDescription cprojDesc = CCorePlugin.getDefault().createProjectDescription(project, false);
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project); ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
ManagedProject mProj = new ManagedProject(cprojDesc); ManagedProject mProj = new ManagedProject(cprojDesc);
info.setManagedProject(mProj); info.setManagedProject(mProj);
Board board = null; Board board = null;
IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class); IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
IRemoteConnectionType connectionType = remoteManager.getConnectionType(ArduinoRemoteConnection.TYPE_ID); IRemoteConnectionType connectionType = remoteManager.getConnectionType(ArduinoRemoteConnection.TYPE_ID);
Collection<IRemoteConnection> connections = connectionType.getConnections(); Collection<IRemoteConnection> connections = connectionType.getConnections();
@ -108,7 +103,6 @@ public class ArduinoProjectGenerator {
} }
createBuildConfiguration(cprojDesc, board); createBuildConfiguration(cprojDesc, board);
CCorePlugin.getDefault().setProjectDescription(project, cprojDesc, true, monitor); CCorePlugin.getDefault().setProjectDescription(project, cprojDesc, true, monitor);
// Generate files // Generate files
@ -124,7 +118,7 @@ public class ArduinoProjectGenerator {
generateFile(fmModel, fmConfig.getTemplate("arduino.mk"), project.getFile("arduino.mk")); //$NON-NLS-1$ //$NON-NLS-2$ generateFile(fmModel, fmConfig.getTemplate("arduino.mk"), project.getFile("arduino.mk")); //$NON-NLS-1$ //$NON-NLS-2$
sourceFile = project.getFile(project.getName() + ".cpp"); //$NON-NLS-1$ sourceFile = project.getFile(project.getName() + ".cpp"); //$NON-NLS-1$
generateFile(fmModel, fmConfig.getTemplate("arduino.cpp"), sourceFile); //$NON-NLS-1$ generateFile(fmModel, fmConfig.getTemplate("arduino.cpp"), sourceFile); //$NON-NLS-1$
} catch (IOException e) { } catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), e.getLocalizedMessage(), e)); throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), e.getLocalizedMessage(), e));
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
@ -137,7 +131,8 @@ public class ArduinoProjectGenerator {
project.build(IncrementalProjectBuilder.FULL_BUILD, monitor); project.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
} }
private static void generateFile(Object model, Template template, final IFile outputFile) throws TemplateException, IOException, CoreException { private static void generateFile(Object model, Template template, final IFile outputFile)
throws TemplateException, IOException, CoreException {
final PipedInputStream in = new PipedInputStream(); final PipedInputStream in = new PipedInputStream();
PipedOutputStream out = new PipedOutputStream(in); PipedOutputStream out = new PipedOutputStream(in);
final Writer writer = new OutputStreamWriter(out); final Writer writer = new OutputStreamWriter(out);
@ -165,11 +160,13 @@ public class ArduinoProjectGenerator {
throw new CoreException(status); throw new CoreException(status);
} }
public static ICConfigurationDescription createBuildConfiguration(ICProjectDescription projDesc, Board board) throws CoreException { public static ICConfigurationDescription createBuildConfiguration(ICProjectDescription projDesc, Board board)
throws CoreException {
ManagedProject managedProject = new ManagedProject(projDesc); ManagedProject managedProject = new ManagedProject(projDesc);
String configId = ManagedBuildManager.calculateChildId(AVR_TOOLCHAIN_ID, null); String configId = ManagedBuildManager.calculateChildId(AVR_TOOLCHAIN_ID, null);
IToolChain avrToolChain = ManagedBuildManager.getExtensionToolChain(AVR_TOOLCHAIN_ID); IToolChain avrToolChain = ManagedBuildManager.getExtensionToolChain(AVR_TOOLCHAIN_ID);
org.eclipse.cdt.managedbuilder.internal.core.Configuration newConfig = new org.eclipse.cdt.managedbuilder.internal.core.Configuration(managedProject, (ToolChain) avrToolChain, configId, board.getId()); org.eclipse.cdt.managedbuilder.internal.core.Configuration newConfig = new org.eclipse.cdt.managedbuilder.internal.core.Configuration(
managedProject, (ToolChain) avrToolChain, configId, board.getId());
IToolChain newToolChain = newConfig.getToolChain(); IToolChain newToolChain = newConfig.getToolChain();
IOption newOption = newToolChain.getOptionBySuperClassId(BOARD_OPTION_ID); IOption newOption = newToolChain.getOptionBySuperClassId(BOARD_OPTION_ID);
ManagedBuildManager.setOption(newConfig, newToolChain, newOption, board.getId()); ManagedBuildManager.setOption(newConfig, newToolChain, newOption, board.getId());

View file

@ -10,16 +10,20 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.arduino.core.internal.launch; package org.eclipse.cdt.arduino.core.internal.launch;
import org.eclipse.cdt.arduino.core.internal.Activator;
import org.eclipse.cdt.arduino.core.internal.ArduinoProjectNature; import org.eclipse.cdt.arduino.core.internal.ArduinoProjectNature;
import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection; import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.launchbar.core.ILaunchDescriptor; import org.eclipse.launchbar.core.ILaunchDescriptor;
import org.eclipse.launchbar.core.ProjectPerTargetLaunchConfigProvider; import org.eclipse.launchbar.core.ProjectPerTargetLaunchConfigProvider;
import org.eclipse.remote.core.IRemoteConnection; import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteConnectionType;
import org.eclipse.remote.core.IRemoteServicesManager;
public class ArduinoLaunchConfigurationProvider extends ProjectPerTargetLaunchConfigProvider { public class ArduinoLaunchConfigurationProvider extends ProjectPerTargetLaunchConfigProvider {
@ -36,7 +40,7 @@ public class ArduinoLaunchConfigurationProvider extends ProjectPerTargetLaunchCo
return false; return false;
} }
if (!target.getConnectionType().getId().equals(ArduinoRemoteConnection.TYPE_ID)) { if (target != null && !target.getConnectionType().getId().equals(ArduinoRemoteConnection.TYPE_ID)) {
return false; return false;
} }
@ -49,7 +53,25 @@ public class ArduinoLaunchConfigurationProvider extends ProjectPerTargetLaunchCo
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);
workingCopy.setAttribute(ArduinoLaunchConfigurationDelegate.CONNECTION_NAME, target.getName()); if (target != null) {
workingCopy.setAttribute(ArduinoLaunchConfigurationDelegate.CONNECTION_NAME, target.getName());
}
}
@Override
protected IRemoteConnection getLaunchTarget(ILaunchConfiguration configuration) throws CoreException {
String name = configuration.getAttribute(ArduinoLaunchConfigurationDelegate.CONNECTION_NAME, ""); //$NON-NLS-1$
if (name.isEmpty()) {
return null;
}
IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class);
IRemoteConnectionType type = manager.getConnectionType(ArduinoRemoteConnection.TYPE_ID);
return type.getConnection(name);
}
@Override
protected boolean providesForNullTarget() {
return true;
} }
} }

View file

@ -20,18 +20,9 @@ import org.eclipse.launchbar.core.ProjectLaunchDescriptor;
public class ArduinoLaunchDescriptorType implements ILaunchDescriptorType { public class ArduinoLaunchDescriptorType implements ILaunchDescriptorType {
@Override @Override
public boolean ownsLaunchObject(Object element) throws CoreException { public ILaunchDescriptor getDescriptor(Object launchObject) throws CoreException {
if (element instanceof IProject) { if (launchObject instanceof IProject && ArduinoProjectNature.hasNature((IProject) launchObject)) {
return ArduinoProjectNature.hasNature((IProject) element); return new ProjectLaunchDescriptor(this, (IProject) launchObject);
}
return false;
}
@Override
public ILaunchDescriptor getDescriptor(Object element) throws CoreException {
if (element instanceof IProject) {
return new ProjectLaunchDescriptor(this, (IProject) element);
} }
return null; return null;