19
19
import java .io .FileReader ;
20
20
import java .io .IOException ;
21
21
import java .io .InputStream ;
22
- import java .io .InputStreamReader ;
23
22
import java .io .Reader ;
24
23
import java .net .HttpURLConnection ;
25
24
import java .net .MalformedURLException ;
26
25
import java .net .URL ;
27
- import java .nio .charset .Charset ;
28
26
import java .nio .file .Files ;
29
27
import java .nio .file .Path ;
30
28
import java .nio .file .Paths ;
31
29
import java .util .ArrayList ;
32
30
import java .util .Arrays ;
31
+ import java .util .Collection ;
33
32
import java .util .HashMap ;
34
33
import java .util .HashSet ;
35
34
import java .util .List ;
36
35
import java .util .Map ;
37
36
import java .util .Set ;
38
37
39
- import javax .net .ssl .HttpsURLConnection ;
40
-
41
38
import org .apache .commons .compress .archivers .ArchiveEntry ;
42
39
import org .apache .commons .compress .archivers .ArchiveInputStream ;
43
40
import org .apache .commons .compress .archivers .tar .TarArchiveEntry ;
48
45
import org .eclipse .core .runtime .IPath ;
49
46
import org .eclipse .core .runtime .IProgressMonitor ;
50
47
import org .eclipse .core .runtime .IStatus ;
48
+ import org .eclipse .core .runtime .NullProgressMonitor ;
51
49
import org .eclipse .core .runtime .Platform ;
52
50
import org .eclipse .core .runtime .Status ;
53
51
import org .eclipse .ui .statushandlers .StatusManager ;
@@ -74,8 +72,7 @@ private Manager() {
74
72
}
75
73
76
74
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 ()));
79
76
jsonUrlsToAdd .addAll (originalJsonUrls );
80
77
81
78
ConfigurationPreferences .setJsonURLs (jsonUrlsToAdd );
@@ -93,7 +90,7 @@ public static void startup_Pluging(IProgressMonitor monitor) {
93
90
loadJsons (ConfigurationPreferences .getUpdateJasonFilesFlag ());
94
91
List <Board > allBoards = getInstalledBoards ();
95
92
if (allBoards .isEmpty ()) { // If boards are installed do nothing
96
- // InstallDefaultLibraries(monitor);
93
+ // InstallDefaultLibraries(monitor);
97
94
MyMultiStatus mstatus = new MyMultiStatus ("Failed to configer Sloeber" ); //$NON-NLS-1$
98
95
99
96
// Downnload sample programs
@@ -126,16 +123,14 @@ public static void startup_Pluging(IProgressMonitor monitor) {
126
123
127
124
}
128
125
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
+ */
139
134
140
135
/**
141
136
* Given a platform description in a json file download and install all
@@ -181,7 +176,7 @@ static public IStatus downloadAndInstall(ArduinoPlatform platform, boolean force
181
176
static private void loadJsons (boolean forceDownload ) {
182
177
packageIndices = new ArrayList <>();
183
178
libraryIndices = new ArrayList <>();
184
-
179
+
185
180
String [] jsonUrls = ConfigurationPreferences .getJsonURLList ();
186
181
for (String jsonUrl : jsonUrls ) {
187
182
loadJson (jsonUrl , forceDownload );
@@ -235,37 +230,37 @@ static private void loadJson(String url, boolean forceDownload) {
235
230
}
236
231
}
237
232
if (jsonFile .exists ()) {
238
- if (jsonFile .getName ().startsWith ("package_" )) {
233
+ if (jsonFile .getName ().startsWith ("package_" )) { //$NON-NLS-1$
239
234
loadPackage (jsonFile );
240
- } else if (jsonFile .getName ().startsWith ("library_" )) {
235
+ } else if (jsonFile .getName ().startsWith ("library_" )) { //$NON-NLS-1$
241
236
loadLibrary (jsonFile );
242
237
}
243
238
}
244
239
}
245
-
240
+
246
241
static private void loadPackage (File jsonFile ) {
247
242
try (Reader reader = new FileReader (jsonFile )) {
248
243
PackageIndex index = new Gson ().fromJson (reader , PackageIndex .class );
249
244
index .setOwners (null );
250
245
index .setJsonFile (jsonFile );
251
246
packageIndices .add (index );
252
247
} 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$
255
250
jsonFile .delete ();// Delete the file so it stops damaging
256
251
}
257
252
}
258
-
253
+
259
254
static private void loadLibrary (File jsonFile ) {
260
255
try (Reader reader = new FileReader (jsonFile )) {
261
256
LibraryIndex index = new Gson ().fromJson (reader , LibraryIndex .class );
262
257
index .resolve ();
263
- // index.setOwners(null);
258
+ // index.setOwners(null);
264
259
index .setJsonFile (jsonFile );
265
260
libraryIndices .add (index );
266
261
} 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$
269
264
jsonFile .delete ();// Delete the file so it stops damaging
270
265
}
271
266
}
@@ -814,8 +809,10 @@ public static void removePackageURLs(Set<String> packageUrlsToRemove) {
814
809
}
815
810
}
816
811
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
819
816
loadJsons (false );
820
817
821
818
}
@@ -845,8 +842,10 @@ public static void setJsonURL(String[] newJsonUrls) {
845
842
}
846
843
// save to configurationsettings before calling LoadIndices
847
844
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
850
849
// new files will be added
851
850
loadJsons (false );
852
851
}
@@ -861,7 +860,7 @@ public static void setReady(boolean b) {
861
860
*
862
861
* @param url
863
862
* @param localFile
864
- * @throws IOException
863
+ * @throws IOException
865
864
*/
866
865
@ SuppressWarnings ("nls" )
867
866
private static void myCopy (URL url , File localFile ) throws IOException {
@@ -879,14 +878,15 @@ private static void myCopy(URL url, File localFile) throws IOException {
879
878
Files .copy (url .openStream (), localFile .toPath (), REPLACE_EXISTING );
880
879
return ;
881
880
}
882
-
881
+
883
882
if (status == HttpURLConnection .HTTP_MOVED_TEMP || status == HttpURLConnection .HTTP_MOVED_PERM
884
883
|| status == HttpURLConnection .HTTP_SEE_OTHER ) {
885
884
Files .copy (new URL (conn .getHeaderField ("Location" )).openStream (), localFile .toPath (), REPLACE_EXISTING );
886
885
return ;
887
886
}
888
887
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 ));
890
890
throw new IOException ("Failed to download url " + url + " error code is: " + status );
891
891
} catch (Exception e ) {
892
892
Common .log (new Status (IStatus .WARNING , Activator .getId (), "Failed to download url " + url , e ));
@@ -901,4 +901,16 @@ public static void onlyKeepLatestPlatforms() {
901
901
}
902
902
}
903
903
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
+
904
916
}
0 commit comments