@@ -58,6 +58,7 @@ public class SloeberProject extends Common {
58
58
private IProject myProject = null ;
59
59
private boolean isConfigured = false ;
60
60
private boolean isDirty = false ; // if anything has changed
61
+ private boolean myNeedsClean = false ; // is there old sloeber data that needs cleaning
61
62
62
63
private static final String ENV_KEY_BUILD_SOURCE_PATH = ERASE_START + "build.source.path" ; //$NON-NLS-1$
63
64
private static final String ENV_KEY_BUILD_GENERIC_PATH = ERASE_START + "build.generic.path" ; //$NON-NLS-1$
@@ -75,7 +76,7 @@ private SloeberProject(IProject project, boolean isProjectCreating) {
75
76
if (isProjectCreating ) {
76
77
return ;
77
78
}
78
- configureUpdateProject ();
79
+ configureProject ();
79
80
80
81
}
81
82
@@ -105,8 +106,9 @@ public static IProject createArduinoProject(String projectName, URI projectURI,
105
106
IProgressMonitor monitor ) {
106
107
107
108
String realProjectName = Common .MakeNameCompileSafe (projectName );
108
- IWorkspaceRoot root = ResourcesPlugin . getWorkspace (). getRoot ();
109
+
109
110
final IWorkspace workspace = ResourcesPlugin .getWorkspace ();
111
+ IWorkspaceRoot root = workspace .getRoot ();
110
112
ICoreRunnable runnable = new ICoreRunnable () {
111
113
@ Override
112
114
public void run (IProgressMonitor internalMonitor ) throws CoreException {
@@ -176,7 +178,6 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
176
178
}
177
179
178
180
arduinoProjDesc .createSloeberConfigFiles (prjCDesc );
179
- ;
180
181
SubMonitor refreshMonitor = SubMonitor .convert (internalMonitor , 3 );
181
182
newProjectHandle .open (refreshMonitor );
182
183
newProjectHandle .refreshLocal (IResource .DEPTH_INFINITE , refreshMonitor );
@@ -244,39 +245,57 @@ private HashMap<String, String> getEnvVars(ICConfigurationDescription confDesc)
244
245
return allVars ;
245
246
}
246
247
247
- private void configureUpdateProject () {
248
+ private void configureProject () {
248
249
249
250
CCorePlugin cCorePlugin = CCorePlugin .getDefault ();
250
251
ICProjectDescription prjCDesc = cCorePlugin .getProjectDescription (myProject );
251
- if (configureUpdateProject (prjCDesc )) {
252
- try {
253
- cCorePlugin .setProjectDescription (myProject , prjCDesc , true , null );
254
- } catch (CoreException e ) {
255
- // TODO Auto-generated catch block
256
- e .printStackTrace ();
257
- }
258
- }
252
+ configureProject (prjCDesc , false );
259
253
}
260
254
261
- private boolean configureUpdateProject (ICProjectDescription prjCDesc ) {
262
- boolean prjDescChanged = false ;
255
+ private void configureProject (ICProjectDescription prjCDesc , boolean prjDescWritable ) {
263
256
if (isConfigured ) {
264
257
if (isDirty ) {
265
258
createSloeberConfigFiles (prjCDesc );
266
-
267
- setActiveConfig (prjCDesc .getActiveConfiguration ());
268
- prjDescChanged = true ;
269
- isDirty = false ;
270
259
}
271
- return prjDescChanged ;
260
+ if (prjDescWritable && myNeedsClean ) {
261
+ cleanOldData (prjCDesc );
262
+ }
263
+ return ;
272
264
}
273
- readSloeberConfig (prjCDesc );
274
- if (isDirty ) {
265
+ // first configuration of the sloeber project
266
+ if (readSloeberConfig (prjCDesc )) {
267
+ // we migrated from a previous sloeber configuration
268
+ myNeedsClean = true ;
275
269
createSloeberConfigFiles (prjCDesc );
276
- isDirty = false ;
270
+ // we need a writable project description to clean the old sloeber data
271
+ if (prjDescWritable ) {
272
+ cleanOldData (prjCDesc );
273
+ }
277
274
}
278
275
isConfigured = true ;
279
- return true ;
276
+ }
277
+
278
+ /**
279
+ * remove environment variables from the old sloeber way
280
+ *
281
+ * @param prjCDesc
282
+ * @return
283
+ */
284
+ private void cleanOldData (ICProjectDescription prjCDesc ) {
285
+ IEnvironmentVariableManager envManager = CCorePlugin .getDefault ().getBuildEnvironmentManager ();
286
+ IContributedEnvironment contribEnv = envManager .getContributedEnvironment ();
287
+ for (ICConfigurationDescription confDesc : prjCDesc .getConfigurations ()) {
288
+ IEnvironmentVariable [] CurVariables = contribEnv .getVariables (confDesc );
289
+ for (int i = (CurVariables .length - 1 ); i > 0 ; i --) {
290
+ if (CurVariables [i ].getName ().startsWith ("A." )) {
291
+ contribEnv .removeVariable (CurVariables [i ].getName (), confDesc );
292
+ }
293
+ if (CurVariables [i ].getName ().startsWith ("JANTJE." )) {
294
+ contribEnv .removeVariable (CurVariables [i ].getName (), confDesc );
295
+ }
296
+ }
297
+ }
298
+ myNeedsClean = false ;
280
299
}
281
300
282
301
/**
@@ -287,7 +306,9 @@ private boolean configureUpdateProject(ICProjectDescription prjCDesc) {
287
306
* @param confDesc
288
307
* returns true if the config needs saving otherwise false
289
308
*/
290
- private void readSloeberConfig (ICProjectDescription prjCDesc ) {
309
+ @ SuppressWarnings ("nls" )
310
+ private boolean readSloeberConfig (final ICProjectDescription prjCDesc ) {
311
+ boolean needToCreateConfigFiles = false ;
291
312
IFile file = getConfigLocalFile ();
292
313
if (file .exists ()) {
293
314
myCfgFile = new TxtFile (file .getLocation ().toFile ());
@@ -312,7 +333,7 @@ private void readSloeberConfig(ICProjectDescription prjCDesc) {
312
333
} else {
313
334
// Maybe this is a old Sloeber project with the data in the eclipse build
314
335
// environment variables
315
- isDirty = true ;
336
+ needToCreateConfigFiles = true ;
316
337
for (ICConfigurationDescription confDesc : prjCDesc .getConfigurations ()) {
317
338
318
339
BoardDescription boardDesc = BoardDescription .getFromCDT (confDesc );
@@ -322,23 +343,10 @@ private void readSloeberConfig(ICProjectDescription prjCDesc) {
322
343
myCompileDescriptions .put (confDesc .getId (), compileDescription );
323
344
myOtherDescriptions .put (confDesc .getId (), otherDesc );
324
345
}
325
- // remove environment variables from the old sloeber way
326
- IEnvironmentVariableManager envManager = CCorePlugin .getDefault ().getBuildEnvironmentManager ();
327
- IContributedEnvironment contribEnv = envManager .getContributedEnvironment ();
328
- for (ICConfigurationDescription confDesc : prjCDesc .getConfigurations ()) {
329
- IEnvironmentVariable [] CurVariables = contribEnv .getVariables (confDesc );
330
- for (int i = (CurVariables .length - 1 ); i > 0 ; i --) {
331
- if (CurVariables [i ].getName ().startsWith (Const .ERASE_START )) {
332
- contribEnv .removeVariable (CurVariables [i ].getName (), confDesc );
333
- }
334
- if (CurVariables [i ].getName ().startsWith (Const .ENV_KEY_JANTJE_START )) {
335
- contribEnv .removeVariable (CurVariables [i ].getName (), confDesc );
336
- }
337
- }
338
- }
346
+
339
347
}
340
348
}
341
- setActiveConfig ( prjCDesc . getActiveConfiguration ()) ;
349
+ return needToCreateConfigFiles ;
342
350
}
343
351
344
352
private void setActiveConfig (ICConfigurationDescription confDesc ) {
@@ -372,7 +380,7 @@ private void setActiveConfig(ICConfigurationDescription confDesc) {
372
380
* @param project
373
381
* the project to store the data for
374
382
*/
375
- private void createSloeberConfigFiles (ICProjectDescription prjCDesc ) {
383
+ private void createSloeberConfigFiles (final ICProjectDescription prjCDesc ) {
376
384
377
385
Map <String , String > configVars = new TreeMap <>();
378
386
Map <String , String > versionVars = new TreeMap <>();
@@ -400,6 +408,7 @@ private void createSloeberConfigFiles(ICProjectDescription prjCDesc) {
400
408
try {
401
409
storeConfigurationFile (getConfigVersionFile (), versionVars );
402
410
storeConfigurationFile (getConfigLocalFile (), configVars );
411
+ isDirty = false ;
403
412
} catch (CoreException e ) {
404
413
Common .log (new Status (IStatus .ERROR , io .sloeber .core .Activator .getId (),
405
414
"failed to save the sloeber config files" , e )); //$NON-NLS-1$
@@ -535,22 +544,22 @@ public void setOtherDescription(ICConfigurationDescription confDesc, OtherDescri
535
544
*/
536
545
public BoardDescription getBoardDescription (ICConfigurationDescription confDesc , boolean allowNull ) {
537
546
if (!allowNull ) {
538
- configureUpdateProject ();
547
+ configureProject ();
539
548
}
540
549
return myBoardDescriptions .get (confDesc .getId ());
541
550
}
542
551
543
552
public CompileDescription getCompileDescription (ICConfigurationDescription confDesc , boolean allowNull ) {
544
553
if (!allowNull ) {
545
- configureUpdateProject ();
554
+ configureProject ();
546
555
}
547
556
return myCompileDescriptions .get (confDesc .getId ());
548
557
}
549
558
550
559
551
560
public OtherDescription getOtherDescription (ICConfigurationDescription confDesc , boolean allowNull ) {
552
561
if (!allowNull ) {
553
- configureUpdateProject ();
562
+ configureProject ();
554
563
}
555
564
return myOtherDescriptions .get (confDesc .getId ());
556
565
}
@@ -597,11 +606,9 @@ private IFile getConfigLocalFile() {
597
606
public void configChangeAboutToApply (ICProjectDescription newProjDesc , ICProjectDescription oldProjDesc ) {
598
607
ICConfigurationDescription newActiveConfig = newProjDesc .getActiveConfiguration ();
599
608
ICConfigurationDescription oldActiveConfig = oldProjDesc .getActiveConfiguration ();
609
+ configureProject (newProjDesc , true );
600
610
if (!newActiveConfig .getName ().equals (oldActiveConfig .getName ())) {
601
- configureUpdateProject (newProjDesc );
602
611
setActiveConfig (newActiveConfig );
603
- } else {
604
- configureUpdateProject (newProjDesc );
605
612
}
606
613
607
614
}
0 commit comments