Skip to content

Commit 14eca20

Browse files
author
jantje
committed
#1268 all vars are now saved
Regression test are now successfull
1 parent 063978d commit 14eca20

File tree

4 files changed

+129
-57
lines changed

4 files changed

+129
-57
lines changed

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

+34-28
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ public class BoardDescription extends Common {
5454
private static final String ENV_KEY_JANTJE_MENU_SELECTION = ENV_KEY_JANTJE_START + Const.MENU;
5555
private static final String ENV_KEY_JANTJE_UPLOAD_PORT = ENV_KEY_JANTJE_START + Const.COM_PORT;
5656
private static final String ENV_KEY_JANTJE_BOARD_NAME = ENV_KEY_JANTJE_START + "board_name"; //$NON-NLS-1$
57-
private static final String ENV_KEY_JANTJE_PROJECT_NAME = ENV_KEY_JANTJE_START + "project_name"; //$NON-NLS-1$
58-
private static final String ENV_KEY_JANTJE_OS = ENV_KEY_JANTJE_START + "os_name"; //$NON-NLS-1$
59-
private static final String ENV_KEY_JANTJE_WORKSPACE_LOCATION = ENV_KEY_JANTJE_START + "workspace_location"; //$NON-NLS-1$
60-
private static final String ENV_KEY_JANTJE_ECLIPSE_LOCATION = ENV_KEY_JANTJE_START + "eclipse_location"; //$NON-NLS-1$
6157
private static final String ENV_KEY_JANTJE_BOARDS_FILE = ENV_KEY_JANTJE_START + "boards_file"; //$NON-NLS-1$
6258
private static final String ENV_KEY_JANTJE_PACKAGE_ID = ENV_KEY_JANTJE_START + "package_ID"; //$NON-NLS-1$
6359
private static final String ENV_KEY_JANTJE_ARCITECTURE_ID = ENV_KEY_JANTJE_START + "architecture_ID"; //$NON-NLS-1$
@@ -88,10 +84,10 @@ public class BoardDescription extends Common {
8884
/*
8985
* This is the basic info contained in the descriptor
9086
*/
91-
private String myUploadPort;
92-
private String myProgrammer;
93-
private String myBoardID;
94-
private Map<String, String> myOptions;
87+
private String myUploadPort = EMPTY;
88+
private String myProgrammer = Defaults.getDefaultUploadProtocol();
89+
private String myBoardID = EMPTY;
90+
private Map<String, String> myOptions = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
9591

9692
/*
9793
* Stuff to make things work
@@ -106,8 +102,12 @@ public class BoardDescription extends Common {
106102
private IPath myReferencedUploadToolPlatformPath;
107103
private String myUploadTool;
108104
private boolean isDirty = true;
109-
private final String ENV_KEY_JANTJE_PROGRAMMER = "SLOEBER.PROGRAMMER.NAME"; //$NON-NLS-1$
110-
private final String ENV_KEY_JANTJE_BOARD_TXT = "SLOEBER.PRODUCT.NAME"; //$NON-NLS-1$
105+
private final String ENV_KEY_SLOEBER_PROGRAMMER = "SLOEBER.PROGRAMMER.NAME"; //$NON-NLS-1$
106+
private final String ENV_KEY_SLOEBER_BOARD_TXT = "SLOEBER.BOARD.TXT"; //$NON-NLS-1$
107+
private final String ENV_KEY_SLOEBER_BOARD_ID = "SLOEBER.BOARD.ID"; //$NON-NLS-1$
108+
private final String ENV_KEY_SLOEBER_UPLOAD_PORT = "SLOEBER.UPLOAD.PORT"; //$NON-NLS-1$
109+
private final String ENV_KEY_SLOEBER_UPLOAD_TOOL = "SLOEBER.UPLOAD.TOOL"; //$NON-NLS-1$
110+
private final String ENV_KEY_SLOEBER_MENU_SELECTION = "SLOEBER.MENU"; //$NON-NLS-1$
111111

112112

113113
@Override
@@ -369,10 +369,7 @@ public static List<BoardDescription> makeBoardDescriptors(File boardFile, Map<St
369369
* if null default options are taken
370370
*/
371371
BoardDescription(File boardsFile, String boardID, Map<String, String> options) {
372-
this.myUploadPort = EMPTY;
373-
this.myProgrammer = Defaults.getDefaultUploadProtocol();
374372
this.myBoardID = boardID;
375-
this.myOptions = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
376373
this.myreferencingBoardsFile = boardsFile;
377374
this.myTxtFile = new BoardTxtFile(this.myreferencingBoardsFile);
378375
setDefaultOptions();
@@ -382,10 +379,7 @@ public static List<BoardDescription> makeBoardDescriptors(File boardFile, Map<St
382379
}
383380

384381
protected BoardDescription(BoardTxtFile txtFile, String boardID) {
385-
this.myUploadPort = EMPTY;
386-
this.myProgrammer = Defaults.getDefaultUploadProtocol();
387382
this.myBoardID = boardID;
388-
this.myOptions = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
389383
this.myreferencingBoardsFile = txtFile.getTxtFile();
390384
this.myTxtFile = txtFile;
391385
setDefaultOptions();
@@ -806,31 +800,39 @@ private Map<String, String> getEnvVarsTxt() {
806800
}
807801

808802
BoardDescription(TxtFile configFile) {
803+
809804
KeyValueTree tree = configFile.getData();
810-
this.myUploadPort = EMPTY;
811-
this.myProgrammer = tree.getValue(ENV_KEY_JANTJE_PROGRAMMER);
812-
this.myBoardID = tree.getValue(ENV_KEY_JANTJE_BOARD_ID);
813-
myreferencingBoardsFile = new File(tree.getValue(ENV_KEY_JANTJE_BOARD_TXT));
814-
this.myTxtFile = new BoardTxtFile(this.myreferencingBoardsFile);
815805

816-
KeyValueTree optionsTree = tree.getChild(ENV_KEY_JANTJE_MENU_SELECTION);
806+
this.myProgrammer = tree.getValue(ENV_KEY_SLOEBER_PROGRAMMER);
807+
this.myBoardID = tree.getValue(ENV_KEY_SLOEBER_BOARD_ID);
808+
String board_txt = tree.getValue(ENV_KEY_SLOEBER_BOARD_TXT);
809+
this.myUploadPort = tree.getValue(ENV_KEY_SLOEBER_UPLOAD_PORT);
810+
this.myUploadTool = tree.getValue(ENV_KEY_SLOEBER_UPLOAD_TOOL);
811+
KeyValueTree optionsTree = tree.getChild(ENV_KEY_SLOEBER_MENU_SELECTION);
817812
Map<String, String> options = optionsTree.toKeyValues(EMPTY, false);
818-
this.myOptions = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
819813

814+
myreferencingBoardsFile = new File(board_txt);
815+
this.myTxtFile = new BoardTxtFile(this.myreferencingBoardsFile);
820816
setDefaultOptions();
821817
if (options != null) {
822818
this.myOptions.putAll(options);
823819
}
820+
821+
// this.myOptions =
822+
824823
}
825824
public Map<String, String> getEnvVarsConfig() {
826825
Map<String, String> allVars = new TreeMap<>();
827-
allVars.put(ENV_KEY_JANTJE_PROGRAMMER, this.myProgrammer);
828-
allVars.put(ENV_KEY_JANTJE_BOARD_ID, this.myBoardID);
829-
allVars.put(ENV_KEY_JANTJE_BOARD_TXT, myreferencingBoardsFile.toString());
830-
// allVars.put(ENV_KEY_JANTJE_PRODUCT_VERSION, EMPTY);
826+
String board_txt = myreferencingBoardsFile.toString();
827+
828+
allVars.put(ENV_KEY_SLOEBER_PROGRAMMER, this.myProgrammer);
829+
allVars.put(ENV_KEY_SLOEBER_BOARD_ID, this.myBoardID);
830+
allVars.put(ENV_KEY_SLOEBER_BOARD_TXT, board_txt);
831+
allVars.put(ENV_KEY_SLOEBER_UPLOAD_PORT, this.myUploadPort);
832+
allVars.put(ENV_KEY_SLOEBER_UPLOAD_TOOL, this.myUploadTool);
831833

832834
for (Entry<String, String> curOption : this.myOptions.entrySet()) {
833-
allVars.put(ENV_KEY_JANTJE_MENU_SELECTION + DOT + curOption.getKey(), curOption.getValue());
835+
allVars.put(ENV_KEY_SLOEBER_MENU_SELECTION + DOT + curOption.getKey(), curOption.getValue());
834836
}
835837
return allVars;
836838
}
@@ -1120,5 +1122,9 @@ private static Map<String, String> getEnvVarsHookBuild(Map<String, String> vars,
11201122
return extraVars;
11211123
}
11221124

1125+
public static BoardDescription getFromCDTEnvVars() {
1126+
// TODO Auto-generated method stub
1127+
return null;
1128+
}
11231129

11241130
}

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

+18-3
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ public void set_All_CompileOptions(String my_All_CompileOptions) {
178178
public Map<String, String> getEnvVars() {
179179
Map<String, String> ret = getEnvVarsConfig();
180180

181-
ret.put(ENV_KEY_JANTJE_WARNING_LEVEL, Boolean.valueOf(myWarningLevel).toString());
182-
183181
if (this.isWarningLevel()) {
184182
ret.put(ENV_KEY_WARNING_LEVEL_OFF, ENV_KEY_WARNING_LEVEL_ON);
185183
}
@@ -237,6 +235,9 @@ public Map<String, String> getEnvVarsConfig() {
237235
ret.put(ENV_KEY_JANTJE_ARCHIVE_COMPILE_OPTIONS, this.my_Archive_CompileOptions);
238236
ret.put(ENV_KEY_JANTJE_LINK_COMPILE_OPTIONS, this.my_Link_CompileOptions);
239237
ret.put(ENV_KEY_JANTJE_ALL_COMPILE_OPTIONS, this.my_All_CompileOptions);
238+
ret.put(ENV_KEY_JANTJE_WARNING_LEVEL, Boolean.valueOf(myWarningLevel).toString());
239+
ret.put(ENV_KEY_JANTJE_SIZE_SWITCH, Boolean.valueOf(myAlternativeSizeCommand).toString());
240+
240241
return ret;
241242
}
242243

@@ -249,6 +250,8 @@ public CompileDescription(TxtFile configFile) {
249250
my_Archive_CompileOptions = tree.getValue(ENV_KEY_JANTJE_ARCHIVE_COMPILE_OPTIONS);
250251
my_Link_CompileOptions = tree.getValue(ENV_KEY_JANTJE_LINK_COMPILE_OPTIONS);
251252
my_All_CompileOptions = tree.getValue(ENV_KEY_JANTJE_ALL_COMPILE_OPTIONS);
253+
myWarningLevel = Const.TRUE.equalsIgnoreCase(tree.getValue(ENV_KEY_JANTJE_WARNING_LEVEL));
254+
myAlternativeSizeCommand = Const.TRUE.equalsIgnoreCase(tree.getValue(ENV_KEY_JANTJE_SIZE_SWITCH));
252255

253256
}
254257

@@ -259,7 +262,14 @@ public CompileDescription() {
259262
// therefore this is not set here but in the ui before project creation
260263
}
261264

262-
public boolean isEqual(CompileDescription other) {
265+
/**
266+
* Compares 2 compile descriptors parallel build is ignored as this is a project
267+
* creation only setting
268+
*
269+
* @param other
270+
* @return
271+
*/
272+
public boolean equals(CompileDescription other) {
263273
return (myWarningLevel == other.myWarningLevel) && (myAlternativeSizeCommand == other.myAlternativeSizeCommand)
264274
&& (my_CPP_CompileOptions.equals(other.my_CPP_CompileOptions))
265275
&& (my_C_CompileOptions.equals(other.my_C_CompileOptions))
@@ -270,4 +280,9 @@ public boolean isEqual(CompileDescription other) {
270280
&& (my_All_CompileOptions.equals(other.my_All_CompileOptions));
271281

272282
}
283+
284+
public static CompileDescription getFromCDTEnvVars() {
285+
// TODO Auto-generated method stub
286+
return null;
287+
}
273288
}

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

+76-25
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.HashMap;
66
import java.util.Map;
77
import java.util.Map.Entry;
8+
import java.util.TreeMap;
89

910
import org.eclipse.cdt.core.CCorePlugin;
1011
import org.eclipse.cdt.core.envvar.IContributedEnvironment;
@@ -52,7 +53,7 @@ public class SloeberProjectDescription extends Common {
5253
"Sloeber_Project_Description"); //$NON-NLS-1$
5354
private Map<String, BoardDescription> myBoardDescriptions = new HashMap<>();
5455
private Map<String, CompileDescription> myCompileDescriptions = new HashMap<>();
55-
56+
5657
private static final String ENV_KEY_BUILD_SOURCE_PATH = ERASE_START + "build.source.path"; //$NON-NLS-1$
5758
private static final String ENV_KEY_BUILD_GENERIC_PATH = ERASE_START + "build.generic.path"; //$NON-NLS-1$
5859
private static final String ENV_KEY_COMPILER_PATH = ERASE_START + "compiler.path"; //$NON-NLS-1$
@@ -180,7 +181,7 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
180181

181182
private void saveConfig(ICConfigurationDescription confDesc) {
182183

183-
createSloeberConfigFile(confDesc);
184+
createSloeberConfigFiles(confDesc);
184185
setEnvVars(confDesc, getEnvVars(confDesc), true);
185186

186187
}
@@ -241,33 +242,63 @@ private void readSloeberConfigFile(ICConfigurationDescription confDesc) {
241242

242243
}
243244

244-
private void createSloeberConfigFile(ICConfigurationDescription confDesc) {
245+
private static IFile getConfigLocalFile(ICConfigurationDescription confDesc) {
246+
IProject project = confDesc.getProjectDescription().getProject();
247+
return project.getFile(".sloeber." + confDesc.getName() + ".txt"); //$NON-NLS-1$ //$NON-NLS-2$
248+
}
249+
250+
private static IFile getConfigVersionFile(ICConfigurationDescription confDesc) {
251+
IProject project = confDesc.getProjectDescription().getProject();
252+
return project.getFile("sloeber." + confDesc.getName() + ".txt"); //$NON-NLS-1$ //$NON-NLS-2$
253+
}
254+
255+
/**
256+
* This methods creates/updates 2 files in the workspace. Together these files
257+
* contain the Sloeber project configuration info The info is split into 2 files
258+
* because you probably do not want to add all the info to a version control
259+
* tool.
260+
*
261+
* sloeber.[config name].txt is the file you can add to a version control
262+
* .sloeber.[config name].txt is the file with settings you do not want to add
263+
* to version control
264+
*
265+
* @param confDesc
266+
*/
267+
private void createSloeberConfigFiles(ICConfigurationDescription confDesc) {
245268
IProject project = confDesc.getProjectDescription().getProject();
246269
BoardDescription boardDescription = getBoardDescription(confDesc);
247270
CompileDescription compileDescription = getCompileDescription(confDesc);
248-
Map<String, String> configVars = new HashMap<>();
249-
if (boardDescription != null) {
250-
configVars = boardDescription.getEnvVarsConfig();
251-
}
252-
if (compileDescription == null) {
253-
compileDescription = new CompileDescription();
254-
}
271+
Map<String, String> configVars = new TreeMap<>();
272+
configVars.putAll(boardDescription.getEnvVarsConfig());
255273
configVars.putAll(compileDescription.getEnvVarsConfig());
256-
String newFileContent = EMPTY;
274+
275+
String versionFileContent = EMPTY;
276+
String localFileContent = EMPTY;
257277
for (Entry<String, String> curLine : configVars.entrySet()) {
258-
newFileContent += curLine.getKey() + '=' + curLine.getValue() + '\n';
278+
// TODO add filter to seperate local file info from
279+
// version file info
280+
versionFileContent += curLine.getKey() + '=' + curLine.getValue() + '\n';
259281
}
260-
IFile file = project.getFile("sloeber." + confDesc.getName() + ".txt"); //$NON-NLS-1$ //$NON-NLS-2$
282+
IFile versionFile = getConfigVersionFile(confDesc);
283+
IFile localFile = getConfigLocalFile(confDesc);
261284
try {
262-
file.refreshLocal(IResource.DEPTH_INFINITE, null);
263-
if (file.exists()) {
264-
file.delete(true, null);
265-
file.refreshLocal(IResource.DEPTH_INFINITE, null);
285+
project.refreshLocal(IResource.DEPTH_INFINITE, null);
286+
if (versionFile.exists()) {
287+
versionFile.delete(true, null);
266288
}
267289

268-
if (!file.exists() && (!newFileContent.isBlank())) {
269-
ByteArrayInputStream stream = new ByteArrayInputStream(newFileContent.getBytes());
270-
file.create(stream, true, null);
290+
if (!versionFile.exists() && (!versionFileContent.isBlank())) {
291+
ByteArrayInputStream stream = new ByteArrayInputStream(versionFileContent.getBytes());
292+
versionFile.create(stream, true, null);
293+
}
294+
295+
if (localFile.exists()) {
296+
localFile.delete(true, null);
297+
}
298+
299+
if (!localFile.exists() && (!localFileContent.isBlank())) {
300+
ByteArrayInputStream stream = new ByteArrayInputStream(localFileContent.getBytes());
301+
localFile.create(stream, true, null);
271302
}
272303
} catch (CoreException e) {
273304
// TODO Auto-generated catch block
@@ -403,11 +434,26 @@ public void setCompileDescription(ICConfigurationDescription confDesc, CompileDe
403434
}
404435
}
405436

437+
/**
438+
* Method that tries to give you the boardDescription settings for this
439+
* project/configuration This method tries folowing things 1)memory (after 2 or
440+
* 3) 2)configuration files in the project (at project creation) 3)CDT
441+
* environment variables (to update projects created by previous versions of
442+
* Sloeber)
443+
*
444+
* @param confDesc
445+
* @return
446+
*/
406447
public BoardDescription getBoardDescription(ICConfigurationDescription confDesc) {
407448
BoardDescription ret = myBoardDescriptions.get(confDesc.getId());
408449
if (ret == null) {
409-
readSloeberConfigFile(confDesc);
410-
ret = myBoardDescriptions.get(confDesc.getId());
450+
IFile file = getConfigVersionFile(confDesc);
451+
if (file.exists()) {
452+
readSloeberConfigFile(confDesc);
453+
ret = myBoardDescriptions.get(confDesc.getId());
454+
} else {
455+
ret = BoardDescription.getFromCDTEnvVars();
456+
}
411457
}
412458
return ret;
413459
}
@@ -423,16 +469,21 @@ private void putCompileDescription(ICConfigurationDescription confDesc, CompileD
423469
public CompileDescription getCompileDescription(ICConfigurationDescription confDesc) {
424470
CompileDescription ret = myCompileDescriptions.get(confDesc.getId());
425471
if (ret == null) {
426-
readSloeberConfigFile(confDesc);
427-
ret = myCompileDescriptions.get(confDesc.getId());
472+
IFile file = getConfigVersionFile(confDesc);
473+
if (file.exists()) {
474+
readSloeberConfigFile(confDesc);
475+
ret = myCompileDescriptions.get(confDesc.getId());
476+
} else {
477+
ret = CompileDescription.getFromCDTEnvVars();
478+
}
428479
}
429480
return ret;
430481
}
431482

432483
public String getDecoratedText(ICConfigurationDescription confDesc, String text) {
433484
BoardDescription boardDescriptor = getBoardDescription(confDesc);
434485
if (boardDescriptor == null) {
435-
return text + " Project needs to be configured";
486+
return text + " Project not configured"; //$NON-NLS-1$
436487
}
437488
String boardName = boardDescriptor.getBoardName();
438489
String portName = boardDescriptor.getActualUploadPort();

io.sloeber.core/src/io/sloeber/core/tools/Helpers.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public static void addArduinoCodeToProject(BoardDescription boardDescriptor,
328328
if (corePath != null) {
329329
addCodeFolder(project, corePath, ARDUINO_CODE_FOLDER_PATH, configurationDescription, true);
330330
IPath variantPath = boardDescriptor.getActualVariantPath();
331-
if (variantPath == null) {
331+
if ((variantPath == null) || (!variantPath.toFile().exists())) {
332332
// remove the existing link
333333
Helpers.removeCodeFolder(project, ARDUINO_VARIANT_FOLDER_PATH);
334334
} else {

0 commit comments

Comments
 (0)