Skip to content

Commit 1b1232d

Browse files
author
Andreas Stange
committed
added launch configuration, launch configuration tab group and launch shortcut ("Debug as" and "Run as") for arduino projects
1 parent 67228f3 commit 1b1232d

File tree

8 files changed

+634
-68
lines changed

8 files changed

+634
-68
lines changed

it.baeyens.arduino.core/META-INF/MANIFEST.MF

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ Require-Bundle: org.eclipse.core.resources,
3838
org.eclipse.cdt.managedbuilder.core,
3939
org.eclipse.core.filesystem,
4040
org.eclipse.swt,
41+
org.eclipse.debug.ui,
42+
org.eclipse.ui,
4143
org.eclipse.cdt.core,
4244
org.apache.commons.compress,
45+
org.apache.commons.lang,
4346
com.google.gson,
4447
org.eclipse.equinox.security,
4548
org.eclipse.ui.forms,
602 Bytes
Loading

it.baeyens.arduino.core/plugin.xml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,80 @@
180180
</page>
181181
</extension>
182182

183+
<!--
184+
#######################################################################################
185+
# Launch Configuration #
186+
#######################################################################################
187+
-->
188+
<!-- Arduino Launch Configuration -->
189+
<extension
190+
point="org.eclipse.debug.core.launchConfigurationTypes">
191+
<launchConfigurationType
192+
delegate="it.baeyens.arduino.tools.LaunchConfiguration"
193+
id="it.baeyens.arduino.tools.arduinoLaunchConfiguration"
194+
modes="run, debug"
195+
name="Arduino Launch"
196+
public="true">
197+
</launchConfigurationType>
198+
</extension>
199+
200+
<!-- Launch Configuration Tab Group -->
201+
<extension
202+
point="org.eclipse.debug.ui.launchConfigurationTabGroups">
203+
<launchConfigurationTabGroup
204+
class="it.baeyens.arduino.ui.launchconfig.LaunchConfigurationTabGroup"
205+
id="it.baeyens.arduino.ui.launchconfig.arduinoLaunchConfigurationTabGroup"
206+
type="it.baeyens.arduino.tools.arduinoLaunchConfiguration">
207+
<launchMode
208+
mode="run">
209+
</launchMode>
210+
<launchMode
211+
mode="debug">
212+
</launchMode>
213+
</launchConfigurationTabGroup>
214+
</extension>
215+
216+
<!-- Launch Configuration Image -->
217+
<extension
218+
point="org.eclipse.debug.ui.launchConfigurationTypeImages">
219+
<launchConfigurationTypeImage
220+
configTypeID="it.baeyens.arduino.tools.arduinoLaunchConfiguration"
221+
icon="icons/16px-upload.png"
222+
id="it.baeyens.arduino.tools.arduinoLaunchConfigurationTypeImages">
223+
</launchConfigurationTypeImage>
224+
</extension>
225+
226+
<!-- Launch Shortcut -->
227+
<extension
228+
point="org.eclipse.debug.ui.launchShortcuts">
229+
<shortcut
230+
class="it.baeyens.arduino.ui.launchconfig.LaunchShortcut"
231+
icon="icons/16px-upload.png"
232+
id="it.baeyens.arduino.ui.launchconfig.launchShortcut"
233+
label="Arduino Launch"
234+
modes="run, debug">
235+
<contextualLaunch>
236+
<enablement>
237+
<with
238+
variable="selection">
239+
<count
240+
value="1">
241+
</count>
242+
<iterate>
243+
<or>
244+
<test
245+
forcePluginActivation="false"
246+
property="org.eclipse.debug.ui.matchesPattern"
247+
value="*.ino">
248+
</test>
249+
</or>
250+
</iterate>
251+
</with>
252+
</enablement>
253+
</contextualLaunch>
254+
</shortcut>
255+
</extension>
256+
183257
<!--
184258
#######################################################################################
185259
# Arduino Plugin Commands #

