11
11
import java .io .Reader ;
12
12
import java .net .MalformedURLException ;
13
13
import java .net .URL ;
14
+ import java .nio .charset .Charset ;
15
+ import java .nio .charset .StandardCharsets ;
14
16
import java .nio .file .Files ;
15
17
import java .nio .file .Paths ;
16
18
import java .nio .file .StandardCopyOption ;
22
24
import java .util .HashSet ;
23
25
import java .util .List ;
24
26
import java .util .Map ;
25
- import java .util .Set ;
26
27
import java .util .TreeMap ;
27
28
import java .util .TreeSet ;
28
29
29
- import org .eclipse .cdt .core .parser .util .StringUtil ;
30
30
import org .eclipse .core .runtime .IPath ;
31
31
import org .eclipse .core .runtime .IProgressMonitor ;
32
32
import org .eclipse .core .runtime .IStatus ;
62
62
*
63
63
*/
64
64
public class BoardsManager {
65
- private static String stringSplitter = "\n " ;//$NON-NLS-1$
66
- private static final String KEY_MANAGER_JSON_URLS_V3 = "Arduino Manager board Urls" ; //$NON-NLS-1$
67
- private static final String KEY_MANAGER_ARDUINO_LIBRARY_JSON_URL = "https://downloads.arduino.cc/libraries/library_index.json" ; //$NON-NLS-1$
68
- private static final String KEY_MANAGER_JSON_URLS = "Manager jsons" ; //$NON-NLS-1$
69
- private static final String DEFAULT_JSON_URLS = "https://downloads.arduino.cc/packages/package_index.json\n " //$NON-NLS-1$
70
- + "https://raw.githubusercontent.com/jantje/hardware/master/package_jantje_index.json\n " //$NON-NLS-1$
71
- + "https://raw.githubusercontent.com/jantje/ArduinoLibraries/master/library_jantje_index.json\n " //$NON-NLS-1$
72
- + "https://arduino.esp8266.com/stable/package_esp8266com_index.json\n " //$NON-NLS-1$
73
- + "https://www.pjrc.com/teensy/package_teensy_index.json\n " //$NON-NLS-1$
74
- + KEY_MANAGER_ARDUINO_LIBRARY_JSON_URL ;
65
+ private static final String THIRD_PARTY_URL_FILE ="sloeber_third_party_url.txt" ; //$NON-NLS-1$
66
+ private static final String [] DEFAULT_JSON_URLS = {"https://downloads.arduino.cc/packages/package_index.json" , //$NON-NLS-1$
67
+ "https://raw.githubusercontent.com/jantje/hardware/master/package_jantje_index.json" , //$NON-NLS-1$
68
+ "https://raw.githubusercontent.com/jantje/ArduinoLibraries/master/library_jantje_index.json" , //$NON-NLS-1$
69
+ "https://arduino.esp8266.com/stable/package_esp8266com_index.json" , //$NON-NLS-1$
70
+ "https://www.pjrc.com/teensy/package_teensy_index.json" , //$NON-NLS-1$
71
+ "https://downloads.arduino.cc/libraries/library_index.json" };//$NON-NLS-1$
75
72
76
73
protected static List <ArduinoPlatformPackageIndex > packageIndices ;
77
74
private static boolean myHasbeenLogged = false ;
@@ -131,17 +128,21 @@ static private BoardDescription getNewestBoardIDFromBoardsManager(String jsonFil
131
128
return boardid ;
132
129
}
133
130
134
- public static void addPackageURLs (HashSet <String > packageUrlsToAdd , boolean forceDownload ) {
131
+ public static void addPackageURLs (Collection <String > packageUrlsToAdd , boolean forceDownload ) {
132
+ if (!isReady ()) {
133
+ Common .log (new Status (IStatus .ERROR , CORE_PLUGIN_ID , BoardsManagerIsBussy , new Exception ()));
134
+ return ;
135
+ }
135
136
HashSet <String > originalJsonUrls = new HashSet <>(Arrays .asList (getJsonURLList ()));
136
137
packageUrlsToAdd .addAll (originalJsonUrls );
137
138
138
139
setJsonURLs (packageUrlsToAdd );
139
140
loadJsons (forceDownload );
140
141
}
141
142
142
- public static void setPackageURLs (HashSet <String > packageUrls , boolean forceDownload ) {
143
+ public static void setPackageURLs (Collection <String > packageUrls , boolean forceDownload ) {
143
144
if (!isReady ()) {
144
- Common .log (new Status (IStatus .ERROR , Const . CORE_PLUGIN_ID , BoardsManagerIsBussy , new Exception ()));
145
+ Common .log (new Status (IStatus .ERROR , CORE_PLUGIN_ID , BoardsManagerIsBussy , new Exception ()));
145
146
return ;
146
147
}
147
148
setJsonURLs (packageUrls );
@@ -152,7 +153,7 @@ public static void setPackageURLs(HashSet<String> packageUrls, boolean forceDown
152
153
* installs a subset of the latest platforms It skips the first <fromIndex>
153
154
* platforms And stops at <toIndex> platforms. To install the 5 first latest
154
155
* platforms installsubsetOfLatestPlatforms(0,5)
155
- *
156
+ *
156
157
* @param fromIndex
157
158
* the platforms at the start to skip
158
159
* @param toIndex
@@ -161,7 +162,7 @@ public static void setPackageURLs(HashSet<String> packageUrls, boolean forceDown
161
162
public static void installsubsetOfLatestPlatforms (int fromIndex , int toIndex ) {
162
163
String DEPRECATED = "DEPRECATED" ; //$NON-NLS-1$
163
164
if (!isReady ()) {
164
- Common .log (new Status (IStatus .ERROR , Const . CORE_PLUGIN_ID , BoardsManagerIsBussy , new Exception ()));
165
+ Common .log (new Status (IStatus .ERROR , CORE_PLUGIN_ID , BoardsManagerIsBussy , new Exception ()));
165
166
return ;
166
167
}
167
168
envVarsNeedUpdating = true ;
@@ -199,7 +200,7 @@ public static void installAllLatestPlatforms() {
199
200
200
201
public static void installLatestPlatform (String JasonName , String packageName , String architectureName ) {
201
202
if (!isReady ()) {
202
- Common .log (new Status (IStatus .ERROR , Const . CORE_PLUGIN_ID , BoardsManagerIsBussy , new Exception ()));
203
+ Common .log (new Status (IStatus .ERROR , CORE_PLUGIN_ID , BoardsManagerIsBussy , new Exception ()));
203
204
return ;
204
205
}
205
206
envVarsNeedUpdating = true ;
@@ -215,7 +216,7 @@ public static void installLatestPlatform(String JasonName, String packageName, S
215
216
}
216
217
}
217
218
}
218
- Common .log (new Status (IStatus .ERROR , Const . CORE_PLUGIN_ID ,
219
+ Common .log (new Status (IStatus .ERROR , CORE_PLUGIN_ID ,
219
220
"failed to find " + JasonName + " " + packageName + " " + architectureName )); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
220
221
}
221
222
@@ -276,7 +277,7 @@ private static IStatus install(ArduinoPlatformVersion platformVersion, IProgress
276
277
277
278
WorkAround .applyKnownWorkArounds (platformVersion );
278
279
279
- System .out .println ("done installing platform " + platformVersion .toString ()); //$NON-NLS-1$
280
+ System .out .println ("done installing platform " + platformVersion .toString ()); //$NON-NLS-1$
280
281
return mstatus ;
281
282
}
282
283
@@ -308,10 +309,10 @@ public static File[] getAllBoardsFiles() {
308
309
309
310
TreeSet <File > boardFiles = new TreeSet <>();
310
311
for (String CurFolder : hardwareFolders ) {
311
- searchFiles (new File (CurFolder ), boardFiles , Const . BOARDS_FILE_NAME , 6 );
312
+ searchFiles (new File (CurFolder ), boardFiles , BOARDS_FILE_NAME , 6 );
312
313
}
313
314
if (boardFiles .size () == 0 ) {
314
- Common .log (new Status (IStatus .ERROR , Const . CORE_PLUGIN_ID ,
315
+ Common .log (new Status (IStatus .ERROR , CORE_PLUGIN_ID ,
315
316
Helpers_No_boards_txt_found .replace (FILE_TAG , String .join ("\n " , hardwareFolders )), null )); //$NON-NLS-1$
316
317
return null ;
317
318
}
@@ -323,15 +324,18 @@ private static void searchFiles(File folder, TreeSet<File> Hardwarelists, String
323
324
File [] a = folder .listFiles ();
324
325
if (a == null ) {
325
326
if (!myHasbeenLogged ) {
326
- Common .log (new Status (IStatus .INFO , Const . CORE_PLUGIN_ID ,
327
+ Common .log (new Status (IStatus .INFO , CORE_PLUGIN_ID ,
327
328
Helpers_Error_The_folder_is_empty .replace (FOLDER_TAG , folder .toString ()), null ));
328
329
myHasbeenLogged = true ;
329
330
}
330
331
return ;
331
332
}
332
333
for (File f : a ) {
333
334
if (f .isDirectory ()) {
334
- searchFiles (f , Hardwarelists , Filename , depth - 1 );
335
+ //ignore folders named tools
336
+ if (!f .getName ().equals (TOOLS )) {
337
+ searchFiles (f , Hardwarelists , Filename , depth - 1 );
338
+ }
335
339
} else if (f .getName ().equals (Filename )) {
336
340
Hardwarelists .add (f );
337
341
}
@@ -352,7 +356,7 @@ private static String[] getHardwarePaths() {
352
356
public static IStatus updatePlatforms (List <ArduinoPlatformVersion > platformsToInstall ,
353
357
List <ArduinoPlatformVersion > platformsToRemove , IProgressMonitor monitor , MultiStatus status ) {
354
358
if (!isReady ()) {
355
- status .add (new Status (IStatus .ERROR , Const . CORE_PLUGIN_ID , BoardsManagerIsBussy , null ));
359
+ status .add (new Status (IStatus .ERROR , CORE_PLUGIN_ID , BoardsManagerIsBussy , null ));
356
360
return status ;
357
361
}
358
362
//TODO updating the jsons after selecting what to install seems dangerous to me; check to delete
@@ -405,7 +409,7 @@ public static TreeMap<String, String> getAllmenus() {
405
409
406
410
public static void setPrivateHardwarePaths (String [] hardWarePaths ) {
407
411
if (!isReady ()) {
408
- Common .log (new Status (IStatus .ERROR , Const . CORE_PLUGIN_ID , BoardsManagerIsBussy , new Exception ()));
412
+ Common .log (new Status (IStatus .ERROR , CORE_PLUGIN_ID , BoardsManagerIsBussy , new Exception ()));
409
413
return ;
410
414
}
411
415
InstancePreferences .setPrivateHardwarePaths (hardWarePaths );
@@ -509,91 +513,55 @@ protected static File getLocalFileName(String url, boolean show_error) {
509
513
return packagePath .toFile ();
510
514
}
511
515
512
- public static String getDefaultJsonURLs () {
516
+ public static String [] getDefaultJsonURLs () {
513
517
return DEFAULT_JSON_URLS ;
514
518
}
515
519
516
- public static String getJsonUrlsKey () {
517
- return KEY_MANAGER_JSON_URLS ;
518
- }
519
-
520
- public static void setJsonURLs (String urls ) {
521
- setString (KEY_MANAGER_JSON_URLS , urls );
522
- }
523
520
524
- private static void saveJsonURLs (String urls []) {
525
- setString (KEY_MANAGER_JSON_URLS , StringUtil .join (urls , stringSplitter ));
526
- }
527
-
528
- public static void setJsonURLs (HashSet <String > urls ) {
529
- setString (KEY_MANAGER_JSON_URLS , StringUtil .join (urls , stringSplitter ));
521
+ private static void setJsonURLs (Collection <String > urls ) {
522
+ IPath myThirdPartyURLStoragePath =getThirdPartyURLStoragePath ();
523
+ try {
524
+ if (myThirdPartyURLStoragePath !=null ) {
525
+ Files .write (myThirdPartyURLStoragePath .toPath (),urls , Charset .forName (StandardCharsets .UTF_8 .name ()));
526
+ }
527
+ } catch (IOException e ) {
528
+ // TODO Auto-generated catch block
529
+ e .printStackTrace ();
530
+ }
530
531
}
531
532
532
533
public static String [] getJsonURLList () {
533
- return getJsonURLs ().replace ("\r " , new String ()).split (stringSplitter ); //$NON-NLS-1$
534
- }
535
-
536
- public static String getJsonURLs () {
537
- // I added some code here to get easier from V3 to V4
538
- // the library json url is now managed as the boards url's so it also
539
- // needs to be added to the json url's
540
- // this is doen in the default but people who have installed other
541
- // boards or do not move to the default (which is by default)
542
- // wil not see libraries
543
- // to fix this I changed the storage name and if the new storage name is
544
- // empty I read the ol one and add the lib
545
- String ret = getString (KEY_MANAGER_JSON_URLS , DEFAULT_JSON_URLS );
546
- if (DEFAULT_JSON_URLS .equals (ret )) {
547
- ret = getString (KEY_MANAGER_JSON_URLS_V3 , DEFAULT_JSON_URLS );
548
- if (!DEFAULT_JSON_URLS .equals (ret )) {
549
- ret += System .lineSeparator () + KEY_MANAGER_ARDUINO_LIBRARY_JSON_URL ;
550
- setString (KEY_MANAGER_JSON_URLS , ret );
551
- removeKey (KEY_MANAGER_JSON_URLS_V3 );
552
- }
553
- }
554
- return ret ;
534
+ IPath myThirdPartyURLStoragePath =getThirdPartyURLStoragePath ();
535
+ try {
536
+ if (myThirdPartyURLStoragePath !=null && myThirdPartyURLStoragePath .toFile ().exists ()) {
537
+ List <String >thirdPartyURLs = Files .readAllLines (myThirdPartyURLStoragePath .toPath (), Charset .forName (StandardCharsets .UTF_8 .name ()));
538
+ if (thirdPartyURLs .size ()>0 ) {
539
+ return thirdPartyURLs .toArray (new String [thirdPartyURLs .size ()]);
540
+ }
541
+ }
542
+ } catch (IOException e ) {
543
+ // TODO Auto-generated catch block
544
+ e .printStackTrace ();
545
+ }
546
+ //The new way of storing the thirdparty urls's failed
547
+ //try the Sloeber V3 way for downwards compatibility
548
+ String [] sloeberV4Storage = getString ("Manager jsons" , EMPTY_STRING ).replace ("\r " , new String ()).split ("\n " ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
549
+ if (sloeberV4Storage .length >3 ) {
550
+ return sloeberV4Storage ;
551
+ }
552
+ //Everything failed; This is probably a new install; return the defaults;
553
+ return DEFAULT_JSON_URLS ;
554
+
555
+ }
556
+
557
+ private static IPath getThirdPartyURLStoragePath () {
558
+ return sloeberHomePath .append (SLOEBER_HOME_SUB_FOLDER ).append (THIRD_PARTY_URL_FILE );
555
559
}
556
560
557
- /**
558
- * Completely replace the list with jsons with a new list
559
- *
560
- * @param newJsonUrls
561
- */
562
- public static void setJsonURLs (String [] newJsonUrls ) {
563
- if (!isReady ()) {
564
- Common .log (new Status (IStatus .ERROR , Const .CORE_PLUGIN_ID , BoardsManagerIsBussy , new Exception ()));
565
- return ;
566
- }
567
-
568
- String curJsons [] = getJsonURLList ();
569
- HashSet <String > origJsons = new HashSet <>(Arrays .asList (curJsons ));
570
- HashSet <String > currentSelectedJsons = new HashSet <>(Arrays .asList (newJsonUrls ));
571
- origJsons .removeAll (currentSelectedJsons );
572
- // remove the files from disk which were in the old lst but not in the
573
- // new one
574
- for (String curJson : origJsons ) {
575
- try {
576
- File localFile = getLocalFileName (curJson , false );
577
- if (localFile .exists ()) {
578
- localFile .delete ();
579
- }
580
- } catch (@ SuppressWarnings ("unused" ) Exception e ) {
581
- // ignore
582
- }
583
- }
584
- // save to configurationsettings before calling LoadIndices
585
- saveJsonURLs (newJsonUrls );
586
- // reload the indices (this will remove all potential remaining
587
- // references
588
- // existing files do not need to be refreshed as they have been
589
- // refreshed at startup
590
- // new files will be added
591
- loadJsons (false );
592
- }
593
561
594
562
public static void removeAllInstalledPlatforms () {
595
563
if (!isReady ()) {
596
- Common .log (new Status (IStatus .ERROR , Const . CORE_PLUGIN_ID , BoardsManagerIsBussy , new Exception ()));
564
+ Common .log (new Status (IStatus .ERROR , CORE_PLUGIN_ID , BoardsManagerIsBussy , new Exception ()));
597
565
return ;
598
566
}
599
567
try {
@@ -617,9 +585,9 @@ public static Map<String, String> getEnvironmentVariables() {
617
585
return myWorkbenchEnvironmentVariables ;
618
586
}
619
587
myWorkbenchEnvironmentVariables .clear ();
620
- ArduinoPlatformVersion latestAvrPlatform = getNewestInstalledPlatform (Const . VENDOR_ARDUINO , Const . AVR );
621
- ArduinoPlatformVersion latestSamdPlatform = getNewestInstalledPlatform (Const . VENDOR_ARDUINO , Const . SAMD );
622
- ArduinoPlatformVersion latestSamPlatform = getNewestInstalledPlatform (Const . VENDOR_ARDUINO , Const . SAM );
588
+ ArduinoPlatformVersion latestAvrPlatform = getNewestInstalledPlatform (VENDOR_ARDUINO , AVR );
589
+ ArduinoPlatformVersion latestSamdPlatform = getNewestInstalledPlatform (VENDOR_ARDUINO , SAMD );
590
+ ArduinoPlatformVersion latestSamPlatform = getNewestInstalledPlatform (VENDOR_ARDUINO , SAM );
623
591
624
592
if (latestSamdPlatform != null ) {
625
593
myWorkbenchEnvironmentVariables .putAll (getEnvVarPlatformFileTools (latestSamdPlatform ));
@@ -651,7 +619,7 @@ private static Map<String, String> getEnvVarPlatformFileTools(ArduinoPlatformVer
651
619
/**
652
620
* given a vendor and a architecture provide the newest installed platform
653
621
* version
654
- *
622
+ *
655
623
* @param vendor
656
624
* @param architecture
657
625
* @return the found platformVersion or null if none found
@@ -827,48 +795,13 @@ static public ArduinoPackage getPackage(String packageName) {
827
795
return null ;
828
796
}
829
797
830
- /**
831
- * This method removes the json files from disk and removes memory references to
832
- * these files or their content
833
- *
834
- * @param packageUrlsToRemove
835
- */
836
- public static void removePackageURLs (Set <String > packageUrlsToRemove ) {
837
- if (!isReady ()) {
838
- Common .log (new Status (IStatus .ERROR , Const .CORE_PLUGIN_ID , BoardsManagerIsBussy , new Exception ()));
839
- return ;
840
- }
841
- // remove the files from memory
842
- Set <String > activeUrls = new HashSet <>(Arrays .asList (getJsonURLList ()));
843
-
844
- activeUrls .removeAll (packageUrlsToRemove );
845
-
846
- setJsonURLs (activeUrls .toArray ((String []) null ));
847
-
848
- // remove the files from disk
849
- for (String curJson : packageUrlsToRemove ) {
850
- File localFile = getLocalFileName (curJson , true );
851
- if (localFile != null ) {
852
- if (localFile .exists ()) {
853
- localFile .delete ();
854
- }
855
- }
856
- }
857
-
858
- // reload the indices (this will remove all potential remaining
859
- // references
860
- // existing files do not need to be refreshed as they have been
861
- // refreshed at startup
862
- loadJsons (false );
863
-
864
- }
865
798
866
799
/**
867
800
* Remove all packages that have a more recent version
868
801
*/
869
802
public static void onlyKeepLatestPlatforms () {
870
803
if (!isReady ()) {
871
- Common .log (new Status (IStatus .ERROR , Const . CORE_PLUGIN_ID , BoardsManagerIsBussy , new Exception ()));
804
+ Common .log (new Status (IStatus .ERROR , CORE_PLUGIN_ID , BoardsManagerIsBussy , new Exception ()));
872
805
return ;
873
806
}
874
807
List <ArduinoPackage > allPackages = getPackages ();
0 commit comments