Skip to content

Commit bd3665d

Browse files
author
jantje
committed
#1268 store boards.txt starting with ${SLOEBER_HOME}
This way project using boards installed by the boards manager can be in different locations on different machines
1 parent a25122e commit bd3665d

File tree

6 files changed

+65
-34
lines changed

6 files changed

+65
-34
lines changed

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

+15-11
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ public boolean needsRebuild(BoardDescription otherBoardDescriptor) {
152152
if (!this.getBoardID().equals(otherBoardDescriptor.getBoardID())) {
153153
return true;
154154
}
155-
if (!this.getReferencingBoardsFile().equals(otherBoardDescriptor.getReferencingBoardsFile())) {
155+
String moddedReferencingBoardsFile = makePathEnvironmentString(getReferencingBoardsFile());
156+
String moddedOtherReferencingBoardsFile = makePathEnvironmentString(
157+
otherBoardDescriptor.getReferencingBoardsFile());
158+
if (!moddedReferencingBoardsFile.equals(moddedOtherReferencingBoardsFile)) {
156159
return true;
157160
}
158161
if (!this.getOptions().equals(otherBoardDescriptor.getOptions())) {
@@ -320,7 +323,7 @@ private void ParseSection() {
320323
* @return a list of board descriptors
321324
*/
322325
public static List<BoardDescription> makeBoardDescriptors(File boardFile, Map<String, String> options) {
323-
BoardTxtFile txtFile = new BoardTxtFile(boardFile);
326+
BoardTxtFile txtFile = new BoardTxtFile(resolvePathEnvironmentString(boardFile));
324327
List<BoardDescription> boards = new ArrayList<>();
325328
String[] allSectionNames = txtFile.getAllSectionNames();
326329
for (String curboardName : allSectionNames) {
@@ -344,7 +347,7 @@ public static List<BoardDescription> makeBoardDescriptors(File boardFile, Map<St
344347
*/
345348
BoardDescription(File boardsFile, String boardID, Map<String, String> options) {
346349
this.myBoardID = boardID;
347-
this.myreferencingBoardsFile = boardsFile;
350+
this.myreferencingBoardsFile = resolvePathEnvironmentString(boardsFile);
348351
this.myTxtFile = new BoardTxtFile(this.myreferencingBoardsFile);
349352
setDefaultOptions();
350353
if (options != null) {
@@ -353,7 +356,8 @@ public static List<BoardDescription> makeBoardDescriptors(File boardFile, Map<St
353356
}
354357

355358
public BoardDescription() {
356-
myreferencingBoardsFile = new File(myStorageNode.get(KEY_LAST_USED_BOARDS_FILE, EMPTY));
359+
myreferencingBoardsFile = resolvePathEnvironmentString(
360+
new File(myStorageNode.get(KEY_LAST_USED_BOARDS_FILE, EMPTY)));
357361
myTxtFile = new BoardTxtFile(this.myreferencingBoardsFile);
358362
myBoardID = myStorageNode.get(KEY_LAST_USED_BOARD, EMPTY);
359363
myUploadPort = myStorageNode.get(KEY_LAST_USED_UPLOAD_PORT, EMPTY);
@@ -410,7 +414,7 @@ private void setDefaultOptions() {
410414
* project
411415
*/
412416
public void saveUserSelection() {
413-
myStorageNode.put(KEY_LAST_USED_BOARDS_FILE, makePathEnvironmentString(getReferencingBoardsFile().toString()));
417+
myStorageNode.put(KEY_LAST_USED_BOARDS_FILE, makePathEnvironmentString(getReferencingBoardsFile()));
414418
myStorageNode.put(KEY_LAST_USED_BOARD, this.myBoardID);
415419
myStorageNode.put(KEY_LAST_USED_UPLOAD_PORT, this.myUploadPort);
416420
myStorageNode.put(KEY_LAST_USED_UPLOAD_PROTOCOL, this.myProgrammer);
@@ -492,11 +496,11 @@ public void setreferencingBoardsFile(File boardsFile) {
492496
if (boardsFile == null) {
493497
return;// ignore
494498
}
495-
if (this.myreferencingBoardsFile.equals(boardsFile)) {
499+
if (this.myreferencingBoardsFile.equals(resolvePathEnvironmentString(boardsFile))) {
496500
return;
497501
}
498502

499-
this.myreferencingBoardsFile = boardsFile;
503+
this.myreferencingBoardsFile = resolvePathEnvironmentString(boardsFile);
500504
this.myTxtFile = new BoardTxtFile(this.myreferencingBoardsFile);
501505
setDirty();
502506
}
@@ -773,7 +777,7 @@ private Map<String, String> getEnvVarsTxt() {
773777
KeyValueTree optionsTree = section.getChild(KEY_SLOEBER_MENU_SELECTION);
774778
Map<String, String> options = optionsTree.toKeyValues(EMPTY, false);
775779

776-
myreferencingBoardsFile = new File(board_txt);
780+
myreferencingBoardsFile = resolvePathEnvironmentString(new File(board_txt));
777781
this.myTxtFile = new BoardTxtFile(this.myreferencingBoardsFile);
778782
setDefaultOptions();
779783
if (options != null) {
@@ -809,7 +813,7 @@ private Map<String, String> onlyKeepValidOptions(Map<String, String> options) {
809813
*/
810814
public Map<String, String> getEnvVarsConfig(String prefix) {
811815
Map<String, String> allVars = new TreeMap<>();
812-
String board_txt = myreferencingBoardsFile.toString();
816+
String board_txt = makePathEnvironmentString(getReferencingBoardsFile());
813817

814818
allVars.put(prefix + KEY_SLOEBER_PROGRAMMER, myProgrammer);
815819
allVars.put(prefix + KEY_SLOEBER_BOARD_ID, myBoardID);
@@ -1109,9 +1113,9 @@ public static BoardDescription getFromCDT(ICConfigurationDescription confDesc) {
11091113
packagesIndex=referencingBoardsFile.indexOf( "/arduinoPlugin/packages/");
11101114
}
11111115
if(packagesIndex!=-1) {
1112-
referencingBoardsFile = eclipseHomePath.append(referencingBoardsFile.substring(packagesIndex)).toString();
1116+
referencingBoardsFile = sloeberHomePath.append(referencingBoardsFile.substring(packagesIndex)).toString();
11131117
}
1114-
ret.myreferencingBoardsFile = new File(referencingBoardsFile);
1118+
ret.myreferencingBoardsFile = resolvePathEnvironmentString(new File(referencingBoardsFile));
11151119
ret.myTxtFile = new BoardTxtFile(ret.myreferencingBoardsFile);
11161120

11171121
return ret;

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

+10-3
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ private void configureProject(ICProjectDescription prjCDesc, boolean prjDescWrit
256256
if (isConfigured) {
257257
if (isDirty) {
258258
createSloeberConfigFiles(prjCDesc);
259+
setEnvironmentVariables(prjCDesc);
259260
}
260261
if (prjDescWritable && myNeedsClean) {
261262
cleanOldData(prjCDesc);
@@ -272,6 +273,7 @@ private void configureProject(ICProjectDescription prjCDesc, boolean prjDescWrit
272273
cleanOldData(prjCDesc);
273274
}
274275
}
276+
setEnvironmentVariables(prjCDesc);
275277
isConfigured = true;
276278
}
277279

@@ -287,10 +289,10 @@ private void cleanOldData(ICProjectDescription prjCDesc) {
287289
for (ICConfigurationDescription confDesc : prjCDesc.getConfigurations()) {
288290
IEnvironmentVariable[] CurVariables = contribEnv.getVariables(confDesc);
289291
for (int i = (CurVariables.length - 1); i > 0; i--) {
290-
if (CurVariables[i].getName().startsWith("A.")) {
292+
if (CurVariables[i].getName().startsWith("A.")) { //$NON-NLS-1$
291293
contribEnv.removeVariable(CurVariables[i].getName(), confDesc);
292294
}
293-
if (CurVariables[i].getName().startsWith("JANTJE.")) {
295+
if (CurVariables[i].getName().startsWith("JANTJE.")) { //$NON-NLS-1$
294296
contribEnv.removeVariable(CurVariables[i].getName(), confDesc);
295297
}
296298
}
@@ -367,6 +369,12 @@ private boolean setActiveConfig(ICConfigurationDescription confDesc) {
367369
return false;
368370
}
369371

372+
private void setEnvironmentVariables(final ICProjectDescription prjCDesc) {
373+
for (ICConfigurationDescription confDesc : prjCDesc.getConfigurations()) {
374+
setEnvVars(confDesc, getEnvVars(confDesc));
375+
}
376+
}
377+
370378
/**
371379
* This methods creates/updates 2 files in the workspace. Together these files
372380
* contain the Sloeber project configuration info The info is split into 2 files
@@ -401,7 +409,6 @@ private void createSloeberConfigFiles(final ICProjectDescription prjCDesc) {
401409
versionVars.putAll(compileDescription.getEnvVarsConfig(compPrefix));
402410
versionVars.putAll(otherDescription.getEnvVarsConfig(otherPrefix));
403411
}
404-
setEnvVars(confDesc, getEnvVars(confDesc));
405412
}
406413

407414
try {

io.sloeber.core/src/io/sloeber/core/common/Common.java

+22-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sloeber.core.common;
22

3+
import java.io.File;
34
import java.net.URI;
45
import java.net.URISyntaxException;
56
import java.net.URL;
@@ -24,10 +25,11 @@
2425

2526
public class Common extends Const {
2627

27-
public final static String eclipseHome = getEclipseHome();
28-
public final static IPath eclipseHomePath = new Path(eclipseHome);
28+
public final static String sloeberHome = getSloeberHome();
29+
public final static IPath sloeberHomePath = new Path(sloeberHome);
30+
public final static String sloeberHomePathToOSString = sloeberHomePath.toOSString();
2931

30-
private static String getEclipseHome() {
32+
private static String getSloeberHome() {
3133

3234
try {
3335
String sloeber_HomeValue = System.getenv(Const.SLOEBER_HOME);
@@ -36,7 +38,8 @@ private static String getEclipseHome() {
3638
return sloeber_HomeValue;
3739
}
3840
}
39-
41+
// no sloeber home provided
42+
// use eclipse home as sloeber home
4043
URL resolvedUrl = Platform.getInstallLocation().getURL();
4144
URI resolvedUri = new URI(resolvedUrl.getProtocol(), resolvedUrl.getPath(), null);
4245
return Paths.get(resolvedUri).toString();
@@ -208,19 +211,28 @@ public static IPath getWorkspaceRoot() {
208211
return myWorkspaceRoot.getLocation();
209212
}
210213

211-
214+
private final static String SLOEBER_HOME_VAR = makeEnvironmentVar(SLOEBER_HOME);
212215

213216
/**
214-
* Check whether the string starts with the eclipse path If it does replace with
215-
* environment variable This keeps things more compatible over environments
217+
* Check whether the string starts with the SLOEBER_HOME path If it does replace
218+
* with environment variable This keeps things more compatible over environments
216219
*
217-
* @param path string to check
220+
* @param path
221+
* string to check
218222
* @return modified string or the original
219223
*/
220-
public static String makePathEnvironmentString(String path) {
221-
return path.replace(eclipseHome, makeEnvironmentVar(ECLIPSE_HOME));
224+
public static String makePathEnvironmentString(IPath path) {
225+
return path.toOSString().replace(sloeberHomePathToOSString, SLOEBER_HOME_VAR);
222226
}
223227

228+
public static String makePathEnvironmentString(File file) {
229+
return file.getPath().replace(sloeberHomePathToOSString, SLOEBER_HOME_VAR);
230+
}
231+
232+
public static File resolvePathEnvironmentString(File file) {
233+
String retString = file.getPath().replace(SLOEBER_HOME_VAR, sloeberHomePathToOSString);
234+
return new File(retString);
235+
}
224236

225237

226238
/**

io.sloeber.core/src/io/sloeber/core/common/ConfigurationPreferences.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private static void setString(String key, String value) {
116116

117117

118118
public static IPath getInstallationPath() {
119-
return Common.eclipseHomePath.append("arduinoPlugin"); //$NON-NLS-1$
119+
return Common.sloeberHomePath.append("arduinoPlugin"); //$NON-NLS-1$
120120
}
121121

122122
public static IPath getInstallationPathLibraries() {

io.sloeber.core/src/io/sloeber/core/common/Const.java

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public class Const {
5555
public static final String CORE_PLUGIN_ID = "io.sloeber.arduino.core";
5656
public static final String ARDUINO_NATURE_ID = "io.sloeber.arduinonature";
5757
public static final String KEY_LAST_USED_EXAMPLES = "Last used Examples";
58-
public static final String ECLIPSE_HOME = "eclipse_home";
5958
public static final String SLOEBER_HOME = "SLOEBER_HOME";
6059

6160
// Folder and file Information

io.sloeber.core/src/io/sloeber/core/toolchain/SloeberProjectVariableSupplier.java

+17-8
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider;
1414
import org.eclipse.cdt.managedbuilder.envvar.IProjectEnvironmentVariableSupplier;
1515

16+
import io.sloeber.core.common.Common;
17+
1618
//SloeberConfigurationVariableSupplier
1719
public class SloeberProjectVariableSupplier implements IProjectEnvironmentVariableSupplier {
18-
private Map<String, BuildEnvironmentVariable> myValues = new HashMap<>();
20+
1921

2022

2123
private static BuildEnvironmentVariable get_EXTRA_TIME_UTC() {
@@ -45,6 +47,10 @@ private static BuildEnvironmentVariable get_EXTRA_TIME_DTS() {
4547
return new BuildEnvironmentVariable(EXTRA_TIME_DTS, Long.toString(daylight));
4648
}
4749

50+
private static BuildEnvironmentVariable get_SLOEBER_HOME() {
51+
return new BuildEnvironmentVariable(SLOEBER_HOME, Common.sloeberHome);
52+
}
53+
4854

4955
@Override
5056
public IBuildEnvironmentVariable getVariable(String variableName, IManagedProject project,
@@ -58,18 +64,21 @@ public IBuildEnvironmentVariable getVariable(String variableName, IManagedProjec
5864
return get_EXTRA_TIME_ZONE();
5965
case EXTRA_TIME_DTS:
6066
return get_EXTRA_TIME_DTS();
61-
default:
62-
return myValues.get(variableName);
67+
case SLOEBER_HOME:
68+
return get_SLOEBER_HOME();
6369
}
70+
return null;
6471
}
6572

6673
@Override
6774
public IBuildEnvironmentVariable[] getVariables(IManagedProject project, IEnvironmentVariableProvider provider) {
68-
myValues.put(EXTRA_TIME_UTC, get_EXTRA_TIME_UTC());
69-
myValues.put(EXTRA_TIME_LOCAL, get_EXTRA_TIME_LOCAL());
70-
myValues.put(EXTRA_TIME_ZONE, get_EXTRA_TIME_ZONE());
71-
myValues.put(EXTRA_TIME_DTS, get_EXTRA_TIME_DTS());
72-
return myValues.values().toArray(new BuildEnvironmentVariable[myValues.size()]);
75+
Map<String, BuildEnvironmentVariable> retValues = new HashMap<>();
76+
retValues.put(EXTRA_TIME_UTC, get_EXTRA_TIME_UTC());
77+
retValues.put(EXTRA_TIME_LOCAL, get_EXTRA_TIME_LOCAL());
78+
retValues.put(EXTRA_TIME_ZONE, get_EXTRA_TIME_ZONE());
79+
retValues.put(EXTRA_TIME_DTS, get_EXTRA_TIME_DTS());
80+
retValues.put(SLOEBER_HOME, get_SLOEBER_HOME());
81+
return retValues.values().toArray(new BuildEnvironmentVariable[retValues.size()]);
7382
}
7483

7584
}

0 commit comments

Comments
 (0)