diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 41e53169d..900ae8260 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -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 = ""; diff --git a/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java b/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java index c285ade68..4b22c40f6 100644 --- a/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java +++ b/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java @@ -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() { + @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) { diff --git a/arduino-core/src/cc/arduino/contributions/libraries/filters/LibraryInstalledInsideCore.java b/arduino-core/src/cc/arduino/contributions/libraries/filters/LibraryInstalledInsideCore.java new file mode 100644 index 000000000..cde6a54c2 --- /dev/null +++ b/arduino-core/src/cc/arduino/contributions/libraries/filters/LibraryInstalledInsideCore.java @@ -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 { + + private final ContributionsIndexer indexer; + + public LibraryInstalledInsideCore(ContributionsIndexer indexer) { + this.indexer = indexer; + } + + @Override + public boolean apply(ContributedLibrary contributedLibrary) { + return indexer.isFolderInsidePlatform(contributedLibrary.getInstalledFolder()); + } + +} diff --git a/app/src/cc/arduino/contributions/libraries/filters/TypePredicate.java b/arduino-core/src/cc/arduino/contributions/libraries/filters/TypePredicate.java similarity index 100% rename from app/src/cc/arduino/contributions/libraries/filters/TypePredicate.java rename to arduino-core/src/cc/arduino/contributions/libraries/filters/TypePredicate.java diff --git a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndex.java b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndex.java index 1804e719f..54e1ee298 100644 --- a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndex.java +++ b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndex.java @@ -83,7 +83,11 @@ public abstract class ContributionsIndex { return platforms.iterator().next(); } - public ContributedPlatform getInstalled(String packageName, String platformArch) { + public List getInstalledPlatforms() { + return Lists.newLinkedList(Collections2.filter(getPlatforms(), new InstalledPredicate())); + } + + public ContributedPlatform getInstalledPlatform(String packageName, String platformArch) { List installedPlatforms = new LinkedList(Collections2.filter(findPlatforms(packageName, platformArch), new InstalledPredicate())); Collections.sort(installedPlatforms, new DownloadableContributionBuiltInAtTheBottomComparator()); diff --git a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java index fd26b7e68..c8f596966 100644 --- a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java +++ b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java @@ -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 getInstalledPlatforms() { + if (index == null) { + return new LinkedList(); + } + return index.getInstalledPlatforms(); + } + + public boolean isFolderInsidePlatform(final File folder) { + return getPlatformByFolder(folder) != null; + } + + public ContributedPlatform getPlatformByFolder(final File folder) { + com.google.common.base.Optional platformOptional = Iterables.tryFind(getInstalledPlatforms(), new Predicate() { + @Override + public boolean apply(ContributedPlatform contributedPlatform) { + assert contributedPlatform.getInstalledFolder() != null; + return FileUtils.isSubDirectory(contributedPlatform.getInstalledFolder(), folder); + } + }); + + return platformOptional.orNull(); } } diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java index da2fcfdd9..895f6aef1 100644 --- a/arduino-core/src/processing/app/BaseNoGui.java +++ b/arduino-core/src/processing/app/BaseNoGui.java @@ -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"); diff --git a/arduino-core/src/processing/app/packages/UserLibrary.java b/arduino-core/src/processing/app/packages/UserLibrary.java index 82d2d01ff..941da7ad2 100644 --- a/arduino-core/src/processing/app/packages/UserLibrary.java +++ b/arduino-core/src/processing/app/packages/UserLibrary.java @@ -56,13 +56,13 @@ public class UserLibrary extends ContributedLibrary { private List declaredTypes; private static final List 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 CATEGORIES = Arrays.asList(new String[]{ - "Display", "Communication", "Signal Input/Output", "Sensors", - "Device Control", "Timing", "Data Storage", "Data Processing", "Other", - "Uncategorized"}); + private static final List 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 diff --git a/hardware/arduino/avr/libraries/EEPROM/library.properties b/hardware/arduino/avr/libraries/EEPROM/library.properties index 765aa41a2..c6532559b 100644 --- a/hardware/arduino/avr/libraries/EEPROM/library.properties +++ b/hardware/arduino/avr/libraries/EEPROM/library.properties @@ -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 diff --git a/hardware/arduino/avr/libraries/SPI/library.properties b/hardware/arduino/avr/libraries/SPI/library.properties index 07af86961..582ce5b5c 100644 --- a/hardware/arduino/avr/libraries/SPI/library.properties +++ b/hardware/arduino/avr/libraries/SPI/library.properties @@ -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 diff --git a/hardware/arduino/avr/libraries/SoftwareSerial/library.properties b/hardware/arduino/avr/libraries/SoftwareSerial/library.properties index 8b433d94a..45368f8e7 100644 --- a/hardware/arduino/avr/libraries/SoftwareSerial/library.properties +++ b/hardware/arduino/avr/libraries/SoftwareSerial/library.properties @@ -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 diff --git a/hardware/arduino/avr/libraries/Wire/library.properties b/hardware/arduino/avr/libraries/Wire/library.properties index 32c074525..74406459d 100644 --- a/hardware/arduino/avr/libraries/Wire/library.properties +++ b/hardware/arduino/avr/libraries/Wire/library.properties @@ -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 diff --git a/hardware/arduino/sam/libraries/SPI/library.properties b/hardware/arduino/sam/libraries/SPI/library.properties index d3d378872..543906ba5 100644 --- a/hardware/arduino/sam/libraries/SPI/library.properties +++ b/hardware/arduino/sam/libraries/SPI/library.properties @@ -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 diff --git a/hardware/arduino/sam/libraries/Wire/library.properties b/hardware/arduino/sam/libraries/Wire/library.properties index aabdececc..780f911d4 100644 --- a/hardware/arduino/sam/libraries/Wire/library.properties +++ b/hardware/arduino/sam/libraries/Wire/library.properties @@ -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