1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-20 14:54:31 +01:00

UserLibrary: ensure that types field is always not-null

This commit is contained in:
Cristian Maglie 2018-01-17 17:21:27 +01:00
parent 20bc297151
commit ac570c50bd
6 changed files with 18 additions and 14 deletions

View File

@ -47,13 +47,17 @@ public class LibraryByTypeComparator implements Comparator<UserLibrary> {
@Override @Override
public int compare(UserLibrary o1, UserLibrary o2) { public int compare(UserLibrary o1, UserLibrary o2) {
if (o1.getTypes() == null) { if (o1.getTypes().isEmpty() && o2.getTypes().isEmpty()) {
return 0;
}
if (o1.getTypes().isEmpty()) {
return 1; return 1;
} }
if (o2.getTypes() == null) { if (o2.getTypes().isEmpty()) {
return -1; return -1;
} }
return libraryTypeComparator.compare(o1.getTypes().get(0), o2.getTypes().get(0)); return libraryTypeComparator.compare(o1.getTypes().get(0),
o2.getTypes().get(0));
} }
} }

View File

@ -37,10 +37,13 @@ public class LibraryOfSameTypeComparator implements Comparator<UserLibrary> {
@Override @Override
public int compare(UserLibrary o1, UserLibrary o2) { public int compare(UserLibrary o1, UserLibrary o2) {
if (o1.getTypes() == null) { if (o1.getTypes().isEmpty() && o2.getTypes().isEmpty()) {
return 0;
}
if (o1.getTypes().isEmpty()) {
return 1; return 1;
} }
if (o2.getTypes() == null) { if (o2.getTypes().isEmpty()) {
return -1; return -1;
} }
if (!o1.getTypes().get(0).equals(o2.getTypes().get(0))) { if (!o1.getTypes().get(0).equals(o2.getTypes().get(0))) {

View File

@ -1193,10 +1193,7 @@ public class Base {
if (location == Location.IDE_BUILTIN) { if (location == Location.IDE_BUILTIN) {
if (compatible) { if (compatible) {
// only compatible IDE libs are shown // only compatible IDE libs are shown
boolean retired = false; if (lib.getTypes().contains("Retired")) {
List<String> types = lib.getTypes();
if (types != null) retired = types.contains("Retired");
if (retired) {
retiredIdeLibs.add(lib); retiredIdeLibs.add(lib);
} else { } else {
ideLibs.add(lib); ideLibs.add(lib);
@ -1214,7 +1211,7 @@ public class Base {
} else if (location == Location.SKETCHBOOK) { } else if (location == Location.SKETCHBOOK) {
if (compatible) { if (compatible) {
// libraries promoted from sketchbook (behave as builtin) // libraries promoted from sketchbook (behave as builtin)
if (lib.getTypes() != null && lib.getTypes().contains("Arduino") if (!lib.getTypes().isEmpty() && lib.getTypes().contains("Arduino")
&& lib.getArchitectures().contains("*")) { && lib.getArchitectures().contains("*")) {
ideLibs.add(lib); ideLibs.add(lib);
} else { } else {

View File

@ -204,11 +204,11 @@ public class LibrariesIndexer {
} }
} }
if (lib.getTypes() == null && folderDesc.location == Location.SKETCHBOOK) { if (lib.getTypes().isEmpty() && loc == Location.SKETCHBOOK) {
lib.setTypes(lib.getDeclaredTypes()); lib.setTypes(lib.getDeclaredTypes());
} }
if (lib.getTypes() == null) { if (lib.getTypes().isEmpty()) {
lib.setTypes(Collections.singletonList("Contributed")); lib.setTypes(Collections.singletonList("Contributed"));
} }
} }

View File

@ -43,7 +43,7 @@ public class TypePredicate implements Predicate<UserLibrary> {
@Override @Override
public boolean test(UserLibrary input) { public boolean test(UserLibrary input) {
return input.getTypes() != null && input.getTypes().contains(type); return input.getTypes().contains(type);
} }
} }

View File

@ -56,7 +56,7 @@ public class UserLibrary {
private String category; private String category;
private String license; private String license;
private List<String> architectures; private List<String> architectures;
private List<String> types; private List<String> types = new ArrayList<>();
private List<String> declaredTypes; private List<String> declaredTypes;
private boolean onGoingDevelopment; private boolean onGoingDevelopment;
private List<String> includes; private List<String> includes;