Skip to content

Commit edf09c9

Browse files
authored
Merge pull request #1176 from Sloeber/issue_#1175
Issue #1175
2 parents f9fa998 + 9ef3c98 commit edf09c9

File tree

4 files changed

+98
-101
lines changed

4 files changed

+98
-101
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ script:
1414
- sh -c "if $TRAVIS_SECURE_ENV_VARS; then echo Travis SECURE available -- Deploy; else echo Travis SECURE NOT available -- Verify; fi"
1515

1616
#Execute the maven commands depending on SECURE availabilty and print the elapsed time out periodically.
17-
- sh -c "if $TRAVIS_SECURE_ENV_VARS; then ./travis_exec_and_print_time.sh 'mvn deploy -Dtest=RegressionTest --quiet --settings settings.xml'; else ./travis_exec_and_print_time.sh 'mvn verify -Dtest=RegressionTest --quiet --settings settings.xml'; fi"
17+
- sh -c "if $TRAVIS_SECURE_ENV_VARS; then ./travis_exec_and_print_time.sh 'mvn verify -Dtest=RegressionTest --quiet --settings settings.xml'; else ./travis_exec_and_print_time.sh 'mvn verify -Dtest=RegressionTest --quiet --settings settings.xml'; fi"
1818

1919
#Several usernames and passwords/tokens are required for deployment.
2020
#When testing on your local/remote setup then you need to set/export env. variables:

io.sloeber.core/src/io/sloeber/core/managers/WorkAround.java

Lines changed: 83 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,30 @@
1919
import io.sloeber.core.tools.Version;
2020