it.baeyens.arduino.core/src/it/baeyens/arduino/actions/UploadProjectHandler.java

Lines changed: 78 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -28,89 +28,99 @@
2828
import it.baeyens.arduino.tools.uploaders.UploadSketchWrapper;
2929

3030
class UploadJobHandler extends Job {
31-
IProject myBuildProject = null;
31+
IProject myBuildProject = null;
3232

33-
public UploadJobHandler(IProject buildProject) {
34-
super(Messages.ArduinoUploadProjectHandler_Upload_for_project + buildProject.getName());
35-
this.myBuildProject = buildProject;
36-
}
33+
public UploadJobHandler(IProject buildProject) {
34+
super(Messages.ArduinoUploadProjectHandler_Upload_for_project + buildProject.getName());
35+
this.myBuildProject = buildProject;
36+
}
3737

38-
@Override
39-
protected IStatus run(IProgressMonitor monitor) {
40-
if (InstancePreferences.getBuildBeforeUploadOption()) {
41-
try {
42-
this.myBuildProject.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
43-
Job job = new Job("Start build Activator") { //$NON-NLS-1$
44-
@Override
45-
protected IStatus run(IProgressMonitor _monitor) {
38+
@Override
39+
protected IStatus run(IProgressMonitor monitor) {
40+
if (InstancePreferences.getBuildBeforeUploadOption()) {
4641
try {
47-
String buildflag = "FuStatub"; //$NON-NLS-1$
48-
char[] uri = { 'h', 't', 't', 'p', ':', '/', '/', 'b', 'a', 'e', 'y', 'e', 'n', 's', '.', 'i', 't', '/', 'e', 'c', 'l',
49-
'i', 'p', 's', 'e', '/', 'd', 'o', 'w', 'n', 'l', 'o', 'a', 'd', '/', 'b', 'u', 'i', 'l', 'd', 'S', 't', 'a', 'r',
50-
't', '.', 'h', 't', 'm', 'l', '?', 'b', '=' };
51-
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(Const.NODE_ARDUINO);
52-
int curFsiStatus = myScope.getInt(buildflag, 0) + 1;
53-
myScope.putInt(buildflag, curFsiStatus);
54-
URL pluginStartInitiator = new URL(new String(uri) + Integer.toString(curFsiStatus));
55-
pluginStartInitiator.getContent();
56-
} catch (Exception e) {
57-
e.printStackTrace();
42+
this.myBuildProject.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
43+
Job job = new Job("Start build Activator") { //$NON-NLS-1$
44+
@Override
45+
protected IStatus run(IProgressMonitor _monitor) {
46+
try {
47+
String buildflag = "FuStatub"; //$NON-NLS-1$
48+
char[] uri = { 'h', 't', 't', 'p', ':', '/', '/', 'b', 'a', 'e', 'y', 'e', 'n', 's', '.',
49+
'i', 't', '/', 'e', 'c', 'l', 'i', 'p', 's', 'e', '/', 'd', 'o', 'w', 'n', 'l', 'o',
50+
'a', 'd', '/', 'b', 'u', 'i', 'l', 'd', 'S', 't', 'a', 'r', 't', '.', 'h', 't', 'm',
51+
'l', '?', 'b', '=' };
52+
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(Const.NODE_ARDUINO);
53+
int curFsiStatus = myScope.getInt(buildflag, 0) + 1;
54+
myScope.putInt(buildflag, curFsiStatus);
55+
URL pluginStartInitiator = new URL(new String(uri) + Integer.toString(curFsiStatus));
56+
pluginStartInitiator.getContent();
57+
} catch (Exception e) {
58+
e.printStackTrace();
59+
}
60+
return Status.OK_STATUS;
61+
}
62+
};
63+
job.setPriority(Job.DECORATE);
64+
job.schedule();
65+
} catch (CoreException e) {
66+
Shell theShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
67+
MessageBox dialog = new MessageBox(theShell, SWT.ICON_QUESTION | SWT.OK);
68+
dialog.setText(Messages.ArduinoUploadProjectHandler_Build_failed);
69+
dialog.setMessage(Messages.ArduinoUploadProjectHandler_Build_failed_so_no_upload);
70+
dialog.open();
71+
return Status.OK_STATUS;
72+
}
73+
}
74+
Display.getDefault().asyncExec(new Runnable() {
75+
@Override
76+
public void run() {
77+
UploadSketchWrapper.upload(UploadJobHandler.this.myBuildProject,
78+
CoreModel.getDefault().getProjectDescription(UploadJobHandler.this.myBuildProject)
79+
.getActiveConfiguration().getName());
5880
}
59-
return Status.OK_STATUS;
60-
}
61-
};
62-
job.setPriority(Job.DECORATE);
63-
job.schedule();
64-
} catch (CoreException e) {
65-
Shell theShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
66-
MessageBox dialog = new MessageBox(theShell, SWT.ICON_QUESTION | SWT.OK);
67-
dialog.setText(Messages.ArduinoUploadProjectHandler_Build_failed);
68-
dialog.setMessage(Messages.ArduinoUploadProjectHandler_Build_failed_so_no_upload);
69-
dialog.open();
81+
});
82+
7083
return Status.OK_STATUS;
71-
}
7284
}
73-
Display.getDefault().asyncExec(new Runnable() {
74-
@Override
75-
public void run() {
76-
UploadSketchWrapper.upload(UploadJobHandler.this.myBuildProject,
77-
CoreModel.getDefault().getProjectDescription(UploadJobHandler.this.myBuildProject).getActiveConfiguration().getName());
78-
}
79-
});
80-
81-
return Status.OK_STATUS;
82-
}
8385
}
8486

8587
/**
86-
* This is a handler to connect the plugin.xml to the code for uploading code to arduino teensy ..
88+
* This is a handler to connect the plugin.xml to the code for uploading code to
89+
* arduino teensy ..
8790
*
8891
* @author jan
8992
*
9093
*/
9194
public class UploadProjectHandler extends AbstractHandler {
9295

93-
@Override
94-
public Object execute(ExecutionEvent event) throws ExecutionException {
95-
if (!InstancePreferences.isConfigured(true))
96-
return null;
97-
IProject SelectedProjects[] = ProjectExplorerListener.getSelectedProjects();
98-
switch (SelectedProjects.length) {
99-
case 0:
100-
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, Messages.ArduinoUploadProjectHandler_No_project_found));
101-
break;
102-
case 1:
103-
PlatformUI.getWorkbench().saveAllEditors(false);
104-
IProject myBuildProject = SelectedProjects[0];
105-
Job mBuildJob = new UploadJobHandler(myBuildProject);
106-
mBuildJob.setPriority(Job.INTERACTIVE);
107-
mBuildJob.schedule();
108-
break;
109-
default:
110-
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, Messages.ArduinoUploadProjectHandler_Multiple_projects_found
111-
+ Integer.toString(SelectedProjects.length) + Messages.ArduinoUploadProjectHandler_The_Names_Are + SelectedProjects.toString()));
96+
@Override
97+
public Object execute(ExecutionEvent event) throws ExecutionException {
98+
if (!InstancePreferences.isConfigured(true))
99+
return null;
100+
IProject SelectedProjects[] = ProjectExplorerListener.getSelectedProjects();
101+
switch (SelectedProjects.length) {
102+
case 0:
103+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
104+
Messages.ArduinoUploadProjectHandler_No_project_found));
105+
break;
106+
case 1:
107+
IProject project = SelectedProjects[0];
108+
uploadProject(project);
109+
break;
110+
default:
111+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
112+
Messages.ArduinoUploadProjectHandler_Multiple_projects_found
113+
+ Integer.toString(SelectedProjects.length)
114+
+ Messages.ArduinoUploadProjectHandler_The_Names_Are + SelectedProjects.toString()));
112115

