Skip to content

Use arduino-cli to manage libraries (WIP) #8420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/src/cc/arduino/contributions/ContributionsSelfCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
package cc.arduino.contributions;

import cc.arduino.contributions.libraries.LibraryInstaller;
import cc.arduino.contributions.libraries.filters.UpdatableLibraryPredicate;
import cc.arduino.contributions.packages.ContributionInstaller;
import cc.arduino.contributions.packages.filters.UpdatablePlatformPredicate;
import cc.arduino.view.NotificationPopup;
Expand Down Expand Up @@ -130,7 +129,7 @@ static boolean checkForUpdatablePlatforms() {

static boolean checkForUpdatableLibraries() {
return BaseNoGui.librariesIndexer.getIndex().getLibraries().stream()
.anyMatch(new UpdatableLibraryPredicate());
.anyMatch(r -> r.getInstalled().isPresent() && !r.getLatest().isLibraryInstalled());
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,16 @@
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import javax.swing.JComboBox;
import javax.swing.JTable;

import cc.arduino.contributions.DownloadableContributionVersionComparator;
import cc.arduino.contributions.VersionComparator;
import cc.arduino.contributions.libraries.ContributedLibrary;
import cc.arduino.contributions.libraries.ContributedLibraryReleases;
import cc.arduino.contributions.ui.InstallerTableCell;
import cc.arduino.utils.ReverseComparator;

@SuppressWarnings("serial")
public class ContributedLibraryTableCellEditor extends InstallerTableCell {
Expand All @@ -67,12 +66,11 @@ public Component getTableCellEditorComponent(JTable table, Object value,

editorCell = new ContributedLibraryTableCellJPanel(table, value, true);
editorCell.installButton
.addActionListener(e -> onInstall(editorValue.getSelected(),
editorValue.getInstalled()));
.addActionListener(e -> onInstall(editorValue.getSelected()));
editorCell.downgradeButton.addActionListener(e -> {
JComboBox chooser = editorCell.downgradeChooser;
ContributedLibrary lib = (ContributedLibrary) chooser.getSelectedItem();
onInstall(lib, editorValue.getInstalled());
onInstall(lib);
});
editorCell.versionToInstallChooser.addActionListener(e -> {
editorValue.select((ContributedLibrary) editorCell.versionToInstallChooser.getSelectedItem());
Expand All @@ -83,24 +81,24 @@ public Component getTableCellEditorComponent(JTable table, Object value,

setEnabled(true);

final Optional<ContributedLibrary> mayInstalled = editorValue.getInstalled();
Map<String, ContributedLibrary> releases = editorValue.getReleases();
List<ContributedLibrary> notInstalled = new LinkedList<>(releases.values());

List<ContributedLibrary> releases = editorValue.getReleases();
List<ContributedLibrary> notInstalled = new LinkedList<>(releases);
final Optional<ContributedLibrary> mayInstalled = editorValue.getInstalled();
if (mayInstalled.isPresent()) {
notInstalled.remove(editorValue.getInstalled().get());
notInstalled.remove(mayInstalled.get());
}

Collections.sort(notInstalled, new ReverseComparator<>(
new DownloadableContributionVersionComparator()));
Collections.sort(notInstalled, VersionComparator::compareTo);
Collections.reverse(notInstalled);

editorCell.downgradeChooser.removeAllItems();
editorCell.downgradeChooser.addItem(tr("Select version"));

final List<ContributedLibrary> notInstalledPrevious = new LinkedList<>();
final List<ContributedLibrary> notInstalledNewer = new LinkedList<>();

notInstalled.stream().forEach(input -> {
notInstalled.forEach(input -> {
if (!mayInstalled.isPresent()
|| VersionComparator.greaterThan(mayInstalled.get(), input)) {
notInstalledPrevious.add(input);
Expand Down Expand Up @@ -142,8 +140,7 @@ protected void onRemove(ContributedLibrary selected) {
// Empty
}

protected void onInstall(ContributedLibrary selected,
Optional<ContributedLibrary> mayInstalled) {
protected void onInstall(ContributedLibrary selected) {
// Empty
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.StyleSheet;

import cc.arduino.contributions.DownloadableContributionVersionComparator;
import cc.arduino.contributions.VersionComparator;
import cc.arduino.contributions.libraries.ContributedLibrary;
import cc.arduino.contributions.libraries.ContributedLibraryReleases;
import cc.arduino.contributions.ui.InstallerTableCell;
Expand Down Expand Up @@ -126,8 +126,7 @@ public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
upgradable = false;
} else {
installable = false;
upgradable = new DownloadableContributionVersionComparator()
.compare(selected, mayInstalled.get()) > 0;
upgradable = VersionComparator.greaterThan(selected, mayInstalled.get());
}
if (installable) {
installButton.setText(tr("Install"));
Expand Down Expand Up @@ -165,7 +164,7 @@ public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,

// ...version.
if (mayInstalled.isPresent()) {
String installedVer = mayInstalled.get().getParsedVersion();
String installedVer = mayInstalled.get().getVersion();
if (installedVer == null) {
desc += " " + tr("Version unknown");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,51 +158,8 @@ private boolean filterCondition(ContributedLibraryReleases lib) {
return true;
}

public void updateLibrary(ContributedLibrary lib) {
// Find the row interested in the change
int row = -1;
for (ContributedLibraryReleases 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 (ContributedLibraryReleases 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<ContributedLibraryReleases> rebuildContributionsFromIndex() {
List<ContributedLibraryReleases> res = new ArrayList<>();
BaseNoGui.librariesIndexer.getIndex().getLibraries(). //
forEach(lib -> {
for (ContributedLibraryReleases contribution : res) {
if (!contribution.shouldContain(lib))
continue;
contribution.add(lib);
return;
}

res.add(new ContributedLibraryReleases(lib));
});
return res;
}

private void updateContributions() {
List<ContributedLibraryReleases> all = rebuildContributionsFromIndex();
List<ContributedLibraryReleases> all = BaseNoGui.librariesIndexer.getIndex().getLibraries();
contributions.clear();
all.stream().filter(this::filterCondition).forEach(contributions::add);
Collections.sort(contributions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

import javax.swing.Box;
Expand Down Expand Up @@ -81,12 +80,8 @@ protected TableCellRenderer createCellRenderer() {
protected InstallerTableCell createCellEditor() {
return new ContributedLibraryTableCellEditor() {
@Override
protected void onInstall(ContributedLibrary selectedLibrary, Optional<ContributedLibrary> mayInstalledLibrary) {
if (mayInstalledLibrary.isPresent() && selectedLibrary.isIDEBuiltIn()) {
onRemovePressed(mayInstalledLibrary.get());
} else {
onInstallPressed(selectedLibrary, mayInstalledLibrary);
}
protected void onInstall(ContributedLibrary selectedLibrary) {
onInstallPressed(selectedLibrary);
}

@Override
Expand Down Expand Up @@ -213,12 +208,12 @@ protected void onUpdatePressed() {
installerThread.start();
}

public void onInstallPressed(final ContributedLibrary lib, final Optional<ContributedLibrary> mayReplaced) {
public void onInstallPressed(final ContributedLibrary lib) {
clearErrorMessage();
installerThread = new Thread(() -> {
try {
setProgressVisible(true, tr("Installing..."));
installer.install(lib, mayReplaced, this::setProgress);
installer.install(lib, this::setProgress);
// TODO: Do a better job in refreshing only the needed element
if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing();
Expand Down
19 changes: 5 additions & 14 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public Base(String[] args) throws Exception {
pdeKeywords.reload();

contributionInstaller = new ContributionInstaller(BaseNoGui.getPlatform(), new GPGDetachedSignatureVerifier());
libraryInstaller = new LibraryInstaller(BaseNoGui.getPlatform());
libraryInstaller = new LibraryInstaller();

parser.parseArgumentsPhase2();

Expand Down Expand Up @@ -364,26 +364,17 @@ public Base(String[] args) throws Exception {
}
selected = indexer.getIndex().find(libraryToInstallParts[0], version.get().toString());
} else if (libraryToInstallParts.length == 1) {
List<ContributedLibrary> librariesByName = indexer.getIndex().find(libraryToInstallParts[0]);
Collections.sort(librariesByName, new DownloadableContributionVersionComparator());
if (!librariesByName.isEmpty()) {
selected = librariesByName.get(librariesByName.size() - 1);
ContributedLibraryReleases releases = indexer.getIndex().find(libraryToInstallParts[0]);
if (releases != null) {
selected = releases.getLatest();
}
}
if (selected == null) {
System.out.println(tr("Selected library is not available"));
System.exit(1);
}

Optional<ContributedLibrary> mayInstalled = indexer.getIndex().getInstalled(libraryToInstallParts[0]);
if (mayInstalled.isPresent() && selected.isIDEBuiltIn()) {
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...",
library, mayInstalled.get().getParsedVersion())));
libraryInstaller.remove(mayInstalled.get(), progressListener);
} else {
libraryInstaller.install(selected, mayInstalled, progressListener);
}
libraryInstaller.install(selected, progressListener);
}

System.exit(0);
Expand Down
8 changes: 4 additions & 4 deletions app/test/cc/arduino/contributions/UpdatableLibraryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void testUpdatableLibrary() throws Exception {

ContributedLibrary sdLib = indexer.getIndex().getInstalled("SD").get();
assertTrue("SD lib is installed", sdLib.isLibraryInstalled());
assertEquals("SD installed version", "1.1.1", sdLib.getParsedVersion());
assertEquals("SD installed version", "1.1.1", sdLib.getVersion());

assertTrue(ContributionsSelfCheck.checkForUpdatableLibraries());

Expand All @@ -50,7 +50,7 @@ public void testUpdatableLibrary() throws Exception {

sdLib = indexer.getIndex().getInstalled("SD").get();
assertTrue("SD lib is installed", sdLib.isLibraryInstalled());
assertEquals("SD installed version", "1.2.1", sdLib.getParsedVersion());
assertEquals("SD installed version", "1.2.1", sdLib.getVersion());

assertFalse(ContributionsSelfCheck.checkForUpdatableLibraries());
}
Expand All @@ -68,7 +68,7 @@ public void testUpdatableLibraryWithBundled() throws Exception {

ContributedLibrary l = indexer.getIndex().getInstalled("Bridge").get();
assertTrue("Bridge lib is installed", l.isLibraryInstalled());
assertEquals("Bridge installed version", "1.6.3", l.getParsedVersion());
assertEquals("Bridge installed version", "1.6.3", l.getVersion());

assertTrue(ContributionsSelfCheck.checkForUpdatableLibraries());

Expand All @@ -77,7 +77,7 @@ public void testUpdatableLibraryWithBundled() throws Exception {

l = indexer.getIndex().getInstalled("Bridge").get();
assertTrue("Bridge lib is installed", l.isLibraryInstalled());
assertEquals("Bridge installed version", "1.7.0", l.getParsedVersion());
assertEquals("Bridge installed version", "1.7.0", l.getVersion());

assertFalse(ContributionsSelfCheck.checkForUpdatableLibraries());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ public static ContributedLibrary max(ContributedLibrary a, ContributedLibrary b)
}

public static boolean greaterThan(ContributedLibrary a, ContributedLibrary b) {
return greaterThan(a.getParsedVersion(), b.getParsedVersion());
return greaterThan(a.getVersion(), b.getVersion());
}

public static int compareTo(ContributedLibrary a, ContributedLibrary b) {
return compareTo(a.getParsedVersion(), b.getParsedVersion());
return compareTo(a.getVersion(), b.getVersion());
}
}
Loading