mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-14 11:29:26 +01:00
Rename ContributeLibrary and ContributeLibraryReleases
the classes have been renamed as: ContributedLibrary -> ContributedLibraryRelease ContributedLibraryReleases -> ContributedLibrary The reason is that a ContributedLibrary will have a name and a list of releases, each one containing the relative metadata. The changes to reflect that will be made in the next commits.
This commit is contained in:
parent
9500b34719
commit
310a5df5e1
@ -33,11 +33,11 @@ import java.util.List;
|
|||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import cc.arduino.contributions.VersionComparator;
|
import cc.arduino.contributions.VersionComparator;
|
||||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
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<ContributedLibrary> {
|
public class UpdatableLibraryPredicate implements Predicate<ContributedLibraryRelease> {
|
||||||
|
|
||||||
LibrariesIndexer librariesIndexer;
|
LibrariesIndexer librariesIndexer;
|
||||||
|
|
||||||
@ -50,13 +50,13 @@ public class UpdatableLibraryPredicate implements Predicate<ContributedLibrary>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(ContributedLibrary lib) {
|
public boolean test(ContributedLibraryRelease lib) {
|
||||||
if (!lib.isLibraryInstalled()) {
|
if (!lib.isLibraryInstalled()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String libraryName = lib.getName();
|
String libraryName = lib.getName();
|
||||||
List<ContributedLibrary> libraries = librariesIndexer.getIndex().find(libraryName);
|
List<ContributedLibraryRelease> libraries = librariesIndexer.getIndex().find(libraryName);
|
||||||
ContributedLibrary latest = libraries.stream().reduce(VersionComparator::max).get();
|
ContributedLibraryRelease latest = libraries.stream().reduce(VersionComparator::max).get();
|
||||||
return !latest.isLibraryInstalled();
|
return !latest.isLibraryInstalled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,14 +29,14 @@
|
|||||||
|
|
||||||
package cc.arduino.contributions.libraries.ui;
|
package cc.arduino.contributions.libraries.ui;
|
||||||
|
|
||||||
|
import cc.arduino.contributions.libraries.ContributedLibraryRelease;
|
||||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||||
import cc.arduino.contributions.libraries.ContributedLibraryReleases;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
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<ContributedLibraryReleases> {
|
public class ContributedLibraryReleasesComparator implements Comparator<ContributedLibrary> {
|
||||||
|
|
||||||
private final String firstType;
|
private final String firstType;
|
||||||
|
|
||||||
@ -45,9 +45,9 @@ public class ContributedLibraryReleasesComparator implements Comparator<Contribu
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(ContributedLibraryReleases o1, ContributedLibraryReleases o2) {
|
public int compare(ContributedLibrary o1, ContributedLibrary o2) {
|
||||||
ContributedLibrary lib1 = o1.getLatest();
|
ContributedLibraryRelease lib1 = o1.getLatest();
|
||||||
ContributedLibrary lib2 = o2.getLatest();
|
ContributedLibraryRelease lib2 = o2.getLatest();
|
||||||
|
|
||||||
List<String> types1 = lib1.getTypes();
|
List<String> types1 = lib1.getTypes();
|
||||||
List<String> types2 = lib2.getTypes();
|
List<String> types2 = lib2.getTypes();
|
||||||
@ -66,7 +66,7 @@ public class ContributedLibraryReleasesComparator implements Comparator<Contribu
|
|||||||
return compareName(lib1, lib2);
|
return compareName(lib1, lib2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int compareName(ContributedLibrary lib1, ContributedLibrary lib2) {
|
private int compareName(ContributedLibraryRelease lib1, ContributedLibraryRelease lib2) {
|
||||||
return lib1.getName().compareToIgnoreCase(lib2.getName());
|
return lib1.getName().compareToIgnoreCase(lib2.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,15 +43,15 @@ 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.ContributedLibraryReleases;
|
|
||||||
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 ContributedLibraryReleases editorValue;
|
private ContributedLibrary editorValue;
|
||||||
private ContributedLibraryTableCellJPanel editorCell;
|
private ContributedLibraryTableCellJPanel editorCell;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -63,7 +63,7 @@ public class ContributedLibraryTableCellEditor extends InstallerTableCell {
|
|||||||
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 = (ContributedLibraryReleases) value;
|
editorValue = (ContributedLibrary) value;
|
||||||
|
|
||||||
editorCell = new ContributedLibraryTableCellJPanel(table, value, true);
|
editorCell = new ContributedLibraryTableCellJPanel(table, value, true);
|
||||||
editorCell.installButton
|
editorCell.installButton
|
||||||
@ -71,11 +71,11 @@ public class ContributedLibraryTableCellEditor extends InstallerTableCell {
|
|||||||
editorValue.getInstalled()));
|
editorValue.getInstalled()));
|
||||||
editorCell.downgradeButton.addActionListener(e -> {
|
editorCell.downgradeButton.addActionListener(e -> {
|
||||||
JComboBox chooser = editorCell.downgradeChooser;
|
JComboBox chooser = editorCell.downgradeChooser;
|
||||||
ContributedLibrary lib = (ContributedLibrary) chooser.getSelectedItem();
|
ContributedLibraryRelease lib = (ContributedLibraryRelease) chooser.getSelectedItem();
|
||||||
onInstall(lib, editorValue.getInstalled());
|
onInstall(lib, editorValue.getInstalled());
|
||||||
});
|
});
|
||||||
editorCell.versionToInstallChooser.addActionListener(e -> {
|
editorCell.versionToInstallChooser.addActionListener(e -> {
|
||||||
editorValue.select((ContributedLibrary) editorCell.versionToInstallChooser.getSelectedItem());
|
editorValue.select((ContributedLibraryRelease) editorCell.versionToInstallChooser.getSelectedItem());
|
||||||
if (editorCell.versionToInstallChooser.getSelectedIndex() != 0) {
|
if (editorCell.versionToInstallChooser.getSelectedIndex() != 0) {
|
||||||
InstallerTableCell.dropdownSelected(true);
|
InstallerTableCell.dropdownSelected(true);
|
||||||
}
|
}
|
||||||
@ -83,10 +83,10 @@ public class ContributedLibraryTableCellEditor extends InstallerTableCell {
|
|||||||
|
|
||||||
setEnabled(true);
|
setEnabled(true);
|
||||||
|
|
||||||
final Optional<ContributedLibrary> mayInstalled = editorValue.getInstalled();
|
final Optional<ContributedLibraryRelease> mayInstalled = editorValue.getInstalled();
|
||||||
|
|
||||||
List<ContributedLibrary> releases = editorValue.getReleases();
|
List<ContributedLibraryRelease> releases = editorValue.getReleases();
|
||||||
List<ContributedLibrary> notInstalled = new LinkedList<>(releases);
|
List<ContributedLibraryRelease> notInstalled = new LinkedList<>(releases);
|
||||||
if (mayInstalled.isPresent()) {
|
if (mayInstalled.isPresent()) {
|
||||||
notInstalled.remove(editorValue.getInstalled().get());
|
notInstalled.remove(editorValue.getInstalled().get());
|
||||||
}
|
}
|
||||||
@ -97,8 +97,8 @@ public class ContributedLibraryTableCellEditor extends InstallerTableCell {
|
|||||||
editorCell.downgradeChooser.removeAllItems();
|
editorCell.downgradeChooser.removeAllItems();
|
||||||
editorCell.downgradeChooser.addItem(tr("Select version"));
|
editorCell.downgradeChooser.addItem(tr("Select version"));
|
||||||
|
|
||||||
final List<ContributedLibrary> notInstalledPrevious = new LinkedList<>();
|
final List<ContributedLibraryRelease> notInstalledPrevious = new LinkedList<>();
|
||||||
final List<ContributedLibrary> notInstalledNewer = new LinkedList<>();
|
final List<ContributedLibraryRelease> notInstalledNewer = new LinkedList<>();
|
||||||
|
|
||||||
notInstalled.stream().forEach(input -> {
|
notInstalled.stream().forEach(input -> {
|
||||||
if (!mayInstalled.isPresent()
|
if (!mayInstalled.isPresent()
|
||||||
@ -139,12 +139,12 @@ public class ContributedLibraryTableCellEditor extends InstallerTableCell {
|
|||||||
editorCell.statusLabel.setText(status);
|
editorCell.statusLabel.setText(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onRemove(ContributedLibrary selected) {
|
protected void onRemove(ContributedLibraryRelease selected) {
|
||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onInstall(ContributedLibrary selected,
|
protected void onInstall(ContributedLibraryRelease selected,
|
||||||
Optional<ContributedLibrary> mayInstalled) {
|
Optional<ContributedLibraryRelease> mayInstalled) {
|
||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@ import javax.swing.text.html.HTMLDocument;
|
|||||||
import javax.swing.text.html.StyleSheet;
|
import javax.swing.text.html.StyleSheet;
|
||||||
|
|
||||||
import cc.arduino.contributions.DownloadableContributionVersionComparator;
|
import cc.arduino.contributions.DownloadableContributionVersionComparator;
|
||||||
|
import cc.arduino.contributions.libraries.ContributedLibraryRelease;
|
||||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||||
import cc.arduino.contributions.libraries.ContributedLibraryReleases;
|
|
||||||
import cc.arduino.contributions.ui.InstallerTableCell;
|
import cc.arduino.contributions.ui.InstallerTableCell;
|
||||||
import processing.app.Base;
|
import processing.app.Base;
|
||||||
import processing.app.PreferencesData;
|
import processing.app.PreferencesData;
|
||||||
@ -119,15 +119,15 @@ public class ContributedLibraryTableCellJPanel extends JPanel {
|
|||||||
|
|
||||||
add(Box.createVerticalStrut(15));
|
add(Box.createVerticalStrut(15));
|
||||||
|
|
||||||
ContributedLibraryReleases releases = (ContributedLibraryReleases) value;
|
ContributedLibrary releases = (ContributedLibrary) value;
|
||||||
|
|
||||||
// FIXME: happens on macosx, don't know why
|
// FIXME: happens on macosx, don't know why
|
||||||
if (releases == null)
|
if (releases == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ContributedLibrary selected = releases.getSelected();
|
ContributedLibraryRelease selected = releases.getSelected();
|
||||||
titledBorder.setTitle(selected.getName());
|
titledBorder.setTitle(selected.getName());
|
||||||
Optional<ContributedLibrary> mayInstalled = releases.getInstalled();
|
Optional<ContributedLibraryRelease> mayInstalled = releases.getInstalled();
|
||||||
|
|
||||||
boolean installable, upgradable;
|
boolean installable, upgradable;
|
||||||
if (!mayInstalled.isPresent()) {
|
if (!mayInstalled.isPresent()) {
|
||||||
|
@ -29,21 +29,21 @@
|
|||||||
|
|
||||||
package cc.arduino.contributions.libraries.ui;
|
package cc.arduino.contributions.libraries.ui;
|
||||||
|
|
||||||
import cc.arduino.contributions.libraries.ContributedLibraryReleases;
|
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||||
import cc.arduino.contributions.ui.DropdownItem;
|
import cc.arduino.contributions.ui.DropdownItem;
|
||||||
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import static processing.app.I18n.tr;
|
import static processing.app.I18n.tr;
|
||||||
|
|
||||||
public class DropdownAllLibraries implements DropdownItem<ContributedLibraryReleases> {
|
public class DropdownAllLibraries implements DropdownItem<ContributedLibrary> {
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return tr("All");
|
return tr("All");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Predicate<ContributedLibraryReleases> getFilterPredicate() {
|
public Predicate<ContributedLibrary> getFilterPredicate() {
|
||||||
return x -> true;
|
return x -> true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,20 +33,20 @@ import static processing.app.I18n.tr;
|
|||||||
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import cc.arduino.contributions.libraries.ContributedLibraryReleases;
|
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||||
import cc.arduino.contributions.ui.DropdownItem;
|
import cc.arduino.contributions.ui.DropdownItem;
|
||||||
|
|
||||||
public class DropdownInstalledLibraryItem implements DropdownItem<ContributedLibraryReleases> {
|
public class DropdownInstalledLibraryItem implements DropdownItem<ContributedLibrary> {
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return tr("Installed");
|
return tr("Installed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Predicate<ContributedLibraryReleases> getFilterPredicate() {
|
public Predicate<ContributedLibrary> getFilterPredicate() {
|
||||||
return new Predicate<ContributedLibraryReleases>() {
|
return new Predicate<ContributedLibrary>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean test(ContributedLibraryReleases t) {
|
public boolean test(ContributedLibrary t) {
|
||||||
return t.getInstalled().isPresent();
|
return t.getInstalled().isPresent();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -29,15 +29,15 @@
|
|||||||
|
|
||||||
package cc.arduino.contributions.libraries.ui;
|
package cc.arduino.contributions.libraries.ui;
|
||||||
|
|
||||||
|
import cc.arduino.contributions.libraries.ContributedLibraryRelease;
|
||||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||||
import cc.arduino.contributions.libraries.ContributedLibraryReleases;
|
|
||||||
import cc.arduino.contributions.ui.DropdownItem;
|
import cc.arduino.contributions.ui.DropdownItem;
|
||||||
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import static processing.app.I18n.tr;
|
import static processing.app.I18n.tr;
|
||||||
|
|
||||||
public class DropdownLibraryOfCategoryItem implements DropdownItem<ContributedLibraryReleases> {
|
public class DropdownLibraryOfCategoryItem implements DropdownItem<ContributedLibrary> {
|
||||||
|
|
||||||
private final String category;
|
private final String category;
|
||||||
|
|
||||||
@ -50,11 +50,11 @@ public class DropdownLibraryOfCategoryItem implements DropdownItem<ContributedLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Predicate<ContributedLibraryReleases> getFilterPredicate() {
|
public Predicate<ContributedLibrary> getFilterPredicate() {
|
||||||
return new Predicate<ContributedLibraryReleases>() {
|
return new Predicate<ContributedLibrary>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean test(ContributedLibraryReleases rel) {
|
public boolean test(ContributedLibrary rel) {
|
||||||
ContributedLibrary lib = rel.getLatest();
|
ContributedLibraryRelease lib = rel.getLatest();
|
||||||
return category.equals(lib.getCategory());
|
return category.equals(lib.getCategory());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
package cc.arduino.contributions.libraries.ui;
|
package cc.arduino.contributions.libraries.ui;
|
||||||
|
|
||||||
import cc.arduino.contributions.libraries.ContributedLibraryReleases;
|
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||||
import cc.arduino.contributions.ui.DropdownItem;
|
import cc.arduino.contributions.ui.DropdownItem;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -37,7 +37,7 @@ import java.util.function.Predicate;
|
|||||||
|
|
||||||
import static processing.app.I18n.tr;
|
import static processing.app.I18n.tr;
|
||||||
|
|
||||||
public class DropdownLibraryOfTypeItem implements DropdownItem<ContributedLibraryReleases> {
|
public class DropdownLibraryOfTypeItem implements DropdownItem<ContributedLibrary> {
|
||||||
|
|
||||||
private final String type;
|
private final String type;
|
||||||
|
|
||||||
@ -50,10 +50,10 @@ public class DropdownLibraryOfTypeItem implements DropdownItem<ContributedLibrar
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Predicate<ContributedLibraryReleases> getFilterPredicate() {
|
public Predicate<ContributedLibrary> getFilterPredicate() {
|
||||||
return new Predicate<ContributedLibraryReleases>() {
|
return new Predicate<ContributedLibrary>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean test(ContributedLibraryReleases lib) {
|
public boolean test(ContributedLibrary lib) {
|
||||||
List<String> types = lib.getLatest().getTypes();
|
List<String> types = lib.getLatest().getTypes();
|
||||||
return types != null && types.contains(type);
|
return types != null && types.contains(type);
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,8 @@
|
|||||||
|
|
||||||
package cc.arduino.contributions.libraries.ui;
|
package cc.arduino.contributions.libraries.ui;
|
||||||
|
|
||||||
|
import cc.arduino.contributions.libraries.ContributedLibraryRelease;
|
||||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||||
import cc.arduino.contributions.libraries.ContributedLibraryReleases;
|
|
||||||
import cc.arduino.contributions.ui.DropdownItem;
|
import cc.arduino.contributions.ui.DropdownItem;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -38,14 +38,14 @@ import java.util.function.Predicate;
|
|||||||
|
|
||||||
import static processing.app.I18n.tr;
|
import static processing.app.I18n.tr;
|
||||||
|
|
||||||
public class DropdownUpdatableLibrariesItem implements DropdownItem<ContributedLibraryReleases> {
|
public class DropdownUpdatableLibrariesItem implements DropdownItem<ContributedLibrary> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Predicate<ContributedLibraryReleases> getFilterPredicate() {
|
public Predicate<ContributedLibrary> getFilterPredicate() {
|
||||||
return new Predicate<ContributedLibraryReleases>() {
|
return new Predicate<ContributedLibrary>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean test(ContributedLibraryReleases lib) {
|
public boolean test(ContributedLibrary lib) {
|
||||||
Optional<ContributedLibrary> mayInstalled = lib.getInstalled();
|
Optional<ContributedLibraryRelease> mayInstalled = lib.getInstalled();
|
||||||
if (!mayInstalled.isPresent()) {
|
if (!mayInstalled.isPresent()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,8 @@
|
|||||||
|
|
||||||
package cc.arduino.contributions.libraries.ui;
|
package cc.arduino.contributions.libraries.ui;
|
||||||
|
|
||||||
|
import cc.arduino.contributions.libraries.ContributedLibraryRelease;
|
||||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||||
import cc.arduino.contributions.libraries.ContributedLibraryReleases;
|
|
||||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||||
import cc.arduino.contributions.ui.FilteredAbstractTableModel;
|
import cc.arduino.contributions.ui.FilteredAbstractTableModel;
|
||||||
import processing.app.BaseNoGui;
|
import processing.app.BaseNoGui;
|
||||||
@ -42,19 +42,19 @@ import java.util.function.Predicate;
|
|||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class LibrariesIndexTableModel
|
public class LibrariesIndexTableModel
|
||||||
extends FilteredAbstractTableModel<ContributedLibraryReleases> {
|
extends FilteredAbstractTableModel<ContributedLibrary> {
|
||||||
|
|
||||||
private final List<ContributedLibraryReleases> contributions = new ArrayList<>();
|
private final List<ContributedLibrary> contributions = new ArrayList<>();
|
||||||
|
|
||||||
private final String[] columnNames = { "Description" };
|
private final String[] columnNames = { "Description" };
|
||||||
|
|
||||||
private final Class<?>[] columnTypes = { ContributedPlatform.class };
|
private final Class<?>[] columnTypes = { ContributedPlatform.class };
|
||||||
|
|
||||||
Predicate<ContributedLibraryReleases> selectedCategoryFilter = null;
|
Predicate<ContributedLibrary> selectedCategoryFilter = null;
|
||||||
String selectedFilters[] = null;
|
String selectedFilters[] = null;
|
||||||
|
|
||||||
public void updateIndexFilter(String filters[],
|
public void updateIndexFilter(String filters[],
|
||||||
Predicate<ContributedLibraryReleases> additionalFilter) {
|
Predicate<ContributedLibrary> additionalFilter) {
|
||||||
selectedCategoryFilter = additionalFilter;
|
selectedCategoryFilter = additionalFilter;
|
||||||
selectedFilters = filters;
|
selectedFilters = filters;
|
||||||
update();
|
update();
|
||||||
@ -117,7 +117,7 @@ public class LibrariesIndexTableModel
|
|||||||
if (row >= contributions.size()) {
|
if (row >= contributions.size()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ContributedLibraryReleases contribution = contributions.get(row);
|
ContributedLibrary contribution = contributions.get(row);
|
||||||
return contribution;// .getSelected();
|
return contribution;// .getSelected();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,11 +126,11 @@ public class LibrariesIndexTableModel
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContributedLibraryReleases getReleases(int row) {
|
public ContributedLibrary getReleases(int row) {
|
||||||
return contributions.get(row);
|
return contributions.get(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContributedLibrary getSelectedRelease(int row) {
|
public ContributedLibraryRelease getSelectedRelease(int row) {
|
||||||
return contributions.get(row).getSelected();
|
return contributions.get(row).getSelected();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,12 +139,12 @@ public class LibrariesIndexTableModel
|
|||||||
fireTableDataChanged();
|
fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean filterCondition(ContributedLibraryReleases lib) {
|
private boolean filterCondition(ContributedLibrary lib) {
|
||||||
if (selectedCategoryFilter != null && !selectedCategoryFilter.test(lib)) {
|
if (selectedCategoryFilter != null && !selectedCategoryFilter.test(lib)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ContributedLibrary latest = lib.getLatest();
|
ContributedLibraryRelease latest = lib.getLatest();
|
||||||
String compoundTargetSearchText = latest.getName() + " "
|
String compoundTargetSearchText = latest.getName() + " "
|
||||||
+ latest.getParagraph() + " "
|
+ latest.getParagraph() + " "
|
||||||
+ latest.getSentence();
|
+ latest.getSentence();
|
||||||
@ -158,10 +158,10 @@ public class LibrariesIndexTableModel
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateLibrary(ContributedLibrary lib) {
|
public void updateLibrary(ContributedLibraryRelease lib) {
|
||||||
// Find the row interested in the change
|
// Find the row interested in the change
|
||||||
int row = -1;
|
int row = -1;
|
||||||
for (ContributedLibraryReleases releases : contributions) {
|
for (ContributedLibrary releases : contributions) {
|
||||||
if (releases.shouldContain(lib))
|
if (releases.shouldContain(lib))
|
||||||
row = contributions.indexOf(releases);
|
row = contributions.indexOf(releases);
|
||||||
}
|
}
|
||||||
@ -170,7 +170,7 @@ public class LibrariesIndexTableModel
|
|||||||
|
|
||||||
// If the library is found in the list send update event
|
// If the library is found in the list send update event
|
||||||
// or insert event on the specific row...
|
// or insert event on the specific row...
|
||||||
for (ContributedLibraryReleases releases : contributions) {
|
for (ContributedLibrary releases : contributions) {
|
||||||
if (releases.shouldContain(lib)) {
|
if (releases.shouldContain(lib)) {
|
||||||
if (row == -1) {
|
if (row == -1) {
|
||||||
row = contributions.indexOf(releases);
|
row = contributions.indexOf(releases);
|
||||||
@ -185,24 +185,24 @@ public class LibrariesIndexTableModel
|
|||||||
fireTableRowsDeleted(row, row);
|
fireTableRowsDeleted(row, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ContributedLibraryReleases> rebuildContributionsFromIndex() {
|
private List<ContributedLibrary> rebuildContributionsFromIndex() {
|
||||||
List<ContributedLibraryReleases> res = new ArrayList<>();
|
List<ContributedLibrary> res = new ArrayList<>();
|
||||||
BaseNoGui.librariesIndexer.getIndex().getLibraries(). //
|
BaseNoGui.librariesIndexer.getIndex().getLibraries(). //
|
||||||
forEach(lib -> {
|
forEach(lib -> {
|
||||||
for (ContributedLibraryReleases contribution : res) {
|
for (ContributedLibrary contribution : res) {
|
||||||
if (!contribution.shouldContain(lib))
|
if (!contribution.shouldContain(lib))
|
||||||
continue;
|
continue;
|
||||||
contribution.add(lib);
|
contribution.add(lib);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.add(new ContributedLibraryReleases(lib));
|
res.add(new ContributedLibrary(lib));
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateContributions() {
|
private void updateContributions() {
|
||||||
List<ContributedLibraryReleases> all = rebuildContributionsFromIndex();
|
List<ContributedLibrary> all = rebuildContributionsFromIndex();
|
||||||
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,
|
||||||
|
@ -48,8 +48,8 @@ import javax.swing.JLabel;
|
|||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.table.TableCellRenderer;
|
import javax.swing.table.TableCellRenderer;
|
||||||
|
|
||||||
|
import cc.arduino.contributions.libraries.ContributedLibraryRelease;
|
||||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||||
import cc.arduino.contributions.libraries.ContributedLibraryReleases;
|
|
||||||
import cc.arduino.contributions.libraries.LibraryInstaller;
|
import cc.arduino.contributions.libraries.LibraryInstaller;
|
||||||
import cc.arduino.contributions.libraries.LibraryTypeComparator;
|
import cc.arduino.contributions.libraries.LibraryTypeComparator;
|
||||||
import cc.arduino.contributions.libraries.ui.MultiLibraryInstallDialog.Result;
|
import cc.arduino.contributions.libraries.ui.MultiLibraryInstallDialog.Result;
|
||||||
@ -62,7 +62,7 @@ import cc.arduino.utils.Progress;
|
|||||||
import processing.app.BaseNoGui;
|
import processing.app.BaseNoGui;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryReleases> {
|
public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
||||||
|
|
||||||
private final JComboBox typeChooser;
|
private final JComboBox typeChooser;
|
||||||
private final LibraryInstaller installer;
|
private final LibraryInstaller installer;
|
||||||
@ -85,7 +85,7 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
|
|||||||
protected InstallerTableCell createCellEditor() {
|
protected InstallerTableCell createCellEditor() {
|
||||||
return new ContributedLibraryTableCellEditor() {
|
return new ContributedLibraryTableCellEditor() {
|
||||||
@Override
|
@Override
|
||||||
protected void onInstall(ContributedLibrary selectedLibrary, Optional<ContributedLibrary> mayInstalledLibrary) {
|
protected void onInstall(ContributedLibraryRelease selectedLibrary, Optional<ContributedLibraryRelease> mayInstalledLibrary) {
|
||||||
if (mayInstalledLibrary.isPresent() && selectedLibrary.isIDEBuiltIn()) {
|
if (mayInstalledLibrary.isPresent() && selectedLibrary.isIDEBuiltIn()) {
|
||||||
onRemovePressed(mayInstalledLibrary.get());
|
onRemovePressed(mayInstalledLibrary.get());
|
||||||
} else {
|
} else {
|
||||||
@ -94,7 +94,7 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onRemove(ContributedLibrary library) {
|
protected void onRemove(ContributedLibraryRelease library) {
|
||||||
onRemovePressed(library);
|
onRemovePressed(library);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -120,7 +120,7 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
|
|||||||
protected final ActionListener typeChooserActionListener = new ActionListener() {
|
protected final ActionListener typeChooserActionListener = new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
DropdownItem<ContributedLibraryReleases> selected = (DropdownItem<ContributedLibraryReleases>) typeChooser.getSelectedItem();
|
DropdownItem<ContributedLibrary> selected = (DropdownItem<ContributedLibrary>) typeChooser.getSelectedItem();
|
||||||
previousRowAtPoint = -1;
|
previousRowAtPoint = -1;
|
||||||
if (selected != null && extraFilter != selected.getFilterPredicate()) {
|
if (selected != null && extraFilter != selected.getFilterPredicate()) {
|
||||||
extraFilter = selected.getFilterPredicate();
|
extraFilter = selected.getFilterPredicate();
|
||||||
@ -217,8 +217,8 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
|
|||||||
installerThread.start();
|
installerThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onInstallPressed(final ContributedLibrary lib) {
|
public void onInstallPressed(final ContributedLibraryRelease lib) {
|
||||||
List<ContributedLibrary> deps = BaseNoGui.librariesIndexer.getIndex().resolveDependeciesOf(lib);
|
List<ContributedLibraryRelease> deps = BaseNoGui.librariesIndexer.getIndex().resolveDependeciesOf(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) {
|
||||||
@ -257,7 +257,7 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
|
|||||||
installerThread.start();
|
installerThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onRemovePressed(final ContributedLibrary lib) {
|
public void onRemovePressed(final ContributedLibraryRelease lib) {
|
||||||
boolean managedByIndex = BaseNoGui.librariesIndexer.getIndex().getLibraries().contains(lib);
|
boolean managedByIndex = BaseNoGui.librariesIndexer.getIndex().getLibraries().contains(lib);
|
||||||
|
|
||||||
if (!managedByIndex) {
|
if (!managedByIndex) {
|
||||||
|
@ -51,7 +51,7 @@ import javax.swing.text.Document;
|
|||||||
import javax.swing.text.html.HTMLDocument;
|
import javax.swing.text.html.HTMLDocument;
|
||||||
import javax.swing.text.html.StyleSheet;
|
import javax.swing.text.html.StyleSheet;
|
||||||
|
|
||||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
import cc.arduino.contributions.libraries.ContributedLibraryRelease;
|
||||||
import cc.arduino.contributions.libraries.UnavailableContributedLibrary;
|
import cc.arduino.contributions.libraries.UnavailableContributedLibrary;
|
||||||
import processing.app.Base;
|
import processing.app.Base;
|
||||||
import processing.app.Theme;
|
import processing.app.Theme;
|
||||||
@ -64,8 +64,8 @@ public class MultiLibraryInstallDialog extends JDialog {
|
|||||||
|
|
||||||
private Result result = Result.CANCEL;
|
private Result result = Result.CANCEL;
|
||||||
|
|
||||||
public MultiLibraryInstallDialog(Window parent, ContributedLibrary lib,
|
public MultiLibraryInstallDialog(Window parent, ContributedLibraryRelease lib,
|
||||||
List<ContributedLibrary> dependencies) {
|
List<ContributedLibraryRelease> dependencies) {
|
||||||
super(parent, format(tr("Dependencies for library {0}:{1}"), lib.getName(),
|
super(parent, format(tr("Dependencies for library {0}:{1}"), lib.getName(),
|
||||||
lib.getParsedVersion()),
|
lib.getParsedVersion()),
|
||||||
ModalityType.APPLICATION_MODAL);
|
ModalityType.APPLICATION_MODAL);
|
||||||
@ -115,7 +115,7 @@ public class MultiLibraryInstallDialog extends JDialog {
|
|||||||
String desc = format(tr("The library {0} needs some other library<br />dependencies currently not installed:"),
|
String desc = format(tr("The library {0} needs some other library<br />dependencies currently not installed:"),
|
||||||
libName);
|
libName);
|
||||||
desc += "<br/><br/>";
|
desc += "<br/><br/>";
|
||||||
for (ContributedLibrary l : dependencies) {
|
for (ContributedLibraryRelease l : dependencies) {
|
||||||
if (l.getName().equals(lib.getName()))
|
if (l.getName().equals(lib.getName()))
|
||||||
continue;
|
continue;
|
||||||
if (l.getInstalledLibrary().isPresent())
|
if (l.getInstalledLibrary().isPresent())
|
||||||
|
@ -27,7 +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.LibrariesIndexer;
|
import cc.arduino.contributions.libraries.LibrariesIndexer;
|
||||||
import cc.arduino.contributions.libraries.LibraryInstaller;
|
import cc.arduino.contributions.libraries.LibraryInstaller;
|
||||||
import cc.arduino.contributions.libraries.LibraryOfSameTypeComparator;
|
import cc.arduino.contributions.libraries.LibraryOfSameTypeComparator;
|
||||||
@ -368,7 +368,7 @@ public class Base {
|
|||||||
for (String library : parser.getLibraryToInstall().split(",")) {
|
for (String library : parser.getLibraryToInstall().split(",")) {
|
||||||
String[] libraryToInstallParts = library.split(":");
|
String[] libraryToInstallParts = library.split(":");
|
||||||
|
|
||||||
ContributedLibrary selected = null;
|
ContributedLibraryRelease selected = null;
|
||||||
if (libraryToInstallParts.length == 2) {
|
if (libraryToInstallParts.length == 2) {
|
||||||
Optional<Version> version = VersionHelper.valueOf(libraryToInstallParts[1]);
|
Optional<Version> version = VersionHelper.valueOf(libraryToInstallParts[1]);
|
||||||
if (!version.isPresent()) {
|
if (!version.isPresent()) {
|
||||||
@ -377,7 +377,7 @@ public class Base {
|
|||||||
}
|
}
|
||||||
selected = indexer.getIndex().find(libraryToInstallParts[0], version.get().toString());
|
selected = indexer.getIndex().find(libraryToInstallParts[0], version.get().toString());
|
||||||
} else if (libraryToInstallParts.length == 1) {
|
} else if (libraryToInstallParts.length == 1) {
|
||||||
List<ContributedLibrary> librariesByName = indexer.getIndex().find(libraryToInstallParts[0]);
|
List<ContributedLibraryRelease> librariesByName = indexer.getIndex().find(libraryToInstallParts[0]);
|
||||||
Collections.sort(librariesByName, new DownloadableContributionVersionComparator());
|
Collections.sort(librariesByName, new DownloadableContributionVersionComparator());
|
||||||
if (!librariesByName.isEmpty()) {
|
if (!librariesByName.isEmpty()) {
|
||||||
selected = librariesByName.get(librariesByName.size() - 1);
|
selected = librariesByName.get(librariesByName.size() - 1);
|
||||||
@ -388,7 +388,7 @@ public class Base {
|
|||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<ContributedLibrary> mayInstalled = indexer.getIndex().getInstalled(libraryToInstallParts[0]);
|
Optional<ContributedLibraryRelease> mayInstalled = indexer.getIndex().getInstalled(libraryToInstallParts[0]);
|
||||||
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...",
|
||||||
|
@ -10,7 +10,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
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;
|
||||||
import processing.app.packages.UserLibraryFolder;
|
import processing.app.packages.UserLibraryFolder;
|
||||||
@ -38,7 +38,7 @@ public class UpdatableLibraryTest {
|
|||||||
indexer.parseIndex();
|
indexer.parseIndex();
|
||||||
indexer.setLibrariesFoldersAndRescan(folders);
|
indexer.setLibrariesFoldersAndRescan(folders);
|
||||||
|
|
||||||
ContributedLibrary sdLib = indexer.getIndex().getInstalled("SD").get();
|
ContributedLibraryRelease sdLib = indexer.getIndex().getInstalled("SD").get();
|
||||||
assertTrue("SD lib is installed", sdLib.isLibraryInstalled());
|
assertTrue("SD lib is installed", sdLib.isLibraryInstalled());
|
||||||
assertEquals("SD installed version", "1.1.1", sdLib.getParsedVersion());
|
assertEquals("SD installed version", "1.1.1", sdLib.getParsedVersion());
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ public class UpdatableLibraryTest {
|
|||||||
indexer.parseIndex();
|
indexer.parseIndex();
|
||||||
indexer.setLibrariesFoldersAndRescan(folders);
|
indexer.setLibrariesFoldersAndRescan(folders);
|
||||||
|
|
||||||
ContributedLibrary l = indexer.getIndex().getInstalled("Bridge").get();
|
ContributedLibraryRelease l = indexer.getIndex().getInstalled("Bridge").get();
|
||||||
assertTrue("Bridge lib is installed", l.isLibraryInstalled());
|
assertTrue("Bridge lib is installed", l.isLibraryInstalled());
|
||||||
assertEquals("Bridge installed version", "1.6.3", l.getParsedVersion());
|
assertEquals("Bridge installed version", "1.6.3", l.getParsedVersion());
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ package cc.arduino.contributions;
|
|||||||
|
|
||||||
import com.github.zafarkhaja.semver.Version;
|
import com.github.zafarkhaja.semver.Version;
|
||||||
|
|
||||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
import cc.arduino.contributions.libraries.ContributedLibraryRelease;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -70,15 +70,15 @@ public class VersionComparator implements Comparator<String> {
|
|||||||
return greaterThan(a, b) ? a : b;
|
return greaterThan(a, b) ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ContributedLibrary max(ContributedLibrary a, ContributedLibrary b) {
|
public static ContributedLibraryRelease max(ContributedLibraryRelease a, ContributedLibraryRelease b) {
|
||||||
return greaterThan(a, b) ? a : b;
|
return greaterThan(a, b) ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean greaterThan(ContributedLibrary a, ContributedLibrary b) {
|
public static boolean greaterThan(ContributedLibraryRelease a, ContributedLibraryRelease b) {
|
||||||
return greaterThan(a.getParsedVersion(), b.getParsedVersion());
|
return greaterThan(a.getParsedVersion(), b.getParsedVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int compareTo(ContributedLibrary a, ContributedLibrary b) {
|
public static int compareTo(ContributedLibraryRelease a, ContributedLibraryRelease b) {
|
||||||
return compareTo(a.getParsedVersion(), b.getParsedVersion());
|
return compareTo(a.getParsedVersion(), b.getParsedVersion());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Arduino.
|
* This file is part of Arduino.
|
||||||
*
|
*
|
||||||
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
|
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||||
*
|
*
|
||||||
* Arduino is free software; you can redistribute it and/or modify
|
* Arduino is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -29,195 +29,81 @@
|
|||||||
|
|
||||||
package cc.arduino.contributions.libraries;
|
package cc.arduino.contributions.libraries;
|
||||||
|
|
||||||
import cc.arduino.contributions.DownloadableContribution;
|
import cc.arduino.contributions.VersionComparator;
|
||||||
import processing.app.I18n;
|
import processing.app.packages.UserLibraryFolder.Location;
|
||||||
import processing.app.packages.UserLibrary;
|
|
||||||
import static processing.app.I18n.tr;
|
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.LinkedList;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import cc.arduino.contributions.VersionHelper;
|
public class ContributedLibrary {
|
||||||
|
|
||||||
public class ContributedLibrary extends DownloadableContribution {
|
private List<ContributedLibraryRelease> releases = new LinkedList<>();
|
||||||
|
private List<String> versions = new LinkedList<>();
|
||||||
|
private ContributedLibraryRelease latest = null;
|
||||||
|
private ContributedLibraryRelease selected = null;
|
||||||
|
|
||||||
private String url;
|
public ContributedLibrary(ContributedLibraryRelease release) {
|
||||||
private String version;
|
add(release);
|
||||||
private String checksum;
|
|
||||||
private long size;
|
|
||||||
private String archiveFileName;
|
|
||||||
private String name;
|
|
||||||
private String maintainer;
|
|
||||||
private String author;
|
|
||||||
private String website;
|
|
||||||
private String category;
|
|
||||||
private String licence;
|
|
||||||
private String paragraph;
|
|
||||||
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 String getVersion() { return version; }
|
|
||||||
|
|
||||||
public String getChecksum() { return checksum; }
|
|
||||||
|
|
||||||
public long getSize() { return size; }
|
|
||||||
|
|
||||||
public String getArchiveFileName() { return archiveFileName; }
|
|
||||||
|
|
||||||
public String getName() { return name; }
|
|
||||||
|
|
||||||
public String getMaintainer() { return maintainer; }
|
|
||||||
|
|
||||||
public String getAuthor() { return author; }
|
|
||||||
|
|
||||||
public String getWebsite() { return website; }
|
|
||||||
|
|
||||||
public String getCategory() { return category; }
|
|
||||||
|
|
||||||
public void setCategory(String category) { this.category = category; }
|
|
||||||
|
|
||||||
public String getLicense() { return licence; }
|
|
||||||
|
|
||||||
public String getParagraph() { return paragraph; }
|
|
||||||
|
|
||||||
public String getSentence() { return sentence; }
|
|
||||||
|
|
||||||
public List<String> getArchitectures() { return architectures; }
|
|
||||||
|
|
||||||
public List<String> getTypes() { return types; }
|
|
||||||
|
|
||||||
public List<ContributedLibraryDependency> getDependencies() { return dependencies; }
|
|
||||||
|
|
||||||
public List<String> getProvidesIncludes() { return providesIncludes; }
|
|
||||||
|
|
||||||
public static final Comparator<ContributedLibrary> CASE_INSENSITIVE_ORDER = (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName());
|
|
||||||
|
|
||||||
private Optional<UserLibrary> installedLib = Optional.empty();
|
|
||||||
|
|
||||||
public Optional<UserLibrary> getInstalledLibrary() {
|
|
||||||
return installedLib;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLibraryInstalled() {
|
public ContributedLibrary(List<ContributedLibraryRelease> releases) {
|
||||||
return installedLib.isPresent();
|
releases.forEach(this::add);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInstalledUserLibrary(UserLibrary installed) {
|
public List<ContributedLibraryRelease> getReleases() {
|
||||||
this.installedLib = Optional.of(installed);
|
return releases;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unsetInstalledUserLibrary() {
|
public boolean shouldContain(ContributedLibraryRelease release) {
|
||||||
installedLib = Optional.empty();
|
if (latest == null) {
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isIDEBuiltIn() {
|
|
||||||
if (!installedLib.isPresent()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return installedLib.get().isIDEBuiltIn();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns <b>true</b> if the library declares to support the specified
|
|
||||||
* architecture (through the "architectures" property field).
|
|
||||||
*
|
|
||||||
* @param reqArch
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean supportsArchitecture(String reqArch) {
|
|
||||||
return getArchitectures().contains(reqArch) || getArchitectures().contains("*");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns <b>true</b> if the library declares to support at least one of the
|
|
||||||
* specified architectures.
|
|
||||||
*
|
|
||||||
* @param reqArchs A List of architectures to check
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean supportsArchitecture(List<String> reqArchs) {
|
|
||||||
if (reqArchs.contains("*"))
|
|
||||||
return true;
|
return true;
|
||||||
for (String reqArch : reqArchs)
|
|
||||||
if (supportsArchitecture(reqArch))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return I18n.format(tr("Version {0}"), getParsedVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String info() {
|
|
||||||
String res = "";
|
|
||||||
res += " ContributedLibrary : " + getName() + "\n";
|
|
||||||
res += " author : " + getAuthor() + "\n";
|
|
||||||
res += " maintainer : " + getMaintainer() + "\n";
|
|
||||||
res += " version : " + getParsedVersion() + "\n";
|
|
||||||
res += " website : " + getUrl() + "\n";
|
|
||||||
res += " category : " + getCategory() + "\n";
|
|
||||||
res += " license : " + getLicense() + "\n";
|
|
||||||
res += " descrip : " + getSentence() + "\n";
|
|
||||||
if (getParagraph() != null && !getParagraph().isEmpty())
|
|
||||||
res += " " + getParagraph() + "\n";
|
|
||||||
res += " architectures : ";
|
|
||||||
if (getArchitectures() != null)
|
|
||||||
for (String a : getArchitectures()) {
|
|
||||||
res += a + ",";
|
|
||||||
}
|
|
||||||
res += "\n";
|
|
||||||
res += " requires :\n";
|
|
||||||
if (getDependencies() != null)
|
|
||||||
for (ContributedLibraryDependency r : getDependencies()) {
|
|
||||||
res += " " + r;
|
|
||||||
}
|
|
||||||
res += "\n";
|
|
||||||
|
|
||||||
// DownloadableContribution
|
|
||||||
res += super.toString();
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (!(obj instanceof ContributedLibrary)) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
ContributedLibrary other = (ContributedLibrary) obj;
|
return release.getName().equals(latest.getName());
|
||||||
String thisVersion = getParsedVersion();
|
|
||||||
String otherVersion = other.getParsedVersion();
|
|
||||||
|
|
||||||
boolean versionEquals = (thisVersion != null
|
|
||||||
&& thisVersion.equals(otherVersion));
|
|
||||||
|
|
||||||
// Important: for legacy libs, versions are null. Two legacy libs must
|
|
||||||
// always pass this test.
|
|
||||||
if (thisVersion == null && otherVersion == null)
|
|
||||||
versionEquals = true;
|
|
||||||
|
|
||||||
String thisName = getName();
|
|
||||||
String otherName = other.getName();
|
|
||||||
boolean nameEquals = thisName != null && thisName.equals(otherName);
|
|
||||||
|
|
||||||
return versionEquals && nameEquals;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBefore(ContributedLibrary other) {
|
public void add(ContributedLibraryRelease release) {
|
||||||
return VersionHelper.compare(getVersion(), other.getVersion()) < 0;
|
if (latest == null) {
|
||||||
|
latest = release;
|
||||||
|
}
|
||||||
|
releases.add(release);
|
||||||
|
String version = release.getParsedVersion();
|
||||||
|
if (version != null) {
|
||||||
|
versions.add(version);
|
||||||
|
}
|
||||||
|
if (VersionComparator.greaterThan(version, latest.getParsedVersion())) {
|
||||||
|
latest = release;
|
||||||
|
}
|
||||||
|
selected = latest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public Optional<ContributedLibraryRelease> getInstalled() {
|
||||||
public int hashCode() {
|
return releases.stream() //
|
||||||
String hashingData = "CONTRIBUTEDLIB" + getName() + getVersion();
|
.filter(ContributedLibraryRelease::isLibraryInstalled) //
|
||||||
return hashingData.hashCode();
|
.reduce((x, y) -> {
|
||||||
|
Location lx = x.getInstalledLibrary().get().getLocation();
|
||||||
|
Location ly = y.getInstalledLibrary().get().getLocation();
|
||||||
|
if (lx == ly) {
|
||||||
|
return VersionComparator.max(x, y);
|
||||||
|
}
|
||||||
|
return lx == Location.SKETCHBOOK ? x : y;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContributedLibraryRelease getLatest() {
|
||||||
|
return latest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContributedLibraryRelease getSelected() {
|
||||||
|
return selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void select(ContributedLibraryRelease lib) {
|
||||||
|
for (ContributedLibraryRelease r : releases) {
|
||||||
|
if (r == lib) {
|
||||||
|
selected = r;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,223 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Arduino.
|
||||||
|
*
|
||||||
|
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
|
||||||
|
*
|
||||||
|
* Arduino is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* As a special exception, you may use this file as part of a free software
|
||||||
|
* library without restriction. Specifically, if other files instantiate
|
||||||
|
* templates or use macros or inline functions from this file, or you compile
|
||||||
|
* this file and link it with other files to produce an executable, this
|
||||||
|
* file does not by itself cause the resulting executable to be covered by
|
||||||
|
* the GNU General Public License. This exception does not however
|
||||||
|
* invalidate any other reasons why the executable file might be covered by
|
||||||
|
* the GNU General Public License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cc.arduino.contributions.libraries;
|
||||||
|
|
||||||
|
import cc.arduino.contributions.DownloadableContribution;
|
||||||
|
import processing.app.I18n;
|
||||||
|
import processing.app.packages.UserLibrary;
|
||||||
|
import static processing.app.I18n.tr;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import cc.arduino.contributions.VersionHelper;
|
||||||
|
|
||||||
|
public class ContributedLibraryRelease extends DownloadableContribution {
|
||||||
|
|
||||||
|
private String url;
|
||||||
|
private String version;
|
||||||
|
private String checksum;
|
||||||
|
private long size;
|
||||||
|
private String archiveFileName;
|
||||||
|
private String name;
|
||||||
|
private String maintainer;
|
||||||
|
private String author;
|
||||||
|
private String website;
|
||||||
|
private String category;
|
||||||
|
private String licence;
|
||||||
|
private String paragraph;
|
||||||
|
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 String getVersion() { return version; }
|
||||||
|
|
||||||
|
public String getChecksum() { return checksum; }
|
||||||
|
|
||||||
|
public long getSize() { return size; }
|
||||||
|
|
||||||
|
public String getArchiveFileName() { return archiveFileName; }
|
||||||
|
|
||||||
|
public String getName() { return name; }
|
||||||
|
|
||||||
|
public String getMaintainer() { return maintainer; }
|
||||||
|
|
||||||
|
public String getAuthor() { return author; }
|
||||||
|
|
||||||
|
public String getWebsite() { return website; }
|
||||||
|
|
||||||
|
public String getCategory() { return category; }
|
||||||
|
|
||||||
|
public void setCategory(String category) { this.category = category; }
|
||||||
|
|
||||||
|
public String getLicense() { return licence; }
|
||||||
|
|
||||||
|
public String getParagraph() { return paragraph; }
|
||||||
|
|
||||||
|
public String getSentence() { return sentence; }
|
||||||
|
|
||||||
|
public List<String> getArchitectures() { return architectures; }
|
||||||
|
|
||||||
|
public List<String> getTypes() { return types; }
|
||||||
|
|
||||||
|
public List<ContributedLibraryDependency> getDependencies() { return dependencies; }
|
||||||
|
|
||||||
|
public List<String> getProvidesIncludes() { return providesIncludes; }
|
||||||
|
|
||||||
|
public static final Comparator<ContributedLibraryRelease> CASE_INSENSITIVE_ORDER = (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName());
|
||||||
|
|
||||||
|
private Optional<UserLibrary> installedLib = Optional.empty();
|
||||||
|
|
||||||
|
public Optional<UserLibrary> getInstalledLibrary() {
|
||||||
|
return installedLib;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLibraryInstalled() {
|
||||||
|
return installedLib.isPresent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInstalledUserLibrary(UserLibrary installed) {
|
||||||
|
this.installedLib = Optional.of(installed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsetInstalledUserLibrary() {
|
||||||
|
installedLib = Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isIDEBuiltIn() {
|
||||||
|
if (!installedLib.isPresent()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return installedLib.get().isIDEBuiltIn();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns <b>true</b> if the library declares to support the specified
|
||||||
|
* architecture (through the "architectures" property field).
|
||||||
|
*
|
||||||
|
* @param reqArch
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean supportsArchitecture(String reqArch) {
|
||||||
|
return getArchitectures().contains(reqArch) || getArchitectures().contains("*");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns <b>true</b> if the library declares to support at least one of the
|
||||||
|
* specified architectures.
|
||||||
|
*
|
||||||
|
* @param reqArchs A List of architectures to check
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean supportsArchitecture(List<String> reqArchs) {
|
||||||
|
if (reqArchs.contains("*"))
|
||||||
|
return true;
|
||||||
|
for (String reqArch : reqArchs)
|
||||||
|
if (supportsArchitecture(reqArch))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return I18n.format(tr("Version {0}"), getParsedVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String info() {
|
||||||
|
String res = "";
|
||||||
|
res += " ContributedLibrary : " + getName() + "\n";
|
||||||
|
res += " author : " + getAuthor() + "\n";
|
||||||
|
res += " maintainer : " + getMaintainer() + "\n";
|
||||||
|
res += " version : " + getParsedVersion() + "\n";
|
||||||
|
res += " website : " + getUrl() + "\n";
|
||||||
|
res += " category : " + getCategory() + "\n";
|
||||||
|
res += " license : " + getLicense() + "\n";
|
||||||
|
res += " descrip : " + getSentence() + "\n";
|
||||||
|
if (getParagraph() != null && !getParagraph().isEmpty())
|
||||||
|
res += " " + getParagraph() + "\n";
|
||||||
|
res += " architectures : ";
|
||||||
|
if (getArchitectures() != null)
|
||||||
|
for (String a : getArchitectures()) {
|
||||||
|
res += a + ",";
|
||||||
|
}
|
||||||
|
res += "\n";
|
||||||
|
res += " requires :\n";
|
||||||
|
if (getDependencies() != null)
|
||||||
|
for (ContributedLibraryDependency r : getDependencies()) {
|
||||||
|
res += " " + r;
|
||||||
|
}
|
||||||
|
res += "\n";
|
||||||
|
|
||||||
|
// DownloadableContribution
|
||||||
|
res += super.toString();
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (!(obj instanceof ContributedLibraryRelease)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ContributedLibraryRelease other = (ContributedLibraryRelease) obj;
|
||||||
|
String thisVersion = getParsedVersion();
|
||||||
|
String otherVersion = other.getParsedVersion();
|
||||||
|
|
||||||
|
boolean versionEquals = (thisVersion != null
|
||||||
|
&& thisVersion.equals(otherVersion));
|
||||||
|
|
||||||
|
// Important: for legacy libs, versions are null. Two legacy libs must
|
||||||
|
// always pass this test.
|
||||||
|
if (thisVersion == null && otherVersion == null)
|
||||||
|
versionEquals = true;
|
||||||
|
|
||||||
|
String thisName = getName();
|
||||||
|
String otherName = other.getName();
|
||||||
|
boolean nameEquals = thisName != null && thisName.equals(otherName);
|
||||||
|
|
||||||
|
return versionEquals && nameEquals;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBefore(ContributedLibraryRelease other) {
|
||||||
|
return VersionHelper.compare(getVersion(), other.getVersion()) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
String hashingData = "CONTRIBUTEDLIB" + getName() + getVersion();
|
||||||
|
return hashingData.hashCode();
|
||||||
|
}
|
||||||
|
}
|
@ -1,109 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Arduino.
|
|
||||||
*
|
|
||||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
|
||||||
*
|
|
||||||
* Arduino is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*
|
|
||||||
* As a special exception, you may use this file as part of a free software
|
|
||||||
* library without restriction. Specifically, if other files instantiate
|
|
||||||
* templates or use macros or inline functions from this file, or you compile
|
|
||||||
* this file and link it with other files to produce an executable, this
|
|
||||||
* file does not by itself cause the resulting executable to be covered by
|
|
||||||
* the GNU General Public License. This exception does not however
|
|
||||||
* invalidate any other reasons why the executable file might be covered by
|
|
||||||
* the GNU General Public License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package cc.arduino.contributions.libraries;
|
|
||||||
|
|
||||||
import cc.arduino.contributions.VersionComparator;
|
|
||||||
import processing.app.packages.UserLibraryFolder.Location;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class ContributedLibraryReleases {
|
|
||||||
|
|
||||||
private List<ContributedLibrary> releases = new LinkedList<>();
|
|
||||||
private List<String> versions = new LinkedList<>();
|
|
||||||
private ContributedLibrary latest = null;
|
|
||||||
private ContributedLibrary selected = null;
|
|
||||||
|
|
||||||
public ContributedLibraryReleases(ContributedLibrary library) {
|
|
||||||
add(library);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContributedLibraryReleases(List<ContributedLibrary> libraries) {
|
|
||||||
libraries.forEach(this::add);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ContributedLibrary> getReleases() {
|
|
||||||
return releases;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean shouldContain(ContributedLibrary lib) {
|
|
||||||
if (latest == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return lib.getName().equals(latest.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(ContributedLibrary library) {
|
|
||||||
if (latest == null) {
|
|
||||||
latest = library;
|
|
||||||
}
|
|
||||||
releases.add(library);
|
|
||||||
String version = library.getParsedVersion();
|
|
||||||
if (version != null) {
|
|
||||||
versions.add(version);
|
|
||||||
}
|
|
||||||
if (VersionComparator.greaterThan(version, latest.getParsedVersion())) {
|
|
||||||
latest = library;
|
|
||||||
}
|
|
||||||
selected = latest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<ContributedLibrary> getInstalled() {
|
|
||||||
return releases.stream() //
|
|
||||||
.filter(ContributedLibrary::isLibraryInstalled) //
|
|
||||||
.reduce((x, y) -> {
|
|
||||||
Location lx = x.getInstalledLibrary().get().getLocation();
|
|
||||||
Location ly = y.getInstalledLibrary().get().getLocation();
|
|
||||||
if (lx == ly) {
|
|
||||||
return VersionComparator.max(x, y);
|
|
||||||
}
|
|
||||||
return lx == Location.SKETCHBOOK ? x : y;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContributedLibrary getLatest() {
|
|
||||||
return latest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContributedLibrary getSelected() {
|
|
||||||
return selected;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void select(ContributedLibrary lib) {
|
|
||||||
for (ContributedLibrary r : releases) {
|
|
||||||
if (r == lib) {
|
|
||||||
selected = r;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -42,23 +42,23 @@ import cc.arduino.contributions.VersionComparator;
|
|||||||
|
|
||||||
public class LibrariesIndex {
|
public class LibrariesIndex {
|
||||||
|
|
||||||
private ArrayList<ContributedLibrary> list = new ArrayList<>();
|
private ArrayList<ContributedLibraryRelease> list = new ArrayList<>();
|
||||||
|
|
||||||
public List<ContributedLibrary> getLibraries() {
|
public List<ContributedLibraryRelease> getLibraries() {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ContributedLibrary> find(final String name) {
|
public List<ContributedLibraryRelease> find(final String name) {
|
||||||
return getLibraries().stream() //
|
return getLibraries().stream() //
|
||||||
.filter(l -> name.equals(l.getName())) //
|
.filter(l -> name.equals(l.getName())) //
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContributedLibrary find(String name, String version) {
|
public ContributedLibraryRelease find(String name, String version) {
|
||||||
if (name == null || version == null) {
|
if (name == null || version == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (ContributedLibrary lib : find(name)) {
|
for (ContributedLibraryRelease lib : find(name)) {
|
||||||
if (version.equals(lib.getParsedVersion())) {
|
if (version.equals(lib.getParsedVersion())) {
|
||||||
return lib;
|
return lib;
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ public class LibrariesIndex {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (ContributedLibrary library : getLibraries()) {
|
for (ContributedLibraryRelease library : getLibraries()) {
|
||||||
sb.append(library.toString());
|
sb.append(library.toString());
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
@ -77,7 +77,7 @@ public class LibrariesIndex {
|
|||||||
|
|
||||||
public List<String> getCategories() {
|
public List<String> getCategories() {
|
||||||
List<String> categories = new LinkedList<>();
|
List<String> categories = new LinkedList<>();
|
||||||
for (ContributedLibrary lib : getLibraries()) {
|
for (ContributedLibraryRelease lib : getLibraries()) {
|
||||||
if (lib.getCategory() != null && !categories.contains(lib.getCategory())) {
|
if (lib.getCategory() != null && !categories.contains(lib.getCategory())) {
|
||||||
categories.add(lib.getCategory());
|
categories.add(lib.getCategory());
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ public class LibrariesIndex {
|
|||||||
|
|
||||||
public List<String> getTypes() {
|
public List<String> getTypes() {
|
||||||
Collection<String> typesAccumulator = new HashSet<>();
|
Collection<String> typesAccumulator = new HashSet<>();
|
||||||
for (ContributedLibrary lib : getLibraries()) {
|
for (ContributedLibraryRelease lib : getLibraries()) {
|
||||||
if (lib.getTypes() != null) {
|
if (lib.getTypes() != null) {
|
||||||
typesAccumulator.addAll(lib.getTypes());
|
typesAccumulator.addAll(lib.getTypes());
|
||||||
}
|
}
|
||||||
@ -101,13 +101,13 @@ public class LibrariesIndex {
|
|||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<ContributedLibrary> getInstalled(String name) {
|
public Optional<ContributedLibraryRelease> getInstalled(String name) {
|
||||||
ContributedLibraryReleases rel = new ContributedLibraryReleases(find(name));
|
ContributedLibrary rel = new ContributedLibrary(find(name));
|
||||||
return rel.getInstalled();
|
return rel.getInstalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ContributedLibrary> resolveDependeciesOf(ContributedLibrary library) {
|
public List<ContributedLibraryRelease> resolveDependeciesOf(ContributedLibraryRelease library) {
|
||||||
List<ContributedLibrary> solution = new ArrayList<>();
|
List<ContributedLibraryRelease> solution = new ArrayList<>();
|
||||||
solution.add(library);
|
solution.add(library);
|
||||||
if (resolveDependeciesOf(solution, library)) {
|
if (resolveDependeciesOf(solution, library)) {
|
||||||
return solution;
|
return solution;
|
||||||
@ -116,8 +116,8 @@ public class LibrariesIndex {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean resolveDependeciesOf(List<ContributedLibrary> solution,
|
public boolean resolveDependeciesOf(List<ContributedLibraryRelease> solution,
|
||||||
ContributedLibrary library) {
|
ContributedLibraryRelease library) {
|
||||||
List<ContributedLibraryDependency> requirements = library.getDependencies();
|
List<ContributedLibraryDependency> requirements = library.getDependencies();
|
||||||
if (requirements == null) {
|
if (requirements == null) {
|
||||||
// No deps for this library, great!
|
// No deps for this library, great!
|
||||||
@ -133,7 +133,7 @@ public class LibrariesIndex {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Generate possible matching dependencies
|
// Generate possible matching dependencies
|
||||||
List<ContributedLibrary> possibleDeps = findMatchingDependencies(dep);
|
List<ContributedLibraryRelease> possibleDeps = findMatchingDependencies(dep);
|
||||||
|
|
||||||
// If there are no dependencies available add as "missing" lib
|
// If there are no dependencies available add as "missing" lib
|
||||||
if (possibleDeps.isEmpty()) {
|
if (possibleDeps.isEmpty()) {
|
||||||
@ -142,8 +142,8 @@ public class LibrariesIndex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pick the installed version if available
|
// Pick the installed version if available
|
||||||
ContributedLibrary selected;
|
ContributedLibraryRelease selected;
|
||||||
Optional<ContributedLibrary> installed = possibleDeps.stream()
|
Optional<ContributedLibraryRelease> installed = possibleDeps.stream()
|
||||||
.filter(l -> l.getInstalledLibrary().isPresent()).findAny();
|
.filter(l -> l.getInstalledLibrary().isPresent()).findAny();
|
||||||
if (installed.isPresent()) {
|
if (installed.isPresent()) {
|
||||||
selected = installed.get();
|
selected = installed.get();
|
||||||
@ -161,8 +161,8 @@ public class LibrariesIndex {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ContributedLibrary> findMatchingDependencies(ContributedLibraryDependency dep) {
|
private List<ContributedLibraryRelease> findMatchingDependencies(ContributedLibraryDependency dep) {
|
||||||
List<ContributedLibrary> available = find(dep.getName());
|
List<ContributedLibraryRelease> available = find(dep.getName());
|
||||||
if (dep.getVersion() == null || dep.getVersion().isEmpty())
|
if (dep.getVersion() == null || dep.getVersion().isEmpty())
|
||||||
return available;
|
return available;
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ public class LibrariesIndexer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ContributedLibrary lib : index.getLibraries()) {
|
for (ContributedLibraryRelease lib : index.getLibraries()) {
|
||||||
lib.unsetInstalledUserLibrary();
|
lib.unsetInstalledUserLibrary();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ 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
|
||||||
ContributedLibrary foundLib = index.find(lib.getName(), lib.getVersion());
|
ContributedLibraryRelease foundLib = index.find(lib.getName(), lib.getVersion());
|
||||||
if (foundLib != null) {
|
if (foundLib != null) {
|
||||||
foundLib.setInstalledUserLibrary(lib);
|
foundLib.setInstalledUserLibrary(lib);
|
||||||
lib.setTypes(foundLib.getTypes());
|
lib.setTypes(foundLib.getTypes());
|
||||||
|
@ -111,16 +111,16 @@ public class LibraryInstaller {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void install(ContributedLibrary lib, ProgressListener progressListener) throws Exception {
|
public void install(ContributedLibraryRelease lib, ProgressListener progressListener) throws Exception {
|
||||||
ArrayList<ContributedLibrary> libs = new ArrayList<>();
|
ArrayList<ContributedLibraryRelease> libs = new ArrayList<>();
|
||||||
libs.add(lib);
|
libs.add(lib);
|
||||||
install(libs, progressListener);
|
install(libs, progressListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void install(List<ContributedLibrary> 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 (ContributedLibrary lib : libs) {
|
for (ContributedLibraryRelease lib : libs) {
|
||||||
// Do install library (3 steps)
|
// Do install library (3 steps)
|
||||||
performInstall(lib, progressListener, progress);
|
performInstall(lib, progressListener, progress);
|
||||||
}
|
}
|
||||||
@ -129,7 +129,7 @@ public class LibraryInstaller {
|
|||||||
rescanLibraryIndex(progress, progressListener);
|
rescanLibraryIndex(progress, progressListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void performInstall(ContributedLibrary 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,7 +140,7 @@ 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<ContributedLibrary> replacedLib = index.find(lib.getName()).stream() //
|
Optional<ContributedLibraryRelease> replacedLib = index.find(lib.getName()).stream() //
|
||||||
.filter(l -> l.getInstalledLibrary().isPresent()) //
|
.filter(l -> l.getInstalledLibrary().isPresent()) //
|
||||||
.filter(l -> l.getInstalledLibrary().get().getInstalledFolder().equals(destFolder)) //
|
.filter(l -> l.getInstalledLibrary().get().getInstalledFolder().equals(destFolder)) //
|
||||||
.findAny();
|
.findAny();
|
||||||
@ -184,7 +184,7 @@ public class LibraryInstaller {
|
|||||||
progress.stepDone();
|
progress.stepDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void remove(ContributedLibrary lib, ProgressListener progressListener) throws IOException {
|
public synchronized void remove(ContributedLibraryRelease lib, ProgressListener progressListener) throws IOException {
|
||||||
if (lib.isIDEBuiltIn()) {
|
if (lib.isIDEBuiltIn()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ package cc.arduino.contributions.libraries;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class UnavailableContributedLibrary extends ContributedLibrary {
|
public class UnavailableContributedLibrary extends ContributedLibraryRelease {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String version;
|
private String version;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user