mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Adapt Arduino plug-ins to final LaunchBar API.
Change-Id: Ib5d7738ad137566b7cf6f9b8c177f72c747b2d2b
This commit is contained in:
parent
8282a1767e
commit
76267c7aa9
4 changed files with 48 additions and 28 deletions
|
@ -112,6 +112,16 @@
|
|||
class="org.eclipse.cdt.arduino.core.internal.launch.ArduinoLaunchDescriptorType"
|
||||
id="org.eclipse.cdt.arduino.core.descriptorType"
|
||||
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>
|
||||
<configProvider
|
||||
class="org.eclipse.cdt.arduino.core.internal.launch.ArduinoLaunchConfigurationProvider"
|
||||
|
|
|
@ -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.Messages;
|
||||
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.CProjectNature;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
|
||||
|
@ -73,26 +71,23 @@ public class ArduinoProjectGenerator {
|
|||
}
|
||||
|
||||
public void setupArduinoProject(IProgressMonitor monitor) throws CoreException {
|
||||
// create the CDT-ness of the project
|
||||
// Add Arduino nature
|
||||
IProjectDescription projDesc = project.getDescription();
|
||||
CCorePlugin.getDefault().createCDTProject(projDesc, project, monitor);
|
||||
|
||||
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);
|
||||
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);
|
||||
project.setDescription(projDesc, monitor);
|
||||
|
||||
// create the CDT natures and build setup
|
||||
CCorePlugin.getDefault().createCDTProject(projDesc, project, monitor);
|
||||
ICProjectDescription cprojDesc = CCorePlugin.getDefault().createProjectDescription(project, false);
|
||||
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
|
||||
ManagedProject mProj = new ManagedProject(cprojDesc);
|
||||
info.setManagedProject(mProj);
|
||||
|
||||
Board board = null;
|
||||
|
||||
IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
|
||||
IRemoteConnectionType connectionType = remoteManager.getConnectionType(ArduinoRemoteConnection.TYPE_ID);
|
||||
Collection<IRemoteConnection> connections = connectionType.getConnections();
|
||||
|
@ -108,7 +103,6 @@ public class ArduinoProjectGenerator {
|
|||
}
|
||||
|
||||
createBuildConfiguration(cprojDesc, board);
|
||||
|
||||
CCorePlugin.getDefault().setProjectDescription(project, cprojDesc, true, monitor);
|
||||
|
||||
// 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$
|
||||
|
||||
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) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), e.getLocalizedMessage(), e));
|
||||
} catch (URISyntaxException e) {
|
||||
|
@ -137,7 +131,8 @@ public class ArduinoProjectGenerator {
|
|||
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();
|
||||
PipedOutputStream out = new PipedOutputStream(in);
|
||||
final Writer writer = new OutputStreamWriter(out);
|
||||
|
@ -165,11 +160,13 @@ public class ArduinoProjectGenerator {
|
|||
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);
|
||||
String configId = ManagedBuildManager.calculateChildId(AVR_TOOLCHAIN_ID, null);
|
||||
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();
|
||||
IOption newOption = newToolChain.getOptionBySuperClassId(BOARD_OPTION_ID);
|
||||
ManagedBuildManager.setOption(newConfig, newToolChain, newOption, board.getId());
|
||||
|
|
|
@ -10,16 +10,20 @@
|
|||
*******************************************************************************/
|
||||
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.remote.ArduinoRemoteConnection;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
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.launchbar.core.ILaunchDescriptor;
|
||||
import org.eclipse.launchbar.core.ProjectPerTargetLaunchConfigProvider;
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
import org.eclipse.remote.core.IRemoteConnectionType;
|
||||
import org.eclipse.remote.core.IRemoteServicesManager;
|
||||
|
||||
public class ArduinoLaunchConfigurationProvider extends ProjectPerTargetLaunchConfigProvider {
|
||||
|
||||
|
@ -36,7 +40,7 @@ public class ArduinoLaunchConfigurationProvider extends ProjectPerTargetLaunchCo
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!target.getConnectionType().getId().equals(ArduinoRemoteConnection.TYPE_ID)) {
|
||||
if (target != null && !target.getConnectionType().getId().equals(ArduinoRemoteConnection.TYPE_ID)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -49,7 +53,25 @@ public class ArduinoLaunchConfigurationProvider extends ProjectPerTargetLaunchCo
|
|||
protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target,
|
||||
ILaunchConfigurationWorkingCopy workingCopy) throws CoreException {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,18 +20,9 @@ import org.eclipse.launchbar.core.ProjectLaunchDescriptor;
|
|||
public class ArduinoLaunchDescriptorType implements ILaunchDescriptorType {
|
||||
|
||||
@Override
|
||||
public boolean ownsLaunchObject(Object element) throws CoreException {
|
||||
if (element instanceof IProject) {
|
||||
return ArduinoProjectNature.hasNature((IProject) element);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchDescriptor getDescriptor(Object element) throws CoreException {
|
||||
if (element instanceof IProject) {
|
||||
return new ProjectLaunchDescriptor(this, (IProject) element);
|
||||
public ILaunchDescriptor getDescriptor(Object launchObject) throws CoreException {
|
||||
if (launchObject instanceof IProject && ArduinoProjectNature.hasNature((IProject) launchObject)) {
|
||||
return new ProjectLaunchDescriptor(this, (IProject) launchObject);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
Loading…
Add table
Reference in a new issue