1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-17 06:52:18 +01:00

Libraries bundled with cores will take the type of that core, instead of relying on an undocumented 'types' property. Fixes #2875

This commit is contained in:
Federico Fissore 2015-05-19 12:24:11 +02:00
parent 65e0d8b547
commit 42b07f0337
14 changed files with 84 additions and 22 deletions

View File

@ -397,7 +397,7 @@ public class Base {
System.exit(0);
} else if (parser.isInstallLibrary()) {
LibrariesIndexer indexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder());
LibrariesIndexer indexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder(), new ContributionsIndexer(BaseNoGui.getSettingsFolder()));
LibraryInstaller installer = new LibraryInstaller(indexer) {
private String lastStatus = "";

View File

@ -28,9 +28,15 @@
*/
package cc.arduino.contributions.libraries;
import cc.arduino.contributions.libraries.filters.LibraryInstalledInsideCore;
import cc.arduino.contributions.libraries.filters.TypePredicate;
import cc.arduino.contributions.packages.ContributedPlatform;
import cc.arduino.contributions.packages.ContributionsIndexer;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import processing.app.BaseNoGui;
import processing.app.I18n;
import processing.app.helpers.FileUtils;
@ -50,6 +56,7 @@ import static processing.app.I18n._;
public class LibrariesIndexer {
private final ContributionsIndexer contributionsIndexer;
private LibrariesIndex index;
private final LibraryList installedLibraries = new LibraryList();
private final LibraryList installedLibrariesWithDuplicates = new LibraryList();
@ -58,10 +65,10 @@ public class LibrariesIndexer {
private final File stagingFolder;
private File sketchbookLibrariesFolder;
public LibrariesIndexer(File preferencesFolder) {
indexFile = new File(preferencesFolder, "library_index.json");
stagingFolder = new File(preferencesFolder, "staging" + File.separator +
"libraries");
public LibrariesIndexer(File preferencesFolder, ContributionsIndexer contributionsIndexer) {
this.contributionsIndexer = contributionsIndexer;
this.indexFile = new File(preferencesFolder, "library_index.json");
this.stagingFolder = new File(new File(preferencesFolder, "staging"), "libraries");
}
public void parseIndex() throws IOException {
@ -101,12 +108,23 @@ public class LibrariesIndexer {
// Clear all installed flags
installedLibraries.clear();
installedLibrariesWithDuplicates.clear();
for (ContributedLibrary lib : index.getLibraries())
for (ContributedLibrary lib : index.getLibraries()) {
lib.setInstalled(false);
}
// Rescan libraries
for (File folder : librariesFolders)
for (File folder : librariesFolders) {
scanInstalledLibraries(folder, folder.equals(sketchbookLibrariesFolder));
}
FluentIterable.from(installedLibraries).filter(new TypePredicate("Contributed")).filter(new LibraryInstalledInsideCore(contributionsIndexer)).transform(new Function<UserLibrary, Object>() {
@Override
public Object apply(UserLibrary userLibrary) {
ContributedPlatform platform = contributionsIndexer.getPlatformByFolder(userLibrary.getInstalledFolder());
userLibrary.setTypes(Arrays.asList(platform.getCategory()));
return userLibrary;
}
}).toList();
}
private void scanInstalledLibraries(File folder, boolean isSketchbook) {

View File

@ -0,0 +1,20 @@
package cc.arduino.contributions.libraries.filters;
import cc.arduino.contributions.libraries.ContributedLibrary;
import cc.arduino.contributions.packages.ContributionsIndexer;
import com.google.common.base.Predicate;
public class LibraryInstalledInsideCore implements Predicate<ContributedLibrary> {
private final ContributionsIndexer indexer;
public LibraryInstalledInsideCore(ContributionsIndexer indexer) {
this.indexer = indexer;
}
@Override
public boolean apply(ContributedLibrary contributedLibrary) {
return indexer.isFolderInsidePlatform(contributedLibrary.getInstalledFolder());
}
}

View File

@ -83,7 +83,11 @@ public abstract class ContributionsIndex {
return platforms.iterator().next();
}
public ContributedPlatform getInstalled(String packageName, String platformArch) {
public List<ContributedPlatform> getInstalledPlatforms() {
return Lists.newLinkedList(Collections2.filter(getPlatforms(), new InstalledPredicate()));
}
public ContributedPlatform getInstalledPlatform(String packageName, String platformArch) {
List<ContributedPlatform> installedPlatforms = new LinkedList<ContributedPlatform>(Collections2.filter(findPlatforms(packageName, platformArch), new InstalledPredicate()));
Collections.sort(installedPlatforms, new DownloadableContributionBuiltInAtTheBottomComparator());

View File

@ -37,14 +37,17 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimaps;
import processing.app.BaseNoGui;
import processing.app.debug.TargetPackage;
import processing.app.debug.TargetPlatform;
import processing.app.debug.TargetPlatformException;
import processing.app.helpers.FileUtils;
import processing.app.helpers.PreferencesMap;
import java.io.File;
@ -398,6 +401,29 @@ public class ContributionsIndexer {
if (index == null) {
return null;
}
return index.getInstalled(packageName, platformArch);
return index.getInstalledPlatform(packageName, platformArch);
}
public List<ContributedPlatform> getInstalledPlatforms() {
if (index == null) {
return new LinkedList<ContributedPlatform>();
}
return index.getInstalledPlatforms();
}
public boolean isFolderInsidePlatform(final File folder) {
return getPlatformByFolder(folder) != null;
}
public ContributedPlatform getPlatformByFolder(final File folder) {
com.google.common.base.Optional<ContributedPlatform> platformOptional = Iterables.tryFind(getInstalledPlatforms(), new Predicate<ContributedPlatform>() {
@Override
public boolean apply(ContributedPlatform contributedPlatform) {
assert contributedPlatform.getInstalledFolder() != null;
return FileUtils.isSubDirectory(contributedPlatform.getInstalledFolder(), folder);
}
});
return platformOptional.orNull();
}
}

View File

@ -630,7 +630,7 @@ public class BaseNoGui {
loadContributedHardware(indexer);
createToolPreferences(indexer);
librariesIndexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder());
librariesIndexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder(), indexer);
File librariesIndexFile = librariesIndexer.getIndexFile();
if (!librariesIndexFile.isFile()) {
File defaultLibraryJsonFile = new File(getContentFile("dist"), "library_index.json");

View File

@ -56,13 +56,13 @@ public class UserLibrary extends ContributedLibrary {
private List<String> declaredTypes;
private static final List<String> MANDATORY_PROPERTIES = Arrays
.asList(new String[]{"name", "version", "author", "maintainer",
"sentence", "paragraph", "url"});
.asList("name", "version", "author", "maintainer",
"sentence", "paragraph", "url");
private static final List<String> CATEGORIES = Arrays.asList(new String[]{
"Display", "Communication", "Signal Input/Output", "Sensors",
"Device Control", "Timing", "Data Storage", "Data Processing", "Other",
"Uncategorized"});
private static final List<String> CATEGORIES = Arrays.asList(
"Display", "Communication", "Signal Input/Output", "Sensors",
"Device Control", "Timing", "Data Storage", "Data Processing", "Other",
"Uncategorized");
public static UserLibrary create(File libFolder) throws IOException {
// Parse metadata

View File

@ -6,5 +6,4 @@ sentence=Enables reading and writing to the permanent board storage. For all Ard
paragraph=
url=http://arduino.cc/en/Reference/EEPROM
architectures=avr
types=Arduino

View File

@ -6,5 +6,4 @@ sentence=Enables the communication with devices that use the Serial Peripheral I
paragraph=
url=http://arduino.cc/en/Reference/SPI
architectures=avr
types=Arduino

View File

@ -6,5 +6,4 @@ sentence=Enables serial communication on digital pins. For all Arduino boards, B
paragraph=
url=http://arduino.cc/en/Reference/SoftwareSerial
architectures=avr
types=Arduino

View File

@ -6,5 +6,4 @@ sentence=Allows the communication between devices or sensors connected via Two W
paragraph=
url=http://arduino.cc/en/Reference/Wire
architectures=avr
types=Arduino

View File

@ -6,5 +6,4 @@ sentence=Enables the communication with devices that use the Serial Peripheral I
paragraph=
url=http://arduino.cc/en/Reference/SPI
architectures=sam
types=Arduino

View File

@ -6,5 +6,4 @@ sentence=Allows the communication between devices or sensors connected via Two W
paragraph=
url=http://arduino.cc/en/Reference/Wire
architectures=sam
types=Arduino