1919import 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" )
3533public 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 */
@@ -70,107 +68,102 @@ static synchronized 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 */
8280 static synchronized public File MakeBoardsSloeberTxt (File requestedFileToWorkAround ) {
83- if (!requestedFileToWorkAround .exists ()) {
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- 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 )) {
9088 Common .log (new Status (IStatus .ERROR , Activator .getId (),
9189 "Boards.txt file is not recognized " + requestedFileToWorkAround .toString ()));
9290 return requestedFileToWorkAround ;
9391 }
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
9795 String firstLine = null ;
98- try (BufferedReader Buff = new BufferedReader (new FileReader (boardsSloeberTXT ));) {
96+ try (BufferedReader Buff = new BufferedReader (new FileReader (boardsSloeberTXT ));) {
9997 firstLine = Buff .readLine ();
10098 } 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 )) {
104102 boardsSloeberTXT .delete ();
105103 }
106104 }
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" );
127115 }
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 ;
128121 }
129122 }
130123 return boardsSloeberTXT ;
131124 }
132-
133-
125+
134126 /**
135127 * create a workedaround platform.txt and return that filz
136- *
128+ *
137129 * @param requestedFileToWorkAround
138130 *
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
140133 */
141134 public synchronized static File MakePlatformSloeberTXT (File requestedFileToWorkAround ) {
142- if (!requestedFileToWorkAround .exists ()) {
135+ if (!requestedFileToWorkAround .exists ()) {
143136 return requestedFileToWorkAround ;
144137 }
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 )) {
148141 Common .log (new Status (IStatus .ERROR , Activator .getId (),
149142 "platform.txt file is not recognized " + requestedFileToWorkAround .toString ()));
150143 return requestedFileToWorkAround ;
151144 }
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
155148 String firstLine = null ;
156- try (BufferedReader Buff = new BufferedReader (new FileReader (platformSloeberTXT ));) {
149+ try (BufferedReader Buff = new BufferedReader (new FileReader (platformSloeberTXT ));) {
157150 firstLine = Buff .readLine ();
158151 } 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 )) {
162155 platformSloeberTXT .delete ();
163156 }
164157 }
165158 if (!platformSloeberTXT .exists ()) {
166159 try {
167- String platformTXT = FIRST_SLOEBER_WORKAROUND_LINE + "\n " ;
160+ String platformTXT = FIRST_SLOEBER_WORKAROUND_LINE + "\n " ;
168161 platformTXT += FileUtils .readFileToString (requestedFileToWorkAround , Charset .defaultCharset ());
169162 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 ;
174167 if (inCombineStartIndex > 0 ) {
175168 int inCombineEndIndex = platformTXT .indexOf ("\n " , inCombineStartIndex ) - 1 ;
176169 if (inCombineEndIndex > 0 ) {
@@ -182,15 +175,14 @@ public synchronized static File MakePlatformSloeberTXT(File requestedFileToWorkA
182175 }
183176 }
184177
185-
186178 // workaround for infineon arm v1.4.0 overwriting the default to a wrong value
187179 platformTXT = platformTXT .replace ("\n build.core.path" , "\n #line removed by Sloeber build.core.path" );
188180
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 );
194186 if (Version .compare ("1.8.0" , platformVersion ) != 1 ) {
195187 if ("stm32" .equals (platformArchitecture )) {
196188 if ("STM32" .equals (platformName )) {
@@ -200,30 +192,29 @@ public synchronized static File MakePlatformSloeberTXT(File requestedFileToWorkA
200192 }
201193 }
202194
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+
207199 if (SystemUtils .IS_OS_WINDOWS ) {
208200 // replace FI '-DUSB_PRODUCT={build.usb_product}' with
209201 // "-DUSB_PRODUCT=\"{build.usb_product}\""
210202 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}\" " ,
219212 "\" -DUSB_MANUFACTURER=\\ \" {build.usb_manufacturer}\\ \" \" " );
220- platformTXT = platformTXT .replace ("\" -DUSB_PRODUCT={build.usb_product}\" " ,
213+ platformTXT = platformTXT .replace ("\" -DUSB_PRODUCT={build.usb_product}\" " ,
221214 "\" -DUSB_PRODUCT=\\ \" {build.usb_product}\\ \" \" " );
222- platformTXT = platformTXT .replace (" -DARDUINO_BOARD=\" {build.board}\" " ,
215+ platformTXT = platformTXT .replace (" -DARDUINO_BOARD=\" {build.board}\" " ,
223216 " \" -DARDUINO_BOARD=\\ \" {build.board}\\ \" \" " );
224-
225217
226-
227218 }
228219 FileUtils .write (platformSloeberTXT , platformTXT , Charset .defaultCharset ());
229220 } catch (IOException e ) {
0 commit comments