28
28
import java .nio .file .Paths ;
29
29
import java .util .ArrayList ;
30
30
import java .util .Arrays ;
31
+ import java .util .Collection ;
31
32
import java .util .HashMap ;
32
33
import java .util .HashSet ;
33
34
import java .util .List ;
44
45
import org .eclipse .core .runtime .IPath ;
45
46
import org .eclipse .core .runtime .IProgressMonitor ;
46
47
import org .eclipse .core .runtime .IStatus ;
48
+ import org .eclipse .core .runtime .NullProgressMonitor ;
47
49
import org .eclipse .core .runtime .Platform ;
48
50
import org .eclipse .core .runtime .Status ;
49
51
import org .eclipse .ui .statushandlers .StatusManager ;
@@ -70,8 +72,7 @@ private Manager() {
70
72
}
71
73
72
74
public static void addJsonURLs (HashSet <String > jsonUrlsToAdd , boolean forceDownload ) {
73
- HashSet <String > originalJsonUrls = new HashSet <>(
74
- Arrays .asList (ConfigurationPreferences .getJsonURLList ()));
75
+ HashSet <String > originalJsonUrls = new HashSet <>(Arrays .asList (ConfigurationPreferences .getJsonURLList ()));
75
76
jsonUrlsToAdd .addAll (originalJsonUrls );
76
77
77
78
ConfigurationPreferences .setJsonURLs (jsonUrlsToAdd );
@@ -179,7 +180,7 @@ static public IStatus downloadAndInstall(ArduinoPlatform platform, boolean force
179
180
static private void loadJsons (boolean forceDownload ) {
180
181
packageIndices = new ArrayList <>();
181
182
libraryIndices = new ArrayList <>();
182
-
183
+
183
184
String [] jsonUrls = ConfigurationPreferences .getJsonURLList ();
184
185
for (String jsonUrl : jsonUrls ) {
185
186
loadJson (jsonUrl , forceDownload );
@@ -240,29 +241,29 @@ static private void loadJson(String url, boolean forceDownload) {
240
241
}
241
242
}
242
243
}
243
-
244
+
244
245
static private void loadPackage (File jsonFile ) {
245
246
try (Reader reader = new FileReader (jsonFile )) {
246
247
PackageIndex index = new Gson ().fromJson (reader , PackageIndex .class );
247
248
index .setOwners (null );
248
249
index .setJsonFile (jsonFile );
249
250
packageIndices .add (index );
250
251
} catch (Exception e ) {
251
- Common .log (new Status ( IStatus . ERROR , Activator . getId (),
252
- "Unable to parse " + jsonFile .getAbsolutePath (), e )); //$NON-NLS-1$
252
+ Common .log (
253
+ new Status ( IStatus . ERROR , Activator . getId (), "Unable to parse " + jsonFile .getAbsolutePath (), e )); //$NON-NLS-1$
253
254
jsonFile .delete ();// Delete the file so it stops damaging
254
255
}
255
256
}
256
-
257
+
257
258
static private void loadLibrary (File jsonFile ) {
258
259
try (Reader reader = new FileReader (jsonFile )) {
259
260
LibraryIndex index = new Gson ().fromJson (reader , LibraryIndex .class );
260
261
index .resolve ();
261
262
index .setJsonFile (jsonFile );
262
263
libraryIndices .add (index );
263
264
} catch (Exception e ) {
264
- Common .log (new Status ( IStatus . ERROR , Activator . getId (),
265
- "Unable to parse " + jsonFile .getAbsolutePath (), e )); //$NON-NLS-1$
265
+ Common .log (
266
+ new Status ( IStatus . ERROR , Activator . getId (), "Unable to parse " + jsonFile .getAbsolutePath (), e )); //$NON-NLS-1$
266
267
jsonFile .delete ();// Delete the file so it stops damaging
267
268
}
268
269
}
@@ -820,8 +821,10 @@ public static void removePackageURLs(Set<String> packageUrlsToRemove) {
820
821
}
821
822
}
822
823
823
- // reload the indices (this will remove all potential remaining references
824
- // existing files do not need to be refreshed as they have been refreshed at startup
824
+ // reload the indices (this will remove all potential remaining
825
+ // references
826
+ // existing files do not need to be refreshed as they have been
827
+ // refreshed at startup
825
828
loadJsons (false );
826
829
827
830
}
@@ -851,8 +854,10 @@ public static void setJsonURL(String[] newJsonUrls) {
851
854
}
852
855
// save to configurationsettings before calling LoadIndices
853
856
ConfigurationPreferences .setJsonURLs (newJsonUrls );
854
- // reload the indices (this will remove all potential remaining references
855
- // existing files do not need to be refreshed as they have been refreshed at startup
857
+ // reload the indices (this will remove all potential remaining
858
+ // references
859
+ // existing files do not need to be refreshed as they have been
860
+ // refreshed at startup
856
861
// new files will be added
857
862
loadJsons (false );
858
863
}
@@ -867,7 +872,7 @@ public static void setReady(boolean b) {
867
872
*
868
873
* @param url
869
874
* @param localFile
870
- * @throws IOException
875
+ * @throws IOException
871
876
*/
872
877
@ SuppressWarnings ("nls" )
873
878
private static void myCopy (URL url , File localFile ) throws IOException {
@@ -885,14 +890,15 @@ private static void myCopy(URL url, File localFile) throws IOException {
885
890
Files .copy (url .openStream (), localFile .toPath (), REPLACE_EXISTING );
886
891
return ;
887
892
}
888
-
893
+
889
894
if (status == HttpURLConnection .HTTP_MOVED_TEMP || status == HttpURLConnection .HTTP_MOVED_PERM
890
895
|| status == HttpURLConnection .HTTP_SEE_OTHER ) {
891
896
Files .copy (new URL (conn .getHeaderField ("Location" )).openStream (), localFile .toPath (), REPLACE_EXISTING );
892
897
return ;
893
898
}
894
899
895
- Common .log (new Status (IStatus .WARNING , Activator .getId (), "Failed to download url " + url + " error code is: " + status , null ));
900
+ Common .log (new Status (IStatus .WARNING , Activator .getId (),
901
+ "Failed to download url " + url + " error code is: " + status , null ));
896
902
throw new IOException ("Failed to download url " + url + " error code is: " + status );
897
903
} catch (Exception e ) {
898
904
Common .log (new Status (IStatus .WARNING , Activator .getId (), "Failed to download url " + url , e ));
@@ -907,4 +913,16 @@ public static void onlyKeepLatestPlatforms() {
907
913
}
908
914
}
909
915
916
+ public static void installAllLatestLibraries (String category ) {
917
+ List <LibraryIndex > libraryIndices1 = getLibraryIndices ();
918
+ for (LibraryIndex libraryIndex : libraryIndices1 ) {
919
+ Collection <Library > libraries = libraryIndex .getLatestLibraries (category );
920
+ for (Library library : libraries ) {
921
+ if (!library .isInstalled ()) {
922
+ library .install (new NullProgressMonitor ());
923
+ }
924
+ }
925
+ }
926
+ }
927
+
910
928
}
0 commit comments