1919import java .io .FileReader ;
2020import java .io .IOException ;
2121import java .io .InputStream ;
22- import java .io .InputStreamReader ;
2322import java .io .Reader ;
2423import java .net .HttpURLConnection ;
2524import java .net .MalformedURLException ;
2625import java .net .URL ;
27- import java .nio .charset .Charset ;
2826import java .nio .file .Files ;
2927import java .nio .file .Path ;
3028import java .nio .file .Paths ;
3129import java .util .ArrayList ;
3230import java .util .Arrays ;
31+ import java .util .Collection ;
3332import java .util .HashMap ;
3433import java .util .HashSet ;
3534import java .util .List ;
3635import java .util .Map ;
3736import java .util .Set ;
3837
39- import javax .net .ssl .HttpsURLConnection ;
40-
4138import org .apache .commons .compress .archivers .ArchiveEntry ;
4239import org .apache .commons .compress .archivers .ArchiveInputStream ;
4340import org .apache .commons .compress .archivers .tar .TarArchiveEntry ;
4845import org .eclipse .core .runtime .IPath ;
4946import org .eclipse .core .runtime .IProgressMonitor ;
5047import org .eclipse .core .runtime .IStatus ;
48+ import org .eclipse .core .runtime .NullProgressMonitor ;
5149import org .eclipse .core .runtime .Platform ;
5250import org .eclipse .core .runtime .Status ;
5351import org .eclipse .ui .statushandlers .StatusManager ;
@@ -74,8 +72,7 @@ private Manager() {
7472 }
7573
7674 public static void addJsonURLs (HashSet <String > jsonUrlsToAdd , boolean forceDownload ) {
77- HashSet <String > originalJsonUrls = new HashSet <>(
78- Arrays .asList (ConfigurationPreferences .getJsonURLList ()));
75+ HashSet <String > originalJsonUrls = new HashSet <>(Arrays .asList (ConfigurationPreferences .getJsonURLList ()));
7976 jsonUrlsToAdd .addAll (originalJsonUrls );
8077
8178 ConfigurationPreferences .setJsonURLs (jsonUrlsToAdd );
@@ -93,7 +90,7 @@ public static void startup_Pluging(IProgressMonitor monitor) {
9390 loadJsons (ConfigurationPreferences .getUpdateJasonFilesFlag ());
9491 List <Board > allBoards = getInstalledBoards ();
9592 if (allBoards .isEmpty ()) { // If boards are installed do nothing
96- // InstallDefaultLibraries(monitor);
93+ // InstallDefaultLibraries(monitor);
9794 MyMultiStatus mstatus = new MyMultiStatus ("Failed to configer Sloeber" ); //$NON-NLS-1$
9895
9996 // Downnload sample programs
@@ -126,16 +123,14 @@ public static void startup_Pluging(IProgressMonitor monitor) {
126123
127124 }
128125
129- /* private static void InstallDefaultLibraries(IProgressMonitor monitor) {
130- LibraryIndex libindex = getLibraryIndex();
131-
132- for (String library : Defaults.INSTALLED_LIBRARIES) {
133- Library toInstalLib = libindex.getLatestLibrary(library);
134- if (toInstalLib != null) {
135- toInstalLib.install(monitor);
136- }
137- }
138- }*/
126+ /*
127+ * private static void InstallDefaultLibraries(IProgressMonitor monitor) {
128+ * LibraryIndex libindex = getLibraryIndex();
129+ *
130+ * for (String library : Defaults.INSTALLED_LIBRARIES) { Library toInstalLib
131+ * = libindex.getLatestLibrary(library); if (toInstalLib != null) {
132+ * toInstalLib.install(monitor); } } }
133+ */
139134
140135 /**
141136 * Given a platform description in a json file download and install all
@@ -181,7 +176,7 @@ static public IStatus downloadAndInstall(ArduinoPlatform platform, boolean force
181176 static private void loadJsons (boolean forceDownload ) {
182177 packageIndices = new ArrayList <>();
183178 libraryIndices = new ArrayList <>();
184-
179+
185180 String [] jsonUrls = ConfigurationPreferences .getJsonURLList ();
186181 for (String jsonUrl : jsonUrls ) {
187182 loadJson (jsonUrl , forceDownload );
@@ -235,37 +230,37 @@ static private void loadJson(String url, boolean forceDownload) {
235230 }
236231 }
237232 if (jsonFile .exists ()) {
238- if (jsonFile .getName ().startsWith ("package_" )) {
233+ if (jsonFile .getName ().startsWith ("package_" )) { //$NON-NLS-1$
239234 loadPackage (jsonFile );
240- } else if (jsonFile .getName ().startsWith ("library_" )) {
235+ } else if (jsonFile .getName ().startsWith ("library_" )) { //$NON-NLS-1$
241236 loadLibrary (jsonFile );
242237 }
243238 }
244239 }
245-
240+
246241 static private void loadPackage (File jsonFile ) {
247242 try (Reader reader = new FileReader (jsonFile )) {
248243 PackageIndex index = new Gson ().fromJson (reader , PackageIndex .class );
249244 index .setOwners (null );
250245 index .setJsonFile (jsonFile );
251246 packageIndices .add (index );
252247 } catch (Exception e ) {
253- Common .log (new Status ( IStatus . ERROR , Activator . getId (),
254- "Unable to parse " + jsonFile .getAbsolutePath (), e )); //$NON-NLS-1$
248+ Common .log (
249+ new Status ( IStatus . ERROR , Activator . getId (), "Unable to parse " + jsonFile .getAbsolutePath (), e )); //$NON-NLS-1$
255250 jsonFile .delete ();// Delete the file so it stops damaging
256251 }
257252 }
258-
253+
259254 static private void loadLibrary (File jsonFile ) {
260255 try (Reader reader = new FileReader (jsonFile )) {
261256 LibraryIndex index = new Gson ().fromJson (reader , LibraryIndex .class );
262257 index .resolve ();
263- // index.setOwners(null);
258+ // index.setOwners(null);
264259 index .setJsonFile (jsonFile );
265260 libraryIndices .add (index );
266261 } catch (Exception e ) {
267- Common .log (new Status ( IStatus . ERROR , Activator . getId (),
268- "Unable to parse " + jsonFile .getAbsolutePath (), e )); //$NON-NLS-1$
262+ Common .log (
263+ new Status ( IStatus . ERROR , Activator . getId (), "Unable to parse " + jsonFile .getAbsolutePath (), e )); //$NON-NLS-1$
269264 jsonFile .delete ();// Delete the file so it stops damaging
270265 }
271266 }
@@ -814,8 +809,10 @@ public static void removePackageURLs(Set<String> packageUrlsToRemove) {
814809 }
815810 }
816811
817- // reload the indices (this will remove all potential remaining references
818- // existing files do not need to be refreshed as they have been refreshed at startup
812+ // reload the indices (this will remove all potential remaining
813+ // references
814+ // existing files do not need to be refreshed as they have been
815+ // refreshed at startup
819816 loadJsons (false );
820817
821818 }
@@ -845,8 +842,10 @@ public static void setJsonURL(String[] newJsonUrls) {
845842 }
846843 // save to configurationsettings before calling LoadIndices
847844 ConfigurationPreferences .setJsonURLs (newJsonUrls );
848- // reload the indices (this will remove all potential remaining references
849- // existing files do not need to be refreshed as they have been refreshed at startup
845+ // reload the indices (this will remove all potential remaining
846+ // references
847+ // existing files do not need to be refreshed as they have been
848+ // refreshed at startup
850849 // new files will be added
851850 loadJsons (false );
852851 }
@@ -861,7 +860,7 @@ public static void setReady(boolean b) {
861860 *
862861 * @param url
863862 * @param localFile
864- * @throws IOException
863+ * @throws IOException
865864 */
866865 @ SuppressWarnings ("nls" )
867866 private static void myCopy (URL url , File localFile ) throws IOException {
@@ -879,14 +878,15 @@ private static void myCopy(URL url, File localFile) throws IOException {
879878 Files .copy (url .openStream (), localFile .toPath (), REPLACE_EXISTING );
880879 return ;
881880 }
882-
881+
883882 if (status == HttpURLConnection .HTTP_MOVED_TEMP || status == HttpURLConnection .HTTP_MOVED_PERM
884883 || status == HttpURLConnection .HTTP_SEE_OTHER ) {
885884 Files .copy (new URL (conn .getHeaderField ("Location" )).openStream (), localFile .toPath (), REPLACE_EXISTING );
886885 return ;
887886 }
888887
889- Common .log (new Status (IStatus .WARNING , Activator .getId (), "Failed to download url " + url + " error code is: " + status , null ));
888+ Common .log (new Status (IStatus .WARNING , Activator .getId (),
889+ "Failed to download url " + url + " error code is: " + status , null ));
890890 throw new IOException ("Failed to download url " + url + " error code is: " + status );
891891 } catch (Exception e ) {
892892 Common .log (new Status (IStatus .WARNING , Activator .getId (), "Failed to download url " + url , e ));
@@ -901,4 +901,16 @@ public static void onlyKeepLatestPlatforms() {
901901 }
902902 }
903903
904+ public static void installAllLatestLibraries (String category ) {
905+ List <LibraryIndex > libraryIndices1 = getLibraryIndices ();
906+ for (LibraryIndex libraryIndex : libraryIndices1 ) {
907+ Collection <Library > libraries = libraryIndex .getLatestLibraries (category );
908+ for (Library library : libraries ) {
909+ if (!library .isInstalled ()) {
910+ library .install (new NullProgressMonitor ());
911+ }
912+ }
913+ }
914+ }
915+
904916}
0 commit comments