1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-21 15:54:39 +01:00

Filter examples based on contributed libraries by architecture

Solves #4762
This commit is contained in:
Martino Facchin 2016-04-06 14:41:12 +02:00
parent f74afc4ad9
commit c28c854936
3 changed files with 19 additions and 7 deletions

View File

@ -82,6 +82,7 @@ public class Base {
public static final Predicate<UserLibrary> CONTRIBUTED = library -> library.getTypes() == null || library.getTypes().isEmpty() || library.getTypes().contains("Contributed"); public static final Predicate<UserLibrary> CONTRIBUTED = library -> library.getTypes() == null || library.getTypes().isEmpty() || library.getTypes().contains("Contributed");
public static final Predicate<UserLibrary> RETIRED = library -> library.getTypes() != null && library.getTypes().contains("Retired"); public static final Predicate<UserLibrary> RETIRED = library -> library.getTypes() != null && library.getTypes().contains("Retired");
public static final Predicate<UserLibrary> COMPATIBLE = library -> library.getArchitectures() != null && (library.getArchitectures().contains("*") || library.getArchitectures().contains(BaseNoGui.getTargetPlatform().getId()));
private static final int RECENT_SKETCHES_MAX_SIZE = 10; private static final int RECENT_SKETCHES_MAX_SIZE = 10;
@ -1104,6 +1105,7 @@ public class Base {
List<UserLibrary> libs = installedLibraries.stream() List<UserLibrary> libs = installedLibraries.stream()
.filter(CONTRIBUTED.negate()) .filter(CONTRIBUTED.negate())
.filter(RETIRED.negate()) .filter(RETIRED.negate())
.filter(COMPATIBLE)
.collect(Collectors.toList()); .collect(Collectors.toList());
return new LibraryList(libs); return new LibraryList(libs);
} }

View File

@ -187,11 +187,11 @@ public class LibrariesIndexer {
if (headers.length == 0) { if (headers.length == 0) {
throw new IOException(lib.getSrcFolder().getAbsolutePath()); throw new IOException(lib.getSrcFolder().getAbsolutePath());
} }
installedLibraries.addOrReplace(lib); installedLibraries.addOrReplaceArchAware(lib);
if (isSketchbook) { if (isSketchbook) {
installedLibrariesWithDuplicates.add(lib); installedLibrariesWithDuplicates.add(lib);
} else { } else {
installedLibrariesWithDuplicates.addOrReplace(lib); installedLibrariesWithDuplicates.addOrReplaceArchAware(lib);
} }
// Check if we can find the same library in the index // Check if we can find the same library in the index

View File

@ -57,16 +57,26 @@ public class LibraryList extends LinkedList<UserLibrary> {
return null; return null;
} }
public synchronized void addOrReplaceArchAware(UserLibrary lib) {
addOrReplace(lib, true);
}
public synchronized void addOrReplace(UserLibrary lib) { public synchronized void addOrReplace(UserLibrary lib) {
remove(lib); addOrReplace(lib, false);
}
public synchronized void addOrReplace(UserLibrary lib, boolean archAware) {
remove(lib, archAware);
add(lib); add(lib);
} }
public synchronized void remove(UserLibrary lib) { public synchronized void remove(UserLibrary lib, boolean archAware) {
UserLibrary l = getByName(lib.getName()); UserLibrary l = getByName(lib.getName());
if (l != null) if (l != null) {
if (!archAware || lib.getArchitectures().contains("*") || lib.getArchitectures().containsAll(l.getArchitectures()))
super.remove(l); super.remove(l);
} }
}
public synchronized void sort() { public synchronized void sort() {
Collections.sort(this, UserLibrary.CASE_INSENSITIVE_ORDER); Collections.sort(this, UserLibrary.CASE_INSENSITIVE_ORDER);