1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-12 06:54:24 +01:00

Library manager through arduino-cli (WIP, part 1)

- library index is now fetched arduino-cli
- ContributedLibraries and derivatives classes have been adapted
  to arduino-cli structure
- install/update/remove are temporary disabled
- library index updated is now done trough arduino-cli
- added progress wrapper

Next steps:

- detect installed libraries using arduino-cli
- implement install/update/remove using arduino-cli
This commit is contained in:
Cristian Maglie 2019-11-29 00:28:33 +01:00
parent cc26e75e96
commit f6ca1f7b16
18 changed files with 339 additions and 564 deletions

View File

@ -29,15 +29,14 @@
package cc.arduino.contributions.libraries.filters; package cc.arduino.contributions.libraries.filters;
import java.util.List;
import java.util.function.Predicate; import java.util.function.Predicate;
import cc.arduino.contributions.VersionComparator; import cc.arduino.contributions.libraries.ContributedLibrary;
import cc.arduino.contributions.libraries.ContributedLibraryRelease; import cc.arduino.contributions.libraries.ContributedLibraryRelease;
import cc.arduino.contributions.libraries.LibrariesIndexer; import cc.arduino.contributions.libraries.LibrariesIndexer;
import processing.app.BaseNoGui; import processing.app.BaseNoGui;
public class UpdatableLibraryPredicate implements Predicate<ContributedLibraryRelease> { public class UpdatableLibraryPredicate implements Predicate<ContributedLibrary> {
LibrariesIndexer librariesIndexer; LibrariesIndexer librariesIndexer;
@ -50,13 +49,11 @@ public class UpdatableLibraryPredicate implements Predicate<ContributedLibraryRe
} }
@Override @Override
public boolean test(ContributedLibraryRelease lib) { public boolean test(ContributedLibrary lib) {
if (!lib.isLibraryInstalled()) { if (!lib.getInstalled().isPresent()) {
return false; return false;
} }
String libraryName = lib.getName(); ContributedLibraryRelease latest = lib.getLatest().get(); // it must be present
List<ContributedLibraryRelease> libraries = librariesIndexer.getIndex().find(libraryName);
ContributedLibraryRelease latest = libraries.stream().reduce(VersionComparator::max).get();
return !latest.isLibraryInstalled(); return !latest.isLibraryInstalled();
} }
} }

View File