2121
/**
22-
* A class to apply workarounds to installed packages
23-
* workaround are done after installation
24-
* at usage of boards.txt file
25-
* at usage of platform.txt file
22+
* A class to apply workarounds to installed packages workaround are done after
23+
* installation at usage of boards.txt file at usage of platform.txt file
2624
*
27-
* The first line of the worked around files contain a key
28-
* A newer version of sloeber that has a different workaround shuld change the key
29-
* in this way the worked around files can be persisted and updated when needed
25+
* The first line of the worked around files contain a key A newer version of
26+
* sloeber that has a different workaround shuld change the key in this way the
27+
* worked around files can be persisted and updated when needed
3028
*
3129
* @author jan
3230
*
3331
*/
3432
@SuppressWarnings("nls")
3533
public class WorkAround {
36-
//Each time this class is touched consider changing the String below to enforce updates
34+
// Each time this class is touched consider changing the String below to enforce
35+
// updates
3736
private static final String FIRST_SLOEBER_WORKAROUND_LINE = "#Sloeber created workaound file V1.00.test 3";
3837

39-
4038
/**
41-
* workarounds done at installation time.
42-
* I try to keep those at a minimum but none platform.txt and boards.txt
43-
* workarounds need to be doine during install time
39+
* workarounds done at installation time. I try to keep those at a minimum but
40+
* none platform.txt and boards.txt workarounds need to be doine during install
41+
* time
4442
*
4543
* @param platform
4644
*/
47-
static public void applyKnownWorkArounds(ArduinoPlatform platform) {
45+
static synchronized public void applyKnownWorkArounds(ArduinoPlatform platform) {
4846

4947
/*
5048
* for STM32 V1.8 and later #include "SrcWrapper.h" to Arduino.h remove the
@@ -70,105 +68,101 @@ static public void applyKnownWorkArounds(ArduinoPlatform platform) {
7068
MakeBoardsSloeberTxt(platform.getBoardsFile());
7169

7270
}
73-
74-
71+
7572
/**
7673
* create a workedaround boards.txt and return that filz
77-
*
74+
*
7875
* @param requestedFileToWorkAround
7976
*
80-
* @return the worked around file or requestedFileToWorkAround is it does not exist or error
77+
* @return the worked around file or requestedFileToWorkAround is it does not
78+
* exist or error
8179
*/
82-
static public File MakeBoardsSloeberTxt(File requestedFileToWorkAround) {
83-
if(!requestedFileToWorkAround.exists()) {
80+
static synchronized public File MakeBoardsSloeberTxt(File requestedFileToWorkAround) {
81+
if (!requestedFileToWorkAround.exists()) {
8482
return requestedFileToWorkAround;
8583
}
86-
String inFile=requestedFileToWorkAround.toString();
87-
String actualFileToLoad=inFile.replace(Const.BOARDS_FILE_NAME,"boards.sloeber.txt");
88-
if(inFile.equals(actualFileToLoad)) {
84+
String inFile = requestedFileToWorkAround.toString();
85+
String actualFileToLoad = inFile.replace(Const.BOARDS_FILE_NAME, "boards.sloeber.txt");
86+
if (inFile.equals(actualFileToLoad)) {
8987
Common.log(new Status(IStatus.ERROR, Activator.getId(),
9088
"Boards.txt file is not recognized " + requestedFileToWorkAround.toString()));
9189
return requestedFileToWorkAround;
9290
}
93-
File boardsSloeberTXT=new File(actualFileToLoad);
94-
if(boardsSloeberTXT.exists()) {
95-
//delete if outdated
91+
File boardsSloeberTXT = new File(actualFileToLoad);
92+
if (boardsSloeberTXT.exists()) {
93+
// delete if outdated
9694
String firstLine = null;
97-
try(BufferedReader Buff = new BufferedReader(new FileReader(boardsSloeberTXT));) {
95+
try (BufferedReader Buff = new BufferedReader(new FileReader(boardsSloeberTXT));) {
9896
firstLine = Buff.readLine();
9997
} catch (Exception e) {
100-
//ignore and delete the file
101-
}
102-
if(!FIRST_SLOEBER_WORKAROUND_LINE.equals(firstLine)) {
98+
// ignore and delete the file
99+
}
100+
if (!FIRST_SLOEBER_WORKAROUND_LINE.equals(firstLine)) {
103101
boardsSloeberTXT.delete();
104102
}
105103
}
106-
if(!boardsSloeberTXT.exists()) {
107-
if (requestedFileToWorkAround.exists()) {
108-
try {
109-
if (SystemUtils.IS_OS_WINDOWS) {
110-
String boardsTXT = FIRST_SLOEBER_WORKAROUND_LINE+"\n";
111-
boardsTXT += FileUtils.readFileToString(requestedFileToWorkAround, Charset.defaultCharset());
112-
boardsTXT = boardsTXT.replace("\r\n", "\n");
113-
114-
115-
// replace FI circuitplay32u4cat.build.usb_manufacturer="Adafruit"
116-
// with circuitplay32u4cat.build.usb_manufacturer=Adafruit
117-
boardsTXT = boardsTXT.replaceAll("(\\S+\\.build\\.usb\\S+)=\\\"(.+)\\\"", "$1=$2");
118-
119-
120-
FileUtils.write(boardsSloeberTXT, boardsTXT, Charset.defaultCharset());
121-
}
122-
} catch (IOException e) {
123-
// TODO Auto-generated catch block
124-
e.printStackTrace();
104+
if (!boardsSloeberTXT.exists()) {
105+
try {
106+
String boardsTXT = FIRST_SLOEBER_WORKAROUND_LINE + "\n";
107+
boardsTXT += FileUtils.readFileToString(requestedFileToWorkAround, Charset.defaultCharset());
108+
boardsTXT = boardsTXT.replace("\r\n", "\n");
109+
110+
if (SystemUtils.IS_OS_WINDOWS) {
111+
// replace FI circuitplay32u4cat.build.usb_manufacturer="Adafruit"
112+
// with circuitplay32u4cat.build.usb_manufacturer=Adafruit
113+
boardsTXT = boardsTXT.replaceAll("(\\S+\\.build\\.usb\\S+)=\\\"(.+)\\\"", "$1=$2");
125114
}
115+
FileUtils.write(boardsSloeberTXT, boardsTXT, Charset.defaultCharset());
116+
} catch (IOException e) {
117+
Common.log(new Status(IStatus.WARNING, Activator.getId(),
118+
"Failed to apply work arounds to " + requestedFileToWorkAround.toString(), e));
119+
return requestedFileToWorkAround;
126120
}
127121
}
128122
return boardsSloeberTXT;
129123
}
130-
131-
124+
132125
/**
133126
* create a workedaround platform.txt and return that filz
134-
*
127+
*
135128
* @param requestedFileToWorkAround
136129
*
137-
* @return the worked around file or requestedFileToWorkAround is it does not exist or error
130+
* @return the worked around file or requestedFileToWorkAround is it does not
131+
* exist or error
138132
*/
139-
public static File MakePlatformSloeberTXT(File requestedFileToWorkAround) {
140-
if(!requestedFileToWorkAround.exists()) {
133+
public synchronized static File MakePlatformSloeberTXT(File requestedFileToWorkAround) {
134+
if (!requestedFileToWorkAround.exists()) {
141135
return requestedFileToWorkAround;
142136
}
143-
String inFile=requestedFileToWorkAround.toString();
144-
String actualFileToLoad=inFile.replace(Const.PLATFORM_FILE_NAME,"platform.sloeber.txt");
145-
if(inFile.equals(actualFileToLoad)) {
137+
String inFile = requestedFileToWorkAround.toString();
138+
String actualFileToLoad = inFile.replace(Const.PLATFORM_FILE_NAME, "platform.sloeber.txt");
139+
if (inFile.equals(actualFileToLoad)) {
146140
Common.log(new Status(IStatus.ERROR, Activator.getId(),
147141
"platform.txt file is not recognized " + requestedFileToWorkAround.toString()));
148142
return requestedFileToWorkAround;
149143
}
150-
File platformSloeberTXT=new File(actualFileToLoad);
151-
if(platformSloeberTXT.exists()) {
152-
//delete if outdated
144+
File platformSloeberTXT = new File(actualFileToLoad);
145+
if (platformSloeberTXT.exists()) {
146+
// delete if outdated
153147
String firstLine = null;
154-
try(BufferedReader Buff = new BufferedReader(new FileReader(platformSloeberTXT));) {
148+
try (BufferedReader Buff = new BufferedReader(new FileReader(platformSloeberTXT));) {
155149
firstLine = Buff.readLine();
156150
} catch (Exception e) {
157-
//ignore and delete the file
158-
}
159-
if(!FIRST_SLOEBER_WORKAROUND_LINE.equals(firstLine)) {
151+
// ignore and delete the file
152+
}
153+
if (!FIRST_SLOEBER_WORKAROUND_LINE.equals(firstLine)) {
160154
platformSloeberTXT.delete();
161155
}
162156
}
163157
if (!platformSloeberTXT.exists()) {
164158
try {
165-
String platformTXT = FIRST_SLOEBER_WORKAROUND_LINE+"\n";
159+
String platformTXT = FIRST_SLOEBER_WORKAROUND_LINE + "\n";
166160
platformTXT += FileUtils.readFileToString(requestedFileToWorkAround, Charset.defaultCharset());
167161
platformTXT = platformTXT.replace("\r\n", "\n");
168-
169-
//Arduino treats core differently so we need to change the location of directly
170-
//referenced files this manifestates only in the combine recipe
171-
int inCombineStartIndex=platformTXT.indexOf("\nrecipe.c.combine.pattern")+1;
162+
163+
// Arduino treats core differently so we need to change the location of directly
164+
// referenced files this manifestates only in the combine recipe
165+
int inCombineStartIndex = platformTXT.indexOf("\nrecipe.c.combine.pattern") + 1;
172166
if (inCombineStartIndex > 0) {
173167
int inCombineEndIndex = platformTXT.indexOf("\n", inCombineStartIndex) - 1;
174168
if (inCombineEndIndex > 0) {
@@ -180,15 +174,14 @@ public static File MakePlatformSloeberTXT(File requestedFileToWorkAround) {
180174
}
181175
}
182176

183-
184177
// workaround for infineon arm v1.4.0 overwriting the default to a wrong value
185178
platformTXT = platformTXT.replace("\nbuild.core.path", "\n#line removed by Sloeber build.core.path");
186179

187-
Path platformTXTPath= new Path (requestedFileToWorkAround.toString());
188-
int totalSegments= platformTXTPath.segmentCount();
189-
String platformVersion= platformTXTPath.segment(totalSegments-2);
190-
String platformArchitecture= platformTXTPath.segment(totalSegments-3);
191-
String platformName= platformTXTPath.segment(totalSegments-5);
180+
Path platformTXTPath = new Path(requestedFileToWorkAround.toString());
181+
int totalSegments = platformTXTPath.segmentCount();
182+
String platformVersion = platformTXTPath.segment(totalSegments - 2);
183+
String platformArchitecture = platformTXTPath.segment(totalSegments - 3);
184+
String platformName = platformTXTPath.segment(totalSegments - 5);
192185
if (Version.compare("1.8.0", platformVersion) != 1) {
193186
if ("stm32".equals(platformArchitecture)) {
194187
if ("STM32".equals(platformName)) {
@@ -198,30 +191,29 @@ public static File MakePlatformSloeberTXT(File requestedFileToWorkAround) {
198191
}
199192
}
200193

201-
202-
//for adafruit nfr
203-
platformTXT = platformTXT.replace("-DARDUINO_BSP_VERSION=\"{version}\"", "\"-DARDUINO_BSP_VERSION=\\\"{version}\\\"\"");
204-
194+
// for adafruit nfr
195+
platformTXT = platformTXT.replace("-DARDUINO_BSP_VERSION=\"{version}\"",
196+
"\"-DARDUINO_BSP_VERSION=\\\"{version}\\\"\"");
197+
205198
if (SystemUtils.IS_OS_WINDOWS) {
206199
// replace FI '-DUSB_PRODUCT={build.usb_product}' with
207200
// "-DUSB_PRODUCT=\"{build.usb_product}\""
208201
platformTXT = platformTXT.replaceAll("\\'-D(\\S+)=\\{(\\S+)}\\'", "\"-D$1=\\\\\"{$2}\\\\\"\"");
209-
210-
211-
//quoting fixes for embedutils
212-
platformTXT = platformTXT.replaceAll("\"?(-DMBEDTLS_\\S+)=\\\\?\"(mbedtls\\S+)\"\\\\?\"*", "\"$1=\\\\\"$2\\\\\"\"");
213-
214-
//Sometimes "-DUSB_MANUFACTURER={build.usb_manufacturer}" "-DUSB_PRODUCT={build.usb_product}"
215-
//is used fi LinKit smart
216-
platformTXT = platformTXT.replace("\"-DUSB_MANUFACTURER={build.usb_manufacturer}\"",
202+
203+
// quoting fixes for embedutils
204+
platformTXT = platformTXT.replaceAll("\"?(-DMBEDTLS_\\S+)=\\\\?\"(mbedtls\\S+)\"\\\\?\"*",
205+
"\"$1=\\\\\"$2\\\\\"\"");
206+
207+
// Sometimes "-DUSB_MANUFACTURER={build.usb_manufacturer}"
208+
// "-DUSB_PRODUCT={build.usb_product}"
209+
// is used fi LinKit smart
210+
platformTXT = platformTXT.replace("\"-DUSB_MANUFACTURER={build.usb_manufacturer}\"",
217211
"\"-DUSB_MANUFACTURER=\\\"{build.usb_manufacturer}\\\"\"");
218-
platformTXT = platformTXT.replace("\"-DUSB_PRODUCT={build.usb_product}\"",
212+
platformTXT = platformTXT.replace("\"-DUSB_PRODUCT={build.usb_product}\"",
219213
"\"-DUSB_PRODUCT=\\\"{build.usb_product}\\\"\"");
220-
platformTXT = platformTXT.replace(" -DARDUINO_BOARD=\"{build.board}\" ",
214+
platformTXT = platformTXT.replace(" -DARDUINO_BOARD=\"{build.board}\" ",
221215
" \"-DARDUINO_BOARD=\\\"{build.board}\\\"\" ");
222-
223216

224-
225217
}
226218
FileUtils.write(platformSloeberTXT, platformTXT, Charset.defaultCharset());
227219
} catch (IOException e) {

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,21 @@ public TxtFile(File boardsFileName, boolean workAround) {
6262

6363
this.mLastLoadedTxtFile =boardsFileName;
6464
File actuallyLoadedTxtFile = mLastLoadedTxtFile;
65+
// If the file doesn't exist ignore it.
66+
if (!boardsFileName.exists()) {
67+
return ;
68+
}
69+
6570
if(workAround) {
6671
actuallyLoadedTxtFile =WorkAround.MakeBoardsSloeberTxt(boardsFileName);
6772
}
68-
// If the file doesn't exist ignore it.
69-
if (!actuallyLoadedTxtFile.exists())
73+
74+
if (!actuallyLoadedTxtFile.exists()) {
75+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
76+
"Worked around file " +actuallyLoadedTxtFile.toString() + " does not exist.")); //$NON-NLS-1$ //$NON-NLS-2$
7077
return ;
78+
}
79+
7180

7281
this.fileContent.clear();
7382

io.sloeber.tests/src/io/sloeber/core/RegressionTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import io.sloeber.providers.ESP8266;
2828
import io.sloeber.providers.MCUBoard;
2929

30-
@SuppressWarnings("nls")
30+
@SuppressWarnings({"nls","static-method"})
3131
public class RegressionTest {
3232
private static final boolean reinstall_boards_and_libraries = false;
3333

@@ -64,14 +64,15 @@ public static void installAdditionalBoards() {
6464
* make sure when switching between a board with variant file and without
6565
* the build still succeeds
6666
*/
67-
@SuppressWarnings("static-method")
6867
@Test
6968
public void issue555() {
7069
if (MySystem.getTeensyPlatform().isEmpty()) {
7170
//skip test due to no teensy install folder provided
7271
//do not fail as this will always fail on travis
72+
System.out.println("skipping the test because teensy is not installed.");
7373
return;
7474
}
75+
System.out.println("Teensy is installed at "+MySystem.getTeensyPlatform());
7576
Map<String, String> unoOptions = new HashMap<>();
7677
BoardDescriptor unoBoardid = PackageManager.getBoardDescriptor("package_index.json", "arduino", "Arduino AVR Boards",
7778
"uno", unoOptions);
@@ -121,7 +122,6 @@ public void issue555() {
121122
* support void loop{};
122123
* @throws Exception
123124
*/
124-
@SuppressWarnings("static-method")
125125
@Test
126126
public void issue687() throws Exception {
127127
Arduino.installLatestAVRBoards();
@@ -155,7 +155,6 @@ public void issue687() throws Exception {
155155
* support void loop{};
156156
* @throws Exception
157157
*/
158-
@SuppressWarnings("static-method")
159158
@Test
160159
public void issue1047_Board_Names_Can_Be_used_as_Strings() throws Exception {
161160
MCUBoard unoBoard = ESP8266.nodeMCU();
@@ -189,7 +188,6 @@ public void issue1047_Board_Names_Can_Be_used_as_Strings() throws Exception {
189188
* code checks whether these defines are set properly
190189
* @throws Exception
191190
*/
192-
@SuppressWarnings("static-method")
193191
@Test
194192
public void are_jantjes_options_taken_into_account() throws Exception {
195193
Arduino.installLatestAVRBoards();
@@ -232,7 +230,6 @@ public void are_jantjes_options_taken_into_account() throws Exception {
232230
* properly by the ino to cpp parser
233231
* @throws Exception
234232
*/
235-
@SuppressWarnings("static-method")
236233
@Test
237234
public void are_defines_before_includes_taken_into_account() throws Exception {
238235
Arduino.installLatestAVRBoards();
@@ -269,7 +266,6 @@ public void are_defines_before_includes_taken_into_account() throws Exception {
269266
* be handled properly by the ino to cpp parser
270267
* @throws Exception
271268
*/
272-
@SuppressWarnings("static-method")
273269
@Test
274270
public void is_extern_C_taken_into_account() throws Exception {
275271
Arduino.installLatestAVRBoards();

0 commit comments

Comments
 (0)