Skip to content

Commit c30f4f6

Browse files
author
jantje
committed
#1367 initial check in
1 parent e760535 commit c30f4f6

File tree

7 files changed

+106
-3
lines changed

7 files changed

+106
-3
lines changed

io.sloeber.core/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ Require-Bundle: org.eclipse.cdt.managedbuilder.core,
2525
org.eclipse.core.resources;bundle-version="3.13.700",
2626
org.eclipse.ui;bundle-version="3.117.0",
2727
org.eclipse.ui.console,
28-
org.eclipse.debug.core
28+
org.eclipse.debug.core,
29+
org.eclipse.core.variables
2930
Export-Package: cc.arduino.packages;x-internal:=true,
3031
cc.arduino.packages.discoverers;x-internal:=true,
3132
cc.arduino.packages.ssh;x-internal:=true,

io.sloeber.core/plugin.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,16 @@ priority="high"/>
514514
</builder>
515515
</extension>
516516

517+
<extension
518+
point="org.eclipse.core.variables.dynamicVariables">
519+
<variable
520+
description="The expanded value of the key (provided in the argument) as defined in Arduino txt files (boaards/platfor/programmers) from the active configuration ."
521+
name="Arduino_environment_variable"
522+
resolver="io.sloeber.core.eclipseIntegrations.CDT_EnvironmentVariableResolver"
523+
supportsArgument="true">
524+
</variable>
525+
</extension>
526+
517527
</plugin>
518528

519529

io.sloeber.core/src/io/sloeber/core/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public class Messages extends NLS {
103103
public static String No_Platform_available ;
104104
public static String decorator_no_platform;
105105
public static String decorator_no_port;
106+
public static String projectNotFoundInGUI;
106107

107108
static {
108109
// initialize resource bundle
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package io.sloeber.core.eclipseIntegrations;
2+
3+
import static io.sloeber.core.common.Const.*;
4+
5+
import org.eclipse.cdt.core.CCorePlugin;
6+
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
7+
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
8+
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
9+
import org.eclipse.core.resources.IProject;
10+
import org.eclipse.core.resources.IWorkspaceRoot;
11+
import org.eclipse.core.resources.ResourcesPlugin;
12+
import org.eclipse.core.runtime.CoreException;
13+
import org.eclipse.core.runtime.IStatus;
14+
import org.eclipse.core.runtime.Path;
15+
import org.eclipse.core.runtime.Status;
16+
import org.eclipse.core.variables.IDynamicVariable;
17+
import org.eclipse.core.variables.IDynamicVariableResolver;
18+
import org.eclipse.core.variables.IStringVariableManager;
19+
import org.eclipse.core.variables.VariablesPlugin;
20+
21+
import io.sloeber.core.Messages;
22+
23+
public class CDT_EnvironmentVariableResolver implements IDynamicVariableResolver {
24+
25+
@Override
26+
public String resolveValue(IDynamicVariable variable, String varName) throws CoreException {
27+
try {
28+
ICConfigurationDescription confDesc = getConfigurationDescription();
29+
return getBuildEnvironmentVariable(confDesc, varName);
30+
31+
} catch (@SuppressWarnings("unused") Exception dontCare) {
32+
Status iStatus = new Status(IStatus.ERROR, PLUGIN_ID, Messages.projectNotFoundInGUI);
33+
throw new CoreException(iStatus);
34+
}
35+
}
36+
37+
/**
38+
* Find the active configuration of the project selected in the project manager
39+
*
40+
* @return The configuration description or null if not found
41+
*/
42+
private static ICConfigurationDescription getConfigurationDescription() {
43+
IProject project = getGUISelectedProject();
44+
45+
if (project != null && project.exists() && project.isOpen()) {
46+
CCorePlugin cCorePlugin = CCorePlugin.getDefault();
47+
ICProjectDescription prjCDesc = cCorePlugin.getProjectDescription(project);
48+
return prjCDesc.getActiveConfiguration();
49+
}
50+
return null;
51+
}
52+
53+
static private String getBuildEnvironmentVariable(ICConfigurationDescription configurationDescription,
54+
String envName) {
55+
try {
56+
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
57+
return envManager.getVariable(envName, configurationDescription, true).getValue();
58+
} catch (@SuppressWarnings("unused") Exception e) {// ignore all errors and return the default value
59+
}
60+
return new String();
61+
}
62+
63+
/**
64+
* Returns the project selected GUI. Uses the ${selected_resource_path} variable
65+
* to determine the selected resource. This variable is provided by the debug.ui
66+
* plug-in. Selected resource resolution is only available when the debug.ui
67+
* plug-in is present.
68+
*
69+
* @return project related to selected resource in the gui if no project is
70+
* found null is returned
71+
*
72+
*/
73+
private static IProject getGUISelectedProject() {
74+
try {
75+
IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
76+
IWorkspaceRoot workSpaceRoot = ResourcesPlugin.getWorkspace().getRoot();
77+
String pathString;
78+
79+
pathString = manager.performStringSubstitution("${selected_resource_path}"); //$NON-NLS-1$
80+
81+
return workSpaceRoot.findMember(new Path(pathString)).getProject();
82+
} catch (@SuppressWarnings("unused") CoreException e) {
83+
return null;
84+
}
85+
86+
}
87+
88+
}

io.sloeber.core/src/io/sloeber/core/messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@ BoardsManagerIsBussy=The BoardsManager is still busy, retry later.
7575
No_Platform_available=The default platform (Arduino avr) was not found. Please install a platform in arduino->preferences.
7676
decorator_no_platform=no platform
7777
decorator_no_port=no port
78-
78+
projectNotFoundInGUI=The selected resource does not belong to a project

io.sloeber.core/src/io/sloeber/core/messages_it.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,5 @@ uploader_Failed_to_get_upload_recipe=Impossibile determinare il processo di uplo
7272
uploader_no_reset_using_network=Reset non richiesto dato che si sta eseguendo un upload di rete
7373
uploader_no_reset_using_programmer=Reset non richiesto dato che si sta utilizzando un dispositivo programmatore
7474
decorator_no_platform=nessuna piattaforma
75-
decorator_no_port=nessuna porta
75+
decorator_no_port=nessuna porta
76+
projectNotFoundInGUI=La risorsa selezionata non fa parte di un progetto.

io.sloeber.core/src/io/sloeber/core/messages_nl.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,5 @@ uploader_no_reset_using_programmer=Het bord wordt niet gereset want we gebruiken
7474
BoardsManagerIsBussy=BoardsManager is nog bezig, probeer later opnieuw.
7575
decorator_no_platform=geen platform
7676
decorator_no_port=geen poort
77+
projectNotFoundInGUI=Het in de GUI geselecteerde item is niet gerelateerd met een project.
78+

0 commit comments

Comments
 (0)