@ -36,18 +36,18 @@ import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
public class ContributedLibraryReleasesComparator implements Comparator<ContributedLibrary> { public class ContributedLibraryComparatorWithTypePriority implements Comparator<ContributedLibrary> {
private final String firstType; private final String firstType;
public ContributedLibraryReleasesComparator(String firstType) { public ContributedLibraryComparatorWithTypePriority(String firstType) {
this.firstType = firstType; this.firstType = firstType;
} }
@Override @Override
public int compare(ContributedLibrary o1, ContributedLibrary o2) { public int compare(ContributedLibrary o1, ContributedLibrary o2) {
ContributedLibraryRelease lib1 = o1.getLatest(); ContributedLibraryRelease lib1 = o1.getLatest().get();
ContributedLibraryRelease lib2 = o2.getLatest(); ContributedLibraryRelease lib2 = o2.getLatest().get();
List<String> types1 = lib1.getTypes(); List<String> types1 = lib1.getTypes();
List<String> types2 = lib2.getTypes(); List<String> types2 = lib2.getTypes();

View File

@ -33,6 +33,8 @@ import static processing.app.I18n.tr;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -43,39 +45,39 @@ import javax.swing.JTable;
import cc.arduino.contributions.DownloadableContributionVersionComparator; import cc.arduino.contributions.DownloadableContributionVersionComparator;
import cc.arduino.contributions.VersionComparator; import cc.arduino.contributions.VersionComparator;
import cc.arduino.contributions.libraries.ContributedLibraryRelease;
import cc.arduino.contributions.libraries.ContributedLibrary; import cc.arduino.contributions.libraries.ContributedLibrary;
import cc.arduino.contributions.libraries.ContributedLibraryRelease;
import cc.arduino.contributions.ui.InstallerTableCell; import cc.arduino.contributions.ui.InstallerTableCell;
import cc.arduino.utils.ReverseComparator; import cc.arduino.utils.ReverseComparator;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class ContributedLibraryTableCellEditor extends InstallerTableCell { public class ContributedLibraryTableCellEditor extends InstallerTableCell {
private ContributedLibrary editorValue; private ContributedLibrary editorLibrary;
private ContributedLibraryTableCellJPanel editorCell; private ContributedLibraryTableCellJPanel editorCell;
@Override @Override
public Object getCellEditorValue() { public Object getCellEditorValue() {
return editorValue; return editorLibrary;
} }
@Override @Override
public Component getTableCellEditorComponent(JTable table, Object value, public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, boolean isSelected, int row,
int column) { int column) {
editorValue = (ContributedLibrary) value; editorLibrary = (ContributedLibrary) value;
editorCell = new ContributedLibraryTableCellJPanel(table, value, true); editorCell = new ContributedLibraryTableCellJPanel(table, value, true);
editorCell.installButton editorCell.installButton
.addActionListener(e -> onInstall(editorValue.getSelected(), .addActionListener(e -> onInstall(editorLibrary.getSelected().get(),
editorValue.getInstalled())); editorLibrary.getInstalled()));
editorCell.downgradeButton.addActionListener(e -> { editorCell.downgradeButton.addActionListener(e -> {
JComboBox chooser = editorCell.downgradeChooser; JComboBox chooser = editorCell.downgradeChooser;
ContributedLibraryRelease lib = (ContributedLibraryRelease) chooser.getSelectedItem(); ContributedLibraryRelease lib = (ContributedLibraryRelease) chooser.getSelectedItem();
onInstall(lib, editorValue.getInstalled()); onInstall(lib, editorLibrary.getInstalled());
}); });
editorCell.versionToInstallChooser.addActionListener(e -> { editorCell.versionToInstallChooser.addActionListener(e -> {
editorValue.select((ContributedLibraryRelease) editorCell.versionToInstallChooser.getSelectedItem()); editorLibrary.select((ContributedLibraryRelease) editorCell.versionToInstallChooser.getSelectedItem());
if (editorCell.versionToInstallChooser.getSelectedIndex() != 0) { if (editorCell.versionToInstallChooser.getSelectedIndex() != 0) {
InstallerTableCell.dropdownSelected(true); InstallerTableCell.dropdownSelected(true);
} }
@ -83,12 +85,12 @@ public class ContributedLibraryTableCellEditor extends InstallerTableCell {
setEnabled(true); setEnabled(true);
final Optional<ContributedLibraryRelease> mayInstalled = editorValue.getInstalled(); final Optional<ContributedLibraryRelease> mayInstalled = editorLibrary.getInstalled();
List<ContributedLibraryRelease> releases = editorValue.getReleases(); Collection<ContributedLibraryRelease> releases = editorLibrary.getReleases();
List<ContributedLibraryRelease> notInstalled = new LinkedList<>(releases); List<ContributedLibraryRelease> notInstalled = new ArrayList<>(releases);
if (mayInstalled.isPresent()) { if (mayInstalled.isPresent()) {
notInstalled.remove(editorValue.getInstalled().get()); notInstalled.remove(mayInstalled.get());
} }
Collections.sort(notInstalled, new ReverseComparator<>( Collections.sort(notInstalled, new ReverseComparator<>(

View File

@ -125,7 +125,7 @@ public class ContributedLibraryTableCellJPanel extends JPanel {
if (releases == null) if (releases == null)
return; return;
ContributedLibraryRelease selected = releases.getSelected(); ContributedLibraryRelease selected = releases.getSelected().get();
titledBorder.setTitle(selected.getName()); titledBorder.setTitle(selected.getName());
Optional<ContributedLibraryRelease> mayInstalled = releases.getInstalled(); Optional<ContributedLibraryRelease> mayInstalled = releases.getInstalled();

View File

@ -54,7 +54,7 @@ public class DropdownLibraryOfCategoryItem implements DropdownItem<ContributedLi
return new Predicate<ContributedLibrary>() { return new Predicate<ContributedLibrary>() {
@Override @Override
public boolean test(ContributedLibrary rel) { public boolean test(ContributedLibrary rel) {
ContributedLibraryRelease lib = rel.getLatest(); ContributedLibraryRelease lib = rel.getLatest().get();
return category.equals(lib.getCategory()); return category.equals(lib.getCategory());
} }
}; };

View File

@ -54,7 +54,7 @@ public class DropdownLibraryOfTypeItem implements DropdownItem<ContributedLibrar
return new Predicate<ContributedLibrary>() { return new Predicate<ContributedLibrary>() {
@Override @Override
public boolean test(ContributedLibrary lib) { public boolean test(ContributedLibrary lib) {
List<String> types = lib.getLatest().getTypes(); List<String> types = lib.getLatest().get().getTypes();
return types != null && types.contains(type); return types != null && types.contains(type);
} }
}; };

View File

@ -36,6 +36,7 @@ import cc.arduino.contributions.ui.FilteredAbstractTableModel;
import processing.app.BaseNoGui; import processing.app.BaseNoGui;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -131,7 +132,7 @@ public class LibrariesIndexTableModel
} }
public ContributedLibraryRelease getSelectedRelease(int row) { public ContributedLibraryRelease getSelectedRelease(int row) {
return contributions.get(row).getSelected(); return contributions.get(row).getSelected().get();
} }
public void update() { public void update() {
@ -144,7 +145,7 @@ public class LibrariesIndexTableModel
return false; return false;
} }
ContributedLibraryRelease latest = lib.getLatest(); ContributedLibraryRelease latest = lib.getLatest().get();
String compoundTargetSearchText = latest.getName() + " " String compoundTargetSearchText = latest.getName() + " "
+ latest.getParagraph() + " " + latest.getParagraph() + " "
+ latest.getSentence(); + latest.getSentence();
@ -158,55 +159,12 @@ public class LibrariesIndexTableModel
return true; return true;
} }
public void updateLibrary(ContributedLibraryRelease lib) {
// Find the row interested in the change
int row = -1;
for (ContributedLibrary releases : contributions) {
if (releases.shouldContain(lib))
row = contributions.indexOf(releases);
}
updateContributions();
// If the library is found in the list send update event
// or insert event on the specific row...
for (ContributedLibrary releases : contributions) {
if (releases.shouldContain(lib)) {
if (row == -1) {
row = contributions.indexOf(releases);
fireTableRowsInserted(row, row);
} else {
fireTableRowsUpdated(row, row);
}
return;
}
}
// ...otherwise send a row deleted event
fireTableRowsDeleted(row, row);
}
private List<ContributedLibrary> rebuildContributionsFromIndex() {
List<ContributedLibrary> res = new ArrayList<>();
BaseNoGui.librariesIndexer.getIndex().getLibraries(). //
forEach(lib -> {
for (ContributedLibrary contribution : res) {
if (!contribution.shouldContain(lib))
continue;
contribution.add(lib);
return;
}
res.add(new ContributedLibrary(lib));
});
return res;
}
private void updateContributions() { private void updateContributions() {
List<ContributedLibrary> all = rebuildContributionsFromIndex(); Collection<ContributedLibrary> all = BaseNoGui.librariesIndexer.getIndex().getLibraries();
contributions.clear(); contributions.clear();
all.stream().filter(this::filterCondition).forEach(contributions::add); all.stream().filter(this::filterCondition).forEach(contributions::add);
Collections.sort(contributions, Collections.sort(contributions,
new ContributedLibraryReleasesComparator("Arduino")); new ContributedLibraryComparatorWithTypePriority("Arduino"));
} }
} }

View File

@ -200,7 +200,7 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
installerThread = new Thread(() -> { installerThread = new Thread(() -> {
try { try {
setProgressVisible(true, ""); setProgressVisible(true, "");
installer.updateIndex(this::setProgress); BaseNoGui.getArduinoCoreService().updateLibrariesIndex(this::setProgress);
onIndexesUpdated(); onIndexesUpdated();
if (contribTable.getCellEditor() != null) { if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing(); contribTable.getCellEditor().stopCellEditing();
@ -218,7 +218,7 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
} }
public void onInstallPressed(final ContributedLibraryRelease lib) { public void onInstallPressed(final ContributedLibraryRelease lib) {
List<ContributedLibraryRelease> deps = BaseNoGui.librariesIndexer.getIndex().resolveDependeciesOf(lib); List<ContributedLibraryRelease> deps = BaseNoGui.getArduinoCoreService().libraryResolveDependecies(lib);
boolean depsInstalled = deps.stream().allMatch(l -> l.getInstalledLibrary().isPresent() || l.getName().equals(lib.getName())); boolean depsInstalled = deps.stream().allMatch(l -> l.getInstalledLibrary().isPresent() || l.getName().equals(lib.getName()));
Result installDeps; Result installDeps;
if (!depsInstalled) { if (!depsInstalled) {

View File

@ -27,6 +27,7 @@ import cc.arduino.Constants;
import cc.arduino.UpdatableBoardsLibsFakeURLsHandler; import cc.arduino.UpdatableBoardsLibsFakeURLsHandler;
import cc.arduino.UploaderUtils; import cc.arduino.UploaderUtils;
import cc.arduino.contributions.*; import cc.arduino.contributions.*;
import cc.arduino.contributions.libraries.ContributedLibrary;
import cc.arduino.contributions.libraries.ContributedLibraryRelease; import cc.arduino.contributions.libraries.ContributedLibraryRelease;
import cc.arduino.contributions.libraries.LibrariesIndexer; import cc.arduino.contributions.libraries.LibrariesIndexer;
import cc.arduino.contributions.libraries.LibraryInstaller; import cc.arduino.contributions.libraries.LibraryInstaller;
@ -298,7 +299,7 @@ public class Base {
final GPGDetachedSignatureVerifier gpgDetachedSignatureVerifier = new GPGDetachedSignatureVerifier(); final GPGDetachedSignatureVerifier gpgDetachedSignatureVerifier = new GPGDetachedSignatureVerifier();
contributionInstaller = new ContributionInstaller(BaseNoGui.getPlatform(), gpgDetachedSignatureVerifier); contributionInstaller = new ContributionInstaller(BaseNoGui.getPlatform(), gpgDetachedSignatureVerifier);
libraryInstaller = new LibraryInstaller(BaseNoGui.getPlatform(), gpgDetachedSignatureVerifier); libraryInstaller = new LibraryInstaller(BaseNoGui.getPlatform());
parser.parseArgumentsPhase2(); parser.parseArgumentsPhase2();
@ -358,15 +359,15 @@ public class Base {
BaseNoGui.onBoardOrPortChange(); BaseNoGui.onBoardOrPortChange();
ProgressListener progressListener = new ConsoleProgressListener(); ProgressListener progressListener = new ConsoleProgressListener();
libraryInstaller.updateIndex(progressListener); BaseNoGui.getArduinoCoreService().updateLibrariesIndex(progressListener);
LibrariesIndexer indexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder()); LibrariesIndexer indexer = new LibrariesIndexer(BaseNoGui.getArduinoCoreService());
indexer.parseIndex(); indexer.regenerateIndex();
indexer.setLibrariesFolders(BaseNoGui.getLibrariesFolders()); indexer.setLibrariesFolders(BaseNoGui.getLibrariesFolders());
indexer.rescanLibraries(); indexer.rescanLibraries();
for (String library : parser.getLibraryToInstall().split(",")) { for (String libraryArg : parser.getLibraryToInstall().split(",")) {
String[] libraryToInstallParts = library.split(":"); String[] libraryToInstallParts = libraryArg.split(":");
ContributedLibraryRelease selected = null; ContributedLibraryRelease selected = null;
if (libraryToInstallParts.length == 2) { if (libraryToInstallParts.length == 2) {
@ -375,12 +376,11 @@ public class Base {
System.out.println(format(tr("Invalid version {0}"), libraryToInstallParts[1])); System.out.println(format(tr("Invalid version {0}"), libraryToInstallParts[1]));
System.exit(1); System.exit(1);
} }
selected = indexer.getIndex().find(libraryToInstallParts[0], version.get().toString()); selected = indexer.getIndex().find(libraryToInstallParts[0], version.get().toString()).orElse(null);
} else if (libraryToInstallParts.length == 1) { } else if (libraryToInstallParts.length == 1) {
List<ContributedLibraryRelease> librariesByName = indexer.getIndex().find(libraryToInstallParts[0]); ContributedLibrary library = indexer.getIndex().find(libraryToInstallParts[0]).orElse(null);
Collections.sort(librariesByName, new DownloadableContributionVersionComparator()); if (library != null) {
if (!librariesByName.isEmpty()) { selected = library.getLatest().orElse(null);
selected = librariesByName.get(librariesByName.size() - 1);
} }
} }
if (selected == null) { if (selected == null) {
@ -392,7 +392,7 @@ public class Base {
if (mayInstalled.isPresent() && selected.isIDEBuiltIn()) { if (mayInstalled.isPresent() && selected.isIDEBuiltIn()) {
System.out.println(tr(I18n System.out.println(tr(I18n
.format("Library {0} is available as built-in in the IDE.\nRemoving the other version {1} installed in the sketchbook...", .format("Library {0} is available as built-in in the IDE.\nRemoving the other version {1} installed in the sketchbook...",
library, mayInstalled.get().getParsedVersion()))); libraryArg, mayInstalled.get().getParsedVersion())));
libraryInstaller.remove(mayInstalled.get(), progressListener); libraryInstaller.remove(mayInstalled.get(), progressListener);
} else { } else {
libraryInstaller.install(selected, progressListener); libraryInstaller.install(selected, progressListener);

View File

@ -1,82 +0,0 @@
package cc.arduino.contributions;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import cc.arduino.contributions.libraries.ContributedLibraryRelease;
import cc.arduino.contributions.libraries.LibrariesIndexer;
import processing.app.BaseNoGui;
import processing.app.packages.UserLibraryFolder;
import processing.app.packages.UserLibraryFolder.Location;
public class UpdatableLibraryTest {
File testdata = new File(
UpdatableLibraryTest.class.getResource("/").getFile(),
"../testdata/libraries");
File index_SD_only = new File(testdata, "index_SD_only");
File SD111 = new File(testdata, "SD_1.1.1");
File SD121 = new File(testdata, "SD_1.2.1");
File index_Bridge_only = new File(testdata, "index_Bridge_only");
File Bridge163 = new File(testdata, "Bridge_1.6.3");
File Bridge170 = new File(testdata, "Bridge_1.7.0");
@Test
public void testUpdatableLibrary() throws Exception {
List<UserLibraryFolder> folders = new ArrayList<>();
folders.add(new UserLibraryFolder(SD111, Location.IDE_BUILTIN));
LibrariesIndexer indexer = new LibrariesIndexer(index_SD_only);
BaseNoGui.librariesIndexer = indexer;
indexer.parseIndex();
indexer.setLibrariesFoldersAndRescan(folders);
ContributedLibraryRelease sdLib = indexer.getIndex().getInstalled("SD").get();
assertTrue("SD lib is installed", sdLib.isLibraryInstalled());
assertEquals("SD installed version", "1.1.1", sdLib.getParsedVersion());
assertTrue(ContributionsSelfCheck.checkForUpdatableLibraries());
folders.add(new UserLibraryFolder(SD121, Location.SKETCHBOOK));
indexer.setLibrariesFoldersAndRescan(folders);
sdLib = indexer.getIndex().getInstalled("SD").get();
assertTrue("SD lib is installed", sdLib.isLibraryInstalled());
assertEquals("SD installed version", "1.2.1", sdLib.getParsedVersion());
assertFalse(ContributionsSelfCheck.checkForUpdatableLibraries());
}
@Test
public void testUpdatableLibraryWithBundled() throws Exception {
List<UserLibraryFolder> folders = new ArrayList<>();
folders.add(new UserLibraryFolder(Bridge163, Location.IDE_BUILTIN));
LibrariesIndexer indexer = new LibrariesIndexer(index_Bridge_only);
BaseNoGui.librariesIndexer = indexer;
indexer.parseIndex();
indexer.setLibrariesFoldersAndRescan(folders);
ContributedLibraryRelease l = indexer.getIndex().getInstalled("Bridge").get();
assertTrue("Bridge lib is installed", l.isLibraryInstalled());
assertEquals("Bridge installed version", "1.6.3", l.getParsedVersion());
assertTrue(ContributionsSelfCheck.checkForUpdatableLibraries());
folders.add(new UserLibraryFolder(Bridge170, Location.SKETCHBOOK));
indexer.setLibrariesFoldersAndRescan(folders);
l = indexer.getIndex().getInstalled("Bridge").get();
assertTrue("Bridge lib is installed", l.isLibraryInstalled());
assertEquals("Bridge installed version", "1.7.0", l.getParsedVersion());
assertFalse(ContributionsSelfCheck.checkForUpdatableLibraries());
}
}

View File

@ -151,4 +151,9 @@ public class ArduinoCoreInstance {
throw e.getStatus().asException(); throw e.getStatus().asException();
} }
} }
public List<ContributedLibraryRelease> libraryResolveDependecies(ContributedLibraryRelease lib) {
return new ArrayList<>();
}
} }

View File

@ -29,56 +29,52 @@
package cc.arduino.contributions.libraries; package cc.arduino.contributions.libraries;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import cc.arduino.contributions.VersionComparator; import cc.arduino.contributions.VersionComparator;
import processing.app.packages.UserLibraryFolder.Location; import processing.app.packages.UserLibraryFolder.Location;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
public class ContributedLibrary { public class ContributedLibrary {
private List<ContributedLibraryRelease> releases = new LinkedList<>(); private String name;
private List<String> versions = new LinkedList<>(); // version -> release map
private ContributedLibraryRelease latest = null; private Map<String, ContributedLibraryRelease> releases = new HashMap<>();
private ContributedLibraryRelease selected = null; private Optional<ContributedLibraryRelease> latest = Optional.empty();
private Optional<ContributedLibraryRelease> selected = Optional.empty();
public ContributedLibrary(ContributedLibraryRelease release) { public ContributedLibrary(String name) {
add(release); this.name = name;
} }
public ContributedLibrary(List<ContributedLibraryRelease> releases) { public String getName() {
releases.forEach(this::add); return name;
} }
public List<ContributedLibraryRelease> getReleases() { public Collection<ContributedLibraryRelease> getReleases() {
return releases; return releases.values();
} }
public boolean shouldContain(ContributedLibraryRelease release) { public Optional<ContributedLibraryRelease> getVersion(String version) {
if (latest == null) { return Optional.ofNullable(releases.get(version));
return true;
}
return release.getName().equals(latest.getName());
} }
public void add(ContributedLibraryRelease release) { public void addRelease(ContributedLibraryRelease release) {
if (latest == null) { if (!latest.isPresent()) {
latest = release; latest = Optional.of(release);
} }
releases.add(release);
String version = release.getParsedVersion(); String version = release.getParsedVersion();
if (version != null) { releases.put(version, release);
versions.add(version); if (VersionComparator.greaterThan(version, latest.get().getParsedVersion())) {
} latest = Optional.of(release);
if (VersionComparator.greaterThan(version, latest.getParsedVersion())) {
latest = release;
} }
selected = latest; selected = latest;
} }
public Optional<ContributedLibraryRelease> getInstalled() { public Optional<ContributedLibraryRelease> getInstalled() {
return releases.stream() // return releases.values().stream() //
.filter(ContributedLibraryRelease::isLibraryInstalled) // .filter(ContributedLibraryRelease::isLibraryInstalled) //
.reduce((x, y) -> { .reduce((x, y) -> {
Location lx = x.getInstalledLibrary().get().getLocation(); Location lx = x.getInstalledLibrary().get().getLocation();
@ -90,18 +86,18 @@ public class ContributedLibrary {
}); });
} }
public ContributedLibraryRelease getLatest() { public Optional<ContributedLibraryRelease> getLatest() {
return latest; return latest;
} }
public ContributedLibraryRelease getSelected() { public Optional<ContributedLibraryRelease> getSelected() {
return selected; return selected;
} }
public void select(ContributedLibraryRelease lib) { public void select(ContributedLibraryRelease lib) {
for (ContributedLibraryRelease r : releases) { for (ContributedLibraryRelease r : releases.values()) {
if (r == lib) { if (r == lib) {
selected = r; selected = Optional.of(r);
return; return;
} }
} }

View File

@ -35,7 +35,6 @@ import processing.app.packages.UserLibrary;
import static processing.app.I18n.tr; import static processing.app.I18n.tr;
import java.util.Comparator; import java.util.Comparator;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -43,61 +42,136 @@ import cc.arduino.contributions.VersionHelper;
public class ContributedLibraryRelease extends DownloadableContribution { public class ContributedLibraryRelease extends DownloadableContribution {
private String url; final private ContributedLibrary library;
private String version; final private String maintainer;
private String checksum; final private String author;
private long size; final private String website;
private String archiveFileName; final private String category;
private String name; final private String license;
private String maintainer; final private String paragraph;
private String author; final private String sentence;
private String website; final private List<String> architectures;
private String category; final private List<String> types;
private String licence; final private List<ContributedLibraryDependency> dependencies;
private String paragraph; final private List<String> providesIncludes;
private String sentence;
private ArrayList<String> architectures;
private ArrayList<String> types;
private ArrayList<ContributedLibraryDependency> dependencies;
private ArrayList<String> providesIncludes;
public String getUrl() { return url; } public ContributedLibraryRelease(ContributedLibrary library,
String maintainer, String author,
String website, String category,
String license, String paragraph,
String sentence, List<String> architectures,
List<String> types,
List<ContributedLibraryDependency> dependencies,
List<String> providesIncludes, //
//
String url, String version, String checksum,
long size, String archiveFileName) {
this.library = library;
this.maintainer = maintainer;
this.author = author;
this.website = website;
this.category = category;
this.license = license;
this.paragraph = paragraph;
this.sentence = sentence;
this.architectures = architectures;
this.types = types;
this.dependencies = dependencies;
this.providesIncludes = providesIncludes;
public String getVersion() { return version; } this.url = url;
this.version = version;
this.checksum = checksum;
this.size = size;
this.archiveFileName = archiveFileName;
}
public String getChecksum() { return checksum; } public ContributedLibrary getLibrary() {
return library;
}
public long getSize() { return size; } public String getName() {
return library.getName();
}
public String getArchiveFileName() { return archiveFileName; } public String getMaintainer() {
return maintainer;
}
public String getName() { return name; } public String getAuthor() {
return author;
}
public String getMaintainer() { return maintainer; } public String getWebsite() {
return website;
}
public String getAuthor() { return author; } public String getCategory() {
return category;
}
public String getWebsite() { return website; } public String getLicense() {
return license;
}
public String getCategory() { return category; } public String getParagraph() {
return paragraph;
}
public void setCategory(String category) { this.category = category; } public String getSentence() {
return sentence;
}
public String getLicense() { return licence; } public List<String> getArchitectures() {
return architectures;
}
public String getParagraph() { return paragraph; } public List<String> getTypes() {
return types;
}
public String getSentence() { return sentence; } public List<ContributedLibraryDependency> getDependencies() {
return dependencies;
}
public List<String> getArchitectures() { return architectures; } public List<String> getProvidesIncludes() {
return providesIncludes;
}
public List<String> getTypes() { return types; } // Implementation of DownloadableResource
final private String url;
final private String version;
final private String checksum;
final private long size;
final private String archiveFileName;
public List<ContributedLibraryDependency> getDependencies() { return dependencies; } @Override
public String getUrl() {
return url;
}
public List<String> getProvidesIncludes() { return providesIncludes; } @Override
public String getVersion() {
return version;
}
public static final Comparator<ContributedLibraryRelease> CASE_INSENSITIVE_ORDER = (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()); @Override
public String getChecksum() {
return checksum;
}
@Override
public long getSize() {
return size;
}
@Override
public String getArchiveFileName() {
return archiveFileName;
}
public static final Comparator<ContributedLibraryRelease> //
CASE_INSENSITIVE_ORDER = (o1, o2) -> o1.getName()
.compareToIgnoreCase(o2.getName());
private Optional<UserLibrary> installedLib = Optional.empty(); private Optional<UserLibrary> installedLib = Optional.empty();
@ -132,14 +206,16 @@ public class ContributedLibraryRelease extends DownloadableContribution {
* @return * @return
*/ */
public boolean supportsArchitecture(String reqArch) { public boolean supportsArchitecture(String reqArch) {
return getArchitectures().contains(reqArch) || getArchitectures().contains("*"); return getArchitectures().contains(reqArch)
|| getArchitectures().contains("*");
} }
/** /**
* Returns <b>true</b> if the library declares to support at least one of the * Returns <b>true</b> if the library declares to support at least one of the
* specified architectures. * specified architectures.
* *
* @param reqArchs A List of architectures to check * @param reqArchs
* A List of architectures to check
* @return * @return
*/ */
public boolean supportsArchitecture(List<String> reqArchs) { public boolean supportsArchitecture(List<String> reqArchs) {

View File

@ -32,151 +32,60 @@ package cc.arduino.contributions.libraries;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.Set;
import cc.arduino.contributions.VersionComparator;
public class LibrariesIndex { public class LibrariesIndex {
private ArrayList<ContributedLibraryRelease> list = new ArrayList<>(); // name -> library map
private Map<String, ContributedLibrary> libraries = new HashMap<>();
private Set<String> categories = new HashSet<>();
private Set<String> types = new HashSet<>();
public List<ContributedLibraryRelease> getLibraries() { public Collection<ContributedLibrary> getLibraries() {
return list; return libraries.values();
} }
public List<ContributedLibraryRelease> find(final String name) { public void add(ContributedLibrary library) {
return getLibraries().stream() // libraries.put(library.getName(), library);
.filter(l -> name.equals(l.getName())) // library.getReleases().forEach(rel -> {
.collect(Collectors.toList()); categories.add(rel.getCategory());
types.addAll(rel.getTypes());
});
} }
public ContributedLibraryRelease find(String name, String version) { public Optional<ContributedLibrary> find(String name) {
if (name == null || version == null) { return Optional.ofNullable(libraries.get(name));
return null;
}
for (ContributedLibraryRelease lib : find(name)) {
if (version.equals(lib.getParsedVersion())) {
return lib;
}
}
return null;
} }
@Override public Optional<ContributedLibraryRelease> find(String name, String version) {
public String toString() { if (libraries.containsKey(name)) {
StringBuilder sb = new StringBuilder(); return libraries.get(name).getVersion(version);
for (ContributedLibraryRelease library : getLibraries()) {
sb.append(library.toString());
} }
return sb.toString(); return Optional.empty();
} }
public List<String> getCategories() { public List<String> getCategories() {
List<String> categories = new LinkedList<>(); List<String> res = new ArrayList<>(categories);
for (ContributedLibraryRelease lib : getLibraries()) { Collections.sort(res);
if (lib.getCategory() != null && !categories.contains(lib.getCategory())) { return res;
categories.add(lib.getCategory());
}
}
Collections.sort(categories);
return categories;
} }
public List<String> getTypes() { public List<String> getTypes() {
Collection<String> typesAccumulator = new HashSet<>(); List<String> res = new ArrayList<>(types);
for (ContributedLibraryRelease lib : getLibraries()) { Collections.sort(res);
if (lib.getTypes() != null) { return res;
typesAccumulator.addAll(lib.getTypes());
}
}
List<String> types = new LinkedList<>(typesAccumulator);
Collections.sort(types);
return types;
} }
public Optional<ContributedLibraryRelease> getInstalled(String name) { public Optional<ContributedLibraryRelease> getInstalled(String name) {
ContributedLibrary rel = new ContributedLibrary(find(name)); if (libraries.containsKey(name)) {
return rel.getInstalled(); return libraries.get(name).getInstalled();
}
return Optional.empty();
} }
public List<ContributedLibraryRelease> resolveDependeciesOf(ContributedLibraryRelease library) {
List<ContributedLibraryRelease> solution = new ArrayList<>();
solution.add(library);
if (resolveDependeciesOf(solution, library)) {
return solution;
} else {
return null;
}
}
public boolean resolveDependeciesOf(List<ContributedLibraryRelease> solution,
ContributedLibraryRelease library) {
List<ContributedLibraryDependency> requirements = library.getDependencies();
if (requirements == null) {
// No deps for this library, great!
return true;
}
for (ContributedLibraryDependency dep : requirements) {
// If the current solution already contains this dependency, skip over
boolean alreadyInSolution = solution.stream()
.anyMatch(l -> l.getName().equals(dep.getName()));
if (alreadyInSolution)
continue;
// Generate possible matching dependencies
List<ContributedLibraryRelease> possibleDeps = findMatchingDependencies(dep);
// If there are no dependencies available add as "missing" lib
if (possibleDeps.isEmpty()) {
solution.add(new UnavailableContributedLibrary(dep));
continue;
}
// Pick the installed version if available
ContributedLibraryRelease selected;
Optional<ContributedLibraryRelease> installed = possibleDeps.stream()
.filter(l -> l.getInstalledLibrary().isPresent()).findAny();
if (installed.isPresent()) {
selected = installed.get();
} else {
// otherwise pick the latest version
selected = possibleDeps.stream().reduce(VersionComparator::max).get();
}
// Add dependency to the solution and process recursively
solution.add(selected);
if (!resolveDependeciesOf(solution, selected)) {
return false;
}
}
return true;
}
private List<ContributedLibraryRelease> findMatchingDependencies(ContributedLibraryDependency dep) {
List<ContributedLibraryRelease> available = find(dep.getName());
if (dep.getVersion() == null || dep.getVersion().isEmpty())
return available;
// XXX: The following part is actually never reached. The use of version
// constraints requires a much complex backtracking algorithm, the following
// is just a draft placeholder.
// List<ContributedLibrary> match = available.stream()
// // TODO: add more complex version comparators (> >= < <= ~ 1.0.* 1.*...)
// .filter(candidate -> candidate.getParsedVersion()
// .equals(dep.getVersionRequired()))
// .collect(Collectors.toList());
// return match;
return available;
}
} }

View File

@ -29,14 +29,19 @@
package cc.arduino.contributions.libraries; package cc.arduino.contributions.libraries;
import cc.arduino.Constants; import static processing.app.I18n.format;
import cc.arduino.contributions.packages.ContributedPlatform; import static processing.app.I18n.tr;
import com.fasterxml.jackson.core.JsonParseException; import java.io.File;
import com.fasterxml.jackson.databind.DeserializationFeature; import java.io.IOException;
import com.fasterxml.jackson.databind.JsonMappingException; import java.util.ArrayList;
import com.fasterxml.jackson.databind.ObjectMapper; import java.util.Collections;
import org.apache.commons.compress.utils.IOUtils; import java.util.List;
import java.util.Optional;
import cc.arduino.cli.ArduinoCoreInstance;
import cc.arduino.contributions.packages.ContributedPlatform;
import io.grpc.StatusException;
import processing.app.BaseNoGui; import processing.app.BaseNoGui;
import processing.app.I18n; import processing.app.I18n;
import processing.app.helpers.filefilters.OnlyDirs; import processing.app.helpers.filefilters.OnlyDirs;
@ -47,70 +52,54 @@ import processing.app.packages.UserLibraryFolder;
import processing.app.packages.UserLibraryFolder.Location; import processing.app.packages.UserLibraryFolder.Location;
import processing.app.packages.UserLibraryPriorityComparator; import processing.app.packages.UserLibraryPriorityComparator;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
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.format;
import static processing.app.I18n.tr;
public class LibrariesIndexer { public class LibrariesIndexer {
private LibrariesIndex index; private LibrariesIndex index;
private final LibraryList installedLibraries = new LibraryList(); private final LibraryList installedLibraries = new LibraryList();
private List<UserLibraryFolder> librariesFolders; private List<UserLibraryFolder> librariesFolders;
private final File indexFile;
private final File stagingFolder;
private final List<String> badLibNotified = new ArrayList<>(); private final List<String> badLibNotified = new ArrayList<>();
private ArduinoCoreInstance core;
public LibrariesIndexer(File preferencesFolder) { public LibrariesIndexer(ArduinoCoreInstance core) {
indexFile = new File(preferencesFolder, "library_index.json"); this.core = core;
stagingFolder = new File(new File(preferencesFolder, "staging"), "libraries");
} }
public void parseIndex() throws IOException { public void regenerateIndex() {
index = new LibrariesIndex(); // Fallback index = new LibrariesIndex();
if (!indexFile.exists()) {
return;
}
parseIndex(indexFile);
// TODO: resolve libraries inner references
}
private void parseIndex(File file) throws IOException {
InputStream indexIn = null;
try { try {
indexIn = new FileInputStream(file); core.searchLibrary("").forEach(inLib -> {
ObjectMapper mapper = new ObjectMapper(); ContributedLibrary library = new ContributedLibrary(inLib.getName());
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); inLib.getReleasesMap().forEach((ver, rel) -> {
mapper.configure(DeserializationFeature.EAGER_DESERIALIZER_FETCH, true); ContributedLibraryRelease release = new ContributedLibraryRelease(
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); library, //
LibrariesIndex newIndex = mapper.readValue(indexIn, LibrariesIndex.class); rel.getMaintainer(), //
rel.getAuthor(), //
newIndex.getLibraries() rel.getWebsite(), //
.stream() rel.getCategory(), //
.filter(library -> library.getCategory() == null || "".equals(library.getCategory()) || !Constants.LIBRARY_CATEGORIES.contains(library.getCategory())) "", // TODO: license
.forEach(library -> library.setCategory("Uncategorized")); rel.getParagraph(), //
rel.getSentence(), //
index = newIndex; rel.getArchitecturesList(), //
} catch (JsonParseException | JsonMappingException e) { rel.getTypesList(), //
System.err.println( null, // TODO: dependencies - List<ContributedLibraryDependency>
format(tr("Error parsing libraries index: {0}\nTry to open the Library Manager to update the libraries index."), null, // TODO: providesIncludes - List<String>
e.getMessage())); //
} catch (Exception e) { rel.getResources().getUrl(), //
System.err.println(format(tr("Error reading libraries index: {0}"), e.getMessage())); rel.getVersion(), //
} finally { rel.getResources().getChecksum(), //
IOUtils.closeQuietly(indexIn); rel.getResources().getSize(), //
rel.getResources().getArchivefilename());
library.addRelease(release);
});
index.add(library);
});
} catch (StatusException e) {
e.printStackTrace();
} }
// format(tr("Error parsing libraries index: {0}\nTry to open the Library Manager to update the libraries index."),
// System.err.println(format(tr("Error reading libraries index: {0}"),
} }
public void setLibrariesFolders(List<UserLibraryFolder> folders) { public void setLibrariesFolders(List<UserLibraryFolder> folders) {
@ -126,7 +115,8 @@ public class LibrariesIndexer {
return librariesFolders; return librariesFolders;
} }
private UserLibraryPriorityComparator priorityComparator = new UserLibraryPriorityComparator(null); private UserLibraryPriorityComparator priorityComparator = new UserLibraryPriorityComparator(
null);
public void addToInstalledLibraries(UserLibrary lib) { public void addToInstalledLibraries(UserLibrary lib) {
UserLibrary toReplace = installedLibraries.getByName(lib.getName()); UserLibrary toReplace = installedLibraries.getByName(lib.getName());
@ -154,8 +144,10 @@ public class LibrariesIndexer {
return; return;
} }
for (ContributedLibraryRelease lib : index.getLibraries()) { for (ContributedLibrary lib : index.getLibraries()) {
lib.unsetInstalledUserLibrary(); for (ContributedLibraryRelease libRelease : lib.getReleases()) {
libRelease.unsetInstalledUserLibrary();
}
} }
// Rescan libraries // Rescan libraries
@ -165,10 +157,12 @@ public class LibrariesIndexer {
installedLibraries.stream() // installedLibraries.stream() //
.filter(l -> l.getTypes().contains("Contributed")) // .filter(l -> l.getTypes().contains("Contributed")) //
.filter(l -> l.getLocation() == Location.CORE || l.getLocation() == Location.REFERENCED_CORE) // .filter(l -> l.getLocation() == Location.CORE
|| l.getLocation() == Location.REFERENCED_CORE) //
.forEach(l -> { .forEach(l -> {
File libFolder = l.getInstalledFolder(); File libFolder = l.getInstalledFolder();
Optional<ContributedPlatform> platform = BaseNoGui.indexer.getPlatformByFolder(libFolder); Optional<ContributedPlatform> platform = BaseNoGui.indexer
.getPlatformByFolder(libFolder);
if (platform.isPresent()) { if (platform.isPresent()) {
l.setTypes(Collections.singletonList(platform.get().getCategory())); l.setTypes(Collections.singletonList(platform.get().getCategory()));
} }
@ -185,12 +179,14 @@ public class LibrariesIndexer {
String subfolderName = subfolder.getName(); String subfolderName = subfolder.getName();
if (!BaseNoGui.isSanitaryName(subfolderName)) { if (!BaseNoGui.isSanitaryName(subfolderName)) {
// Detect whether the current folder name has already had a notification. // Detect whether the current folder name has already had a
// notification.
if (!badLibNotified.contains(subfolderName)) { if (!badLibNotified.contains(subfolderName)) {
badLibNotified.add(subfolderName); badLibNotified.add(subfolderName);
String mess = I18n.format(tr("The library \"{0}\" cannot be used.\n" String mess = I18n.format(
tr("The library \"{0}\" cannot be used.\n"
+ "Library folder names must start with a letter or number, followed by letters,\n" + "Library folder names must start with a letter or number, followed by letters,\n"
+ "numbers, dashes, dots and underscores. Maximum length is 63 characters."), + "numbers, dashes, dots and underscores. Maximum length is 63 characters."),
subfolderName); subfolderName);
@ -202,7 +198,8 @@ public class LibrariesIndexer {
try { try {
scanLibrary(new UserLibraryFolder(subfolder, folderDesc.location)); scanLibrary(new UserLibraryFolder(subfolder, folderDesc.location));
} catch (IOException e) { } catch (IOException e) {
System.out.println(I18n.format(tr("Invalid library found in {0}: {1}"), subfolder, e.getMessage())); System.out.println(I18n.format(tr("Invalid library found in {0}: {1}"),
subfolder, e.getMessage()));
} }
} }
} }
@ -214,9 +211,11 @@ public class LibrariesIndexer {
if (!check.exists() || !check.isFile()) { if (!check.exists() || !check.isFile()) {
// Create a legacy library and exit // Create a legacy library and exit
LegacyUserLibrary lib = LegacyUserLibrary.create(folderDesc); LegacyUserLibrary lib = LegacyUserLibrary.create(folderDesc);
String[] headers = BaseNoGui.headerListFromIncludePath(lib.getSrcFolder()); String[] headers = BaseNoGui
.headerListFromIncludePath(lib.getSrcFolder());
if (headers.length == 0) { if (headers.length == 0) {
throw new IOException(format(tr("no headers files (.h) found in {0}"), lib.getSrcFolder())); throw new IOException(format(tr("no headers files (.h) found in {0}"),
lib.getSrcFolder()));
} }
addToInstalledLibraries(lib); addToInstalledLibraries(lib);
return; return;
@ -226,7 +225,8 @@ public class LibrariesIndexer {
UserLibrary lib = UserLibrary.create(folderDesc); UserLibrary lib = UserLibrary.create(folderDesc);
String[] headers = BaseNoGui.headerListFromIncludePath(lib.getSrcFolder()); String[] headers = BaseNoGui.headerListFromIncludePath(lib.getSrcFolder());
if (headers.length == 0) { if (headers.length == 0) {
throw new IOException(format(tr("no headers files (.h) found in {0}"), lib.getSrcFolder())); throw new IOException(
format(tr("no headers files (.h) found in {0}"), lib.getSrcFolder()));
} }
addToInstalledLibraries(lib); addToInstalledLibraries(lib);
@ -234,11 +234,10 @@ public class LibrariesIndexer {
if (loc != Location.CORE && loc != Location.REFERENCED_CORE) { if (loc != Location.CORE && loc != Location.REFERENCED_CORE) {
// Check if we can find the same library in the index // Check if we can find the same library in the index
// and mark it as installed // and mark it as installed
ContributedLibraryRelease foundLib = index.find(lib.getName(), lib.getVersion()); index.find(lib.getName(), lib.getVersion()).ifPresent(foundLib -> {
if (foundLib != null) {
foundLib.setInstalledUserLibrary(lib); foundLib.setInstalledUserLibrary(lib);
lib.setTypes(foundLib.getTypes()); lib.setTypes(foundLib.getTypes());
} });
} }
if (lib.getTypes().isEmpty() && loc == Location.SKETCHBOOK) { if (lib.getTypes().isEmpty() && loc == Location.SKETCHBOOK) {
@ -257,12 +256,4 @@ public class LibrariesIndexer {
public LibraryList getInstalledLibraries() { public LibraryList getInstalledLibraries() {
return new LibraryList(installedLibraries); return new LibraryList(installedLibraries);
} }
public File getStagingFolder() {
return stagingFolder;
}
public File getIndexFile() {
return indexFile;
}
} }

View File

@ -60,16 +60,14 @@ public class LibraryInstaller {
private static Logger log = LogManager.getLogger(LibraryInstaller.class); private static Logger log = LogManager.getLogger(LibraryInstaller.class);
private final Platform platform; private final Platform platform;
private final GPGDetachedSignatureVerifier signatureVerifier;
public LibraryInstaller(Platform platform, GPGDetachedSignatureVerifier signatureVerifier) { public LibraryInstaller(Platform platform) {
this.platform = platform; this.platform = platform;
this.signatureVerifier = signatureVerifier;
} }
public synchronized void updateIndex(ProgressListener progressListener) throws Exception { public synchronized void updateIndex(ProgressListener progressListener) throws Exception {
/*
final MultiStepProgress progress = new MultiStepProgress(3); final MultiStepProgress progress = new MultiStepProgress(3);
DownloadableContributionsDownloader downloader = new DownloadableContributionsDownloader(BaseNoGui.librariesIndexer.getStagingFolder()); DownloadableContributionsDownloader downloader = new DownloadableContributionsDownloader(BaseNoGui.librariesIndexer.getStagingFolder());
// Step 1: Download index // Step 1: Download index
File outputFile = BaseNoGui.librariesIndexer.getIndexFile(); File outputFile = BaseNoGui.librariesIndexer.getIndexFile();
@ -104,11 +102,11 @@ public class LibraryInstaller {
} }
// Step 2: Parse index // Step 2: Parse index
BaseNoGui.librariesIndexer.parseIndex(); BaseNoGui.librariesIndexer.regenerateIndex();
// Step 3: Rescan index // Step 3: Rescan index
rescanLibraryIndex(progress, progressListener); rescanLibraryIndex(progress, progressListener);
*/
} }
public void install(ContributedLibraryRelease lib, ProgressListener progressListener) throws Exception { public void install(ContributedLibraryRelease lib, ProgressListener progressListener) throws Exception {
@ -118,6 +116,7 @@ public class LibraryInstaller {
} }
public synchronized void install(List<ContributedLibraryRelease> libs, ProgressListener progressListener) throws Exception { public synchronized void install(List<ContributedLibraryRelease> libs, ProgressListener progressListener) throws Exception {
/*
MultiStepProgress progress = new MultiStepProgress(3 * libs.size() + 1); MultiStepProgress progress = new MultiStepProgress(3 * libs.size() + 1);
for (ContributedLibraryRelease lib : libs) { for (ContributedLibraryRelease lib : libs) {
@ -127,9 +126,11 @@ public class LibraryInstaller {
// Rescan index (1 step) // Rescan index (1 step)
rescanLibraryIndex(progress, progressListener); rescanLibraryIndex(progress, progressListener);
*/
} }
private void performInstall(ContributedLibraryRelease lib, ProgressListener progressListener, MultiStepProgress progress) throws Exception { private void performInstall(ContributedLibraryRelease lib, ProgressListener progressListener, MultiStepProgress progress) throws Exception {
/*
if (lib.isLibraryInstalled()) { if (lib.isLibraryInstalled()) {
System.out.println(I18n.format(tr("Library is already installed: {0}:{1}"), lib.getName(), lib.getParsedVersion())); System.out.println(I18n.format(tr("Library is already installed: {0}:{1}"), lib.getName(), lib.getParsedVersion()));
return; return;
@ -140,12 +141,28 @@ public class LibraryInstaller {
// Check if we are replacing an already installed lib // Check if we are replacing an already installed lib
LibrariesIndex index = BaseNoGui.librariesIndexer.getIndex(); LibrariesIndex index = BaseNoGui.librariesIndexer.getIndex();
Optional<ContributedLibraryRelease> replacedLib = index.find(lib.getName()).stream() // Optional<ContributedLibraryRelease> mayReplacedLib = lib.getLibrary()
.filter(l -> l.getInstalledLibrary().isPresent()) // .getInstalled();
.filter(l -> l.getInstalledLibrary().get().getInstalledFolder().equals(destFolder)) // if (mayReplacedLib.isPresent()) {
.findAny(); if (mayReplacedLib.get().getInstalledLibrary().get().getInstalledFolder()
.equals(destFolder) && destFolder.exists()) {
System.out
.println(I18n.format(tr("Library {0} is already installed in: {1}"),
lib.getName(), destFolder));
return;
}
}
// TODO: Check correctness
// Optional<ContributedLibraryRelease> mayReplacedLib =
// index.find(lib.getName());
// .filter(l ->
// l.getInstalledLibrary().get().getInstalledFolder().equals(destFolder)) //
// .findAny();
if (!replacedLib.isPresent() && destFolder.exists()) { if (!replacedLib.isPresent() && destFolder.exists()) {
System.out.println(I18n.format(tr("Library {0} is already installed in: {1}"), lib.getName(), destFolder)); System.out
.println(I18n.format(tr("Library {0} is already installed in: {1}"),
lib.getName(), destFolder));
return; return;
} }
DownloadableContributionsDownloader downloader = new DownloadableContributionsDownloader(BaseNoGui.librariesIndexer.getStagingFolder()); DownloadableContributionsDownloader downloader = new DownloadableContributionsDownloader(BaseNoGui.librariesIndexer.getStagingFolder());
@ -182,9 +199,11 @@ public class LibraryInstaller {
} }
tmpFolder.renameTo(destFolder); tmpFolder.renameTo(destFolder);
progress.stepDone(); progress.stepDone();
*/
} }
public synchronized void remove(ContributedLibraryRelease lib, ProgressListener progressListener) throws IOException { public synchronized void remove(ContributedLibraryRelease lib, ProgressListener progressListener) throws IOException {
/*
if (lib.isIDEBuiltIn()) { if (lib.isIDEBuiltIn()) {
return; return;
} }
@ -199,6 +218,7 @@ public class LibraryInstaller {
// Step 2: Rescan index // Step 2: Rescan index
rescanLibraryIndex(progress, progressListener); rescanLibraryIndex(progress, progressListener);
*/
} }
private void rescanLibraryIndex(MultiStepProgress progress, ProgressListener progressListener) { private void rescanLibraryIndex(MultiStepProgress progress, ProgressListener progressListener) {

View File

@ -30,114 +30,22 @@
package cc.arduino.contributions.libraries; package cc.arduino.contributions.libraries;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
public class UnavailableContributedLibrary extends ContributedLibraryRelease { public class UnavailableContributedLibrary extends ContributedLibraryRelease {
private String name;
private String version;
public UnavailableContributedLibrary(ContributedLibraryDependency dependency) { public UnavailableContributedLibrary(ContributedLibraryDependency dependency) {
this(dependency.getName(), dependency.getVersion()); this(dependency.getName(), dependency.getVersion());
} }
public UnavailableContributedLibrary(String _name, String _version) { public UnavailableContributedLibrary(String name, String version) {
name = _name; super(new ContributedLibrary(name), "Unknown", "Unknown", "Unknown",
version = _version; "Uncategorized", "Unknown", "", "", new ArrayList<>(),
} new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), "", version,
"", 0, "");
@Override
public String getName() {
return name;
}
@Override
public String getMaintainer() {
return "Unknown";
}
@Override
public String getAuthor() {
return "Unknown";
}
@Override
public String getWebsite() {
return "Unknown";
}
@Override
public String getCategory() {
return "Uncategorized";
}
@Override
public void setCategory(String category) {
// Empty
}
@Override
public String getLicense() {
return "Unknown";
}
@Override
public String getParagraph() {
return "";
}
@Override
public String getSentence() {
return "";
}
@Override
public List<String> getArchitectures() {
return new ArrayList<>();
}
@Override
public List<String> getTypes() {
return new ArrayList<>();
}
@Override
public List<ContributedLibraryDependency> getDependencies() {
return new ArrayList<>();
}
@Override
public String getUrl() {
return "";
}
@Override
public String getVersion() {
return version;
}
@Override
public String getChecksum() {
return "";
}
@Override
public long getSize() {
return 0;
}
@Override
public String getArchiveFileName() {
return "";
} }
@Override @Override
public String toString() { public String toString() {
return "!" + super.toString(); return "!" + super.toString();
} }
@Override
public List<String> getProvidesIncludes() {
return new ArrayList<>();
}
} }

View File

@ -520,13 +520,8 @@ public class BaseNoGui {
loadHardware(getSketchbookHardwareFolder()); loadHardware(getSketchbookHardwareFolder());
createToolPreferences(indexer.getInstalledTools(), true); createToolPreferences(indexer.getInstalledTools(), true);
librariesIndexer = new LibrariesIndexer(getSettingsFolder()); librariesIndexer = new LibrariesIndexer(BaseNoGui.getArduinoCoreService());
try { librariesIndexer.regenerateIndex();
librariesIndexer.parseIndex();
} catch (JsonProcessingException e) {
File librariesIndexFile = librariesIndexer.getIndexFile();
librariesIndexFile.delete();
}
if (discoveryManager == null) { if (discoveryManager == null) {
discoveryManager = new DiscoveryManager(packages); discoveryManager = new DiscoveryManager(packages);