mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-29 18:52:13 +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:
parent
65e0d8b547
commit
42b07f0337
@ -397,7 +397,7 @@ public class Base {
|
|||||||
System.exit(0);
|
System.exit(0);
|
||||||
|
|
||||||
} else if (parser.isInstallLibrary()) {
|
} 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) {
|
LibraryInstaller installer = new LibraryInstaller(indexer) {
|
||||||
private String lastStatus = "";
|
private String lastStatus = "";
|
||||||
|
|
||||||
|
@ -28,9 +28,15 @@
|
|||||||
*/
|
*/
|
||||||
package cc.arduino.contributions.libraries;
|
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.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
|
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.BaseNoGui;
|
||||||
import processing.app.I18n;
|
import processing.app.I18n;
|
||||||
import processing.app.helpers.FileUtils;
|
import processing.app.helpers.FileUtils;
|
||||||
@ -50,6 +56,7 @@ import static processing.app.I18n._;
|
|||||||
|
|
||||||
public class LibrariesIndexer {
|
public class LibrariesIndexer {
|
||||||
|
|
||||||
|
private final ContributionsIndexer contributionsIndexer;
|
||||||
private LibrariesIndex index;
|
private LibrariesIndex index;
|
||||||
private final LibraryList installedLibraries = new LibraryList();
|
private final LibraryList installedLibraries = new LibraryList();
|
||||||
private final LibraryList installedLibrariesWithDuplicates = new LibraryList();
|
private final LibraryList installedLibrariesWithDuplicates = new LibraryList();
|
||||||
@ -58,10 +65,10 @@ public class LibrariesIndexer {
|
|||||||
private final File stagingFolder;
|
private final File stagingFolder;
|
||||||
private File sketchbookLibrariesFolder;
|
private File sketchbookLibrariesFolder;
|
||||||
|
|
||||||
public LibrariesIndexer(File preferencesFolder) {
|
public LibrariesIndexer(File preferencesFolder, ContributionsIndexer contributionsIndexer) {
|
||||||
indexFile = new File(preferencesFolder, "library_index.json");
|
this.contributionsIndexer = contributionsIndexer;
|
||||||
stagingFolder = new File(preferencesFolder, "staging" + File.separator +
|
this.indexFile = new File(preferencesFolder, "library_index.json");
|
||||||
"libraries");
|
this.stagingFolder = new File(new File(preferencesFolder, "staging"), "libraries");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void parseIndex() throws IOException {
|
public void parseIndex() throws IOException {
|
||||||
@ -101,12 +108,23 @@ public class LibrariesIndexer {
|
|||||||
// Clear all installed flags
|
// Clear all installed flags
|
||||||
installedLibraries.clear();
|
installedLibraries.clear();
|
||||||
installedLibrariesWithDuplicates.clear();
|
installedLibrariesWithDuplicates.clear();
|
||||||
for (ContributedLibrary lib : index.getLibraries())
|
for (ContributedLibrary lib : index.getLibraries()) {
|
||||||
lib.setInstalled(false);
|
lib.setInstalled(false);
|
||||||
|
}
|
||||||
|
|
||||||
// Rescan libraries
|
// Rescan libraries
|
||||||
for (File folder : librariesFolders)
|
for (File folder : librariesFolders) {
|
||||||
scanInstalledLibraries(folder, folder.equals(sketchbookLibrariesFolder));
|
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) {
|
private void scanInstalledLibraries(File folder, boolean isSketchbook) {
|
||||||
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -83,7 +83,11 @@ public abstract class ContributionsIndex {
|
|||||||
return platforms.iterator().next();
|
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()));
|
List<ContributedPlatform> installedPlatforms = new LinkedList<ContributedPlatform>(Collections2.filter(findPlatforms(packageName, platformArch), new InstalledPredicate()));
|
||||||
Collections.sort(installedPlatforms, new DownloadableContributionBuiltInAtTheBottomComparator());
|
Collections.sort(installedPlatforms, new DownloadableContributionBuiltInAtTheBottomComparator());
|
||||||
|
|
||||||
|
@ -37,14 +37,17 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
|
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.collect.Collections2;
|
import com.google.common.collect.Collections2;
|
||||||
import com.google.common.collect.ImmutableListMultimap;
|
import com.google.common.collect.ImmutableListMultimap;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Multimaps;
|
import com.google.common.collect.Multimaps;
|
||||||
import processing.app.BaseNoGui;
|
import processing.app.BaseNoGui;
|
||||||
import processing.app.debug.TargetPackage;
|
import processing.app.debug.TargetPackage;
|
||||||
import processing.app.debug.TargetPlatform;
|
import processing.app.debug.TargetPlatform;
|
||||||
import processing.app.debug.TargetPlatformException;
|
import processing.app.debug.TargetPlatformException;
|
||||||
|
import processing.app.helpers.FileUtils;
|
||||||
import processing.app.helpers.PreferencesMap;
|
import processing.app.helpers.PreferencesMap;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -398,6 +401,29 @@ public class ContributionsIndexer {
|
|||||||
if (index == null) {
|
if (index == null) {
|
||||||
return 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -630,7 +630,7 @@ public class BaseNoGui {
|
|||||||
loadContributedHardware(indexer);
|
loadContributedHardware(indexer);
|
||||||
createToolPreferences(indexer);
|
createToolPreferences(indexer);
|
||||||
|
|
||||||
librariesIndexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder());
|
librariesIndexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder(), indexer);
|
||||||
File librariesIndexFile = librariesIndexer.getIndexFile();
|
File librariesIndexFile = librariesIndexer.getIndexFile();
|
||||||
if (!librariesIndexFile.isFile()) {
|
if (!librariesIndexFile.isFile()) {
|
||||||
File defaultLibraryJsonFile = new File(getContentFile("dist"), "library_index.json");
|
File defaultLibraryJsonFile = new File(getContentFile("dist"), "library_index.json");
|
||||||
|
@ -56,13 +56,13 @@ public class UserLibrary extends ContributedLibrary {
|
|||||||
private List<String> declaredTypes;
|
private List<String> declaredTypes;
|
||||||
|
|
||||||
private static final List<String> MANDATORY_PROPERTIES = Arrays
|
private static final List<String> MANDATORY_PROPERTIES = Arrays
|
||||||
.asList(new String[]{"name", "version", "author", "maintainer",
|
.asList("name", "version", "author", "maintainer",
|
||||||
"sentence", "paragraph", "url"});
|
"sentence", "paragraph", "url");
|
||||||
|
|
||||||
private static final List<String> CATEGORIES = Arrays.asList(new String[]{
|
private static final List<String> CATEGORIES = Arrays.asList(
|
||||||
"Display", "Communication", "Signal Input/Output", "Sensors",
|
"Display", "Communication", "Signal Input/Output", "Sensors",
|
||||||
"Device Control", "Timing", "Data Storage", "Data Processing", "Other",
|
"Device Control", "Timing", "Data Storage", "Data Processing", "Other",
|
||||||
"Uncategorized"});
|
"Uncategorized");
|
||||||
|
|
||||||
public static UserLibrary create(File libFolder) throws IOException {
|
public static UserLibrary create(File libFolder) throws IOException {
|
||||||
// Parse metadata
|
// Parse metadata
|
||||||
|
@ -6,5 +6,4 @@ sentence=Enables reading and writing to the permanent board storage. For all Ard
|
|||||||
paragraph=
|
paragraph=
|
||||||
url=http://arduino.cc/en/Reference/EEPROM
|
url=http://arduino.cc/en/Reference/EEPROM
|
||||||
architectures=avr
|
architectures=avr
|
||||||
types=Arduino
|
|
||||||
|
|
||||||
|
@ -6,5 +6,4 @@ sentence=Enables the communication with devices that use the Serial Peripheral I
|
|||||||
paragraph=
|
paragraph=
|
||||||
url=http://arduino.cc/en/Reference/SPI
|
url=http://arduino.cc/en/Reference/SPI
|
||||||
architectures=avr
|
architectures=avr
|
||||||
types=Arduino
|
|
||||||
|
|
||||||
|
@ -6,5 +6,4 @@ sentence=Enables serial communication on digital pins. For all Arduino boards, B
|
|||||||
paragraph=
|
paragraph=
|
||||||
url=http://arduino.cc/en/Reference/SoftwareSerial
|
url=http://arduino.cc/en/Reference/SoftwareSerial
|
||||||
architectures=avr
|
architectures=avr
|
||||||
types=Arduino
|
|
||||||
|
|
||||||
|
@ -6,5 +6,4 @@ sentence=Allows the communication between devices or sensors connected via Two W
|
|||||||
paragraph=
|
paragraph=
|
||||||
url=http://arduino.cc/en/Reference/Wire
|
url=http://arduino.cc/en/Reference/Wire
|
||||||
architectures=avr
|
architectures=avr
|
||||||
types=Arduino
|
|
||||||
|
|
||||||
|
@ -6,5 +6,4 @@ sentence=Enables the communication with devices that use the Serial Peripheral I
|
|||||||
paragraph=
|
paragraph=
|
||||||
url=http://arduino.cc/en/Reference/SPI
|
url=http://arduino.cc/en/Reference/SPI
|
||||||
architectures=sam
|
architectures=sam
|
||||||
types=Arduino
|
|
||||||
|
|
||||||
|
@ -6,5 +6,4 @@ sentence=Allows the communication between devices or sensors connected via Two W
|
|||||||
paragraph=
|
paragraph=
|
||||||
url=http://arduino.cc/en/Reference/Wire
|
url=http://arduino.cc/en/Reference/Wire
|
||||||
architectures=sam
|
architectures=sam
|
||||||
types=Arduino
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user