mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
Step 1 of adapting Arduino IDE to new Launch Bar API.
Change-Id: I5fcfcde182eff8a5cc34d64f75ba5deea9487770
This commit is contained in:
parent
3d8907e788
commit
a170ca1895
7 changed files with 85 additions and 87 deletions
|
@ -87,7 +87,6 @@
|
|||
<extension
|
||||
point="org.eclipse.remote.core.remoteServices">
|
||||
<connectionType
|
||||
capabilities="7"
|
||||
id="org.eclipse.cdt.arduino.core.connectionType"
|
||||
name="Arduino">
|
||||
</connectionType>
|
||||
|
@ -116,18 +115,9 @@
|
|||
</descriptorType>
|
||||
<configProvider
|
||||
class="org.eclipse.cdt.arduino.core.internal.launch.ArduinoLaunchConfigurationProvider"
|
||||
launchConfigurationType="org.eclipse.cdt.arduino.core.launchConfigurationType">
|
||||
</configProvider>
|
||||
<configType
|
||||
descriptorType="org.eclipse.cdt.arduino.core.descriptorType"
|
||||
isDefault="true"
|
||||
launchConfigurationType="org.eclipse.cdt.arduino.core.launchConfigurationType"
|
||||
targetType="org.eclipse.cdt.arduino.core.targetType">
|
||||
</configType>
|
||||
<targetType
|
||||
connectionTypeId="org.eclipse.cdt.arduino.core.connectionType"
|
||||
id="org.eclipse.cdt.arduino.core.targetType">
|
||||
</targetType>
|
||||
priority="5">
|
||||
</configProvider>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.core.contenttype.contentTypes">
|
||||
|
|
|
@ -25,7 +25,6 @@ import java.util.Map;
|
|||
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.launch.ArduinoLaunchConfigurationDelegate;
|
||||
import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection;
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
|
@ -55,7 +54,6 @@ import org.eclipse.core.runtime.jobs.Job;
|
|||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
import org.eclipse.remote.core.IRemoteConnectionType;
|
||||
import org.eclipse.remote.core.IRemoteServicesManager;
|
||||
import org.eclipse.remote.core.launch.IRemoteLaunchConfigService;
|
||||
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
|
@ -69,16 +67,16 @@ public class ArduinoProjectGenerator {
|
|||
|
||||
private final IProject project;
|
||||
private IFile sourceFile;
|
||||
|
||||
|
||||
public ArduinoProjectGenerator(IProject project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
|
||||
public void setupArduinoProject(IProgressMonitor monitor) throws CoreException {
|
||||
// create the CDT-ness of the project
|
||||
IProjectDescription projDesc = project.getDescription();
|
||||
CCorePlugin.getDefault().createCDTProject(projDesc, project, monitor);
|
||||
|
||||
|
||||
String[] oldIds = projDesc.getNatureIds();
|
||||
String[] newIds = new String[oldIds.length + 3];
|
||||
System.arraycopy(oldIds, 0, newIds, 0, oldIds.length);
|
||||
|
@ -94,28 +92,21 @@ public class ArduinoProjectGenerator {
|
|||
info.setManagedProject(mProj);
|
||||
|
||||
Board board = null;
|
||||
|
||||
|
||||
IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
|
||||
IRemoteLaunchConfigService remoteLaunchService = Activator.getService(IRemoteLaunchConfigService.class);
|
||||
IRemoteConnection remoteConnection = remoteLaunchService.getLastActiveConnection(ArduinoLaunchConfigurationDelegate.getLaunchConfigurationType());
|
||||
if (remoteConnection != null) {
|
||||
IArduinoRemoteConnection arduinoRemote = remoteConnection.getService(IArduinoRemoteConnection.class);
|
||||
board = arduinoRemote.getBoard();
|
||||
} else {
|
||||
IRemoteConnectionType connectionType = remoteManager.getConnectionType(ArduinoRemoteConnection.TYPE_ID);
|
||||
Collection<IRemoteConnection> connections = connectionType.getConnections();
|
||||
if (!connections.isEmpty()) {
|
||||
IRemoteConnection firstConnection = connections.iterator().next();
|
||||
IArduinoRemoteConnection firstArduino = firstConnection.getService(IArduinoRemoteConnection.class);
|
||||
board = firstArduino.getBoard();
|
||||
}
|
||||
IRemoteConnectionType connectionType = remoteManager.getConnectionType(ArduinoRemoteConnection.TYPE_ID);
|
||||
Collection<IRemoteConnection> connections = connectionType.getConnections();
|
||||
if (!connections.isEmpty()) {
|
||||
IRemoteConnection firstConnection = connections.iterator().next();
|
||||
IArduinoRemoteConnection firstArduino = firstConnection.getService(IArduinoRemoteConnection.class);
|
||||
board = firstArduino.getBoard();
|
||||
}
|
||||
|
||||
|
||||
if (board == null) {
|
||||
IArduinoBoardManager boardManager = Activator.getService(IArduinoBoardManager.class);
|
||||
board = boardManager.getBoard("uno"); // the default //$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
||||
createBuildConfiguration(cprojDesc, board);
|
||||
|
||||
CCorePlugin.getDefault().setProjectDescription(project, cprojDesc, true, monitor);
|
||||
|
@ -128,9 +119,9 @@ public class ArduinoProjectGenerator {
|
|||
|
||||
final Map<String, Object> fmModel = new HashMap<>();
|
||||
fmModel.put("projectName", project.getName()); //$NON-NLS-1$
|
||||
|
||||
|
||||
generateFile(fmModel, fmConfig.getTemplate("Makefile"), project.getFile("Makefile")); //$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$
|
||||
} catch (IOException e) {
|
||||
|
@ -140,7 +131,7 @@ public class ArduinoProjectGenerator {
|
|||
} catch (TemplateException e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), e.getLocalizedMessage(), e));
|
||||
}
|
||||
|
||||
|
||||
// Do the initial build
|
||||
project.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
|
||||
}
|
||||
|
@ -172,7 +163,7 @@ public class ArduinoProjectGenerator {
|
|||
if (!status.isOK())
|
||||
throw new CoreException(status);
|
||||
}
|
||||
|
||||
|
||||
public static ICConfigurationDescription createBuildConfiguration(ICProjectDescription projDesc, Board board) throws CoreException {
|
||||
ManagedProject managedProject = new ManagedProject(projDesc);
|
||||
String configId = ManagedBuildManager.calculateChildId(AVR_TOOLCHAIN_ID, null);
|
||||
|
@ -191,7 +182,7 @@ public class ArduinoProjectGenerator {
|
|||
IToolChain toolChain = configuration.getToolChain();
|
||||
IOption boardOption = toolChain.getOptionBySuperClassId(BOARD_OPTION_ID);
|
||||
String boardId = boardOption.getStringValue();
|
||||
|
||||
|
||||
IArduinoBoardManager boardManager = Activator.getService(IArduinoBoardManager.class);
|
||||
Board board = boardManager.getBoard(boardId);
|
||||
if (board == null) {
|
||||
|
@ -201,11 +192,11 @@ public class ArduinoProjectGenerator {
|
|||
} catch (BuildException e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), e.getLocalizedMessage(), e));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public IFile getSourceFile() {
|
||||
return sourceFile;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -38,32 +38,23 @@ import org.eclipse.core.runtime.jobs.Job;
|
|||
import org.eclipse.debug.core.DebugPlugin;
|
||||
import org.eclipse.debug.core.ILaunch;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||
import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
|
||||
import org.eclipse.launchbar.core.launch.RemoteLaunchConfigurationDelegate;
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
import org.eclipse.remote.core.launch.IRemoteLaunchConfigService;
|
||||
|
||||
public class ArduinoLaunchConfigurationDelegate extends LaunchConfigurationDelegate {
|
||||
public class ArduinoLaunchConfigurationDelegate extends RemoteLaunchConfigurationDelegate {
|
||||
|
||||
public static ILaunchConfigurationType getLaunchConfigurationType() {
|
||||
return DebugPlugin.getDefault().getLaunchManager()
|
||||
.getLaunchConfigurationType("org.eclipse.cdt.arduino.core.launchConfigurationType"); //$NON-NLS-1$
|
||||
}
|
||||
public static final String TYPE_ID = "org.eclipse.cdt.arduino.core.launchConfigurationType"; //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
|
||||
public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IRemoteConnection target,
|
||||
IProgressMonitor monitor) throws CoreException {
|
||||
// 1. make sure proper build config is set active
|
||||
IProject project = configuration.getMappedResources()[0].getProject();
|
||||
ICProjectDescription projDesc = CCorePlugin.getDefault().getProjectDescription(project);
|
||||
IRemoteConnection remoteConnection = getActiveRemote(configuration);
|
||||
if (remoteConnection == null) {
|
||||
// TODO default?
|
||||
return false;
|
||||
}
|
||||
ICConfigurationDescription configDesc = getBuildConfiguration(projDesc, remoteConnection);
|
||||
ICConfigurationDescription configDesc = getBuildConfiguration(projDesc, target);
|
||||
boolean newConfig = false;
|
||||
if (configDesc == null) {
|
||||
IArduinoRemoteConnection arduinoRemote = remoteConnection.getService(IArduinoRemoteConnection.class);
|
||||
IArduinoRemoteConnection arduinoRemote = target.getService(IArduinoRemoteConnection.class);
|
||||
configDesc = ArduinoProjectGenerator.createBuildConfiguration(projDesc, arduinoRemote.getBoard());
|
||||
newConfig = true;
|
||||
}
|
||||
|
@ -75,7 +66,7 @@ public class ArduinoLaunchConfigurationDelegate extends LaunchConfigurationDeleg
|
|||
// 2. Run the build
|
||||
return super.buildForLaunch(configuration, mode, monitor);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected IProject[] getBuildOrder(ILaunchConfiguration configuration, String mode) throws CoreException {
|
||||
// 1. Extract project from configuration
|
||||
|
@ -84,43 +75,38 @@ public class ArduinoLaunchConfigurationDelegate extends LaunchConfigurationDeleg
|
|||
}
|
||||
|
||||
@Override
|
||||
public void launch(final ILaunchConfiguration configuration, String mode,
|
||||
public void launch(final ILaunchConfiguration configuration, String mode, final IRemoteConnection target,
|
||||
final ILaunch launch, IProgressMonitor monitor) throws CoreException {
|
||||
new Job(Messages.ArduinoLaunchConfigurationDelegate_0) {
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
try {
|
||||
ArduinoLaunchConsoleService consoleService = getConsoleService();
|
||||
|
||||
IRemoteConnection connection = getActiveRemote(configuration);
|
||||
if (connection == null) {
|
||||
return new Status(IStatus.ERROR, Activator.getId(), Messages.ArduinoLaunchConfigurationDelegate_1);
|
||||
}
|
||||
|
||||
// The project
|
||||
IProject project = (IProject) configuration.getMappedResources()[0];
|
||||
|
||||
// The build environment
|
||||
ICProjectDescription projDesc = CCorePlugin.getDefault().getProjectDescription(project);
|
||||
ICConfigurationDescription configDesc = getBuildConfiguration(projDesc, connection);
|
||||
ICConfigurationDescription configDesc = getBuildConfiguration(projDesc, target);
|
||||
IEnvironmentVariable[] envVars = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariables(configDesc, true);
|
||||
List<String> envVarList = new ArrayList<String>(envVars.length + 1);
|
||||
for (IEnvironmentVariable var : envVars) {
|
||||
envVarList.add(var.getName() + '=' + var.getValue());
|
||||
}
|
||||
// Add in the serial port based on launch config
|
||||
IArduinoRemoteConnection arduinoRemote = connection.getService(IArduinoRemoteConnection.class);
|
||||
IArduinoRemoteConnection arduinoRemote = target.getService(IArduinoRemoteConnection.class);
|
||||
envVarList.add("SERIAL_PORT=" + arduinoRemote.getPortName()); //$NON-NLS-1$
|
||||
String[] envp = envVarList.toArray(new String[envVarList.size()]);
|
||||
|
||||
// The project directory to launch from
|
||||
File projectDir = new File(project.getLocationURI());
|
||||
|
||||
|
||||
// The build command
|
||||
IConfiguration buildConfig = ManagedBuildManager.getConfigurationForDescription(configDesc);
|
||||
String command = buildConfig.getBuilder().getCommand();
|
||||
|
||||
// If opened, temporarily close the connection so we can use it to download the firmware.
|
||||
boolean wasOpened = connection.isOpen();
|
||||
boolean wasOpened = target.isOpen();
|
||||
if (wasOpened) {
|
||||
arduinoRemote.pause();
|
||||
}
|
||||
|
@ -162,9 +148,14 @@ public class ArduinoLaunchConfigurationDelegate extends LaunchConfigurationDeleg
|
|||
* @param launchConfig
|
||||
* @return
|
||||
*/
|
||||
private ICConfigurationDescription getBuildConfiguration(ICProjectDescription projDesc, IRemoteConnection remoteConnection) throws CoreException {
|
||||
IArduinoRemoteConnection arduinoRemote = remoteConnection.getService(IArduinoRemoteConnection.class);
|
||||
String boardId = arduinoRemote.getBoard().getId();
|
||||
private ICConfigurationDescription getBuildConfiguration(ICProjectDescription projDesc, IRemoteConnection target) throws CoreException {
|
||||
String boardId;
|
||||
if (target != null) {
|
||||
IArduinoRemoteConnection arduinoRemote = target.getService(IArduinoRemoteConnection.class);
|
||||
boardId = arduinoRemote.getBoard().getId();
|
||||
} else {
|
||||
boardId = "uno"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
for (ICConfigurationDescription configDesc : projDesc.getConfigurations()) {
|
||||
IConfiguration config = ManagedBuildManager.getConfigurationForDescription(configDesc);
|
||||
|
@ -175,8 +166,4 @@ public class ArduinoLaunchConfigurationDelegate extends LaunchConfigurationDeleg
|
|||
return null;
|
||||
}
|
||||
|
||||
private IRemoteConnection getActiveRemote(ILaunchConfiguration configuration) {
|
||||
IRemoteLaunchConfigService remoteLaunchService = Activator.getService(IRemoteLaunchConfigService.class);
|
||||
return remoteLaunchService.getActiveConnection(configuration);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,15 +10,35 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.arduino.core.internal.launch;
|
||||
|
||||
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.ILaunchConfigurationType;
|
||||
import org.eclipse.launchbar.core.ProjectLaunchConfigurationProvider;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||
import org.eclipse.launchbar.core.ProjectPerTypeLaunchConfigProvider;
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
|
||||
public class ArduinoLaunchConfigurationProvider extends ProjectLaunchConfigurationProvider {
|
||||
public class ArduinoLaunchConfigurationProvider extends ProjectPerTypeLaunchConfigProvider {
|
||||
|
||||
@Override
|
||||
public ILaunchConfigurationType getLaunchConfigurationType() throws CoreException {
|
||||
return ArduinoLaunchConfigurationDelegate.getLaunchConfigurationType();
|
||||
protected String getLaunchConfigurationTypeId() {
|
||||
return ArduinoLaunchConfigurationDelegate.TYPE_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRemoteConnectionTypeId() {
|
||||
return ArduinoRemoteConnection.TYPE_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
||||
if (!super.supports(descriptor, target)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// must have the arduino nature
|
||||
IProject project = descriptor.getAdapter(IProject.class);
|
||||
return ArduinoProjectNature.hasNature(project);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,8 @@ public class Activator extends AbstractUIPlugin {
|
|||
// The plug-in ID
|
||||
public static final String PLUGIN_ID = "org.eclipse.cdt.arduino.ui"; //$NON-NLS-1$
|
||||
|
||||
public static final String IMG_ARDUINO = "arduino"; //$NON-NLS-1$
|
||||
public static final String IMG_ARDUINO = PLUGIN_ID + ".arduino"; //$NON-NLS-1$
|
||||
public static final String IMG_CONNECTION_TYPE = PLUGIN_ID + ".connectionType"; //$NON-NLS-1$
|
||||
|
||||
// The shared instance
|
||||
private static Activator plugin;
|
||||
|
@ -38,6 +39,7 @@ public class Activator extends AbstractUIPlugin {
|
|||
|
||||
ImageRegistry imageRegistry = getImageRegistry();
|
||||
imageRegistry.put(IMG_ARDUINO, imageDescriptorFromPlugin(PLUGIN_ID, "icons/cprojects.gif")); //$NON-NLS-1$
|
||||
imageRegistry.put(IMG_CONNECTION_TYPE, imageDescriptorFromPlugin(PLUGIN_ID, "icons/arduino.png")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
|
@ -62,10 +64,6 @@ public class Activator extends AbstractUIPlugin {
|
|||
return plugin.getBundle().getSymbolicName();
|
||||
}
|
||||
|
||||
public Image getImage(String id) {
|
||||
return getImageRegistry().get(id);
|
||||
}
|
||||
|
||||
public static void log(Exception e) {
|
||||
if (e instanceof CoreException) {
|
||||
plugin.getLog().log(((CoreException) e).getStatus());
|
||||
|
|
|
@ -19,7 +19,7 @@ public class ArduinoDescriptorLabelProvider extends LabelProvider {
|
|||
|
||||
@Override
|
||||
public Image getImage(Object element) {
|
||||
return Activator.getDefault().getImage(Activator.IMG_ARDUINO);
|
||||
return Activator.getDefault().getImageRegistry().get(Activator.IMG_ARDUINO);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,19 +5,21 @@ import java.lang.reflect.InvocationTargetException;
|
|||
import org.eclipse.cdt.arduino.ui.internal.Activator;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.operation.IRunnableContext;
|
||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||
import org.eclipse.jface.viewers.ILabelProvider;
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
import org.eclipse.remote.core.IRemoteConnectionType;
|
||||
import org.eclipse.remote.core.IRemoteConnectionType.Service;
|
||||
import org.eclipse.remote.core.exception.RemoteConnectionException;
|
||||
import org.eclipse.remote.ui.AbstractRemoteUIConnectionService;
|
||||
import org.eclipse.remote.ui.IRemoteUIConnectionService;
|
||||
import org.eclipse.remote.ui.IRemoteUIConnectionWizard;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
public class ArduinoRemoteServicesUI extends PlatformObject implements IRemoteUIConnectionService {
|
||||
public class ArduinoRemoteServicesUI extends AbstractRemoteUIConnectionService {
|
||||
|
||||
private final IRemoteConnectionType connectionType;
|
||||
|
||||
|
@ -53,6 +55,16 @@ public class ArduinoRemoteServicesUI extends PlatformObject implements IRemoteUI
|
|||
return new NewArduinoTargetWizard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILabelProvider getLabelProvider() {
|
||||
return new DefaultLabelProvider() {
|
||||
@Override
|
||||
public Image getImage(Object element) {
|
||||
return Activator.getDefault().getImageRegistry().get(Activator.IMG_CONNECTION_TYPE);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static class Factory implements IRemoteConnectionType.Service.Factory {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue