Skip to content

Commit 0af7560

Browse files
author
jantje
committed
add extra params to conversion #1524
1 parent 4aca218 commit 0af7560

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

io.sloeber.core/src/io/sloeber/core/api/SloeberProject.java

+28-22
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,22 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
138138

139139
// create a sloeber project
140140
SloeberProject sloeberProject = new SloeberProject(project);
141+
CCorePlugin cCorePlugin = CCorePlugin.getDefault();
142+
ICProjectDescription prjCDesc = cCorePlugin.getProjectDescription(project, true);
143+
if (upgradeArduinoProject(sloeberProject, prjCDesc)) {
144+
try {
145+
cCorePlugin.setProjectDescription(project, prjCDesc);
146+
} catch (CoreException e) {
147+
e.printStackTrace();
148+
}
149+
}
141150
if (!sloeberProject.readConfigFromFiles()) {
142151
String RELEASE = "Release";
143152
sloeberProject.setBoardDescription(RELEASE, new BoardDescription(), false);
144153
sloeberProject.setCompileDescription(RELEASE, new CompileDescription());
145154
sloeberProject.setOtherDescription(RELEASE, new OtherDescription());
146-
// we failed to read from disk so we set opourselfves some values
147-
// faking the stuf is in memory
155+
// we failed to read from disk so we set up some values
156+
// faking the stuff is in memory
148157

149158
}
150159
String configName = sloeberProject.myBoardDescriptions.keySet().iterator().next();
@@ -184,9 +193,7 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
184193
ManagedBuildManager.setDefaultConfiguration(project, defaultConfig);
185194

186195
Map<String, String> configs2 = new HashMap<>();
187-
188-
CCorePlugin cCorePlugin = CCorePlugin.getDefault();
189-
ICProjectDescription prjCDesc = cCorePlugin.getProjectDescription(project);
196+
prjCDesc = cCorePlugin.getProjectDescription(project);
190197
ICConfigurationDescription activeConfig = prjCDesc.getActiveConfiguration();
191198

192199
for (String curConfigName : sloeberProject.myBoardDescriptions.keySet()) {
@@ -370,36 +377,29 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
370377
* project in a new for
371378
* currently only 1 conversion is implemented
372379
*
373-
* @param projectName
374-
* @param projectURI
375-
* @param monitor
380+
* returns true if the projectdescription needs to be saved
376381
*/
377382

378-
public void upgradeArduinoProject(String projectName, URI projectURI, IProgressMonitor monitor) {
383+
private static boolean upgradeArduinoProject(SloeberProject project, ICProjectDescription prjCDesc) {
379384
boolean saveProjDesc = false;
380-
CCorePlugin cCorePlugin = CCorePlugin.getDefault();
381-
ICProjectDescription prjCDesc = cCorePlugin.getProjectDescription(myProject, true);
385+
382386
if (prjCDesc == null) {
383387
//CDT project description is not found or is not writable
388+
return false;
384389
}
385390

386-
if (!getConfigLocalFile().exists()) {
391+
if (project.getConfigLocalFile().exists()) {
387392
//if the .sproject file exists check for old data and clean old data if found
393+
saveProjDesc = removeCDTEnvironmentVars(prjCDesc);
388394
} else {
389395
//No sloeber project file try to migrate from old CDT storage
390-
if (readConfigFromCDT(prjCDesc)) {
391-
createSloeberConfigFiles(prjCDesc);
392-
setAllEnvironmentVars(prjCDesc);
396+
if (project.readConfigFromCDT(prjCDesc)) {
397+
project.createSloeberConfigFiles(prjCDesc);
398+
project.setAllEnvironmentVars(prjCDesc);
393399
saveProjDesc = removeCDTEnvironmentVars(prjCDesc);
394400
}
395401
}
396-
if (saveProjDesc) {
397-
try {
398-
cCorePlugin.setProjectDescription(myProject, prjCDesc);
399-
} catch (CoreException e) {
400-
e.printStackTrace();
401-
}
402-
}
402+
return saveProjDesc;
403403
}
404404

405405
private HashMap<String, String> getEnvVars(String configKey) {
@@ -959,10 +959,16 @@ private static String getOtherPrefix(String confDescName) {
959959
return CONFIG_DOT + confDescName + DOT + "other."; //$NON-NLS-1$
960960
}
961961

962+
/*
963+
* Get the file that Sloeber maintains and that is meant to be stored in version control
964+
*/
962965
private IFile getConfigVersionFile() {
963966
return myProject.getFile(SLOEBER_CFG);
964967
}
965968

969+
/*
970+
* Get the sloeber configuration file
971+
*/
966972
private IFile getConfigLocalFile() {
967973
return myProject.getFile(".sproject"); //$NON-NLS-1$
968974
}

0 commit comments

Comments
 (0)