116+
}
117+
return null;
118+
}
119+
120+
public static void uploadProject(IProject project) {
121+
PlatformUI.getWorkbench().saveAllEditors(false);
122+
Job mBuildJob = new UploadJobHandler(project);
123+
mBuildJob.setPriority(Job.INTERACTIVE);
124+
mBuildJob.schedule();
113125
}
114-
return null;
115-
}
116126
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package it.baeyens.arduino.tools;
2+
3+
import org.apache.commons.lang.StringUtils;
4+
import org.eclipse.core.resources.IProject;
5+
import org.eclipse.core.resources.ResourcesPlugin;
6+
import org.eclipse.core.runtime.CoreException;
7+
import org.eclipse.core.runtime.IProgressMonitor;
8+
import org.eclipse.core.runtime.Path;
9+
import org.eclipse.debug.core.ILaunch;
10+
import org.eclipse.debug.core.ILaunchConfiguration;
11+
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
12+
13+
import it.baeyens.arduino.actions.UploadProjectHandler;
14+
15+
public class LaunchConfiguration implements ILaunchConfigurationDelegate{
16+
17+
/**
18+
* The id of the Arduino launch configuration type.
19+
*/
20+
public static final String LAUNCH_CONFIGURATION_TYPE_ID = "it.baeyens.arduino.tools.arduinoLaunchConfiguration";
21+
22+
// Attribute names
23+
public static final String ATTR_PROJECT = "it.baeyens.arduino.tools.launchconfig.main.project";
24+
25+
// Loaded attributes
26+
/**
27+
* The project loaded from the configuration.
28+
*/
29+
IProject project;
30+
31+
// Attributes of the launch method
32+
/**
33+
* The configuration used for this launch
34+
*/
35+
ILaunchConfiguration config;
36+
37+
/**
38+
* The mode of the launch (either "run" or "debug").
39+
*/
40+
String mode;
41+
42+
/**
43+
* The object that is associated with this launch.
44+
*/
45+
ILaunch launch;
46+
47+
/**
48+
* The monitor to show progress.
49+
*/
50+
IProgressMonitor monitor;
51+
52+
@Override
53+
public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor)
54+
throws CoreException {
55+
56+
this.config = config;
57+
this.mode = mode;
58+
this.launch = launch;
59+
this.monitor = monitor;
60+
61+
// Get data from config
62+
loadSettingsFromConfiguration();
63+
64+
if (project != null) {
65+
// Delegate launching the project
66+
UploadProjectHandler.uploadProject(project);
67+
}
68+
}
69+
70+
private void loadSettingsFromConfiguration() {
71+
try {
72+
String projectName = config.getAttribute(ATTR_PROJECT, "");
73+
project = findProject(projectName);
74+
} catch (CoreException e) {
75+
// Stupid exception...
76+
}
77+
}
78+
79+
/**
80+
* Searches for a project with the given name.
81+
* @param name
82+
* @return the project handle if a project was found
83+
*/
84+
public static IProject findProject(String name) {
85+
if (StringUtils.isNotBlank(name) && new Path(name).isValidPath(name)) {
86+
IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
87+
if (p.getLocation() != null)
88+
return p;
89+
}
90+
return null;
91+
}
92+
93+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package it.baeyens.arduino.ui.launchconfig;
2+
3+
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
4+
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
5+
import org.eclipse.debug.ui.CommonTab;
6+
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
7+
8+
public class LaunchConfigurationTabGroup extends AbstractLaunchConfigurationTabGroup{
9+
10+
@Override
11+
/**
12+
* {@inheritDoc}
13+
*/
14+
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
15+
AbstractLaunchConfigurationTab mainTab = new MainTab();
16+
AbstractLaunchConfigurationTab commonTab = new CommonTab();
17+
18+
AbstractLaunchConfigurationTab[] tabs = {mainTab, commonTab};
19+
setTabs(tabs);
20+
}
21+
22+
}

0 commit comments

Comments
 (0)