1
1
package io .sloeber .core .api ;
2
2
3
3
import static io .sloeber .core .Messages .*;
4
+ import static io .sloeber .core .common .ConfigurationPreferences .*;
4
5
import static io .sloeber .core .common .Const .*;
5
6
import static java .nio .file .StandardCopyOption .*;
6
7
27
28
import java .util .TreeSet ;
28
29
29
30
import org .apache .commons .io .FileUtils ;
31
+ import org .eclipse .cdt .core .parser .util .StringUtil ;
30
32
import org .eclipse .core .runtime .IPath ;
31
33
import org .eclipse .core .runtime .IProgressMonitor ;
32
34
import org .eclipse .core .runtime .IStatus ;
59
61
*
60
62
*/
61
63
public class PackageManager {
64
+ private static String stringSplitter = "\n " ;//$NON-NLS-1$
65
+ private static final String KEY_MANAGER_JSON_URLS_V3 = "Arduino Manager board Urls" ; //$NON-NLS-1$
66
+ private static final String KEY_MANAGER_ARDUINO_LIBRARY_JSON_URL = "https://downloads.arduino.cc/libraries/library_index.json" ; //$NON-NLS-1$
67
+ private static final String KEY_MANAGER_JSON_URLS = "Manager jsons" ; //$NON-NLS-1$
68
+ private static final String DEFAULT_JSON_URLS = "https://downloads.arduino.cc/packages/package_index.json\n " //$NON-NLS-1$
69
+ + "https://raw.githubusercontent.com/jantje/hardware/master/package_jantje_index.json\n " //$NON-NLS-1$
70
+ + "https://raw.githubusercontent.com/jantje/ArduinoLibraries/master/library_jantje_index.json\n " //$NON-NLS-1$
71
+ + "https://arduino.esp8266.com/stable/package_esp8266com_index.json\n " //$NON-NLS-1$
72
+ + KEY_MANAGER_ARDUINO_LIBRARY_JSON_URL ;
62
73
63
74
64
75
protected static List <PackageIndex > packageIndices ;
@@ -120,10 +131,10 @@ static private BoardDescription getNewestBoardIDFromBoardsManager(String jsonFil
120
131
}
121
132
122
133
public static void addPackageURLs (HashSet <String > packageUrlsToAdd , boolean forceDownload ) {
123
- HashSet <String > originalJsonUrls = new HashSet <>(Arrays .asList (ConfigurationPreferences . getJsonURLList ()));
134
+ HashSet <String > originalJsonUrls = new HashSet <>(Arrays .asList (getJsonURLList ()));
124
135
packageUrlsToAdd .addAll (originalJsonUrls );
125
136
126
- ConfigurationPreferences . setJsonURLs (packageUrlsToAdd );
137
+ setJsonURLs (packageUrlsToAdd );
127
138
loadJsons (forceDownload );
128
139
}
129
140
@@ -132,7 +143,7 @@ public static void setPackageURLs(HashSet<String> packageUrls, boolean forceDown
132
143
Common .log (new Status (IStatus .ERROR , Const .CORE_PLUGIN_ID , BoardsManagerIsBussy , new Exception ()));
133
144
return ;
134
145
}
135
- ConfigurationPreferences . setJsonURLs (packageUrls );
146
+ setJsonURLs (packageUrls );
136
147
loadJsons (forceDownload );
137
148
}
138
149
@@ -641,7 +652,7 @@ protected static synchronized void loadJsons(boolean forceDownload) {
641
652
packageIndices = new ArrayList <>();
642
653
LibraryManager .flushIndices ();
643
654
644
- String [] jsonUrls = ConfigurationPreferences . getJsonURLList ();
655
+ String [] jsonUrls = getJsonURLList ();
645
656
for (String jsonUrl : jsonUrls ) {
646
657
if (!jsonUrl .trim ().isEmpty ()) // skip empty lines
647
658
loadJson (jsonUrl , forceDownload );
@@ -812,10 +823,50 @@ protected static void mySafeCopy(URL url, File localFile, boolean report_error)
812
823
}
813
824
}
814
825
815
- public static String [] getJsonURLList () {
816
- return ConfigurationPreferences .getJsonURLList ();
826
+ public static String getDefaultJsonURLs () {
827
+ return DEFAULT_JSON_URLS ;
828
+ }
829
+
830
+ public static String getJsonUrlsKey () {
831
+ return KEY_MANAGER_JSON_URLS ;
832
+ }
833
+
834
+ public static void setJsonURLs (String urls ) {
835
+ setString (KEY_MANAGER_JSON_URLS , urls );
836
+ }
837
+
838
+ private static void saveJsonURLs (String urls []) {
839
+ setString (KEY_MANAGER_JSON_URLS , StringUtil .join (urls , stringSplitter ));
840
+ }
841
+
842
+ public static void setJsonURLs (HashSet <String > urls ) {
843
+ setString (KEY_MANAGER_JSON_URLS , StringUtil .join (urls , stringSplitter ));
817
844
}
818
845
846
+ public static String [] getJsonURLList () {
847
+ return getJsonURLs ().replace ("\r " , new String ()).split (stringSplitter ); //$NON-NLS-1$
848
+ }
849
+
850
+ public static String getJsonURLs () {
851
+ // I added some code here to get easier from V3 to V4
852
+ // the library json url is now managed as the boards url's so it also
853
+ // needs to be added to the json url's
854
+ // this is doen in the default but people who have installed other
855
+ // boards or do not move to the default (which is by default)
856
+ // wil not see libraries
857
+ // to fix this I changed the storage name and if the new storage name is
858
+ // empty I read the ol one and add the lib
859
+ String ret = getString (KEY_MANAGER_JSON_URLS , DEFAULT_JSON_URLS );
860
+ if (DEFAULT_JSON_URLS .equals (ret )) {
861
+ ret = getString (KEY_MANAGER_JSON_URLS_V3 , DEFAULT_JSON_URLS );
862
+ if (!DEFAULT_JSON_URLS .equals (ret )) {
863
+ ret += System .lineSeparator () + KEY_MANAGER_ARDUINO_LIBRARY_JSON_URL ;
864
+ setString (KEY_MANAGER_JSON_URLS , ret );
865
+ removeKey (KEY_MANAGER_JSON_URLS_V3 );
866
+ }
867
+ }
868
+ return ret ;
869
+ }
819
870
/**
820
871
* Completely replace the list with jsons with a new list
821
872
*
@@ -844,7 +895,7 @@ public static void setJsonURLs(String[] newJsonUrls) {
844
895
}
845
896
}
846
897
// save to configurationsettings before calling LoadIndices
847
- ConfigurationPreferences . setJsonURLs (newJsonUrls );
898
+ saveJsonURLs (newJsonUrls );
848
899
// reload the indices (this will remove all potential remaining
849
900
// references
850
901
// existing files do not need to be refreshed as they have been
@@ -853,9 +904,7 @@ public static void setJsonURLs(String[] newJsonUrls) {
853
904
loadJsons (false );
854
905
}
855
906
856
- public static String getDefaultURLs () {
857
- return ConfigurationPreferences .getDefaultJsonURLs ();
858
- }
907
+
859
908
860
909
public static void removeAllInstalledPlatforms () {
861
910
if (!isReady ()) {
0 commit comments