Skip to content

Commit 00f2cf4

Browse files
authored
Merge branch 'master' into master
2 parents 304db38 + dcb987f commit 00f2cf4

File tree

4 files changed

+67
-22
lines changed

4 files changed

+67
-22
lines changed

io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public static IStatus setLibraryTree(LibraryTree libs, IProgressMonitor monitor,
200200
status.add(toInstall.install(monitor));
201201
}
202202
}
203-
203+
204204
if (monitor.isCanceled())
205205
return Status.CANCEL_STATUS;
206206
}
@@ -219,4 +219,27 @@ public static String getPrivateLibraryPathsString() {
219219
return InstancePreferences.getPrivateLibraryPathsString();
220220
}
221221

222+
public static void installAllLatestLibraries(String category) {
223+
Manager.installAllLatestLibraries(category);
224+
}
225+
226+
public static void installAllLatestLibraries() {
227+
Set<String> allcategories = getAllCategories();
228+
for (String categorieName : allcategories) {
229+
Manager.installAllLatestLibraries(categorieName);
230+
}
231+
232+
}
233+
234+
public static Set<String> getAllCategories() {
235+
236+
Set<String> ret = new TreeSet<>();
237+
238+
for (LibraryIndex libraryIndex : Manager.getLibraryIndices()) {
239+
for (String categoryName : libraryIndex.getCategories()) {
240+
ret.add(categoryName);
241+
}
242+
}
243+
return ret;
244+
}
222245
}

io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class LibraryIndex {
1818

1919
// category name to library name
2020
private Map<String, Set<String>> categories = new HashMap<>();
21-
21+
2222
// library name to latest version of library
2323
private Map<String, Library> latestLibs = new HashMap<>();
2424

@@ -105,13 +105,14 @@ public Collection<Library> getLibraries(String category) {
105105

106106
public void setJsonFile(File packageFile) {
107107
String fileName = packageFile.getName().toLowerCase();
108-
if (fileName.matches("(?i)library_index.json")) {
108+
if (fileName.matches("(?i)library_index.json")) { //$NON-NLS-1$
109109
this.indexName = Defaults.DEFAULT;
110110
} else {
111-
this.indexName = fileName.replaceAll("(?i)"+Pattern.quote("library_"), "").replaceAll("(?i)"+Pattern.quote("_index.json"), "");
111+
this.indexName = fileName.replaceAll("(?i)" + Pattern.quote("library_"), "") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
112+
.replaceAll("(?i)" + Pattern.quote("_index.json"), ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
112113
}
113114
}
114-
115+
115116
public String getName() {
116117
return this.indexName;
117118
}

io.sloeber.core/src/io/sloeber/core/managers/Manager.java

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.nio.file.Paths;
2929
import java.util.ArrayList;
3030
import java.util.Arrays;
31+
import java.util.Collection;
3132
import java.util.HashMap;
3233
import java.util.HashSet;
3334
import java.util.List;
@@ -44,6 +45,7 @@
4445
import org.eclipse.core.runtime.IPath;
4546
import org.eclipse.core.runtime.IProgressMonitor;
4647
import org.eclipse.core.runtime.IStatus;
48+
import org.eclipse.core.runtime.NullProgressMonitor;
4749
import org.eclipse.core.runtime.Platform;
4850
import org.eclipse.core.runtime.Status;
4951
import 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
}

io.sloeber.core/src/jUnit/CreateAndCompileExamples.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.sloeber.core.api.CodeDescriptor;
2828
import io.sloeber.core.api.CompileOptions;
2929
import io.sloeber.core.api.ConfigurationDescriptor;
30+
import io.sloeber.core.api.LibraryManager;
3031

3132
@SuppressWarnings("nls")
3233
@RunWith(Parameterized.class)
@@ -157,9 +158,11 @@ public static void WaitForInstallerToFinish() {
157158
}
158159

159160
public static void installAdditionalBoards() {
160-
String[] packageUrlsToAdd = { "http://arduino.esp8266.com/stable/package_esp8266com_index.json" };
161+
String[] packageUrlsToAdd = { "http://arduino.esp8266.com/stable/package_esp8266com_index.json",
162+
"http://www.lmt.sk/arduino/library_mikula_index.json" };
161163
BoardsManager.addPackageURLs(new HashSet<>(Arrays.asList(packageUrlsToAdd)), true);
162164
BoardsManager.installAllLatestPlatforms();
165+
LibraryManager.installAllLatestLibraries();
163166

164167
}
165168

0 commit comments

Comments
 (0)