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
34
+ // Each time this class is touched consider changing the String below to enforce
35
+ // updates
37
36
private static final String FIRST_SLOEBER_WORKAROUND_LINE = "#Sloeber created workaound file V1.00.test 3" ;
38
37
39
-
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
*/
@@ -70,107 +68,102 @@ static synchronized 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
80
static synchronized public File MakeBoardsSloeberTxt (File requestedFileToWorkAround ) {
83
- if (!requestedFileToWorkAround .exists ()) {
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
- System .out .println ("converting " +inFile +" to " + actualFileToLoad );
89
- if (inFile .equals (actualFileToLoad )) {
84
+ String inFile = requestedFileToWorkAround .toString ();
85
+ String actualFileToLoad = inFile .replace (Const .BOARDS_FILE_NAME , "boards.sloeber.txt" );
86
+ System .out .println ("converting " + inFile + " to " + actualFileToLoad );
87
+ if (inFile .equals (actualFileToLoad )) {
90
88
Common .log (new Status (IStatus .ERROR , Activator .getId (),
91
89
"Boards.txt file is not recognized " + requestedFileToWorkAround .toString ()));
92
90
return requestedFileToWorkAround ;
93
91
}
94
- File boardsSloeberTXT = new File (actualFileToLoad );
95
- if (boardsSloeberTXT .exists ()) {
96
- //delete if outdated
92
+ File boardsSloeberTXT = new File (actualFileToLoad );
93
+ if (boardsSloeberTXT .exists ()) {
94
+ // delete if outdated
97
95
String firstLine = null ;
98
- try (BufferedReader Buff = new BufferedReader (new FileReader (boardsSloeberTXT ));) {
96
+ try (BufferedReader Buff = new BufferedReader (new FileReader (boardsSloeberTXT ));) {
99
97
firstLine = Buff .readLine ();
100
98
} catch (Exception e ) {
101
- //ignore and delete the file
102
- }
103
- if (!FIRST_SLOEBER_WORKAROUND_LINE .equals (firstLine )) {
99
+ // ignore and delete the file
100
+ }
101
+ if (!FIRST_SLOEBER_WORKAROUND_LINE .equals (firstLine )) {
104
102
boardsSloeberTXT .delete ();
105
103
}
106
104
}
107
- if (!boardsSloeberTXT .exists ()) {
108
- if (requestedFileToWorkAround .exists ()) {
109
- try {
110
- if (SystemUtils .IS_OS_WINDOWS ) {
111
- String boardsTXT = FIRST_SLOEBER_WORKAROUND_LINE +"\n " ;
112
- boardsTXT += FileUtils .readFileToString (requestedFileToWorkAround , Charset .defaultCharset ());
113
- boardsTXT = boardsTXT .replace ("\r \n " , "\n " );
114
-
115
-
116
- // replace FI circuitplay32u4cat.build.usb_manufacturer="Adafruit"
117
- // with circuitplay32u4cat.build.usb_manufacturer=Adafruit
118
- boardsTXT = boardsTXT .replaceAll ("(\\ S+\\ .build\\ .usb\\ S+)=\\ \" (.+)\\ \" " , "$1=$2" );
119
-
120
-
121
- FileUtils .write (boardsSloeberTXT , boardsTXT , Charset .defaultCharset ());
122
- }
123
- } catch (IOException e ) {
124
- Common .log (new Status (IStatus .WARNING , Activator .getId (),
125
- "Failed to apply work arounds to " + requestedFileToWorkAround .toString (), e ));
126
- return requestedFileToWorkAround ;
105
+ if (!boardsSloeberTXT .exists ()) {
106
+ try {
107
+ String boardsTXT = FIRST_SLOEBER_WORKAROUND_LINE + "\n " ;
108
+ boardsTXT += FileUtils .readFileToString (requestedFileToWorkAround , Charset .defaultCharset ());
109
+ boardsTXT = boardsTXT .replace ("\r \n " , "\n " );
110
+
111
+ if (SystemUtils .IS_OS_WINDOWS ) {
112
+ // replace FI circuitplay32u4cat.build.usb_manufacturer="Adafruit"
113
+ // with circuitplay32u4cat.build.usb_manufacturer=Adafruit
114
+ boardsTXT = boardsTXT .replaceAll ("(\\ S+\\ .build\\ .usb\\ S+)=\\ \" (.+)\\ \" " , "$1=$2" );
127
115
}
116
+ FileUtils .write (boardsSloeberTXT , boardsTXT , Charset .defaultCharset ());
117
+ } catch (IOException e ) {
118
+ Common .log (new Status (IStatus .WARNING , Activator .getId (),
119
+ "Failed to apply work arounds to " + requestedFileToWorkAround .toString (), e ));
120
+ return requestedFileToWorkAround ;
128
121
}
129
122
}
130
123
return boardsSloeberTXT ;
131
124
}
132
-
133
-
125
+
134
126
/**
135
127
* create a workedaround platform.txt and return that filz
136
- *
128
+ *
137
129
* @param requestedFileToWorkAround
138
130
*
139
- * @return the worked around file or requestedFileToWorkAround is it does not exist or error
131
+ * @return the worked around file or requestedFileToWorkAround is it does not
132
+ * exist or error
140
133
*/
141
134
public synchronized static File MakePlatformSloeberTXT (File requestedFileToWorkAround ) {
142
- if (!requestedFileToWorkAround .exists ()) {
135
+ if (!requestedFileToWorkAround .exists ()) {
143
136
return requestedFileToWorkAround ;
144
137
}
145
- String inFile = requestedFileToWorkAround .toString ();
146
- String actualFileToLoad = inFile .replace (Const .PLATFORM_FILE_NAME ,"platform.sloeber.txt" );
147
- if (inFile .equals (actualFileToLoad )) {
138
+ String inFile = requestedFileToWorkAround .toString ();
139
+ String actualFileToLoad = inFile .replace (Const .PLATFORM_FILE_NAME , "platform.sloeber.txt" );
140
+ if (inFile .equals (actualFileToLoad )) {
148
141
Common .log (new Status (IStatus .ERROR , Activator .getId (),
149
142
"platform.txt file is not recognized " + requestedFileToWorkAround .toString ()));
150
143
return requestedFileToWorkAround ;
151
144
}
152
- File platformSloeberTXT = new File (actualFileToLoad );
153
- if (platformSloeberTXT .exists ()) {
154
- //delete if outdated
145
+ File platformSloeberTXT = new File (actualFileToLoad );
146
+ if (platformSloeberTXT .exists ()) {
147
+ // delete if outdated
155
148
String firstLine = null ;
156
- try (BufferedReader Buff = new BufferedReader (new FileReader (platformSloeberTXT ));) {
149
+ try (BufferedReader Buff = new BufferedReader (new FileReader (platformSloeberTXT ));) {
157
150
firstLine = Buff .readLine ();
158
151
} catch (Exception e ) {
159
- //ignore and delete the file
160
- }
161
- if (!FIRST_SLOEBER_WORKAROUND_LINE .equals (firstLine )) {
152
+ // ignore and delete the file
153
+ }
154
+ if (!FIRST_SLOEBER_WORKAROUND_LINE .equals (firstLine )) {
162
155
platformSloeberTXT .delete ();
163
156
}
164
157
}
165
158
if (!platformSloeberTXT .exists ()) {
166
159
try {
167
- String platformTXT = FIRST_SLOEBER_WORKAROUND_LINE + "\n " ;
160
+ String platformTXT = FIRST_SLOEBER_WORKAROUND_LINE + "\n " ;
168
161
platformTXT += FileUtils .readFileToString (requestedFileToWorkAround , Charset .defaultCharset ());
169
162
platformTXT = platformTXT .replace ("\r \n " , "\n " );
170
-
171
- //Arduino treats core differently so we need to change the location of directly
172
- //referenced files this manifestates only in the combine recipe
173
- int inCombineStartIndex = platformTXT .indexOf ("\n recipe.c.combine.pattern" )+ 1 ;
163
+
164
+ // Arduino treats core differently so we need to change the location of directly
165
+ // referenced files this manifestates only in the combine recipe
166
+ int inCombineStartIndex = platformTXT .indexOf ("\n recipe.c.combine.pattern" ) + 1 ;
174
167
if (inCombineStartIndex > 0 ) {
175
168
int inCombineEndIndex = platformTXT .indexOf ("\n " , inCombineStartIndex ) - 1 ;
176
169
if (inCombineEndIndex > 0 ) {
@@ -182,15 +175,14 @@ public synchronized static File MakePlatformSloeberTXT(File requestedFileToWorkA
182
175
}
183
176
}
184
177
185
-
186
178
// workaround for infineon arm v1.4.0 overwriting the default to a wrong value
187
179
platformTXT = platformTXT .replace ("\n build.core.path" , "\n #line removed by Sloeber build.core.path" );
188
180
189
- Path platformTXTPath = new Path (requestedFileToWorkAround .toString ());
190
- int totalSegments = platformTXTPath .segmentCount ();
191
- String platformVersion = platformTXTPath .segment (totalSegments - 2 );
192
- String platformArchitecture = platformTXTPath .segment (totalSegments - 3 );
193
- String platformName = platformTXTPath .segment (totalSegments - 5 );
181
+ Path platformTXTPath = new Path (requestedFileToWorkAround .toString ());
182
+ int totalSegments = platformTXTPath .segmentCount ();
183
+ String platformVersion = platformTXTPath .segment (totalSegments - 2 );
184
+ String platformArchitecture = platformTXTPath .segment (totalSegments - 3 );
185
+ String platformName = platformTXTPath .segment (totalSegments - 5 );
194
186
if (Version .compare ("1.8.0" , platformVersion ) != 1 ) {
195
187
if ("stm32" .equals (platformArchitecture )) {
196
188
if ("STM32" .equals (platformName )) {
@@ -200,30 +192,29 @@ public synchronized static File MakePlatformSloeberTXT(File requestedFileToWorkA
200
192
}
201
193
}
202
194
203
-
204
- //for adafruit nfr
205
- platformTXT = platformTXT . replace ( "-DARDUINO_BSP_VERSION= \" {version} \" " , "\" -DARDUINO_BSP_VERSION=\\ \" {version}\\ \" \" " );
206
-
195
+ // for adafruit nfr
196
+ platformTXT = platformTXT . replace ( "-DARDUINO_BSP_VERSION= \" {version} \" " ,
197
+ "\" -DARDUINO_BSP_VERSION=\\ \" {version}\\ \" \" " );
198
+
207
199
if (SystemUtils .IS_OS_WINDOWS ) {
208
200
// replace FI '-DUSB_PRODUCT={build.usb_product}' with
209
201
// "-DUSB_PRODUCT=\"{build.usb_product}\""
210
202
platformTXT = platformTXT .replaceAll ("\\ '-D(\\ S+)=\\ {(\\ S+)}\\ '" , "\" -D$1=\\ \\ \" {$2}\\ \\ \" \" " );
211
-
212
-
213
- //quoting fixes for embedutils
214
- platformTXT = platformTXT .replaceAll ("\" ?(-DMBEDTLS_\\ S+)=\\ \\ ?\" (mbedtls\\ S+)\" \\ \\ ?\" *" , "\" $1=\\ \\ \" $2\\ \\ \" \" " );
215
-
216
- //Sometimes "-DUSB_MANUFACTURER={build.usb_manufacturer}" "-DUSB_PRODUCT={build.usb_product}"
217
- //is used fi LinKit smart
218
- platformTXT = platformTXT .replace ("\" -DUSB_MANUFACTURER={build.usb_manufacturer}\" " ,
203
+
204
+ // quoting fixes for embedutils
205
+ platformTXT = platformTXT .replaceAll ("\" ?(-DMBEDTLS_\\ S+)=\\ \\ ?\" (mbedtls\\ S+)\" \\ \\ ?\" *" ,
206
+ "\" $1=\\ \\ \" $2\\ \\ \" \" " );
207
+
208
+ // Sometimes "-DUSB_MANUFACTURER={build.usb_manufacturer}"
209
+ // "-DUSB_PRODUCT={build.usb_product}"
210
+ // is used fi LinKit smart
211
+ platformTXT = platformTXT .replace ("\" -DUSB_MANUFACTURER={build.usb_manufacturer}\" " ,
219
212
"\" -DUSB_MANUFACTURER=\\ \" {build.usb_manufacturer}\\ \" \" " );
220
- platformTXT = platformTXT .replace ("\" -DUSB_PRODUCT={build.usb_product}\" " ,
213
+ platformTXT = platformTXT .replace ("\" -DUSB_PRODUCT={build.usb_product}\" " ,
221
214
"\" -DUSB_PRODUCT=\\ \" {build.usb_product}\\ \" \" " );
222
- platformTXT = platformTXT .replace (" -DARDUINO_BOARD=\" {build.board}\" " ,
215
+ platformTXT = platformTXT .replace (" -DARDUINO_BOARD=\" {build.board}\" " ,
223
216
" \" -DARDUINO_BOARD=\\ \" {build.board}\\ \" \" " );
224
-
225
217
226
-
227
218
}
228
219
FileUtils .write (platformSloeberTXT , platformTXT , Charset .defaultCharset ());
229
220
} catch (IOException e ) {
0 commit comments