Skip to content

Commit dcb987f

Browse files
author
jantje
committed
#727 added unit tests: Warning 14134 projects are now created.
We will need some filtering
1 parent fb321b1 commit dcb987f

File tree

4 files changed

+82
-43
lines changed

4 files changed

+82
-43
lines changed

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ public LibraryTree() {
136136
this.categories.put(category.getName(), category);
137137
}
138138
for (io.sloeber.core.managers.Library library : libraryIndex.getLibraries(categoryName)) {
139-
Library lib = category.libraries.get(library.getName() + " (" + libraryIndex.getName() + ")");
139+
Library lib = category.libraries.get(library.getName() + " (" + libraryIndex.getName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
140140
if (lib == null) {
141141
StringBuilder builder = new StringBuilder("Architectures:") //$NON-NLS-1$
142142
.append(library.getArchitectures().toString()).append("\n\n") //$NON-NLS-1$
143143
.append(library.getSentence());
144144
lib = new Library(category, library.getName(), libraryIndex.getName(), builder.toString());
145-
category.libraries.put(library.getName() + " (" + libraryIndex.getName() + ")", lib);
145+
category.libraries.put(library.getName() + " (" + libraryIndex.getName() + ")", lib); //$NON-NLS-1$ //$NON-NLS-2$
146146
}
147147
lib.versions.add(new VersionNumber(library.getVersion()));
148148
if (library.isInstalled()) {
@@ -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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class LibraryIndex {
1616

1717
// category name to library name
1818
private Map<String, Set<String>> categories = new HashMap<>();
19-
19+
2020
// library name to latest version of library
2121
private Map<String, Library> latestLibs = new HashMap<>();
2222

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

104104
public void setJsonFile(File packageFile) {
105105
String fileName = packageFile.getName().toLowerCase();
106-
if (fileName.matches("(?i)library_index.json")) {
107-
this.indexName = "Default";
106+
if (fileName.matches("(?i)library_index.json")) { //$NON-NLS-1$
107+
this.indexName = "Default"; //$NON-NLS-1$
108108
} else {
109-
this.indexName = fileName.replaceAll("(?i)"+Pattern.quote("library_"), "").replaceAll("(?i)"+Pattern.quote("_index.json"), "");
109+
this.indexName = fileName.replaceAll("(?i)" + Pattern.quote("library_"), "") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
110+
.replaceAll("(?i)" + Pattern.quote("_index.json"), ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
110111
}
111112
}
112-
113+
113114
public String getName() {
114115
return this.indexName;
115116
}

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

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,22 @@
1919
import java.io.FileReader;
2020
import java.io.IOException;
2121
import java.io.InputStream;
22-
import java.io.InputStreamReader;
2322
import java.io.Reader;
2423
import java.net.HttpURLConnection;
2524
import java.net.MalformedURLException;
2625
import java.net.URL;
27-
import java.nio.charset.Charset;
2826
import java.nio.file.Files;
2927
import java.nio.file.Path;
3028
import java.nio.file.Paths;
3129
import java.util.ArrayList;
3230
import java.util.Arrays;
31+
import java.util.Collection;
3332
import java.util.HashMap;
3433
import java.util.HashSet;
3534
import java.util.List;
3635
import java.util.Map;
3736
import java.util.Set;
3837

39-
import javax.net.ssl.HttpsURLConnection;
40-
4138
import org.apache.commons.compress.archivers.ArchiveEntry;
4239
import org.apache.commons.compress.archivers.ArchiveInputStream;
4340
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
@@ -48,6 +45,7 @@
4845
import org.eclipse.core.runtime.IPath;
4946
import org.eclipse.core.runtime.IProgressMonitor;
5047
import org.eclipse.core.runtime.IStatus;
48+
import org.eclipse.core.runtime.NullProgressMonitor;
5149
import org.eclipse.core.runtime.Platform;
5250
import org.eclipse.core.runtime.Status;
5351
import 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
}

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)