1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-30 19:52:13 +01:00

Fixed NPE when setting Types field in core-libraries

The core libraries may come from platforms installed inside the
"sketchbook/hardware" directory. Those platforms are not indexed
and doesn't have a category field to propagate in the core-libraries.
This commit is contained in:
Cristian Maglie 2018-05-17 12:46:03 +02:00
parent 3bce82092e
commit 77ec25de61
2 changed files with 8 additions and 6 deletions

View File

@ -52,6 +52,7 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import static processing.app.I18n.tr;
@ -151,8 +152,11 @@ public class LibrariesIndexer {
.filter(l -> l.getTypes().contains("Contributed")) //
.filter(l -> l.getLocation() == Location.CORE || l.getLocation() == Location.REFERENCED_CORE) //
.forEach(l -> {
ContributedPlatform platform = BaseNoGui.indexer.getPlatformByFolder(l.getInstalledFolder());
l.setTypes(Collections.singletonList(platform.getCategory()));
File libFolder = l.getInstalledFolder();
Optional<ContributedPlatform> platform = BaseNoGui.indexer.getPlatformByFolder(libFolder);
if (platform.isPresent()) {
l.setTypes(Collections.singletonList(platform.get().getCategory()));
}
});
}

View File

@ -461,13 +461,11 @@ public class ContributionsIndexer {
return index.getInstalledPlatforms();
}
public ContributedPlatform getPlatformByFolder(final File folder) {
Optional<ContributedPlatform> platformOptional = getInstalledPlatforms().stream().filter(contributedPlatform -> {
public Optional<ContributedPlatform> getPlatformByFolder(final File folder) {
return getInstalledPlatforms().stream().filter(contributedPlatform -> {
assert contributedPlatform.getInstalledFolder() != null;
return FileUtils.isSubDirectory(contributedPlatform.getInstalledFolder(), folder);
}).findFirst();
return platformOptional.orElse(null);
}
public ContributedPlatform getContributedPlaform(TargetPlatform targetPlatform) {