4
4
import java .util .Map ;
5
5
import java .util .Map .Entry ;
6
6
7
+ import org .eclipse .cdt .core .settings .model .ICConfigurationDescription ;
8
+ import org .eclipse .cdt .core .settings .model .ICProjectDescription ;
7
9
import org .eclipse .cdt .managedbuilder .core .IConfiguration ;
10
+ import org .eclipse .cdt .managedbuilder .core .ManagedBuildManager ;
8
11
import org .eclipse .cdt .managedbuilder .envvar .IBuildEnvironmentVariable ;
9
12
import org .eclipse .cdt .managedbuilder .envvar .IConfigurationEnvironmentVariableSupplier ;
10
13
import org .eclipse .cdt .managedbuilder .envvar .IEnvironmentVariableProvider ;
14
+ import org .eclipse .core .resources .IProject ;
11
15
12
16
import io .sloeber .core .api .PackageManager ;
17
+ import io .sloeber .core .api .SloeberProject ;
13
18
14
19
public class SloeberConfigurationVariableSupplier implements IConfigurationEnvironmentVariableSupplier {
15
20
// variables per configuration
@@ -18,19 +23,13 @@ public class SloeberConfigurationVariableSupplier implements IConfigurationEnvir
18
23
@ Override
19
24
public IBuildEnvironmentVariable getVariable (String variableName , IConfiguration configuration ,
20
25
IEnvironmentVariableProvider provider ) {
26
+ initializeIfNotYetDone (configuration );
21
27
Map <String , String > curConfigVars = myConfigValues .get (configuration .getName ());
22
28
if (null == curConfigVars ) {
23
29
return null ;
24
- // maybe the project is not yet loaded by Sloeber.
25
- // try to load and retry
26
- // ICConfigurationDescription confDesc =
27
- // ManagedBuildManager.getDescriptionForConfiguration(configuration);
28
- // IProject project = confDesc.getProjectDescription().getProject();
29
- // ArduinoProjectDescription.getArduinoProjectDescription(project);
30
- // curConfigVars = myValues.get(configuration.getName());
31
- // if (null == curConfigVars) {
32
- // return null;
33
- // }
30
+ // This should only happen if a config is existing Sloeber does not know about
31
+ // because we configured the sloeber project above
32
+ // So this should not happen
34
33
}
35
34
String ret = curConfigVars .get (variableName );
36
35
if (ret == null ) {
@@ -46,6 +45,7 @@ public IBuildEnvironmentVariable getVariable(String variableName, IConfiguration
46
45
@ Override
47
46
public IBuildEnvironmentVariable [] getVariables (IConfiguration configuration ,
48
47
IEnvironmentVariableProvider provider ) {
48
+ initializeIfNotYetDone (configuration );
49
49
Map <String , String > retVars = new HashMap <>();
50
50
Map <String , String > workbenchVars = PackageManager .getEnvironmentVariables ();
51
51
if (workbenchVars != null ) {
@@ -68,4 +68,15 @@ public IBuildEnvironmentVariable[] getVariables(IConfiguration configuration,
68
68
public void setEnvVars (IConfiguration configuration , Map <String , String > values ) {
69
69
myConfigValues .put (configuration .getName (), values );
70
70
}
71
+
72
+ private void initializeIfNotYetDone (IConfiguration configuration ) {
73
+ if (!myConfigValues .isEmpty ()) {
74
+ // we have some data; asume it is correct
75
+ return ;
76
+ }
77
+ ICConfigurationDescription confDesc = ManagedBuildManager .getDescriptionForConfiguration (configuration );
78
+ ICProjectDescription projDesc = confDesc .getProjectDescription ();
79
+ IProject project = projDesc .getProject ();
80
+ SloeberProject .getSloeberProject (project , false );
81
+ }
71
82
}
0 commit comments