2828import java .nio .file .Paths ;
2929import java .util .ArrayList ;
3030import java .util .Arrays ;
31+ import java .util .Collection ;
3132import java .util .HashMap ;
3233import java .util .HashSet ;
3334import java .util .List ;
4445import org .eclipse .core .runtime .IPath ;
4546import org .eclipse .core .runtime .IProgressMonitor ;
4647import org .eclipse .core .runtime .IStatus ;
48+ import org .eclipse .core .runtime .NullProgressMonitor ;
4749import org .eclipse .core .runtime .Platform ;
4850import org .eclipse .core .runtime .Status ;
4951import org .eclipse .ui .statushandlers .StatusManager ;
@@ -70,8 +72,7 @@ private Manager() {
7072 }
7173
7274 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 ()));
7576 jsonUrlsToAdd .addAll (originalJsonUrls );
7677
7778 ConfigurationPreferences .setJsonURLs (jsonUrlsToAdd );
@@ -179,7 +180,7 @@ static public IStatus downloadAndInstall(ArduinoPlatform platform, boolean force
179180 static private void loadJsons (boolean forceDownload ) {
180181 packageIndices = new ArrayList <>();
181182 libraryIndices = new ArrayList <>();
182-
183+
183184 String [] jsonUrls = ConfigurationPreferences .getJsonURLList ();
184185 for (String jsonUrl : jsonUrls ) {
185186 loadJson (jsonUrl , forceDownload );
@@ -240,29 +241,29 @@ static private void loadJson(String url, boolean forceDownload) {
240241 }
241242 }
242243 }
243-
244+
244245 static private void loadPackage (File jsonFile ) {
245246 try (Reader reader = new FileReader (jsonFile )) {
246247 PackageIndex index = new Gson ().fromJson (reader , PackageIndex .class );
247248 index .setOwners (null );
248249 index .setJsonFile (jsonFile );
249250 packageIndices .add (index );
250251 } 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$
253254 jsonFile .delete ();// Delete the file so it stops damaging
254255 }
255256 }
256-
257+
257258 static private void loadLibrary (File jsonFile ) {
258259 try (Reader reader = new FileReader (jsonFile )) {
259260 LibraryIndex index = new Gson ().fromJson (reader , LibraryIndex .class );
260261 index .resolve ();
261262 index .setJsonFile (jsonFile );
262263 libraryIndices .add (index );
263264 } 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$
266267 jsonFile .delete ();// Delete the file so it stops damaging
267268 }
268269 }
@@ -820,8 +821,10 @@ public static void removePackageURLs(Set<String> packageUrlsToRemove) {
820821 }
821822 }
822823
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
825828 loadJsons (false );
826829
827830 }
@@ -851,8 +854,10 @@ public static void setJsonURL(String[] newJsonUrls) {
851854 }
852855 // save to configurationsettings before calling LoadIndices
853856 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
856861 // new files will be added
857862 loadJsons (false );
858863 }
@@ -867,7 +872,7 @@ public static void setReady(boolean b) {
867872 *
868873 * @param url
869874 * @param localFile
870- * @throws IOException
875+ * @throws IOException
871876 */
872877 @ SuppressWarnings ("nls" )
873878 private static void myCopy (URL url , File localFile ) throws IOException {
@@ -885,14 +890,15 @@ private static void myCopy(URL url, File localFile) throws IOException {
885890 Files .copy (url .openStream (), localFile .toPath (), REPLACE_EXISTING );
886891 return ;
887892 }
888-
893+
889894 if (status == HttpURLConnection .HTTP_MOVED_TEMP || status == HttpURLConnection .HTTP_MOVED_PERM
890895 || status == HttpURLConnection .HTTP_SEE_OTHER ) {
891896 Files .copy (new URL (conn .getHeaderField ("Location" )).openStream (), localFile .toPath (), REPLACE_EXISTING );
892897 return ;
893898 }
894899
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 ));
896902 throw new IOException ("Failed to download url " + url + " error code is: " + status );
897903 } catch (Exception e ) {
898904 Common .log (new Status (IStatus .WARNING , Activator .getId (), "Failed to download url " + url , e ));
@@ -907,4 +913,16 @@ public static void onlyKeepLatestPlatforms() {
907913 }
908914 }
909915
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+
910928}
0 commit comments