19
19
import io .sloeber .core .tools .Version ;
20
20
21
21
/**
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
26
24
*
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
30
28
*
31
29
* @author jan
32
30
*
33
31
*/
34
32
@ SuppressWarnings ("nls" )
35
33
public class WorkAround {
36
- //Each time this class is touched consider changing the String below to enforce updates
37
- private static final String FIRST_SLOEBER_WORKAROUND_LINE = "#Sloeber created workaound file V1.00.test 3" ;
38
-
34
+ // Each time this class is touched consider changing the String below to enforce
35
+ // updates
36
+ private static final String FIRST_SLOEBER_WORKAROUND_LINE = "#Sloeber created workaound file V1.00.test 4" ;
39
37
40
38
/**
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
44
42
*
45
43
* @param platform
46
44
*/
47
- static public void applyKnownWorkArounds (ArduinoPlatform platform ) {
45
+ static synchronized public void applyKnownWorkArounds (ArduinoPlatform platform ) {
48
46
49
47
/*
50
48
* for STM32 V1.8 and later #include "SrcWrapper.h" to Arduino.h remove the
@@ -70,105 +68,101 @@ static public void applyKnownWorkArounds(ArduinoPlatform platform) {
70
68
MakeBoardsSloeberTxt (platform .getBoardsFile ());
71
69
72
70
}
73
-
74
-
71
+
75
72
/**
76
73
* create a workedaround boards.txt and return that filz
77
- *
74
+ *
78
75
* @param requestedFileToWorkAround
79
76
*
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
81
79
*/
82
- static public File MakeBoardsSloeberTxt (File requestedFileToWorkAround ) {
83
- if (!requestedFileToWorkAround .exists ()) {
80
+ static synchronized public File MakeBoardsSloeberTxt (File requestedFileToWorkAround ) {
81
+ if (!requestedFileToWorkAround .exists ()) {
84
82
return requestedFileToWorkAround ;
85
83
}
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 )) {
89
87
Common .log (new Status (IStatus .ERROR , Activator .getId (),
90
88
"Boards.txt file is not recognized " + requestedFileToWorkAround .toString ()));
91
89
return requestedFileToWorkAround ;
92
90
}
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
96
94
String firstLine = null ;
97
- try (BufferedReader Buff = new BufferedReader (new FileReader (boardsSloeberTXT ));) {
95
+ try (BufferedReader Buff = new BufferedReader (new FileReader (boardsSloeberTXT ));) {
98
96
firstLine = Buff .readLine ();
99
97
} 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 )) {
103
101
boardsSloeberTXT .delete ();
104
102
}
105
103
}
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" );
125
114
}
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 ;
126
120
}
127
121
}
128
122
return boardsSloeberTXT ;
129
123
}
130
-
131
-
124
+
132
125
/**
133
126
* create a workedaround platform.txt and return that filz
134
- *
127
+ *
135
128
* @param requestedFileToWorkAround
136
129
*
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
138
132
*/
139
- public static File MakePlatformSloeberTXT (File requestedFileToWorkAround ) {
140
- if (!requestedFileToWorkAround .exists ()) {
133
+ public synchronized static File MakePlatformSloeberTXT (File requestedFileToWorkAround ) {
134
+ if (!requestedFileToWorkAround .exists ()) {
141
135
return requestedFileToWorkAround ;
142
136
}
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 )) {
146
140
Common .log (new Status (IStatus .ERROR , Activator .getId (),
147
141
"platform.txt file is not recognized " + requestedFileToWorkAround .toString ()));
148
142
return requestedFileToWorkAround ;
149
143
}
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
153
147
String firstLine = null ;
154
- try (BufferedReader Buff = new BufferedReader (new FileReader (platformSloeberTXT ));) {
148
+ try (BufferedReader Buff = new BufferedReader (new FileReader (platformSloeberTXT ));) {
155
149
firstLine = Buff .readLine ();
156
150
} 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 )) {
160
154
platformSloeberTXT .delete ();
161
155
}
162
156
}
163
157
if (!platformSloeberTXT .exists ()) {
164
158
try {
165
- String platformTXT = FIRST_SLOEBER_WORKAROUND_LINE + "\n " ;
159
+ String platformTXT = FIRST_SLOEBER_WORKAROUND_LINE + "\n " ;
166
160
platformTXT += FileUtils .readFileToString (requestedFileToWorkAround , Charset .defaultCharset ());
167
161
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 ("\n recipe.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 ("\n recipe.c.combine.pattern" ) + 1 ;
172
166
if (inCombineStartIndex > 0 ) {
173
167
int inCombineEndIndex = platformTXT .indexOf ("\n " , inCombineStartIndex ) - 1 ;
174
168
if (inCombineEndIndex > 0 ) {
@@ -180,15 +174,14 @@ public static File MakePlatformSloeberTXT(File requestedFileToWorkAround) {
180
174
}
181
175
}
182
176
183
-
184
177
// workaround for infineon arm v1.4.0 overwriting the default to a wrong value
185
178
platformTXT = platformTXT .replace ("\n build.core.path" , "\n #line removed by Sloeber build.core.path" );
186
179
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 );
192
185
if (Version .compare ("1.8.0" , platformVersion ) != 1 ) {
193
186
if ("stm32" .equals (platformArchitecture )) {
194
187
if ("STM32" .equals (platformName )) {
@@ -198,30 +191,37 @@ public static File MakePlatformSloeberTXT(File requestedFileToWorkAround) {
198
191
}
199
192
}
200
193
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
+
205
198
if (SystemUtils .IS_OS_WINDOWS ) {
206
199
// replace FI '-DUSB_PRODUCT={build.usb_product}' with
207
200
// "-DUSB_PRODUCT=\"{build.usb_product}\""
208
201
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}\" " ,
217
211
"\" -DUSB_MANUFACTURER=\\ \" {build.usb_manufacturer}\\ \" \" " );
218
- platformTXT = platformTXT .replace ("\" -DUSB_PRODUCT={build.usb_product}\" " ,
212
+ platformTXT = platformTXT .replace ("\" -DUSB_PRODUCT={build.usb_product}\" " ,
219
213
"\" -DUSB_PRODUCT=\\ \" {build.usb_product}\\ \" \" " );
220
- platformTXT = platformTXT .replace (" -DARDUINO_BOARD=\" {build.board}\" " ,
214
+ platformTXT = platformTXT .replace (" -DARDUINO_BOARD=\" {build.board}\" " ,
221
215
" \" -DARDUINO_BOARD=\\ \" {build.board}\\ \" \" " );
222
-
223
216
224
-
217
+ }
218
+ if (SystemUtils .IS_OS_LINUX ) {
219
+ platformTXT = platformTXT .replace (" -DUSB_MANUFACTURER={build.usb_manufacturer} " ,
220
+ " '-DUSB_MANUFACTURER=\" {build.usb_manufacturer}\" ' " );
221
+ platformTXT = platformTXT .replace (" -DUSB_PRODUCT={build.usb_product} " ,
222
+ " '-DUSB_PRODUCT=\" {build.usb_product}\" '" );
223
+ platformTXT = platformTXT .replace (" -DARDUINO_BOARD=\" {build.board}\" " ,
224
+ " '-DARDUINO_BOARD=\" {build.board}\" ' " );
225
225
}
226
226
FileUtils .write (platformSloeberTXT , platformTXT , Charset .defaultCharset ());
227
227
} catch (IOException e ) {
0 commit comments